Files
haiku-beta6/src/tools/cppunit/TestCase.cpp
T

64 lines
1.2 KiB
C++
Raw Normal View History

2002-07-09 12:24:59 +00:00
#include <TestCase.h>
#include <TestShell.h>
2002-07-09 12:24:59 +00:00
#include <unistd.h>
2002-07-11 03:31:07 +00:00
#include <stdio.h>
2002-07-17 10:50:55 +00:00
#include <stdarg.h>
2002-07-09 12:24:59 +00:00
2002-07-11 03:31:07 +00:00
BTestCase::BTestCase(std::string name)
: CppUnit::TestCase(name)
2002-07-09 12:24:59 +00:00
, fValidCWD(false)
2002-07-11 03:31:07 +00:00
, fSubTestNum(0)
2002-07-09 12:24:59 +00:00
{
}
2002-07-11 03:31:07 +00:00
void
BTestCase::tearDown() {
if (fSubTestNum != 0)
NextSubTestBlock();
2002-07-11 03:31:07 +00:00
}
void
BTestCase::NextSubTest() {
if (BTestShell::GlobalBeVerbose()) {
printf("[%ld]", fSubTestNum++);
fflush(stdout);
}
2002-07-11 03:31:07 +00:00
}
void
BTestCase::NextSubTestBlock() {
if (BTestShell::GlobalBeVerbose())
printf("\n");
2002-07-09 12:24:59 +00:00
}
2002-07-17 10:50:55 +00:00
void
BTestCase::Outputf(const char *str, ...) {
if (BTestShell::GlobalBeVerbose()) {
2002-07-17 10:50:55 +00:00
va_list args;
va_start(args, str);
vprintf(str, args);
va_end(args);
fflush(stdout);
}
}
2002-07-11 03:31:07 +00:00
/*! To return to the last saved working directory, call RestoreCWD(). */
2002-07-09 12:24:59 +00:00
void
2002-07-11 03:31:07 +00:00
BTestCase::SaveCWD() {
2002-07-09 12:24:59 +00:00
fValidCWD = getcwd(fCurrentWorkingDir, B_PATH_NAME_LENGTH);
}
2002-07-11 03:31:07 +00:00
/* If SaveCWD() has not been called and an alternate
2002-07-09 12:24:59 +00:00
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
2002-07-11 03:31:07 +00:00
BTestCase::RestoreCWD(const char *alternate) {
2002-07-09 12:24:59 +00:00
if (fValidCWD)
chdir(fCurrentWorkingDir);
else if (alternate != NULL)
chdir(alternate);
}
2002-07-17 10:50:55 +00:00