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/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
NS_LOG_COMPONENT_DEFINE
(
"BuildingsHelperTest"
);
33
34
namespace
ns3 {
35
36
37
struct
PositionInBuilding
38
{
39
PositionInBuilding
();
40
Vector
pos
;
// coordinates of the mobility model instance
41
bool
indoor
;
// true if indoor, false otherwise
42
uint32_t
bid
;
// building id
43
uint16_t
rx
;
// room x
44
uint16_t
ry
;
// room y
45
uint16_t
fn
;
// floor number
46
};
47
48
PositionInBuilding::PositionInBuilding
()
49
: pos (0,0,0),
50
indoor (false),
51
bid (0xffffffff),
52
rx (0),
53
ry (0),
54
fn (0)
55
{
56
}
57
65
struct
BuildingData
66
{
67
BuildingData
();
68
double
xmin
;
69
double
xmax
;
70
double
ymin
;
71
double
ymax
;
72
double
zmin
;
73
double
zmax
;
74
uint16_t
nrx
;
75
uint16_t
nry
;
76
uint16_t
nf
;
77
};
78
79
BuildingData::BuildingData
()
80
: xmin (0),
81
xmax (0),
82
ymin (0),
83
ymax (0),
84
zmin (0),
85
zmax (0),
86
nrx (0),
87
nry (0),
88
nf (0)
89
{
90
}
91
92
class
BuildingsHelperOneTestCase
:
public
TestCase
93
{
94
public
:
95
static
std::string
BuildNameString
(
PositionInBuilding
pib,
BuildingData
bd);
96
BuildingsHelperOneTestCase
(
PositionInBuilding
pib,
BuildingData
bd);
97
98
private
:
99
virtual
void
DoRun
(
void
);
100
101
PositionInBuilding
m_pib
;
102
BuildingData
m_bd
;
103
104
};
105
106
std::string
BuildingsHelperOneTestCase::BuildNameString
(
PositionInBuilding
pib,
BuildingData
bd)
107
{
108
std::ostringstream oss;
109
oss <<
"pos="
<< pib.
pos
;
110
if
(pib.
indoor
)
111
{
112
oss <<
", bid="
<< pib.
bid
113
<<
", rx="
<< pib.
rx
114
<<
", ry="
<< pib.
ry
115
<<
", fn="
<< pib.
fn
;
116
}
117
else
118
{
119
oss <<
", outdoor"
;
120
}
121
return
oss.str ();
122
}
123
124
125
BuildingsHelperOneTestCase::BuildingsHelperOneTestCase
(
PositionInBuilding
pib,
BuildingData
bd)
126
:
TestCase
(BuildNameString (pib, bd)),
127
m_pib (pib),
128
m_bd (bd)
129
{
130
}
131
132
void
133
BuildingsHelperOneTestCase::DoRun
()
134
{
135
NS_LOG_FUNCTION
(
this
<<
BuildNameString
(
m_pib
,
m_bd
));
136
MobilityHelper
mobility;
137
mobility.
SetMobilityModel
(
"ns3::ConstantPositionMobilityModel"
);
138
139
NodeContainer
nodes
;
140
nodes.
Create
(1);
141
mobility.
Install
(nodes);
142
143
Ptr<ConstantPositionMobilityModel>
bmm = nodes.
Get
(0)->
GetObject
<
ConstantPositionMobilityModel
> ();
144
bmm->SetPosition (
m_pib
.
pos
);
145
146
NS_LOG_LOGIC
(
"create building"
);
147
Ptr<Building>
b = CreateObject<Building> ();
148
b->
SetBoundaries
(
Box
(
m_bd
.
xmin
,
m_bd
.
xmax
,
m_bd
.
ymin
,
m_bd
.
ymax
,
m_bd
.
zmin
,
m_bd
.
zmax
));
149
b->
SetNFloors
(
m_bd
.
nf
);
150
b->
SetNRoomsX
(
m_bd
.
nrx
);
151
b->
SetNRoomsY
(
m_bd
.
nry
);
152
Ptr<MobilityBuildingInfo>
buildingInfo = CreateObject<MobilityBuildingInfo> (b);
153
bmm->AggregateObject (buildingInfo);
// operation usually done by BuildingsHelper::Install
154
BuildingsHelper::MakeMobilityModelConsistent
();
155
156
157
NS_TEST_ASSERT_MSG_EQ
(buildingInfo->IsIndoor (),
m_pib
.
indoor
,
"indoor/outdoor mismatch"
);
158
if
(
m_pib
.
indoor
)
159
{
160
NS_LOG_LOGIC
(
" got bid="
<< buildingInfo->GetBuilding ()->GetId () <<
", f="
<< (uint32_t) buildingInfo->GetFloorNumber () <<
", rx="
<< (uint32_t) buildingInfo->GetRoomNumberX () <<
", roomY="
<< (uint32_t) buildingInfo->GetRoomNumberY ());
161
// only one building in this test, so Id will be 0
162
NS_TEST_ASSERT_MSG_EQ
(buildingInfo->GetBuilding ()->GetId (), 0,
"Building ID mismatch"
);
163
NS_TEST_ASSERT_MSG_EQ
((uint32_t) buildingInfo->GetFloorNumber (),
m_pib
.
fn
,
"floor number mismatch"
);
164
NS_TEST_ASSERT_MSG_EQ
((uint32_t) buildingInfo->GetRoomNumberX (),
m_pib
.
rx
,
"x room number mismatch"
);
165
NS_TEST_ASSERT_MSG_EQ
((uint32_t) buildingInfo->GetRoomNumberY (),
m_pib
.
ry
,
"y room number mismatch"
);
166
}
167
168
Simulator::Destroy
();
169
}
170
171
172
173
174
175
176
177
class
BuildingsHelperTestSuite
:
public
TestSuite
178
{
179
public
:
180
BuildingsHelperTestSuite
();
181
};
182
183
184
BuildingsHelperTestSuite::BuildingsHelperTestSuite
()
185
:
TestSuite
(
"buildings-helper"
, UNIT)
186
{
187
NS_LOG_FUNCTION
(
this
);
188
189
BuildingData
b1;
190
b1.
xmin
= 1;
191
b1.
xmax
= 3;
192
b1.
ymin
= 1;
193
b1.
ymax
= 2;
194
b1.
zmin
= 0;
195
b1.
zmax
= 4;
196
b1.
nrx
= 1;
197
b1.
nry
= 1;
198
b1.
nf
= 1;
199
200
Vector
vp1 (1.5, 1.5, 0.5);
201
PositionInBuilding
p1;
202
p1.
pos
= vp1;
203
p1.
indoor
=
true
;
204
p1.
bid
= 0;
205
p1.
rx
= 1;
206
p1.
ry
= 1;
207
p1.
fn
= 1;
208
AddTestCase
(
new
BuildingsHelperOneTestCase
(p1, b1),
TestCase::QUICK
);
209
210
Vector
vp2 (1.5, 0.5, 0.5);
211
PositionInBuilding
p2;
212
p2.
pos
= vp2;
213
p2.
indoor
=
false
;
214
AddTestCase
(
new
BuildingsHelperOneTestCase
(p2, b1),
TestCase::QUICK
);
215
216
Vector
vp3 (1.5, 2.5, 0.5);
217
PositionInBuilding
p3;
218
p3.
pos
= vp3;
219
p3.
indoor
=
false
;
220
AddTestCase
(
new
BuildingsHelperOneTestCase
(p3, b1),
TestCase::QUICK
);
221
222
Vector
vp4 (1.5, 1.5, 5);
223
PositionInBuilding
p4;
224
p4.
pos
= vp4;
225
p4.
indoor
=
false
;
226
AddTestCase
(
new
BuildingsHelperOneTestCase
(p4, b1),
TestCase::QUICK
);
227
228
Vector
vp5 (2.5, 1.6, 3.5);
229
PositionInBuilding
p5;
230
p5.
pos
= vp5;
231
p5.
indoor
=
true
;
232
p5.
bid
= 0;
233
p5.
rx
= 1;
234
p5.
ry
= 1;
235
p5.
fn
= 1;
236
AddTestCase
(
new
BuildingsHelperOneTestCase
(p5, b1),
TestCase::QUICK
);
237
238
Vector
vp6 (0.9999, 1.5, 1.5);
239
PositionInBuilding
p6;
240
p6.
pos
= vp6;
241
p6.
indoor
=
false
;
242
AddTestCase
(
new
BuildingsHelperOneTestCase
(p6, b1),
TestCase::QUICK
);
243
244
Vector
vp7 (3.0001, 1.5, 2.5);
245
PositionInBuilding
p7;
246
p7.
pos
= vp7;
247
p7.
indoor
=
false
;
248
AddTestCase
(
new
BuildingsHelperOneTestCase
(p7, b1),
TestCase::QUICK
);
249
250
Vector
vp8 (1.001, 1.001, -0.01);
251
PositionInBuilding
p8;
252
p8.
pos
= vp8;
253
p8.
indoor
=
false
;
254
AddTestCase
(
new
BuildingsHelperOneTestCase
(p8, b1),
TestCase::QUICK
);
255
256
Vector
vp9 (1.5, 1.5, 4.001);
257
PositionInBuilding
p9;
258
p9.
pos
= vp9;
259
p9.
indoor
=
false
;
260
AddTestCase
(
new
BuildingsHelperOneTestCase
(p9, b1),
TestCase::QUICK
);
261
262
263
264
265
BuildingData
b2;
266
b2.
xmin
= -1;
267
b2.
xmax
= 0.5;
268
b2.
ymin
= -2;
269
b2.
ymax
= 0.5;
270
b2.
zmin
= 0;
271
b2.
zmax
= 2;
272
b2.
nrx
= 3;
273
b2.
nry
= 5;
274
b2.
nf
= 4;
275
276
Vector
vq1 (-0.7, -1.1, 1.2);
277
PositionInBuilding
q1;
278
q1.
pos
= vq1;
279
q1.
indoor
=
true
;
280
q1.
bid
= 1;
281
q1.
rx
= 1;
282
q1.
ry
= 2;
283
q1.
fn
= 3;
284
AddTestCase
(
new
BuildingsHelperOneTestCase
(q1, b2),
TestCase::QUICK
);
285
286
Vector
vq2 (0.2, 0.3, 0.2);
287
PositionInBuilding
q2;
288
q2.
pos
= vq2;
289
q2.
indoor
=
true
;
290
q2.
bid
= 1;
291
q2.
rx
= 3;
292
q2.
ry
= 5;
293
q2.
fn
= 1;
294
AddTestCase
(
new
BuildingsHelperOneTestCase
(q2, b2),
TestCase::QUICK
);
295
296
Vector
vq3 (0.6, -1.75, 1.5);
297
PositionInBuilding
q3;
298
q3.
pos
= vq3;
299
q3.
indoor
=
false
;
300
AddTestCase
(
new
BuildingsHelperOneTestCase
(q3, b2),
TestCase::QUICK
);
301
302
Vector
vq4 (-1.01, 0.3, 1.99);
303
PositionInBuilding
q4;
304
q4.
pos
= vq4;
305
q4.
indoor
=
false
;
306
AddTestCase
(
new
BuildingsHelperOneTestCase
(q4, b2),
TestCase::QUICK
);
307
308
Vector
vq5 (-0.8, 0.7, 0.01);
309
PositionInBuilding
q5;
310
q5.
pos
= vq5;
311
q5.
indoor
=
false
;
312
AddTestCase
(
new
BuildingsHelperOneTestCase
(q5, b2),
TestCase::QUICK
);
313
314
Vector
vq6 (0.2, 0.3, -0.2);
315
PositionInBuilding
q6;
316
q6.
pos
= vq6;
317
q6.
indoor
=
false
;
318
AddTestCase
(
new
BuildingsHelperOneTestCase
(q6, b2),
TestCase::QUICK
);
319
320
Vector
vq7 (0.2, 0.3, 2.001);
321
PositionInBuilding
q7;
322
q7.
pos
= vq7;
323
q7.
indoor
=
false
;
324
AddTestCase
(
new
BuildingsHelperOneTestCase
(q7, b2),
TestCase::QUICK
);
325
}
326
327
static
BuildingsHelperTestSuite
buildingsHelperAntennaTestSuiteInstance
;
328
329
}
// namespace ns3
330
src
buildings
test
buildings-helper-test.cc
Generated on Fri Aug 30 2013 01:42:45 for ns-3 by
1.8.1.2