diff options
author | luigi1111 <luigi1111w@gmail.com> | 2020-07-08 17:07:50 -0500 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2020-07-08 17:07:50 -0500 |
commit | 35e2520115835463c55840912d2dc0f89e32ab97 (patch) | |
tree | 7ac452c205e9fcd43fdfff9be1622cc6da308a2b /tests/unit_tests | |
parent | Merge pull request #6550 (diff) | |
parent | ByteSlice: Fix persisting ptr to std::moved SSO buffer (diff) | |
download | monero-35e2520115835463c55840912d2dc0f89e32ab97.tar.xz |
Merge pull request #6559
15538f7 ByteSlice: Fix persisting ptr to std::moved SSO buffer (Doy-lee)
Diffstat (limited to 'tests/unit_tests')
-rw-r--r-- | tests/unit_tests/epee_utils.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp index a2cec965e..0f91671a7 100644 --- a/tests/unit_tests/epee_utils.cpp +++ b/tests/unit_tests/epee_utils.cpp @@ -387,6 +387,29 @@ TEST(ByteSlice, Construction) EXPECT_FALSE(std::is_copy_assignable<epee::byte_slice>()); } +TEST(ByteSlice, DataReturnedMatches) +{ + for (int i = 64; i > 0; i--) + { + std::string sso_string(i, 'a'); + std::string original = sso_string; + epee::byte_slice slice{std::move(sso_string)}; + + EXPECT_EQ(slice.size(), original.size()); + EXPECT_EQ(memcmp(slice.data(), original.data(), original.size()), 0); + } + + for (int i = 64; i > 0; i--) + { + std::vector<uint8_t> sso_vector(i, 'a'); + std::vector<uint8_t> original = sso_vector; + epee::byte_slice slice{std::move(sso_vector)}; + + EXPECT_EQ(slice.size(), original.size()); + EXPECT_EQ(memcmp(slice.data(), original.data(), original.size()), 0); + } +} + TEST(ByteSlice, NoExcept) { EXPECT_TRUE(std::is_nothrow_default_constructible<epee::byte_slice>()); |