A Discrete-Event Network Simulator
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 
47 {
48 public:
53  {}
54 
55 private:
56  virtual void DoRun (void);
57 };
58 
60  : TestCase ("Check GlobalValue mechanism")
61 {}
62 
63 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  //
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 
100 {
101 public:
104 };
105 
107  : TestSuite ("global-value")
108 {
110 }
111 
117 
118 
119 } // namespace tests
120 
121 } // namespace ns3
122 
Hold a so-called 'global value'.
Definition: global-value.h:74
void GetValue(AttributeValue &value) const
Get the value.
std::vector< GlobalValue * > Vector
Container type for holding all the GlobalValues.
Definition: global-value.h:76
static Vector * GetVector(void)
Get the static vector of all GlobalValues.
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
Hold an unsigned integer type.
Definition: uinteger.h:44
uint64_t Get(void) const
Definition: uinteger.cc:35
Test for the ability to get at a GlobalValue.
virtual void DoRun(void)
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:141
Every class exported by the ns3 library is enclosed in the ns3 namespace.