59 gnsstk::TestUtil tester(
"SP3Data",
"Read/Write (" + inFile +
")", __FILE__, __LINE__ );
62 std::string dataFileName =
dataFilePath + gnsstk::getFileSep() +
63 "test_input_" + inFile +
".sp3";
66 tester.
assert( inStream.good(),
"error creating input stream", __LINE__ );
68 inStream.exceptions(std::ios_base::failbit);
73 inStream >> inStream.
header;
74 tester.
assert(
true,
"header read successfully", __LINE__ );
78 std::ostringstream oss;
79 oss <<
"stream exception reading header: " << e;
80 tester.
assert(
false, oss.str(), __LINE__ );
84 tester.
assert(
false,
"unknown exception reading header", __LINE__ );
88 std::vector<gnsstk::SP3Data>
data;
89 while (inStream.good() && (EOF != inStream.peek() ) )
95 data.push_back(record);
99 std::ostringstream oss;
100 oss <<
"stream exception reading record: " << e;
101 tester.
assert(
false, oss.str(), __LINE__ );
105 tester.
assert(
false,
"unknown exception reading record", __LINE__ );
111 std::string tempFileName =
tempFilePath + gnsstk::getFileSep() +
112 "test_output_" + inFile +
"_tmp.sp3";
115 tester.
assert( outStream.good(),
"error creating ouput stream", __LINE__ );
117 outStream.exceptions(std::ios_base::failbit | std::ios_base::badbit);
123 outStream << outStream.
header;
124 tester.
assert(
true,
"header written successfully", __LINE__ );
128 std::ostringstream oss;
129 oss <<
"stream exception writing header: " << e;
130 tester.
assert(
false, oss.str(), __LINE__ );
134 tester.
assert(
false,
"unknown exception writing header", __LINE__ );
138 std::vector<gnsstk::SP3Data>::iterator recordIter =
data.begin();
139 for ( ; recordIter !=
data.end(); ++recordIter)
143 outStream << *recordIter;
144 tester.
assert(
true,
"put record", __LINE__ );
148 std::ostringstream oss;
149 oss <<
"exception writing record: " << e;
150 tester.
assert(
false, oss.str(), __LINE__ );
154 tester.
assert(
false,
"unknown exception writing record", __LINE__ );
161 std::ostringstream diffoss;
162 diffoss <<
"files '" << dataFileName <<
"' and '" << tempFileName
163 <<
"' should be equal but differ on"
164 <<
" line " << (diff >> 8)
165 <<
" column " << ((diff & 0xFF) + 1);
166 tester.
assert( (0 == diff), diffoss.str(), __LINE__ );
186 const std::string& checkFile )
188 std::ifstream refStream;
189 std::ifstream checkStream;
191 std::string checkLine;
194 refStream.open( refFile.c_str() );
195 checkStream.open( checkFile.c_str() );
198 while ( !refStream.eof() )
204 if ( checkStream.eof() )
206 return (lineNumber << 8);
210 getline( refStream, refLine );
211 getline( checkStream, checkLine );
214 std::size_t idx = refLine.find_last_not_of(
" \t\r\n\f\v");
215 if (idx != std::string::npos)
216 refLine.erase(idx+1);
219 idx = checkLine.find_last_not_of(
" \t\r\n\f\v");
220 if (idx != std::string::npos)
221 checkLine.erase(idx+1);
226 if (refLine.size() != checkLine.size())
228 return (lineNumber << 8);
232 int lastPos = refLine.size() - 1;
235 std::ostringstream oss;
236 oss <<
"Line " << lineNumber <<
" in the reference file exceeeds "
237 <<
"the maximum valid SP3 line length (80)";
243 if (refLine[
pos] != checkLine[
pos])
245 if (
pos >= lastPos - 1)
247 return (lineNumber << 8) +
pos;
251 switch (refLine[
pos])
254 if ((
'-' == refLine[
pos + 1]) && (
'.' == refLine[
pos + 2]))
256 if ((
'-' == checkLine[
pos]) && (
'0' == checkLine[
pos + 1]))
262 else if (
'.' == refLine[
pos + 1])
264 if (
'0' == checkLine[
pos])
272 if ((
' ' == checkLine[
pos]) && (
'0' == refLine[
pos + 1]) && (
'.' == refLine[
pos + 2]))
279 if ((
' ' == checkLine[
pos]) && (
'.' == refLine[
pos + 1]))
287 return (lineNumber << 8) +
pos;
294 return ( checkStream.eof() ? 0 : (lineNumber << 8) );
328 std::cerr <<
"unexpected exception executing tests: " << e;
330 catch (std::exception& e)
333 std::cerr <<
"unexpected exception executing tests: " << e.
what();
338 std::cerr <<
"unexpected exception executing tests";
340 return( errorTotal );