A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
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
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#include "ns3/global-value.h"
21
#include "ns3/test.h"
22
#include "ns3/uinteger.h"
23
37
namespace
ns3
{
38
39
namespace
tests
{
40
41
46
class
GlobalValueTestCase
:
public
TestCase
47
{
48
public
:
50
GlobalValueTestCase
();
52
virtual
~GlobalValueTestCase
()
53
{}
54
55
private
:
56
virtual
void
DoRun
(
void
);
57
};
58
59
GlobalValueTestCase::GlobalValueTestCase
()
60
:
TestCase
(
"Check GlobalValue mechanism"
)
61
{}
62
63
void
64
GlobalValueTestCase::DoRun
(
void
)
65
{
66
//
67
// Typically these are static globals but we can make one on the stack to
68
// keep it hidden from the documentation.
69
//
70
GlobalValue
uint =
GlobalValue
(
"TestUint"
,
"help text"
,
71
UintegerValue
(10),
72
MakeUintegerChecker<uint32_t> ());
73
74
//
75
// Make sure we can get at the value and that it was initialized correctly.
76
//
77
UintegerValue
uv;
78
uint.
GetValue
(uv);
79
NS_TEST_ASSERT_MSG_EQ
(uv.
Get
(), 10,
"GlobalValue \"TestUint\" not initialized as expected"
);
80
81
//
82
// Remove the global value for a valgrind clean run
83
//
84
GlobalValue::Vector
*vector =
GlobalValue::GetVector
();
85
for
(GlobalValue::Vector::iterator i = vector->begin (); i != vector->end (); ++i)
86
{
87
if
((*i) == &uint)
88
{
89
vector->erase (i);
90
break
;
91
}
92
}
93
}
94
99
class
GlobalValueTestSuite
:
public
TestSuite
100
{
101
public
:
103
GlobalValueTestSuite
();
104
};
105
106
GlobalValueTestSuite::GlobalValueTestSuite
()
107
:
TestSuite
(
"global-value"
)
108
{
109
AddTestCase
(
new
GlobalValueTestCase
);
110
}
111
116
static
GlobalValueTestSuite
g_globalValueTestSuite
;
117
118
119
}
// namespace tests
120
121
}
// namespace ns3
122
ns3::GlobalValue
Hold a so-called 'global value'.
Definition:
global-value.h:74
ns3::GlobalValue::GetValue
void GetValue(AttributeValue &value) const
Get the value.
Definition:
global-value.cc:117
ns3::GlobalValue::Vector
std::vector< GlobalValue * > Vector
Container type for holding all the GlobalValues.
Definition:
global-value.h:76
ns3::GlobalValue::GetVector
static Vector * GetVector(void)
Get the static vector of all GlobalValues.
Definition:
global-value.cc:233
ns3::TestCase
encapsulates test code
Definition:
test.h:994
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1188
ns3::UintegerValue
Hold an unsigned integer type.
Definition:
uinteger.h:44
ns3::UintegerValue::Get
uint64_t Get(void) const
Definition:
uinteger.cc:35
ns3::tests::GlobalValueTestCase
Test for the ability to get at a GlobalValue.
Definition:
global-value-test-suite.cc:47
ns3::tests::GlobalValueTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
global-value-test-suite.cc:64
ns3::tests::GlobalValueTestCase::~GlobalValueTestCase
virtual ~GlobalValueTestCase()
Destructor.
Definition:
global-value-test-suite.cc:52
ns3::tests::GlobalValueTestCase::GlobalValueTestCase
GlobalValueTestCase()
Constructor.
Definition:
global-value-test-suite.cc:59
ns3::tests::GlobalValueTestSuite
The Test Suite that glues all of the Test Cases together.
Definition:
global-value-test-suite.cc:100
ns3::tests::GlobalValueTestSuite::GlobalValueTestSuite
GlobalValueTestSuite()
Constructor.
Definition:
global-value-test-suite.cc:106
ns3::tests::g_globalValueTestSuite
static GlobalValueTestSuite g_globalValueTestSuite
GlobalValueTestSuite instance variable.
Definition:
global-value-test-suite.cc:116
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:141
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
test-ns3.tests
tests
Definition:
test-ns3.py:2134
src
core
test
global-value-test-suite.cc
Generated on Tue Feb 6 2024 19:21:17 for ns-3 by
1.9.1