diff options
Diffstat (limited to 'gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity')
14 files changed, 769 insertions, 0 deletions
diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/1.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/1.cc new file mode 100644 index 000000000..736e596b3 --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/1.cc @@ -0,0 +1,60 @@ +// 1999-05-07 +// bkoz + +// Copyright (C) 1999-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 23.2.4.2 vector capacity + +#include <vector> +#include <stdexcept> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +template<typename T> + struct A { }; + +struct B { }; + +void test01() +{ + // non POD types + bool test __attribute__((unused)) = true; + std::vector< A<B> > vec01; + typedef std::vector< A<B> >::size_type size_type; + + size_type sz01 = vec01.capacity(); + vec01.reserve(100); + size_type sz02 = vec01.capacity(); + VERIFY( sz02 >= sz01 ); + + sz01 = vec01.size() + 5; + vec01.resize(sz01); + sz02 = vec01.size(); + VERIFY( sz01 == sz02 ); + + sz01 = vec01.size() - 5; + vec01.resize(sz01); + sz02 = vec01.size(); + VERIFY( sz01 == sz02 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/2.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/2.cc new file mode 100644 index 000000000..d9b216285 --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/2.cc @@ -0,0 +1,102 @@ +// 1999-05-07 +// bkoz + +// Copyright (C) 1999-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 23.2.4.2 vector capacity + +#include <vector> +#include <stdexcept> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +using __gnu_test::copy_tracker; +using __gnu_test::tracker_allocator_counter; +using __gnu_test::tracker_allocator; +using __gnu_test::copy_constructor; +using __gnu_test::assignment_operator; +using __gnu_test::destructor; + +// Verifies basic functionality of reserve() with forced reallocation. +void +test_reserve() +{ + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X a(3); + const X::size_type old_size = a.size(); + const X::size_type old_capacity = a.capacity(); + const X::size_type new_capacity = old_capacity + 10; + T::reset(); + + a.reserve(new_capacity); + + // [23.2.4.1 (2)] + VERIFY(new_capacity <= a.capacity()); + // [23.2.4.1 (3)] + VERIFY(old_size == a.size()); + VERIFY(copy_constructor::count() <= old_size); + VERIFY(destructor::count() <= old_size); + } + // check for memory leaks + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); +} + +// Verifies that reserve() with reallocation offers the strong +// exception guarantee. +void +test_reserve_exception_guarantee() +{ + bool test __attribute__((unused)) = true; + typedef copy_tracker T; + typedef std::vector<T, tracker_allocator<T> > X; + + tracker_allocator_counter::reset(); + { + X a(7); + const X::size_type old_size __attribute__((unused)) = a.size(); + const X::size_type old_capacity = a.capacity(); + const X::size_type new_capacity = old_capacity + 10; + T::reset(); + copy_constructor::throw_on(3); + + try + { + a.reserve(new_capacity); + VERIFY(false); + } + catch (...) + { + } + + VERIFY(old_capacity == a.capacity()); + VERIFY(copy_constructor::count() == destructor::count()+1); + } + VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count()); +} + +int main() +{ + test_reserve(); + test_reserve_exception_guarantee(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/29134-2.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/29134-2.cc new file mode 100644 index 000000000..7f4dd852f --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/29134-2.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2006-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 23.2.4.2 vector capacity [lib.vector.capacity] + +#include <vector> +#include <stdexcept> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + vector<int> v; + + try + { + v.resize(size_t(-1)); + } + catch(const std::length_error&) + { + VERIFY( true ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/29134.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/29134.cc new file mode 100644 index 000000000..ecaedcbe7 --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/29134.cc @@ -0,0 +1,37 @@ +// Copyright (C) 2006-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 23.2.4.2 vector capacity [lib.vector.capacity] + +#include <vector> +#include <testsuite_hooks.h> + +// libstdc++/29134 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<int> v; + + VERIFY( v.max_size() == v.get_allocator().max_size() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc new file mode 100644 index 000000000..58115542e --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2010-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-D_GLIBCXX_DEBUG_PEDANTIC" } + +#include <vector> +#include <testsuite_hooks.h> + +// libstdc++/44190 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<int> v; + v.resize(10); + VERIFY( v.size() <= v.capacity() ); +} + +int main() +{ + + test01(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/8230.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/8230.cc new file mode 100644 index 000000000..78258ed0e --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/8230.cc @@ -0,0 +1,77 @@ +// 1999-05-07 +// bkoz + +// Copyright (C) 1999-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 23.2.4.2 vector capacity + +#include <vector> +#include <stdexcept> +#include <testsuite_allocator.h> +#include <testsuite_hooks.h> + +// libstdc++/8230 +void test02() +{ + bool test __attribute__((unused)) = true; + { + std::vector<int> array; + const std::size_t size = array.max_size(); + try + { + array.reserve(size); + } + catch (const std::length_error& error) + { + test &= false; + } + catch (const std::bad_alloc& error) + { + test &= true; + } + catch (...) + { + test &= false; + } + VERIFY( test ); + } + + { + std::vector<int> array; + const std::size_t size = array.max_size() + 1; + try + { + array.reserve(size); + } + catch (const std::length_error& error) + { + test &= true; + } + catch (...) + { + test &= false; + } + VERIFY( test ); + } +} + +int main() +{ + test02(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc new file mode 100644 index 000000000..0ed52eb9b --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } + +// 2007-10-28 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2007-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace __gnu_test; + + std::vector<copycounter> a(40); + copycounter::copycount = 0; + + a.reserve(50); + VERIFY( copycounter::copycount == 0 ); + + a.reserve(200); + VERIFY( copycounter::copycount == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable2.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable2.cc new file mode 100644 index 000000000..171ee2c26 --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable2.cc @@ -0,0 +1,45 @@ +// { dg-options "-std=gnu++0x" } + +// 2011-06-07 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2011-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace __gnu_test; + + std::vector<throwing_move_constructor> v(5); + + v.reserve(50); + VERIFY( v.capacity() >= 50 ); + + v.reserve(500); + VERIFY( v.capacity() >= 500 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc new file mode 100644 index 000000000..4a7ff0417 --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc @@ -0,0 +1,55 @@ +// 1999-05-07 +// bkoz + +// Copyright (C) 1999-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 23.2.4.2 vector capacity + +// This fails on some versions of Darwin 8 because malloc doesn't return +// NULL even if an allocation fails (filed as Radar 3884894). +// { dg-do run { xfail *-*-darwin8.[0-4].* } } + +#include <vector> +#include <stdexcept> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::vector<int> v; + try + { + v.resize(v.max_size()); + v[v.max_size() - 1] = 2002; + } + catch (const std::bad_alloc& error) + { + test = true; + } + catch (...) + { + test = false; + } + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc new file mode 100644 index 000000000..e8d67b52f --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc @@ -0,0 +1,55 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2005-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +using namespace __gnu_test; + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<copycounter> a; + copycounter::copycount = 0; + a.resize(10); + a.resize(98); + a.resize(99); + a.resize(100); + VERIFY( copycounter::copycount == 0 ); + + a.resize(99); + a.resize(0); + VERIFY( copycounter::copycount == 0 ); + + a.resize(100); + VERIFY( copycounter::copycount == 0 ); + + a.clear(); + VERIFY( copycounter::copycount == 0 ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable2.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable2.cc new file mode 100644 index 000000000..dd9547b60 --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable2.cc @@ -0,0 +1,57 @@ +// { dg-options "-std=gnu++0x" } + +// 2011-06-07 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2011-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_rvalref.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + using namespace __gnu_test; + + std::vector<throwing_move_constructor> v(5); + + v.resize(50); + VERIFY( v.size() == 50 ); + + v.reserve(200); + VERIFY( v.capacity() >= 200 ); + + v.resize(100); + VERIFY( v.size() == 100 ); + + v.resize(500, throwing_move_constructor()); + VERIFY( v.size() == 500 ); + + v.reserve(2000); + VERIFY( v.capacity() >= 2000 ); + + v.resize(1000, throwing_move_constructor()); + VERIFY( v.size() == 1000 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc new file mode 100644 index 000000000..a02ef24a7 --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc @@ -0,0 +1,43 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-06-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_api.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<__gnu_test::NonCopyConstructible> v; + VERIFY( std::distance(v.begin(), v.end()) == 0 ); + + v.resize(1000); + VERIFY( std::distance(v.begin(), v.end()) == 1000 ); + for(auto it = v.begin(); it != v.end(); ++it) + VERIFY( *it == -1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit.cc new file mode 100644 index 000000000..5e228781a --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit.cc @@ -0,0 +1,42 @@ +// { dg-options "-std=gnu++0x" } + +// 2010-01-08 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <vector> +#include <testsuite_hooks.h> + +// libstdc++/42573 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::vector<int> v(100); + v.push_back(1); + v.push_back(1); + VERIFY( v.size() < v.capacity() ); + v.shrink_to_fit(); + VERIFY( v.size() == v.capacity() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit2.cc b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit2.cc new file mode 100644 index 000000000..b099117ea --- /dev/null +++ b/gcc-4.8/libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit2.cc @@ -0,0 +1,61 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2011-2013 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <vector> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using __gnu_test::propagating_allocator; + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef propagating_allocator<int, true> alloc_type; + alloc_type alloc(5); + + std::vector<int, alloc_type> v(10u, 1, alloc); + v.reserve(100); + VERIFY( v.size() < v.capacity() ); + v.shrink_to_fit(); + VERIFY( v.size() == v.capacity() ); + VERIFY( v.get_allocator().get_personality() == alloc.get_personality() ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + + typedef propagating_allocator<int, false> alloc_type; + alloc_type alloc(5); + + std::vector<int, alloc_type> v(10u, 1, alloc); + v.reserve(100); + VERIFY( v.size() < v.capacity() ); + v.shrink_to_fit(); + VERIFY( v.size() == v.capacity() ); + VERIFY( v.get_allocator().get_personality() == alloc.get_personality() ); +} + +int main() +{ + test01(); + test02(); + return 0; +} |