SatID_T.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk 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 GNSSTk 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 GNSSTk; 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-2022, 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 gnsstk
49 {
50  std::ostream& operator<<(std::ostream& s, const SatelliteSystem sys)
51  {
53  return s;
54  }
55 }
56 
57 class SatID_T
58 {
59 public:
60  SatID_T() {} // Default Constructor, set the precision value
61  ~SatID_T() {} // Default Desructor
62 
63 
65  unsigned initializationTest()
66  {
67  TUDEF("SatID", "Constructor");
68 
69  gnsstk::SatID compare1(5, gnsstk::SatelliteSystem (1));
70  TUASSERTE(int, 5, compare1.id);
73  compare1.system);
74 
75  gnsstk::SatID compare2(0, gnsstk::SatelliteSystem (12));
76  TUASSERTE(int, 0, compare2.id);
79  compare2.system);
80 
81  gnsstk::SatID compare3(-1, gnsstk::SatelliteSystem (-1));
82  TUASSERTE(int, -1, compare3.id);
85  compare3.system);
86 
87  gnsstk::SatID ws1;
88  TUASSERTE(bool, false, ws1.wildId);
89  TUASSERTE(bool, false, ws1.wildSys);
90  gnsstk::SatID ws2(99);
91  TUASSERTE(int, 99, ws2.id);
92  TUASSERTE(bool, false, ws2.wildId);
93  TUASSERTE(bool, true, ws2.wildSys);
96  ws3.system);
97  TUASSERTE(bool, true, ws3.wildId);
98  TUASSERTE(bool, false, ws3.wildSys);
100  TUASSERTE(int, -65, ws4.id);
102  ws4.system);
103  TUASSERTE(bool, false, ws4.wildId);
104  TUASSERTE(bool, false, ws4.wildSys);
106  gnsstk::SatID ws5(foo);
107  TUASSERTE(int, 25, ws5.id);
109  ws5.system);
110  TUASSERTE(bool, false, ws5.wildId);
111  TUASSERTE(bool, false, ws5.wildSys);
112 
113  TURETURN();
114  }
115 
116 
118  unsigned dumpTest()
119  {
120  TUDEF("SatID", "dump(std::stream)");
121 
122  //---------------------------------------------------------------------
123  //Output for GPS satellite and single digit ID
124  //---------------------------------------------------------------------
126  std::string outputString1, compareString1;
127  std::stringstream outputStream1;
128 
129  sat1.dump(outputStream1);
130  outputString1 = outputStream1.str();
131  compareString1 = "GPS 5";
132  TUASSERTE(std::string, compareString1, outputString1);
133 
134  //---------------------------------------------------------------------
135  //Output for invalid UserDefined satellite and triple digit ID
136  //---------------------------------------------------------------------
137  gnsstk::SatID sat2(110, gnsstk::SatelliteSystem (11));
138  std::string outputString2, compareString2;
139  std::stringstream outputStream2;
140 
141  sat2.dump(outputStream2);
142  outputString2 = outputStream2.str();
143  compareString2 = "UserDefined 110";
144  TUASSERTE(std::string, compareString2, outputString2);
145 
146  //---------------------------------------------------------------------
147  //Output for invalid satellite and negative ID
148  //---------------------------------------------------------------------
149  gnsstk::SatID sat3(-10, gnsstk::SatelliteSystem (50));
150  std::string outputString3, compareString3;
151  std::stringstream outputStream3;
152 
153  sat3.dump(outputStream3);
154  outputString3 = outputStream3.str();
155  compareString3 = "??? -10";
156  TUASSERTE(std::string, compareString3, outputString3);
157 
158  TURETURN();
159 
160  }
161 
162 
164  unsigned asStringTest()
165  {
166  TUDEF("SatID", "asStringTest");
167 
168  std::string compareString1,compareString2,compareString3;
169 
170  //---------------------------------------------------------------------
171  //Output for GPS satellite and single digit ID
172  //---------------------------------------------------------------------
174  compareString1 = "GPS 5";
175  TUASSERTE(std::string, compareString1,gnsstk::StringUtils::asString(sat1));
176 
177  //---------------------------------------------------------------------
178  //Output for invalid UserDefined satellite and triple digit ID
179  //---------------------------------------------------------------------
180  gnsstk::SatID sat2(110, gnsstk::SatelliteSystem (11));
181  compareString2 = "UserDefined 110";
182  TUASSERTE(std::string, compareString2,gnsstk::StringUtils::asString(sat2));
183 
184  //---------------------------------------------------------------------
185  //Output for invalid satellite and negative ID
186  //---------------------------------------------------------------------
187  gnsstk::SatID sat3(-10, gnsstk::SatelliteSystem (50));
188  compareString3 = "??? -10";
189  TUASSERTE(std::string, compareString3,gnsstk::StringUtils::asString(sat3));
190 
191  TURETURN();
192  }
193 
194 
196  unsigned operatorTest()
197  {
198  TUDEF("SatID", "OperatorEquivalence");
199 
200  gnsstk::SatID compare (5, gnsstk::SatelliteSystem(2));
201  gnsstk::SatID equivalent (5, gnsstk::SatelliteSystem(2));
202  gnsstk::SatID lessThanID (2, gnsstk::SatelliteSystem(2));
203  gnsstk::SatID diffSatSys (5, gnsstk::SatelliteSystem(5));
204  gnsstk::SatID diffEvery (2, gnsstk::SatelliteSystem(5));
205  gnsstk::SatID diffEvery2 (7, gnsstk::SatelliteSystem(1));
206  gnsstk::SatID redirected (6, gnsstk::SatelliteSystem(1));
207 
208  //---------------------------------------------------------------------
209  //Does the == Operator function?
210  //---------------------------------------------------------------------
211  TUASSERT( compare == equivalent);
212  TUASSERT(!(compare == lessThanID));
213  TUASSERT(!(compare == diffSatSys));
214 
215  TUCSM("operator!=");
216  //---------------------------------------------------------------------
217  //Does the != Operator function?
218  //---------------------------------------------------------------------
219  TUASSERT(!(compare != equivalent));
220  TUASSERT( compare != lessThanID);
221  TUASSERT( compare != diffSatSys);
222 
223  TUCSM("operator<");
224  //---------------------------------------------------------------------
225  //Does the < Operator function?
226  //---------------------------------------------------------------------
227 
228  //ID only comparisons
229  TUASSERT(!(compare < lessThanID));
230  TUASSERT( lessThanID < compare);
231  TUASSERT(!(compare < equivalent));
232 
233  //SatelliteSystem only comparisons
234  TUASSERT( compare < diffSatSys);
235  TUASSERT(!(diffSatSys < compare));
236 
237  //Completely different comparisons
238  TUASSERT( compare < diffEvery);
239  TUASSERT(!(diffEvery < compare));
240  TUASSERT(!(compare < diffEvery2));
241  TUASSERT( diffEvery2 < compare);
242 
243  TUCSM("operator>");
244  //---------------------------------------------------------------------
245  //Does the > Operator function?
246  //---------------------------------------------------------------------
247 
248  //ID only comparisons
249  TUASSERT((compare > lessThanID));
250  TUASSERT(!(lessThanID > compare));
251  TUASSERT(!(compare > equivalent));
252 
253  //SatelliteSystem only comparisons
254  TUASSERT(!(compare > diffSatSys));
255  TUASSERT((diffSatSys > compare));
256 
257  //Completely different comparisons
258  TUASSERT(!(compare > diffEvery));
259  TUASSERT((diffEvery > compare));
260  TUASSERT((compare > diffEvery2));
261  TUASSERT(!(diffEvery2 > compare));
262 
263  TUCSM("operator<=");
264  //---------------------------------------------------------------------
265  //Does the <= Operator function?
266  //---------------------------------------------------------------------
267 
268  //ID only comparisons
269  TUASSERT(!(compare <= lessThanID));
270  TUASSERT( lessThanID <= compare);
271  TUASSERT((compare <= equivalent));
272 
273  //SatelliteSystem only comparisons
274  TUASSERT( compare <= diffSatSys);
275  TUASSERT(!(diffSatSys <= compare));
276 
277  //Completely different comparisons
278  TUASSERT( compare <= diffEvery);
279  TUASSERT(!(diffEvery <= compare));
280  TUASSERT(!(compare <= diffEvery2));
281  TUASSERT( diffEvery2 <= compare);
282 
283  TUCSM("operator>=");
284  //---------------------------------------------------------------------
285  //Does the >= Operator function?
286  //---------------------------------------------------------------------
287 
288  //ID only comparisons
289  TUASSERT((compare >= lessThanID));
290  TUASSERT(!(lessThanID >= compare));
291  TUASSERT((compare >= equivalent));
292 
293  //SatelliteSystem only comparisons
294  TUASSERT(!(compare >= diffSatSys));
295  TUASSERT((diffSatSys >= compare));
296 
297  //Completely different comparisons
298  TUASSERT(!(compare >= diffEvery));
299  TUASSERT((diffEvery >= compare));
300  TUASSERT((compare >= diffEvery2));
301  TUASSERT(!(diffEvery2 >= compare));
302 
303  TUCSM("operator==");
308  gnsstk::SatID ws5(1); // wildcard system
309  gnsstk::SatID ws6(gnsstk::SatelliteSystem::GPS); // wildcard satellite
310  gnsstk::SatID ws7(gnsstk::SatelliteSystem::QZSS); // wildcard satellite
311  gnsstk::SatID ws8; // wildcard sat and sys
312  // we have to set wildcard flags explicitly for ws8
313  ws8.makeWild();
314  gnsstk::SatID ws9(2); // wildcard system
315  // sanity checks
316  TUASSERTE(bool, false, ws5.wildId);
317  TUASSERTE(bool, true, ws5.wildSys);
318  TUASSERTE(bool, true, ws6.wildId);
319  TUASSERTE(bool, false, ws6.wildSys);
320  TUASSERTE(bool, true, ws7.wildId);
321  TUASSERTE(bool, false, ws7.wildSys);
322  TUASSERTE(bool, true, ws8.wildId);
323  TUASSERTE(bool, true, ws8.wildSys);
324  TUASSERTE(bool, false, ws9.wildId);
325  TUASSERTE(bool, true, ws9.wildSys);
326  // actual tests
327  TUASSERTE(bool, true, ws1 == ws2);
328  TUASSERTE(bool, false, ws1 == ws3);
329  TUASSERTE(bool, false, ws1 == ws4);
330  TUASSERTE(bool, true, ws1 == ws5);
331  TUASSERTE(bool, true, ws1 == ws6);
332  TUASSERTE(bool, false, ws1 == ws7);
333  TUASSERTE(bool, true, ws1 == ws8);
334  TUASSERTE(bool, false, ws1 == ws9);
335 
336  TUCSM("operator<<");
337  //---------------------------------------------------------------------
338  //Does the << Operator function?
339  //---------------------------------------------------------------------
340 
341  std::string outputString, compareString;
342  std::stringstream outputStream;
343  outputStream << redirected;
344  outputString = outputStream.str();
345  compareString = "GPS 6";
346 
347  TUASSERTE(std::string, compareString, outputString);
348 
349  TURETURN();
350  }
351 
352 
353  unsigned lessThanTest()
354  {
355  TUDEF("SatID", "operator<");
360  gnsstk::SatID ws5(1); // wildcard system
361  gnsstk::SatID ws6(gnsstk::SatelliteSystem::GPS); // wildcard satellite
362  gnsstk::SatID ws7(gnsstk::SatelliteSystem::QZSS); // wildcard satellite
363  gnsstk::SatID ws8; // wildcard sat and sys
364  // we have to set wildcard flags explicitly for ws8
365  ws8.makeWild();
366  gnsstk::SatID ws9(2); // wildcard system
367  // sanity checks
368  TUASSERTE(bool, false, ws5.wildId);
369  TUASSERTE(bool, true, ws5.wildSys);
370  TUASSERTE(bool, true, ws6.wildId);
371  TUASSERTE(bool, false, ws6.wildSys);
372  TUASSERTE(bool, true, ws7.wildId);
373  TUASSERTE(bool, false, ws7.wildSys);
374  TUASSERTE(bool, true, ws8.wildId);
375  TUASSERTE(bool, true, ws8.wildSys);
376  TUASSERTE(bool, false, ws9.wildId);
377  TUASSERTE(bool, true, ws9.wildSys);
378  // actual tests
379  TUASSERTE(bool, false, ws1 < ws2);
380  TUASSERTE(bool, false, ws2 < ws1);
381  TUASSERTE(bool, true, ws1 < ws3);
382  TUASSERTE(bool, false, ws3 < ws1);
383  TUASSERTE(bool, true, ws1 < ws4);
384  TUASSERTE(bool, false, ws4 < ws1);
385  TUASSERTE(bool, false, ws1 < ws5);
386  TUASSERTE(bool, false, ws5 < ws1);
387  TUASSERTE(bool, false, ws1 < ws6);
388  TUASSERTE(bool, false, ws6 < ws1);
389  TUASSERTE(bool, true, ws1 < ws7);
390  TUASSERTE(bool, false, ws7 < ws1);
391  TUASSERTE(bool, false, ws1 < ws8);
392  TUASSERTE(bool, false, ws8 < ws1);
393  TUASSERTE(bool, true, ws1 < ws9);
394  TUASSERTE(bool, false, ws9 < ws1);
395  TURETURN();
396  }
397 
398 
400  unsigned isValidTest()
401  {
402  TUDEF("SatID", "isValid()");
403 
404  gnsstk::SatID compare1(5 , gnsstk::SatelliteSystem(1));
405  gnsstk::SatID compare2(1 , gnsstk::SatelliteSystem(15));
406  gnsstk::SatID compare3(-1 , gnsstk::SatelliteSystem(-1));
407  gnsstk::SatID compare4(100, gnsstk::SatelliteSystem(-1));
408  gnsstk::SatID compare5(0 , gnsstk::SatelliteSystem(1));
409  gnsstk::SatID compare6(32 , gnsstk::SatelliteSystem(1));
410  gnsstk::SatID compare7(50 , gnsstk::SatelliteSystem(1));
411  gnsstk::SatID compare8(0 , gnsstk::SatelliteSystem(1));
412  gnsstk::SatID compare9(-3 , gnsstk::SatelliteSystem(1));
413 
414  TUASSERT(compare1.isValid());
415  TUASSERT(compare2.isValid());
416  TUASSERT(!compare3.isValid());
417  TUASSERT(!compare4.isValid());
418  TUASSERT(!compare5.isValid());
419  TUASSERT(compare6.isValid());
420  TUASSERT(!compare7.isValid());
421  TUASSERT(!compare8.isValid());
422  TUASSERT(!compare9.isValid());
423 
424  TURETURN();
425  }
426 
428  unsigned stringConvertTest()
429  {
430  TUDEF("SatID", "convertSatelliteSystemToString");
431  std::map<gnsstk::SatelliteSystem, std::string> testVals =
432  {
433  { gnsstk::SatelliteSystem::GPS, "GPS" },
434  { gnsstk::SatelliteSystem::Galileo, "Galileo" },
435  { gnsstk::SatelliteSystem::Glonass, "GLONASS" },
436  { gnsstk::SatelliteSystem::Geosync, "Geostationary" },
437  { gnsstk::SatelliteSystem::LEO, "LEO" },
438  { gnsstk::SatelliteSystem::Transit, "Transit" },
439  { gnsstk::SatelliteSystem::BeiDou, "BeiDou" },
440  { gnsstk::SatelliteSystem::QZSS, "QZSS" },
441  { gnsstk::SatelliteSystem::IRNSS, "IRNSS" },
442  { gnsstk::SatelliteSystem::Mixed, "Mixed" },
443  { gnsstk::SatelliteSystem::UserDefined, "UserDefined" },
444  { gnsstk::SatelliteSystem::Unknown, "Unknown" }
445  };
446 
447  for (const auto& tvi : testVals)
448  {
449  TUCSM("convertSatelliteSystemToString");
450  TUASSERTE(std::string, tvi.second,
452  TUCSM("convertStringToSatelliteSystem");
455  }
456 
457  TURETURN();
458  }
459 };
460 
461 
462 int main() //Main function to initialize and run all tests above
463 {
464  SatID_T testClass;
465  unsigned errorTotal = 0;
466 
467  errorTotal += testClass.initializationTest();
468  errorTotal += testClass.dumpTest();
469  errorTotal += testClass.operatorTest();
470  errorTotal += testClass.lessThanTest();
471  errorTotal += testClass.isValidTest();
472  errorTotal += testClass.stringConvertTest();
473  errorTotal += testClass.asStringTest();
474 
475  std::cout << "Total Failures for " << __FILE__ << ": " << errorTotal
476  << std::endl;
477 
478  return errorTotal; //Return the total number of errors
479 }
gnsstk::SatelliteSystem::IRNSS
@ IRNSS
Official name changed from IRNSS to NavIC.
SatID_T::operatorTest
unsigned operatorTest()
verify the various operators of the SatID class
Definition: SatID_T.cpp:196
TUCSM
#define TUCSM(METHOD)
Definition: TestUtil.hpp:59
SatID_T::asStringTest
unsigned asStringTest()
check that a SatID object can be reported as a string
Definition: SatID_T.cpp:164
gnsstk::SatID::isValid
bool isValid() const
Definition: SatID.cpp:135
gnsstk::SatID::id
int id
Satellite identifier, e.g. PRN.
Definition: SatID.hpp:154
SatID_T::dumpTest
unsigned dumpTest()
check the output from SatID::dump meets its expectations
Definition: SatID_T.cpp:118
gnsstk::SatID::makeWild
void makeWild()
Definition: SatID.cpp:74
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
SatelliteSystem.hpp
gnsstk::SatID::dump
void dump(std::ostream &s) const
Convenience output method.
Definition: SatID.cpp:88
gnsstk::SatelliteSystem::LEO
@ LEO
gnsstk::SatelliteSystem
SatelliteSystem
Supported satellite systems.
Definition: SatelliteSystem.hpp:55
gnsstk::SatelliteSystem::Transit
@ Transit
gnsstk::SatID
Definition: SatID.hpp:89
SatID.hpp
gnsstk::StringUtils::asString
std::string asString(IonexStoreStrategy e)
Convert a IonexStoreStrategy to a whitespace-free string name.
Definition: IonexStoreStrategy.cpp:46
gnsstk::SatID::wildId
bool wildId
If true, any satellite matches.
Definition: SatID.hpp:155
gnsstk::SatelliteSystem::Geosync
@ Geosync
SatID_T::~SatID_T
~SatID_T()
Definition: SatID_T.cpp:61
main
int main()
Definition: SatID_T.cpp:462
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::convertStringToSatelliteSystem
SatelliteSystem convertStringToSatelliteSystem(const std::string &s)
Definition: SatelliteSystem.hpp:107
SatID_T::isValidTest
unsigned isValidTest()
check that the isValid method returns the proper value
Definition: SatID_T.cpp:400
gnsstk::SatelliteSystem::GPS
@ GPS
TUASSERT
#define TUASSERT(EXPR)
Definition: TestUtil.hpp:63
gnsstk::SatID::wildSys
bool wildSys
If true, any system matches.
Definition: SatID.hpp:157
TestUtil.hpp
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
gnsstk::SatelliteSystem::Unknown
@ Unknown
gnsstk::operator<<
std::ostream & operator<<(std::ostream &s, const ObsEpoch &oe) noexcept
Definition: ObsEpochMap.cpp:54
SatID_T
Definition: SatID_T.cpp:57
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
SatID_T::initializationTest
unsigned initializationTest()
ensure the constructors set the values properly
Definition: SatID_T.cpp:65
gnsstk::SatID::system
SatelliteSystem system
System for this satellite.
Definition: SatID.hpp:156
gnsstk::SatelliteSystem::UserDefined
@ UserDefined
gnsstk::SatelliteSystem::Mixed
@ Mixed
SatID_T::stringConvertTest
unsigned stringConvertTest()
Regression testing for string <-> enum translation.
Definition: SatID_T.cpp:428
SatID_T::SatID_T
SatID_T()
Definition: SatID_T.cpp:60
gnsstk::SatelliteSystem::Glonass
@ Glonass
gnsstk::SatelliteSystem::BeiDou
@ BeiDou
aka Compass
gnsstk::convertSatelliteSystemToString
std::string convertSatelliteSystemToString(SatelliteSystem s)
Definition: SatelliteSystem.hpp:96
gnsstk::SatelliteSystem::QZSS
@ QZSS
gnsstk::SatelliteSystem::Galileo
@ Galileo
SatID_T::lessThanTest
unsigned lessThanTest()
Definition: SatID_T.cpp:353


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:41