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 "OrbitEphStore.hpp"
40 #include "CivilTime.hpp"
41 #include "TimeString.hpp"
42 #include "TestUtil.hpp"
43 #include "GPSWeekSecond.hpp"
44 
45 using namespace std;
46 
47 class OrbitEphStore_T
48 {
49 public:
50       /** This tests the behavior of OrbitEphStore when the store is
51        * empty.  Under normal circumstances the map for a given
52        * satellite would not be empty, but that can't be guaranteed as
53        * soon as edit() is used. */
doFindEphEmptyTests()54    unsigned doFindEphEmptyTests()
55    {
56       TUDEF("OrbitEphStore","findUserOrbitEph");
57       try
58       {
59          gpstk::OrbitEphStore store;
60             // this eph will be removed by edit()
61          gpstk::OrbitEph baleted;
62          gpstk::SatID sat(11, gpstk::SatelliteSystem::GPS);
63          gpstk::ObsID obsID(gpstk::ObservationType::NavMsg,
64                             gpstk::CarrierBand::L1,
65                             gpstk::TrackingCode::CA);
66          baleted.dataLoadedFlag = true;
67          baleted.satID = sat;
68          baleted.obsID = obsID;
69          baleted.ctToe = gpstk::GPSWeekSecond(1917, 576000);
70          baleted.ctToc = gpstk::GPSWeekSecond(1917, 576000);
71          baleted.beginValid = baleted.ctToe - 3600;
72          baleted.endValid = baleted.ctToe + 3600;
73 
74          gpstk::CommonTime searchTime(baleted.ctToe);
75 
76          TUCSM("addEphemeris");
77          store.addEphemeris(&baleted);
78 
79             // make sure the ephemeris is in the store
80          TUCSM("size");
81          TUASSERTE(unsigned, 1, store.size());
82 
83             // make sure we can find it
84          TUCSM("findNearOrbitEph");
85          TUASSERT(store.findNearOrbitEph(sat, searchTime) != NULL);
86 
87          TUCSM("findUserOrbitEph");
88          TUASSERT(store.findUserOrbitEph(sat, searchTime) != NULL);
89 
90             // remove the ephemeris
91          TUCSM("edit");
92          store.edit(baleted.endValid + 604800);
93 
94             // make sure the ephemeris has been removed
95          TUCSM("size");
96          TUASSERTE(unsigned, 0, store.size());
97 
98             // make sure we can't find it and don't seg fault
99          TUCSM("findNearOrbitEph");
100          TUASSERT(store.findNearOrbitEph(sat, searchTime) == NULL);
101 
102          TUCSM("findUserOrbitEph");
103          TUASSERT(store.findUserOrbitEph(sat, searchTime) == NULL);
104       }
105       catch (gpstk::Exception &exc)
106       {
107          cerr << exc << endl;
108          TUFAIL("Unexpected exception");
109       }
110       catch (...)
111       {
112          TUFAIL("Unexpected exception");
113       }
114       TURETURN();
115    }
116 
117 
basicTests()118    unsigned basicTests()
119    {
120       TUDEF("OrbitEphStore","Basic Access Tests");
121       try
122       {
123          gpstk::OrbitEphStore store;
124 
125             // Create a small number of OrbElemBase object with
126             // specific characteristics.
127 
128          gpstk::OrbitEph to1;
129          gpstk::SatID sat1(1, gpstk::SatelliteSystem::GPS);
130          gpstk::ObsID obsID(gpstk::ObservationType::NavMsg,
131                             gpstk::CarrierBand::L1,
132                             gpstk::TrackingCode::CA);
133          to1.dataLoadedFlag = true;
134          to1.satID = sat1;
135          to1.obsID = obsID;
136          to1.ctToe = gpstk::GPSWeekSecond(2000, 7200);   // 0200
137          to1.ctToc = to1.ctToe;
138          to1.beginValid = to1.ctToe - 7200;
139          to1.endValid = to1.ctToe + 7200;
140 
141          gpstk::OrbitEph to2;
142          gpstk::SatID sat2(32, gpstk::SatelliteSystem::GPS);
143          to2.dataLoadedFlag = true;
144          to2.satID = sat2;
145          to2.obsID = obsID;
146          to2.ctToe = gpstk::GPSWeekSecond(2000, 79200);    // 2200
147          to2.ctToc = to2.ctToe;
148          to2.beginValid = to2.ctToe - 7200;
149          to2.endValid = to2.ctToe + 7200;
150 
151          gpstk::OrbitEph to3;
152          gpstk::SatID sat3(16, gpstk::SatelliteSystem::GPS);
153          to3.dataLoadedFlag = true;
154          to3.satID = sat3;
155          to3.obsID = obsID;
156          to3.ctToe = gpstk::GPSWeekSecond(2000, 43200);    // 1200
157          to3.ctToc = to3.ctToe;
158          to3.beginValid = to3.ctToe - 7200;
159          to3.endValid = to3.ctToe + 7200;
160 
161          store.addEphemeris(&to1);
162          store.addEphemeris(&to2);
163          store.addEphemeris(&to3);
164 
165             // make sure the ephemeris is in the store
166          TUCSM("size");
167          TUASSERTE(unsigned, 3, store.size());
168 
169          TUCSM("getIndexSet");
170          set<gpstk::SatID> testSet = store.getIndexSet();
171          if (testSet.find(sat1)==testSet.end())
172          {
173             stringstream ss;
174             ss << "Did not find expected SV ";
175             ss << sat1;
176             ss << " in the store.";
177             TUFAIL(ss.str());
178          }
179          if (testSet.find(sat2)==testSet.end())
180          {
181             stringstream ss;
182             ss << "Did not find expected SV ";
183             ss << sat2;
184             ss << " in the store.";
185             TUFAIL(ss.str());
186          }
187          if (testSet.find(sat3)==testSet.end())
188          {
189             stringstream ss;
190             ss << "Did not find expected SV ";
191             ss << sat3;
192             ss << " in the store.";
193             TUFAIL(ss.str());
194          }
195 
196          TUCSM("computeXvt");
197          gpstk::Xvt xvt;
198          TUCATCH(xvt = store.computeXvt(to1.satID, to1.ctToe));
199          TUASSERTE(gpstk::Xvt::HealthStatus,
200                    gpstk::Xvt::HealthStatus::Healthy, xvt.health);
201          TUCATCH(xvt = store.computeXvt(to2.satID, to2.ctToe));
202          TUASSERTE(gpstk::Xvt::HealthStatus,
203                    gpstk::Xvt::HealthStatus::Healthy, xvt.health);
204          TUCATCH(xvt = store.computeXvt(to3.satID, to3.ctToe));
205          TUASSERTE(gpstk::Xvt::HealthStatus,
206                    gpstk::Xvt::HealthStatus::Healthy, xvt.health);
207          gpstk::SatID bogus(33, gpstk::SatelliteSystem::GPS);
208          TUCATCH(xvt = store.computeXvt(bogus, to3.ctToe));
209          TUASSERTE(gpstk::Xvt::HealthStatus,
210                    gpstk::Xvt::HealthStatus::Unavailable, xvt.health);
211 
212          TUCSM("getSVHealth");
213          gpstk::Xvt::HealthStatus health;
214          TUCATCH(health = store.getSVHealth(to1.satID, to1.ctToe));
215          TUASSERTE(gpstk::Xvt::HealthStatus,
216                    gpstk::Xvt::HealthStatus::Healthy, health);
217          TUCATCH(health = store.getSVHealth(to2.satID, to2.ctToe));
218          TUASSERTE(gpstk::Xvt::HealthStatus,
219                    gpstk::Xvt::HealthStatus::Healthy, health);
220          TUCATCH(health = store.getSVHealth(to3.satID, to3.ctToe));
221          TUASSERTE(gpstk::Xvt::HealthStatus,
222                    gpstk::Xvt::HealthStatus::Healthy, health);
223          TUCATCH(health = store.getSVHealth(bogus, to3.ctToe));
224          TUASSERTE(gpstk::Xvt::HealthStatus,
225                    gpstk::Xvt::HealthStatus::Unavailable, health);
226 
227          TUCSM("getInitialTime");
228          TUASSERTE(gpstk::CommonTime, to1.beginValid, store.getInitialTime());
229 
230          TUCSM("getFinalTime");
231          TUASSERTE(gpstk::CommonTime, to2.endValid, store.getFinalTime());
232       }
233       catch (gpstk::Exception &exc)
234       {
235          cerr << exc << endl;
236          TUFAIL("Unexpected exception");
237       }
238       catch (...)
239       {
240          TUFAIL("Unexpected exception");
241       }
242       TURETURN();
243    }
244 };
245 
246 
main(int argc,char * argv[])247 int main(int argc, char *argv[])
248 {
249    unsigned total = 0;
250    OrbitEphStore_T testClass;
251    total += testClass.doFindEphEmptyTests();
252    total += testClass.basicTests();
253 
254    cout << "Total Failures for " << __FILE__ << ": " << total << endl;
255    return total;
256 }
257