bug 675: kill old test framework
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 01 Oct 2009 13:17:24 +0200
changeset 5342 3c6109eec550
parent 5341 586ce4339aab
child 5343 2c86afb0a8f5
bug 675: kill old test framework
src/core/callback-test-suite.cc
src/core/test.cc
src/core/test.h
utils/run-tests.cc
utils/wscript
--- a/src/core/callback-test-suite.cc	Thu Oct 01 15:21:21 2009 +0400
+++ b/src/core/callback-test-suite.cc	Thu Oct 01 13:17:24 2009 +0200
@@ -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
 // ===========================================================================
--- a/src/core/test.cc	Thu Oct 01 15:21:21 2009 +0400
+++ b/src/core/test.cc	Thu Oct 01 13:17:24 2009 +0200
@@ -693,148 +693,4 @@
   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
--- a/src/core/test.h	Thu Oct 01 15:21:21 2009 +0400
+++ b/src/core/test.h	Thu Oct 01 13:17:24 2009 +0200
@@ -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 <iostream>
 #include <fstream>
@@ -1151,170 +1151,6 @@
   return m_vectors[i];
 }
 
-}; // 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 ();
+} // namespace ns3 
 
-  typedef std::list<std::pair<Test *,std::string *> > Tests;
-  typedef std::list<std::pair<Test *,std::string *> >::iterator TestsI;
-  typedef std::list<std::pair<Test *,std::string *> >::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 << ":" <<line                            \
-                   << ": expected " << (expected)                   \
-                   << ", got " << (got) << std::endl;               \
-        result = false;                                             \
-      }                                                             \
-  } while (false)
-
-#define NS_TEST_ASSERT_UNEQUAL_FILELINE(got, expected,file,line)    \
-  do {                                                              \
-    if ((got) == (expected))                                        \
-      {                                                             \
-        Failure () << file << ":" <<line                            \
-                   << ": did not want " << (expected)               \
-                   << ", got " << (got) << std::endl;               \
-        result = false;                                             \
-      }                                                             \
-  } while (false)
-
-
-#define NS_TEST_ASSERT_FILELINE(assertion, file, line)  \
-  do {                                                  \
-    if (!(assertion))                                   \
-      {                                                 \
-        Failure () << file << ":" <<line                \
-                   << ": assertion `" << #assertion     \
-                   << "' failed." << std::endl;         \
-        result = false;                                 \
-      }                                                 \
-  } while (false)
-
-
-
-/**
- * Convenience macro to check that a value returned by a test is what
- * is expected.  Note: this macro assumes a 'bool result = true'
- * declaration exists in the test function body, and that the function
- * returns that value.
- *
- * \param got value obtained from the test
- * \param expected value that the test is expected to return
- */
-#define NS_TEST_ASSERT_EQUAL(got, expected)             \
-  NS_TEST_ASSERT_EQUAL_FILELINE(got,expected,__FILE__,__LINE__)
-
-/**
- * Convenience macro to check that a value returned by a test is what
- * is expected.  Note: this macro assumes a 'bool result = true'
- * declaration exists in the test function body, and that the function
- * returns that value.
- *
- * \param got value obtained from the test
- * \param expected value that the test is expected to return
- */
-#define NS_TEST_ASSERT_UNEQUAL(got, expected)           \
-  NS_TEST_ASSERT_UNEQUAL_FILELINE(got,expected,__FILE__,__LINE__)
-
-/**
- * Convenience macro to check an assertion is held during an unit
- * test.  Note: this macro assumes a 'bool result = true' declaration
- * exists in the test function body, and that the function returns
- * that value.
- *
- * \param assertion expression that must be true if the test did not fail
- */
-#define NS_TEST_ASSERT(assertion)                       \
-  NS_TEST_ASSERT_FILELINE (assertion, __FILE__,__LINE__)
-
-
-#endif /* RUN_SELF_TESTS */
-
-#endif /* TEST_H */
+#endif /* NS3_TEST_H */
--- a/utils/run-tests.cc	Thu Oct 01 15:21:21 2009 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#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;
-}
-
--- a/utils/wscript	Thu Oct 01 15:21:21 2009 +0400
+++ b/utils/wscript	Thu Oct 01 13:17:24 2009 +0200
@@ -4,12 +4,6 @@
 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'