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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 */
8
9#include "ns3/log.h"
10#include "ns3/test.h"
11#include <ns3/building.h>
12#include <ns3/buildings-helper.h>
13#include <ns3/constant-position-mobility-model.h>
14#include <ns3/mobility-building-info.h>
15#include <ns3/mobility-helper.h>
16#include <ns3/simulator.h>
17
18using namespace ns3;
19
20NS_LOG_COMPONENT_DEFINE("BuildingsHelperTest");
21
22/**
23 * \ingroup building-test
24 *
25 * \brief Struct representing a position in a building
26 */
28{
30 Vector pos; //!< coordinates of the mobility model instance
31 bool indoor; //!< true if indoor, false otherwise
32 uint32_t bid; //!< building id
33 uint16_t rx; //!< room x
34 uint16_t ry; //!< room y
35 uint16_t fn; //!< floor number
36};
37
39 : pos(0, 0, 0),
40 indoor(false),
41 bid(0xffffffff),
42 rx(0),
43 ry(0),
44 fn(0)
45{
46}
47
48/**
49 * \ingroup building-test
50
51 * Data to construct a Building object. We don't want to pass Building
52 * objects to the TestCase constructor because otherwise BuildingList
53 * would contain all of them (even if only one is meant to be in the
54 * test case).
55 *
56 */
58{
60 double xmin; //!< X min coordinate
61 double xmax; //!< X max coordinate
62 double ymin; //!< Y min coordinate
63 double ymax; //!< Y max coordinate
64 double zmin; //!< Z min coordinate
65 double zmax; //!< Z max coordinate
66 uint16_t nrx; //!< Number of rooms (X coord)
67 uint16_t nry; //!< Number of rooms (Y coord)
68 uint16_t nf; //!< Number of floors
69};
70
72 : xmin(0),
73 xmax(0),
74 ymin(0),
75 ymax(0),
76 zmin(0),
77 zmax(0),
78 nrx(0),
79 nry(0),
80 nf(0)
81{
82}
83
84/**
85 * \ingroup building-test
86 *
87 * \brief BuildingsHelper test
88 */
90{
91 public:
92 /**
93 * Build the testcase name
94 * \param pib Position in building
95 * \param bd Building data
96 * \return the TestCase name
97 */
98 static std::string BuildNameString(PositionInBuilding pib, BuildingData bd);
99
100 /**
101 * Constructor
102 * \param pib Position in building
103 * \param bd Building data
104 */
106
107 private:
108 void DoRun() override;
109
110 PositionInBuilding m_pib; //!< Position in the building
111 BuildingData m_bd; //!< Building data
112};
113
114std::string
116{
117 std::ostringstream oss;
118 oss << "pos=" << pib.pos;
119 if (pib.indoor)
120 {
121 oss << ", bid=" << pib.bid << ", rx=" << pib.rx << ", ry=" << pib.ry << ", fn=" << pib.fn;
122 }
123 else
124 {
125 oss << ", outdoor";
126 }
127 return oss.str();
128}
129
131 : TestCase(BuildNameString(pib, bd)),
132 m_pib(pib),
133 m_bd(bd)
134{
135}
136
137void
139{
141 MobilityHelper mobility;
142 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
143
145 nodes.Create(1);
146 mobility.Install(nodes);
147
150 bmm->SetPosition(m_pib.pos);
151
152 NS_LOG_LOGIC("create building");
154 b->SetBoundaries(Box(m_bd.xmin, m_bd.xmax, m_bd.ymin, m_bd.ymax, m_bd.zmin, m_bd.zmax));
155 b->SetNFloors(m_bd.nf);
156 b->SetNRoomsX(m_bd.nrx);
157 b->SetNRoomsY(m_bd.nry);
159 bmm->AggregateObject(buildingInfo); // operation usually done by BuildingsHelper::Install
160
161 NS_TEST_ASSERT_MSG_EQ(buildingInfo->IsIndoor(), m_pib.indoor, "indoor/outdoor mismatch");
162 if (m_pib.indoor)
163 {
164 NS_LOG_LOGIC(" got bid=" << buildingInfo->GetBuilding()->GetId()
165 << ", f=" << (uint32_t)buildingInfo->GetFloorNumber()
166 << ", rx=" << (uint32_t)buildingInfo->GetRoomNumberX()
167 << ", roomY=" << (uint32_t)buildingInfo->GetRoomNumberY());
168 // only one building in this test, so Id will be 0
169 NS_TEST_ASSERT_MSG_EQ(buildingInfo->GetBuilding()->GetId(), 0, "Building ID mismatch");
170 NS_TEST_ASSERT_MSG_EQ((uint32_t)buildingInfo->GetFloorNumber(),
171 m_pib.fn,
172 "floor number mismatch");
173 NS_TEST_ASSERT_MSG_EQ((uint32_t)buildingInfo->GetRoomNumberX(),
174 m_pib.rx,
175 "x room number mismatch");
176 NS_TEST_ASSERT_MSG_EQ((uint32_t)buildingInfo->GetRoomNumberY(),
177 m_pib.ry,
178 "y room number mismatch");
179 }
180
182}
183
184/**
185 * \ingroup building-test
186 *
187 * \brief BuildingsHelper TestSuite
188 */
190{
191 public:
193};
194
196 : TestSuite("buildings-helper", Type::UNIT)
197{
198 NS_LOG_FUNCTION(this);
199
200 BuildingData b1;
201 b1.xmin = 1;
202 b1.xmax = 3;
203 b1.ymin = 1;
204 b1.ymax = 2;
205 b1.zmin = 0;
206 b1.zmax = 4;
207 b1.nrx = 1;
208 b1.nry = 1;
209 b1.nf = 1;
210
211 Vector vp1(1.5, 1.5, 0.5);
213 p1.pos = vp1;
214 p1.indoor = true;
215 p1.bid = 0;
216 p1.rx = 1;
217 p1.ry = 1;
218 p1.fn = 1;
219 AddTestCase(new BuildingsHelperOneTestCase(p1, b1), TestCase::Duration::QUICK);
220
221 Vector vp2(1.5, 0.5, 0.5);
223 p2.pos = vp2;
224 p2.indoor = false;
225 AddTestCase(new BuildingsHelperOneTestCase(p2, b1), TestCase::Duration::QUICK);
226
227 Vector vp3(1.5, 2.5, 0.5);
229 p3.pos = vp3;
230 p3.indoor = false;
231 AddTestCase(new BuildingsHelperOneTestCase(p3, b1), TestCase::Duration::QUICK);
232
233 Vector vp4(1.5, 1.5, 5);
235 p4.pos = vp4;
236 p4.indoor = false;
237 AddTestCase(new BuildingsHelperOneTestCase(p4, b1), TestCase::Duration::QUICK);
238
239 Vector vp5(2.5, 1.6, 3.5);
241 p5.pos = vp5;
242 p5.indoor = true;
243 p5.bid = 0;
244 p5.rx = 1;
245 p5.ry = 1;
246 p5.fn = 1;
247 AddTestCase(new BuildingsHelperOneTestCase(p5, b1), TestCase::Duration::QUICK);
248
249 Vector vp6(0.9999, 1.5, 1.5);
251 p6.pos = vp6;
252 p6.indoor = false;
253 AddTestCase(new BuildingsHelperOneTestCase(p6, b1), TestCase::Duration::QUICK);
254
255 Vector vp7(3.0001, 1.5, 2.5);
257 p7.pos = vp7;
258 p7.indoor = false;
259 AddTestCase(new BuildingsHelperOneTestCase(p7, b1), TestCase::Duration::QUICK);
260
261 Vector vp8(1.001, 1.001, -0.01);
263 p8.pos = vp8;
264 p8.indoor = false;
265 AddTestCase(new BuildingsHelperOneTestCase(p8, b1), TestCase::Duration::QUICK);
266
267 Vector vp9(1.5, 1.5, 4.001);
269 p9.pos = vp9;
270 p9.indoor = false;
271 AddTestCase(new BuildingsHelperOneTestCase(p9, b1), TestCase::Duration::QUICK);
272
273 BuildingData b2;
274 b2.xmin = -1;
275 b2.xmax = 0.5;
276 b2.ymin = -2;
277 b2.ymax = 0.5;
278 b2.zmin = 0;
279 b2.zmax = 2;
280 b2.nrx = 3;
281 b2.nry = 5;
282 b2.nf = 4;
283
284 Vector vq1(-0.7, -1.1, 1.2);
286 q1.pos = vq1;
287 q1.indoor = true;
288 q1.bid = 1;
289 q1.rx = 1;
290 q1.ry = 2;
291 q1.fn = 3;
292 AddTestCase(new BuildingsHelperOneTestCase(q1, b2), TestCase::Duration::QUICK);
293
294 Vector vq2(0.2, 0.3, 0.2);
296 q2.pos = vq2;
297 q2.indoor = true;
298 q2.bid = 1;
299 q2.rx = 3;
300 q2.ry = 5;
301 q2.fn = 1;
302 AddTestCase(new BuildingsHelperOneTestCase(q2, b2), TestCase::Duration::QUICK);
303
304 Vector vq3(0.6, -1.75, 1.5);
306 q3.pos = vq3;
307 q3.indoor = false;
308 AddTestCase(new BuildingsHelperOneTestCase(q3, b2), TestCase::Duration::QUICK);
309
310 Vector vq4(-1.01, 0.3, 1.99);
312 q4.pos = vq4;
313 q4.indoor = false;
314 AddTestCase(new BuildingsHelperOneTestCase(q4, b2), TestCase::Duration::QUICK);
315
316 Vector vq5(-0.8, 0.7, 0.01);
318 q5.pos = vq5;
319 q5.indoor = false;
320 AddTestCase(new BuildingsHelperOneTestCase(q5, b2), TestCase::Duration::QUICK);
321
322 Vector vq6(0.2, 0.3, -0.2);
324 q6.pos = vq6;
325 q6.indoor = false;
326 AddTestCase(new BuildingsHelperOneTestCase(q6, b2), TestCase::Duration::QUICK);
327
328 Vector vq7(0.2, 0.3, 2.001);
330 q7.pos = vq7;
331 q7.indoor = false;
332 AddTestCase(new BuildingsHelperOneTestCase(q7, b2), TestCase::Duration::QUICK);
333}
334
335/// Static variable for test initialization
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:24
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:511
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:134
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