26 #include "boost/filesystem.hpp"
34 namespace bfs = boost::filesystem;
42 200.00018816645022000000, 0.00000000000000000000,
43 200.00043034083151000000, 0.00000000000000000000,
44 200.00067251579924000000, 0.00000000000000000000,
45 200.00091469135347000000, 0.00000000000000000000,
46 201.10647068550810000000, 0.00000000000000000000,
47 201.10671554643099000000, 0.00000000000000000000,
48 201.10696040795017000000, 0.00000000000000000000,
49 201.10720527006566000000, 0.00000000000000000000,
50 201.10745013277739000000, 908.68475341796875000000,
51 201.10769499608537000000, 1266.26928710937500000000,
52 201.10793985998967000000, 1258.11450195312500000000,
53 201.10818472449023000000, 848.79339599609375000000,
54 201.10842958958708000000, 0.00000000000000000000,
55 201.10867445528024000000, 0.00000000000000000000,
56 201.10891932156963000000, 0.0000000000000000000,
69 const char*
sampleEncoded32Big_ =
"Q0gADAAAAABDSAAcAAAAAENIACwAAAAAQ0gAPAAAAABDSRtCAAAAAENJG1IAAAAAQ0kbYgAAAABDSRtyAAAAAENJG4JEYyvTQ0kbkkSeSJ5DSRuiRJ1DqkNJG7JEVDLHQ0kbwgAAAABDSRvSAAAAAENJG+IAAAAAQ0gAAAAAAABDlgAAP4AAAEPIAABBIAAAQ/oAAELIAABEFgAARHoAAA==";
70 const char*
sampleEncoded32Little_ =
"DABIQwAAAAAcAEhDAAAAACwASEMAAAAAPABIQwAAAABCG0lDAAAAAFIbSUMAAAAAYhtJQwAAAAByG0lDAAAAAIIbSUPTK2NEkhtJQ55InkSiG0lDqkOdRLIbSUPHMlREwhtJQwAAAADSG0lDAAAAAOIbSUMAAAAAAABIQwAAAAAAAJZDAACAPwAAyEMAACBBAAD6QwAAyEIAABZEAAB6RA==";
71 const char*
sampleEncoded64Little_ =
"/xedigEAaUAAAAAAAAAAAIV5fYYDAGlAAAAAAAAAAACkK16CBQBpQAAAAAAAAAAAXy4/fgcAaUAAAAAAAAAAAK4HNjVoI2lAAAAAAAAAAACrvLg2aiNpQAAAAAAAAAAAnMM7OGwjaUAAAAAAAAAAAIIcvzluI2lAAAAAAAAAAABax0I7cCNpQAAAAGB6ZYxAJcTGPHIjaUAAAADAE8mTQOUSSz50I2lAAAAAQHWok0CYs88/diNpQAAAAOBYhopAP6ZUQXgjaUAAAAAAAAAAANvq2UJ6I2lAAAAAAAAAAABpgV9EfCNpQAAAAAAAAAAAAAAAAAAAaUAAAAAAAAAAAAAAAAAAwHJAAAAAAAAA8D8AAAAAAAB5QAAAAAAAACRAAAAAAABAf0AAAAAAAABZQAAAAAAAwIJAAAAAAABAj0A=";
72 const char*
sampleEncoded64Big_ =
"QGkAAYqdF/8AAAAAAAAAAEBpAAOGfXmFAAAAAAAAAABAaQAFgl4rpAAAAAAAAAAAQGkAB34/Ll8AAAAAAAAAAEBpI2g1NgeuAAAAAAAAAABAaSNqNri8qwAAAAAAAAAAQGkjbDg7w5wAAAAAAAAAAEBpI245vxyCAAAAAAAAAABAaSNwO0LHWkCMZXpgAAAAQGkjcjzGxCVAk8kTwAAAAEBpI3Q+SxLlQJOodUAAAABAaSN2P8+zmECKhljgAAAAQGkjeEFUpj8AAAAAAAAAAEBpI3pC2erbAAAAAAAAAABAaSN8RF+BaQAAAAAAAAAAQGkAAAAAAAAAAAAAAAAAAEBywAAAAAAAP/AAAAAAAABAeQAAAAAAAEAkAAAAAAAAQH9AAAAAAABAWQAAAAAAAECCwAAAAAAAQI9AAAAAAAA=";
73 const char*
sampleEncoded32LittleZlib_ =
"eJzjYfBwZgACGSitA6VtoLSTtCeYDoLSSVC6CEo3AenL2skuk4D0PI95LouA9CrnuS6bgPRxoxCXQ1B1l6D0IyjNADWfgWEakG6wZ2A4AaQVHBkYfgHpE04MDGIuDAxVLgB7LB3q";
74 const char*
sampleEncoded32BigZlib_ =
"eJxz9mDgYQACZw8GGSitA6VtwLSntBOUDoLSSVC6CEo3uSRrXwbSk1zmecwD0otc5jqvAtKbXEKMjgPpQ1B1l6D0I6j5YOA8jYHBvgFIn2BgcFQA0r8YGJyAbBcxIK5iYAAAfLkd6g==";
75 const char*
sampleEncoded64LittleZlib_ =
"eJz7Lz63i5Eh04EBClora9uYkfhLtOOaWJH48Xr2dexI/HXsZqYZygj+6j07zLKQ+HMOW1vkIPGbZPZb5iHxo447WRdA+AlVqT0OqkeO2RRB+AeET052eCrkbVcC4TuUrpjsMGPzefsyCP9BRFuXg/2yEMcKJPNuv7rpVIXEz2yMd6lB4kNFUfkHiqD8D/YQuhLKV4HQDvVQfiSEPtAEFe93AACmsz1+";
76 const char*
sampleEncoded64BigZlib_ =
"eJxzyGRg7Jor/p8BChwyGZjbaitbkfisTXHaS5D47HX2evEIvnKGqRn7OiR+ltmOPauR+DkW1ofnIPHzLPfLNCHxC6ydjkc59KRWJUD4RTbHjqg6TD4pfADCL7HzFnrqMHlFqQOEX2Z/fvMMh662iAcQfoVjyDJ7JPOqnG6+uo3Er3GJb8xEcj8KcCg6AKbtP0D5lVBaBUrXO0DoSCi/CaLeoR8iDgC0Qj1+";
77 const char*
sampleEncodedNumpressLinear_ =
"QS69PAAAAAAu7AEMAAAAAA9J0wgQ61LPfgY70wgQbTLPfg4d0wgQ7hLPfgMM1BgQwGKtfgvq1SgQ4UKtfgjc1SgQIyKtfgXO1SgQRAKtfgKw5SgQ78OG4QNVqQugf3Tmpg+6yRCARe2G9wiYdBGAecaFZgs+qjKwizv8oQVa5SgQS0GtfgJM5SgQjCGtfgwC5BgQApLPfgicxA4Q5MmQzQzK9+kgoDYaDQAvNdQwS+AZrAhzqAY5hKD/kA==";
78 const char*
sampleEncodedNumpressLinearZlib_ =
"eJxz1NtrwwAEem8YeUA0v+dlDoHXQefr2KyBjFyj83V8skDGO6Hzdcw8VyQEDiStreN+dVVD4KHT2jqOO0CGstLaOtZzQIYL09o6pg1PNQTeH257yBy6kntBfcmzZfy7Tgo0uL5t+84xo0SwofJYaxq33SqjDd3WfxayRgEVezsCdfkAGT2Ka+t4mJ5ICDBNOl/HMecIn8CTkxPO8pz6/lJhgZkUL4O+6RUD7weSaziKV7BZtiz4PwEAkp1KXg==";
79 const char*
sampleEncodedNumpressSlof_ =
"QMHqAAAAAAACvgAAAr4AAAK+AAACvgAANL4AADS+AAA0vgAANL4AADS+GvQ0vvr/NL6//zS+qfE0vgAANL4AADS+AAACvgAAeszWGMHW6VW73lqlQOWH9w==";
83 const char*
sampleEncodedModified64BigZlib_ =
"eJxzyGRg7Jor/r/+/X8wcMhkYG6rrWz9j+CzNsVpL6m/D+ez19nrxf+H85UzTM3Y1zFAAZCfZbZjz2okfo6F9eE5SPw8y/0yTUj8Amun41EOPalVCRB+kc2xI6oOk08KH4DwS+y8hZ46TF5R6gDhl9mf3zzDoast4gGEX+EYssweybwqp5uvbiPxa1ziGzMRfAYU4FB0AEzbf4DyK6G0CpSud4DQkVB+E0S9Qz9EHACREFv+";
87 if (expectNumpressIgnored)
93 if (config.
numpress == BinaryDataEncoder::Numpress_Linear)
96 if (config.
numpress == BinaryDataEncoder::Numpress_Pic)
99 if (config.
numpress == BinaryDataEncoder::Numpress_Slof)
102 if (config.
precision == BinaryDataEncoder::Precision_32 &&
103 config.
byteOrder == BinaryDataEncoder::ByteOrder_LittleEndian &&
104 config.
compression == BinaryDataEncoder::Compression_None)
107 if (config.
precision == BinaryDataEncoder::Precision_32 &&
108 config.
byteOrder == BinaryDataEncoder::ByteOrder_BigEndian &&
109 config.
compression == BinaryDataEncoder::Compression_None)
112 if (config.
precision == BinaryDataEncoder::Precision_64 &&
113 config.
byteOrder == BinaryDataEncoder::ByteOrder_LittleEndian &&
114 config.
compression == BinaryDataEncoder::Compression_None)
117 if (config.
precision == BinaryDataEncoder::Precision_64 &&
118 config.
byteOrder == BinaryDataEncoder::ByteOrder_BigEndian &&
119 config.
compression == BinaryDataEncoder::Compression_None)
122 if (config.
precision == BinaryDataEncoder::Precision_32 &&
123 config.
byteOrder == BinaryDataEncoder::ByteOrder_LittleEndian &&
124 config.
compression == BinaryDataEncoder::Compression_Zlib)
127 if (config.
precision == BinaryDataEncoder::Precision_32 &&
128 config.
byteOrder == BinaryDataEncoder::ByteOrder_BigEndian &&
129 config.
compression == BinaryDataEncoder::Compression_Zlib)
132 if (config.
precision == BinaryDataEncoder::Precision_64 &&
133 config.
byteOrder == BinaryDataEncoder::ByteOrder_LittleEndian &&
134 config.
compression == BinaryDataEncoder::Compression_Zlib)
137 if (config.
precision == BinaryDataEncoder::Precision_64 &&
138 config.
byteOrder == BinaryDataEncoder::ByteOrder_BigEndian &&
139 config.
compression == BinaryDataEncoder::Compression_Zlib)
142 throw runtime_error(
"[BinaryDataEncoderTest::regressionTest()] Untested configuration.");
150 *
os_ <<
"testConfiguration: " << config << endl;
158 if (checkNumpressMaxErrorSupression)
160 binary[1] = numeric_limits<double>::max( )-.1;
161 binary[3] = -binary[1];
162 binary[5] = .5*binary[1];
163 binary[7] = .5*binary[3];
168 *
os_ <<
"original: " << binary.size() << endl;
169 *
os_ << setprecision(20) << fixed;
170 copy(binary.begin(), binary.end(), ostream_iterator<double>(*
os_,
"\n"));
180 encoder.
encode(binary, encoded);
183 *
os_ <<
"encoded: " << encoded.size() << endl << encoded << endl;
192 encoder.
decode(encoded, decoded);
196 *
os_ <<
"decoded: " << decoded.
size() << endl;
197 copy(decoded.
begin(), decoded.
end(), ostream_iterator<double>(*
os_,
"\n"));
204 const double epsilon = config.
precision == BinaryDataEncoder::Precision_64 ? 1e-14 : 1e-5 ;
206 auto jt = decoded.
begin();
209 case BinaryDataEncoder::Numpress_Linear:
210 case BinaryDataEncoder::Numpress_Slof:
211 case BinaryDataEncoder::Numpress_Pic:
213 for (
auto it = binary.begin(); it!=binary.end(); ++it, ++jt)
215 if (0==*it || 0==*jt)
224 for (
auto it = binary.begin(); it!=binary.end(); ++it, ++jt)
230 if (
os_) *
os_ <<
"validated with epsilon: " << fixed << setprecision(1) << scientific <<
epsilon <<
"\n\n";
238 config.
precision = BinaryDataEncoder::Precision_32;
239 config.
byteOrder = BinaryDataEncoder::ByteOrder_LittleEndian;
242 config.
precision = BinaryDataEncoder::Precision_32;
243 config.
byteOrder = BinaryDataEncoder::ByteOrder_BigEndian;
246 config.
precision = BinaryDataEncoder::Precision_64;
247 config.
byteOrder = BinaryDataEncoder::ByteOrder_LittleEndian;
250 config.
precision = BinaryDataEncoder::Precision_64;
251 config.
byteOrder = BinaryDataEncoder::ByteOrder_BigEndian;
254 config.
precision = BinaryDataEncoder::Precision_32;
255 config.
byteOrder = BinaryDataEncoder::ByteOrder_LittleEndian;
256 config.
compression = BinaryDataEncoder::Compression_Zlib;
259 config.
precision = BinaryDataEncoder::Precision_32;
260 config.
byteOrder = BinaryDataEncoder::ByteOrder_BigEndian;
261 config.
compression = BinaryDataEncoder::Compression_Zlib;
264 config.
precision = BinaryDataEncoder::Precision_64;
265 config.
byteOrder = BinaryDataEncoder::ByteOrder_LittleEndian;
266 config.
compression = BinaryDataEncoder::Compression_Zlib;
269 config.
precision = BinaryDataEncoder::Precision_64;
270 config.
byteOrder = BinaryDataEncoder::ByteOrder_BigEndian;
271 config.
compression = BinaryDataEncoder::Compression_Zlib;
275 config.
compression = BinaryDataEncoder::Compression_None;
278 for (
int zloop=3;zloop--;)
280 config.
numpress = BinaryDataEncoder::Numpress_Linear;
283 config.
numpress = BinaryDataEncoder::Numpress_Slof;
286 config.
numpress = BinaryDataEncoder::Numpress_Pic;
289 config.
compression = BinaryDataEncoder::Compression_Zlib;
302 if (
os_) *
os_ <<
"testBadFile: " << filename << flush;
308 filesize = (size_t) bfs::file_size(filename);
312 cerr <<
"\nUnable to find file " << filename << endl;
316 if (
os_) *
os_ <<
" (" << filesize <<
" bytes)\n";
322 vector<double> data(filesize/
sizeof(
double));
323 ifstream is(filename.c_str(), ios::binary);
324 is.read((
char*)&data[0], filesize);
330 if (filename.find(
"BinaryDataEncoderTest.bad.bin")!=string::npos)
333 config.
precision = BinaryDataEncoder::Precision_32;
334 config.
byteOrder = BinaryDataEncoder::ByteOrder_LittleEndian;
335 config.
compression = BinaryDataEncoder::Compression_Zlib;
342 encoder.
encode(data, encoded);
345 encoder.
decode(encoded, decoded);
350 for (
size_t i=0; i<decoded.
size(); i++)
355 int main(
int argc,
char* argv[])
363 for (
int i=1; i<argc; i++)
365 if (!strcmp(argv[i],
"-v"))
os_ = &cout;
366 else if (bal::starts_with(argv[i],
"--"))
continue;
370 if (
os_) *
os_ <<
"BinaryDataEncoderTest\n\n";