summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/23_containers/vector/capacity
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers/vector/capacity')
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/capacity/1.cc61
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/capacity/2.cc102
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/capacity/29134-2.cc50
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/capacity/29134.cc37
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc38
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/capacity/8230.cc78
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc47
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc60
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc56
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc43
-rw-r--r--libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit.cc42
11 files changed, 614 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/1.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/1.cc
new file mode 100644
index 000000000..557b329f3
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/1.cc
@@ -0,0 +1,61 @@
+// 1999-05-07
+// bkoz
+
+// Copyright (C) 1999, 2002, 2003, 2004, 2005, 2009
+// 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/libstdc++-v3/testsuite/23_containers/vector/capacity/2.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/2.cc
new file mode 100644
index 000000000..1cf0cae98
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/2.cc
@@ -0,0 +1,102 @@
+// 1999-05-07
+// bkoz
+
+// Copyright (C) 1999, 2002, 2003, 2009 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/libstdc++-v3/testsuite/23_containers/vector/capacity/29134-2.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/29134-2.cc
new file mode 100644
index 000000000..c48e474e9
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/29134-2.cc
@@ -0,0 +1,50 @@
+// Copyright (C) 2006, 2009 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/libstdc++-v3/testsuite/23_containers/vector/capacity/29134.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/29134.cc
new file mode 100644
index 000000000..72fac56c2
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/29134.cc
@@ -0,0 +1,37 @@
+// Copyright (C) 2006, 2009 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/libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc
new file mode 100644
index 000000000..737108b49
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/44190.cc
@@ -0,0 +1,38 @@
+// Copyright (C) 2010 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/libstdc++-v3/testsuite/23_containers/vector/capacity/8230.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/8230.cc
new file mode 100644
index 000000000..b1b2c7d48
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/8230.cc
@@ -0,0 +1,78 @@
+// 1999-05-07
+// bkoz
+
+// Copyright (C) 1999, 2002, 2003, 2004, 2005, 2009
+// 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/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/reserve/moveable.cc
new file mode 100644
index 000000000..c8ce77b63
--- /dev/null
+++ b/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, 2009 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/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc
new file mode 100644
index 000000000..168df7a4a
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/1.cc
@@ -0,0 +1,60 @@
+// 1999-05-07
+// bkoz
+
+// Copyright (C) 1999, 2002, 2004, 2005, 2009 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
+
+// XXX This test will not work for irix6 because of bug(s) in libc malloc
+// XXX for very large allocations. However -lmalloc seems to work.
+// See http://gcc.gnu.org/ml/libstdc++/2002-12/msg00131.html
+// { dg-options "-lmalloc" { target mips*-*-irix6* } }
+
+// 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/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc
new file mode 100644
index 000000000..5ba026dbe
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/moveable.cc
@@ -0,0 +1,56 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
+// 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/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/resize/resize_size.cc
new file mode 100644
index 000000000..d181168ac
--- /dev/null
+++ b/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 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/libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/shrink_to_fit.cc
new file mode 100644
index 000000000..482166cab
--- /dev/null
+++ b/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 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;
+}