Permalink
Browse files

Fixed stream_reader.read. (#24)

* Patch: Fixed ``stream_reader.read``.
  • Loading branch information...
jpihl committed Oct 27, 2017
1 parent 6ba723a commit d7c11e5ed12d0f9ff2bb764465df2cd192f5ecb5
Showing with 24 additions and 3 deletions.
  1. +1 −1 NEWS.rst
  2. +1 −1 src/endian/stream_reader.hpp
  3. +22 −1 test/src/test_stream_reader.cpp
View
@@ -6,7 +6,7 @@ every change, see the Git log.
Latest
------
* tbd
* Patch: Fixed ``stream_reader.read``.
8.0.0
-----
@@ -66,7 +66,7 @@ class stream_reader : public stream
{
// Make sure there is enough data to read in the underlying buffer
assert(sizeof(ValueType) <= remaining_size());
read<sizeof(ValueType)>(value);
read_bytes<sizeof(ValueType), ValueType>(value);
}
/// Reads raw bytes from the stream to fill a buffer represented by
@@ -92,7 +92,7 @@ static void test_basic_api()
}
{
SCOPED_TRACE(testing::Message() << "peek");
SCOPED_TRACE(testing::Message() << "peek_bytes");
std::vector<uint8_t> buffer = { 1, 2 };
endian::stream_reader<EndianType> stream(buffer.data(), buffer.size());
uint8_t first_peek = 0;
@@ -112,6 +112,27 @@ static void test_basic_api()
EXPECT_EQ(third_peek, second_read);
}
{
SCOPED_TRACE(testing::Message() << "peek");
std::vector<uint8_t> buffer = { 1, 2 };
endian::stream_reader<EndianType> stream(buffer.data(), buffer.size());
uint8_t first_peek = 0;
uint8_t second_peek = 0;
uint8_t first_read = 0;
stream.peek(first_peek);
stream.peek(second_peek);
stream.read(first_read);
EXPECT_EQ(first_peek, second_peek);
EXPECT_EQ(first_peek, first_read);
uint8_t second_read = 0;
uint8_t third_peek = 0;
stream.peek(third_peek);
stream.read(second_read);
EXPECT_NE(first_peek, third_peek);
EXPECT_EQ(third_peek, second_read);
}
{
SCOPED_TRACE(testing::Message() << "offset peek");
std::vector<uint8_t> buffer = { 1, 2, 3, 4 };

0 comments on commit d7c11e5

Please sign in to comment.