A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
46
class
GlobalValueTestCase
:
public
TestCase
47
{
48
public
:
50
GlobalValueTestCase
();
51
53
~GlobalValueTestCase
()
override
54
{
55
}
56
57
private
:
58
void
DoRun
()
override
;
59
};
60
61
GlobalValueTestCase::GlobalValueTestCase
()
62
:
TestCase
(
"Check GlobalValue mechanism"
)
63
{
64
}
65
66
void
67
GlobalValueTestCase::DoRun
()
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
//
86
GlobalValue::Vector
* vector =
GlobalValue::GetVector
();
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
101
class
GlobalValueTestSuite
:
public
TestSuite
102
{
103
public
:
105
GlobalValueTestSuite
();
106
};
107
108
GlobalValueTestSuite::GlobalValueTestSuite
()
109
:
TestSuite
(
"global-value"
)
110
{
111
AddTestCase
(
new
GlobalValueTestCase
);
112
}
113
118
static
GlobalValueTestSuite
g_globalValueTestSuite
;
119
120
}
// namespace tests
121
122
}
// namespace ns3
ns3::GlobalValue
Hold a so-called 'global value'.
Definition:
global-value.h:76
ns3::GlobalValue::Vector
std::vector< GlobalValue * > Vector
Container type for holding all the GlobalValues.
Definition:
global-value.h:78
ns3::GlobalValue::GetValue
void GetValue(AttributeValue &value) const
Get the value.
Definition:
global-value.cc:98
ns3::GlobalValue::GetVector
static Vector * GetVector()
Get the static vector of all GlobalValues.
Definition:
global-value.cc:218
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
ns3::UintegerValue
Hold an unsigned integer type.
Definition:
uinteger.h:45
ns3::UintegerValue::Get
uint64_t Get() const
Definition:
uinteger.cc:37
ns3::tests::GlobalValueTestCase
Test for the ability to get at a GlobalValue.
Definition:
global-value-test-suite.cc:47
ns3::tests::GlobalValueTestCase::GlobalValueTestCase
GlobalValueTestCase()
Constructor.
Definition:
global-value-test-suite.cc:61
ns3::tests::GlobalValueTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
global-value-test-suite.cc:67
ns3::tests::GlobalValueTestCase::~GlobalValueTestCase
~GlobalValueTestCase() override
Destructor.
Definition:
global-value-test-suite.cc:53
ns3::tests::GlobalValueTestSuite
The Test Suite that glues all of the Test Cases together.
Definition:
global-value-test-suite.cc:102
ns3::tests::GlobalValueTestSuite::GlobalValueTestSuite
GlobalValueTestSuite()
Constructor.
Definition:
global-value-test-suite.cc:108
ns3::tests::g_globalValueTestSuite
static GlobalValueTestSuite g_globalValueTestSuite
GlobalValueTestSuite instance variable.
Definition:
global-value-test-suite.cc:118
NS_TEST_ASSERT_MSG_EQ
#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
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
test
global-value-test-suite.cc
Generated on Sun Mar 3 2024 17:10:56 for ns-3 by
1.9.1