A Discrete-Event Network Simulator
API
buildings-channel-condition-model-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2019 SIGNET Lab, Department of Information Engineering,
4  * University of Padova
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #include "ns3/abort.h"
21 #include "ns3/test.h"
22 #include "ns3/config.h"
23 #include "ns3/buildings-channel-condition-model.h"
24 #include "ns3/constant-position-mobility-model.h"
25 #include "ns3/buildings-module.h"
26 #include "ns3/log.h"
27 #include "ns3/simulator.h"
28 
29 using namespace ns3;
30 
31 NS_LOG_COMPONENT_DEFINE ("BuildingsChannelConditionModelsTest");
32 
42 {
43 public:
48 
53 
54 private:
58  virtual void DoRun (void);
59 
63  typedef struct
64  {
65  Vector m_positionA;
66  Vector m_positionB;
68  } TestVector;
69 
71 };
72 
74  : TestCase ("Test case for the BuildingsChannelConditionModel"), m_testVectors ()
75 {
76 }
77 
79 {
80 }
81 
82 void
84 {
85  TestVector testVector;
86 
87  testVector.m_positionA = Vector (0.0, 5.0, 1.5);
88  testVector.m_positionB = Vector (20.0, 5.0, 1.5);
89  testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
90  m_testVectors.Add (testVector);
91 
92  testVector.m_positionA = Vector (0.0, 11.0, 1.5);
93  testVector.m_positionB = Vector (20.0, 11.0, 1.5);
94  testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
95  m_testVectors.Add (testVector);
96 
97  testVector.m_positionA = Vector (5.0, 5.0, 1.5);
98  testVector.m_positionB = Vector (20.0, 5.0, 1.5);
99  testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
100  m_testVectors.Add (testVector);
101 
102  testVector.m_positionA = Vector (4.0, 5.0, 1.5);
103  testVector.m_positionB = Vector (5.0, 5.0, 1.5);
104  testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
105  m_testVectors.Add (testVector);
106 
107  // Deploy nodes and building and get the channel condition
109  nodes.Create (2);
110 
111  Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
112  nodes.Get (0)->AggregateObject (a);
113 
114  Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
115  nodes.Get (1)->AggregateObject (b);
116 
117  Ptr<BuildingsChannelConditionModel> condModel = CreateObject<BuildingsChannelConditionModel> ();
118 
119  Ptr<Building> building = Create<Building> ();
120  building->SetNRoomsX (1);
121  building->SetNRoomsY (1);
122  building->SetNFloors (1);
123  building->SetBoundaries (Box (0.0, 10.0, 0.0, 10.0, 0.0, 5.0));
124 
125  BuildingsHelper::Install (nodes);
126 
127  for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
128  {
129  testVector = m_testVectors.Get (i);
130  a->SetPosition (testVector.m_positionA);
131  b->SetPosition (testVector.m_positionB);
133  buildingInfoA->MakeConsistent (a);
135  buildingInfoA->MakeConsistent (b);
136  Ptr<ChannelCondition> cond = condModel->GetChannelCondition (a, b);
137 
138  NS_LOG_DEBUG ("Got " << cond->GetLosCondition () << " expected condition " << testVector.m_losCond);
139  NS_TEST_ASSERT_MSG_EQ (cond->GetLosCondition (), testVector.m_losCond, " Got unexpected channel condition");
140  }
141 
142  Simulator::Destroy ();
143 }
144 
151 {
152 public:
154 };
155 
157  : TestSuite ("buildings-channel-condition-model", UNIT)
158 {
160 }
161 
static BuildingsChannelConditionModelsTestSuite BuildingsChannelConditionModelsTestSuite
Static variable for test initialization.
Test case for the class BuildingsChannelConditionModel.
virtual void DoRun(void)
Builds the simulation scenario and perform the tests.
TestVectors< TestVector > m_testVectors
array containg all the test vectors
Test suite for the buildings channel condition model.
a 3d box
Definition: box.h:35
LosConditionValue
Possible values for Line-of-Sight condition.
mobility buildings information (to be used by mobility models)
void SetPosition(const Vector &position)
keep track of a set of node pointers.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
A simple way to store test vectors (for stimulus or from responses)
Definition: test.h:1251
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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:141
nodes
Definition: first.py:32
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ChannelCondition::LosConditionValue m_losCond
the correct channel condition