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 
24 using namespace ns3;
25 
26 // ===========================================================================
27 // Test for the ability to get at a GlobalValue.
28 // ===========================================================================
30 {
31 public:
33  virtual ~GlobalValueTestCase () {}
34 
35 private:
36  virtual void DoRun (void);
37 };
38 
40  : TestCase ("Check GlobalValue mechanism")
41 {
42 }
43 
44 void
46 {
47  //
48  // Typically these are static globals but we can make one on the stack to
49  // keep it hidden from the documentation.
50  //
51  GlobalValue uint = GlobalValue ("TestUint", "help text",
52  UintegerValue (10),
53  MakeUintegerChecker<uint32_t> ());
54 
55  //
56  // Make sure we can get at the value and that it was initialized correctly.
57  //
58  UintegerValue uv;
59  uint.GetValue (uv);
60  NS_TEST_ASSERT_MSG_EQ (uv.Get (), 10, "GlobalValue \"TestUint\" not initialized as expected");
61 
62  //
63  // Remove the global value for a valgrind clean run
64  //
65  GlobalValue::Vector *vector = GlobalValue::GetVector ();
66  for (GlobalValue::Vector::iterator i = vector->begin (); i != vector->end (); ++i)
67  {
68  if ((*i) == &uint)
69  {
70  vector->erase (i);
71  break;
72  }
73  }
74 }
75 
76 // ===========================================================================
77 // The Test Suite that glues all of the Test Cases together.
78 // ===========================================================================
80 {
81 public:
83 };
84 
86  : TestSuite ("global-value", UNIT)
87 {
88  AddTestCase (new GlobalValueTestCase, TestCase::QUICK);
89 }
90 
static GlobalValueTestSuite globalValueTestSuite
A suite of tests to run.
Definition: test.h:1333
encapsulates test code
Definition: test.h:1147
Hold a so-called 'global value'.
Definition: global-value.h:70
virtual void DoRun(void)
Implementation to actually run this TestCase.
uint64_t Get(void) const
Definition: uinteger.cc:35
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
Hold an unsigned integer type.
Definition: uinteger.h:44
#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:161
std::vector< GlobalValue * > Vector
Container type for holding all the GlobalValues.
Definition: global-value.h:73
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void GetValue(AttributeValue &value) const
Get the value.