A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sample-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 
3 // An essential include is test.h
4 #include "ns3/test.h"
5 
6 // Do not put your test classes in namespace ns3. You may find it useful
7 // to use the using directive to access the ns3 namespace directly
8 using namespace ns3;
9 
10 // This is an example TestCase.
11 class SampleTestCase1 : public TestCase
12 {
13 public:
14  SampleTestCase1 ();
15  virtual ~SampleTestCase1 ();
16 
17 private:
18  virtual void DoRun (void);
19 };
20 
21 // Add some help text to this case to describe what it is intended to test
23  : TestCase ("Sample test case (does nothing)")
24 {
25 }
26 
27 // This destructor does nothing but we include it as a reminder that
28 // the test case should clean up after itself
30 {
31 }
32 
33 //
34 // This method is the pure virtual method from class TestCase that every
35 // TestCase must implement
36 //
37 void
39 {
40  // A wide variety of test macros are available in src/core/test.h
41  NS_TEST_ASSERT_MSG_EQ (true, true, "true doesn't equal true for some reason");
42  // Use this one for floating point comparisons
43  NS_TEST_ASSERT_MSG_EQ_TOL (0.01, 0.01, 0.001, "Numbers are not equal within tolerance");
44 }
45 
46 // The TestSuite class names the TestSuite, identifies what type of TestSuite,
47 // and enables the TestCases to be run. Typically, only the constructor for
48 // this class must be defined
49 //
50 class SampleTestSuite : public TestSuite
51 {
52 public:
53  SampleTestSuite ();
54 };
55 
57  : TestSuite ("sample", UNIT)
58 {
59  AddTestCase (new SampleTestCase1, TestCase::QUICK);
60 }
61 
62 // Do not forget to allocate an instance of this TestSuite
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition: test.h:326
A suite of tests to run.
Definition: test.h:1025
virtual void DoRun(void)
Implementation to actually run this TestCase.
encapsulates test code
Definition: test.h:849
static SampleTestSuite sampleTestSuite
virtual ~SampleTestCase1()
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:173
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:137