A Discrete-Event Network Simulator
API
sample-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 
20 // An essential include is test.h
21 #include "ns3/test.h"
22 
23 // Do not put your test classes in namespace ns3. You may find it useful
24 // to use the using directive to access the ns3 namespace directly
25 using namespace ns3;
26 
27 // This is an example TestCase.
28 class SampleTestCase1 : public TestCase
29 {
30 public:
31  SampleTestCase1 ();
32  virtual ~SampleTestCase1 ();
33 
34 private:
35  virtual void DoRun (void);
36 };
37 
38 // Add some help text to this case to describe what it is intended to test
40  : TestCase ("Sample test case (does nothing)")
41 {
42 }
43 
44 // This destructor does nothing but we include it as a reminder that
45 // the test case should clean up after itself
47 {
48 }
49 
50 //
51 // This method is the pure virtual method from class TestCase that every
52 // TestCase must implement
53 //
54 void
56 {
57  // A wide variety of test macros are available in src/core/test.h
58  NS_TEST_ASSERT_MSG_EQ (true, true, "true doesn't equal true for some reason");
59  // Use this one for floating point comparisons
60  NS_TEST_ASSERT_MSG_EQ_TOL (0.01, 0.01, 0.001, "Numbers are not equal within tolerance");
61 }
62 
63 // The TestSuite class names the TestSuite, identifies what type of TestSuite,
64 // and enables the TestCases to be run. Typically, only the constructor for
65 // this class must be defined
66 //
67 class SampleTestSuite : public TestSuite
68 {
69 public:
70  SampleTestSuite ();
71 };
72 
74  : TestSuite ("sample", UNIT)
75 {
76  AddTestCase (new SampleTestCase1, TestCase::QUICK);
77 }
78 
79 // Do not forget to allocate an instance of this TestSuite
A suite of tests to run.
Definition: test.h:1333
virtual void DoRun(void)
Implementation to actually run this TestCase.
encapsulates test code
Definition: test.h:1147
static SampleTestSuite sampleTestSuite
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
#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:161
virtual ~SampleTestCase1()
#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:373
Every class exported by the ns3 library is enclosed in the ns3 namespace.