mirror of
https://github.com/boostorg/circular_buffer.git
synced 2026-02-09 23:12:25 +00:00
circular_buffer: updated srcdoc and test cases
[SVN r3921]
This commit is contained in:
@@ -58,6 +58,104 @@ void min_capacity_test() {
|
||||
BOOST_CHECK(cb3.capacity().min_capacity() <= cb3.internal_capacity());
|
||||
}
|
||||
|
||||
void some_constructor_tests() {
|
||||
|
||||
cb_space_optimized cb1;
|
||||
BOOST_CHECK(cb1.capacity() == cb1.max_size());
|
||||
BOOST_CHECK(cb1.capacity().min_capacity() == 0);
|
||||
BOOST_CHECK(cb1.internal_capacity() == 0);
|
||||
BOOST_CHECK(cb1.size() == 0);
|
||||
|
||||
cb1.push_back(1);
|
||||
cb1.push_back(2);
|
||||
cb1.push_back(3);
|
||||
|
||||
BOOST_CHECK(cb1.size() == 3);
|
||||
BOOST_CHECK(cb1.capacity() == cb1.max_size());
|
||||
|
||||
cb_space_optimized cb2(cb1.begin(), cb1.end());
|
||||
|
||||
BOOST_CHECK(cb2.capacity() == 3);
|
||||
BOOST_CHECK(cb2.capacity().min_capacity() == 0);
|
||||
BOOST_CHECK(cb2.size() == 3);
|
||||
}
|
||||
|
||||
void shrink_to_fit() {
|
||||
|
||||
cb_space_optimized cb(1000);
|
||||
cb.push_back(1);
|
||||
cb.push_back(2);
|
||||
cb.push_back(3);
|
||||
|
||||
BOOST_CHECK(cb.size() == 3);
|
||||
BOOST_CHECK(cb.capacity() == 1000);
|
||||
|
||||
size_t internal_capacity = cb.internal_capacity();
|
||||
cb_space_optimized(cb).swap(cb);
|
||||
|
||||
BOOST_CHECK(cb.size() == 3);
|
||||
BOOST_CHECK(cb.capacity() == 1000);
|
||||
BOOST_CHECK(internal_capacity >= cb.internal_capacity());
|
||||
}
|
||||
|
||||
void iterator_invalidation_test() {
|
||||
|
||||
#if !defined(NDEBUG) && !defined(BOOST_CB_DISABLE_DEBUG)
|
||||
|
||||
cb_space_optimized cb1(10, 1);
|
||||
cb1.push_back(2);
|
||||
cb1.push_back(3);
|
||||
cb1.push_back(4);
|
||||
cb_space_optimized::iterator it1 = cb1.end();
|
||||
cb_space_optimized::const_iterator it2 = cb1.begin();
|
||||
cb_space_optimized::iterator it3 = cb1.begin() + 6;
|
||||
|
||||
cb1.set_capacity(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_CHECK(!it3.is_valid(&cb1));
|
||||
|
||||
it1 = cb1.end();
|
||||
it2 = cb1.begin();
|
||||
it3 = cb1.begin() + 6;
|
||||
cb1.rset_capacity(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_CHECK(!it3.is_valid(&cb1));
|
||||
|
||||
it1 = cb1.end();
|
||||
it2 = cb1.begin();
|
||||
it3 = cb1.begin() + 6;
|
||||
cb1.resize(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_CHECK(!it3.is_valid(&cb1));
|
||||
|
||||
it1 = cb1.end();
|
||||
it2 = cb1.begin();
|
||||
it3 = cb1.begin() + 6;
|
||||
cb1.rresize(10);
|
||||
BOOST_CHECK(it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_CHECK(!it3.is_valid(&cb1));
|
||||
|
||||
{
|
||||
cb_space_optimized cb2(10, 1);
|
||||
cb2.push_back(2);
|
||||
cb2.push_back(3);
|
||||
cb2.push_back(4);
|
||||
it1 = cb2.end();
|
||||
it2 = cb2.begin();
|
||||
it3 = cb2.begin() + 6;
|
||||
}
|
||||
BOOST_CHECK(!it1.is_valid(&cb1));
|
||||
BOOST_CHECK(!it2.is_valid(&cb1));
|
||||
BOOST_CHECK(!it3.is_valid(&cb1));
|
||||
|
||||
|
||||
#endif // #if !defined(NDEBUG) && !defined(BOOST_CB_DISABLE_DEBUG)
|
||||
}
|
||||
|
||||
// test main
|
||||
test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) {
|
||||
|
||||
@@ -65,6 +163,9 @@ test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) {
|
||||
add_common_tests(tests);
|
||||
|
||||
tests->add(BOOST_TEST_CASE(&min_capacity_test));
|
||||
tests->add(BOOST_TEST_CASE(&some_constructor_tests));
|
||||
tests->add(BOOST_TEST_CASE(&shrink_to_fit));
|
||||
tests->add(BOOST_TEST_CASE(&iterator_invalidation_test));
|
||||
|
||||
return tests;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user