2002-07-09 12:24:59 +00:00
|
|
|
#include <TestCase.h>
|
2002-07-15 06:50:13 +00:00
|
|
|
#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() {
|
2002-07-19 06:45:28 +00:00
|
|
|
if (fSubTestNum != 0)
|
|
|
|
|
NextSubTestBlock();
|
2002-07-11 03:31:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
BTestCase::NextSubTest() {
|
2002-07-18 01:03:19 +00:00
|
|
|
if (BTestShell::GlobalBeVerbose()) {
|
2002-07-15 06:50:13 +00:00
|
|
|
printf("[%ld]", fSubTestNum++);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
}
|
2002-07-11 03:31:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
BTestCase::NextSubTestBlock() {
|
2002-07-18 01:03:19 +00:00
|
|
|
if (BTestShell::GlobalBeVerbose())
|
2002-07-15 06:50:13 +00:00
|
|
|
printf("\n");
|
2002-07-09 12:24:59 +00:00
|
|
|
}
|
|
|
|
|
|
2002-07-17 10:50:55 +00:00
|
|
|
void
|
|
|
|
|
BTestCase::Outputf(const char *str, ...) {
|
2002-07-18 01:03:19 +00:00
|
|
|
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
|
|
|
|