CommonTime_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 "CommonTime.hpp"
40 #include "Exception.hpp"
41 #include "TestUtil.hpp"
43 #include "CivilTime.hpp"
44 #include <iostream>
45 #include <cmath>
46 using namespace gnsstk;
47 using namespace std;
48 
49 class CommonTime_T : public CommonTime
50 {
51 public:
52 
54  CommonTime_T();
55 
58  unsigned initializationTest();
59 
62  unsigned improperSetTest();
63 
66  unsigned setComparisonTest();
67 
69  unsigned arithmeticTest();
70 
72  unsigned operatorTest();
73 
75  unsigned resetTest();
76 
79  unsigned timeSystemTest();
80 
82  unsigned printfTest();
83 
86  unsigned rolloverTest();
87 
88  unsigned changeTimeSystemTest();
89 private:
90 
91  double eps;
92 };
93 
94 
97 {
98  eps = 1e-11;
99 }
100 
101 
102 unsigned CommonTime_T ::
104 {
105  TUDEF("CommonTime", "CommonTime");
106 
107  //----------------------------------------
108  // Constructor test
109  //----------------------------------------
110  try
111  {
113  TUPASS("CommonTime constructor did not throw an exception.");
114  }
115  catch(...)
116  {
117  TUFAIL("CommonTime constructor should not have thrown an exception.");
118  }
119 
120  //----------------------------------------
121  // CommonTime.set() test
122  //----------------------------------------
123  try
124  {
125  CommonTime Test1;
126  Test1.set( (long)700000, (long)0, (double)0. );
127  TUPASS("CommonTime.set() did not throw an exception.");
128  }
129  catch (...)
130  {
131  TUFAIL("CommonTime.set() threw an exception, but should not have.");
132  }
133 
134  // Undocumented comment line:
135  // CommonTime Test1((long)700000,(long)0,(double)0.); // This is a protected method
136 
137  //----------------------------------------
138  // Copy-Constructer test
139  //----------------------------------------
140  try
141  {
142  CommonTime Test1;
143  Test1.set( (long)700000, (long)0, (double)0. );
144  CommonTime Test2(Test1);
145  TUPASS("CommonTime2(CommonTime1) copy constructor did not throw an exception.");
146  }
147  catch (...)
148  {
149  TUFAIL("CommonTime Copy Constructor threw an exception, but should not have");
150  }
151 
152  //----------------------------------------
153  // Assignment operator test
154  //----------------------------------------
155  try
156  {
157  CommonTime Test1;
158  Test1.set( (long)700000, (long)0, (double)0. );
159  CommonTime Test3 = Test1;
160  TUPASS("CommonTime assignment operator did not throw an exception.");
161  }
162  catch (...)
163  {
164  TUFAIL("CommonTime assignment operator on same line threw an exception, but should not have");
165  }
166 
167  //----------------------------------------
168  // Assignment operator test
169  //----------------------------------------
170  try
171  {
172  CommonTime Test1;
173  Test1.set( (long)700000, (long)0, (double)0.);
174  CommonTime Test4;
175  Test4 = Test1;
176  TUPASS("CommonTime assignment operator did not throw an exception");
177  }
178  catch (...)
179  {
180  TUFAIL("CommonTime assignment operator on separate line should not have thrown an exception");
181  }
182 
183  //----------------------------------------
184  // The End!
185  //----------------------------------------
186  TURETURN();
187 }
188 
189 
190 unsigned CommonTime_T ::
192 {
193  CommonTime Test;
194  Test.set (700000, 0, 0.);
195 
196  TUDEF("CommonTime", "set");
197 
198  // Break the input in various ways and make sure the proper exception is called
199 
200  //----------------------------------------
201  // Does CommonTime.set() work with negative days?
202  //----------------------------------------
203  try
204  {
205  Test.set(-1,0,0.);
206  TUFAIL("[testing] CommonTime.set() with negative day, exception gnsstk::Exception, [actual] threw no exception");
207  }
208  // QUESTION: Why test for gnsstk::InvalidRequest exception instead of gnsstk::Exception?
209  // ANSWER: gnsstk::InvalidRequest is a child of gnsstk::Exception, and depending on CommonTime.cpp
210  // we might sometimes need to be more specific than catching gnsstk::Exception
211  // catch( gnsstk::InvalidParameter e)
212  // For now, I'm replacing gnsstk::InvalidParameter with gnsstk::Exception to be consistent throughout this test application
213  catch( gnsstk::Exception e)
214  {
215  TUPASS("CommonTime.set() with negative day should throw a gnsstk::Exception");
216  }
217  catch(...)
218  {
219  TUFAIL("[testing] CommonTime.set() with negative day, exception gnsstk::Exception, [actual] threw wrong exception");
220  }
221 
222  //----------------------------------------
223  // Does CommonTime.set() work with too many days?
224  //----------------------------------------
225  try
226  {
227  Test.set(3442449,0,0.);
228  TUFAIL("[testing] CommonTime.set() with too many days, exception gnsstk::Exception, [actual] threw no exception");
229  }
230  catch(gnsstk::Exception e)
231  {
232  TUPASS("CommonTime.set() with too many days should throw a gnsstk::Exception" );
233  }
234  catch (...)
235  {
236  TUFAIL("[testing] CommonTime.set() with too many days, exception gnsstk::Exception, [actual] threw wrong exception");
237  }
238 
239  //----------------------------------------
240  // Does CommonTime.set() work with negative seconds?
241  //----------------------------------------
242  try
243  {
244  Test.set(700000,-1,0.);
245  TUFAIL("[testing] CommonTime.set() with negative seconds, exception gnsstk::Exception, [actual] threw no exception");
246  }
247  catch(gnsstk::Exception e)
248  {
249  TUPASS("CommonTime.set() with negative seconds should throw a gnsstk::Exception");
250  }
251  catch (...)
252  {
253  TUFAIL("Fail");
254  }
255 
256  //----------------------------------------
257  // Does a set method work with too many seconds?
258  //----------------------------------------
259  try
260  {
261  Test.set(700000,24*60*60+1,0.);
262  TUFAIL("[testing] CommonTime.set() with too many seconds, exception gnsstk::Exception, [actual] threw no exception");
263  }
264  catch(gnsstk::Exception e)
265  {
266  TUPASS("CommonTime.set() with too many seconds should throw a gnsstk::Exception");
267  }
268  catch (...)
269  {
270  TUFAIL("[testing] CommonTime.set() with too many seconds, exception gnsstk::Exception, [actual] threw wrong exception");
271  }
272 
273  //----------------------------------------
274  // Does a set method work with negative fractional seconds?
275  //----------------------------------------
276  try
277  {
278  Test.set(700000,0,-1.);
279  TUFAIL("[testing] CommonTime.set() with negative fractional seconds, exception gnsstk::Exception, [actual] threw no exception");
280  }
281  catch(gnsstk::Exception e)
282  {
283  TUPASS("CommonTime.set() with negative fractional seconds should throw a gnsstk::Exception");
284  }
285  catch (...)
286  {
287  TUFAIL("[testing] CommonTime.set() with negative fractional seconds, exception gnsstk::Exception, [actual] threw wrong exception");
288  }
289 
290  //----------------------------------------
291  // Does a set method work with too many fractional seconds?
292  //----------------------------------------
293  try
294  {
295  Test.set(700000,0,2.);
296  TUFAIL("[testing] CommonTime.set() with too many fractional seconds, exception gnsstk::Exception, [actual] threw no exception");
297  }
298  catch( gnsstk::Exception e )
299  {
300  TUPASS("CommonTime.set() with too many fractional seconds should throw a gnsstk::Exception");
301  }
302  catch(...)
303  {
304  TUFAIL("[testing] CommonTime.set() with too many fractional seconds, exception gnsstk::Exception, [actual] threw wrong exception");
305  }
306 
307  //----------------------------------------
308  // Does a setInternal work with negative days?
309  //----------------------------------------
310  try
311  {
312  Test.setInternal(-1,0,0.);
313  TUFAIL("[testing] CommonTime.setInternal() with negative days, exception gnsstk::Exception, [actual] threw no exception");
314  }
315  catch( gnsstk::Exception e )
316  {
317  TUPASS("CommonTime.setInternal() with negative days should throw a gnsstk::Exception");
318  }
319  catch (...)
320  {
321  TUFAIL("[testing] CommonTime.setInternal() with negative days, exception gnsstk::Exception, [actual] threw wrong exception");
322  }
323 
324  //----------------------------------------
325  // Does a setInternal work with too many days?
326  //----------------------------------------
327  try
328  {
329  Test.setInternal(3442449,0,0.);
330  TUFAIL("[testing] CommonTime.setInternal() with too many days, exception gnsstk::Exception, [actual] threw no exception");
331  }
332  catch(gnsstk::Exception e)
333  {
334  TUPASS("CommonTime.setInternal() with too many days should throw a gnsstk::Exception");
335  }
336  catch (...)
337  {
338  TUFAIL("[testing] CommonTime.setInternal() with too many days, exception gnsstk::Exception, [actual] threw wrong exception");
339  }
340 
341  //----------------------------------------
342  // Does a setInternal work with negative milliseconds?
343  //----------------------------------------
344  try
345  {
346  Test.setInternal(700000,-1,0.);
347  TUFAIL("[testing] CommonTime.setInternal() with negative milliseconds, exception gnsstk::Exception, [actual] threw no exception");
348  }
349  catch(gnsstk::Exception e)
350  {
351  TUPASS("CommonTime.setInternal() with negative milliseconds should throw a gnsstk::Exception");
352  }
353  catch (...)
354  {
355  TUFAIL("[testing] CommonTime.setInternal() with negative milliseconds, exception gnsstk::Exception, [actual] threw wrong exception");
356  }
357 
358  //----------------------------------------
359  // Does a setInternal method work with too many milliseconds?
360  //----------------------------------------
361  try
362  {
363  Test.setInternal(700000,24*60*60*1000+1,0.);
364  TUFAIL("[testing] CommonTime.setInternal() with too many milliseconds, exception gnsstk::Exception, [actual] threw no exception");
365  }
366  catch(gnsstk::Exception e)
367  {
368  TUPASS("CommonTime.setInternal() with too many milliseconds should throw a gnsstk::Exception");
369  }
370  // catch(...)
371  // {
372  // TUFAIL("[testing] CommonTime.setInternal() with too many milliseconds, exception gnsstk::Exception, [actual] threw wrong exception");
373  // }
374 
375  //----------------------------------------
376  // Does a setInternal method work with negative fractional seconds?
377  //----------------------------------------
378  try
379  {
380  Test.setInternal(700000,1001,-1.);
381  TUFAIL("[testing] CommonTime.setInternal() with negative fractional seconds, exception gnsstk::Exception, [actual] threw no exception");
382  }
383  catch(gnsstk::Exception e)
384  {
385  TUPASS("CommonTime.setInternal() with negative fractional seconds should throw a gnsstk::Exception");
386  }
387  catch (...)
388  {
389  TUFAIL("[testing] CommonTime.setInternal() with negative fractional seconds, exception gnsstk::Exception, [actual] threw wrong exception");
390  }
391 
392  //----------------------------------------
393  // Does a setInternal method work with too many fractional seconds?
394  //----------------------------------------
395  try
396  {
397  Test.setInternal(700000,1001,1001.);
398  TUFAIL("[testing] CommonTime.setInternal() with too many fractional seconds, exception gnsstk::Exception, [actual] threw no exception");
399  }
400  catch(gnsstk::Exception e)
401  {
402  TUPASS("CommonTime.setInternal() with too many fractional seconds should throw a gnsstk::Exception");
403  }
404  catch(...)
405  {
406  TUFAIL("[testing] CommonTime.setInternal() with too many fractional seconds, exception gnsstk::Exception, [actual] threw wrong exception");
407  }
408 
409  //----------------------------------------
410  // The End!
411  //----------------------------------------
412  TURETURN();
413 }
414 
415 
416 unsigned CommonTime_T ::
418 {
419  TUDEF("CommonTime", "set");
420 
421  CommonTime Test1, Test2, Test3, Test4;
422  long day, day2;
423  long sod, sod2;
424  double fsod, fsod2;
425  double dec = 1.1/SEC_PER_DAY;
426 
427  //----------------------------------------
428  // Set in different ways
429  //----------------------------------------
430  Test1.set(700001,1,.1); //Set with set(long day,long sod,double fsod,TimeSystem timeSystem = TimeSystem::Unknown )
431  Test2.set(700001,1.1); //Set with set(long day,double sod,TimeSystem timeSystem = TimeSystem::Unknown )
432  Test3.set(700001 + dec); //Set with set(double day,TimeSystem timeSys = TimeSystem::Unknown )
433  Test4.setInternal(700001,1100,0.); //Set with setInternal(long day,long msod,double fsod,TimeSystem timeSys = TimeSystem::Unknown );
434 
435  //Load up compare variables
436  Test1.get(day,sod,fsod);
437  Test2.get(day2,sod2,fsod2);
438 
439  TUASSERTE(long, day, day2);
440  TUASSERTE(long, sod, sod2);
441  TUASSERTFEPS(fsod, fsod2, eps);
442 
443  //----------------------------------------
444  // Load up compare variables
445  //----------------------------------------
446  Test3.get( day2, sod2, fsod2 );
447 
448  TUASSERTE(long, day, day2);
449  TUASSERTE(long, sod, sod2);
450 
451  //Testing results show fsod = 0.1 fsod2 = 0.100004
452  //Appears to be a result of the input double is 700001.000012732
453  //Rounding the last digit appears to be causing the issue and the
454  //large error.
455 
456  testFramework.assert( fabs(fsod - fsod2) < 1E-4, "Does a set method store the correct fsod value?", __LINE__ );
457 
458  //----------------------------------------
459  // Adding a test for a much lower day value to ensure the
460  // error is from round off error.
461  //----------------------------------------
462  Test1.set(1,1,.1);
463  Test3.set(1+dec);
464  Test1.get(day,sod,fsod);
465  Test3.get(day2,sod2,fsod2);
466 
467  testFramework.assert( fabs(fsod - fsod2) < eps, "Does a set method store the correct fsod value?", __LINE__ );
468 
469  //----------------------------------------
470  //Load up compare variables
471  //----------------------------------------
472  Test1.set(700001,1,.1);
473  Test1.get(day,sod,fsod);
474  Test4.get(day2,sod2,fsod2);
475 
476  testFramework.assert( day == day2, "Does a setInternal method store the correct day value?", __LINE__ );
477  testFramework.assert( sod == sod2, "Does a setInternal method store the correct sod value?", __LINE__ );
478  testFramework.assert( fabs(fsod - fsod2) < eps, "Does a setInternal method store the correct sod value?", __LINE__ );
479 
480  //----------------------------------------
481  // The End!
482  //----------------------------------------
483  TURETURN();
484 }
485 
486 
487 unsigned CommonTime_T ::
489 {
490  TUDEF("CommonTime", "Operators");
491 
492 
493  CommonTime Arith1;
494  Arith1.set(700000,1,0.1);
495  CommonTime Arith2(Arith1); //Set second time equal to the first
496  CommonTime Result;
497  long day, day2, sod;
498  double fsod, sod2;
499 
500  testFramework.assert( fabs((Arith1-Arith2) - 0) < eps, "Does it subtract between two CommonTime objects?", __LINE__ );
501 
502 
503  //----------------------------------------
504  // Add seconds with +
505  //----------------------------------------
506  Result = Arith2 + 1;
507  Result.get(day,sod,fsod);
508  testFramework.assert( day == 700000, "Does it not add to the day value?", __LINE__ );
509  testFramework.assert( sod == 2, "Does it add to the sod value?", __LINE__ );
510  testFramework.assert( fabs(fsod - 0.1) < eps, "Does it not add to the fsod value?", __LINE__ );
511 
512  //----------------------------------------
513  // Subtract seconds with -
514  //----------------------------------------
515  Result = Arith2 - 1;
516  Result.get(day,sod,fsod);
517  testFramework.assert( day == 700000, "Does it not subtract from the day value?", __LINE__ );
518  testFramework.assert( sod == 0, "Does it subtract from the sod value?", __LINE__ );
519  testFramework.assert( fabs(fsod - 0.1) < eps, "Does it not subtract from the fsod value?", __LINE__ );
520 
521  //----------------------------------------
522  // Add seconds with +=
523  //----------------------------------------
524  Arith2 += 1;
525  testFramework.assert( fabs((Arith2-Arith1) - 1) < eps, "Does it add to a CommonTime object?", __LINE__ );
526  testFramework.assert( 1 == Arith2 - Arith1, "Check that values can be compared with integer seconds", __LINE__ );
527 
528  //----------------------------------------
529  // Subtract seconds with -=
530  //----------------------------------------
531  Arith2 -= 1;
532  testFramework.assert(fabs((Arith2-Arith1) - 0) < eps, "Does it subtract from a CommonTime object?", __LINE__ );
533 
534  //----------------------------------------
535  // Add days with addDays
536  //----------------------------------------
537  Arith2.addDays((long)1);
538  day = Arith2.getDays();
539  testFramework.assert( 700001. == day, "Does the addDays method function correctly with +?", __LINE__ );
540 
541  // Subtract days with addDays
542  Arith2.addDays((long)-1);
543  day = Arith2.getDays();
544  testFramework.assert( 700000. == day, "Does the addDays method function correctly with -?", __LINE__ );
545 
546  // Add seconds with addSeconds(double)
547  Arith2.addSeconds(86400000.+1000.);
548  testFramework.assert(fabs(86401000. - (Arith2-Arith1)) < eps, "Does the addSeconds method function correctly with +?", __LINE__ );
549 
550  // Subtract seconds with addSeconds(long)
551  Arith2.addSeconds((long)-86401000);
552  testFramework.assert( fabs(0. - (Arith2-Arith1)) < eps, "Does the addSeconds method function correctly with -?", __LINE__ );
553 
554  // Check that the two parameter get method returns day2 as the proper double
555  Arith2.get(day2, sod2);
556  testFramework.assert( (long)700000 == day2, "Does the 2 parameter get method reuturn days as a double?", __LINE__ );
557  testFramework.assert( ((double)0. - sod2) < eps, "Does the 2 parameter get method reuturn days as a double?", __LINE__ );
558 
559  // Check seconds using getSecondOfDay()
560  testFramework.assert( fabs(sod2 - Arith2.getSecondOfDay()) < eps, "Check seconds using getSecondOfDay()", __LINE__ );
561 
562  // Add milliseconds with addMilliseconds(long)
563  Arith2.addMilliseconds( (long)1 );
564  testFramework.assert( fabs(sod2+0.001 - Arith2.getSecondOfDay()) < eps, "Does the addMilliseconds method function correctly with +?", __LINE__ );
565 
566  Arith2.addMilliseconds( (long)-1 );
567  testFramework.assert(fabs(sod2 - Arith2.getSecondOfDay()) < eps, "Does the addMilliseconds method function correctly with -?", __LINE__ );
568 
569  //----------------------------------------
570  // The End!
571  //----------------------------------------
572  TURETURN();
573 }
574 
575 
576 unsigned CommonTime_T ::
578 {
579  TUDEF("CommonTime", "Differing TimeSystem, Operator ==");
580 
581  CommonTime Compare; Compare.set(1000,200,0.2); // Initialize with value
582  CommonTime LessThanDay; LessThanDay.set(100,200,0.2); // Initialize with smaller day value
583  CommonTime LessThanSecond; LessThanSecond.set(1000,20,0.2); // Initialize with smaller second value
584  CommonTime LessThanFSecond; LessThanFSecond.set(1000,200,0.1); // Initialize with smaller fractional second value
585  CommonTime CompareCopy(Compare); // Initialize with copy constructor
586 
587  testFramework.assert( Compare == CompareCopy, "GPSWeekZCount operator ==, Are equivalent objects equivalent?", __LINE__ );
588  testFramework.assert( !(Compare == LessThanDay), "GPSWeekZCount operator !=, Are non-equivalent objects equivalent?", __LINE__ );
589 
590  //----------------------------------------
591  // Operator !=
592  //----------------------------------------
593  testFramework.changeSourceMethod( "Operator !=" );
594  testFramework.assert( Compare != LessThanDay, "GPSWeekZCount operator !=, Are non-equivalent objects not equivalent?", __LINE__ );
595  testFramework.assert( Compare != LessThanSecond, "GPSWeekZCount operator !=, Are non-equivalent objects not equivalent?", __LINE__ );
596  testFramework.assert( Compare != LessThanFSecond, "GPSWeekZCount operator !=, Are non-equivalent objects not equivalent?", __LINE__ );
597  testFramework.assert( !(Compare != Compare), "GPSWeekZCount operator !=, Are equivalent objects not equivalent?", __LINE__ );
598 
599  //----------------------------------------
600  // Operator <
601  //----------------------------------------
602  testFramework.changeSourceMethod( "Operator <" );
603  testFramework.assert( LessThanDay < Compare, "Does the < operator function when left_object < right_object?", __LINE__ );
604  testFramework.assert( LessThanSecond < Compare, "Does the < operator function when left_object < right_object by days?", __LINE__ );
605  testFramework.assert( !(Compare < LessThanSecond), "Does the < operator function when left_object > right_object by days?", __LINE__ );
606  testFramework.assert( LessThanFSecond < Compare, "Does the < operator function when left_object < right_object by seconds?", __LINE__ );
607  testFramework.assert( !(Compare < LessThanFSecond), "Does the < operator function when left_object > right_object by seconds?", __LINE__ );
608  testFramework.assert( !(Compare < CompareCopy), "Does the < operator function when left_object = right_object?", __LINE__ );
609 
610  //----------------------------------------
611  // Greater than assertions
612  //----------------------------------------
613  testFramework.changeSourceMethod( "Operator >" );
614  testFramework.assert( Compare > LessThanDay, "Does the > operator function when left_object > right_object by years?", __LINE__ );
615  testFramework.assert( !(LessThanDay > Compare), "Does the > operator function when left_object < right_object by years?", __LINE__ );
616  testFramework.assert( Compare > LessThanSecond, "Does the > operator function when left_object > right_object by days?", __LINE__ );
617  testFramework.assert( !(LessThanSecond > Compare), "Does the > operator function when left_object < right_object by days?", __LINE__ );
618  testFramework.assert( Compare > LessThanFSecond, "Does the > operator function when left_object > right_object by seconds?", __LINE__ );
619  testFramework.assert( !(LessThanFSecond > Compare), "Does the > operator function when left_object < right_object by seconds?", __LINE__ );
620  testFramework.assert( !(Compare > CompareCopy), "Does the > operator function when left_object = right_object?", __LINE__ );
621 
622  //----------------------------------------
623  // Less than equals assertion
624  //----------------------------------------
625  testFramework.changeSourceMethod( "Operator <=" );
626  testFramework.assert( LessThanDay <= Compare, "Does the < operator function when left_object < right_object by years?", __LINE__ );
627  testFramework.assert( !(Compare <= LessThanDay), "Does the <= operator function when left_object > right_object by years?", __LINE__ );
628  testFramework.assert( LessThanSecond <= Compare, "Does the <= operator function when left_object < right_object by days?", __LINE__ );
629  testFramework.assert( !(Compare <= LessThanSecond), "Does the <= operator function when left_object > right_object by days?", __LINE__ );
630  testFramework.assert( LessThanFSecond <= Compare, "Does the <= operator function when left_object < right_object by seconds?", __LINE__ );
631  testFramework.assert( !(Compare <= LessThanFSecond), "Does the <= operator function when left_object > right_object by seconds?", __LINE__ );
632  testFramework.assert( Compare <= CompareCopy, "Does the <= operator function when left_object = right_object?", __LINE__ );
633 
634  //----------------------------------------
635  // Greater than equals assertion
636  //----------------------------------------
637  testFramework.changeSourceMethod( "Operator >=" );
638  testFramework.assert( Compare >= LessThanDay, "Does the >= operator function when left_object > right_object by years?", __LINE__ );
639  testFramework.assert( !(LessThanDay >= Compare), "Does the >= operator function when left_object < right_object by years?", __LINE__ );
640  testFramework.assert( Compare >= LessThanSecond, "Does the >= operator function when left_object > right_object by days?", __LINE__ );
641  testFramework.assert( !(LessThanSecond >= Compare), "Does the >= operator function when left_object < right_object by days?", __LINE__ );
642  testFramework.assert( Compare >= LessThanFSecond, "Does the >= operator function when left_object > right_object by seconds?", __LINE__ );
643  testFramework.assert( !(LessThanFSecond >= Compare), "Does the >= operator function when left_object < right_object by seconds?", __LINE__ );
644  // typo from last guy??
645  testFramework.assert( !(Compare < CompareCopy), "Does the > operator function when left_object = right_object?", __LINE__ );
646 
647  //----------------------------------------
648  // The End!
649  //----------------------------------------
650  TURETURN();
651 }
652 
653 
654 unsigned CommonTime_T ::
656 {
657  TUDEF("CommonTime", "reset" );
658 
659  CommonTime Compare; Compare.set(1000,200,0.2); // Initialize with value
660  long day, sod;
661  double fsod;
662  Compare.reset(); // Reset it
663  Compare.get(day,sod,fsod);
664 
665  testFramework.assert( TimeSystem(0) == Compare.getTimeSystem(), "Was the time system reset to expectation?", __LINE__ );
666  testFramework.assert( 0 == day, "Was the day value reset to expectation?", __LINE__ );
667  testFramework.assert( 0 == sod, "Was the sod value reset to expectation?", __LINE__ );
668  testFramework.assert( 0 == fsod, "Was the fsod value reset to expectation?", __LINE__ );
669 
670  TURETURN();
671 }
672 
673 
674 unsigned CommonTime_T ::
676 {
677  TUDEF("CommonTime", "Differing TimeSystem == Operator");
678 
679  CommonTime GPS1; GPS1.set( 1000, 200, 0.2, TimeSystem(2) );
680  CommonTime GPS2; GPS2.set( 100, 200, 0.2, TimeSystem(2) );
681  CommonTime UTC1; UTC1.set( 1000, 200, 0.2, TimeSystem(5) );
682  CommonTime UNKNOWN; UNKNOWN.set( 1000, 200, 0.2, TimeSystem(0) );
683  CommonTime ANY; ANY.set( 1000, 200, 0.2, TimeSystem(1) );
684 
685  //----------------------------------------
686  // ???
687  //----------------------------------------
688  testFramework.assert( !(GPS1 == GPS2), "Verify same Time System but different time inequality", __LINE__ );
689  testFramework.assert( GPS1.getTimeSystem() == GPS2.getTimeSystem(), "Verify same Time System equality", __LINE__ );
690 
691  //----------------------------------------
692  // Differing TimeSystem != Operator
693  //----------------------------------------
694  testFramework.changeSourceMethod( "Differing TimeSystem != Operator" );
695  testFramework.assert( GPS1 != UTC1, "Verify different Time System but same time inequality", __LINE__ );
696  testFramework.assert( GPS1 != UNKNOWN, "Verify different Time System but same time inequality", __LINE__ );
697 
698  //----------------------------------------
699  // ANY TimeSystem == Operator
700  //----------------------------------------
701  testFramework.changeSourceMethod( "ANY TimeSystem == Operator" );
702  testFramework.assert( GPS1 == ANY, "Verify TimeSystem=ANY does not matter in TimeSystem=GPS comparisons", __LINE__ );
703  testFramework.assert( UTC1 == ANY, "Verify TimeSystem=ANY does not matter in TimeSystem=UTC comparisons", __LINE__ );
704  testFramework.assert( UNKNOWN == ANY, "Verify TimeSystem=ANY does not matter in TimeSystem=UNKOWN comparisons", __LINE__ );
705 
706  //----------------------------------------
707  // ANY TimeSystem < Operator
708  //----------------------------------------
709  testFramework.changeSourceMethod( "ANY TimeSystem < Operator" );
710  testFramework.assert( !(GPS2 == ANY) && (GPS2 < ANY), "Verify TimeSystem=ANY does not matter in other operator comparisons", __LINE__ );
711 
712  //----------------------------------------
713  // setTimeSystem
714  //----------------------------------------
715  testFramework.changeSourceMethod( "setTimeSystem" );
716  UNKNOWN.setTimeSystem( TimeSystem(2) ); //Set the Unknown TimeSystem
717  testFramework.assert( UNKNOWN.getTimeSystem()==TimeSystem(2), "Ensure resetting a Time System changes it", __LINE__ );
718 
719  //----------------------------------------
720  // The End!
721  //----------------------------------------
722  TURETURN();
723 }
724 
725 
726 unsigned CommonTime_T ::
728 {
729  TUDEF("CommonTime", "printf");
730 
731  CommonTime GPS1; GPS1.set( 1234567, 24000, 0.2111, TimeSystem::GPS );
732  CommonTime UTC1; UTC1.set( 1000, 200, 0.2, TimeSystem::UTC );
733 
734  testFramework.assert( GPS1.asString() == (std::string)"1234567 24000211 0.000100000000000 GPS", "Verify printed output matches expectation", __LINE__ );
735  testFramework.assert( UTC1.asString() == (std::string)"0001000 00200200 0.000000000000000 UTC", "Verify printed output matches expectation", __LINE__ );
736  testFramework.assert( BEGINNING_OF_TIME.asString() == (std::string)"0000000 00000000 0.000000000000000 Any", "Test if BEGINNING_OF_TIME matches expectations", __LINE__ );
737 
738  //----------------------------------------
739  // The End!
740  //----------------------------------------
741  TURETURN();
742 }
743 
744 
745 unsigned CommonTime_T ::
747 {
748  TUDEF("CommonTime", "addSeconds");
749 
750  CommonTime fsodRollover; fsodRollover.set(10 , 6789 , 0.000999);
751  CommonTime msodRollover; msodRollover.set(10 , 86399, 0.0001 );
752  CommonTime dayRollunder; dayRollunder.set(10 , 2 , 0.0001 );
753  CommonTime msodRollunder; msodRollunder.set(10 , 10 , 0.000001);
754 
755  CommonTime expectedfsodROver; expectedfsodROver.set(10, 6789 , 0.001000);
756  CommonTime expectedmsodROver; expectedmsodROver.set(11, 0 , 0.0001);
757  CommonTime expectedDayRUnder; expectedDayRUnder.set( 9, 86399, 0.0001);
758  CommonTime expectedmsodRUnder; expectedmsodRUnder.set(10, 9 , 0.999999);
759 
760  long obtainedDay, expectedDay;
761  long obtainedMsod, expectedMsod;
762  double obtainedFsod, expectedFsod;
763  double diff;
764  long incrementSecLong = 1L , decrementSecLong = -3L;
765  double incrementSecDouble = 0.000001, decrementSecDouble = -0.000002;
766 
767  //--------------------------------
768  //Rollover Tests
769  //--------------------------------
770 
771  //fsod Rollover test
772  fsodRollover.addSeconds(incrementSecDouble);
773  fsodRollover.get(obtainedDay,obtainedMsod,obtainedFsod);
774  expectedfsodROver.get(expectedDay,expectedMsod,expectedFsod);
775 
776  testFramework.assert(obtainedDay == expectedDay , "Rollover of fsod affected day value" , __LINE__);
777  testFramework.assert(obtainedMsod == expectedMsod, "Rollover of fsod did not change msod", __LINE__);
778  diff = fabs(obtainedFsod - expectedFsod);
779  testFramework.assert(diff < eps, "fsod did not rollover properly" , __LINE__);
780 
781 
782  //msod Rollover test
783  msodRollover.addSeconds(incrementSecLong);
784  msodRollover.get(obtainedDay,obtainedMsod,obtainedFsod);
785  expectedmsodROver.get(expectedDay,expectedMsod,expectedFsod);
786 
787  testFramework.assert(obtainedDay == expectedDay , "Rollover of msod did not change day" , __LINE__);
788  testFramework.assert(obtainedMsod == expectedMsod, "msod did not rollover properly" , __LINE__);
789  diff = fabs(obtainedFsod - expectedFsod);
790  testFramework.assert(diff < eps, "Rollover of msod affected fsod oddly", __LINE__);
791 
792 
793  //--------------------------------
794  //Rollunder Tests
795  //--------------------------------
796 
797  //fsod Rollover test
798  dayRollunder.addSeconds(decrementSecLong);
799  dayRollunder.get(obtainedDay,obtainedMsod,obtainedFsod);
800  expectedDayRUnder.get(expectedDay,expectedMsod,expectedFsod);
801 
802  testFramework.assert(obtainedDay == expectedDay , "Rollunder of msod did not change day" , __LINE__);
803  testFramework.assert(obtainedMsod == expectedMsod, "msod did not rollunder properly" , __LINE__);
804  diff = fabs(obtainedFsod - expectedFsod);
805  testFramework.assert(diff < eps, "Rollunder of msod affected fsod oddly", __LINE__);
806 
807 
808  //msod Rollover test
809  msodRollunder.addSeconds(decrementSecDouble);
810  msodRollunder.get(obtainedDay,obtainedMsod,obtainedFsod);
811  expectedmsodRUnder.get(expectedDay,expectedMsod,expectedFsod);
812 
813  testFramework.assert(obtainedDay == expectedDay , "Rollunder of fsod affected day value" , __LINE__);
814  testFramework.assert(obtainedMsod == expectedMsod, "Rollunder of fsod did not change msod", __LINE__);
815  diff = fabs(obtainedFsod - expectedFsod);
816  testFramework.assert(diff < eps, "fsod did not rollunder properly" , __LINE__);
817 
818  TURETURN();
819 }
820 
821 
822 unsigned CommonTime_T ::
824 {
825  TUDEF("CommonTime", "changeTimeSystem");
826  std::shared_ptr<TimeSystemConverter> btscShared =
827  make_shared<gnsstk::BasicTimeSystemConverter>();
829  dynamic_cast<gnsstk::BasicTimeSystemConverter *>(btscShared.get());
830  gnsstk::CommonTime uut, exp;
831 
832  //Check conversion from any given time system to UTC and back
833  uut = gnsstk::CivilTime(1990,11,6,0,0,6,gnsstk::TimeSystem::UTC);
834  exp = gnsstk::CivilTime(1990,11,6,0,0,0,gnsstk::TimeSystem::GPS);
835  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::GPS,btsc));
836  TUASSERTE(gnsstk::CommonTime, uut, exp);
837 
838  uut = gnsstk::CivilTime(2004,11,15,23,59,47,gnsstk::TimeSystem::GPS);
839  exp = gnsstk::CivilTime(2004,11,16,0,0,0,gnsstk::TimeSystem::UTC);
840  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::UTC,btsc));
841  TUASSERTE(gnsstk::CommonTime, uut, exp);
842 
843  uut = gnsstk::CivilTime(1992,10,3,0,0,0,gnsstk::TimeSystem::UTC);
844  exp = gnsstk::CivilTime(1992,10,3,0,0,0,gnsstk::TimeSystem::GLO);
845  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::GLO,btsc));
846  TUASSERTE(gnsstk::CommonTime, uut, exp);
847 
848  uut = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
849  exp = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::UTC);
850  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::UTC,btsc));
851  TUASSERTE(gnsstk::CommonTime, uut, exp);
852 
853  uut = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
854  exp = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
855  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::GLO,btsc));
856  TUASSERTE(gnsstk::CommonTime, uut, exp);
857 
858  uut = gnsstk::CivilTime(2019,12,31,23,59,42,gnsstk::TimeSystem::GPS);
859  exp = gnsstk::CivilTime(2020,1,1,0,0,0,gnsstk::TimeSystem::GLO);
860  TUASSERTE(bool, true, uut.changeTimeSystem(gnsstk::TimeSystem::GLO,btsc));
861  TUASSERTE(gnsstk::CommonTime, uut, exp);
862 
863  // conversion using static TimeSystemConverter
864  gnsstk::CommonTime::tsConv = btscShared;
865  uut = gnsstk::CivilTime(1990,11,6,0,0,6,gnsstk::TimeSystem::UTC);
866  exp = gnsstk::CivilTime(1990,11,6,0,0,0,gnsstk::TimeSystem::GPS);
868  TUASSERTE(gnsstk::CommonTime, uut, exp);
869 
870  uut = gnsstk::CivilTime(2004,11,15,23,59,47,gnsstk::TimeSystem::GPS);
871  exp = gnsstk::CivilTime(2004,11,16,0,0,0,gnsstk::TimeSystem::UTC);
873  TUASSERTE(gnsstk::CommonTime, uut, exp);
874 
875  uut = gnsstk::CivilTime(1992,10,3,0,0,0,gnsstk::TimeSystem::UTC);
876  exp = gnsstk::CivilTime(1992,10,3,0,0,0,gnsstk::TimeSystem::GLO);
878  TUASSERTE(gnsstk::CommonTime, uut, exp);
879 
880  uut = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
881  exp = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::UTC);
883  TUASSERTE(gnsstk::CommonTime, uut, exp);
884 
885  uut = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
886  exp = gnsstk::CivilTime(1995,5,10,0,0,0,gnsstk::TimeSystem::GLO);
888  TUASSERTE(gnsstk::CommonTime, uut, exp);
889 
890  uut = gnsstk::CivilTime(2019,12,31,23,59,42,gnsstk::TimeSystem::GPS);
891  exp = gnsstk::CivilTime(2020,1,1,0,0,0,gnsstk::TimeSystem::GLO);
893  TUASSERTE(gnsstk::CommonTime, uut, exp);
894 
895  TURETURN();
896 }
897 
898 
899 
900 //============================================================
901 // Main function to initialize and run all tests above
902 //============================================================
903 int main()
904 {
905  unsigned errorTotal = 0;
906  CommonTime_T testClass;
907 
908  //----------------------------------------
909  // Run all test methods
910  //----------------------------------------
911 
912  errorTotal += testClass.initializationTest();
913  errorTotal += testClass.improperSetTest();
914  errorTotal += testClass.setComparisonTest();
915  errorTotal += testClass.arithmeticTest();
916  errorTotal += testClass.rolloverTest();
917  errorTotal += testClass.operatorTest();
918  errorTotal += testClass.resetTest();
919  errorTotal += testClass.timeSystemTest();
920  errorTotal += testClass.printfTest();
921  errorTotal += testClass.changeTimeSystemTest();
922 
923  //----------------------------------------
924  // Echo total fails to stdout
925  //----------------------------------------
926  cout << "Total Failures for " << __FILE__ << ": " << errorTotal << endl;
927 
928  //----------------------------------------
929  // Return total fails
930  //----------------------------------------
931  return errorTotal;
932 }
CommonTime_T::rolloverTest
unsigned rolloverTest()
Definition: CommonTime_T.cpp:746
gnsstk::CommonTime::addSeconds
CommonTime & addSeconds(double seconds)
Definition: CommonTime.cpp:332
example6.day
day
Definition: example6.py:66
gnsstk::CommonTime::setInternal
CommonTime & setInternal(long day=0, long msod=0, double fsod=0.0, TimeSystem timeSys=TimeSystem::Unknown)
Definition: CommonTime.cpp:153
gnsstk::BEGINNING_OF_TIME
const Epoch BEGINNING_OF_TIME(CommonTime::BEGINNING_OF_TIME)
Earliest representable Epoch.
gnsstk::CommonTime::tsConv
static GNSSTK_EXPORT std::shared_ptr< TimeSystemConverter > tsConv
Definition: CommonTime.hpp:406
gnsstk::SEC_PER_DAY
const long SEC_PER_DAY
Seconds per day.
Definition: TimeConstants.hpp:63
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
TUFAIL
#define TUFAIL(MSG)
Definition: TestUtil.hpp:228
CommonTime_T::resetTest
unsigned resetTest()
Test will check the reset method.
Definition: CommonTime_T.cpp:655
CommonTime_T::arithmeticTest
unsigned arithmeticTest()
Test to check arithmetic operations function properly.
Definition: CommonTime_T.cpp:488
CommonTime_T::CommonTime_T
CommonTime_T()
Default Constructor, set the precision value.
Definition: CommonTime_T.cpp:96
gnsstk::CommonTime::setTimeSystem
CommonTime & setTimeSystem(TimeSystem timeSystem)
Definition: CommonTime.hpp:195
CommonTime_T::operatorTest
unsigned operatorTest()
Test the comparison operators.
Definition: CommonTime_T.cpp:577
CommonTime_T::eps
double eps
Definition: CommonTime_T.cpp:91
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::CommonTime::getSecondOfDay
double getSecondOfDay() const
Obtain the seconds of day (ignoring the day).
Definition: CommonTime.cpp:279
gnsstk::CommonTime::reset
void reset()
Definition: CommonTime.hpp:399
gnsstk::Exception
Definition: Exception.hpp:151
TestUtil.hpp
gnsstk::StringUtils::FFLead::Zero
@ Zero
Start with zero, e.g. 0.12345.
BasicTimeSystemConverter.hpp
gnsstk::CommonTime::getDays
double getDays() const
Obtain the time, in days, including the fraction of a day.
Definition: CommonTime.cpp:271
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
CommonTime_T::initializationTest
unsigned initializationTest()
Definition: CommonTime_T.cpp:103
TUPASS
#define TUPASS(MSG)
Definition: TestUtil.hpp:230
CommonTime_T::timeSystemTest
unsigned timeSystemTest()
Definition: CommonTime_T.cpp:675
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
TUASSERTFEPS
#define TUASSERTFEPS(EXP, GOT, EPS)
Definition: TestUtil.hpp:126
CivilTime.hpp
gnsstk::CommonTime::get
void get(long &day, long &sod, double &fsod, TimeSystem &timeSystem) const
Definition: CommonTime.cpp:213
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
gnsstk::TimeSystem::GLO
@ GLO
GLONASS system time (aka UTC(SU))
CommonTime_T
Definition: CommonTime_T.cpp:49
gnsstk::TimeSystem::UTC
@ UTC
Coordinated Universal Time (e.g., from NTP)
CommonTime_T::improperSetTest
unsigned improperSetTest()
Definition: CommonTime_T.cpp:191
gnsstk::CivilTime
Definition: CivilTime.hpp:55
example6.sod
sod
Definition: example6.py:103
gnsstk::CommonTime::getTimeSystem
TimeSystem getTimeSystem() const
Obtain time system info (enum).
Definition: CommonTime.cpp:288
gnsstk::BasicTimeSystemConverter
Definition: BasicTimeSystemConverter.hpp:51
gnsstk::CommonTime::addMilliseconds
CommonTime & addMilliseconds(long ms)
Definition: CommonTime.cpp:371
Exception.hpp
gnsstk::TimeSystem::GPS
@ GPS
GPS system time.
CommonTime.hpp
std
Definition: Angle.hpp:142
main
int main()
Definition: CommonTime_T.cpp:903
gnsstk::CommonTime::changeTimeSystem
bool changeTimeSystem(TimeSystem timeSystem, TimeSystemConverter *conv)
Definition: CommonTime.cpp:190
CommonTime_T::changeTimeSystemTest
unsigned changeTimeSystemTest()
Definition: CommonTime_T.cpp:823
CommonTime_T::printfTest
unsigned printfTest()
Test Formatted Printing.
Definition: CommonTime_T.cpp:727
CommonTime_T::setComparisonTest
unsigned setComparisonTest()
Definition: CommonTime_T.cpp:417
gnsstk::CommonTime::asString
std::string asString() const
Definition: CommonTime.cpp:442
gnsstk::CommonTime::addDays
CommonTime & addDays(long days)
Definition: CommonTime.cpp:365
gnsstk::CommonTime::set
CommonTime & set(long day, long sod, double fsod=0.0, TimeSystem timeSystem=TimeSystem::Unknown)
Definition: CommonTime.cpp:87


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