2002-07-09 16:24:59 +04:00
|
|
|
#ifndef _beos_test_shell_h_
|
|
|
|
#define _beos_test_shell_h_
|
|
|
|
|
2002-07-11 07:28:37 +04:00
|
|
|
#include <LockerSyncObject.h>
|
|
|
|
#include <cppunit/Exception.h>
|
|
|
|
#include <cppunit/Test.h>
|
|
|
|
#include <cppunit/TestListener.h>
|
|
|
|
#include <cppunit/TestResult.h>
|
|
|
|
#include <cppunit/TestResultCollector.h>
|
2003-11-10 03:45:18 +03:00
|
|
|
#include <image.h>
|
2002-07-15 10:52:57 +04:00
|
|
|
#include <TestSuite.h>
|
2002-07-11 07:28:37 +04:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-07-15 10:52:57 +04:00
|
|
|
class BDirectory;
|
2003-11-10 03:45:18 +03:00
|
|
|
class BLocker;
|
2003-10-13 06:26:22 +04:00
|
|
|
class BPath;
|
2002-07-15 10:52:57 +04:00
|
|
|
|
2003-11-10 03:45:18 +03:00
|
|
|
class ElfSymbolPatchGroup;
|
|
|
|
|
2002-07-11 07:28:37 +04:00
|
|
|
// Defines SuiteFunction to be a pointer to a function that
|
|
|
|
// takes no arguments and returns a pointer to a CppUnit::Test
|
|
|
|
typedef CppUnit::Test* (*SuiteFunction)(void);
|
|
|
|
|
|
|
|
// This is just absurd to have to type...
|
|
|
|
typedef CppUnit::SynchronizedObject::SynchronizationObject SyncObject;
|
|
|
|
|
2003-11-10 03:45:18 +03:00
|
|
|
/*! \brief Executes a statement that is supposed to call debugger().
|
|
|
|
An exception is thrown if the debugger is not invoked by the
|
|
|
|
statement.
|
|
|
|
*/
|
|
|
|
#define CPPUNIT_ASSERT_DEBUGGER(statement) \
|
|
|
|
BTestShell::GlobalShell()->ExpectDebuggerCall(); \
|
|
|
|
statement; \
|
|
|
|
::CppUnit::Asserter::failIf( \
|
|
|
|
!BTestShell::GlobalShell()->WasDebuggerCalled(), \
|
|
|
|
(#statement), \
|
|
|
|
CPPUNIT_SOURCELINE() );
|
|
|
|
|
|
|
|
|
2002-07-11 07:28:37 +04:00
|
|
|
//! BeOS savvy command line interface for the CppUnit testing framework.
|
|
|
|
/*! This class provides a fully functional command-line testing interface
|
|
|
|
built on top of the CppUnit testing library. You add named test suites
|
|
|
|
via AddSuite(), and then call Run(), which does all the dirty work. The
|
|
|
|
user can get a list of each test installed via AddSuite(), and optionally
|
|
|
|
can opt to run only a specified set of them.
|
|
|
|
*/
|
2004-02-19 00:38:04 +03:00
|
|
|
class CPPUNIT_API BTestShell {
|
2002-07-09 16:24:59 +04:00
|
|
|
public:
|
2004-02-17 22:57:58 +03:00
|
|
|
BTestShell(const string &description = "", SyncObject *syncObject = 0);
|
2002-07-18 05:03:19 +04:00
|
|
|
virtual ~BTestShell();
|
2002-07-11 07:28:37 +04:00
|
|
|
|
2002-07-15 10:52:57 +04:00
|
|
|
// This function is used to add the tests for a given kit (as contained
|
|
|
|
// in a BTestSuite object) to the list of available tests. The shell assumes
|
|
|
|
// ownership of the BTestSuite object. Each test in the kit is added to
|
2004-02-17 22:57:58 +03:00
|
|
|
// the list of tests via a call to AddTest(string
|
2002-07-15 10:52:57 +04:00
|
|
|
status_t AddSuite(BTestSuite *kit);
|
|
|
|
|
2002-07-11 07:28:37 +04:00
|
|
|
// This function is used to add test suites to the list of available
|
|
|
|
// tests. A SuiteFunction is just a function that takes no parameters
|
|
|
|
// and returns a pointer to a CppUnit::Test object. Return NULL at
|
|
|
|
// your own risk :-). The name given is the name that will be presented
|
|
|
|
// when the program is run with "--list" as an argument. Usually the
|
|
|
|
// given suite would be a test suite for an entire class, but that's
|
|
|
|
// not a requirement.
|
2004-02-17 22:57:58 +03:00
|
|
|
void AddTest(const string &name, CppUnit::Test* test);
|
2002-07-15 10:52:57 +04:00
|
|
|
|
|
|
|
// This function loads all the test addons it finds in the given
|
|
|
|
// directory, returning the number of tests actually loaded.
|
|
|
|
int32 LoadSuitesFrom(BDirectory *libDir);
|
2002-07-11 07:28:37 +04:00
|
|
|
|
|
|
|
// This is the function you call after you've added all your test
|
|
|
|
// suites with calls to AddSuite(). It runs the test, or displays
|
|
|
|
// help, or lists installed tests, or whatever, depending on the
|
|
|
|
// command-line arguments passed in.
|
2002-07-09 16:24:59 +04:00
|
|
|
int Run(int argc, char *argv[]);
|
2002-07-11 07:28:37 +04:00
|
|
|
|
|
|
|
// Verbosity Level enumeration and accessor function
|
2002-07-24 04:12:02 +04:00
|
|
|
enum VerbosityLevel { v0, v1, v2, v3, v4 };
|
2002-07-11 07:28:37 +04:00
|
|
|
VerbosityLevel Verbosity() const;
|
|
|
|
|
|
|
|
// Returns true if verbosity is high enough that individual tests are
|
|
|
|
// allowed to make noise.
|
|
|
|
bool BeVerbose() const { return Verbosity() >= v2; };
|
2002-07-17 14:50:55 +04:00
|
|
|
|
|
|
|
static bool GlobalBeVerbose() { return (fGlobalShell ? fGlobalShell->BeVerbose() : true); };
|
|
|
|
|
|
|
|
// Returns a pointer to a global BTestShell object. This function is
|
|
|
|
// something of a hack, used to give BTestCase and its subclasses
|
|
|
|
// access to verbosity information. Don't rely on it if you don't
|
|
|
|
// have to (and always make sure the pointer it returns isn't NULL
|
|
|
|
// before you try to use it :-).
|
2002-07-18 05:03:19 +04:00
|
|
|
static BTestShell* GlobalShell() { return fGlobalShell; };
|
2002-07-15 10:52:57 +04:00
|
|
|
|
2002-07-17 14:50:55 +04:00
|
|
|
// Sets the global BTestShell pointer. The BTestShell class does
|
|
|
|
// not assume ownership of the object.
|
2002-07-18 05:03:19 +04:00
|
|
|
static void SetGlobalShell(BTestShell *shell) { fGlobalShell = shell; };
|
|
|
|
|
|
|
|
const char* TestDir() const;
|
|
|
|
static const char* GlobalTestDir() { return (fGlobalShell ? fGlobalShell->TestDir() : NULL); };
|
|
|
|
|
2003-11-10 03:45:18 +03:00
|
|
|
void ExpectDebuggerCall();
|
|
|
|
bool WasDebuggerCalled();
|
2002-07-11 07:28:37 +04:00
|
|
|
|
2002-07-19 10:45:28 +04:00
|
|
|
protected:
|
2004-02-17 22:57:58 +03:00
|
|
|
typedef map<string, CppUnit::Test*> TestMap;
|
|
|
|
typedef map<string, BTestSuite*> SuiteMap;
|
2002-07-19 10:45:28 +04:00
|
|
|
|
2002-07-11 07:28:37 +04:00
|
|
|
VerbosityLevel fVerbosityLevel;
|
2004-02-17 22:57:58 +03:00
|
|
|
set<string> fTestsToRun;
|
|
|
|
set<string> fSuitesToRun;
|
2002-07-19 10:45:28 +04:00
|
|
|
TestMap fTests;
|
|
|
|
SuiteMap fSuites;
|
2004-02-17 22:57:58 +03:00
|
|
|
set<string> fLibDirs;
|
2002-07-11 07:28:37 +04:00
|
|
|
CppUnit::TestResult fTestResults;
|
|
|
|
CppUnit::TestResultCollector fResultsCollector;
|
2004-02-17 22:57:58 +03:00
|
|
|
string fDescription;
|
2002-07-15 10:52:57 +04:00
|
|
|
static BTestShell* fGlobalShell;
|
2002-07-17 14:50:55 +04:00
|
|
|
static const char indent[];
|
|
|
|
bool fListTestsAndExit;
|
2002-07-18 05:03:19 +04:00
|
|
|
BPath *fTestDir;
|
2003-11-10 03:45:18 +03:00
|
|
|
int32 fTLSDebuggerCall;
|
2004-02-19 00:38:04 +03:00
|
|
|
#ifndef NO_ELF_SYMBOL_PATCHING
|
|
|
|
BLocker *fPatchGroupLocker;
|
2003-11-10 03:45:18 +03:00
|
|
|
ElfSymbolPatchGroup *fPatchGroup;
|
|
|
|
void (*fOldDebuggerHook)(const char*);
|
|
|
|
image_id (*fOldLoadAddOnHook)(const char*);
|
|
|
|
status_t (*fOldUnloadAddOnHook)(image_id);
|
2004-02-19 00:38:04 +03:00
|
|
|
#endif // ! NO_ELF_SYMBOL_PATCHING
|
2002-07-11 07:28:37 +04:00
|
|
|
|
2002-07-17 14:50:55 +04:00
|
|
|
//! Prints a brief description of the program.
|
2002-07-11 07:28:37 +04:00
|
|
|
virtual void PrintDescription(int argc, char *argv[]);
|
|
|
|
|
2002-07-17 14:50:55 +04:00
|
|
|
//! Prints out command line argument instructions
|
2002-07-11 07:28:37 +04:00
|
|
|
void PrintHelp();
|
2002-07-17 14:50:55 +04:00
|
|
|
|
|
|
|
/*! \brief Prints out the list of valid command line arguments.
|
|
|
|
Called by PrintHelp().
|
|
|
|
*/
|
|
|
|
virtual void PrintValidArguments();
|
2002-07-11 07:28:37 +04:00
|
|
|
|
2002-07-17 14:50:55 +04:00
|
|
|
//! Prints out a list of all the currently available tests
|
|
|
|
void PrintInstalledTests();
|
|
|
|
|
|
|
|
/*! \brief Handles command line arguments; returns true if everything goes
|
|
|
|
okay, false if not (or if the program just needs to terminate without
|
|
|
|
running any tests). Modifies settings in "settings" as necessary.
|
|
|
|
*/
|
2002-07-11 07:28:37 +04:00
|
|
|
bool ProcessArguments(int argc, char *argv[]);
|
2002-07-17 14:50:55 +04:00
|
|
|
|
|
|
|
//! Processes a single argument, given by the \c arg parameter.
|
2004-02-17 22:57:58 +03:00
|
|
|
virtual bool ProcessArgument(string arg, int argc, char *argv[]);
|
2002-07-11 07:28:37 +04:00
|
|
|
|
2002-07-17 14:50:55 +04:00
|
|
|
//! Makes any necessary pre-test preparations
|
2002-07-11 07:28:37 +04:00
|
|
|
void InitOutput();
|
|
|
|
|
2002-07-17 14:50:55 +04:00
|
|
|
/*! \brief Prints out the test results in the proper format per
|
|
|
|
the specified verbosity level.
|
|
|
|
*/
|
2002-07-11 07:28:37 +04:00
|
|
|
void PrintResults();
|
|
|
|
|
2002-07-17 14:50:55 +04:00
|
|
|
/*! \brief Searches all the paths in \c fLibDirs, loading any dynamically
|
|
|
|
loadable suites it finds.
|
|
|
|
*/
|
|
|
|
virtual void LoadDynamicSuites();
|
|
|
|
|
2002-07-18 05:03:19 +04:00
|
|
|
//! Sets the current test directory.
|
|
|
|
void UpdateTestDir(char *argv[]);
|
2003-11-10 03:45:18 +03:00
|
|
|
|
|
|
|
void InstallPatches();
|
|
|
|
void UninstallPatches();
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
private:
|
2003-11-10 03:45:18 +03:00
|
|
|
//! Prevents the use of the copy constructor.
|
|
|
|
BTestShell( const BTestShell © );
|
2002-07-11 07:28:37 +04:00
|
|
|
|
2003-11-10 03:45:18 +03:00
|
|
|
//! Prevents the use of the copy operator.
|
|
|
|
void operator =( const BTestShell © );
|
|
|
|
|
2004-02-19 00:38:04 +03:00
|
|
|
#ifndef NO_ELF_SYMBOL_PATCHING
|
2003-11-10 03:45:18 +03:00
|
|
|
void _Debugger(const char* message);
|
|
|
|
image_id _LoadAddOn(const char* path);
|
|
|
|
status_t _UnloadAddOn(image_id image);
|
|
|
|
|
|
|
|
static void _DebuggerHook(const char* message);
|
|
|
|
static image_id _LoadAddOnHook(const char* path);
|
|
|
|
static status_t _UnloadAddOnHook(image_id image);
|
2004-02-19 00:38:04 +03:00
|
|
|
#endif // ! NO_ELF_SYMBOL_PATCHING
|
2003-11-10 03:45:18 +03:00
|
|
|
|
2002-07-11 07:28:37 +04:00
|
|
|
}; // class BTestShell
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2002-09-28 04:11:29 +04:00
|
|
|
#endif // _beos_test_shell_h_
|