58 unsigned initializationTest();
62 unsigned improperSetTest();
66 unsigned setComparisonTest();
69 unsigned arithmeticTest();
72 unsigned operatorTest();
79 unsigned timeSystemTest();
82 unsigned printfTest();
86 unsigned rolloverTest();
88 unsigned changeTimeSystemTest();
105 TUDEF(
"CommonTime",
"CommonTime");
113 TUPASS(
"CommonTime constructor did not throw an exception.");
117 TUFAIL(
"CommonTime constructor should not have thrown an exception.");
126 Test1.
set( (
long)700000, (
long)0, (
double)0. );
127 TUPASS(
"CommonTime.set() did not throw an exception.");
131 TUFAIL(
"CommonTime.set() threw an exception, but should not have.");
143 Test1.
set( (
long)700000, (
long)0, (
double)0. );
145 TUPASS(
"CommonTime2(CommonTime1) copy constructor did not throw an exception.");
149 TUFAIL(
"CommonTime Copy Constructor threw an exception, but should not have");
158 Test1.
set( (
long)700000, (
long)0, (
double)0. );
160 TUPASS(
"CommonTime assignment operator did not throw an exception.");
164 TUFAIL(
"CommonTime assignment operator on same line threw an exception, but should not have");
173 Test1.
set( (
long)700000, (
long)0, (
double)0.);
176 TUPASS(
"CommonTime assignment operator did not throw an exception");
180 TUFAIL(
"CommonTime assignment operator on separate line should not have thrown an exception");
194 Test.
set (700000, 0, 0.);
196 TUDEF(
"CommonTime",
"set");
206 TUFAIL(
"[testing] CommonTime.set() with negative day, exception gnsstk::Exception, [actual] threw no exception");
215 TUPASS(
"CommonTime.set() with negative day should throw a gnsstk::Exception");
219 TUFAIL(
"[testing] CommonTime.set() with negative day, exception gnsstk::Exception, [actual] threw wrong exception");
227 Test.
set(3442449,0,0.);
228 TUFAIL(
"[testing] CommonTime.set() with too many days, exception gnsstk::Exception, [actual] threw no exception");
232 TUPASS(
"CommonTime.set() with too many days should throw a gnsstk::Exception" );
236 TUFAIL(
"[testing] CommonTime.set() with too many days, exception gnsstk::Exception, [actual] threw wrong exception");
244 Test.
set(700000,-1,0.);
245 TUFAIL(
"[testing] CommonTime.set() with negative seconds, exception gnsstk::Exception, [actual] threw no exception");
249 TUPASS(
"CommonTime.set() with negative seconds should throw a gnsstk::Exception");
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");
266 TUPASS(
"CommonTime.set() with too many seconds should throw a gnsstk::Exception");
270 TUFAIL(
"[testing] CommonTime.set() with too many seconds, exception gnsstk::Exception, [actual] threw wrong exception");
278 Test.
set(700000,0,-1.);
279 TUFAIL(
"[testing] CommonTime.set() with negative fractional seconds, exception gnsstk::Exception, [actual] threw no exception");
283 TUPASS(
"CommonTime.set() with negative fractional seconds should throw a gnsstk::Exception");
287 TUFAIL(
"[testing] CommonTime.set() with negative fractional seconds, exception gnsstk::Exception, [actual] threw wrong exception");
295 Test.
set(700000,0,2.);
296 TUFAIL(
"[testing] CommonTime.set() with too many fractional seconds, exception gnsstk::Exception, [actual] threw no exception");
300 TUPASS(
"CommonTime.set() with too many fractional seconds should throw a gnsstk::Exception");
304 TUFAIL(
"[testing] CommonTime.set() with too many fractional seconds, exception gnsstk::Exception, [actual] threw wrong exception");
313 TUFAIL(
"[testing] CommonTime.setInternal() with negative days, exception gnsstk::Exception, [actual] threw no exception");
317 TUPASS(
"CommonTime.setInternal() with negative days should throw a gnsstk::Exception");
321 TUFAIL(
"[testing] CommonTime.setInternal() with negative days, exception gnsstk::Exception, [actual] threw wrong exception");
330 TUFAIL(
"[testing] CommonTime.setInternal() with too many days, exception gnsstk::Exception, [actual] threw no exception");
334 TUPASS(
"CommonTime.setInternal() with too many days should throw a gnsstk::Exception");
338 TUFAIL(
"[testing] CommonTime.setInternal() with too many days, exception gnsstk::Exception, [actual] threw wrong exception");
347 TUFAIL(
"[testing] CommonTime.setInternal() with negative milliseconds, exception gnsstk::Exception, [actual] threw no exception");
351 TUPASS(
"CommonTime.setInternal() with negative milliseconds should throw a gnsstk::Exception");
355 TUFAIL(
"[testing] CommonTime.setInternal() with negative milliseconds, exception gnsstk::Exception, [actual] threw wrong exception");
364 TUFAIL(
"[testing] CommonTime.setInternal() with too many milliseconds, exception gnsstk::Exception, [actual] threw no exception");
368 TUPASS(
"CommonTime.setInternal() with too many milliseconds should throw a gnsstk::Exception");
381 TUFAIL(
"[testing] CommonTime.setInternal() with negative fractional seconds, exception gnsstk::Exception, [actual] threw no exception");
385 TUPASS(
"CommonTime.setInternal() with negative fractional seconds should throw a gnsstk::Exception");
389 TUFAIL(
"[testing] CommonTime.setInternal() with negative fractional seconds, exception gnsstk::Exception, [actual] threw wrong exception");
398 TUFAIL(
"[testing] CommonTime.setInternal() with too many fractional seconds, exception gnsstk::Exception, [actual] threw no exception");
402 TUPASS(
"CommonTime.setInternal() with too many fractional seconds should throw a gnsstk::Exception");
406 TUFAIL(
"[testing] CommonTime.setInternal() with too many fractional seconds, exception gnsstk::Exception, [actual] threw wrong exception");
419 TUDEF(
"CommonTime",
"set");
430 Test1.
set(700001,1,.1);
431 Test2.
set(700001,1.1);
432 Test3.
set(700001 + dec);
437 Test2.
get(day2,sod2,fsod2);
446 Test3.
get( day2, sod2, fsod2 );
456 testFramework.assert( fabs(fsod - fsod2) < 1E-4,
"Does a set method store the correct fsod value?", __LINE__ );
465 Test3.
get(day2,sod2,fsod2);
467 testFramework.assert( fabs(fsod - fsod2) < eps,
"Does a set method store the correct fsod value?", __LINE__ );
472 Test1.
set(700001,1,.1);
474 Test4.
get(day2,sod2,fsod2);
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__ );
490 TUDEF(
"CommonTime",
"Operators");
494 Arith1.
set(700000,1,0.1);
500 testFramework.assert( fabs((Arith1-Arith2) - 0) < eps,
"Does it subtract between two CommonTime objects?", __LINE__ );
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__ );
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__ );
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__ );
532 testFramework.assert(fabs((Arith2-Arith1) - 0) < eps,
"Does it subtract from a CommonTime object?", __LINE__ );
539 testFramework.assert( 700001. ==
day,
"Does the addDays method function correctly with +?", __LINE__ );
544 testFramework.assert( 700000. ==
day,
"Does the addDays method function correctly with -?", __LINE__ );
548 testFramework.assert(fabs(86401000. - (Arith2-Arith1)) < eps,
"Does the addSeconds method function correctly with +?", __LINE__ );
552 testFramework.assert( fabs(0. - (Arith2-Arith1)) < eps,
"Does the addSeconds method function correctly with -?", __LINE__ );
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__ );
560 testFramework.assert( fabs(sod2 - Arith2.
getSecondOfDay()) < eps,
"Check seconds using getSecondOfDay()", __LINE__ );
564 testFramework.assert( fabs(sod2+0.001 - Arith2.
getSecondOfDay()) < eps,
"Does the addMilliseconds method function correctly with +?", __LINE__ );
567 testFramework.assert(fabs(sod2 - Arith2.
getSecondOfDay()) < eps,
"Does the addMilliseconds method function correctly with -?", __LINE__ );
579 TUDEF(
"CommonTime",
"Differing TimeSystem, Operator ==");
584 CommonTime LessThanFSecond; LessThanFSecond.
set(1000,200,0.1);
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__ );
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__ );
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__ );
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__ );
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__ );
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__ );
645 testFramework.assert( !(Compare < CompareCopy),
"Does the > operator function when left_object = right_object?", __LINE__ );
657 TUDEF(
"CommonTime",
"reset" );
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__ );
677 TUDEF(
"CommonTime",
"Differing TimeSystem == Operator");
688 testFramework.assert( !(GPS1 == GPS2),
"Verify same Time System but different time inequality", __LINE__ );
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__ );
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__ );
709 testFramework.changeSourceMethod(
"ANY TimeSystem < Operator" );
710 testFramework.assert( !(GPS2 == ANY) && (GPS2 < ANY),
"Verify TimeSystem=ANY does not matter in other operator comparisons", __LINE__ );
715 testFramework.changeSourceMethod(
"setTimeSystem" );
717 testFramework.assert( UNKNOWN.
getTimeSystem()==
TimeSystem(2),
"Ensure resetting a Time System changes it", __LINE__ );
729 TUDEF(
"CommonTime",
"printf");
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__ );
748 TUDEF(
"CommonTime",
"addSeconds");
750 CommonTime fsodRollover; fsodRollover.
set(10 , 6789 , 0.000999);
751 CommonTime msodRollover; msodRollover.
set(10 , 86399, 0.0001 );
753 CommonTime msodRollunder; msodRollunder.
set(10 , 10 , 0.000001);
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);
760 long obtainedDay, expectedDay;
761 long obtainedMsod, expectedMsod;
762 double obtainedFsod, expectedFsod;
764 long incrementSecLong = 1L , decrementSecLong = -3L;
765 double incrementSecDouble = 0.000001, decrementSecDouble = -0.000002;
773 fsodRollover.
get(obtainedDay,obtainedMsod,obtainedFsod);
774 expectedfsodROver.
get(expectedDay,expectedMsod,expectedFsod);
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__);
784 msodRollover.
get(obtainedDay,obtainedMsod,obtainedFsod);
785 expectedmsodROver.
get(expectedDay,expectedMsod,expectedFsod);
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__);
799 dayRollunder.
get(obtainedDay,obtainedMsod,obtainedFsod);
800 expectedDayRUnder.
get(expectedDay,expectedMsod,expectedFsod);
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__);
810 msodRollunder.
get(obtainedDay,obtainedMsod,obtainedFsod);
811 expectedmsodRUnder.
get(expectedDay,expectedMsod,expectedFsod);
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__);
825 TUDEF(
"CommonTime",
"changeTimeSystem");
826 std::shared_ptr<TimeSystemConverter> btscShared =
827 make_shared<gnsstk::BasicTimeSystemConverter>();
905 unsigned errorTotal = 0;
926 cout <<
"Total Failures for " << __FILE__ <<
": " << errorTotal << endl;