A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
global-value-test-suite.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#include "ns3/global-value.h"
9#include "ns3/test.h"
10#include "ns3/uinteger.h"
11
12/**
13 * @file
14 * @ingroup core
15 * @ingroup core-tests
16 * @ingroup global-value-tests
17 * GlobalValue test suite
18 */
19
20/**
21 * @ingroup core-tests
22 * @defgroup global-value-tests GlobalValue test suite
23 */
24
25namespace ns3
26{
27
28namespace tests
29{
30
31/**
32 * @ingroup global-value-tests
33 * Test for the ability to get at a GlobalValue.
34 */
36{
37 public:
38 /** Constructor. */
40
41 /** Destructor. */
43 {
44 }
45
46 private:
47 void DoRun() override;
48};
49
51 : TestCase("Check GlobalValue mechanism")
52{
53}
54
55void
57{
58 //
59 // Typically these are static globals but we can make one on the stack to
60 // keep it hidden from the documentation.
61 //
62 GlobalValue uint =
63 GlobalValue("TestUint", "help text", UintegerValue(10), MakeUintegerChecker<uint32_t>());
64
65 //
66 // Make sure we can get at the value and that it was initialized correctly.
67 //
69 uint.GetValue(uv);
70 NS_TEST_ASSERT_MSG_EQ(uv.Get(), 10, "GlobalValue \"TestUint\" not initialized as expected");
71
72 //
73 // Remove the global value for a valgrind clean run
74 //
76 for (auto i = vector->begin(); i != vector->end(); ++i)
77 {
78 if ((*i) == &uint)
79 {
80 vector->erase(i);
81 break;
82 }
83 }
84}
85
86/**
87 * @ingroup global-value-tests
88 * The Test Suite that glues all of the Test Cases together.
89 */
91{
92 public:
93 /** Constructor. */
95};
96
102
103/**
104 * @ingroup global-value-tests
105 * GlobalValueTestSuite instance variable.
106 */
108
109} // namespace tests
110
111} // namespace ns3
Hold a so-called 'global value'.
std::vector< GlobalValue * > Vector
Container type for holding all the GlobalValues.
void GetValue(AttributeValue &value) const
Get the value.
static Vector * GetVector()
Get the static vector of all GlobalValues.
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
Hold an unsigned integer type.
Definition uinteger.h:34
uint64_t Get() const
Definition uinteger.cc:26
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.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
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:134
Every class exported by the ns3 library is enclosed in the ns3 namespace.