LUMIERA.clone/tests/library/query/query-utils-test.cpp

151 lines
4.7 KiB
C++
Raw Permalink Normal View History

2010-04-13 06:37:21 +02:00
/*
QueryUtils(Test) - checking various utils provided for dealing with config queries
2010-12-17 23:28:49 +01:00
Copyright: clarify and simplify the file headers * Lumiera source code always was copyrighted by individual contributors * there is no entity "Lumiera.org" which holds any copyrights * Lumiera source code is provided under the GPL Version 2+ == Explanations == Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above. For this to become legally effective, the ''File COPYING in the root directory is sufficient.'' The licensing header in each file is not strictly necessary, yet considered good practice; attaching a licence notice increases the likeliness that this information is retained in case someone extracts individual code files. However, it is not by the presence of some text, that legally binding licensing terms become effective; rather the fact matters that a given piece of code was provably copyrighted and published under a license. Even reformatting the code, renaming some variables or deleting parts of the code will not alter this legal situation, but rather creates a derivative work, which is likewise covered by the GPL! The most relevant information in the file header is the notice regarding the time of the first individual copyright claim. By virtue of this initial copyright, the first author is entitled to choose the terms of licensing. All further modifications are permitted and covered by the License. The specific wording or format of the copyright header is not legally relevant, as long as the intention to publish under the GPL remains clear. The extended wording was based on a recommendation by the FSF. It can be shortened, because the full terms of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
Copyright (C)
2008, Hermann Vosseler <Ichthyostega@web.de>
2010-12-17 23:28:49 +01:00
Copyright: clarify and simplify the file headers * Lumiera source code always was copyrighted by individual contributors * there is no entity "Lumiera.org" which holds any copyrights * Lumiera source code is provided under the GPL Version 2+ == Explanations == Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above. For this to become legally effective, the ''File COPYING in the root directory is sufficient.'' The licensing header in each file is not strictly necessary, yet considered good practice; attaching a licence notice increases the likeliness that this information is retained in case someone extracts individual code files. However, it is not by the presence of some text, that legally binding licensing terms become effective; rather the fact matters that a given piece of code was provably copyrighted and published under a license. Even reformatting the code, renaming some variables or deleting parts of the code will not alter this legal situation, but rather creates a derivative work, which is likewise covered by the GPL! The most relevant information in the file header is the notice regarding the time of the first individual copyright claim. By virtue of this initial copyright, the first author is entitled to choose the terms of licensing. All further modifications are permitted and covered by the License. The specific wording or format of the copyright header is not legally relevant, as long as the intention to publish under the GPL remains clear. The extended wording was based on a recommendation by the FSF. It can be shortened, because the full terms of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
  **Lumiera** 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. See the file COPYING for further details.
2010-12-17 23:28:49 +01:00
Copyright: clarify and simplify the file headers * Lumiera source code always was copyrighted by individual contributors * there is no entity "Lumiera.org" which holds any copyrights * Lumiera source code is provided under the GPL Version 2+ == Explanations == Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above. For this to become legally effective, the ''File COPYING in the root directory is sufficient.'' The licensing header in each file is not strictly necessary, yet considered good practice; attaching a licence notice increases the likeliness that this information is retained in case someone extracts individual code files. However, it is not by the presence of some text, that legally binding licensing terms become effective; rather the fact matters that a given piece of code was provably copyrighted and published under a license. Even reformatting the code, renaming some variables or deleting parts of the code will not alter this legal situation, but rather creates a derivative work, which is likewise covered by the GPL! The most relevant information in the file header is the notice regarding the time of the first individual copyright claim. By virtue of this initial copyright, the first author is entitled to choose the terms of licensing. All further modifications are permitted and covered by the License. The specific wording or format of the copyright header is not legally relevant, as long as the intention to publish under the GPL remains clear. The extended wording was based on a recommendation by the FSF. It can be shortened, because the full terms of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
* *****************************************************************/
2010-04-13 06:37:21 +02:00
/** @file query-utils-test.cpp
** unit test \ref QueryUtils_test
*/
2010-04-13 06:37:21 +02:00
#include "lib/test/run.hpp"
#include "lib/util.hpp"
#include "lib/util-foreach.hpp"
2012-12-03 00:18:18 +01:00
#include "lib/query-util.hpp"
2010-04-13 06:37:21 +02:00
#include "lib/cmdline.hpp"
#include "lib/query-diagnostics.hpp"
#include "lib/format-cout.hpp"
2010-04-13 06:37:21 +02:00
#include <functional>
2010-04-13 06:37:21 +02:00
using lib::Cmdline;
2010-04-13 06:37:21 +02:00
using util::isnil;
using util::contains;
using util::for_each;
using std::placeholders::_1;
using std::bind;
2010-04-13 06:37:21 +02:00
using std::string;
2012-12-03 00:18:18 +01:00
namespace lib {
2010-04-13 06:37:21 +02:00
namespace query {
namespace test{
struct Thing
{
virtual ~Thing() {} // add RTTI for Query.asKey();
};
/********************************************************************//**
2010-04-13 06:37:21 +02:00
* @test check the various small helpers and utilities we utilise
2025-06-07 23:59:57 +02:00
* for dealing with ConfigQuery
2010-04-13 06:37:21 +02:00
*/
class QueryUtils_test : public Test
{
virtual void
2025-06-07 23:59:57 +02:00
run (Arg arg)
2010-04-13 06:37:21 +02:00
{
if (isnil(arg)) arg = Cmdline ("normaliseID extractID removeTerm countPred");
2010-04-13 06:37:21 +02:00
if (contains (arg, "normaliseID")) check_normaliseID();
if (contains (arg, "extractID" )) check_extractID ();
if (contains (arg, "removeTerm" )) check_removeTerm ();
if (contains (arg, "countPred" )) check_countPred ();
}
/** @test sanitising and normalising various tokens */
void
check_normaliseID ()
{
Cmdline tokens ("a A AA dufte 1a _1 A_A BÄH");
tokens.push_back ("");
tokens.push_back (" White \t space ");
2010-04-13 06:37:21 +02:00
tokens.push_back ("§&Ω%€GΩ%€ar ☠☠☠ baäääääge!!!!! ");
cout << "..original : "<<tokens<<" :"<<endl;
2010-04-13 06:37:21 +02:00
for_each (tokens, normaliseID, _1 );
cout << "normalised : "<<tokens<<" :"<<endl;
2010-04-13 06:37:21 +02:00
}
/** @test the simple regexp extracting a parameter token */
void
check_extractID ()
{
CHECK ("tok" == extractID ("pred", "pred(tok)." ));
CHECK ("tok" == extractID ("pred", " pred( tok )" ));
CHECK ("tok" == extractID ("pred", "pred(tok), pred(tux)." ));
CHECK ("tok" == extractID ("pred", "other(xyz) pred(tok) pred(tux)" ));
CHECK ("tok" == extractID ("pred", "some( pred(tok)" ));
2010-04-13 06:37:21 +02:00
CHECK (isnil (extractID ("pred", "pred (tok)")));
CHECK (isnil (extractID ("pred", "pred tok)" )));
CHECK (isnil (extractID ("pred", "pred(tok " )));
2010-04-13 06:37:21 +02:00
}
/** @test the regexp based cutting of a term with given symbol */
void
check_removeTerm ()
{
// successful------Symbol---input-string----------------------extracted------remaining-------------
CHECK_removeTerm ("pred", "pred(tok).", "pred(tok)", "." );
CHECK_removeTerm ("pred", " pred( tok )", "pred(tok)", " " );
CHECK_removeTerm ("pred", "pred(tok), pred(tux).", "pred(tok)", "pred(tux)." );
CHECK_removeTerm ("pred", "other(xyz) pred(tok) pred(tux)", "pred(tok)", "other(xyz) pred(tux)" );
CHECK_removeTerm ("pred", "some( pred(tok)", "pred(tok)", "some( " );
2010-04-13 06:37:21 +02:00
// not successful
CHECK_removeTerm ("pred", "pred (tok", "", "pred (tok" );
CHECK_removeTerm ("pred", "pred tok)", "", "pred tok)" );
CHECK_removeTerm ("pred", "pred(tok", "", "pred(tok" );
2010-04-13 06:37:21 +02:00
}
void
CHECK_removeTerm (Symbol sym, string input, string extracted, string modified)
2010-04-13 06:37:21 +02:00
{
CHECK (extracted == removeTerm (sym, input));
CHECK (modified == input);
2010-04-13 06:37:21 +02:00
}
/** @test counting of predicates in a query
* (currently 4/08 regexp based...)
*/
void
check_countPred ()
{
for (uint i=1; i <= 30; ++i)
CHECK ( i == countPred (garbage_query (i)));
2010-04-13 06:37:21 +02:00
}
};
/** Register this test class... */
LAUNCHER (QueryUtils_test, "unit query");
}}} // namespace lib::query::test