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
33/**
34 * \ingroup building-test
35 *
36 * \brief Struct representing a position in a building
37 */
39{
41 Vector pos; //!< coordinates of the mobility model instance
42 bool indoor; //!< true if indoor, false otherwise
43 uint32_t bid; //!< building id
44 uint16_t rx; //!< room x
45 uint16_t ry; //!< room y
46 uint16_t fn; //!< floor number
47};
48
50 : pos(0, 0, 0),
51 indoor(false),
52 bid(0xffffffff),
53 rx(0),
54 ry(0),
55 fn(0)
56{
57}
58
59/**
60 * \ingroup building-test
61
62 * Data to construct a Building object. We don't want to pass Building
63 * objects to the TestCase constructor because otherwise BuildingList
64 * would contain all of them (even if only one is meant to be in the
65 * test case).
66 *
67 */
69{
71 double xmin; //!< X min coordinate
72 double xmax; //!< X max coordinate
73 double ymin; //!< Y min coordinate
74 double ymax; //!< Y max coordinate
75 double zmin; //!< Z min coordinate
76 double zmax; //!< Z max coordinate
77 uint16_t nrx; //!< Number of rooms (X coord)
78 uint16_t nry; //!< Number of rooms (Y coord)
79 uint16_t nf; //!< Number of floors
80};
81
83 : xmin(0),
84 xmax(0),
85 ymin(0),
86 ymax(0),
87 zmin(0),
88 zmax(0),
89 nrx(0),
90 nry(0),
91 nf(0)
92{
93}
94
95/**
96 * \ingroup building-test
97 *
98 * \brief BuildingsHelper test
99 */
101{
102 public:
103 /**
104 * Build the testcase name
105 * \param pib Position in building
106 * \param bd Building data
107 * \return the TestCase name
108 */
109 static std::string BuildNameString(PositionInBuilding pib, BuildingData bd);
110
111 /**
112 * Constructor
113 * \param pib Position in building
114 * \param bd Building data
115 */
117
118 private:
119 void DoRun() override;
120
121 PositionInBuilding m_pib; //!< Position in the building
122 BuildingData m_bd; //!< Building data
123};
124
125std::string
127{
128 std::ostringstream oss;
129 oss << "pos=" << pib.pos;
130 if (pib.indoor)
131 {
132 oss << ", bid=" << pib.bid << ", rx=" << pib.rx << ", ry=" << pib.ry << ", fn=" << pib.fn;
133 }
134 else
135 {
136 oss << ", outdoor";
137 }
138 return oss.str();
139}
140
142 : TestCase(BuildNameString(pib, bd)),
143 m_pib(pib),
144 m_bd(bd)
145{
146}
147
148void
150{
152 MobilityHelper mobility;
153 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
154
156 nodes.Create(1);
157 mobility.Install(nodes);
158
161 bmm->SetPosition(m_pib.pos);
162
163 NS_LOG_LOGIC("create building");
164 Ptr<Building> b = CreateObject<Building>();
165 b->SetBoundaries(Box(m_bd.xmin, m_bd.xmax, m_bd.ymin, m_bd.ymax, m_bd.zmin, m_bd.zmax));
166 b->SetNFloors(m_bd.nf);
167 b->SetNRoomsX(m_bd.nrx);
168 b->SetNRoomsY(m_bd.nry);
169 Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo>(b);
170 bmm->AggregateObject(buildingInfo); // operation usually done by BuildingsHelper::Install
171
172 NS_TEST_ASSERT_MSG_EQ(buildingInfo->IsIndoor(), m_pib.indoor, "indoor/outdoor mismatch");
173 if (m_pib.indoor)
174 {
175 NS_LOG_LOGIC(" got bid=" << buildingInfo->GetBuilding()->GetId()
176 << ", f=" << (uint32_t)buildingInfo->GetFloorNumber()
177 << ", rx=" << (uint32_t)buildingInfo->GetRoomNumberX()
178 << ", roomY=" << (uint32_t)buildingInfo->GetRoomNumberY());
179 // only one building in this test, so Id will be 0
180 NS_TEST_ASSERT_MSG_EQ(buildingInfo->GetBuilding()->GetId(), 0, "Building ID mismatch");
181 NS_TEST_ASSERT_MSG_EQ((uint32_t)buildingInfo->GetFloorNumber(),
182 m_pib.fn,
183 "floor number mismatch");
184 NS_TEST_ASSERT_MSG_EQ((uint32_t)buildingInfo->GetRoomNumberX(),
185 m_pib.rx,
186 "x room number mismatch");
187 NS_TEST_ASSERT_MSG_EQ((uint32_t)buildingInfo->GetRoomNumberY(),
188 m_pib.ry,
189 "y room number mismatch");
190 }
191
193}
194
195/**
196 * \ingroup building-test
197 *
198 * \brief BuildingsHelper TestSuite
199 */
201{
202 public:
204};
205
207 : TestSuite("buildings-helper", Type::UNIT)
208{
209 NS_LOG_FUNCTION(this);
210
211 BuildingData b1;
212 b1.xmin = 1;
213 b1.xmax = 3;
214 b1.ymin = 1;
215 b1.ymax = 2;
216 b1.zmin = 0;
217 b1.zmax = 4;
218 b1.nrx = 1;
219 b1.nry = 1;
220 b1.nf = 1;
221
222 Vector vp1(1.5, 1.5, 0.5);
224 p1.pos = vp1;
225 p1.indoor = true;
226 p1.bid = 0;
227 p1.rx = 1;
228 p1.ry = 1;
229 p1.fn = 1;
230 AddTestCase(new BuildingsHelperOneTestCase(p1, b1), TestCase::Duration::QUICK);
231
232 Vector vp2(1.5, 0.5, 0.5);
234 p2.pos = vp2;
235 p2.indoor = false;
236 AddTestCase(new BuildingsHelperOneTestCase(p2, b1), TestCase::Duration::QUICK);
237
238 Vector vp3(1.5, 2.5, 0.5);
240 p3.pos = vp3;
241 p3.indoor = false;
242 AddTestCase(new BuildingsHelperOneTestCase(p3, b1), TestCase::Duration::QUICK);
243
244 Vector vp4(1.5, 1.5, 5);
246 p4.pos = vp4;
247 p4.indoor = false;
248 AddTestCase(new BuildingsHelperOneTestCase(p4, b1), TestCase::Duration::QUICK);
249
250 Vector vp5(2.5, 1.6, 3.5);
252 p5.pos = vp5;
253 p5.indoor = true;
254 p5.bid = 0;
255 p5.rx = 1;
256 p5.ry = 1;
257 p5.fn = 1;
258 AddTestCase(new BuildingsHelperOneTestCase(p5, b1), TestCase::Duration::QUICK);
259
260 Vector vp6(0.9999, 1.5, 1.5);
262 p6.pos = vp6;
263 p6.indoor = false;
264 AddTestCase(new BuildingsHelperOneTestCase(p6, b1), TestCase::Duration::QUICK);
265
266 Vector vp7(3.0001, 1.5, 2.5);
268 p7.pos = vp7;
269 p7.indoor = false;
270 AddTestCase(new BuildingsHelperOneTestCase(p7, b1), TestCase::Duration::QUICK);
271
272 Vector vp8(1.001, 1.001, -0.01);
274 p8.pos = vp8;
275 p8.indoor = false;
276 AddTestCase(new BuildingsHelperOneTestCase(p8, b1), TestCase::Duration::QUICK);
277
278 Vector vp9(1.5, 1.5, 4.001);
280 p9.pos = vp9;
281 p9.indoor = false;
282 AddTestCase(new BuildingsHelperOneTestCase(p9, b1), TestCase::Duration::QUICK);
283
284 BuildingData b2;
285 b2.xmin = -1;
286 b2.xmax = 0.5;
287 b2.ymin = -2;
288 b2.ymax = 0.5;
289 b2.zmin = 0;
290 b2.zmax = 2;
291 b2.nrx = 3;
292 b2.nry = 5;
293 b2.nf = 4;
294
295 Vector vq1(-0.7, -1.1, 1.2);
297 q1.pos = vq1;
298 q1.indoor = true;
299 q1.bid = 1;
300 q1.rx = 1;
301 q1.ry = 2;
302 q1.fn = 3;
303 AddTestCase(new BuildingsHelperOneTestCase(q1, b2), TestCase::Duration::QUICK);
304
305 Vector vq2(0.2, 0.3, 0.2);
307 q2.pos = vq2;
308 q2.indoor = true;
309 q2.bid = 1;
310 q2.rx = 3;
311 q2.ry = 5;
312 q2.fn = 1;
313 AddTestCase(new BuildingsHelperOneTestCase(q2, b2), TestCase::Duration::QUICK);
314
315 Vector vq3(0.6, -1.75, 1.5);
317 q3.pos = vq3;
318 q3.indoor = false;
319 AddTestCase(new BuildingsHelperOneTestCase(q3, b2), TestCase::Duration::QUICK);
320
321 Vector vq4(-1.01, 0.3, 1.99);
323 q4.pos = vq4;
324 q4.indoor = false;
325 AddTestCase(new BuildingsHelperOneTestCase(q4, b2), TestCase::Duration::QUICK);
326
327 Vector vq5(-0.8, 0.7, 0.01);
329 q5.pos = vq5;
330 q5.indoor = false;
331 AddTestCase(new BuildingsHelperOneTestCase(q5, b2), TestCase::Duration::QUICK);
332
333 Vector vq6(0.2, 0.3, -0.2);
335 q6.pos = vq6;
336 q6.indoor = false;
337 AddTestCase(new BuildingsHelperOneTestCase(q6, b2), TestCase::Duration::QUICK);
338
339 Vector vq7(0.2, 0.3, 2.001);
341 q7.pos = vq7;
342 q7.indoor = false;
343 AddTestCase(new BuildingsHelperOneTestCase(q7, b2), TestCase::Duration::QUICK);
344}
345
346/// 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: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:522
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:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
#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:145
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