A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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/buildings-mobility-model.h>
26
#include <ns3/building.h>
27
#include <ns3/buildings-helper.h>
28
#include <ns3/mobility-helper.h>
29
#include <ns3/simulator.h>
30
31
NS_LOG_COMPONENT_DEFINE
(
"BuildingsHelperTest"
);
32
33
namespace
ns3 {
34
35
36
struct
PositionInBuilding
37
{
38
PositionInBuilding
();
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
47
PositionInBuilding::PositionInBuilding
()
48
: pos (0,0,0),
49
indoor (false),
50
bid (0xffffffff),
51
rx (0),
52
ry (0),
53
fn (0)
54
{
55
}
56
64
struct
BuildingData
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
78
BuildingData::BuildingData
()
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
91
class
BuildingsHelperOneTestCase
:
public
TestCase
92
{
93
public
:
94
static
std::string
BuildNameString
(
PositionInBuilding
pib,
BuildingData
bd);
95
BuildingsHelperOneTestCase
(
PositionInBuilding
pib,
BuildingData
bd);
96
97
private
:
98
virtual
void
DoRun
(
void
);
99
100
PositionInBuilding
m_pib
;
101
BuildingData
m_bd
;
102
103
};
104
105
std::string
BuildingsHelperOneTestCase::BuildNameString
(
PositionInBuilding
pib,
BuildingData
bd)
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
124
BuildingsHelperOneTestCase::BuildingsHelperOneTestCase
(
PositionInBuilding
pib,
BuildingData
bd)
125
:
TestCase
(BuildNameString (pib, bd)),
126
m_pib (pib),
127
m_bd (bd)
128
{
129
}
130
131
void
132
BuildingsHelperOneTestCase::DoRun
()
133
{
134
NS_LOG_FUNCTION
(
this
<<
BuildNameString
(
m_pib
,
m_bd
));
135
MobilityHelper
mobility;
136
mobility.
SetMobilityModel
(
"ns3::BuildingsMobilityModel"
);
137
138
NodeContainer
nodes;
139
nodes.
Create
(1);
140
mobility.
Install
(nodes);
141
142
Ptr<BuildingsMobilityModel>
bmm = nodes.
Get
(0)->
GetObject
<
BuildingsMobilityModel
> ();
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
152
BuildingsHelper::MakeMobilityModelConsistent
();
153
154
155
NS_TEST_ASSERT_MSG_EQ
(bmm->
IsIndoor
(),
m_pib
.
indoor
,
"indoor/outdoor mismatch"
);
156
if
(
m_pib
.
indoor
)
157
{
158
NS_LOG_LOGIC
(
" got bid="
<< bmm->
GetBuilding
()->
GetId
() <<
", f="
<< (uint32_t) bmm->
GetFloorNumber
() <<
", rx="
<< (uint32_t) bmm->
GetRoomNumberX
() <<
", roomY="
<< (uint32_t) bmm->
GetRoomNumberY
());
159
// only one building in this test, so Id will be 0
160
NS_TEST_ASSERT_MSG_EQ
(bmm->
GetBuilding
()->
GetId
(), 0,
"Building ID mismatch"
);
161
NS_TEST_ASSERT_MSG_EQ
((uint32_t) bmm->
GetFloorNumber
(),
m_pib
.
fn
,
"floor number mismatch"
);
162
NS_TEST_ASSERT_MSG_EQ
((uint32_t) bmm->
GetRoomNumberX
(),
m_pib
.
rx
,
"x room number mismatch"
);
163
NS_TEST_ASSERT_MSG_EQ
((uint32_t) bmm->
GetRoomNumberY
(),
m_pib
.
ry
,
"y room number mismatch"
);
164
}
165
166
Simulator::Destroy
();
167
}
168
169
170
171
172
173
174
175
class
BuildingsHelperTestSuite
:
public
TestSuite
176
{
177
public
:
178
BuildingsHelperTestSuite
();
179
};
180
181
182
BuildingsHelperTestSuite::BuildingsHelperTestSuite
()
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);
199
PositionInBuilding
p1;
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);
209
PositionInBuilding
p2;
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);
215
PositionInBuilding
p3;
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);
221
PositionInBuilding
p4;
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);
227
PositionInBuilding
p5;
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);
237
PositionInBuilding
p6;
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);
243
PositionInBuilding
p7;
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);
249
PositionInBuilding
p8;
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);
255
PositionInBuilding
p9;
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);
275
PositionInBuilding
q1;
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);
285
PositionInBuilding
q2;
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);
295
PositionInBuilding
q3;
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);
301
PositionInBuilding
q4;
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);
307
PositionInBuilding
q5;
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);
313
PositionInBuilding
q6;
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);
319
PositionInBuilding
q7;
320
q7.
pos
= vq7;
321
q7.
indoor
=
false
;
322
AddTestCase
(
new
BuildingsHelperOneTestCase
(q7, b2),
TestCase::QUICK
);
323
}
324
325
static
BuildingsHelperTestSuite
buildingsHelperAntennaTestSuiteInstance
;
326
327
}
// namespace ns3
328
src
buildings
test
buildings-helper-test.cc
Generated on Tue May 14 2013 11:08:16 for ns-3 by
1.8.1.2