aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlexander Blair <snipa@jagtech.io>2020-08-27 12:05:15 -0700
committerAlexander Blair <snipa@jagtech.io>2020-08-27 12:05:16 -0700
commit44cd8a13ec85288aafd86f24a36ec53ac7cd9efa (patch)
treed8ee8db2339c7542cfbf1679c5ea4e7d68979797 /tests
parentMerge pull request #6739 (diff)
parentAdd clear method to byte_stream (diff)
downloadmonero-44cd8a13ec85288aafd86f24a36ec53ac7cd9efa.tar.xz
Merge pull request #6769
b641e0a2c Add clear method to byte_stream (Lee Clagett)
Diffstat (limited to 'tests')
-rw-r--r--tests/unit_tests/epee_utils.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index 0f91671a7..b365cad86 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -1117,6 +1117,47 @@ TEST(ByteStream, ToByteSlice)
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)
{
EXPECT_TRUE(epee::to_hex::string(nullptr).empty());