[Wheat-cvs] r1/util test-test.cpp,1.11,1.12 test.cpp,1.17,1.18 test.h,1.14,1.15 testutil.cpp,1.11,1.
Status: Pre-Alpha
Brought to you by:
mark_lentczner
From: Jim K. <ki...@us...> - 2005-04-20 00:29:04
|
Update of /cvsroot/wheat/r1/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14242/util Modified Files: test-test.cpp test.cpp test.h testutil.cpp Log Message: Let test-test.cpp have its own test group, rather than having to use the global one ("airplanes" no longer shows up in the regular test run). Index: test.h =================================================================== RCS file: /cvsroot/wheat/r1/util/test.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- test.h 28 Feb 2005 07:54:20 -0000 1.14 +++ test.h 20 Apr 2005 00:28:35 -0000 1.15 @@ -48,9 +48,22 @@ }; +class test; +typedef tstrlist<test> TestList; + +struct TestGroup { + string name; + TestList list; + + TestGroup(const char* n) : name(n) { } +}; + +typedef tstrlist<TestGroup> TestGroupList; + + class ptpublic test : public unknown { public: - test(const char* group, const char* name, + test(TestGroupList& list, const char* group, const char* name, const char* built = __DATE__ " " __TIME__); virtual void run() = 0; @@ -117,9 +130,11 @@ }; +extern TestGroupList& registry(); + #define TEST(group, name) \ struct Test_##group##_##name : public pt::test { \ - Test_##group##_##name() : pt::test(#group, #name) { } \ + Test_##group##_##name() : pt::test(pt::registry(), #group, #name) { } \ void run(); \ } test_##group##_##name; \ void Test_##group##_##name::run() @@ -155,28 +170,10 @@ CHECK((ptr) != 0) - - -/* The following is for communication between test.cpp and test-test.cpp. - We perhaps should move it when we think of a better way to do this. */ - -typedef tstrlist<test> TestList; - -struct TestGroup { - string name; - TestList list; - - TestGroup(const char* n) : name(n) { } -}; - -typedef tstrlist<TestGroup> TestGroupList; - extern bool pt::runAll( outstm& out, TestGroupList& tests, bool reportPerGroup, bool stopOnFailingGroup); -/* End test.cpp/test-test.cpp section */ - PTYPES_END #endif // INCLUDED_TEST_H Index: test-test.cpp =================================================================== RCS file: /cvsroot/wheat/r1/util/test-test.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- test-test.cpp 28 Feb 2005 07:54:20 -0000 1.11 +++ test-test.cpp 20 Apr 2005 00:28:35 -0000 1.12 @@ -257,9 +257,10 @@ } } +static TestGroupList tests(SL_SORTED | SL_DUPLICATES); struct Test_airplanes_takeoff : test { Test_airplanes_takeoff() - : test("airplanes", "takeoff", "Apr 6 2005 18:43:31") { } + : test(tests, "airplanes", "takeoff", "Apr 6 2005 18:43:31") { } void run(); } test_airplanes_takeoff; void Test_airplanes_takeoff::run() @@ -272,12 +273,6 @@ pt::outmemory out; out.open(); - TestGroupList tests(SL_SORTED | SL_DUPLICATES); - TestGroup group("airplanes"); - const string key("20050406184331airplanes"); - int gindex = tests.add(key, &group); - tests[gindex]->list.add("takeoff", &test_airplanes_takeoff); - pt::runAll(out, tests, false, false); pt::string output = out.get_strdata(); Index: testutil.cpp =================================================================== RCS file: /cvsroot/wheat/r1/util/testutil.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- testutil.cpp 21 Feb 2005 07:40:44 -0000 1.11 +++ testutil.cpp 20 Apr 2005 00:28:35 -0000 1.12 @@ -116,7 +116,7 @@ const Path& package, const pt::string& name, const pt::string& method) - : pt::test(name, method, 0), + : pt::test(pt::registry(), name, method, 0), mPackage(package), mMethod(method) { } Index: test.cpp =================================================================== RCS file: /cvsroot/wheat/r1/util/test.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- test.cpp 28 Feb 2005 07:54:20 -0000 1.17 +++ test.cpp 20 Apr 2005 00:28:35 -0000 1.18 @@ -128,19 +128,20 @@ -static TestGroupList& -registry() +TestGroupList& +pt::registry() { - // Because this global is used in other global initializers, - // in particular test::test(), we must us this trick - // to ensure that it is constructed before used. - // See C++ FAQ Lite, sections 10.11 through 10.13 + /* This trick is to ensure that this global is constructed before + it is used. + See C++ FAQ Lite, sections 10.11 through 10.13 + */ static TestGroupList* r = new TestGroupList(SL_SORTED | SL_DUPLICATES); return *r; } -test::test(const char* group, const char* name, const char* built) +test::test(TestGroupList& list, const char* group, const char* name, + const char* built) { string key; struct tm timeInfo; @@ -156,12 +157,12 @@ key += group; - int gindex = registry().indexof(key); + int gindex = list.indexof(key); if (gindex < 0) { - gindex = registry().add(key, new TestGroup(group)); + gindex = list.add(key, new TestGroup(group)); } - registry()[gindex]->list.add(name, this); + list[gindex]->list.add(name, this); } static bool anyPasses; |