From 8a8c62d587f69e41548158cf7ecc8d724c230694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 29 Nov 2010 18:46:58 +0000 Subject: [PATCH] * Build fix for GCC4. * Use CPPUNIT_ASSERT() instead of assert() in unit tests. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39673 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kits/support/ByteOrderTest.cpp | 20 ++- src/tests/kits/support/ByteOrderTest.h | 9 +- .../barchivable/InstantiateObjectTester.cpp | 6 +- .../barchivable/InstantiateObjectTester.h | 81 ++++----- .../bblockcache/BlockCacheConcurrencyTest.cpp | 159 ++++++++---------- .../bblockcache/BlockCacheExerciseTest.cpp | 116 ++++++------- .../blocker/BenaphoreLockCountTest1.cpp | 37 ++-- .../support/blocker/BenaphoreLockCountTest1.h | 4 +- .../kits/support/blocker/ConcurrencyTest1.cpp | 8 +- .../kits/support/blocker/ConcurrencyTest2.cpp | 12 +- .../kits/support/blocker/ConcurrencyTest2.h | 12 +- .../support/blocker/ConstructionTest1.cpp | 38 +++-- .../kits/support/blocker/DestructionTest1.cpp | 6 +- .../kits/support/blocker/DestructionTest2.cpp | 8 +- .../kits/support/blocker/LockerTestCase.cpp | 8 +- .../blocker/SemaphoreLockCountTest1.cpp | 32 ++-- 16 files changed, 259 insertions(+), 297 deletions(-) diff --git a/src/tests/kits/support/ByteOrderTest.cpp b/src/tests/kits/support/ByteOrderTest.cpp index 7851ce59c9..ac20abddc1 100644 --- a/src/tests/kits/support/ByteOrderTest.cpp +++ b/src/tests/kits/support/ByteOrderTest.cpp @@ -1,18 +1,20 @@ -/* -** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2004-2010, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ -#include "TestCase.h" #include "ByteOrderTest.h" -#include -#include -#include + +#include +#include #include -#include +#include +#include + +#include using namespace CppUnit; diff --git a/src/tests/kits/support/ByteOrderTest.h b/src/tests/kits/support/ByteOrderTest.h index bdfcfb1ff1..3102d5ecd2 100644 --- a/src/tests/kits/support/ByteOrderTest.h +++ b/src/tests/kits/support/ByteOrderTest.h @@ -1,8 +1,15 @@ +/* + * Copyright 2004-2010, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ #ifndef _BYTE_ORDER_TEST_H_ #define _BYTE_ORDER_TEST_H_ -class CppUnit::Test; + +#include "TestCase.h" + CppUnit::Test *ByteOrderTestSuite(); + #endif // _BYTE_ORDER_TEST_H_ diff --git a/src/tests/kits/support/barchivable/InstantiateObjectTester.cpp b/src/tests/kits/support/barchivable/InstantiateObjectTester.cpp index d67f88dfc8..f6b77fe9b1 100644 --- a/src/tests/kits/support/barchivable/InstantiateObjectTester.cpp +++ b/src/tests/kits/support/barchivable/InstantiateObjectTester.cpp @@ -12,9 +12,12 @@ */ //------------------------------------------------------------------------------ +#include "InstantiateObjectTester.h" + // Standard Includes ----------------------------------------------------------- #include #include +#include // System Includes ------------------------------------------------------------- #include @@ -27,9 +30,10 @@ // Local Includes -------------------------------------------------------------- #include "remoteobjectdef/RemoteTestObject.h" -#include "InstantiateObjectTester.h" #include "LocalTestObject.h" +using namespace std; + // Local Defines --------------------------------------------------------------- #define FORMAT_AND_THROW(MSG, ERR) \ FormatAndThrow(__LINE__, __FILE__, MSG, ERR) diff --git a/src/tests/kits/support/barchivable/InstantiateObjectTester.h b/src/tests/kits/support/barchivable/InstantiateObjectTester.h index 166647ae81..1285f85bd7 100644 --- a/src/tests/kits/support/barchivable/InstantiateObjectTester.h +++ b/src/tests/kits/support/barchivable/InstantiateObjectTester.h @@ -1,65 +1,42 @@ -//------------------------------------------------------------------------------ -// InstantiateObjectTester.h -// -//------------------------------------------------------------------------------ +#ifndef INSTANTIATE_OBJECT_TESTER_H +#define INSTANTIATE_OBJECT_TESTER_H -#ifndef INSTANTIATEOBJECTTESTER_H -#define INSTANTIATEOBJECTTESTER_H -// Standard Includes ----------------------------------------------------------- - -// System Includes ------------------------------------------------------------- - -// Project Includes ------------------------------------------------------------ - -// Local Includes -------------------------------------------------------------- #include "LocalCommon.h" -// Local Defines --------------------------------------------------------------- -// Globals --------------------------------------------------------------------- +class TInstantiateObjectTester : public BTestCase { +public: + TInstantiateObjectTester( + std::string name = ""); -//------------------------------------------------------------------------------ -class TInstantiateObjectTester : public BTestCase -{ - public: - TInstantiateObjectTester(std::string name = ""); - - void Case1(); - void Case2(); - void Case3(); - void Case4(); - void Case5(); - void Case6(); - void Case7(); - void Case8(); - void Case9(); - void Case10(); - void Case11(); - void Case12(); - void Case13(); - void Case14(); + void Case1(); + void Case2(); + void Case3(); + void Case4(); + void Case5(); + void Case6(); + void Case7(); + void Case8(); + void Case9(); + void Case10(); + void Case11(); + void Case12(); + void Case13(); + void Case14(); - void RunTests(); + void RunTests(); - static CppUnit::Test* Suite(); + static CppUnit::Test* Suite(); - private: - void LoadAddon(); - void UnloadAddon(); - std::string GetLocalSignature(); +private: + void LoadAddon(); + void UnloadAddon(); + std::string GetLocalSignature(); - image_id fAddonId; +private: + image_id fAddonId; }; -//------------------------------------------------------------------------------ - -#endif //INSTANTIATEOBJECTTESTER_H - -/* - * $Log $ - * - * $Id $ - * - */ +#endif // INSTANTIATE_OBJECT_TESTER_H diff --git a/src/tests/kits/support/bblockcache/BlockCacheConcurrencyTest.cpp b/src/tests/kits/support/bblockcache/BlockCacheConcurrencyTest.cpp index 91d838370f..29cd68cacb 100644 --- a/src/tests/kits/support/bblockcache/BlockCacheConcurrencyTest.cpp +++ b/src/tests/kits/support/bblockcache/BlockCacheConcurrencyTest.cpp @@ -1,46 +1,44 @@ /* - $Id: BlockCacheConcurrencyTest.cpp 10124 2004-11-21 18:37:49Z shatty $ - This file tests BBlockCache from multiple threads to ensure there are no concurrency problems. - - */ +*/ #include "BlockCacheConcurrencyTest.h" -#include "ThreadedTestCaller.h" + +#include + #include #include +#include "ThreadedTestCaller.h" + /* * Method: BlockCacheConcurrencyTest::BlockCacheConcurrencyTest() * Descr: This method is the only constructor for the BlockCacheConcurrencyTest * class. */ - - - BlockCacheConcurrencyTest::BlockCacheConcurrencyTest(std::string name) : - BThreadedTestCase(name), - theObjCache(NULL), - theMallocCache(NULL), - numBlocksInCache(128), - sizeOfBlocksInCache(23), - sizeOfNonCacheBlocks(29) +BlockCacheConcurrencyTest::BlockCacheConcurrencyTest(std::string name) + : + BThreadedTestCase(name), + theObjCache(NULL), + theMallocCache(NULL), + numBlocksInCache(128), + sizeOfBlocksInCache(23), + sizeOfNonCacheBlocks(29) { - } +} /* * Method: BlockCacheConcurrencyTest::~BlockCacheConcurrencyTest() * Descr: This method is the destructor for the BlockCacheConcurrencyTest class. */ - - - BlockCacheConcurrencyTest::~BlockCacheConcurrencyTest() +BlockCacheConcurrencyTest::~BlockCacheConcurrencyTest() { } - + /* * Method: BlockCacheConcurrencyTest::setUp() @@ -48,24 +46,22 @@ * tests on. One uses new/delete and the other uses malloc/free * on its blocks. */ - - - void BlockCacheConcurrencyTest::setUp(void) +void +BlockCacheConcurrencyTest::setUp() { theObjCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache, - B_OBJECT_CACHE); + B_OBJECT_CACHE); theMallocCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache, - B_MALLOC_CACHE); + B_MALLOC_CACHE); } - + /* * Method: BlockCacheConcurrencyTest::tearDown() * Descr: This method cleans up the BBlockCache instances which were tested. */ - - - void BlockCacheConcurrencyTest::tearDown(void) +void +BlockCacheConcurrencyTest::tearDown() { delete theObjCache; delete theMallocCache; @@ -77,27 +73,23 @@ * Descr: This method returns a pointer from the BBlockCache, checking * the value before passing it to the caller. */ - - - void *BlockCacheConcurrencyTest::GetBlock(BBlockCache *theCache, - size_t blockSize, - thread_id theThread, - BList *cacheList, - BList *nonCacheList) +void * +BlockCacheConcurrencyTest::GetBlock(BBlockCache *theCache, size_t blockSize, + thread_id theThread, BList *cacheList, BList *nonCacheList) { void *thePtr = theCache->Get(blockSize); - + // The new block should not already be used by this thread. - assert(!cacheList->HasItem(thePtr)); - assert(!nonCacheList->HasItem(thePtr)); - + CPPUNIT_ASSERT(!cacheList->HasItem(thePtr)); + CPPUNIT_ASSERT(!nonCacheList->HasItem(thePtr)); + // Add the block to the list of blocks used by this thread. if (blockSize == sizeOfBlocksInCache) { - assert(cacheList->AddItem(thePtr)); + CPPUNIT_ASSERT(cacheList->AddItem(thePtr)); } else { - assert(nonCacheList->AddItem(thePtr)); + CPPUNIT_ASSERT(nonCacheList->AddItem(thePtr)); } - + // Store the thread id at the start of the block for future // reference. *((thread_id *)thePtr) = theThread; @@ -110,29 +102,25 @@ * Descr: This method passes the pointer back to the BBlockCache * and checks the sanity of the lists. */ - - - void BlockCacheConcurrencyTest::SaveBlock(BBlockCache *theCache, - void *thePtr, - size_t blockSize, - thread_id theThread, - BList *cacheList, - BList *nonCacheList) +void +BlockCacheConcurrencyTest::SaveBlock(BBlockCache *theCache, void *thePtr, + size_t blockSize, thread_id theThread, BList *cacheList, + BList *nonCacheList) { // The block being returned to the cache should still have // the thread id of this thread in it, or some other thread has // perhaps manipulated this block which would indicate a // concurrency problem. - assert(*((thread_id *)thePtr) == theThread); - + CPPUNIT_ASSERT(*((thread_id *)thePtr) == theThread); + // Remove the item from the appropriate list and confirm it isn't // on the other list for some reason. if (blockSize == sizeOfBlocksInCache) { - assert(cacheList->RemoveItem(thePtr)); - assert(!nonCacheList->HasItem(thePtr)); + CPPUNIT_ASSERT(cacheList->RemoveItem(thePtr)); + CPPUNIT_ASSERT(!nonCacheList->HasItem(thePtr)); } else { - assert(!cacheList->HasItem(thePtr)); - assert(nonCacheList->RemoveItem(thePtr)); + CPPUNIT_ASSERT(!cacheList->HasItem(thePtr)); + CPPUNIT_ASSERT(nonCacheList->RemoveItem(thePtr)); } theCache->Save(thePtr, blockSize); } @@ -143,29 +131,25 @@ * Descr: This method frees the block directly using delete[] or free(), * checking the sanity of the lists as it does the operation. */ - - - void BlockCacheConcurrencyTest::FreeBlock(void *thePtr, - size_t blockSize, - bool isMallocTest, - thread_id theThread, - BList *cacheList, - BList *nonCacheList) +void +BlockCacheConcurrencyTest::FreeBlock(void *thePtr, size_t blockSize, + bool isMallocTest, thread_id theThread, BList *cacheList, + BList *nonCacheList) { // The block being returned to the cache should still have // the thread id of this thread in it, or some other thread has // perhaps manipulated this block which would indicate a // concurrency problem. - assert(*((thread_id *)thePtr) == theThread); - + CPPUNIT_ASSERT(*((thread_id *)thePtr) == theThread); + // Remove the item from the appropriate list and confirm it isn't // on the other list for some reason. if (blockSize == sizeOfBlocksInCache) { - assert(cacheList->RemoveItem(thePtr)); - assert(!nonCacheList->HasItem(thePtr)); + CPPUNIT_ASSERT(cacheList->RemoveItem(thePtr)); + CPPUNIT_ASSERT(!nonCacheList->HasItem(thePtr)); } else { - assert(!cacheList->HasItem(thePtr)); - assert(nonCacheList->RemoveItem(thePtr)); + CPPUNIT_ASSERT(!cacheList->HasItem(thePtr)); + CPPUNIT_ASSERT(nonCacheList->RemoveItem(thePtr)); } if (isMallocTest) { free(thePtr); @@ -189,10 +173,9 @@ * end of this method, all blocks unfreed by this method are * freed to avoid a memory leak. */ - - - void BlockCacheConcurrencyTest::TestBlockCache(BBlockCache *theCache, - bool isMallocTest) +void +BlockCacheConcurrencyTest::TestBlockCache(BBlockCache *theCache, + bool isMallocTest) { BList cacheList; BList nonCacheList; @@ -207,17 +190,17 @@ GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList); - + SaveBlock(theCache, cacheList.ItemAt(cacheList.CountItems() / 2), sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList); SaveBlock(theCache, nonCacheList.ItemAt(nonCacheList.CountItems() / 2), sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList); - + GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfBlocksInCache, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList); GetBlock(theCache, sizeOfNonCacheBlocks, theThread, &cacheList, &nonCacheList); - + FreeBlock(cacheList.ItemAt(cacheList.CountItems() / 2), sizeOfBlocksInCache, isMallocTest, theThread, &cacheList, &nonCacheList); FreeBlock(nonCacheList.ItemAt(nonCacheList.CountItems() / 2), @@ -248,29 +231,27 @@ } } } - + /* * Method: BlockCacheConcurrencyTest::TestThreadMalloc() * Descr: This method passes the BBlockCache instance to TestBlockCache() * where the instance will be tested. */ - - - void BlockCacheConcurrencyTest::TestThreadMalloc(void) +void +BlockCacheConcurrencyTest::TestThreadMalloc() { TestBlockCache(theMallocCache, true); } - + /* * Method: BlockCacheConcurrencyTest::TestThreadObj() * Descr: This method passes the BBlockCache instance to TestBlockCache() * where the instance will be tested. */ - - - void BlockCacheConcurrencyTest::TestThreadObj(void) +void +BlockCacheConcurrencyTest::TestThreadObj() { TestBlockCache(theObjCache, false); } @@ -278,14 +259,12 @@ /* * Method: BlockCacheConcurrencyTest::suite() - * Descr: This static member function returns a test caller for performing + * Descr: This static member function returns a test caller for performing * the "BlockCacheConcurrencyTest" test. The test caller * is created as a ThreadedTestCaller with six independent threads. */ - - -CppUnit::Test *BlockCacheConcurrencyTest::suite(void) -{ +CppUnit::Test *BlockCacheConcurrencyTest::suite() +{ typedef BThreadedTestCaller BlockCacheConcurrencyTestCaller; diff --git a/src/tests/kits/support/bblockcache/BlockCacheExerciseTest.cpp b/src/tests/kits/support/bblockcache/BlockCacheExerciseTest.cpp index aaf2878e4e..f9021c1176 100644 --- a/src/tests/kits/support/bblockcache/BlockCacheExerciseTest.cpp +++ b/src/tests/kits/support/bblockcache/BlockCacheExerciseTest.cpp @@ -1,44 +1,42 @@ /* - $Id: BlockCacheExerciseTest.cpp 10124 2004-11-21 18:37:49Z shatty $ - This file tests basic functionality of BBlockCache. - - */ +*/ #include "BlockCacheExerciseTest.h" -#include "cppunit/TestCaller.h" + +#include + #include +#include "cppunit/TestCaller.h" + /* * Method: BlockCacheExerciseTest::BlockCacheExerciseTest() * Descr: This method is the only constructor for the BlockCacheExerciseTest * class. */ - - - BlockCacheExerciseTest::BlockCacheExerciseTest(std::string name) : - TestCase(name), - theCache(NULL), - numBlocksInCache(0), - sizeOfBlocksInCache(0), - sizeOfNonCacheBlocks(0), - isMallocTest(false) +BlockCacheExerciseTest::BlockCacheExerciseTest(std::string name) + : + TestCase(name), + theCache(NULL), + numBlocksInCache(0), + sizeOfBlocksInCache(0), + sizeOfNonCacheBlocks(0), + isMallocTest(false) { - } +} /* * Method: BlockCacheExerciseTest::~BlockCacheExerciseTest() * Descr: This method is the destructor for the BlockCacheExerciseTest class. */ - - - BlockCacheExerciseTest::~BlockCacheExerciseTest() +BlockCacheExerciseTest::~BlockCacheExerciseTest() { - } - +} + /* * Method: BlockCacheExerciseTest::TestBlockCache() @@ -88,9 +86,8 @@ * * The sum total of these actions test the BBlockCache. */ - - - void BlockCacheExerciseTest::TestBlockCache(void) +void +BlockCacheExerciseTest::TestBlockCache(void) { // First get all items from the cache plus ten more @@ -146,10 +143,10 @@ sizeOfBlocksInCache); FreeBlock(nonCacheList.ItemAt(nonCacheList.CountItems() / 3), sizeOfNonCacheBlocks); - } } - - +} + + /* * Method: BlockCacheExerciseTest::BuildLists() * Descr: This method gets all of the blocks from the cache in order to @@ -159,9 +156,8 @@ * access allocated memory without resorting to malloc()'s or new's, * this should be a fair assumption. */ - - - void BlockCacheExerciseTest::BuildLists(void) +void +BlockCacheExerciseTest::BuildLists() { freeList.MakeEmpty(); usedList.MakeEmpty(); @@ -181,31 +177,30 @@ * Descr: This method returns a pointer from the BBlockCache, checking * the value before passing it to the caller. */ - - - void *BlockCacheExerciseTest::GetBlock(size_t blockSize) +void * +BlockCacheExerciseTest::GetBlock(size_t blockSize) { void *thePtr = theCache->Get(blockSize); // This new pointer should not be one which we already // have from the BBlockCache which we haven't given back // yet. - assert(!usedList.HasItem(thePtr)); - assert(!nonCacheList.HasItem(thePtr)); + CPPUNIT_ASSERT(!usedList.HasItem(thePtr)); + CPPUNIT_ASSERT(!nonCacheList.HasItem(thePtr)); if (blockSize == sizeOfBlocksInCache) { // If this block was one which could have come from the // cache and there are free items on the cache, it // should be one of those free blocks. if (freeList.CountItems() > 0) { - assert(freeList.RemoveItem(thePtr)); + CPPUNIT_ASSERT(freeList.RemoveItem(thePtr)); } - assert(usedList.AddItem(thePtr)); + CPPUNIT_ASSERT(usedList.AddItem(thePtr)); } else { // A "non-cache sized" block should never come from the // free list. - assert(!freeList.HasItem(thePtr)); - assert(nonCacheList.AddItem(thePtr)); + CPPUNIT_ASSERT(!freeList.HasItem(thePtr)); + CPPUNIT_ASSERT(nonCacheList.AddItem(thePtr)); } return(thePtr); } @@ -216,13 +211,12 @@ * Descr: This method passes the pointer back to the BBlockCache * and checks the sanity of the lists. */ - - - void BlockCacheExerciseTest::SaveBlock(void *thePtr, size_t blockSize) +void +BlockCacheExerciseTest::SaveBlock(void *thePtr, size_t blockSize) { // The memory block being returned to the cache should // not already be free. - assert(!freeList.HasItem(thePtr)); + CPPUNIT_ASSERT(!freeList.HasItem(thePtr)); if (blockSize == sizeOfBlocksInCache) { // If there is room on the free list, when this block @@ -230,18 +224,18 @@ // free list. Therefore we will also track it as // a free block on the cache. if (freeList.CountItems() < numBlocksInCache) { - assert(freeList.AddItem(thePtr)); + CPPUNIT_ASSERT(freeList.AddItem(thePtr)); } // This block should not be on the non-cache list but it // should be on the used list. - assert(!nonCacheList.HasItem(thePtr)); - assert(usedList.RemoveItem(thePtr)); + CPPUNIT_ASSERT(!nonCacheList.HasItem(thePtr)); + CPPUNIT_ASSERT(usedList.RemoveItem(thePtr)); } else { // This block should not be on the used list but it should // be on the non-cache list. - assert(!usedList.HasItem(thePtr)); - assert(nonCacheList.RemoveItem(thePtr)); + CPPUNIT_ASSERT(!usedList.HasItem(thePtr)); + CPPUNIT_ASSERT(nonCacheList.RemoveItem(thePtr)); } theCache->Save(thePtr, blockSize); } @@ -252,24 +246,23 @@ * Descr: This method frees the block directly using delete[] or free(), * checking the sanity of the lists as it does the operation. */ - - - void BlockCacheExerciseTest::FreeBlock(void *thePtr, size_t blockSize) +void +BlockCacheExerciseTest::FreeBlock(void *thePtr, size_t blockSize) { // The block being freed should not already have been // returned to the cache. - assert(!freeList.HasItem(thePtr)); + CPPUNIT_ASSERT(!freeList.HasItem(thePtr)); if (blockSize == sizeOfBlocksInCache) { // This block should not be on the non-cache list but it // should be on the used list. - assert(!nonCacheList.HasItem(thePtr)); - assert(usedList.RemoveItem(thePtr)); + CPPUNIT_ASSERT(!nonCacheList.HasItem(thePtr)); + CPPUNIT_ASSERT(usedList.RemoveItem(thePtr)); } else { // This block should not be on the used list but it should // be on the non-cache list. - assert(!usedList.HasItem(thePtr)); - assert(nonCacheList.RemoveItem(thePtr)); + CPPUNIT_ASSERT(!usedList.HasItem(thePtr)); + CPPUNIT_ASSERT(nonCacheList.RemoveItem(thePtr)); } if (isMallocTest) { free(thePtr); @@ -292,9 +285,8 @@ * 3. Frees all blocks left after the test to prevent * memory leaks. */ - - - void BlockCacheExerciseTest::PerformTest(void) +void +BlockCacheExerciseTest::PerformTest(void) { for (numBlocksInCache = 8; numBlocksInCache < 513; numBlocksInCache *= 2) { for (sizeOfBlocksInCache = 13; sizeOfBlocksInCache < 9478; sizeOfBlocksInCache *= 3) { @@ -306,7 +298,7 @@ isMallocTest = false; theCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache, B_OBJECT_CACHE); - assert(theCache != NULL); + CPPUNIT_ASSERT(theCache != NULL); // Query the cache and determine the blocks in it. BuildLists(); @@ -323,7 +315,7 @@ isMallocTest = true; theCache = new BBlockCache(numBlocksInCache, sizeOfBlocksInCache, B_MALLOC_CACHE); - assert(theCache != NULL); + CPPUNIT_ASSERT(theCache != NULL); // Query the cache and determine the blocks in it. BuildLists(); @@ -347,9 +339,7 @@ * Descr: This static member function returns a test caller for performing * the "BlockCacheExerciseTest" test. */ - - -CppUnit::Test *BlockCacheExerciseTest::suite(void) +CppUnit::Test *BlockCacheExerciseTest::suite() { typedef CppUnit::TestCaller BlockCacheExerciseTestCaller; diff --git a/src/tests/kits/support/blocker/BenaphoreLockCountTest1.cpp b/src/tests/kits/support/blocker/BenaphoreLockCountTest1.cpp index 5d3d01dd6f..09de1e4abc 100644 --- a/src/tests/kits/support/blocker/BenaphoreLockCountTest1.cpp +++ b/src/tests/kits/support/blocker/BenaphoreLockCountTest1.cpp @@ -22,12 +22,15 @@ */ -#include #include "BenaphoreLockCountTest1.h" + #include #include + #include +#include + // This constant is used to determine the number of microseconds to // sleep during major steps of the test. @@ -91,38 +94,38 @@ void BenaphoreLockCountTest1::TestThread1(void) SafetyLock theSafetyLock2(&thread2Lock); SafetyLock theSafetyLock3(&thread3Lock); - assert(thread2Lock.Lock()); + CPPUNIT_ASSERT(thread2Lock.Lock()); NextSubTest(); - assert(thread3Lock.Lock()); + CPPUNIT_ASSERT(thread3Lock.Lock()); NextSubTest(); - assert(CheckLockRequests(0)); + CPPUNIT_ASSERT(CheckLockRequests(0)); NextSubTest(); - assert(theLocker->Lock()); + CPPUNIT_ASSERT(theLocker->Lock()); NextSubTest(); - assert(CheckLockRequests(1)); + CPPUNIT_ASSERT(CheckLockRequests(1)); NextSubTest(); thread2Lock.Unlock(); NextSubTest(); snooze(SNOOZE_TIME); NextSubTest(); - assert(CheckLockRequests(3)); + CPPUNIT_ASSERT(CheckLockRequests(3)); NextSubTest(); thread3Lock.Unlock(); NextSubTest(); snooze(SNOOZE_TIME); NextSubTest(); - assert(CheckLockRequests(5)); + CPPUNIT_ASSERT(CheckLockRequests(5)); NextSubTest(); theLocker->Unlock(); NextSubTest(); snooze(SNOOZE_TIME); NextSubTest(); - assert(CheckLockRequests(2)); + CPPUNIT_ASSERT(CheckLockRequests(2)); NextSubTest(); } @@ -143,16 +146,16 @@ void BenaphoreLockCountTest1::TestThread2(void) snooze(SNOOZE_TIME / 10); NextSubTest(); - assert(thread2Lock.Lock()); + CPPUNIT_ASSERT(thread2Lock.Lock()); NextSubTest(); - assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); + CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); NextSubTest(); - assert(theLocker->Lock()); + CPPUNIT_ASSERT(theLocker->Lock()); NextSubTest(); int actual = theLocker->CountLockRequests(); NextSubTest(); - assert((actual == 3) || (actual == 4)); + CPPUNIT_ASSERT((actual == 3) || (actual == 4)); NextSubTest(); theLocker->Unlock(); NextSubTest(); @@ -175,16 +178,16 @@ void BenaphoreLockCountTest1::TestThread3(void) snooze(SNOOZE_TIME / 10); NextSubTest(); - assert(thread3Lock.Lock()); + CPPUNIT_ASSERT(thread3Lock.Lock()); NextSubTest(); - assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); + CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); NextSubTest(); - assert(theLocker->Lock()); + CPPUNIT_ASSERT(theLocker->Lock()); NextSubTest(); int actual = theLocker->CountLockRequests(); NextSubTest(); - assert((actual == 3) || (actual == 4)); + CPPUNIT_ASSERT((actual == 3) || (actual == 4)); NextSubTest(); theLocker->Unlock(); NextSubTest(); diff --git a/src/tests/kits/support/blocker/BenaphoreLockCountTest1.h b/src/tests/kits/support/blocker/BenaphoreLockCountTest1.h index 414451288e..58dee1f1cf 100644 --- a/src/tests/kits/support/blocker/BenaphoreLockCountTest1.h +++ b/src/tests/kits/support/blocker/BenaphoreLockCountTest1.h @@ -11,10 +11,10 @@ #define BenaphoreLockCountTest1_H -#include "LockerTestCase.h" #include -class CppUnit::Test; +#include "LockerTestCase.h" + class BenaphoreLockCountTest1 : public LockerTestCase { private: diff --git a/src/tests/kits/support/blocker/ConcurrencyTest1.cpp b/src/tests/kits/support/blocker/ConcurrencyTest1.cpp index c86d2016b8..f0716ae7eb 100644 --- a/src/tests/kits/support/blocker/ConcurrencyTest1.cpp +++ b/src/tests/kits/support/blocker/ConcurrencyTest1.cpp @@ -166,19 +166,19 @@ void ConcurrencyTest1::TestThread(void) NextSubTest(); CheckLock(0); - assert(AcquireLock(i, true)); + CPPUNIT_ASSERT(AcquireLock(i, true)); - assert(!lockTestValue); + CPPUNIT_ASSERT(!lockTestValue); lockTestValue = true; CheckLock(1); - assert(AcquireLock(i, false)); + CPPUNIT_ASSERT(AcquireLock(i, false)); CheckLock(2); theLocker->Unlock(); CheckLock(1); - assert(lockTestValue); + CPPUNIT_ASSERT(lockTestValue); lockTestValue = false; theLocker->Unlock(); CheckLock(0); diff --git a/src/tests/kits/support/blocker/ConcurrencyTest2.cpp b/src/tests/kits/support/blocker/ConcurrencyTest2.cpp index fabb601786..66e822af41 100644 --- a/src/tests/kits/support/blocker/ConcurrencyTest2.cpp +++ b/src/tests/kits/support/blocker/ConcurrencyTest2.cpp @@ -117,7 +117,7 @@ void ConcurrencyTest2::AcquireThread(void) { SafetyLock theSafetyLock(theLocker); - assert(theLocker->Lock()); + CPPUNIT_ASSERT(theLocker->Lock()); NextSubTest(); snooze(SNOOZE_TIME); NextSubTest(); @@ -171,7 +171,7 @@ void ConcurrencyTest2::TimeoutThread(void) snooze(SNOOZE_TIME/2); NextSubTest(); - assert(theLocker->LockWithTimeout(SNOOZE_TIME/10) == B_TIMED_OUT); + CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME/10) == B_TIMED_OUT); NextSubTest(); LockingLoop(); NextSubTest(); @@ -209,19 +209,19 @@ void ConcurrencyTest2::LockingLoop(void) for (i = 0; i < MAXLOOP; i++) { CheckLock(0); - assert(AcquireLock(i, true)); + CPPUNIT_ASSERT(AcquireLock(i, true)); - assert(!lockTestValue); + CPPUNIT_ASSERT(!lockTestValue); lockTestValue = true; CheckLock(1); - assert(AcquireLock(i, false)); + CPPUNIT_ASSERT(AcquireLock(i, false)); CheckLock(2); theLocker->Unlock(); CheckLock(1); - assert(lockTestValue); + CPPUNIT_ASSERT(lockTestValue); lockTestValue = false; theLocker->Unlock(); CheckLock(0); diff --git a/src/tests/kits/support/blocker/ConcurrencyTest2.h b/src/tests/kits/support/blocker/ConcurrencyTest2.h index eda431eeae..a943085c4e 100644 --- a/src/tests/kits/support/blocker/ConcurrencyTest2.h +++ b/src/tests/kits/support/blocker/ConcurrencyTest2.h @@ -13,10 +13,8 @@ #include "LockerTestCase.h" -class CppUnit::Test; -class ConcurrencyTest2 : public LockerTestCase { - +class ConcurrencyTest2 : public LockerTestCase { private: bool lockTestValue; @@ -31,9 +29,7 @@ public: void AcquireThread(void); void TimeoutThread(void); static CppUnit::Test *suite(void); - }; - +}; + + #endif - - - diff --git a/src/tests/kits/support/blocker/ConstructionTest1.cpp b/src/tests/kits/support/blocker/ConstructionTest1.cpp index 2137391a00..904bc164aa 100644 --- a/src/tests/kits/support/blocker/ConstructionTest1.cpp +++ b/src/tests/kits/support/blocker/ConstructionTest1.cpp @@ -11,9 +11,13 @@ #include "ConstructionTest1.h" -#include -#include + +#include + #include +#include + +#include /* @@ -51,7 +55,7 @@ bool { sem_info theSemInfo; - assert(get_sem_info(lockerArg->Sem(), &theSemInfo) == B_OK); + CPPUNIT_ASSERT(get_sem_info(lockerArg->Sem(), &theSemInfo) == B_OK); return(strcmp(name, theSemInfo.name) == 0); } @@ -69,7 +73,7 @@ bool { int32 semCount; - assert(get_sem_count(lockerArg->Sem(), &semCount) == B_OK); + CPPUNIT_ASSERT(get_sem_count(lockerArg->Sem(), &semCount) == B_OK); switch (semCount) { case 0: return(true); break; @@ -79,7 +83,7 @@ bool // This should not happen. The semaphore count should be // 0 for a benaphore, 1 for a semaphore. No other value // is legal in this case. - assert(false); + CPPUNIT_ASSERT(false); break; } return(false); @@ -96,33 +100,33 @@ bool void ConstructionTest1::PerformTest(void) { NextSubTest(); - assert(NameMatches("some BLocker", theLocker)); - assert(IsBenaphore(theLocker)); + CPPUNIT_ASSERT(NameMatches("some BLocker", theLocker)); + CPPUNIT_ASSERT(IsBenaphore(theLocker)); NextSubTest(); BLocker locker1("test string"); - assert(NameMatches("test string", &locker1)); - assert(IsBenaphore(&locker1)); + CPPUNIT_ASSERT(NameMatches("test string", &locker1)); + CPPUNIT_ASSERT(IsBenaphore(&locker1)); NextSubTest(); BLocker locker2(false); - assert(NameMatches("some BLocker", &locker2)); - assert(!IsBenaphore(&locker2)); + CPPUNIT_ASSERT(NameMatches("some BLocker", &locker2)); + CPPUNIT_ASSERT(!IsBenaphore(&locker2)); NextSubTest(); BLocker locker3(true); - assert(NameMatches("some BLocker", &locker3)); - assert(IsBenaphore(&locker3)); + CPPUNIT_ASSERT(NameMatches("some BLocker", &locker3)); + CPPUNIT_ASSERT(IsBenaphore(&locker3)); NextSubTest(); BLocker locker4("test string", false); - assert(NameMatches("test string", &locker4)); - assert(!IsBenaphore(&locker4)); + CPPUNIT_ASSERT(NameMatches("test string", &locker4)); + CPPUNIT_ASSERT(!IsBenaphore(&locker4)); NextSubTest(); BLocker locker5("test string", true); - assert(NameMatches("test string", &locker5)); - assert(IsBenaphore(&locker5)); + CPPUNIT_ASSERT(NameMatches("test string", &locker5)); + CPPUNIT_ASSERT(IsBenaphore(&locker5)); } diff --git a/src/tests/kits/support/blocker/DestructionTest1.cpp b/src/tests/kits/support/blocker/DestructionTest1.cpp index d08d757324..c04ed1eb85 100644 --- a/src/tests/kits/support/blocker/DestructionTest1.cpp +++ b/src/tests/kits/support/blocker/DestructionTest1.cpp @@ -63,7 +63,7 @@ const bigtime_t SNOOZE_TIME = 200000; void DestructionTest1::TestThread1(void) { - assert(theLocker->Lock()); + CPPUNIT_ASSERT(theLocker->Lock()); NextSubTest(); snooze(SNOOZE_TIME); NextSubTest(); @@ -71,7 +71,7 @@ void DestructionTest1::TestThread1(void) NextSubTest(); snooze(SNOOZE_TIME); NextSubTest(); - assert(!theLocker->Lock()); + CPPUNIT_ASSERT(!theLocker->Lock()); NextSubTest(); } @@ -89,7 +89,7 @@ void DestructionTest1::TestThread2(void) snooze(SNOOZE_TIME); NextSubTest(); - assert(theLocker->Lock()); + CPPUNIT_ASSERT(theLocker->Lock()); NextSubTest(); snooze(SNOOZE_TIME); NextSubTest(); diff --git a/src/tests/kits/support/blocker/DestructionTest2.cpp b/src/tests/kits/support/blocker/DestructionTest2.cpp index 50100e640c..b796e3b4a1 100644 --- a/src/tests/kits/support/blocker/DestructionTest2.cpp +++ b/src/tests/kits/support/blocker/DestructionTest2.cpp @@ -65,7 +65,7 @@ const bigtime_t SNOOZE_TIME = 200000; void DestructionTest2::TestThread1(void) { - assert(theLocker->LockWithTimeout(SNOOZE_TIME) == B_OK); + CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME) == B_OK); NextSubTest(); snooze(SNOOZE_TIME); NextSubTest(); @@ -73,7 +73,7 @@ void DestructionTest2::TestThread1(void) NextSubTest(); snooze(SNOOZE_TIME); NextSubTest(); - assert(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_BAD_SEM_ID); + CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_BAD_SEM_ID); NextSubTest(); } @@ -93,9 +93,9 @@ void DestructionTest2::TestThread2(void) snooze(SNOOZE_TIME/10); NextSubTest(); - assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); + CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); NextSubTest(); - assert(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_OK); + CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME * 10) == B_OK); NextSubTest(); snooze(SNOOZE_TIME); NextSubTest(); diff --git a/src/tests/kits/support/blocker/LockerTestCase.cpp b/src/tests/kits/support/blocker/LockerTestCase.cpp index a69a38b7e7..9cee56743d 100644 --- a/src/tests/kits/support/blocker/LockerTestCase.cpp +++ b/src/tests/kits/support/blocker/LockerTestCase.cpp @@ -60,11 +60,11 @@ void LockerTestCase::CheckLock(int expectedCount) int32 actualCount = theLocker->CountLocks(); if (expectedCount > 0) { - assert(isLocked); - assert(expectedThread == actualThread); - assert(expectedCount == actualCount); + CPPUNIT_ASSERT(isLocked); + CPPUNIT_ASSERT(expectedThread == actualThread); + CPPUNIT_ASSERT(expectedCount == actualCount); } else { - assert(!((isLocked) && (actualThread == expectedThread))); + CPPUNIT_ASSERT(!((isLocked) && (actualThread == expectedThread))); } return; } diff --git a/src/tests/kits/support/blocker/SemaphoreLockCountTest1.cpp b/src/tests/kits/support/blocker/SemaphoreLockCountTest1.cpp index e161cf0306..9b41ec0d2e 100644 --- a/src/tests/kits/support/blocker/SemaphoreLockCountTest1.cpp +++ b/src/tests/kits/support/blocker/SemaphoreLockCountTest1.cpp @@ -91,30 +91,30 @@ void SemaphoreLockCountTest1::TestThread1(void) SafetyLock theSafetyLock3(&thread3Lock); NextSubTest(); - assert(thread2Lock.Lock()); - assert(thread3Lock.Lock()); + CPPUNIT_ASSERT(thread2Lock.Lock()); + CPPUNIT_ASSERT(thread3Lock.Lock()); NextSubTest(); - assert(CheckLockRequests(1)); - assert(theLocker->Lock()); + CPPUNIT_ASSERT(CheckLockRequests(1)); + CPPUNIT_ASSERT(theLocker->Lock()); NextSubTest(); - assert(CheckLockRequests(2)); + CPPUNIT_ASSERT(CheckLockRequests(2)); NextSubTest(); thread2Lock.Unlock(); snooze(SNOOZE_TIME); - assert(CheckLockRequests(4)); + CPPUNIT_ASSERT(CheckLockRequests(4)); NextSubTest(); thread3Lock.Unlock(); snooze(SNOOZE_TIME); - assert(CheckLockRequests(6)); + CPPUNIT_ASSERT(CheckLockRequests(6)); NextSubTest(); theLocker->Unlock(); snooze(SNOOZE_TIME); - assert(CheckLockRequests(3)); + CPPUNIT_ASSERT(CheckLockRequests(3)); } @@ -134,13 +134,13 @@ void SemaphoreLockCountTest1::TestThread2(void) NextSubTest(); snooze(SNOOZE_TIME / 10); - assert(thread2Lock.Lock()); + CPPUNIT_ASSERT(thread2Lock.Lock()); NextSubTest(); - assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); - assert(theLocker->Lock()); + CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); + CPPUNIT_ASSERT(theLocker->Lock()); int actual = theLocker->CountLockRequests(); - assert((actual == 4) || (actual == 5)); + CPPUNIT_ASSERT((actual == 4) || (actual == 5)); theLocker->Unlock(); } @@ -161,13 +161,13 @@ void SemaphoreLockCountTest1::TestThread3(void) NextSubTest(); snooze(SNOOZE_TIME / 10); - assert(thread3Lock.Lock()); + CPPUNIT_ASSERT(thread3Lock.Lock()); NextSubTest(); - assert(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); - assert(theLocker->Lock()); + CPPUNIT_ASSERT(theLocker->LockWithTimeout(SNOOZE_TIME / 10) == B_TIMED_OUT); + CPPUNIT_ASSERT(theLocker->Lock()); int actual = theLocker->CountLockRequests(); - assert((actual == 4) || (actual == 5)); + CPPUNIT_ASSERT((actual == 4) || (actual == 5)); theLocker->Unlock(); }