Commit 8d59b230 by Benjamin Kosnik Committed by Benjamin Kosnik

Renames, namespaces for testsuite utilities.


2003-01-12  Benjamin Kosnik  <bkoz@redhat.com>

	Renames, namespaces for testsuite utilities.
	* testsuite/testsuite_hooks.h: Put into namespace __gnu_cxx_test.
	(gnu_allocator_tracker): Rename to allocation_tracker.
	(gnu_new_allocator): Rename to tracker_alloc.
	(__set_testsuite_memlimit): Rename to set_memory_limits.
	(gnu_assignment_operator): Rename to assignment_operator.
	(gnu_destructor): Rename to destructor.
	(gnu_copy_tracker): Rename to copy_tracker.
	(gnu_char, gnu_int, gnu_long): Rename to pod_char, pod_int, pod_long.
	(run_tests_wrapped_locale): New.
	(run_tests_wrapped_env): New.
	* testsuite/testsuite_hooks.cc: Same.
	(class locale_data): Add.
	(class enviornment_variable): Add.
	(class not_found): Add.
	* testsuite/testsuite_allocator.h: Same.
	* testsuite/testsuite_allocator.cc: Same.
	* testsuite/23_containers/deque_ctor.cc
	(test_copy_ctor_exception_safety): Change gnu_allocator_tracker to
	allocation_tracker.
	Change gnu_new_allocator to tracker_alloc.
	Change gnu_counting_struct to counter.
	Change gnu_copy_tracker to copy_tracker.
	Change gnu_copy_constructor to copy_constructor.
	Change gnu_assignment_operator to assignment_operator.
	Inject.
	* testsuite/23_containers/vector_capacity.cc: Same.
	* testsuite/23_containers/vector_ctor.cc (test01): Same.
	* testsuite/23_containers/list_modifiers.cc: Change
	gnu_copy_tracker to copy_tracker.
	* testsuite/21_strings/ctor_copy_dtor.cc (main): Change
	__set_testsuite_memlimit to set_memory_limits.
	* testsuite/21_strings/insert.cc (main): Same.
	* testsuite/27_io/filebuf.cc: Change gnu_char to pod_char.
	* testsuite/27_io/stringstream.cc: Same.
	* testsuite/27_io/stringbuf.cc: Same.
	* testsuite/27_io/streambuf.cc: Same.
	* testsuite/27_io/ostream.cc: Same.
	* testsuite/27_io/istream.cc: Same.
	* testsuite/27_io/fstream.cc: Same.
	* testsuite/lib/libstdc++-v3-dg.exp
	(libstdc++-v3-list-sourcefiles): Additionally handle files two and
	three levels deeper in glob patterns.

