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;
114 std::list<TestCase *>
FilterTests (std::string testName,
132 std::string _limit, std::string _message,
133 std::string _file, int32_t _line)
134 : cond (_cond), actual (_actual), limit (_limit),
135 message (_message), file (_file), line (_line)
137 NS_LOG_FUNCTION (
this << _cond << _actual << _limit << _message << _file << _line);
140 : childrenFailed (false)
164 for (std::vector<TestCase *>::const_iterator i =
m_children.begin (); i !=
m_children.end (); ++i)
187 std::string::size_type slash, antislash;
188 slash = testCase->
m_name.find (
"/");
189 antislash = testCase->
m_name.find (
"\\");
190 if (slash != std::string::npos || antislash != std::string::npos)
192 std::string fullname = testCase->
m_name;
196 fullname = current->
m_name +
"/" + fullname;
199 if (slash != std::string::npos)
201 NS_FATAL_ERROR (
"Invalid test name: cannot contain slashes: \"" << fullname <<
"\"");
203 if (antislash != std::string::npos)
205 NS_FATAL_ERROR (
"Invalid test name: cannot contain antislashes: \"" << fullname <<
"\"");
225 for (std::vector<TestCase *>::const_iterator i =
m_children.begin (); i !=
m_children.end (); ++i)
248 std::string limit, std::string message,
249 std::string file, int32_t line)
251 NS_LOG_FUNCTION (
this << cond << actual << limit << message << file << line);
253 message, file, line));
281 while (current != 0 && current->
m_dataDir ==
"")
287 NS_FATAL_ERROR (
"No one called SetDataDir prior to calling this function");
304 std::list<std::string> names;
308 names.push_front (current->
m_name);
377 m_assertOnFailure (false),
378 m_continueOnFailure (true),
436 bool haveVersion =
false;
437 bool haveLicense =
false;
445 for (std::list<std::string>::const_iterator i = files.begin (); i != files.end (); ++i)
451 else if (*i ==
"LICENSE")
457 return haveVersion && haveLicense;
466 while (!elements.empty ())
473 elements.pop_back ();
475 NS_FATAL_ERROR (
"Could not find source directory from self=" <<
self);
487 typedef std::map <char, std::string> specials_map;
488 specials_map specials;
489 specials[
'<'] =
"<";
490 specials[
'>'] =
">";
491 specials[
'&'] =
"&";
492 specials[
'"'] =
"'";
493 specials[
'\''] =
""";
496 std::size_t length = xml.length ();
498 for (
size_t i = 0; i < length; ++i)
500 char character = xml[i];
502 specials_map::const_iterator it = specials.find (character);
504 if (it == specials.end ())
506 result.push_back (character);
510 result += it->second;
528 for (
int i = 0; i < val.
level; i++)
545 const double MS_PER_SEC = 1000.;
550 std::streamsize oldPrecision = (*os).precision (3);
553 std::string statusString = test->
IsFailed ()?
"FAIL":
"PASS";
556 *os <<
Indent (level) <<
"<Test>" << std::endl;
558 <<
"</Name>" << std::endl;
559 *os <<
Indent (level+1) <<
"<Result>" << statusString <<
"</Result>" << std::endl;
560 *os <<
Indent (level+1) <<
"<Time real=\"" << real <<
"\" user=\"" << user
561 <<
"\" system=\"" << system <<
"\"/>" << std::endl;
565 *os <<
Indent (level+2) <<
"<FailureDetails>" << std::endl
566 <<
Indent (level+3) <<
"<Condition>"
568 <<
Indent (level+3) <<
"<Actual>"
570 <<
Indent (level+3) <<
"<Limit>"
572 <<
Indent (level+3) <<
"<Message>"
574 <<
Indent (level+3) <<
"<File>"
576 <<
Indent (level+3) <<
"<Line>" << failure.
line <<
"</Line>" << std::endl
577 <<
Indent (level+2) <<
"</FailureDetails>" << std::endl;
579 for (uint32_t i = 0; i < test->
m_children.size (); i++)
584 *os <<
Indent (level) <<
"</Test>" << std::endl;
588 *os <<
Indent (level) << statusString <<
" " << test->
GetName ()
589 <<
" " << real <<
" s" << std::endl;
595 *os <<
Indent (level) <<
" got=\"" << failure.
cond <<
"\" expected=\""
596 << failure.
actual <<
"\" in=\"" << failure.
file <<
":" << failure.
line
597 <<
"\" " << failure.
message << std::endl;
599 for (uint32_t i = 0; i < test->
m_children.size (); i++)
607 (*os).unsetf(std::ios_base::floatfield);
608 (*os).precision (oldPrecision);
615 std::cout <<
"Usage: " << program_name <<
" [OPTIONS]" << std::endl
617 <<
"Options: " << std::endl
618 <<
" --help : print these options" << std::endl
619 <<
" --print-test-name-list : print the list of names of tests available" << std::endl
620 <<
" --list : an alias for --print-test-name-list" << std::endl
621 <<
" --print-test-types : print the type of tests along with their names" << std::endl
622 <<
" --print-test-type-list : print the list of types of tests available" << std::endl
623 <<
" --print-temp-dir : print name of temporary directory before running " << std::endl
624 <<
" the tests" << std::endl
625 <<
" --test-type=TYPE : process only tests of type TYPE" << std::endl
626 <<
" --test-name=NAME : process only test whose name matches NAME" << std::endl
627 <<
" --suite=NAME : an alias (here for compatibility reasons only) " << std::endl
628 <<
" for --test-name=NAME" << std::endl
629 <<
" --assert-on-failure : when a test fails, crash immediately (useful" << std::endl
630 <<
" when running under a debugger" << std::endl
631 <<
" --stop-on-failure : when a test fails, stop immediately" << std::endl
632 <<
" --fullness=FULLNESS : choose the duration of tests to run: QUICK, " << std::endl
633 <<
" EXTENSIVE, or TAKES_FOREVER, where EXTENSIVE " << std::endl
634 <<
" includes QUICK and TAKES_FOREVER includes " << std::endl
635 <<
" QUICK and EXTENSIVE (only QUICK tests are " << std::endl
636 <<
" run by default)" << std::endl
637 <<
" --verbose : print details of test execution" << std::endl
638 <<
" --xml : format test run output as xml" << std::endl
639 <<
" --tempdir=DIR : set temp dir for tests to store output files" << std::endl
640 <<
" --datadir=DIR : set data dir for tests to read reference files" << std::endl
641 <<
" --out=FILE : send test result to FILE instead of standard "
642 <<
"output" << std::endl
643 <<
" --append=FILE : append test result to FILE instead of standard "
644 <<
"output" << std::endl
650 std::list<TestCase *>::const_iterator end,
651 bool printTestType)
const
654 std::map<TestSuite::Type, std::string> label;
663 for (std::list<TestCase *>::const_iterator i = begin; i != end; ++i)
671 std::cout << test->
GetName () << std::endl;
679 std::cout <<
" bvt: Build Verification Tests (to see if build completed successfully)" << std::endl;
680 std::cout <<
" core: Run all TestSuite-based tests (exclude examples)" << std::endl;
681 std::cout <<
" example: Examples (to see if example programs run successfully)" << std::endl;
682 std::cout <<
" performance: Performance Tests (check to see if the system is as fast as expected)" << std::endl;
683 std::cout <<
" system: System Tests (spans modules to check integration of modules)" << std::endl;
684 std::cout <<
" unit: Unit Tests (within modules to check basic functionality)" << std::endl;
688 std::list<TestCase *>
694 std::list<TestCase *> tests;
695 for (uint32_t i = 0; i <
m_suites.size (); ++i)
703 if (testName !=
"" && test->
GetName () != testName)
710 std::vector<TestCase *>::iterator j;
711 for (j = test->m_children.begin (); j != test->m_children.end ();)
717 if (testCase->
m_duration > maximumTestDuration)
723 j = test->m_children.erase (j);
734 tests.push_back (test);
744 std::string testName =
"";
745 std::string testTypeString =
"";
746 std::string out =
"";
747 std::string fullness =
"";
750 bool printTempDir =
false;
751 bool printTestTypeList =
false;
752 bool printTestNameList =
false;
753 bool printTestTypeAndName =
false;
755 char *progname = argv[0];
763 if (strcmp(arg,
"--assert-on-failure") == 0)
767 else if (strcmp (arg,
"--stop-on-failure") == 0)
771 else if (strcmp (arg,
"--verbose") == 0)
775 else if (strcmp (arg,
"--print-temp-dir") == 0)
779 else if (strcmp (arg,
"--update-data") == 0)
783 else if (strcmp (arg,
"--help") == 0)
788 else if (strcmp (arg,
"--print-test-name-list") == 0 ||
789 strcmp(arg,
"--list") == 0)
791 printTestNameList =
true;
793 else if (strcmp (arg,
"--print-test-types") == 0)
795 printTestTypeAndName =
true;
797 else if (strcmp (arg,
"--print-test-type-list") == 0)
799 printTestTypeList =
true;
801 else if (strcmp(arg,
"--append") == 0)
805 else if (strcmp(arg,
"--xml") == 0)
809 else if (strncmp(arg,
"--test-type=", strlen(
"--test-type=")) == 0)
811 testTypeString = arg + strlen(
"--test-type=");
813 else if (strncmp(arg,
"--test-name=", strlen(
"--test-name=")) == 0)
815 testName = arg + strlen(
"--test-name=");
817 else if (strncmp(arg,
"--suite=", strlen(
"--suite=")) == 0)
819 testName = arg + strlen(
"--suite=");
821 else if (strncmp(arg,
"--tempdir=", strlen(
"--tempdir=")) == 0)
825 else if (strncmp(arg,
"--out=", strlen(
"--out=")) == 0)
827 out = arg + strlen(
"--out=");
829 else if (strncmp(arg,
"--fullness=", strlen(
"--fullness=")) == 0)
831 fullness = arg + strlen(
"--fullness=");
834 if (fullness ==
"EXTENSIVE")
838 else if (fullness ==
"TAKES_FOREVER")
856 if (testTypeString ==
"")
860 else if (testTypeString ==
"bvt")
864 else if (testTypeString ==
"core")
868 else if (testTypeString ==
"example")
872 else if (testTypeString ==
"unit")
876 else if (testTypeString ==
"system")
880 else if (testTypeString ==
"performance")
886 std::cout <<
"Invalid test type specified: " << testTypeString << std::endl;
891 std::list<TestCase *> tests =
FilterTests (testName, testType, maximumTestDuration);
901 if (printTestNameList)
906 if (printTestTypeList)
917 ofs =
new std::ofstream();
918 std::ios_base::openmode mode = std::ios_base::out;
921 mode |= std::ios_base::app;
925 mode |= std::ios_base::trunc;
927 ofs->open (out.c_str (), mode);
937 for (std::list<TestCase *>::const_iterator i = tests.begin (); i != tests.end (); ++i)