TimeString_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 "TimeString.hpp"
41 #include "ANSITime.hpp"
42 #include "CivilTime.hpp"
43 #include "MJD.hpp"
44 #include "JulianDate.hpp"
45 #include "GPSWeekSecond.hpp"
46 #include "GPSWeekZcount.hpp"
47 #include "UnixTime.hpp"
48 #include "YDSTime.hpp"
49 #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 //=============================================================================
60 // This test file will contain a series of scanTime checks for
61 // each of the directly tested TimeTag classes.
62 //=============================================================================
64 {
65 public:
68 
69 //=============================================================================
70 // ANSITime scanTime Test
71 //=============================================================================
72  int scanTimeANSITime( void )
73  {
74  TestUtil testFramework( "TimeString", "scanTime(ANSITime)", __FILE__, __LINE__ );
75 
76 
77  ANSITime scannedTime;
78  CommonTime scannedCommonTime, hardcodedCommonTime;
79  std::string formatString, timeString;
80  // Set a hardcoded time
81  ANSITime hardcodedTime(13500000,TimeSystem(2));
82  hardcodedCommonTime = hardcodedTime.convertToCommonTime();
83 
84  // Provide a format string
85  formatString = "%08K %03P";
86  // Print the time using that format
87  timeString = hardcodedTime.printf(formatString);
88  // Read the formatted string back into a new time variable
89  scanTime(scannedTime, timeString, formatString);
90  // Verify the scanned time is the same as the hardcoded time
91  TUASSERTE(ANSITime,hardcodedTime,scannedTime);
92 
93  // Reset the TimeTag child object
94  scannedTime.reset();
95  // Read the formatted string back into a CommonTime time
96  // variable
97  scanTime(scannedCommonTime, timeString, formatString);
98  // Convert to the TimeTag child class
99  scannedTime.convertFromCommonTime(scannedCommonTime);
100  // Verify the scanned CommonTime time is the same as the
101  // hardcoded time
102  TUASSERTE(ANSITime,hardcodedTime,scannedTime);
103 
104  scannedCommonTime.reset();
105  scannedTime.reset();
106  // Read the formatted string back into a CommonTime time
107  // variable
108  mixedScanTime(scannedCommonTime, timeString, formatString);
109  // Convert to the TimeTag child class
110  scannedTime.convertFromCommonTime(scannedCommonTime);
111  // Verify the scanned CommonTime time is the same as the
112  // hardcoded time
113  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
114 
115  return testFramework.countFails();
116  }
117 
118 //=============================================================================
119 // CivilTime scanTime Test
120 //=============================================================================
121  int scanTimeCivilTime( void )
122  {
123  TestUtil testFramework( "TimeString", "scanTime(CivilTime)", __FILE__, __LINE__ );
124 
125 
126  CivilTime scannedTime;
127  CommonTime scannedCommonTime, hardcodedCommonTime;
128  std::string formatString, timeString;
129  // Set a hardcoded time
130  CivilTime hardcodedTime(2008,8,21,13,30,15.,TimeSystem::UTC);
131  hardcodedCommonTime = hardcodedTime.convertToCommonTime();
132 
133  // Provide a format string
134  formatString = "%04Y %02m %02d %02H %02M %02S %03P";
135  // Print the time using that format
136  timeString = hardcodedTime.printf(formatString);
137  // Read the formatted string back into a new time variable
138  scanTime(scannedTime, timeString, formatString);
139  // Verify the scanned time is the same as the hardcoded time
140  TUASSERTE(CivilTime,hardcodedTime,scannedTime);
141 
142  // Reset the TimeTag child object
143  scannedTime.reset();
144  // Read the formatted string back into a CommonTime time
145  // variable
146  scanTime(scannedCommonTime, timeString, formatString);
147  // Convert to the TimeTag child class
148  scannedTime.convertFromCommonTime(scannedCommonTime);
149  // Verify the scanned CommonTime time is the same as the
150  // hardcoded time
151  TUASSERTE(CivilTime,hardcodedTime,scannedTime);
152 
153  scannedCommonTime.reset();
154  scannedTime.reset();
155  // Read the formatted string back into a CommonTime time
156  // variable
157  mixedScanTime(scannedCommonTime, timeString, formatString);
158  // Convert to the TimeTag child class
159  scannedTime.convertFromCommonTime(scannedCommonTime);
160  // Verify the scanned CommonTime time is the same as the
161  // hardcoded time
162  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
163 
164  scannedTime.reset();
165 
166 
167  // Provide a format string
168  formatString = "%02y %02m %02d %02H %02M %02S %03P";
169  // Print the time using that format
170  timeString = hardcodedTime.printf(formatString);
171  // Read the formatted string back into a new time variable
172  scanTime(scannedTime, timeString, formatString);
173  // Verify the scanned time is the same as the hardcoded time
174  TUASSERTE(CivilTime,hardcodedTime,scannedTime);
175 
176  // Reset the TimeTag child object
177  scannedTime.reset();
178  // Read the formatted string back into a CommonTime time
179  // variable
180  scanTime(scannedCommonTime, timeString, formatString);
181  // Convert to the TimeTag child class
182  scannedTime.convertFromCommonTime(scannedCommonTime);
183  // Verify the scanned CommonTime time is the same as the
184  // hardcoded time
185  TUASSERTE(CivilTime,hardcodedTime,scannedTime);
186 
187  scannedCommonTime.reset();
188  scannedTime.reset();
189  // Read the formatted string back into a CommonTime time
190  // variable
191  mixedScanTime(scannedCommonTime, timeString, formatString);
192  // Convert to the TimeTag child class
193  scannedTime.convertFromCommonTime(scannedCommonTime);
194 
195  // Verify the scanned CommonTime time is the same as the
196  // hardcoded time
197  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
198 
199  // Reset the time for a new format to be scanned
200  scannedTime.reset();
201 
202  // Provide a format string
203  formatString = "%04Y %03b %02d %02H %02M %02S %03P";
204  // Print the time using that format
205  timeString = hardcodedTime.printf(formatString);
206  // Read the formatted string back into a new time variable
207  scanTime(scannedTime, timeString, formatString);
208  // Verify the scanned time is the same as the hardcoded time
209  TUASSERTE(CivilTime,hardcodedTime,scannedTime);
210 
211  // Reset the TimeTag child object
212  scannedTime.reset();
213  // Read the formatted string back into a CommonTime time
214  // variable
215  scanTime(scannedCommonTime, timeString, formatString);
216  // Convert to the TimeTag child class
217  scannedTime.convertFromCommonTime(scannedCommonTime);
218  // Verify the scanned CommonTime time is the same as the
219  // hardcoded time
220  TUASSERTE(CivilTime,hardcodedTime,scannedTime);
221 
222  scannedCommonTime.reset();
223  scannedTime.reset();
224  // Read the formatted string back into a CommonTime time
225  // variable
226  mixedScanTime(scannedCommonTime, timeString, formatString);
227  // Convert to the TimeTag child class
228  scannedTime.convertFromCommonTime(scannedCommonTime);
229 
230  // Verify the scanned CommonTime time is the same as the
231  // hardcoded time
232  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
233 
234  // Reset the time for a new format to be scanned
235  scannedTime.reset();
236 
237  // Provide a format string
238  formatString = "%04Y %03b %02d %02H %02M %5.2f %03P";
239  // Print the time using that format
240  timeString = hardcodedTime.printf(formatString);
241  // Read the formatted string back into a new time variable
242  scanTime(scannedTime, timeString, formatString);
243  // Verify the scanned time is the same as the hardcoded time
244  TUASSERTE(CivilTime,hardcodedTime,scannedTime);
245 
246  // Reset the TimeTag child object
247  scannedTime.reset();
248  // Read the formatted string back into a CommonTime time
249  // variable
250  scanTime(scannedCommonTime, timeString, formatString);
251  // Convert to the TimeTag child class
252  scannedTime.convertFromCommonTime(scannedCommonTime);
253  // Verify the scanned CommonTime time is the same as the
254  // hardcoded time
255  TUASSERTE(CivilTime,hardcodedTime,scannedTime);
256 
257  scannedCommonTime.reset();
258  scannedTime.reset();
259  // Read the formatted string back into a CommonTime time
260  // variable
261  mixedScanTime(scannedCommonTime, timeString, formatString);
262  // Convert to the TimeTag child class
263  scannedTime.convertFromCommonTime(scannedCommonTime);
264 
265  // Verify the scanned CommonTime time is the same as the
266  // hardcoded time
267  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
268 
269  // Reset the time for a new format to be scanned
270  scannedTime.reset();
271 
272  // Provide a format string
273  formatString = "%02y %03b %02d %02H %02M %5.2f %03P";
274  // Print the time using that format
275  timeString = hardcodedTime.printf(formatString);
276  // Read the formatted string back into a new time variable
277  scanTime(scannedTime, timeString, formatString);
278  // Verify the scanned time is the same as the hardcoded time
279  TUASSERTE(CivilTime,hardcodedTime,scannedTime);
280 
281  // Reset the TimeTag child object
282  scannedTime.reset();
283  // Read the formatted string back into a CommonTime time
284  // variable
285  scanTime(scannedCommonTime, timeString, formatString);
286  // Convert to the TimeTag child class
287  scannedTime.convertFromCommonTime(scannedCommonTime);
288  // Verify the scanned CommonTime time is the same as the
289  // hardcoded time
290  TUASSERTE(CivilTime,hardcodedTime,scannedTime);
291 
292  scannedCommonTime.reset();
293  scannedTime.reset();
294  // Read the formatted string back into a CommonTime time
295  // variable
296  mixedScanTime(scannedCommonTime, timeString, formatString);
297  // Convert to the TimeTag child class
298  scannedTime.convertFromCommonTime(scannedCommonTime);
299 
300  // Verify the scanned CommonTime time is the same as the
301  // hardcoded time
302  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
303 
304  // Reset the time for a new format to be scanned
305  scannedTime.reset();
306 
307  return testFramework.countFails();
308  }
309 
310 
311 
312 //=============================================================================
313 // GPSWeekSecond scanTime Test
314 //=============================================================================
316  {
317  TestUtil testFramework( "TimeString", "scanTime(GPSWeekSecond)", __FILE__, __LINE__ );
318 
319 
320  GPSWeekSecond scannedTime;
321  CommonTime scannedCommonTime, hardcodedCommonTime;
322  std::string formatString, timeString;
323  // Set a hardcoded time
324  GPSWeekSecond hardcodedTime(1300,13500.,TimeSystem::GPS);
325  hardcodedCommonTime = hardcodedTime.convertToCommonTime();
326 
327  // Provide a format string
328  formatString = "%04F %8.2g %03P";
329  // Print the time using that format
330  timeString = hardcodedTime.printf(formatString);
331  // Read the formatted string back into a new time variable
332  scanTime(scannedTime, timeString, formatString);
333  // Verify the scanned time is the same as the hardcoded time
334  TUASSERTE(GPSWeekSecond,hardcodedTime,scannedTime);
335 
336  // Reset the TimeTag child object
337  scannedTime.reset();
338  // Read the formatted string back into a CommonTime time
339  // variable
340  scanTime(scannedCommonTime, timeString, formatString);
341  // Convert to the TimeTag child class
342  scannedTime.convertFromCommonTime(scannedCommonTime);
343  // Verify the scanned CommonTime time is the same as the
344  // hardcoded time
345  TUASSERTE(GPSWeekSecond,hardcodedTime,scannedTime);
346 
347  scannedCommonTime.reset();
348  scannedTime.reset();
349  // Read the formatted string back into a CommonTime time
350  // variable
351  mixedScanTime(scannedCommonTime, timeString, formatString);
352  // Convert to the TimeTag child class
353  scannedTime.convertFromCommonTime(scannedCommonTime);
354  // Verify the scanned CommonTime time is the same as the
355  // hardcoded time
356  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
357 
358  return testFramework.countFails();
359  }
360 
361 //=============================================================================
362 // GPSWeekZcount scanTime Test
363 //=============================================================================
365  {
366  TestUtil testFramework( "TimeString", "scanTime(GPSWeekZcount)", __FILE__, __LINE__ );
367 
368 
369  GPSWeekZcount scannedTime;
370  CommonTime scannedCommonTime, hardcodedCommonTime;
371  std::string formatString, timeString;
372  // Set a hardcoded time
373  GPSWeekZcount hardcodedTime(1300,13500.,TimeSystem(2));
374  hardcodedCommonTime = hardcodedTime.convertToCommonTime();
375 
376  // Provide a format string
377  formatString = "%04F %05z %03P";
378  // Print the time using that format
379  timeString = hardcodedTime.printf(formatString);
380  // Read the formatted string back into a new time variable
381  scanTime(scannedTime, timeString, formatString);
382  // Verify the scanned time is the same as the hardcoded time
383  TUASSERTE(GPSWeekZcount,hardcodedTime,scannedTime);
384 
385  // Reset the TimeTag child object
386  scannedTime.reset();
387  // Read the formatted string back into a CommonTime time
388  // variable
389  scanTime(scannedCommonTime, timeString, formatString);
390  // Convert to the TimeTag child class
391  scannedTime.convertFromCommonTime(scannedCommonTime);
392  // Verify the scanned CommonTime time is the same as the
393  // hardcoded time
394  TUASSERTE(GPSWeekZcount,hardcodedTime,scannedTime);
395 
396  scannedCommonTime.reset();
397  scannedTime.reset();
398  // Read the formatted string back into a CommonTime time
399  // variable
400  mixedScanTime(scannedCommonTime, timeString, formatString);
401  // Convert to the TimeTag child class
402  scannedTime.convertFromCommonTime(scannedCommonTime);
403  // Verify the scanned CommonTime time is the same as the
404  // hardcoded time
405  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
406 
407  // Reset the time for a new format to be scanned
408  scannedTime.reset();
409 
410 
411  // Provide a format string
412  formatString = "%04F %10C %03P";
413  // Print the time using that format
414  timeString = hardcodedTime.printf(formatString);
415  // Read the formatted string back into a new time variable
416  scanTime(scannedTime, timeString, formatString);
417  // Verify the scanned time is the same as the hardcoded time
418  TUASSERTE(GPSWeekZcount,hardcodedTime,scannedTime);
419 
420  // Reset the TimeTag child object
421  scannedTime.reset();
422  // Read the formatted string back into a CommonTime time
423  // variable
424  scanTime(scannedCommonTime, timeString, formatString);
425  // Convert to the TimeTag child class
426  scannedTime.convertFromCommonTime(scannedCommonTime);
427  // Verify the scanned CommonTime time is the same as the
428  // hardcoded time
429  TUASSERTE(GPSWeekZcount,hardcodedTime,scannedTime);
430 
431  scannedCommonTime.reset();
432  scannedTime.reset();
433  // Read the formatted string back into a CommonTime time
434  // variable
435  mixedScanTime(scannedCommonTime, timeString, formatString);
436  // Convert to the TimeTag child class
437  scannedTime.convertFromCommonTime(scannedCommonTime);
438  // Verify the scanned CommonTime time is the same as the
439  // hardcoded time
440  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
441 
442  // Reset the time for a new format to be scanned
443  scannedTime.reset();
444 
445 
446  // Provide a format string
447  formatString = "%04F %10c %03P";
448  // Print the time using that format
449  timeString = hardcodedTime.printf(formatString);
450  // Read the formatted string back into a new time variable
451  scanTime(scannedTime, timeString, formatString);
452  // Verify the scanned time is the same as the hardcoded time
453  TUASSERTE(GPSWeekZcount,hardcodedTime,scannedTime);
454 
455  // Reset the TimeTag child object
456  scannedTime.reset();
457  // Read the formatted string back into a CommonTime time
458  // variable
459  scanTime(scannedCommonTime, timeString, formatString);
460  // Convert to the TimeTag child class
461  scannedTime.convertFromCommonTime(scannedCommonTime);
462 
463  // Verify the scanned CommonTime time is the same as the
464  // hardcoded time
465  TUASSERTE(GPSWeekZcount,hardcodedTime,scannedTime);
466 
467  scannedCommonTime.reset();
468  scannedTime.reset();
469  // Read the formatted string back into a CommonTime time
470  // variable
471  mixedScanTime(scannedCommonTime, timeString, formatString);
472  // Convert to the TimeTag child class
473  scannedTime.convertFromCommonTime(scannedCommonTime);
474  // Verify the scanned CommonTime time is the same as the
475  // hardcoded time
476  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
477 
478  return testFramework.countFails();
479  }
480 
481 //=============================================================================
482 // JulianDate scanTime Test
483 //=============================================================================
484  int scanTimeJulianDate( void )
485  {
486  TestUtil testFramework( "TimeString", "scanTime(JulianDate)", __FILE__, __LINE__ );
487 
488 
489  JulianDate scannedTime;
490  CommonTime scannedCommonTime, hardcodedCommonTime;
491  std::string formatString, timeString;
492  // Set a hardcoded time
493  JulianDate hardcodedTime(1234567,TimeSystem(2));
494  hardcodedCommonTime = hardcodedTime.convertToCommonTime();
495 
496  // Provide a format string
497  formatString = "%10.2J %03P";
498  // Print the time using that format
499  timeString = hardcodedTime.printf(formatString);
500  // Read the formatted string back into a new time variable
501  scanTime(scannedTime, timeString, formatString);
502  // Verify the scanned time is the same as the hardcoded time
503  TUASSERTE(JulianDate,hardcodedTime,scannedTime);
504 
505  // Reset the TimeTag child object
506  scannedTime.reset();
507  // Read the formatted string back into a CommonTime time
508  // variable
509  scanTime(scannedCommonTime, timeString, formatString);
510  // Convert to the TimeTag child class
511  scannedTime.convertFromCommonTime(scannedCommonTime);
512  // Verify the scanned CommonTime time is the same as the
513  // hardcoded time
514  TUASSERTE(JulianDate,hardcodedTime,scannedTime);
515 
516  scannedCommonTime.reset();
517  scannedTime.reset();
518  // Read the formatted string back into a CommonTime time
519  // variable
520  mixedScanTime(scannedCommonTime, timeString, formatString);
521  // Convert to the TimeTag child class
522  scannedTime.convertFromCommonTime(scannedCommonTime);
523 
524  // Verify the scanned CommonTime time is the same as the
525  // hardcoded time
526  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
527 
528  return testFramework.countFails();
529  }
530 
531 //=============================================================================
532 // MJD scanTime Test
533 //=============================================================================
534  int scanTimeMJD( void )
535  {
536  TestUtil testFramework( "TimeString", "scanTime(MJD)", __FILE__, __LINE__ );
537 
538 
539  MJD scannedTime;
540  CommonTime scannedCommonTime, hardcodedCommonTime;
541  std::string formatString, timeString;
542  // Set a hardcoded time
543  MJD hardcodedTime(123456.0,TimeSystem(1));
544  hardcodedCommonTime = hardcodedTime.convertToCommonTime();
545 
546  // Provide a format string
547  formatString = "%9.2Q %03P";
548  // Print the time using that format
549  timeString = hardcodedTime.printf(formatString);
550  // Read the formatted string back into a new time variable
551  scanTime(scannedTime, timeString, formatString);
552  // Verify the scanned time is the same as the hardcoded time
553  TUASSERTE(MJD,hardcodedTime,scannedTime);
554 
555  // Reset the TimeTag child object
556  scannedTime.reset();
557  // Read the formatted string back into a CommonTime time
558  // variable
559  scanTime(scannedCommonTime, timeString, formatString);
560  // Convert to the TimeTag child class
561  scannedTime.convertFromCommonTime(scannedCommonTime);
562  // Verify the scanned CommonTime time is the same as the
563  // hardcoded time
564  TUASSERTE(MJD,hardcodedTime,scannedTime);
565 
566  scannedCommonTime.reset();
567  scannedTime.reset();
568  // Read the formatted string back into a CommonTime time
569  // variable
570  mixedScanTime(scannedCommonTime, timeString, formatString);
571  // Convert to the TimeTag child class
572  scannedTime.convertFromCommonTime(scannedCommonTime);
573  // Verify the scanned CommonTime time is the same as the
574  // hardcoded time
575  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
576 
577  return testFramework.countFails();
578  }
579 
580 //=============================================================================
581 // UnixTime scanTime Test
582 //=============================================================================
583  int scanTimeUnixTime( void )
584  {
585  TestUtil testFramework( "TimeString", "scanTime(UnixTime)", __FILE__, __LINE__ );
586 
587 
588  UnixTime scannedTime;
589  CommonTime scannedCommonTime, hardcodedCommonTime;
590  std::string formatString, timeString;
591  // Set a hardcoded time
592  UnixTime hardcodedTime(1654321,10,TimeSystem(5));
593  hardcodedCommonTime = hardcodedTime.convertToCommonTime();
594 
595  // Provide a format string
596  formatString = "%07U %02u %03P";
597  // Print the time using that format
598  timeString = hardcodedTime.printf(formatString);
599  // Read the formatted string back into a new time variable
600  scanTime(scannedTime, timeString, formatString);
601  // Verify the scanned time is the same as the hardcoded time
602  TUASSERTE(UnixTime,hardcodedTime,scannedTime);
603 
604  // Reset the TimeTag child object
605  scannedTime.reset();
606  // Read the formatted string back into a CommonTime time
607  // variable
608  scanTime(scannedCommonTime, timeString, formatString);
609  // Convert to the TimeTag child class
610  scannedTime.convertFromCommonTime(scannedCommonTime);
611  // Verify the scanned CommonTime time is the same as the
612  // hardcoded time
613  TUASSERTE(UnixTime,hardcodedTime,scannedTime);
614 
615  scannedCommonTime.reset();
616  scannedTime.reset();
617  // Read the formatted string back into a CommonTime time
618  // variable
619  mixedScanTime(scannedCommonTime, timeString, formatString);
620  // Convert to the TimeTag child class
621  scannedTime.convertFromCommonTime(scannedCommonTime);
622  // Verify the scanned CommonTime time is the same as the
623  // hardcoded time
624  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
625 
626  return testFramework.countFails();
627  }
628 
629 
630 //=============================================================================
631 // YDSTime scanTime Test
632 //=============================================================================
633  int scanTimeYDSTime( void )
634  {
635  TestUtil testFramework( "TimeString", "scanTime(YDSTime)", __FILE__, __LINE__ );
636 
637 
638  YDSTime scannedTime;
639  CommonTime scannedCommonTime, hardcodedCommonTime;
640  std::string formatString, timeString;
641  // Set a hardcoded time
642  YDSTime hardcodedTime(2008,200,1000,TimeSystem::GPS);
643  hardcodedCommonTime = hardcodedTime.convertToCommonTime();
644 
645  // Provide a format string
646  formatString = "%04Y %03j %7.2s %03P";
647  // Print the time using that format
648  timeString = hardcodedTime.printf(formatString);
649  // Read the formatted string back into a new time variable
650  scanTime(scannedTime, timeString, formatString);
651  // Verify the scanned time is the same as the hardcoded time
652  TUASSERTE(YDSTime,hardcodedTime,scannedTime);
653 
654  // Reset the TimeTag child object
655  scannedTime.reset();
656  // Read the formatted string back into a CommonTime time
657  // variable
658  scanTime(scannedCommonTime, timeString, formatString);
659  // Convert to the TimeTag child class
660  scannedTime.convertFromCommonTime(scannedCommonTime);
661  // Verify the scanned CommonTime time is the same as the
662  // hardcoded time
663  TUASSERTE(YDSTime,hardcodedTime,scannedTime);
664 
665  scannedCommonTime.reset();
666  scannedTime.reset();
667  // Read the formatted string back into a CommonTime time
668  // variable
669  mixedScanTime(scannedCommonTime, timeString, formatString);
670  // Convert to the TimeTag child class
671  scannedTime.convertFromCommonTime(scannedCommonTime);
672  // Verify the scanned CommonTime time is the same as the
673  // hardcoded time
674  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
675 
676  scannedTime.reset();
677  scannedCommonTime.reset();
678 
679  // Provide a format string
680  formatString = "%02y %03j %7.2s %03P";
681  // Print the time using that format
682  timeString = hardcodedTime.printf(formatString);
683  // Read the formatted string back into a new time variable
684  scanTime(scannedTime, timeString, formatString);
685  // Verify the scanned time is the same as the hardcoded time
686  TUASSERTE(YDSTime,hardcodedTime,scannedTime);
687 
688  // Reset the TimeTag child object
689  scannedTime.reset();
690  // Read the formatted string back into a CommonTime time
691  // variable
692  scanTime(scannedCommonTime, timeString, formatString);
693  // Convert to the TimeTag child class
694  scannedTime.convertFromCommonTime(scannedCommonTime);
695  // Verify the scanned CommonTime time is the same as the
696  // hardcoded time
697  TUASSERTE(YDSTime,hardcodedTime,scannedTime);
698 
699  scannedCommonTime.reset();
700  scannedTime.reset();
701  // Read the formatted string back into a CommonTime time
702  // variable
703  mixedScanTime(scannedCommonTime, timeString, formatString);
704  // Convert to the TimeTag child class
705  scannedTime.convertFromCommonTime(scannedCommonTime);
706  // Verify the scanned CommonTime time is the same as the
707  // hardcoded time
708  TUASSERTE(CommonTime,hardcodedCommonTime,scannedCommonTime);
709  return testFramework.countFails();
710  }
711 };
712 
713 
714 
715 int main() // Main function to initialize and run all tests above
716 {
717  int check, errorCounter = 0;
718  TimeString_T testClass;
719 
720  check = testClass.scanTimeANSITime();
721  errorCounter += check;
722 
723  check = testClass.scanTimeCivilTime();
724  errorCounter += check;
725 
726  check = testClass.scanTimeGPSWeekSecond();
727  errorCounter += check;
728 
729  check = testClass.scanTimeGPSWeekZcount();
730  errorCounter += check;
731 
732  check = testClass.scanTimeJulianDate();
733  errorCounter += check;
734 
735  check = testClass.scanTimeMJD();
736  errorCounter += check;
737 
738  check = testClass.scanTimeUnixTime();
739  errorCounter += check;
740 
741  check = testClass.scanTimeYDSTime();
742  errorCounter += check;
743 
744  std::cout << "Total Failures for " << __FILE__ << ": " << errorCounter << std::endl;
745 
746  // Return the total number of errors
747  return errorCounter;
748 }
gnsstk::YDSTime::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: YDSTime.cpp:76
GPSWeekZcount.hpp
TimeString_T::scanTimeJulianDate
int scanTimeJulianDate(void)
Definition: TimeString_T.cpp:484
YDSTime.hpp
gnsstk::WeekSecond::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: WeekSecond.cpp:55
gnsstk::JulianDate::reset
virtual void reset()
Reset this object to the default state.
Definition: JulianDate.cpp:162
gnsstk::JulianDate::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: JulianDate.cpp:76
gnsstk::TestUtil::countFails
int countFails(void)
Definition: TestUtil.hpp:771
gnsstk::JulianDate::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: JulianDate.cpp:54
gnsstk::MJD::reset
virtual void reset()
Reset this object to the default state.
Definition: MJD.cpp:169
gnsstk::scanTime
void scanTime(TimeTag &btime, const string &str, const string &fmt)
Definition: TimeString.cpp:93
gnsstk::YDSTime
Definition: YDSTime.hpp:58
TimeString_T::TimeString_T
TimeString_T()
Definition: TimeString_T.cpp:66
gnsstk::GPSWeekZcount::reset
virtual void reset()
Reset this object to the default state.
Definition: GPSWeekZcount.hpp:158
gnsstk::WeekSecond::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: WeekSecond.cpp:78
gnsstk::GPSWeekZcount::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: GPSWeekZcount.cpp:88
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
TimeString_T
Definition: TimeString_T.cpp:63
main
int main()
Definition: TimeString_T.cpp:715
gnsstk::UnixTime::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: UnixTime.cpp:54
gnsstk::ANSITime::printf
virtual std::string printf(const std::string &fmt) const
Definition: ANSITime.cpp:94
gnsstk::JulianDate
Definition: JulianDate.hpp:89
gnsstk::CivilTime::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: CivilTime.cpp:97
gnsstk::GPSWeekZcount::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: GPSWeekZcount.cpp:68
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
MJD.hpp
gnsstk::GPSWeekSecond
Definition: GPSWeekSecond.hpp:56
gnsstk::CommonTime::reset
void reset()
Definition: CommonTime.hpp:399
gnsstk::WeekSecond::reset
virtual void reset()
Reset this object to the default state.
Definition: WeekSecond.cpp:105
gnsstk::mixedScanTime
void mixedScanTime(CommonTime &t, const string &str, const string &fmt)
Definition: TimeString.cpp:432
TestUtil.hpp
gnsstk::CivilTime::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: CivilTime.cpp:75
JulianDate.hpp
TimeString_T::scanTimeMJD
int scanTimeMJD(void)
Definition: TimeString_T.cpp:534
gnsstk::GPSWeekZcount::printf
virtual std::string printf(const std::string &fmt) const
Definition: GPSWeekZcount.cpp:114
gnsstk::ANSITime::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: ANSITime.cpp:71
TimeString_T::scanTimeCivilTime
int scanTimeCivilTime(void)
Definition: TimeString_T.cpp:121
gnsstk::CivilTime::printf
virtual std::string printf(const std::string &fmt) const
Definition: CivilTime.cpp:111
gnsstk::CommonTime
Definition: CommonTime.hpp:84
TimeString_T::scanTimeYDSTime
int scanTimeYDSTime(void)
Definition: TimeString_T.cpp:633
TimeString_T::~TimeString_T
~TimeString_T()
Definition: TimeString_T.cpp:67
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
CivilTime.hpp
UnixTime.hpp
TimeTag.hpp
TimeString_T::scanTimeGPSWeekSecond
int scanTimeGPSWeekSecond(void)
Definition: TimeString_T.cpp:315
gnsstk::MJD::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: MJD.cpp:84
gnsstk::UnixTime
Definition: UnixTime.hpp:67
gnsstk::GPSWeekZcount
Definition: GPSWeekZcount.hpp:55
gnsstk::UnixTime::reset
virtual void reset()
Reset this object to the default state.
Definition: UnixTime.cpp:187
gnsstk::TimeSystem::UTC
@ UTC
Coordinated Universal Time (e.g., from NTP)
gnsstk::YDSTime::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: YDSTime.cpp:61
gnsstk::ANSITime::reset
virtual void reset()
Reset this object to the default state.
Definition: ANSITime.cpp:168
gnsstk::MJD::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: MJD.cpp:54
gnsstk::CivilTime
Definition: CivilTime.hpp:55
gnsstk::CivilTime::reset
virtual void reset()
Reset this object to the default state.
Definition: CivilTime.cpp:273
gnsstk::ANSITime
Definition: ANSITime.hpp:56
GPSWeekSecond.hpp
gnsstk::TimeSystem::GPS
@ GPS
GPS system time.
std
Definition: Angle.hpp:142
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
TimeString_T::scanTimeANSITime
int scanTimeANSITime(void)
Definition: TimeString_T.cpp:72
gnsstk::MJD
Definition: MJD.hpp:54
gnsstk::JulianDate::printf
virtual std::string printf(const std::string &fmt) const
Definition: JulianDate.cpp:88
TimeString_T::scanTimeUnixTime
int scanTimeUnixTime(void)
Definition: TimeString_T.cpp:583
gnsstk::UnixTime::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: UnixTime.cpp:71
gnsstk::ANSITime::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: ANSITime.cpp:54
gnsstk::TestUtil
Definition: TestUtil.hpp:265
TimeString.hpp
ANSITime.hpp
gnsstk::YDSTime::printf
virtual std::string printf(const std::string &fmt) const
Definition: YDSTime.cpp:88
TimeString_T::scanTimeGPSWeekZcount
int scanTimeGPSWeekZcount(void)
Definition: TimeString_T.cpp:364


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