4 // Copyright (C) 1999-2013 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // 23.2.4.2 vector capacity
25 #include <testsuite_allocator.h>
26 #include <testsuite_hooks.h>
28 using __gnu_test::copy_tracker;
29 using __gnu_test::tracker_allocator_counter;
30 using __gnu_test::tracker_allocator;
31 using __gnu_test::copy_constructor;
32 using __gnu_test::assignment_operator;
33 using __gnu_test::destructor;
35 // Verifies basic functionality of reserve() with forced reallocation.
39 bool test __attribute__((unused)) = true;
40 typedef copy_tracker T;
41 typedef std::vector<T, tracker_allocator<T> > X;
43 tracker_allocator_counter::reset();
46 const X::size_type old_size = a.size();
47 const X::size_type old_capacity = a.capacity();
48 const X::size_type new_capacity = old_capacity + 10;
51 a.reserve(new_capacity);
54 VERIFY(new_capacity <= a.capacity());
56 VERIFY(old_size == a.size());
57 VERIFY(copy_constructor::count() <= old_size);
58 VERIFY(destructor::count() <= old_size);
60 // check for memory leaks
61 VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
64 // Verifies that reserve() with reallocation offers the strong
65 // exception guarantee.
67 test_reserve_exception_guarantee()
69 bool test __attribute__((unused)) = true;
70 typedef copy_tracker T;
71 typedef std::vector<T, tracker_allocator<T> > X;
73 tracker_allocator_counter::reset();
76 const X::size_type old_size __attribute__((unused)) = a.size();
77 const X::size_type old_capacity = a.capacity();
78 const X::size_type new_capacity = old_capacity + 10;
80 copy_constructor::throw_on(3);
84 a.reserve(new_capacity);
91 VERIFY(old_capacity == a.capacity());
92 VERIFY(copy_constructor::count() == destructor::count()+1);
94 VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
100 test_reserve_exception_guarantee();