TimeTag_T.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include "TimeTag.hpp"
40 #include "ANSITime.hpp"
41 #include "CivilTime.hpp"
42 #include "MJD.hpp"
43 #include "JulianDate.hpp"
44 #include "GPSWeekSecond.hpp"
45 #include "GPSWeekZcount.hpp"
46 #include "UnixTime.hpp"
47 #include "YDSTime.hpp"
48 #include "TestUtil.hpp"
50 #include <iostream>
51 #include <fstream>
52 #include <string>
53 #include <iomanip>
54 #include <sstream>
55 
56 using namespace gnsstk;
57 using namespace std;
58 
59 // This test file will contain a series of scanf checks for each of
60 // the directly tested TimeTag classes.
61 
62 class TimeTag_T
63 {
64 public:
65  TimeTag_T() {}
67 
68 // ANSITime scanf Test
69  unsigned scanfANSITime()
70  {
71  TUDEF("TimeTag", "scanf(ANSITime)");
72 
73 
74  //Set a hardcoded time
75  ANSITime hardCodedTime(13500000,TimeSystem(2));
76  //Provide a format string
77  std::string formatString = "%08K %03P";
78  //Print the time using that format
79  std::string timeString = hardCodedTime.printf(formatString);
80  ANSITime scannedTime;
81 
82  //Read the formatted string back into a new time variable
83  scannedTime.scanf(timeString, formatString);
84 
85  //Verify the scanned time is the same as the hardcoded time
86  TUASSERTE(ANSITime, hardCodedTime, scannedTime);
87 
88  TURETURN();
89  }
90 
91 // CivilTime scanf Test
92  unsigned scanfCivilTime()
93  {
94  TUDEF("TimeTag", "scanf(CivilTime)");
95 
96 
97  //Set a hardcoded time
98  CivilTime hardCodedTime(2008,8,21,13,30,15.,TimeSystem::UTC);
99  //Provide a format string
100  std::string formatString = "%04Y %02m %02d %02H %02M %02S %03P";
101  //Print the time using that format
102  std::string timeString = hardCodedTime.printf(formatString);
103  CivilTime scannedTime;
104 
105  //Read the formatted string back into a new time variable
106  scannedTime.scanf(timeString, formatString);
107 
108  //Verify the scanned time is the same as the hardcoded time
109  TUASSERTE(CivilTime, hardCodedTime, scannedTime);
110 
111  //Reset the time for a new format to be scanned
112  scannedTime.reset();
113 
114 
115  //Provide a format string
116  formatString = "%02y %02m %02d %02H %02M %02S %03P";
117  //Print the time using that format
118  timeString = hardCodedTime.printf(formatString);
119  //Read the formatted string back into a new time variable
120  scannedTime.scanf(timeString, formatString);
121 
122  //Verify the scanned time is the same as the hardcoded time
123  TUASSERTE(CivilTime, hardCodedTime, scannedTime);
124 
125  //Reset the time for a new format to be scanned
126  scannedTime.reset();
127 
128  //Provide a format string
129  formatString = "%04Y %03b %02d %02H %02M %02S %03P";
130  //Print the time using that format
131  timeString = hardCodedTime.printf(formatString);
132  //Read the formatted string back into a new time variable
133  scannedTime.scanf(timeString, formatString);
134 
135  //Verify the scanned time is the same as the hardcoded time
136  TUASSERTE(CivilTime, hardCodedTime, scannedTime);
137 
138  //Reset the time for a new format to be scanned
139  scannedTime.reset();
140 
141  //Provide a format string
142  formatString = "%04Y %03b %02d %02H %02M %5.2f %03P";
143  //Print the time using that format
144  timeString = hardCodedTime.printf(formatString);
145  //Read the formatted string back into a new time variable
146  scannedTime.scanf(timeString, formatString);
147 
148  //Verify the scanned time is the same as the hardcoded time
149  TUASSERTE(CivilTime, hardCodedTime, scannedTime);
150 
151  //Reset the time for a new format to be scanned
152  scannedTime.reset();
153 
154  //Provide a format string
155  formatString = "%02y %03b %02d %02H %02M %5.2f %03P";
156  //Print the time using that format
157  timeString = hardCodedTime.printf(formatString);
158  //Read the formatted string back into a new time variable
159  scannedTime.scanf(timeString, formatString);
160 
161  //Verify the scanned time is the same as the hardcoded time
162  TUASSERTE(CivilTime, hardCodedTime, scannedTime);
163 
164  //Reset the time for a new format to be scanned
165  scannedTime.reset();
166 
167  TURETURN();
168  }
169 
170 
171 
172 // GPSWeekSecond scanf Test
174  {
175  TUDEF("TimeTag", "scanf(GPSWeekSecond)");
176 
177 
178  //Set a hardcoded time
179  GPSWeekSecond hardCodedTime(1300,13500.,TimeSystem::GPS);
180  //Provide a format string
181  std::string formatString = "%04F %8.2g %03P";
182  //Print the time using that format
183  std::string timeString = hardCodedTime.printf(formatString);
184  GPSWeekSecond scannedTime;
185 
186  //Read the formatted string back into a new time variable
187  scannedTime.scanf(timeString, formatString);
188 
189  //Verify the scanned time is the same as the hardcoded time
190  TUASSERTE(GPSWeekSecond, hardCodedTime, scannedTime);
191 
192  TURETURN();
193  }
194 
195 // GPSWeekZcount scanf Test
197  {
198  TUDEF("TimeTag", "scanf(GPSWeekZcount)");
199 
200 
201  //Set a hardcoded time
202  GPSWeekZcount hardCodedTime(1300,13500.,TimeSystem(2));
203  //Provide a format string
204  std::string formatString = "%04F %05z %03P";
205  //Print the time using that format
206  std::string timeString = hardCodedTime.printf(formatString);
207  GPSWeekZcount scannedTime;
208 
209  //Read the formatted string back into a new time variable
210  scannedTime.scanf(timeString, formatString);
211 
212  //Verify the scanned time is the same as the hardcoded time
213  TUASSERTE(GPSWeekZcount, hardCodedTime, scannedTime);
214 
215  //Reset the time for a new format to be scanned
216  scannedTime.reset();
217 
218 
219  //Provide a format string
220  formatString = "%04F %10C %03P";
221  //Print the time using that format
222  timeString = hardCodedTime.printf(formatString);
223  //Read the formatted string back into a new time variable
224  scannedTime.scanf(timeString, formatString);
225 
226  //Verify the scanned time is the same as the hardcoded time
227  TUASSERTE(GPSWeekZcount, hardCodedTime, scannedTime);
228 
229  //Reset the time for a new format to be scanned
230  scannedTime.reset();
231 
232 
233  //Provide a format string
234  formatString = "%04F %10c %03P";
235  //Print the time using that format
236  timeString = hardCodedTime.printf(formatString);
237  //Read the formatted string back into a new time variable
238  scannedTime.scanf(timeString, formatString);
239 
240  //Verify the scanned time is the same as the hardcoded time
241  TUASSERTE(GPSWeekZcount, hardCodedTime, scannedTime);
242 
243  TURETURN();
244  }
245 
246 // JulianDate scanf Test
247  unsigned scanfJulianDate()
248  {
249  TUDEF("TimeTag", "scanf(JulianDate)");
250 
251 
252  //Set a hardcoded time
253  JulianDate hardCodedTime(1234567,TimeSystem(2));
254  //Provide a format string
255  std::string formatString = "%10.2J %03P";
256  //Print the time using that format
257  std::string timeString = hardCodedTime.printf(formatString);
258  JulianDate scannedTime;
259 
260  //Read the formatted string back into a new time variable
261  scannedTime.scanf(timeString, formatString);
262 
263  //Verify the scanned time is the same as the hardcoded time
264  TUASSERTE(JulianDate, hardCodedTime, scannedTime);
265 
266  TURETURN();
267  }
268 
269 // MJD scanf Test
270  unsigned scanfMJD()
271  {
272  TUDEF("TimeTag", "scanf(MJD)");
273 
274 
275  //Set a hardcoded time
276  MJD hardCodedTime(123456,TimeSystem(1));
277  //Provide a format string
278  std::string formatString = "%08Q %03P";
279  //Print the time using that format
280  std::string timeString = hardCodedTime.printf(formatString);
281  MJD scannedTime;
282 
283  //Read the formatted string back into a new time variable
284  scannedTime.scanf(timeString, formatString);
285 
286  //Verify the scanned time is the same as the hardcoded time
287  TUASSERTE(MJD, hardCodedTime, scannedTime);
288 
289  TURETURN();
290  }
291 
292 // UnixTime scanf Test
293  unsigned scanfUnixTime()
294  {
295  TUDEF("TimeTag", "scanf(UnixTime)");
296 
297 
298  //Set a hardcoded time
299  UnixTime hardCodedTime(1654321,10,TimeSystem(5));
300  //Provide a format string
301  std::string formatString = "%07U %02u %03P";
302  //Print the time using that format
303  std::string timeString = hardCodedTime.printf(formatString);
304  UnixTime scannedTime;
305 
306  //Read the formatted string back into a new time variable
307  scannedTime.scanf(timeString, formatString);
308 
309  //Verify the scanned time is the same as the hardcoded time
310  TUASSERTE(UnixTime, hardCodedTime, scannedTime);
311 
312  TURETURN();
313  }
314 
315 
316 // YDSTime scanf Test
317  unsigned scanfYDSTime()
318  {
319  TUDEF("TimeTag", "scanf(YDSTime)");
320 
321 
322  //Set a hardcoded time
323  YDSTime hardCodedTime(2008,200,1000,TimeSystem::GPS);
324  //Provide a format string
325  std::string formatString = "%04Y %03j %7.2s %03P";
326  //Print the time using that format
327  std::string timeString = hardCodedTime.printf(formatString);
328  YDSTime scannedTime;
329 
330  //Read the formatted string back into a new time variable
331  scannedTime.scanf(timeString, formatString);
332 
333  //Verify the scanned time is the same as the hardcoded time
334  TUASSERTE(YDSTime, hardCodedTime, scannedTime);
335  //Reset the time for a new format to be scanned
336  scannedTime.reset();
337 
338 
339  //Provide a format string
340  formatString = "%02y %03j %7.2s %03P";
341  //Print the time using that format
342  timeString = hardCodedTime.printf(formatString);
343  //Read the formatted string back into a new time variable
344  scannedTime.scanf(timeString, formatString);
345 
346  //Verify the scanned time is the same as the hardcoded time
347  TUASSERTE(YDSTime, hardCodedTime, scannedTime);
348 
349  TURETURN();
350  }
351 
352  unsigned changeTimeSystemTest();
353 };
354 
355 
356 unsigned TimeTag_T ::
358 {
359  TUDEF("TimeTag", "changeTimeSystem");
360  std::shared_ptr<TimeSystemConverter> btscShared =
361  make_shared<gnsstk::BasicTimeSystemConverter>();
363  dynamic_cast<gnsstk::BasicTimeSystemConverter *>(btscShared.get());
364  // can't use TimeTag directly as it's abstract, so use CivilTime instead
365  gnsstk::CivilTime uut, exp;
366 
367  //Check conversion from any given time system to UTC and back
368  uut = gnsstk::CivilTime(1990,11,6,0,0,6,gnsstk::TimeSystem::UTC);
369  exp = gnsstk::CivilTime(1990,11,6,0,0,0,gnsstk::TimeSystem::GPS);
370  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::GPS,btsc));
371  TUASSERTE(gnsstk::CommonTime, uut, exp);
372 
373  uut = gnsstk::CivilTime(2004,11,15,23,59,47,gnsstk::TimeSystem::GPS);
374  exp = gnsstk::CivilTime(2004,11,16,0,0,0,gnsstk::TimeSystem::UTC);
375  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::UTC,btsc));
376  TUASSERTE(gnsstk::CommonTime, uut, exp);
377 
378  uut = gnsstk::CivilTime(1992,10,3,0,0,0,gnsstk::TimeSystem::UTC);
379  exp = gnsstk::CivilTime(1992,10,3,0,0,0,gnsstk::TimeSystem::GLO);
380  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::GLO,btsc));
381  TUASSERTE(gnsstk::CommonTime, uut, exp);
382 
383  uut = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
384  exp = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::UTC);
385  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::UTC,btsc));
386  TUASSERTE(gnsstk::CommonTime, uut, exp);
387 
388  uut = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
389  exp = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
390  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::GLO,btsc));
391  TUASSERTE(gnsstk::CommonTime, uut, exp);
392 
393  uut = gnsstk::CivilTime(2019,12,31,23,59,42,gnsstk::TimeSystem::GPS);
394  exp = gnsstk::CivilTime(2020,1,1,0,0,0,gnsstk::TimeSystem::GLO);
395  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::GLO,btsc));
396  TUASSERTE(gnsstk::CommonTime, uut, exp);
397 
398  // conversion using static TimeSystemConverter
399  gnsstk::CommonTime::tsConv = btscShared;
400  uut = gnsstk::CivilTime(1990,11,6,0,0,6,gnsstk::TimeSystem::UTC);
401  exp = gnsstk::CivilTime(1990,11,6,0,0,0,gnsstk::TimeSystem::GPS);
403  TUASSERTE(gnsstk::CommonTime, uut, exp);
404 
405  uut = gnsstk::CivilTime(2004,11,15,23,59,47,gnsstk::TimeSystem::GPS);
406  exp = gnsstk::CivilTime(2004,11,16,0,0,0,gnsstk::TimeSystem::UTC);
408  TUASSERTE(gnsstk::CommonTime, uut, exp);
409 
410  uut = gnsstk::CivilTime(1992,10,3,0,0,0,gnsstk::TimeSystem::UTC);
411  exp = gnsstk::CivilTime(1992,10,3,0,0,0,gnsstk::TimeSystem::GLO);
413  TUASSERTE(gnsstk::CommonTime, uut, exp);
414 
415  uut = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
416  exp = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::UTC);
418  TUASSERTE(gnsstk::CommonTime, uut, exp);
419 
420  uut = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
421  exp = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
423  TUASSERTE(gnsstk::CommonTime, uut, exp);
424 
425  uut = gnsstk::CivilTime(2019,12,31,23,59,42,gnsstk::TimeSystem::GPS);
426  exp = gnsstk::CivilTime(2020,1,1,0,0,0,gnsstk::TimeSystem::GLO);
428  TUASSERTE(gnsstk::CommonTime, uut, exp);
429 
430  TURETURN();
431 }
432 
433 
434 int main() //Main function to initialize and run all tests above
435 {
436  unsigned errorTotal = 0;
437  TimeTag_T testClass;
438 
439  errorTotal += testClass.scanfANSITime();
440  errorTotal += testClass.scanfCivilTime();
441  errorTotal += testClass.scanfGPSWeekSecond();
442  errorTotal += testClass.scanfGPSWeekZcount();
443  errorTotal += testClass.scanfJulianDate();
444  errorTotal += testClass.scanfMJD();
445  errorTotal += testClass.scanfUnixTime();
446  errorTotal += testClass.scanfYDSTime();
447  errorTotal += testClass.changeTimeSystemTest();
448 
449  cout << "Total Failures for " << __FILE__ << ": " << errorTotal << endl;
450 
451  //Return the total number of errors
452  return errorTotal;
453 }
GPSWeekZcount.hpp
YDSTime.hpp
main
int main()
Definition: TimeTag_T.cpp:434
gnsstk::CommonTime::tsConv
static GNSSTK_EXPORT std::shared_ptr< TimeSystemConverter > tsConv
Definition: CommonTime.hpp:406
gnsstk::YDSTime
Definition: YDSTime.hpp:58
gnsstk::GPSWeekZcount::reset
virtual void reset()
Reset this object to the default state.
Definition: GPSWeekZcount.hpp:158
gnsstk::YDSTime::reset
virtual void reset()
Reset this object to the default state.
Definition: YDSTime.cpp:200
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
gnsstk::UnixTime::printf
virtual std::string printf(const std::string &fmt) const
Definition: UnixTime.cpp:105
TimeTag_T::scanfGPSWeekZcount
unsigned scanfGPSWeekZcount()
Definition: TimeTag_T.cpp:196
gnsstk::ANSITime::printf
virtual std::string printf(const std::string &fmt) const
Definition: ANSITime.cpp:94
TimeTag_T::scanfYDSTime
unsigned scanfYDSTime()
Definition: TimeTag_T.cpp:317
gnsstk::JulianDate
Definition: JulianDate.hpp:89
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
MJD.hpp
gnsstk::GPSWeekSecond
Definition: GPSWeekSecond.hpp:56
TimeTag_T::scanfANSITime
unsigned scanfANSITime()
Definition: TimeTag_T.cpp:69
TimeTag_T::scanfUnixTime
unsigned scanfUnixTime()
Definition: TimeTag_T.cpp:293
TestUtil.hpp
JulianDate.hpp
TimeTag_T::scanfGPSWeekSecond
unsigned scanfGPSWeekSecond()
Definition: TimeTag_T.cpp:173
BasicTimeSystemConverter.hpp
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
gnsstk::TimeTag::scanf
virtual void scanf(const std::string &str, const std::string &fmt)
Definition: TimeTag.cpp:44
gnsstk::GPSWeekZcount::printf
virtual std::string printf(const std::string &fmt) const
Definition: GPSWeekZcount.cpp:114
gnsstk::CivilTime::printf
virtual std::string printf(const std::string &fmt) const
Definition: CivilTime.cpp:111
gnsstk::CommonTime
Definition: CommonTime.hpp:84
TimeTag_T::scanfMJD
unsigned scanfMJD()
Definition: TimeTag_T.cpp:270
TimeTag_T
Definition: TimeTag_T.cpp:62
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
CivilTime.hpp
UnixTime.hpp
TimeTag.hpp
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
gnsstk::TimeSystem::GLO
@ GLO
GLONASS system time (aka UTC(SU))
gnsstk::UnixTime
Definition: UnixTime.hpp:67
gnsstk::GPSWeekZcount
Definition: GPSWeekZcount.hpp:55
gnsstk::TimeSystem::UTC
@ UTC
Coordinated Universal Time (e.g., from NTP)
gnsstk::CivilTime
Definition: CivilTime.hpp:55
gnsstk::CivilTime::reset
virtual void reset()
Reset this object to the default state.
Definition: CivilTime.cpp:273
gnsstk::TimeTag::changeTimeSystem
bool changeTimeSystem(TimeSystem timeSys, TimeSystemConverter *conv)
Definition: TimeTag.cpp:181
gnsstk::ANSITime
Definition: ANSITime.hpp:56
GPSWeekSecond.hpp
gnsstk::BasicTimeSystemConverter
Definition: BasicTimeSystemConverter.hpp:51
TimeTag_T::TimeTag_T
TimeTag_T()
Definition: TimeTag_T.cpp:65
gnsstk::TimeSystem::GPS
@ GPS
GPS system time.
std
Definition: Angle.hpp:142
TimeTag_T::~TimeTag_T
~TimeTag_T()
Definition: TimeTag_T.cpp:66
TimeTag_T::changeTimeSystemTest
unsigned changeTimeSystemTest()
Definition: TimeTag_T.cpp:357
gnsstk::GPSWeekSecond::printf
virtual std::string printf(const std::string &fmt) const
Definition: GPSWeekSecond.hpp:145
gnsstk::MJD::printf
virtual std::string printf(const std::string &fmt) const
Definition: MJD.cpp:95
gnsstk::MJD
Definition: MJD.hpp:54
gnsstk::JulianDate::printf
virtual std::string printf(const std::string &fmt) const
Definition: JulianDate.cpp:88
TimeTag_T::scanfCivilTime
unsigned scanfCivilTime()
Definition: TimeTag_T.cpp:92
TimeTag_T::scanfJulianDate
unsigned scanfJulianDate()
Definition: TimeTag_T.cpp:247
ANSITime.hpp
gnsstk::YDSTime::printf
virtual std::string printf(const std::string &fmt) const
Definition: YDSTime.cpp:88


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