From-SVN: r61261
parent fd371a93
2003-01-12 Benjamin Kosnik <bkoz@redhat.com>
Renames, namespaces for testsuite utilities.
* testsuite/testsuite_hooks.h: Put into namespace __gnu_cxx_test.
(gnu_allocator_tracker): Rename to allocation_tracker.
(gnu_new_allocator): Rename to tracker_alloc.
(__set_testsuite_memlimit): Rename to set_memory_limits.
(gnu_assignment_operator): Rename to assignment_operator.
(gnu_destructor): Rename to destructor.
(gnu_copy_tracker): Rename to copy_tracker.
(gnu_char, gnu_int, gnu_long): Rename to pod_char, pod_int, pod_long.
(run_tests_wrapped_locale): New.
(run_tests_wrapped_env): New.
* testsuite/testsuite_hooks.cc: Same.
(class locale_data): Add.
(class enviornment_variable): Add.
(class not_found): Add.
* testsuite/testsuite_allocator.h: Same.
* testsuite/testsuite_allocator.cc: Same.
* testsuite/23_containers/deque_ctor.cc
(test_copy_ctor_exception_safety): Change gnu_allocator_tracker to
allocation_tracker.
Change gnu_new_allocator to tracker_alloc.
Change gnu_counting_struct to counter.
Change gnu_copy_tracker to copy_tracker.
Change gnu_copy_constructor to copy_constructor.
Change gnu_assignment_operator to assignment_operator.
Inject.
* testsuite/23_containers/vector_capacity.cc: Same.
* testsuite/23_containers/vector_ctor.cc (test01): Same.
* testsuite/23_containers/list_modifiers.cc: Change
gnu_copy_tracker to copy_tracker.
* testsuite/21_strings/ctor_copy_dtor.cc (main): Change
__set_testsuite_memlimit to set_memory_limits.
* testsuite/21_strings/insert.cc (main): Same.
* testsuite/27_io/filebuf.cc: Change gnu_char to pod_char.
* testsuite/27_io/stringstream.cc: Same.
* testsuite/27_io/stringbuf.cc: Same.
* testsuite/27_io/streambuf.cc: Same.
* testsuite/27_io/ostream.cc: Same.
* testsuite/27_io/istream.cc: Same.
* testsuite/27_io/fstream.cc: Same.
* testsuite/lib/libstdc++-v3-dg.exp
(libstdc++-v3-list-sourcefiles): Additionally handle files two and
three levels deeper in glob patterns.
2003-01-11 Phil Edwards <pme@gcc.gnu.org> 2003-01-11 Phil Edwards <pme@gcc.gnu.org>
* docs/doxygen/tables.html: Finished now. * docs/doxygen/tables.html: Finished now.
......
// 1999-06-04 bkoz // 1999-06-04 bkoz
// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -230,7 +230,7 @@ void test05() ...@@ -230,7 +230,7 @@ void test05()
int main() int main()
{ {
__set_testsuite_memlimit(); __gnu_cxx_test::set_memory_limits();
test01(); test01();
test02(); test02();
test03(); test03();
......
// 1999-06-03 bkoz // 1999-06-03 bkoz
// Copyright (C) 1999 Free Software Foundation, Inc. // Copyright (C) 1999, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -246,7 +246,7 @@ int test02(void) ...@@ -246,7 +246,7 @@ int test02(void)
int main() int main()
{ {
__set_testsuite_memlimit(); __gnu_cxx_test::set_memory_limits();
test01(); test01();
test02(); test02();
return 0; return 0;
......
// 2001-12-27 pme // 2001-12-27 pme
// //
// Copyright (C) 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -26,7 +26,15 @@ ...@@ -26,7 +26,15 @@
#include <testsuite_allocator.h> #include <testsuite_allocator.h>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
typedef std::deque<gnu_counting_struct> gdeque; using __gnu_cxx_test::copy_tracker;
using __gnu_cxx_test::allocation_tracker;
using __gnu_cxx_test::tracker_alloc;
using __gnu_cxx_test::copy_constructor;
using __gnu_cxx_test::assignment_operator;
using __gnu_cxx_test::counter;
using __gnu_cxx_test::destructor;
typedef std::deque<counter> gdeque;
bool test = true; bool test = true;
...@@ -133,10 +141,10 @@ void ...@@ -133,10 +141,10 @@ void
defaultConstructorCheck() defaultConstructorCheck()
{ {
// setup // setup
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T> X; typedef std::deque<T> X;
gnu_copy_tracker::reset(); copy_tracker::reset();
// run test // run test
const X u; const X u;
...@@ -171,7 +179,7 @@ void ...@@ -171,7 +179,7 @@ void
copyConstructorCheck() copyConstructorCheck()
{ {
// setup // setup
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T> X; typedef std::deque<T> X;
const int copyBaseSize = 17; // arbitrary const int copyBaseSize = 17; // arbitrary
...@@ -179,7 +187,7 @@ copyConstructorCheck() ...@@ -179,7 +187,7 @@ copyConstructorCheck()
X a; X a;
for (int i = 0; i < copyBaseSize; ++i) for (int i = 0; i < copyBaseSize; ++i)
a.push_back(i); a.push_back(i);
gnu_copy_tracker::reset(); copy_tracker::reset();
// assert preconditions // assert preconditions
VERIFY(!a.empty()); VERIFY(!a.empty());
...@@ -192,7 +200,7 @@ copyConstructorCheck() ...@@ -192,7 +200,7 @@ copyConstructorCheck()
// assert postconditions // assert postconditions
VERIFY(u == a); VERIFY(u == a);
VERIFY(copyBaseSize == gnu_copy_constructor::count()); VERIFY(copyBaseSize == copy_constructor::count());
// teardown // teardown
} }
...@@ -212,20 +220,20 @@ void ...@@ -212,20 +220,20 @@ void
fillConstructorCheck() fillConstructorCheck()
{ {
// setup // setup
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T> X; typedef std::deque<T> X;
const X::size_type n(23); const X::size_type n(23);
const X::value_type t(111); const X::value_type t(111);
gnu_copy_tracker::reset(); copy_tracker::reset();
// run test // run test
X a(n, t); X a(n, t);
// assert postconditions // assert postconditions
VERIFY(n == a.size()); VERIFY(n == a.size());
VERIFY(n == gnu_copy_constructor::count()); VERIFY(n == copy_constructor::count());
// teardown // teardown
} }
...@@ -239,18 +247,18 @@ fillConstructorCheck() ...@@ -239,18 +247,18 @@ fillConstructorCheck()
void void
fillConstructorCheck2() fillConstructorCheck2()
{ {
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T> X; typedef std::deque<T> X;
const int f = 23; const int f = 23;
const int l = 111; const int l = 111;
gnu_copy_tracker::reset(); copy_tracker::reset();
X a(f, l); X a(f, l);
VERIFY(f == a.size()); VERIFY(f == a.size());
VERIFY(f == gnu_copy_constructor::count()); VERIFY(f == copy_constructor::count());
} }
...@@ -265,7 +273,7 @@ void ...@@ -265,7 +273,7 @@ void
rangeConstructorCheckForwardIterator() rangeConstructorCheckForwardIterator()
{ {
// setup // setup
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T> X; typedef std::deque<T> X;
const X::size_type n(726); const X::size_type n(726);
...@@ -275,14 +283,14 @@ rangeConstructorCheckForwardIterator() ...@@ -275,14 +283,14 @@ rangeConstructorCheckForwardIterator()
X::iterator j = source.end(); X::iterator j = source.end();
X::size_type rangeSize = std::distance(i, j); X::size_type rangeSize = std::distance(i, j);
gnu_copy_tracker::reset(); copy_tracker::reset();
// test // test
X a(i, j); X a(i, j);
// assert postconditions // assert postconditions
VERIFY(rangeSize == a.size()); VERIFY(rangeSize == a.size());
VERIFY(gnu_copy_constructor::count() <= rangeSize); VERIFY(copy_constructor::count() <= rangeSize);
} }
...@@ -295,7 +303,7 @@ rangeConstructorCheckForwardIterator() ...@@ -295,7 +303,7 @@ rangeConstructorCheckForwardIterator()
void void
rangeConstructorCheckInputIterator() rangeConstructorCheckInputIterator()
{ {
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T> X; typedef std::deque<T> X;
std::istringstream ibuf("1234567890123456789"); std::istringstream ibuf("1234567890123456789");
...@@ -303,12 +311,12 @@ rangeConstructorCheckInputIterator() ...@@ -303,12 +311,12 @@ rangeConstructorCheckInputIterator()
std::istream_iterator<char> i(ibuf); std::istream_iterator<char> i(ibuf);
std::istream_iterator<char> j; std::istream_iterator<char> j;
gnu_copy_tracker::reset(); copy_tracker::reset();
X a(i, j); X a(i, j);
VERIFY(rangeSize == a.size()); VERIFY(rangeSize == a.size());
VERIFY(gnu_copy_constructor::count() <= (2 * rangeSize)); VERIFY(copy_constructor::count() <= (2 * rangeSize));
} }
...@@ -316,7 +324,7 @@ rangeConstructorCheckInputIterator() ...@@ -316,7 +324,7 @@ rangeConstructorCheckInputIterator()
void void
copyAssignmentCheck() copyAssignmentCheck()
{ {
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T> X; typedef std::deque<T> X;
const X::size_type n(18); const X::size_type n(18);
...@@ -324,12 +332,12 @@ copyAssignmentCheck() ...@@ -324,12 +332,12 @@ copyAssignmentCheck()
X a(n, t); X a(n, t);
X r; X r;
gnu_copy_tracker::reset(); copy_tracker::reset();
r = a; r = a;
VERIFY(r == a); VERIFY(r == a);
VERIFY(n == gnu_copy_constructor::count()); VERIFY(n == copy_constructor::count());
} }
...@@ -343,7 +351,7 @@ copyAssignmentCheck() ...@@ -343,7 +351,7 @@ copyAssignmentCheck()
void void
fillAssignmentCheck() fillAssignmentCheck()
{ {
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T> X; typedef std::deque<T> X;
const X::size_type starting_size(10); const X::size_type starting_size(10);
...@@ -352,7 +360,7 @@ fillAssignmentCheck() ...@@ -352,7 +360,7 @@ fillAssignmentCheck()
const X::value_type t(111); const X::value_type t(111);
X a(starting_size, starting_value); X a(starting_size, starting_value);
gnu_copy_tracker::reset(); copy_tracker::reset();
// preconditions // preconditions
VERIFY(starting_size == a.size()); VERIFY(starting_size == a.size());
...@@ -362,8 +370,8 @@ fillAssignmentCheck() ...@@ -362,8 +370,8 @@ fillAssignmentCheck()
// postconditions // postconditions
VERIFY(n == a.size()); VERIFY(n == a.size());
VERIFY(n == (gnu_copy_constructor::count() + gnu_assignment_operator::count())); VERIFY(n == (copy_constructor::count() + assignment_operator::count()));
VERIFY(starting_size == (gnu_destructor::count() + gnu_assignment_operator::count())); VERIFY(starting_size == (destructor::count() + assignment_operator::count()));
} }
...@@ -391,7 +399,7 @@ fillAssignmentCheck() ...@@ -391,7 +399,7 @@ fillAssignmentCheck()
void void
rangeAssignmentCheck() rangeAssignmentCheck()
{ {
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T> X; typedef std::deque<T> X;
const X::size_type source_size(726); const X::size_type source_size(726);
...@@ -407,13 +415,13 @@ rangeAssignmentCheck() ...@@ -407,13 +415,13 @@ rangeAssignmentCheck()
X a(starting_size, starting_value); X a(starting_size, starting_value);
VERIFY(starting_size == a.size()); VERIFY(starting_size == a.size());
gnu_copy_tracker::reset(); copy_tracker::reset();
a.assign(i, j); a.assign(i, j);
VERIFY(source == a); VERIFY(source == a);
VERIFY(rangeSize == (gnu_copy_constructor::count() + gnu_assignment_operator::count())); VERIFY(rangeSize == (copy_constructor::count() + assignment_operator::count()));
VERIFY(starting_size == (gnu_destructor::count() + gnu_assignment_operator::count())); VERIFY(starting_size == (destructor::count() + assignment_operator::count()));
} }
...@@ -423,7 +431,7 @@ void ...@@ -423,7 +431,7 @@ void
rangeAssignmentCheckWithException() rangeAssignmentCheckWithException()
{ {
// setup // setup
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T> X; typedef std::deque<T> X;
// test // test
...@@ -436,7 +444,7 @@ void ...@@ -436,7 +444,7 @@ void
fillAssignmentCheck2() fillAssignmentCheck2()
{ {
// setup // setup
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T> X; typedef std::deque<T> X;
// test // test
...@@ -449,12 +457,12 @@ void ...@@ -449,12 +457,12 @@ void
test_default_ctor_exception_safety() test_default_ctor_exception_safety()
{ {
// setup // setup
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T, gnu_new_allocator<T> > X; typedef std::deque<T, tracker_alloc<T> > X;
T::reset(); T::reset();
gnu_copy_constructor::throw_on(3); copy_constructor::throw_on(3);
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
// test // test
try try
...@@ -467,7 +475,7 @@ test_default_ctor_exception_safety() ...@@ -467,7 +475,7 @@ test_default_ctor_exception_safety()
} }
// assert postconditions // assert postconditions
VERIFY(gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal()); VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
// teardown // teardown
} }
...@@ -477,14 +485,14 @@ void ...@@ -477,14 +485,14 @@ void
test_copy_ctor_exception_safety() test_copy_ctor_exception_safety()
{ {
// setup // setup
typedef gnu_copy_tracker T; typedef copy_tracker T;
typedef std::deque<T, gnu_new_allocator<T> > X; typedef std::deque<T, tracker_alloc<T> > X;
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
{ {
X a(7); X a(7);
T::reset(); T::reset();
gnu_copy_constructor::throw_on(3); copy_constructor::throw_on(3);
// test // test
...@@ -499,7 +507,7 @@ test_copy_ctor_exception_safety() ...@@ -499,7 +507,7 @@ test_copy_ctor_exception_safety()
} }
// assert postconditions // assert postconditions
VERIFY(gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal()); VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
// teardown // teardown
} }
......
// Copyright (C) 2001 Free Software Foundation, Inc. // Copyright (C) 2001, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include <list> #include <list>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
typedef gnu_copy_tracker T; typedef __gnu_cxx_test::copy_tracker T;
bool test = true; bool test = true;
......
// 1999-05-07 // 1999-05-07
// bkoz // bkoz
// Copyright (C) 1999, 2002 Free Software Foundation, Inc. // Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -26,6 +26,13 @@ ...@@ -26,6 +26,13 @@
#include <testsuite_allocator.h> #include <testsuite_allocator.h>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
using __gnu_cxx_test::copy_tracker;
using __gnu_cxx_test::allocation_tracker;
using __gnu_cxx_test::tracker_alloc;
using __gnu_cxx_test::copy_constructor;
using __gnu_cxx_test::assignment_operator;
using __gnu_cxx_test::destructor;
template<typename T> template<typename T>
struct A { }; struct A { };
...@@ -58,7 +65,6 @@ void test01() ...@@ -58,7 +65,6 @@ void test01()
void test02() void test02()
{ {
bool test = true; bool test = true;
{ {
std::vector<int> array; std::vector<int> array;
const std::size_t size = array.max_size(); const std::size_t size = array.max_size();
...@@ -104,10 +110,11 @@ void test02() ...@@ -104,10 +110,11 @@ void test02()
void void
test_reserve() test_reserve()
{ {
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
{ {
X a(3); X a(3);
const X::size_type old_size = a.size(); const X::size_type old_size = a.size();
...@@ -121,11 +128,11 @@ test_reserve() ...@@ -121,11 +128,11 @@ test_reserve()
VERIFY(new_capacity <= a.capacity()); VERIFY(new_capacity <= a.capacity());
// [23.2.4.1 (3)] // [23.2.4.1 (3)]
VERIFY(old_size == a.size()); VERIFY(old_size == a.size());
VERIFY(gnu_copy_constructor::count() <= old_size); VERIFY(copy_constructor::count() <= old_size);
VERIFY(gnu_destructor::count() <= old_size); VERIFY(destructor::count() <= old_size);
} }
// check for memory leaks // check for memory leaks
VERIFY(gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal()); VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
} }
// Verifies that reserve() with reallocation offers the strong // Verifies that reserve() with reallocation offers the strong
...@@ -133,17 +140,18 @@ test_reserve() ...@@ -133,17 +140,18 @@ test_reserve()
void void
test_reserve_exception_guarantee() test_reserve_exception_guarantee()
{ {
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
{ {
X a(7); X a(7);
const X::size_type old_size = a.size(); const X::size_type old_size = a.size();
const X::size_type old_capacity = a.capacity(); const X::size_type old_capacity = a.capacity();
const X::size_type new_capacity = old_capacity + 10; const X::size_type new_capacity = old_capacity + 10;
T::reset(); T::reset();
gnu_copy_constructor::throw_on(3); copy_constructor::throw_on(3);
try try
{ {
...@@ -155,9 +163,9 @@ test_reserve_exception_guarantee() ...@@ -155,9 +163,9 @@ test_reserve_exception_guarantee()
} }
VERIFY(old_capacity == a.capacity()); VERIFY(old_capacity == a.capacity());
VERIFY(gnu_copy_constructor::count() == gnu_destructor::count()+1); VERIFY(copy_constructor::count() == destructor::count()+1);
} }
VERIFY(gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal()); VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
} }
int main() int main()
......
// 1999-06-29 bkoz // 1999-06-29 bkoz
// Copyright (C) 1999-2001, 2002 Free Software Foundation, Inc. // Copyright (C) 1999-2001, 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -25,6 +25,12 @@ ...@@ -25,6 +25,12 @@
#include <testsuite_allocator.h> #include <testsuite_allocator.h>
#include <testsuite_hooks.h> #include <testsuite_hooks.h>
using __gnu_cxx_test::copy_tracker;
using __gnu_cxx_test::allocation_tracker;
using __gnu_cxx_test::tracker_alloc;
using __gnu_cxx_test::copy_constructor;
using __gnu_cxx_test::assignment_operator;
template<typename T> template<typename T>
struct A { }; struct A { };
...@@ -32,7 +38,6 @@ struct B { }; ...@@ -32,7 +38,6 @@ struct B { };
void test01() void test01()
{ {
// 1 // 1
bool test = true; bool test = true;
std::vector< A<B> > vec01; std::vector< A<B> > vec01;
...@@ -62,11 +67,11 @@ void test02() ...@@ -62,11 +67,11 @@ void test02()
void void
test03() test03()
{ {
bool test = true;
const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
const int B[] = {7, 7, 7, 7, 7}; const int B[] = {7, 7, 7, 7, 7};
const int N = sizeof(A) / sizeof(int); const int N = sizeof(A) / sizeof(int);
const int M = sizeof(B) / sizeof(int); const int M = sizeof(B) / sizeof(int);
bool test = true;
std::vector<int> v3(A, A + N); std::vector<int> v3(A, A + N);
VERIFY(std::equal(v3.begin(), v3.end(), A)); VERIFY(std::equal(v3.begin(), v3.end(), A));
...@@ -105,12 +110,13 @@ void ...@@ -105,12 +110,13 @@ void
test_default_ctor_exception_gurantee() test_default_ctor_exception_gurantee()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_copy_constructor::throw_on(3); copy_constructor::throw_on(3);
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
// run test // run test
try try
...@@ -124,7 +130,7 @@ test_default_ctor_exception_gurantee() ...@@ -124,7 +130,7 @@ test_default_ctor_exception_gurantee()
// assert postconditions // assert postconditions
VERIFY(("memory leak detected:", VERIFY(("memory leak detected:",
gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal())); allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal()));
// teardown // teardown
} }
...@@ -137,14 +143,15 @@ void ...@@ -137,14 +143,15 @@ void
test_copy_ctor_exception_gurantee() test_copy_ctor_exception_gurantee()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
{ {
X a(7); X a(7);
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_copy_constructor::throw_on(3); copy_constructor::throw_on(3);
// run test // run test
try try
...@@ -158,11 +165,11 @@ test_copy_ctor_exception_gurantee() ...@@ -158,11 +165,11 @@ test_copy_ctor_exception_gurantee()
} }
// assert postconditions // assert postconditions
VERIFY(gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal()); VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
// operator=() // operator=()
...@@ -175,13 +182,14 @@ void ...@@ -175,13 +182,14 @@ void
test_assignment_operator_1() test_assignment_operator_1()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
X r(9); X r(9);
X a(r.size() - 2); X a(r.size() - 2);
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
// preconditions // preconditions
VERIFY(r.size() > a.size()); VERIFY(r.size() > a.size());
...@@ -191,25 +199,26 @@ test_assignment_operator_1() ...@@ -191,25 +199,26 @@ test_assignment_operator_1()
// assert postconditions // assert postconditions
VERIFY(r == a); VERIFY(r == a);
VERIFY(gnu_allocator_tracker::allocationTotal() == 0); VERIFY(allocation_tracker::allocationTotal() == 0);
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
void void
test_assignment_operator_2() test_assignment_operator_2()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
X r(1); X r(1);
r.reserve(17); r.reserve(17);
X a(r.size() + 7); X a(r.size() + 7);
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
// preconditions // preconditions
VERIFY(r.size() < a.size()); VERIFY(r.size() < a.size());
...@@ -220,25 +229,26 @@ test_assignment_operator_2() ...@@ -220,25 +229,26 @@ test_assignment_operator_2()
// assert postconditions // assert postconditions
VERIFY(r == a); VERIFY(r == a);
VERIFY(gnu_allocator_tracker::allocationTotal() == 0); VERIFY(allocation_tracker::allocationTotal() == 0);
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
void void
test_assignment_operator_3() test_assignment_operator_3()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
{ {
X r(1); X r(1);
X a(r.capacity() + 7); X a(r.capacity() + 7);
gnu_copy_tracker::reset(); copy_tracker::reset();
// preconditions // preconditions
VERIFY(r.capacity() < a.size()); VERIFY(r.capacity() < a.size());
...@@ -249,26 +259,27 @@ test_assignment_operator_3() ...@@ -249,26 +259,27 @@ test_assignment_operator_3()
// assert postconditions // assert postconditions
VERIFY(r == a); VERIFY(r == a);
} }
VERIFY(gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal()); VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
void void
test_assignment_operator_3_exception_guarantee() test_assignment_operator_3_exception_guarantee()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
{ {
X r(1); X r(1);
X a(r.capacity() + 7); X a(r.capacity() + 7);
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_copy_constructor::throw_on(3); copy_constructor::throw_on(3);
// preconditions // preconditions
VERIFY(r.capacity() < a.size()); VERIFY(r.capacity() < a.size());
...@@ -285,11 +296,11 @@ test_assignment_operator_3_exception_guarantee() ...@@ -285,11 +296,11 @@ test_assignment_operator_3_exception_guarantee()
} }
// assert postconditions // assert postconditions
VERIFY(gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal()); VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
// fill assign() // fill assign()
...@@ -304,35 +315,37 @@ void ...@@ -304,35 +315,37 @@ void
test_fill_assign_1() test_fill_assign_1()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
X a(7); X a(7);
X::size_type old_size = a.size(); X::size_type old_size = a.size();
X::size_type new_size = old_size - 2; X::size_type new_size = old_size - 2;
const T t; const T t;
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
// run test // run test
a.assign(new_size, t); a.assign(new_size, t);
// assert postconditions // assert postconditions
VERIFY(a.size() == new_size); VERIFY(a.size() == new_size);
VERIFY(gnu_allocator_tracker::allocationTotal() == 0); VERIFY(allocation_tracker::allocationTotal() == 0);
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
void void
test_fill_assign_2() test_fill_assign_2()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
X a(7); X a(7);
a.reserve(11); a.reserve(11);
...@@ -341,8 +354,8 @@ test_fill_assign_2() ...@@ -341,8 +354,8 @@ test_fill_assign_2()
X::size_type new_size = old_size + 2; X::size_type new_size = old_size + 2;
const T t; const T t;
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
// assert preconditions // assert preconditions
VERIFY(old_size < new_size); VERIFY(old_size < new_size);
...@@ -353,21 +366,22 @@ test_fill_assign_2() ...@@ -353,21 +366,22 @@ test_fill_assign_2()
// assert postconditions // assert postconditions
VERIFY(a.size() == new_size); VERIFY(a.size() == new_size);
VERIFY(gnu_allocator_tracker::allocationTotal() == 0); VERIFY(allocation_tracker::allocationTotal() == 0);
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
void void
test_fill_assign_3() test_fill_assign_3()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
{ {
X a(7); X a(7);
X::size_type old_size = a.size(); X::size_type old_size = a.size();
...@@ -375,7 +389,7 @@ test_fill_assign_3() ...@@ -375,7 +389,7 @@ test_fill_assign_3()
X::size_type new_size = old_capacity + 4; X::size_type new_size = old_capacity + 4;
const T t; const T t;
gnu_copy_tracker::reset(); copy_tracker::reset();
// assert preconditions // assert preconditions
VERIFY(new_size > old_capacity); VERIFY(new_size > old_capacity);
...@@ -387,22 +401,23 @@ test_fill_assign_3() ...@@ -387,22 +401,23 @@ test_fill_assign_3()
VERIFY(a.size() == new_size); VERIFY(a.size() == new_size);
} }
VERIFY(gnu_allocator_tracker::allocationTotal() > 0); VERIFY(allocation_tracker::allocationTotal() > 0);
VERIFY(gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal()); VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
void void
test_fill_assign_3_exception_guarantee() test_fill_assign_3_exception_guarantee()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
{ {
X a(7); X a(7);
X::size_type old_size = a.size(); X::size_type old_size = a.size();
...@@ -410,8 +425,8 @@ test_fill_assign_3_exception_guarantee() ...@@ -410,8 +425,8 @@ test_fill_assign_3_exception_guarantee()
X::size_type new_size = old_capacity + 4; X::size_type new_size = old_capacity + 4;
const T t; const T t;
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_copy_constructor::throw_on(3); copy_constructor::throw_on(3);
// assert preconditions // assert preconditions
VERIFY(new_size > old_capacity); VERIFY(new_size > old_capacity);
...@@ -431,39 +446,40 @@ test_fill_assign_3_exception_guarantee() ...@@ -431,39 +446,40 @@ test_fill_assign_3_exception_guarantee()
VERIFY(a.capacity() == old_capacity); VERIFY(a.capacity() == old_capacity);
} }
VERIFY(gnu_allocator_tracker::allocationTotal() > 0); VERIFY(allocation_tracker::allocationTotal() > 0);
VERIFY(gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal()); VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
void void
test_fill_assign_4() test_fill_assign_4()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
X a(7); X a(7);
X::size_type old_size = a.size(); X::size_type old_size = a.size();
X::size_type new_size = old_size - 2; X::size_type new_size = old_size - 2;
X::size_type new_value = 117; X::size_type new_value = 117;
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
// run test // run test
a.assign(new_size, new_value); a.assign(new_size, new_value);
// assert postconditions // assert postconditions
VERIFY(a.size() == new_size); VERIFY(a.size() == new_size);
VERIFY(gnu_allocator_tracker::allocationTotal() == 0); VERIFY(allocation_tracker::allocationTotal() == 0);
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
// range assign() // range assign()
...@@ -486,15 +502,16 @@ void ...@@ -486,15 +502,16 @@ void
test_range_assign_2() test_range_assign_2()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
X a(7); X a(7);
X b(3); X b(3);
X::size_type old_size = a.size(); X::size_type old_size = a.size();
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
// assert preconditions // assert preconditions
VERIFY(b.size() < a.capacity()); VERIFY(b.size() < a.capacity());
...@@ -505,27 +522,28 @@ test_range_assign_2() ...@@ -505,27 +522,28 @@ test_range_assign_2()
// assert postconditions // assert postconditions
VERIFY(a.size() == b.size()); VERIFY(a.size() == b.size());
VERIFY(a == b); VERIFY(a == b);
VERIFY(gnu_allocator_tracker::allocationTotal() == 0); VERIFY(allocation_tracker::allocationTotal() == 0);
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
void void
test_range_assign_3() test_range_assign_3()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
X a(7); X a(7);
a.reserve(a.size() + 7); a.reserve(a.size() + 7);
X b(a.size() + 3); X b(a.size() + 3);
X::size_type old_size = a.size(); X::size_type old_size = a.size();
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
// assert preconditions // assert preconditions
VERIFY(a.size() < b.size()); VERIFY(a.size() < b.size());
...@@ -537,27 +555,28 @@ test_range_assign_3() ...@@ -537,27 +555,28 @@ test_range_assign_3()
// assert postconditions // assert postconditions
VERIFY(a.size() == b.size()); VERIFY(a.size() == b.size());
VERIFY(a == b); VERIFY(a == b);
VERIFY(gnu_allocator_tracker::allocationTotal() == 0); VERIFY(allocation_tracker::allocationTotal() == 0);
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
void void
test_range_assign_4() test_range_assign_4()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
{ {
X a(7); X a(7);
X b(a.capacity() + 7); X b(a.capacity() + 7);
X::size_type old_size = a.size(); X::size_type old_size = a.size();
gnu_copy_tracker::reset(); copy_tracker::reset();
// assert preconditions // assert preconditions
VERIFY(b.size() > a.capacity()); VERIFY(b.size() > a.capacity());
...@@ -569,29 +588,30 @@ test_range_assign_4() ...@@ -569,29 +588,30 @@ test_range_assign_4()
VERIFY(a.size() == b.size()); VERIFY(a.size() == b.size());
VERIFY(a == b); VERIFY(a == b);
} }
VERIFY(gnu_allocator_tracker::allocationTotal() > 0); VERIFY(allocation_tracker::allocationTotal() > 0);
VERIFY(gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal()); VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
void void
test_range_assign_4_exception_guarantee() test_range_assign_4_exception_guarantee()
{ {
// setup // setup
typedef gnu_copy_tracker T; bool test = true;
typedef std::vector<T, gnu_new_allocator<T> > X; typedef copy_tracker T;
typedef std::vector<T, tracker_alloc<T> > X;
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
{ {
X a(7); X a(7);
X b(a.capacity() + 7); X b(a.capacity() + 7);
X::size_type old_size = a.size(); X::size_type old_size = a.size();
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_copy_constructor::throw_on(3); copy_constructor::throw_on(3);
// assert preconditions // assert preconditions
VERIFY(b.size() > a.capacity()); VERIFY(b.size() > a.capacity());
...@@ -608,12 +628,12 @@ test_range_assign_4_exception_guarantee() ...@@ -608,12 +628,12 @@ test_range_assign_4_exception_guarantee()
} }
// assert postconditions // assert postconditions
VERIFY(gnu_allocator_tracker::allocationTotal() > 0); VERIFY(allocation_tracker::allocationTotal() > 0);
VERIFY(gnu_allocator_tracker::allocationTotal() == gnu_allocator_tracker::deallocationTotal()); VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
// teardown // teardown
gnu_copy_tracker::reset(); copy_tracker::reset();
gnu_allocator_tracker::resetCounts(); allocation_tracker::resetCounts();
} }
......
// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char // 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Free Software Foundation, Inc. // Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
...@@ -45,9 +45,10 @@ void test01() ...@@ -45,9 +45,10 @@ void test01()
namespace test namespace test
{ {
using namespace std; using namespace std;
using __gnu_cxx_test::pod_char;
typedef short type_t; typedef short type_t;
template class basic_filebuf<type_t, char_traits<type_t> >; template class basic_filebuf<type_t, char_traits<type_t> >;
template class basic_filebuf<gnu_char, char_traits<gnu_char> >; template class basic_filebuf<pod_char, char_traits<pod_char> >;
} // test } // test
......
// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> // 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2002 Free Software Foundation, Inc. // Copyright (C) 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -50,9 +50,10 @@ void test01() ...@@ -50,9 +50,10 @@ void test01()
namespace test namespace test
{ {
using namespace std; using namespace std;
using __gnu_cxx_test::pod_char;
typedef short type_t; typedef short type_t;
template class basic_fstream<type_t, char_traits<type_t> >; template class basic_fstream<type_t, char_traits<type_t> >;
template class basic_fstream<gnu_char, char_traits<gnu_char> >; template class basic_fstream<pod_char, char_traits<pod_char> >;
} // test } // test
int main() int main()
......
// 1999-09-20 bkoz // 1999-09-20 bkoz
// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -50,9 +50,10 @@ void test01() ...@@ -50,9 +50,10 @@ void test01()
namespace test namespace test
{ {
using namespace std; using namespace std;
using __gnu_cxx_test::pod_char;
typedef short type_t; typedef short type_t;
template class basic_istream<type_t, char_traits<type_t> >; template class basic_istream<type_t, char_traits<type_t> >;
template class basic_istream<gnu_char, char_traits<gnu_char> >; template class basic_istream<pod_char, char_traits<pod_char> >;
} // test } // test
int main() int main()
......
// 1999-09-20 bkoz // 1999-09-20 bkoz
// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -50,9 +50,10 @@ void test01() ...@@ -50,9 +50,10 @@ void test01()
namespace test namespace test
{ {
using namespace std; using namespace std;
using __gnu_cxx_test::pod_char;
typedef short type_t; typedef short type_t;
template class basic_ostream<type_t, char_traits<type_t> >; template class basic_ostream<type_t, char_traits<type_t> >;
template class basic_ostream<gnu_char, char_traits<gnu_char> >; template class basic_ostream<pod_char, char_traits<pod_char> >;
} // test } // test
int main() int main()
......
// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> // 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2002 Free Software Foundation, Inc. // Copyright (C) 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -50,9 +50,10 @@ void test01() ...@@ -50,9 +50,10 @@ void test01()
namespace test namespace test
{ {
using namespace std; using namespace std;
using __gnu_cxx_test::pod_char;
typedef short type_t; typedef short type_t;
template class basic_streambuf<type_t, char_traits<type_t> >; template class basic_streambuf<type_t, char_traits<type_t> >;
template class basic_streambuf<gnu_char, char_traits<gnu_char> >; template class basic_streambuf<pod_char, char_traits<pod_char> >;
} // test } // test
int main() int main()
......
// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> // 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2002 Free Software Foundation, Inc. // Copyright (C) 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -50,9 +50,10 @@ void test01() ...@@ -50,9 +50,10 @@ void test01()
namespace test namespace test
{ {
using namespace std; using namespace std;
using __gnu_cxx_test::pod_char;
typedef short type_t; typedef short type_t;
template class basic_stringbuf<type_t, char_traits<type_t> >; template class basic_stringbuf<type_t, char_traits<type_t> >;
template class basic_stringbuf<gnu_char, char_traits<gnu_char> >; template class basic_stringbuf<pod_char, char_traits<pod_char> >;
} // test } // test
int main() int main()
......
// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> // 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
// Copyright (C) 2002 Free Software Foundation, Inc. // Copyright (C) 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -50,9 +50,10 @@ void test01() ...@@ -50,9 +50,10 @@ void test01()
namespace test namespace test
{ {
using namespace std; using namespace std;
using __gnu_cxx_test::pod_char;
typedef short type_t; typedef short type_t;
template class basic_stringstream<type_t, char_traits<type_t> >; template class basic_stringstream<type_t, char_traits<type_t> >;
template class basic_stringstream<gnu_char, char_traits<gnu_char> >; template class basic_stringstream<pod_char, char_traits<pod_char> >;
} // test } // test
int main() int main()
......
...@@ -233,7 +233,7 @@ proc libstdc++-v3-list-sourcefiles { } { ...@@ -233,7 +233,7 @@ proc libstdc++-v3-list-sourcefiles { } {
set f [open $files_file "w"] set f [open $files_file "w"]
set where_we_were [pwd] set where_we_were [pwd]
cd $srcdir cd $srcdir
foreach s [lsort [glob -nocomplain "{,*/}*/*.cc"]] { foreach s [lsort [glob -nocomplain "*/*.cc" "*/*/*.cc" "{,*/}*/*/*/*.cc" ]] {
lappend sfiles ${srcdir}/${s} lappend sfiles ${srcdir}/${s}
puts $f $s puts $f $s
} }
......
// -*- C++ -*-
// Testing allocator for the C++ library testsuite.
// //
// Copyright (C) 2002 Free Software Foundation, Inc. // Copyright (C) 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -28,8 +30,11 @@ ...@@ -28,8 +30,11 @@
#include <testsuite_allocator.h> #include <testsuite_allocator.h>
gnu_allocator_tracker::size_type gnu_allocator_tracker::allocationTotal_ = 0; namespace __gnu_cxx_test
gnu_allocator_tracker::size_type gnu_allocator_tracker::deallocationTotal_ = 0; {
int gnu_allocator_tracker::constructCount_ = 0; allocation_tracker::size_type allocation_tracker::allocationTotal_ = 0;
int gnu_allocator_tracker::destructCount_ = 0; allocation_tracker::size_type allocation_tracker::deallocationTotal_ = 0;
int allocation_tracker::constructCount_ = 0;
int allocation_tracker::destructCount_ = 0;
}; // namespace __cxx_test
// -*- C++ -*-
// Testing allocator for the C++ library testsuite. // Testing allocator for the C++ library testsuite.
// //
// Copyright (C) 2002 Free Software Foundation, Inc. // Copyright (C) 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -37,8 +38,10 @@ ...@@ -37,8 +38,10 @@
#include <cstddef> #include <cstddef>
#include <limits> #include <limits>
class gnu_allocator_tracker namespace __gnu_cxx_test
{ {
class allocation_tracker
{
public: public:
typedef std::size_t size_type; typedef std::size_t size_type;
...@@ -50,12 +53,10 @@ class gnu_allocator_tracker ...@@ -50,12 +53,10 @@ class gnu_allocator_tracker
} }
static void static void
construct() construct() { constructCount_++; }
{ constructCount_++; }
static void static void
destroy() destroy() { destructCount_++; }
{ destructCount_++; }
static void static void
deallocate(void* p, size_type blocksize) deallocate(void* p, size_type blocksize)
...@@ -65,20 +66,16 @@ class gnu_allocator_tracker ...@@ -65,20 +66,16 @@ class gnu_allocator_tracker
} }
static size_type static size_type
allocationTotal() allocationTotal() { return allocationTotal_; }
{ return allocationTotal_; }
static size_type static size_type
deallocationTotal() deallocationTotal() { return deallocationTotal_; }
{ return deallocationTotal_; }
static int static int
constructCount() constructCount() { return constructCount_; }
{ return constructCount_; }
static int static int
destructCount() destructCount() { return destructCount_; }
{ return destructCount_; }
static void static void
resetCounts() resetCounts()
...@@ -94,14 +91,13 @@ class gnu_allocator_tracker ...@@ -94,14 +91,13 @@ class gnu_allocator_tracker
static size_type deallocationTotal_; static size_type deallocationTotal_;
static int constructCount_; static int constructCount_;
static int destructCount_; static int destructCount_;
}; };
// A simple basic allocator that just forwards to the // A simple basic allocator that just forwards to the
// gnu_allocator_tracker to fulfill memory requests. This class is // allocation_tracker to fulfill memory requests. This class is
// templated on the target object type, but gnu_allocator_tracker // templated on the target object type, but tracker isn't.
// isn't. template<class T>
template<class T> class tracker_alloc
class gnu_new_allocator
{ {
public: public:
typedef T value_type; typedef T value_type;
...@@ -112,7 +108,7 @@ template<class T> ...@@ -112,7 +108,7 @@ template<class T>
typedef std::size_t size_type; typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type; typedef std::ptrdiff_t difference_type;
template<class U> struct rebind { typedef gnu_new_allocator<U> other; }; template<class U> struct rebind { typedef tracker_alloc<U> other; };
pointer pointer
address(reference value) const address(reference value) const
...@@ -122,17 +118,17 @@ template<class T> ...@@ -122,17 +118,17 @@ template<class T>
address(const_reference value) const address(const_reference value) const
{ return &value; } { return &value; }
gnu_new_allocator() throw() tracker_alloc() throw()
{ } { }
gnu_new_allocator(const gnu_new_allocator&) throw() tracker_alloc(const tracker_alloc&) throw()
{ } { }
template<class U> template<class U>
gnu_new_allocator(const gnu_new_allocator<U>&) throw() tracker_alloc(const tracker_alloc<U>&) throw()
{ } { }
~gnu_new_allocator() throw() ~tracker_alloc() throw()
{ } { }
size_type size_type
...@@ -140,42 +136,40 @@ template<class T> ...@@ -140,42 +136,40 @@ template<class T>
{ return std::numeric_limits<std::size_t>::max() / sizeof(T); } { return std::numeric_limits<std::size_t>::max() / sizeof(T); }
pointer pointer
allocate(size_type num, const void* = 0) allocate(size_type n, const void* = 0)
{ {
return static_cast<pointer>(gnu_allocator_tracker::allocate(num * return static_cast<pointer>(allocation_tracker::allocate(n * sizeof(T)));
sizeof(T)));
} }
void void
construct(pointer p, const T& value) construct(pointer p, const T& value)
{ {
new (p) T(value); new (p) T(value);
gnu_allocator_tracker::construct(); allocation_tracker::construct();
} }
void void
destroy(pointer p) destroy(pointer p)
{ {
p->~T(); p->~T();
gnu_allocator_tracker::destroy(); allocation_tracker::destroy();
} }
void void
deallocate(pointer p, size_type num) deallocate(pointer p, size_type num)
{ gnu_allocator_tracker::deallocate(p, num * sizeof(T)); } { allocation_tracker::deallocate(p, num * sizeof(T)); }
}; };
template<class T1, class T2> template<class T1, class T2>
bool bool
operator==(const gnu_new_allocator<T1>&, operator==(const tracker_alloc<T1>&, const tracker_alloc<T2>&) throw()
const gnu_new_allocator<T2>&) throw()
{ return true; } { return true; }
template<class T1, class T2> template<class T1, class T2>
bool bool
operator!=(const gnu_new_allocator<T1>&, operator!=(const tracker_alloc<T1>&, const tracker_alloc<T2>&) throw()
const gnu_new_allocator<T2>&) throw()
{ return false; } { return false; }
}; // namespace __gnu_cxx_test
#endif // _GLIBCPP_TESTSUITE_ALLOCATOR_H #endif // _GLIBCPP_TESTSUITE_ALLOCATOR_H
// -*- C++ -*-
// Utility subroutines for the C++ library testsuite. // Utility subroutines for the C++ library testsuite.
// //
// Copyright (C) 2002 Free Software Foundation, Inc. // Copyright (C) 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -33,14 +34,22 @@ ...@@ -33,14 +34,22 @@
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/resource.h> #include <sys/resource.h>
#endif
#include <list>
#include <string>
#include <stdexcept>
#include <clocale>
#include <locale>
void namespace __gnu_cxx_test
__set_testsuite_memlimit(float __size)
{ {
#ifdef _GLIBCPP_MEM_LIMITS
void
set_memory_limits(float size)
{
struct rlimit r; struct rlimit r;
// Cater to the absence of rlim_t. // Cater to the absence of rlim_t.
__typeof__ (r.rlim_cur) limit __typeof__ (r.rlim_cur) limit = (__typeof__ (r.rlim_cur))(size * 1048576);
= (__typeof__ (r.rlim_cur))(__size * 1048576);
// Heap size, seems to be common. // Heap size, seems to be common.
#if _GLIBCPP_HAVE_MEMLIMIT_DATA #if _GLIBCPP_HAVE_MEMLIMIT_DATA
...@@ -69,19 +78,90 @@ __set_testsuite_memlimit(float __size) ...@@ -69,19 +78,90 @@ __set_testsuite_memlimit(float __size)
r.rlim_cur = limit; r.rlim_cur = limit;
setrlimit(RLIMIT_AS, &r); setrlimit(RLIMIT_AS, &r);
#endif #endif
} }
#else #else
void void
__set_testsuite_memlimit(float) { } set_memory_limits(float) { }
#endif /* _GLIBCPP_MEM_LIMITS */ #endif
// Useful exceptions.
class locale_data : public std::runtime_error
{
public:
explicit
locale_data(const std::string& __arg) : runtime_error(__arg) { }
};
class environment_variable: public std::runtime_error
{
public:
explicit
environment_variable(const std::string& __arg) : runtime_error(__arg) { }
};
class not_found : public std::runtime_error
{
public:
explicit
not_found(const std::string& __arg) : runtime_error(__arg) { }
};
gnu_counting_struct::size_type gnu_counting_struct::count = 0; void
run_tests_wrapped_locale(const char* name, const func_callback& l)
{
using namespace std;
bool test = true;
unsigned int gnu_copy_constructor::count_ = 0; // Set the global locale.
unsigned int gnu_copy_constructor::throw_on_ = 0; locale loc_name(name);
unsigned int gnu_assignment_operator::count_ = 0; locale orig = locale::global(loc_name);
unsigned int gnu_assignment_operator::throw_on_ = 0;
unsigned int gnu_destructor::count_ = 0; const char* res = setlocale(LC_ALL, name);
int gnu_copy_tracker::next_id_ = 0; if (res != NULL)
{
string preLC_ALL = res;
for (func_callback::const_iterator i = l.begin(); i != l.end(); ++i)
(*i)();
string postLC_ALL= setlocale(LC_ALL, NULL);
VERIFY( preLC_ALL == postLC_ALL );
}
else
throw environment_variable(string("LC_ALL for") + string(name));
}
void
run_tests_wrapped_env(const char* name, const char* env,
const func_callback& l)
{
using namespace std;
bool test = true;
#ifdef _GLIBCPP_HAVE_SETENV
// Set the global locale.
locale loc_name(name);
locale orig = locale::global(loc_name);
// Set environment variable env to value in name.
const char* oldENV = getenv(env);
if (!setenv(env, name, 1))
{
for (func_callback::const_iterator i = l.begin(); i != l.end(); ++i)
(*i)();
setenv(env, oldENV ? oldENV : "", 1);
}
else
throw environment_variable(string(env) + string(" to ") + string(name));
#else
throw not_found("setenv");
#endif
}
counter::size_type counter::count = 0;
unsigned int copy_constructor::count_ = 0;
unsigned int copy_constructor::throw_on_ = 0;
unsigned int assignment_operator::count_ = 0;
unsigned int assignment_operator::throw_on_ = 0;
unsigned int destructor::_M_count = 0;
int copy_tracker::next_id_ = 0;
}; // namespace __cxx_test
// -*- C++ -*-
// Utility subroutines for the C++ library testsuite. // Utility subroutines for the C++ library testsuite.
// //
// Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // 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 // software; you can redistribute it and/or modify it under the
...@@ -34,24 +35,24 @@ ...@@ -34,24 +35,24 @@
// #define(able) assert() behavior for debugging/testing. It may be // #define(able) assert() behavior for debugging/testing. It may be
// a suitable location for other furry woodland creatures as well. // a suitable location for other furry woodland creatures as well.
// //
// 2) __set_testsuite_memlimit() // 2) set_memory_limits()
// __set_testsuite_memlimit() uses setrlimit() to restrict dynamic memory // set_memory_limits() uses setrlimit() to restrict dynamic memory
// allocation. We provide a default memory limit if none is passed by the // allocation. We provide a default memory limit if none is passed by the
// calling application. The argument to __set_testsuite_memlimit() is the // calling application. The argument to set_memory_limits() is the
// limit in megabytes (a floating-point number). If _GLIBCPP_MEM_LIMITS is // limit in megabytes (a floating-point number). If _GLIBCPP_MEM_LIMITS is
// not #defined before including this header, then no limiting is attempted. // not #defined before including this header, then no limiting is attempted.
// //
// 3) gnu_counting_struct // 3) counter
// This is a POD with a static data member, gnu_counting_struct::count, // This is a POD with a static data member, gnu_counting_struct::count,
// which starts at zero, increments on instance construction, and decrements // which starts at zero, increments on instance construction, and decrements
// on instance destruction. "assert_count(n)" can be called to VERIFY() // on instance destruction. "assert_count(n)" can be called to VERIFY()
// that the count equals N. // that the count equals N.
// //
// 4) gnu_copy_tracker, from Stephen M. Webb <stephen@bregmasoft.com>. // 4) copy_tracker, from Stephen M. Webb <stephen@bregmasoft.com>.
// A class with nontrivial ctor/dtor that provides the ability to track the // A class with nontrivial ctor/dtor that provides the ability to track the
// number of copy ctors and dtors, and will throw on demand during copy. // number of copy ctors and dtors, and will throw on demand during copy.
// //
// 5) gnu_char, gnu_char_traits, abstract character classes and // 5) pod_char, pod_int, , abstract character classes and
// char_traits specializations for testing instantiations. // char_traits specializations for testing instantiations.
#ifndef _GLIBCPP_TESTSUITE_HOOKS_H #ifndef _GLIBCPP_TESTSUITE_HOOKS_H
...@@ -60,64 +61,101 @@ ...@@ -60,64 +61,101 @@
#include <bits/c++config.h> #include <bits/c++config.h>
#include <bits/functexcept.h> #include <bits/functexcept.h>
#include <cstddef> #include <cstddef>
#ifdef DEBUG_ASSERT #ifdef DEBUG_ASSERT
# include <cassert> # include <cassert>
# define VERIFY(fn) assert(fn) # define VERIFY(fn) assert(fn)
#else #else
# define VERIFY(fn) test &= (fn) # define VERIFY(fn) test &= (fn)
#endif #endif
#include <list>
// Defined in GLIBCPP_CONFIGURE_TESTSUITE. namespace __gnu_cxx_test
#ifndef _GLIBCPP_MEM_LIMITS {
// Don't do memory limits. // All macros are defined in GLIBCPP_CONFIGURE_TESTSUITE and imported
extern void // from c++config.h
__set_testsuite_memlimit(float x = 0);
// Set memory limits if possible, if not set to 0.
#ifndef _GLIBCPP_MEM_LIMITS
# define MEMLIMIT_MB 0
#else #else
# ifndef MEMLIMIT_MB
// Do memory limits. # define MEMLIMIT_MB 16.0
#ifndef MEMLIMIT_MB # endif
#define MEMLIMIT_MB 16.0
#endif #endif
extern void
set_memory_limits(float __size = MEMLIMIT_MB);
extern void // Simple callback structure for variable numbers of tests (all with
__set_testsuite_memlimit(float __size = MEMLIMIT_MB); // same signature). Assume all unit tests are of the signature
#endif // void test01();
typedef void (*test_func) (void);
typedef std::list<test_func> func_callback;
// Run select unit tests after setting global locale.
void
run_tests_wrapped_locale(const char*, const func_callback&);
struct gnu_counting_struct // Run select unit tests after setting environment variables.
{ void
run_tests_wrapped_env(const char*, const char*, const func_callback&);
// Test data types.
struct pod_char
{
unsigned char c;
};
struct pod_int
{
int i;
};
struct pod_unsigned_int
{
unsigned int i;
};
struct pod_long
{
unsigned long i;
};
struct state
{
unsigned long l;
unsigned long l2;
};
// Counting.
struct counter
{
// Specifically and glaringly-obviously marked 'signed' so that when // Specifically and glaringly-obviously marked 'signed' so that when
// COUNT mistakenly goes negative, we can track the patterns of // COUNT mistakenly goes negative, we can track the patterns of
// deletions more easily. // deletions more easily.
typedef signed int size_type; typedef signed int size_type;
static size_type count; static size_type count;
gnu_counting_struct() { ++count; } counter() { ++count; }
gnu_counting_struct (const gnu_counting_struct&) { ++count; } counter (const counter&) { ++count; }
~gnu_counting_struct() { --count; } ~counter() { --count; }
}; };
#define assert_count(n) VERIFY(gnu_counting_struct::count == n) #define assert_count(n) VERIFY(__gnu_cxx_test::counter::count == n)
// A (static) class for counting copy constructors and possibly throwing an // A (static) class for counting copy constructors and possibly throwing an
// exception on a desired count. // exception on a desired count.
class gnu_copy_constructor class copy_constructor
{ {
public: public:
static unsigned int static unsigned int
count() count() { return count_; }
{ return count_; }
static void static void
mark_call() mark_call()
{ {
count_++; count_++;
if (count_ == throw_on_) if (count_ == throw_on_)
{
__throw_exception_again "copy constructor exception"; __throw_exception_again "copy constructor exception";
} }
}
static void static void
reset() reset()
...@@ -127,32 +165,28 @@ public: ...@@ -127,32 +165,28 @@ public:
} }
static void static void
throw_on(unsigned int count) throw_on(unsigned int count) { throw_on_ = count; }
{ throw_on_ = count; }
private: private:
static unsigned int count_; static unsigned int count_;
static unsigned int throw_on_; static unsigned int throw_on_;
}; };
// A (static) class for counting assignment operator calls and possibly // A (static) class for counting assignment operator calls and
// throwing an exception on a desired count. // possibly throwing an exception on a desired count.
class gnu_assignment_operator class assignment_operator
{ {
public: public:
static unsigned int static unsigned int
count() count() { return count_; }
{ return count_; }
static void static void
mark_call() mark_call()
{ {
count_++; count_++;
if (count_ == throw_on_) if (count_ == throw_on_)
{
__throw_exception_again "assignment operator exception"; __throw_exception_again "assignment operator exception";
} }
}
static void static void
reset() reset()
...@@ -162,83 +196,71 @@ public: ...@@ -162,83 +196,71 @@ public:
} }
static void static void
throw_on(unsigned int count) throw_on(unsigned int count) { throw_on_ = count; }
{ throw_on_ = count; }
private: private:
static unsigned int count_; static unsigned int count_;
static unsigned int throw_on_; static unsigned int throw_on_;
}; };
// A (static) class for tracking calls to an object's destructor. // A (static) class for tracking calls to an object's destructor.
class gnu_destructor class destructor
{ {
public: public:
static unsigned int static unsigned int
count() count() { return _M_count; }
{ return count_; }
static void static void
mark_call() mark_call() { _M_count++; }
{ count_++; }
static void static void
reset() reset() { _M_count = 0; }
{ count_ = 0; }
private: private:
static unsigned int count_; static unsigned int _M_count;
}; };
// An class of objects that can be used for validating various behaviours and // An class of objects that can be used for validating various
// guarantees of containers and algorithms defined in the standard library. // behaviours and guarantees of containers and algorithms defined in
class gnu_copy_tracker // the standard library.
{ class copy_tracker
public:
// Creates a copy-tracking object with the given ID number.
// If "throw_on_copy" is set, an exception will be thrown if
// an attempt is made to copy this object.
gnu_copy_tracker(int id = next_id_--, bool throw_on_copy = false)
: id_(id)
, throw_on_copy_(throw_on_copy)
{ {
} public:
// Creates a copy-tracking object with the given ID number. If
// "throw_on_copy" is set, an exception will be thrown if an
// attempt is made to copy this object.
copy_tracker(int id = next_id_--, bool throw_on_copy = false)
: id_(id) , throw_on_copy_(throw_on_copy) { }
// Copy-constructs the object, marking a call to the copy // Copy-constructs the object, marking a call to the copy
// constructor and forcing an exception if indicated. // constructor and forcing an exception if indicated.
gnu_copy_tracker(const gnu_copy_tracker& rhs) copy_tracker(const copy_tracker& rhs)
: id_(rhs.id()), throw_on_copy_(rhs.throw_on_copy_) : id_(rhs.id()), throw_on_copy_(rhs.throw_on_copy_)
{ {
int kkk = throw_on_copy_; int kkk = throw_on_copy_;
if (throw_on_copy_) if (throw_on_copy_)
{ copy_constructor::throw_on(copy_constructor::count() + 1);
gnu_copy_constructor::throw_on(gnu_copy_constructor::count() + 1); copy_constructor::mark_call();
}
gnu_copy_constructor::mark_call();
} }
// Assigns the value of another object to this one, tracking the // Assigns the value of another object to this one, tracking the
// number of times this member function has been called and if the // number of times this member function has been called and if the
// other object is supposed to throw an exception when it is // other object is supposed to throw an exception when it is
// copied, well, make it so. // copied, well, make it so.
gnu_copy_tracker& copy_tracker&
operator=(const gnu_copy_tracker& rhs) operator=(const copy_tracker& rhs)
{ {
id_ = rhs.id(); id_ = rhs.id();
if (rhs.throw_on_copy_) if (rhs.throw_on_copy_)
{ assignment_operator::throw_on(assignment_operator::count() + 1);
gnu_assignment_operator::throw_on(gnu_assignment_operator::count() assignment_operator::mark_call();
+ 1);
}
gnu_assignment_operator::mark_call();
} }
~gnu_copy_tracker() ~copy_tracker()
{ gnu_destructor::mark_call(); } { destructor::mark_call(); }
int int
id() const id() const { return id_; }
{ return id_; }
private: private:
int id_; int id_;
...@@ -248,59 +270,44 @@ class gnu_copy_tracker ...@@ -248,59 +270,44 @@ class gnu_copy_tracker
static void static void
reset() reset()
{ {
gnu_copy_constructor::reset(); copy_constructor::reset();
gnu_assignment_operator::reset(); assignment_operator::reset();
gnu_destructor::reset(); destructor::reset();
} }
// for backwards-compatibility // for backwards-compatibility
static int static int
copyCount() copyCount()
{ return gnu_copy_constructor::count(); } { return copy_constructor::count(); }
// for backwards-compatibility // for backwards-compatibility
static int static int
dtorCount() dtorCount()
{ return gnu_destructor::count(); } { return destructor::count(); }
private: private:
static int next_id_; static int next_id_;
}; };
inline bool
operator==(const gnu_copy_tracker& lhs, const gnu_copy_tracker& rhs)
{ return lhs.id() == rhs.id(); }
struct gnu_char
{
unsigned long c;
};
struct gnu_int
{
unsigned long i;
};
struct gnu_state inline bool
{ operator==(const copy_tracker& lhs, const copy_tracker& rhs)
unsigned long l; { return lhs.id() == rhs.id(); }
unsigned long l2; }; // namespace __gnu_cxx_test
};
// char_traits specialization
namespace std namespace std
{ {
template<class _CharT> template<class _CharT>
struct char_traits; struct char_traits;
// char_traits specialization
template<> template<>
struct char_traits<gnu_char> struct char_traits<__gnu_cxx_test::pod_char>
{ {
typedef gnu_char char_type; typedef __gnu_cxx_test::pod_char char_type;
typedef gnu_int int_type; typedef __gnu_cxx_test::pod_int int_type;
typedef long pos_type; typedef long pos_type;
typedef unsigned long off_type; typedef unsigned long off_type;
typedef gnu_state state_type; typedef __gnu_cxx_test::state state_type;
static void static void
assign(char_type& __c1, const char_type& __c2); assign(char_type& __c1, const char_type& __c2);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment