diff --git a/src/core/callback-test-suite.cc b/src/core/callback-test-suite.cc index b1e94d333..194cec655 100644 --- a/src/core/callback-test-suite.cc +++ b/src/core/callback-test-suite.cc @@ -22,18 +22,6 @@ namespace ns3 { -class X : public ns3::Test -{ -public: - X () : Test ("Callback") {} - void PublicParent (void) {} -protected: - static void StaticProtectedParent (void) {} - void ProtectedParent (void) {} -private: - void PrivateParent (void) {} -}; - // =========================================================================== // Test the basic Callback mechanism // =========================================================================== diff --git a/src/core/test.cc b/src/core/test.cc index c863c8fb7..57d285ad0 100644 --- a/src/core/test.cc +++ b/src/core/test.cc @@ -693,148 +693,4 @@ TestRunner::GetTestSuite (uint32_t n) return TestRunnerImpl::Instance ()->GetTestSuite (n); } -}; // namespace ns3 - -#ifdef RUN_SELF_TESTS - -namespace ns3 { - -TestManager * -TestManager::Get (void) -{ - static TestManager manager; - return &manager; -} - -TestManager::TestManager () - : m_verbose (false) -{} - -TestManager::~TestManager () -{ - TestsI i = m_tests.begin (); - while (i != m_tests.end ()) - { - delete (*i).second; - i = m_tests.erase (i); - } -} -void -TestManager::Add (Test *test, char const *name) -{ - Get ()->m_tests.push_back (std::make_pair (test, new std::string (name))); -} -void -TestManager::EnableVerbose (void) -{ - Get ()->m_verbose = true; -} - -void -TestManager::PrintTestNames (std::ostream &os) -{ - for (TestsCI i = Get ()->m_tests.begin (); i != Get ()->m_tests.end (); i++) - { - std::string *testName = (*i).second; - os << *testName << std::endl; - } -} - -std::ostream & -TestManager::Failure (void) -{ - return std::cerr; -} -bool -TestManager::RunTests (void) -{ - return Get ()->RealRunTests (); -} -bool -TestManager::RealRunTests (void) -{ - bool isSuccess = true; - for (TestsCI i = m_tests.begin (); i != m_tests.end (); i++) - { - std::string *testName = (*i).second; - if (!(*i).first->RunTests ()) - { - isSuccess = false; - if (m_verbose) - { - std::cerr << "FAIL " << *testName << std::endl; - } - } - else - { - if (m_verbose) - { - std::cerr << "PASS "<<*testName << std::endl; - } - } - } - if (!isSuccess) - { - std::cerr << "FAIL" << std::endl; - } - return isSuccess; -} - -bool -TestManager::RunTest (std::string name) -{ - return Get ()->RealRunTest (name); -} -bool -TestManager::RealRunTest (std::string name) -{ - TestsCI i; - - for (i = m_tests.begin (); i != m_tests.end (); i++) - { - std::string *testName = (*i).second; - if (*testName == name) - { - break; - } - } - if (i == m_tests.end ()) - { - std::cerr << "Test with name " << name << " not found." << std::endl; - } - - if (!(*i).first->RunTests ()) - { - if (m_verbose) - { - std::cerr << "FAIL " << name << std::endl; - } - return false; - } - else - { - if (m_verbose) - { - std::cerr << "PASS "<< name << std::endl; - } - return true; - } -} - -Test::Test (char const *name) -{ - TestManager::Add (this, name); -} - -Test::~Test () -{} - -std::ostream & -Test::Failure (void) -{ - return TestManager::Failure (); -} - -}; // namespace ns3 - -#endif /* RUN_SELF_TESTS */ +} // namespace ns3 diff --git a/src/core/test.h b/src/core/test.h index ac320e2a1..58db025f9 100644 --- a/src/core/test.h +++ b/src/core/test.h @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef TEST_H -#define TEST_H +#ifndef NS3_TEST_H +#define NS3_TEST_H #include #include @@ -1151,170 +1151,6 @@ TestVectors::Get (uint32_t i) const return m_vectors[i]; } -}; // namespace ns3 +} // namespace ns3 -// -// Original ns-3 unit test code for compatibility -// -#ifdef RUN_SELF_TESTS - -namespace ns3 { - -class TestManager; - -/** - * \ingroup core - * \defgroup test Test - */ -/** - * \ingroup test - * - * \brief base class for new regressions tests - * - * To add a new regression test, you need to: - * - create subclass of this abstract base class - * - instantiate once this subclass through a static - * variable. - * - * The following sample code shows you how to do this: - * \include samples/main-test.cc - */ -class Test { -public: - /** - * \param name the name of the test - */ - Test (char const *name); - virtual ~Test (); - - /** - * \returns true if the test was successful, false otherwise. - */ - virtual bool RunTests (void) = 0; - -protected: - /** - * \returns an output stream which base classes can write to - * to return extra information on test errors. - */ - std::ostream &Failure (void); -}; - -/** - * \ingroup test - * - * \brief gather and run all regression tests - */ -class TestManager { -public: - /** - * Enable verbose output. If you do not enable verbose output, - * nothing is printed on screen during the test runs. - */ - static void EnableVerbose (void); - /** - * \returns true if all tests passed, false otherwise. - * - * run all registered regression tests - */ - static bool RunTests (void); - - static bool RunTest (std::string name); - - static void PrintTestNames (std::ostream &os); - -private: - friend class Test; - static void Add (Test *test, char const *name); - static std::ostream &Failure (void); - static TestManager *Get (void); - bool RealRunTests (void); - bool RealRunTest (std::string name); - - TestManager (); - ~TestManager (); - - typedef std::list > Tests; - typedef std::list >::iterator TestsI; - typedef std::list >::const_iterator TestsCI; - - Tests m_tests; - bool m_verbose; -}; -}; // namespace ns3 - -#define NS_TEST_ASSERT_EQUAL_FILELINE(got, expected, file, line) \ - do { \ - if (! ((got) == (expected))) \ - { \ - Failure () << file << ":" < - */ - -#include "ns3/test.h" -#include "ns3/packet-metadata.h" -#include "ns3/random-variable.h" - - -int main (int argc, char *argv[]) -{ - if (argc > 1) - { - if (std::string (argv[1]) == "--ListTests") - { -#ifdef RUN_SELF_TESTS - ns3::TestManager::PrintTestNames (std::cout); -#endif - } - else - { - // run the test named by argv[1] -#ifdef RUN_SELF_TESTS - bool success = ns3::TestManager::RunTest (argv[1]); - if (!success) - { - return 1; - } -#else - std::cerr << "Unit tests not enabled" << std::endl; - return 1; -#endif - } - } - else - { - // run all tests -#ifdef RUN_SELF_TESTS - ns3::PacketMetadata::Enable (); - ns3::TestManager::EnableVerbose (); - bool success = ns3::TestManager::RunTests (); - if (!success) - { - return 1; - } -#endif /* RUN_SELF_TESTS */ - } - return 0; -} - diff --git a/utils/wscript b/utils/wscript index d30726465..ee037d02e 100644 --- a/utils/wscript +++ b/utils/wscript @@ -4,12 +4,6 @@ import os.path def build(bld): env = bld.env - unit_tests = bld.create_ns3_program('run-tests', ['common']) - unit_tests.install_path = None # do not install - unit_tests.source = 'run-tests.cc' - ## link unit test program with all ns3 modules - unit_tests.uselib_local = 'ns3' - test_runner = bld.create_ns3_program('test-runner', ['core']) test_runner.install_path = None # do not install test_runner.source = 'test-runner.cc'