OLD | NEW |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2011, 2012 Centre Tecnologic de Telecomunicacions de Catalunya
(CTTC) | 3 * Copyright (c) 2011, 2012 Centre Tecnologic de Telecomunicacions de Catalunya
(CTTC) |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include <ns3/constant-position-mobility-model.h> | 26 #include <ns3/constant-position-mobility-model.h> |
27 #include <ns3/building.h> | 27 #include <ns3/building.h> |
28 #include <ns3/buildings-helper.h> | 28 #include <ns3/buildings-helper.h> |
29 #include <ns3/mobility-helper.h> | 29 #include <ns3/mobility-helper.h> |
30 #include <ns3/simulator.h> | 30 #include <ns3/simulator.h> |
31 | 31 |
32 using namespace ns3; | 32 using namespace ns3; |
33 | 33 |
34 NS_LOG_COMPONENT_DEFINE ("BuildingsHelperTest"); | 34 NS_LOG_COMPONENT_DEFINE ("BuildingsHelperTest"); |
35 | 35 |
| 36 /** |
| 37 * \ingroup buildings-test |
| 38 * \ingroup tests |
| 39 * |
| 40 * \brief PositionInBuilding structure |
| 41 */ |
36 struct PositionInBuilding | 42 struct PositionInBuilding |
37 { | 43 { |
38 PositionInBuilding (); | 44 PositionInBuilding (); |
39 Vector pos; // coordinates of the mobility model instance | 45 Vector pos; ///< coordinates of the mobility model instance |
40 bool indoor; // true if indoor, false otherwise | 46 bool indoor; ///< true if indoor, false otherwise |
41 uint32_t bid; // building id | 47 uint32_t bid; ///< building id |
42 uint16_t rx; // room x | 48 uint16_t rx; ///< room x |
43 uint16_t ry; // room y | 49 uint16_t ry; ///< room y |
44 uint16_t fn; // floor number | 50 uint16_t fn; ///< floor number |
45 }; | 51 }; |
46 | 52 |
47 PositionInBuilding::PositionInBuilding () | 53 PositionInBuilding::PositionInBuilding () |
48 : pos (0,0,0), | 54 : pos (0,0,0), |
49 indoor (false), | 55 indoor (false), |
50 bid (0xffffffff), | 56 bid (0xffffffff), |
51 rx (0), | 57 rx (0), |
52 ry (0), | 58 ry (0), |
53 fn (0) | 59 fn (0) |
54 { | 60 { |
55 } | 61 } |
56 | 62 |
57 /** | 63 /** |
58 * data to construct a Building object. We don't want to pass Building | 64 * \ingroup buildings-test |
| 65 * \ingroup tests |
| 66 * |
| 67 * \brief data to construct a Building object. We don't want to pass Building |
59 * objects to the TestCase constructor because otherwise BuildingList | 68 * objects to the TestCase constructor because otherwise BuildingList |
60 * would contain all of them (even if only one is meant to be in the | 69 * would contain all of them (even if only one is meant to be in the |
61 * test case). | 70 * test case). |
62 * | 71 * |
63 */ | 72 */ |
64 struct BuildingData | 73 struct BuildingData |
65 { | 74 { |
66 BuildingData (); | 75 BuildingData (); |
67 double xmin; | 76 double xmin; ///< X minimum |
68 double xmax; | 77 double xmax; ///< X maximum |
69 double ymin; | 78 double ymin; ///< Y minimum |
70 double ymax; | 79 double ymax; ///< Y maximum |
71 double zmin; | 80 double zmin; ///< Z minimum |
72 double zmax; | 81 double zmax; ///< Z maximum |
73 uint16_t nrx; | 82 uint16_t nrx; ///< Number of rooms X dimension |
74 uint16_t nry; | 83 uint16_t nry; ///< Number of rooms Y dimension |
75 uint16_t nf; | 84 uint16_t nf; ///< Number of floors |
76 }; | 85 }; |
77 | 86 |
78 BuildingData::BuildingData () | 87 BuildingData::BuildingData () |
79 : xmin (0), | 88 : xmin (0), |
80 xmax (0), | 89 xmax (0), |
81 ymin (0), | 90 ymin (0), |
82 ymax (0), | 91 ymax (0), |
83 zmin (0), | 92 zmin (0), |
84 zmax (0), | 93 zmax (0), |
85 nrx (0), | 94 nrx (0), |
86 nry (0), | 95 nry (0), |
87 nf (0) | 96 nf (0) |
88 { | 97 { |
89 } | 98 } |
90 | 99 |
| 100 /** |
| 101 * \ingroup buildings-test |
| 102 * \ingroup tests |
| 103 * |
| 104 * \brief Building helpter test #1 |
| 105 */ |
91 class BuildingsHelperOneTestCase : public TestCase | 106 class BuildingsHelperOneTestCase : public TestCase |
92 { | 107 { |
93 public: | 108 public: |
| 109 /** |
| 110 * Build name string function |
| 111 * \param pib The position in the buulding |
| 112 * \param bd The building data |
| 113 * \returns the name string |
| 114 */ |
94 static std::string BuildNameString (PositionInBuilding pib, BuildingData bd); | 115 static std::string BuildNameString (PositionInBuilding pib, BuildingData bd); |
| 116 /** |
| 117 * Constructor |
| 118 * \param pib The position in the buulding |
| 119 * \param bd The building data |
| 120 */ |
95 BuildingsHelperOneTestCase (PositionInBuilding pib, BuildingData bd); | 121 BuildingsHelperOneTestCase (PositionInBuilding pib, BuildingData bd); |
96 | 122 |
97 private: | 123 private: |
98 virtual void DoRun (void); | 124 virtual void DoRun (void); |
99 | 125 |
100 PositionInBuilding m_pib; | 126 PositionInBuilding m_pib; ///< position in building |
101 BuildingData m_bd; | 127 BuildingData m_bd; ///< building data |
102 | 128 |
103 }; | 129 }; |
104 | 130 |
105 std::string BuildingsHelperOneTestCase::BuildNameString (PositionInBuilding pib,
BuildingData bd) | 131 std::string BuildingsHelperOneTestCase::BuildNameString (PositionInBuilding pib,
BuildingData bd) |
106 { | 132 { |
107 std::ostringstream oss; | 133 std::ostringstream oss; |
108 oss << "pos=" << pib.pos; | 134 oss << "pos=" << pib.pos; |
109 if (pib.indoor) | 135 if (pib.indoor) |
110 { | 136 { |
111 oss << ", bid=" << pib.bid | 137 oss << ", bid=" << pib.bid |
112 » << ", rx=" << pib.rx· | 138 << ", rx=" << pib.rx |
113 » << ", ry=" << pib.ry | 139 << ", ry=" << pib.ry |
114 » << ", fn=" << pib.fn; | 140 << ", fn=" << pib.fn; |
115 } | 141 } |
116 else | 142 else |
117 { | 143 { |
118 oss << ", outdoor"; | 144 oss << ", outdoor"; |
119 } | 145 } |
120 return oss.str (); | 146 return oss.str (); |
121 } | 147 } |
122 | 148 |
123 | 149 |
124 BuildingsHelperOneTestCase::BuildingsHelperOneTestCase (PositionInBuilding pib,
BuildingData bd) | 150 BuildingsHelperOneTestCase::BuildingsHelperOneTestCase (PositionInBuilding pib,
BuildingData bd) |
125 : TestCase (BuildNameString (pib, bd)), | 151 : TestCase (BuildNameString (pib, bd)), |
126 m_pib (pib), | 152 m_pib (pib), |
127 m_bd (bd) | 153 m_bd (bd) |
128 { | 154 { |
129 } | 155 } |
130 | 156 |
131 void | 157 void |
132 BuildingsHelperOneTestCase::DoRun () | 158 BuildingsHelperOneTestCase::DoRun () |
133 { | 159 { |
134 NS_LOG_FUNCTION (this << BuildNameString (m_pib, m_bd)); | 160 NS_LOG_FUNCTION (this << BuildNameString (m_pib, m_bd)); |
135 MobilityHelper mobility; | 161 MobilityHelper mobility; |
136 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); | 162 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
137 | 163 |
138 NodeContainer nodes; | 164 NodeContainer nodes; |
139 nodes.Create (1); | 165 nodes.Create (1); |
140 mobility.Install (nodes); | 166 mobility.Install (nodes); |
141 | 167 |
142 Ptr<ConstantPositionMobilityModel> bmm = nodes.Get (0)->GetObject<ConstantPosi
tionMobilityModel> (); | 168 Ptr<ConstantPositionMobilityModel> bmm = nodes.Get (0)->GetObject<ConstantPosi
tionMobilityModel> (); |
143 bmm->SetPosition (m_pib.pos); | 169 bmm->SetPosition (m_pib.pos); |
144 | 170 |
145 NS_LOG_LOGIC ("create building"); | 171 NS_LOG_LOGIC ("create building"); |
146 Ptr<Building> b = CreateObject<Building> (); | 172 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)); | 173 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); | 174 b->SetNFloors (m_bd.nf); |
149 b->SetNRoomsX (m_bd.nrx); | 175 b->SetNRoomsX (m_bd.nrx); |
150 b->SetNRoomsY (m_bd.nry); | 176 b->SetNRoomsY (m_bd.nry); |
151 Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> (b
); | 177 Ptr<MobilityBuildingInfo> buildingInfo = CreateObject<MobilityBuildingInfo> (b
); |
152 bmm->AggregateObject (buildingInfo); // operation usually done by BuildingsHel
per::Install | 178 bmm->AggregateObject (buildingInfo); // operation usually done by BuildingsHel
per::Install |
153 BuildingsHelper::MakeMobilityModelConsistent (); | 179 BuildingsHelper::MakeMobilityModelConsistent (); |
154 | 180 |
155 | 181 |
156 NS_TEST_ASSERT_MSG_EQ (buildingInfo->IsIndoor (), m_pib.indoor, "indoor/outdoo
r mismatch"); | 182 NS_TEST_ASSERT_MSG_EQ (buildingInfo->IsIndoor (), m_pib.indoor, "indoor/outdoo
r mismatch"); |
157 if (m_pib.indoor) | 183 if (m_pib.indoor) |
158 { | 184 { |
159 NS_LOG_LOGIC (" got bid=" << buildingInfo->GetBuilding ()->GetId () << ",
f=" << (uint32_t) buildingInfo->GetFloorNumber () << ", rx=" << (uint32_t) build
ingInfo->GetRoomNumberX () << ", roomY=" << (uint32_t) buildingInfo->GetRoomNumb
erY ()); | 185 NS_LOG_LOGIC (" got bid=" << buildingInfo->GetBuilding ()->GetId () << ",
f=" << (uint32_t) buildingInfo->GetFloorNumber () << ", rx=" << (uint32_t) build
ingInfo->GetRoomNumberX () << ", roomY=" << (uint32_t) buildingInfo->GetRoomNumb
erY ()); |
160 // only one building in this test, so Id will be 0 | 186 // only one building in this test, so Id will be 0 |
161 NS_TEST_ASSERT_MSG_EQ (buildingInfo->GetBuilding ()->GetId (), 0, "Buildin
g ID mismatch"); | 187 NS_TEST_ASSERT_MSG_EQ (buildingInfo->GetBuilding ()->GetId (), 0, "Buildin
g ID mismatch"); |
162 NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetFloorNumber (), m_pib.f
n, "floor number mismatch"); | 188 NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetFloorNumber (), m_pib.f
n, "floor number mismatch"); |
163 NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberX (), m_pib.r
x, "x room number mismatch"); | 189 NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberX (), m_pib.r
x, "x room number mismatch"); |
164 NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberY (), m_pib.r
y, "y room number mismatch"); | 190 NS_TEST_ASSERT_MSG_EQ ((uint32_t) buildingInfo->GetRoomNumberY (), m_pib.r
y, "y room number mismatch"); |
165 } | 191 } |
166 | 192 |
167 Simulator::Destroy (); | 193 Simulator::Destroy (); |
168 } | 194 } |
169 | 195 |
170 | 196 |
171 | 197 |
172 | 198 |
173 | 199 |
174 | 200 |
175 | 201 /** |
| 202 * \ingroup buildings-test |
| 203 * \ingroup tests |
| 204 * |
| 205 * \brief Building helper test suite |
| 206 */ |
176 class BuildingsHelperTestSuite : public TestSuite | 207 class BuildingsHelperTestSuite : public TestSuite |
177 { | 208 { |
178 public: | 209 public: |
179 BuildingsHelperTestSuite (); | 210 BuildingsHelperTestSuite (); |
180 }; | 211 }; |
181 | 212 |
182 | 213 |
183 BuildingsHelperTestSuite::BuildingsHelperTestSuite () | 214 BuildingsHelperTestSuite::BuildingsHelperTestSuite () |
184 : TestSuite ("buildings-helper", UNIT) | 215 : TestSuite ("buildings-helper", UNIT) |
185 { | 216 { |
186 NS_LOG_FUNCTION (this); | 217 NS_LOG_FUNCTION (this); |
187 | 218 |
188 BuildingData b1; | 219 BuildingData b1; |
189 b1.xmin = 1; | 220 b1.xmin = 1; |
190 b1.xmax = 3; | 221 b1.xmax = 3; |
191 b1.ymin = 1; | 222 b1.ymin = 1; |
192 b1.ymax = 2; | 223 b1.ymax = 2; |
193 b1.zmin = 0; | 224 b1.zmin = 0; |
194 b1.zmax = 4; | 225 b1.zmax = 4; |
195 b1.nrx = 1; | 226 b1.nrx = 1; |
196 b1.nry = 1; | 227 b1.nry = 1; |
197 b1.nf = 1; | 228 b1.nf = 1; |
198 | 229 |
199 Vector vp1 (1.5, 1.5, 0.5); | 230 Vector vp1 (1.5, 1.5, 0.5); |
200 PositionInBuilding p1; | 231 PositionInBuilding p1; |
201 p1.pos = vp1; | 232 p1.pos = vp1; |
202 p1.indoor = true; | 233 p1.indoor = true; |
203 p1.bid = 0; | 234 p1.bid = 0; |
204 p1.rx = 1; | 235 p1.rx = 1; |
205 p1.ry = 1; | 236 p1.ry = 1; |
206 p1.fn = 1; | 237 p1.fn = 1; |
207 AddTestCase (new BuildingsHelperOneTestCase (p1, b1), TestCase::QUICK); | 238 AddTestCase (new BuildingsHelperOneTestCase (p1, b1), TestCase::QUICK); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 Vector vq6 (0.2, 0.3, -0.2); | 344 Vector vq6 (0.2, 0.3, -0.2); |
314 PositionInBuilding q6; | 345 PositionInBuilding q6; |
315 q6.pos = vq6; | 346 q6.pos = vq6; |
316 q6.indoor = false; | 347 q6.indoor = false; |
317 AddTestCase (new BuildingsHelperOneTestCase (q6, b2), TestCase::QUICK); | 348 AddTestCase (new BuildingsHelperOneTestCase (q6, b2), TestCase::QUICK); |
318 | 349 |
319 Vector vq7 (0.2, 0.3, 2.001); | 350 Vector vq7 (0.2, 0.3, 2.001); |
320 PositionInBuilding q7; | 351 PositionInBuilding q7; |
321 q7.pos = vq7; | 352 q7.pos = vq7; |
322 q7.indoor = false; | 353 q7.indoor = false; |
323 AddTestCase (new BuildingsHelperOneTestCase (q7, b2), TestCase::QUICK); | 354 AddTestCase (new BuildingsHelperOneTestCase (q7, b2), TestCase::QUICK); |
324 } | 355 } |
325 | 356 |
326 static BuildingsHelperTestSuite buildingsHelperAntennaTestSuiteInstance; | 357 static BuildingsHelperTestSuite buildingsHelperAntennaTestSuiteInstance; |
OLD | NEW |