50 std::ios::openmode mode=std::ios::in|std::ios::binary)
63 std::ios::openmode mode=std::ios::in|std::ios::binary)
86 template <
class StreamType>
87 void testStream(
const std::string& outfn,
const std::string& reffn,
106 string dp = gnsstk::getPathData() + gnsstk::getFileSep();
107 string op = gnsstk::getPathTestTemp() + gnsstk::getFileSep();
112 beFile = op +
"test_output_FFBinaryStream_BE.dat";
113 leFile = op +
"test_output_FFBinaryStream_LE.dat";
114 beRef = dp +
"test_output_FFBinaryStream_BE.exp";
115 leRef = dp +
"test_output_FFBinaryStream_LE.exp";
122 TUDEF(
"FFBinaryStream",
"writeData");
123 testFramework.changeSourceMethod(
"getData/writeData (little-endian)");
124 testStream<FFBinaryStreamLE>(leFile, leRef, testFramework);
125 testFramework.changeSourceMethod(
"getData/writeData (big-endian)");
126 testStream<FFBinaryStreamBE>(beFile, beRef, testFramework);
127 return testFramework.countFails();
131 template <
class StreamType>
133 testStream(
const std::string& outfn,
const std::string& reffn,
136 StreamType testStrm(outfn.c_str(), ios::out);
137 static const uint8_t uint8Arr[] = {
'H',
'e',
'l',
'l',
'o',
',',
' ',
'W',
138 'o',
'r',
'l',
'd',
'!' };
140 static const uint16_t uint16Arr[] = { 0xffff, 0x0000, 0xdead, 0xbeef,
142 static const uint32_t uint32Arr[] = { 0, 2147483647, 4294967295, 6456568 };
143 static const uint64_t uint64Arr[] = { 0, 9223372036854775807,
144 18446744073709551615lu, 2904954569522 };
146 static const int8_t int8Arr[] = { 0, 127, -127, -1 };
147 static const int16_t int16Arr[] = { 0, -1, -32767, 32767, 98, -1553 };
148 static const int32_t int32Arr[] = { 0, -1, -2147483647, 2147483647, -123456,
150 static const int64_t int64Arr[] = { 0, -1, -9223372036854775807,
151 9223372036854775807, 104993356393,
156 static const float fltArr[] = { 4.918649210594594E-4 };
160 static const double dblArr[] = { 3.5127005640885040e-303,
161 2.4573306210644260e-12 };
163 static const streampos fileSize =
194 streampos expectedPos = 0;
195 for (i = 0; i <
sizeof(uint8Arr); i++)
197 testStrm.writeData(uint8Arr[i]);
199 TUASSERTE(streampos, expectedPos, testStrm.tellg());
202 for (i = 0; i < (
sizeof(uint16Arr) >> 1); i++)
204 testStrm.writeData(uint16Arr[i]);
206 TUASSERTE(streampos, expectedPos, testStrm.tellg());
208 for (i = 0; i < (
sizeof(uint32Arr) >> 2); i++)
210 testStrm.writeData(uint32Arr[i]);
212 TUASSERTE(streampos, expectedPos, testStrm.tellg());
214 for (i = 0; i < (
sizeof(uint64Arr) >> 3); i++)
216 testStrm.writeData(uint64Arr[i]);
218 TUASSERTE(streampos, expectedPos, testStrm.tellg());
222 for (i = 0; i <
sizeof(int8Arr); i++)
224 testStrm.writeData(int8Arr[i]);
226 TUASSERTE(streampos, expectedPos, testStrm.tellg());
228 for (i = 0; i < (
sizeof(int16Arr) >> 1); i++)
230 testStrm.writeData(int16Arr[i]);
232 TUASSERTE(streampos, expectedPos, testStrm.tellg());
234 for (i = 0; i < (
sizeof(int32Arr) >> 2); i++)
236 testStrm.writeData(int32Arr[i]);
238 TUASSERTE(streampos, expectedPos, testStrm.tellg());
240 for (i = 0; i < (
sizeof(int64Arr) >> 3); i++)
242 testStrm.writeData(int64Arr[i]);
244 TUASSERTE(streampos, expectedPos, testStrm.tellg());
246 for (i = 0; i < (
sizeof(fltArr) >> 2); i++)
248 testStrm.writeData(fltArr[i]);
250 TUASSERTE(streampos, expectedPos, testStrm.tellg());
252 for (i = 0; i < (
sizeof(dblArr) >> 3); i++)
254 testStrm.writeData(dblArr[i]);
256 TUASSERTE(streampos, expectedPos, testStrm.tellg());
265 StreamType testStrmIn(outfn.c_str(), ios::in);
268 testFramework.
assert(
bool(testStrmIn),
"Couldn't open " + outfn +
" for input", __LINE__);
270 testFramework.
assert(
static_cast<bool>(testStrmIn),
"Couldn't open " + outfn +
" for input", __LINE__);
274 testStrmIn.seekg(0, testStrmIn.end);
275 TUASSERTE(streampos, fileSize, testStrmIn.tellg());
276 testStrmIn.seekg(0, testStrmIn.beg);
279 for (i = 0; i <
sizeof(uint8Arr); i++)
281 testStrmIn.getData(tu8);
285 for (i = 0; i < (
sizeof(uint16Arr) >> 1); i++)
287 testStrmIn.getData(tu16);
290 for (i = 0; i < (
sizeof(uint32Arr) >> 2); i++)
292 testStrmIn.getData(tu32);
295 for (i = 0; i < (
sizeof(uint64Arr) >> 3); i++)
297 testStrmIn.getData(tu64);
302 for (i = 0; i <
sizeof(int8Arr); i++)
304 testStrmIn.getData(ts8);
307 for (i = 0; i < (
sizeof(int16Arr) >> 1); i++)
309 testStrmIn.getData(ts16);
312 for (i = 0; i < (
sizeof(int32Arr) >> 2); i++)
314 testStrmIn.getData(ts32);
317 for (i = 0; i < (
sizeof(int64Arr) >> 3); i++)
319 testStrmIn.getData(ts64);
322 for (i = 0; i < (
sizeof(fltArr) >> 2); i++)
324 testStrmIn.getData(tf);
327 for (i = 0; i < (
sizeof(dblArr) >> 3); i++)
329 testStrmIn.getData(td);
336 (__LINE__, reffn, outfn,
"Encoded output file does not match reference");
344 int main(
int argc,
char *argv[])
352 cout <<
"Total Failures for " << __FILE__ <<
": " << errorTotal << endl;
354 return( errorTotal );