diff --git a/headers/tools/cppunit/TestShell.h b/headers/tools/cppunit/TestShell.h index 1f0cfcb270..10a5bb808f 100644 --- a/headers/tools/cppunit/TestShell.h +++ b/headers/tools/cppunit/TestShell.h @@ -83,11 +83,15 @@ public: static const char* GlobalTestDir() { return (fGlobalShell ? fGlobalShell->TestDir() : NULL); }; -protected: +protected: + typedef std::map TestMap; + typedef std::map SuiteMap; + VerbosityLevel fVerbosityLevel; std::set fTestsToRun; - std::map fTests; - std::map fSuites; + std::set fSuitesToRun; + TestMap fTests; + SuiteMap fSuites; std::set fLibDirs; CppUnit::TestResult fTestResults; CppUnit::TestResultCollector fResultsCollector; diff --git a/headers/tools/cppunit/TestUtils.h b/headers/tools/cppunit/TestUtils.h index 21cb0ae91a..05f6bf5f69 100644 --- a/headers/tools/cppunit/TestUtils.h +++ b/headers/tools/cppunit/TestUtils.h @@ -15,6 +15,9 @@ // use it inline in tests if necessary. status_t DecodeResult(status_t result); +// Returns a string version of the given integer +std::string IntToStr(int i); + // Calls system() with the concatenated string of command and parameter. void ExecCommand(const char *command, const char *parameter); diff --git a/headers/tools/cppunit/ThreadedTestCaller.h b/headers/tools/cppunit/ThreadedTestCaller.h index 10a963f323..090c77ae3f 100644 --- a/headers/tools/cppunit/ThreadedTestCaller.h +++ b/headers/tools/cppunit/ThreadedTestCaller.h @@ -176,10 +176,13 @@ BThreadedTestCaller::run(CppUnit::TestResult *resu // If we get this far, we actually managed to acquire the semaphore, // so we should release it now. release_sem_etc(fThreadSem, fThreads.size(), 0); + + // Print out a newline for asthetics :-) + printf("\n"); + /* - // Wait for them all to finish, then clean up for (ThreadManagerMap::iterator i = fThreads.begin(); i != fThreads.end (); @@ -254,7 +257,7 @@ BThreadedTestCaller::tearDown() { template std::string BThreadedTestCaller::toString() const { - return "BThreadedTestCaller for " + getName(); + return std::string("BThreadedTestCaller for ") + getName(); } #endif // _beos_threaded_test_caller_h_ diff --git a/src/tests/ExampleTest.cpp b/src/tests/ExampleTest.cpp index 421719f3a1..ea834bb09c 100644 --- a/src/tests/ExampleTest.cpp +++ b/src/tests/ExampleTest.cpp @@ -6,6 +6,7 @@ #include #include #include +#include ExampleTest::ExampleTest(std::string name) : BThreadedTestCase(name) @@ -33,6 +34,13 @@ ExampleTest::Suite() { caller->addThread("Thread3", &ExampleTest::TestFunc1); suite->addTest(caller); + // And one that fails, if you're so inclined + caller = new BThreadedTestCaller("ExampleTests::MultiThreaded Failing Test"); + caller->addThread("GoodThread1", &ExampleTest::TestFunc1); + caller->addThread("GoodThread2", &ExampleTest::TestFunc2); + caller->addThread("BadThread", &ExampleTest::FailureFunc); + suite->addTest(caller); + // And some single threaded ones suite->addTest(new CppUnit::TestCaller("ExampleTests::SingleThreaded Test #1", &ExampleTest::TestFunc1)); suite->addTest(new CppUnit::TestCaller("ExampleTests::SingleThreaded Test #2", &ExampleTest::TestFunc2)); @@ -81,3 +89,8 @@ ExampleTest::TestFunc3() { } } +void +ExampleTest::FailureFunc() { + CHK(true == false); +} + diff --git a/src/tests/ExampleTest.h b/src/tests/ExampleTest.h index 059ad22f90..a18c56fd2b 100644 --- a/src/tests/ExampleTest.h +++ b/src/tests/ExampleTest.h @@ -14,6 +14,7 @@ public: void TestFunc1(); // num += 10 void TestFunc2(); // num *= 2 void TestFunc3(); // num -= 5 + void FailureFunc(); // Fails assertion protected: BLocker *fLocker; int fNum; diff --git a/src/tests/UnitTester.cpp b/src/tests/UnitTester.cpp index 441fc09422..ecd503ae22 100644 --- a/src/tests/UnitTester.cpp +++ b/src/tests/UnitTester.cpp @@ -51,9 +51,9 @@ UnitTesterShell::PrintDescription(int argc, char *argv[]) { void UnitTesterShell::PrintValidArguments() { BTestShell::PrintValidArguments(); - cout << indent << "-obos Runs tests linked against our OpenBeOS libraries (*default*)" << endl; - cout << indent << "-r5 Runs tests linked against Be Inc.'s R5 libraries (instead" << endl; - cout << indent << " of our libraries) for the sake of comparison." << endl; + cout << indent << "-obos Runs tests linked against our OpenBeOS libraries (*default*)" << endl; + cout << indent << "-r5 Runs tests linked against Be Inc.'s R5 libraries (instead" << endl; + cout << indent << " of our libraries) for the sake of comparison." << endl; } bool diff --git a/src/tests/kits/support/Jamfile b/src/tests/kits/support/Jamfile index 0f1bb389df..1eb6a89213 100644 --- a/src/tests/kits/support/Jamfile +++ b/src/tests/kits/support/Jamfile @@ -1,15 +1,45 @@ SubDir OBOS_TOP src tests kits support ; +# Let Jam know where to find some of our source files +SEARCH_SOURCE += [ FDirName $(SUBDIR) barchivable ] ; +SEARCH_SOURCE += [ FDirName $(SUBDIR) bautolock ] ; +SEARCH_SOURCE += [ FDirName $(SUBDIR) blocker ] ; + CommonTestLib libsupporttest.so : SupportKitTestAddon.cpp + + # BArchivable + ArchivableTest.cpp + BArchivableTester.cpp + FindInstantiationFuncTester.cpp + InstantiateObjectTester.cpp + LocalTestObject.cpp + ValidateInstantiationTester.cpp + + # BAutolock + AutolockTest.cpp + AutolockLockerTest.cpp + AutolockLooperTest.cpp + + # BLocker (all in ./blocker) + LockerTest.cpp + BenaphoreLockCountTest1.cpp + ConcurrencyTest1.cpp + ConcurrencyTest2.cpp + ConstructionTest1.cpp + DestructionTest1.cpp + DestructionTest2.cpp + LockerTestCase.cpp + SemaphoreLockCountTest1.cpp + : libopenbeos.so be stdc++.r4 : be stdc++.r4 - : libsupporttest_blocker.so + : libsupporttest_RemoteTestObject.so : support ; -#SubInclude OBOS_TOP src tests kits support barchivable ; +SubInclude OBOS_TOP src tests kits support barchivable ; #SubInclude OBOS_TOP src tests kits support bautolock ; -SubInclude OBOS_TOP src tests kits support blocker ; +#SubInclude OBOS_TOP src tests kits support blocker ; diff --git a/src/tests/kits/support/SupportKitTestAddon.cpp b/src/tests/kits/support/SupportKitTestAddon.cpp index 0618045e5a..e4bcf21a66 100644 --- a/src/tests/kits/support/SupportKitTestAddon.cpp +++ b/src/tests/kits/support/SupportKitTestAddon.cpp @@ -2,12 +2,16 @@ #include // ##### Include headers for your tests here ##### +#include "barchivable/ArchivableTest.h" +#include "bautolock/AutolockTest.h" #include "blocker/LockerTest.h" BTestSuite* getTestSuite() { BTestSuite *suite = new BTestSuite("Support"); // ##### Add test suites here ##### + suite->addTest("BArchivable", ArchivableTestSuite()); + suite->addTest("BAutolock", AutolockTestSuite()); suite->addTest("BLocker", LockerTestSuite()); return suite; diff --git a/src/tests/kits/support/barchivable/ArchivableTest.cpp b/src/tests/kits/support/barchivable/ArchivableTest.cpp new file mode 100644 index 0000000000..8cd88cad57 --- /dev/null +++ b/src/tests/kits/support/barchivable/ArchivableTest.cpp @@ -0,0 +1,25 @@ +/* + $Id: +*/ + +#include "BArchivableTester.h" +#include "ValidateInstantiationTester.h" +#include "InstantiateObjectTester.h" +#include "FindInstantiationFuncTester.h" +#include "ArchivableTest.h" +#include "cppunit/Test.h" +#include "cppunit/TestSuite.h" + +CppUnit::Test* ArchivableTestSuite() +{ + CppUnit::TestSuite *testSuite = new CppUnit::TestSuite(); + + testSuite->addTest(TBArchivableTestCase::Suite()); + testSuite->addTest(TValidateInstantiationTest::Suite()); + testSuite->addTest(TInstantiateObjectTester::Suite()); + testSuite->addTest(TFindInstantiationFuncTester::Suite()); + + return testSuite; +} + + diff --git a/src/tests/kits/support/barchivable/ArchivableTest.h b/src/tests/kits/support/barchivable/ArchivableTest.h new file mode 100644 index 0000000000..b121221414 --- /dev/null +++ b/src/tests/kits/support/barchivable/ArchivableTest.h @@ -0,0 +1,9 @@ +#ifndef _archivable_test_file_h_ +#define _archivable_test_file_h_ + +class CppUnit::Test; + +CppUnit::Test* ArchivableTestSuite(); + +#endif // _locker_test_h_ + diff --git a/src/tests/kits/support/barchivable/BArchivableTester.cpp b/src/tests/kits/support/barchivable/BArchivableTester.cpp index e16601cc0f..c977c02904 100644 --- a/src/tests/kits/support/barchivable/BArchivableTester.cpp +++ b/src/tests/kits/support/barchivable/BArchivableTester.cpp @@ -34,7 +34,7 @@ void TBArchivableTestCase::TestPerform() { BArchivable Archive; - assert(Archive.Perform(0, NULL) == B_ERROR); + CPPUNIT_ASSERT(Archive.Perform(0, NULL) == B_ERROR); } //------------------------------------------------------------------------------ /** @@ -47,7 +47,7 @@ void TBArchivableTestCase::TestPerform() void TBArchivableTestCase::InvalidArchiveShallow() { BArchivable Archive; - assert(Archive.Archive(NULL, false) == B_BAD_VALUE); + CPPUNIT_ASSERT(Archive.Archive(NULL, false) == B_BAD_VALUE); } //------------------------------------------------------------------------------ /** @@ -63,10 +63,10 @@ void TBArchivableTestCase::ValidArchiveShallow() { BMessage Storage; BArchivable Archive; - assert(Archive.Archive(&Storage, false) == B_OK); + CPPUNIT_ASSERT(Archive.Archive(&Storage, false) == B_OK); const char* name; - assert(Storage.FindString("class", &name) == B_OK); - assert(strcmp(name, "BArchivable") == 0); + CPPUNIT_ASSERT(Storage.FindString("class", &name) == B_OK); + CPPUNIT_ASSERT(strcmp(name, "BArchivable") == 0); } //------------------------------------------------------------------------------ /** @@ -79,7 +79,7 @@ void TBArchivableTestCase::ValidArchiveShallow() void TBArchivableTestCase::InvalidArchiveDeep() { BArchivable Archive; - assert(Archive.Archive(NULL, true) == B_BAD_VALUE); + CPPUNIT_ASSERT(Archive.Archive(NULL, true) == B_BAD_VALUE); } //------------------------------------------------------------------------------ /** @@ -95,15 +95,15 @@ void TBArchivableTestCase::ValidArchiveDeep() { BMessage Storage; BArchivable Archive; - assert(Archive.Archive(&Storage, true) == B_OK); + CPPUNIT_ASSERT(Archive.Archive(&Storage, true) == B_OK); const char* name; - assert(Storage.FindString("class", &name) == B_OK); - assert(strcmp(name, "BArchivable") == 0); + CPPUNIT_ASSERT(Storage.FindString("class", &name) == B_OK); + CPPUNIT_ASSERT(strcmp(name, "BArchivable") == 0); } //------------------------------------------------------------------------------ -Test* TBArchivableTestCase::Suite() +CppUnit::Test* TBArchivableTestCase::Suite() { - TestSuite* SuiteOfTests = new TestSuite; + CppUnit::TestSuite* SuiteOfTests = new CppUnit::TestSuite; ADD_TEST(SuiteOfTests, TBArchivableTestCase, TestPerform); #if !defined(TEST_R5) ADD_TEST(SuiteOfTests, TBArchivableTestCase, InvalidArchiveShallow); @@ -126,3 +126,5 @@ Test* TBArchivableTestCase::Suite() * */ + + diff --git a/src/tests/kits/support/barchivable/BArchivableTester.h b/src/tests/kits/support/barchivable/BArchivableTester.h index 37c6128e2d..1ad921d20d 100644 --- a/src/tests/kits/support/barchivable/BArchivableTester.h +++ b/src/tests/kits/support/barchivable/BArchivableTester.h @@ -19,10 +19,10 @@ // Globals --------------------------------------------------------------------- -class TBArchivableTestCase : public TestCase +class TBArchivableTestCase : public BTestCase { public: - TBArchivableTestCase(std::string name) : TestCase(name) {;} + TBArchivableTestCase(std::string name = "") : BTestCase(name) {;} void TestPerform(); void InvalidArchiveShallow(); @@ -30,7 +30,7 @@ class TBArchivableTestCase : public TestCase void InvalidArchiveDeep(); void ValidArchiveDeep(); - static Test* Suite(); + static CppUnit::Test* Suite(); }; @@ -43,3 +43,4 @@ class TBArchivableTestCase : public TestCase * */ + diff --git a/src/tests/kits/support/barchivable/FindInstantiationFuncTester.cpp b/src/tests/kits/support/barchivable/FindInstantiationFuncTester.cpp index bfa54fa0d0..5d383e6de3 100644 --- a/src/tests/kits/support/barchivable/FindInstantiationFuncTester.cpp +++ b/src/tests/kits/support/barchivable/FindInstantiationFuncTester.cpp @@ -49,7 +49,7 @@ void TFindInstantiationFuncTester::Case1() { instantiation_func f = find_instantiation_func(NULL, NULL); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -62,7 +62,7 @@ void TFindInstantiationFuncTester::Case1() void TFindInstantiationFuncTester::Case2() { instantiation_func f = find_instantiation_func(gInvalidClassName, NULL); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -75,7 +75,7 @@ void TFindInstantiationFuncTester::Case2() void TFindInstantiationFuncTester::Case3() { instantiation_func f = find_instantiation_func(NULL, gInvalidSig); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -89,7 +89,7 @@ void TFindInstantiationFuncTester::Case4() { instantiation_func f = find_instantiation_func(gInvalidClassName, gInvalidSig); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -103,12 +103,12 @@ void TFindInstantiationFuncTester::Case4() void TFindInstantiationFuncTester::Case5() { instantiation_func f = find_instantiation_func(gLocalClassName, NULL); - assert(f != NULL); + CPPUNIT_ASSERT(f != NULL); BMessage Archive; Archive.AddString("class", gLocalClassName); TIOTest* Test = dynamic_cast(f(&Archive)); - assert(Test != NULL); + CPPUNIT_ASSERT(Test != NULL); } //------------------------------------------------------------------------------ /** @@ -122,7 +122,7 @@ void TFindInstantiationFuncTester::Case5() void TFindInstantiationFuncTester::Case6() { instantiation_func f = find_instantiation_func(gRemoteClassName, NULL); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -137,7 +137,7 @@ void TFindInstantiationFuncTester::Case7() { instantiation_func f = find_instantiation_func(gLocalClassName, gInvalidSig); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -152,7 +152,7 @@ void TFindInstantiationFuncTester::Case8() { instantiation_func f = find_instantiation_func(gRemoteClassName, gInvalidSig); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -169,7 +169,7 @@ void TFindInstantiationFuncTester::Case8() void TFindInstantiationFuncTester::Case9() { instantiation_func f = find_instantiation_func(gLocalClassName, gLocalSig); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -186,7 +186,7 @@ void TFindInstantiationFuncTester::Case10() { instantiation_func f = find_instantiation_func(gRemoteClassName, gRemoteSig); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -197,7 +197,7 @@ void TFindInstantiationFuncTester::Case10() void TFindInstantiationFuncTester::Case1M() { instantiation_func f = find_instantiation_func((BMessage*)NULL); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -212,7 +212,7 @@ void TFindInstantiationFuncTester::Case2M() BMessage Archive; Archive.AddString("class", gInvalidClassName); instantiation_func f = find_instantiation_func(&Archive); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -227,7 +227,7 @@ void TFindInstantiationFuncTester::Case3M() BMessage Archive; Archive.AddString("add_on", gInvalidSig); instantiation_func f = find_instantiation_func(&Archive); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -243,7 +243,7 @@ void TFindInstantiationFuncTester::Case4M() Archive.AddString("class", gInvalidClassName); Archive.AddString("add_on", gInvalidSig); instantiation_func f = find_instantiation_func(&Archive); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -260,10 +260,10 @@ void TFindInstantiationFuncTester::Case5M() Archive.AddString("class", gLocalClassName); instantiation_func f = find_instantiation_func(&Archive); - assert(f != NULL); + CPPUNIT_ASSERT(f != NULL); TIOTest* Test = dynamic_cast(f(&Archive)); - assert(Test != NULL); + CPPUNIT_ASSERT(Test != NULL); } //------------------------------------------------------------------------------ /** @@ -279,7 +279,7 @@ void TFindInstantiationFuncTester::Case6M() BMessage Archive; Archive.AddString("class", gRemoteClassName); instantiation_func f = find_instantiation_func(&Archive); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -296,7 +296,7 @@ void TFindInstantiationFuncTester::Case7M() Archive.AddString("class", gLocalClassName); Archive.AddString("add_on", gInvalidSig); instantiation_func f = find_instantiation_func(&Archive); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -313,7 +313,7 @@ void TFindInstantiationFuncTester::Case8M() Archive.AddString("class", gRemoteClassName); Archive.AddString("add_on", gInvalidSig); instantiation_func f = find_instantiation_func(&Archive); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -333,7 +333,7 @@ void TFindInstantiationFuncTester::Case9M() Archive.AddString("class", gLocalClassName); Archive.AddString("add_on", gLocalSig); instantiation_func f = find_instantiation_func(&Archive); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ /** @@ -352,12 +352,12 @@ void TFindInstantiationFuncTester::Case10M() Archive.AddString("class", gRemoteClassName); Archive.AddString("add_on", gRemoteSig); instantiation_func f = find_instantiation_func(&Archive); - assert(f == NULL); + CPPUNIT_ASSERT(f == NULL); } //------------------------------------------------------------------------------ -Test* TFindInstantiationFuncTester::Suite() +CppUnit::Test* TFindInstantiationFuncTester::Suite() { - TestSuite* SuiteOfTests = new TestSuite; + CppUnit::TestSuite* SuiteOfTests = new CppUnit::TestSuite; ADD_TEST(SuiteOfTests, TFindInstantiationFuncTester, Case1); ADD_TEST(SuiteOfTests, TFindInstantiationFuncTester, Case2); @@ -371,7 +371,7 @@ Test* TFindInstantiationFuncTester::Suite() ADD_TEST(SuiteOfTests, TFindInstantiationFuncTester, Case10); // BMessage using versions -#if !defined(SYSTEM_TEST) +#if !defined(TEST_R5) ADD_TEST(SuiteOfTests, TFindInstantiationFuncTester, Case1M); #endif ADD_TEST(SuiteOfTests, TFindInstantiationFuncTester, Case2M); @@ -395,3 +395,5 @@ Test* TFindInstantiationFuncTester::Suite() * */ + + diff --git a/src/tests/kits/support/barchivable/FindInstantiationFuncTester.h b/src/tests/kits/support/barchivable/FindInstantiationFuncTester.h index 0f125c51ef..3459eaffb9 100644 --- a/src/tests/kits/support/barchivable/FindInstantiationFuncTester.h +++ b/src/tests/kits/support/barchivable/FindInstantiationFuncTester.h @@ -19,10 +19,10 @@ // Globals --------------------------------------------------------------------- -class TFindInstantiationFuncTester : public TestCase +class TFindInstantiationFuncTester : public BTestCase { public: - TFindInstantiationFuncTester(std::string name) : TestCase(name) {;} + TFindInstantiationFuncTester(std::string name = "") : BTestCase(name) {;} void Case1(); void Case2(); @@ -47,7 +47,7 @@ class TFindInstantiationFuncTester : public TestCase void Case9M(); void Case10M(); - static Test* Suite(); + static CppUnit::Test* Suite(); }; #endif //FINDINSTATIATIONFUNCTESTER_H @@ -59,3 +59,4 @@ class TFindInstantiationFuncTester : public TestCase * */ + diff --git a/src/tests/kits/support/barchivable/InstantiateObjectTester.cpp b/src/tests/kits/support/barchivable/InstantiateObjectTester.cpp index ac1e070f79..865d91e691 100644 --- a/src/tests/kits/support/barchivable/InstantiateObjectTester.cpp +++ b/src/tests/kits/support/barchivable/InstantiateObjectTester.cpp @@ -22,10 +22,10 @@ #include // Project Includes ------------------------------------------------------------ +#include // Local Includes -------------------------------------------------------------- -#include "framework/estring.h" -#include "RemoteObjectDef/RemoteTestObject.h" +#include "remoteobjectdef/RemoteTestObject.h" #include "InstantiateObjectTester.h" #include "LocalTestObject.h" @@ -47,7 +47,7 @@ void FormatAndThrow(int line, const char* file, const char* msg, int err); //------------------------------------------------------------------------------ TInstantiateObjectTester::TInstantiateObjectTester(string name) - : TestCase(name), fAddonId(B_ERROR) + : BTestCase(name), fAddonId(B_ERROR) { ; } @@ -66,9 +66,9 @@ void TInstantiateObjectTester::Case1() errno = B_OK; image_id id = B_OK; TIOTest* Test = (TIOTest*)instantiate_object(NULL, &id); - assert(Test == NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_BAD_VALUE); + CPPUNIT_ASSERT(Test == NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_BAD_VALUE); } //------------------------------------------------------------------------------ /** @@ -86,9 +86,9 @@ void TInstantiateObjectTester::Case2() BMessage Archive; image_id id = B_OK; TIOTest* Test = (TIOTest*)instantiate_object(&Archive, &id); - assert(Test == NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_OK); + CPPUNIT_ASSERT(Test == NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_OK); } //------------------------------------------------------------------------------ @@ -112,9 +112,9 @@ void TInstantiateObjectTester::Case3() Archive.AddString("class", gInvalidClassName); image_id id = B_OK; TIOTest* Test = (TIOTest*)instantiate_object(&Archive, &id); - assert(Test == NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_BAD_VALUE); + CPPUNIT_ASSERT(Test == NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_BAD_VALUE); } //------------------------------------------------------------------------------ /** @@ -136,9 +136,9 @@ void TInstantiateObjectTester::Case4() Archive.AddString("add_on", gInvalidSig); image_id id = B_OK; TIOTest* Test = (TIOTest*)instantiate_object(&Archive, &id); - assert(Test == NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_LAUNCH_FAILED_APP_NOT_FOUND); + CPPUNIT_ASSERT(Test == NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_LAUNCH_FAILED_APP_NOT_FOUND); } //------------------------------------------------------------------------------ /** @@ -161,7 +161,7 @@ void TInstantiateObjectTester::Case5() Archive.AddString("add_on", gValidSig); image_id id = B_OK; TIOTest* Test = (TIOTest*)instantiate_object(&Archive, &id); - assert(Test == NULL); + CPPUNIT_ASSERT(Test == NULL); // The system implementation returns the image_id of the last addon searched // Implies the addon is not unloaded. How to verify this behaviour? Should // the addon be unloaded if it doesn't contain our function? Addons do, @@ -171,9 +171,9 @@ void TInstantiateObjectTester::Case5() // runs after this case without explicitely unloaded the addon here, it // fails because it depends on the addon image not being available within // the team. - assert(id > 0); + CPPUNIT_ASSERT(id > 0); unload_add_on(id); - assert(errno == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_BAD_VALUE); } //------------------------------------------------------------------------------ @@ -203,9 +203,9 @@ void TInstantiateObjectTester::Case6() Archive.AddString("class", gLocalClassName); image_id id = B_OK; TIOTest* Test = (TIOTest*)instantiate_object(&Archive, &id); - assert(Test != NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_OK); + CPPUNIT_ASSERT(Test != NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_OK); } //------------------------------------------------------------------------------ /** @@ -231,9 +231,9 @@ void TInstantiateObjectTester::Case7() image_id id = B_OK; TRemoteTestObject* Test = (TRemoteTestObject*)instantiate_object(&Archive, &id); - assert(Test != NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_OK); + CPPUNIT_ASSERT(Test != NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_OK); UnloadAddon(); } @@ -257,9 +257,9 @@ void TInstantiateObjectTester::Case8() image_id id = B_OK; TRemoteTestObject* Test = (TRemoteTestObject*)instantiate_object(&Archive, &id); - assert(Test == NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_BAD_VALUE); + CPPUNIT_ASSERT(Test == NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_BAD_VALUE); } //------------------------------------------------------------------------------ /** @@ -282,9 +282,9 @@ void TInstantiateObjectTester::Case9() Archive.AddString("add_on", gInvalidSig); image_id id = B_OK; TIOTest* Test = (TIOTest*)instantiate_object(&Archive, &id); - assert(Test == NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_LAUNCH_FAILED_APP_NOT_FOUND); + CPPUNIT_ASSERT(Test == NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_LAUNCH_FAILED_APP_NOT_FOUND); } //------------------------------------------------------------------------------ /** @@ -310,9 +310,9 @@ void TInstantiateObjectTester::Case10() Archive.AddString("add_on", gInvalidSig); image_id id = B_OK; TIOTest* Test = (TIOTest*)instantiate_object(&Archive, &id); - assert(Test == NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_LAUNCH_FAILED_APP_NOT_FOUND); + CPPUNIT_ASSERT(Test == NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_LAUNCH_FAILED_APP_NOT_FOUND); UnloadAddon(); } @@ -337,9 +337,9 @@ void TInstantiateObjectTester::Case11() Archive.AddString("add_on", gInvalidSig); image_id id = B_OK; TIOTest* Test = (TIOTest*)instantiate_object(&Archive, &id); - assert(Test == NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_LAUNCH_FAILED_APP_NOT_FOUND); + CPPUNIT_ASSERT(Test == NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_LAUNCH_FAILED_APP_NOT_FOUND); } //------------------------------------------------------------------------------ /** @@ -367,9 +367,9 @@ void TInstantiateObjectTester::Case12() Archive.AddString("add_on", GetLocalSignature().c_str()); image_id id = B_OK; TIOTest* Test = (TIOTest*)instantiate_object(&Archive, &id); - assert(Test != NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_OK); + CPPUNIT_ASSERT(Test != NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_OK); } //------------------------------------------------------------------------------ /** @@ -395,9 +395,9 @@ void TInstantiateObjectTester::Case13() Archive.AddString("add_on", gRemoteSig); image_id id = B_OK; TRemoteTestObject* Test = (TRemoteTestObject*)instantiate_object(&Archive, &id); - assert(Test != NULL); - assert(id == B_BAD_VALUE); - assert(errno == B_OK); + CPPUNIT_ASSERT(Test != NULL); + CPPUNIT_ASSERT(id == B_BAD_VALUE); + CPPUNIT_ASSERT(errno == B_OK); UnloadAddon(); } @@ -423,15 +423,15 @@ void TInstantiateObjectTester::Case14() Archive.AddString("add_on", gRemoteSig); image_id id = B_OK; TRemoteTestObject* Test = (TRemoteTestObject*)instantiate_object(&Archive, &id); - assert(Test != NULL); - assert(id > 0); + CPPUNIT_ASSERT(Test != NULL); + CPPUNIT_ASSERT(id > 0); unload_add_on(id); - assert(errno == B_OK); + CPPUNIT_ASSERT(errno == B_OK); } //------------------------------------------------------------------------------ -Test* TInstantiateObjectTester::Suite() +CppUnit::Test* TInstantiateObjectTester::Suite() { - TestSuite* SuiteOfTests = new TestSuite; + CppUnit::TestSuite* SuiteOfTests = new CppUnit::TestSuite; ADD_TEST(SuiteOfTests, TInstantiateObjectTester, Case1); ADD_TEST(SuiteOfTests, TInstantiateObjectTester, Case2); @@ -529,16 +529,16 @@ std::string TInstantiateObjectTester::GetLocalSignature() //------------------------------------------------------------------------------ void FormatAndThrow(int line, const char *file, const char *msg, int err) { - string s("line: "); - s += estring(line); + std::string s("line: "); + s += IntToStr(line); s += " "; s += file; s += msg; s += strerror(err); s += "("; - s += estring(err); + s += IntToStr(err); s += ")"; - std::runtime_error re(s.c_str()); + CppUnit::Exception re(s.c_str()); throw re; } //------------------------------------------------------------------------------ @@ -550,3 +550,4 @@ void FormatAndThrow(int line, const char *file, const char *msg, int err) * */ + diff --git a/src/tests/kits/support/barchivable/InstantiateObjectTester.h b/src/tests/kits/support/barchivable/InstantiateObjectTester.h index b1621b2363..ef7e93b19f 100644 --- a/src/tests/kits/support/barchivable/InstantiateObjectTester.h +++ b/src/tests/kits/support/barchivable/InstantiateObjectTester.h @@ -20,10 +20,10 @@ // Globals --------------------------------------------------------------------- //------------------------------------------------------------------------------ -class TInstantiateObjectTester : public TestCase +class TInstantiateObjectTester : public BTestCase { public: - TInstantiateObjectTester(std::string name); + TInstantiateObjectTester(std::string name = ""); void Case1(); void Case2(); @@ -40,7 +40,7 @@ class TInstantiateObjectTester : public TestCase void Case13(); void Case14(); - static Test* Suite(); + static CppUnit::Test* Suite(); private: void LoadAddon(); @@ -60,3 +60,4 @@ class TInstantiateObjectTester : public TestCase * */ + diff --git a/src/tests/kits/support/barchivable/Jamfile b/src/tests/kits/support/barchivable/Jamfile new file mode 100644 index 0000000000..229076b5d7 --- /dev/null +++ b/src/tests/kits/support/barchivable/Jamfile @@ -0,0 +1,3 @@ +SubDir OBOS_TOP src tests kits support barchivable ; + +SubInclude OBOS_TOP src tests kits support barchivable remoteobjectdef ; diff --git a/src/tests/kits/support/barchivable/LocalCommon.h b/src/tests/kits/support/barchivable/LocalCommon.h index ddefea7970..cde44b3751 100644 --- a/src/tests/kits/support/barchivable/LocalCommon.h +++ b/src/tests/kits/support/barchivable/LocalCommon.h @@ -7,15 +7,14 @@ #define LOCALCOMMON_H // Standard Includes ----------------------------------------------------------- +#include // System Includes ------------------------------------------------------------- -#ifdef TEST_R5 -#include -#else -#include "Archivable.h" -#endif +#include // Project Includes ------------------------------------------------------------ +#include +#include // Local Includes -------------------------------------------------------------- #include "common.h" @@ -41,3 +40,5 @@ extern const char* gValidSig; * */ + + diff --git a/src/tests/kits/support/barchivable/LocalTestObject.cpp b/src/tests/kits/support/barchivable/LocalTestObject.cpp index fb5d3d1aac..9823ade3ce 100644 --- a/src/tests/kits/support/barchivable/LocalTestObject.cpp +++ b/src/tests/kits/support/barchivable/LocalTestObject.cpp @@ -54,3 +54,5 @@ TIOTest* TIOTest::Instantiate(BMessage *archive) * */ + + diff --git a/src/tests/kits/support/barchivable/LocalTestObject.h b/src/tests/kits/support/barchivable/LocalTestObject.h index c751206c63..a7aefb90c4 100644 --- a/src/tests/kits/support/barchivable/LocalTestObject.h +++ b/src/tests/kits/support/barchivable/LocalTestObject.h @@ -9,12 +9,8 @@ // Standard Includes ----------------------------------------------------------- // System Includes ------------------------------------------------------------- -#include -#ifdef SYSTEM_TEST -#include -#else -#include "../../../../source/lib/support/headers/Archivable.h" -#endif +#include +#include // Project Includes ------------------------------------------------------------ @@ -48,3 +44,4 @@ class TIOTest : public BArchivable * */ + diff --git a/src/tests/kits/support/barchivable/ValidateInstantiationTester.cpp b/src/tests/kits/support/barchivable/ValidateInstantiationTester.cpp index b066858efd..e26ae9c4e6 100644 --- a/src/tests/kits/support/barchivable/ValidateInstantiationTester.cpp +++ b/src/tests/kits/support/barchivable/ValidateInstantiationTester.cpp @@ -38,8 +38,8 @@ const char* gBogusClassName = "BarFoo"; void TValidateInstantiationTest::AllParamsInvalid() { errno = B_OK; - assert(!validate_instantiation(NULL, NULL)); - assert(errno == B_BAD_VALUE); + CPPUNIT_ASSERT(!validate_instantiation(NULL, NULL)); + CPPUNIT_ASSERT(errno == B_BAD_VALUE); } //------------------------------------------------------------------------------ /** @@ -54,8 +54,8 @@ void TValidateInstantiationTest::ClassNameParamInvalid() { errno = B_OK; BMessage Archive; - assert(!validate_instantiation(&Archive, NULL)); - assert(errno == B_MISMATCHED_VALUES); + CPPUNIT_ASSERT(!validate_instantiation(&Archive, NULL)); + CPPUNIT_ASSERT(errno == B_MISMATCHED_VALUES); } //------------------------------------------------------------------------------ /** @@ -72,8 +72,8 @@ void TValidateInstantiationTest::ClassNameParamInvalid() void TValidateInstantiationTest::ArchiveParamInvalid() { errno = B_OK; - assert(!validate_instantiation(NULL, gClassName)); - assert(errno == B_BAD_VALUE); + CPPUNIT_ASSERT(!validate_instantiation(NULL, gClassName)); + CPPUNIT_ASSERT(errno == B_BAD_VALUE); } //------------------------------------------------------------------------------ /** @@ -89,8 +89,8 @@ void TValidateInstantiationTest::ClassFieldEmpty() { errno = B_OK; BMessage Archive; - assert(!validate_instantiation(&Archive, gClassName)); - assert(errno == B_MISMATCHED_VALUES); + CPPUNIT_ASSERT(!validate_instantiation(&Archive, gClassName)); + CPPUNIT_ASSERT(errno == B_MISMATCHED_VALUES); } //------------------------------------------------------------------------------ /** @@ -108,8 +108,8 @@ void TValidateInstantiationTest::ClassFieldBogus() errno = B_OK; BMessage Archive; Archive.AddString("class", gClassName); - assert(!validate_instantiation(&Archive, gBogusClassName)); - assert(errno == B_MISMATCHED_VALUES); + CPPUNIT_ASSERT(!validate_instantiation(&Archive, gBogusClassName)); + CPPUNIT_ASSERT(errno == B_MISMATCHED_VALUES); } //------------------------------------------------------------------------------ /** @@ -127,13 +127,13 @@ void TValidateInstantiationTest::AllValid() errno = B_OK; BMessage Archive; Archive.AddString("class", gClassName); - assert(validate_instantiation(&Archive, gClassName)); - assert(errno == B_OK); + CPPUNIT_ASSERT(validate_instantiation(&Archive, gClassName)); + CPPUNIT_ASSERT(errno == B_OK); } //------------------------------------------------------------------------------ -Test* TValidateInstantiationTest::Suite() +CppUnit::Test* TValidateInstantiationTest::Suite() { - TestSuite* SuiteOfTests = new TestSuite; + CppUnit::TestSuite* SuiteOfTests = new CppUnit::TestSuite; #if !defined(TEST_R5) ADD_TEST(SuiteOfTests, TValidateInstantiationTest, AllParamsInvalid); #endif @@ -156,3 +156,5 @@ Test* TValidateInstantiationTest::Suite() * */ + + diff --git a/src/tests/kits/support/barchivable/ValidateInstantiationTester.h b/src/tests/kits/support/barchivable/ValidateInstantiationTester.h index 07ccd1b732..060dfc96f7 100644 --- a/src/tests/kits/support/barchivable/ValidateInstantiationTester.h +++ b/src/tests/kits/support/barchivable/ValidateInstantiationTester.h @@ -20,10 +20,10 @@ // Globals --------------------------------------------------------------------- //------------------------------------------------------------------------------ -class TValidateInstantiationTest : public TestCase +class TValidateInstantiationTest : public BTestCase { public: - TValidateInstantiationTest(std::string name) : TestCase(name) {;} + TValidateInstantiationTest(std::string name = "") : BTestCase(name) {;} void AllParamsInvalid(); void ClassNameParamInvalid(); @@ -32,7 +32,7 @@ class TValidateInstantiationTest : public TestCase void ClassFieldBogus(); void AllValid(); - static Test* Suite(); + static CppUnit::Test* Suite(); }; //------------------------------------------------------------------------------ @@ -46,3 +46,4 @@ class TValidateInstantiationTest : public TestCase * */ + diff --git a/src/tests/kits/support/barchivable/common.h b/src/tests/kits/support/barchivable/common.h new file mode 100644 index 0000000000..c73d500024 --- /dev/null +++ b/src/tests/kits/support/barchivable/common.h @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ + +#ifndef COMMON_H +#define COMMON_H + +// Standard Includes ----------------------------------------------------------- +#include +#include + +// System Includes ------------------------------------------------------------- + +// Project Includes ------------------------------------------------------------ +#include "cppunit/TestCaller.h" +#include "TestCase.h" +//#include "TestResult.h" +#include "cppunit/TestSuite.h" + +// Local Includes -------------------------------------------------------------- + +// Local Defines --------------------------------------------------------------- +#define assert_err(condition) \ + (this->assertImplementation ((condition), std::string((#condition)) + \ + strerror(condition),\ + __LINE__, __FILE__)) + +#define ADD_TEST(suitename, classname, funcname) \ + (suitename)->addTest(new CppUnit::TestCaller(std::string("BArchivable::") + \ + std::string((#funcname)), &classname::funcname)); + +#define CHECK_ERRNO \ + cout << endl << "errno == \"" << strerror(errno) << "\" (" << errno \ + << ") in " << __PRETTY_FUNCTION__ << endl + +#define CHECK_STATUS(status__) \ + cout << endl << "status_t == \"" << strerror((status__)) << "\" (" \ + << (status__) << ") in " << __PRETTY_FUNCTION__ << endl + +// Globals --------------------------------------------------------------------- + + +#endif //COMMON_H + +/* + * $Log $ + * + * $Id $ + * + */ + diff --git a/src/tests/kits/support/barchivable/remoteobjectdef/Jamfile b/src/tests/kits/support/barchivable/remoteobjectdef/Jamfile index e669a28b14..9351e37e54 100644 --- a/src/tests/kits/support/barchivable/remoteobjectdef/Jamfile +++ b/src/tests/kits/support/barchivable/remoteobjectdef/Jamfile @@ -1,10 +1,15 @@ SubDir OBOS_TOP src tests kits support barchivable remoteobjectdef ; -CommonUnitTest RemoteTestObject +CommonTestLib libsupporttest_RemoteTestObject.so : RemoteTestObject.cpp - : kits support : libopenbeos.so be stdc++.r4 : be stdc++.r4 + : : support + : Resource.rsrc ; +# Add the libraries' resource files. If this sort of thing is needed +# anywhere else, we ought to make it into a real rule. +AddResources libsupporttest_RemoteTestObject.so : Resource.rsrc ; +AddResources libsupporttest_RemoteTestObject_r5.so : Resource.rsrc ; diff --git a/src/tests/kits/support/bautolock/AutolockLockerTest.cpp b/src/tests/kits/support/bautolock/AutolockLockerTest.cpp index edc88e3b08..837c885439 100644 --- a/src/tests/kits/support/bautolock/AutolockLockerTest.cpp +++ b/src/tests/kits/support/bautolock/AutolockLockerTest.cpp @@ -1,5 +1,5 @@ /* - $Id: AutolockLockerTest.cpp,v 1.1 2002/07/09 12:24:57 ejakowatz Exp $ + $Id: AutolockLockerTest.cpp,v 1.2 2002/07/19 06:45:28 tylerdauwalder Exp $ This file tests all use cases of the BAutolock when used with a BLocker. BLooper based tests are done seperately. @@ -7,9 +7,9 @@ */ +#include "ThreadedTestCaller.h" #include "AutolockLockerTest.h" -#include -#include "Autolock.h" +#include #include @@ -17,26 +17,26 @@ const bigtime_t SNOOZE_TIME = 250000; /* - * Method: AutolockLockerTest::AutolockLockerTest() + * Method: AutolockLockerTest::AutolockLockerTest() * Descr: This method is the only constructor for the AutolockLockerTest * class. */ -template - AutolockLockerTest::AutolockLockerTest(std::string name) : - TestCase(name), theLocker(new Locker) + + AutolockLockerTest::AutolockLockerTest(std::string name) : + BThreadedTestCase(name), theLocker(new BLocker) { } /* - * Method: AutolockLockerTest::~AutolockLockerTest() + * Method: AutolockLockerTest::~AutolockLockerTest() * Descr: This method is the destructor for the AutolockLockerTest class. * It only deallocates the autolocker and locker. */ -template - AutolockLockerTest::~AutolockLockerTest() + + AutolockLockerTest::~AutolockLockerTest() { delete theLocker; theLocker = NULL; @@ -44,7 +44,7 @@ template /* - * Method: AutolockLockerTest::TestThread1() + * Method: AutolockLockerTest::TestThread1() * Descr: This method performs the tests on the Autolock. It first acquires the * lock and sleeps for a short time. It deletes the lock rather than Unlock() * it in order to test the other two threads. Then, it constructs a new @@ -54,91 +54,100 @@ template * constructed by passing a reference to the Locker. */ -template - void AutolockLockerTest::TestThread1(void) + + void AutolockLockerTest::TestThread1(void) { - Autolock *theAutolock; + BAutolock *theAutolock; - assert(theLocker->Lock()); - assert(theLocker->LockingThread() == find_thread(NULL)); + NextSubTest(); + CPPUNIT_ASSERT(theLocker->Lock()); + CPPUNIT_ASSERT(theLocker->LockingThread() == find_thread(NULL)); snooze(SNOOZE_TIME); delete theLocker; - theLocker = new Locker; - theAutolock = new Autolock(theLocker); + NextSubTest(); + theLocker = new BLocker; + theAutolock = new BAutolock(theLocker); - assert(theLocker->IsLocked()); - assert(theLocker->LockingThread() == find_thread(NULL)); - assert(theAutolock->IsLocked()); + CPPUNIT_ASSERT(theLocker->IsLocked()); + CPPUNIT_ASSERT(theLocker->LockingThread() == find_thread(NULL)); + CPPUNIT_ASSERT(theAutolock->IsLocked()); + NextSubTest(); delete theAutolock; theAutolock = NULL; - assert(theLocker->LockingThread() != find_thread(NULL)); + CPPUNIT_ASSERT(theLocker->LockingThread() != find_thread(NULL)); - theAutolock = new Autolock(*theLocker); - assert(theLocker->IsLocked()); - assert(theLocker->LockingThread() == find_thread(NULL)); - assert(theAutolock->IsLocked()); + NextSubTest(); + theAutolock = new BAutolock(*theLocker); + CPPUNIT_ASSERT(theLocker->IsLocked()); + CPPUNIT_ASSERT(theLocker->LockingThread() == find_thread(NULL)); + CPPUNIT_ASSERT(theAutolock->IsLocked()); + NextSubTest(); delete theAutolock; theAutolock = NULL; - assert(theLocker->LockingThread() != find_thread(NULL)); + CPPUNIT_ASSERT(theLocker->LockingThread() != find_thread(NULL)); } /* - * Method: AutolockLockerTest::TestThread2() + * Method: AutolockLockerTest::TestThread2() * Descr: This method performs the tests on the Autolock. It first sleeps for a short * time and then tries to acquire the lock with an Autolock. It passes a pointer * to the lock to the Autolock. It expects the acquisition to fail and IsLocked() * is tested to be sure. */ -template - void AutolockLockerTest::TestThread2(void) + + void AutolockLockerTest::TestThread2(void) { + NextSubTest(); snooze(SNOOZE_TIME / 10); - Autolock theAutolock(theLocker); - assert(!theAutolock.IsLocked()); + BAutolock theAutolock(theLocker); + CPPUNIT_ASSERT(!theAutolock.IsLocked()); } /* - * Method: AutolockLockerTest::TestThread3() + * Method: AutolockLockerTest::TestThread3() * Descr: This method performs the tests on the Autolock. It first sleeps for a short * time and then tries to acquire the lock with an Autolock. It passes a reference * to the lock to the Autolock. It expects the acquisition to fail and IsLocked() * is tested to be sure. */ -template - void AutolockLockerTest::TestThread3(void) + + void AutolockLockerTest::TestThread3(void) { + NextSubTest(); snooze(SNOOZE_TIME / 10); - Autolock theAutolock(*theLocker); - assert(!theAutolock.IsLocked()); + BAutolock theAutolock(*theLocker); + CPPUNIT_ASSERT(!theAutolock.IsLocked()); } /* - * Method: AutolockLockerTest::suite() + * Method: AutolockLockerTest::suite() * Descr: This static member function returns a test caller for performing * the "AutolockLockerTest" test. The test caller * is created as a ThreadedTestCaller (typedef'd as * BenaphoreLockCountTest1Caller) with three independent threads. */ -template - Test *AutolockLockerTest::suite(void) + +CppUnit::Test *AutolockLockerTest::suite(void) { - AutolockLockerTest *theTest = new AutolockLockerTest(""); - AutolockLockerTestCaller *threadedTest = new AutolockLockerTestCaller("", theTest); - threadedTest->addThread(":Thread1", &AutolockLockerTest::TestThread1); - threadedTest->addThread(":Thread2", &AutolockLockerTest::TestThread2); - threadedTest->addThread(":Thread3", &AutolockLockerTest::TestThread3); + typedef BThreadedTestCaller + AutolockLockerTestCaller; + + AutolockLockerTest *theTest = new AutolockLockerTest(""); + AutolockLockerTestCaller *threadedTest = new AutolockLockerTestCaller("BAutolock::Locker Test", theTest); + threadedTest->addThread("A", &AutolockLockerTest::TestThread1); + threadedTest->addThread("B", &AutolockLockerTest::TestThread2); + threadedTest->addThread("C", &AutolockLockerTest::TestThread3); return(threadedTest); - } - - -template class AutolockLockerTest; -template class AutolockLockerTest; \ No newline at end of file +} + + + diff --git a/src/tests/kits/support/bautolock/AutolockLockerTest.h b/src/tests/kits/support/bautolock/AutolockLockerTest.h index 6356814299..dcb28d8ff7 100644 --- a/src/tests/kits/support/bautolock/AutolockLockerTest.h +++ b/src/tests/kits/support/bautolock/AutolockLockerTest.h @@ -1,5 +1,5 @@ /* - $Id: AutolockLockerTest.h,v 1.1 2002/07/09 12:24:57 ejakowatz Exp $ + $Id: AutolockLockerTest.h,v 1.2 2002/07/19 06:45:28 tylerdauwalder Exp $ This file defines the class for performing all BAutolock tests on a BLocker. @@ -10,25 +10,28 @@ #ifndef AutolockLockerTest_H #define AutolockLockerTest_H +#include "ThreadedTestCase.h" +#include -#include "ThreadedTestCaller.h" -#include "TestCase.h" +class BLocker; +class CppUnit::Test; -template class AutolockLockerTest : public TestCase { +class AutolockLockerTest : public BThreadedTestCase { private: - typedef ThreadedTestCaller > - AutolockLockerTestCaller; - - Locker *theLocker; + BLocker *theLocker; public: - static Test *suite(void); + static CppUnit::Test *suite(void); void TestThread1(void); void TestThread2(void); void TestThread3(void); AutolockLockerTest(std::string); virtual ~AutolockLockerTest(); - }; +}; -#endif \ No newline at end of file +#endif + + + + diff --git a/src/tests/kits/support/bautolock/AutolockLooperTest.cpp b/src/tests/kits/support/bautolock/AutolockLooperTest.cpp index 6430c20743..4d76072b56 100644 --- a/src/tests/kits/support/bautolock/AutolockLooperTest.cpp +++ b/src/tests/kits/support/bautolock/AutolockLooperTest.cpp @@ -1,5 +1,5 @@ /* - $Id: AutolockLooperTest.cpp,v 1.1 2002/07/09 12:24:57 ejakowatz Exp $ + $Id: AutolockLooperTest.cpp,v 1.2 2002/07/19 06:45:28 tylerdauwalder Exp $ This file tests all use cases of the BAutolock when used with a BLooper. BLocker based tests are done seperately. @@ -7,9 +7,10 @@ */ +#include "ThreadedTestCaller.h" #include "AutolockLooperTest.h" -#include -#include "Autolock.h" +#include +#include #include @@ -17,27 +18,27 @@ const bigtime_t SNOOZE_TIME = 250000; /* - * Method: AutolockLooperTest::AutolockLooperTest() + * Method: AutolockLooperTest::AutolockLooperTest() * Descr: This method is the only constructor for the AutolockLooperTest * class. */ -template - AutolockLooperTest::AutolockLooperTest(std::string name) : - TestCase(name), theLooper(new Looper) + + AutolockLooperTest::AutolockLooperTest(std::string name) : + BThreadedTestCase(name), theLooper(new BLooper) { theLooper->Run(); } /* - * Method: AutolockLooperTest::~AutolockLooperTest() + * Method: AutolockLooperTest::~AutolockLooperTest() * Descr: This method is the destructor for the AutolockLooperTest class. * It only deallocates the autoLooper and Looper. */ -template - AutolockLooperTest::~AutolockLooperTest() + + AutolockLooperTest::~AutolockLooperTest() { if (theLooper != NULL) theLooper->Lock(); @@ -46,45 +47,50 @@ template /* - * Method: AutolockLooperTest::TestThread1() + * Method: AutolockLooperTest::TestThread1() * Descr: This method performs the tests on the Autolock. It constructs a new * Autolock and checks that both the Autolock and the Looper are * both locked. Then, the Autolock is released by deleting it. The Looper * is checked to see that it is now released. */ -template - void AutolockLooperTest::TestThread1(void) -{ - Autolock *theAutolock = new Autolock(theLooper); - assert(theLooper->IsLocked()); - assert(theLooper->LockingThread() == find_thread(NULL)); - assert(theAutolock->IsLocked()); + void AutolockLooperTest::TestThread1(void) +{ + BAutolock *theAutolock = new BAutolock(theLooper); + + NextSubTest(); + CPPUNIT_ASSERT(theLooper->IsLocked()); + CPPUNIT_ASSERT(theLooper->LockingThread() == find_thread(NULL)); + CPPUNIT_ASSERT(theAutolock->IsLocked()); + NextSubTest(); delete theAutolock; theAutolock = NULL; - assert(theLooper->LockingThread() != find_thread(NULL)); + CPPUNIT_ASSERT(theLooper->LockingThread() != find_thread(NULL)); } /* - * Method: AutolockLooperTest::suite() + * Method: AutolockLooperTest::suite() * Descr: This static member function returns a test caller for performing * the "AutolockLooperTest" test. The test caller * is created as a ThreadedTestCaller (typedef'd as * BenaphoreLockCountTest1Caller) with three independent threads. */ -template - Test *AutolockLooperTest::suite(void) + +CppUnit::Test *AutolockLooperTest::suite(void) { - AutolockLooperTest *theTest = new AutolockLooperTest(""); - AutolockLooperTestCaller *threadedTest = new AutolockLooperTestCaller("", theTest); - threadedTest->addThread(":Thread1", &AutolockLooperTest::TestThread1); + typedef BThreadedTestCaller + AutolockLooperTestCaller; + + AutolockLooperTest *theTest = new AutolockLooperTest(""); + AutolockLooperTestCaller *threadedTest = new AutolockLooperTestCaller("BAutolock::Looper Test", theTest); + threadedTest->addThread("A", &AutolockLooperTest::TestThread1); return(threadedTest); - } - - -template class AutolockLooperTest; -template class AutolockLooperTest; \ No newline at end of file +} + + + + diff --git a/src/tests/kits/support/bautolock/AutolockLooperTest.h b/src/tests/kits/support/bautolock/AutolockLooperTest.h index 899a8f78ee..fddb60ba72 100644 --- a/src/tests/kits/support/bautolock/AutolockLooperTest.h +++ b/src/tests/kits/support/bautolock/AutolockLooperTest.h @@ -1,5 +1,5 @@ /* - $Id: AutolockLooperTest.h,v 1.1 2002/07/09 12:24:57 ejakowatz Exp $ + $Id: AutolockLooperTest.h,v 1.2 2002/07/19 06:45:28 tylerdauwalder Exp $ This file defines the class for performing all BAutolock tests on a BLooper. @@ -11,22 +11,26 @@ #define AutolockLooperTest_H -#include "ThreadedTestCaller.h" -#include "TestCase.h" +#include "ThreadedTestCase.h" +#include -template class AutolockLooperTest : public TestCase { +class BLooper; +class CppUnit::Test; + +class AutolockLooperTest : public BThreadedTestCase { private: - typedef ThreadedTestCaller > - AutolockLooperTestCaller; - - Looper *theLooper; + BLooper *theLooper; public: static Test *suite(void); void TestThread1(void); AutolockLooperTest(std::string); virtual ~AutolockLooperTest(); - }; +}; -#endif \ No newline at end of file +#endif + + + + diff --git a/src/tests/kits/support/bautolock/AutolockTest.cpp b/src/tests/kits/support/bautolock/AutolockTest.cpp new file mode 100644 index 0000000000..ba3b7978eb --- /dev/null +++ b/src/tests/kits/support/bautolock/AutolockTest.cpp @@ -0,0 +1,19 @@ +/* + $Id: +*/ + +#include "AutolockLockerTest.h" +#include "AutolockLooperTest.h" +#include "cppunit/Test.h" +#include "cppunit/TestSuite.h" + +CppUnit::Test* AutolockTestSuite() +{ + CppUnit::TestSuite *testSuite = new CppUnit::TestSuite(); + + testSuite->addTest(AutolockLockerTest::suite()); + testSuite->addTest(AutolockLooperTest::suite()); + + return testSuite; +} + diff --git a/src/tests/kits/support/bautolock/AutolockTest.h b/src/tests/kits/support/bautolock/AutolockTest.h new file mode 100644 index 0000000000..169d72cdfc --- /dev/null +++ b/src/tests/kits/support/bautolock/AutolockTest.h @@ -0,0 +1,8 @@ +#ifndef _autolock_test_h_ +#define _autolock_test_h_ + +class CppUnit::Test; + +CppUnit::Test* AutolockTestSuite(); + +#endif // _autolock_test_h_ diff --git a/src/tools/cppunit/TestCase.cpp b/src/tools/cppunit/TestCase.cpp index bcdb179647..2b9a52082f 100644 --- a/src/tools/cppunit/TestCase.cpp +++ b/src/tools/cppunit/TestCase.cpp @@ -13,7 +13,8 @@ BTestCase::BTestCase(std::string name) void BTestCase::tearDown() { - NextSubTestBlock(); + if (fSubTestNum != 0) + NextSubTestBlock(); } void diff --git a/src/tools/cppunit/TestListener.cpp b/src/tools/cppunit/TestListener.cpp index a3b5a0e6e6..08584ff6f9 100644 --- a/src/tools/cppunit/TestListener.cpp +++ b/src/tools/cppunit/TestListener.cpp @@ -27,7 +27,7 @@ void BTestListener::endTest( CppUnit::Test *test ) { if (fOkay) cout << " + PASSED" << endl; - else - cout << " - FAILED" << endl; +// else +// cout << " - FAILED" << endl; cout << endl; } diff --git a/src/tools/cppunit/TestShell.cpp b/src/tools/cppunit/TestShell.cpp index 0ee15ccd91..142e0763a7 100644 --- a/src/tools/cppunit/TestShell.cpp +++ b/src/tools/cppunit/TestShell.cpp @@ -42,8 +42,8 @@ BTestShell::AddSuite(BTestSuite *suite) { fSuites[suite->getName()] = suite; // Add its tests - const std::map &map = suite->getTests(); - for (std::map::const_iterator i = map.begin(); + const TestMap &map = suite->getTests(); + for (TestMap::const_iterator i = map.begin(); i != map.end(); i++) AddTest(i->first, i->second); @@ -127,16 +127,39 @@ BTestShell::Run(int argc, char *argv[]) { cout << "ERROR: No installed tests to run!" << endl; return 0; - } else if (fTestsToRun.empty()) { + } else if (fSuitesToRun.empty() && fTestsToRun.empty()) { // None specified, so run them all - std::map::iterator i; + TestMap::iterator i; for (i = fTests.begin(); i != fTests.end(); ++i) suite.addTest( i->second ); - } else { - // One or more specified, so only run those + } else { std::set::const_iterator i; + std::set suitesToRemove; + + // Add all the tests from any specified suites to the list of + // tests to run (since we use a set, this eliminates the concern + // of having duplicate entries). + for (i = fTestsToRun.begin(); i != fTestsToRun.end(); ++i) { + // See if it's a suite (since it may just be a single test) + if (fSuites.find(*i) != fSuites.end()) { + suitesToRemove.insert(*i); // Note the suite name for later + const TestMap &tests = fSuites[*i]->getTests(); + TestMap::const_iterator j; + for (j = tests.begin(); j != tests.end(); j++) { + fTestsToRun.insert( j->first ); + } + } + } + + // Remove the names of all of the suites we discovered from the + // list of tests to run + for (i = suitesToRemove.begin(); i != suitesToRemove.end(); i++) { + fTestsToRun.erase(*i); + } + + // Everything still in fTestsToRun must then be an explicit test for (i = fTestsToRun.begin(); i != fTestsToRun.end(); ++i) { // Make sure it's a valid test if (fTests.find(*i) != fTests.end()) { @@ -184,27 +207,39 @@ BTestShell::PrintHelp() { void BTestShell::PrintValidArguments() { - cout << indent << "--help Displays this help text plus some other garbage" << endl; - cout << indent << "--list Lists the names of classes with installed tests" << endl; - cout << indent << "-v0 Sets verbosity level to 0 (concise summary only)" << endl; - cout << indent << "-v1 Sets verbosity level to 1 (complete summary only)" << endl; - cout << indent << "-v2 Sets verbosity level to 2 (*default* -- per-test results plus" << endl; - cout << indent << " complete summary)" << endl; - cout << indent << "-v3 Sets verbosity level to 3 (per-test results and timing info" << endl; - cout << indent << " plus complete summary)" << endl; - cout << indent << "CLASSNAME Instructs the program to run the test for the given class; if" << endl; - cout << indent << " no classes are specified, all tests are run" << endl; - cout << indent << "-lPATH Adds PATH to the search path for dynamically loadable test" << endl; - cout << indent << " libraries." << endl; + cout << indent << "--help Displays this help text plus some other garbage" << endl; + cout << indent << "--list Lists the names of classes with installed tests" << endl; + cout << indent << "-v0 Sets verbosity level to 0 (concise summary only)" << endl; + cout << indent << "-v1 Sets verbosity level to 1 (complete summary only)" << endl; + cout << indent << "-v2 Sets verbosity level to 2 (*default* -- per-test results plus" << endl; + cout << indent << " complete summary)" << endl; + cout << indent << "-v3 Sets verbosity level to 3 (dynamic loading information, per-test " << endl; + cout << indent << " results and timing info, plus complete summary)" << endl; + cout << indent << "NAME Instructs the program to run the test for the given class or all" << endl; + cout << indent << " the tests for the given suite. If some bonehead adds both a class" << endl; + cout << indent << " and a suite with the same name, the suite will be run, not the class" << endl; + cout << indent << " (unless the class is part of the suite with the same name :-). If no" << endl; + cout << indent << " classes or suites are specified, all available tests are run" << endl; + cout << indent << "-lPATH Adds PATH to the search path for dynamically loadable test" << endl; + cout << indent << " libraries" << endl; } void BTestShell::PrintInstalledTests() { + // Print out the list of installed suites + cout << "------------------------------------------------------------------------------" << endl; + cout << "Available Suites:" << endl; + cout << "------------------------------------------------------------------------------" << endl; + SuiteMap::const_iterator j; + for (j = fSuites.begin(); j != fSuites.end(); ++j) + cout << j->first << endl; + cout << endl; + // Print out the list of installed tests cout << "------------------------------------------------------------------------------" << endl; cout << "Available Tests:" << endl; cout << "------------------------------------------------------------------------------" << endl; - std::map::const_iterator i; + TestMap::const_iterator i; for (i = fTests.begin(); i != fTests.end(); ++i) cout << i->first << endl; cout << endl; @@ -250,8 +285,9 @@ BTestShell::ProcessArgument(std::string arg, int argc, char *argv[]) { } else if (arg == "-v3") { fVerbosityLevel = v3; - } - else { + } else if (arg.length() >= 2 && arg[0] == '-' && arg[1] == 'l') { + fLibDirs.insert(arg.substr(2, arg.size()-2)); + } else { fTestsToRun.insert(arg); } return true; @@ -323,15 +359,26 @@ BTestShell::PrintResults() { void BTestShell::LoadDynamicSuites() { + if (Verbosity() >= v3) { + cout << "------------------------------------------------------------------------------" << endl; + cout << "Loading " << endl; + cout << "------------------------------------------------------------------------------" << endl; + } + std::set::iterator i; for (i = fLibDirs.begin(); i != fLibDirs.end(); i++) { BDirectory libDir((*i).c_str()); + if (Verbosity() >= v3) + cout << "Checking " << *i << endl; int count = LoadSuitesFrom(&libDir); - if (Verbosity() >= v3) { - cout << "Loaded " << count << " suite" << (count == 1 ? "" : "s"); - cout << " from " << *i << endl; + if (Verbosity() >= v3) { +// cout << "Loaded " << count << " suite" << (count == 1 ? "" : "s"); +// cout << " from " << *i << endl; } } + + if (Verbosity() >= v3) + cout << endl; } void diff --git a/src/tools/cppunit/TestUtils.cpp b/src/tools/cppunit/TestUtils.cpp index eb7affccfe..04eff435c7 100644 --- a/src/tools/cppunit/TestUtils.cpp +++ b/src/tools/cppunit/TestUtils.cpp @@ -2,6 +2,7 @@ #include #include +#include status_t DecodeResult(status_t result) { if (!BTestShell::GlobalBeVerbose()) @@ -169,6 +170,12 @@ status_t DecodeResult(status_t result) { return result; } +std::string IntToStr(int i) { + char num[32]; + sprintf(num, "%d", i); + return std::string(num); +} + void ExecCommand(const char *command) { if (command) system(command);