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 
39 {
40 public:
45 
50 
51 private:
55  virtual void DoRun (void);
56 
60  typedef struct
61  {
62  Vector m_positionA;
63  Vector m_positionB;
65  } TestVector;
66 
68 };
69 
71  : TestCase ("Test case for the BuildingsChannelConditionModel"), m_testVectors ()
72 {
73 }
74 
76 {
77 }
78 
79 void
81 {
82  TestVector testVector;
83 
84  testVector.m_positionA = Vector (0.0, 5.0, 1.5);
85  testVector.m_positionB = Vector (20.0, 5.0, 1.5);
86  testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
87  m_testVectors.Add (testVector);
88 
89  testVector.m_positionA = Vector (0.0, 11.0, 1.5);
90  testVector.m_positionB = Vector (20.0, 11.0, 1.5);
91  testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
92  m_testVectors.Add (testVector);
93 
94  testVector.m_positionA = Vector (5.0, 5.0, 1.5);
95  testVector.m_positionB = Vector (20.0, 5.0, 1.5);
96  testVector.m_losCond = ChannelCondition::LosConditionValue::NLOS;
97  m_testVectors.Add (testVector);
98 
99  testVector.m_positionA = Vector (4.0, 5.0, 1.5);
100  testVector.m_positionB = Vector (5.0, 5.0, 1.5);
101  testVector.m_losCond = ChannelCondition::LosConditionValue::LOS;
102  m_testVectors.Add (testVector);
103 
104  // Deploy nodes and building and get the channel condition
106  nodes.Create (2);
107 
108  Ptr<MobilityModel> a = CreateObject<ConstantPositionMobilityModel> ();
109  nodes.Get (0)->AggregateObject (a);
110 
111  Ptr<MobilityModel> b = CreateObject<ConstantPositionMobilityModel> ();
112  nodes.Get (1)->AggregateObject (b);
113 
114  Ptr<BuildingsChannelConditionModel> condModel = CreateObject<BuildingsChannelConditionModel> ();
115 
116  Ptr<Building> building = Create<Building> ();
117  building->SetNRoomsX (1);
118  building->SetNRoomsY (1);
119  building->SetNFloors (1);
120  building->SetBoundaries (Box (0.0, 10.0, 0.0, 10.0, 0.0, 5.0));
121 
122  BuildingsHelper::Install (nodes);
123 
124  for (uint32_t i = 0; i < m_testVectors.GetN (); ++i)
125  {
126  testVector = m_testVectors.Get (i);
127  a->SetPosition (testVector.m_positionA);
128  b->SetPosition (testVector.m_positionB);
130  buildingInfoA->MakeConsistent (a);
132  buildingInfoA->MakeConsistent (b);
133  Ptr<ChannelCondition> cond = condModel->GetChannelCondition (a, b);
134 
135  NS_LOG_DEBUG ("Got " << cond->GetLosCondition () << " expected condition " << testVector.m_losCond);
136  NS_TEST_ASSERT_MSG_EQ (cond->GetLosCondition (), testVector.m_losCond, " Got unexpected channel condition");
137  }
138 
139  Simulator::Destroy ();
140 }
141 
146 {
147 public:
149 };
150 
152  : TestSuite ("buildings-channel-condition-model", UNIT)
153 {
155 }
156 
static BuildingsChannelConditionModelsTestSuite BuildingsChannelConditionModelsTestSuite
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:1154
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:1344
A simple way to store test vectors (for stimulus or from responses)
Definition: test.h:1407
#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:166
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