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> ();
147  b->SetBoundaries (Box (m_bd.xmin, m_bd.xmax, m_bd.ymin, m_bd.ymax, m_bd.zmin, m_bd.zmax));
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 
154 
155  NS_TEST_ASSERT_MSG_EQ (buildingInfo->IsIndoor (), m_pib.indoor, "indoor/outdoor mismatch");
156  if (m_pib.indoor)
157  {
158  NS_LOG_LOGIC (" got bid=" << buildingInfo->GetBuilding ()->GetId () << ", f=" << (uint32_t) buildingInfo->GetFloorNumber () << ", rx=" << (uint32_t) buildingInfo->GetRoomNumberX () << ", roomY=" << (uint32_t) buildingInfo->GetRoomNumberY ());
159  // only one building in this test, so Id will be 0
160  NS_TEST_ASSERT_MSG_EQ (buildingInfo->GetBuilding ()->GetId (), 0, "Building ID mismatch");
161  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetFloorNumber (), m_pib.fn, "floor number mismatch");
162  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberX (), m_pib.rx, "x room number mismatch");
163  NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberY (), m_pib.ry, "y room number mismatch");
164  }
165 
166  Simulator::Destroy ();
167 }
168 
169 
170 
171 
172 
173 
174 
176 {
177 public:
179 };
180 
181 
183  : TestSuite ("buildings-helper", UNIT)
184 {
185  NS_LOG_FUNCTION (this);
186 
187  BuildingData b1;
188  b1.xmin = 1;
189  b1.xmax = 3;
190  b1.ymin = 1;
191  b1.ymax = 2;
192  b1.zmin = 0;
193  b1.zmax = 4;
194  b1.nrx = 1;
195  b1.nry = 1;
196  b1.nf = 1;
197 
198  Vector vp1 (1.5, 1.5, 0.5);
200  p1.pos = vp1;
201  p1.indoor = true;
202  p1.bid = 0;
203  p1.rx = 1;
204  p1.ry = 1;
205  p1.fn = 1;
206  AddTestCase (new BuildingsHelperOneTestCase (p1, b1), TestCase::QUICK);
207 
208  Vector vp2 (1.5, 0.5, 0.5);
210  p2.pos = vp2;
211  p2.indoor = false;
212  AddTestCase (new BuildingsHelperOneTestCase (p2, b1), TestCase::QUICK);
213 
214  Vector vp3 (1.5, 2.5, 0.5);
216  p3.pos = vp3;
217  p3.indoor = false;
218  AddTestCase (new BuildingsHelperOneTestCase (p3, b1), TestCase::QUICK);
219 
220  Vector vp4 (1.5, 1.5, 5);
222  p4.pos = vp4;
223  p4.indoor = false;
224  AddTestCase (new BuildingsHelperOneTestCase (p4, b1), TestCase::QUICK);
225 
226  Vector vp5 (2.5, 1.6, 3.5);
228  p5.pos = vp5;
229  p5.indoor = true;
230  p5.bid = 0;
231  p5.rx = 1;
232  p5.ry = 1;
233  p5.fn = 1;
234  AddTestCase (new BuildingsHelperOneTestCase (p5, b1), TestCase::QUICK);
235 
236  Vector vp6 (0.9999, 1.5, 1.5);
238  p6.pos = vp6;
239  p6.indoor = false;
240  AddTestCase (new BuildingsHelperOneTestCase (p6, b1), TestCase::QUICK);
241 
242  Vector vp7 (3.0001, 1.5, 2.5);
244  p7.pos = vp7;
245  p7.indoor = false;
246  AddTestCase (new BuildingsHelperOneTestCase (p7, b1), TestCase::QUICK);
247 
248  Vector vp8 (1.001, 1.001, -0.01);
250  p8.pos = vp8;
251  p8.indoor = false;
252  AddTestCase (new BuildingsHelperOneTestCase (p8, b1), TestCase::QUICK);
253 
254  Vector vp9 (1.5, 1.5, 4.001);
256  p9.pos = vp9;
257  p9.indoor = false;
258  AddTestCase (new BuildingsHelperOneTestCase (p9, b1), TestCase::QUICK);
259 
260 
261 
262 
263  BuildingData b2;
264  b2.xmin = -1;
265  b2.xmax = 0.5;
266  b2.ymin = -2;
267  b2.ymax = 0.5;
268  b2.zmin = 0;
269  b2.zmax = 2;
270  b2.nrx = 3;
271  b2.nry = 5;
272  b2.nf = 4;
273 
274  Vector vq1 (-0.7, -1.1, 1.2);
276  q1.pos = vq1;
277  q1.indoor = true;
278  q1.bid = 1;
279  q1.rx = 1;
280  q1.ry = 2;
281  q1.fn = 3;
282  AddTestCase (new BuildingsHelperOneTestCase (q1, b2), TestCase::QUICK);
283 
284  Vector vq2 (0.2, 0.3, 0.2);
286  q2.pos = vq2;
287  q2.indoor = true;
288  q2.bid = 1;
289  q2.rx = 3;
290  q2.ry = 5;
291  q2.fn = 1;
292  AddTestCase (new BuildingsHelperOneTestCase (q2, b2), TestCase::QUICK);
293 
294  Vector vq3 (0.6, -1.75, 1.5);
296  q3.pos = vq3;
297  q3.indoor = false;
298  AddTestCase (new BuildingsHelperOneTestCase (q3, b2), TestCase::QUICK);
299 
300  Vector vq4 (-1.01, 0.3, 1.99);
302  q4.pos = vq4;
303  q4.indoor = false;
304  AddTestCase (new BuildingsHelperOneTestCase (q4, b2), TestCase::QUICK);
305 
306  Vector vq5 (-0.8, 0.7, 0.01);
308  q5.pos = vq5;
309  q5.indoor = false;
310  AddTestCase (new BuildingsHelperOneTestCase (q5, b2), TestCase::QUICK);
311 
312  Vector vq6 (0.2, 0.3, -0.2);
314  q6.pos = vq6;
315  q6.indoor = false;
316  AddTestCase (new BuildingsHelperOneTestCase (q6, b2), TestCase::QUICK);
317 
318  Vector vq7 (0.2, 0.3, 2.001);
320  q7.pos = vq7;
321  q7.indoor = false;
322  AddTestCase (new BuildingsHelperOneTestCase (q7, b2), TestCase::QUICK);
323 }
324 
static BuildingsHelperTestSuite buildingsHelperAntennaTestSuiteInstance
virtual void DoRun(void)
Implementation to actually run this TestCase.
static std::string BuildNameString(PositionInBuilding pib, BuildingData bd)
BuildingsHelperOneTestCase(PositionInBuilding pib, BuildingData bd)
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:1154
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:1344
#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:166
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.