tests: add test for managed_vector
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
This commit is contained in:
@@ -152,6 +152,7 @@ urchin_tests = [
|
||||
'tests/murmur_hash_test',
|
||||
'tests/allocation_strategy_test',
|
||||
'tests/logalloc_test',
|
||||
'tests/managed_vector_test',
|
||||
'tests/crc_test',
|
||||
]
|
||||
|
||||
@@ -401,7 +402,7 @@ deps = {
|
||||
|
||||
for t in urchin_tests:
|
||||
deps[t] = urchin_tests_dependencies + [t + '.cc']
|
||||
if 'types_test' not in t and 'keys_test' not in t and 'partitioner_test' not in t and 'map_difference_test' not in t and 'frozen_mutation_test' not in t and 'perf_mutation' not in t and 'cartesian_product_test' not in t and 'perf_hash' not in t and 'perf_cql_parser' not in t and 'message' not in t and 'perf_simple_query' not in t and 'serialization' not in t and t != 'tests/gossip' and 'compound_test' not in t and 'range_test' not in t and 'crc_test' not in t and 'perf_sstable' not in t:
|
||||
if 'types_test' not in t and 'keys_test' not in t and 'partitioner_test' not in t and 'map_difference_test' not in t and 'frozen_mutation_test' not in t and 'perf_mutation' not in t and 'cartesian_product_test' not in t and 'perf_hash' not in t and 'perf_cql_parser' not in t and 'message' not in t and 'perf_simple_query' not in t and 'serialization' not in t and t != 'tests/gossip' and 'compound_test' not in t and 'range_test' not in t and 'crc_test' not in t and 'perf_sstable' not in t and 'managed_vector_test' not in t:
|
||||
deps[t] += urchin_tests_seastar_deps
|
||||
|
||||
deps['tests/sstable_test'] += ['tests/sstable_datafile_test.cc']
|
||||
|
||||
142
tests/managed_vector_test.cc
Normal file
142
tests/managed_vector_test.cc
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright 2015 Cloudius Systems
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE core
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include "utils/managed_vector.hh"
|
||||
#include "utils/logalloc.hh"
|
||||
|
||||
static constexpr unsigned count = 125;
|
||||
|
||||
template<typename Vector>
|
||||
void fill(Vector& vec) {
|
||||
BOOST_CHECK(vec.empty());
|
||||
for (unsigned i = 0; i < count; i++) {
|
||||
vec.emplace_back(i);
|
||||
}
|
||||
BOOST_CHECK(!vec.empty());
|
||||
BOOST_CHECK_EQUAL(vec.size(), count);
|
||||
BOOST_CHECK_GE(vec.capacity(), vec.size());
|
||||
}
|
||||
|
||||
template<typename Vector>
|
||||
void verify_filled(const Vector& vec) {
|
||||
unsigned idx = 0;
|
||||
for (auto&& v : vec) {
|
||||
BOOST_CHECK_EQUAL(v, idx);
|
||||
BOOST_CHECK_EQUAL(vec[idx], idx);
|
||||
idx++;
|
||||
}
|
||||
BOOST_CHECK_EQUAL(idx, count);
|
||||
}
|
||||
|
||||
template<typename Vector>
|
||||
void verify_empty(const Vector& vec) {
|
||||
BOOST_CHECK_EQUAL(vec.size(), 0);
|
||||
BOOST_CHECK(vec.empty());
|
||||
for (auto&& v : vec) {
|
||||
(void)v;
|
||||
BOOST_FAIL("vec should be empty");
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_emplace) {
|
||||
managed_vector<unsigned> vec;
|
||||
fill(vec);
|
||||
verify_filled(vec);
|
||||
|
||||
vec.clear();
|
||||
verify_empty(vec);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_copy) {
|
||||
managed_vector<unsigned> vec;
|
||||
|
||||
managed_vector<unsigned> vec2(vec);
|
||||
verify_empty(vec2);
|
||||
|
||||
fill(vec);
|
||||
|
||||
managed_vector<unsigned> vec3(vec);
|
||||
verify_filled(vec);
|
||||
verify_filled(vec3);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_move) {
|
||||
managed_vector<unsigned> vec;
|
||||
|
||||
managed_vector<unsigned> vec2(std::move(vec));
|
||||
verify_empty(vec2);
|
||||
|
||||
fill(vec);
|
||||
|
||||
managed_vector<unsigned> vec3(std::move(vec));
|
||||
verify_empty(vec);
|
||||
verify_filled(vec3);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_erase) {
|
||||
managed_vector<unsigned> vec;
|
||||
fill(vec);
|
||||
|
||||
vec.erase(vec.begin());
|
||||
|
||||
unsigned idx = 1;
|
||||
for (auto&& v : vec) {
|
||||
BOOST_CHECK_EQUAL(v, idx);
|
||||
BOOST_CHECK_EQUAL(vec[idx - 1], idx);
|
||||
idx++;
|
||||
}
|
||||
BOOST_CHECK_EQUAL(idx, count);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_resize_up) {
|
||||
managed_vector<unsigned> vec;
|
||||
fill(vec);
|
||||
vec.resize(count + 5);
|
||||
|
||||
unsigned idx = 0;
|
||||
for (auto&& v : vec) {
|
||||
if (idx < count) {
|
||||
BOOST_CHECK_EQUAL(v, idx);
|
||||
BOOST_CHECK_EQUAL(vec[idx], idx);
|
||||
} else {
|
||||
BOOST_CHECK_EQUAL(v, 0);
|
||||
BOOST_CHECK_EQUAL(vec[idx], 0);
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
BOOST_CHECK_EQUAL(idx, count + 5);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_resize_down) {
|
||||
managed_vector<unsigned> vec;
|
||||
fill(vec);
|
||||
vec.resize(5);
|
||||
|
||||
unsigned idx = 0;
|
||||
for (auto&& v : vec) {
|
||||
BOOST_CHECK_EQUAL(v, idx);
|
||||
BOOST_CHECK_EQUAL(vec[idx], idx);
|
||||
idx++;
|
||||
}
|
||||
BOOST_CHECK_EQUAL(idx, 5);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_compaction) {
|
||||
logalloc::region reg;
|
||||
with_allocator(reg.allocator(), [&] {
|
||||
managed_vector<unsigned> vec;
|
||||
fill(vec);
|
||||
|
||||
verify_filled(vec);
|
||||
|
||||
reg.full_compaction();
|
||||
|
||||
verify_filled(vec);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user