satellite-geo-coordinate-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd
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: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
27 #include "../utils/satellite-env-variables.h"
28 
29 #include "ns3/geo-coordinate.h"
30 #include "ns3/log.h"
31 #include "ns3/simulator.h"
32 #include "ns3/singleton.h"
33 #include "ns3/test.h"
34 
35 using namespace ns3;
36 
37 // #define PRINT_POSITION_INFO // uncomment to see info while executing test
38 
39 #ifdef PRINT_POSITION_INFO
40 static void
41 PrintPositionInfo(GeoCoordinate pos)
42 {
43  Vector pos2 = pos.ToVector();
44 
45  // sets number of decimal places
46  std::cout.setf(std::ios::fixed, std::ios::floatfield);
47  std::cout.precision(15);
48  std::cout << pos.GetRefEllipsoid()
49  << " position="
50  "x="
51  << pos2.x << ", y=" << pos2.y << ", z=" << pos2.z
52  << ", longitude=" << pos.GetLongitude() << ", latitude=" << pos.GetLatitude()
53  << ", altitude=" << pos.GetAltitude() << std::endl;
54 }
55 #endif
56 
60 class GeoCoordinateTestCase : public TestCase
61 {
62  public:
64  virtual ~GeoCoordinateTestCase();
65 
66  private:
67  virtual void DoRun(void);
68  void Validate(GeoCoordinate& coord1, GeoCoordinate& coord2);
69 };
70 
72  : TestCase("Test Geo Coordinate correctness")
73 {
74 }
75 
77 {
78 }
79 
80 void
82 {
83  GeoCoordinate position1;
84  GeoCoordinate position2;
85 
86  // Set simulation output details
87  Singleton<SatEnvVariables>::Get()->DoInitialize();
88  Singleton<SatEnvVariables>::Get()->SetOutputVariables("test-geo-coordinate", "", true);
89 
90  for (int i = -180; i <= 180; i += 30)
91  {
92  position1 = GeoCoordinate(i / 2, i, i * 30);
93  position2 = GeoCoordinate(position1.ToVector());
94 
95  Validate(position1, position2);
96 
97  position1 = GeoCoordinate(i / 2, i, i * 30, GeoCoordinate::SPHERE);
98  position2 = GeoCoordinate(position1.ToVector(), GeoCoordinate::SPHERE);
99 
100  Validate(position1, position2);
101 
102  position1 = GeoCoordinate(i / 2, i, i * 30, GeoCoordinate::WGS84);
103  position2 = GeoCoordinate(position1.ToVector(), GeoCoordinate::WGS84);
104 
105  Validate(position1, position2);
106 
107  position1 = GeoCoordinate(i / 2, i, i * 30, GeoCoordinate::GRS80);
108  position2 = GeoCoordinate(position1.ToVector(), GeoCoordinate::GRS80);
109 
110  Validate(position1, position2);
111  }
112 
113  Singleton<SatEnvVariables>::Get()->DoDispose();
114 }
115 
116 void
118 {
119  double altDiff, lonDiff, latDiff = 0;
120  bool altSignSame, lonSignSame, latSignSame = false;
121 
122 #ifdef PRINT_POSITION_INFO
123  PrintPositionInfo(position1);
124  PrintPositionInfo(position2);
125 #endif
126 
127  altDiff = std::abs(position1.GetAltitude() - position2.GetAltitude());
128  lonDiff = std::abs(position1.GetLongitude() - position2.GetLongitude());
129  latDiff = std::abs(position1.GetLatitude() - position2.GetLatitude());
130 
131  altSignSame = ((position1.GetAltitude() > 0) == (position2.GetAltitude() > 0));
132  lonSignSame = ((position1.GetLongitude() > 0) == (position2.GetLongitude() > 0));
133  latSignSame = ((position1.GetLatitude() > 0) == (position2.GetLatitude() > 0));
134 
135  // check that is difference is ok
136  NS_TEST_ASSERT_MSG_LT(altDiff, 0.0001, "Altitude difference too big!");
137  NS_TEST_ASSERT_MSG_LT(lonDiff, 0.0001, "Longitude difference too big!");
138  NS_TEST_ASSERT_MSG_LT(latDiff, 0.0001, "Latitude difference too big!");
139 
140  NS_TEST_ASSERT_MSG_EQ(altSignSame, true, "Altitude signs are different.");
141  NS_TEST_ASSERT_MSG_EQ(lonSignSame, true, "Longitude signs are different.");
142  NS_TEST_ASSERT_MSG_EQ(latSignSame, true, "Latitude signs are different.");
143 }
144 
148 class GeoCoordinateTestSuite : public TestSuite
149 {
150  public:
152 };
153 
155  : TestSuite("geo-coordinate-test", UNIT)
156 {
157  AddTestCase(new GeoCoordinateTestCase, TestCase::QUICK);
158 }
159 
160 // Do allocate an instance of this TestSuite
Test case to unit test that GeoCoordinate can be created with valid values.
void Validate(GeoCoordinate &coord1, GeoCoordinate &coord2)
Test suite for GeoCoordinate unit test cases.
GeoCoordinate class is used to store and operate with geodetic coordinates.
double GetAltitude() const
Gets altitude value of coordinate.
double GetLatitude() const
Gets latitude value of coordinate.
ReferenceEllipsoid_t GetRefEllipsoid()
Gets reference ellipsoid used by GeoCoordinate object.
double GetLongitude() const
Gets longitude value of coordinate.
Vector ToVector() const
Converts Geodetic coordinates to Cartesian coordinates.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static GeoCoordinateTestSuite geoCoordinateTestSuite