Rinex3Clock_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 <iostream>
41 
42 #include "Rinex3ClockHeader.hpp"
43 #include "Rinex3ClockData.hpp"
44 #include "Rinex3ClockStream.hpp"
45 #include "RinexObsID.hpp"
46 #include "SatID.hpp"
47 
48 #include "build_config.h"
49 
51 {
52 public:
53  Rinex3Clock_T() {} // Default Constructor, set the precision value
54  ~Rinex3Clock_T() {} // Default Destructor
55 
56 
57  void init(void);
58  void toRinex3(void);
59  int headerExceptionTest(void);
60  int hardCodeTest(void);
61  int dataExceptionTest(void);
62  int filterOperatorsTest(void);
63  int rinex3HeaderFormat(void);
64 
65 private:
66  std::string dataFilePath;
67  std::string tempFilePath;
68 
69  std::string dataBadEpochLine;
70  std::string dataIncompleteHeader;
71  std::string dataInvalidLineLength;
72  std::string dataNotAClockFile;
73  std::string dataRinexClockFile;
75 
76  std::string testR3HeaderOutputExp;
77  std::string testR3HeaderOutput;
78  std::string dataTestOutput;
79 
80  std::string testMesg;
81  bool fileEqual;
82 
83 };
84 
85 // Initialize data file names
87 {
88  gnsstk::TestUtil testFramework;
89  dataFilePath = gnsstk::getPathData();
90  tempFilePath = gnsstk::getPathTestTemp();
91 
92  std::cout<<"Running tests for Rinex v.2 files"<<std::endl;
93 
94  std::string file_sep = gnsstk::getFileSep();
95 
97  "test_input_rinex2_clock_BadEpochLine.96c";
99  "test_input_rinex2_clock_IncompleteHeader.96c";
101  "test_input_rinex2_clock_InvalidLineLength.96c";
103  "test_input_rinex2_clock_NotAClockFile.96c";
105  "test_input_rinex2_clock_RinexClockExample.96c";
107  "test_input_rinex2_clock_UnknownHeaderLabel.96c";
108 
110  "test_output_rinex2_clock_TestOutput.96c";
112  "test_output_rinex3_clock_TestR3HeaderOutput.96c";
114  "test_output_rinex3_clock_TestR3HeaderOutput.exp";
115 
116 
117 }
118 
120 {
121  std::cout<<"Running tests for Rinex v.3 files"<<std::endl;
122 
123  std::string file_sep = gnsstk::getFileSep();
124 
126  "test_input_rinex3_clock_BadEpochLine.96c";
128  "test_input_rinex3_clock_IncompleteHeader.96c";
130  "test_input_rinex3_clock_InvalidLineLength.96c";
132  "test_input_rinex3_clock_NotAClockFile.96c";
134  "test_input_rinex3_clock_RinexClockExample.96c";
135 
137  "test_output_rinex3_clock_TestOutput.96c";
138 
139 }
140 
142 {
143  TUDEF("Rinex3ClockStream", "HeaderExceptions");
144 
145  std::string msg_desc = "";
146  std::string msg_expect = ", should throw gnsstk::Exception";
147  std::string msg_falsePass = " but threw no exception.";
148  std::string msg_trueFail = " but instead threw an unknown exception";
149 
150  try
151  {
152  // gnsstk::Rinex3ClockStream BadEpochLine(dataBadEpochLine.c_str());
153  gnsstk::Rinex3ClockStream IncompleteHeader(dataIncompleteHeader.c_str());
154  gnsstk::Rinex3ClockStream InvalidLineLength(dataInvalidLineLength.c_str());
155  gnsstk::Rinex3ClockStream NotAClockFile(dataNotAClockFile.c_str());
156  gnsstk::Rinex3ClockStream RinexClockFile(dataRinexClockFile.c_str());
157  gnsstk::Rinex3ClockStream UnknownHeaderLabel(dataUnknownHeaderLabel.c_str());
158 
160 
161  // BadEpochLine.exceptions(std::fstream::failbit);
162  IncompleteHeader.exceptions(std::fstream::failbit);
163  InvalidLineLength.exceptions(std::fstream::failbit);
164  NotAClockFile.exceptions(std::fstream::failbit);
165  RinexClockFile.exceptions(std::fstream::failbit);
166  UnknownHeaderLabel.exceptions(std::fstream::failbit);
167  /*
168  //---------------------------------------------------------------------
169  msg_desc = "BadEpochLine test";
170  try
171  {
172  BadEpochLine >> ch;
173  TUFAIL(msg_desc + msg_expect + msg_falsePass);
174  }
175  catch(gnsstk::Exception e)
176  {
177  TUPASS(msg_desc + msg_expect);
178  }
179  catch(...)
180  {
181  TUFAIL(msg_desc + msg_expect + msg_trueFail);
182  }
183  */
184  //--------------------------------------------------------------------
185 
186 #ifdef RINEX_3_CLOCK_ACTUALLY_IMPLEMENTED
187  msg_desc = "IncompleteHeader test";
188  try
189  {
190  IncompleteHeader >> ch; //Not valid but doesn't throw errors
191  TUFAIL(msg_desc + msg_expect + msg_falsePass);
192  }
193  catch(gnsstk::Exception e)
194  {
195  TUPASS(msg_desc + msg_expect);
196  }
197  catch(...)
198  {
199  TUFAIL(msg_desc + msg_expect + msg_trueFail);
200  }
201 #endif
202 
203  //--------------------------------------------------------------------
204 
205  msg_desc = "InvalidLineLength test";
206  try
207  {
208  InvalidLineLength >> ch;
209  TUFAIL(msg_desc + msg_expect + msg_falsePass);
210  }
211  catch(gnsstk::Exception e)
212  {
213  TUPASS(msg_desc + msg_expect);
214  }
215  catch(...)
216  {
217  TUFAIL(msg_desc + msg_expect + msg_trueFail);
218  }
219 
220  //--------------------------------------------------------------------
221 
222  msg_desc = "NotAClockFile test";
223  try
224  {
225  NotAClockFile >> ch;
226  TUFAIL(msg_desc + msg_expect + msg_falsePass);
227  }
228  catch(gnsstk::Exception e)
229  {
230  TUPASS(msg_desc + msg_expect);
231  }
232  catch(...)
233  {
234  TUFAIL(msg_desc + msg_expect + msg_trueFail);
235  }
236 
237  //--------------------------------------------------------------------
238 
239  msg_desc = "UnknownHeaderLabel test";
240  try
241  {
242  UnknownHeaderLabel >> ch;
243  TUFAIL(msg_desc + msg_expect + msg_falsePass);
244  }
245  catch(gnsstk::Exception e)
246  {
247  TUPASS(msg_desc + msg_expect);
248  }
249  catch(...)
250  {
251  TUFAIL(msg_desc + msg_expect + msg_trueFail);
252  }
253 
254 
255  }
256  catch(gnsstk::Exception e)
257  {
258  TUFAIL("Error thrown when running headerExceptionTest: "+e.what());
259  }
260  catch(...)
261  {
262  TUFAIL("Unknown error thrown when running headerExceptionTest");
263  }
264 
265  return testFramework.countFails();
266 }
267 
269 {
270  TUDEF("Rinex3ClockStream", "DataExceptions");
271 
272  std::string msg_desc = "";
273  std::string msg_expect = ", should throw gnsstk::Exception";
274  std::string msg_falsePass = " but threw no exception.";
275  std::string msg_trueFail = " but instead threw an unknown exception";
276 
277  try
278  {
279  gnsstk::Rinex3ClockStream BadEpochLine(dataBadEpochLine.c_str());
280 
282 
283  msg_desc = "BadEpochLine test";
284  try
285  {
286  while (BadEpochLine >> cd);
287  TUFAIL(msg_desc + msg_expect + msg_falsePass);
288  }
289  catch(gnsstk::Exception e)
290  {
291  TUPASS(msg_desc + msg_expect);
292  }
293  catch(...)
294  {
295  TUFAIL(msg_desc + msg_expect + msg_trueFail);
296  }
297 
298  }
299  catch(gnsstk::Exception e)
300  {
301  TUFAIL("Error thrown when running dataExceptionTest: "+e.what());
302  }
303  catch(...)
304  {
305  TUFAIL("Unknown error thrown when running dataExceptionTest");
306  }
307 
308  return testFramework.countFails();
309 }
310 
311 //Test that reading/writing out the file doesn't change it
313 {
314  TUDEF("Rinex3ClockStream", "Read & write to file");
315 
318 
319  try
320  {
321  gnsstk::Rinex3ClockStream inputStream(dataRinexClockFile.c_str());
322  TUPASS(testMesg);
323  }
324  catch (gnsstk::Exception e)
325  {
326  testMesg = "Input stream failed to open: " + e.what();
327  TUFAIL(testMesg);
328  }
329 
330  try
331  {
332  gnsstk::Rinex3ClockStream outputStream(dataTestOutput.c_str());
333  TUPASS(testMesg);
334  }
335  catch (gnsstk::Exception e)
336  {
337  testMesg = "Output stream failed to open: " + e.what();
338  TUFAIL(testMesg);
339  }
340 
341  gnsstk::Rinex3ClockStream inputStream;
342  gnsstk::Rinex3ClockStream outputStream;
343 
344  try
345  {
346  inputStream.open(dataRinexClockFile.c_str(), std::ios::in);
347  outputStream.open(dataTestOutput.c_str(), std::ios::out);
348  inputStream >> ch;
349  // ch.dump(std::cout);
350  outputStream << ch;
351  while(inputStream >> cd)
352  {
353  // cd.dump(std::cout);
354  outputStream << cd;
355  }
356 
357  TUPASS(testMesg);
358  }
359  catch (gnsstk::Exception e)
360  {
361  testMesg = "Unable to read/write to file stream: " + e.what();
362  TUFAIL(testMesg);
363  }
364 
365  fileEqual = false;
366 
367  int skipLines = 2; //First two lines of the header are not supposed to match
368 
369  fileEqual = testFramework.fileEqualTest(dataRinexClockFile,
370  dataTestOutput, skipLines);
371 
372  testMesg = "Files are not consistent after input & out";
373  testFramework.assert(fileEqual, testMesg, __LINE__);
374 
375  return testFramework.countFails();
376 }
377 
378 //Test that reading/writing out the file doesn't change it
380 {
381  TUDEF("Rinex3ClockStream", "write to R3 file");
382 
384 
385  gnsstk::Rinex3ClockStream inputStream;
386  gnsstk::Rinex3ClockStream outputStream;
387 
388  try
389  {
390  inputStream.open(testR3HeaderOutputExp.c_str(), std::ios::in);
391  outputStream.open(testR3HeaderOutput.c_str(), std::ios::out);
392  inputStream >> ch;
393  outputStream << ch;
394 
395  TUPASS(testMesg);
396  }
397  catch (gnsstk::Exception e)
398  {
399  testMesg = "Unable to read/write to file stream: " + e.what();
400  TUFAIL(testMesg);
401  }
402 
403  int skipLines = 2; //First two lines of the header are not supposed to match
404 
405  fileEqual = testFramework.fileEqualTest(testR3HeaderOutput,
406  testR3HeaderOutputExp, skipLines);
407 
408  testMesg = "Headers are not consistent after input & out";
409  testFramework.assert(fileEqual, testMesg, __LINE__);
410 
411  return testFramework.countFails();
412 }
413 
414 
415 int main(void) //Main function to initialize and run all tests above
416 {
417  Rinex3Clock_T testClass;
418  int check, errorCounter = 0;
419 
420  testClass.init();
421 
422  check = testClass.headerExceptionTest();
423  errorCounter += check;
424 
425 #ifdef RINEX_3_CLOCK_ACTUALLY_IMPLEMENTED
426  check = testClass.dataExceptionTest();
427  errorCounter += check;
428 
429  check = testClass.hardCodeTest();
430  errorCounter += check;
431 #endif
432 
433  //Run all tests for Rinex v.3 files
434  testClass.toRinex3();
435 
436  check = testClass.headerExceptionTest();
437  errorCounter += check;
438 
439  errorCounter += testClass.rinex3HeaderFormat();
440 
441 #ifdef RINEX_3_CLOCK_ACTUALLY_IMPLEMENTED
442  check = testClass.dataExceptionTest();
443  errorCounter += check;
444 
445  check = testClass.hardCodeTest();
446  errorCounter += check;
447 #endif
448 
449  std::cout << "Total Failures for " << __FILE__ << ": " << errorCounter
450  << std::endl;
451 
452  return errorCounter; //Return the total number of errors
453 }
gnsstk::Rinex3ClockStream
Definition: Rinex3ClockStream.hpp:59
Rinex3Clock_T::rinex3HeaderFormat
int rinex3HeaderFormat(void)
Definition: Rinex3Clock_T.cpp:379
Rinex3Clock_T::dataTestOutput
std::string dataTestOutput
Definition: Rinex3Clock_T.cpp:78
Rinex3Clock_T::dataInvalidLineLength
std::string dataInvalidLineLength
Definition: Rinex3Clock_T.cpp:71
gnsstk::Rinex3ClockHeader
Definition: Rinex3ClockHeader.hpp:64
Rinex3Clock_T::init
void init(void)
Definition: Rinex3Clock_T.cpp:86
TUFAIL
#define TUFAIL(MSG)
Definition: TestUtil.hpp:228
Rinex3ClockStream.hpp
Rinex3Clock_T::hardCodeTest
int hardCodeTest(void)
Definition: Rinex3Clock_T.cpp:312
gnsstk::Exception::what
std::string what() const
Dump to a string.
Definition: Exception.cpp:193
SatID.hpp
Rinex3Clock_T::testMesg
std::string testMesg
Definition: Rinex3Clock_T.cpp:80
Rinex3Clock_T::dataBadEpochLine
std::string dataBadEpochLine
Definition: Rinex3Clock_T.cpp:69
Rinex3Clock_T::headerExceptionTest
int headerExceptionTest(void)
Definition: Rinex3Clock_T.cpp:141
Rinex3Clock_T::testR3HeaderOutput
std::string testR3HeaderOutput
Definition: Rinex3Clock_T.cpp:77
gnsstk::Exception
Definition: Exception.hpp:151
Rinex3Clock_T::dataNotAClockFile
std::string dataNotAClockFile
Definition: Rinex3Clock_T.cpp:72
TestUtil.hpp
gnsstk::Rinex3ClockStream::open
virtual void open(const char *filename, std::ios::openmode mode)
Definition: Rinex3ClockStream.cpp:68
Rinex3ClockData.hpp
Rinex3Clock_T::filterOperatorsTest
int filterOperatorsTest(void)
Rinex3Clock_T::dataUnknownHeaderLabel
std::string dataUnknownHeaderLabel
Definition: Rinex3Clock_T.cpp:74
TUPASS
#define TUPASS(MSG)
Definition: TestUtil.hpp:230
Rinex3Clock_T::dataIncompleteHeader
std::string dataIncompleteHeader
Definition: Rinex3Clock_T.cpp:70
RinexObsID.hpp
Rinex3Clock_T::dataFilePath
std::string dataFilePath
Definition: Rinex3Clock_T.cpp:66
Rinex3Clock_T::dataRinexClockFile
std::string dataRinexClockFile
Definition: Rinex3Clock_T.cpp:73
Rinex3Clock_T::Rinex3Clock_T
Rinex3Clock_T()
Definition: Rinex3Clock_T.cpp:53
file_sep
string file_sep
Definition: Rinex3Obs_FromScratch_T.cpp:52
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
Rinex3ClockHeader.hpp
Rinex3Clock_T::~Rinex3Clock_T
~Rinex3Clock_T()
Definition: Rinex3Clock_T.cpp:54
Rinex3Clock_T::tempFilePath
std::string tempFilePath
Definition: Rinex3Clock_T.cpp:67
gnsstk::Rinex3ClockData
Definition: Rinex3ClockData.hpp:86
Rinex3Clock_T::dataExceptionTest
int dataExceptionTest(void)
Definition: Rinex3Clock_T.cpp:268
Rinex3Clock_T::fileEqual
bool fileEqual
Definition: Rinex3Clock_T.cpp:81
Rinex3Clock_T
Definition: Rinex3Clock_T.cpp:50
Rinex3Clock_T::testR3HeaderOutputExp
std::string testR3HeaderOutputExp
Definition: Rinex3Clock_T.cpp:76
Rinex3Clock_T::toRinex3
void toRinex3(void)
Definition: Rinex3Clock_T.cpp:119
main
int main(void)
Definition: Rinex3Clock_T.cpp:415
gnsstk::TestUtil
Definition: TestUtil.hpp:265


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