35 double delta, difference;
41 double max = (fabs (x1) > fabs (x2)) ? x1 : x2;
42 (void)frexp (max, &exponent);
48 delta = ldexp (epsilon, exponent);
51 if (difference > delta || difference < -delta)
61 std::string _limit, std::string _message,
62 std::string _file, int32_t _line);
85 std::string limit, std::string message,
86 std::string file, int32_t line);
93 int Run (
int argc,
char *argv[]);
105 std::list<TestCase *>::const_iterator end)
const;
107 void PrintHelp (
const char *programName)
const;
124 std::string _limit, std::string _message,
125 std::string _file, int32_t _line)
126 : cond (_cond), actual (_actual), limit (_limit),
127 message (_message), file (_file), line (_line)
130 : childrenFailed (false)
149 for (std::vector<TestCase *>::const_iterator i =
m_children.begin (); i !=
m_children.end (); ++i)
162 std::string::size_type slash, antislash;
163 slash = testCase->
m_name.find (
"/");
164 antislash = testCase->
m_name.find (
"\\");
165 if (slash != std::string::npos || antislash != std::string::npos)
167 std::string fullname = testCase->
m_name;
171 fullname = current->
m_name +
"/" + fullname;
174 if (slash != std::string::npos)
176 NS_FATAL_ERROR (
"Invalid test name: cannot contain slashes: \"" << fullname <<
"\"");
178 if (antislash != std::string::npos)
180 NS_FATAL_ERROR (
"Invalid test name: cannot contain antislashes: \"" << fullname <<
"\"");
198 for (std::vector<TestCase *>::const_iterator i =
m_children.begin (); i !=
m_children.end (); ++i)
220 std::string limit, std::string message,
221 std::string file, int32_t line)
224 message, file, line));
249 while (current->
m_dataDir ==
"" && current != 0)
255 NS_FATAL_ERROR (
"No one called SetDataDir prior to calling this function");
271 std::list<std::string> names;
275 names.push_front (current->
m_name);
332 m_assertOnFailure (false),
333 m_continueOnFailure (true),
382 bool haveVersion =
false;
383 bool haveLicense =
false;
391 for (std::list<std::string>::const_iterator i = files.begin (); i != files.end (); ++i)
397 else if (*i ==
"LICENSE")
403 return haveVersion && haveLicense;
411 while (!elements.empty ())
418 elements.pop_back ();
420 NS_FATAL_ERROR (
"Could not find source directory from self=" <<
self);
431 std::string specials =
"<>&\"'";
432 std::string replacements[] = {
"<",
">",
"&",
"'",
"""};
434 std::size_t index, length = xml.length ();
436 for (
size_t i = 0; i < length; ++i)
438 char character = xml[i];
440 if ((index = specials.find (character)) == std::string::npos)
442 result.push_back (character);
446 result += replacements[index];
462 for (
int i = 0; i < val.
level; i++)
478 const double MS_PER_SEC = 1000.;
486 std::string statusString = test->
IsFailed ()?
"FAIL":
"PASS";
489 *os <<
Indent (level) <<
"<Test>" << std::endl;
491 <<
"</Name>" << std::endl;
492 *os <<
Indent (level+1) <<
"<Result>" << statusString <<
"</Result>" << std::endl;
493 *os <<
Indent (level+1) <<
"<Time real=\"" << real <<
"\" user=\"" << user
494 <<
"\" system=\"" << system <<
"\"/>" << std::endl;
498 *os <<
Indent (level+2) <<
"<FailureDetails>" << std::endl
499 <<
Indent (level+3) <<
"<Condition>"
501 <<
Indent (level+3) <<
"<Actual>"
503 <<
Indent (level+3) <<
"<Limit>"
505 <<
Indent (level+3) <<
"<Message>"
507 <<
Indent (level+3) <<
"<File>"
509 <<
Indent (level+3) <<
"<Line>" << failure.
line <<
"</Line>" << std::endl
510 <<
Indent (level+2) <<
"</FailureDetails>" << std::endl;
512 for (uint32_t i = 0; i < test->
m_children.size (); i++)
517 *os <<
Indent (level) <<
"</Test>" << std::endl;
521 *os <<
Indent (level) << statusString <<
" " << test->
GetName ()
522 <<
" " << real <<
" s" << std::endl;
528 *os <<
Indent (level) <<
" got=\"" << failure.
cond <<
"\" expected=\""
529 << failure.
actual <<
"\" in=\"" << failure.
file <<
":" << failure.
line
530 <<
"\" " << failure.
message << std::endl;
532 for (uint32_t i = 0; i < test->
m_children.size (); i++)
544 std::cout <<
"Usage: " << program_name <<
" [OPTIONS]" << std::endl
547 <<
" --help : print these options" << std::endl
548 <<
" --print-test-name-list : print the list of names of tests available" << std::endl
549 <<
" --list : an alias for --print-test-name-list" << std::endl
550 <<
" --print-test-type-list : print the list of types of tests available" << std::endl
551 <<
" --print-temp-dir : Print name of temporary directory before running the tests" << std::endl
552 <<
" --test-type=TYPE : Process only tests of type TYPE" << std::endl
553 <<
" --test-name=NAME : Process only test whose name matches NAME" << std::endl
554 <<
" --suite=NAME : an alias (here for compatibility reasons only) "
555 <<
"for --test-name=NAME" << std::endl
556 <<
" --assert-on-failure : when a test fails, crash immediately (useful" << std::endl
557 <<
" when running under a debugger" << std::endl
558 <<
" --stop-on-failure : when a test fails, stop immediately" << std::endl
559 <<
" --verbose : Print details of test execution" << std::endl
560 <<
" --xml : format test run output as xml" << std::endl
561 <<
" --tempdir=DIR : set temp dir for tests to store output files" << std::endl
562 <<
" --datadir=DIR : set data dir for tests to read reference files" << std::endl
563 <<
" --out=FILE : send test result to FILE instead of standard "
564 <<
"output" << std::endl
565 <<
" --append=FILE : append test result to FILE instead of standard "
566 <<
"output" << std::endl
572 std::list<TestCase *>::const_iterator end)
const
574 for (std::list<TestCase *>::const_iterator i = begin; i != end; ++i)
577 std::cout << test->
GetName () << std::endl;
584 std::cout <<
" bvt: Build Verification Tests (to see if build completed successfully)" << std::endl;
585 std::cout <<
" core: Run all TestSuite-based tests (exclude examples)" << std::endl;
586 std::cout <<
" example: Examples (to see if example programs run successfully)" << std::endl;
587 std::cout <<
" performance: Performance Tests (check to see if the system is as fast as expected)" << std::endl;
588 std::cout <<
" system: System Tests (spans modules to check integration of modules)" << std::endl;
589 std::cout <<
" unit: Unit Tests (within modules to check basic functionality)" << std::endl;
593 std::list<TestCase *>
596 std::list<TestCase *> tests;
597 for (uint32_t i = 0; i <
m_suites.size (); ++i)
605 if (testName !=
"" && test->
GetName () != testName)
610 tests.push_back (test);
619 std::string testName =
"";
620 std::string testTypeString =
"";
621 std::string out =
"";
624 bool printTempDir =
false;
625 bool printTestTypeList =
false;
626 bool printTestNameList =
false;
627 char *progname = argv[0];
635 if (strcmp(arg,
"--assert-on-failure") == 0)
639 else if (strcmp (arg,
"--stop-on-failure") == 0)
643 else if (strcmp (arg,
"--verbose") == 0)
647 else if (strcmp (arg,
"--print-temp-dir") == 0)
651 else if (strcmp (arg,
"--update-data") == 0)
655 else if (strcmp (arg,
"--help") == 0)
660 else if (strcmp (arg,
"--print-test-name-list") == 0 ||
661 strcmp(arg,
"--list") == 0)
663 printTestNameList =
true;
665 else if (strcmp (arg,
"--print-test-type-list") == 0)
667 printTestTypeList =
true;
669 else if (strcmp(arg,
"--append") == 0)
673 else if (strcmp(arg,
"--xml") == 0)
677 else if (strncmp(arg,
"--test-type=", strlen(
"--test-type=")) == 0)
679 testTypeString = arg + strlen(
"--test-type=");
681 else if (strncmp(arg,
"--test-name=", strlen(
"--test-name=")) == 0)
683 testName = arg + strlen(
"--test-name=");
685 else if (strncmp(arg,
"--suite=", strlen(
"--suite=")) == 0)
687 testName = arg + strlen(
"--suite=");
689 else if (strncmp(arg,
"--tempdir=", strlen(
"--tempdir=")) == 0)
693 else if (strncmp(arg,
"--out=", strlen(
"--out=")) == 0)
695 out = arg + strlen(
"--out=");
706 if (testTypeString ==
"")
710 else if (testTypeString ==
"bvt")
714 else if (testTypeString ==
"core")
718 else if (testTypeString ==
"example")
722 else if (testTypeString ==
"unit")
726 else if (testTypeString ==
"system")
732 std::cout <<
"Invalid test type specified: " << testTypeString << std::endl;
737 std::list<TestCase *> tests =
FilterTests (testName, testType);
747 if (printTestNameList)
752 if (printTestTypeList)
763 ofs =
new std::ofstream();
764 std::ios_base::openmode mode = std::ios_base::out;
767 mode |= std::ios_base::app;
771 mode |= std::ios_base::trunc;
773 ofs->open (out.c_str (), mode);
783 for (std::list<TestCase *>::const_iterator i = tests.begin (); i != tests.end (); ++i)