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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8// An essential include is test.h
9#include "ns3/test.h"
10
11/**
12 * \file
13 * \ingroup core-tests
14 * \ingroup testing
15 * \ingroup testing-example
16 *
17 * Example use of TestSuite.
18 *
19 * Assume this is the test suite for `class Class`
20 * in module 'module'.
21 *
22 * Document the file as follows. (Note: for purposes of this
23 * illustration Doxygen comments are set off with triple `\\\\\\';
24 * you should use the normal Javadoc format. )
25 *
26 * Add it to the groups module-tests and class-tests:
27 *
28 * \verbatim /// \file
29/// \ingroup module-tests
30/// \ingroup class-tests
31/// Class test suite. \endverbatim
32 *
33 * Define the class-tests group:
34 * \verbatim /// \ingroup module-tests
35/// \defgroup class-tests Class test suite \endverbatim
36 *
37 * Make sure test.h is included:
38 * \verbatim #include "ns3/test.h" \endverbatim
39 *
40 * Put the test code in namespace ns3::tests.
41 * \verbatim namespace ns3 {
42 namespace tests { \endverbatim
43 *
44 * Write your test cases and final test suite, and put them in
45 * your test group:
46 * \verbatim /// \ingroup class-tests
47class ClassTestSuite : public TestSuite {...}; \endverbatim
48 *
49 * Create a static variable to hold the instance of your test suite:
50 * \verbatim /// \ingroup class-tests
51/// ClassTestSuite instance variable.
52static ClassTestSuite g_classTestSuite; \endverbatim
53 *
54 * Finally, close the ingroup and namespace blocks:
55 * \verbatim } // namespace tests
56} // namespace ns3 \endverbatim
57*/
58
59/**
60 * \ingroup core-tests
61 * \defgroup testing-example Example use of TestSuite
62 */
63
64namespace ns3
65{
66
67namespace tests
68{
69
70/**
71 * \ingroup testing-example
72 * This is an example TestCase.
73 */
75{
76 public:
77 /** Constructor. */
79 /** Destructor. */
80 ~SampleTestCase1() override;
81
82 private:
83 void DoRun() override;
84};
85
86/** Add some help text to this case to describe what it is intended to test. */
88 : TestCase("Sample test case (does nothing)")
89{
90}
91
92/**
93 * This destructor does nothing but we include it as a reminder that
94 * the test case should clean up after itself
95 */
99
100/**
101 * This method is the pure virtual method from class TestCase that every
102 * TestCase must implement
103 */
104void
106{
107 // A wide variety of test macros are available in src/core/test.h
108 NS_TEST_ASSERT_MSG_EQ(true, true, "true doesn't equal true for some reason");
109 // Use this one for floating point comparisons
110 NS_TEST_ASSERT_MSG_EQ_TOL(0.01, 0.01, 0.001, "Numbers are not equal within tolerance");
111}
112
113/**
114 * \ingroup testing-example
115 * The TestSuite class names the TestSuite, identifies what type of TestSuite,
116 * and enables the TestCases to be run. Typically, only the constructor for
117 * this class must be defined
118 */
120{
121 public:
122 /** Constructor. */
124};
125
131
132// Do not forget to allocate an instance of this TestSuite
133/**
134 * \ingroup testing-example
135 * SampleTestSuite instance variable.
136 */
138
139} // namespace tests
140
141} // namespace ns3
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
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:134
#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:327
Every class exported by the ns3 library is enclosed in the ns3 namespace.