41 double delta, difference;
47 double max = (std::fabs (x1) > std::fabs (x2)) ? x1 : x2;
48 (void)std::frexp (max, &exponent);
54 delta = std::ldexp (epsilon, exponent);
57 if (difference > delta || difference < -delta)
67 std::string _limit, std::string _message,
68 std::string _file, int32_t _line);
91 std::string limit, std::string message,
92 std::string file, int32_t line);
99 int Run (
int argc,
char *argv[]);
111 std::list<TestCase *>::const_iterator end,
112 bool printTestType)
const;
114 void PrintHelp (
const char *programName)
const;
115 std::list<TestCase *>
FilterTests (std::string testName,
133 std::string _limit, std::string _message,
134 std::string _file, int32_t _line)
135 : cond (_cond), actual (_actual), limit (_limit),
136 message (_message), file (_file), line (_line)
138 NS_LOG_FUNCTION (
this << _cond << _actual << _limit << _message << _file << _line);
141 : childrenFailed (false)
165 for (std::vector<TestCase *>::const_iterator i =
m_children.begin (); i !=
m_children.end (); ++i)
188 std::string::size_type slash, antislash;
189 slash = testCase->
m_name.find (
"/");
190 antislash = testCase->
m_name.find (
"\\");
191 if (slash != std::string::npos || antislash != std::string::npos)
193 std::string fullname = testCase->
m_name;
197 fullname = current->
m_name +
"/" + fullname;
200 if (slash != std::string::npos)
202 NS_FATAL_ERROR (
"Invalid test name: cannot contain slashes: \"" << fullname <<
"\"");
204 if (antislash != std::string::npos)
206 NS_FATAL_ERROR (
"Invalid test name: cannot contain antislashes: \"" << fullname <<
"\"");
226 for (std::vector<TestCase *>::const_iterator i =
m_children.begin (); i !=
m_children.end (); ++i)
249 std::string limit, std::string message,
250 std::string file, int32_t line)
252 NS_LOG_FUNCTION (
this << cond << actual << limit << message << file << line);
254 message, file, line));
282 while (current != 0 && current->
m_dataDir ==
"")
288 NS_FATAL_ERROR (
"No one called SetDataDir prior to calling this function");
305 std::list<std::string> names;
309 names.push_front (current->
m_name);
378 m_assertOnFailure (false),
379 m_continueOnFailure (true),
437 bool haveVersion =
false;
438 bool haveLicense =
false;
446 for (std::list<std::string>::const_iterator i = files.begin (); i != files.end (); ++i)
452 else if (*i ==
"LICENSE")
458 return haveVersion && haveLicense;
467 while (!elements.empty ())
474 elements.pop_back ();
476 NS_FATAL_ERROR (
"Could not find source directory from self=" <<
self);
488 typedef std::map <char, std::string> specials_map;
489 specials_map specials;
490 specials[
'<'] =
"<";
491 specials[
'>'] =
">";
492 specials[
'&'] =
"&";
493 specials[
'"'] =
"'";
494 specials[
'\''] =
""";
497 std::size_t length = xml.length ();
499 for (
size_t i = 0; i < length; ++i)
501 char character = xml[i];
503 specials_map::const_iterator it = specials.find (character);
505 if (it == specials.end ())
507 result.push_back (character);
511 result += it->second;
529 for (
int i = 0; i < val.
level; i++)
546 const double MS_PER_SEC = 1000.;
551 std::streamsize oldPrecision = (*os).precision (3);
554 std::string statusString = test->
IsFailed ()?
"FAIL":
"PASS";
557 *os <<
Indent (level) <<
"<Test>" << std::endl;
559 <<
"</Name>" << std::endl;
560 *os <<
Indent (level+1) <<
"<Result>" << statusString <<
"</Result>" << std::endl;
561 *os <<
Indent (level+1) <<
"<Time real=\"" << real <<
"\" user=\"" << user
562 <<
"\" system=\"" << system <<
"\"/>" << std::endl;
566 *os <<
Indent (level+2) <<
"<FailureDetails>" << std::endl
567 <<
Indent (level+3) <<
"<Condition>"
569 <<
Indent (level+3) <<
"<Actual>"
571 <<
Indent (level+3) <<
"<Limit>"
573 <<
Indent (level+3) <<
"<Message>"
575 <<
Indent (level+3) <<
"<File>"
577 <<
Indent (level+3) <<
"<Line>" << failure.
line <<
"</Line>" << std::endl
578 <<
Indent (level+2) <<
"</FailureDetails>" << std::endl;
580 for (uint32_t i = 0; i < test->
m_children.size (); i++)
585 *os <<
Indent (level) <<
"</Test>" << std::endl;
589 *os <<
Indent (level) << statusString <<
" " << test->
GetName ()
590 <<
" " << real <<
" s" << std::endl;
596 *os <<
Indent (level) <<
" got=\"" << failure.
cond <<
"\" expected=\""
597 << failure.
actual <<
"\" in=\"" << failure.
file <<
":" << failure.
line
598 <<
"\" " << failure.
message << std::endl;
600 for (uint32_t i = 0; i < test->
m_children.size (); i++)
608 (*os).unsetf(std::ios_base::floatfield);
609 (*os).precision (oldPrecision);
616 std::cout <<
"Usage: " << program_name <<
" [OPTIONS]" << std::endl
618 <<
"Options: " << std::endl
619 <<
" --help : print these options" << std::endl
620 <<
" --print-test-name-list : print the list of names of tests available" << std::endl
621 <<
" --list : an alias for --print-test-name-list" << std::endl
622 <<
" --print-test-types : print the type of tests along with their names" << std::endl
623 <<
" --print-test-type-list : print the list of types of tests available" << std::endl
624 <<
" --print-temp-dir : print name of temporary directory before running " << std::endl
625 <<
" the tests" << std::endl
626 <<
" --test-type=TYPE : process only tests of type TYPE" << std::endl
627 <<
" --test-name=NAME : process only test whose name matches NAME" << std::endl
628 <<
" --suite=NAME : an alias (here for compatibility reasons only) " << std::endl
629 <<
" for --test-name=NAME" << std::endl
630 <<
" --assert-on-failure : when a test fails, crash immediately (useful" << std::endl
631 <<
" when running under a debugger" << std::endl
632 <<
" --stop-on-failure : when a test fails, stop immediately" << std::endl
633 <<
" --fullness=FULLNESS : choose the duration of tests to run: QUICK, " << std::endl
634 <<
" EXTENSIVE, or TAKES_FOREVER, where EXTENSIVE " << std::endl
635 <<
" includes QUICK and TAKES_FOREVER includes " << std::endl
636 <<
" QUICK and EXTENSIVE (only QUICK tests are " << std::endl
637 <<
" run by default)" << std::endl
638 <<
" --verbose : print details of test execution" << std::endl
639 <<
" --xml : format test run output as xml" << std::endl
640 <<
" --tempdir=DIR : set temp dir for tests to store output files" << std::endl
641 <<
" --datadir=DIR : set data dir for tests to read reference files" << std::endl
642 <<
" --out=FILE : send test result to FILE instead of standard "
643 <<
"output" << std::endl
644 <<
" --append=FILE : append test result to FILE instead of standard "
645 <<
"output" << std::endl
651 std::list<TestCase *>::const_iterator end,
652 bool printTestType)
const
655 std::map<TestSuite::Type, std::string> label;
664 for (std::list<TestCase *>::const_iterator i = begin; i != end; ++i)
672 std::cout << test->
GetName () << std::endl;
680 std::cout <<
" bvt: Build Verification Tests (to see if build completed successfully)" << std::endl;
681 std::cout <<
" core: Run all TestSuite-based tests (exclude examples)" << std::endl;
682 std::cout <<
" example: Examples (to see if example programs run successfully)" << std::endl;
683 std::cout <<
" performance: Performance Tests (check to see if the system is as fast as expected)" << std::endl;
684 std::cout <<
" system: System Tests (spans modules to check integration of modules)" << std::endl;
685 std::cout <<
" unit: Unit Tests (within modules to check basic functionality)" << std::endl;
689 std::list<TestCase *>
695 std::list<TestCase *> tests;
696 for (uint32_t i = 0; i <
m_suites.size (); ++i)
704 if (testName !=
"" && test->
GetName () != testName)
711 std::vector<TestCase *>::iterator j;
712 for (j = test->m_children.begin (); j != test->m_children.end ();)
718 if (testCase->
m_duration > maximumTestDuration)
724 j = test->m_children.erase (j);
735 tests.push_back (test);
745 std::string testName =
"";
746 std::string testTypeString =
"";
747 std::string out =
"";
748 std::string fullness =
"";
751 bool printTempDir =
false;
752 bool printTestTypeList =
false;
753 bool printTestNameList =
false;
754 bool printTestTypeAndName =
false;
756 char *progname = argv[0];
764 if (strcmp(arg,
"--assert-on-failure") == 0)
768 else if (strcmp (arg,
"--stop-on-failure") == 0)
772 else if (strcmp (arg,
"--verbose") == 0)
776 else if (strcmp (arg,
"--print-temp-dir") == 0)
780 else if (strcmp (arg,
"--update-data") == 0)
784 else if (strcmp (arg,
"--help") == 0)
789 else if (strcmp (arg,
"--print-test-name-list") == 0 ||
790 strcmp(arg,
"--list") == 0)
792 printTestNameList =
true;
794 else if (strcmp (arg,
"--print-test-types") == 0)
796 printTestTypeAndName =
true;
798 else if (strcmp (arg,
"--print-test-type-list") == 0)
800 printTestTypeList =
true;
802 else if (strcmp(arg,
"--append") == 0)
806 else if (strcmp(arg,
"--xml") == 0)
810 else if (strncmp(arg,
"--test-type=", strlen(
"--test-type=")) == 0)
812 testTypeString = arg + strlen(
"--test-type=");
814 else if (strncmp(arg,
"--test-name=", strlen(
"--test-name=")) == 0)
816 testName = arg + strlen(
"--test-name=");
818 else if (strncmp(arg,
"--suite=", strlen(
"--suite=")) == 0)
820 testName = arg + strlen(
"--suite=");
822 else if (strncmp(arg,
"--tempdir=", strlen(
"--tempdir=")) == 0)
826 else if (strncmp(arg,
"--out=", strlen(
"--out=")) == 0)
828 out = arg + strlen(
"--out=");
830 else if (strncmp(arg,
"--fullness=", strlen(
"--fullness=")) == 0)
832 fullness = arg + strlen(
"--fullness=");
835 if (fullness ==
"EXTENSIVE")
839 else if (fullness ==
"TAKES_FOREVER")
857 if (testTypeString ==
"")
861 else if (testTypeString ==
"bvt")
865 else if (testTypeString ==
"core")
869 else if (testTypeString ==
"example")
873 else if (testTypeString ==
"unit")
877 else if (testTypeString ==
"system")
881 else if (testTypeString ==
"performance")
887 std::cout <<
"Invalid test type specified: " << testTypeString << std::endl;
892 std::list<TestCase *> tests =
FilterTests (testName, testType, maximumTestDuration);
902 if (printTestNameList)
907 if (printTestTypeList)
918 ofs =
new std::ofstream();
919 std::ios_base::openmode mode = std::ios_base::out;
922 mode |= std::ios_base::app;
926 mode |= std::ios_base::trunc;
928 ofs->open (out.c_str (), mode);
938 for (std::list<TestCase *>::const_iterator i = tests.begin (); i != tests.end (); ++i)
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
bool MustAssertOnFailure(void) const
void PrintHelp(const char *programName) const
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
#define NS_LOG_FUNCTION(parameters)
This test suite implements a System Test.
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
TestCaseFailure(std::string _cond, std::string _actual, std::string _limit, std::string _message, std::string _file, int32_t _line)
void AddTestSuite(TestSuite *testSuite)
#define NS_ASSERT(condition)
bool IsFailed(void) const
void MakeDirectories(std::string path)
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
enum TestDuration m_duration
TestCase duration.
void PrintReport(TestCase *test, std::ostream *os, bool xml, int level)
void PrintTestNameList(std::list< TestCase * >::const_iterator begin, std::list< TestCase * >::const_iterator end, bool printTestType) const
TestSuite(std::string name, Type type=UNIT)
Constuct a new test suite.
#define NS_FATAL_ERROR(msg)
fatal error handling
virtual void DoRun(void)
Implementation to actually run this TestCase.
std::list< TestCase * > FilterTests(std::string testName, enum TestSuite::Type testType, enum TestCase::TestDuration maximumTestDuration)
std::string GetTempDir(void) const
measure elapsed time in milliseconds
TestCase * m_parent
Pointer to my parent TestCase.
TestRunnerImpl * m_runner
Pointer to the TestRunner.
std::string Join(std::list< std::string >::const_iterator begin, std::list< std::string >::const_iterator end)
bool TestDoubleIsEqual(const double x1, const double x2, const double epsilon)
Compare two double precision floating point numbers and declare them equal if they are within some ep...
std::string GetTopLevelSourceDir(void) const
std::list< std::string > ReadFiles(std::string path)
void Start(void)
Start a measure.
bool MustUpdateData(void) const
TestSuite::Type m_type
Type of this TestSuite.
bool MustAssertOnFailure(void) const
This test suite implements a Performance Test.
TestCase(std::string name)
This test suite implements a Build Verification Test.
std::string FindSelfDirectory(void)
void ReportTestFailure(std::string cond, std::string actual, std::string limit, std::string message, std::string file, int32_t line)
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
bool GetErrorStatus(void) const NS_DEPRECATED
TestDuration
How long the test takes to execute.
bool MustContinueOnFailure(void) const
virtual ~TestCase()
Destructor.
std::string CreateDataDirFilename(std::string filename)
virtual void DoRun(void)=0
Implementation to actually run this TestCase.
struct Result * m_result
Results data.
bool IsStatusFailure(void) const
void ReportTestFailure(std::string cond, std::string actual, std::string limit, std::string message, std::string file, int32_t line)
std::string Append(std::string left, std::string right)
std::string MakeTemporaryDirectoryName(void)
void Run(TestRunnerImpl *runner)
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
bool IsStatusSuccess(void) const
int64_t GetElapsedUser(void) const
std::string CreateTempDirFilename(std::string filename)
int64_t GetElapsedReal(void) const
std::string ReplaceXmlSpecialCharacters(std::string xml) const
void SetDataDir(std::string directory)
std::vector< TestSuite * > TestSuiteVector
static TestRunnerImpl * Instance(void)
std::vector< TestCase * > m_children
Vector of my children.
This test suite implements an Example Test.
int64_t GetElapsedSystem(void) const
std::string GetName(void) const
bool IsTopLevelSourceDir(std::string path) const
This test suite implements a Unit Test.
TestSuite::Type GetTestType(void)
get the kind of test this test suite implements
void PrintTestTypeList(void) const
std::vector< TestCaseFailure > failure
void StartTestCase(std::string name)
std::list< std::string > Split(std::string path)
int64_t End(void)
Stop measuring the time since Start() was called.
static int Run(int argc, char *argv[])
Run the requested suite of tests.
int Run(int argc, char *argv[])
std::string m_name
TestCase name.
std::string m_dataDir
My data directory.
bool MustContinueOnFailure(void) const