]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/testsuite/23_containers/vector/cons/4.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / cons / 4.cc
index af7556517f60caee079f36cf96211b0f4eb15a4b..182a46a97501340e5bbbba5811167a3a5bb9b33a 100644 (file)
@@ -1,11 +1,11 @@
 // 1999-06-29 bkoz
 
-// Copyright (C) 1999-2001, 2002, 2003 Free Software Foundation, Inc.
+// Copyright (C) 1999-2024 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 2, or (at your option)
+// 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,
@@ -14,9 +14,8 @@
 // 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 COPYING.  If not, write to the Free
-// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-// USA.
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
 
 // 23.2.4.1 vector constructors, copy, and assignment
 
@@ -26,8 +25,8 @@
 #include <testsuite_hooks.h>
 
 using __gnu_test::copy_tracker;
-using __gnu_test::allocation_tracker;
-using __gnu_test::tracker_alloc;
+using __gnu_test::tracker_allocator_counter;
+using __gnu_test::tracker_allocator;
 using __gnu_test::copy_constructor;
 using __gnu_test::assignment_operator;
 
@@ -40,27 +39,26 @@ void
 test_default_ctor_exception_gurantee()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
   copy_tracker::reset();
   copy_constructor::throw_on(3);
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 
   // run test
   try
   {
-    X a(7);
-    VERIFY(("no exception thrown", false));
+    T ref;
+    X a(7, ref);
+    VERIFY(false);
   }
   catch (...)
   {
   }
 
   // assert postconditions
-  VERIFY(("memory leak detected:",
-          allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal()));
+  VERIFY( tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count() );
 
   // teardown
 }
