--- a/SConstruct Wed Sep 06 13:34:58 2006 +0200
+++ b/SConstruct Wed Sep 06 13:35:23 2006 +0200
@@ -610,6 +610,12 @@
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 ()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/samples/main-test.cc Wed Sep 06 13:35:23 2006 +0200
@@ -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;
+}
--- a/src/core/system-wall-clock-ms.h Wed Sep 06 13:34:58 2006 +0200
+++ b/src/core/system-wall-clock-ms.h Wed Sep 06 13:35:23 2006 +0200
@@ -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;
--- a/src/core/test.h Wed Sep 06 13:34:58 2006 +0200
+++ b/src/core/test.h Wed Sep 06 13:35:23 2006 +0200
@@ -35,30 +35,57 @@
/**
* \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);