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
+111
View File
@@ -220,6 +220,117 @@ rule Server
NOTFILE obostests ; NOTFILE obostests ;
NOTFILE r5tests ; NOTFILE r5tests ;
rule CommonTestLib
{
# CommonUnitTest <target> : <sources> : <obos libraries>
# : <r5 libraries> : <public headers>;
# Builds a unit test for both OBOS and R5 modules.
# <target> The name of the target.
# <sources> The list of sources.
# <obos libraries> A list of link libraries for the OBOS tests (as passed
# to LinkSharedOSLibs).
# <r5 libraries> A list of link libraries for the R5 tests (as passed
# to LinkSharedOSLibs).
# <public headers> A list of public header dirs (as passed to
# UsePublicHeaders).
local testlibdir = [ FDirName $(OBOS_TEST_DIR) lib ] ; #/boot/home/config/lib/obos_tests ;
TestLib $(1) : $(2) : $(testlibdir) : $(3) : $(5) ;
R5TestLib $(1) : $(2) : $(testlibdir) : $(4) ;
}
rule TestLib
{
# TestLib <target> : <sources> : <dest> : <libraries> : <public headers>
# Builds a unit test library for an OBOS module.
# <target> The name of the target.
# <sources> The list of sources.
# <dest> The directory for the target (as passed to FDirName).
# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
# <public headers> A list of public header dirs (as passed to
# UsePublicHeaders).
local target = $(1) ;
local sources = $(2) ;
local dest = $(3) ;
local libraries = $(4) ;
local headerDirs = $(5) ;
# Turn optimization off.
local optim = $(OPTIM) ;
OPTIM = ;
# SetupIncludes ;
UseCppUnitHeaders ;
SetupObjectsDir ;
MakeLocateObjects $(sources) ;
Main $(target) : $(sources) ;
MakeLocate $(target) : $(dest) ;
DEPENDS $(target) : libcppunit.so ;
DEPENDS obostests : $(target) ;
LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
UsePublicObjectHeaders $(sources) : $(headerDirs) ;
ObjectDefines $(sources) : TEST_OBOS ;
LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
# Turn debugging on. That is usually desired for test code.
ObjectCcFlags $(sources) : "-g" ;
ObjectC++Flags $(sources) : "-g" ;
# Turn optimization on again.
OPTIM = $(optim) ;
}
rule R5TestLib
{
# R5UnitTest <target> : <sources> : <dest> : <libraries>
# Builds a unit test for an R5 module. "_r5" is appended to the object
# and the target name.
# <target> The name of the target.
# <sources> The list of sources.
# <dest> The directory for the target (as passed to FDirName).
# <libraries> A list of link libraries (as passed to LinkSharedOSLibs).
local target = $(1:B)_r5$(1:S) ;
local sources = $(2) ;
local dest = $(3)_r5 ;
local libraries = $(4) ;
local objects = [ R5ObjectNames $(sources) ] ;
# Turn optimization off.
local optim = $(OPTIM) ;
OPTIM = ;
UseCppUnitHeaders ;
SetupObjectsDir ;
MakeLocateObjects $(objects) ;
# Our Main replacement.
MainFromObjects $(target) : $(objects) ;
local source ;
for source in [ FGristFiles $(sources) ]
{
local object = [ R5ObjectNames $(source) ] ;
Object $(object) : $(source) ;
Depends obj : $(object) ;
}
MakeLocate $(target) : $(dest) ;
DEPENDS $(target) : libcppunit.so ;
DEPENDS r5tests : $(target) ;
LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ;
ObjectDefines $(objects) : TEST_R5 ;
LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ;
# Turn debugging on. That is usually desired for test code.
ObjectCcFlags $(objects) : "-g" ;
ObjectC++Flags $(objects) : "-g" ;
# Turn optimization on again.
OPTIM = $(optim) ;
}
rule CommonUnitTest rule CommonUnitTest
{ {
# CommonUnitTest <target> : <sources> : <dest> : <obos libraries> # CommonUnitTest <target> : <sources> : <dest> : <obos libraries>
+8
View File
@@ -16,6 +16,11 @@ public:
//! Starts a new sub test block (i.e. prints a newline :-) //! Starts a new sub test block (i.e. prints a newline :-)
virtual void NextSubTestBlock(); virtual void NextSubTestBlock();
/*! \brief Prints to standard out just like printf, except shell verbosity
settings are honored.
*/
virtual void Outputf(const char *str, ...);
//! Saves the location of the current working directory. //! Saves the location of the current working directory.
void SaveCWD(); void SaveCWD();
@@ -24,6 +29,9 @@ public:
//! Restores the current working directory to last directory saved by a call to SaveCWD(). //! Restores the current working directory to last directory saved by a call to SaveCWD().
void RestoreCWD(const char *alternate = NULL); void RestoreCWD(const char *alternate = NULL);
protected: protected:
//! Returns true if the current shell settings allow us to print to standard output.
bool BeVerbose();
bool fValidCWD; bool fValidCWD;
char fCurrentWorkingDir[B_PATH_NAME_LENGTH+1]; char fCurrentWorkingDir[B_PATH_NAME_LENGTH+1];
int32 fSubTestNum; int32 fSubTestNum;
+41 -13
View File
@@ -64,41 +64,69 @@ public:
// Returns true if verbosity is high enough that individual tests are // Returns true if verbosity is high enough that individual tests are
// allowed to make noise. // allowed to make noise.
bool BeVerbose() const { return Verbosity() >= v2; }; bool BeVerbose() const { return Verbosity() >= v2; };
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 :-).
static BTestShell* Shell() { return fGlobalShell; }; static BTestShell* Shell() { return fGlobalShell; };
static void SetShell(BTestShell *shell) { fGlobalShell = shell; };
// Sets the global BTestShell pointer. The BTestShell class does
// not assume ownership of the object.
static void SetShell(BTestShell *shell) { fGlobalShell = shell; };
protected: protected:
VerbosityLevel fVerbosityLevel; VerbosityLevel fVerbosityLevel;
std::set<std::string> fTestsToRun; std::set<std::string> fTestsToRun;
std::map<std::string, CppUnit::Test*> fTests; std::map<std::string, CppUnit::Test*> fTests;
std::map<std::string, BTestSuite*> fSuites; std::map<std::string, BTestSuite*> fSuites;
std::set<std::string> fLibDirs;
CppUnit::TestResult fTestResults; CppUnit::TestResult fTestResults;
CppUnit::TestResultCollector fResultsCollector; CppUnit::TestResultCollector fResultsCollector;
std::string fDescription; std::string fDescription;
static BTestShell* fGlobalShell; static BTestShell* fGlobalShell;
static const char indent[];
bool fListTestsAndExit;
// Prints a brief description of the program and a guess as to //! Prints a brief description of the program.
// which Storage Kit library the app was linked with based on
// the filename of the app
virtual void PrintDescription(int argc, char *argv[]); virtual void PrintDescription(int argc, char *argv[]);
// Prints out command line argument instructions //! Prints out command line argument instructions
void PrintHelp(); void PrintHelp();
/*! \brief Prints out the list of valid command line arguments.
Called by PrintHelp().
*/
virtual void PrintValidArguments();
// Handles command line arguments; returns true if everything goes //! Prints out a list of all the currently available tests
// okay, false if not (or if the program just needs to terminate without void PrintInstalledTests();
// running any tests). Modifies settings in "settings" as necessary.
/*! \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.
*/
bool ProcessArguments(int argc, char *argv[]); bool ProcessArguments(int argc, char *argv[]);
//! Processes a single argument, given by the \c arg parameter.
virtual bool ProcessArgument(std::string arg, int argc, char *argv[]);
// Makes any necessary pre-test preparations //! Makes any necessary pre-test preparations
void InitOutput(); void InitOutput();
// Prints out the test results in the proper format per /*! \brief Prints out the test results in the proper format per
// the specified verbosity level. the specified verbosity level.
*/
void PrintResults(); void PrintResults();
/*! \brief Searches all the paths in \c fLibDirs, loading any dynamically
loadable suites it finds.
*/
virtual void LoadDynamicSuites();
private: private:
//! Prevents the use of the copy constructor. //! Prevents the use of the copy constructor.
BTestShell( const BTestShell &copy ); BTestShell( const BTestShell &copy );
+1 -1
View File
@@ -10,7 +10,7 @@ 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 BTestSuite : public CppUnit::Test {
public: public:
BTestSuite( std::string name ); BTestSuite( std::string name = "" );
virtual ~BTestSuite(); virtual ~BTestSuite();
virtual void run( CppUnit::TestResult *result ); virtual void run( CppUnit::TestResult *result );
+4 -1
View File
@@ -153,6 +153,7 @@ BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *resu
// Try to acquire the semaphore // Try to acquire the semaphore
err = acquire_sem_etc(fThreadSem, fThreads.size(), B_RELATIVE_TIMEOUT, 500000); err = acquire_sem_etc(fThreadSem, fThreads.size(), B_RELATIVE_TIMEOUT, 500000);
// Get a pointer to the current global shell
BTestShell *shell = BTestShell::Shell(); BTestShell *shell = BTestShell::Shell();
// Empty the UpdateList // Empty the UpdateList
@@ -161,7 +162,9 @@ BThreadedTestCaller<TestClass, ExpectedException>::run(CppUnit::TestResult *resu
i != list.end(); i != list.end();
i++) i++)
{ {
if (shell && shell->BeVerbose()) { // Only print to standard out if the current global shell
// lets us (or if no global shell is designated).
if ((shell && shell->BeVerbose()) || !shell) {
printf("%s", (*i).c_str()); printf("%s", (*i).c_str());
fflush(stdout); fflush(stdout);
} }
+10
View File
@@ -18,6 +18,16 @@ public:
thread in which it's called (i.e. [A.0][B.0][A.1][A.2][B.1]...). */ thread in which it's called (i.e. [A.0][B.0][A.1][A.2][B.1]...). */
virtual void NextSubTest(); virtual void NextSubTest();
/*! \brief Prints to standard out just like printf, except shell verbosity
settings are honored, and output from threads other than the main thread
happens before the test is over.
\note Currently your output is limited to a length of 1024 characters. If
you really need to print a single string that's long than that, fix the
function yourself :-).
*/
virtual void Outputf(const char *str, ...);
//! Saves the location of the current working directory. //! Saves the location of the current working directory.
void SaveCWD(); void SaveCWD();
+7 -7
View File
@@ -20,22 +20,22 @@ ExampleTest::Suite() {
// Add a multithreaded test // Add a multithreaded test
ExampleTest *test = new ExampleTest("This name is never used, just so you know :-)"); 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("A", &ExampleTest::TestFunc1);
caller->addThread("B", &ExampleTest::TestFunc2); caller->addThread("B", &ExampleTest::TestFunc2);
caller->addThread("C", &ExampleTest::TestFunc3); caller->addThread("C", &ExampleTest::TestFunc3);
suite->addTest(caller); suite->addTest(caller);
// And another // And another
caller = new BThreadedTestCaller<ExampleTest>("MultiThreaded Test #2"); caller = new BThreadedTestCaller<ExampleTest>("ExampleTests::MultiThreaded Test #2");
caller->addThread("Thread1", &ExampleTest::TestFunc1); caller->addThread("Thread1", &ExampleTest::TestFunc1);
caller->addThread("Thread2", &ExampleTest::TestFunc1); caller->addThread("Thread2", &ExampleTest::TestFunc1);
caller->addThread("Thread3", &ExampleTest::TestFunc1); caller->addThread("Thread3", &ExampleTest::TestFunc1);
suite->addTest(caller); suite->addTest(caller);
// And some single threaded ones // And some single threaded ones
suite->addTest(new CppUnit::TestCaller<ExampleTest>("SingleThreaded Test #1", &ExampleTest::TestFunc1)); suite->addTest(new CppUnit::TestCaller<ExampleTest>("ExampleTests::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 #2", &ExampleTest::TestFunc2));
return suite; return suite;
} }
@@ -48,10 +48,10 @@ ExampleTest::TestFunc1() {
// Get the lock and do our business // Get the lock and do our business
NextSubTest(); NextSubTest();
fLocker->Lock(); fLocker->Lock();
// printf("TestFunc1() -- %d + 10 = %d\n", fNum, fNum+10);
fNum += 10; fNum += 10;
fLocker->Unlock(); fLocker->Unlock();
snooze(sleeptime); snooze(sleeptime);
// Outputf("(1:%d)", i);
} }
} }
@@ -61,10 +61,10 @@ ExampleTest::TestFunc2() {
// Get the lock and do our business // Get the lock and do our business
NextSubTest(); NextSubTest();
fLocker->Lock(); fLocker->Lock();
// printf("TestFunc2() -- %d * 2 = %d\n", fNum, fNum*2);
fNum *= 2; fNum *= 2;
fLocker->Unlock(); fLocker->Unlock();
snooze(sleeptime); snooze(sleeptime);
// Outputf("(2:%d)", i);
} }
} }
@@ -74,10 +74,10 @@ ExampleTest::TestFunc3() {
// Get the lock and do our business // Get the lock and do our business
NextSubTest(); NextSubTest();
fLocker->Lock(); fLocker->Lock();
// printf("TestFunc3() -- %d - 5 = %d\n", fNum, fNum-5);
fNum += 10; fNum += 10;
fLocker->Unlock(); fLocker->Unlock();
snooze(sleeptime); snooze(sleeptime);
// Outputf("(3:%d)", i);
} }
} }
+1 -1
View File
@@ -9,7 +9,7 @@ public:
ExampleTest(std::string name = ""); ExampleTest(std::string name = "");
virtual ~ExampleTest() { delete fLocker; } virtual ~ExampleTest() { delete fLocker; }
static Test* Suite(); static CppUnit::Test* Suite();
void TestFunc1(); // num += 10 void TestFunc1(); // num += 10
void TestFunc2(); // num *= 2 void TestFunc2(); // num *= 2
+2 -2
View File
@@ -3,7 +3,7 @@
#include <ExampleTest.h> #include <ExampleTest.h>
BTestSuite* getTestSuite() { BTestSuite* getTestSuite() {
BTestSuite *suite = new BTestSuite("Example"); BTestSuite *suite = new BTestSuite("ExampleSuite");
suite->addTest("BExample", ExampleTest::Suite()); suite->addTest("ExampleTests", ExampleTest::Suite());
return suite; return suite;
} }
+16
View File
@@ -1,4 +1,20 @@
SubDir OBOS_TOP src tests ; 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 add-ons ;
SubInclude OBOS_TOP src tests kits ; SubInclude OBOS_TOP src tests kits ;
+33 -4
View File
@@ -1,6 +1,5 @@
#include "UnitTester.h" #include "UnitTester.h"
#include <SemaphoreSyncObject.h> #include <SemaphoreSyncObject.h>
#include <string>
#include <Directory.h> #include <Directory.h>
// ##### Include headers for statically linked tests here ##### // ##### Include headers for statically linked tests here #####
@@ -15,15 +14,15 @@ int main(int argc, char *argv[]) {
BTestShell::SetShell(&shell); BTestShell::SetShell(&shell);
// Load our dynamically linked tests // Load our dynamically linked tests
BDirectory libDir("./lib");
int count = shell.LoadSuitesFrom(&libDir);
cout << "Loaded " << count << " suites" << endl;
return shell.Run(argc, argv); return shell.Run(argc, argv);
} }
const std::string UnitTesterShell::defaultLibDir = "./lib";
UnitTesterShell::UnitTesterShell(const std::string &description, SyncObject *syncObject) UnitTesterShell::UnitTesterShell(const std::string &description, SyncObject *syncObject)
: BTestShell(description, 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 << "of testing and verifying the various kits, classes, functions," << endl;
cout << "and the like that comprise OpenBeOS." << endl; cout << "and the like that comprise OpenBeOS." << endl;
/*
if (AppName.rfind("UnitTester_r5") != std::string::npos) { if (AppName.rfind("UnitTester_r5") != std::string::npos) {
cout << endl; cout << endl;
cout << "Judging by its name (UnitTester_r5), this copy was" << 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 << "Judging by its name (UnitTester), this copy was probably" << endl;
cout << "linked against our own OpenBeOS implementations." << 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__ #define __testing_is_delightful_h__
#include <TestShell.h> #include <TestShell.h>
#include <string>
class UnitTesterShell : public BTestShell { class UnitTesterShell : public BTestShell {
public: public:
UnitTesterShell(const std::string &description = "", SyncObject *syncObject = 0); 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 PrintDescription(int argc, char *argv[]);
virtual void PrintValidArguments();
virtual bool ProcessArgument(std::string arg, int argc, char *argv[]);
virtual void LoadDynamicSuites();
}; };
//extern UnitTesterShell shell; //extern UnitTesterShell shell;
+3 -21
View File
@@ -23,7 +23,7 @@ count_available_fds()
// constructor // constructor
BasicTest::BasicTest() BasicTest::BasicTest()
: StorageKit::TestCase(), : BTestCase(),
fSubTestNumber(0), fSubTestNumber(0),
fAvailableFDs(0) fAvailableFDs(0)
{ {
@@ -33,6 +33,7 @@ BasicTest::BasicTest()
void void
BasicTest::setUp() BasicTest::setUp()
{ {
BTestCase::setUp();
fAvailableFDs = count_available_fds(); fAvailableFDs = count_available_fds();
SaveCWD(); SaveCWD();
fSubTestNumber = 0; fSubTestNumber = 0;
@@ -43,32 +44,13 @@ void
BasicTest::tearDown() BasicTest::tearDown()
{ {
RestoreCWD(); RestoreCWD();
nextSubTestBlock();
int32 availableFDs = count_available_fds(); int32 availableFDs = count_available_fds();
if (availableFDs != fAvailableFDs) { if (availableFDs != fAvailableFDs) {
printf("WARNING: Number of available file descriptors has changed " printf("WARNING: Number of available file descriptors has changed "
"during test: %ld -> %ld\n", fAvailableFDs, availableFDs); "during test: %ld -> %ld\n", fAvailableFDs, availableFDs);
fAvailableFDs = availableFDs; fAvailableFDs = availableFDs;
} }
} BTestCase::tearDown();
// nextSubTest
void
BasicTest::nextSubTest()
{
if (shell.BeVerbose()) {
printf("[%ld]", fSubTestNumber++);
fflush(stdout);
}
}
// nextSubTestBlock
void
BasicTest::nextSubTestBlock()
{
if (shell.BeVerbose())
printf("\n");
fSubTestNumber = 0;
} }
// execCommand // execCommand
+7 -8
View File
@@ -3,14 +3,13 @@
#ifndef __sk_basic_test_h__ #ifndef __sk_basic_test_h__
#define __sk_basic_test_h__ #define __sk_basic_test_h__
#include <SupportDefs.h>
#include <TestCase.h>
#include <TestShell.h>
#include <set> #include <set>
#include <stdio.h> #include <stdio.h>
#include <SupportDefs.h> class BasicTest : public BTestCase
#include "StorageKitTester.h"
class BasicTest : public StorageKit::TestCase
{ {
public: public:
BasicTest(); BasicTest();
@@ -23,8 +22,8 @@ public:
// helper functions // helper functions
void nextSubTest(); // void nextSubTest();
void nextSubTestBlock(); // void nextSubTestBlock();
static void execCommand(const string &command); static void execCommand(const string &command);
@@ -110,7 +109,7 @@ public:
fTestedNames.clear(); 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()); bool result = (fUntestedNames.find(name) != fUntestedNames.end());
if (result) { 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 ; SubDir OBOS_TOP src tests kits storage ;
# Exclude the whole thing until it compiles again. # EntryTest.cpp
if "" # FileTest.cpp
{ # FindDirectoryTest.cpp
# MimeTypeTest.cpp
# PathTest.cpp
# QueryTest.cpp
# ResourcesTest.cpp
# ResourceStringsTest.cpp
# StatableTest.cpp
# SymLinkTest.cpp
# TestApp.cpp
CommonUnitTest StorageKitTester CommonTestLib libstoragetest.so
: StorageKitTester.cpp : StorageKitTestAddon.cpp
BasicTest.cpp BasicTest.cpp
DirectoryTest.cpp DirectoryTest.cpp
EntryTest.cpp
FileTest.cpp
FindDirectoryTest.cpp
MimeTypeTest.cpp
NodeTest.cpp NodeTest.cpp
PathTest.cpp PathTest.cpp
QueryTest.cpp
ResourcesTest.cpp
ResourceStringsTest.cpp
StatableTest.cpp StatableTest.cpp
SymLinkTest.cpp
TestApp.cpp
TestUtils.cpp TestUtils.cpp
: kits storage
: libstorage.so be stdc++.r4 : libstorage.so be stdc++.r4
: be stdc++.r4 : be stdc++.r4
: storage : storage
@@ -29,21 +27,20 @@ CommonUnitTest StorageKitTester
# To run the tests the libraries must be around. # 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)>libstorage.so : $(libdir) ;
MakeLocate <$(SOURCE_GRIST)>libbeadapter.so : $(libdir) ; MakeLocate <$(SOURCE_GRIST)>libbeadapter.so : $(libdir) ;
RelSymLink <$(SOURCE_GRIST)>libstorage.so : libstorage.so ; RelSymLink <$(SOURCE_GRIST)>libstorage.so : libstorage.so ;
RelSymLink <$(SOURCE_GRIST)>libbeadapter.so : libbeadapter.so ; RelSymLink <$(SOURCE_GRIST)>libbeadapter.so : libbeadapter.so ;
DEPENDS StorageKitTester StorageKitTester_r5 DEPENDS libstoragetest.so
: <$(SOURCE_GRIST)>libstorage.so <$(SOURCE_GRIST)>libbeadapter.so ; : <$(SOURCE_GRIST)>libstorage.so <$(SOURCE_GRIST)>libbeadapter.so ;
} }
# To run the tests some test files must be around. # To run the tests some test files must be around.
{ {
local resdir = <storage!kit!test!files>resources ; 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 ] ; 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 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 Read/Write/Remove Test", &NodeTest::AttrTest) );
suite->addTest( new CppUnit::TestCaller<NodeTest>("BNode::Attribute Rename Test" 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)" " (NOTE: test not actually performed with R5 libraries)"
#endif #endif
, &NodeTest::AttrRenameTest) ); , &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::Equality Test", &NodeTest::EqualityTest) );
suite->addTest( new CppUnit::TestCaller<NodeTest>("BNode::Assignment Test", &NodeTest::AssignmentTest) ); suite->addTest( new CppUnit::TestCaller<NodeTest>("BNode::Assignment Test", &NodeTest::AssignmentTest) );
suite->addTest( new CppUnit::TestCaller<NodeTest>("BNode::Lock Test" 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)" " (NOTE: test not actually performed with OpenBeOS Posix libraries)"
#endif #endif
, &NodeTest::LockTest) ); , &NodeTest::LockTest) );
@@ -202,76 +202,76 @@ NodeTest::InitTest1()
const char *nonExistingSuper = nonExistingSuperDirname; const char *nonExistingSuper = nonExistingSuperDirname;
const char *nonExistingRel = nonExistingRelDirname; const char *nonExistingRel = nonExistingRelDirname;
// 1. default constructor // 1. default constructor
nextSubTest(); NextSubTest();
{ {
BNode node; BNode node;
CPPUNIT_ASSERT( node.InitCheck() == B_NO_INIT ); CPPUNIT_ASSERT( node.InitCheck() == B_NO_INIT );
} }
// 2. BNode(const char*) // 2. BNode(const char*)
nextSubTest(); NextSubTest();
{ {
BNode node(fileLink); BNode node(fileLink);
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BNode node(nonExisting); BNode node(nonExisting);
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
} }
nextSubTest(); NextSubTest();
{ {
BNode node((const char *)NULL); BNode node((const char *)NULL);
CPPUNIT_ASSERT( equals(node.InitCheck(), B_BAD_VALUE, B_NO_INIT) ); CPPUNIT_ASSERT( equals(node.InitCheck(), B_BAD_VALUE, B_NO_INIT) );
} }
nextSubTest(); NextSubTest();
{ {
BNode node(""); BNode node("");
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
} }
nextSubTest(); NextSubTest();
{ {
BNode node(existingFile); BNode node(existingFile);
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BNode node(existingDir); BNode node(existingDir);
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BNode node(tooLongEntryname); BNode node(tooLongEntryname);
CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG ); CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG );
} }
// 3. BNode(const BEntry*) // 3. BNode(const BEntry*)
nextSubTest(); NextSubTest();
{ {
BEntry entry(dirLink); BEntry entry(dirLink);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK ); CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
BNode node(&entry); BNode node(&entry);
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BEntry entry(nonExisting); BEntry entry(nonExisting);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK ); CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
BNode node(&entry); BNode node(&entry);
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
} }
nextSubTest(); NextSubTest();
{ {
BNode node((BEntry *)NULL); BNode node((BEntry *)NULL);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE ); CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
} }
nextSubTest(); NextSubTest();
{ {
BEntry entry; BEntry entry;
BNode node(&entry); BNode node(&entry);
CPPUNIT_ASSERT( equals(node.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) ); CPPUNIT_ASSERT( equals(node.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) );
} }
nextSubTest(); NextSubTest();
{ {
BEntry entry(existingFile); BEntry entry(existingFile);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK ); CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -279,7 +279,7 @@ NodeTest::InitTest1()
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BEntry entry(existingDir); BEntry entry(existingDir);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK ); CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -287,7 +287,7 @@ NodeTest::InitTest1()
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BEntry entry(tooLongEntryname); BEntry entry(tooLongEntryname);
// R5 returns E2BIG instead of B_NAME_TOO_LONG // R5 returns E2BIG instead of B_NAME_TOO_LONG
@@ -297,7 +297,7 @@ NodeTest::InitTest1()
} }
// 4. BNode(const entry_ref*) // 4. BNode(const entry_ref*)
nextSubTest(); NextSubTest();
{ {
BEntry entry(dirLink); BEntry entry(dirLink);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK ); CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -306,7 +306,7 @@ NodeTest::InitTest1()
BNode node(&ref); BNode node(&ref);
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BEntry entry(nonExisting); BEntry entry(nonExisting);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK ); CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -315,12 +315,12 @@ NodeTest::InitTest1()
BNode node(&ref); BNode node(&ref);
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
} }
nextSubTest(); NextSubTest();
{ {
BNode node((entry_ref *)NULL); BNode node((entry_ref *)NULL);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE ); CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
} }
nextSubTest(); NextSubTest();
{ {
BEntry entry(existingFile); BEntry entry(existingFile);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK ); CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -329,7 +329,7 @@ NodeTest::InitTest1()
BNode node(&ref); BNode node(&ref);
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BEntry entry(existingDir); BEntry entry(existingDir);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK ); CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
@@ -340,73 +340,73 @@ NodeTest::InitTest1()
} }
// 5. BNode(const BDirectory*, const char*) // 5. BNode(const BDirectory*, const char*)
nextSubTest(); NextSubTest();
{ {
BDirectory pathDir(dirSuperLink); BDirectory pathDir(dirSuperLink);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK ); CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, dirRelLink); BNode node(&pathDir, dirRelLink);
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BDirectory pathDir(dirSuperLink); BDirectory pathDir(dirSuperLink);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK ); CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, dirLink); BNode node(&pathDir, dirLink);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE ); CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
} }
nextSubTest(); NextSubTest();
{ {
BDirectory pathDir(nonExistingSuper); BDirectory pathDir(nonExistingSuper);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK ); CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, nonExistingRel); BNode node(&pathDir, nonExistingRel);
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
} }
nextSubTest(); NextSubTest();
{ {
BNode node((BDirectory *)NULL, (const char *)NULL); BNode node((BDirectory *)NULL, (const char *)NULL);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE ); CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
} }
nextSubTest(); NextSubTest();
{ {
BNode node((BDirectory *)NULL, dirLink); BNode node((BDirectory *)NULL, dirLink);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE ); CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
} }
nextSubTest(); NextSubTest();
{ {
BDirectory pathDir(dirSuperLink); BDirectory pathDir(dirSuperLink);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK ); CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, (const char *)NULL); BNode node(&pathDir, (const char *)NULL);
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE ); CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
} }
nextSubTest(); NextSubTest();
{ {
BDirectory pathDir(dirSuperLink); BDirectory pathDir(dirSuperLink);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK ); CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, ""); BNode node(&pathDir, "");
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BDirectory pathDir(existingSuperFile); BDirectory pathDir(existingSuperFile);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK ); CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, existingRelFile); BNode node(&pathDir, existingRelFile);
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BDirectory pathDir(existingSuperDir); BDirectory pathDir(existingSuperDir);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK ); CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, existingRelDir); BNode node(&pathDir, existingRelDir);
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
} }
nextSubTest(); NextSubTest();
{ {
BDirectory pathDir(tooLongSuperEntryname); BDirectory pathDir(tooLongSuperEntryname);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK ); CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
BNode node(&pathDir, tooLongRelEntryname); BNode node(&pathDir, tooLongRelEntryname);
CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG ); CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG );
} }
nextSubTest(); NextSubTest();
{ {
BDirectory pathDir(fileSuperDirname); BDirectory pathDir(fileSuperDirname);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK ); CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
@@ -434,155 +434,155 @@ NodeTest::InitTest2()
const char *nonExistingRel = nonExistingRelDirname; const char *nonExistingRel = nonExistingRelDirname;
BNode node; BNode node;
// 2. BNode(const char*) // 2. BNode(const char*)
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( node.SetTo(fileLink) == B_OK ); CPPUNIT_ASSERT( node.SetTo(fileLink) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( node.SetTo(nonExisting) == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.SetTo(nonExisting) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == 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, CPPUNIT_ASSERT( equals(node.SetTo((const char *)NULL), B_BAD_VALUE,
B_NO_INIT) ); B_NO_INIT) );
CPPUNIT_ASSERT( equals(node.InitCheck(), 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.SetTo("") == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( node.SetTo(existingFile) == B_OK ); CPPUNIT_ASSERT( node.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( node.SetTo(existingDir) == B_OK ); CPPUNIT_ASSERT( node.SetTo(existingDir) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( node.SetTo(tooLongEntryname) == B_NAME_TOO_LONG ); CPPUNIT_ASSERT( node.SetTo(tooLongEntryname) == B_NAME_TOO_LONG );
CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG ); CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG );
// 3. BNode(const BEntry*) // 3. BNode(const BEntry*)
nextSubTest(); NextSubTest();
BEntry entry(dirLink); BEntry entry(dirLink);
CPPUNIT_ASSERT( entry.InitCheck() == B_OK ); CPPUNIT_ASSERT( entry.InitCheck() == B_OK );
CPPUNIT_ASSERT( node.SetTo(&entry) == B_OK ); CPPUNIT_ASSERT( node.SetTo(&entry) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(nonExisting) == B_OK ); CPPUNIT_ASSERT( entry.SetTo(nonExisting) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&entry) == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.SetTo(&entry) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == 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.SetTo((BEntry *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE ); CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
// //
nextSubTest(); NextSubTest();
entry.Unset(); entry.Unset();
CPPUNIT_ASSERT( entry.InitCheck() == B_NO_INIT ); CPPUNIT_ASSERT( entry.InitCheck() == B_NO_INIT );
CPPUNIT_ASSERT( equals(node.SetTo(&entry), B_BAD_ADDRESS, B_BAD_VALUE) ); CPPUNIT_ASSERT( equals(node.SetTo(&entry), B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( equals(node.InitCheck(), 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( entry.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&entry) == B_OK ); CPPUNIT_ASSERT( node.SetTo(&entry) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(existingDir) == B_OK ); CPPUNIT_ASSERT( entry.SetTo(existingDir) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&entry) == B_OK ); CPPUNIT_ASSERT( node.SetTo(&entry) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
// R5 returns E2BIG instead of B_NAME_TOO_LONG // R5 returns E2BIG instead of B_NAME_TOO_LONG
CPPUNIT_ASSERT( equals(entry.SetTo(tooLongEntryname), E2BIG, 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.SetTo(&entry), B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( equals(node.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) ); CPPUNIT_ASSERT( equals(node.InitCheck(), B_BAD_ADDRESS, B_BAD_VALUE) );
// 4. BNode(const entry_ref*) // 4. BNode(const entry_ref*)
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(dirLink) == B_OK ); CPPUNIT_ASSERT( entry.SetTo(dirLink) == B_OK );
entry_ref ref; entry_ref ref;
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK ); CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&ref) == B_OK ); CPPUNIT_ASSERT( node.SetTo(&ref) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(nonExisting) == B_OK ); CPPUNIT_ASSERT( entry.SetTo(nonExisting) == B_OK );
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK ); CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&ref) == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.SetTo(&ref) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == 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.SetTo((entry_ref *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE ); CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK ); CPPUNIT_ASSERT( entry.SetTo(existingFile) == B_OK );
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK ); CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&ref) == B_OK ); CPPUNIT_ASSERT( node.SetTo(&ref) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( entry.SetTo(existingDir) == B_OK ); CPPUNIT_ASSERT( entry.SetTo(existingDir) == B_OK );
CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK ); CPPUNIT_ASSERT( entry.GetRef(&ref) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&ref) == B_OK ); CPPUNIT_ASSERT( node.SetTo(&ref) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// 5. BNode(const BDirectory*, const char*) // 5. BNode(const BDirectory*, const char*)
nextSubTest(); NextSubTest();
BDirectory pathDir(dirSuperLink); BDirectory pathDir(dirSuperLink);
CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK ); CPPUNIT_ASSERT( pathDir.InitCheck() == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, dirRelLink) == B_OK ); CPPUNIT_ASSERT( node.SetTo(&pathDir, dirRelLink) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(dirSuperLink) == B_OK ); CPPUNIT_ASSERT( pathDir.SetTo(dirSuperLink) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, dirLink) == B_BAD_VALUE ); CPPUNIT_ASSERT( node.SetTo(&pathDir, dirLink) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE ); CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(nonExistingSuper) == B_OK ); CPPUNIT_ASSERT( pathDir.SetTo(nonExistingSuper) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, nonExistingRel) == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.SetTo(&pathDir, nonExistingRel) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.InitCheck() == B_ENTRY_NOT_FOUND );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( node.SetTo((BDirectory *)NULL, (const char *)NULL) CPPUNIT_ASSERT( node.SetTo((BDirectory *)NULL, (const char *)NULL)
== B_BAD_VALUE ); == B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == 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.SetTo((BDirectory *)NULL, dirLink) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE ); CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(dirSuperLink) == B_OK ); CPPUNIT_ASSERT( pathDir.SetTo(dirSuperLink) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, (const char *)NULL) == B_BAD_VALUE ); CPPUNIT_ASSERT( node.SetTo(&pathDir, (const char *)NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE ); CPPUNIT_ASSERT( node.InitCheck() == B_BAD_VALUE );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(dirSuperLink) == B_OK ); CPPUNIT_ASSERT( pathDir.SetTo(dirSuperLink) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, "") == B_OK ); CPPUNIT_ASSERT( node.SetTo(&pathDir, "") == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(existingSuperFile) == B_OK ); CPPUNIT_ASSERT( pathDir.SetTo(existingSuperFile) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, existingRelFile) == B_OK ); CPPUNIT_ASSERT( node.SetTo(&pathDir, existingRelFile) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(existingSuperDir) == B_OK ); CPPUNIT_ASSERT( pathDir.SetTo(existingSuperDir) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, existingRelDir) == B_OK ); CPPUNIT_ASSERT( node.SetTo(&pathDir, existingRelDir) == B_OK );
CPPUNIT_ASSERT( node.InitCheck() == B_OK ); CPPUNIT_ASSERT( node.InitCheck() == B_OK );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(tooLongSuperEntryname) == B_OK ); CPPUNIT_ASSERT( pathDir.SetTo(tooLongSuperEntryname) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, tooLongRelEntryname) == B_NAME_TOO_LONG ); CPPUNIT_ASSERT( node.SetTo(&pathDir, tooLongRelEntryname) == B_NAME_TOO_LONG );
CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG ); CPPUNIT_ASSERT( node.InitCheck() == B_NAME_TOO_LONG );
// //
nextSubTest(); NextSubTest();
CPPUNIT_ASSERT( pathDir.SetTo(fileSuperDirname) == B_OK ); CPPUNIT_ASSERT( pathDir.SetTo(fileSuperDirname) == B_OK );
CPPUNIT_ASSERT( node.SetTo(&pathDir, fileRelDirname) == B_ENTRY_NOT_FOUND ); CPPUNIT_ASSERT( node.SetTo(&pathDir, fileRelDirname) == B_ENTRY_NOT_FOUND );
CPPUNIT_ASSERT( node.InitCheck() == 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 ); CPPUNIT_ASSERT( node.RewindAttrs() == B_OK );
testSet.rewind(); testSet.rewind();
// R5: crashs, if passing a NULL buffer // R5: crashs, if passing a NULL buffer
#if !SK_TEST_R5 #if !TEST_R5
CPPUNIT_ASSERT( node.GetNextAttrName(NULL) == B_BAD_VALUE ); CPPUNIT_ASSERT( node.GetNextAttrName(NULL) == B_BAD_VALUE );
#endif #endif
} }
@@ -655,7 +655,7 @@ void
NodeTest::AttrDirTest() NodeTest::AttrDirTest()
{ {
// uninitialized objects // uninitialized objects
nextSubTest(); NextSubTest();
TestNodes testEntries; TestNodes testEntries;
CreateUninitializedNodes(testEntries); CreateUninitializedNodes(testEntries);
BNode *node; BNode *node;
@@ -667,7 +667,7 @@ NodeTest::AttrDirTest()
} }
testEntries.delete_all(); testEntries.delete_all();
// existing entries // existing entries
nextSubTest(); NextSubTest();
CreateRWNodes(testEntries); CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) { for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
AttrDirTest(*node); AttrDirTest(*node);
@@ -760,7 +760,7 @@ void
NodeTest::AttrTest() NodeTest::AttrTest()
{ {
// uninitialized objects // uninitialized objects
nextSubTest(); NextSubTest();
TestNodes testEntries; TestNodes testEntries;
CreateUninitializedNodes(testEntries); CreateUninitializedNodes(testEntries);
BNode *node; BNode *node;
@@ -775,7 +775,7 @@ NodeTest::AttrTest()
} }
testEntries.delete_all(); testEntries.delete_all();
// existing entries // existing entries
nextSubTest(); NextSubTest();
CreateRWNodes(testEntries); CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) { for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
AttrTest(*node); AttrTest(*node);
@@ -787,7 +787,7 @@ NodeTest::AttrTest()
void void
NodeTest::AttrRenameTest(BNode &node) NodeTest::AttrRenameTest(BNode &node)
{ {
#if !SK_TEST_R5 #if !TEST_R5
const char attr1[] = "StorageKit::SomeAttribute"; const char attr1[] = "StorageKit::SomeAttribute";
const char attr2[] = "StorageKit::AnotherAttribute"; const char attr2[] = "StorageKit::AnotherAttribute";
const char str[] = "This is my testing string and it rules your world."; const char str[] = "This is my testing string and it rules your world.";
@@ -837,7 +837,7 @@ void
NodeTest::AttrRenameTest() NodeTest::AttrRenameTest()
{ {
// uninitialized objects // uninitialized objects
nextSubTest(); NextSubTest();
TestNodes testEntries; TestNodes testEntries;
CreateUninitializedNodes(testEntries); CreateUninitializedNodes(testEntries);
BNode *node; BNode *node;
@@ -847,7 +847,7 @@ NodeTest::AttrRenameTest()
} }
testEntries.delete_all(); testEntries.delete_all();
// existing entries // existing entries
nextSubTest(); NextSubTest();
CreateRWNodes(testEntries); CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) { for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
AttrRenameTest(*node); AttrRenameTest(*node);
@@ -920,7 +920,7 @@ void
NodeTest::AttrInfoTest() NodeTest::AttrInfoTest()
{ {
// uninitialized objects // uninitialized objects
nextSubTest(); NextSubTest();
TestNodes testEntries; TestNodes testEntries;
CreateUninitializedNodes(testEntries); CreateUninitializedNodes(testEntries);
BNode *node; BNode *node;
@@ -931,7 +931,7 @@ NodeTest::AttrInfoTest()
} }
testEntries.delete_all(); testEntries.delete_all();
// existing entries // existing entries
nextSubTest(); NextSubTest();
CreateRWNodes(testEntries); CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) { for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
AttrInfoTest(*node); AttrInfoTest(*node);
@@ -985,7 +985,7 @@ NodeTest::AttrBStringTest(BNode &node)
BString readValue; BString readValue;
BString writeValue("test"); BString writeValue("test");
// R5: crashes, if supplying a NULL BString // 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.WriteAttrString(attrNames[0], NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( node.ReadAttrString(attrNames[0], NULL) == B_BAD_VALUE ); CPPUNIT_ASSERT( node.ReadAttrString(attrNames[0], NULL) == B_BAD_VALUE );
#endif #endif
@@ -993,7 +993,7 @@ NodeTest::AttrBStringTest(BNode &node)
B_BAD_ADDRESS, B_BAD_VALUE) ); B_BAD_ADDRESS, B_BAD_VALUE) );
CPPUNIT_ASSERT( equals(node.ReadAttrString(NULL, &readValue), CPPUNIT_ASSERT( equals(node.ReadAttrString(NULL, &readValue),
B_BAD_ADDRESS, B_BAD_VALUE) ); B_BAD_ADDRESS, B_BAD_VALUE) );
#if !SK_TEST_R5 #if !TEST_R5
CPPUNIT_ASSERT( node.WriteAttrString(NULL, NULL) == B_BAD_VALUE ); CPPUNIT_ASSERT( node.WriteAttrString(NULL, NULL) == B_BAD_VALUE );
#endif #endif
CPPUNIT_ASSERT( equals(node.ReadAttrString(NULL, NULL), CPPUNIT_ASSERT( equals(node.ReadAttrString(NULL, NULL),
@@ -1021,7 +1021,7 @@ void
NodeTest::AttrBStringTest() NodeTest::AttrBStringTest()
{ {
// uninitialized objects // uninitialized objects
nextSubTest(); NextSubTest();
TestNodes testEntries; TestNodes testEntries;
CreateUninitializedNodes(testEntries); CreateUninitializedNodes(testEntries);
BNode *node; BNode *node;
@@ -1035,7 +1035,7 @@ NodeTest::AttrBStringTest()
} }
testEntries.delete_all(); testEntries.delete_all();
// existing entries // existing entries
nextSubTest(); NextSubTest();
CreateRWNodes(testEntries); CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) { for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
AttrBStringTest(*node); AttrBStringTest(*node);
@@ -1051,7 +1051,7 @@ NodeTest::SyncTest() {
const char str[] = "This string rules your world."; const char str[] = "This string rules your world.";
const int len = strlen(str) + 1; const int len = strlen(str) + 1;
// uninitialized objects // uninitialized objects
nextSubTest(); NextSubTest();
TestNodes testEntries; TestNodes testEntries;
CreateUninitializedNodes(testEntries); CreateUninitializedNodes(testEntries);
BNode *node; BNode *node;
@@ -1061,7 +1061,7 @@ NodeTest::SyncTest() {
} }
testEntries.delete_all(); testEntries.delete_all();
// existing entries // existing entries
nextSubTest(); NextSubTest();
CreateRWNodes(testEntries); CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) { for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
CPPUNIT_ASSERT( node->WriteAttr(attr, B_STRING_TYPE, 0, str, len) CPPUNIT_ASSERT( node->WriteAttr(attr, B_STRING_TYPE, 0, str, len)
@@ -1085,7 +1085,7 @@ void
NodeTest::DupTest() NodeTest::DupTest()
{ {
// uninitialized objects // uninitialized objects
nextSubTest(); NextSubTest();
TestNodes testEntries; TestNodes testEntries;
CreateUninitializedNodes(testEntries); CreateUninitializedNodes(testEntries);
BNode *node; BNode *node;
@@ -1095,7 +1095,7 @@ NodeTest::DupTest()
} }
testEntries.delete_all(); testEntries.delete_all();
// existing entries // existing entries
nextSubTest(); NextSubTest();
CreateRWNodes(testEntries); CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) { for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
DupTest(*node); DupTest(*node);
@@ -1172,9 +1172,9 @@ NodeTest::LockTest(BNode &node, const char *entryName)
void void
NodeTest::LockTest() NodeTest::LockTest()
{ {
#if !SK_TEST_OBOS_POSIX #if !TEST_OBOS /* !!!POSIX ONLY!!! */
// uninitialized objects // uninitialized objects
nextSubTest(); NextSubTest();
TestNodes testEntries; TestNodes testEntries;
CreateUninitializedNodes(testEntries); CreateUninitializedNodes(testEntries);
BNode *node; BNode *node;
@@ -1184,7 +1184,7 @@ NodeTest::LockTest()
} }
testEntries.delete_all(); testEntries.delete_all();
// existing entries // existing entries
nextSubTest(); NextSubTest();
CreateRWNodes(testEntries); CreateRWNodes(testEntries);
for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) { for (testEntries.rewind(); testEntries.getNext(node, nodeName); ) {
LockTest(*node, nodeName.c_str()); 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__ #ifndef __sk_path_test_h__
#define __sk_path_test_h__ #define __sk_path_test_h__
#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>
#include <StorageDefs.h> #include <StorageDefs.h>
#include <SupportDefs.h> #include <SupportDefs.h>
#include <BasicTest.h>
#include "BasicTest.h" class CppUnit::Test;
class PathTest : public BasicTest class PathTest : public BasicTest
{ {
+21 -21
View File
@@ -34,7 +34,7 @@ StatableTest::GetStatTest()
BStatable *statable; BStatable *statable;
string entryName; string entryName;
// existing entries // existing entries
nextSubTest(); NextSubTest();
CreateROStatables(testEntries); CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) { for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st1, st2; struct stat st1, st2;
@@ -44,7 +44,7 @@ StatableTest::GetStatTest()
} }
testEntries.delete_all(); testEntries.delete_all();
// uninitialized objects // uninitialized objects
nextSubTest(); NextSubTest();
CreateUninitializedStatables(testEntries); CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) { for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st1; struct stat st1;
@@ -52,7 +52,7 @@ StatableTest::GetStatTest()
} }
testEntries.delete_all(); testEntries.delete_all();
// bad args // bad args
nextSubTest(); NextSubTest();
CreateROStatables(testEntries); CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) for (testEntries.rewind(); testEntries.getNext(statable, entryName); )
CPPUNIT_ASSERT( statable->GetStat(NULL) != B_OK ); CPPUNIT_ASSERT( statable->GetStat(NULL) != B_OK );
@@ -67,7 +67,7 @@ StatableTest::IsXYZTest()
BStatable *statable; BStatable *statable;
string entryName; string entryName;
// existing entries // existing entries
nextSubTest(); NextSubTest();
CreateROStatables(testEntries); CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) { for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st; struct stat st;
@@ -78,7 +78,7 @@ StatableTest::IsXYZTest()
} }
testEntries.delete_all(); testEntries.delete_all();
// uninitialized objects // uninitialized objects
nextSubTest(); NextSubTest();
CreateUninitializedStatables(testEntries); CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) { for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
CPPUNIT_ASSERT( statable->IsDirectory() == false ); CPPUNIT_ASSERT( statable->IsDirectory() == false );
@@ -96,7 +96,7 @@ StatableTest::GetXYZTest()
BStatable *statable; BStatable *statable;
string entryName; string entryName;
// test with existing entries // test with existing entries
nextSubTest(); NextSubTest();
CreateROStatables(testEntries); CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) { for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st; struct stat st;
@@ -108,7 +108,7 @@ StatableTest::GetXYZTest()
time_t mtime; time_t mtime;
time_t ctime; time_t ctime;
// R5: access time unused // R5: access time unused
#if !SK_TEST_R5 && !SK_TEST_OBOS_POSIX #if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
time_t atime; time_t atime;
#endif #endif
BVolume volume; BVolume volume;
@@ -120,7 +120,7 @@ StatableTest::GetXYZTest()
CPPUNIT_ASSERT( statable->GetSize(&size) == B_OK ); CPPUNIT_ASSERT( statable->GetSize(&size) == B_OK );
CPPUNIT_ASSERT( statable->GetModificationTime(&mtime) == B_OK ); CPPUNIT_ASSERT( statable->GetModificationTime(&mtime) == B_OK );
CPPUNIT_ASSERT( statable->GetCreationTime(&ctime) == 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 ); CPPUNIT_ASSERT( statable->GetAccessTime(&atime) == B_OK );
#endif #endif
CPPUNIT_ASSERT( statable->GetVolume(&volume) == B_OK ); CPPUNIT_ASSERT( statable->GetVolume(&volume) == B_OK );
@@ -133,17 +133,17 @@ StatableTest::GetXYZTest()
CPPUNIT_ASSERT( size == st.st_size ); CPPUNIT_ASSERT( size == st.st_size );
CPPUNIT_ASSERT( mtime == st.st_mtime ); CPPUNIT_ASSERT( mtime == st.st_mtime );
CPPUNIT_ASSERT( ctime == st.st_crtime ); 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 ); CPPUNIT_ASSERT( atime == st.st_atime );
#endif #endif
// OBOS: BVolume::==() is not implemented yet // OBOS: BVolume::==() is not implemented yet
#if !SK_TEST_OBOS_POSIX #if !TEST_OBOS /* !!!POSIX ONLY!!! */
CPPUNIT_ASSERT( volume == BVolume(st.st_dev) ); CPPUNIT_ASSERT( volume == BVolume(st.st_dev) );
#endif #endif
} }
testEntries.delete_all(); testEntries.delete_all();
// test with uninitialized objects // test with uninitialized objects
nextSubTest(); NextSubTest();
CreateUninitializedStatables(testEntries); CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) { for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
node_ref ref; node_ref ref;
@@ -167,11 +167,11 @@ StatableTest::GetXYZTest()
} }
testEntries.delete_all(); testEntries.delete_all();
// bad args // bad args
nextSubTest(); NextSubTest();
CreateROStatables(testEntries); CreateROStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) { for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
// R5: crashs, if passing NULL to any of these methods // 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->GetNodeRef(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetOwner(NULL) == B_BAD_VALUE ); CPPUNIT_ASSERT( statable->GetOwner(NULL) == B_BAD_VALUE );
CPPUNIT_ASSERT( statable->GetGroup(NULL) == B_BAD_VALUE ); CPPUNIT_ASSERT( statable->GetGroup(NULL) == B_BAD_VALUE );
@@ -194,48 +194,48 @@ StatableTest::SetXYZTest()
BStatable *statable; BStatable *statable;
string entryName; string entryName;
// test with existing entries // test with existing entries
nextSubTest(); NextSubTest();
CreateRWStatables(testEntries); CreateRWStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) { for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
struct stat st; struct stat st;
uid_t owner = 0xdad; uid_t owner = 0xdad;
gid_t group = 0xdee; gid_t group = 0xdee;
// OBOS: no fchmod(), no FD time setters // 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? ;-) mode_t perms = 0x0ab; // -w- r-x -wx -- unusual enough? ;-)
time_t mtime = 1234567; time_t mtime = 1234567;
time_t ctime = 654321; time_t ctime = 654321;
#endif #endif
// R5: access time unused // R5: access time unused
#if !SK_TEST_R5 && !SK_TEST_OBOS_POSIX #if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
time_t atime = 2345678; time_t atime = 2345678;
#endif #endif
// OBOS: no fchmod(), no FD time setters // OBOS: no fchmod(), no FD time setters
CPPUNIT_ASSERT( statable->SetOwner(owner) == B_OK ); CPPUNIT_ASSERT( statable->SetOwner(owner) == B_OK );
CPPUNIT_ASSERT( statable->SetGroup(group) == 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->SetPermissions(perms) == B_OK );
CPPUNIT_ASSERT( statable->SetModificationTime(mtime) == B_OK ); CPPUNIT_ASSERT( statable->SetModificationTime(mtime) == B_OK );
CPPUNIT_ASSERT( statable->SetCreationTime(ctime) == B_OK ); CPPUNIT_ASSERT( statable->SetCreationTime(ctime) == B_OK );
#endif #endif
#if !SK_TEST_R5 && !SK_TEST_OBOS_POSIX #if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
CPPUNIT_ASSERT( statable->SetAccessTime(atime) == B_OK ); CPPUNIT_ASSERT( statable->SetAccessTime(atime) == B_OK );
#endif #endif
CPPUNIT_ASSERT( lstat(entryName.c_str(), &st) == 0 ); CPPUNIT_ASSERT( lstat(entryName.c_str(), &st) == 0 );
CPPUNIT_ASSERT( owner == st.st_uid ); CPPUNIT_ASSERT( owner == st.st_uid );
CPPUNIT_ASSERT( group == st.st_gid ); 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( perms == (st.st_mode & S_IUMSK) );
CPPUNIT_ASSERT( mtime == st.st_mtime ); CPPUNIT_ASSERT( mtime == st.st_mtime );
CPPUNIT_ASSERT( ctime == st.st_crtime ); CPPUNIT_ASSERT( ctime == st.st_crtime );
#endif #endif
#if !SK_TEST_R5 && !SK_TEST_OBOS_POSIX #if !TEST_R5 && !TEST_OBOS /* !!!POSIX ONLY!!! */
CPPUNIT_ASSERT( atime == st.st_atime ); CPPUNIT_ASSERT( atime == st.st_atime );
#endif #endif
} }
testEntries.delete_all(); testEntries.delete_all();
// test with uninitialized objects // test with uninitialized objects
nextSubTest(); NextSubTest();
CreateUninitializedStatables(testEntries); CreateUninitializedStatables(testEntries);
for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) { for (testEntries.rewind(); testEntries.getNext(statable, entryName); ) {
uid_t owner = 0xdad; uid_t owner = 0xdad;
+3
View File
@@ -3,6 +3,9 @@
#ifndef __sk_statable_test_h__ #ifndef __sk_statable_test_h__
#define __sk_statable_test_h__ #define __sk_statable_test_h__
#include <cppunit/TestCaller.h>
#include <cppunit/TestSuite.h>
#include <list> #include <list>
#include <string> #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 // TestUtils.cpp
#include "TestUtils.h" #include "TestUtils.h"
#include "StorageKitTester.h" #include <TestShell.h>
status_t DecodeResult(status_t result) { status_t DecodeResult(status_t result) {
if (!shell.BeVerbose()) if (!BTestShell::GlobalBeVerbose())
return result; return result;
std::string str; std::string str;
+20 -4
View File
@@ -2,6 +2,7 @@
#include <TestShell.h> #include <TestShell.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h>
BTestCase::BTestCase(std::string name) BTestCase::BTestCase(std::string name)
: CppUnit::TestCase(name) : CppUnit::TestCase(name)
@@ -17,8 +18,7 @@ BTestCase::tearDown() {
void void
BTestCase::NextSubTest() { BTestCase::NextSubTest() {
BTestShell *shell = BTestShell::Shell(); if (BeVerbose()) {
if (shell && shell->BeVerbose()) {
printf("[%ld]", fSubTestNum++); printf("[%ld]", fSubTestNum++);
fflush(stdout); fflush(stdout);
} }
@@ -26,11 +26,21 @@ BTestCase::NextSubTest() {
void void
BTestCase::NextSubTestBlock() { BTestCase::NextSubTestBlock() {
BTestShell *shell = BTestShell::Shell(); if (BeVerbose())
if (shell && shell->BeVerbose())
printf("\n"); 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(). */ /*! To return to the last saved working directory, call RestoreCWD(). */
void void
BTestCase::SaveCWD() { BTestCase::SaveCWD() {
@@ -49,3 +59,9 @@ BTestCase::RestoreCWD(const char *alternate) {
else if (alternate != NULL) else if (alternate != NULL)
chdir(alternate); 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 <string>
#include <vector> #include <vector>
BTestShell *BTestShell::fGlobalShell = NULL;
const char BTestShell::indent[] = " ";
BTestShell::BTestShell(const std::string &description, SyncObject *syncObject) BTestShell::BTestShell(const std::string &description, SyncObject *syncObject)
: fVerbosityLevel(v2) : fVerbosityLevel(v2)
, fDescription(description) , fDescription(description)
, fTestResults(syncObject) , fTestResults(syncObject)
, fListTestsAndExit(false)
{ {
}; };
status_t status_t
BTestShell::AddSuite(BTestSuite *suite) { BTestShell::AddSuite(BTestSuite *suite) {
if (suite) { if (suite) {
cout << "Adding suite '" << suite->getName() << "'" << endl; if (Verbosity() >= v3)
cout << "Adding suite '" << suite->getName() << "'" << endl;
// Add the suite // Add the suite
fSuites[suite->getName()] = suite; fSuites[suite->getName()] = suite;
@@ -67,14 +72,18 @@ BTestShell::LoadSuitesFrom(BDirectory *libDir) {
status_t err; status_t err;
err = addonEntry.GetPath(&addonPath); err = addonEntry.GetPath(&addonPath);
if (!err) { if (!err) {
// cout << "Checking " << addonPath.Path() << "..." << flush;
addonImage = load_add_on(addonPath.Path()); addonImage = load_add_on(addonPath.Path());
err = (addonImage > 0 ? B_OK : B_ERROR); err = (addonImage > 0 ? B_OK : B_ERROR);
} }
if (!err) { if (!err) {
// cout << "..." << endl;
err = get_image_symbol(addonImage, err = get_image_symbol(addonImage,
"getTestSuite", "getTestSuite",
B_SYMBOL_TYPE_TEXT, B_SYMBOL_TYPE_TEXT,
reinterpret_cast<void **>(&func)); reinterpret_cast<void **>(&func));
} else {
// cout << " !!! err == " << err << endl;
} }
if (!err) if (!err)
err = AddSuite(func()); err = AddSuite(func());
@@ -90,6 +99,16 @@ BTestShell::Run(int argc, char *argv[]) {
if (!ProcessArguments(argc, argv)) if (!ProcessArguments(argc, argv))
return 0; 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 // Add the proper tests to our suite (or exit if there
// are no tests installed). // are no tests installed).
CppUnit::TestSuite suite; CppUnit::TestSuite suite;
@@ -106,12 +125,19 @@ BTestShell::Run(int argc, char *argv[]) {
for (i = fTests.begin(); i != fTests.end(); ++i) for (i = fTests.begin(); i != fTests.end(); ++i)
suite.addTest( i->second ); suite.addTest( i->second );
} else { } else {
// One or more specified, so only run those // One or more specified, so only run those
std::set<std::string>::const_iterator i; std::set<std::string>::const_iterator i;
for (i = fTestsToRun.begin(); i != fTestsToRun.end(); ++i) for (i = fTestsToRun.begin(); i != fTestsToRun.end(); ++i) {
suite.addTest( fTests[*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; return 0;
} }
BTestShell *BTestShell::fGlobalShell = NULL;
BTestShell::VerbosityLevel BTestShell::VerbosityLevel
BTestShell::Verbosity() const { BTestShell::Verbosity() const {
return fVerbosityLevel; return fVerbosityLevel;
@@ -137,9 +161,15 @@ BTestShell::PrintDescription(int argc, char *argv[]) {
void void
BTestShell::PrintHelp() { BTestShell::PrintHelp() {
const char indent[] = " ";
cout << endl; cout << endl;
cout << "VALID ARGUMENTS: " << 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 << "--help Displays this help text plus some other garbage" << endl;
cout << indent << "--list Lists the names of classes with installed tests" << 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; 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 << " plus complete summary)" << endl;
cout << indent << "CLASSNAME Instructs the program to run the test for the given class; if" << 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 << " 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; cout << endl;
} }
bool bool
@@ -166,51 +208,47 @@ BTestShell::ProcessArguments(int argc, char *argv[]) {
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
std::string str(argv[i]); std::string str(argv[i]);
if (str == "--help") { if (!ProcessArgument(str, argc, argv))
PrintDescription(argc, argv); return false;
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;
}
} }
return true; 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 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
// as we go. This involves a custom CppUnit::TestListener // as we go. This involves a custom CppUnit::TestListener
// class. // class.
if (fVerbosityLevel == v2) { if (fVerbosityLevel >= v2) {
cout << "------------------------------------------------------------------------------" << endl; cout << "------------------------------------------------------------------------------" << endl;
cout << "Tests" << endl; cout << "Tests" << endl;
cout << "------------------------------------------------------------------------------" << 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(); 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 void
BThreadedTestCase::InitThreadInfo(thread_id id, std::string threadName) { BThreadedTestCase::InitThreadInfo(thread_id id, std::string threadName) {
BAutolock lock(fUpdateLock); // Lock the number map BAutolock lock(fUpdateLock); // Lock the number map