SystemTime_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 "TestUtil.hpp"
40 #include "SystemTime.hpp"
41 #include "ANSITime.hpp"
42 #include "CommonTime.hpp"
43 #include "UnixTime.hpp"
44 #include <iostream>
45 #include <ctime>
46 
47 using namespace std;
48 using namespace gnsstk;
49 
51 {
52 public:
53  SystemTime_T(){}// Default Constructor, set the precision value
54  ~SystemTime_T() {} // Default Destructor
63  {
64  TUDEF("SystemTime", "SystemTime()");
65 
66  unsigned failcount = 0, succcount = 0;
67  // Run the test at most 5 times, or until we have more
68  // successes than failures. We do this because we sometimes
69  // get failures because the seconds of day don't always
70  // exactly match when the system time queries being compared
71  // don't happen at the exact same time.
72  while (((failcount + succcount) < 5) && (succcount <= failcount))
73  {
74  long day, day2;
75  long sod, sod2;
76  double fsod, fsod2;
77 
78  SystemTime timeFromSystemTime;
79  time_t t;
80  time(&t);
81  ANSITime timeFromctime(t);
82 
83  CommonTime commonTimeSystemTime(timeFromSystemTime);
84  CommonTime commonTimectime(timeFromctime);
85 
86  commonTimeSystemTime.get(day,sod,fsod);
87  commonTimectime.get(day2,sod2,fsod2);
88  // Was the time obtained properly?
89  if (day != day2)
90  {
91  cerr << "day mismatch" << endl;
92  failcount++;
93  }
94  else if (sod != sod2)
95  {
96  cerr << "second mismatch" << endl;
97  failcount++;
98  }
99  else if (TimeSystem::UTC != commonTimeSystemTime.getTimeSystem())
100  {
101  cerr << "time system mismatch" << endl;
102  failcount++;
103  }
104  else
105  {
106  succcount++;
107  }
108  }
109  if (failcount >= succcount)
110  {
111  TUFAIL("too many mismatches");
112  }
113  TURETURN();
114  }
115 
116 };
117 
118 
119 int main()
120 {
121  unsigned errorCounter = 0;
122  SystemTime_T testClass;
123 
124  errorCounter += testClass.obtainTimeFromSystemTest();
125 
126  std::cout << "Total Failures for " << __FILE__ << ": " << errorCounter
127  << std::endl;
128 
129  return errorCounter;
130 }
example6.day
day
Definition: example6.py:66
TUFAIL
#define TUFAIL(MSG)
Definition: TestUtil.hpp:228
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
SystemTime_T::~SystemTime_T
~SystemTime_T()
Definition: SystemTime_T.cpp:54
TestUtil.hpp
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
example4.time
time
Definition: example4.py:103
SystemTime.hpp
gnsstk::SystemTime
Definition: SystemTime.hpp:54
gnsstk::CommonTime
Definition: CommonTime.hpp:84
SystemTime_T::SystemTime_T
SystemTime_T()
Definition: SystemTime_T.cpp:53
UnixTime.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::ANSITime
Definition: ANSITime.hpp:56
example6.sod
sod
Definition: example6.py:103
gnsstk::CommonTime::getTimeSystem
TimeSystem getTimeSystem() const
Obtain time system info (enum).
Definition: CommonTime.cpp:288
CommonTime.hpp
std
Definition: Angle.hpp:142
SystemTime_T
Definition: SystemTime_T.cpp:50
SystemTime_T::obtainTimeFromSystemTest
int obtainTimeFromSystemTest()
Definition: SystemTime_T.cpp:62
main
int main()
Definition: SystemTime_T.cpp:119
ANSITime.hpp


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