From 76160925a621ad53f594aa3881e3be9058e3a44e Mon Sep 17 00:00:00 2001 From: Adam Crume Date: Tue, 19 Aug 2014 13:45:09 -0700 Subject: [PATCH] rbd-replay: Add unit test for Ser Signed-off-by: Adam Crume --- src/test/test_rbd_replay.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/test_rbd_replay.cc b/src/test/test_rbd_replay.cc index 4d1fe727c5f74..d05074af231b3 100644 --- a/src/test/test_rbd_replay.cc +++ b/src/test/test_rbd_replay.cc @@ -19,6 +19,7 @@ #include "rbd_replay/Deser.hpp" #include "rbd_replay/ImageNameMap.hpp" #include "rbd_replay/rbd_loc.hpp" +#include "rbd_replay/Ser.hpp" using rbd_replay::ImageNameMap; @@ -36,6 +37,23 @@ static void add_mapping(ImageNameMap *map, std::string mapping_string) { map->add_mapping(mapping); } +TEST(RBDReplay, Ser) { + std::ostringstream oss; + rbd_replay::Ser ser(oss); + ser.write_uint32_t(0x01020304u); + ser.write_string("hello"); + ser.write_bool(true); + ser.write_bool(false); + std::string s(oss.str()); + const char* data = s.data(); + size_t size = s.size(); + ASSERT_EQ(15, size); + const char expected_data[] = {1, 2, 3, 4, 0, 0, 0, 5, 'h', 'e', 'l', 'l', 'o', 1, 0}; + for (size_t i = 0; i < size; i++) { + EXPECT_EQ(expected_data[i], data[i]); + } +} + TEST(RBDReplay, Deser) { const char data[] = {1, 2, 3, 4, 0, 0, 0, 5, 'h', 'e', 'l', 'l', 'o', 1, 0}; const std::string s(data, sizeof(data)); -- 2.39.5