diff options
author | Alexander Blair <snipa@jagtech.io> | 2020-12-10 17:34:50 -0800 |
---|---|---|
committer | Alexander Blair <snipa@jagtech.io> | 2020-12-10 17:34:50 -0800 |
commit | 1e9483a2d585d4ce4c2bf001862132ca46185c16 (patch) | |
tree | b9a58d5cd7de6b8ed5da9df1c869449f0623611b /tests/unit_tests | |
parent | Merge pull request #7003 (diff) | |
parent | Change epee binary output from std::stringstream to byte_stream (diff) | |
download | monero-1e9483a2d585d4ce4c2bf001862132ca46185c16.tar.xz |
Merge pull request #7009
7414e2bac Change epee binary output from std::stringstream to byte_stream (Lee Clagett)
Diffstat (limited to 'tests/unit_tests')
-rw-r--r-- | tests/unit_tests/epee_levin_protocol_handler_async.cpp | 9 | ||||
-rw-r--r-- | tests/unit_tests/levin.cpp | 4 | ||||
-rw-r--r-- | tests/unit_tests/net.cpp | 30 | ||||
-rw-r--r-- | tests/unit_tests/test_protocol_pack.cpp | 4 |
4 files changed, 23 insertions, 24 deletions
diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp index 314fcf9f2..ab6791324 100644 --- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp +++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp @@ -56,13 +56,13 @@ namespace { } - virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, test_levin_connection_context& context) + virtual int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, test_levin_connection_context& context) { m_invoke_counter.inc(); boost::unique_lock<boost::mutex> lock(m_mutex); m_last_command = command; m_last_in_buf = std::string((const char*)in_buff.data(), in_buff.size()); - buff_out = m_invoke_out_buf; + buff_out = m_invoke_out_buf.clone(); return m_return_code; } @@ -102,8 +102,7 @@ namespace int return_code() const { return m_return_code; } void return_code(int v) { m_return_code = v; } - const std::string& invoke_out_buf() const { return m_invoke_out_buf; } - void invoke_out_buf(const std::string& v) { m_invoke_out_buf = v; } + void invoke_out_buf(std::string v) { m_invoke_out_buf = epee::byte_slice{std::move(v)}; } int last_command() const { return m_last_command; } const std::string& last_in_buf() const { return m_last_in_buf; } @@ -118,7 +117,7 @@ namespace boost::mutex m_mutex; int m_return_code; - std::string m_invoke_out_buf; + epee::byte_slice m_invoke_out_buf; int m_last_command; std::string m_last_in_buf; diff --git a/tests/unit_tests/levin.cpp b/tests/unit_tests/levin.cpp index 22638942d..2ad149afe 100644 --- a/tests/unit_tests/levin.cpp +++ b/tests/unit_tests/levin.cpp @@ -238,9 +238,9 @@ namespace return {connection, std::move(request)}; } - virtual int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, cryptonote::levin::detail::p2p_context& context) override final + virtual int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, cryptonote::levin::detail::p2p_context& context) override final { - buff_out.clear(); + buff_out = nullptr; invoked_.push_back( {context.m_connection_id, command, std::string{reinterpret_cast<const char*>(in_buff.data()), in_buff.size()}} ); diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp index f5aef4796..dffda5e4e 100644 --- a/tests/unit_tests/net.cpp +++ b/tests/unit_tests/net.cpp @@ -245,7 +245,7 @@ namespace TEST(tor_address, epee_serializev_v2) { - std::string buffer{}; + epee::byte_slice buffer{}; { test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v2_onion, 10))}; EXPECT_FALSE(command.tor.is_unknown()); @@ -266,7 +266,7 @@ TEST(tor_address, epee_serializev_v2) EXPECT_EQ(0u, command.tor.port()); epee::serialization::portable_storage stg{}; - EXPECT_TRUE(stg.load_from_binary(buffer)); + EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer))); EXPECT_TRUE(command.load(stg)); } EXPECT_FALSE(command.tor.is_unknown()); @@ -277,7 +277,7 @@ TEST(tor_address, epee_serializev_v2) // make sure that exceeding max buffer doesn't destroy tor_address::_load { epee::serialization::portable_storage stg{}; - stg.load_from_binary(buffer); + stg.load_from_binary(epee::to_span(buffer)); std::string host{}; ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false))); @@ -296,7 +296,7 @@ TEST(tor_address, epee_serializev_v2) TEST(tor_address, epee_serializev_v3) { - std::string buffer{}; + epee::byte_slice buffer{}; { test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v3_onion, 10))}; EXPECT_FALSE(command.tor.is_unknown()); @@ -317,7 +317,7 @@ TEST(tor_address, epee_serializev_v3) EXPECT_EQ(0u, command.tor.port()); epee::serialization::portable_storage stg{}; - EXPECT_TRUE(stg.load_from_binary(buffer)); + EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer))); EXPECT_TRUE(command.load(stg)); } EXPECT_FALSE(command.tor.is_unknown()); @@ -328,7 +328,7 @@ TEST(tor_address, epee_serializev_v3) // make sure that exceeding max buffer doesn't destroy tor_address::_load { epee::serialization::portable_storage stg{}; - stg.load_from_binary(buffer); + stg.load_from_binary(epee::to_span(buffer)); std::string host{}; ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false))); @@ -347,7 +347,7 @@ TEST(tor_address, epee_serializev_v3) TEST(tor_address, epee_serialize_unknown) { - std::string buffer{}; + epee::byte_slice buffer{}; { test_command_tor command{net::tor_address::unknown()}; EXPECT_TRUE(command.tor.is_unknown()); @@ -368,7 +368,7 @@ TEST(tor_address, epee_serialize_unknown) EXPECT_EQ(0u, command.tor.port()); epee::serialization::portable_storage stg{}; - EXPECT_TRUE(stg.load_from_binary(buffer)); + EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer))); EXPECT_TRUE(command.load(stg)); } EXPECT_TRUE(command.tor.is_unknown()); @@ -379,7 +379,7 @@ TEST(tor_address, epee_serialize_unknown) // make sure that exceeding max buffer doesn't destroy tor_address::_load { epee::serialization::portable_storage stg{}; - stg.load_from_binary(buffer); + stg.load_from_binary(epee::to_span(buffer)); std::string host{}; ASSERT_TRUE(stg.get_value("host", host, stg.open_section("tor", nullptr, false))); @@ -700,7 +700,7 @@ namespace TEST(i2p_address, epee_serializev_b32) { - std::string buffer{}; + epee::byte_slice buffer{}; { test_command_i2p command{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10))}; EXPECT_FALSE(command.i2p.is_unknown()); @@ -721,7 +721,7 @@ TEST(i2p_address, epee_serializev_b32) EXPECT_EQ(0u, command.i2p.port()); epee::serialization::portable_storage stg{}; - EXPECT_TRUE(stg.load_from_binary(buffer)); + EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer))); EXPECT_TRUE(command.load(stg)); } EXPECT_FALSE(command.i2p.is_unknown()); @@ -732,7 +732,7 @@ TEST(i2p_address, epee_serializev_b32) // make sure that exceeding max buffer doesn't destroy i2p_address::_load { epee::serialization::portable_storage stg{}; - stg.load_from_binary(buffer); + stg.load_from_binary(epee::to_span(buffer)); std::string host{}; ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false))); @@ -751,7 +751,7 @@ TEST(i2p_address, epee_serializev_b32) TEST(i2p_address, epee_serialize_unknown) { - std::string buffer{}; + epee::byte_slice buffer{}; { test_command_i2p command{net::i2p_address::unknown()}; EXPECT_TRUE(command.i2p.is_unknown()); @@ -772,7 +772,7 @@ TEST(i2p_address, epee_serialize_unknown) EXPECT_EQ(0u, command.i2p.port()); epee::serialization::portable_storage stg{}; - EXPECT_TRUE(stg.load_from_binary(buffer)); + EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer))); EXPECT_TRUE(command.load(stg)); } EXPECT_TRUE(command.i2p.is_unknown()); @@ -783,7 +783,7 @@ TEST(i2p_address, epee_serialize_unknown) // make sure that exceeding max buffer doesn't destroy i2p_address::_load { epee::serialization::portable_storage stg{}; - stg.load_from_binary(buffer); + stg.load_from_binary(epee::to_span(buffer)); std::string host{}; ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false))); diff --git a/tests/unit_tests/test_protocol_pack.cpp b/tests/unit_tests/test_protocol_pack.cpp index 312f18dfe..1a4fd30f8 100644 --- a/tests/unit_tests/test_protocol_pack.cpp +++ b/tests/unit_tests/test_protocol_pack.cpp @@ -36,7 +36,7 @@ TEST(protocol_pack, protocol_pack_command) { - std::string buff; + epee::byte_slice buff; cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request r; r.start_height = 1; r.total_height = 3; @@ -47,7 +47,7 @@ TEST(protocol_pack, protocol_pack_command) ASSERT_TRUE(res); cryptonote::NOTIFY_RESPONSE_CHAIN_ENTRY::request r2; - res = epee::serialization::load_t_from_binary(r2, buff); + res = epee::serialization::load_t_from_binary(r2, epee::to_span(buff)); ASSERT_TRUE(res); ASSERT_TRUE(r.m_block_ids.size() == i); ASSERT_TRUE(r.start_height == 1); |