From 495c246850e02e64553f8b6fe60305ecbeaa97f1 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 6 Sep 2006 13:35:23 +0200 Subject: [PATCH] add sample code for test, add doxygen doc --- SConstruct | 6 +++++ samples/main-test.cc | 39 +++++++++++++++++++++++++++++++++ src/core/system-wall-clock-ms.h | 13 +++++++++++ src/core/test.h | 33 +++++++++++++++++++++++++--- 4 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 samples/main-test.cc diff --git a/SConstruct b/SConstruct index 93e05cce2..e56c38692 100644 --- a/SConstruct +++ b/SConstruct @@ -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 () diff --git a/samples/main-test.cc b/samples/main-test.cc new file mode 100644 index 000000000..fc9ea51c4 --- /dev/null +++ b/samples/main-test.cc @@ -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; +} diff --git a/src/core/system-wall-clock-ms.h b/src/core/system-wall-clock-ms.h index 0c47079a6..172080a47 100644 --- a/src/core/system-wall-clock-ms.h +++ b/src/core/system-wall-clock-ms.h @@ -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; diff --git a/src/core/test.h b/src/core/test.h index 782d6068b..f758442f7 100644 --- a/src/core/test.h +++ b/src/core/test.h @@ -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);