Unit testing update:

- Verbosity is now honored globally
- Added BTestCase::Outputf()
- Migrated BNode, BStatable, BDirectory, and BPath tests
- Added CommonTestLib, TestLib, and R5TestLib rules to Jamrules
- Updated Jamfiles for unit testing stuff
- Probably a few other things I've forgotten


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@269 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-07-17 10:50:55 +00:00
parent cbe085bc5a
commit d1f6c38f0d
26 changed files with 890 additions and 585 deletions
+7 -7
View File
@@ -20,22 +20,22 @@ ExampleTest::Suite() {
// Add a multithreaded test
ExampleTest *test = new ExampleTest("This name is never used, just so you know :-)");
caller = new BThreadedTestCaller<ExampleTest>("MultiThreaded Test #1", test);
caller = new BThreadedTestCaller<ExampleTest>("ExampleTests::MultiThreaded Test #1", test);
caller->addThread("A", &ExampleTest::TestFunc1);
caller->addThread("B", &ExampleTest::TestFunc2);
caller->addThread("C", &ExampleTest::TestFunc3);
suite->addTest(caller);
// And another
caller = new BThreadedTestCaller<ExampleTest>("MultiThreaded Test #2");
caller = new BThreadedTestCaller<ExampleTest>("ExampleTests::MultiThreaded Test #2");
caller->addThread("Thread1", &ExampleTest::TestFunc1);
caller->addThread("Thread2", &ExampleTest::TestFunc1);
caller->addThread("Thread3", &ExampleTest::TestFunc1);
suite->addTest(caller);
// And some single threaded ones
suite->addTest(new CppUnit::TestCaller<ExampleTest>("SingleThreaded Test #1", &ExampleTest::TestFunc1));
suite->addTest(new CppUnit::TestCaller<ExampleTest>("SingleThreaded Test #2", &ExampleTest::TestFunc2));
suite->addTest(new CppUnit::TestCaller<ExampleTest>("ExampleTests::SingleThreaded Test #1", &ExampleTest::TestFunc1));
suite->addTest(new CppUnit::TestCaller<ExampleTest>("ExampleTests::SingleThreaded Test #2", &ExampleTest::TestFunc2));
return suite;
}
@@ -48,10 +48,10 @@ ExampleTest::TestFunc1() {
// Get the lock and do our business
NextSubTest();
fLocker->Lock();
// printf("TestFunc1() -- %d + 10 = %d\n", fNum, fNum+10);
fNum += 10;
fLocker->Unlock();
snooze(sleeptime);
// Outputf("(1:%d)", i);
}
}
@@ -61,10 +61,10 @@ ExampleTest::TestFunc2() {
// Get the lock and do our business
NextSubTest();
fLocker->Lock();
// printf("TestFunc2() -- %d * 2 = %d\n", fNum, fNum*2);
fNum *= 2;
fLocker->Unlock();
snooze(sleeptime);
// Outputf("(2:%d)", i);
}
}
@@ -74,10 +74,10 @@ ExampleTest::TestFunc3() {
// Get the lock and do our business
NextSubTest();
fLocker->Lock();
// printf("TestFunc3() -- %d - 5 = %d\n", fNum, fNum-5);
fNum += 10;
fLocker->Unlock();
snooze(sleeptime);
// Outputf("(3:%d)", i);
}
}
+1 -1
View File
@@ -9,7 +9,7 @@ public:
ExampleTest(std::string name = "");
virtual ~ExampleTest() { delete fLocker; }
static Test* Suite();
static CppUnit::Test* Suite();
void TestFunc1(); // num += 10
void TestFunc2(); // num *= 2
+2 -2
View File
@@ -3,7 +3,7 @@
#include <ExampleTest.h>
BTestSuite* getTestSuite() {
BTestSuite *suite = new BTestSuite("Example");
suite->addTest("BExample", ExampleTest::Suite());
BTestSuite *suite = new BTestSuite("ExampleSuite");
suite->addTest("ExampleTests", ExampleTest::Suite());
return suite;
}
+16
View File
@@ -1,4 +1,20 @@
SubDir OBOS_TOP src tests ;
CommonTestLib libexampletest.so
: ExampleTestAddon.cpp
ExampleTest.cpp
: be stdc++.r4
: be stdc++.r4
:
;
UnitTest UnitTester
: UnitTester.cpp
:
: be stdc++.r4
# : be stdc++.r4
:
;
SubInclude OBOS_TOP src tests add-ons ;
SubInclude OBOS_TOP src tests kits ;
+33 -4
View File
@@ -1,6 +1,5 @@
#include "UnitTester.h"
#include <SemaphoreSyncObject.h>
#include <string>
#include <Directory.h>
// ##### Include headers for statically linked tests here #####
@@ -15,15 +14,15 @@ int main(int argc, char *argv[]) {
BTestShell::SetShell(&shell);
// Load our dynamically linked tests
BDirectory libDir("./lib");
int count = shell.LoadSuitesFrom(&libDir);
cout << "Loaded " << count << " suites" << endl;
return shell.Run(argc, argv);
}
const std::string UnitTesterShell::defaultLibDir = "./lib";
UnitTesterShell::UnitTesterShell(const std::string &description, SyncObject *syncObject)
: BTestShell(description, syncObject)
, doR5Tests(false)
{
}
@@ -35,6 +34,7 @@ UnitTesterShell::PrintDescription(int argc, char *argv[]) {
cout << "of testing and verifying the various kits, classes, functions," << endl;
cout << "and the like that comprise OpenBeOS." << endl;
/*
if (AppName.rfind("UnitTester_r5") != std::string::npos) {
cout << endl;
cout << "Judging by its name (UnitTester_r5), this copy was" << endl;
@@ -45,5 +45,34 @@ UnitTesterShell::PrintDescription(int argc, char *argv[]) {
cout << "Judging by its name (UnitTester), this copy was probably" << endl;
cout << "linked against our own OpenBeOS implementations." << endl;
}
*/
}
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;
}
bool
UnitTesterShell::ProcessArgument(std::string arg, int argc, char *argv[]) {
if (arg == "-r5") {
doR5Tests = true;
} else if (arg == "-obos") {
doR5Tests = false;
} else
return BTestShell::ProcessArgument(arg, argc, argv);
return true;
}
void
UnitTesterShell::LoadDynamicSuites() {
// Add the appropriate test lib path
fLibDirs.insert(defaultLibDir + (doR5Tests ? "_r5" : ""));
// Load away
BTestShell::LoadDynamicSuites();
}
+7
View File
@@ -2,11 +2,18 @@
#define __testing_is_delightful_h__
#include <TestShell.h>
#include <string>
class UnitTesterShell : public BTestShell {
public:
UnitTesterShell(const std::string &description = "", SyncObject *syncObject = 0);
protected:
static const std::string defaultLibDir;
bool doR5Tests;
virtual void PrintDescription(int argc, char *argv[]);
virtual void PrintValidArguments();
virtual bool ProcessArgument(std::string arg, int argc, char *argv[]);
virtual void LoadDynamicSuites();
};
//extern UnitTesterShell shell;
+3 -21
View File
@@ -23,7 +23,7 @@ count_available_fds()
// constructor
BasicTest::BasicTest()
: StorageKit::TestCase(),
: BTestCase(),
fSubTestNumber(0),
fAvailableFDs(0)
{
@@ -33,6 +33,7 @@ BasicTest::BasicTest()
void
BasicTest::setUp()
{
BTestCase::setUp();
fAvailableFDs = count_available_fds();
SaveCWD();
fSubTestNumber = 0;
@@ -43,32 +44,13 @@ void
BasicTest::tearDown()
{
RestoreCWD();
nextSubTestBlock();
int32 availableFDs = count_available_fds();
if (availableFDs != fAvailableFDs) {
printf("WARNING: Number of available file descriptors has changed "
"during test: %ld -> %ld\n", fAvailableFDs, availableFDs);
fAvailableFDs = availableFDs;
}
}
// nextSubTest
void
BasicTest::nextSubTest()
{
if (shell.BeVerbose()) {
printf("[%ld]", fSubTestNumber++);
fflush(stdout);
}
}
// nextSubTestBlock
void
BasicTest::nextSubTestBlock()
{
if (shell.BeVerbose())
printf("\n");
fSubTestNumber = 0;
BTestCase::tearDown();
}
// execCommand
+7 -8
View File
@@ -3,14 +3,13 @@
#ifndef __sk_basic_test_h__
#define __sk_basic_test_h__
#include <SupportDefs.h>
#include <TestCase.h>
#include <TestShell.h>
#include <set>
#include <stdio.h>
#include <SupportDefs.h>
#include "StorageKitTester.h"
class BasicTest : public StorageKit::TestCase
class BasicTest : public BTestCase
{
public:
BasicTest();
@@ -23,8 +22,8 @@ public:
// helper functions
void nextSubTest();
void nextSubTestBlock();
// void nextSubTest();
// void nextSubTestBlock();
static void execCommand(const string &command);
@@ -110,7 +109,7 @@ public:
fTestedNames.clear();
}
bool test(string name, bool dump = shell.BeVerbose())
bool test(string name, bool dump = BTestShell::GlobalBeVerbose())
{
bool result = (fUntestedNames.find(name) != fUntestedNames.end());
if (result) {
File diff suppressed because it is too large Load Diff
+17 -20
View File
@@ -1,27 +1,25 @@
SubDir OBOS_TOP src tests kits storage ;
# Exclude the whole thing until it compiles again.
if ""
{
# EntryTest.cpp
# FileTest.cpp
# FindDirectoryTest.cpp
# MimeTypeTest.cpp
# PathTest.cpp
# QueryTest.cpp
# ResourcesTest.cpp
# ResourceStringsTest.cpp
# StatableTest.cpp
# SymLinkTest.cpp
# TestApp.cpp
CommonUnitTest StorageKitTester
: StorageKitTester.cpp
CommonTestLib libstoragetest.so
: StorageKitTestAddon.cpp
BasicTest.cpp
DirectoryTest.cpp
EntryTest.cpp
FileTest.cpp
FindDirectoryTest.cpp
MimeTypeTest.cpp
NodeTest.cpp
PathTest.cpp
QueryTest.cpp
ResourcesTest.cpp
ResourceStringsTest.cpp
StatableTest.cpp
SymLinkTest.cpp
TestApp.cpp
TestUtils.cpp
: kits storage
: libstorage.so be stdc++.r4
: be stdc++.r4
: storage
@@ -29,21 +27,20 @@ CommonUnitTest StorageKitTester
# To run the tests the libraries must be around.
{
local libdir = [ on StorageKitTester FDirName $(LOCATE[1]) lib ] ;
local libdir = [ on UnitTester FDirName $(LOCATE[1]) lib ] ;
MakeLocate <$(SOURCE_GRIST)>libstorage.so : $(libdir) ;
MakeLocate <$(SOURCE_GRIST)>libbeadapter.so : $(libdir) ;
RelSymLink <$(SOURCE_GRIST)>libstorage.so : libstorage.so ;
RelSymLink <$(SOURCE_GRIST)>libbeadapter.so : libbeadapter.so ;
DEPENDS StorageKitTester StorageKitTester_r5
DEPENDS libstoragetest.so
: <$(SOURCE_GRIST)>libstorage.so <$(SOURCE_GRIST)>libbeadapter.so ;
}
# To run the tests some test files must be around.
{
local resdir = <storage!kit!test!files>resources ;
MakeLocate $(resdir) : [ on StorageKitTester return $(LOCATE[1]) ] ;
MakeLocate $(resdir) : [ on libstoragetest.so return $(LOCATE[1]) ] ;
RelSymLink $(resdir) : [ FDirName $(SUBDIR) resources ] ;
DEPENDS StorageKitTester StorageKitTester_r5 : $(resdir) ;
DEPENDS libstoragetest.so : $(resdir) ;
}
} # if ""
+84 -84
View File
@@ -41,7 +41,7 @@ NodeTest::Suite() {
suite->addTest( new CppUnit::TestCaller<NodeTest>("BNode::Attribute Directory Test", &NodeTest::AttrDirTest) );
suite->addTest( new CppUnit::TestCaller<NodeTest>("BNode::Attribute Read/Write/Remove Test", &NodeTest::AttrTest) );
suite->addTest( new CppUnit::TestCaller<NodeTest>("BNode::Attribute Rename Test"
#if SK_TEST_R5
#if TEST_R5
" (NOTE: test not actually performed with R5 libraries)"
#endif
, &NodeTest::AttrRenameTest) );
@@ -52,7 +52,7 @@ NodeTest::Suite() {
suite->addTest( new CppUnit::TestCaller<NodeTest>("BNode::Equality Test", &NodeTest::EqualityTest) );
suite->addTest( new CppUnit::TestCaller<NodeTest>("BNode::Assignment Test", &NodeTest::AssignmentTest) );
suite->addTest( new CppUnit::TestCaller<NodeTest>("BNode::Lock Test"
#if SK_TEST_OBOS_POSIX
#if TEST_OBOS /* !!!POSIX ONLY!!! */
" (NOTE: test not actually performed with OpenBeOS Posix libraries)"
#endif
, &NodeTest::LockTest) );
@@ -202,76 +202,76 @@ NodeTest::InitTest1()
const char *nonExistingSuper = nonExistingSuperDirname;
const char *nonExistingRel = nonExistingRelDirname;
// 1. default constructor
nextSubTest();
NextSubTest();
{
BNode node;
CPPUNIT_ASSERT( node.InitCheck() == B_NO_INIT );
}
// 2. BNode(const char*)
nextSubTest();
NextSubTest();
{
BNode node(fileLink);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BNode node(nonExisting);
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
}
nextSubTest();
NextSubTest();
{
BNode node((const char *)NULL);
CPPUNIT_ASSERT( equals(node.InitCheck(), B_BAD_VALUE, B_NO_INIT) );
}
nextSubTest();
NextSubTest();
{
BNode node("");
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
}
nextSubTest();
NextSubTest();
{
BNode node(existingFile);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BNode node(existingDir);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BNode node(tooLongEntryname);
CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG );
}
// 3. BNode(const BEntry*)
nextSubTest();
NextSubTest();
{
BEntry entry(dirLink);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
BNode node(&entry);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BEntry entry(nonExisting);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
BNode node(&entry);
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
}
nextSubTest();
NextSubTest();
{
BNode node((BEntry *)NULL);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
}
nextSubTest();
NextSubTest();
{
BEntry entry;
BNode node(&entry);
CPPUNIT_ASSERT( equals(node.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) );
}
nextSubTest();
NextSubTest();
{
BEntry entry(existingFile);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -279,7 +279,7 @@ NodeTest::InitTest1()
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BEntry entry(existingDir);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -287,7 +287,7 @@ NodeTest::InitTest1()
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BEntry entry(tooLongEntryname);
// R5 returns E2BIG instead of B_NAME_TOO_LONG
@@ -297,7 +297,7 @@ NodeTest::InitTest1()
}
// 4. BNode(const entry_ref*)
nextSubTest();
NextSubTest();
{
BEntry entry(dirLink);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -306,7 +306,7 @@ NodeTest::InitTest1()
BNode node(&ref);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BEntry entry(nonExisting);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -315,12 +315,12 @@ NodeTest::InitTest1()
BNode node(&ref);
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
}
nextSubTest();
NextSubTest();
{
BNode node((entry_ref *)NULL);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
}
nextSubTest();
NextSubTest();
{
BEntry entry(existingFile);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -329,7 +329,7 @@ NodeTest::InitTest1()
BNode node(&ref);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BEntry entry(existingDir);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -340,73 +340,73 @@ NodeTest::InitTest1()
}
// 5. BNode(const BDirectory*, const char*)
nextSubTest();
NextSubTest();
{
BDirectory pathDir(dirSuperLink);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, dirRelLink);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BDirectory pathDir(dirSuperLink);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, dirLink);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
}
nextSubTest();
NextSubTest();
{
BDirectory pathDir(nonExistingSuper);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, nonExistingRel);
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
}
nextSubTest();
NextSubTest();
{
BNode node((BDirectory *)NULL, (const char *)NULL);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
}
nextSubTest();
NextSubTest();
{
BNode node((BDirectory *)NULL, dirLink);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
}
nextSubTest();
NextSubTest();
{
BDirectory pathDir(dirSuperLink);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, (const char *)NULL);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
}
nextSubTest();
NextSubTest();
{
BDirectory pathDir(dirSuperLink);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, "");
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BDirectory pathDir(existingSuperFile);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, existingRelFile);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BDirectory pathDir(existingSuperDir);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, existingRelDir);
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
}
nextSubTest();
NextSubTest();
{
BDirectory pathDir(tooLongSuperEntryname);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, tooLongRelEntryname);
CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG );
}
nextSubTest();
NextSubTest();
{
BDirectory pathDir(fileSuperDirname);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
@@ -434,155 +434,155 @@ NodeTest::InitTest2()
const char *nonExistingRel = nonExistingRelDirname;
BNode node;
// 2. BNode(const char*)
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( node.SetTo(fileLink) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( node.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( equals(node.SetTo((const char *)NULL), B_BAD_VALUE,
B_NO_INIT) );
CPPUNIT_ASSERT( equals(node.InitCheck(), B_BAD_VALUE, B_NO_INIT) );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( node.SetTo("") == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( node.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( node.SetTo(existingDir) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( node.SetTo(tooLongEntryname) == B_NAME_TOO_LONG );
CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG );
// 3. BNode(const BEntry*)
nextSubTest();
NextSubTest();
BEntry entry(dirLink);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( node.SetTo(&entry) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(nonExisting) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&entry) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( node.SetTo((BEntry *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
//
nextSubTest();
NextSubTest();
entry.Unset();
CPPUNIT_ASSERT( entry.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( equals(node.SetTo(&entry), B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( equals(node.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&entry) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(existingDir) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&entry) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
// R5 returns E2BIG instead of B_NAME_TOO_LONG
CPPUNIT_ASSERT( equals(entry.SetTo(tooLongEntryname), E2BIG, B_NAME_TOO_LONG) );
CPPUNIT_ASSERT( equals(node.SetTo(&entry), B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( equals(node.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) );
// 4. BNode(const entry_ref*)
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(dirLink) == B_OK );
entry_ref ref;
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&ref) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(nonExisting) == B_OK );
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&ref) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( node.SetTo((entry_ref *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&ref) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(existingDir) == B_OK );
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&ref) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// 5. BNode(const BDirectory*, const char*)
nextSubTest();
NextSubTest();
BDirectory pathDir(dirSuperLink);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, dirRelLink) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(dirSuperLink) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, dirLink) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(nonExistingSuper) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, nonExistingRel) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( node.SetTo((BDirectory *)NULL, (const char *)NULL)
== B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( node.SetTo((BDirectory *)NULL, dirLink) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(dirSuperLink) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, (const char *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(dirSuperLink) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, "") == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(existingSuperFile) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, existingRelFile) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(existingSuperDir) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, existingRelDir) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(tooLongSuperEntryname) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, tooLongRelEntryname) == B_NAME_TOO_LONG );
CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG );
//
nextSubTest();
NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(fileSuperDirname) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, fileRelDirname) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
@@ -645,7 +645,7 @@ NodeTest::AttrDirTest(BNode &node)
CPPUNIT_ASSERT( node.RewindAttrs() == B_OK );
testSet.rewind();
// R5: crashs, if passing a NULL buffer
#if !SK_TEST_R5
#if !TEST_R5
CPPUNIT_ASSERT( node.GetNextAttrName(NULL) == B_BAD_VALUE );
#endif
}
@@ -655,7 +655,7 @@ void
NodeTest::AttrDirTest()
{
// uninitialized objects
nextSubTest();
NextSubTest();
TestNodes testEntries;
CreateUninitializedNodes(testEntries);
BNode *node;
@@ -667,7 +667,7 @@ NodeTest::AttrDirTest()
}
testEntries.delete_all();
// existing entries
nextSubTest();
NextSubTest();
CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
AttrDirTest(*node);
@@ -760,7 +760,7 @@ void
NodeTest::AttrTest()
{
// uninitialized objects
nextSubTest();
NextSubTest();
TestNodes testEntries;
CreateUninitializedNodes(testEntries);
BNode *node;
@@ -775,7 +775,7 @@ NodeTest::AttrTest()
}
testEntries.delete_all();
// existing entries
nextSubTest();
NextSubTest();
CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
AttrTest(*node);
@@ -787,7 +787,7 @@ NodeTest::AttrTest()
void
NodeTest::AttrRenameTest(BNode &node)
{
#if !SK_TEST_R5
#if !TEST_R5
const char attr1[] = "StorageKit::SomeAttribute";
const char attr2[] = "StorageKit::AnotherAttribute";
const char str[] = "This is my testing string and it rules your world.";
@@ -837,7 +837,7 @@ void
NodeTest::AttrRenameTest()
{
// uninitialized objects
nextSubTest();
NextSubTest();
TestNodes testEntries;
CreateUninitializedNodes(testEntries);
BNode *node;
@@ -847,7 +847,7 @@ NodeTest::AttrRenameTest()
}
testEntries.delete_all();
// existing entries
nextSubTest();
NextSubTest();
CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
AttrRenameTest(*node);
@@ -920,7 +920,7 @@ void
NodeTest::AttrInfoTest()
{
// uninitialized objects
nextSubTest();
NextSubTest();
TestNodes testEntries;
CreateUninitializedNodes(testEntries);
BNode *node;
@@ -931,7 +931,7 @@ NodeTest::AttrInfoTest()
}
testEntries.delete_all();
// existing entries
nextSubTest();
NextSubTest();
CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
AttrInfoTest(*node);
@@ -985,7 +985,7 @@ NodeTest::AttrBStringTest(BNode &node)
BString readValue;
BString writeValue("test");
// R5: crashes, if supplying a NULL BString
#if !SK_TEST_R5
#if !TEST_R5
CPPUNIT_ASSERT( node.WriteAttrString(attrNames[0], NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.ReadAttrString(attrNames[0], NULL) == B_BAD_VALUE );
#endif
@@ -993,7 +993,7 @@ NodeTest::AttrBStringTest(BNode &node)
B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( equals(node.ReadAttrString(NULL, &readValue),
B_BAD_ADDRESS, B_BAD_VALUE) );
#if !SK_TEST_R5
#if !TEST_R5
CPPUNIT_ASSERT( node.WriteAttrString(NULL, NULL) == B_BAD_VALUE );
#endif
CPPUNIT_ASSERT( equals(node.ReadAttrString(NULL, NULL),
@@ -1021,7 +1021,7 @@ void
NodeTest::AttrBStringTest()
{
// uninitialized objects
nextSubTest();
NextSubTest();
TestNodes testEntries;
CreateUninitializedNodes(testEntries);
BNode *node;
@@ -1035,7 +1035,7 @@ NodeTest::AttrBStringTest()
}
testEntries.delete_all();
// existing entries
nextSubTest();
NextSubTest();
CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
AttrBStringTest(*node);
@@ -1051,7 +1051,7 @@ NodeTest::SyncTest() {
const char str[] = "This string rules your world.";
const int len = strlen(str) + 1;
// uninitialized objects
nextSubTest();
NextSubTest();
TestNodes testEntries;
CreateUninitializedNodes(testEntries);
BNode *node;
@@ -1061,7 +1061,7 @@ NodeTest::SyncTest() {
}
testEntries.delete_all();
// existing entries
nextSubTest();
NextSubTest();
CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
CPPUNIT_ASSERT( node->WriteAttr(attr, B_STRING_TYPE, 0, str, len)
@@ -1085,7 +1085,7 @@ void
NodeTest::DupTest()
{
// uninitialized objects
nextSubTest();
NextSubTest();
TestNodes testEntries;
CreateUninitializedNodes(testEntries);
BNode *node;
@@ -1095,7 +1095,7 @@ NodeTest::DupTest()
}
testEntries.delete_all();
// existing entries
nextSubTest();
NextSubTest();
CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
DupTest(*node);
@@ -1172,9 +1172,9 @@ NodeTest::LockTest(BNode &node, const char *entryName)
void
NodeTest::LockTest()
{
#if !SK_TEST_OBOS_POSIX
#if !TEST_OBOS /* !!!POSIX ONLY!!! */
// uninitialized objects
nextSubTest();
NextSubTest();
TestNodes testEntries;
CreateUninitializedNodes(testEntries);
BNode *node;
@@ -1184,7 +1184,7 @@ NodeTest::LockTest()
}
testEntries.delete_all();
// existing entries
nextSubTest();
NextSubTest();
CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
LockTest(*node, nodeName.c_str());
File diff suppressed because it is too large Load Diff
+2 -4
View File
@@ -3,13 +3,11 @@
#ifndef __sk_path_test_h__
#define __sk_path_test_h__
#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>
#include <StorageDefs.h>
#include <SupportDefs.h>
#include <BasicTest.h>
#include "BasicTest.h"
class CppUnit::Test;
class PathTest : public BasicTest
{
+21 -21
View File
@@ -34,7 +34,7 @@ StatableTest::GetStatTest()
BStatable *statable;
string entryName;
// existing entries
nextSubTest();
NextSubTest();
CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st1, st2;
@@ -44,7 +44,7 @@ StatableTest::GetStatTest()
}
testEntries.delete_all();
// uninitialized objects
nextSubTest();
NextSubTest();
CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st1;
@@ -52,7 +52,7 @@ StatableTest::GetStatTest()
}
testEntries.delete_all();
// bad args
nextSubTest();
NextSubTest();
CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); )
CPPUNIT_ASSERT( statable->GetStat(NULL) != B_OK );
@@ -67,7 +67,7 @@ StatableTest::IsXYZTest()
BStatable *statable;
string entryName;
// existing entries
nextSubTest();
NextSubTest();
CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st;
@@ -78,7 +78,7 @@ StatableTest::IsXYZTest()
}
testEntries.delete_all();
// uninitialized objects
nextSubTest();
NextSubTest();
CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
CPPUNIT_ASSERT( statable->IsDirectory() == false );
@@ -96,7 +96,7 @@ StatableTest::GetXYZTest()
BStatable *statable;
string entryName;
// test with existing entries
nextSubTest();
NextSubTest();
CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st;
@@ -108,7 +108,7 @@ StatableTest::GetXYZTest()
time_t mtime;
time_t ctime;
// R5: access time unused
#if !SK_TEST_R5 && !SK_TEST_OBOS_POSIX
#if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
time_t atime;
#endif
BVolume volume;
@@ -120,7 +120,7 @@ StatableTest::GetXYZTest()
CPPUNIT_ASSERT( statable->GetSize(&size) == B_OK );
CPPUNIT_ASSERT( statable->GetModificationTime(&mtime) == B_OK );
CPPUNIT_ASSERT( statable->GetCreationTime(&ctime) == B_OK );
#if !SK_TEST_R5 && !SK_TEST_OBOS_POSIX
#if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
CPPUNIT_ASSERT( statable->GetAccessTime(&atime) == B_OK );
#endif
CPPUNIT_ASSERT( statable->GetVolume(&volume) == B_OK );
@@ -133,17 +133,17 @@ StatableTest::GetXYZTest()
CPPUNIT_ASSERT( size == st.st_size );
CPPUNIT_ASSERT( mtime == st.st_mtime );
CPPUNIT_ASSERT( ctime == st.st_crtime );
#if !SK_TEST_R5 && !SK_TEST_OBOS_POSIX
#if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
CPPUNIT_ASSERT( atime == st.st_atime );
#endif
// OBOS: BVolume::==() is not implemented yet
#if !SK_TEST_OBOS_POSIX
#if !TEST_OBOS /* !!!POSIX ONLY!!! */
CPPUNIT_ASSERT( volume == BVolume(st.st_dev) );
#endif
}
testEntries.delete_all();
// test with uninitialized objects
nextSubTest();
NextSubTest();
CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
node_ref ref;
@@ -167,11 +167,11 @@ StatableTest::GetXYZTest()
}
testEntries.delete_all();
// bad args
nextSubTest();
NextSubTest();
CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
// R5: crashs, if passing NULL to any of these methods
#if !SK_TEST_R5
#if !TEST_R5
CPPUNIT_ASSERT( statable->GetNodeRef(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetOwner(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetGroup(NULL) == B_BAD_VALUE );
@@ -194,48 +194,48 @@ StatableTest::SetXYZTest()
BStatable *statable;
string entryName;
// test with existing entries
nextSubTest();
NextSubTest();
CreateRWStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st;
uid_t owner = 0xdad;
gid_t group = 0xdee;
// OBOS: no fchmod(), no FD time setters
#if !SK_TEST_OBOS_POSIX
#if !TEST_OBOS /* !!!POSIX ONLY!!! */
mode_t perms = 0x0ab; // -w- r-x -wx -- unusual enough? ;-)
time_t mtime = 1234567;
time_t ctime = 654321;
#endif
// R5: access time unused
#if !SK_TEST_R5 && !SK_TEST_OBOS_POSIX
#if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
time_t atime = 2345678;
#endif
// OBOS: no fchmod(), no FD time setters
CPPUNIT_ASSERT( statable->SetOwner(owner) == B_OK );
CPPUNIT_ASSERT( statable->SetGroup(group) == B_OK );
#if !SK_TEST_OBOS_POSIX
#if !TEST_OBOS /* !!!POSIX ONLY!!! */
CPPUNIT_ASSERT( statable->SetPermissions(perms) == B_OK );
CPPUNIT_ASSERT( statable->SetModificationTime(mtime) == B_OK );
CPPUNIT_ASSERT( statable->SetCreationTime(ctime) == B_OK );
#endif
#if !SK_TEST_R5 && !SK_TEST_OBOS_POSIX
#if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
CPPUNIT_ASSERT( statable->SetAccessTime(atime) == B_OK );
#endif
CPPUNIT_ASSERT( lstat(entryName.c_str(), &st) == 0 );
CPPUNIT_ASSERT( owner == st.st_uid );
CPPUNIT_ASSERT( group == st.st_gid );
#if !SK_TEST_OBOS_POSIX
#if !TEST_OBOS /* !!!POSIX ONLY!!! */
CPPUNIT_ASSERT( perms == (st.st_mode & S_IUMSK) );
CPPUNIT_ASSERT( mtime == st.st_mtime );
CPPUNIT_ASSERT( ctime == st.st_crtime );
#endif
#if !SK_TEST_R5 && !SK_TEST_OBOS_POSIX
#if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
CPPUNIT_ASSERT( atime == st.st_atime );
#endif
}
testEntries.delete_all();
// test with uninitialized objects
nextSubTest();
NextSubTest();
CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
uid_t owner = 0xdad;
+3
View File
@@ -3,6 +3,9 @@
#ifndef __sk_statable_test_h__
#define __sk_statable_test_h__
#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>
#include <list>
#include <string>
@@ -0,0 +1,18 @@
#include <TestSuite.h>
#include <TestSuiteAddon.h>
// ##### Include headers for your tests here #####
#include <DirectoryTest.h>
#include <NodeTest.h>
#include <PathTest.h>
BTestSuite* getTestSuite() {
BTestSuite *suite = new BTestSuite("Storage");
// ##### Add test suites for statically linked tests here #####
suite->addTest("BDirectory", DirectoryTest::Suite());
suite->addTest("BNode", NodeTest::Suite());
suite->addTest("BPath", PathTest::Suite());
return suite;
}
+2 -2
View File
@@ -1,10 +1,10 @@
// TestUtils.cpp
#include "TestUtils.h"
#include "StorageKitTester.h"
#include <TestShell.h>
status_t DecodeResult(status_t result) {
if (!shell.BeVerbose())
if (!BTestShell::GlobalBeVerbose())
return result;
std::string str;
+20 -4
View File
@@ -2,6 +2,7 @@
#include <TestShell.h>
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
BTestCase::BTestCase(std::string name)
: CppUnit::TestCase(name)
@@ -17,8 +18,7 @@ BTestCase::tearDown() {
void
BTestCase::NextSubTest() {
BTestShell *shell = BTestShell::Shell();
if (shell && shell->BeVerbose()) {
if (BeVerbose()) {
printf("[%ld]", fSubTestNum++);
fflush(stdout);
}
@@ -26,11 +26,21 @@ BTestCase::NextSubTest() {
void
BTestCase::NextSubTestBlock() {
BTestShell *shell = BTestShell::Shell();
if (shell && shell->BeVerbose())
if (BeVerbose())
printf("\n");
}
void
BTestCase::Outputf(const char *str, ...) {
if (BeVerbose()) {
va_list args;
va_start(args, str);
vprintf(str, args);
va_end(args);
fflush(stdout);
}
}
/*! To return to the last saved working directory, call RestoreCWD(). */
void
BTestCase::SaveCWD() {
@@ -49,3 +59,9 @@ BTestCase::RestoreCWD(const char *alternate) {
else if (alternate != NULL)
chdir(alternate);
}
bool
BTestCase::BeVerbose() {
BTestShell *shell = BTestShell::Shell();
return ((shell && shell->BeVerbose()) || !shell);
}
+94 -44
View File
@@ -15,17 +15,22 @@
#include <string>
#include <vector>
BTestShell *BTestShell::fGlobalShell = NULL;
const char BTestShell::indent[] = " ";
BTestShell::BTestShell(const std::string &description, SyncObject *syncObject)
: fVerbosityLevel(v2)
, fDescription(description)
, fTestResults(syncObject)
, fListTestsAndExit(false)
{
};
status_t
BTestShell::AddSuite(BTestSuite *suite) {
if (suite) {
cout << "Adding suite '" << suite->getName() << "'" << endl;
if (Verbosity() >= v3)
cout << "Adding suite '" << suite->getName() << "'" << endl;
// Add the suite
fSuites[suite->getName()] = suite;
@@ -67,14 +72,18 @@ BTestShell::LoadSuitesFrom(BDirectory *libDir) {
status_t err;
err = addonEntry.GetPath(&addonPath);
if (!err) {
// cout << "Checking " << addonPath.Path() << "..." << flush;
addonImage = load_add_on(addonPath.Path());
err = (addonImage > 0 ? B_OK : B_ERROR);
}
if (!err) {
// cout << "..." << endl;
err = get_image_symbol(addonImage,
"getTestSuite",
B_SYMBOL_TYPE_TEXT,
reinterpret_cast<void **>(&func));
} else {
// cout << " !!! err == " << err << endl;
}
if (!err)
err = AddSuite(func());
@@ -90,6 +99,16 @@ BTestShell::Run(int argc, char *argv[]) {
if (!ProcessArguments(argc, argv))
return 0;
// Load any dynamically loadable tests we can find
LoadDynamicSuites();
// See if the user requested a list of tests. If so,
// print and bail.
if (fListTestsAndExit) {
PrintInstalledTests();
return 0;
}
// Add the proper tests to our suite (or exit if there
// are no tests installed).
CppUnit::TestSuite suite;
@@ -106,12 +125,19 @@ BTestShell::Run(int argc, char *argv[]) {
for (i = fTests.begin(); i != fTests.end(); ++i)
suite.addTest( i->second );
} else {
} else {
// One or more specified, so only run those
std::set<std::string>::const_iterator i;
for (i = fTestsToRun.begin(); i != fTestsToRun.end(); ++i)
suite.addTest( fTests[*i] );
for (i = fTestsToRun.begin(); i != fTestsToRun.end(); ++i) {
// Make sure it's a valid test
if (fTests.find(*i) != fTests.end()) {
suite.addTest( fTests[*i] );
} else {
cout << endl << "ERROR: Invalid argument \"" << *i << "\"" << endl;
PrintHelp();
return 0;
}
}
}
@@ -123,8 +149,6 @@ BTestShell::Run(int argc, char *argv[]) {
return 0;
}
BTestShell *BTestShell::fGlobalShell = NULL;
BTestShell::VerbosityLevel
BTestShell::Verbosity() const {
return fVerbosityLevel;
@@ -137,9 +161,15 @@ BTestShell::PrintDescription(int argc, char *argv[]) {
void
BTestShell::PrintHelp() {
const char indent[] = " ";
cout << endl;
cout << "VALID ARGUMENTS: " << endl;
PrintValidArguments();
cout << endl;
}
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;
@@ -150,8 +180,20 @@ BTestShell::PrintHelp() {
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;
}
void
BTestShell::PrintInstalledTests() {
// Print out the list of installed tests
cout << "------------------------------------------------------------------------------" << endl;
cout << "Available Tests:" << endl;
cout << "------------------------------------------------------------------------------" << endl;
std::map<std::string, CppUnit::Test*>::const_iterator i;
for (i = fTests.begin(); i != fTests.end(); ++i)
cout << i->first << endl;
cout << endl;
}
bool
@@ -166,51 +208,47 @@ BTestShell::ProcessArguments(int argc, char *argv[]) {
for (int i = 1; i < argc; i++) {
std::string str(argv[i]);
if (str == "--help") {
PrintDescription(argc, argv);
PrintHelp();
return false;
}
else if (str == "--list") {
// Print out the list of installed tests
cout << "------------------------------------------------------------------------------" << endl;
cout << "Available Tests:" << endl;
cout << "------------------------------------------------------------------------------" << endl;
std::map<std::string, CppUnit::Test*>::const_iterator i;
for (i = fTests.begin(); i != fTests.end(); ++i)
cout << i->first << endl;
cout << endl;
return false;
}
else if (str == "-v0") {
fVerbosityLevel = v0;
}
else if (str == "-v1") {
fVerbosityLevel = v1;
}
else if (str == "-v2") {
fVerbosityLevel = v2;
}
else if (fTests.find(str) != fTests.end()) {
fTestsToRun.insert(str);
}
else {
cout << endl << "ERROR: Invalid argument \"" << str << "\"" << endl;
PrintHelp();
return false;
}
if (!ProcessArgument(str, argc, argv))
return false;
}
return true;
}
bool
BTestShell::ProcessArgument(std::string arg, int argc, char *argv[]) {
if (arg == "--help") {
PrintDescription(argc, argv);
PrintHelp();
return false;
}
else if (arg == "--list") {
fListTestsAndExit = true;
}
else if (arg == "-v0") {
fVerbosityLevel = v0;
}
else if (arg == "-v1") {
fVerbosityLevel = v1;
}
else if (arg == "-v2") {
fVerbosityLevel = v2;
}
else if (arg == "-v3") {
fVerbosityLevel = v3;
}
else {
fTestsToRun.insert(arg);
}
return true;
}
void
BTestShell::InitOutput() {
// For vebosity level 2, we output info about each test
// as we go. This involves a custom CppUnit::TestListener
// class.
if (fVerbosityLevel == v2) {
if (fVerbosityLevel >= v2) {
cout << "------------------------------------------------------------------------------" << endl;
cout << "Tests" << endl;
cout << "------------------------------------------------------------------------------" << endl;
@@ -269,3 +307,15 @@ BTestShell::PrintResults() {
}
void
BTestShell::LoadDynamicSuites() {
std::set<std::string>::iterator i;
for (i = fLibDirs.begin(); i != fLibDirs.end(); i++) {
BDirectory libDir((*i).c_str());
int count = LoadSuitesFrom(&libDir);
if (Verbosity() >= v3) {
cout << "Loaded " << count << " suite" << (count == 1 ? "" : "s");
cout << " from " << *i << endl;
}
}
}
+31
View File
@@ -46,6 +46,37 @@ BThreadedTestCase::NextSubTest() {
BTestCase::NextSubTest();
}
void
BThreadedTestCase::Outputf(const char *str, ...) {
if (BeVerbose()) {
// Figure out if this is a multithreaded test or not
thread_id id = find_thread(NULL);
bool isSingleThreaded;
{
BAutolock lock(fUpdateLock);
isSingleThreaded = fNumberMap.find(id) == fNumberMap.end();
}
if (isSingleThreaded) {
va_list args;
va_start(args, str);
vprintf(str, args);
va_end(args);
fflush(stdout);
} else {
va_list args;
va_start(args, str);
char msg[1024]; // Need a longer string? Change the constant or change the function. :-)
vsprintf(msg, str, args);
va_end(args);
{
// Acquire the update lock and post our update
BAutolock lock(fUpdateLock);
fUpdateList.push_back(std::string(msg));
}
}
}
}
void
BThreadedTestCase::InitThreadInfo(thread_id id, std::string threadName) {
BAutolock lock(fUpdateLock); // Lock the number map