streams: Unit test for VectorReader class.
This commit is contained in:
parent
947133dec9
commit
87f2d9ee43
1 changed files with 45 additions and 0 deletions
|
@ -68,6 +68,51 @@ BOOST_AUTO_TEST_CASE(streams_vector_writer)
|
|||
vch.clear();
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(streams_vector_reader)
|
||||
{
|
||||
std::vector<unsigned char> vch = {1, 255, 3, 4, 5, 6};
|
||||
|
||||
VectorReader reader(SER_NETWORK, INIT_PROTO_VERSION, vch, 0);
|
||||
BOOST_CHECK_EQUAL(reader.size(), 6);
|
||||
BOOST_CHECK(!reader.empty());
|
||||
|
||||
// Read a single byte as an unsigned char.
|
||||
unsigned char a;
|
||||
reader >> a;
|
||||
BOOST_CHECK_EQUAL(a, 1);
|
||||
BOOST_CHECK_EQUAL(reader.size(), 5);
|
||||
BOOST_CHECK(!reader.empty());
|
||||
|
||||
// Read a single byte as a signed char.
|
||||
signed char b;
|
||||
reader >> b;
|
||||
BOOST_CHECK_EQUAL(b, -1);
|
||||
BOOST_CHECK_EQUAL(reader.size(), 4);
|
||||
BOOST_CHECK(!reader.empty());
|
||||
|
||||
// Read a 4 bytes as an unsigned int.
|
||||
unsigned int c;
|
||||
reader >> c;
|
||||
BOOST_CHECK_EQUAL(c, 100992003); // 3,4,5,6 in little-endian base-256
|
||||
BOOST_CHECK_EQUAL(reader.size(), 0);
|
||||
BOOST_CHECK(reader.empty());
|
||||
|
||||
// Reading after end of byte vector throws an error.
|
||||
signed int d;
|
||||
BOOST_CHECK_THROW(reader >> d, std::ios_base::failure);
|
||||
|
||||
// Read a 4 bytes as a signed int from the beginning of the buffer.
|
||||
reader.seek(-6);
|
||||
reader >> d;
|
||||
BOOST_CHECK_EQUAL(d, 67370753); // 1,255,3,4 in little-endian base-256
|
||||
BOOST_CHECK_EQUAL(reader.size(), 2);
|
||||
BOOST_CHECK(!reader.empty());
|
||||
|
||||
// Reading after end of byte vector throws an error even if the reader is
|
||||
// not totally empty.
|
||||
BOOST_CHECK_THROW(reader >> d, std::ios_base::failure);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(streams_serializedata_xor)
|
||||
{
|
||||
std::vector<char> in;
|
||||
|
|
Loading…
Reference in a new issue