RinexClock_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 "RinexClockBase.hpp"
40 #include "RinexClockData.hpp"
41 #include "RinexClockStream.hpp"
42 #include "RinexClockHeader.hpp"
43 
44 #include "build_config.h"
45 
46 #include "TestUtil.hpp"
47 #include <iostream>
48 
49 using namespace gnsstk;
50 
52 {
53 public:
54  RinexClock_T();
55 
56  void init();
57 
59  int headerExceptionTest();
67  int roundTripTest();
70  int dataExceptionTest();
71 
72  std::string dataRinexClockFile;
73  std::string dataRinexClockRef;
74  std::string dataBadEpochLine;
75  std::string dataIncompleteHeader;
76  std::string dataInvalidLineLength;
77  std::string dataNotAClockFile;
79 
80  std::string dataTestOutput;
81  std::string dataRoundTripOutput;
82 };
83 
84 
87 {
88  init();
89 }
90 
91 
92 void RinexClock_T ::
94 {
95  TestUtil test0;
96  std::string iPath = gnsstk::getPathData() + getFileSep();
97  std::string oPath = gnsstk::getPathTestTemp() + getFileSep();
98 
99  dataRinexClockFile = iPath +
100  "test_input_rinex2_clock_RinexClockExample.96c";
101  // This file is the same *content* as dataRinexClockFile, except
102  // that the formatting of numbers has been made more consistent.
103  // The example file may sometimes have leading zeroes on numbers
104  // but not always.
105  dataRinexClockRef = iPath +
106  "test_input_rinex2_clock_RinexClockReference.96c";
107  dataBadEpochLine = iPath + "test_input_rinex2_clock_BadEpochLine.96c";
108  dataIncompleteHeader = iPath +
109  "test_input_rinex2_clock_IncompleteHeader.96c";
110  dataInvalidLineLength = iPath +
111  "test_input_rinex2_clock_InvalidLineLength.96c";
112  dataNotAClockFile = iPath + "test_input_rinex2_clock_NotAClockFile.96c";
113  dataUnknownHeaderLabel = iPath +
114  "test_input_rinex2_clock_UnknownHeaderLabel.96c";
115 
116  dataTestOutput = oPath + "test_output_rinex_clock_TestOutput.96o";
117  dataRoundTripOutput = oPath + "test_output_rinex_clock_RoundTripOutput.96o";
118 }
119 
120 
121  /* What the hell are we doing here?
122  *
123  * 1) Doing permissive reads of error-ridden RINEX OBS headers,
124  * i.e. allowing the headers to be read into memory despite errors.
125  * This is done by leaving the default behavior of streams that no
126  * exceptions are thrown on error conditions.
127  *
128  * 2) Doing strict writes of same error-ridden headers and verifying
129  * that exceptions are being thrown as expected.
130  */
131 int RinexClock_T ::
133 {
134  TUDEF( "RinexClockStream", "operator<<" );
135 
136  try
137  {
139  rinexClockFile( dataRinexClockFile.c_str() ),
140  ih( dataIncompleteHeader.c_str() ),
141  il( dataInvalidLineLength.c_str() ),
142  no( dataNotAClockFile.c_str() ),
143  uh( dataUnknownHeaderLabel.c_str() ),
144  out( dataTestOutput.c_str(), std::ios::out );
146  rinexClockHeader,
147  ihh,
148  ilh,
149  noh,
150  uhh;
151  gnsstk::RinexClockData rinexClockData;
152 
153  // read in some good and some bad headers
154  rinexClockFile >> rinexClockHeader;
155  ih >> ihh;
156  il >> ilh;
157  no >> noh;
158  uh >> uhh;
159 
160  out.exceptions( std::fstream::failbit );
161  // write good and bad headers, checking for exceptions
162  try
163  {
164  out << rinexClockHeader;
165  TUPASS("exception");
166  }
167  catch (...)
168  {
169  TUFAIL("Exception while writing valid RINEX clock header");
170  }
171  out.clear();
172  try
173  {
174  out << ihh;
175  TUFAIL("No Exception while writing invalid RINEX clock header");
176  }
177  catch (...)
178  {
179  TUPASS("exception");
180  }
181  out.clear();
182  try
183  {
184  out << ilh;
185  TUFAIL("No Exception while writing invalid RINEX clock header");
186  }
187  catch (...)
188  {
189  TUPASS("exception");
190  }
191  out.clear();
192  try
193  {
194  out << noh;
195  TUFAIL("No Exception while writing invalid RINEX clock header");
196  }
197  catch (...)
198  {
199  TUPASS("exception");
200  }
201  out.clear();
202  try
203  {
204  // The error in this header will not have made it into the
205  // data structure, being an invalid header line, thus
206  // output is expected to succeed in this case.
207  out << uhh;
208  TUPASS("exception");
209  }
210  catch (...)
211  {
212  TUFAIL("Exception while writing valid(ish) RINEX clock header");
213  }
214  out.clear();
215  while( rinexClockFile >> rinexClockData )
216  {
217  out << rinexClockData;
218  }
219  }
220  catch (...)
221  {
222  TUFAIL("Unanticipated exception caught");
223  }
224 
225  return testFramework.countFails();
226 }
227 
228 
229 int RinexClock_T ::
231 {
232  TUDEF( "RinexClockData", "operator>>" );
233  int numLinesSkip = 0;
234  try
235  {
237  rinexClockFile( dataRinexClockFile.c_str() ),
238  out( dataRoundTripOutput.c_str(), std::ios::out );
239  gnsstk::RinexClockHeader rinexClockHeader;
240  gnsstk::RinexClockData rinexClockData;
241 
242  rinexClockFile.exceptions(std::fstream::failbit);
243  out.exceptions(std::fstream::failbit);
244 
245  rinexClockFile >> rinexClockHeader;
246  out << rinexClockHeader;
247 
248  while (rinexClockFile >> rinexClockData)
249  {
250  out << rinexClockData;
251  }
252  rinexClockFile.close();
253  out.close();
254 
255  testFramework.assert_files_equal(
256  __LINE__, dataRinexClockRef, dataRoundTripOutput,
257  "files do not match: " + dataRinexClockRef + " " + dataRoundTripOutput,
258  numLinesSkip, false, true );
259  }
260  catch (...)
261  {
262  TUFAIL("Caught unanticipated exception");
263  }
264 
265  return testFramework.countFails();
266 }
267 
268 
270 {
271  TUDEF("RinexClockStream", "DataExceptions");
272 
273  std::string msg_desc = "";
274  std::string msg_expect = ", should throw gnsstk::Exception";
275  std::string msg_falsePass = " but threw no exception.";
276  std::string msg_trueFail = " but instead threw an unknown exception";
277 
278  try
279  {
280  gnsstk::RinexClockStream badEpochLine(dataBadEpochLine.c_str());
281  badEpochLine.exceptions(std::fstream::failbit);
283 
284  msg_desc = "BadEpochLine test";
285  try
286  {
287  while (badEpochLine >> cd);
288  TUFAIL(msg_desc + msg_expect + msg_falsePass);
289  }
290  catch(gnsstk::Exception e)
291  {
292  TUPASS(msg_desc + msg_expect);
293  }
294  catch(...)
295  {
296  TUFAIL(msg_desc + msg_expect + msg_trueFail);
297  }
298 
299  }
300  catch(gnsstk::Exception e)
301  {
302  TUFAIL("Error thrown when running dataExceptionTest: "+e.what());
303  }
304  catch(...)
305  {
306  TUFAIL("Unknown error thrown when running dataExceptionTest");
307  }
308 
309  return testFramework.countFails();
310 }
311 
312 
313 int main() //Main function to initialize and run all tests above
314 {
315  RinexClock_T testClass;
316  int errorTotal = 0;
317 
318  errorTotal += testClass.headerExceptionTest();
319  errorTotal += testClass.roundTripTest();
320  errorTotal += testClass.dataExceptionTest();
321 
322  std::cout << "Total Failures for " << __FILE__ << ": " << errorTotal
323  << std::endl;
324 
325  return errorTotal; //Return the total number of errors
326 }
RinexClockHeader.hpp
main
int main()
Definition: RinexClock_T.cpp:313
RinexClock_T::roundTripTest
int roundTripTest()
Definition: RinexClock_T.cpp:230
RinexClockData.hpp
TUFAIL
#define TUFAIL(MSG)
Definition: TestUtil.hpp:228
gnsstk::Exception::what
std::string what() const
Dump to a string.
Definition: Exception.cpp:193
RinexClockStream.hpp
gnsstk::RinexClockData
Definition: RinexClockData.hpp:62
RinexClockBase.hpp
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
RinexClock_T::dataRinexClockFile
std::string dataRinexClockFile
Definition: RinexClock_T.cpp:72
gnsstk::Exception
Definition: Exception.hpp:151
RinexClock_T::dataIncompleteHeader
std::string dataIncompleteHeader
Definition: RinexClock_T.cpp:75
RinexClock_T::init
void init()
Definition: RinexClock_T.cpp:93
TestUtil.hpp
TUPASS
#define TUPASS(MSG)
Definition: TestUtil.hpp:230
RinexClock_T::dataRinexClockRef
std::string dataRinexClockRef
Definition: RinexClock_T.cpp:73
RinexClock_T::dataBadEpochLine
std::string dataBadEpochLine
Definition: RinexClock_T.cpp:74
RinexClock_T::dataInvalidLineLength
std::string dataInvalidLineLength
Definition: RinexClock_T.cpp:76
gnsstk::RinexClockHeader
Definition: RinexClockHeader.hpp:61
RinexClock_T::dataExceptionTest
int dataExceptionTest()
Definition: RinexClock_T.cpp:269
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
RinexClock_T::dataUnknownHeaderLabel
std::string dataUnknownHeaderLabel
Definition: RinexClock_T.cpp:78
RinexClock_T::RinexClock_T
RinexClock_T()
Definition: RinexClock_T.cpp:86
RinexClock_T::dataRoundTripOutput
std::string dataRoundTripOutput
Definition: RinexClock_T.cpp:81
RinexClock_T::headerExceptionTest
int headerExceptionTest()
Check that exceptions are thrown/not thrown for invalid/valid headers.
Definition: RinexClock_T.cpp:132
gnsstk::RinexClockStream
Definition: RinexClockStream.hpp:62
RinexClock_T::dataTestOutput
std::string dataTestOutput
Definition: RinexClock_T.cpp:80
gnsstk::TestUtil
Definition: TestUtil.hpp:265
RinexClock_T
Definition: RinexClock_T.cpp:51
RinexClock_T::dataNotAClockFile
std::string dataNotAClockFile
Definition: RinexClock_T.cpp:77


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