Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/boost/redis/impl/flat_tree.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions include/boost/redis/resp3/flat_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <boost/redis/resp3/node.hpp>
#include <boost/redis/resp3/tree.hpp>

#include <string>
#include <vector>

namespace boost::redis {
Expand Down Expand Up @@ -108,7 +107,7 @@ struct flat_tree {

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;
Expand Down
44 changes: 32 additions & 12 deletions test/test_low_level_sync_sans_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,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);
Expand All @@ -427,7 +427,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.
Expand All @@ -447,25 +447,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;

// Move assignment
resp3::flat_tree move3;
move3 = std::move(ref4);

BOOST_TEST((copy1 == ref1));
BOOST_TEST((copy2 == ref1));
BOOST_TEST((copy3 == ref1));

BOOST_TEST((copy1 == resp));
BOOST_TEST((copy2 == resp));
BOOST_TEST((copy3 == resp));
BOOST_TEST((move1 == ref1));
BOOST_TEST((move2 == ref1));
BOOST_TEST((move3 == ref1));
}

BOOST_AUTO_TEST_CASE(generic_flat_response_simple_error)
Expand Down