CivilTime_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 "CivilTime.hpp"
40 #include "TimeSystem.hpp"
41 #include "TestUtil.hpp"
42 #include <iostream>
43 #include <fstream>
44 #include <cmath>
45 
46 using namespace gnsstk;
47 using namespace std;
48 
50 {
51  public:
52  CivilTime_T(){eps = 1e-12;}// Default Constructor, set the precision value
53  ~CivilTime_T() {} // Default Desructor
54 
55  public:
56 
57 //==========================================================================================================================
58 // initializationTest ensures the constructors set the values properly
59 //==========================================================================================================================
60  int initializationTest (void)
61  {
62  TestUtil testFramework( "CivilTime", "Constructor", __FILE__, __LINE__ );
63  CivilTime Compare(2008,8,21,13,30,15.,TimeSystem::GPS); //Initialize an object
64 
65  //---------------------------------------------------------------------
66  //Were the attributes set to expectation with the explicit constructor?
67  //---------------------------------------------------------------------
68  testFramework.assert(TimeSystem(2) == Compare.getTimeSystem(), "Explicit constructor did not set the TimeSystem properly", __LINE__);
69  testFramework.assert(2008 == (int)Compare.year, "Explicit constructor did not set the year properly", __LINE__);
70  testFramework.assert( 8 == (int)Compare.month, "Explicit constructor did not set the month properly", __LINE__);
71  testFramework.assert(21 == (int)Compare.day, "Explicit constructor did not set the day properly", __LINE__);
72  testFramework.assert(13 == (int)Compare.hour, "Explicit constructor did not set the hour properly", __LINE__);
73  testFramework.assert(30 == (int)Compare.minute, "Explicit constructor did not set the minute properly", __LINE__);
74  testFramework.assert(15 == (double)Compare.second, "Explicit constructor did not set the second properly", __LINE__);
75 
76 
77  testFramework.changeSourceMethod("ConstructorCopy");
78  CivilTime Copy(Compare); // Initialize with copy constructor
79  //---------------------------------------------------------------------
80  //Were the attributes set to expectation with the copy constructor?
81  //---------------------------------------------------------------------
82  testFramework.assert(TimeSystem(2) == Copy.getTimeSystem(), "Copy constructor did not set the TimeSystem properly", __LINE__);
83  testFramework.assert(2008 == (int)Copy.year, "Copy constructor did not set the year properly", __LINE__);
84  testFramework.assert(8 == (int)Copy.month, "Copy constructor did not set the month properly", __LINE__);
85  testFramework.assert(21 == (int)Copy.day, "Copy constructor did not set the day properly", __LINE__);
86  testFramework.assert(13 == (int)Copy.hour, "Copy constructor did not set the hour properly", __LINE__);
87  testFramework.assert(30 == (int)Copy.minute, "Copy constructor did not set the minute properly", __LINE__);
88  testFramework.assert(15 == (double)Copy.second, "Copy constructor did not set the second properly", __LINE__);
89 
90 
91  CivilTime Assigned;
92  Assigned = Compare;
93  testFramework.changeSourceMethod("OperatorSet");
94  //---------------------------------------------------------------------
95  //Were the attributes set to expectation with the Set operator?
96  //---------------------------------------------------------------------
97  testFramework.assert(TimeSystem(2) == Assigned.getTimeSystem(), "Set Operator did not set the TimeSystem properly", __LINE__);
98  testFramework.assert(2008 == (int)Assigned.year, "Set Operator did not set the year properly", __LINE__);
99  testFramework.assert(8 == (int)Assigned.month, "Set Operator did not set the month properly", __LINE__);
100  testFramework.assert(21 == (int)Assigned.day, "Set Operator did not set the day properly", __LINE__);
101  testFramework.assert(13 == (int)Assigned.hour, "Set Operator did not set the hour properly", __LINE__);
102  testFramework.assert(30 == (int)Assigned.minute, "Set Operator did not set the mimute properly", __LINE__);
103  testFramework.assert(15 == (double)Assigned.second, "Set Operator did not set the second properly", __LINE__);
104 
105  return testFramework.countFails();
106  }
107 
108 //==========================================================================================================================
109 // Test will check if CivilTime variable can be set from a map.
110 //==========================================================================================================================
111  int setFromInfoTest (void)
112  {
113  TestUtil testFramework( "CivilTime", "setFromInfo", __FILE__, __LINE__ );
114 
115  //Create several objects for testing
116  CivilTime setFromInfo1;
117  CivilTime setFromInfo2;
118  CivilTime setFromInfo3;
119  CivilTime setFromInfo4;
120  CivilTime setFromInfo5;
121 
122  //Set several values to set the objects
124  Id['b'] = "Dec";
125  Id['d'] = "31";
126  Id['Y'] = "2008";
127  Id['H'] = "12";
128  Id['M'] = "00";
129  Id['S'] = "00";
130  Id['P'] = "GPS";
131  CivilTime Check(2008,12,31,12,0,0,TimeSystem::GPS);
132  //---------------------------------------------------------------------
133  //Can a CivilTime object be set with b,d,Y,H,M,S,P options?
134  //---------------------------------------------------------------------
135  testFramework.assert(setFromInfo1.setFromInfo(Id), "setFromInfo experienced an error and returned false", __LINE__);
136  testFramework.assert(setFromInfo1 == Check, "setFromInfo did not set all of the values properly", __LINE__);
137 
138 
139  Id.erase('b');
140  Id.erase('Y');
141  Id['m'] = "12";
142  Id['y'] = "06";
143  CivilTime Check2(2006,12,31,12,0,0,TimeSystem::GPS);
144  //---------------------------------------------------------------------
145  //Can a CivilTime object be set with d,m,y,H,M,S,P options?
146  //---------------------------------------------------------------------
147  testFramework.assert(setFromInfo2.setFromInfo(Id), "setFromInfo experienced an error and returned false", __LINE__);
148  testFramework.assert(setFromInfo2 == Check2, "setFromInfo did not set all of the values properly", __LINE__);
149 
150 
151  Id.erase('y');
152  Id['y'] = "006";
153  //---------------------------------------------------------------------
154  //Can a CivilTime object be set with a 3 digit year? Answer should be no. 'y' option is for 2 digit years.
155  //---------------------------------------------------------------------
156  testFramework.assert(!setFromInfo3.setFromInfo(Id), "setFromInfo allowed a 3 digit year to be set with 'y' option", __LINE__);
157 
158 
159  Id.erase('y');
160  //---------------------------------------------------------------------
161  //Can a CivilTime object be set without a year?
162  //---------------------------------------------------------------------
163  testFramework.assert(setFromInfo4.setFromInfo(Id), "setFromInfo experienced an error and returned false", __LINE__);
164 
165 
166  Id.erase('m');
167  Id['b'] = "AAA";
168  //---------------------------------------------------------------------
169  //Can a CivilTime object be set with an improper month?
170  //---------------------------------------------------------------------
171  testFramework.assert(!(setFromInfo5.setFromInfo(Id)), "setFromInfo allowed the month to be set with an improper value", __LINE__);
172 
173 
174  return testFramework.countFails();
175  }
176 
177 
178 //==========================================================================================================================
179 // Test will check if the ways to initialize and set an CivilTime object.
180 // Test also tests whether the comparison operators and isValid method function.
181 //==========================================================================================================================
182  int operatorTest (void)
183  {
184  TestUtil testFramework( "CivilTime", "OperatorEquivalent", __FILE__, __LINE__ );
185 
186  CivilTime Aug21(2008,8,21,13,30,15.); //Reference time
187  // Series of conditions less than Aug21 above
188  CivilTime LessThanYear(2005,8,21,13,30,15.);
189  CivilTime LessThanMonth(2008,7,21,13,30,15.);
190  CivilTime LessThanDay(2008,8,20,13,30,15.);
191  CivilTime LessThanHour(2008,8,21,12,30,15.);
192  CivilTime LessThanMinute(2008,8,21,13,20,15.);
193  CivilTime LessThanSecond(2008,8,21,13,30,0.);
194  CivilTime Aug21Copy(Aug21); //Use copy constructor
195  CivilTime Aug21Copy2 = Aug21Copy; //Use the = set operator.
196 
197  //---------------------------------------------------------------------
198  //Does the == Operator function?
199  //---------------------------------------------------------------------
200  testFramework.assert( Aug21 == Aug21Copy, "Equivalence operator found equivalent objects to be not equivalent", __LINE__);
201  testFramework.assert(!(Aug21 == LessThanYear), "Equivalence operator found different year objects to be equivalent", __LINE__);
202  testFramework.assert(!(Aug21 == LessThanMonth), "Equivalence operator found different month objects to be equivalent", __LINE__);
203  testFramework.assert(!(Aug21 == LessThanDay), "Equivalence operator found different day objects to be equivalent", __LINE__);
204  testFramework.assert(!(Aug21 == LessThanHour), "Equivalence operator found different hour objects to be equivalent", __LINE__);
205  testFramework.assert(!(Aug21 == LessThanMinute), "Equivalence operator found different minute objects to be equivalent", __LINE__);
206  testFramework.assert(!(Aug21 == LessThanSecond), "Equivalence operator found different second objects to be equivalent", __LINE__);
207 
208 
209  testFramework.changeSourceMethod("OperatorNotEquivalent");
210  //---------------------------------------------------------------------
211  //Does the != Operator function?
212  //---------------------------------------------------------------------
213  testFramework.assert( Aug21 != LessThanYear, "Not-equal operator found different year objects to be equivalent", __LINE__);
214  testFramework.assert( Aug21 != LessThanMonth, "Not-equal operator found different month objects to be equivalent", __LINE__);
215  testFramework.assert( Aug21 != LessThanDay, "Not-equal operator found different day objects to be equivalent", __LINE__);
216  testFramework.assert( Aug21 != LessThanHour, "Not-equal operator found different hour objects to be equivalent", __LINE__);
217  testFramework.assert( Aug21 != LessThanMinute, "Not-equal operator found different minute objects to be equivalent", __LINE__);
218  testFramework.assert( Aug21 != LessThanSecond, "Not-equal operator found different second objects to be equivalent", __LINE__);
219  testFramework.assert(!(Aug21 != Aug21Copy), "Not-equal operator found equivalent objects to not be equivalent", __LINE__);
220 
221  testFramework.changeSourceMethod("OperatorLessThan");
222  //---------------------------------------------------------------------
223  //Does the < operator function?
224  //---------------------------------------------------------------------
225  testFramework.assert( LessThanYear < Aug21, "Less-than operator found less-than year object to not be less than", __LINE__);
226  testFramework.assert( LessThanMonth < Aug21, "Less-than operator found less-than month object to not be less than", __LINE__);
227  testFramework.assert( LessThanDay < Aug21, "Less-than operator found less-than day object to not be less than", __LINE__);
228  testFramework.assert( LessThanHour < Aug21, "Less-than operator found less-than hour object to not be less than", __LINE__);
229  testFramework.assert( LessThanMinute < Aug21, "Less-than operator found less-than minute object to not be less than", __LINE__);
230  testFramework.assert( LessThanSecond < Aug21, "Less-than operator found less-than second object to not be less than", __LINE__);
231  testFramework.assert(!(Aug21 < LessThanYear), "Less-than operator found greater-than year object to be less than", __LINE__);
232  testFramework.assert(!(Aug21 < LessThanMonth), "Less-than operator found greater-than month object to be less than", __LINE__);
233  testFramework.assert(!(Aug21 < LessThanDay), "Less-than operator found greater-than day object to be less than", __LINE__);
234  testFramework.assert(!(Aug21 < LessThanHour), "Less-than operator found greater-than hour object to be less than", __LINE__);
235  testFramework.assert(!(Aug21 < LessThanMinute), "Less-than operator found greater-than minute object to be less than", __LINE__);
236  testFramework.assert(!(Aug21 < LessThanSecond), "Less-than operator found greater-than second object to be less than", __LINE__);
237  testFramework.assert(!(Aug21 < Aug21Copy), "Less-than operator found equivalent objects to be less than", __LINE__);
238 
239 
240  testFramework.changeSourceMethod("OperatorGreaterThan");
241  //---------------------------------------------------------------------
242  //Does the > operator function?
243  //---------------------------------------------------------------------
244  testFramework.assert(!(LessThanYear > Aug21), "Greater-than operator found less-than year object to be greater-than", __LINE__);
245  testFramework.assert(!(LessThanMonth > Aug21), "Greater-than operator found less-than month object to be greater-than", __LINE__);
246  testFramework.assert(!(LessThanDay > Aug21), "Greater-than operator found less-than day object to be greater-than", __LINE__);
247  testFramework.assert(!(LessThanHour > Aug21), "Greater-than operator found less-than hour object to be greater-than", __LINE__);
248  testFramework.assert(!(LessThanMinute > Aug21), "Greater-than operator found less-than minute object to be greater-than", __LINE__);
249  testFramework.assert(!(LessThanSecond > Aug21), "Greater-than operator found less-than second object to be greater-than", __LINE__);
250  testFramework.assert( Aug21 > LessThanYear, "Greater-than operator found greater-than year object to not be greater-than", __LINE__);
251  testFramework.assert( Aug21 > LessThanMonth, "Greater-than operator found greater-than month object to not be greater-than", __LINE__);
252  testFramework.assert( Aug21 > LessThanDay, "Greater-than operator found greater-than day object to not be greater-than", __LINE__);
253  testFramework.assert( Aug21 > LessThanHour, "Greater-than operator found greater-than hour object to not be greater-than", __LINE__);
254  testFramework.assert( Aug21 > LessThanMinute, "Greater-than operator found greater-than minute object to not be greater-than", __LINE__);
255  testFramework.assert( Aug21 > LessThanSecond, "Greater-than operator found greater-than second object to not be greater-than", __LINE__);
256  testFramework.assert(!(Aug21 > Aug21Copy), "Greater-than operator found equivalent objects to be greater-than", __LINE__);
257 
258 
259  testFramework.changeSourceMethod("OperatorLessThanOrEqualTo");
260  //---------------------------------------------------------------------
261  //Does the <= operator function?
262  //---------------------------------------------------------------------
263  testFramework.assert( LessThanYear <= Aug21, "Less-than-or-equal-to operator found less-than year object to not be less-than-or-equal-to", __LINE__);
264  testFramework.assert( LessThanMonth <= Aug21, "Less-than-or-equal-to operator found less-than month object to not be less-than-or-equal-to", __LINE__);
265  testFramework.assert( LessThanDay <= Aug21, "Less-than-or-equal-to operator found less-than day object to not be less-than-or-equal-to", __LINE__);
266  testFramework.assert( LessThanHour <= Aug21, "Less-than-or-equal-to operator found less-than hour object to not be less-than-or-equal-to", __LINE__);
267  testFramework.assert( LessThanMinute <= Aug21, "Less-than-or-equal-to operator found less-than minute object to not be less-than-or-equal-to", __LINE__);
268  testFramework.assert( LessThanSecond <= Aug21, "Less-than-or-equal-to operator found less-than second object to not be less-than-or-equal-to", __LINE__);
269  testFramework.assert(!(Aug21 <= LessThanYear), "Less-than-or-equal-to operator found greater-than year object to be less-than-or-equal-to", __LINE__);
270  testFramework.assert(!(Aug21 <= LessThanMonth), "Less-than-or-equal-to operator found greater-than month object to be less-than-or-equal-to", __LINE__);
271  testFramework.assert(!(Aug21 <= LessThanDay), "Less-than-or-equal-to operator found greater-than day object to be less-than-or-equal-to", __LINE__);
272  testFramework.assert(!(Aug21 <= LessThanHour), "Less-than-or-equal-to operator found greater-than hour object to be less-than-or-equal-to", __LINE__);
273  testFramework.assert(!(Aug21 <= LessThanMinute), "Less-than-or-equal-to operator found greater-than minute object to be less-than-or-equal-to", __LINE__);
274  testFramework.assert(!(Aug21 <= LessThanSecond), "Less-than-or-equal-to operator found greater-than second object to be less-than-or-equal-to", __LINE__);
275  testFramework.assert( Aug21 <= Aug21Copy, "Less-than-or-equal-to operator found equivalent objects to not be less-than-or-equal-to", __LINE__);
276 
277 
278  testFramework.changeSourceMethod("OperatorGreaterThanOrEqualTo");
279  //---------------------------------------------------------------------
280  //Does the >= operator function?
281  //---------------------------------------------------------------------
282  testFramework.assert(!(LessThanYear >= Aug21), "Greater-than-or-equal-to operator found less-than year object to be greater-than-or-equal-to", __LINE__);
283  testFramework.assert(!(LessThanMonth >= Aug21), "Greater-than-or-equal-to operator found less-than month object to be greater-than-or-equal-to", __LINE__);
284  testFramework.assert(!(LessThanDay >= Aug21), "Greater-than-or-equal-to operator found less-than day object to be greater-than-or-equal-to", __LINE__);
285  testFramework.assert(!(LessThanHour >= Aug21), "Greater-than-or-equal-to operator found less-than hour object to be greater-than-or-equal-to", __LINE__);
286  testFramework.assert(!(LessThanMinute >= Aug21), "Greater-than-or-equal-to operator found less-than minute object to be greater-than-or-equal-to", __LINE__);
287  testFramework.assert(!(LessThanSecond >= Aug21), "Greater-than-or-equal-to operator found less-than second object to be greater-than-or-equal-to", __LINE__);
288  testFramework.assert( Aug21 >= LessThanYear, "Greater-than-or-equal-to operator found greater-than year object to not be greater-than-or-equal-to", __LINE__);
289  testFramework.assert( Aug21 >= LessThanMonth, "Greater-than-or-equal-to operator found greater-than month object to not be greater-than-or-equal-to", __LINE__);
290  testFramework.assert( Aug21 >= LessThanDay, "Greater-than-or-equal-to operator found greater-than day object to not be greater-than-or-equal-to", __LINE__);
291  testFramework.assert( Aug21 >= LessThanHour, "Greater-than-or-equal-to operator found greater-than hour object to not be greater-than-or-equal-to", __LINE__);
292  testFramework.assert( Aug21 >= LessThanMinute, "Greater-than-or-equal-to operator found greater-than minute object to not be greater-than-or-equal-to", __LINE__);
293  testFramework.assert( Aug21 >= LessThanSecond, "Greater-than-or-equal-to operator found greater-than second object to not be greater-than-or-equal-to", __LINE__);
294  testFramework.assert( Aug21 >= Aug21Copy, "Greater-than-or-equal-to operator found equivalent objects to not be greater-than-or-equal-to", __LINE__);
295 
296 
297  return testFramework.countFails();
298  }
299 
300 
301 //==========================================================================================================================
302 // Test will check converting to/from CommonTime.
303 //==========================================================================================================================
305  {
306  TestUtil testFramework( "CivilTime", "isValid", __FILE__, __LINE__ );
307 
308  CivilTime Aug21(2008,8,21,13,30,15.,TimeSystem::GPS);
309  //---------------------------------------------------------------------
310  //Is the time after the BEGINNING_OF_TIME?
311  //---------------------------------------------------------------------
312  testFramework.assert(Aug21.convertToCommonTime() > CommonTime::BEGINNING_OF_TIME, "Time provided found to be less than the beginning of time", __LINE__);
313 
314  //---------------------------------------------------------------------
315  //Is the set object valid?
316  //---------------------------------------------------------------------
317  testFramework.assert(Aug21.isValid(), "Time provided found to be unable to convert to/from CommonTime", __LINE__);
318 
319 
320  CommonTime Test = Aug21.convertToCommonTime();
321 
322  CivilTime Test2;
323  Test2.convertFromCommonTime(Test);
324 
325  testFramework.changeSourceMethod("CommonTimeConversion");
326  //---------------------------------------------------------------------
327  //Is the result of conversion the same?
328  //---------------------------------------------------------------------
329  testFramework.assert(Test2.getTimeSystem()==Aug21.getTimeSystem(), "TimeSystem provided found to be different after converting to and from CommonTime", __LINE__);
330  testFramework.assert(Test2.year == Aug21.year, "Year provided found to be different after converting to and from CommonTime", __LINE__);
331  testFramework.assert(Test2.month == Aug21.month, "Month provided found to be different after converting to and from CommonTime", __LINE__);
332  testFramework.assert(Test2.day == Aug21.day, "Day provided found to be different after converting to and from CommonTime", __LINE__);
333  testFramework.assert(Test2.hour == Aug21.hour, "Hour provided found to be different after converting to and from CommonTime", __LINE__);
334  testFramework.assert(Test2.minute == Aug21.minute, "Minute provided found to be different after converting to and from CommonTime", __LINE__);
335  testFramework.assert(Test2.second == Aug21.second, "Second provided found to be different after converting to and from CommonTime", __LINE__);
336 
337  return testFramework.countFails();
338  }
339 
340 
341 
342 
343 //==========================================================================================================================
344 // Test will check the reset method.
345 //==========================================================================================================================
346 
347  int resetTest (void)
348  {
349  TestUtil testFramework( "CivilTime", "reset", __FILE__, __LINE__ );
350  //Initialize a time
351  CivilTime Aug21(2008,8,21,13,30,15.,TimeSystem::GPS);
352 
353  Aug21.reset();
354  //---------------------------------------------------------------------
355  //Were the attributes reset to expectation?
356  //---------------------------------------------------------------------
357  testFramework.assert(Aug21.getTimeSystem()==TimeSystem(0), "TimeSystem not set to default (Unknown) after reset", __LINE__);
358  testFramework.assert(0 == (int)Aug21.year, "Year not set to default (0) after reset", __LINE__);
359  testFramework.assert(1 == (int)Aug21.month, "Month not set to default (1) after reset", __LINE__);
360  testFramework.assert(1 == (int)Aug21.day, "Day not set to default (1) after reset", __LINE__);
361  testFramework.assert(0 == (int)Aug21.hour, "Hour not set to default (0) after reset", __LINE__);
362  testFramework.assert(0 == (int)Aug21.minute, "Minute not set to default (0) after reset", __LINE__);
363  testFramework.assert(0 == (int)Aug21.second, "Second not set to default (0) after reset", __LINE__);
364 
365  return testFramework.countFails();
366  }
367 
368 
369 //==========================================================================================================================
370 // Test to check the TimeSystem comparisons when using the comparison operators.
371 //==========================================================================================================================
372  int timeSystemTest (void)
373  {
374  TestUtil testFramework( "CivilTime", "OperatorEquivalentWithDifferingTimeSystem", __FILE__, __LINE__ );
375 
376  CivilTime GPS1( 2008,8,21,13,30,15.,TimeSystem::GPS);
377  CivilTime GPS2( 2005,8,21,13,30,15.,TimeSystem::GPS); // Time is less than the others
378  CivilTime UTC1( 2008,8,21,13,30,15.,TimeSystem::UTC);
379  CivilTime UNKNOWN(2008,8,21,13,30,15.,TimeSystem::Unknown);
380  CivilTime ANY( 2008,8,21,13,30,15.,TimeSystem::Any);
381  CivilTime ANY2( 2005,8,21,13,30,15.,TimeSystem::Any);
382 
383  //---------------------------------------------------------------------
384  //Verify differing TimeSystem sets equivalence operator to false
385  //Note that the operator test checks for == in ALL members
386  //---------------------------------------------------------------------
387  testFramework.assert(!(GPS1 == UTC1), "Equivalence operator found objects with differing TimeSystems to be the same", __LINE__);
388  testFramework.assert(GPS1 == ANY, "Differing TimeSystems where one is TimeSystem::Any is not ignored for equals", __LINE__);
389  testFramework.assert(UTC1 == ANY, "Differing TimeSystems where one is TimeSystem::Any is not ignored for equals", __LINE__);
390  testFramework.assert(UNKNOWN == ANY, "Differing TimeSystems where one is TimeSystem::Any is not ignored for equals", __LINE__);
391 
392  testFramework.changeSourceMethod("OperatorNotEquivalentWithDifferingTimeSystem");
393  //---------------------------------------------------------------------
394  //Verify different Time System but same time inequality
395  //---------------------------------------------------------------------
396  testFramework.assert(GPS1 != UTC1, "Equivalent objects with differing TimeSystems are found to be equal", __LINE__);
397  testFramework.assert(GPS1 != UNKNOWN, "Equivalent objects with differing TimeSystems are found to be equal", __LINE__);
398  testFramework.assert(!(GPS1 != ANY), "Equivalent objects with differing TimeSystems where one is TimeSystem::Any are found to be not-equal", __LINE__);
399 
400  testFramework.changeSourceMethod("OperatorLessThanWithDifferingTimeSystem");
401  //---------------------------------------------------------------------
402  //Verify TimeSystem=ANY does not matter in other operator comparisons
403  //---------------------------------------------------------------------
404  testFramework.assert(ANY2 < GPS1, "Less than object with Any TimeSystem is not found to be less than", __LINE__);
405  testFramework.assert(GPS2 < ANY,"Less than object with GPS TimeSystem is not found to be less-than a greater object with Any TimeSystem", __LINE__);
406 
407  testFramework.changeSourceMethod("setTimeSystem");
408  UNKNOWN.setTimeSystem(TimeSystem(2)); //Set the Unknown TimeSystem
409  //---------------------------------------------------------------------
410  //Ensure resetting a Time System changes it
411  //---------------------------------------------------------------------
412  testFramework.assert(UNKNOWN.getTimeSystem()==TimeSystem(2), "setTimeSystem was unable to set the TimeSystem", __LINE__);
413 
414 
415  return testFramework.countFails();
416 
417  }
418 
419 
420 //==========================================================================================================================
421 // Test for the formatted printing of CivilTime objects
422 //==========================================================================================================================
423  int printfTest (void)
424  {
425  TestUtil testFramework( "CivilTime", "printf", __FILE__, __LINE__ );
426 
427  CivilTime GPS1(2008,8,21,13,30,15.,TimeSystem::GPS);
428  CivilTime UTC1(2008,8,21,13,30,15.,TimeSystem::UTC);
429  //---------------------------------------------------------------------
430  //Verify printed output matches expectation
431  //---------------------------------------------------------------------
432  testFramework.assert(GPS1.printf("%04Y %02y %02m %02b %02d %02H %02M %02S %02f %02P") ==
433  (std::string)"2008 08 08 Aug 21 13 30 15 15.000000 GPS", "printf did not output in the proper format", __LINE__);
434  testFramework.assert(UTC1.printf("%04Y %02y %02m %02b %02d %02H %02M %02S %02f %02P") ==
435  (std::string)"2008 08 08 Aug 21 13 30 15 15.000000 UTC", "printf did not output in the proper format", __LINE__);
436 
437 
438  testFramework.changeSourceMethod("printError");
439  //---------------------------------------------------------------------
440  //Verify printed error message matches expectation
441  //---------------------------------------------------------------------
442  testFramework.assert(GPS1.printError("%04Y %02y %02m %02b %02d %02H %02M %02S %02f %02P") ==
443  (std::string)"ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime", "printError did not output in the proper format", __LINE__);
444  testFramework.assert(UTC1.printError("%04Y %02y %02m %02b %02d %02H %02M %02S %02f %02P") ==
445  (std::string)"ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime ErrorBadTime", "printError did not output in the proper format", __LINE__);
446 
447 
448  return testFramework.countFails();
449  }
450 
451  private:
452  double eps;
453 };
454 
455 int main() //Main function to initialize and run all tests above
456 {
457  int check, errorCounter = 0;
458  CivilTime_T testClass;
459 
460  check = testClass.initializationTest();
461  errorCounter += check;
462 
463  check = testClass.operatorTest();
464  errorCounter += check;
465 
466  check = testClass.setFromInfoTest();
467  errorCounter += check;
468 
469  check = testClass.resetTest();
470  errorCounter += check;
471 
472  check = testClass.timeSystemTest();
473  errorCounter += check;
474 
475  check = testClass.toFromCommonTimeTest();
476  errorCounter += check;
477 
478  check = testClass.printfTest();
479  errorCounter += check;
480 
481  std::cout << "Total Errors: " << errorCounter << std::endl;
482 
483  return errorCounter; //Return the total number of errors
484 }
TimeSystem.hpp
gnsstk::TimeTag::setTimeSystem
void setTimeSystem(const TimeSystem &timeSys)
Set method for internal variable timeSystem (enum).
Definition: TimeTag.hpp:165
gnsstk::TestUtil::countFails
int countFails(void)
Definition: TestUtil.hpp:771
gnsstk::TestUtil::assert
void assert(bool testExpression, const std::string &testMsg, const int lineNumber)
Definition: TestUtil.hpp:607
gnsstk::CivilTime::year
int year
Definition: CivilTime.hpp:198
CivilTime_T::resetTest
int resetTest(void)
Definition: CivilTime_T.cpp:347
CivilTime_T::timeSystemTest
int timeSystemTest(void)
Definition: CivilTime_T.cpp:372
gnsstk::CivilTime::printError
virtual std::string printError(const std::string &fmt) const
Definition: CivilTime.cpp:148
gnsstk::TimeTag::IdToValue
std::map< char, std::string > IdToValue
Definition: TimeTag.hpp:103
CivilTime_T::~CivilTime_T
~CivilTime_T()
Definition: CivilTime_T.cpp:53
CivilTime_T::eps
double eps
Definition: CivilTime_T.cpp:452
gnsstk::TimeSystem::Any
@ Any
wildcard; allows comparison with any other type
gnsstk::CivilTime::day
int day
Definition: CivilTime.hpp:200
gnsstk::CommonTime::BEGINNING_OF_TIME
static const GNSSTK_EXPORT CommonTime BEGINNING_OF_TIME
earliest representable CommonTime
Definition: CommonTime.hpp:102
CivilTime_T::setFromInfoTest
int setFromInfoTest(void)
Definition: CivilTime_T.cpp:111
gnsstk::CivilTime::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: CivilTime.cpp:97
gnsstk::TimeSystem::Unknown
@ Unknown
unknown time frame; for legacy code compatibility
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::TestUtil::changeSourceMethod
void changeSourceMethod(const std::string &newMethod)
Definition: TestUtil.hpp:785
TestUtil.hpp
gnsstk::CivilTime::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: CivilTime.cpp:75
gnsstk::CivilTime::printf
virtual std::string printf(const std::string &fmt) const
Definition: CivilTime.cpp:111
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
CivilTime.hpp
CivilTime_T
Definition: CivilTime_T.cpp:49
gnsstk::CivilTime::minute
int minute
Definition: CivilTime.hpp:202
gnsstk::TimeSystem::UTC
@ UTC
Coordinated Universal Time (e.g., from NTP)
gnsstk::CivilTime::isValid
virtual bool isValid() const
Returns true if this object's members are valid, false otherwise.
Definition: CivilTime.cpp:262
main
int main()
Definition: CivilTime_T.cpp:455
CivilTime_T::toFromCommonTimeTest
int toFromCommonTimeTest(void)
Definition: CivilTime_T.cpp:304
gnsstk::CivilTime
Definition: CivilTime.hpp:55
gnsstk::CivilTime::reset
virtual void reset()
Reset this object to the default state.
Definition: CivilTime.cpp:273
gnsstk::TimeSystem::GPS
@ GPS
GPS system time.
std
Definition: Angle.hpp:142
gnsstk::CivilTime::month
int month
Definition: CivilTime.hpp:199
gnsstk::CivilTime::second
double second
Definition: CivilTime.hpp:203
CivilTime_T::operatorTest
int operatorTest(void)
Definition: CivilTime_T.cpp:182
gnsstk::CivilTime::setFromInfo
virtual bool setFromInfo(const IdToValue &info)
Definition: CivilTime.cpp:185
CivilTime_T::printfTest
int printfTest(void)
Definition: CivilTime_T.cpp:423
gnsstk::TestUtil
Definition: TestUtil.hpp:265
CivilTime_T::initializationTest
int initializationTest(void)
Definition: CivilTime_T.cpp:60
CivilTime_T::CivilTime_T
CivilTime_T()
Definition: CivilTime_T.cpp:52
gnsstk::TimeTag::getTimeSystem
TimeSystem getTimeSystem() const
Obtain time system info (enum).
Definition: TimeTag.hpp:169
gnsstk::CivilTime::hour
int hour
Definition: CivilTime.hpp:201


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