mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-29 22:33:28 +01:00
Merge pull request #6769
b641e0a2c
Add clear method to byte_stream (Lee Clagett)
This commit is contained in:
commit
44cd8a13ec
@ -117,6 +117,9 @@ namespace epee
|
|||||||
check(more);
|
check(more);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Reset write position, but do not release internal memory. \post `size() == 0`.
|
||||||
|
void clear() noexcept { next_write_ = buffer_.get(); }
|
||||||
|
|
||||||
/*! Copy `length` bytes starting at `ptr` to end of stream.
|
/*! Copy `length` bytes starting at `ptr` to end of stream.
|
||||||
\throw std::range_error If exceeding max size_t value.
|
\throw std::range_error If exceeding max size_t value.
|
||||||
\throw std::bad_alloc If allocation fails. */
|
\throw std::bad_alloc If allocation fails. */
|
||||||
|
@ -1117,6 +1117,47 @@ TEST(ByteStream, ToByteSlice)
|
|||||||
EXPECT_EQ(nullptr, empty_slice.data());
|
EXPECT_EQ(nullptr, empty_slice.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ByteStream, Clear)
|
||||||
|
{
|
||||||
|
static constexpr const std::uint8_t source[] =
|
||||||
|
{0xde, 0xad, 0xbe, 0xef, 0xef};
|
||||||
|
|
||||||
|
epee::byte_stream stream{4};
|
||||||
|
|
||||||
|
EXPECT_EQ(4u, stream.increase_size());
|
||||||
|
|
||||||
|
EXPECT_EQ(nullptr, stream.data());
|
||||||
|
EXPECT_EQ(nullptr, stream.tellp());
|
||||||
|
EXPECT_EQ(0u, stream.size());
|
||||||
|
EXPECT_EQ(0u, stream.available());
|
||||||
|
EXPECT_EQ(0u, stream.capacity());
|
||||||
|
|
||||||
|
stream.clear();
|
||||||
|
|
||||||
|
EXPECT_EQ(nullptr, stream.data());
|
||||||
|
EXPECT_EQ(nullptr, stream.tellp());
|
||||||
|
EXPECT_EQ(0u, stream.size());
|
||||||
|
EXPECT_EQ(0u, stream.available());
|
||||||
|
EXPECT_EQ(0u, stream.capacity());
|
||||||
|
|
||||||
|
stream.write({source, 3});
|
||||||
|
std::uint8_t const* const loc = stream.data();
|
||||||
|
|
||||||
|
EXPECT_EQ(loc, stream.data());
|
||||||
|
EXPECT_EQ(loc + 3, stream.tellp());
|
||||||
|
EXPECT_EQ(3u, stream.size());
|
||||||
|
EXPECT_EQ(1u, stream.available());
|
||||||
|
EXPECT_EQ(4u, stream.capacity());
|
||||||
|
|
||||||
|
stream.clear();
|
||||||
|
|
||||||
|
EXPECT_EQ(loc, stream.data());
|
||||||
|
EXPECT_EQ(loc, stream.tellp());
|
||||||
|
EXPECT_EQ(0u, stream.size());
|
||||||
|
EXPECT_EQ(4u, stream.available());
|
||||||
|
EXPECT_EQ(4u, stream.capacity());
|
||||||
|
}
|
||||||
|
|
||||||
TEST(ToHex, String)
|
TEST(ToHex, String)
|
||||||
{
|
{
|
||||||
EXPECT_TRUE(epee::to_hex::string(nullptr).empty());
|
EXPECT_TRUE(epee::to_hex::string(nullptr).empty());
|
||||||
|
Loading…
Reference in New Issue
Block a user