Made the Unit test stuff a bit more mwcc/mwld friendly. It still doesn't build right out of the box with our build system, but with a few changes to the build system it can be done (I'm not going to do that, though).

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6640 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2004-02-18 21:38:04 +00:00
parent 5e88de2dea
commit 1b89aa98ff
24 changed files with 149 additions and 35 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
/*! This class is used to serialize access to a TestResult object. You should /*! This class is used to serialize access to a TestResult object. You should
not need to explicitly use it anywhere in your testing code. not need to explicitly use it anywhere in your testing code.
*/ */
class LockerSyncObject : public CppUnit::SynchronizedObject::SynchronizationObject { class CPPUNIT_API LockerSyncObject : public CppUnit::SynchronizedObject::SynchronizationObject {
public: public:
LockerSyncObject() {} LockerSyncObject() {}
virtual ~LockerSyncObject() {} virtual ~LockerSyncObject() {}
+1 -1
View File
@@ -8,7 +8,7 @@
/*! This class is used to serialize access to a TestResult object. You should /*! This class is used to serialize access to a TestResult object. You should
not need to explicitly use it anywhere in your testing code. not need to explicitly use it anywhere in your testing code.
*/ */
class SemaphoreSyncObject : public CppUnit::SynchronizedObject::SynchronizationObject { class CPPUNIT_API SemaphoreSyncObject : public CppUnit::SynchronizedObject::SynchronizationObject {
public: public:
SemaphoreSyncObject(); SemaphoreSyncObject();
virtual ~SemaphoreSyncObject(); virtual ~SemaphoreSyncObject();
+3 -1
View File
@@ -7,6 +7,8 @@
#include <List.h> #include <List.h>
#include <MessageQueue.h> #include <MessageQueue.h>
#include <cppunit/Portability.h>
// TestHandler // TestHandler
class BTestHandler : public BHandler { class BTestHandler : public BHandler {
@@ -21,7 +23,7 @@ private:
// TestApp // TestApp
class BTestApp : public BApplication { class CPPUNIT_API BTestApp : public BApplication {
public: public:
BTestApp(const char *signature); BTestApp(const char *signature);
virtual ~BTestApp(); virtual ~BTestApp();
+1 -1
View File
@@ -6,7 +6,7 @@
#include <SupportDefs.h> #include <SupportDefs.h>
//! Base class for single threaded unit tests //! Base class for single threaded unit tests
class BTestCase : public CppUnit::TestCase { class CPPUNIT_API BTestCase : public CppUnit::TestCase {
public: public:
BTestCase(string Name = ""); BTestCase(string Name = "");
+1 -1
View File
@@ -16,7 +16,7 @@ class CppUnit::Exception;
You should not need to explicitly use this class in any You should not need to explicitly use this class in any
of your tests. of your tests.
*/ */
class BTestListener : public CppUnit::TestListener { class CPPUNIT_API BTestListener : public CppUnit::TestListener {
public: public:
virtual void startTest( CppUnit::Test *test ); virtual void startTest( CppUnit::Test *test );
virtual void addFailure( const CppUnit::TestFailure &failure ); virtual void addFailure( const CppUnit::TestFailure &failure );
+6 -3
View File
@@ -46,7 +46,7 @@ typedef CppUnit::SynchronizedObject::SynchronizationObject SyncObject;
user can get a list of each test installed via AddSuite(), and optionally user can get a list of each test installed via AddSuite(), and optionally
can opt to run only a specified set of them. can opt to run only a specified set of them.
*/ */
class BTestShell { class CPPUNIT_API BTestShell {
public: public:
BTestShell(const string &description = "", SyncObject *syncObject = 0); BTestShell(const string &description = "", SyncObject *syncObject = 0);
virtual ~BTestShell(); virtual ~BTestShell();
@@ -120,13 +120,14 @@ protected:
static const char indent[]; static const char indent[];
bool fListTestsAndExit; bool fListTestsAndExit;
BPath *fTestDir; BPath *fTestDir;
BLocker *fPatchGroupLocker;
int32 fTLSDebuggerCall; int32 fTLSDebuggerCall;
#ifndef NO_ELF_SYMBOL_PATCHING
BLocker *fPatchGroupLocker;
ElfSymbolPatchGroup *fPatchGroup; ElfSymbolPatchGroup *fPatchGroup;
void (*fOldDebuggerHook)(const char*); void (*fOldDebuggerHook)(const char*);
image_id (*fOldLoadAddOnHook)(const char*); image_id (*fOldLoadAddOnHook)(const char*);
status_t (*fOldUnloadAddOnHook)(image_id); status_t (*fOldUnloadAddOnHook)(image_id);
#endif // ! NO_ELF_SYMBOL_PATCHING
//! Prints a brief description of the program. //! Prints a brief description of the program.
virtual void PrintDescription(int argc, char *argv[]); virtual void PrintDescription(int argc, char *argv[]);
@@ -177,6 +178,7 @@ private:
//! Prevents the use of the copy operator. //! Prevents the use of the copy operator.
void operator =( const BTestShell &copy ); void operator =( const BTestShell &copy );
#ifndef NO_ELF_SYMBOL_PATCHING
void _Debugger(const char* message); void _Debugger(const char* message);
image_id _LoadAddOn(const char* path); image_id _LoadAddOn(const char* path);
status_t _UnloadAddOn(image_id image); status_t _UnloadAddOn(image_id image);
@@ -184,6 +186,7 @@ private:
static void _DebuggerHook(const char* message); static void _DebuggerHook(const char* message);
static image_id _LoadAddOnHook(const char* path); static image_id _LoadAddOnHook(const char* path);
static status_t _UnloadAddOnHook(image_id image); static status_t _UnloadAddOnHook(image_id image);
#endif // ! NO_ELF_SYMBOL_PATCHING
}; // class BTestShell }; // class BTestShell
+1 -1
View File
@@ -8,7 +8,7 @@
class CppUnit::TestResult; class CppUnit::TestResult;
//! Groups together a set of tests for a given kit. //! Groups together a set of tests for a given kit.
class BTestSuite : public CppUnit::Test { class CPPUNIT_API BTestSuite : public CppUnit::Test {
public: public:
BTestSuite( string name = "" ); BTestSuite( string name = "" );
virtual ~BTestSuite(); virtual ~BTestSuite();
+1 -3
View File
@@ -3,8 +3,6 @@
class BTestSuite; class BTestSuite;
extern "C" { extern "C" CPPUNIT_API BTestSuite* getTestSuite();
BTestSuite* getTestSuite();
}
#endif // _beos_test_suite_addon_h_ #endif // _beos_test_suite_addon_h_
+8 -6
View File
@@ -4,6 +4,8 @@
#include <string> #include <string>
#include <SupportDefs.h> #include <SupportDefs.h>
#include <cppunit/Portability.h>
// Handy defines :-) // Handy defines :-)
#define CHK CPPUNIT_ASSERT #define CHK CPPUNIT_ASSERT
#define RES DecodeResult #define RES DecodeResult
@@ -13,7 +15,7 @@
// out just what the R5 libraries are returning. // out just what the R5 libraries are returning.
// Returns the same value passed in, so you can // Returns the same value passed in, so you can
// use it inline in tests if necessary. // use it inline in tests if necessary.
status_t DecodeResult(status_t result); extern CPPUNIT_API status_t DecodeResult(status_t result);
// First parameter is equal to the second or third // First parameter is equal to the second or third
template<typename A, typename B, typename C> template<typename A, typename B, typename C>
@@ -26,17 +28,17 @@ Equals(const A &a, const B &b, const C &c)
} }
// Returns a string version of the given integer // Returns a string version of the given integer
string IntToStr(int i); extern CPPUNIT_API string IntToStr(int i);
// Calls system() with the concatenated string of command and parameter. // Calls system() with the concatenated string of command and parameter.
void ExecCommand(const char *command, const char *parameter); extern CPPUNIT_API void ExecCommand(const char *command, const char *parameter);
// Calls system() with the concatenated string of command, parameter1, // Calls system() with the concatenated string of command, parameter1,
// " " and parameter2. // " " and parameter2.
void ExecCommand(const char *command, const char *parameter1, extern CPPUNIT_API void ExecCommand(const char *command, const char *parameter1,
const char *parameter2); const char *parameter2);
// Calls system() with the given command (kind of silly, but it's consistent :-) // Calls system() with the given command (kind of silly, but it's consistent :-)
void ExecCommand(const char *command); extern CPPUNIT_API void ExecCommand(const char *command);
#endif // __beos_test_utils_h__ #endif // __beos_test_utils_h__
+1 -1
View File
@@ -13,7 +13,7 @@
// Helper class to handle thread management // Helper class to handle thread management
template <class TestClass, class ExpectedException> template <class TestClass, class ExpectedException>
class BThreadManager { class CPPUNIT_API BThreadManager {
public: public:
typedef void (TestClass::*ThreadMethod)(); typedef void (TestClass::*ThreadMethod)();
+1 -1
View File
@@ -14,7 +14,7 @@
class TestResult; class TestResult;
template <class TestClass, class ExpectedException = CppUnit::NoExceptionExpected> template <class TestClass, class ExpectedException = CppUnit::NoExceptionExpected>
class BThreadedTestCaller : public CppUnit::TestCase { class CPPUNIT_API BThreadedTestCaller : public CppUnit::TestCase {
public: public:
/*! \brief Pointer to a test function in the given class. /*! \brief Pointer to a test function in the given class.
Each ThreadMethod added with addThread() is run in its own thread. Each ThreadMethod added with addThread() is run in its own thread.
+1 -1
View File
@@ -9,7 +9,7 @@
#include <vector> #include <vector>
//! Base class for single threaded unit tests //! Base class for single threaded unit tests
class BThreadedTestCase : public BTestCase { class CPPUNIT_API BThreadedTestCase : public BTestCase {
public: public:
BThreadedTestCase(string Name = "", string progressSeparator = "."); BThreadedTestCase(string Name = "", string progressSeparator = ".");
virtual ~BThreadedTestCase(); virtual ~BThreadedTestCase();
+5 -1
View File
@@ -41,7 +41,11 @@
// CPPUNIT_API is defined in <config_msvc6.h> if required (building or using as dll) // CPPUNIT_API is defined in <config_msvc6.h> if required (building or using as dll)
#ifndef CPPUNIT_API #ifndef CPPUNIT_API
#define CPPUNIT_API # ifdef BUILDING_CPPUNIT
# define CPPUNIT_API _EXPORT
# else
# define CPPUNIT_API _IMPORT
# endif
#undef CPPUNIT_NEED_DLL_DECL #undef CPPUNIT_NEED_DLL_DECL
#define CPPUNIT_NEED_DLL_DECL 0 #define CPPUNIT_NEED_DLL_DECL 0
#endif #endif
+5 -3
View File
@@ -1,3 +1,5 @@
#include <iostream>
#include "UnitTesterHelper.h" #include "UnitTesterHelper.h"
#include <SemaphoreSyncObject.h> #include <SemaphoreSyncObject.h>
#include <Directory.h> #include <Directory.h>
@@ -23,16 +25,16 @@ int main(int argc, char *argv[]) {
return result; return result;
} }
//const std::string UnitTesterShell::defaultLibDir = "./lib"; //const string UnitTesterShell::defaultLibDir = "./lib";
UnitTesterShell::UnitTesterShell(const std::string &description, SyncObject *syncObject) UnitTesterShell::UnitTesterShell(const string &description, SyncObject *syncObject)
: BTestShell(description, syncObject) : BTestShell(description, syncObject)
{ {
} }
void void
UnitTesterShell::PrintDescription(int argc, char *argv[]) { UnitTesterShell::PrintDescription(int argc, char *argv[]) {
std::string AppName = argv[0]; string AppName = argv[0];
cout << endl; cout << endl;
cout << "This program is the central testing framework for the purpose" << endl; cout << "This program is the central testing framework for the purpose" << endl;
cout << "of testing and verifying the various kits, classes, functions," << endl; cout << "of testing and verifying the various kits, classes, functions," << endl;
+1 -1
View File
@@ -6,7 +6,7 @@
class UnitTesterShell : public BTestShell { class UnitTesterShell : public BTestShell {
public: public:
UnitTesterShell(const std::string &description = "", SyncObject *syncObject = 0); UnitTesterShell(const string &description = "", SyncObject *syncObject = 0);
protected: protected:
virtual void PrintDescription(int argc, char *argv[]); virtual void PrintDescription(int argc, char *argv[]);
virtual void PrintValidArguments(); virtual void PrintValidArguments();
+16 -6
View File
@@ -6,13 +6,20 @@ rule CppUnitLibrary
{ {
# CppUnitLibrary <sources> ; # CppUnitLibrary <sources> ;
local _lib = libcppunit.so ; local _lib = libcppunit.so ;
UseCppUnitHeaders ; UseCppUnitHeaders ;
SetupObjectsDir ; SetupObjectsDir ;
MakeLocateObjects [ FGristFiles $(<) ] ; MakeLocateObjects [ FGristFiles $(1) ] ;
BuildPlatformMain $(_lib) : $(<) ; BuildPlatformMain $(_lib) : $(1) ;
MakeLocate $(_lib) : /boot/home/config/lib ; MakeLocate $(_lib) : /boot/home/config/lib ;
LINKFLAGS on $(_lib) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(_lib)\" ; LINKFLAGS on $(_lib) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(_lib)\" ;
local defines = BUILDING_CPPUNIT ;
if $(OS) = BEOS && $(OSPLAT) = PPC {
defines += NO_ELF_SYMBOL_PATCHING ;
}
ObjectsDefines $(1) : $(defines) ;
} }
CppUnitLibrary CppUnitLibrary
@@ -49,7 +56,10 @@ CppUnitLibrary
; ;
LinkSharedOSLibs libcppunit.so : LinkSharedOSLibs libcppunit.so :
stdc++.r4 stdc++.r4 # is called `mslcpp_4_0' on PPC -- just create a symlink
/boot/develop/lib/x86/libbe.so be
libelfsymbolpatcher.a
; ;
if $(OS) != BEOS || $(OSPLAT) != PPC {
LinkSharedOSLibs libcppunit.so : libelfsymbolpatcher.a ;
}
@@ -1,6 +1,7 @@
#include <SemaphoreSyncObject.h> #include <SemaphoreSyncObject.h>
#include <cppunit/Exception.h> #include <cppunit/Exception.h>
_EXPORT
SemaphoreSyncObject::SemaphoreSyncObject() SemaphoreSyncObject::SemaphoreSyncObject()
: fSemId(create_sem(1, "CppUnitSync")) : fSemId(create_sem(1, "CppUnitSync"))
{ {
@@ -8,16 +9,19 @@ SemaphoreSyncObject::SemaphoreSyncObject()
throw CppUnit::Exception("SemaphoreSyncObject::SemaphoreSyncObject() -- Error creating semaphore"); throw CppUnit::Exception("SemaphoreSyncObject::SemaphoreSyncObject() -- Error creating semaphore");
} }
_EXPORT
SemaphoreSyncObject::~SemaphoreSyncObject() { SemaphoreSyncObject::~SemaphoreSyncObject() {
delete_sem(fSemId); delete_sem(fSemId);
} }
_EXPORT
void void
SemaphoreSyncObject::lock() { SemaphoreSyncObject::lock() {
if (acquire_sem(fSemId) < B_OK) if (acquire_sem(fSemId) < B_OK)
throw CppUnit::Exception("SemaphoreSyncObject::lock() -- Error acquiring semaphore"); throw CppUnit::Exception("SemaphoreSyncObject::lock() -- Error acquiring semaphore");
} }
_EXPORT
void void
SemaphoreSyncObject::unlock() { SemaphoreSyncObject::unlock() {
if (release_sem(fSemId) < B_OK) if (release_sem(fSemId) < B_OK)
+12
View File
@@ -7,6 +7,7 @@
// TestHandler // TestHandler
// MessageReceived // MessageReceived
_EXPORT
void void
BTestHandler::MessageReceived(BMessage *message) BTestHandler::MessageReceived(BMessage *message)
{ {
@@ -18,6 +19,7 @@ BTestHandler::MessageReceived(BMessage *message)
} }
// Queue // Queue
_EXPORT
BMessageQueue & BMessageQueue &
BTestHandler::Queue() BTestHandler::Queue()
{ {
@@ -28,6 +30,7 @@ BTestHandler::Queue()
// TestApp // TestApp
// constructor // constructor
_EXPORT
BTestApp::BTestApp(const char *signature) BTestApp::BTestApp(const char *signature)
: BApplication(signature), : BApplication(signature),
fAppThread(B_ERROR), fAppThread(B_ERROR),
@@ -38,6 +41,7 @@ BTestApp::BTestApp(const char *signature)
} }
// destructor // destructor
_EXPORT
BTestApp::~BTestApp() BTestApp::~BTestApp()
{ {
int32 count = fHandlers.CountItems(); int32 count = fHandlers.CountItems();
@@ -46,6 +50,7 @@ BTestApp::~BTestApp()
} }
// Init // Init
_EXPORT
status_t status_t
BTestApp::Init() BTestApp::Init()
{ {
@@ -65,6 +70,7 @@ BTestApp::Init()
} }
// Terminate // Terminate
_EXPORT
void void
BTestApp::Terminate() BTestApp::Terminate()
{ {
@@ -74,12 +80,14 @@ BTestApp::Terminate()
} }
// ReadyToRun // ReadyToRun
_EXPORT
void void
BTestApp::ReadyToRun() BTestApp::ReadyToRun()
{ {
} }
// CreateTestHandler // CreateTestHandler
_EXPORT
BTestHandler * BTestHandler *
BTestApp::CreateTestHandler() BTestApp::CreateTestHandler()
{ {
@@ -92,6 +100,7 @@ BTestApp::CreateTestHandler()
} }
// DeleteTestHandler // DeleteTestHandler
_EXPORT
bool bool
BTestApp::DeleteTestHandler(BTestHandler *handler) BTestApp::DeleteTestHandler(BTestHandler *handler)
{ {
@@ -107,6 +116,7 @@ BTestApp::DeleteTestHandler(BTestHandler *handler)
} }
// Handler // Handler
_EXPORT
BTestHandler & BTestHandler &
BTestApp::Handler() BTestApp::Handler()
{ {
@@ -116,6 +126,7 @@ BTestApp::Handler()
} }
// TestHandlerAt // TestHandlerAt
_EXPORT
BTestHandler * BTestHandler *
BTestApp::TestHandlerAt(int32 index) BTestApp::TestHandlerAt(int32 index)
{ {
@@ -124,6 +135,7 @@ BTestApp::TestHandlerAt(int32 index)
} }
// _AppThreadStart // _AppThreadStart
_EXPORT
int32 int32
BTestApp::_AppThreadStart(void *data) BTestApp::_AppThreadStart(void *data)
{ {
+7
View File
@@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
_EXPORT
BTestCase::BTestCase(string name) BTestCase::BTestCase(string name)
: CppUnit::TestCase(name) : CppUnit::TestCase(name)
, fValidCWD(false) , fValidCWD(false)
@@ -11,12 +12,14 @@ BTestCase::BTestCase(string name)
{ {
} }
_EXPORT
void void
BTestCase::tearDown() { BTestCase::tearDown() {
if (fSubTestNum != 0) if (fSubTestNum != 0)
NextSubTestBlock(); NextSubTestBlock();
} }
_EXPORT
void void
BTestCase::NextSubTest() { BTestCase::NextSubTest() {
if (BTestShell::GlobalBeVerbose()) { if (BTestShell::GlobalBeVerbose()) {
@@ -25,12 +28,14 @@ BTestCase::NextSubTest() {
} }
} }
_EXPORT
void void
BTestCase::NextSubTestBlock() { BTestCase::NextSubTestBlock() {
if (BTestShell::GlobalBeVerbose()) if (BTestShell::GlobalBeVerbose())
printf("\n"); printf("\n");
} }
_EXPORT
void void
BTestCase::Outputf(const char *str, ...) { BTestCase::Outputf(const char *str, ...) {
if (BTestShell::GlobalBeVerbose()) { if (BTestShell::GlobalBeVerbose()) {
@@ -43,6 +48,7 @@ BTestCase::Outputf(const char *str, ...) {
} }
/*! To return to the last saved working directory, call RestoreCWD(). */ /*! To return to the last saved working directory, call RestoreCWD(). */
_EXPORT
void void
BTestCase::SaveCWD() { BTestCase::SaveCWD() {
fValidCWD = getcwd(fCurrentWorkingDir, B_PATH_NAME_LENGTH); fValidCWD = getcwd(fCurrentWorkingDir, B_PATH_NAME_LENGTH);
@@ -53,6 +59,7 @@ BTestCase::SaveCWD() {
changed to alternate. If alternate is null, the current working directory changed to alternate. If alternate is null, the current working directory
is not modified. is not modified.
*/ */
_EXPORT
void void
BTestCase::RestoreCWD(const char *alternate) { BTestCase::RestoreCWD(const char *alternate) {
if (fValidCWD) if (fValidCWD)
+4
View File
@@ -7,6 +7,7 @@
#include <stdio.h> #include <stdio.h>
#include <OS.h> #include <OS.h>
_EXPORT
void void
BTestListener::startTest( CppUnit::Test *test ) { BTestListener::startTest( CppUnit::Test *test ) {
fOkay = true; fOkay = true;
@@ -14,6 +15,7 @@ BTestListener::startTest( CppUnit::Test *test ) {
startTime = real_time_clock_usecs(); startTime = real_time_clock_usecs();
} }
_EXPORT
void void
BTestListener::addFailure( const CppUnit::TestFailure &failure ) { BTestListener::addFailure( const CppUnit::TestFailure &failure ) {
fOkay = false; fOkay = false;
@@ -26,6 +28,7 @@ BTestListener::addFailure( const CppUnit::TestFailure &failure ) {
cout << endl; cout << endl;
} }
_EXPORT
void void
BTestListener::endTest( CppUnit::Test *test ) { BTestListener::endTest( CppUnit::Test *test ) {
bigtime_t length = real_time_clock_usecs() - startTime; bigtime_t length = real_time_clock_usecs() - startTime;
@@ -37,6 +40,7 @@ BTestListener::endTest( CppUnit::Test *test ) {
cout << endl; cout << endl;
} }
_EXPORT
void void
BTestListener::printTime(bigtime_t time) { BTestListener::printTime(bigtime_t time) {
// Print out the elapsed time all pretty and stuff: // Print out the elapsed time all pretty and stuff:
+44 -2
View File
@@ -21,32 +21,42 @@
#include <TestShell.h> #include <TestShell.h>
#include <TestListener.h> #include <TestListener.h>
#include <ElfSymbolPatcher.h>
BTestShell *BTestShell::fGlobalShell = NULL; #ifndef NO_ELF_SYMBOL_PATCHING
# include <ElfSymbolPatcher.h>
#endif
_EXPORT BTestShell *BTestShell::fGlobalShell = NULL;
const char BTestShell::indent[] = " "; const char BTestShell::indent[] = " ";
_EXPORT
BTestShell::BTestShell(const string &description, SyncObject *syncObject) BTestShell::BTestShell(const string &description, SyncObject *syncObject)
: fVerbosityLevel(v2) : fVerbosityLevel(v2)
, fTestResults(syncObject) , fTestResults(syncObject)
, fDescription(description) , fDescription(description)
, fListTestsAndExit(false) , fListTestsAndExit(false)
, fTestDir(NULL) , fTestDir(NULL)
#ifndef NO_ELF_SYMBOL_PATCHING
, fPatchGroupLocker(new(nothrow) BLocker) , fPatchGroupLocker(new(nothrow) BLocker)
, fPatchGroup(NULL) , fPatchGroup(NULL)
, fOldDebuggerHook(NULL) , fOldDebuggerHook(NULL)
, fOldLoadAddOnHook(NULL) , fOldLoadAddOnHook(NULL)
, fOldUnloadAddOnHook(NULL) , fOldUnloadAddOnHook(NULL)
#endif // ! NO_ELF_SYMBOL_PATCHING
{ {
fTLSDebuggerCall = tls_allocate(); fTLSDebuggerCall = tls_allocate();
} }
_EXPORT
BTestShell::~BTestShell() { BTestShell::~BTestShell() {
delete fTestDir; delete fTestDir;
#ifndef NO_ELF_SYMBOL_PATCHING
delete fPatchGroupLocker; delete fPatchGroupLocker;
#endif // ! NO_ELF_SYMBOL_PATCHING
} }
_EXPORT
status_t status_t
BTestShell::AddSuite(BTestSuite *suite) { BTestShell::AddSuite(BTestSuite *suite) {
if (suite) { if (suite) {
@@ -71,6 +81,7 @@ BTestShell::AddSuite(BTestSuite *suite) {
return B_BAD_VALUE; return B_BAD_VALUE;
} }
_EXPORT
void void
BTestShell::AddTest(const string &name, CppUnit::Test *test) { BTestShell::AddTest(const string &name, CppUnit::Test *test) {
if (test != NULL) if (test != NULL)
@@ -79,6 +90,7 @@ BTestShell::AddTest(const string &name, CppUnit::Test *test) {
fTests.erase(name); fTests.erase(name);
} }
_EXPORT
int32 int32
BTestShell::LoadSuitesFrom(BDirectory *libDir) { BTestShell::LoadSuitesFrom(BDirectory *libDir) {
if (!libDir || libDir->InitCheck() != B_OK) if (!libDir || libDir->InitCheck() != B_OK)
@@ -117,6 +129,7 @@ BTestShell::LoadSuitesFrom(BDirectory *libDir) {
return count; return count;
} }
_EXPORT
int int
BTestShell::Run(int argc, char *argv[]) { BTestShell::Run(int argc, char *argv[]) {
// Make note of which directory we started in // Make note of which directory we started in
@@ -206,11 +219,13 @@ BTestShell::Run(int argc, char *argv[]) {
return 0; return 0;
} }
_EXPORT
BTestShell::VerbosityLevel BTestShell::VerbosityLevel
BTestShell::Verbosity() const { BTestShell::Verbosity() const {
return fVerbosityLevel; return fVerbosityLevel;
} }
_EXPORT
const char* const char*
BTestShell::TestDir() const { BTestShell::TestDir() const {
return (fTestDir ? fTestDir->Path() : NULL); return (fTestDir ? fTestDir->Path() : NULL);
@@ -222,6 +237,7 @@ BTestShell::TestDir() const {
A subsequent call of debugger() will be intercepted and a respective A subsequent call of debugger() will be intercepted and a respective
flag will be set. WasDebuggerCalled() will then return \c true. flag will be set. WasDebuggerCalled() will then return \c true.
*/ */
_EXPORT
void void
BTestShell::ExpectDebuggerCall() BTestShell::ExpectDebuggerCall()
{ {
@@ -238,6 +254,7 @@ BTestShell::ExpectDebuggerCall()
\return \c true, if debugger() has been called by the current thread since \return \c true, if debugger() has been called by the current thread since
the last invocation of ExpectDebuggerCall(), \c false otherwise. the last invocation of ExpectDebuggerCall(), \c false otherwise.
*/ */
_EXPORT
bool bool
BTestShell::WasDebuggerCalled() BTestShell::WasDebuggerCalled()
{ {
@@ -246,11 +263,13 @@ BTestShell::WasDebuggerCalled()
return ((int)var > 1); return ((int)var > 1);
} }
_EXPORT
void void
BTestShell::PrintDescription(int argc, char *argv[]) { BTestShell::PrintDescription(int argc, char *argv[]) {
cout << endl << fDescription; cout << endl << fDescription;
} }
_EXPORT
void void
BTestShell::PrintHelp() { BTestShell::PrintHelp() {
cout << endl; cout << endl;
@@ -260,6 +279,7 @@ BTestShell::PrintHelp() {
} }
_EXPORT
void void
BTestShell::PrintValidArguments() { BTestShell::PrintValidArguments() {
cout << indent << "--help Displays this help text plus some other garbage" << endl; cout << indent << "--help Displays this help text plus some other garbage" << endl;
@@ -281,6 +301,7 @@ BTestShell::PrintValidArguments() {
cout << indent << " libraries" << endl; cout << indent << " libraries" << endl;
} }
_EXPORT
void void
BTestShell::PrintInstalledTests() { BTestShell::PrintInstalledTests() {
// Print out the list of installed suites // Print out the list of installed suites
@@ -302,6 +323,7 @@ BTestShell::PrintInstalledTests() {
cout << endl; cout << endl;
} }
_EXPORT
bool bool
BTestShell::ProcessArguments(int argc, char *argv[]) { BTestShell::ProcessArguments(int argc, char *argv[]) {
// If we're given no parameters, the default settings // If we're given no parameters, the default settings
@@ -321,6 +343,7 @@ BTestShell::ProcessArguments(int argc, char *argv[]) {
return true; return true;
} }
_EXPORT
bool bool
BTestShell::ProcessArgument(string arg, int argc, char *argv[]) { BTestShell::ProcessArgument(string arg, int argc, char *argv[]) {
if (arg == "--help") { if (arg == "--help") {
@@ -347,6 +370,7 @@ BTestShell::ProcessArgument(string arg, int argc, char *argv[]) {
return true; return true;
} }
_EXPORT
void void
BTestShell::InitOutput() { BTestShell::InitOutput() {
// For vebosity level 2, we output info about each test // For vebosity level 2, we output info about each test
@@ -361,6 +385,7 @@ BTestShell::InitOutput() {
fTestResults.addListener(&fResultsCollector); fTestResults.addListener(&fResultsCollector);
} }
_EXPORT
void void
BTestShell::PrintResults() { BTestShell::PrintResults() {
@@ -411,6 +436,7 @@ BTestShell::PrintResults() {
} }
_EXPORT
void void
BTestShell::LoadDynamicSuites() { BTestShell::LoadDynamicSuites() {
if (Verbosity() >= v3) { if (Verbosity() >= v3) {
@@ -447,6 +473,7 @@ BTestShell::LoadDynamicSuites() {
} }
_EXPORT
void void
BTestShell::UpdateTestDir(char *argv[]) { BTestShell::UpdateTestDir(char *argv[]) {
BPath path(argv[0]); BPath path(argv[0]);
@@ -465,9 +492,11 @@ BTestShell::UpdateTestDir(char *argv[]) {
load_add_on() and unload_add_on() are patches as well, to keep the load_add_on() and unload_add_on() are patches as well, to keep the
patch group up to date, when images are loaded/unloaded. patch group up to date, when images are loaded/unloaded.
*/ */
_EXPORT
void void
BTestShell::InstallPatches() BTestShell::InstallPatches()
{ {
#ifndef NO_ELF_SYMBOL_PATCHING
if (fPatchGroup) { if (fPatchGroup) {
cerr << "BTestShell::InstallPatches(): Patch group already exist!" cerr << "BTestShell::InstallPatches(): Patch group already exist!"
<< endl; << endl;
@@ -503,14 +532,17 @@ BTestShell::InstallPatches()
<< endl; << endl;
UninstallPatches(); UninstallPatches();
} }
#endif // ! NO_ELF_SYMBOL_PATCHING
} }
// UninstallPatches // UninstallPatches
/*! \brief Undoes the patches applied by InstallPatches(). /*! \brief Undoes the patches applied by InstallPatches().
*/ */
_EXPORT
void void
BTestShell::UninstallPatches() BTestShell::UninstallPatches()
{ {
#ifndef NO_ELF_SYMBOL_PATCHING
BAutolock locker(fPatchGroupLocker); BAutolock locker(fPatchGroupLocker);
if (!locker.IsLocked()) { if (!locker.IsLocked()) {
cerr << "BTestShell::UninstallPatches(): " cerr << "BTestShell::UninstallPatches(): "
@@ -522,9 +554,13 @@ BTestShell::UninstallPatches()
delete fPatchGroup; delete fPatchGroup;
fPatchGroup = NULL; fPatchGroup = NULL;
} }
#endif // ! NO_ELF_SYMBOL_PATCHING
} }
#ifndef NO_ELF_SYMBOL_PATCHING
// _Debugger // _Debugger
_EXPORT
void void
BTestShell::_Debugger(const char *message) BTestShell::_Debugger(const char *message)
{ {
@@ -546,6 +582,7 @@ cout << "debugger() called: " << message << endl;
} }
// _LoadAddOn // _LoadAddOn
_EXPORT
image_id image_id
BTestShell::_LoadAddOn(const char *path) BTestShell::_LoadAddOn(const char *path)
{ {
@@ -560,6 +597,7 @@ BTestShell::_LoadAddOn(const char *path)
} }
// _UnloadAddOn // _UnloadAddOn
_EXPORT
status_t status_t
BTestShell::_UnloadAddOn(image_id image) BTestShell::_UnloadAddOn(image_id image)
{ {
@@ -577,6 +615,7 @@ BTestShell::_UnloadAddOn(image_id image)
} }
// _DebuggerHook // _DebuggerHook
_EXPORT
void void
BTestShell::_DebuggerHook(const char *message) BTestShell::_DebuggerHook(const char *message)
{ {
@@ -584,6 +623,7 @@ BTestShell::_DebuggerHook(const char *message)
} }
// _LoadAddOnHook // _LoadAddOnHook
_EXPORT
image_id image_id
BTestShell::_LoadAddOnHook(const char *path) BTestShell::_LoadAddOnHook(const char *path)
{ {
@@ -591,9 +631,11 @@ BTestShell::_LoadAddOnHook(const char *path)
} }
// _UnloadAddOnHook // _UnloadAddOnHook
_EXPORT
status_t status_t
BTestShell::_UnloadAddOnHook(image_id image) BTestShell::_UnloadAddOnHook(image_id image)
{ {
return fGlobalShell->_UnloadAddOn(image); return fGlobalShell->_UnloadAddOn(image);
} }
#endif // ! NO_ELF_SYMBOL_PATCHING
+9
View File
@@ -3,18 +3,21 @@
#include <cppunit/TestResult.h> #include <cppunit/TestResult.h>
// Default constructor // Default constructor
_EXPORT
BTestSuite::BTestSuite( string name ) BTestSuite::BTestSuite( string name )
: fName(name) : fName(name)
{ {
} }
// Destructor // Destructor
_EXPORT
BTestSuite::~BTestSuite() { BTestSuite::~BTestSuite() {
deleteContents(); deleteContents();
} }
// Deletes all tests in the suite. // Deletes all tests in the suite.
_EXPORT
void void
BTestSuite::deleteContents() { BTestSuite::deleteContents() {
for ( map<string, CppUnit::Test*>::iterator it = fTests.begin(); for ( map<string, CppUnit::Test*>::iterator it = fTests.begin();
@@ -26,6 +29,7 @@ BTestSuite::deleteContents() {
/// Runs the tests and collects their result in a TestResult. /// Runs the tests and collects their result in a TestResult.
_EXPORT
void void
BTestSuite::run( CppUnit::TestResult *result ) { BTestSuite::run( CppUnit::TestResult *result ) {
for ( map<string, CppUnit::Test*>::iterator it = fTests.begin(); for ( map<string, CppUnit::Test*>::iterator it = fTests.begin();
@@ -42,6 +46,7 @@ BTestSuite::run( CppUnit::TestResult *result ) {
// Counts the number of test cases that will be run by this test. // Counts the number of test cases that will be run by this test.
_EXPORT
int int
BTestSuite::countTestCases() const { BTestSuite::countTestCases() const {
int count = 0; int count = 0;
@@ -56,6 +61,7 @@ BTestSuite::countTestCases() const {
// Adds a test to the suite. // Adds a test to the suite.
_EXPORT
void void
BTestSuite::addTest(string name, CppUnit::Test *test) { BTestSuite::addTest(string name, CppUnit::Test *test) {
fTests[name] = test; fTests[name] = test;
@@ -63,6 +69,7 @@ BTestSuite::addTest(string name, CppUnit::Test *test) {
// Returns a string representation of the test suite. // Returns a string representation of the test suite.
_EXPORT
string string
BTestSuite::toString() const { BTestSuite::toString() const {
return "suite " + getName(); return "suite " + getName();
@@ -70,12 +77,14 @@ BTestSuite::toString() const {
// Returns the name of the test suite. // Returns the name of the test suite.
_EXPORT
string string
BTestSuite::getName() const { BTestSuite::getName() const {
return fName; return fName;
} }
_EXPORT
const map<string, CppUnit::Test*> & const map<string, CppUnit::Test*> &
BTestSuite::getTests() const { BTestSuite::getTests() const {
return fTests; return fTests;
+5
View File
@@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#include <iostream> #include <iostream>
_EXPORT
status_t DecodeResult(status_t result) { status_t DecodeResult(status_t result) {
if (!BTestShell::GlobalBeVerbose()) if (!BTestShell::GlobalBeVerbose())
return result; return result;
@@ -178,17 +179,20 @@ status_t DecodeResult(status_t result) {
return result; return result;
} }
_EXPORT
string IntToStr(int i) { string IntToStr(int i) {
char num[32]; char num[32];
sprintf(num, "%d", i); sprintf(num, "%d", i);
return string(num); return string(num);
} }
_EXPORT
void ExecCommand(const char *command) { void ExecCommand(const char *command) {
if (command) if (command)
system(command); system(command);
} }
_EXPORT
void ExecCommand(const char *command, const char *parameter) { void ExecCommand(const char *command, const char *parameter) {
if (command && parameter) { if (command && parameter) {
char *cmdLine = new char[strlen(command) + strlen(parameter) + 1]; char *cmdLine = new char[strlen(command) + strlen(parameter) + 1];
@@ -199,6 +203,7 @@ void ExecCommand(const char *command, const char *parameter) {
} }
} }
_EXPORT
void ExecCommand(const char *command, const char *parameter1, void ExecCommand(const char *command, const char *parameter1,
const char *parameter2) { const char *parameter2) {
if (command && parameter1 && parameter2) { if (command && parameter1 && parameter2) {
+11 -1
View File
@@ -1,8 +1,10 @@
#include <TestShell.h> #include <TestShell.h>
#include <ThreadedTestCase.h> #include <ThreadedTestCase.h>
#include <Autolock.h> #include <Autolock.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h>
_EXPORT
BThreadedTestCase::BThreadedTestCase(string name, string progressSeparator) BThreadedTestCase::BThreadedTestCase(string name, string progressSeparator)
: BTestCase(name) : BTestCase(name)
, fProgressSeparator(progressSeparator) , fProgressSeparator(progressSeparator)
@@ -10,6 +12,7 @@ BThreadedTestCase::BThreadedTestCase(string name, string progressSeparator)
{ {
} }
_EXPORT
BThreadedTestCase::~BThreadedTestCase() { BThreadedTestCase::~BThreadedTestCase() {
// Kill our locker // Kill our locker
delete fUpdateLock; delete fUpdateLock;
@@ -23,6 +26,7 @@ BThreadedTestCase::~BThreadedTestCase() {
} }
} }
_EXPORT
void void
BThreadedTestCase::NextSubTest() { BThreadedTestCase::NextSubTest() {
// Find out what thread we're in // Find out what thread we're in
@@ -47,6 +51,7 @@ BThreadedTestCase::NextSubTest() {
BTestCase::NextSubTest(); BTestCase::NextSubTest();
} }
_EXPORT
void void
BThreadedTestCase::Outputf(const char *str, ...) { BThreadedTestCase::Outputf(const char *str, ...) {
if (BTestShell::GlobalBeVerbose()) { if (BTestShell::GlobalBeVerbose()) {
@@ -78,6 +83,7 @@ BThreadedTestCase::Outputf(const char *str, ...) {
} }
} }
_EXPORT
void void
BThreadedTestCase::InitThreadInfo(thread_id id, string threadName) { BThreadedTestCase::InitThreadInfo(thread_id id, string threadName) {
BAutolock lock(fUpdateLock); // Lock the number map BAutolock lock(fUpdateLock); // Lock the number map
@@ -94,6 +100,7 @@ BThreadedTestCase::InitThreadInfo(thread_id id, string threadName) {
} }
} }
_EXPORT
bool bool
BThreadedTestCase::RegisterForUse() { BThreadedTestCase::RegisterForUse() {
if (!fInUse) { if (!fInUse) {
@@ -103,17 +110,20 @@ BThreadedTestCase::RegisterForUse() {
return false; return false;
} }
_EXPORT
void void
BThreadedTestCase::UnregisterForUse() { BThreadedTestCase::UnregisterForUse() {
fInUse = false; fInUse = false;
} }
_EXPORT
vector<string>& vector<string>&
BThreadedTestCase::AcquireUpdateList() { BThreadedTestCase::AcquireUpdateList() {
fUpdateLock->Lock(); fUpdateLock->Lock();
return fUpdateList; return fUpdateList;
} }
_EXPORT
void void
BThreadedTestCase::ReleaseUpdateList() { BThreadedTestCase::ReleaseUpdateList() {
fUpdateLock->Unlock(); fUpdateLock->Unlock();