A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
25
namespace
ns3
26
{
27
28
namespace
tests
29
{
30
31
/**
32
* \ingroup global-value-tests
33
* Test for the ability to get at a GlobalValue.
34
*/
35
class
GlobalValueTestCase
:
public
TestCase
36
{
37
public
:
38
/** Constructor. */
39
GlobalValueTestCase
();
40
41
/** Destructor. */
42
~GlobalValueTestCase
()
override
43
{
44
}
45
46
private
:
47
void
DoRun
()
override
;
48
};
49
50
GlobalValueTestCase::GlobalValueTestCase
()
51
:
TestCase
(
"Check GlobalValue mechanism"
)
52
{
53
}
54
55
void
56
GlobalValueTestCase::DoRun
()
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
//
68
UintegerValue
uv;
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
//
75
GlobalValue::Vector
* vector =
GlobalValue::GetVector
();
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
*/
90
class
GlobalValueTestSuite
:
public
TestSuite
91
{
92
public
:
93
/** Constructor. */
94
GlobalValueTestSuite
();
95
};
96
97
GlobalValueTestSuite::GlobalValueTestSuite
()
98
:
TestSuite
(
"global-value"
)
99
{
100
AddTestCase
(
new
GlobalValueTestCase
);
101
}
102
103
/**
104
* \ingroup global-value-tests
105
* GlobalValueTestSuite instance variable.
106
*/
107
static
GlobalValueTestSuite
g_globalValueTestSuite
;
108
109
}
// namespace tests
110
111
}
// namespace ns3
ns3::GlobalValue
Hold a so-called 'global value'.
Definition
global-value.h:65
ns3::GlobalValue::Vector
std::vector< GlobalValue * > Vector
Container type for holding all the GlobalValues.
Definition
global-value.h:67
ns3::GlobalValue::GetValue
void GetValue(AttributeValue &value) const
Get the value.
Definition
global-value.cc:87
ns3::GlobalValue::GetVector
static Vector * GetVector()
Get the static vector of all GlobalValues.
Definition
global-value.cc:207
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::UintegerValue
Hold an unsigned integer type.
Definition
uinteger.h:34
ns3::UintegerValue::Get
uint64_t Get() const
Definition
uinteger.cc:26
ns3::tests::GlobalValueTestCase
Test for the ability to get at a GlobalValue.
Definition
global-value-test-suite.cc:36
ns3::tests::GlobalValueTestCase::GlobalValueTestCase
GlobalValueTestCase()
Constructor.
Definition
global-value-test-suite.cc:50
ns3::tests::GlobalValueTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
global-value-test-suite.cc:56
ns3::tests::GlobalValueTestCase::~GlobalValueTestCase
~GlobalValueTestCase() override
Destructor.
Definition
global-value-test-suite.cc:42
ns3::tests::GlobalValueTestSuite
The Test Suite that glues all of the Test Cases together.
Definition
global-value-test-suite.cc:91
ns3::tests::GlobalValueTestSuite::GlobalValueTestSuite
GlobalValueTestSuite()
Constructor.
Definition
global-value-test-suite.cc:97
ns3::tests::g_globalValueTestSuite
static GlobalValueTestSuite g_globalValueTestSuite
GlobalValueTestSuite instance variable.
Definition
global-value-test-suite.cc:107
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:134
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::MakeUintegerChecker
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition
uinteger.h:85
src
core
test
global-value-test-suite.cc
Generated on Fri Nov 8 2024 13:59:00 for ns-3 by
1.11.0