A Discrete-Event Network Simulator
API
test-isotropic-antenna.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 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 #include <ns3/log.h>
22 #include <ns3/test.h>
23 #include <ns3/isotropic-antenna-model.h>
24 #include <cmath>
25 #include <string>
26 #include <iostream>
27 #include <sstream>
28 
29 using namespace ns3;
30 
32 {
33 public:
34  static std::string BuildNameString (Angles a);
35  IsotropicAntennaModelTestCase (Angles a, double expectedGainDb);
36 
37 
38 private:
39  virtual void DoRun (void);
40 
43 };
44 
46 {
47  std::ostringstream oss;
48  oss << "theta=" << a.theta << " , phi=" << a.phi;
49  return oss.str ();
50 }
51 
52 
54  : TestCase (BuildNameString (a)),
55  m_a (a),
56  m_expectedGain (expectedGainDb)
57 {
58 }
59 
60 void
62 {
63  Ptr<IsotropicAntennaModel> a = CreateObject<IsotropicAntennaModel> ();
64  double actualGain = a->GetGainDb (m_a);
65  NS_TEST_EXPECT_MSG_EQ_TOL (actualGain, m_expectedGain, 0.01, "wrong value of the radiation pattern");
66 }
67 
68 
69 
70 
72 {
73 public:
75 };
76 
78  : TestSuite ("isotropic-antenna-model", UNIT)
79 {
80  AddTestCase (new IsotropicAntennaModelTestCase (Angles (0, 0), 0.0), TestCase::QUICK);
81  AddTestCase (new IsotropicAntennaModelTestCase (Angles (0, M_PI), 0.0), TestCase::QUICK);
82  AddTestCase (new IsotropicAntennaModelTestCase (Angles (0, M_PI_2), 0.0), TestCase::QUICK);
83  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI, 0), 0.0), TestCase::QUICK);
84  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI, M_PI), 0.0), TestCase::QUICK);
85  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI, M_PI_2), 0.0), TestCase::QUICK);
86  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI_2, 0), 0.0), TestCase::QUICK);
87  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI_2, M_PI), 0.0), TestCase::QUICK);
88  AddTestCase (new IsotropicAntennaModelTestCase (Angles (M_PI_2, M_PI_2), 0.0), TestCase::QUICK);
89 
90 };
91 
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
A suite of tests to run.
Definition: test.h:1342
double theta
the inclination angle in radians
Definition: angles.h:117
encapsulates test code
Definition: test.h:1155
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if ...
Definition: test.h:565
static IsotropicAntennaModelTestSuite staticIsotropicAntennaModelTestSuiteInstance
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static std::string BuildNameString(Angles a)
virtual double GetGainDb(Angles a)
this method is expected to be re-implemented by each antenna model
IsotropicAntennaModelTestCase(Angles a, double expectedGainDb)
double phi
the azimuth angle in radians
Definition: angles.h:111
virtual void DoRun(void)
Implementation to actually run this TestCase.
struct holding the azimuth and inclination angles of spherical coordinates.
Definition: angles.h:71