2
0
mirror of https://github.com/boostorg/redis.git synced 2026-01-19 16:52:08 +00:00

Fixes SBO problem and adds some tests (#356)

This commit is contained in:
Marcelo
2025-11-20 14:38:49 +01:00
committed by GitHub
parent bdd9c327c1
commit 91afb4a279
3 changed files with 34 additions and 15 deletions

View File

@@ -81,7 +81,7 @@ void flat_tree::add_node_impl(node_view const& node)
ranges_.push_back({data_.size(), node.value.size()});
// This must come after setting the offset above.
data_.append(node.value.data(), node.value.size());
data_.insert(data_.end(), node.value.begin(), node.value.end());
view_tree_.push_back(node);
}

View File

@@ -12,7 +12,6 @@
#include <boost/redis/resp3/node.hpp>
#include <boost/redis/resp3/tree.hpp>
#include <string>
#include <vector>
namespace boost::redis {
@@ -108,7 +107,7 @@ private:
friend bool operator==(range const&, range const&);
std::string data_;
std::vector<char> data_;
view_tree view_tree_;
std::vector<range> ranges_;
std::size_t pos_ = 0u;

View File

@@ -395,10 +395,10 @@ BOOST_AUTO_TEST_CASE(flat_tree_views_are_set)
deserialize(resp3_set, adapt2(resp3), ec);
BOOST_CHECK_EQUAL(ec, error_code{});
BOOST_CHECK_EQUAL(resp2.get_reallocs(), 1u);
BOOST_CHECK_EQUAL(resp2.get_reallocs(), 4u);
BOOST_CHECK_EQUAL(resp2.get_total_msgs(), 1u);
BOOST_CHECK_EQUAL(resp3.value().get_reallocs(), 1u);
BOOST_CHECK_EQUAL(resp3.value().get_reallocs(), 4u);
BOOST_CHECK_EQUAL(resp3.value().get_total_msgs(), 1u);
auto const tmp2 = from_flat(resp2);
@@ -418,7 +418,7 @@ BOOST_AUTO_TEST_CASE(flat_tree_reuse)
deserialize(resp3_set, adapt2(tmp), ec);
BOOST_CHECK_EQUAL(ec, error_code{});
BOOST_CHECK_EQUAL(tmp.get_reallocs(), 1u);
BOOST_CHECK_EQUAL(tmp.get_reallocs(), 4u);
BOOST_CHECK_EQUAL(tmp.get_total_msgs(), 1u);
// Copy to compare after the reuse.
@@ -438,25 +438,45 @@ BOOST_AUTO_TEST_CASE(flat_tree_reuse)
BOOST_AUTO_TEST_CASE(flat_tree_copy_assign)
{
flat_tree resp;
flat_tree ref1;
flat_tree ref2;
flat_tree ref3;
flat_tree ref4;
error_code ec;
deserialize(resp3_set, adapt2(resp), ec);
deserialize(resp3_set, adapt2(ref1), ec);
deserialize(resp3_set, adapt2(ref2), ec);
deserialize(resp3_set, adapt2(ref3), ec);
deserialize(resp3_set, adapt2(ref4), ec);
BOOST_CHECK_EQUAL(ec, error_code{});
// Copy
resp3::flat_tree copy1{resp};
// Copy ctor
resp3::flat_tree copy1{ref1};
// Move ctor
resp3::flat_tree move1{std::move(ref2)};
// Copy assignment
resp3::flat_tree copy2 = resp;
resp3::flat_tree copy2 = ref1;
// Move assignment
resp3::flat_tree move2 = std::move(ref3);
// Assignment
resp3::flat_tree copy3;
copy3 = resp;
copy3 = ref1;
BOOST_TEST((copy1 == resp));
BOOST_TEST((copy2 == resp));
BOOST_TEST((copy3 == resp));
// Move assignment
resp3::flat_tree move3;
move3 = std::move(ref4);
BOOST_TEST((copy1 == ref1));
BOOST_TEST((copy2 == ref1));
BOOST_TEST((copy3 == ref1));
BOOST_TEST((move1 == ref1));
BOOST_TEST((move2 == ref1));
BOOST_TEST((move3 == ref1));
}
BOOST_AUTO_TEST_CASE(generic_flat_response_simple_error)