Finished migrating Storage Kit tests to new framework.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@292 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -15,10 +15,12 @@ rule CppUnitLibrary
|
||||
|
||||
CppUnitLibrary
|
||||
SemaphoreSyncObject.cpp
|
||||
TestApp.cpp
|
||||
TestCase.cpp
|
||||
TestListener.cpp
|
||||
TestShell.cpp
|
||||
TestSuite.cpp
|
||||
TestUtils.cpp
|
||||
ThreadedTestCase.cpp
|
||||
cppunit/Asserter.cpp
|
||||
cppunit/CompilerOutputter.cpp
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// TestApp.cpp
|
||||
|
||||
#include <TestApp.h>
|
||||
|
||||
// TestHandler
|
||||
|
||||
// MessageReceived
|
||||
void
|
||||
TestHandler::MessageReceived(BMessage *message)
|
||||
{
|
||||
// clone and push it
|
||||
BMessage *clone = new BMessage(*message);
|
||||
fQueue.Lock();
|
||||
fQueue.AddMessage(clone);
|
||||
fQueue.Unlock();
|
||||
}
|
||||
|
||||
// Queue
|
||||
BMessageQueue &
|
||||
TestHandler::Queue()
|
||||
{
|
||||
return fQueue;
|
||||
}
|
||||
|
||||
|
||||
// TestApp
|
||||
|
||||
// constructor
|
||||
TestApp::TestApp(const char *signature)
|
||||
: BApplication(signature),
|
||||
fAppThread(B_ERROR),
|
||||
fHandler()
|
||||
{
|
||||
AddHandler(&fHandler);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
// Init
|
||||
status_t
|
||||
TestApp::Init()
|
||||
{
|
||||
status_t error = B_OK;
|
||||
fAppThread = spawn_thread(&_AppThreadStart, "query app",
|
||||
B_NORMAL_PRIORITY, this);
|
||||
if (fAppThread < 0)
|
||||
error = fAppThread;
|
||||
else {
|
||||
error = resume_thread(fAppThread);
|
||||
if (error != B_OK)
|
||||
kill_thread(fAppThread);
|
||||
}
|
||||
if (error != B_OK)
|
||||
fAppThread = B_ERROR;
|
||||
return error;
|
||||
}
|
||||
|
||||
// Terminate
|
||||
void
|
||||
TestApp::Terminate()
|
||||
{
|
||||
PostMessage(B_QUIT_REQUESTED, this);
|
||||
int32 result;
|
||||
wait_for_thread(fAppThread, &result);
|
||||
}
|
||||
|
||||
// ReadyToRun
|
||||
void
|
||||
TestApp::ReadyToRun()
|
||||
{
|
||||
}
|
||||
|
||||
// Handler
|
||||
TestHandler &
|
||||
TestApp::Handler()
|
||||
{
|
||||
return fHandler;
|
||||
}
|
||||
|
||||
// _AppThreadStart
|
||||
int32
|
||||
TestApp::_AppThreadStart(void *data)
|
||||
{
|
||||
if (TestApp *app = (TestApp*)data) {
|
||||
app->Lock();
|
||||
app->Run();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ BTestCase::tearDown() {
|
||||
|
||||
void
|
||||
BTestCase::NextSubTest() {
|
||||
if (BeVerbose()) {
|
||||
if (BTestShell::GlobalBeVerbose()) {
|
||||
printf("[%ld]", fSubTestNum++);
|
||||
fflush(stdout);
|
||||
}
|
||||
@@ -26,13 +26,13 @@ BTestCase::NextSubTest() {
|
||||
|
||||
void
|
||||
BTestCase::NextSubTestBlock() {
|
||||
if (BeVerbose())
|
||||
if (BTestShell::GlobalBeVerbose())
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void
|
||||
BTestCase::Outputf(const char *str, ...) {
|
||||
if (BeVerbose()) {
|
||||
if (BTestShell::GlobalBeVerbose()) {
|
||||
va_list args;
|
||||
va_start(args, str);
|
||||
vprintf(str, args);
|
||||
@@ -60,8 +60,3 @@ BTestCase::RestoreCWD(const char *alternate) {
|
||||
chdir(alternate);
|
||||
}
|
||||
|
||||
bool
|
||||
BTestCase::BeVerbose() {
|
||||
BTestShell *shell = BTestShell::Shell();
|
||||
return ((shell && shell->BeVerbose()) || !shell);
|
||||
}
|
||||
|
||||
@@ -23,9 +23,15 @@ BTestShell::BTestShell(const std::string &description, SyncObject *syncObject)
|
||||
, fDescription(description)
|
||||
, fTestResults(syncObject)
|
||||
, fListTestsAndExit(false)
|
||||
, fTestDir(NULL)
|
||||
{
|
||||
};
|
||||
|
||||
BTestShell::~BTestShell() {
|
||||
delete fTestDir;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BTestShell::AddSuite(BTestSuite *suite) {
|
||||
if (suite) {
|
||||
@@ -95,6 +101,9 @@ BTestShell::LoadSuitesFrom(BDirectory *libDir) {
|
||||
|
||||
int
|
||||
BTestShell::Run(int argc, char *argv[]) {
|
||||
// Make note of which directory we started in
|
||||
UpdateTestDir(argv);
|
||||
|
||||
// Parse the command line args
|
||||
if (!ProcessArguments(argc, argv))
|
||||
return 0;
|
||||
@@ -154,6 +163,11 @@ BTestShell::Verbosity() const {
|
||||
return fVerbosityLevel;
|
||||
}
|
||||
|
||||
const char*
|
||||
BTestShell::TestDir() const {
|
||||
return (fTestDir ? fTestDir->Path() : NULL);
|
||||
}
|
||||
|
||||
void
|
||||
BTestShell::PrintDescription(int argc, char *argv[]) {
|
||||
cout << endl << fDescription;
|
||||
@@ -253,8 +267,8 @@ BTestShell::InitOutput() {
|
||||
cout << "Tests" << endl;
|
||||
cout << "------------------------------------------------------------------------------" << endl;
|
||||
fTestResults.addListener(new BTestListener);
|
||||
fTestResults.addListener(&fResultsCollector);
|
||||
}
|
||||
fTestResults.addListener(&fResultsCollector);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -319,3 +333,16 @@ BTestShell::LoadDynamicSuites() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BTestShell::UpdateTestDir(char *argv[]) {
|
||||
BPath path(argv[0]);
|
||||
if (path.InitCheck() == B_OK) {
|
||||
delete fTestDir;
|
||||
fTestDir = new BPath();
|
||||
if (path.GetParent(fTestDir) != B_OK)
|
||||
cout << "Couldn't get test dir." << endl;
|
||||
} else
|
||||
cout << "Couldn't find the path to the test app." << endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
// TestUtils.cpp
|
||||
|
||||
#include <TestUtils.h>
|
||||
#include <TestShell.h>
|
||||
|
||||
status_t DecodeResult(status_t result) {
|
||||
if (!BTestShell::GlobalBeVerbose())
|
||||
return result;
|
||||
|
||||
std::string str;
|
||||
switch (result) {
|
||||
|
||||
case B_OK:
|
||||
str = "B_OK";
|
||||
break;
|
||||
|
||||
case B_ERROR:
|
||||
str = "B_ERROR";
|
||||
break;
|
||||
|
||||
|
||||
// Storage Kit Errors
|
||||
case B_FILE_ERROR:
|
||||
str = "B_FILE_ERROR";
|
||||
break;
|
||||
|
||||
case B_FILE_NOT_FOUND:
|
||||
str = "B_FILE_NOT_FOUND";
|
||||
break;
|
||||
|
||||
case B_FILE_EXISTS:
|
||||
str = "B_FILE_EXISTS";
|
||||
break;
|
||||
|
||||
case B_ENTRY_NOT_FOUND:
|
||||
str = "B_ENTRY_NOT_FOUND";
|
||||
break;
|
||||
|
||||
case B_NAME_TOO_LONG:
|
||||
str = "B_NAME_TOO_LONG";
|
||||
break;
|
||||
|
||||
case B_DIRECTORY_NOT_EMPTY:
|
||||
str = "B_DIRECTORY_NOT_EMPTY";
|
||||
break;
|
||||
|
||||
case B_DEVICE_FULL:
|
||||
str = "B_DEVICE_FULL";
|
||||
break;
|
||||
|
||||
case B_READ_ONLY_DEVICE:
|
||||
str = "B_READ_ONLY_DEVICE";
|
||||
break;
|
||||
|
||||
case B_IS_A_DIRECTORY:
|
||||
str = "B_IS_A_DIRECTORY";
|
||||
break;
|
||||
|
||||
case B_NO_MORE_FDS:
|
||||
str = "B_NO_MORE_FDS";
|
||||
break;
|
||||
|
||||
case B_CROSS_DEVICE_LINK:
|
||||
str = "B_CROSS_DEVICE_LINK";
|
||||
break;
|
||||
|
||||
case B_LINK_LIMIT:
|
||||
str = "B_LINK_LIMIT";
|
||||
break;
|
||||
|
||||
case B_BUSTED_PIPE:
|
||||
str = "B_BUSTED_PIPE";
|
||||
break;
|
||||
|
||||
case B_UNSUPPORTED:
|
||||
str = "B_UNSUPPORTED";
|
||||
break;
|
||||
|
||||
case B_PARTITION_TOO_SMALL:
|
||||
str = "B_PARTITION_TOO_SMALL";
|
||||
break;
|
||||
|
||||
|
||||
// General Errors
|
||||
case B_NO_MEMORY:
|
||||
str = "B_NO_MEMORY";
|
||||
break;
|
||||
|
||||
case B_IO_ERROR:
|
||||
str = "B_IO_ERROR";
|
||||
break;
|
||||
|
||||
case B_PERMISSION_DENIED:
|
||||
str = "B_PERMISSION_DENIED";
|
||||
break;
|
||||
|
||||
case B_BAD_INDEX:
|
||||
str = "B_BAD_INDEX";
|
||||
break;
|
||||
|
||||
case B_BAD_TYPE:
|
||||
str = "B_BAD_TYPE";
|
||||
break;
|
||||
|
||||
case B_BAD_VALUE:
|
||||
str = "B_BAD_VALUE";
|
||||
break;
|
||||
|
||||
case B_MISMATCHED_VALUES:
|
||||
str = "B_MISMATCHED_VALUES";
|
||||
break;
|
||||
|
||||
case B_NAME_NOT_FOUND:
|
||||
str = "B_NAME_NOT_FOUND";
|
||||
break;
|
||||
|
||||
case B_NAME_IN_USE:
|
||||
str = "B_NAME_IN_USE";
|
||||
break;
|
||||
|
||||
case B_TIMED_OUT:
|
||||
str = "B_TIMED_OUT";
|
||||
break;
|
||||
|
||||
case B_INTERRUPTED:
|
||||
str = "B_INTERRUPTED";
|
||||
break;
|
||||
|
||||
case B_WOULD_BLOCK:
|
||||
str = "B_WOULD_BLOCK";
|
||||
break;
|
||||
|
||||
case B_CANCELED:
|
||||
str = "B_CANCELED";
|
||||
break;
|
||||
|
||||
case B_NO_INIT:
|
||||
str = "B_NO_INIT";
|
||||
break;
|
||||
|
||||
case B_BUSY:
|
||||
str = "B_BUSY";
|
||||
break;
|
||||
|
||||
case B_NOT_ALLOWED:
|
||||
str = "B_NOT_ALLOWED";
|
||||
break;
|
||||
|
||||
|
||||
// Kernel Errors
|
||||
case B_BAD_ADDRESS:
|
||||
str = "B_BAD_ADDRESS";
|
||||
break;
|
||||
|
||||
// OS Errors
|
||||
case B_BAD_PORT_ID:
|
||||
str = "B_BAD_PORT_ID";
|
||||
break;
|
||||
|
||||
// Anything Else
|
||||
default:
|
||||
str = "??????????";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
cout << endl << "DecodeResult() -- " "0x" << hex << result << " (" << dec << result << ") == " << str << endl;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ExecCommand(const char *command) {
|
||||
if (command)
|
||||
system(command);
|
||||
}
|
||||
|
||||
void ExecCommand(const char *command, const char *parameter) {
|
||||
if (command && parameter) {
|
||||
char *cmdLine = new char[strlen(command) + strlen(parameter) + 1];
|
||||
strcpy(cmdLine, command);
|
||||
strcat(cmdLine, parameter);
|
||||
system(cmdLine);
|
||||
delete[] cmdLine;
|
||||
}
|
||||
}
|
||||
|
||||
void ExecCommand(const char *command, const char *parameter1,
|
||||
const char *parameter2) {
|
||||
if (command && parameter1 && parameter2) {
|
||||
char *cmdLine = new char[strlen(command) + strlen(parameter1)
|
||||
+ 1 + strlen(parameter2) + 1];
|
||||
strcpy(cmdLine, command);
|
||||
strcat(cmdLine, parameter1);
|
||||
strcat(cmdLine, " ");
|
||||
strcat(cmdLine, parameter2);
|
||||
system(cmdLine);
|
||||
delete[] cmdLine;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <TestShell.h>
|
||||
#include <ThreadedTestCase.h>
|
||||
#include <Autolock.h>
|
||||
#include <stdio.h>
|
||||
@@ -48,7 +49,7 @@ BThreadedTestCase::NextSubTest() {
|
||||
|
||||
void
|
||||
BThreadedTestCase::Outputf(const char *str, ...) {
|
||||
if (BeVerbose()) {
|
||||
if (BTestShell::GlobalBeVerbose()) {
|
||||
// Figure out if this is a multithreaded test or not
|
||||
thread_id id = find_thread(NULL);
|
||||
bool isSingleThreaded;
|
||||
|
||||
Reference in New Issue
Block a user