Courtesy of Oliver Tappe. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6616 a95241bf-73f2-0310-859d-f6bbb57e9c96
64 lines
1.2 KiB
C++
64 lines
1.2 KiB
C++
#include <TestCase.h>
|
|
#include <TestShell.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdarg.h>
|
|
|
|
BTestCase::BTestCase(string name)
|
|
: CppUnit::TestCase(name)
|
|
, fValidCWD(false)
|
|
, fSubTestNum(0)
|
|
{
|
|
}
|
|
|
|
void
|
|
BTestCase::tearDown() {
|
|
if (fSubTestNum != 0)
|
|
NextSubTestBlock();
|
|
}
|
|
|
|
void
|
|
BTestCase::NextSubTest() {
|
|
if (BTestShell::GlobalBeVerbose()) {
|
|
printf("[%ld]", fSubTestNum++);
|
|
fflush(stdout);
|
|
}
|
|
}
|
|
|
|
void
|
|
BTestCase::NextSubTestBlock() {
|
|
if (BTestShell::GlobalBeVerbose())
|
|
printf("\n");
|
|
}
|
|
|
|
void
|
|
BTestCase::Outputf(const char *str, ...) {
|
|
if (BTestShell::GlobalBeVerbose()) {
|
|
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() {
|
|
fValidCWD = getcwd(fCurrentWorkingDir, B_PATH_NAME_LENGTH);
|
|
}
|
|
|
|
/* If SaveCWD() has not been called and an alternate
|
|
directory is specified by alternate, the current working directory is
|
|
changed to alternate. If alternate is null, the current working directory
|
|
is not modified.
|
|
*/
|
|
void
|
|
BTestCase::RestoreCWD(const char *alternate) {
|
|
if (fValidCWD)
|
|
chdir(fCurrentWorkingDir);
|
|
else if (alternate != NULL)
|
|
chdir(alternate);
|
|
}
|
|
|