1#include <TestCase.h> 2#include <TestShell.h> 3#include <unistd.h> 4#include <stdio.h> 5#include <stdarg.h> 6 7using std::string; 8 9_EXPORT 10BTestCase::BTestCase(string name) 11 : CppUnit::TestCase(name) 12 , fValidCWD(false) 13 , fSubTestNum(0) 14{ 15} 16 17_EXPORT 18void 19BTestCase::tearDown() { 20 if (fSubTestNum != 0) 21 NextSubTestBlock(); 22} 23 24_EXPORT 25void 26BTestCase::NextSubTest() { 27 if (BTestShell::GlobalBeVerbose()) { 28 printf("[%" B_PRId32 "]", fSubTestNum++); 29 fflush(stdout); 30 } 31} 32 33_EXPORT 34void 35BTestCase::NextSubTestBlock() { 36 if (BTestShell::GlobalBeVerbose()) 37 printf("\n"); 38} 39 40_EXPORT 41void 42BTestCase::Outputf(const char *str, ...) { 43 if (BTestShell::GlobalBeVerbose()) { 44 va_list args; 45 va_start(args, str); 46 vprintf(str, args); 47 va_end(args); 48 fflush(stdout); 49 } 50} 51 52/*! To return to the last saved working directory, call RestoreCWD(). */ 53_EXPORT 54void 55BTestCase::SaveCWD() { 56 fValidCWD = getcwd(fCurrentWorkingDir, B_PATH_NAME_LENGTH); 57} 58 59/* If SaveCWD() has not been called and an alternate 60 directory is specified by alternate, the current working directory is 61 changed to alternate. If alternate is null, the current working directory 62 is not modified. 63*/ 64_EXPORT 65void 66BTestCase::RestoreCWD(const char *alternate) { 67 if (fValidCWD) 68 chdir(fCurrentWorkingDir); 69 else if (alternate != NULL) 70 chdir(alternate); 71} 72 73