From cb13b09360bcd0800d607b740ab6100ee81be5d2 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 19 Aug 2007 21:57:19 +0200 Subject: [PATCH] WIP: started augmenting my test-runner class to be configurable via cmdline Added dependency to boost::program_options. Still trying to get into pace with the testing thing ;-) --- SConstruct | 13 +- src/common/error.cpp | 15 +++ src/common/error.hpp | 25 +++- .../helper => src/common/test}/run.hpp | 12 +- .../helper => src/common/test}/suite.cpp | 15 ++- .../helper => src/common/test}/suite.hpp | 13 +- src/common/test/testoption.cpp | 122 ++++++++++++++++++ src/common/test/testoption.hpp | 70 ++++++++++ tests/.gitignore | 1 + tests/50components.tests | 5 + tests/components/common/factorytest.cpp | 2 +- .../components/common/test/testoptiontest.cpp | 73 +++++++++++ .../{common => }/helloworldtest.cpp | 3 +- tests/components/mainsuite.cpp | 3 +- wiki/index.html | 7 +- 15 files changed, 353 insertions(+), 26 deletions(-) rename {tests/components/helper => src/common/test}/run.hpp (85%) rename {tests/components/helper => src/common/test}/suite.cpp (92%) rename {tests/components/helper => src/common/test}/suite.hpp (82%) create mode 100644 src/common/test/testoption.cpp create mode 100644 src/common/test/testoption.hpp create mode 100644 tests/components/common/test/testoptiontest.cpp rename tests/components/{common => }/helloworldtest.cpp (92%) diff --git a/SConstruct b/SConstruct index 9b11e379e..8c7a7781c 100644 --- a/SConstruct +++ b/SConstruct @@ -174,6 +174,7 @@ def configurePlatform(env): print 'Did not find the pthread lib or pthread.h, exiting.' else: conf.env.Append(CPPFLAGS = ' -DHAVE_PTHREAD_H') + conf.env.Append(CCFLAGS = ' -pthread') if conf.CheckCHeader('execinfo.h'): conf.env.Append(CPPFLAGS = ' -DHAS_EXECINFO_H') @@ -188,10 +189,14 @@ def configurePlatform(env): if not conf.CheckCXXHeader('boost/config.hpp'): print 'We need the C++ boost-lib.' Exit(1) - - if not conf.CheckCXXHeader('boost/shared_ptr.hpp'): - print 'We need boost::shared_ptr (shared_ptr.hpp).' - Exit(1) + else: + if not conf.CheckCXXHeader('boost/shared_ptr.hpp'): + print 'We need boost::shared_ptr (shared_ptr.hpp).' + Exit(1) + if not conf.CheckLibWithHeader('boost_program_options-mt','boost/program_options.hpp','C++'): + print 'We need boost::program_options (also the corresponding binary lib).' + Exit(1) + # create new env containing the finished configuration return conf.Finish() diff --git a/src/common/error.cpp b/src/common/error.cpp index 0e869fe93..cd46fa15f 100644 --- a/src/common/error.cpp +++ b/src/common/error.cpp @@ -22,9 +22,21 @@ #include "common/error.hpp" +#include "nobugcfg.h" + +///////////////////////////////////TODO +#include + +extern void booo() + { + std::cerr << "Booooo!!!" << std::endl; + std::cerr.flush(); + } +///////////////////////////////////TODO namespace cinelerra { + char* killme ="cinelerra Errrror. TODO real description needed"; /** Description of the problem, including the internal char constant * in accordance to cinelerras error identification scheme. @@ -34,6 +46,8 @@ namespace cinelerra const char* Error::what () const throw() { + TODO("really implement cinelerra::Error description"); + return killme; } @@ -46,6 +60,7 @@ namespace cinelerra std::exception Error::rootCause() const throw() { + UNIMPLEMENTED("storing and managing root causes"); } diff --git a/src/common/error.hpp b/src/common/error.hpp index 973fa1d8a..bc72d6861 100644 --- a/src/common/error.hpp +++ b/src/common/error.hpp @@ -72,6 +72,11 @@ namespace cinelerra { }; + + class Fatal : public Logic + { + + }; class Config : public Error { @@ -93,10 +98,24 @@ namespace cinelerra }; - - - + + } // namespace error } // namespace cinelerra + +#include + +extern void booo(); + +/****************************************************** + * if NoBug is used, redefine some macros + * to rather throw Cinelerra Errors instead of aborting + */ +#ifdef NOBUG_ABORT +#undef NOBUG_ABORT +#define NOBUG_ABORT throw cinelerra::error::Fatal(); ////////////////TODO +#endif + + #endif diff --git a/tests/components/helper/run.hpp b/src/common/test/run.hpp similarity index 85% rename from tests/components/helper/run.hpp rename to src/common/test/run.hpp index 518ff37d2..79fae255f 100644 --- a/tests/components/helper/run.hpp +++ b/src/common/test/run.hpp @@ -28,7 +28,7 @@ #include #include -#include "helper/suite.hpp" +#include "common/test/suite.hpp" namespace test @@ -37,7 +37,7 @@ namespace test using std::string; using std::auto_ptr; - typedef std::vector * Arg; + typedef std::vector & Arg; @@ -89,4 +89,12 @@ using ::test::Arg; using ::test::Test; using ::test::Launch; +// and provide shortcut for registration +#define LAUNCHER(_TEST_CLASS_, _GROUPS_) \ + /** Register _TEST_CLASS_ to be invoked in some test suites (groups) _GROUPS_ */ \ + Launch<_TEST_CLASS_> run_##_TEST_CLASS_##_(STRINGIFY(_TEST_CLASS_), _GROUPS_); + +#define STRINGIFY(TOKEN) __STRINFY(TOKEN) +#define __STRINFY(TOKEN) #TOKEN + #endif diff --git a/tests/components/helper/suite.cpp b/src/common/test/suite.cpp similarity index 92% rename from tests/components/helper/suite.cpp rename to src/common/test/suite.cpp index 6d8250cac..ee3596c29 100644 --- a/tests/components/helper/suite.cpp +++ b/src/common/test/suite.cpp @@ -28,8 +28,8 @@ #include #include -#include "helper/suite.hpp" -#include "helper/run.hpp" +#include "common/test/suite.hpp" +#include "common/test/run.hpp" #include "common/error.hpp" #include "common/util.hpp" @@ -151,15 +151,18 @@ namespace test // go ahead and invoke just this test. if (argc > 2) { // pass additional cmdline as vector + FIXME("use Optparser"); vector arglist(argc-2); for ( int i=2; irun(&arglist); + (*test)()->run(arglist); } else - (*test)()->run(0); // without additional argumens + FIXME("use Optparser"); + vector nix; + (*test)()->run(nix); // without additional argumens return; } @@ -172,7 +175,9 @@ namespace test { std::cout << " ----------"<< i->first<< "----------\n"; Launcher& test = *(i->second); - test()->run(0); // without cmdline arguments + FIXME("use Optparser"); + vector nix; + test()->run(nix); // without cmdline arguments } } diff --git a/tests/components/helper/suite.hpp b/src/common/test/suite.hpp similarity index 82% rename from tests/components/helper/suite.hpp rename to src/common/test/suite.hpp index 8060aaab3..addd13e07 100644 --- a/tests/components/helper/suite.hpp +++ b/src/common/test/suite.hpp @@ -37,10 +37,12 @@ namespace test class Launcher; - /** - * Helper class for running a collection of tests. - * + * Enables running a collection of tests. + * In internal registration service #enroll() is provided + * for the individual Test - inscances to be recognized as + * testcases. The groupID passed to the constructor selects + * all testcases declared as belonging to this Group. */ class Suite { @@ -53,8 +55,7 @@ namespace test static const string ALLGROUP; }; - - - + + } // namespace test #endif diff --git a/src/common/test/testoption.cpp b/src/common/test/testoption.cpp new file mode 100644 index 000000000..2e1e4686e --- /dev/null +++ b/src/common/test/testoption.cpp @@ -0,0 +1,122 @@ +/* + Suite - helper class for running collections of tests + + Copyright (C) CinelerraCV + 2007, Christian Thaeter + + 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 +//#include +//#include +//#include +//#include + +#include "common/test/testoption.hpp" +#include "common/test/suite.hpp" +//#include "common/util.hpp" + +#include "nobugcfg.h" +#include "common/error.hpp" + + +namespace test + { +// using std::map; +// using std::auto_ptr; +// using std::tr1::shared_ptr; + +// using util::isnil; + + + + /** set up an options parser to use the current commandline. + * reconizes the following options + * \code + * --help + * --group + * \endcode + */ + TestOption::TestOption (int argc, const char* argv[]) + : vm(), cmdline() + { + cmdline.reserve (10); + parseOptions (argc,argv); + } + + + /** variant of the ctor taking a "fake" cmdline */ + TestOption::TestOption (string line) + : vm(), cmdline() + { + cmdline.reserve (10); + const char* fakeArg[3] = {"test", line.c_str() }; +// fakeArg[1] = line.c_str(); + parseOptions (1,fakeArg); + } + + + /** do the comandline parsing for the ctors */ + void TestOption::parseOptions (int argc, const char* argv[]) + { + TODO("define options"); + UNIMPLEMENTED("actual commandline parsing!!"); + } + + + /** @return the Tests-Group as given on cmdline, or Suite::ALLGROUP as default + */ + const string & + TestOption::getTestgroup () + { + FIXME("actual commandline parsing!!"); + return Suite::ALLGROUP; + } + + string booooh = "boooh!"; + /** @return ID of a single test to run, empty if not specified + */ + const string & + TestOption::getTestID () + { + UNIMPLEMENTED("actual commandline parsing"); + return booooh; + } + + + /** gather all remaining unknown cmd line tokens into a vector. + * @Note: the actual vector remains a member of this object, but isn't const + */ + vector& + TestOption::remainingCmdline () + { + UNIMPLEMENTED("get unknown remaining options"); + return cmdline; + } + + + /** */ + TestOption::operator string const () + { + UNIMPLEMENTED("convert the remaining Cmndline to string"); + return 0; + } + + + +} // namespace test diff --git a/src/common/test/testoption.hpp b/src/common/test/testoption.hpp new file mode 100644 index 000000000..c0aa073cb --- /dev/null +++ b/src/common/test/testoption.hpp @@ -0,0 +1,70 @@ +/* + TESTOPTION.hpp - handle cmdline for invoking Testsuite + + Copyright (C) CinelerraCV + 2007, Christian Thaeter + + 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 TESTHELPER_TESTOPTION_H +#define TESTHELPER_TESTOPTION_H + +#include +#include +#include + + + +namespace test + { + using std::string; + using std::vector; + + typedef boost::program_options::variables_map VarMap; + + + /** + * Support for selecting and configuring testcases + * via commandline arguments. A preconfigured wrapper + * around boost::program_options, with the ability + * to tolerate unknown options and get an vector + * of everything remaining in the commandline after + * parsing the known options. + */ + class TestOption + { + public: + TestOption (int argc, const char* argv[]); + explicit TestOption (string cmdline); + const string& getTestgroup (); + const string& getTestID (); + vector& remainingCmdline (); + + operator string const (); + + private: + VarMap vm; + vector cmdline; + + void parseOptions (int argc, const char* argv[]); + }; + + + +} // namespace test +#endif diff --git a/tests/.gitignore b/tests/.gitignore index cbfcd6fe3..0ae34206f 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,4 +1,5 @@ ,* +test-* mainsuite errortest plugin-example diff --git a/tests/50components.tests b/tests/50components.tests index e022d0d35..99e575ad0 100644 --- a/tests/50components.tests +++ b/tests/50components.tests @@ -10,3 +10,8 @@ out: This is how the world ends... return: 0 END +TEST "Parseoption" TestOption_test < + + 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 +#include "common/test/run.hpp" +#include "common/test/testoption.hpp" +#include "common/util.hpp" + +using util::isnil; + +namespace test + { + + class TestOption_test : public Test + { + virtual void run(Arg arg) + { + noOptions(); + help(); + groupID(); + singleTest(); + groupFilter1(); + groupFilter2(); + additionalCmd(); + additionalCmd2(); + } + + void doIt (const string cmdline) + { + std::cout << "Testing invocation with cmdline: " << cmdline << "..." << std::endl; + + TestOption optparser (cmdline); + const string testID = optparser.getTestID(); + std::cout << "--> Testgroup=" << optparser.getTestgroup() << std::endl; + std::cout << "--> Test-ID =" << (isnil(testID)? testID : "--missing--") << std::endl; + std::cout << "--> remaining=" << string(optparser) << std::endl; + } + + void noOptions() { doIt (""); } + void help() { doIt ("--help"); } + void groupID() { doIt ("--group TestGroupID"); } + void singleTest() { doIt (" SingleTestID"); } + void groupFilter1() { doIt (" SingleTestID --group TestGroupID"); } + void groupFilter2() { doIt (" --group TestGroupID SingleTestID "); } + void additionalCmd() { doIt (" --group TestGroupID SingleTestID spam eggs"); } + void additionalCmd2() { doIt ("\t\tSingleTestID spam --group TestGroupID \t eggs"); } + + }; + + LAUNCHER (TestOption_test, "function common"); + +} // namespace test + diff --git a/tests/components/common/helloworldtest.cpp b/tests/components/helloworldtest.cpp similarity index 92% rename from tests/components/common/helloworldtest.cpp rename to tests/components/helloworldtest.cpp index d22ad619d..09c049f55 100644 --- a/tests/components/common/helloworldtest.cpp +++ b/tests/components/helloworldtest.cpp @@ -22,7 +22,7 @@ #include -#include "helper/run.hpp" +#include "common/test/run.hpp" namespace cinelerra @@ -49,6 +49,7 @@ namespace cinelerra /** Register this test class to be invoked in some test groups (suites) */ Launch run_HelloWorld_test("HelloWorld_test","unit common"); + // NOTE: you may use the Macro "LAUNCHER" in run.hpp to simplify this Registration } // namespace test diff --git a/tests/components/mainsuite.cpp b/tests/components/mainsuite.cpp index 9ed0831fe..3264ad7de 100644 --- a/tests/components/mainsuite.cpp +++ b/tests/components/mainsuite.cpp @@ -21,8 +21,7 @@ */ -#include "helper/suite.hpp" - +#include "common/test/suite.hpp" /** run all tests or any single test specified in the first * cmd line argument. diff --git a/wiki/index.html b/wiki/index.html index e77f90799..cc4fc1b8d 100755 --- a/wiki/index.html +++ b/wiki/index.html @@ -747,14 +747,17 @@ config.macros.timeline.handler = function(place,macroName,params,wikifier,paramS } //}}} -
+
for __Building__
 * gcc (4.1), glibc6 (2.3), libstdc++6 (4.1)
 * [[build system|BuildSystem]] dependencies: SCons (0.96.90), Python (2.3)
 * NoBug for Logging, Tracing, Asserting (can be obtained from [[Pipapo.org|http://www.pipapo.org/pipawiki/NoBug]])
 * ~NoBug needs [[valgrind|Valgrind]] (3.2), execinfo.h and libpthread (&rarr; glibc)
 * std::tr1 &mdash; esp. for the former BOOST::shared_ptr (which is now proposed standard)
-* BOOST
+* BOOST ~~(below are the DEBIAN package names)~~
+** libboost-dev (=1.34.1-2)
+** libboost-program-options-dev (=1.34.1-2)
+** libboost-program-options1.34.1 (=1.34.1-2) ''NOTE: binary dependency''
 //usually, newer versions are OK//
 
 for __Running__