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 
43 {
45  Vector pos;
46  bool indoor;
47  uint32_t bid;
48  uint16_t rx;
49  uint16_t ry;
50  uint16_t fn;
51 };
52 
54  : pos (0,0,0),
55  indoor (false),
56  bid (0xffffffff),
57  rx (0),
58  ry (0),
59  fn (0)
60 {
61 }
62 
74 {
75  BuildingData ();
76  double xmin;
77  double xmax;
78  double ymin;
79  double ymax;
80  double zmin;
81  double zmax;
82  uint16_t nrx;
83  uint16_t nry;
84  uint16_t nf;
85 };
86 
88  : xmin (0),
89  xmax (0),
90  ymin (0),
91  ymax (0),
92  zmin (0),
93  zmax (0),
94  nrx (0),
95  nry (0),
96  nf (0)
97 {
98 }
99 
107 {
108 public:
115  static std::string BuildNameString (PositionInBuilding pib, BuildingData bd);
116 
123 
124 private:
125  virtual void DoRun (void);
126 
129 
130 };
131 
133 {
134  std::ostringstream oss;
135  oss << "pos=" << pib.pos;
136  if (pib.indoor)
137  {
138  oss << ", bid=" << pib.bid
139  << ", rx=" << pib.rx
140  << ", ry=" << pib.ry
141  << ", fn=" << pib.fn;
142  }
143  else
144  {
145  oss << ", outdoor";
146  }
147  return oss.str ();
148 }
149 
150 
152  : TestCase (BuildNameString (pib, bd)),
153  m_pib (pib),
154  m_bd (bd)
155 {
156 }
157 
158 void
160 {
163  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
164 
166  nodes.Create (1);
167  mobility.Install (nodes);
168 
170  bmm->SetPosition (m_pib.pos);
171 
172  NS_LOG_LOGIC ("create building");
173  Ptr<Building> b = CreateObject<Building> ();
174  b->SetBoundaries (Box (m_bd.xmin, m_bd.xmax, m_bd.ymin, m_bd.ymax, m_bd.zmin, m_bd.zmax));
175  b->SetNFloors (m_bd.nf);
176  b->SetNRoomsX (m_bd.nrx);
177  b->SetNRoomsY (m_bd.nry);
178  Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> (b);
179  bmm->AggregateObject (buildingInfo); // operation usually done by BuildingsHelper::Install
180 
181 
182  NS_TEST_ASSERT_MSG_EQ (buildingInfo->IsIndoor (), m_pib.indoor, "indoor/outdoor mismatch");
183  if (m_pib.indoor)
184  {
185  NS_LOG_LOGIC (" got bid=" << buildingInfo->GetBuilding ()->GetId () << ", f=" << (uint32_t) buildingInfo->GetFloorNumber () << ", rx=" << (uint32_t) buildingInfo->GetRoomNumberX () << ", roomY=" << (uint32_t) buildingInfo->GetRoomNumberY ());
186  // only one building in this test, so Id will be 0
187  NS_TEST_ASSERT_MSG_EQ (buildingInfo->GetBuilding ()->GetId (), 0, "Building ID mismatch");
188  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetFloorNumber (), m_pib.fn, "floor number mismatch");
189  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberX (), m_pib.rx, "x room number mismatch");
190  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberY (), m_pib.ry, "y room number mismatch");
191  }
192 
193  Simulator::Destroy ();
194 }
195 
196 
204 {
205 public:
207 };
208 
209 
211  : TestSuite ("buildings-helper", UNIT)
212 {
213  NS_LOG_FUNCTION (this);
214 
215  BuildingData b1;
216  b1.xmin = 1;
217  b1.xmax = 3;
218  b1.ymin = 1;
219  b1.ymax = 2;
220  b1.zmin = 0;
221  b1.zmax = 4;
222  b1.nrx = 1;
223  b1.nry = 1;
224  b1.nf = 1;
225 
226  Vector vp1 (1.5, 1.5, 0.5);
228  p1.pos = vp1;
229  p1.indoor = true;
230  p1.bid = 0;
231  p1.rx = 1;
232  p1.ry = 1;
233  p1.fn = 1;
234  AddTestCase (new BuildingsHelperOneTestCase (p1, b1), TestCase::QUICK);
235 
236  Vector vp2 (1.5, 0.5, 0.5);
238  p2.pos = vp2;
239  p2.indoor = false;
240  AddTestCase (new BuildingsHelperOneTestCase (p2, b1), TestCase::QUICK);
241 
242  Vector vp3 (1.5, 2.5, 0.5);
244  p3.pos = vp3;
245  p3.indoor = false;
246  AddTestCase (new BuildingsHelperOneTestCase (p3, b1), TestCase::QUICK);
247 
248  Vector vp4 (1.5, 1.5, 5);
250  p4.pos = vp4;
251  p4.indoor = false;
252  AddTestCase (new BuildingsHelperOneTestCase (p4, b1), TestCase::QUICK);
253 
254  Vector vp5 (2.5, 1.6, 3.5);
256  p5.pos = vp5;
257  p5.indoor = true;
258  p5.bid = 0;
259  p5.rx = 1;
260  p5.ry = 1;
261  p5.fn = 1;
262  AddTestCase (new BuildingsHelperOneTestCase (p5, b1), TestCase::QUICK);
263 
264  Vector vp6 (0.9999, 1.5, 1.5);
266  p6.pos = vp6;
267  p6.indoor = false;
268  AddTestCase (new BuildingsHelperOneTestCase (p6, b1), TestCase::QUICK);
269 
270  Vector vp7 (3.0001, 1.5, 2.5);
272  p7.pos = vp7;
273  p7.indoor = false;
274  AddTestCase (new BuildingsHelperOneTestCase (p7, b1), TestCase::QUICK);
275 
276  Vector vp8 (1.001, 1.001, -0.01);
278  p8.pos = vp8;
279  p8.indoor = false;
280  AddTestCase (new BuildingsHelperOneTestCase (p8, b1), TestCase::QUICK);
281 
282  Vector vp9 (1.5, 1.5, 4.001);
284  p9.pos = vp9;
285  p9.indoor = false;
286  AddTestCase (new BuildingsHelperOneTestCase (p9, b1), TestCase::QUICK);
287 
288 
289 
290 
291  BuildingData b2;
292  b2.xmin = -1;
293  b2.xmax = 0.5;
294  b2.ymin = -2;
295  b2.ymax = 0.5;
296  b2.zmin = 0;
297  b2.zmax = 2;
298  b2.nrx = 3;
299  b2.nry = 5;
300  b2.nf = 4;
301 
302  Vector vq1 (-0.7, -1.1, 1.2);
304  q1.pos = vq1;
305  q1.indoor = true;
306  q1.bid = 1;
307  q1.rx = 1;
308  q1.ry = 2;
309  q1.fn = 3;
310  AddTestCase (new BuildingsHelperOneTestCase (q1, b2), TestCase::QUICK);
311 
312  Vector vq2 (0.2, 0.3, 0.2);
314  q2.pos = vq2;
315  q2.indoor = true;
316  q2.bid = 1;
317  q2.rx = 3;
318  q2.ry = 5;
319  q2.fn = 1;
320  AddTestCase (new BuildingsHelperOneTestCase (q2, b2), TestCase::QUICK);
321 
322  Vector vq3 (0.6, -1.75, 1.5);
324  q3.pos = vq3;
325  q3.indoor = false;
326  AddTestCase (new BuildingsHelperOneTestCase (q3, b2), TestCase::QUICK);
327 
328  Vector vq4 (-1.01, 0.3, 1.99);
330  q4.pos = vq4;
331  q4.indoor = false;
332  AddTestCase (new BuildingsHelperOneTestCase (q4, b2), TestCase::QUICK);
333 
334  Vector vq5 (-0.8, 0.7, 0.01);
336  q5.pos = vq5;
337  q5.indoor = false;
338  AddTestCase (new BuildingsHelperOneTestCase (q5, b2), TestCase::QUICK);
339 
340  Vector vq6 (0.2, 0.3, -0.2);
342  q6.pos = vq6;
343  q6.indoor = false;
344  AddTestCase (new BuildingsHelperOneTestCase (q6, b2), TestCase::QUICK);
345 
346  Vector vq7 (0.2, 0.3, 2.001);
348  q7.pos = vq7;
349  q7.indoor = false;
350  AddTestCase (new BuildingsHelperOneTestCase (q7, b2), TestCase::QUICK);
351 }
352 
static BuildingsHelperTestSuite buildingsHelperAntennaTestSuiteInstance
Static variable for test initialization.
BuildingData m_bd
Building data.
virtual void DoRun(void)
Implementation to actually run this TestCase.
static std::string BuildNameString(PositionInBuilding pib, BuildingData bd)
Build the testcase name.
PositionInBuilding m_pib
Position in the building.
BuildingsHelperOneTestCase(PositionInBuilding pib, BuildingData bd)
Constructor.
BuildingsHelper TestSuite.
a 3d box
Definition: box.h:35
Mobility model for which the current position does not change once it has been set and until it is se...
Helper class used to assign positions and mobility models to nodes.
keep track of a set of node pointers.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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
nodes
Definition: first.py:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mobility
Definition: third.py:108
Data to construct a Building object.
double xmin
X min coordinate.
double ymin
Y min coordinate.
double zmin
Z min coordinate.
uint16_t nrx
Number of rooms (X coord)
uint16_t nry
Number of rooms (Y coord)
double zmax
Z max coordinate.
uint16_t nf
Number of floors.
double ymax
Y max coordinate.
double xmax
X max coordinate.
Struct representing a position in a building.
uint32_t bid
building id
bool indoor
true if indoor, false otherwise
Vector pos
coordinates of the mobility model instance
uint16_t fn
floor number