40 double delta, difference;
46 double max = (std::fabs (x1) > std::fabs (x2)) ? x1 : x2;
47 (void)std::frexp (max, &exponent);
53 delta = std::ldexp (epsilon, exponent);
56 if (difference > delta || difference < -delta)
66 std::string _limit, std::string _message,
67 std::string _file, int32_t _line);
90 std::string limit, std::string message,
91 std::string file, int32_t line);
98 int Run (
int argc,
char *argv[]);
110 std::list<TestCase *>::const_iterator end,
111 bool printTestType)
const;
113 void PrintHelp (
const char *programName)
const;
130 std::string _limit, std::string _message,
131 std::string _file, int32_t _line)
132 : cond (_cond), actual (_actual), limit (_limit),
133 message (_message), file (_file), line (_line)
135 NS_LOG_FUNCTION (
this << _cond << _actual << _limit << _message << _file << _line);
138 : childrenFailed (false)
161 for (std::vector<TestCase *>::const_iterator i =
m_children.begin (); i !=
m_children.end (); ++i)
175 std::string::size_type slash, antislash;
176 slash = testCase->
m_name.find (
"/");
177 antislash = testCase->
m_name.find (
"\\");
178 if (slash != std::string::npos || antislash != std::string::npos)
180 std::string fullname = testCase->
m_name;
184 fullname = current->
m_name +
"/" + fullname;
187 if (slash != std::string::npos)
189 NS_FATAL_ERROR (
"Invalid test name: cannot contain slashes: \"" << fullname <<
"\"");
191 if (antislash != std::string::npos)
193 NS_FATAL_ERROR (
"Invalid test name: cannot contain antislashes: \"" << fullname <<
"\"");
213 for (std::vector<TestCase *>::const_iterator i =
m_children.begin (); i !=
m_children.end (); ++i)
236 std::string limit, std::string message,
237 std::string file, int32_t line)
239 NS_LOG_FUNCTION (
this << cond << actual << limit << message << file << line);
241 message, file, line));
269 while (current->
m_dataDir ==
"" && current != 0)
275 NS_FATAL_ERROR (
"No one called SetDataDir prior to calling this function");
292 std::list<std::string> names;
296 names.push_front (current->
m_name);
365 m_assertOnFailure (false),
366 m_continueOnFailure (true),
424 bool haveVersion =
false;
425 bool haveLicense =
false;
433 for (std::list<std::string>::const_iterator i = files.begin (); i != files.end (); ++i)
439 else if (*i ==
"LICENSE")
445 return haveVersion && haveLicense;
454 while (!elements.empty ())
461 elements.pop_back ();
463 NS_FATAL_ERROR (
"Could not find source directory from self=" <<
self);
475 std::string specials =
"<>&\"'";
476 std::string replacements[] = {
"<",
">",
"&",
"'",
"""};
478 std::size_t index, length = xml.length ();
480 for (
size_t i = 0; i < length; ++i)
482 char character = xml[i];
484 if ((index = specials.find (character)) == std::string::npos)
486 result.push_back (character);
490 result += replacements[index];
508 for (
int i = 0; i < val.
level; i++)
525 const double MS_PER_SEC = 1000.;
533 std::string statusString = test->
IsFailed ()?
"FAIL":
"PASS";
536 *os <<
Indent (level) <<
"<Test>" << std::endl;
538 <<
"</Name>" << std::endl;
539 *os <<
Indent (level+1) <<
"<Result>" << statusString <<
"</Result>" << std::endl;
540 *os <<
Indent (level+1) <<
"<Time real=\"" << real <<
"\" user=\"" << user
541 <<
"\" system=\"" << system <<
"\"/>" << std::endl;
545 *os <<
Indent (level+2) <<
"<FailureDetails>" << std::endl
546 <<
Indent (level+3) <<
"<Condition>"
548 <<
Indent (level+3) <<
"<Actual>"
550 <<
Indent (level+3) <<
"<Limit>"
552 <<
Indent (level+3) <<
"<Message>"
554 <<
Indent (level+3) <<
"<File>"
556 <<
Indent (level+3) <<
"<Line>" << failure.
line <<
"</Line>" << std::endl
557 <<
Indent (level+2) <<
"</FailureDetails>" << std::endl;
559 for (uint32_t i = 0; i < test->
m_children.size (); i++)
564 *os <<
Indent (level) <<
"</Test>" << std::endl;
568 *os <<
Indent (level) << statusString <<
" " << test->
GetName ()
569 <<
" " << real <<
" s" << std::endl;
575 *os <<
Indent (level) <<
" got=\"" << failure.
cond <<
"\" expected=\""
576 << failure.
actual <<
"\" in=\"" << failure.
file <<
":" << failure.
line
577 <<
"\" " << failure.
message << std::endl;
579 for (uint32_t i = 0; i < test->
m_children.size (); i++)
592 std::cout <<
"Usage: " << program_name <<
" [OPTIONS]" << std::endl
595 <<
" --help : print these options" << std::endl
596 <<
" --print-test-name-list : print the list of names of tests available" << std::endl
597 <<
" --list : an alias for --print-test-name-list" << std::endl
598 <<
" --print-test-types : print the type of tests along with their names" << std::endl
599 <<
" --print-test-type-list : print the list of types of tests available" << std::endl
600 <<
" --print-temp-dir : Print name of temporary directory before running the tests" << std::endl
601 <<
" --test-type=TYPE : Process only tests of type TYPE" << std::endl
602 <<
" --test-name=NAME : Process only test whose name matches NAME" << std::endl
603 <<
" --suite=NAME : an alias (here for compatibility reasons only) "
604 <<
"for --test-name=NAME" << std::endl
605 <<
" --assert-on-failure : when a test fails, crash immediately (useful" << std::endl
606 <<
" when running under a debugger" << std::endl
607 <<
" --stop-on-failure : when a test fails, stop immediately" << std::endl
608 <<
" --verbose : Print details of test execution" << std::endl
609 <<
" --xml : format test run output as xml" << std::endl
610 <<
" --tempdir=DIR : set temp dir for tests to store output files" << std::endl
611 <<
" --datadir=DIR : set data dir for tests to read reference files" << std::endl
612 <<
" --out=FILE : send test result to FILE instead of standard "
613 <<
"output" << std::endl
614 <<
" --append=FILE : append test result to FILE instead of standard "
615 <<
"output" << std::endl
621 std::list<TestCase *>::const_iterator end,
622 bool printTestType)
const
625 std::map<TestSuite::Type, std::string> label;
634 for (std::list<TestCase *>::const_iterator i = begin; i != end; ++i)
641 std::cout << test->
GetName () << std::endl;
649 std::cout <<
" bvt: Build Verification Tests (to see if build completed successfully)" << std::endl;
650 std::cout <<
" core: Run all TestSuite-based tests (exclude examples)" << std::endl;
651 std::cout <<
" example: Examples (to see if example programs run successfully)" << std::endl;
652 std::cout <<
" performance: Performance Tests (check to see if the system is as fast as expected)" << std::endl;
653 std::cout <<
" system: System Tests (spans modules to check integration of modules)" << std::endl;
654 std::cout <<
" unit: Unit Tests (within modules to check basic functionality)" << std::endl;
658 std::list<TestCase *>
662 std::list<TestCase *> tests;
663 for (uint32_t i = 0; i <
m_suites.size (); ++i)
671 if (testName !=
"" && test->
GetName () != testName)
676 tests.push_back (test);
686 std::string testName =
"";
687 std::string testTypeString =
"";
688 std::string out =
"";
691 bool printTempDir =
false;
692 bool printTestTypeList =
false;
693 bool printTestNameList =
false;
694 bool printTestTypeAndName =
false;
695 char *progname = argv[0];
703 if (strcmp(arg,
"--assert-on-failure") == 0)
707 else if (strcmp (arg,
"--stop-on-failure") == 0)
711 else if (strcmp (arg,
"--verbose") == 0)
715 else if (strcmp (arg,
"--print-temp-dir") == 0)
719 else if (strcmp (arg,
"--update-data") == 0)
723 else if (strcmp (arg,
"--help") == 0)
728 else if (strcmp (arg,
"--print-test-name-list") == 0 ||
729 strcmp(arg,
"--list") == 0)
731 printTestNameList =
true;
733 else if (strcmp (arg,
"--print-test-types") == 0)
735 printTestTypeAndName =
true;
737 else if (strcmp (arg,
"--print-test-type-list") == 0)
739 printTestTypeList =
true;
741 else if (strcmp(arg,
"--append") == 0)
745 else if (strcmp(arg,
"--xml") == 0)
749 else if (strncmp(arg,
"--test-type=", strlen(
"--test-type=")) == 0)
751 testTypeString = arg + strlen(
"--test-type=");
753 else if (strncmp(arg,
"--test-name=", strlen(
"--test-name=")) == 0)
755 testName = arg + strlen(
"--test-name=");
757 else if (strncmp(arg,
"--suite=", strlen(
"--suite=")) == 0)
759 testName = arg + strlen(
"--suite=");
761 else if (strncmp(arg,
"--tempdir=", strlen(
"--tempdir=")) == 0)
765 else if (strncmp(arg,
"--out=", strlen(
"--out=")) == 0)
767 out = arg + strlen(
"--out=");
778 if (testTypeString ==
"")
782 else if (testTypeString ==
"bvt")
786 else if (testTypeString ==
"core")
790 else if (testTypeString ==
"example")
794 else if (testTypeString ==
"unit")
798 else if (testTypeString ==
"system")
802 else if (testTypeString ==
"performance")
808 std::cout <<
"Invalid test type specified: " << testTypeString << std::endl;
813 std::list<TestCase *> tests =
FilterTests (testName, testType);
823 if (printTestNameList)
828 if (printTestTypeList)
839 ofs =
new std::ofstream();
840 std::ios_base::openmode mode = std::ios_base::out;
843 mode |= std::ios_base::app;
847 mode |= std::ios_base::trunc;
849 ofs->open (out.c_str (), mode);
859 for (std::list<TestCase *>::const_iterator i = tests.begin (); i != tests.end (); ++i)