1 //==============================================================================
2 //
3 // This file is part of GPSTk, the GPS Toolkit.
4 //
5 // The GPSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GPSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GPSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2020, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38
39 #include "TimeSystem.hpp"
40 #include "TestUtil.hpp"
41 #include <iostream>
42 #include <sstream>
43 #include <cmath>
44
45 class TimeSystem_T
46 {
47 public:
operatorTest()48 unsigned operatorTest()
49 {
50 TUDEF("TimeSystem", "operator<<");
51 std::string testMesg;
52
53 gpstk::TimeSystem compare = gpstk::TimeSystem::GAL;
54
55 //Does operator<< function correctly?
56 std::string outputString, compareString;
57 std::stringstream outputStream;
58 outputStream << compare;
59 outputString = outputStream.str();
60 compareString = "GAL";
61 TUASSERTE(std::string, compareString, outputString);
62
63 TURETURN();
64 }
65
66
getLeapSecondsTest()67 unsigned getLeapSecondsTest()
68 {
69 TUDEF("TimeSystem", "getLeapSeconds");
70
71 //Check leap-second computation prior to 1972 but not before 1960
72
73 //Should be (inputDate - lastRefDate) * rate + leapSeconds
74 //4.213170+488*0.002592
75 TUASSERTFE(5.478066, gpstk::getLeapSeconds(1969, 6, 3));
76 //1.8458580 + 118*0.0011232
77 TUASSERTFE(1.9783956, gpstk::getLeapSeconds(1962, 4, 29));
78 //3.6401300 + 5*.001296
79 TUASSERTFE(3.64661, gpstk::getLeapSeconds(1965, 3, 6));
80 //4.2131700 + 295*.002592
81 TUASSERTFE(4.97781, gpstk::getLeapSeconds(1968, 11, 22));
82 //4.3131700 + 409*.002592
83 TUASSERTFE(5.373298, gpstk::getLeapSeconds(1967, 2, 14));
84
85 //Check leap-second computation after 1/1/1972
86 TUASSERTFE(29, gpstk::getLeapSeconds(1995, 10, 13));
87 TUASSERTFE(32, gpstk::getLeapSeconds(2004, 3, 25));
88 TUASSERTFE(22, gpstk::getLeapSeconds(1984, 8, 27));
89 TUASSERTFE(10, gpstk::getLeapSeconds(1972, 5, 8));
90
91 TURETURN();
92 }
93
94
correctionTest()95 unsigned correctionTest()
96 {
97 TUDEF("TimeSystem", "getTimeSystemCorrection");
98
99 //Check conversion from any given time system to UTC and back
100 TUASSERTFE(6, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::UTC, gpstk::TimeSystem::GPS, 1990, 11, 6));
101 TUASSERTFE(-13, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::GPS, gpstk::TimeSystem::UTC, 2004, 11, 16));
102 TUASSERTFE(0, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::UTC, gpstk::TimeSystem::GLO, 1992, 10, 3));
103 TUASSERTFE(0, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::GLO, gpstk::TimeSystem::UTC, 1995, 5, 10));
104 TUASSERTFE(12, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::UTC, gpstk::TimeSystem::GAL, 1997, 7, 25));
105 TUASSERTFE(-14, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::GAL, gpstk::TimeSystem::UTC, 2008, 6, 5));
106
107 // QZSS can't be converted
108 //testMesg = "Conversion from UTC time to QZS time was incorrect";
109 //testFramework.assert(std::abs(gpstk::getTimeSystemCorrection(gpstk::TimeSystem::UTC, gpstk::TimeSystem::QZS, 1985, 8, 10) - 4) < eps, testMesg, __LINE__);
110 //testMesg = "Conversion from QZS time to UTC time was incorrect";
111 //testFramework.assert(std::abs(gpstk::getTimeSystemCorrection(gpstk::TimeSystem::QZS, gpstk::TimeSystem::UTC, 2010, 2, 14) - 15) < eps, testMesg, __LINE__);
112
113 TUASSERTFE(0, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::UTC, gpstk::TimeSystem::BDT, 2006, 9, 21));
114 TUASSERTFE(-2, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::BDT, gpstk::TimeSystem::UTC, 2012, 8, 27));
115 TUASSERTFE(13, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::UTC, gpstk::TimeSystem::IRN, 2004, 11, 16));
116 TUASSERTFE(-13, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::IRN, gpstk::TimeSystem::UTC, 2004, 11, 16));
117 TUASSERTFE(35, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::UTC, gpstk::TimeSystem::TAI, 2014, 6, 1));
118 TUASSERTFE(-35, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::TAI, gpstk::TimeSystem::UTC, 2015, 1, 1));
119 TUASSERTFE(13 + 51.184, gpstk::getTimeSystemCorrection(gpstk::TimeSystem::UTC, gpstk::TimeSystem::TT, 2005, 4, 31));
120 TUASSERTFE(-(6 + 51.184), gpstk::getTimeSystemCorrection(gpstk::TimeSystem::TT, gpstk::TimeSystem::UTC, 1990, 7, 21));
121 //reference section B of astronomical almanac for TDB conversion
122 TUASSERTFE(65.1840299405112091335467994213104248046875,
123 gpstk::getTimeSystemCorrection(gpstk::TimeSystem::UTC, gpstk::TimeSystem::TDB, 2007, 12, 25));
124 TUASSERTFE(-58.1838658094272460630236309953033924102783203125,
125 gpstk::getTimeSystemCorrection(gpstk::TimeSystem::TDB, gpstk::TimeSystem::UTC, 1991, 4, 25));
126
127 TURETURN();
128 }
129 };
130
131
main()132 int main() //Main function to initialize and run all tests above
133 {
134 TimeSystem_T testClass;
135 unsigned errorCounter = 0;
136
137 errorCounter += testClass.operatorTest();
138 errorCounter += testClass.getLeapSecondsTest();
139 errorCounter += testClass.correctionTest();
140
141 std::cout << "Total Failures for " << __FILE__ << ": " << errorCounter
142 << std::endl;
143
144 return errorCounter; //Return the total number of errors
145 }
146