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