bug 675: kill old test framework

This commit is contained in:
Mathieu Lacage
2009-10-01 13:17:24 +02:00
parent 901e12f2da
commit c940ca5a90
5 changed files with 5 additions and 397 deletions

View File

@@ -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
// ===========================================================================

View File

@@ -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

View File

@@ -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 @@ TestVectors<T>::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<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 */

View File

@@ -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;
}

View File

@@ -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'