A Discrete-Event Network Simulator
API
global-value-test-suite.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 INRIA
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  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 #include "ns3/global-value.h"
20 #include "ns3/test.h"
21 #include "ns3/uinteger.h"
22 
36 namespace ns3
37 {
38 
39 namespace tests
40 {
41 
47 {
48  public:
51 
54  {
55  }
56 
57  private:
58  void DoRun() override;
59 };
60 
62  : TestCase("Check GlobalValue mechanism")
63 {
64 }
65 
66 void
68 {
69  //
70  // Typically these are static globals but we can make one on the stack to
71  // keep it hidden from the documentation.
72  //
73  GlobalValue uint =
74  GlobalValue("TestUint", "help text", UintegerValue(10), MakeUintegerChecker<uint32_t>());
75 
76  //
77  // Make sure we can get at the value and that it was initialized correctly.
78  //
79  UintegerValue uv;
80  uint.GetValue(uv);
81  NS_TEST_ASSERT_MSG_EQ(uv.Get(), 10, "GlobalValue \"TestUint\" not initialized as expected");
82 
83  //
84  // Remove the global value for a valgrind clean run
85  //
87  for (auto i = vector->begin(); i != vector->end(); ++i)
88  {
89  if ((*i) == &uint)
90  {
91  vector->erase(i);
92  break;
93  }
94  }
95 }
96 
102 {
103  public:
106 };
107 
109  : TestSuite("global-value")
110 {
112 }
113 
119 
120 } // namespace tests
121 
122 } // namespace ns3
Hold a so-called 'global value'.
Definition: global-value.h:76
std::vector< GlobalValue * > Vector
Container type for holding all the GlobalValues.
Definition: global-value.h:78
void GetValue(AttributeValue &value) const
Get the value.
Definition: global-value.cc:98
static Vector * GetVector()
Get the static vector of all GlobalValues.
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
Hold an unsigned integer type.
Definition: uinteger.h:45
uint64_t Get() const
Definition: uinteger.cc:37
Test for the ability to get at a GlobalValue.
void DoRun() override
Implementation to actually run this TestCase.
The Test Suite that glues all of the Test Cases together.
static GlobalValueTestSuite g_globalValueTestSuite
GlobalValueTestSuite 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:144
Every class exported by the ns3 library is enclosed in the ns3 namespace.