A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
sample-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
18
19// An essential include is test.h
20#include "ns3/test.h"
21
22/**
23 * \file
24 * \ingroup core-tests
25 * \ingroup testing
26 * \ingroup testing-example
27 *
28 * Example use of TestSuite.
29 *
30 * Assume this is the test suite for `class Class`
31 * in module 'module'.
32 *
33 * Document the file as follows. (Note: for purposes of this
34 * illustration Doxygen comments are set off with triple `\\\\\\';
35 * you should use the normal Javadoc format. )
36 *
37 * Add it to the groups module-tests and class-tests:
38 *
39 * \verbatim /// \file
40/// \ingroup module-tests
41/// \ingroup class-tests
42/// Class test suite. \endverbatim
43 *
44 * Define the class-tests group:
45 * \verbatim /// \ingroup module-tests
46/// \defgroup class-tests Class test suite \endverbatim
47 *
48 * Make sure test.h is included:
49 * \verbatim #include "ns3/test.h" \endverbatim
50 *
51 * Put the test code in namespace ns3::tests.
52 * \verbatim namespace ns3 {
53 namespace tests { \endverbatim
54 *
55 * Write your test cases and final test suite, and put them in
56 * your test group:
57 * \verbatim /// \ingroup class-tests
58class ClassTestSuite : public TestSuite {...}; \endverbatim
59 *
60 * Create a static variable to hold the instance of your test suite:
61 * \verbatim /// \ingroup class-tests
62/// ClassTestSuite instance variable.
63static ClassTestSuite g_classTestSuite; \endverbatim
64 *
65 * Finally, close the ingroup and namespace blocks:
66 * \verbatim } // namespace tests
67} // namespace ns3 \endverbatim
68*/
69
70/**
71 * \ingroup core-tests
72 * \defgroup testing-example Example use of TestSuite
73 */
74
75namespace ns3
76{
77
78namespace tests
79{
80
81/**
82 * \ingroup testing-example
83 * This is an example TestCase.
84 */
86{
87 public:
88 /** Constructor. */
90 /** Destructor. */
91 ~SampleTestCase1() override;
92
93 private:
94 void DoRun() override;
95};
96
97/** Add some help text to this case to describe what it is intended to test. */
99 : TestCase("Sample test case (does nothing)")
100{
101}
102
103/**
104 * This destructor does nothing but we include it as a reminder that
105 * the test case should clean up after itself
106 */
108{
109}
110
111/**
112 * This method is the pure virtual method from class TestCase that every
113 * TestCase must implement
114 */
115void
117{
118 // A wide variety of test macros are available in src/core/test.h
119 NS_TEST_ASSERT_MSG_EQ(true, true, "true doesn't equal true for some reason");
120 // Use this one for floating point comparisons
121 NS_TEST_ASSERT_MSG_EQ_TOL(0.01, 0.01, 0.001, "Numbers are not equal within tolerance");
122}
123
124/**
125 * \ingroup testing-example
126 * The TestSuite class names the TestSuite, identifies what type of TestSuite,
127 * and enables the TestCases to be run. Typically, only the constructor for
128 * this class must be defined
129 */
131{
132 public:
133 /** Constructor. */
135};
136
138 : TestSuite("sample")
139{
141}
142
143// Do not forget to allocate an instance of this TestSuite
144/**
145 * \ingroup testing-example
146 * SampleTestSuite instance variable.
147 */
149
150} // namespace tests
151
152} // namespace ns3
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
This is an example TestCase.
~SampleTestCase1() override
Destructor.
void DoRun() override
This method is the pure virtual method from class TestCase that every TestCase must implement.
The TestSuite class names the TestSuite, identifies what type of TestSuite, and enables the TestCases...
static SampleTestSuite g_sampleTestSuite
SampleTestSuite instance variable.
#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:145
#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:338
Every class exported by the ns3 library is enclosed in the ns3 namespace.