add sample code for test, add doxygen doc
This commit is contained in:
1 parent
9f1957be9d
commit
495c246850
4 files changed
+88
-3
No files matched your search
@@ -610,6 +610,12 @@ main_packet.set_executable ()
|
||||
main_packet.add_dep ('common')
|
||||
main_packet.add_source ('main-packet.cc')
|
||||
|
||||
sample_test = Ns3Module ('sample-test', 'samples')
|
||||
sample_test.set_executable ()
|
||||
ns3.add (sample_test)
|
||||
sample_test.add_dep ('core')
|
||||
sample_test.add_source ('main-test.cc')
|
||||
|
||||
|
||||
ns3.generate_dependencies ()
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/* -*- Mode:C++; c-basic-offset:4; tab-width:4; indent-tabs-mode:f -*- */
|
||||
|
||||
#include "ns3/test.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
#ifndef RUN_SELF_TESTS
|
||||
|
||||
class MyTest : public Test {
|
||||
public:
|
||||
MyTest (bool ok);
|
||||
virtual ~MyTest ();
|
||||
virtual bool runTests (void);
|
||||
private:
|
||||
bool m_ok;
|
||||
};
|
||||
|
||||
MyTest::MyTest (bool ok)
|
||||
: Test ("My"),
|
||||
m_ok (ok)
|
||||
{}
|
||||
MyTest::~MyTest ()
|
||||
{}
|
||||
bool
|
||||
MyTest::runTests (void)
|
||||
{
|
||||
return m_ok;
|
||||
}
|
||||
|
||||
MyTest g_my_test = MyTest (false);
|
||||
|
||||
#endif /* RUN_SELF_TESTS */
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
TestManager::enableVerbose ();
|
||||
TestManager::runTests ();
|
||||
return 0;
|
||||
}
|
||||
@@ -24,12 +24,25 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/**
|
||||
* \brief measure wall-clock time in milliseconds
|
||||
*/
|
||||
class SystemWallClockMs {
|
||||
public:
|
||||
SystemWallClockMs ();
|
||||
~SystemWallClockMs ();
|
||||
|
||||
/**
|
||||
* Start a measure.
|
||||
*/
|
||||
void start (void);
|
||||
/**
|
||||
* \returns the measured elapsed wall clock time since
|
||||
* ns3::SystemWallClockMs::start was invoked.
|
||||
*
|
||||
* It is possible to start a new measurement with ns3::SystemWallClockMs::start
|
||||
* after this method returns.
|
||||
*/
|
||||
unsigned long long end (void);
|
||||
private:
|
||||
class SystemWallClockMsPrivate *m_priv;
|
||||
|
||||
+30
-3
@@ -35,30 +35,57 @@ class TestManager;
|
||||
|
||||
/**
|
||||
* \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);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* \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);
|
||||
|
||||
// helper methods
|
||||
private:
|
||||
friend class Test;
|
||||
static void add (Test *test, char const *name);
|
||||
static std::ostream &failure (void);
|
||||
private:
|
||||
static TestManager *get (void);
|
||||
bool realRunTests (void);
|
||||
|
||||
|
||||
Reference in new issue
Block a user