diff --git a/src/common/query.cpp b/src/common/query.cpp index 09c642f1c..d7fb51257 100644 --- a/src/common/query.cpp +++ b/src/common/query.cpp @@ -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 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); } diff --git a/src/common/test/run.hpp b/src/common/test/run.hpp index b38729d8a..529896d0b 100644 --- a/src/common/test/run.hpp +++ b/src/common/test/run.hpp @@ -85,7 +85,7 @@ namespace test { public: Launch (string testID, string groups) { Suite::enroll (this,testID,groups); }; - virtual auto_ptr operator() () { return auto_ptr (new TEST ); }; + virtual auto_ptr operator() () { return auto_ptr (new TEST ); }; }; } // namespace test diff --git a/src/common/util.hpp b/src/common/util.hpp index d56a45432..7f8704554 100644 --- a/src/common/util.hpp +++ b/src/common/util.hpp @@ -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 */ diff --git a/tests/50components.tests b/tests/50components.tests index 10cf575a5..d2d38e5d0 100644 --- a/tests/50components.tests +++ b/tests/50components.tests @@ -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 diff --git a/tests/52query.tests b/tests/52query.tests index 2905bb4b4..ce5f4f31e 100644 --- a/tests/52query.tests +++ b/tests/52query.tests @@ -2,3 +2,22 @@ TESTING "Proc Layer config rules Test Suite" ./test-components --group=query +TEST "QueryUtils_test" QueryUtils_test Query < + + 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 +//#include +#include +//#include +#include + +//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 diff --git a/tests/components/common/query/queryutilstest.cpp b/tests/components/common/query/queryutilstest.cpp new file mode 100644 index 000000000..6a5b7f375 --- /dev/null +++ b/tests/components/common/query/queryutilstest.cpp @@ -0,0 +1,146 @@ +/* + QueryUtils(Test) - checking various utils provided for dealing with config queries + + Copyright (C) Lumiera.org + 2008, Hermann Vosseler + + 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 +#include +#include + +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 ("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 diff --git a/tests/components/common/sanitizedidentifiertest.cpp b/tests/components/common/sanitizedidentifiertest.cpp index 416d81c58..1e96bc515 100644 --- a/tests/components/common/sanitizedidentifiertest.cpp +++ b/tests/components/common/sanitizedidentifiertest.cpp @@ -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 ("§&Ω%€"); } diff --git a/tests/components/proc/mobject/session/defsregistryimpltest.cpp b/tests/components/proc/mobject/session/defsregistryimpltest.cpp index 3bdc8f1f2..fa5d2c4c3 100644 --- a/tests/components/proc/mobject/session/defsregistryimpltest.cpp +++ b/tests/components/proc/mobject/session/defsregistryimpltest.cpp @@ -28,12 +28,15 @@ #include "common/factory.hpp" #include "common/query.hpp" +#include "common/query/querydiagnostics.hpp" + #include #include #include #include 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;