src/core/test.cc
changeset 122 6b8f1eda5c57
parent 110 9ac6d63bfe33
child 131 f4fb87e77034
equal deleted inserted replaced
121:f8bc1a370b82 122:6b8f1eda5c57
    25 #include <iostream>
    25 #include <iostream>
    26 
    26 
    27 namespace ns3 {
    27 namespace ns3 {
    28 
    28 
    29 TestManager *
    29 TestManager *
    30 TestManager::get (void)
    30 TestManager::Get (void)
    31 {
    31 {
    32     static TestManager manager;
    32     static TestManager manager;
    33     return &manager;
    33     return &manager;
    34 }
    34 }
    35 
    35 
    44         delete (*i).second;
    44         delete (*i).second;
    45         i = m_tests.erase (i);
    45         i = m_tests.erase (i);
    46     }
    46     }
    47 }
    47 }
    48 void
    48 void
    49 TestManager::add (Test *test, char const *name)
    49 TestManager::Add (Test *test, char const *name)
    50 {
    50 {
    51     get ()->m_tests.push_back (std::make_pair (test, new std::string (name)));
    51     Get ()->m_tests.push_back (std::make_pair (test, new std::string (name)));
    52 }
    52 }
    53 void
    53 void
    54 TestManager::enableVerbose (void)
    54 TestManager::EnableVerbose (void)
    55 {
    55 {
    56     get ()->m_verbose = true;
    56     Get ()->m_verbose = true;
    57 }
    57 }
    58 std::ostream &
    58 std::ostream &
    59 TestManager::failure (void)
    59 TestManager::Failure (void)
    60 {
    60 {
    61     return std::cerr;
    61     return std::cerr;
    62 }
    62 }
    63 bool 
    63 bool 
    64 TestManager::runTests (void)
    64 TestManager::RunTests (void)
    65 {
    65 {
    66     return get ()->realRunTests ();
    66     return Get ()->RealRunTests ();
    67 }
    67 }
    68 bool 
    68 bool 
    69 TestManager::realRunTests (void)
    69 TestManager::RealRunTests (void)
    70 {
    70 {
    71     bool isSuccess = true;
    71     bool isSuccess = true;
    72     for (TestsCI i = m_tests.begin (); i != m_tests.end (); i++) {
    72     for (TestsCI i = m_tests.begin (); i != m_tests.end (); i++) {
    73         std::string *testName = (*i).second;
    73         std::string *testName = (*i).second;
    74         if (!(*i).first->runTests ()) {
    74         if (!(*i).first->RunTests ()) {
    75             isSuccess = false;
    75             isSuccess = false;
    76             if (m_verbose) {
    76             if (m_verbose) {
    77                 std::cerr << "FAIL " << *testName << std::endl;
    77                 std::cerr << "FAIL " << *testName << std::endl;
    78             }
    78             }
    79         } else {
    79         } else {
    88     return isSuccess;
    88     return isSuccess;
    89 }
    89 }
    90 
    90 
    91 Test::Test (char const *name)
    91 Test::Test (char const *name)
    92 {
    92 {
    93     TestManager::add (this, name);
    93     TestManager::Add (this, name);
    94 }
    94 }
    95 
    95 
    96 Test::~Test ()
    96 Test::~Test ()
    97 {}
    97 {}
    98 
    98 
    99 std::ostream &
    99 std::ostream &
   100 Test::failure (void)
   100 Test::Failure (void)
   101 {
   101 {
   102     return TestManager::failure ();
   102     return TestManager::Failure ();
   103 }
   103 }
   104 
   104 
   105 }; // namespace ns3
   105 }; // namespace ns3
   106 
   106 
   107 #endif /* RUN_SELF_TESTS */
   107 #endif /* RUN_SELF_TESTS */