A Discrete-Event Network Simulator
API
buildings-helper-test.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011, 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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  * Author: Nicola Baldo <nbaldo@cttc.es>
19  */
20 
21 
22 
23 #include "ns3/log.h"
24 #include "ns3/test.h"
25 #include <ns3/mobility-building-info.h>
26 #include <ns3/constant-position-mobility-model.h>
27 #include <ns3/building.h>
28 #include <ns3/buildings-helper.h>
29 #include <ns3/mobility-helper.h>
30 #include <ns3/simulator.h>
31 
32 using namespace ns3;
33 
34 NS_LOG_COMPONENT_DEFINE ("BuildingsHelperTest");
35 
37 {
39  Vector pos; // coordinates of the mobility model instance
40  bool indoor; // true if indoor, false otherwise
41  uint32_t bid; // building id
42  uint16_t rx; // room x
43  uint16_t ry; // room y
44  uint16_t fn; // floor number
45 };
46 
48  : pos (0,0,0),
49  indoor (false),
50  bid (0xffffffff),
51  rx (0),
52  ry (0),
53  fn (0)
54 {
55 }
56 
65 {
66  BuildingData ();
67  double xmin;
68  double xmax;
69  double ymin;
70  double ymax;
71  double zmin;
72  double zmax;
73  uint16_t nrx;
74  uint16_t nry;
75  uint16_t nf;
76 };
77 
79  : xmin (0),
80  xmax (0),
81  ymin (0),
82  ymax (0),
83  zmin (0),
84  zmax (0),
85  nrx (0),
86  nry (0),
87  nf (0)
88 {
89 }
90 
92 {
93 public:
94  static std::string BuildNameString (PositionInBuilding pib, BuildingData bd);
96 
97 private:
98  virtual void DoRun (void);
99 
102 
103 };
104 
106 {
107  std::ostringstream oss;
108  oss << "pos=" << pib.pos;
109  if (pib.indoor)
110  {
111  oss << ", bid=" << pib.bid
112  << ", rx=" << pib.rx
113  << ", ry=" << pib.ry
114  << ", fn=" << pib.fn;
115  }
116  else
117  {
118  oss << ", outdoor";
119  }
120  return oss.str ();
121 }
122 
123 
125  : TestCase (BuildNameString (pib, bd)),
126  m_pib (pib),
127  m_bd (bd)
128 {
129 }
130 
131 void
133 {
136  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
137 
139  nodes.Create (1);
140  mobility.Install (nodes);
141 
143  bmm->SetPosition (m_pib.pos);
144 
145  NS_LOG_LOGIC ("create building");
146  Ptr<Building> b = CreateObject<Building> ();
148  b->SetNFloors (m_bd.nf);
149  b->SetNRoomsX (m_bd.nrx);
150  b->SetNRoomsY (m_bd.nry);
151  Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> (b);
152  bmm->AggregateObject (buildingInfo); // operation usually done by BuildingsHelper::Install
153  BuildingsHelper::MakeMobilityModelConsistent ();
154 
155 
156  NS_TEST_ASSERT_MSG_EQ (buildingInfo->IsIndoor (), m_pib.indoor, "indoor/outdoor mismatch");
157  if (m_pib.indoor)
158  {
159  NS_LOG_LOGIC (" got bid=" << buildingInfo->GetBuilding ()->GetId () << ", f=" << (uint32_t) buildingInfo->GetFloorNumber () << ", rx=" << (uint32_t) buildingInfo->GetRoomNumberX () << ", roomY=" << (uint32_t) buildingInfo->GetRoomNumberY ());
160  // only one building in this test, so Id will be 0
161  NS_TEST_ASSERT_MSG_EQ (buildingInfo->GetBuilding ()->GetId (), 0, "Building ID mismatch");
162  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetFloorNumber (), m_pib.fn, "floor number mismatch");
163  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberX (), m_pib.rx, "x room number mismatch");
164  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberY (), m_pib.ry, "y room number mismatch");
165  }
166 
167  Simulator::Destroy ();
168 }
169 
170 
171 
172 
173 
174 
175 
177 {
178 public:
180 };
181 
182 
184  : TestSuite ("buildings-helper", UNIT)
185 {
186  NS_LOG_FUNCTION (this);
187 
188  BuildingData b1;
189  b1.xmin = 1;
190  b1.xmax = 3;
191  b1.ymin = 1;
192  b1.ymax = 2;
193  b1.zmin = 0;
194  b1.zmax = 4;
195  b1.nrx = 1;
196  b1.nry = 1;
197  b1.nf = 1;
198 
199  Vector vp1 (1.5, 1.5, 0.5);
201  p1.pos = vp1;
202  p1.indoor = true;
203  p1.bid = 0;
204  p1.rx = 1;
205  p1.ry = 1;
206  p1.fn = 1;
207  AddTestCase (new BuildingsHelperOneTestCase (p1, b1), TestCase::QUICK);
208 
209  Vector vp2 (1.5, 0.5, 0.5);
211  p2.pos = vp2;
212  p2.indoor = false;
213  AddTestCase (new BuildingsHelperOneTestCase (p2, b1), TestCase::QUICK);
214 
215  Vector vp3 (1.5, 2.5, 0.5);
217  p3.pos = vp3;
218  p3.indoor = false;
219  AddTestCase (new BuildingsHelperOneTestCase (p3, b1), TestCase::QUICK);
220 
221  Vector vp4 (1.5, 1.5, 5);
223  p4.pos = vp4;
224  p4.indoor = false;
225  AddTestCase (new BuildingsHelperOneTestCase (p4, b1), TestCase::QUICK);
226 
227  Vector vp5 (2.5, 1.6, 3.5);
229  p5.pos = vp5;
230  p5.indoor = true;
231  p5.bid = 0;
232  p5.rx = 1;
233  p5.ry = 1;
234  p5.fn = 1;
235  AddTestCase (new BuildingsHelperOneTestCase (p5, b1), TestCase::QUICK);
236 
237  Vector vp6 (0.9999, 1.5, 1.5);
239  p6.pos = vp6;
240  p6.indoor = false;
241  AddTestCase (new BuildingsHelperOneTestCase (p6, b1), TestCase::QUICK);
242 
243  Vector vp7 (3.0001, 1.5, 2.5);
245  p7.pos = vp7;
246  p7.indoor = false;
247  AddTestCase (new BuildingsHelperOneTestCase (p7, b1), TestCase::QUICK);
248 
249  Vector vp8 (1.001, 1.001, -0.01);
251  p8.pos = vp8;
252  p8.indoor = false;
253  AddTestCase (new BuildingsHelperOneTestCase (p8, b1), TestCase::QUICK);
254 
255  Vector vp9 (1.5, 1.5, 4.001);
257  p9.pos = vp9;
258  p9.indoor = false;
259  AddTestCase (new BuildingsHelperOneTestCase (p9, b1), TestCase::QUICK);
260 
261 
262 
263 
264  BuildingData b2;
265  b2.xmin = -1;
266  b2.xmax = 0.5;
267  b2.ymin = -2;
268  b2.ymax = 0.5;
269  b2.zmin = 0;
270  b2.zmax = 2;
271  b2.nrx = 3;
272  b2.nry = 5;
273  b2.nf = 4;
274 
275  Vector vq1 (-0.7, -1.1, 1.2);
277  q1.pos = vq1;
278  q1.indoor = true;
279  q1.bid = 1;
280  q1.rx = 1;
281  q1.ry = 2;
282  q1.fn = 3;
283  AddTestCase (new BuildingsHelperOneTestCase (q1, b2), TestCase::QUICK);
284 
285  Vector vq2 (0.2, 0.3, 0.2);
287  q2.pos = vq2;
288  q2.indoor = true;
289  q2.bid = 1;
290  q2.rx = 3;
291  q2.ry = 5;
292  q2.fn = 1;
293  AddTestCase (new BuildingsHelperOneTestCase (q2, b2), TestCase::QUICK);
294 
295  Vector vq3 (0.6, -1.75, 1.5);
297  q3.pos = vq3;
298  q3.indoor = false;
299  AddTestCase (new BuildingsHelperOneTestCase (q3, b2), TestCase::QUICK);
300 
301  Vector vq4 (-1.01, 0.3, 1.99);
303  q4.pos = vq4;
304  q4.indoor = false;
305  AddTestCase (new BuildingsHelperOneTestCase (q4, b2), TestCase::QUICK);
306 
307  Vector vq5 (-0.8, 0.7, 0.01);
309  q5.pos = vq5;
310  q5.indoor = false;
311  AddTestCase (new BuildingsHelperOneTestCase (q5, b2), TestCase::QUICK);
312 
313  Vector vq6 (0.2, 0.3, -0.2);
315  q6.pos = vq6;
316  q6.indoor = false;
317  AddTestCase (new BuildingsHelperOneTestCase (q6, b2), TestCase::QUICK);
318 
319  Vector vq7 (0.2, 0.3, 2.001);
321  q7.pos = vq7;
322  q7.indoor = false;
323  AddTestCase (new BuildingsHelperOneTestCase (q7, b2), TestCase::QUICK);
324 }
325 
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetNRoomsY(uint16_t nroomy)
Definition: building.cc:174
static BuildingsHelperTestSuite buildingsHelperAntennaTestSuiteInstance
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
A suite of tests to run.
Definition: test.h:1342
virtual void DoRun(void)
Implementation to actually run this TestCase.
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
Mobility model for which the current position does not change once it has been set and until it is se...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
encapsulates test code
Definition: test.h:1155
a 3d box
Definition: box.h:34
tuple nodes
Definition: first.py:25
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple mobility
Definition: third.py:101
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
void SetNFloors(uint16_t nfloors)
Definition: building.cc:160
#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:168
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void SetPosition(const Vector &position)
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
data to construct a Building object.
Helper class used to assign positions and mobility models to nodes.
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
static std::string BuildNameString(PositionInBuilding pib, BuildingData bd)
void SetNRoomsX(uint16_t nroomx)
Definition: building.cc:167
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
BuildingsHelperOneTestCase(PositionInBuilding pib, BuildingData bd)
void SetBoundaries(Box box)
Set the boundaries of the building.
Definition: building.cc:139