supplement tests for some small utils dealing with query expressions
This commit is contained in:
parent
24825a13f3
commit
b361fc9672
9 changed files with 293 additions and 42 deletions
|
|
@ -34,10 +34,9 @@ using boost::regex;
|
|||
using boost::smatch;
|
||||
using boost::regex_search;
|
||||
using boost::sregex_iterator;
|
||||
using boost::algorithm::is_upper;
|
||||
using boost::algorithm::is_alpha;
|
||||
|
||||
using util::contains;
|
||||
using util::isnil;
|
||||
|
||||
|
||||
namespace lumiera
|
||||
|
|
@ -45,16 +44,29 @@ namespace lumiera
|
|||
|
||||
namespace query
|
||||
{
|
||||
|
||||
namespace // local definitions
|
||||
{
|
||||
typedef boost::function<bool(string::value_type)> ChPredicate;
|
||||
|
||||
ChPredicate is_alpha = boost::algorithm::is_alpha();
|
||||
ChPredicate is_upper = boost::algorithm::is_upper();
|
||||
} // local defs
|
||||
|
||||
|
||||
void
|
||||
normalizeID (string& id)
|
||||
{
|
||||
id = util::sanitize(id);
|
||||
REQUIRE (!util::isnil(id));
|
||||
REQUIRE (is_alpha() (id[0]));
|
||||
if (isnil(id) || !is_alpha (id[0]))
|
||||
id.insert(0, "o");
|
||||
|
||||
|
||||
REQUIRE (!isnil(id));
|
||||
REQUIRE (is_alpha (id[0]));
|
||||
|
||||
char first = id[0];
|
||||
if (is_upper() (first))
|
||||
if (is_upper (first))
|
||||
id[0] = std::tolower (first);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ namespace test
|
|||
{
|
||||
public:
|
||||
Launch (string testID, string groups) { Suite::enroll (this,testID,groups); };
|
||||
virtual auto_ptr<Test> operator() () { return auto_ptr<Test> (new TEST ); };
|
||||
virtual auto_ptr<Test> operator() () { return auto_ptr<Test> (new TEST ); };
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
|
|
|
|||
|
|
@ -197,8 +197,8 @@ namespace util
|
|||
"trailing Withespace \t \n" --> 'trailing_Withespace'
|
||||
"with a lot \nof Whitespace" --> 'with_a_lot_of_Whitespace'
|
||||
"with\"much (punctuation)[]!" --> 'withmuch_(punctuation)'
|
||||
"§&Ω%€ leading garbarge" --> 'leading_garbarge'
|
||||
"mixed Ω garbarge" --> 'mixed_garbarge'
|
||||
"§&Ω%€ leading garbage" --> 'leading_garbage'
|
||||
"mixed Ω garbage" --> 'mixed_garbage'
|
||||
"Bääääh!!" --> 'Bh'
|
||||
\endverbatim
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -129,8 +129,8 @@ out: ' --> 'trailing_Withespace'
|
|||
out: 'with a lot
|
||||
out: of Whitespace' --> 'with_a_lot_of_Whitespace'
|
||||
out: 'with"much (punctuation)[]!' --> 'withmuch_(punctuation)'
|
||||
out: '§&Ω%€ leading garbarge' --> 'leading_garbarge'
|
||||
out: 'mixed Ω garbarge' --> 'mixed_garbarge'
|
||||
out: '§&Ω%€ leading garbage' --> 'leading_garbage'
|
||||
out: 'mixed Ω garbage' --> 'mixed_garbage'
|
||||
out: 'Bääääh!!' --> 'Bh'
|
||||
out: '§&Ω%€' --> ''
|
||||
END
|
||||
|
|
|
|||
|
|
@ -2,3 +2,22 @@ TESTING "Proc Layer config rules Test Suite" ./test-components --group=query
|
|||
|
||||
|
||||
|
||||
TEST "QueryUtils_test" QueryUtils_test Query <<END
|
||||
out: N7lumiera5query4test5ThingE: I am writing a test sentence.
|
||||
END
|
||||
|
||||
|
||||
TEST "QueryUtils_test" QueryUtils_test normalizeID <<END
|
||||
out: ..original : a A AA dufte 1a _1 A_A BÄH White space §&Ω%€GΩ%€ar Ω baäääääge!!!!! :
|
||||
out: normalized : a a aA dufte o1a o_1 a_A bH o white_space gar_bage :
|
||||
END
|
||||
|
||||
|
||||
TEST "QueryUtils_test" QueryUtils_test extractID <<END
|
||||
return: 0
|
||||
END
|
||||
|
||||
|
||||
TEST "QueryUtils_test" QueryUtils_test countPraed <<END
|
||||
return: 0
|
||||
END
|
||||
|
|
|
|||
95
tests/components/common/query/querydiagnostics.hpp
Normal file
95
tests/components/common/query/querydiagnostics.hpp
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
QUERYDIAGNOSTICS.hpp - herlpers for writing tests covering config queries
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2008, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef LUMIERA_TEST_QUERY_QUERYDIAGNOSTICS_H
|
||||
#define LUMIERA_TEST_QUERY_QUERYDIAGNOSTICS_H
|
||||
|
||||
|
||||
//#include "common/factory.hpp"
|
||||
//#include "common/util.hpp"
|
||||
|
||||
//#include <boost/algorithm/string.hpp>
|
||||
//#include <boost/lexical_cast.hpp>
|
||||
#include <boost/format.hpp>
|
||||
//#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
//using boost::algorithm::join;
|
||||
//using boost::lexical_cast;
|
||||
using boost::format;
|
||||
using std::string;
|
||||
//using std::cout;
|
||||
using std::rand;
|
||||
|
||||
|
||||
|
||||
namespace lumiera
|
||||
{
|
||||
namespace query
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace // implementation constants
|
||||
{
|
||||
|
||||
format predicatePatt ("%s_%2i( %s )");
|
||||
const string garbage ("asdfghjklqwertzuiop");
|
||||
|
||||
const uint MAX_DEGREE_RAND = 9;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline string
|
||||
garbage_term () ///< yields a random string of 3 letters
|
||||
{
|
||||
return str (predicatePatt
|
||||
% char ('a'+ rand() % 26)
|
||||
% (rand() % 100)
|
||||
% garbage.substr(rand() % 17 , 3)
|
||||
);
|
||||
}
|
||||
|
||||
inline string
|
||||
garbage_query (int degree=0) ///< fabricating (random) query strings
|
||||
{
|
||||
string fake;
|
||||
if (!degree)
|
||||
degree = 1 + rand() % MAX_DEGREE_RAND;
|
||||
while (0 < --degree)
|
||||
fake += garbage_term() + ", ";
|
||||
fake += garbage_term() + ".";
|
||||
return fake;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace query
|
||||
|
||||
} // namespace lumiera
|
||||
#endif
|
||||
146
tests/components/common/query/queryutilstest.cpp
Normal file
146
tests/components/common/query/queryutilstest.cpp
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
QueryUtils(Test) - checking various utils provided for dealing with config queries
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2008, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
* *****************************************************/
|
||||
|
||||
|
||||
#include "common/test/run.hpp"
|
||||
#include "common/util.hpp"
|
||||
|
||||
#include "common/cmdline.hpp"
|
||||
#include "common/query.hpp"
|
||||
#include "common/query/querydiagnostics.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
|
||||
using lumiera::Query;
|
||||
using util::Cmdline;
|
||||
using util::isnil;
|
||||
using util::contains;
|
||||
using util::for_each;
|
||||
|
||||
using boost::bind;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
|
||||
|
||||
|
||||
namespace lumiera
|
||||
{
|
||||
namespace query
|
||||
{
|
||||
namespace test
|
||||
{
|
||||
|
||||
struct Thing
|
||||
{
|
||||
virtual ~Thing() {} // add RTTI for Query.asKey();
|
||||
};
|
||||
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* @test check the various small helpers and utilities we utilize
|
||||
* for dealing with ConfigQuery
|
||||
*/
|
||||
class QueryUtils_test : public Test
|
||||
{
|
||||
|
||||
virtual void
|
||||
run (Arg arg)
|
||||
{
|
||||
if (isnil(arg)) arg = Cmdline ("Query normalizeID extractID countPraed");
|
||||
|
||||
if (contains (arg, "Query" )) check_Query ();
|
||||
if (contains (arg, "normalizeID")) check_normalizeID ();
|
||||
if (contains (arg, "extractID" )) check_extractID ();
|
||||
if (contains (arg, "countPraed" )) check_countPraed ();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @test Query wrapper class basics */
|
||||
void
|
||||
check_Query ()
|
||||
{
|
||||
cout << Query<Thing> ("I am writing a test sentence.").asKey() << "\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @test sanitizing and normalizing various tokens */
|
||||
void
|
||||
check_normalizeID ()
|
||||
{
|
||||
Cmdline tokens ("a A AA dufte 1a _1 A_A BÄH");
|
||||
tokens.push_back ("");
|
||||
tokens.push_back (" White space ");
|
||||
tokens.push_back ("§&Ω%€GΩ%€ar Ω baäääääge!!!!! ");
|
||||
|
||||
cout << "..original : " << tokens << " :\n";
|
||||
|
||||
for_each (tokens, bind ( &normalizeID, _1 ));
|
||||
|
||||
cout << "normalized : " << tokens << " :\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @test the simple regexp extracting a parameter token */
|
||||
void
|
||||
check_extractID ()
|
||||
{
|
||||
ASSERT ("tok" == extractID ("pred", "pred(tok)." ));
|
||||
ASSERT ("tok" == extractID ("pred", " pred( tok )" ));
|
||||
ASSERT ("tok" == extractID ("pred", "pred(tok), pred(tux)." ));
|
||||
ASSERT ("tok" == extractID ("pred", "other(xyz) pred(tok) pred(tux)" ));
|
||||
ASSERT ("tok" == extractID ("pred", "some( pred(tok)" ));
|
||||
|
||||
ASSERT (isnil (extractID ("pred", "pred (tok)")));
|
||||
ASSERT (isnil (extractID ("pred", "pred tok)" )));
|
||||
ASSERT (isnil (extractID ("pred", "pred(tok " )));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @test counting of predicates in a quiery
|
||||
* (currently 4/08 regexp based...)
|
||||
*/
|
||||
void
|
||||
check_countPraed ()
|
||||
{
|
||||
for (uint i=1; i <= 30; ++i)
|
||||
ASSERT ( i == countPraed (garbage_query (i)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Register this test class... */
|
||||
LAUNCHER (QueryUtils_test, "unit query");
|
||||
|
||||
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace query
|
||||
|
||||
} // namespace lumiera
|
||||
|
|
@ -45,8 +45,8 @@ namespace util
|
|||
print_clean ("trailing Withespace\n \t");
|
||||
print_clean ("with a \t lot\n of Whitespace");
|
||||
print_clean ("with\"much (punctuation)[]!");
|
||||
print_clean ("§&Ω%€ leading garbarge");
|
||||
print_clean ("mixed Ω garbarge");
|
||||
print_clean ("§&Ω%€ leading garbage");
|
||||
print_clean ("mixed Ω garbage");
|
||||
print_clean ("Bääääh!!");
|
||||
print_clean ("§&Ω%€");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,15 @@
|
|||
#include "common/factory.hpp"
|
||||
#include "common/query.hpp"
|
||||
|
||||
#include "common/query/querydiagnostics.hpp"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
|
||||
using lumiera::Query;
|
||||
using lumiera::query::test::garbage_query;
|
||||
using util::isnil;
|
||||
|
||||
using std::tr1::shared_ptr;
|
||||
|
|
@ -52,13 +55,10 @@ namespace mobject
|
|||
namespace test
|
||||
{
|
||||
|
||||
const uint MAX_DEGREE_RAND = 9;
|
||||
|
||||
format typePatt ("Dummy<%2i>");
|
||||
format instancePatt ("obj_%s_%i");
|
||||
format predicatePatt ("%s_%2i( %s )");
|
||||
|
||||
const string garbage ("asdfghjklqwertzuiop");
|
||||
|
||||
|
||||
/** create a random new ID */
|
||||
|
|
@ -85,27 +85,6 @@ namespace mobject
|
|||
|
||||
|
||||
|
||||
string
|
||||
garbage_term () ///< yields a random string of 3 letters
|
||||
{
|
||||
return str (predicatePatt
|
||||
% char ('a'+ rand() % 26)
|
||||
% (rand() % 100)
|
||||
% garbage.substr(rand() % 17 , 3)
|
||||
);
|
||||
}
|
||||
|
||||
string
|
||||
q_str (int degree=0) ///< fabricating (random) query strings
|
||||
{
|
||||
string fake;
|
||||
if (!degree)
|
||||
degree = 1 + rand() % MAX_DEGREE_RAND;
|
||||
while (0 < --degree)
|
||||
fake += garbage_term() + ", ";
|
||||
fake += garbage_term() + ".";
|
||||
return fake;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -141,11 +120,11 @@ namespace mobject
|
|||
public:
|
||||
DefsRegistryImpl_test ()
|
||||
: o1 (oFac()), o2 (oFac()), o3 (oFac()),
|
||||
q1 (q_str (1)),
|
||||
q2 (q_str (2)),
|
||||
q3 (q_str (3)),
|
||||
q4 (q_str (4)),
|
||||
q5 (q_str (5))
|
||||
q1 (garbage_query (1)),
|
||||
q2 (garbage_query (2)),
|
||||
q3 (garbage_query (3)),
|
||||
q4 (garbage_query (4)),
|
||||
q5 (garbage_query (5))
|
||||
{ }
|
||||
|
||||
|
||||
|
|
@ -178,7 +157,7 @@ namespace mobject
|
|||
for (int i=0; i<100; ++i)
|
||||
{
|
||||
P px (pFac());
|
||||
Q23 qx (q_str());
|
||||
Q23 qx (garbage_query());
|
||||
ps[qx] = px;
|
||||
reg_->put (px, qx);
|
||||
px->instanceID = qx;
|
||||
|
|
|
|||
Loading…
Reference in a new issue