@@ -73,11 +71,10 @@ void
 test_copy_ctor_exception_gurantee()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
   {
     X a(7);
     copy_tracker::reset();
@@ -87,7 +84,7 @@ test_copy_ctor_exception_gurantee()
     try
     {
       X u(a);
-      VERIFY(("no exception thrown", false));
+      VERIFY(false);
     }
     catch (...)
     {
@@ -95,11 +92,11 @@ test_copy_ctor_exception_gurantee()
   }
 
   // assert postconditions
-  VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
+  VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 // operator=()
@@ -112,14 +109,13 @@ void
 test_assignment_operator_1()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
   X r(9);
   X a(r.size() - 2);
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 
   // preconditions
   VERIFY(r.size() > a.size());
@@ -129,26 +125,25 @@ test_assignment_operator_1()
 
   // assert postconditions
   VERIFY(r == a);
-  VERIFY(allocation_tracker::allocationTotal() == 0);
+  VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 void
 test_assignment_operator_2()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
   X r(1);
   r.reserve(17);
   X a(r.size() + 7);
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 
   // preconditions
   VERIFY(r.size() < a.size());
@@ -159,22 +154,21 @@ test_assignment_operator_2()
 
   // assert postconditions
   VERIFY(r == a);
-  VERIFY(allocation_tracker::allocationTotal() == 0);
+  VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 void
 test_assignment_operator_3()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
   {
     X r(1);
     X a(r.capacity() + 7);
@@ -189,22 +183,21 @@ test_assignment_operator_3()
     // assert postconditions
     VERIFY(r == a);
   }
-  VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
+  VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 void
 test_assignment_operator_3_exception_guarantee()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
   {
     X r(1);
     X a(r.capacity() + 7);
@@ -218,7 +211,7 @@ test_assignment_operator_3_exception_guarantee()
     try
     {
       r = a;
-      VERIFY(("no exception thrown", false));
+      VERIFY(false);
     }
     catch (...)
     {
@@ -226,11 +219,11 @@ test_assignment_operator_3_exception_guarantee()
   }
 
   // assert postconditions
-  VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
+  VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 // fill assign()
@@ -245,9 +238,8 @@ void
 test_fill_assign_1()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
   X a(7);
   X::size_type old_size = a.size();
@@ -255,27 +247,26 @@ test_fill_assign_1()
   const T t;
 
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 
   // run test
   a.assign(new_size, t);
 
   // assert postconditions
   VERIFY(a.size() == new_size);
-  VERIFY(allocation_tracker::allocationTotal() == 0);
+  VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 void
 test_fill_assign_2()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
   X a(7);
   a.reserve(11);
@@ -285,7 +276,7 @@ test_fill_assign_2()
   const T t;
 
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 
   // assert preconditions
   VERIFY(old_size < new_size);
@@ -296,25 +287,23 @@ test_fill_assign_2()
 
   // assert postconditions
   VERIFY(a.size() == new_size);
-  VERIFY(allocation_tracker::allocationTotal() == 0);
+  VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 void
 test_fill_assign_3()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
   {
     X a(7);
-    X::size_type old_size     = a.size();
     X::size_type old_capacity = a.capacity();
     X::size_type new_size     = old_capacity + 4;
     const T t;
@@ -331,23 +320,22 @@ test_fill_assign_3()
     VERIFY(a.size() == new_size);
   }
 
-  VERIFY(allocation_tracker::allocationTotal() > 0);
-  VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
+  VERIFY(tracker_allocator_counter::get_allocation_count() > 0);
+  VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 void
 test_fill_assign_3_exception_guarantee()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
   {
     X a(7);
     X::size_type old_size     = a.size();
@@ -365,7 +353,7 @@ test_fill_assign_3_exception_guarantee()
     try
     {
       a.assign(new_size, t);
-      VERIFY(("no exception thrown", false));
+      VERIFY(false);
     }
     catch (...)
     {
@@ -376,21 +364,20 @@ test_fill_assign_3_exception_guarantee()
     VERIFY(a.capacity() == old_capacity);
   }
 
-  VERIFY(allocation_tracker::allocationTotal() > 0);
-  VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
+  VERIFY(tracker_allocator_counter::get_allocation_count() > 0);
+  VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 void
 test_fill_assign_4()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
   X a(7);
   X::size_type old_size  = a.size();
@@ -398,18 +385,18 @@ test_fill_assign_4()
   X::size_type new_value = 117;
 
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 
   // run test
   a.assign(new_size, new_value);
 
   // assert postconditions
   VERIFY(a.size() == new_size);
-  VERIFY(allocation_tracker::allocationTotal() == 0);
+  VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 // range assign()
@@ -432,16 +419,14 @@ void
 test_range_assign_2()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
   X a(7);
   X b(3);
-  X::size_type old_size = a.size();
 
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 
   // assert preconditions
   VERIFY(b.size() < a.capacity());
@@ -452,28 +437,26 @@ test_range_assign_2()
   // assert postconditions
   VERIFY(a.size() == b.size());
   VERIFY(a == b);
-  VERIFY(allocation_tracker::allocationTotal() == 0);
+  VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 void
 test_range_assign_3()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
   X a(7);
   a.reserve(a.size() + 7);
   X b(a.size() + 3);
-  X::size_type old_size = a.size();
 
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 
   // assert preconditions
   VERIFY(a.size() < b.size());
@@ -485,26 +468,24 @@ test_range_assign_3()
   // assert postconditions
   VERIFY(a.size() == b.size());
   VERIFY(a == b);
-  VERIFY(allocation_tracker::allocationTotal() == 0);
+  VERIFY(tracker_allocator_counter::get_allocation_count() == 0);
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 void
 test_range_assign_4()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
   {
     X a(7);
     X b(a.capacity() + 7);
-    X::size_type old_size = a.size();
 
     copy_tracker::reset();
 
@@ -518,27 +499,25 @@ test_range_assign_4()
     VERIFY(a.size() == b.size());
     VERIFY(a == b);
   }
-  VERIFY(allocation_tracker::allocationTotal() > 0);
-  VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
+  VERIFY(tracker_allocator_counter::get_allocation_count() > 0);
+  VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }
 
 void
 test_range_assign_4_exception_guarantee()
 {
   // setup
-  bool test = true;
   typedef copy_tracker T;
-  typedef std::vector<T, tracker_alloc<T> > X;
+  typedef std::vector<T, tracker_allocator<T> > X;
 
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
   {
     X a(7);
     X b(a.capacity() + 7);
-    X::size_type old_size = a.size();
 
     copy_tracker::reset();
     copy_constructor::throw_on(3);
@@ -550,7 +529,7 @@ test_range_assign_4_exception_guarantee()
     try
     {
       a.assign(b.begin(), b.end());
-      VERIFY(("no exception thrown", false));
+      VERIFY(false);
     }
     catch (...)
     {
@@ -558,12 +537,12 @@ test_range_assign_4_exception_guarantee()
   }
 
   // assert postconditions
-  VERIFY(allocation_tracker::allocationTotal() > 0);
-  VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
+  VERIFY(tracker_allocator_counter::get_allocation_count() > 0);
+  VERIFY(tracker_allocator_counter::get_allocation_count() == tracker_allocator_counter::get_deallocation_count());
 
   // teardown
   copy_tracker::reset();
-  allocation_tracker::resetCounts();
+  tracker_allocator_counter::reset();
 }