diff --git a/.gitignore b/.gitignore index cf7ebb45d..c89dffc5e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ scripts/* configure config.log aclocal.m4 +autom4te.cache semantic.cache wiki/backups/* doc/devel/draw/*.png diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index cb1451c4f..8e5b1b8ae 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -43,6 +43,7 @@ liblumiera_la_SOURCES = \ $(liblumiera_la_srcdir)/query.cpp \ $(liblumiera_la_srcdir)/streamtype.cpp \ $(liblumiera_la_srcdir)/test/testoption.cpp \ + $(liblumiera_la_srcdir)/test/test-helper.cpp \ $(liblumiera_la_srcdir)/test/suite.cpp \ $(liblumiera_la_srcdir)/cmdline.cpp \ $(liblumiera_la_srcdir)/logging.cpp @@ -92,5 +93,6 @@ noinst_HEADERS += \ $(liblumiera_la_srcdir)/test/mockinjector.hpp \ $(liblumiera_la_srcdir)/test/suite.hpp \ $(liblumiera_la_srcdir)/test/testoption.hpp \ + $(liblumiera_la_srcdir)/test/test-helper.hpp \ $(liblumiera_la_srcdir)/test/run.hpp diff --git a/src/lib/test/test-helper.cpp b/src/lib/test/test-helper.cpp new file mode 100644 index 000000000..3e584bda0 --- /dev/null +++ b/src/lib/test/test-helper.cpp @@ -0,0 +1,46 @@ +/* + Test-Helper - collection of functions supporting unit testing + + Copyright (C) Lumiera.org + 2009, 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 "lib/test/test-helper.hpp" + +//#include "lib/error.hpp" +#include +#include + +using boost::format; +using boost::str; + +namespace lib { +namespace test{ + + + string + showSizeof (size_t siz, Symbol name) + { + static format fmt ("sizeof( %s ) %|30t|= %3d"); + return str (fmt % (name? name:"?") % siz); + } + + + +}} // namespace lib::test diff --git a/src/lib/test/test-helper.hpp b/src/lib/test/test-helper.hpp new file mode 100644 index 000000000..23c252148 --- /dev/null +++ b/src/lib/test/test-helper.hpp @@ -0,0 +1,101 @@ +/* + TEST-HELPER.hpp - collection of functions supporting unit testing + + Copyright (C) Lumiera.org + 2009, 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. + +*/ + + +#ifndef LIB_TEST_TESTHELPER_H +#define LIB_TEST_TESTHELPER_H + + +#include "include/symbol.hpp" + +#include +#include + + + +namespace lib { +namespace test{ + + using lumiera::Symbol; + using std::string; + + + + /** get a sensible display for a type or object + * @param obj object of the type in question + * @param name optional name to be used literally + * @return either the literal name without any further magic, + * or the result of compile-time or run time + * type identification as implemented by the compiler. + */ + template + const char* + showType (T const& obj, Symbol name=0) + { + return name? name : typeid(obj).name(); + } + + /** get a sensible display for a type + * @param name optional name to be used literally + * @return either the literal name without any further magic, + * or the result of compile-time or run time + * type identification as implemented by the compiler. + */ + template + const char* + showType (Symbol name=0) + { + return name? name : typeid(T).name(); + } + + + /** for printing sizeof(). + * prints the given size and name litterally, without any further magic */ + string + showSizeof (size_t siz, Symbol name); + + /** for printing sizeof(), trying to figure out the type name automatically */ + template + string + showSizeof(Symbol name=0) + { + return showSizeof (sizeof (T), showType (name)); + } + + template + string + showSizeof(T const& obj, Symbol name=0) + { + return showSizeof (sizeof (obj), showType (obj,name)); + } + + template + string + showSizeof(T *obj, Symbol name=0) + { + return obj? showSizeof (*obj, name) + : showSizeof (name); + } + + +}} // namespace lib::test +#endif diff --git a/tests/40components.tests b/tests/40components.tests index ea400e7f4..78ae76d6e 100644 --- a/tests/40components.tests +++ b/tests/40components.tests @@ -366,6 +366,12 @@ return: 0 END +TEST "Test support functions" TestHelper_test < Testgroup=ALL +END + + TEST "TestOption_test" TestOption_test < Testgroup=ALL diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index 7c9d41276..cea678415 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -69,6 +69,7 @@ test_lib_SOURCES = \ $(testlib_srcdir)/thread-wrapper-join-test.cpp \ $(testlib_srcdir)/test/cmdlinewrappertest.cpp \ $(testlib_srcdir)/test/testoptiontest.cpp \ + $(testlib_srcdir)/test/test-helper-test.cpp \ $(testlib_srcdir)/vectortransfertest.cpp \ $(testlib_srcdir)/visitingtoolconcept.cpp \ $(testlib_srcdir)/visitingtoolextendedtest.cpp \ diff --git a/tests/lib/test/test-helper-test.cpp b/tests/lib/test/test-helper-test.cpp new file mode 100644 index 000000000..1a9c8c1dd --- /dev/null +++ b/tests/lib/test/test-helper-test.cpp @@ -0,0 +1,97 @@ +/* + TestHelper(Test) - validate the unittest support functions + + 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 "lib/test/run.hpp" +#include "lib/test/test-helper.hpp" + +#include + +using std::cout; +using std::endl; + + +namespace lib { +namespace test{ +namespace test{ + + template + class Wrmrmpft + { + T tt_; + }; + + struct Murpf { }; + + + /************************************************* + * verifies the proper working of helper functions + * frequently used within the Lumiera testsuite. + * @see test-helper.hpp + */ + class TestHelper_test : public Test + { + void + run (Arg) + { + checkTypeDisplay(); + } + + + /** @test prints "sizeof()" including some type name. */ + void + checkTypeDisplay () + { + std::cout << "Displaying types and sizes....\n"; + + typedef Wrmrmpft Wrmpf1; + typedef Wrmrmpft Wrmpf2; + typedef Wrmrmpft Wrmpf3; + + Wrmpf1 rmpf1; + Wrmpf2 rmpf2; + Wrmpf3 rmpf3; + Murpf murpf; + + ASSERT (1 == sizeof (rmpf1)); + ASSERT (2 == sizeof (rmpf2)); + ASSERT (3 == sizeof (rmpf3)); + + cout << showSizeof(42,"theUniverse") << endl; + cout << showSizeof("just a char") << endl; + cout << showSizeof(murpf) << endl; + cout << showSizeof(rmpf1) << endl; + cout << showSizeof(rmpf2) << endl; + cout << showSizeof() << endl; + + Wrmpf1 *p1 = &rmpf1; + Wrmpf1 *p2 = 0; + cout << showSizeof(p1) << endl; + cout << showSizeof(p2) << endl; + } + }; + + LAUNCHER (TestHelper_test, "unit common"); + + +}}} // namespace lib::test::test +