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 "GloEphemerisStore.hpp"
41 #include "CivilTime.hpp"
42 #include "TimeString.hpp"
43 #include "TestUtil.hpp"
44 #include "GPSWeekSecond.hpp"
45 #include "Rinex3NavStream.hpp"
46 #include "Rinex3NavData.hpp"
47 #include "SatelliteSystem.hpp"
48
49 using namespace std;
50
51 namespace gpstk
52 {
operator <<(ostream & s,const gpstk::SatelliteSystem sys)53 ostream& operator<<(ostream& s, const gpstk::SatelliteSystem sys)
54 {
55 s << gpstk::StringUtils::asString(sys);
56 return s;
57 }
58 }
59
60 class OrbElemStore_T
61 {
62 public:
63 std::string inputRN3Data;
64
OrbElemStore_T()65 OrbElemStore_T()
66 {
67 std::string dataFilePath = gpstk::getPathData();
68 std::string tempFilePath = gpstk::getPathTestTemp();
69 std::string fileSep = gpstk::getFileSep();
70
71 inputRN3Data = dataFilePath + fileSep + "mixed.06n";
72 }
73
74
75 /** This tests the behavior of OrbElemStore when the store is
76 * empty. Under normal circumstances the map for a given
77 * satellite would not be empty, but that can't be guaranteed as
78 * soon as edit() is used. */
doFindEphEmptyTests()79 unsigned doFindEphEmptyTests()
80 {
81 TUDEF("OrbElemStore","Empty Store Tests");
82 try
83 {
84 gpstk::GloEphemerisStore store;
85 gpstk::Rinex3NavData nd = loadNav(store, testFramework, true);
86 TUASSERTE(gpstk::SatelliteSystem,
87 gpstk::SatelliteSystem::Glonass, nd.sat.system);
88 gpstk::CommonTime searchTime(nd.time);
89 gpstk::SatID sat(nd.sat);
90
91 // make sure the ephemeris is in the store
92 TUCSM("size");
93 TUASSERTE(unsigned, 1, store.size());
94
95 // make sure we can find it
96 TUCSM("findNearEphemeris");
97 TUCATCH(store.findNearEphemeris(sat, searchTime));
98
99 TUCSM("findEphemeris");
100 TUCATCH(store.findEphemeris(sat, searchTime));
101
102 // remove the ephemeris
103 TUCSM("edit");
104 store.edit(store.getFinalTime() + 604800);
105
106 // make sure the ephemeris has been removed
107 TUCSM("size");
108 TUASSERTE(unsigned, 0, store.size());
109
110 // make sure we can't find it and don't seg fault
111 TUCSM("findNearEphemeris");
112 try
113 {
114 const gpstk::GloEphemeris& ge =
115 store.findNearEphemeris(sat, searchTime);
116 TUFAIL("Called findNearEphemeris for empty store and FAILED to"
117 " throw InvalidRequest");
118 }
119 catch (gpstk::InvalidRequest)
120 {
121 TUPASS("Called findNearEphemeris for empty store and received"
122 " InvalidRequest as expected.");
123 }
124
125 TUCSM("findEphemeris");
126 try
127 {
128 const gpstk::GloEphemeris& ge =
129 store.findEphemeris(sat, searchTime);
130 TUFAIL("Called findEphemeris for empty store and FAILED to"
131 " throw InvalidRequest");
132 }
133 catch (gpstk::InvalidRequest)
134 {
135 TUPASS("Called findEphemeris for empty store and received"
136 " InvalidRequest as expected.");
137 }
138 }
139 catch (gpstk::Exception &exc)
140 {
141 cerr << exc << endl;
142 TUFAIL("Unexpected exception");
143 }
144 catch (...)
145 {
146 TUFAIL("Unexpected exception");
147 }
148 TURETURN();
149 }
150
151
computeXvtTest()152 unsigned computeXvtTest()
153 {
154 TUDEF("GloEphemerisStore", "computeXvt");
155 try
156 {
157 gpstk::GloEphemerisStore store;
158 gpstk::Rinex3NavData nd = loadNav(store, testFramework, false);
159 gpstk::Xvt rv;
160 gpstk::SatID fake(933, gpstk::SatelliteSystem::Glonass);
161 TUCATCH(rv = store.computeXvt(nd.sat, nd.time));
162 TUASSERTE(gpstk::Xvt::HealthStatus,
163 gpstk::Xvt::HealthStatus::Healthy, rv.health);
164 TUCATCH(rv = store.computeXvt(fake, nd.time));
165 TUASSERTE(gpstk::Xvt::HealthStatus,
166 gpstk::Xvt::HealthStatus::Unavailable, rv.health);
167 }
168 catch (...)
169 {
170 TUFAIL("Unexpected exception");
171 }
172 TURETURN();
173 }
174
175
getSVHealthTest()176 unsigned getSVHealthTest()
177 {
178 TUDEF("GloEphemerisStore", "getSVHealth");
179 try
180 {
181 gpstk::GloEphemerisStore store;
182 gpstk::Rinex3NavData nd = loadNav(store, testFramework, false);
183 gpstk::Xvt::HealthStatus rv;
184 gpstk::SatID fake(933, gpstk::SatelliteSystem::Glonass);
185 TUCATCH(rv = store.getSVHealth(nd.sat, nd.time));
186 TUASSERTE(gpstk::Xvt::HealthStatus,
187 gpstk::Xvt::HealthStatus::Healthy, rv);
188 TUCATCH(rv = store.getSVHealth(fake, nd.time));
189 TUASSERTE(gpstk::Xvt::HealthStatus,
190 gpstk::Xvt::HealthStatus::Unavailable, rv);
191 }
192 catch (...)
193 {
194 TUFAIL("Unexpected exception");
195 }
196 TURETURN();
197 }
198
199
loadNav(gpstk::GloEphemerisStore & store,gpstk::TestUtil & testFramework,bool firstOnly)200 gpstk::Rinex3NavData loadNav(gpstk::GloEphemerisStore& store,
201 gpstk::TestUtil& testFramework,
202 bool firstOnly)
203 {
204 gpstk::Rinex3NavStream ns(inputRN3Data.c_str());
205 gpstk::Rinex3NavHeader nh;
206 gpstk::Rinex3NavData nd;
207 TUASSERT(ns.good());
208 ns >> nh;
209 TUASSERT(ns.good());
210 ns >> nd;
211 if (firstOnly)
212 {
213 while ((nd.sat.system != gpstk::SatelliteSystem::Glonass) && ns)
214 {
215 ns >> nd;
216 }
217 if (nd.sat.system != gpstk::SatelliteSystem::Glonass)
218 {
219 // somehow got through the source file without any GLONASS data
220 TUFAIL("input file did not contain GLONASS data");
221 return nd;
222 }
223 TUASSERT(store.addEphemeris(nd));
224 }
225 else
226 {
227 while (ns)
228 {
229 ns >> nd;
230 if (nd.sat.system == gpstk::SatelliteSystem::Glonass)
231 {
232 TUASSERT(store.addEphemeris(nd));
233 }
234 }
235 }
236 return nd;
237 }
238
239 };
240
241
main(int argc,char * argv[])242 int main(int argc, char *argv[])
243 {
244 unsigned total = 0;
245 OrbElemStore_T testClass;
246 total += testClass.doFindEphEmptyTests();
247 total += testClass.computeXvtTest();
248 total += testClass.getSVHealthTest();
249
250 cout << "Total Failures for " << __FILE__ << ": " << total << endl;
251 return total;
252 }
253