A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
buildings-helper-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011, 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 */
19
20#include "ns3/log.h"
21#include "ns3/test.h"
22#include <ns3/building.h>
23#include <ns3/buildings-helper.h>
24#include <ns3/constant-position-mobility-model.h>
25#include <ns3/mobility-building-info.h>
26#include <ns3/mobility-helper.h>
27#include <ns3/simulator.h>
28
29using namespace ns3;
30
31NS_LOG_COMPONENT_DEFINE("BuildingsHelperTest");
32
40{
42 Vector pos;
43 bool indoor;
45 uint16_t rx;
46 uint16_t ry;
47 uint16_t fn;
48};
49
51 : pos(0, 0, 0),
52 indoor(false),
53 bid(0xffffffff),
54 rx(0),
55 ry(0),
56 fn(0)
57{
58}
59
71{
73 double xmin;
74 double xmax;
75 double ymin;
76 double ymax;
77 double zmin;
78 double zmax;
79 uint16_t nrx;
80 uint16_t nry;
81 uint16_t nf;
82};
83
85 : xmin(0),
86 xmax(0),
87 ymin(0),
88 ymax(0),
89 zmin(0),
90 zmax(0),
91 nrx(0),
92 nry(0),
93 nf(0)
94{
95}
96
104{
105 public:
112 static std::string BuildNameString(PositionInBuilding pib, BuildingData bd);
113
120
121 private:
122 void DoRun() override;
123
126};
127
128std::string
130{
131 std::ostringstream oss;
132 oss << "pos=" << pib.pos;
133 if (pib.indoor)
134 {
135 oss << ", bid=" << pib.bid << ", rx=" << pib.rx << ", ry=" << pib.ry << ", fn=" << pib.fn;
136 }
137 else
138 {
139 oss << ", outdoor";
140 }
141 return oss.str();
142}
143
145 : TestCase(BuildNameString(pib, bd)),
146 m_pib(pib),
147 m_bd(bd)
148{
149}
150
151void
153{
155 MobilityHelper mobility;
156 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
157
159 nodes.Create(1);
160 mobility.Install(nodes);
161
164 bmm->SetPosition(m_pib.pos);
165
166 NS_LOG_LOGIC("create building");
167 Ptr<Building> b = CreateObject<Building>();
168 b->SetBoundaries(Box(m_bd.xmin, m_bd.xmax, m_bd.ymin, m_bd.ymax, m_bd.zmin, m_bd.zmax));
169 b->SetNFloors(m_bd.nf);
170 b->SetNRoomsX(m_bd.nrx);
171 b->SetNRoomsY(m_bd.nry);
172 Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo>(b);
173 bmm->AggregateObject(buildingInfo); // operation usually done by BuildingsHelper::Install
174
175 NS_TEST_ASSERT_MSG_EQ(buildingInfo->IsIndoor(), m_pib.indoor, "indoor/outdoor mismatch");
176 if (m_pib.indoor)
177 {
178 NS_LOG_LOGIC(" got bid=" << buildingInfo->GetBuilding()->GetId()
179 << ", f=" << (uint32_t)buildingInfo->GetFloorNumber()
180 << ", rx=" << (uint32_t)buildingInfo->GetRoomNumberX()
181 << ", roomY=" << (uint32_t)buildingInfo->GetRoomNumberY());
182 // only one building in this test, so Id will be 0
183 NS_TEST_ASSERT_MSG_EQ(buildingInfo->GetBuilding()->GetId(), 0, "Building ID mismatch");
184 NS_TEST_ASSERT_MSG_EQ((uint32_t)buildingInfo->GetFloorNumber(),
185 m_pib.fn,
186 "floor number mismatch");
187 NS_TEST_ASSERT_MSG_EQ((uint32_t)buildingInfo->GetRoomNumberX(),
188 m_pib.rx,
189 "x room number mismatch");
190 NS_TEST_ASSERT_MSG_EQ((uint32_t)buildingInfo->GetRoomNumberY(),
191 m_pib.ry,
192 "y room number mismatch");
193 }
194
196}
197
205{
206 public:
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;
235
236 Vector vp2(1.5, 0.5, 0.5);
238 p2.pos = vp2;
239 p2.indoor = false;
241
242 Vector vp3(1.5, 2.5, 0.5);
244 p3.pos = vp3;
245 p3.indoor = false;
247
248 Vector vp4(1.5, 1.5, 5);
250 p4.pos = vp4;
251 p4.indoor = false;
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;
263
264 Vector vp6(0.9999, 1.5, 1.5);
266 p6.pos = vp6;
267 p6.indoor = false;
269
270 Vector vp7(3.0001, 1.5, 2.5);
272 p7.pos = vp7;
273 p7.indoor = false;
275
276 Vector vp8(1.001, 1.001, -0.01);
278 p8.pos = vp8;
279 p8.indoor = false;
281
282 Vector vp9(1.5, 1.5, 4.001);
284 p9.pos = vp9;
285 p9.indoor = false;
287
288 BuildingData b2;
289 b2.xmin = -1;
290 b2.xmax = 0.5;
291 b2.ymin = -2;
292 b2.ymax = 0.5;
293 b2.zmin = 0;
294 b2.zmax = 2;
295 b2.nrx = 3;
296 b2.nry = 5;
297 b2.nf = 4;
298
299 Vector vq1(-0.7, -1.1, 1.2);
301 q1.pos = vq1;
302 q1.indoor = true;
303 q1.bid = 1;
304 q1.rx = 1;
305 q1.ry = 2;
306 q1.fn = 3;
308
309 Vector vq2(0.2, 0.3, 0.2);
311 q2.pos = vq2;
312 q2.indoor = true;
313 q2.bid = 1;
314 q2.rx = 3;
315 q2.ry = 5;
316 q2.fn = 1;
318
319 Vector vq3(0.6, -1.75, 1.5);
321 q3.pos = vq3;
322 q3.indoor = false;
324
325 Vector vq4(-1.01, 0.3, 1.99);
327 q4.pos = vq4;
328 q4.indoor = false;
330
331 Vector vq5(-0.8, 0.7, 0.01);
333 q5.pos = vq5;
334 q5.indoor = false;
336
337 Vector vq6(0.2, 0.3, -0.2);
339 q6.pos = vq6;
340 q6.indoor = false;
342
343 Vector vq7(0.2, 0.3, 2.001);
345 q7.pos = vq7;
346 q7.indoor = false;
348}
349
static BuildingsHelperTestSuite buildingsHelperAntennaTestSuiteInstance
Static variable for test initialization.
BuildingData m_bd
Building data.
static std::string BuildNameString(PositionInBuilding pib, BuildingData bd)
Build the testcase name.
PositionInBuilding m_pib
Position in the building.
void DoRun() override
Implementation to actually run this TestCase.
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.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#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:144
NodeContainer nodes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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