1// Common tests for the circular buffer and its adaptor. 2 3// Copyright (c) 2003-2008 Jan Gaspar 4// Copyright (c) 2013 Antony Polukhin 5 6// Copyright 2014,2018 Glen Joseph Fernandes 7// (glenjofe@gmail.com) 8 9// Use, modification, and distribution is subject to the Boost Software 10// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 11// http://www.boost.org/LICENSE_1_0.txt) 12 13#include <boost/type_traits/is_nothrow_move_constructible.hpp> 14#include <boost/type_traits/is_nothrow_move_assignable.hpp> 15#include <boost/type_traits/has_nothrow_constructor.hpp> 16 17template <class Alloc> 18void generic_test(CB_CONTAINER<MyInteger, Alloc>& cb) { 19 20 vector<int> v; 21 v.push_back(11); 22 v.push_back(12); 23 v.push_back(13); 24 v.push_back(14); 25 v.push_back(15); 26 v.push_back(16); 27 v.push_back(17); 28 29 if (cb.capacity() == 0) { 30 31 cb.insert(cb.begin(), 1); 32 cb.insert(cb.begin(), v.begin(), v.end()); 33 cb.rinsert(cb.end(), 2); 34 cb.rinsert(cb.end(), v.begin(), v.end()); 35 cb.push_back(3); 36 cb.push_front(4); 37 cb.linearize(); 38 39 BOOST_TEST(cb.empty()); 40 BOOST_TEST(cb.full()); 41 42 } else { 43 44 cb.insert(cb.end(), 1); 45 BOOST_TEST(!cb.empty()); 46 BOOST_TEST(cb[cb.size() - 1] == 1); 47 48 size_t size = cb.size(); 49 cb.rerase(cb.end() - 1, cb.end()); 50 BOOST_TEST(size == cb.size() + 1); 51 52 cb.insert(cb.end(), v.begin(), v.end()); 53 BOOST_TEST(!cb.empty()); 54 BOOST_TEST(cb[cb.size() - 1] == 17); 55 56 size = cb.size(); 57 cb.erase(cb.end() - 1, cb.end()); 58 BOOST_TEST(size == cb.size() + 1); 59 60 size = cb.size(); 61 cb.rinsert(cb.begin(), 2); 62 BOOST_TEST(size + 1 == cb.size()); 63 BOOST_TEST(cb[0] == 2); 64 65 size = cb.size(); 66 cb.erase(cb.begin()); 67 BOOST_TEST(size == cb.size() + 1); 68 69 cb.rinsert(cb.begin(), v.begin(), v.end()); 70 BOOST_TEST(!cb.empty()); 71 BOOST_TEST(cb[0] == 11); 72 73 size = cb.size(); 74 cb.pop_front(); 75 BOOST_TEST(size == cb.size() + 1); 76 77 cb.push_back(3); 78 BOOST_TEST(!cb.empty()); 79 BOOST_TEST(cb[cb.size() - 1] == 3); 80 81 size = cb.size(); 82 cb.pop_back(); 83 BOOST_TEST(size == cb.size() + 1); 84 85 cb.push_front(4); 86 BOOST_TEST(!cb.empty()); 87 BOOST_TEST(cb[0] == 4); 88 89 cb.linearize(); 90 BOOST_TEST(!cb.empty()); 91 BOOST_TEST(cb[0] == 4); 92 93 size = cb.size(); 94 cb.rerase(cb.begin()); 95 BOOST_TEST(size == cb.size() + 1); 96 } 97} 98 99void basic_test() { 100 101 vector<int> v; 102 v.push_back(1); 103 v.push_back(2); 104 v.push_back(3); 105 v.push_back(4); 106 v.push_back(5); 107 v.push_back(6); 108 v.push_back(7); 109 CB_CONTAINER<MyInteger> cb1(3, v.begin(), v.end()); 110 CB_CONTAINER<MyInteger> cb2(10, v.begin(), v.end()); 111 CB_CONTAINER<MyInteger> cb3(7, v.begin(), v.end()); 112 113 BOOST_TEST(cb1.full()); 114 BOOST_TEST(cb1.capacity() == 3); 115 BOOST_TEST(cb1.size() == 3); 116 BOOST_TEST(cb1[0] == 5); 117 BOOST_TEST(cb1[2] == 7); 118 BOOST_TEST(!cb2.full()); 119 BOOST_TEST(cb2[2] == 3); 120 BOOST_TEST(cb3.full()); 121 BOOST_TEST(cb3[0] == 1); 122 BOOST_TEST(cb3[6] == 7); 123 124 generic_test(cb1); 125 generic_test(cb2); 126 generic_test(cb3); 127} 128 129void constructor_and_element_access_test() { 130 131 CB_CONTAINER<int> cb(5, 3); 132 cb[1] = 10; 133 134 BOOST_TEST(cb.full()); 135 BOOST_TEST(cb[1] == 10); 136 BOOST_TEST(cb[4] == 3); 137} 138 139void size_test() { 140 141 CB_CONTAINER<MyInteger> cb1(3); 142 cb1.push_back(1); 143 cb1.push_back(2); 144 cb1.push_back(3); 145 cb1.push_back(4); 146 CB_CONTAINER<MyInteger> cb2(5); 147 148 BOOST_TEST(cb1.size() == 3); 149 BOOST_TEST(cb2.size() == 0); 150 BOOST_TEST(cb1.max_size() == cb2.max_size()); 151 152 generic_test(cb1); 153 generic_test(cb2); 154} 155 156template<class T> 157class my_allocator { 158public: 159 typedef T value_type; 160 161 162 typedef std::size_t size_type; 163 typedef std::ptrdiff_t difference_type; 164 165private: 166 template<class U> 167 struct const_pointer_; 168 169 template<class U> 170 struct pointer_ { 171 pointer_() : hidden_ptr_(0) {} 172 pointer_(void* p) : hidden_ptr_(static_cast<U*>(p)) {} 173 difference_type operator-(const const_pointer_<U>& rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; } 174 difference_type operator-(pointer_ rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; } 175 pointer_ operator-(size_type rhs) const { return hidden_ptr_ - rhs; } 176 bool operator == (pointer_ rhs) const { return hidden_ptr_ == rhs.hidden_ptr_; } 177 bool operator != (pointer_ rhs) const { return hidden_ptr_ != rhs.hidden_ptr_; } 178 bool operator < (pointer_ rhs) const { return hidden_ptr_ < rhs.hidden_ptr_; } 179 bool operator >= (pointer_ rhs) const { return hidden_ptr_ >= rhs.hidden_ptr_; } 180 pointer_& operator++() { ++hidden_ptr_; return *this; } 181 pointer_& operator--() { --hidden_ptr_; return *this; } 182 pointer_& operator+=(size_type s) { hidden_ptr_ += s; return *this; } 183 pointer_ operator+(size_type s) const { return hidden_ptr_ + s; } 184 pointer_ operator++(int) { pointer_ p = *this; ++hidden_ptr_; return p; } 185 pointer_ operator--(int) { pointer_ p = *this; --hidden_ptr_; return p; } 186 U& operator*() const { return *hidden_ptr_; } 187 U* operator->() const { return hidden_ptr_; } 188 189 U* hidden_ptr_; 190 }; 191 192 template<class U> 193 struct const_pointer_ { 194 const_pointer_() : hidden_ptr_(0) {} 195 const_pointer_(pointer_<U> p) : hidden_ptr_(p.hidden_ptr_) {} 196 const_pointer_(const void* p) : hidden_ptr_(static_cast<const U*>(p)) {} 197 difference_type operator-(pointer_<U> rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; } 198 difference_type operator-(const_pointer_ rhs) const { return hidden_ptr_ - rhs.hidden_ptr_; } 199 const_pointer_ operator-(size_type rhs) const { return hidden_ptr_ - rhs; } 200 bool operator == (const_pointer_ rhs) const { return hidden_ptr_ == rhs.hidden_ptr_; } 201 bool operator != (const_pointer_ rhs) const { return hidden_ptr_ != rhs.hidden_ptr_; } 202 bool operator < (const_pointer_ rhs) const { return hidden_ptr_ < rhs.hidden_ptr_; } 203 bool operator >= (const_pointer_ rhs) const { return hidden_ptr_ >= rhs.hidden_ptr_; } 204 const_pointer_& operator++() { ++hidden_ptr_; return *this; } 205 const_pointer_& operator--() { --hidden_ptr_; return *this; } 206 const_pointer_& operator+=(size_type s) { hidden_ptr_ += s; return hidden_ptr_; } 207 const_pointer_ operator+(size_type s) const { return hidden_ptr_ + s; } 208 const_pointer_ operator++(int) { const_pointer_ p = *this; ++hidden_ptr_; return p; } 209 const_pointer_ operator--(int) { const_pointer_ p = *this; --hidden_ptr_; return p; } 210 const U& operator*() const { return *hidden_ptr_; } 211 212 const U* hidden_ptr_; 213 }; 214 215public: 216 typedef pointer_<T> pointer; 217 typedef const_pointer_<T> const_pointer; 218 219 template<class T2> 220 struct rebind 221 { 222 typedef my_allocator<T2> other; 223 }; 224 225 pointer allocate(size_type count) { 226 return pointer(::operator new(count * sizeof(value_type))); 227 } 228 229 void deallocate(const pointer& ptr, size_type) 230 { ::operator delete(ptr.hidden_ptr_); } 231 232 template<class P> 233 void construct(value_type* ptr, BOOST_FWD_REF(P) p) 234 { ::new((void*)ptr) value_type(::boost::forward<P>(p)); } 235 236 void destroy(value_type* ptr) 237 { ptr->~value_type(); } 238 239 size_type max_size() const { 240 return ~static_cast<size_type>(0) / sizeof(size_type); 241 } 242}; 243 244void allocator_test() { 245 246 CB_CONTAINER<MyInteger> cb1(10, 0); 247 const CB_CONTAINER<MyInteger> cb2(10, 0); 248 CB_CONTAINER<MyInteger>::allocator_type& alloc_ref = cb1.get_allocator(); 249 CB_CONTAINER<MyInteger>::allocator_type alloc = cb2.get_allocator(); 250 alloc_ref.max_size(); 251 alloc.max_size(); 252 253 generic_test(cb1); 254 255 256 CB_CONTAINER<MyInteger, my_allocator<MyInteger> > cb_a(10, 0); 257 generic_test(cb_a); 258} 259 260#if !defined(BOOST_NO_CXX11_ALLOCATOR) 261template<class T> 262class cxx11_allocator { 263public: 264 typedef T value_type; 265 266 cxx11_allocator() { 267 } 268 269 template<class U> 270 cxx11_allocator(const cxx11_allocator<U> &) { 271 } 272 273 T* allocate(std::size_t n) { 274 return static_cast<T*>(::operator new(n * sizeof(T))); 275 } 276 277 void deallocate(T * p, std::size_t n) { 278 ::operator delete( p ); 279 } 280}; 281 282void cxx11_allocator_test() { 283 CB_CONTAINER<MyInteger, cxx11_allocator<MyInteger> > cb(10, 0); 284 generic_test(cb); 285} 286#endif 287 288void begin_and_end_test() { 289 290 vector<int> v; 291 v.push_back(11); 292 v.push_back(12); 293 v.push_back(13); 294 295 CB_CONTAINER<MyInteger> cb1(10, v.begin(), v.end()); 296 const CB_CONTAINER<MyInteger> cb2(10, v.begin(), v.end()); 297 298 CB_CONTAINER<MyInteger> cb3(10); 299 cb3.push_back(1); 300 cb3.push_back(2); 301 cb3.insert(cb3.begin(), 3); 302 int i = 0; 303 CB_CONTAINER<MyInteger>::const_iterator it = cb3.begin(); 304 for (; it != cb3.end(); it++) { 305 i += *it; 306 } 307 CB_CONTAINER<MyInteger> cb4(20); 308 const CB_CONTAINER<MyInteger> cb5(20); 309 310 BOOST_TEST(*cb1.begin() == 11); 311 BOOST_TEST(*cb2.begin() == 11); 312 BOOST_TEST(i == 6); 313 BOOST_TEST(cb4.begin() == cb4.end()); 314 BOOST_TEST(cb5.begin() == cb5.end()); 315 316 generic_test(cb1); 317 generic_test(cb3); 318 generic_test(cb4); 319} 320 321void rbegin_and_rend_test() { 322 323 vector<int> v; 324 v.push_back(11); 325 v.push_back(12); 326 v.push_back(13); 327 328 CB_CONTAINER<MyInteger> cb1(10, v.begin(), v.end()); 329 const CB_CONTAINER<MyInteger> cb2(10, v.begin(), v.end()); 330 331 CB_CONTAINER<MyInteger> cb3(3); 332 cb3.push_back(1); 333 cb3.push_back(2); 334 cb3.insert(cb3.begin(), 3); 335 cb3.push_back(1); 336 int i = 0; 337 CB_CONTAINER<MyInteger>::reverse_iterator it = cb3.rbegin(); 338 for (; it != cb3.rend(); it++) { 339 i += *it; 340 } 341 CB_CONTAINER<MyInteger> cb4(20); 342 const CB_CONTAINER<MyInteger> cb5(20); 343 344 BOOST_TEST(*cb1.rbegin() == 13); 345 BOOST_TEST(*cb2.rbegin() == 13); 346 BOOST_TEST(i == 4); 347 BOOST_TEST(cb4.rbegin() == cb4.rend()); 348 BOOST_TEST(cb5.rbegin() == cb5.rend()); 349 350 generic_test(cb1); 351 generic_test(cb3); 352 generic_test(cb4); 353} 354 355void element_access_and_insert_test() { 356 357 CB_CONTAINER<MyInteger> cb(3); 358 cb.push_back(1); 359 cb.push_back(2); 360 cb.insert(cb.begin(), 3); 361 cb.push_back(4); 362 const CB_CONTAINER<MyInteger> ccb = cb; 363 364 BOOST_TEST(cb[0] == 1); 365 BOOST_TEST(cb[1] == 2); 366 BOOST_TEST(cb[2] == 4); 367 BOOST_TEST(ccb[2] == 4); 368 369 generic_test(cb); 370} 371 372void at_test() { 373 374#if !defined(BOOST_NO_EXCEPTIONS) 375 376 CB_CONTAINER<MyInteger> cb(3); 377 cb.push_back(1); 378 379 try { 380 BOOST_TEST(cb.at(0) == 1); 381 } 382 catch (out_of_range&) { 383 BOOST_ERROR("An unexpected exception has been thrown!"); 384 } 385 386 BOOST_TEST_THROWS(cb.at(2), out_of_range); 387 388 generic_test(cb); 389 390#endif // #if !defined(BOOST_NO_EXCEPTIONS) 391} 392 393void front_and_back_test() { 394 395 CB_CONTAINER<MyInteger> cb(1); 396 cb.push_back(2); 397 cb.push_back(3); 398 399 BOOST_TEST(cb.front() == cb.back()); 400 BOOST_TEST(cb.back() == 3); 401 402 generic_test(cb); 403} 404 405void linearize_test() { 406 407 vector<int> v; 408 v.push_back(1); 409 v.push_back(2); 410 v.push_back(3); 411 v.push_back(4); 412 v.push_back(5); 413 v.push_back(6); 414 v.push_back(7); 415 v.push_back(8); 416 v.push_back(9); 417 v.push_back(10); 418 v.push_back(11); 419 v.push_back(12); 420 CB_CONTAINER<MyInteger> cb1(10, v.begin(), v.begin() + 10); 421 cb1.push_back(11); 422 cb1.push_back(12); 423 cb1.push_back(13); 424 CB_CONTAINER<MyInteger> cb2(10, v.begin(), v.begin() + 10); 425 cb2.push_back(11); 426 cb2.push_back(12); 427 cb2.push_back(13); 428 cb2.push_back(14); 429 cb2.push_back(15); 430 cb2.push_back(16); 431 cb2.push_back(17); 432 CB_CONTAINER<MyInteger> cb3(10, v.begin(), v.begin() + 10); 433 cb3.push_back(11); 434 cb3.push_back(12); 435 cb3.push_back(13); 436 cb3.pop_front(); 437 cb3.pop_front(); 438 CB_CONTAINER<MyInteger> cb4(5); 439 CB_CONTAINER<MyInteger> cb5(12, v.begin(), v.end()); 440 cb5.push_back(13); 441 cb5.push_back(14); 442 cb5.push_back(15); 443 cb5.pop_front(); 444 cb5.pop_front(); 445 cb5.pop_front(); 446 cb5.pop_front(); 447 cb5.pop_front(); 448 cb5.pop_front(); 449 CB_CONTAINER<MyInteger> cb6(6); 450 cb6.push_back(-2); 451 cb6.push_back(-1); 452 cb6.push_back(0); 453 cb6.push_back(1); 454 cb6.push_back(2); 455 cb6.push_back(3); 456 cb6.push_back(4); 457 cb6.push_back(5); 458 cb6.push_back(6); 459 cb6.pop_back(); 460 CB_CONTAINER<MyInteger> cb7(6); 461 cb7.push_back(0); 462 cb7.push_back(1); 463 cb7.push_back(2); 464 cb7.push_back(3); 465 cb7.push_back(4); 466 467 BOOST_TEST(!cb1.is_linearized()); 468 BOOST_TEST(*cb1.linearize() == 4); 469 BOOST_TEST(cb1.is_linearized()); 470 BOOST_TEST(cb1.linearize() == cb1.array_one().first); 471 BOOST_TEST(&cb1[0] < &cb1[1] 472 && &cb1[1] < &cb1[2] 473 && &cb1[2] < &cb1[3] 474 && &cb1[3] < &cb1[4] 475 && &cb1[4] < &cb1[5] 476 && &cb1[5] < &cb1[6] 477 && &cb1[6] < &cb1[7] 478 && &cb1[7] < &cb1[8] 479 && &cb1[8] < &cb1[9]); 480 BOOST_TEST(*(cb1.linearize() + 1) == 5); 481 BOOST_TEST(*(cb1.linearize() + 2) == 6); 482 BOOST_TEST(*(cb1.linearize() + 3) == 7); 483 BOOST_TEST(*(cb1.linearize() + 4) == 8); 484 BOOST_TEST(*(cb1.linearize() + 5) == 9); 485 BOOST_TEST(*(cb1.linearize() + 6) == 10); 486 BOOST_TEST(*(cb1.linearize() + 7) == 11); 487 BOOST_TEST(*(cb1.linearize() + 8) == 12); 488 BOOST_TEST(*(cb1.linearize() + 9) == 13); 489 BOOST_TEST(!cb2.is_linearized()); 490 BOOST_TEST(*cb2.linearize() == 8); 491 BOOST_TEST(cb2.is_linearized()); 492 BOOST_TEST(&cb2[0] < &cb2[1] 493 && &cb2[1] < &cb2[2] 494 && &cb2[2] < &cb2[3] 495 && &cb2[3] < &cb2[4] 496 && &cb2[4] < &cb2[5] 497 && &cb2[5] < &cb2[6] 498 && &cb2[6] < &cb2[7] 499 && &cb2[7] < &cb2[8] 500 && &cb2[8] < &cb2[9]); 501 BOOST_TEST(*(cb2.linearize() + 1) == 9); 502 BOOST_TEST(*(cb2.linearize() + 2) == 10); 503 BOOST_TEST(*(cb2.linearize() + 3) == 11); 504 BOOST_TEST(*(cb2.linearize() + 4) == 12); 505 BOOST_TEST(*(cb2.linearize() + 5) == 13); 506 BOOST_TEST(*(cb2.linearize() + 6) == 14); 507 BOOST_TEST(*(cb2.linearize() + 7) == 15); 508 BOOST_TEST(*(cb2.linearize() + 8) == 16); 509 BOOST_TEST(*(cb2.linearize() + 9) == 17); 510 BOOST_TEST(cb2.is_linearized()); 511 BOOST_TEST(*cb3.linearize() == 6); 512 BOOST_TEST(cb3.is_linearized()); 513 BOOST_TEST(&cb3[0] < &cb3[1] 514 && &cb3[1] < &cb3[2] 515 && &cb3[2] < &cb3[3] 516 && &cb3[3] < &cb3[4] 517 && &cb3[4] < &cb3[5] 518 && &cb3[5] < &cb3[6] 519 && &cb3[6] < &cb3[7]); 520 BOOST_TEST(*(cb3.linearize() + 1) == 7); 521 BOOST_TEST(*(cb3.linearize() + 2) == 8); 522 BOOST_TEST(*(cb3.linearize() + 3) == 9); 523 BOOST_TEST(*(cb3.linearize() + 4) == 10); 524 BOOST_TEST(*(cb3.linearize() + 5) == 11); 525 BOOST_TEST(*(cb3.linearize() + 6) == 12); 526 BOOST_TEST(*(cb3.linearize() + 7) == 13); 527 BOOST_TEST(cb4.linearize() == 0); 528 BOOST_TEST(cb4.is_linearized()); 529 BOOST_TEST(*cb5.linearize() == 10); 530 BOOST_TEST(cb5.is_linearized()); 531 BOOST_TEST(&cb5[0] < &cb5[1] 532 && &cb5[1] < &cb5[2] 533 && &cb5[2] < &cb5[3] 534 && &cb5[3] < &cb5[4] 535 && &cb5[4] < &cb5[5]); 536 BOOST_TEST(*(cb5.linearize() + 1) == 11); 537 BOOST_TEST(*(cb5.linearize() + 2) == 12); 538 BOOST_TEST(*(cb5.linearize() + 3) == 13); 539 BOOST_TEST(*(cb5.linearize() + 4) == 14); 540 BOOST_TEST(*(cb5.linearize() + 5) == 15); 541 BOOST_TEST(*cb6.linearize() == 1); 542 BOOST_TEST(cb6.is_linearized()); 543 BOOST_TEST(&cb6[0] < &cb6[1] 544 && &cb6[1] < &cb6[2] 545 && &cb6[2] < &cb6[3] 546 && &cb6[3] < &cb6[4]); 547 BOOST_TEST(*(cb6.linearize() + 1) == 2); 548 BOOST_TEST(*(cb6.linearize() + 2) == 3); 549 BOOST_TEST(*(cb6.linearize() + 3) == 4); 550 BOOST_TEST(*(cb6.linearize() + 4) == 5); 551 BOOST_TEST(cb7.is_linearized()); 552 553 generic_test(cb1); 554 generic_test(cb2); 555 generic_test(cb3); 556 generic_test(cb4); 557 generic_test(cb5); 558 generic_test(cb6); 559 generic_test(cb7); 560} 561 562void array_range_test() { 563 564 CB_CONTAINER<MyInteger> cb(7); 565 CB_CONTAINER<MyInteger>::array_range a1 = cb.array_one(); 566 CB_CONTAINER<MyInteger>::array_range a2 = cb.array_two(); 567 CB_CONTAINER<MyInteger>::const_array_range ca1 = cb.array_one(); 568 CB_CONTAINER<MyInteger>::const_array_range ca2 = cb.array_two(); 569 570 BOOST_TEST(a1.second == 0); 571 BOOST_TEST(a2.second == 0); 572 BOOST_TEST(ca1.second == 0); 573 BOOST_TEST(ca2.second == 0); 574 575 cb.push_back(1); 576 cb.push_back(2); 577 cb.push_back(3); 578 a1 = cb.array_one(); 579 a2 = cb.array_two(); 580 ca1 = cb.array_one(); 581 ca2 = cb.array_two(); 582 583 BOOST_TEST(a1.first[0] == 1); 584 BOOST_TEST(a1.first[2] == 3); 585 BOOST_TEST(ca1.first[0] == 1); 586 BOOST_TEST(ca1.first[2] == 3); 587 BOOST_TEST(a1.second == 3); 588 BOOST_TEST(a2.second == 0); 589 BOOST_TEST(ca1.second == 3); 590 BOOST_TEST(ca2.second == 0); 591 592 cb.push_back(4); 593 cb.push_back(5); 594 cb.push_back(6); 595 cb.push_back(7); 596 cb.push_back(8); 597 cb.push_back(9); 598 cb.push_back(10); 599 a1 = cb.array_one(); 600 a2 = cb.array_two(); 601 ca1 = cb.array_one(); 602 ca2 = cb.array_two(); 603 604 BOOST_TEST(a1.first[0] == 4); 605 BOOST_TEST(a1.first[3] == 7); 606 BOOST_TEST(a2.first[0] == 8); 607 BOOST_TEST(a2.first[2] == 10); 608 BOOST_TEST(ca1.first[0] == 4); 609 BOOST_TEST(ca1.first[3] == 7); 610 BOOST_TEST(ca2.first[0] == 8); 611 BOOST_TEST(ca2.first[2] == 10); 612 BOOST_TEST(a1.second == 4); 613 BOOST_TEST(a2.second == 3); 614 BOOST_TEST(ca1.second == 4); 615 BOOST_TEST(ca2.second == 3); 616 617 cb.pop_front(); 618 cb.pop_back(); 619 a1 = cb.array_one(); 620 a2 = cb.array_two(); 621 ca1 = cb.array_one(); 622 ca2 = cb.array_two(); 623 624 BOOST_TEST(a1.first[0] == 5); 625 BOOST_TEST(a1.first[2] == 7); 626 BOOST_TEST(a2.first[0] == 8); 627 BOOST_TEST(a2.first[1] == 9); 628 BOOST_TEST(ca1.first[0] == 5); 629 BOOST_TEST(ca1.first[2] == 7); 630 BOOST_TEST(ca2.first[0] == 8); 631 BOOST_TEST(ca2.first[1] == 9); 632 BOOST_TEST(a1.second == 3); 633 BOOST_TEST(a2.second == 2); 634 BOOST_TEST(ca1.second == 3); 635 BOOST_TEST(ca2.second == 2); 636 637 cb.pop_back(); 638 cb.pop_back(); 639 cb.pop_back(); 640 a1 = cb.array_one(); 641 a2 = cb.array_two(); 642 ca1 = cb.array_one(); 643 ca2 = cb.array_two(); 644 645 BOOST_TEST(a1.first[0] == 5); 646 BOOST_TEST(a1.first[1] == 6); 647 BOOST_TEST(ca1.first[0] == 5); 648 BOOST_TEST(ca1.first[1] == 6); 649 BOOST_TEST(a1.second == 2); 650 BOOST_TEST(a2.second == 0); 651 BOOST_TEST(ca1.second == 2); 652 BOOST_TEST(ca2.second == 0); 653 654 CB_CONTAINER<MyInteger> cb0(0); 655 a1 = cb0.array_one(); 656 a2 = cb0.array_two(); 657 658 BOOST_TEST(a1.second == 0); 659 BOOST_TEST(a2.second == 0); 660 661 const CB_CONTAINER<MyInteger> ccb(10, 1); 662 ca1 = ccb.array_one(); 663 ca2 = ccb.array_two(); 664 665 BOOST_TEST(ca1.second == 10); 666 BOOST_TEST(*(ca1.first) == 1); 667 BOOST_TEST(ca2.second == 0); 668 669 generic_test(cb); 670 generic_test(cb0); 671} 672 673void capacity_and_reserve_test() { 674 675 CB_CONTAINER<MyInteger> cb1(0); 676 CB_CONTAINER<MyInteger> cb2(10); 677 678 BOOST_TEST(cb1.capacity() == 0); 679 BOOST_TEST(cb1.size() == 0); 680 BOOST_TEST(cb1.reserve() == 0); 681 BOOST_TEST(cb1.full()); 682 BOOST_TEST(cb1.empty()); 683 BOOST_TEST(cb1.reserve() == cb1.capacity() - cb1.size()); 684 BOOST_TEST(cb2.capacity() == 10); 685 BOOST_TEST(cb2.size() == 0); 686 BOOST_TEST(cb2.reserve() == 10); 687 BOOST_TEST(cb2.reserve() == cb2.capacity() - cb2.size()); 688 689 cb1.push_back(1); 690 cb2.push_back(2); 691 cb2.push_back(2); 692 cb2.push_back(2); 693 694 BOOST_TEST(cb1.capacity() == 0); 695 BOOST_TEST(cb1.size() == 0); 696 BOOST_TEST(cb1.reserve() == 0); 697 BOOST_TEST(cb1.full()); 698 BOOST_TEST(cb1.empty()); 699 BOOST_TEST(cb1.reserve() == cb1.capacity() - cb1.size()); 700 BOOST_TEST(cb2.capacity() == 10); 701 BOOST_TEST(cb2.size() == 3); 702 BOOST_TEST(cb2.reserve() == 7); 703 BOOST_TEST(cb2.reserve() == cb2.capacity() - cb2.size()); 704 705 generic_test(cb1); 706 generic_test(cb2); 707} 708 709void full_and_empty_test() { 710 711 CB_CONTAINER<MyInteger> cb1(10); 712 CB_CONTAINER<MyInteger> cb2(3); 713 CB_CONTAINER<MyInteger> cb3(2); 714 CB_CONTAINER<MyInteger> cb4(2); 715 cb2.push_back(1); 716 cb2.push_back(3); 717 cb2.push_back(1); 718 cb2.push_back(1); 719 cb2.push_back(1); 720 cb3.push_back(3); 721 cb3.push_back(1); 722 cb4.push_back(1); 723 724 BOOST_TEST(cb1.empty()); 725 BOOST_TEST(cb2.full()); 726 BOOST_TEST(cb3.full()); 727 BOOST_TEST(!cb4.empty()); 728 BOOST_TEST(!cb4.full()); 729 730 generic_test(cb1); 731 generic_test(cb2); 732 generic_test(cb3); 733 generic_test(cb4); 734} 735 736void set_capacity_test() { 737 738 CB_CONTAINER<MyInteger> cb1(10); 739 cb1.push_back(2); 740 cb1.push_back(3); 741 cb1.push_back(1); 742 cb1.set_capacity(5); 743 CB_CONTAINER<MyInteger> cb2(3); 744 cb2.push_back(2); 745 cb2.push_back(3); 746 cb2.push_back(1); 747 cb2.set_capacity(10); 748 CB_CONTAINER<MyInteger> cb3(5); 749 cb3.push_back(2); 750 cb3.push_back(3); 751 cb3.push_back(1); 752 cb3.set_capacity(2); 753 754 BOOST_TEST(cb1.size() == 3); 755 BOOST_TEST(cb1[0] == 2); 756 BOOST_TEST(cb1[2] == 1); 757 BOOST_TEST(cb1.capacity() == 5); 758 BOOST_TEST(cb2.size() == 3); 759 BOOST_TEST(cb2[0] == 2); 760 BOOST_TEST(cb2[2] == 1); 761 BOOST_TEST(cb2.capacity() == 10); 762 BOOST_TEST(cb3.size() == 2); 763 BOOST_TEST(cb3[0] == 2); 764 BOOST_TEST(cb3[1] == 3); 765 BOOST_TEST(cb3.capacity() == 2); 766 767 cb3.set_capacity(2); 768 769 BOOST_TEST(cb3.size() == 2); 770 BOOST_TEST(cb3[0] == 2); 771 BOOST_TEST(cb3[1] == 3); 772 BOOST_TEST(cb3.capacity() == 2); 773 774 cb3.set_capacity(0); 775 776 BOOST_TEST(cb3.size() == 0); 777 BOOST_TEST(cb3.capacity() == 0); 778 779 generic_test(cb1); 780 generic_test(cb2); 781 generic_test(cb3); 782} 783 784void rset_capacity_test() { 785 786 CB_CONTAINER<MyInteger> cb1(10); 787 cb1.push_back(2); 788 cb1.push_back(3); 789 cb1.push_back(1); 790 cb1.rset_capacity(5); 791 CB_CONTAINER<MyInteger> cb2(3); 792 cb2.push_back(2); 793 cb2.push_back(3); 794 cb2.push_back(1); 795 cb2.rset_capacity(10); 796 CB_CONTAINER<MyInteger> cb3(5); 797 cb3.push_back(2); 798 cb3.push_back(3); 799 cb3.push_back(1); 800 cb3.rset_capacity(2); 801 802 BOOST_TEST(cb1.size() == 3); 803 BOOST_TEST(cb1[0] == 2); 804 BOOST_TEST(cb1[2] == 1); 805 BOOST_TEST(cb1.capacity() == 5); 806 BOOST_TEST(cb2.size() == 3); 807 BOOST_TEST(cb2[0] == 2); 808 BOOST_TEST(cb2[2] == 1); 809 BOOST_TEST(cb2.capacity() == 10); 810 BOOST_TEST(cb3.size() == 2); 811 BOOST_TEST(cb3[0] == 3); 812 BOOST_TEST(cb3[1] == 1); 813 BOOST_TEST(cb3.capacity() == 2); 814 815 cb3.rset_capacity(2); 816 817 BOOST_TEST(cb3.size() == 2); 818 BOOST_TEST(cb3[0] == 3); 819 BOOST_TEST(cb3[1] == 1); 820 BOOST_TEST(cb3.capacity() == 2); 821 822 cb3.rset_capacity(0); 823 824 BOOST_TEST(cb3.size() == 0); 825 BOOST_TEST(cb3.capacity() == 0); 826 827 generic_test(cb1); 828 generic_test(cb2); 829 generic_test(cb3); 830} 831 832void resize_test() { 833 834 CB_CONTAINER<MyInteger> cb1(10); 835 cb1.push_back(1); 836 cb1.push_back(2); 837 cb1.push_back(3); 838 cb1.push_back(4); 839 cb1.resize(20, 5); 840 CB_CONTAINER<MyInteger> cb2(10); 841 cb2.push_back(1); 842 cb2.push_back(2); 843 cb2.push_back(3); 844 cb2.push_back(4); 845 cb2.resize(2); 846 CB_CONTAINER<MyInteger> cb3(10, 1); 847 cb3.resize(0); 848 CB_CONTAINER<MyInteger> cb4(10, 1); 849 cb4.resize(10); 850 851 BOOST_TEST(cb1.size() == 20); 852 BOOST_TEST(cb1.capacity() == 20); 853 BOOST_TEST(cb1[0] == 1); 854 BOOST_TEST(cb1[3] == 4); 855 BOOST_TEST(cb1[4] == 5); 856 BOOST_TEST(cb1[19] == 5); 857 BOOST_TEST(cb2.size() == 2); 858 BOOST_TEST(cb2.capacity() == 10); 859 BOOST_TEST(cb2[0] == 1); 860 BOOST_TEST(cb2[1] == 2); 861 BOOST_TEST(cb3.size() == 0); 862 BOOST_TEST(cb3.capacity() == 10); 863 BOOST_TEST(cb4.size() == 10); 864 BOOST_TEST(cb4.capacity() == 10); 865 BOOST_TEST(cb4[0] == 1); 866 BOOST_TEST(cb4[9] == 1); 867 868 generic_test(cb1); 869 generic_test(cb2); 870 generic_test(cb3); 871 generic_test(cb4); 872} 873 874void rresize_test() { 875 876 CB_CONTAINER<MyInteger> cb1(10); 877 cb1.push_back(1); 878 cb1.push_back(2); 879 cb1.push_back(3); 880 cb1.push_back(4); 881 cb1.rresize(20, 5); 882 CB_CONTAINER<MyInteger> cb2(10); 883 cb2.push_back(1); 884 cb2.push_back(2); 885 cb2.push_back(3); 886 cb2.push_back(4); 887 cb2.rresize(2); 888 CB_CONTAINER<MyInteger> cb3(10, 1); 889 cb3.rresize(0); 890 CB_CONTAINER<MyInteger> cb4(10, 1); 891 cb4.rresize(10); 892 893 BOOST_TEST(cb1.size() == 20); 894 BOOST_TEST(cb1.capacity() == 20); 895 BOOST_TEST(cb1[0] == 5); 896 BOOST_TEST(cb1[15] == 5); 897 BOOST_TEST(cb1[16] == 1); 898 BOOST_TEST(cb1[19] == 4); 899 BOOST_TEST(cb2.size() == 2); 900 BOOST_TEST(cb2.capacity() == 10); 901 BOOST_TEST(cb2[0] == 3); 902 BOOST_TEST(cb2[1] == 4); 903 BOOST_TEST(cb3.size() == 0); 904 BOOST_TEST(cb3.capacity() == 10); 905 BOOST_TEST(cb4.size() == 10); 906 BOOST_TEST(cb4.capacity() == 10); 907 BOOST_TEST(cb4[0] == 1); 908 BOOST_TEST(cb4[9] == 1); 909 910 generic_test(cb1); 911 generic_test(cb2); 912 generic_test(cb3); 913 generic_test(cb4); 914} 915 916void constructor_test() { 917 918 CB_CONTAINER<MyInteger> cb0; 919 BOOST_TEST(cb0.capacity() == 0); 920 BOOST_TEST(cb0.size() == 0); 921 922 cb0.push_back(1); 923 cb0.push_back(2); 924 cb0.push_back(3); 925 926 BOOST_TEST(cb0.size() == 0); 927 BOOST_TEST(cb0.capacity() == 0); 928 929 CB_CONTAINER<MyInteger> cb1(3); 930 CB_CONTAINER<MyInteger> cb2(3, 2); 931 vector<int> v; 932 v.push_back(1); 933 v.push_back(2); 934 v.push_back(3); 935 v.push_back(4); 936 v.push_back(5); 937 CB_CONTAINER<MyInteger> cb3(v.begin(), v.end()); 938 CB_CONTAINER<MyInteger> cb4(3, v.begin(), v.end()); 939 CB_CONTAINER<MyInteger> cb5(10, v.begin(), v.end()); 940 CB_CONTAINER<MyInteger> cb6(10, 3, MyInteger(2)); 941 942 BOOST_TEST(cb1.size() == 0); 943 BOOST_TEST(cb1.capacity() == 3); 944 BOOST_TEST(cb2[0] == 2); 945 BOOST_TEST(cb2.full()); 946 BOOST_TEST(cb2[0] == 2); 947 BOOST_TEST(cb2[1] == 2); 948 BOOST_TEST(cb2[2] == 2); 949 BOOST_TEST(cb3.size() == 5); 950 BOOST_TEST(cb3.capacity() == 5); 951 BOOST_TEST(cb3.full()); 952 BOOST_TEST(cb3[0] == 1); 953 BOOST_TEST(cb3[4] == 5); 954 BOOST_TEST(cb4.size() == 3); 955 BOOST_TEST(cb4.capacity() == 3); 956 BOOST_TEST(cb4.full()); 957 BOOST_TEST(cb4[0] == 3); 958 BOOST_TEST(cb4[2] == 5); 959 BOOST_TEST(cb5.size() == 5); 960 BOOST_TEST(cb5.capacity() == 10); 961 BOOST_TEST(!cb5.full()); 962 BOOST_TEST(cb5[0] == 1); 963 BOOST_TEST(cb5[4] == 5); 964 BOOST_TEST(cb6.size() == 3); 965 BOOST_TEST(cb6.capacity() == 10); 966 BOOST_TEST(!cb6.full()); 967 BOOST_TEST(cb6[0] == 2); 968 BOOST_TEST(cb6[2] == 2); 969 970 cb5.push_back(6); 971 cb6.push_back(6); 972 973 BOOST_TEST(cb5[5] == 6); 974 BOOST_TEST(cb5[0] == 1); 975 BOOST_TEST(cb5.size() == 6); 976 BOOST_TEST(cb6[3] == 6); 977 BOOST_TEST(cb6.size() == 4); 978 BOOST_TEST(cb6[0] == 2); 979 980#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) 981 982 CB_CONTAINER<int> cb7(MyInputIterator(v.begin()), MyInputIterator(v.end())); 983 CB_CONTAINER<int> cb8(3, MyInputIterator(v.begin()), MyInputIterator(v.end())); 984 985 BOOST_TEST(cb7.capacity() == 5); 986 BOOST_TEST(cb8.capacity() == 3); 987 988#endif // #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) 989 990 generic_test(cb1); 991 generic_test(cb2); 992 generic_test(cb3); 993 generic_test(cb4); 994 generic_test(cb5); 995 generic_test(cb6); 996} 997 998void assign_test() { 999 1000 CB_CONTAINER<MyInteger> cb1(4); 1001 cb1.push_back(1); 1002 cb1.push_back(2); 1003 cb1.push_back(3); 1004 cb1.push_back(4); 1005 cb1.push_back(5); 1006 cb1.assign(3, 8); 1007 BOOST_TEST(cb1.size() == 3); 1008 BOOST_TEST(cb1.capacity() == 3); 1009 BOOST_TEST(cb1[0] == 8); 1010 BOOST_TEST(cb1[2] == 8); 1011 1012 cb1.assign(6, 7); 1013 BOOST_TEST(cb1.size() == 6); 1014 BOOST_TEST(cb1.capacity() == 6); 1015 BOOST_TEST(cb1[0] == 7); 1016 BOOST_TEST(cb1[5] == 7); 1017 1018 CB_CONTAINER<float> cb2(4); 1019 cb2.assign(3, 1.1f); 1020 BOOST_TEST(cb2[0] == 1.1f); 1021 1022 CB_CONTAINER<MyInteger> cb3(5); 1023 cb3.push_back(1); 1024 cb3.push_back(2); 1025 cb3.push_back(3); 1026 cb3.assign((size_t)10, 1); // The size_t cast is not needed. It is present here just because of testing purposes. 1027 BOOST_TEST(cb3[0] == 1); 1028 BOOST_TEST(cb3[9] == 1); 1029 BOOST_TEST(cb3.size() == 10); 1030 BOOST_TEST(cb3.capacity() == 10); 1031 1032#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) 1033 1034 vector<int> v; 1035 v.push_back(1); 1036 v.push_back(2); 1037 v.push_back(3); 1038 v.push_back(4); 1039 v.push_back(5); 1040 1041 CB_CONTAINER<int> cb4(3); 1042 cb4.assign(MyInputIterator(v.begin()), MyInputIterator(v.end())); 1043 CB_CONTAINER<int> cb5(3); 1044 cb5.assign(4, MyInputIterator(v.begin()), MyInputIterator(v.end())); 1045 1046 BOOST_TEST(cb4.capacity() == 5); 1047 BOOST_TEST(cb5.capacity() == 4); 1048 1049#endif // #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) 1050 1051 generic_test(cb1); 1052 generic_test(cb3); 1053} 1054 1055void copy_constructor_and_assign_test() { 1056 1057 CB_CONTAINER<MyInteger> cb1(4); 1058 cb1.push_back(1); 1059 cb1.push_back(2); 1060 cb1.push_back(3); 1061 cb1.push_back(4); 1062 cb1.push_back(5); 1063 CB_CONTAINER<MyInteger> cb2 = cb1; 1064 1065 BOOST_TEST(cb1 == cb2); 1066 BOOST_TEST(cb2.capacity() == 4); 1067 BOOST_TEST(cb2[0] == 2); 1068 BOOST_TEST(cb2[3] == 5); 1069 1070 CB_CONTAINER<MyInteger> cb3(20); 1071 cb1.pop_back(); 1072 CB_CONTAINER<MyInteger> cb4(3); 1073 cb3 = cb2; 1074 cb3 = cb3; 1075 cb4 = cb1; 1076 CB_CONTAINER<MyInteger> cb5 = cb1; 1077 1078 BOOST_TEST(cb3 == cb2); 1079 BOOST_TEST(cb4 == cb1); 1080 BOOST_TEST(cb2.full()); 1081 BOOST_TEST(cb2[0] == 2); 1082 BOOST_TEST(cb3.full()); 1083 BOOST_TEST(cb3.capacity() == 4); 1084 BOOST_TEST(cb4.capacity() == 4); 1085 BOOST_TEST(!cb4.full()); 1086 BOOST_TEST(*(cb4.end() - 1) == 4); 1087 BOOST_TEST(cb1 == cb5); 1088 BOOST_TEST(cb5.capacity() == 4); 1089 BOOST_TEST(cb2[0] == 2); 1090 BOOST_TEST(cb2[2] == 4); 1091 1092 generic_test(cb1); 1093 generic_test(cb2); 1094 generic_test(cb3); 1095 generic_test(cb4); 1096 generic_test(cb5); 1097} 1098 1099void swap_test() { 1100 1101 CB_CONTAINER<MyInteger> cb1(2); 1102 cb1.push_back(1); 1103 cb1.push_back(2); 1104 cb1.push_back(3); 1105 CB_CONTAINER<MyInteger> cb2(5); 1106 cb2.push_back(8); 1107 cb2.swap(cb1); 1108 cb2.swap(cb2); 1109 1110 BOOST_TEST(cb2.capacity() == 2); 1111 BOOST_TEST(cb2[0] == 2); 1112 BOOST_TEST(cb2.full()); 1113 BOOST_TEST(cb1.capacity() == 5); 1114 BOOST_TEST(cb1[0] == 8); 1115 BOOST_TEST(cb1.size() == 1); 1116 1117 generic_test(cb1); 1118 generic_test(cb2); 1119} 1120 1121void push_back_test() { 1122 1123 CB_CONTAINER<MyDefaultConstructible> cb1(5); 1124 cb1.push_back(); 1125 cb1.push_back(MyDefaultConstructible(2)); 1126 BOOST_TEST(cb1[0].m_n == 1); 1127 BOOST_TEST(cb1[1].m_n == 2); 1128 1129 CB_CONTAINER<MyInteger> cb2(5); 1130 cb2.push_back(); 1131 BOOST_TEST(cb2.back() == CB_CONTAINER<MyInteger>::value_type()); 1132 1133 cb2.push_back(1); 1134 BOOST_TEST(cb2.back() == 1); 1135 1136 generic_test(cb2); 1137} 1138 1139void pop_back_test() { 1140 1141 CB_CONTAINER<MyInteger> cb(4); 1142 cb.push_back(1); 1143 cb.push_back(2); 1144 cb.push_back(3); 1145 cb.push_back(4); 1146 cb.push_back(5); 1147 cb.pop_back(); 1148 1149 BOOST_TEST(cb.size() == 3); 1150 BOOST_TEST(!cb.full()); 1151 BOOST_TEST(cb[0] == 2); 1152 1153 generic_test(cb); 1154} 1155 1156void insert_test() { 1157 1158 CB_CONTAINER<MyInteger> cb1(4); 1159 cb1.push_back(1); 1160 cb1.push_back(2); 1161 cb1.push_back(3); 1162 CB_CONTAINER<MyInteger>::iterator it1 = cb1.begin() + 1; 1163 it1 = cb1.insert(it1, 10); 1164 CB_CONTAINER<MyInteger> cb2(4); 1165 cb2.push_back(1); 1166 cb2.insert(cb2.begin()); 1167 cb2.insert(cb2.begin(), -1); 1168 CB_CONTAINER<MyInteger>::iterator it2 = cb2.begin() + 1; 1169 it2 = cb2.insert(it2, 5); 1170 CB_CONTAINER<MyInteger> cb3(2); 1171 cb3.insert(cb3.end(), 10); 1172 cb3.insert(cb3.end(), 20); 1173 cb3.insert(cb3.begin(), 30); 1174 cb3.insert(cb3.end(), 40); 1175 1176 BOOST_TEST(cb1[1] == 10); 1177 BOOST_TEST(*it1 == 10); 1178 BOOST_TEST(cb1.full()); 1179 BOOST_TEST(cb2[1] == 5); 1180 BOOST_TEST(*it2 == 5); 1181 BOOST_TEST(cb2.full()); 1182 BOOST_TEST(cb3[0] == 20); 1183 BOOST_TEST(cb3[1] == 40); 1184 1185 generic_test(cb1); 1186 generic_test(cb2); 1187 generic_test(cb3); 1188} 1189 1190void insert_n_test() { 1191 1192 CB_CONTAINER<MyInteger> cb1(4); 1193 cb1.push_back(1); 1194 cb1.push_back(2); 1195 cb1.push_back(3); 1196 cb1.insert(cb1.begin() + 1, 2, 10); 1197 CB_CONTAINER<MyInteger> cb2(2, 3); 1198 cb2.insert(cb2.begin(), 10, 5); 1199 CB_CONTAINER<MyInteger> cb3(4); 1200 cb3.insert(cb3.end(), 1, 6); 1201 CB_CONTAINER<MyInteger> cb4(6); 1202 cb4.push_back(1); 1203 cb4.push_back(2); 1204 cb4.push_back(3); 1205 cb4.push_back(4); 1206 cb4.insert(cb4.begin() + 2, 5, 6); 1207 cb4.insert(cb4.begin() + 2, 0, 7); 1208 CB_CONTAINER<MyInteger> cb5(3); 1209 cb5.push_back(1); 1210 cb5.push_back(2); 1211 cb5.pop_front(); 1212 cb5.insert(cb5.begin(), 2, 3); 1213 1214 BOOST_TEST(cb1.full()); 1215 BOOST_TEST(cb1[0] == 10); 1216 BOOST_TEST(cb1[1] == 10); 1217 BOOST_TEST(cb1[2] == 2); 1218 BOOST_TEST(cb1[3] == 3); 1219 BOOST_TEST(cb2[0] == 3); 1220 BOOST_TEST(cb2[1] == 3); 1221 BOOST_TEST(cb3[0] == 6); 1222 BOOST_TEST(cb3.size() == 1); 1223 BOOST_TEST(cb4.size() == 6); 1224 BOOST_TEST(cb4[0] == 6); 1225 BOOST_TEST(cb4[1] == 6); 1226 BOOST_TEST(cb4[2] == 6); 1227 BOOST_TEST(cb4[3] == 6); 1228 BOOST_TEST(cb4[4] == 3); 1229 BOOST_TEST(cb4[5] == 4); 1230 BOOST_TEST(cb5.size() == 3); 1231 BOOST_TEST(cb5[0] == 3); 1232 BOOST_TEST(cb5[1] == 3); 1233 BOOST_TEST(cb5[2] == 2); 1234 1235 generic_test(cb1); 1236 generic_test(cb2); 1237 generic_test(cb3); 1238 generic_test(cb4); 1239 generic_test(cb5); 1240} 1241 1242void insert_range_test() { 1243 1244 vector<int> v; 1245 v.push_back(11); 1246 v.push_back(12); 1247 v.push_back(13); 1248 CB_CONTAINER<MyInteger> cb1(4); 1249 cb1.push_back(1); 1250 cb1.push_back(2); 1251 cb1.push_back(3); 1252 cb1.insert(cb1.begin() + 1, v.begin(), v.end()); 1253 CB_CONTAINER<MyInteger> cb2(2, 2); 1254 cb2.insert(cb2.end(), v.begin(), v.end()); 1255 CB_CONTAINER<MyInteger> cb3(5); 1256 cb3.insert(cb3.end(), v.end(), v.end()); 1257 CB_CONTAINER<MyInteger> cb4(5); 1258 cb4.insert(cb4.end(), v.begin(), v.begin() + 1); 1259 MyInteger array[] = { 5, 6, 7, 8, 9 }; 1260 CB_CONTAINER<MyInteger> cb5(6); 1261 cb5.push_back(1); 1262 cb5.push_back(2); 1263 cb5.push_back(3); 1264 cb5.push_back(4); 1265 cb5.insert(cb5.begin() + 2, array, array + 5); 1266 cb5.insert(cb5.begin(), array, array + 5); 1267 1268 BOOST_TEST(cb1.full()); 1269 BOOST_TEST(cb1[0] == 12); 1270 BOOST_TEST(cb1[1] == 13); 1271 BOOST_TEST(cb1[2] == 2); 1272 BOOST_TEST(cb1[3] == 3); 1273 BOOST_TEST(cb2[0] == 12); 1274 BOOST_TEST(cb2[1] == 13); 1275 BOOST_TEST(cb3.empty()); 1276 BOOST_TEST(cb4[0] == 11); 1277 BOOST_TEST(cb4.size() == 1); 1278 BOOST_TEST(cb5.size() == 6); 1279 BOOST_TEST(cb5[0] == 6); 1280 BOOST_TEST(cb5[1] == 7); 1281 BOOST_TEST(cb5[2] == 8); 1282 BOOST_TEST(cb5[3] == 9); 1283 BOOST_TEST(cb5[4] == 3); 1284 BOOST_TEST(cb5[5] == 4); 1285 1286#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) 1287 1288 v.clear(); 1289 v.push_back(1); 1290 v.push_back(2); 1291 v.push_back(3); 1292 v.push_back(4); 1293 v.push_back(5); 1294 1295 CB_CONTAINER<int> cb6(4); 1296 cb6.push_back(0); 1297 cb6.push_back(-1); 1298 cb6.push_back(-2); 1299 cb6.insert(cb6.begin() + 1, MyInputIterator(v.begin()), MyInputIterator(v.end())); 1300 v.clear(); 1301 v.push_back(11); 1302 v.push_back(12); 1303 v.push_back(13); 1304 CB_CONTAINER<int> cb7(4); 1305 cb7.push_back(1); 1306 cb7.push_back(2); 1307 cb7.push_back(3); 1308 cb7.insert(cb7.begin() + 1, MyInputIterator(v.begin()), MyInputIterator(v.end())); 1309 CB_CONTAINER<int> cb8(2, 2); 1310 cb8.insert(cb8.end(), MyInputIterator(v.begin()), MyInputIterator(v.end())); 1311 CB_CONTAINER<int> cb9(5); 1312 cb9.insert(cb9.end(), MyInputIterator(v.end()), MyInputIterator(v.end())); 1313 CB_CONTAINER<int> cb10(5); 1314 cb10.insert(cb10.end(), MyInputIterator(v.begin()), MyInputIterator(v.begin() + 1)); 1315 v.clear(); 1316 v.push_back(5); 1317 v.push_back(6); 1318 v.push_back(7); 1319 v.push_back(8); 1320 v.push_back(9); 1321 CB_CONTAINER<int> cb11(6); 1322 cb11.push_back(1); 1323 cb11.push_back(2); 1324 cb11.push_back(3); 1325 cb11.push_back(4); 1326 cb11.insert(cb11.begin() + 2, MyInputIterator(v.begin()), MyInputIterator(v.begin() + 5)); 1327 cb11.insert(cb11.begin(), MyInputIterator(v.begin()), MyInputIterator(v.begin() + 5)); 1328 1329 BOOST_TEST(cb6.capacity() == 4); 1330 BOOST_TEST(cb6[0] == 4); 1331 BOOST_TEST(cb6[3] == -2); 1332 BOOST_TEST(cb7.full()); 1333 BOOST_TEST(cb7[0] == 12); 1334 BOOST_TEST(cb7[1] == 13); 1335 BOOST_TEST(cb7[2] == 2); 1336 BOOST_TEST(cb7[3] == 3); 1337 BOOST_TEST(cb8[0] == 12); 1338 BOOST_TEST(cb8[1] == 13); 1339 BOOST_TEST(cb9.empty()); 1340 BOOST_TEST(cb10[0] == 11); 1341 BOOST_TEST(cb10.size() == 1); 1342 BOOST_TEST(cb11.size() == 6); 1343 BOOST_TEST(cb11[0] == 6); 1344 BOOST_TEST(cb11[1] == 7); 1345 BOOST_TEST(cb11[2] == 8); 1346 BOOST_TEST(cb11[3] == 9); 1347 BOOST_TEST(cb11[4] == 3); 1348 BOOST_TEST(cb11[5] == 4); 1349 1350#endif // #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) 1351 1352 generic_test(cb1); 1353 generic_test(cb2); 1354 generic_test(cb3); 1355 generic_test(cb4); 1356 generic_test(cb5); 1357} 1358 1359void push_front_test() { 1360 1361 CB_CONTAINER<MyDefaultConstructible> cb1(5); 1362 cb1.push_front(); 1363 cb1.push_front(MyDefaultConstructible(2)); 1364 BOOST_TEST(cb1[0].m_n == 2); 1365 BOOST_TEST(cb1[1].m_n == 1); 1366 1367 CB_CONTAINER<MyInteger> cb2(5); 1368 cb2.push_front(); 1369 BOOST_TEST(cb2.front() == CB_CONTAINER<MyInteger>::value_type()); 1370 1371 cb2.push_front(1); 1372 BOOST_TEST(cb2.front() == 1); 1373 1374 CB_CONTAINER<MyInteger> cb3(0); 1375 cb3.push_front(10); 1376 BOOST_TEST(cb3.empty()); 1377 1378 generic_test(cb2); 1379 generic_test(cb3); 1380} 1381 1382void pop_front_test() { 1383 1384 CB_CONTAINER<MyInteger> cb(4); 1385 cb.push_front(1); 1386 cb.push_front(2); 1387 cb.push_front(3); 1388 cb.push_front(4); 1389 cb.push_front(5); 1390 cb.pop_front(); 1391 1392 BOOST_TEST(cb.size() == 3); 1393 BOOST_TEST(!cb.full()); 1394 BOOST_TEST(cb[0] == 4); 1395 1396 generic_test(cb); 1397} 1398 1399void rinsert_test() { 1400 1401 CB_CONTAINER<MyInteger> cb1(4); 1402 cb1.push_front(1); 1403 cb1.push_front(2); 1404 cb1.push_front(3); 1405 CB_CONTAINER<MyInteger>::iterator it1 = cb1.begin() + 1; 1406 it1 = cb1.rinsert(it1, 10); 1407 CB_CONTAINER<MyInteger> cb2(4); 1408 cb2.push_front(1); 1409 cb2.rinsert(cb2.begin()); 1410 cb2.rinsert(cb2.begin(), -1); 1411 CB_CONTAINER<MyInteger>::iterator it2 = cb2.end() - 2; 1412 it2 = cb2.rinsert(it2, 5); 1413 CB_CONTAINER<MyInteger> cb3(2); 1414 cb3.rinsert(cb3.begin(), 10); 1415 cb3.rinsert(cb3.begin(), 20); 1416 cb3.rinsert(cb3.end(), 30); 1417 cb3.rinsert(cb3.begin(), 40); 1418 CB_CONTAINER<MyInteger> cb4(4); 1419 cb4.push_back(1); 1420 cb4.push_back(2); 1421 cb4.push_back(3); 1422 CB_CONTAINER<MyInteger>::iterator it3 = cb4.begin() + 1; 1423 it3 = cb4.rinsert(it3, 10); 1424 CB_CONTAINER<MyInteger> cb5(4); 1425 cb5.push_back(1); 1426 cb5.rinsert(cb5.begin(), 0); 1427 cb5.rinsert(cb5.begin(), -1); 1428 CB_CONTAINER<MyInteger>::iterator it4 = cb5.begin() + 1; 1429 it4 = cb5.rinsert(it4, 5); 1430 CB_CONTAINER<MyInteger> cb6(2); 1431 cb6.rinsert(cb6.end(), 10); 1432 cb6.rinsert(cb6.end(), 20); 1433 cb6.rinsert(cb6.begin(), 30); 1434 cb6.rinsert(cb6.end(), 40); 1435 CB_CONTAINER<MyInteger> cb7(6); 1436 cb7.push_back(1); 1437 cb7.push_back(2); 1438 cb7.push_back(3); 1439 cb7.push_back(4); 1440 cb7.rinsert(cb7.begin() + 2, 5, 6); 1441 1442 BOOST_TEST(cb1[1] == 10); 1443 BOOST_TEST(*it1 == 10); 1444 BOOST_TEST(cb1.full()); 1445 BOOST_TEST(cb2[1] == 5); 1446 BOOST_TEST(*it2 == 5); 1447 BOOST_TEST(cb2.full()); 1448 BOOST_TEST(cb2[3] == 1); 1449 BOOST_TEST(cb3[0] == 40); 1450 BOOST_TEST(cb3[1] == 20); 1451 BOOST_TEST(cb4[1] == 10); 1452 BOOST_TEST(*it3 == 10); 1453 BOOST_TEST(cb4.full()); 1454 BOOST_TEST(cb5[1] == 5); 1455 BOOST_TEST(*it4 == 5); 1456 BOOST_TEST(cb5.full()); 1457 BOOST_TEST(cb6[0] == 30); 1458 BOOST_TEST(cb6[1] == 10); 1459 BOOST_TEST(cb7.size() == 6); 1460 BOOST_TEST(cb7[0] == 1); 1461 BOOST_TEST(cb7[1] == 2); 1462 BOOST_TEST(cb7[2] == 6); 1463 BOOST_TEST(cb7[3] == 6); 1464 BOOST_TEST(cb7[4] == 6); 1465 BOOST_TEST(cb7[5] == 6); 1466 1467 generic_test(cb1); 1468 generic_test(cb2); 1469 generic_test(cb3); 1470 generic_test(cb4); 1471 generic_test(cb5); 1472 generic_test(cb6); 1473 generic_test(cb7); 1474} 1475 1476void rinsert_n_test() { 1477 1478 CB_CONTAINER<MyInteger> cb1(4); 1479 cb1.push_front(1); 1480 cb1.push_front(2); 1481 cb1.push_front(3); 1482 cb1.rinsert(cb1.begin() + 1, 2, 10); 1483 CB_CONTAINER<MyInteger> cb2(2, 3); 1484 cb2.rinsert(cb2.begin(), 10, 5); 1485 CB_CONTAINER<MyInteger> cb3(4); 1486 cb3.rinsert(cb3.end(), 1, 6); 1487 CB_CONTAINER<MyInteger> cb4(4); 1488 cb4.push_back(1); 1489 cb4.push_back(2); 1490 cb4.push_back(3); 1491 cb4.rinsert(cb4.begin() + 1, 2, 10); 1492 MyInteger array[] = { 5, 6, 7, 8, 9 }; 1493 CB_CONTAINER<MyInteger> cb5(6); 1494 cb5.push_back(1); 1495 cb5.push_back(2); 1496 cb5.push_back(3); 1497 cb5.push_back(4); 1498 cb5.rinsert(cb5.begin() + 2, array, array + 5); 1499 cb5.rinsert(cb5.end(), array, array + 5); 1500 1501 BOOST_TEST(cb1.full()); 1502 BOOST_TEST(cb1[0] == 3); 1503 BOOST_TEST(cb1[1] == 10); 1504 BOOST_TEST(cb1[2] == 10); 1505 BOOST_TEST(cb1[3] == 2); 1506 BOOST_TEST(cb2[0] == 5); 1507 BOOST_TEST(cb2[1] == 5); 1508 BOOST_TEST(cb3[0] == 6); 1509 BOOST_TEST(cb3.size() == 1); 1510 BOOST_TEST(cb4.full()); 1511 BOOST_TEST(cb4[0] == 1); 1512 BOOST_TEST(cb4[1] == 10); 1513 BOOST_TEST(cb4[2] == 10); 1514 BOOST_TEST(cb4[3] == 2); 1515 BOOST_TEST(cb5.size() == 6); 1516 BOOST_TEST(cb5[0] == 1); 1517 BOOST_TEST(cb5[1] == 2); 1518 BOOST_TEST(cb5[2] == 5); 1519 BOOST_TEST(cb5[3] == 6); 1520 BOOST_TEST(cb5[4] == 7); 1521 BOOST_TEST(cb5[5] == 8); 1522 1523 generic_test(cb1); 1524 generic_test(cb2); 1525 generic_test(cb3); 1526 generic_test(cb4); 1527 generic_test(cb5); 1528} 1529 1530void rinsert_range_test() { 1531 1532 vector<int> v; 1533 v.push_back(11); 1534 v.push_back(12); 1535 v.push_back(13); 1536 v.push_back(14); 1537 CB_CONTAINER<MyInteger> cb1(4); 1538 cb1.push_back(1); 1539 cb1.push_back(2); 1540 cb1.push_back(3); 1541 cb1.rinsert(cb1.begin() + 1, v.begin(), v.end()); 1542 CB_CONTAINER<MyInteger> cb2(2, 2); 1543 cb2.rinsert(cb2.begin(), v.begin(), v.end()); 1544 CB_CONTAINER<MyInteger> cb3(5); 1545 cb3.rinsert(cb3.begin(), v.end(), v.end()); 1546 CB_CONTAINER<MyInteger> cb4(5); 1547 cb4.rinsert(cb4.begin(), v.begin(), v.begin() + 1); 1548 1549 BOOST_TEST(cb1.full()); 1550 BOOST_TEST(cb1[0] == 1); 1551 BOOST_TEST(cb1[1] == 11); 1552 BOOST_TEST(cb1[2] == 12); 1553 BOOST_TEST(cb1[3] == 13); 1554 BOOST_TEST(cb2[0] == 11); 1555 BOOST_TEST(cb2[1] == 12); 1556 BOOST_TEST(cb3.empty()); 1557 BOOST_TEST(cb4[0] == 11); 1558 BOOST_TEST(cb4.size() == 1); 1559 1560#if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) 1561 1562 v.clear(); 1563 v.push_back(1); 1564 v.push_back(2); 1565 v.push_back(3); 1566 v.push_back(4); 1567 v.push_back(5); 1568 1569 CB_CONTAINER<int> cb10(4); 1570 cb10.push_back(0); 1571 cb10.push_back(-1); 1572 cb10.push_back(-2); 1573 cb10.rinsert(cb10.begin() + 1, MyInputIterator(v.begin()), MyInputIterator(v.end())); 1574 v.clear(); 1575 v.push_back(11); 1576 v.push_back(12); 1577 v.push_back(13); 1578 v.push_back(14); 1579 CB_CONTAINER<int> cb11(4); 1580 cb11.push_back(1); 1581 cb11.push_back(2); 1582 cb11.push_back(3); 1583 cb11.rinsert(cb11.begin() + 1, MyInputIterator(v.begin()), MyInputIterator(v.end())); 1584 CB_CONTAINER<int> cb12(2, 2); 1585 cb12.rinsert(cb12.begin(), MyInputIterator(v.begin()), MyInputIterator(v.end())); 1586 CB_CONTAINER<int> cb13(5); 1587 cb13.rinsert(cb13.begin(), MyInputIterator(v.end()), MyInputIterator(v.end())); 1588 CB_CONTAINER<int> cb14(5); 1589 cb14.rinsert(cb14.begin(), MyInputIterator(v.begin()), MyInputIterator(v.begin() + 1)); 1590 1591 BOOST_TEST(cb10.capacity() == 4); 1592 BOOST_TEST(cb10[0] == 0); 1593 BOOST_TEST(cb10[3] == 3); 1594 BOOST_TEST(cb11.full()); 1595 BOOST_TEST(cb11[0] == 1); 1596 BOOST_TEST(cb11[1] == 11); 1597 BOOST_TEST(cb11[2] == 12); 1598 BOOST_TEST(cb11[3] == 13); 1599 BOOST_TEST(cb12[0] == 11); 1600 BOOST_TEST(cb12[1] == 12); 1601 BOOST_TEST(cb13.empty()); 1602 BOOST_TEST(cb14[0] == 11); 1603 BOOST_TEST(cb14.size() == 1); 1604 1605#endif // #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS) 1606 1607 generic_test(cb1); 1608 generic_test(cb2); 1609 generic_test(cb3); 1610 generic_test(cb4); 1611} 1612 1613void erase_test() { 1614 1615 CB_CONTAINER<MyInteger> cb1(4); 1616 cb1.push_back(1); 1617 cb1.push_back(2); 1618 cb1.push_back(3); 1619 CB_CONTAINER<MyInteger>::iterator it1 = cb1.erase(cb1.begin() + 1); 1620 1621 CB_CONTAINER<MyInteger> cb2(1, 1); 1622 CB_CONTAINER<MyInteger>::iterator it2 = cb2.erase(cb2.begin()); 1623 1624 CB_CONTAINER<MyInteger> cb3(4); 1625 cb3.push_back(1); 1626 cb3.push_back(2); 1627 cb3.push_back(3); 1628 CB_CONTAINER<MyInteger>::iterator it3 = cb3.erase(cb3.begin() + 2); 1629 1630 BOOST_TEST(cb1.size() == 2); 1631 BOOST_TEST(cb1.capacity() == 4); 1632 BOOST_TEST(*it1 == 3); 1633 BOOST_TEST(cb1[0] == 1); 1634 BOOST_TEST(cb1[1] == 3); 1635 BOOST_TEST(cb2.size() == 0); 1636 BOOST_TEST(cb2.capacity() == 1); 1637 BOOST_TEST(it2 == cb2.end()); 1638 BOOST_TEST(cb3.size() == 2); 1639 BOOST_TEST(cb3.capacity() == 4); 1640 BOOST_TEST(it3 == cb3.end()); 1641 BOOST_TEST(cb3[0] == 1); 1642 BOOST_TEST(cb3[1] == 2); 1643 1644 generic_test(cb1); 1645 generic_test(cb2); 1646 generic_test(cb3); 1647} 1648 1649void erase_range_test() { 1650 1651 CB_CONTAINER<MyInteger> cb1(4); 1652 cb1.push_back(1); 1653 cb1.push_back(2); 1654 cb1.push_back(3); 1655 cb1.push_back(4); 1656 CB_CONTAINER<MyInteger>::iterator it1 = cb1.erase(cb1.begin() + 1, cb1.begin() + 3); 1657 1658 CB_CONTAINER<MyInteger> cb2(4); 1659 cb2.push_back(1); 1660 cb2.push_back(2); 1661 cb2.push_back(3); 1662 cb2.push_back(4); 1663 CB_CONTAINER<MyInteger>::iterator it2 = cb2.erase(cb2.begin(), cb2.begin()); 1664 1665 CB_CONTAINER<MyInteger> cb3(4); 1666 cb3.push_back(1); 1667 cb3.push_back(2); 1668 cb3.push_back(3); 1669 cb3.push_back(4); 1670 CB_CONTAINER<MyInteger>::iterator it3 = cb3.erase(cb3.begin() + 2, cb3.end()); 1671 1672 CB_CONTAINER<MyInteger> cb4(10, 1); 1673 CB_CONTAINER<MyInteger>::iterator it4 = cb4.erase(cb4.begin(), cb4.end()); 1674 1675 BOOST_TEST(cb1.size() == 2); 1676 BOOST_TEST(cb1.capacity() == 4); 1677 BOOST_TEST(cb1[0] == 1); 1678 BOOST_TEST(cb1[1] == 4); 1679 BOOST_TEST(*it1 == 4); 1680 BOOST_TEST(cb2.size() == 4); 1681 BOOST_TEST(cb2[0] == 1); 1682 BOOST_TEST(cb2[3] == 4); 1683 BOOST_TEST(*it2 == 1); 1684 BOOST_TEST(cb3.size() == 2); 1685 BOOST_TEST(cb3.capacity() == 4); 1686 BOOST_TEST(cb3[0] == 1); 1687 BOOST_TEST(cb3[1] == 2); 1688 BOOST_TEST(it3 == cb3.end()); 1689 BOOST_TEST(cb4.size() == 0); 1690 BOOST_TEST(cb4.capacity() == 10); 1691 BOOST_TEST(it4 == cb4.end()); 1692 1693 generic_test(cb1); 1694 generic_test(cb2); 1695 generic_test(cb3); 1696 generic_test(cb4); 1697} 1698 1699void rerase_test() { 1700 1701 CB_CONTAINER<MyInteger> cb1(4); 1702 cb1.push_back(1); 1703 cb1.push_back(2); 1704 cb1.push_back(3); 1705 CB_CONTAINER<MyInteger>::iterator it1 = cb1.rerase(cb1.begin() + 1); 1706 1707 CB_CONTAINER<MyInteger> cb2(1, 1); 1708 CB_CONTAINER<MyInteger>::iterator it2 = cb2.rerase(cb2.begin()); 1709 1710 CB_CONTAINER<MyInteger> cb3(4); 1711 cb3.push_back(1); 1712 cb3.push_back(2); 1713 cb3.push_back(3); 1714 CB_CONTAINER<MyInteger>::iterator it3 = cb3.rerase(cb3.begin()); 1715 1716 BOOST_TEST(cb1.size() == 2); 1717 BOOST_TEST(cb1.capacity() == 4); 1718 BOOST_TEST(*it1 == 1); 1719 BOOST_TEST(cb1[0] == 1); 1720 BOOST_TEST(cb1[1] == 3); 1721 BOOST_TEST(cb2.size() == 0); 1722 BOOST_TEST(cb2.capacity() == 1); 1723 BOOST_TEST(it2 == cb2.begin()); 1724 BOOST_TEST(cb3.size() == 2); 1725 BOOST_TEST(cb3.capacity() == 4); 1726 BOOST_TEST(it3 == cb3.begin()); 1727 BOOST_TEST(*it3 == 2); 1728 BOOST_TEST(cb3[0] == 2); 1729 BOOST_TEST(cb3[1] == 3); 1730 1731 generic_test(cb1); 1732 generic_test(cb2); 1733 generic_test(cb3); 1734} 1735 1736void rerase_range_test() { 1737 1738 CB_CONTAINER<MyInteger> cb1(4); 1739 cb1.push_back(1); 1740 cb1.push_back(2); 1741 cb1.push_back(3); 1742 cb1.push_back(4); 1743 CB_CONTAINER<MyInteger>::iterator it1 = cb1.rerase(cb1.begin() + 1, cb1.begin() + 3); 1744 1745 CB_CONTAINER<MyInteger> cb2(4); 1746 cb2.push_back(1); 1747 cb2.push_back(2); 1748 cb2.push_back(3); 1749 cb2.push_back(4); 1750 CB_CONTAINER<MyInteger>::iterator it2 = cb2.rerase(cb2.begin(), cb2.begin()); 1751 1752 CB_CONTAINER<MyInteger> cb3(4); 1753 cb3.push_back(1); 1754 cb3.push_back(2); 1755 cb3.push_back(3); 1756 cb3.push_back(4); 1757 CB_CONTAINER<MyInteger>::iterator it3 = cb3.rerase(cb3.begin(), cb3.begin() + 2); 1758 1759 CB_CONTAINER<MyInteger> cb4(10, 1); 1760 CB_CONTAINER<MyInteger>::iterator it4 = cb4.rerase(cb4.begin(), cb4.end()); 1761 1762 BOOST_TEST(cb1.size() == 2); 1763 BOOST_TEST(cb1.capacity() == 4); 1764 BOOST_TEST(cb1[0] == 1); 1765 BOOST_TEST(cb1[1] == 4); 1766 BOOST_TEST(*it1 == 1); 1767 BOOST_TEST(cb2.size() == 4); 1768 BOOST_TEST(cb2[0] == 1); 1769 BOOST_TEST(cb2[3] == 4); 1770 BOOST_TEST(*it2 == 1); 1771 BOOST_TEST(cb3.size() == 2); 1772 BOOST_TEST(cb3.capacity() == 4); 1773 BOOST_TEST(cb3[0] == 3); 1774 BOOST_TEST(cb3[1] == 4); 1775 BOOST_TEST(it3 == cb3.begin()); 1776 BOOST_TEST(cb4.size() == 0); 1777 BOOST_TEST(cb4.capacity() == 10); 1778 BOOST_TEST(it4 == cb4.begin()); 1779 1780 generic_test(cb1); 1781 generic_test(cb2); 1782 generic_test(cb3); 1783 generic_test(cb4); 1784} 1785 1786void clear_test() { 1787 1788 CB_CONTAINER<MyInteger> cb(4); 1789 cb.push_back(1); 1790 cb.push_back(2); 1791 cb.push_back(3); 1792 cb.push_back(4); 1793 cb.clear(); 1794 1795 BOOST_TEST(cb.empty()); 1796 1797 generic_test(cb); 1798} 1799 1800void equality_test() { 1801 1802 CB_CONTAINER<MyInteger> cb1(4); 1803 cb1.push_back(1); 1804 cb1.push_back(2); 1805 cb1.push_back(3); 1806 cb1.push_back(4); 1807 CB_CONTAINER<MyInteger> cb2(10); 1808 cb2.push_back(1); 1809 cb2.push_back(2); 1810 cb2.push_back(3); 1811 cb2.push_back(4); 1812 1813 BOOST_TEST(cb1 == cb2); 1814 BOOST_TEST(!(cb2 != cb1)); 1815 1816 generic_test(cb1); 1817 generic_test(cb2); 1818} 1819 1820void lexicographical_comparison_test() { 1821 1822 CB_CONTAINER<char> cb1(10); 1823 cb1.push_back('a'); 1824 cb1.push_back('d'); 1825 cb1.push_back('a'); 1826 cb1.push_back('m'); 1827 CB_CONTAINER<char> cb2(5); 1828 cb2.push_back('j'); 1829 cb2.push_back('o'); 1830 cb2.push_back('h'); 1831 cb2.push_back('n'); 1832 1833 BOOST_TEST(cb2 > cb1); 1834 BOOST_TEST(cb1 < cb2); 1835} 1836 1837void assign_range_test() { 1838 1839 vector<int> v; 1840 v.push_back(11); 1841 v.push_back(12); 1842 v.push_back(13); 1843 CB_CONTAINER<MyInteger> cb1(4); 1844 cb1.push_back(1); 1845 cb1.push_back(2); 1846 cb1.push_back(3); 1847 cb1.assign(v.begin() + 1, v.end()); 1848 CB_CONTAINER<MyInteger> cb2(2); 1849 cb2.push_back(1); 1850 cb2.push_back(2); 1851 cb2.assign(v.begin(), v.end()); 1852 1853 BOOST_TEST(cb1.capacity() == 2); 1854 BOOST_TEST(cb1[0] == 12); 1855 BOOST_TEST(cb1[1] == 13); 1856 BOOST_TEST(cb2.full()); 1857 BOOST_TEST(cb2.capacity() == 3); 1858 BOOST_TEST(cb2[0] == 11); 1859 BOOST_TEST(cb2[1] == 12); 1860 BOOST_TEST(cb2[2] == 13); 1861 BOOST_TEST(cb2.size() == (size_t)distance(v.begin(), v.end())); 1862 1863 generic_test(cb1); 1864 generic_test(cb2); 1865} 1866 1867// test of the example (introduced in the documentation) 1868void example_test() { 1869 1870 CB_CONTAINER<int> cb1(3); 1871 cb1.push_back(1); 1872 cb1.push_back(2); 1873 1874 BOOST_TEST(cb1[0] == 1); 1875 BOOST_TEST(cb1[1] == 2); 1876 BOOST_TEST(!cb1.full()); 1877 BOOST_TEST(cb1.size() == 2); 1878 BOOST_TEST(cb1.capacity() == 3); 1879 1880 cb1.push_back(3); 1881 cb1.push_back(4); 1882 int sum = accumulate(cb1.begin(), cb1.end(), 0); 1883 1884 BOOST_TEST(cb1[0] == 2); 1885 BOOST_TEST(cb1[1] == 3); 1886 BOOST_TEST(cb1[2] == 4); 1887 BOOST_TEST(*cb1.begin() == 2); 1888 BOOST_TEST(cb1.front() == 2); 1889 BOOST_TEST(cb1.back() == 4); 1890 BOOST_TEST(sum == 9); 1891 BOOST_TEST(cb1.full()); 1892 BOOST_TEST(cb1.size() == 3); 1893 BOOST_TEST(cb1.capacity() == 3); 1894 1895 CB_CONTAINER<int> cb2(5, 1); 1896 cb2.insert(cb2.begin(), 2); 1897 1898 BOOST_TEST(cb2[0] == 1); 1899 BOOST_TEST(cb2[1] == 1); 1900 BOOST_TEST(cb2[2] == 1); 1901 BOOST_TEST(cb2[3] == 1); 1902 BOOST_TEST(cb2[4] == 1); 1903 1904 vector<int> v; 1905 v.push_back(100); 1906 v.push_back(200); 1907 v.push_back(300); 1908 cb2.insert(cb2.begin() + 1, v.begin(), v.end()); 1909 1910 BOOST_TEST(cb2[0] == 300); 1911 BOOST_TEST(cb2[1] == 1); 1912 BOOST_TEST(cb2[2] == 1); 1913 BOOST_TEST(cb2[3] == 1); 1914 BOOST_TEST(cb2[4] == 1); 1915 1916 CB_CONTAINER<int> cb3(3); 1917 cb3.push_back(1); 1918 cb3.push_back(2); 1919 cb3.push_back(3); 1920 1921 BOOST_TEST(cb3[0] == 1); 1922 BOOST_TEST(cb3[1] == 2); 1923 BOOST_TEST(cb3[2] == 3); 1924 1925 cb3.push_back(4); 1926 cb3.push_back(5); 1927 1928 BOOST_TEST(cb3[0] == 3); 1929 BOOST_TEST(cb3[1] == 4); 1930 BOOST_TEST(cb3[2] == 5); 1931 1932 cb3.pop_back(); 1933 cb3.pop_front(); 1934 1935 BOOST_TEST(cb3[0] == 4); 1936} 1937 1938void element_destruction_test() { 1939 1940 CB_CONTAINER<InstanceCounter> cb(5); 1941 cb.push_back(InstanceCounter()); 1942 cb.push_back(InstanceCounter()); 1943 cb.push_back(InstanceCounter()); 1944 int prevCount = InstanceCounter::count(); 1945 cb.clear(); 1946 1947 BOOST_TEST(cb.empty()); 1948 BOOST_TEST(prevCount == 3); 1949 BOOST_TEST(InstanceCounter::count() == 0); 1950} 1951 1952void const_methods_test() { 1953 1954 vector<int> v; 1955 v.push_back(1); 1956 v.push_back(2); 1957 v.push_back(3); 1958 v.push_back(4); 1959 v.push_back(5); 1960 const CB_CONTAINER<MyInteger> cb(5, v.begin(), v.end()); 1961 1962 BOOST_TEST(*cb.begin() == 1); 1963 BOOST_TEST(*(cb.end() - 1) == 5); 1964 BOOST_TEST(*cb.rbegin() == 5); 1965 BOOST_TEST(*(cb.rend() - 1) == 1); 1966 BOOST_TEST(cb[0] == 1); 1967 BOOST_TEST(cb.at(1) == 2); 1968 BOOST_TEST(cb.front() == 1); 1969 BOOST_TEST(cb.back() == 5); 1970} 1971 1972void rotate_test() { 1973 1974 CB_CONTAINER<MyInteger> cb1(10); 1975 cb1.push_back(1); 1976 cb1.push_back(2); 1977 cb1.push_back(3); 1978 cb1.push_back(4); 1979 cb1.push_back(5); 1980 cb1.push_back(6); 1981 cb1.push_back(7); 1982 CB_CONTAINER<MyInteger> cb2 = cb1; 1983 CB_CONTAINER<MyInteger>::iterator it1 = cb1.begin() + 2; 1984 int v1_0 = *it1; 1985 int v1_1 = *(it1 + 1); 1986 int v1_2 = *(it1 + 2); 1987 int v1_3 = *(it1 + 3); 1988 int v1_4 = *(it1 + 4); 1989 int v1_r1 = *(it1 - 1); 1990 int v1_r2 = *(it1 - 2); 1991 cb1.rotate(it1); 1992 rotate(cb2.begin(), cb2.begin() + 2, cb2.end()); 1993 1994 CB_CONTAINER<MyInteger> cb3(7); 1995 cb3.push_back(1); 1996 cb3.push_back(2); 1997 cb3.push_back(3); 1998 cb3.push_back(4); 1999 cb3.push_back(5); 2000 cb3.push_back(6); 2001 cb3.push_back(7); 2002 cb3.push_back(8); 2003 cb3.push_back(9); 2004 CB_CONTAINER<MyInteger> cb4 = cb3; 2005 CB_CONTAINER<MyInteger>::iterator it2 = cb3.begin() + 1; 2006 int v2_0 = *it2; 2007 int v2_1 = *(it2 + 1); 2008 int v2_2 = *(it2 + 2); 2009 int v2_3 = *(it2 + 3); 2010 int v2_4 = *(it2 + 4); 2011 int v2_5 = *(it2 + 5); 2012 int v2_r1 = *(it2 - 1); 2013 cb3.rotate(it2); 2014 rotate(cb4.begin(), cb4.begin() + 1, cb4.end()); 2015 2016 CB_CONTAINER<MyInteger> cb5(10); 2017 cb5.push_back(1); 2018 cb5.push_back(2); 2019 cb5.push_back(3); 2020 cb5.push_back(4); 2021 cb5.push_back(5); 2022 cb5.push_back(6); 2023 cb5.push_back(7); 2024 CB_CONTAINER<MyInteger> cb6 = cb5; 2025 CB_CONTAINER<MyInteger>::iterator it3 = cb5.begin() + 5; 2026 int v3_0 = *it3; 2027 int v3_1 = *(it3 + 1); 2028 int v3_r1 = *(it3 - 1); 2029 int v3_r2 = *(it3 - 2); 2030 int v3_r3 = *(it3 - 3); 2031 int v3_r4 = *(it3 - 4); 2032 int v3_r5 = *(it3 - 5); 2033 cb5.rotate(it3); 2034 rotate(cb6.begin(), cb6.begin() + 5, cb6.end()); 2035 2036 BOOST_TEST(!cb1.full()); 2037 BOOST_TEST(cb1 == cb2); 2038 BOOST_TEST(v1_0 == *it1); 2039 BOOST_TEST(v1_1 == *(it1 + 1)); 2040 BOOST_TEST(v1_2 == *(it1 + 2)); 2041 BOOST_TEST(v1_3 == *(it1 + 3)); 2042 BOOST_TEST(v1_4 == *(it1 + 4)); 2043 BOOST_TEST(v1_r1 == *(it1 + 6)); 2044 BOOST_TEST(v1_r2 == *(it1 + 5)); 2045 BOOST_TEST(cb1.begin() == it1); 2046 BOOST_TEST(v1_0 == cb1[0]); 2047 BOOST_TEST(v1_1 == cb1[1]); 2048 BOOST_TEST(v1_2 == cb1[2]); 2049 BOOST_TEST(v1_3 == cb1[3]); 2050 BOOST_TEST(v1_4 == cb1[4]); 2051 BOOST_TEST(v1_r1 == cb1[6]); 2052 BOOST_TEST(v1_r2 == cb1[5]); 2053 BOOST_TEST(cb3.full()); 2054 BOOST_TEST(cb3 == cb4); 2055 BOOST_TEST(v2_0 == *it2); 2056 BOOST_TEST(v2_1 == *(it2 + 1)); 2057 BOOST_TEST(v2_2 == *(it2 + 2)); 2058 BOOST_TEST(v2_3 == *(it2 + 3)); 2059 BOOST_TEST(v2_4 == *(it2 + 4)); 2060 BOOST_TEST(v2_5 == *(it2 + 5)); 2061 BOOST_TEST(v2_r1 == *(it2 + 6)); 2062 BOOST_TEST(cb3.begin() == it2); 2063 BOOST_TEST(v2_0 == cb3[0]); 2064 BOOST_TEST(v2_1 == cb3[1]); 2065 BOOST_TEST(v2_2 == cb3[2]); 2066 BOOST_TEST(v2_3 == cb3[3]); 2067 BOOST_TEST(v2_4 == cb3[4]); 2068 BOOST_TEST(v2_5 == cb3[5]); 2069 BOOST_TEST(v2_r1 == cb3[6]); 2070 BOOST_TEST(!cb5.full()); 2071 BOOST_TEST(cb5 == cb6); 2072 BOOST_TEST(v3_0 == cb5[0]); 2073 BOOST_TEST(v3_1 == cb5[1]); 2074 BOOST_TEST(v3_r1 == cb5[6]); 2075 BOOST_TEST(v3_r2 == cb5[5]); 2076 BOOST_TEST(v3_r3 == cb5[4]); 2077 BOOST_TEST(v3_r4 == cb5[3]); 2078 BOOST_TEST(v3_r5 == cb5[2]); 2079 2080 generic_test(cb1); 2081 generic_test(cb2); 2082 generic_test(cb3); 2083 generic_test(cb4); 2084 generic_test(cb5); 2085 generic_test(cb6); 2086} 2087 2088int MyInteger::ms_exception_trigger = 0; 2089int InstanceCounter::ms_count = 0; 2090 2091void move_container_on_cpp11() { 2092#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES 2093 CB_CONTAINER<MyInteger> cb1(10); 2094 cb1.push_back(1); 2095 cb1.push_back(2); 2096 cb1.push_back(3); 2097 cb1.push_back(4); 2098 cb1.push_back(5); 2099 cb1.push_back(6); 2100 2101 // Checking move constructor 2102 CB_CONTAINER<MyInteger> cb2(static_cast<CB_CONTAINER<MyInteger>&& >(cb1)); 2103 CB_CONTAINER<MyInteger>::iterator it2 = cb2.begin() + 1; 2104 2105 BOOST_TEST(cb1.empty()); 2106 BOOST_TEST(!cb2.empty()); 2107 BOOST_TEST(it2[0] == 2); 2108 BOOST_TEST(it2[-1] == 1); 2109 BOOST_TEST(it2[2] == 4); 2110 2111 // Checking move assignment 2112 cb1 = static_cast<CB_CONTAINER<MyInteger>&& >(cb2); 2113 CB_CONTAINER<MyInteger>::iterator it1 = cb1.begin() + 1; 2114 2115 BOOST_TEST(!cb1.empty()); 2116 BOOST_TEST(cb2.empty()); 2117 BOOST_TEST(it1[0] == 2); 2118 BOOST_TEST(it1[-1] == 1); 2119 BOOST_TEST(it1[2] == 4); 2120#endif 2121} 2122 2123 2124struct noncopyable_movable_except_t 2125{ 2126private: 2127 BOOST_MOVABLE_BUT_NOT_COPYABLE(noncopyable_movable_except_t) 2128 bool is_moved_; 2129 int value_; 2130public: 2131 static int next_value; 2132 2133 explicit noncopyable_movable_except_t() 2134 : is_moved_(false) 2135 , value_(next_value ++) 2136 {} 2137 2138 noncopyable_movable_except_t(BOOST_RV_REF(noncopyable_movable_except_t) x) { 2139 is_moved_ = x.is_moved_; 2140 value_ = x.value_; 2141 x.is_moved_ = true; 2142 } 2143 2144 noncopyable_movable_except_t& operator=(BOOST_RV_REF(noncopyable_movable_except_t) x) { 2145 is_moved_ = x.is_moved_; 2146 value_ = x.value_; 2147 x.is_moved_ = true; 2148 return *this; 2149 } 2150 2151 bool is_moved() const { 2152 return is_moved_; 2153 } 2154 2155 int value() const { 2156 return value_; 2157 } 2158 2159 void reinit() { is_moved_ = false; value_ = next_value ++; } 2160}; 2161 2162struct noncopyable_movable_noexcept_t 2163{ 2164private: 2165 BOOST_MOVABLE_BUT_NOT_COPYABLE(noncopyable_movable_noexcept_t) 2166 bool is_moved_; 2167 int value_; 2168public: 2169 static int next_value; 2170 2171 explicit noncopyable_movable_noexcept_t() 2172 : is_moved_(false) 2173 , value_(next_value ++) 2174 {} 2175 2176 noncopyable_movable_noexcept_t(BOOST_RV_REF(noncopyable_movable_noexcept_t) x) BOOST_NOEXCEPT { 2177 is_moved_ = x.is_moved_; 2178 value_ = x.value_; 2179 x.is_moved_ = true; 2180 } 2181 2182 noncopyable_movable_noexcept_t& operator=(BOOST_RV_REF(noncopyable_movable_noexcept_t) x) BOOST_NOEXCEPT { 2183 is_moved_ = x.is_moved_; 2184 value_ = x.value_; 2185 x.is_moved_ = true; 2186 return *this; 2187 } 2188 2189 bool is_moved() const { 2190 return is_moved_; 2191 } 2192 2193 int value() const { 2194 return value_; 2195 } 2196 2197 void reinit() { is_moved_ = false; value_ = next_value ++; } 2198}; 2199 2200#if defined(BOOST_NO_CXX11_NOEXCEPT) || !defined(BOOST_IS_NOTHROW_MOVE_CONSTRUCT) 2201namespace boost { 2202 template <> 2203 struct is_nothrow_move_constructible<noncopyable_movable_noexcept_t> 2204 : boost::true_type 2205 {}; 2206} 2207#endif 2208 2209int noncopyable_movable_noexcept_t::next_value = 1; 2210int noncopyable_movable_except_t::next_value = 1; 2211 2212template <class T> 2213void move_container_values_impl() { 2214 typedef T noncopyable_movable_test_t; 2215 noncopyable_movable_test_t::next_value = 1; 2216 2217 CB_CONTAINER<noncopyable_movable_test_t> cb1(40); 2218 noncopyable_movable_test_t var; 2219 cb1.push_back(boost::move(var)); 2220 BOOST_TEST(!cb1.back().is_moved()); 2221 BOOST_TEST(cb1.back().value() == 1); 2222 BOOST_TEST(var.is_moved()); 2223 BOOST_TEST(cb1.size() == 1); 2224 2225 var.reinit(); 2226 cb1.push_front(boost::move(var)); 2227 BOOST_TEST(!cb1.front().is_moved()); 2228 BOOST_TEST(cb1.front().value() == 2); 2229 BOOST_TEST(var.is_moved()); 2230 BOOST_TEST(cb1.size() == 2); 2231 2232 cb1.push_back(); 2233 BOOST_TEST(!cb1.back().is_moved()); 2234 BOOST_TEST(cb1.back().value() == 3); 2235 BOOST_TEST(cb1.size() == 3); 2236 2237 cb1.push_front(); 2238 BOOST_TEST(!cb1.front().is_moved()); 2239 BOOST_TEST(cb1.front().value() == 4); 2240 BOOST_TEST(cb1.size() == 4); 2241 2242 cb1.insert(cb1.begin()); 2243 BOOST_TEST(!cb1.front().is_moved()); 2244 BOOST_TEST(cb1.front().value() == 5); 2245 BOOST_TEST(cb1.size() == 5); 2246 2247 var.reinit(); 2248 cb1.insert(cb1.begin(), boost::move(var)); 2249 BOOST_TEST(!cb1.front().is_moved()); 2250 BOOST_TEST(cb1.front().value() == 6); 2251 BOOST_TEST(cb1.size() == 6); 2252 2253 cb1.rinsert(cb1.begin()); 2254 BOOST_TEST(!cb1.front().is_moved()); 2255 BOOST_TEST(cb1.front().value() == 7); 2256 BOOST_TEST(cb1.size() == 7); 2257 2258 var.reinit(); 2259 cb1.rinsert(cb1.begin(), boost::move(var)); 2260 BOOST_TEST(!cb1.front().is_moved()); 2261 BOOST_TEST(cb1.front().value() == 8); 2262 BOOST_TEST(cb1.size() == 8); 2263 2264 2265 BOOST_TEST(cb1[0].value() == 8); 2266 BOOST_TEST(cb1[1].value() == 7); 2267 BOOST_TEST(cb1[2].value() == 6); 2268 BOOST_TEST(cb1[3].value() == 5); 2269 BOOST_TEST(cb1[4].value() == 4); 2270 BOOST_TEST(cb1[5].value() == 2); 2271 BOOST_TEST(cb1[6].value() == 1); 2272 BOOST_TEST(cb1[7].value() == 3); 2273 cb1.rotate(cb1.begin() + 2); 2274 BOOST_TEST(cb1[0].value() == 6); 2275 BOOST_TEST(cb1[1].value() == 5); 2276 BOOST_TEST(cb1[2].value() == 4); 2277 BOOST_TEST(cb1[3].value() == 2); 2278 BOOST_TEST(cb1[4].value() == 1); 2279 BOOST_TEST(cb1[5].value() == 3); 2280 BOOST_TEST(cb1[6].value() == 8); 2281 BOOST_TEST(cb1[7].value() == 7); 2282 2283 BOOST_TEST(!cb1[0].is_moved()); 2284 BOOST_TEST(!cb1[1].is_moved()); 2285 BOOST_TEST(!cb1[2].is_moved()); 2286 BOOST_TEST(!cb1[3].is_moved()); 2287 BOOST_TEST(!cb1[4].is_moved()); 2288 BOOST_TEST(!cb1[5].is_moved()); 2289 BOOST_TEST(!cb1[6].is_moved()); 2290 BOOST_TEST(!cb1[7].is_moved()); 2291 2292 cb1.linearize(); 2293 BOOST_TEST(!cb1[0].is_moved()); 2294 BOOST_TEST(!cb1[1].is_moved()); 2295 BOOST_TEST(!cb1[2].is_moved()); 2296 BOOST_TEST(!cb1[3].is_moved()); 2297 BOOST_TEST(!cb1[4].is_moved()); 2298 BOOST_TEST(!cb1[5].is_moved()); 2299 BOOST_TEST(!cb1[6].is_moved()); 2300 BOOST_TEST(!cb1[7].is_moved()); 2301 BOOST_TEST(cb1[0].value() == 6); 2302 BOOST_TEST(cb1[1].value() == 5); 2303 BOOST_TEST(cb1[2].value() == 4); 2304 BOOST_TEST(cb1[3].value() == 2); 2305 BOOST_TEST(cb1[4].value() == 1); 2306 BOOST_TEST(cb1[5].value() == 3); 2307 BOOST_TEST(cb1[6].value() == 8); 2308 BOOST_TEST(cb1[7].value() == 7); 2309 2310 cb1.erase(cb1.begin()); 2311 BOOST_TEST(!cb1[0].is_moved()); 2312 BOOST_TEST(!cb1[1].is_moved()); 2313 BOOST_TEST(!cb1[2].is_moved()); 2314 BOOST_TEST(!cb1[3].is_moved()); 2315 BOOST_TEST(!cb1[4].is_moved()); 2316 BOOST_TEST(!cb1[5].is_moved()); 2317 BOOST_TEST(!cb1[6].is_moved()); 2318 BOOST_TEST(cb1[0].value() == 5); 2319 BOOST_TEST(cb1[1].value() == 4); 2320 BOOST_TEST(cb1[2].value() == 2); 2321 BOOST_TEST(cb1[3].value() == 1); 2322 BOOST_TEST(cb1[4].value() == 3); 2323 BOOST_TEST(cb1[5].value() == 8); 2324 BOOST_TEST(cb1[6].value() == 7); 2325 2326 cb1.rerase(cb1.begin()); 2327 BOOST_TEST(!cb1[0].is_moved()); 2328 BOOST_TEST(!cb1[1].is_moved()); 2329 BOOST_TEST(!cb1[2].is_moved()); 2330 BOOST_TEST(!cb1[3].is_moved()); 2331 BOOST_TEST(!cb1[4].is_moved()); 2332 BOOST_TEST(!cb1[5].is_moved()); 2333 BOOST_TEST(cb1[0].value() == 4); 2334 BOOST_TEST(cb1[1].value() == 2); 2335 BOOST_TEST(cb1[2].value() == 1); 2336 BOOST_TEST(cb1[3].value() == 3); 2337 BOOST_TEST(cb1[4].value() == 8); 2338 BOOST_TEST(cb1[5].value() == 7); 2339 2340 cb1.erase(cb1.begin(), cb1.begin() + 1); 2341 BOOST_TEST(!cb1[0].is_moved()); 2342 BOOST_TEST(!cb1[1].is_moved()); 2343 BOOST_TEST(!cb1[2].is_moved()); 2344 BOOST_TEST(!cb1[3].is_moved()); 2345 BOOST_TEST(!cb1[4].is_moved()); 2346 BOOST_TEST(cb1[0].value() == 2); 2347 BOOST_TEST(cb1[1].value() == 1); 2348 BOOST_TEST(cb1[2].value() == 3); 2349 BOOST_TEST(cb1[3].value() == 8); 2350 BOOST_TEST(cb1[4].value() == 7); 2351 2352 cb1.rerase(cb1.begin(), cb1.begin() + 1); 2353 BOOST_TEST(!cb1[0].is_moved()); 2354 BOOST_TEST(!cb1[1].is_moved()); 2355 BOOST_TEST(!cb1[2].is_moved()); 2356 BOOST_TEST(!cb1[3].is_moved()); 2357 BOOST_TEST(cb1[0].value() == 1); 2358 BOOST_TEST(cb1[1].value() == 3); 2359 BOOST_TEST(cb1[2].value() == 8); 2360 BOOST_TEST(cb1[3].value() == 7); 2361} 2362 2363void move_container_values_noexcept() { 2364 move_container_values_impl<noncopyable_movable_noexcept_t>(); 2365 2366 typedef noncopyable_movable_noexcept_t noncopyable_movable_test_t; 2367 noncopyable_movable_test_t::next_value = 1; 2368 CB_CONTAINER<noncopyable_movable_test_t> cb1(40); 2369 cb1.push_back(); 2370 cb1.push_back(); 2371 cb1.push_back(); 2372 cb1.push_back(); 2373 cb1.push_back(); 2374 cb1.push_back(); 2375 cb1.push_back(); 2376 cb1.push_back(); 2377 2378 cb1.set_capacity(100); 2379 BOOST_TEST(!cb1[0].is_moved()); 2380 BOOST_TEST(!cb1[1].is_moved()); 2381 BOOST_TEST(!cb1[2].is_moved()); 2382 BOOST_TEST(!cb1[3].is_moved()); 2383 BOOST_TEST(!cb1[4].is_moved()); 2384 BOOST_TEST(!cb1[5].is_moved()); 2385 BOOST_TEST(!cb1[6].is_moved()); 2386 BOOST_TEST(!cb1[7].is_moved()); 2387 BOOST_TEST(cb1[0].value() == 1); 2388 BOOST_TEST(cb1[1].value() == 2); 2389 BOOST_TEST(cb1[2].value() == 3); 2390 BOOST_TEST(cb1[3].value() == 4); 2391 BOOST_TEST(cb1[4].value() == 5); 2392 BOOST_TEST(cb1[5].value() == 6); 2393 BOOST_TEST(cb1[6].value() == 7); 2394 BOOST_TEST(cb1[7].value() == 8); 2395 2396 cb1.rset_capacity(101); 2397 BOOST_TEST(!cb1[0].is_moved()); 2398 BOOST_TEST(!cb1[1].is_moved()); 2399 BOOST_TEST(!cb1[2].is_moved()); 2400 BOOST_TEST(!cb1[3].is_moved()); 2401 BOOST_TEST(!cb1[4].is_moved()); 2402 BOOST_TEST(!cb1[5].is_moved()); 2403 BOOST_TEST(!cb1[6].is_moved()); 2404 BOOST_TEST(!cb1[7].is_moved()); 2405 BOOST_TEST(cb1[0].value() == 1); 2406 BOOST_TEST(cb1[1].value() == 2); 2407 BOOST_TEST(cb1[2].value() == 3); 2408 BOOST_TEST(cb1[3].value() == 4); 2409 BOOST_TEST(cb1[4].value() == 5); 2410 BOOST_TEST(cb1[5].value() == 6); 2411 BOOST_TEST(cb1[6].value() == 7); 2412 BOOST_TEST(cb1[7].value() == 8); 2413 2414 cb1.set_capacity(2); 2415 BOOST_TEST(!cb1[0].is_moved()); 2416 BOOST_TEST(!cb1[1].is_moved()); 2417 BOOST_TEST(cb1[0].value() == 1); 2418 BOOST_TEST(cb1[1].value() == 2); 2419 2420 cb1.rset_capacity(1); 2421 BOOST_TEST(!cb1[0].is_moved()); 2422 BOOST_TEST(cb1[0].value() == 2); 2423} 2424 2425void check_containers_exception_specifications() { 2426#ifndef BOOST_NO_CXX11_NOEXCEPT 2427#ifndef BOOST_CLANG 2428 // Clang has an error in __has_nothrow_constructor implementation: 2429 // http://llvm.org/bugs/show_bug.cgi?id=16627 2430 BOOST_TEST(boost::has_nothrow_constructor<CB_CONTAINER<int> >::value); 2431#endif 2432 2433#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES 2434#ifdef BOOST_IS_NOTHROW_MOVE_ASSIGN 2435 BOOST_TEST(boost::is_nothrow_move_assignable<CB_CONTAINER<int> >::value); 2436#endif 2437#ifdef BOOST_IS_NOTHROW_MOVE_CONSTRUCT 2438 BOOST_TEST(boost::is_nothrow_move_constructible<CB_CONTAINER<int> >::value); 2439#endif 2440#endif 2441#endif // BOOST_NO_CXX11_NOEXCEPT 2442} 2443 2444// add common tests into a test suite 2445void run_common_tests() 2446{ 2447 basic_test(); 2448 constructor_and_element_access_test(); 2449 size_test(); 2450 allocator_test(); 2451 begin_and_end_test(); 2452 rbegin_and_rend_test(); 2453 element_access_and_insert_test(); 2454 at_test(); 2455 front_and_back_test(); 2456 linearize_test(); 2457 array_range_test(); 2458 capacity_and_reserve_test(); 2459 full_and_empty_test(); 2460 set_capacity_test(); 2461 rset_capacity_test(); 2462 resize_test(); 2463 rresize_test(); 2464 constructor_test(); 2465 assign_test(); 2466 copy_constructor_and_assign_test(); 2467 swap_test(); 2468 push_back_test(); 2469 pop_back_test(); 2470 insert_test(); 2471 insert_n_test(); 2472 insert_range_test(); 2473 push_front_test(); 2474 pop_front_test(); 2475 rinsert_test(); 2476 rinsert_n_test(); 2477 rinsert_range_test(); 2478 erase_test(); 2479 erase_range_test(); 2480 rerase_test(); 2481 rerase_range_test(); 2482 clear_test(); 2483 equality_test(); 2484 lexicographical_comparison_test(); 2485 assign_range_test(); 2486 example_test(); 2487 element_destruction_test(); 2488 const_methods_test(); 2489 rotate_test(); 2490 move_container_on_cpp11(); 2491 move_container_values_noexcept(); 2492 check_containers_exception_specifications(); 2493#if !defined(BOOST_NO_CXX11_ALLOCATOR) 2494 cxx11_allocator_test(); 2495#endif 2496} 2497 2498