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 <list>
40 #include <string>
41 #include <iostream>
42 #include <fstream>
43 #include <iomanip>
44 #include <sstream>
45 
46 #include "Xvt.hpp"
47 #include "RinexEphemerisStore.hpp"
48 #include "Exception.hpp"
49 #include "CivilTime.hpp"
50 #include "CommonTime.hpp"
51 #include "RinexNavData.hpp"
52 #include "EngEphemeris.hpp"
53 #include "GPSEphemerisStore.hpp"
54 #include "SatID.hpp"
55 #include "RinexNavStream.hpp"
56 #include "TestUtil.hpp"
57 
58 
59 
60 using namespace gpstk;
61 using namespace std;
62 
63 
64 class RinexEphemerisStore_T
65 {
66 public:
RinexEphemerisStore_T()67    RinexEphemerisStore_T() {}
68 
69 //=============================================================================
70 //      General test for the RinexEphemerisStore (RES) class
71 //      Test to assure the that RES throws its exceptions in the right
72 //      place and that it loads the RINEX Nav file correctly
73 //=============================================================================
RESTest()74    unsigned RESTest()
75    {
76       TUDEF("RinexEphemerisStore", "Constructor");
77 
78          //-----------------------------------------------------------
79          // Verify the consturctor builds the RES object
80          //-----------------------------------------------------------
81       try
82       {
83          RinexEphemerisStore rinEphStore;
84          TUPASS("sedIdentifier");
85       }
86       catch (...)
87       {
88          TUFAIL("Exception thrown creating RinexEphemerisStoreObject");
89       }
90       RinexEphemerisStore rinEphStore;
91 
92          //-----------------------------------------------------------
93          // Verify the inability to load nonexistent files.
94          //-----------------------------------------------------------
95       TUCSM("loadFile");
96       try
97       {
98          rinEphStore.loadFile(inputNotaFile.c_str());
99          TUFAIL("Loaded a non-existent file.");
100       }
101       catch (Exception& e)
102       {
103          TUPASS("sedIdentifier");
104       }
105 
106          //---------------------------------------------
107          // Verify the ability to load existant files.
108          //---------------------------------------------
109       try
110       {
111          rinEphStore.loadFile(inputRinexNavData.c_str());
112          TUPASS("sedIdentifier");
113       }
114       catch (...)
115       {
116          TUFAIL("Could not load existing file");
117       }
118 
119 //-------------------------------------------------------======================
120 //   It would be nice to verify that the double name exception is
121 //   indeed thrown. However the InvalidParameter exception thrown will
122 //   terminate the program even with a catch-all.
123          /*
124          //--------------RinexEphemerisStore_RESTest_# - Verify that a repeated filename returns an exception
125          try
126          {
127          Store.loadFile(inputRinexNavData.c_str());
128          testFramework.failTest();
129          }
130          catch (Exception& e)
131          {
132          TUPASS("sedIdentifier");
133          cout << "Expected exception received from RinexEphemerisStore" << endl;
134          }
135          catch (...)
136          {
137          cout << "Expected exception received from RinexEphemerisStore!!!!!!!!!" << endl;
138          } }
139          */
140 //-------------------------------------------------------======================
141 
142       TUCSM("clear");
143          //--------------------------------------------------------------------
144          // Verify that once a clear() has been performed the repeated
145          // filename can be opened.
146          //--------------------------------------------------------------------
147       rinEphStore.gpstk::FileStore<RinexNavHeader>::clear();
148       try
149       {
150          rinEphStore.loadFile(inputRinexNavData.c_str());
151          TUPASS("sedIdentifier");
152       }
153       catch (Exception& e)
154       {
155          cout << " Exception received from RinexEphemerisStore, e = " << e
156               << endl;
157          TUFAIL("Could not reopen the cleared file.");
158       }
159 
160       TURETURN();
161    }
162 
163 
164 //=============================================================================
165 //      Test to assure the quality of GPSEphemerisStore class member findEph()
166 //      This test makes sure that exceptions are thrown if there is no
167 //      ephemeris data for the given PRN and also that an exception is
168 //      thrown if there is no data for the PRN at the given
169 //      time. Furthermore, this test finds an Ephemeris for a given
170 //      CivilTime Time and PRN.
171 //      To see the ephemeris information for the selected Time and PRN
172 //      please see findEph#.txt
173 //=============================================================================
findEphTest()174    unsigned findEphTest()
175    {
176       TUDEF("GPSEphemerisStore", "findEphemeris");
177 
178       RinexEphemerisStore rinEphStore;
179       rinEphStore.loadFile(inputRinexNavData.c_str());
180 
181          // Create a list of GPSEphemerides
182       std::list<GPSEphemeris> R3NList;
183          // Create a GPSEphemerisStore for testing
184       GPSEphemerisStore gpsEphStore;
185          // Create an interator for the GPSEphmeris list
186       list<GPSEphemeris>::const_iterator it;
187          // Add the loaded Rinex Nav Data into the list
188       rinEphStore.addToList(R3NList);
189          // Loop over the list adding the ephemerides to the GPSEphemerisStore
190       for (it = R3NList.begin(); it != R3NList.end(); ++it)
191       {
192          gpsEphStore.addEphemeris(GPSEphemeris(*it));
193       }
194 
195          // debug dump of gpsEphStore for reference if needed
196       ofstream gDumpData;
197       gDumpData.open(gpsEphemerisStoreDumpOutput.c_str());
198       gpsEphStore.dump(gDumpData,1);
199       gDumpData.close();
200 
201       const short PRN0 = 0; // Zero PRN (Border test case)
202       const short PRN1 = 1;
203       const short PRN15 = 15;
204       const short PRN32 = 32;
205       const short PRN33 = 33;  // Top PRN (33) (Border test case);
206 
207       const SatID sid0(PRN0,SatelliteSystem::GPS);
208       const SatID sid1(PRN1,SatelliteSystem::GPS);
209       const SatID sid15(PRN15,SatelliteSystem::GPS);
210       const SatID sid32(PRN32,SatelliteSystem::GPS);
211       const SatID sid33(PRN33,SatelliteSystem::GPS);
212 
213       CivilTime Time(2006,1,31,11,45,0,TimeSystem::GPS);
214          // Border Time (Time of Border test cases)
215       CivilTime bTime(2006,1,31,2,0,0,TimeSystem::GPS);
216       const CommonTime ComTime = Time.convertToCommonTime();
217       const CommonTime CombTime = bTime.convertToCommonTime();
218 
219       try
220       {
221          CivilTime crazy(1950,1,31,2,0,0,TimeSystem::GPS);
222          const CommonTime Comcrazy = (CommonTime)crazy;
223 
224             //--------------------------------------------------
225             // For proper input, will the method return properly?
226             //--------------------------------------------------
227          try
228          {
229             gpsEphStore.findEphemeris(sid1,ComTime);
230             TUPASS("sedIdentifier");
231          }
232          catch (...)
233          {
234             TUFAIL("findEphemeris threw an exception when it shouldn't.");
235          }
236 
237             //-----------------------------------------------------------
238             // For a wrong SatID (too small), will an exception be thrown?
239             //-----------------------------------------------------------
240          try
241          {
242             gpsEphStore.findEphemeris(sid0,CombTime);
243             TUFAIL("findEphemeris was successful when it shouldn't be");
244          }
245          catch (InvalidRequest)
246          {
247             TUPASS("sedIdentifier");
248          }
249          catch (...)
250          {
251             TUFAIL("findEphemeris threw an unexpected exception");
252          }
253 
254             //-----------------------------------------------------------
255             // For a wrong SatID (too large), will an exception be thrown?
256             //-----------------------------------------------------------
257          try
258          {
259             gpsEphStore.findEphemeris(sid33,CombTime);
260             TUFAIL("findEphemeris was successful when it shouldn't be");
261          }
262          catch (InvalidRequest)
263          {
264             TUPASS("sedIdentifier");
265          }
266          catch (...)
267          {
268             TUFAIL("findEphemeris threw an unexpected exception");
269          }
270 
271             //-------------------------------------------------------
272             // For an improper time, will an exception be thrown?
273             //-------------------------------------------------------
274          try
275          {
276             gpsEphStore.findEphemeris(sid32,Comcrazy);
277             TUFAIL("findEphemeris was successful when it shouldn't be");
278          }
279          catch (InvalidRequest)
280          {
281             TUPASS("sedIdentifier");
282          }
283          catch (...)
284          {
285             TUFAIL("findEphemeris threw an unexpected exception");
286          }
287 
288             //-------------------------------------------------------
289             // Check findEphemeris output with pre-determined standard
290             //-------------------------------------------------------
291          GPSEphemeris eph(gpsEphStore.findEphemeris(sid1,ComTime));
292          GPSWeekSecond xmitTime(1360, 208800.);
293          CommonTime xmitTimeCT(xmitTime);
294          GPSWeekSecond toe(1360, 215984.);
295          CommonTime toeCT(toe);
296          GPSWeekSecond toc(1360, 215984.);
297          CommonTime tocCT(toc);
298          double Ahalf = .515367877960e+04;
299          double A = Ahalf * Ahalf;
300          TUASSERTE(CommonTime, xmitTimeCT, eph.transmitTime);
301          TUASSERTE(long, 208806, eph.HOWtime);
302          TUASSERTE(short, 0x174, eph.IODC);
303          TUASSERTE(short, 0x74, eph.IODE);
304          TUASSERTE(short, 0, eph.health);
305          TUASSERTE(short, 2, eph.accuracyFlag);
306             // skipping accuracy which is converted from accuracyFlag
307             // and is supposed to be a range rather than a single
308             // number.
309          TUASSERTFE(-3.25962901E-09, eph.Tgd);
310          TUASSERTE(short, 1, eph.codeflags);
311          TUASSERTE(short, 0, eph.L2Pdata);
312          TUASSERTE(short, 4, eph.fitDuration);
313             // This really should be zero, but the toolkit is
314             // inconsistent in its use of this data.
315          TUASSERTE(short, 4, eph.fitint);
316             // OrbitEph data
317          TUASSERTE(SatID, SatID(1, SatelliteSystem::GPS), eph.satID);
318             // skipping obsID which is unknown, not stored in RINEX
319          TUASSERTE(CommonTime, toeCT, eph.ctToe);
320          TUASSERTE(CommonTime, tocCT, eph.ctToc);
321          TUASSERTFE( .342056155205e-04, eph.af0);
322          TUASSERTFE( .193267624127e-11, eph.af1);
323          TUASSERTFE( .000000000000e+00, eph.af2);
324          TUASSERTFE( .231892822330e+00, eph.M0);
325          TUASSERTFE( .415874465698e-08, eph.dn);
326          TUASSERTFE( .632588984445e-02, eph.ecc);
327          TUASSERTFE( A, eph.A);
328          TUASSERTFE(-.171556435925e+01, eph.OMEGA0);
329          TUASSERTFE( .986372320378e+00, eph.i0);
330          TUASSERTFE(-.171070282354e+01, eph.w);
331          TUASSERTFE(-.827605901679e-08, eph.OMEGAdot);
332          TUASSERTFE( .533236497155e-09, eph.idot);
333          TUASSERTFE( .578165054321e-05, eph.Cuc);
334          TUASSERTFE( .529363751411e-05, eph.Cus);
335          TUASSERTFE( .290062500000e+03, eph.Crc);
336          TUASSERTFE( .113406250000e+03, eph.Crs);
337          TUASSERTFE(-.745058059692e-07, eph.Cic);
338          TUASSERTFE(-.279396772385e-07, eph.Cis);
339       }
340       catch (Exception& e)
341       {
342             // cout << e;
343       }
344 
345 
346          // Removed because formatting inconsistencies.  If you want
347          // to do regression tests on formats, create an independent
348          // test.
349          //TUCSM("findEphemeris Output");
350          //-------------------------------------------------------
351          // Check findEphemeris output with pre-determined standard
352          //-------------------------------------------------------
353          //testFramework.assert(testFramework.fileEqualTest(findEphTestOutput, findEphTestInput, 0), "Output file did not match regressive standard.", __LINE__);
354 
355       TURETURN();
356    }
357 
358 
359 //=============================================================================
360 //      Test to assure the quality of GPSEphemerisStore class member getXvt()
361 //      This test makes sure that exceptions are thrown if there is no
362 //      ephemeris data for the given PRN and also that an exception is
363 //      thrown if there is no data for the PRN at the given
364 //      time. Furthermore, this test finds an Xvt for a given
365 //      CivilTime Time and PRN.
366 //      To see the Xvt information for the selected Time and PRN
367 //      please see the files getXvt#.txt
368 //=============================================================================
369 
getXvtTest()370    unsigned getXvtTest()
371    {
372       TUDEF("OrbitEphStore", "getXvt");
373 
374       stringstream fPRN1;
375       stringstream fPRN15;
376       stringstream fPRN32;
377 
378       RinexEphemerisStore rinEphStore;
379       rinEphStore.loadFile(inputRinexNavData.c_str());
380 
381       const short PRN0 = 0; // Zero PRN (Border test case)
382       const short PRN1 = 1;
383       const short PRN15 = 15;
384       const short PRN32 = 32;
385       const short PRN33 = 33;  // Top PRN (33) (Border test case);
386       SatID sid0(PRN0,SatelliteSystem::GPS);
387       SatID sid1(PRN1,SatelliteSystem::GPS);
388       SatID sid15(PRN15,SatelliteSystem::GPS);
389       SatID sid32(PRN32,SatelliteSystem::GPS);
390       SatID sid33(PRN33,SatelliteSystem::GPS);
391 
392       CivilTime Time(2006,1,31,11,45,0,TimeSystem::Any);
393          // Border Time (Time of Border test cases)
394       CivilTime bTime(2006,1,31,2,0,0,TimeSystem::Any);
395       const CommonTime ComTime = (CommonTime)Time;
396       const CommonTime CombTime = (CommonTime)bTime;
397 
398       Xvt xvt1;
399       Xvt xvt15;
400       Xvt xvt32;
401       try
402       {
403             //-------------------------------------------------------
404             // Does getXvt work in ideal settings?
405             //-------------------------------------------------------
406          try
407          {
408             rinEphStore.getXvt(sid1,ComTime);
409             TUPASS("sedIdentifier");
410          }
411          catch (Exception& e)
412          {
413             cout << "Exception thrown is " << e << endl;
414             TUFAIL("getXvt threw an exception when it should not");
415          }
416 
417          xvt1 = rinEphStore.getXvt(sid1,ComTime);
418          xvt15 = rinEphStore.getXvt(sid15,ComTime);
419          xvt32 = rinEphStore.getXvt(sid32,ComTime);
420 
421          fPRN1 << xvt1;
422          fPRN15 << xvt15;
423          fPRN32 << xvt32;
424 
425             //-------------------------------------------------------
426             // Can I get an xvt for a unlisted (too small) SV?
427             //-------------------------------------------------------
428          try
429          {
430             rinEphStore.getXvt(sid0,CombTime);
431             TUFAIL("getXvt was successful when it shouldn't be");
432          }
433          catch (InvalidRequest& e)
434          {
435             TUPASS("sedIdentifier");
436          }
437          catch (...)
438          {
439             TUFAIL("getXvt threw an unexpected exception");
440          }
441 
442             //-------------------------------------------------------
443             // Can I get an xvt for a unlisted (too large) SV?
444             //-------------------------------------------------------
445          try
446          {
447             rinEphStore.getXvt(sid33,CombTime);
448             TUFAIL("getXvt was successful when it shouldn't be");
449          }
450          catch (InvalidRequest& e)
451          {
452             TUPASS("sedIdentifier");
453          }
454          catch (...)
455          {
456             TUFAIL("getXvt threw an unexpected exception");
457          }
458       }
459       catch (Exception& e)
460       {
461             // cout << e;
462       }
463 
464 
465 
466       std::string comparisonOutput1  =
467          "x:(1.43293e+07, -2.70658e+06, -2.19986e+07),"
468          " v:(354.7, 2812.28, -117.977),"
469          " clk bias:3.42039e-05,"
470          " clk drift:1.93268e-12,"
471          " relcorr:-1.49802e-09,"
472          " health:Healthy";
473       std::string comparisonOutput15 =
474          "x:(1.46708e+07, 7.54272e+06, 2.07205e+07),"
475          " v:(-2147.84, 1575.62, 902.864),"
476          " clk bias:0.000558473,"
477          " clk drift:5.91172e-12,"
478          " relcorr:2.04148e-08,"
479          " health:Healthy";
480       std::string comparisonOutput32 =
481          "x:(8.40859e+06, 1.71989e+07, -1.87307e+07),"
482          " v:(-2248.19, -606.201, -1577.98),"
483          " clk bias:2.12814e-05,"
484          " clk drift:3.41061e-12,"
485          " relcorr:-5.04954e-09,"
486          " health:Healthy";
487       TUCSM("getXvt Output");
488 
489          //-------------------------------------------------------
490          // Compare data for SatID 1 with pre-determined standard
491          //-------------------------------------------------------
492       TUASSERTE(std::string, comparisonOutput1, fPRN1.str());
493 
494          //-------------------------------------------------------
495          // Compare data for SatID 15 with pre-determined standard
496          //-------------------------------------------------------
497       TUASSERTE(std::string, comparisonOutput15, fPRN15.str());
498 
499          //-------------------------------------------------------
500          // Compare data for SatID 32 with pre-determined standard
501          //-------------------------------------------------------
502       TUASSERTE(std::string, comparisonOutput32, fPRN32.str());
503 
504       TURETURN();
505    }
506 
computeXvtTest()507    unsigned computeXvtTest()
508    {
509       TUDEF("OrbitEphStore", "computeXvt");
510 
511       try
512       {
513          RinexEphemerisStore rinEphStore;
514          rinEphStore.loadFile(inputRinexNavData.c_str());
515 
516          stringstream fPRN1;
517          stringstream fPRN15;
518          stringstream fPRN32;
519          Xvt rv;
520          const short PRN0 = 0; // Zero PRN (Border test case)
521          const short PRN1 = 1;
522          const short PRN15 = 15;
523          const short PRN32 = 32;
524          const short PRN33 = 33;  // Top PRN (33) (Border test case);
525 
526          SatID sid0(PRN0,SatelliteSystem::GPS);
527          SatID sid1(PRN1,SatelliteSystem::GPS);
528          SatID sid15(PRN15,SatelliteSystem::GPS);
529          SatID sid32(PRN32,SatelliteSystem::GPS);
530          SatID sid33(PRN33,SatelliteSystem::GPS);
531 
532          CivilTime tTime(2006,1,31,11,45,0,TimeSystem::Any);
533             // Border Time (Time of Border test cases)
534          CivilTime bTime(2006,1,31,2,0,0,TimeSystem::Any);
535          const CommonTime comTime = (CommonTime)tTime;
536          const CommonTime combTime = (CommonTime)bTime;
537 
538          TUCATCH(rv = rinEphStore.computeXvt(sid1,comTime));
539          TUASSERTE(Xvt::HealthStatus, Xvt::HealthStatus::Healthy,rv.health);
540          fPRN1 << rv;
541          TUCATCH(rv = rinEphStore.computeXvt(sid15,comTime));
542          TUASSERTE(Xvt::HealthStatus, Xvt::HealthStatus::Healthy,rv.health);
543          fPRN15 << rv;
544          TUCATCH(rv = rinEphStore.computeXvt(sid32,comTime));
545          TUASSERTE(Xvt::HealthStatus, Xvt::HealthStatus::Healthy,rv.health);
546          fPRN32 << rv;
547          TUCATCH(rv = rinEphStore.computeXvt(sid0,combTime));
548          TUASSERTE(Xvt::HealthStatus, Xvt::HealthStatus::Unavailable,rv.health);
549          TUCATCH(rv = rinEphStore.computeXvt(sid33,combTime));
550          TUASSERTE(Xvt::HealthStatus, Xvt::HealthStatus::Unavailable,rv.health);
551 
552          TUASSERTE(std::string, comparisonOutput1, fPRN1.str());
553          TUASSERTE(std::string, comparisonOutput15, fPRN15.str());
554          TUASSERTE(std::string, comparisonOutput32, fPRN32.str());
555       }
556       catch (...)
557       {
558          TUFAIL("Unexpected exception");
559       }
560       TURETURN();
561    }
562 
563 
getSVHealthTest()564    unsigned getSVHealthTest()
565    {
566       TUDEF("OrbitEphStore", "getSVHealth");
567 
568       try
569       {
570          RinexEphemerisStore rinEphStore;
571          rinEphStore.loadFile(inputRinexNavData.c_str());
572 
573          Xvt::HealthStatus rv;
574          const short PRN0 = 0; // Zero PRN (Border test case)
575          const short PRN1 = 1;
576          const short PRN15 = 15;
577          const short PRN32 = 32;
578          const short PRN33 = 33;  // Top PRN (33) (Border test case);
579 
580          SatID sid0(PRN0,SatelliteSystem::GPS);
581          SatID sid1(PRN1,SatelliteSystem::GPS);
582          SatID sid15(PRN15,SatelliteSystem::GPS);
583          SatID sid32(PRN32,SatelliteSystem::GPS);
584          SatID sid33(PRN33,SatelliteSystem::GPS);
585 
586          CivilTime Time(2006,1,31,11,45,0,TimeSystem::Any);
587             // Border Time (Time of Border test cases)
588          CivilTime bTime(2006,1,31,2,0,0,TimeSystem::Any);
589          const CommonTime comTime = (CommonTime)Time;
590          const CommonTime combTime = (CommonTime)bTime;
591 
592          TUCATCH(rv = rinEphStore.getSVHealth(sid1,comTime));
593          TUASSERTE(Xvt::HealthStatus, Xvt::HealthStatus::Healthy, rv);
594          TUCATCH(rv = rinEphStore.getSVHealth(sid15,comTime));
595          TUASSERTE(Xvt::HealthStatus, Xvt::HealthStatus::Healthy, rv);
596          TUCATCH(rv = rinEphStore.getSVHealth(sid32,comTime));
597          TUASSERTE(Xvt::HealthStatus, Xvt::HealthStatus::Healthy, rv);
598          TUCATCH(rv = rinEphStore.getSVHealth(sid0,combTime));
599          TUASSERTE(Xvt::HealthStatus, Xvt::HealthStatus::Unavailable, rv);
600          TUCATCH(rv = rinEphStore.getSVHealth(sid33,combTime));
601          TUASSERTE(Xvt::HealthStatus, Xvt::HealthStatus::Unavailable, rv);
602       }
603       catch (...)
604       {
605          TUFAIL("Unexpected exception");
606       }
607       TURETURN();
608    }
609 
610 
611 //=============================================================================
612 //      Test to assure the quality of GPSEphemerisStore class member
613 //      getXvt() This test differs from the previous in that this
614 //      getXvt() has another parameter for the IODC
615 //
616 //      This test makes sure that exceptions are thrown if there is no
617 //      ephemeris data for the given PRN and also that an exception is
618 //      thrown if there is no data for the PRN at the given
619 //      time. Furthermore, this test finds an Xvt for a given
620 //      CivilTime Time and PRN and IODC.
621 //
622 //      To see the Xvt information for the selected Time and PRN please see
623 //      getXvt2.txt
624 // NOTE: getXvt with an IODC option is now deprecated. Test is no
625 //      longer necessary, but is being left here in case the
626 //      functionality returns.
627 // NOTE: This test will need to be brought up to the newest standard
628 // should it be used again.
629 //=============================================================================
630       /*
631         unsigned getXvt2Test()
632         {
633         TUDEF("OrbitEphStore", "getXvt with IODC");
634 
635 
636         ofstream fPRN1;
637         ofstream fPRN15;
638         ofstream fPRN32;
639 
640         string filename;
641         filename = __FILE__;
642         filename = filename.substr(0, filename.find_last_of("\\/"));
643 
644         fPRN1.open ((filename+"/Logs/getXvt2_1.txt").c_str());
645         fPRN15.open ((filename+"/Logs/getXvt2_15.txt").c_str());
646         fPRN32.open ((filename+"/Logs/getXvt2_32.txt").c_str());
647 
648         RinexEphemerisStore rinEphStore;
649         rinEphStore.loadFile(inputRinexNavData.c_str());
650 
651         std::list<RinexNavData> R3NList;
652         GPSEphemerisStore gpsEphStore;
653         list<RinexNavData>::const_iterator it;
654         rinEphStore.addToList(R3NList);
655         for (it = R3NList.begin(); it != R3NList.end(); ++it)
656         gpsEphStore.addEphemeris(EngEphemeris(*it));
657 
658         const short PRN0 = 0; // Zero PRN (Border test case)
659         const short PRN1 = 1;
660         const short PRN15 = 15;
661         const short PRN32 = 32;
662         const short PRN33 = 33;  // Top PRN (33) (Border test case);
663         SatID sid0(PRN0,SatelliteSystem::GPS);
664         SatID sid1(PRN1,SatelliteSystem::GPS);
665         SatID sid15(PRN15,SatelliteSystem::GPS);
666         SatID sid32(PRN32,SatelliteSystem::GPS);
667         SatID sid33(PRN33,SatelliteSystem::GPS);
668 
669         short IODC0 = 89;
670         short IODC1 = 372;
671         short IODC15 = 455;
672         short IODC32 = 441;
673         short IODC33 = 392;
674 
675         CivilTime Time(2006,1,31,11,45,0,TimeSystem::GPS);
676         CivilTime bTime(2006,1,31,2,0,0,TimeSystem::GPS); // Border Time (Time of Border test cases)
677         const CommonTime ComTime = (CommonTime)Time;
678         const CommonTime CombTime = (CommonTime)bTime;
679 
680         try
681         {
682       //--------------RinexEphemerisStore_getXvt2Test_1 - Does getXvt work in ideal settings?
683       try
684       {
685       rinEphStore.getXvt(sid1,ComTime,IODC1);
686       TUPASS("sedIdentifier");
687       }
688       catch (...) {
689       testFramework.failTest();
690       }
691 
692       fPRN1 << rinEphStore.getXvt(sid1,ComTime,IODC1) << endl;
693       fPRN15 << rinEphStore.getXvt(sid15,ComTime,IODC15) << endl;
694       fPRN32 << rinEphStore.getXvt(sid32,ComTime,IODC32) << endl;
695 
696 
697       //--------------RinexEphemerisStore_getXvt2Test_2 - Is an error thrown when SatID is too small?
698       try
699       {
700       rinEphStore.getXvt(sid0,CombTime,IODC0);
701       testFramework.failTest();
702       }
703       catch (InvalidRequest& e) {
704       TUPASS("sedIdentifier");
705       }
706       catch (...) {
707       testFramework.failTest();
708       }
709 
710       //--------------RinexEphemerisStore_getXvt2Test_3 - Is an error thrown when SatID is too large?
711       try
712       {
713       rinEphStore.getXvt(sid33,CombTime,IODC33);
714       testFramework.failTest();
715       }
716       catch (InvalidRequest& e) {
717       TUPASS("sedIdentifier");
718       }
719       catch (...) {
720       testFramework.failTest();
721       }
722       }
723       catch (Exception& e)
724       {
725          // cout << e;
726          }
727 
728          fPRN1.close();
729          fPRN15.close();
730          fPRN32.close();
731 
732          TUCSM("getXvt with IODC Output");
733       //--------------RinexEphemerisStore_getXvt2Test_4 - Compare data for SatID 1 with pre-determined standard
734       testFramework.assert(fileEqualTest((char*)(filename+"/Logs/getXvt2_1.txt").c_str(),(char*)(filename+"/Checks/getPrnXvt1.chk").c_str()));
735       testFramework.next();
736       //--------------RinexEphemerisStore_getXvt2Test_5 - Compare data for SatID 15 with pre-determined standard
737       testFramework.assert(fileEqualTest((char*)(filename+"/Logs/getXvt2_15.txt").c_str(),(char*)(filename+"/Checks/getPrnXvt15.chk").c_str()));
738       testFramework.next();
739       //--------------RinexEphemerisStore_getXvt2Test_6 - Compare data for SatID 32 with pre-determined standard
740       testFramework.assert(fileEqualTest((char*)(filename+"/Logs/getXvt2_32.txt").c_str(),(char*)(filename+"/Checks/getPrnXvt32.chk").c_str()));
741       testFramework.next();
742 
743       TURETURN();
744       }
745       */
746 
747 
748 //=============================================================================
749 //      Test to assure the quality of GPSEphemerisStore class member dump()
750 //
751 //      This test makes sure that dump() behaves as expected.  With
752 //      parameters from 1-3 with each giving more and more respective
753 //      information, this information is then put into txt files.
754 //
755 //      To see the dump with parameter 1, please view DumpData1.txt
756 //      To see the dump with parameter 2, pleave view DumpData2.txt
757 //      To see the dump with parameter 3, please view DumpData3.txt
758 //=============================================================================
dumpTest()759    unsigned dumpTest()
760    {
761       TUDEF("GPSEphemerisStore", "dump");
762 
763 
764       ofstream dumpTestOutputStreamForDetail0;
765       ofstream dumpTestOutputStreamForDetail1;
766       ofstream dumpTestOutputStreamForDetail2;
767 
768       dumpTestOutputStreamForDetail0.open(dumpTestOutputForDetail0.c_str());
769       dumpTestOutputStreamForDetail1.open(dumpTestOutputForDetail1.c_str());
770       dumpTestOutputStreamForDetail2.open(dumpTestOutputForDetail2.c_str());
771 
772 
773       RinexEphemerisStore rinEphStore;
774       rinEphStore.loadFile(inputRinexNavData.c_str());
775 
776       try
777       {
778             //-----------------------------------------------------------
779             // Check that dump(, detail = 1) will work with no exceptions
780             //-----------------------------------------------------------
781          try
782          {
783             rinEphStore.dump(dumpTestOutputStreamForDetail0,1);
784             TUPASS("sedIdentifier");
785          }
786          catch (...)
787          {
788             TUFAIL("Dump with detail=1 threw an exception when it should not");
789          }
790 
791             //-----------------------------------------------------------
792             // Check that dump(, detail = 2) will work with no exceptions
793             //-----------------------------------------------------------
794          try
795          {
796             rinEphStore.dump(dumpTestOutputStreamForDetail1,2);
797             TUPASS("sedIdentifier");
798          }
799          catch (...)
800          {
801             TUFAIL("Dump with detail=2 threw an exception when it should not");
802          }
803 
804             //-----------------------------------------------------------
805             // Check that dump(, detail = 3) will work with no exceptions
806             //-----------------------------------------------------------
807          try
808          {
809             rinEphStore.dump(dumpTestOutputStreamForDetail2,3);
810             TUPASS("sedIdentifier");
811          }
812          catch (...)
813          {
814             TUFAIL("Dump with detail=3 threw an exception when it should not");
815          }
816 
817 
818       }
819       catch (Exception& e)
820       {
821             // cout << e;
822       }
823 
824       dumpTestOutputStreamForDetail0.close();
825       dumpTestOutputStreamForDetail1.close();
826       dumpTestOutputStreamForDetail2.close();
827 
828          //-----------------------------------------------------------
829          // Check dump(, detail = 1) output against its
830          // pre-determined standard
831          //-----------------------------------------------------------
832       testFramework.assert(testFramework.fileEqualTest(dumpTestOutputForDetail0,
833                             dumpTestInputForDetail0, 2),
834                             "Dump(*,detail=1) did not match its regressive output", __LINE__);
835 
836          //-----------------------------------------------------------
837          // Check dump(, detail = 2) output against its
838          // pre-determined standard
839          //-----------------------------------------------------------
840       testFramework.assert(testFramework.fileEqualTest(dumpTestOutputForDetail1,
841                             dumpTestInputForDetail1, 2),
842                             "Dump(*,detail=2) did not match its regressive output", __LINE__);
843 
844          //-----------------------------------------------------------
845          // Check dump(, detail = 3) output against its
846          // pre-determined standard
847          //-----------------------------------------------------------
848       testFramework.assert(testFramework.fileEqualTest(dumpTestOutputForDetail2,
849                             dumpTestInputForDetail2, 2),
850                             "Dump(*,detail=3) did not match its regressive output", __LINE__);
851 
852       TURETURN();
853    }
854 
855 //=============================================================================
856 //      Test to assure the quality of GPSEphemerisStore class member
857 //      addEphemeris()
858 //
859 //      This test assures that no exceptions are thrown when an
860 //      ephemeris, taken from Store is added to a blank BCES Object.
861 //      Then the test makes sure that only that Ephemeris is in the
862 //      object by checking the start and end times of the Object
863 //=============================================================================
864 
addEphemerisTest()865    unsigned addEphemerisTest()
866    {
867       TUDEF("GPSEphemerisStore", "addEphemeris");
868 
869 
870       GPSEphemerisStore Blank;
871 
872       RinexEphemerisStore rinEphStore;
873       rinEphStore.loadFile(inputRinexNavData.c_str());
874 
875       std::list<GPSEphemeris> R3NList;
876       GPSEphemerisStore gpsEphStore;
877       list<GPSEphemeris>::const_iterator it;
878       rinEphStore.addToList(R3NList);
879       for (it = R3NList.begin(); it != R3NList.end(); ++it)
880       {
881          gpsEphStore.addEphemeris(GPSEphemeris(*it));
882       }
883 
884       short PRN = 1;
885       SatID sid(PRN,SatelliteSystem::GPS);
886 
887       CivilTime Time(2006,1,31,11,45,0,TimeSystem::GPS);
888          // CivilTime TimeB(2006,1,31,9,59,44,TimeSystem::GPS);
889          // CivilTime TimeE(2006,1,31,13,59,44,TimeSystem::GPS);
890       CivilTime TimeBeginning(2006,1,31,10,0,0,TimeSystem::GPS);
891       CivilTime TimeEnd(2006,1,31,14,0,0,TimeSystem::GPS);
892       CivilTime defaultBeginning(4713, 1, 1, 0, 0, 0, TimeSystem::GPS);
893       CivilTime defaultEnd(-4713, 1, 1, 0, 0, 0, TimeSystem::GPS);
894       CivilTime check;
895       const CommonTime ComTime  = Time.convertToCommonTime();
896       const CommonTime ComTimeB = TimeBeginning.convertToCommonTime();
897       const CommonTime ComTimeE = TimeEnd.convertToCommonTime();
898       const CommonTime ComDefB  = defaultBeginning.convertToCommonTime();
899       const CommonTime ComDefE  = defaultEnd.convertToCommonTime();
900       const GPSEphemeris eph = gpsEphStore.findEphemeris(sid,ComTime);
901 
902       try
903       {
904             //-----------------------------------------------------------
905             // Verify that addEphemeris runs with no errors
906             //-----------------------------------------------------------
907          try
908          {
909             Blank.addEphemeris(eph);
910             TUPASS("sedIdentifier");
911          }
912          catch (...)
913          {
914             TUFAIL("addEphemeris threw an exception when all necessary data has been provided");
915          }
916 
917             //-----------------------------------------------------------
918             // Verify that addEphemeris added by checking the initial
919             // time of the GPSEphemerisStore
920             //-----------------------------------------------------------
921          testFramework.assert(ComTimeB == Blank.getInitialTime(),
922                                "addEphemeris may not have added the ephemeris or updated the initial time",
923                                __LINE__);
924 
925             //-----------------------------------------------------------
926             // Verify that addEphemeris added by checking the final
927             // time of the GPSEphemerisStore
928             //-----------------------------------------------------------
929          testFramework.assert(ComTimeE == Blank.getFinalTime(),
930                                "addEphemeris may not have added the ephemeris or updated the final time",
931                                __LINE__);
932 
933 
934          Blank.clear();
935             //-----------------------------------------------------------
936             // Verify that clear() worked by checking the initial time
937             // of the GPSEphemerisStore
938             //-----------------------------------------------------------
939          testFramework.assert(ComDefB == Blank.getInitialTime(),
940                                "clear may not have functioned or reset the initial time", __LINE__);
941 
942             //-----------------------------------------------------------
943             // Verify that clear() worked by checking the initial time
944             // of the GPSEphemerisStore
945             //-----------------------------------------------------------
946          testFramework.assert(ComDefE == Blank.getFinalTime(),
947                                "clear may not have functioned or reset the final time", __LINE__);
948       }
949       catch (Exception& e)
950       {
951          cout << e;
952       }
953 
954       TURETURN();
955    }
956 
957 
958 //=============================================================================
959 //      Test to assure the quality of GPSEphemerisStore class member
960 //      edit()
961 //
962 //      This test assures that no exceptions are thrown when we edit a
963 //      RES object then after we edit the RES Object, we test to make
964 //      sure that our edit time parameters are now the time endpoints
965 //      of the object.
966 //
967 //      For further inspection of the edit, please view editTest.txt
968 //=============================================================================
editTest()969    unsigned editTest()
970    {
971 
972       TUDEF("OrbitEphStore", "edit");
973 
974 
975       ofstream editTestOutputStream;
976       editTestOutputStream.open(editTestOutput.c_str());
977 
978       RinexEphemerisStore rinEphStore;
979       rinEphStore.loadFile(inputRinexNavData.c_str());
980 
981       CivilTime TimeMax(2006,1,31,15,45,0,TimeSystem::GPS);
982       CivilTime TimeMin(2006,1,31,3,0,0,TimeSystem::GPS);
983 
984          // cout << "TimeMax: " << TimeMax << "\n" << "TimeMin: " << TimeMin << "\n";
985 
986       const CommonTime ComTMax = (CommonTime)TimeMax;
987       const CommonTime ComTMin = (CommonTime)TimeMin;
988 
989          // cout << "ComTMax: " << ComTMax << "\n" << "ComTMin: " << ComTMin << "\n";
990 
991       try
992       {
993             //-----------------------------------------------------------
994             // Verify that the edit method runs
995             //-----------------------------------------------------------
996          try
997          {
998             rinEphStore.edit(ComTMin, ComTMax);
999             TUPASS("sedIdentifier");
1000          }
1001          catch (...)
1002          {
1003             TUFAIL("edit threw an error when it should have functioned");
1004          }
1005 
1006          rinEphStore.edit(ComTMin, ComTMax);
1007             //-----------------------------------------------------------
1008             // Verify that the edit method changed the initial time
1009             //-----------------------------------------------------------
1010          testFramework.assert(ComTMin == rinEphStore.getInitialTime(),
1011                               "Edit did not change the initial time", __LINE__);
1012 
1013             //-----------------------------------------------------------
1014             // Verify that the edit method changed the final time
1015             //-----------------------------------------------------------
1016          testFramework.assert(ComTMax == rinEphStore.getFinalTime(),
1017                               "Edit did not change the initial time", __LINE__);
1018 
1019 
1020          rinEphStore.dump(editTestOutputStream,2);
1021 
1022       }
1023       catch (Exception& e)
1024       {
1025             // cout << e;
1026       }
1027 
1028       editTestOutputStream.close();
1029          //-----------------------------------------------------------
1030          // Check edited output against its pre-determined standard
1031          //-----------------------------------------------------------
1032       testFramework.assert(testFramework.fileEqualTest(editTestOutput,
1033                             editTestInput, 2), "Output from edit does not match regressive standard",
1034                             __LINE__);
1035 
1036       TURETURN();
1037    }
1038 
1039 //=============================================================================
1040 //      Test to assure the quality of GPSEphemerisStore class member
1041 //      wiper()
1042 //
1043 //      This test assures that no exceptions are thrown when we wiper
1044 //      a RES object then after we wiper the RES Object, we test to
1045 //      make sure that our wiper time parameter in now the time
1046 //      endpoint of the object.
1047 //
1048 //      For further inspection of the edit, please view wiperTest.txt
1049 //
1050 //      Please note that this test also indirectly tests size
1051 //=============================================================================
1052       /*              unsigned wiperTest()
1053                       {
1054                       TUDEF("RinexEphemerisStore", "wiper");
1055 
1056 
1057                       ofstream dumpData1;
1058                       ofstream dumpData2;
1059                       outputTestOutput1 = outputTestOutput + "wiperTest.txt";
1060                       outputTestOutput15 = outputTestOutput + "wiperTest2.txt";
1061                       dumpData1.open(outputTestOutput1.c_str());
1062                       dumpData2.open(outputTestOutput15.c_str());
1063 
1064 
1065                       RinexEphemerisStore rinEphStore;
1066                       rinEphStore.loadFile(inputRinexNavData.c_str());
1067 
1068                       std::list<GPSEphemeris> R3NList;
1069                       GPSEphemerisStore gpsEphStore;
1070                       list<GPSEphemeris>::const_iterator it;
1071                       rinEphStore.addToList(R3NList);
1072                       for (it = R3NList.begin(); it != R3NList.end(); ++it)
1073                       {
1074                       gpsEphStore.addEphemeris(GPSEphemeris(*it));
1075                       }
1076 
1077                       CivilTime Time(2006,1,31,11,45,0,TimeSystem::GPS);
1078                       const CommonTime ComTime = (CommonTime)Time;
1079 
1080                       try
1081                       {
1082       //--------------RinexEphemerisStore_wiperTest_1 - Verify that the wiper method runs (but shouldn't wipe anything this time)
1083       try {
1084       gpsEphStore.wiper(CommonTime::BEGINNING_OF_TIME); TUPASS("sedIdentifier");
1085       }
1086       catch (...) {
1087       testFramework.failTest();
1088       }
1089 
1090          // Wipe everything outside interval and make sure that we did wipe all the data
1091             // up to the provided time.
1092             gpsEphStore.wiper(ComTime);
1093 
1094             gpsEphStore.dump(dumpData1,1);
1095 
1096       //--------------RinexEphemerisStore_wiperTest_2 - Verify that the new initial time is the time provided (partial wipe)
1097       testFramework.assert(ComTime == gpsEphStore.getInitialTime());
1098       testFramework.next();
1099 
1100          // Wipe everything, return size (should be zero)
1101          gpsEphStore.wiper(CommonTime::END_OF_TIME);
1102          unsigned int Num = gpsEphStore.gpstk::OrbitEphStore::size(); // Get the size of the GPSEphemerisStore
1103 
1104       //--------------RinexEphemerisStore_wiperTest_3 - Verify that the store is empty (total wipe)
1105       testFramework.assert((unsigned int) 0 == Num);
1106       testFramework.next();
1107 
1108       //--------------RinexEphemerisStore_wiperTest_4 - Verify that the initial time is the default END_OF_TIME (indicates empty GPSEphemerisStore)
1109       testFramework.assert(CommonTime::END_OF_TIME == gpsEphStore.getInitialTime());
1110       testFramework.next();
1111 
1112       gpsEphStore.dump(dumpData2,1);
1113       }
1114       catch (Exception& e)
1115       {
1116          // cout << e;
1117          }
1118          dumpData1.close();
1119          dumpData2.close();
1120          inputComparisonOutput1  = inputComparisonOutput + "wiperTest.chk";
1121          inputComparisonOutput15 = inputComparisonOutput + "wiperTest2.chk";
1122 
1123       //--------------RinexEphemerisStore_dumpTest_5 - Check partially wiped output against its pre-determined standard
1124       testFramework.assert(testFramework.fileEqualTest(outputTestOutput1, inputComparisonOutput1, 0));
1125       testFramework.next();
1126 
1127       //--------------RinexEphemerisStore_dumpTest_6 - Check totally wiped output against its pre-determined standard
1128       testFramework.assert(testFramework.fileEqualTest(outputTestOutput15, inputComparisonOutput15, 0));
1129       testFramework.next();
1130 
1131       TURETURN();
1132       }
1133       */
1134 
1135 //=============================================================================
1136 //      Test to assure the quality of OrbitEphStore class member
1137 //      clear()
1138 //
1139 //      This test assures that no exceptions are thrown when we clear
1140 //      a RES object then after we clear the RES Object, we test to
1141 //      make sure that END_OF_TIME is our initial time and
1142 //      BEGINNING_OF_TIME is our final time
1143 //
1144 //      For further inspection of the edit, please view clearTest.txt
1145 //=============================================================================
clearTest()1146    unsigned clearTest()
1147    {
1148       TUDEF("OrbitEphStore", "clear");
1149 
1150 
1151       ofstream clearTestOutputStream;
1152       clearTestOutputStream.open(clearTestOutput.c_str());
1153 
1154       RinexEphemerisStore rinEphStore;
1155       rinEphStore.loadFile(inputRinexNavData.c_str());
1156 
1157       try
1158       {
1159             //-----------------------------------------------------------
1160             // Verify the gpstk::OrbitEphStore::clear() method runs
1161             //-----------------------------------------------------------
1162          try
1163          {
1164             rinEphStore.gpstk::OrbitEphStore::clear();
1165             TUPASS("sedIdentifier");
1166          }
1167          catch (...)
1168          {
1169             TUFAIL("OrbitEphStore::clear() threw an exception when it should not have");
1170          }
1171 
1172             //-----------------------------------------------------------
1173             // Verify that clear set the initial time to END_OF_TIME
1174             //-----------------------------------------------------------
1175          testFramework.assert(CommonTime::END_OF_TIME == rinEphStore.getInitialTime(),
1176                               "clear may not have cleared or may not have reset the initial time", __LINE__);
1177 
1178             //-----------------------------------------------------------
1179             // Verify that clear set the final time to BEGINNING_OF_TIME
1180             //-----------------------------------------------------------
1181          testFramework.assert(CommonTime::BEGINNING_OF_TIME ==
1182                               rinEphStore.getFinalTime(),
1183                               "clear may not have cleared or may not have reset the final time", __LINE__);
1184 
1185 
1186          rinEphStore.dump(clearTestOutputStream,1);
1187       }
1188       catch (Exception& e)
1189       {
1190             // cout << e;
1191       }
1192 
1193       clearTestOutputStream.close();
1194          //-----------------------------------------------------------
1195          // Check partially wiped output against its pre-determined standard
1196          //-----------------------------------------------------------
1197       testFramework.assert(testFramework.fileEqualTest(clearTestOutput,
1198                             clearTestInput, 2),
1199                             "Output from clear does not match its regressive standard.", __LINE__);
1200       TURETURN();
1201    }
1202 
1203 
1204 //=============================================================================
1205 //      Test to assure the quality of OrbitEphStore class member
1206 //      findUserOrbitEph()
1207 //
1208 //      This test will be performed using OrbitEphStore's grand-child
1209 //      class GPSEphemerisStore
1210 //
1211 //      findUserOrbitEph find the ephemeris which a) is within the fit
1212 //      tinterval for the given time of interest and 2) is the last
1213 //      ephemeris transmitted before the time of interest
1214 //      (i.e. min(toi-HOW time))
1215 //
1216 //      This test makes sure that exceptions are thrown if there is no
1217 //      ephemeris data for the given PRN and also that an exception is
1218 //      thrown if there is no data for the PRN at the given
1219 //      time. Store is then cleared and the ephemeris data is readded
1220 //      for output purposes.
1221 //
1222 //      For further inspection of the find, please view findUserTest.txt
1223 //=============================================================================
findUserOrbEphTest()1224    unsigned findUserOrbEphTest()
1225    {
1226       TUDEF("OrbitEphStore", "findUserOrbitEph");
1227 
1228 
1229       ofstream findUserTestOutputStream;
1230       findUserTestOutputStream.open(findUserTestOutput.c_str());
1231 
1232       RinexEphemerisStore rinEphStore;
1233       rinEphStore.loadFile(inputRinexNavData.c_str());
1234 
1235       OrbitEphStore orbEphStore; // Store for found ephemerides
1236 
1237       CivilTime Time(2006,1,31,13,0,1,TimeSystem::GPS);
1238       const CommonTime ComTime = (CommonTime)Time;
1239 
1240       short PRN0 = 0;
1241       short PRN1 = 1;
1242       short PRN15 = 15;
1243       short PRN32 = 32;
1244       short PRN33 = 33;
1245       SatID sid0(PRN0,SatelliteSystem::GPS);
1246       SatID sid1(PRN1,SatelliteSystem::GPS);
1247       SatID sid15(PRN15,SatelliteSystem::GPS);
1248       SatID sid32(PRN32,SatelliteSystem::GPS);
1249       SatID sid33(PRN33,SatelliteSystem::GPS);
1250 
1251       try
1252       {
1253             //-----------------------------------------------------------
1254             // Check that a missing satID (too small) yields a thrown error
1255             //-----------------------------------------------------------
1256          const OrbitEph* oe = rinEphStore.findUserOrbitEph(sid0,ComTime);
1257          if (oe==NULL)
1258          {
1259             TUPASS("sedIdentifier");
1260          }
1261          else
1262          {
1263             TUFAIL("findUserOrbitEph returned a valid pointer when it should not");
1264          }
1265 
1266             //-----------------------------------------------------------
1267             // Check that a missing satID (too big) yields a thrown error
1268             //-----------------------------------------------------------
1269          oe = rinEphStore.findUserOrbitEph(sid33,ComTime);
1270          if (oe==NULL)
1271          {
1272             TUPASS("sedIdentifier");
1273          }
1274          else
1275          {
1276             TUFAIL("findUserOrbitEph returned a valid pointer when it should not");
1277          }
1278 
1279             //-----------------------------------------------------------
1280             // Check that an invalid time yields a thrown error
1281             //-----------------------------------------------------------
1282          oe = rinEphStore.findUserOrbitEph(sid1,CommonTime::END_OF_TIME);
1283          if (oe==NULL)
1284          {
1285             TUPASS("sedIdentifier");
1286          }
1287          else
1288          {
1289             TUFAIL("findUserOrbitEph returned a valid pointer when it should not");
1290          }
1291 
1292             //-----------------------------------------------------------
1293             // Verify that for ideal conditions findUserOrbitEph runs
1294             //-----------------------------------------------------------
1295          oe = rinEphStore.findUserOrbitEph(sid1, ComTime);
1296          if (oe==NULL)
1297          {
1298             TUFAIL("findUserOrbitEph failed to find orbit elements when it should have succeeded");
1299          }
1300          else
1301          {
1302             TUPASS("sedIdentifier");
1303          }
1304 
1305          const OrbitEph* Eph1 = rinEphStore.findUserOrbitEph(sid1, ComTime);
1306          const OrbitEph* Eph15 = rinEphStore.findUserOrbitEph(sid15, ComTime);
1307          const OrbitEph* Eph32 = rinEphStore.findUserOrbitEph(sid32, ComTime);
1308 
1309          orbEphStore.addEphemeris(Eph1);
1310          orbEphStore.addEphemeris(Eph15);
1311          orbEphStore.addEphemeris(Eph32);
1312 
1313          orbEphStore.dump(findUserTestOutputStream,2);
1314 
1315       }
1316       catch (Exception& e)
1317       {
1318             // cout << e;
1319       }
1320 
1321       findUserTestOutputStream.close();
1322          //-----------------------------------------------------------
1323          // Check findUserOrbitEph output against its pre-determined standard
1324          //-----------------------------------------------------------
1325       testFramework.assert(testFramework.fileEqualTest(findUserTestOutput,
1326                             findUserTestInput, 0),
1327                             "findUserOrbitEph output does not match its regressive standard", __LINE__);
1328       TURETURN();
1329    }
1330 
1331 //=============================================================================
1332 //      Test to assure the quality of GPSEphemerisStore class member
1333 //      findNearOrbitEph() findNearOrbitEph finds the ephemeris with
1334 //      the HOW time closest to the time t, i.e with the smalles
1335 //      fabs(t-HOW), but still within the fit interval
1336 //
1337 //      This test makes sure that exceptions are thrown if there is no
1338 //      ephemeris data for the given PRN and also that an exception is
1339 //      thrown if there is no data for the PRN at the given
1340 //      time. Store is then cleared and the epeheris data is readded
1341 //      for output purposes.
1342 //
1343 //      For further inspection of the find, please view findNearTest.txt
1344 //=============================================================================
1345 
1346 
1347 
findNearOrbEphTest()1348    unsigned findNearOrbEphTest()
1349    {
1350       TUDEF("OrbitEphStore", "findNearOrbitEph");
1351 
1352 
1353       ofstream findNearTestOutputStream;
1354       findNearTestOutputStream.open(findNearTestOutput.c_str());
1355 
1356       RinexEphemerisStore rinEphStore;
1357       rinEphStore.loadFile(inputRinexNavData.c_str());
1358 
1359       OrbitEphStore orbEphStore; // Store for found ephemerides
1360 
1361       CivilTime Time(2006,1,31,13,0,1,TimeSystem::GPS);
1362       const CommonTime ComTime = (CommonTime)Time;
1363 
1364       short PRN0 = 0;
1365       short PRN1 = 1;
1366       short PRN15 = 15;
1367       short PRN32 = 32;
1368       short PRN33 = 33;
1369       SatID sid0(PRN0,SatelliteSystem::GPS);
1370       SatID sid1(PRN1,SatelliteSystem::GPS);
1371       SatID sid15(PRN15,SatelliteSystem::GPS);
1372       SatID sid32(PRN32,SatelliteSystem::GPS);
1373       SatID sid33(PRN33,SatelliteSystem::GPS);
1374 
1375       try
1376       {
1377             //-----------------------------------------------------------
1378             // Check that a missing satID (too small) yields a thrown error
1379             //-----------------------------------------------------------
1380          const OrbitEph* oe = rinEphStore.findNearOrbitEph(sid0,ComTime);
1381          if (oe==NULL)
1382          {
1383             TUPASS("sedIdentifier");
1384          }
1385          else
1386          {
1387             TUFAIL("findUserOrbitEph returned a valid pointer when it should not");
1388          }
1389 
1390             //-----------------------------------------------------------
1391             // Check that a missing satID (too big) yields a thrown error
1392             //-----------------------------------------------------------
1393          oe = rinEphStore.findNearOrbitEph(sid33,ComTime);
1394          if (oe==NULL)
1395          {
1396             TUPASS("sedIdentifier");
1397          }
1398          else
1399          {
1400             TUFAIL("findUserOrbitEph returned a valid pointer when it should not");
1401          }
1402 
1403             //-----------------------------------------------------------
1404             // Check that an invalid time yields a thrown error
1405             //
1406             // TEST REMOVED.  findNearOrbitEph() does not check
1407             // that the elements are within their fit interval.  Therefore
1408             // there is no concept of an "invalid time".
1409             //-----------------------------------------------------------
1410             /*
1411             oe = rinEphStore.findNearOrbitEph(sid1,CommonTime::END_OF_TIME);
1412             if (oe==NULL)
1413             {
1414                TUPASS("sedIdentifier");
1415             }
1416             else
1417             {
1418                TUFAIL("findUserOrbitEph returned a valid pointer when it should not");
1419             }
1420             */
1421 
1422             //-----------------------------------------------------------
1423             // Verify that for ideal conditions findUserOrbitEph runs
1424             //-----------------------------------------------------------
1425          oe = rinEphStore.findNearOrbitEph(sid1, ComTime);
1426          if (oe==NULL)
1427          {
1428             TUFAIL("findUserOrbitEph failed to find orbit elements when it should have succeeded");
1429          }
1430          else
1431          {
1432             TUPASS("sedIdentifier");
1433          }
1434 
1435          const OrbitEph* Eph1 = rinEphStore.findUserOrbitEph(sid1, ComTime);
1436          const OrbitEph* Eph15 = rinEphStore.findUserOrbitEph(sid15, ComTime);
1437          const OrbitEph* Eph32 = rinEphStore.findUserOrbitEph(sid32, ComTime);
1438 
1439          orbEphStore.addEphemeris(Eph1);
1440          orbEphStore.addEphemeris(Eph15);
1441          orbEphStore.addEphemeris(Eph32);
1442 
1443          orbEphStore.dump(findNearTestOutputStream,2);
1444 
1445       }
1446       catch (Exception& e)
1447       {
1448          e.addLocation(FILE_LOCATION);
1449          cout << e;
1450       }
1451 
1452       findNearTestOutputStream.close();
1453 
1454          //-----------------------------------------------------------
1455          // Check findNearOrbitEph output against its pre-determined standard
1456          //-----------------------------------------------------------
1457       testFramework.assert(testFramework.fileEqualTest(findNearTestOutput,
1458                             findNearTestInput, 0),
1459                             "findNearOrbitEph output does not match its regressive standard", __LINE__);
1460       TURETURN();
1461    }
1462 
1463 
1464 
1465 //=============================================================================
1466 //      Test to assure the quality of GPSEphemerisStore class member
1467 //      addToList()
1468 
1469 //      This test creats a list of GPSEphemeris and then adds all of
1470 //      the ephemeris members to that list.  After that of the List
1471 //      and Store are checked to be equal.
1472 //=============================================================================
1473 
addToListTest()1474    unsigned addToListTest()
1475    {
1476       TUDEF("OrbitEphStore", "addToList");
1477 
1478 
1479       const short PRN1 = 1;
1480       const short PRN15 = 15;
1481       const short PRN32 = 32;
1482 
1483       unsigned numberOfEntries = 41;
1484       unsigned numberOfEntries1 = 15;
1485       unsigned numberOfEntries15 = 13;
1486       unsigned numberOfEntries32 = 13;
1487 
1488       SatID sid1(PRN1,SatelliteSystem::GPS);
1489       SatID sid15(PRN15,SatelliteSystem::GPS);
1490       SatID sid32(PRN32,SatelliteSystem::GPS);
1491 
1492       RinexEphemerisStore rinEphStore;
1493       rinEphStore.loadFile(inputRinexNavData.c_str());
1494 
1495       std::list<GPSEphemeris> R3NList;
1496       GPSEphemerisStore gpsEphStore;
1497       list<GPSEphemeris>::const_iterator it;
1498       rinEphStore.addToList(R3NList);
1499       for (it = R3NList.begin(); it != R3NList.end(); ++it)
1500       {
1501          gpsEphStore.addEphemeris(GPSEphemeris(*it));
1502 //                        GPSEphemeris(*it).dumpBody(cout);
1503       }
1504       try
1505       {
1506             //-----------------------------------------------------------
1507             // Assert that the number of added members equals the size
1508             // of Store (all members added)
1509             //-----------------------------------------------------------
1510          testFramework.assert(rinEphStore.gpstk::OrbitEphStore::size() ==
1511                               gpsEphStore.gpstk::OrbitEphStore::size(),
1512                               "The added entries are not reflected in the GPSEphemerisStore", __LINE__);
1513 
1514          testFramework.assert(rinEphStore.gpstk::OrbitEphStore::size() ==
1515                               numberOfEntries, "The total number of entries is not what is expected",
1516                               __LINE__);
1517 
1518          testFramework.assert(rinEphStore.gpstk::OrbitEphStore::size(
1519                                  sid1) == numberOfEntries1,
1520                               "The total number of entries for SatID 1 is not what is expected", __LINE__);
1521 
1522          testFramework.assert(rinEphStore.gpstk::OrbitEphStore::size(
1523                                  sid15) == numberOfEntries15,
1524                               "The total number of entries for SatID 15 is not what is expected", __LINE__);
1525 
1526          testFramework.assert(rinEphStore.gpstk::OrbitEphStore::size(
1527                                  sid32) == numberOfEntries32,
1528                               "The total number of entries for SatID 32 is not what is expected", __LINE__);
1529       }
1530       catch (Exception& e)
1531       {
1532             // cout << e;
1533       }
1534       TURETURN();
1535    }
1536 
1537 //=============================================================================
1538 //      Initialize Test Data Filenames
1539 //=============================================================================
1540 
init()1541    void init()
1542    {
1543       std::string dataFilePath = gpstk::getPathData();
1544       std::string tempFilePath = gpstk::getPathTestTemp();
1545       std::string file_sep = "/";
1546 
1547       inputRinexNavData             = dataFilePath + file_sep +
1548                                       "test_input_rinex_nav_ephemerisData.031";
1549       inputNotaFile                 = dataFilePath + file_sep + "NotaFILE";
1550 
1551       findEphTestOutput             = tempFilePath + file_sep +
1552                                       "test_output_ephemeris_dump_findEph.txt";
1553       findEphTestInput              = dataFilePath + file_sep +
1554                                       "test_input_ephemeris_dump_findEph.txt";
1555       gpsEphemerisStoreDumpOutput   = tempFilePath + file_sep + "DataDump.txt";
1556 
1557       dumpTestOutputForDetail0      = tempFilePath + file_sep +
1558                                       "test_output_ephemeris_dump_detail0.txt";
1559       dumpTestOutputForDetail1      = tempFilePath + file_sep +
1560                                       "test_output_ephemeris_dump_detail1.txt";
1561       dumpTestOutputForDetail2      = tempFilePath + file_sep +
1562                                       "test_output_ephemeris_dump_detail2.txt";
1563       dumpTestInputForDetail0       = dataFilePath + file_sep +
1564                                       "test_input_ephemeris_dump_detail0.txt";
1565       dumpTestInputForDetail1       = dataFilePath + file_sep +
1566                                       "test_input_ephemeris_dump_detail1.txt";
1567       dumpTestInputForDetail2       = dataFilePath + file_sep +
1568                                       "test_input_ephemeris_dump_detail2.txt";
1569 
1570       editTestOutput                = tempFilePath + file_sep +
1571                                       "test_output_ephemeris_dump_edit.txt";
1572       editTestInput                 = dataFilePath + file_sep +
1573                                       "test_input_ephemeris_dump_edit.txt";
1574 
1575       clearTestOutput               = tempFilePath + file_sep +
1576                                       "test_output_ephemeris_dump_clear.txt";
1577       clearTestInput                = dataFilePath + file_sep +
1578                                       "test_input_ephemeris_dump_clear.txt";
1579 
1580       findUserTestOutput            = tempFilePath + file_sep +
1581                                       "test_output_ephemeris_dump_findUser.txt";
1582       findUserTestInput             = dataFilePath + file_sep +
1583                                       "test_input_ephemeris_dump_findUser.txt";
1584 
1585       findNearTestOutput            = tempFilePath + file_sep +
1586                                       "test_output_ephemeris_dump_findNear.txt";
1587       findNearTestInput             = dataFilePath + file_sep +
1588                                       "test_input_ephemeris_dump_findNear.txt";
1589       comparisonOutput1  =
1590          "x:(1.43293e+07, -2.70658e+06, -2.19986e+07),"
1591          " v:(354.7, 2812.28, -117.977),"
1592          " clk bias:3.42039e-05,"
1593          " clk drift:1.93268e-12,"
1594          " relcorr:-1.49802e-09,"
1595          " health:Healthy";
1596       comparisonOutput15 =
1597          "x:(1.46708e+07, 7.54272e+06, 2.07205e+07),"
1598          " v:(-2147.84, 1575.62, 902.864),"
1599          " clk bias:0.000558473,"
1600          " clk drift:5.91172e-12,"
1601          " relcorr:2.04148e-08,"
1602          " health:Healthy";
1603       comparisonOutput32 =
1604          "x:(8.40859e+06, 1.71989e+07, -1.87307e+07),"
1605          " v:(-2248.19, -606.201, -1577.98),"
1606          " clk bias:2.12814e-05,"
1607          " clk drift:3.41061e-12,"
1608          " relcorr:-5.04954e-09,"
1609          " health:Healthy";
1610    }
1611 
1612 private:
1613    std::string inputRinexNavData;
1614    std::string inputNotaFile;
1615 
1616    std::string findEphTestOutput;
1617    std::string findEphTestInput;
1618    std::string gpsEphemerisStoreDumpOutput;
1619 
1620    std::string dumpTestOutputForDetail0;
1621    std::string dumpTestOutputForDetail1;
1622    std::string dumpTestOutputForDetail2;
1623    std::string dumpTestInputForDetail0;
1624    std::string dumpTestInputForDetail1;
1625    std::string dumpTestInputForDetail2;
1626 
1627    std::string editTestOutput;
1628    std::string editTestInput;
1629 
1630    std::string clearTestOutput;
1631    std::string clearTestInput;
1632 
1633    std::string findUserTestOutput;
1634    std::string findUserTestInput;
1635 
1636    std::string findNearTestOutput;
1637    std::string findNearTestInput;
1638 
1639    std::string comparisonOutput1;
1640    std::string comparisonOutput15;
1641    std::string comparisonOutput32;
1642 };
1643 
main()1644 int main() // Main function to initialize and run all tests above
1645 {
1646    unsigned errorTotal = 0;
1647    RinexEphemerisStore_T testClass;
1648    testClass.init();
1649 
1650    errorTotal += testClass.RESTest();
1651    errorTotal += testClass.findEphTest();
1652    errorTotal += testClass.getXvtTest();
1653    errorTotal += testClass.computeXvtTest();
1654    errorTotal += testClass.getSVHealthTest();
1655    errorTotal += testClass.dumpTest();
1656    errorTotal += testClass.addToListTest();
1657    errorTotal += testClass.addEphemerisTest();
1658    errorTotal += testClass.editTest();
1659    errorTotal += testClass.clearTest();
1660    errorTotal += testClass.findUserOrbEphTest();
1661    errorTotal += testClass.findNearOrbEphTest();
1662    cout << "Total Failures for " << __FILE__ << ": " << errorTotal << endl;
1663 
1664    return errorTotal; // Return the total number of errors
1665 }
1666