Add buffer reader/writer for per-element serialization

This commit is contained in:
Patrick Niklaus
2018-03-19 17:38:41 +00:00
parent d4300e73f3
commit 4f454a3761
3 changed files with 129 additions and 0 deletions
+21
View File
@@ -20,6 +20,8 @@ const static std::string IO_INCOMPATIBLE_FINGERPRINT_FILE =
"incompatible_fingerprint_file_test_io.tmp";
const static std::string IO_TEXT_FILE = "plain_text_file.tmp";
using namespace osrm;
BOOST_AUTO_TEST_SUITE(osrm_io)
BOOST_AUTO_TEST_CASE(io_data)
@@ -41,6 +43,25 @@ BOOST_AUTO_TEST_CASE(io_data)
BOOST_CHECK_EQUAL_COLLECTIONS(data_out.begin(), data_out.end(), data_in.begin(), data_in.end());
}
BOOST_AUTO_TEST_CASE(io_buffered_data)
{
std::vector<int> data_in(53), data_out;
std::iota(begin(data_in), end(data_in), 0);
std::string result;
{
storage::io::BufferWriter writer;
storage::serialization::write(writer, data_in);
result = writer.GetBuffer();
}
storage::io::BufferReader reader(result);
storage::serialization::read(reader, data_out);
BOOST_REQUIRE_EQUAL(data_in.size(), data_out.size());
BOOST_CHECK_EQUAL_COLLECTIONS(data_out.begin(), data_out.end(), data_in.begin(), data_in.end());
}
BOOST_AUTO_TEST_CASE(io_nonexistent_file)
{
try