1 //==============================================================================
2 //
3 // This file is part of GPSTk, the GPS Toolkit.
4 //
5 // The GPSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GPSTk 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 Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GPSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2020, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38
39 #include "SatelliteSystem.hpp"
40 #include "SatID.hpp"
41
42 #include "TestUtil.hpp"
43 #include <iostream>
44 #include <string>
45 #include <sstream>
46 #include <map>
47
48 namespace gpstk
49 {
operator <<(std::ostream & s,const SatelliteSystem sys)50 std::ostream& operator<<(std::ostream& s, const SatelliteSystem sys)
51 {
52 s << gpstk::StringUtils::asString(sys);
53 return s;
54 }
55 }
56
57 class SatID_T
58 {
59 public:
SatID_T()60 SatID_T() {} // Default Constructor, set the precision value
~SatID_T()61 ~SatID_T() {} // Default Desructor
62
63
64 /// ensure the constructors set the values properly
initializationTest()65 unsigned initializationTest()
66 {
67 TUDEF("SatID", "Constructor");
68
69 gpstk::SatID compare1(5, gpstk::SatelliteSystem (1));
70 TUASSERTE(int, 5, compare1.id);
71 TUASSERTE(gpstk::SatelliteSystem,
72 gpstk::SatelliteSystem(1),
73 compare1.system);
74
75 gpstk::SatID compare2(0, gpstk::SatelliteSystem (12));
76 TUASSERTE(int, 0, compare2.id);
77 TUASSERTE(gpstk::SatelliteSystem,
78 gpstk::SatelliteSystem(12),
79 compare2.system);
80
81 gpstk::SatID compare3(-1, gpstk::SatelliteSystem (-1));
82 TUASSERTE(int, -1, compare3.id);
83 TUASSERTE(gpstk::SatelliteSystem,
84 gpstk::SatelliteSystem(-1),
85 compare3.system);
86
87 TURETURN();
88 }
89
90
91 /// check the output from SatID::dump meets its expectations
dumpTest()92 unsigned dumpTest()
93 {
94 TUDEF("SatID", "dump(std::stream)");
95
96 //---------------------------------------------------------------------
97 //Output for GPS satellite and single digit ID
98 //---------------------------------------------------------------------
99 gpstk::SatID sat1(5, gpstk::SatelliteSystem (1));
100 std::string outputString1, compareString1;
101 std::stringstream outputStream1;
102
103 sat1.dump(outputStream1);
104 outputString1 = outputStream1.str();
105 compareString1 = "GPS 5";
106 TUASSERTE(std::string, compareString1, outputString1);
107
108 //---------------------------------------------------------------------
109 //Output for invalid UserDefined satellite and triple digit ID
110 //---------------------------------------------------------------------
111 gpstk::SatID sat2(110, gpstk::SatelliteSystem (11));
112 std::string outputString2, compareString2;
113 std::stringstream outputStream2;
114
115 sat2.dump(outputStream2);
116 outputString2 = outputStream2.str();
117 compareString2 = "UserDefined 110";
118 TUASSERTE(std::string, compareString2, outputString2);
119
120 //---------------------------------------------------------------------
121 //Output for invalid satellite and negative ID
122 //---------------------------------------------------------------------
123 gpstk::SatID sat3(-10, gpstk::SatelliteSystem (50));
124 std::string outputString3, compareString3;
125 std::stringstream outputStream3;
126
127 sat3.dump(outputStream3);
128 outputString3 = outputStream3.str();
129 compareString3 = "??? -10";
130 TUASSERTE(std::string, compareString3, outputString3);
131
132 TURETURN();
133
134 }
135
136
137 /// check that a SatID object can be reported as a string
asStringTest()138 unsigned asStringTest()
139 {
140 TUDEF("SatID", "asStringTest");
141
142 std::string compareString1,compareString2,compareString3;
143
144 //---------------------------------------------------------------------
145 //Output for GPS satellite and single digit ID
146 //---------------------------------------------------------------------
147 gpstk::SatID sat1(5, gpstk::SatelliteSystem (1));
148 compareString1 = "GPS 5";
149 TUASSERTE(std::string, compareString1,gpstk::StringUtils::asString(sat1));
150
151 //---------------------------------------------------------------------
152 //Output for invalid UserDefined satellite and triple digit ID
153 //---------------------------------------------------------------------
154 gpstk::SatID sat2(110, gpstk::SatelliteSystem (11));
155 compareString2 = "UserDefined 110";
156 TUASSERTE(std::string, compareString2,gpstk::StringUtils::asString(sat2));
157
158 //---------------------------------------------------------------------
159 //Output for invalid satellite and negative ID
160 //---------------------------------------------------------------------
161 gpstk::SatID sat3(-10, gpstk::SatelliteSystem (50));
162 compareString3 = "?? -10";
163 TUASSERTE(std::string, compareString3,gpstk::StringUtils::asString(sat3));
164
165 TURETURN();
166 }
167
168
169 /// verify the various operators of the SatID class
operatorTest()170 unsigned operatorTest()
171 {
172 TUDEF("SatID", "OperatorEquivalence");
173
174 gpstk::SatID compare (5, gpstk::SatelliteSystem(2));
175 gpstk::SatID equivalent (5, gpstk::SatelliteSystem(2));
176 gpstk::SatID lessThanID (2, gpstk::SatelliteSystem(2));
177 gpstk::SatID diffSatSys (5, gpstk::SatelliteSystem(5));
178 gpstk::SatID diffEvery (2, gpstk::SatelliteSystem(5));
179 gpstk::SatID diffEvery2 (7, gpstk::SatelliteSystem(1));
180 gpstk::SatID redirected (6, gpstk::SatelliteSystem(1));
181
182 //---------------------------------------------------------------------
183 //Does the == Operator function?
184 //---------------------------------------------------------------------
185 TUASSERT( compare == equivalent);
186 TUASSERT(!(compare == lessThanID));
187 TUASSERT(!(compare == diffSatSys));
188
189 TUCSM("operator!=");
190 //---------------------------------------------------------------------
191 //Does the != Operator function?
192 //---------------------------------------------------------------------
193 TUASSERT(!(compare != equivalent));
194 TUASSERT( compare != lessThanID);
195 TUASSERT( compare != diffSatSys);
196
197 TUCSM("operator<");
198 //---------------------------------------------------------------------
199 //Does the < Operator function?
200 //---------------------------------------------------------------------
201
202 //ID only comparisons
203 TUASSERT(!(compare < lessThanID));
204 TUASSERT( lessThanID < compare);
205 TUASSERT(!(compare < equivalent));
206
207 //SatelliteSystem only comparisons
208 TUASSERT( compare < diffSatSys);
209 TUASSERT(!(diffSatSys < compare));
210
211 //Completely different comparisons
212 TUASSERT( compare < diffEvery);
213 TUASSERT(!(diffEvery < compare));
214 TUASSERT(!(compare < diffEvery2));
215 TUASSERT( diffEvery2 < compare);
216
217 TUCSM("operator>");
218 //---------------------------------------------------------------------
219 //Does the > Operator function?
220 //---------------------------------------------------------------------
221
222 //ID only comparisons
223 TUASSERT((compare > lessThanID));
224 TUASSERT(!(lessThanID > compare));
225 TUASSERT(!(compare > equivalent));
226
227 //SatelliteSystem only comparisons
228 TUASSERT(!(compare > diffSatSys));
229 TUASSERT((diffSatSys > compare));
230
231 //Completely different comparisons
232 TUASSERT(!(compare > diffEvery));
233 TUASSERT((diffEvery > compare));
234 TUASSERT((compare > diffEvery2));
235 TUASSERT(!(diffEvery2 > compare));
236
237 TUCSM("operator<=");
238 //---------------------------------------------------------------------
239 //Does the <= Operator function?
240 //---------------------------------------------------------------------
241
242 //ID only comparisons
243 TUASSERT(!(compare <= lessThanID));
244 TUASSERT( lessThanID <= compare);
245 TUASSERT((compare <= equivalent));
246
247 //SatelliteSystem only comparisons
248 TUASSERT( compare <= diffSatSys);
249 TUASSERT(!(diffSatSys <= compare));
250
251 //Completely different comparisons
252 TUASSERT( compare <= diffEvery);
253 TUASSERT(!(diffEvery <= compare));
254 TUASSERT(!(compare <= diffEvery2));
255 TUASSERT( diffEvery2 <= compare);
256
257 TUCSM("operator>=");
258 //---------------------------------------------------------------------
259 //Does the >= Operator function?
260 //---------------------------------------------------------------------
261
262 //ID only comparisons
263 TUASSERT((compare >= lessThanID));
264 TUASSERT(!(lessThanID >= compare));
265 TUASSERT((compare >= equivalent));
266
267 //SatelliteSystem only comparisons
268 TUASSERT(!(compare >= diffSatSys));
269 TUASSERT((diffSatSys >= compare));
270
271 //Completely different comparisons
272 TUASSERT(!(compare >= diffEvery));
273 TUASSERT((diffEvery >= compare));
274 TUASSERT((compare >= diffEvery2));
275 TUASSERT(!(diffEvery2 >= compare));
276
277 TUCSM("operator<<");
278 //---------------------------------------------------------------------
279 //Does the << Operator function?
280 //---------------------------------------------------------------------
281
282 std::string outputString, compareString;
283 std::stringstream outputStream;
284 outputStream << redirected;
285 outputString = outputStream.str();
286 compareString = "GPS 6";
287
288 TUASSERTE(std::string, compareString, outputString);
289
290 TURETURN();
291 }
292
293
294 /// check that the isValid method returns the proper value
isValidTest()295 unsigned isValidTest()
296 {
297 TUDEF("SatID", "isValid()");
298
299 gpstk::SatID compare1(5 , gpstk::SatelliteSystem(1));
300 gpstk::SatID compare2(1 , gpstk::SatelliteSystem(15));
301 gpstk::SatID compare3(-1 , gpstk::SatelliteSystem(-1));
302 gpstk::SatID compare4(100, gpstk::SatelliteSystem(-1));
303 gpstk::SatID compare5(0 , gpstk::SatelliteSystem(1));
304 gpstk::SatID compare6(32 , gpstk::SatelliteSystem(1));
305 gpstk::SatID compare7(50 , gpstk::SatelliteSystem(1));
306 gpstk::SatID compare8(0 , gpstk::SatelliteSystem(1));
307 gpstk::SatID compare9(-3 , gpstk::SatelliteSystem(1));
308
309 TUASSERT(compare1.isValid());
310 TUASSERT(compare2.isValid());
311 TUASSERT(!compare3.isValid());
312 TUASSERT(!compare4.isValid());
313 TUASSERT(!compare5.isValid());
314 TUASSERT(compare6.isValid());
315 TUASSERT(!compare7.isValid());
316 TUASSERT(!compare8.isValid());
317 TUASSERT(!compare9.isValid());
318
319 TURETURN();
320 }
321
322 /// Regression testing for string <-> enum translation
stringConvertTest()323 unsigned stringConvertTest()
324 {
325 TUDEF("SatID", "convertSatelliteSystemToString");
326 std::map<gpstk::SatelliteSystem, std::string> testVals =
327 {
328 { gpstk::SatelliteSystem::GPS, "GPS" },
329 { gpstk::SatelliteSystem::Galileo, "Galileo" },
330 { gpstk::SatelliteSystem::Glonass, "GLONASS" },
331 { gpstk::SatelliteSystem::Geosync, "Geostationary" },
332 { gpstk::SatelliteSystem::LEO, "LEO" },
333 { gpstk::SatelliteSystem::Transit, "Transit" },
334 { gpstk::SatelliteSystem::BeiDou, "BeiDou" },
335 { gpstk::SatelliteSystem::QZSS, "QZSS" },
336 { gpstk::SatelliteSystem::IRNSS, "IRNSS" },
337 { gpstk::SatelliteSystem::Mixed, "Mixed" },
338 { gpstk::SatelliteSystem::UserDefined, "UserDefined" },
339 { gpstk::SatelliteSystem::Unknown, "Unknown" }
340 };
341
342 for (const auto& tvi : testVals)
343 {
344 TUCSM("convertSatelliteSystemToString");
345 TUASSERTE(std::string, tvi.second,
346 gpstk::convertSatelliteSystemToString(tvi.first));
347 TUCSM("convertStringToSatelliteSystem");
348 TUASSERTE(gpstk::SatelliteSystem, tvi.first,
349 gpstk::convertStringToSatelliteSystem(tvi.second));
350 }
351
352 TURETURN();
353 }
354 };
355
356
main()357 int main() //Main function to initialize and run all tests above
358 {
359 SatID_T testClass;
360 unsigned errorTotal = 0;
361
362 errorTotal += testClass.initializationTest();
363 errorTotal += testClass.dumpTest();
364 errorTotal += testClass.operatorTest();
365 errorTotal += testClass.isValidTest();
366 errorTotal += testClass.stringConvertTest();
367
368 std::cout << "Total Failures for " << __FILE__ << ": " << errorTotal
369 << std::endl;
370
371 return errorTotal; //Return the total number of errors
372 }
373