You need to sign in or sign up before continuing.
Commit c82e003e authored by Davis King's avatar Davis King
Browse files

Added serialization unit tests to cover the new format

parent 5c81b598
...@@ -402,7 +402,8 @@ namespace ...@@ -402,7 +402,8 @@ namespace
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// This function returns the contents of the file 'stuff.bin' // This function returns the contents of the file 'stuff.bin' but using the old
// floating point serialization format.
const std::string get_decoded_string() const std::string get_decoded_string()
{ {
dlib::base64::kernel_1a base64_coder; dlib::base64::kernel_1a base64_coder;
...@@ -436,6 +437,38 @@ namespace ...@@ -436,6 +437,38 @@ namespace
return sout.str(); return sout.str();
} }
// This function returns the contents of the file 'stuff.bin' but using the new
// floating point serialization format.
const std::string get_decoded_string2()
{
dlib::base64 base64_coder;
dlib::compress_stream::kernel_1ea compressor;
std::ostringstream sout;
std::istringstream sin;
// The base64 encoded data from the file 'stuff.bin' we want to decode and return.
sout << "AVaifX9zEbXa9aocsrcRuvnNqzZLptZ5mRd46xScCIfX6sq/46hG9JwIInElG50EtJKJY/+jAWit";
sout << "TpDBWrxBz124JRLsBz62h0D3Tqgnd8zygRx7t33Ybw40o07MrhzNEHgYavUukaPje5by78JIWHgk";
sout << "l7nb/TK+9ndVLrAThJ4v+GiPT3kh9H1tAAAAAQhbLa06pQjhrnjTXcRox1ZBEAV9/q1zAA==";
// Put the data into the istream sin
sin.str(sout.str());
sout.str("");
// Decode the base64 text into its compressed binary form
base64_coder.decode(sin,sout);
sin.clear();
sin.str(sout.str());
sout.str("");
// Decompress the data into its original form
compressor.decompress(sin,sout);
// Return the decoded and decompressed data
return sout.str();
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// Declare the logger we will use in this test. The name of the tester // Declare the logger we will use in this test. The name of the tester
...@@ -481,12 +514,20 @@ namespace ...@@ -481,12 +514,20 @@ namespace
sin.clear(); sin.clear();
sin.str(get_decoded_string()); sin.str(get_decoded_string());
deserialize(obj,sin);
obj.assert_in_state_1();
deserialize(obj,sin);
obj.assert_in_state_2();
sin.clear();
sin.str(get_decoded_string2());
deserialize(obj,sin); deserialize(obj,sin);
obj.assert_in_state_1(); obj.assert_in_state_1();
deserialize(obj,sin); deserialize(obj,sin);
obj.assert_in_state_2(); obj.assert_in_state_2();
/* /*
// This is the code that produced the encoded data stored in the get_decoded_string() function // This is the code that produced the encoded data stored in the get_decoded_string() function
ofstream fout("stuff.bin",ios::binary); ofstream fout("stuff.bin",ios::binary);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment