#include <deque>
#include <iterator>
#include <sstream>
#include <testsuite_allocator.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::counter;
using __gnu_cxx_test::destructor;
typedef std::deque<counter> gdeque;
bool test = true;
void
test01()
{
assert_count (0);
{
gdeque d(10);
assert_count (10);
}
assert_count (0);
}
void
requiredTypesCheck()
{
typedef int T;
typedef std::deque<T> X;
typedef X::reference reference;
typedef X::const_reference const_reference;
typedef X::iterator iterator;
typedef X::const_iterator const_iterator;
typedef X::size_type size_type;
typedef X::difference_type difference_type;
typedef X::value_type value_type;
typedef X::allocator_type allocator_type;
typedef X::pointer pointer;
typedef X::const_pointer const_pointer;
typedef X::reverse_iterator reverse_iterator;
typedef X::const_reverse_iterator const_reverse_iterator;
}
void
defaultConstructorCheckPOD()
{
typedef int T;
typedef std::deque<T> X;
X u;
VERIFY(u.empty());
VERIFY(0 == u.size());
VERIFY(u.begin() == u.end());
VERIFY(0 == std::distance(u.begin(), u.end()));
}
void
defaultConstructorCheck()
{
typedef copy_tracker T;
typedef std::deque<T> X;
copy_tracker::reset();
const X u;
VERIFY(u.empty());
VERIFY(0 == u.size());
VERIFY(u.begin() == u.end());
VERIFY(0 == std::distance(u.begin(), u.end()));
}
void
copyConstructorCheck()
{
typedef copy_tracker T;
typedef std::deque<T> X;
const int copyBaseSize = 17;
X a;
for (int i = 0; i < copyBaseSize; ++i)
a.push_back(i);
copy_tracker::reset();
VERIFY(!a.empty());
VERIFY(copyBaseSize == a.size());
VERIFY(a.begin() != a.end());
VERIFY(copyBaseSize == std::distance(a.begin(), a.end()));
X u = a;
VERIFY(u == a);
VERIFY(copyBaseSize == copy_constructor::count());
}
void
fillConstructorCheck()
{
typedef copy_tracker T;
typedef std::deque<T> X;
const X::size_type n(23);
const X::value_type t(111);
copy_tracker::reset();
X a(n, t);
VERIFY(n == a.size());
VERIFY(n == copy_constructor::count());
}
void
fillConstructorCheck2()
{
typedef copy_tracker T;
typedef std::deque<T> X;
const int f = 23;
const int l = 111;
copy_tracker::reset();
X a(f, l);
VERIFY(f == a.size());
VERIFY(f == copy_constructor::count());
}
void
rangeConstructorCheckForwardIterator()
{
typedef copy_tracker T;
typedef std::deque<T> X;
const X::size_type n(726);
const X::value_type t(307);
X source(n, t);
X::iterator i = source.begin();
X::iterator j = source.end();
X::size_type rangeSize = std::distance(i, j);
copy_tracker::reset();
X a(i, j);
VERIFY(rangeSize == a.size());
VERIFY(copy_constructor::count() <= rangeSize);
}
void
rangeConstructorCheckInputIterator()
{
typedef copy_tracker T;
typedef std::deque<T> X;
std::istringstream ibuf("1234567890123456789");
const X::size_type rangeSize = ibuf.str().size();
std::istream_iterator<char> i(ibuf);
std::istream_iterator<char> j;
copy_tracker::reset();
X a(i, j);
VERIFY(rangeSize == a.size());
VERIFY(copy_constructor::count() <= (2 * rangeSize));
}
void
copyAssignmentCheck()
{
typedef copy_tracker T;
typedef std::deque<T> X;
const X::size_type n(18);
const X::value_type t(1023);
X a(n, t);
X r;
copy_tracker::reset();
r = a;
VERIFY(r == a);
VERIFY(n == copy_constructor::count());
}
void
fillAssignmentCheck()
{
typedef copy_tracker T;
typedef std::deque<T> X;
const X::size_type starting_size(10);
const X::value_type starting_value(66);
const X::size_type n(23);
const X::value_type t(111);
X a(starting_size, starting_value);
copy_tracker::reset();
VERIFY(starting_size == a.size());
a.assign(n, t);
VERIFY(n == a.size());
VERIFY(n == (copy_constructor::count() + assignment_operator::count()));
VERIFY(starting_size == (destructor::count() + assignment_operator::count()));
}
void
rangeAssignmentCheck()
{
typedef copy_tracker T;
typedef std::deque<T> X;
const X::size_type source_size(726);
const X::value_type source_value(307);
const X::size_type starting_size(10);
const X::value_type starting_value(66);
X source(source_size, source_value);
X::iterator i = source.begin();
X::iterator j = source.end();
X::size_type rangeSize = std::distance(i, j);
X a(starting_size, starting_value);
VERIFY(starting_size == a.size());
copy_tracker::reset();
a.assign(i, j);
VERIFY(source == a);
VERIFY(rangeSize == (copy_constructor::count() + assignment_operator::count()));
VERIFY(starting_size == (destructor::count() + assignment_operator::count()));
}
void
rangeAssignmentCheckWithException()
{
typedef copy_tracker T;
typedef std::deque<T> X;
}
void
fillAssignmentCheck2()
{
typedef copy_tracker T;
typedef std::deque<T> X;
}
void
test_default_ctor_exception_safety()
{
typedef copy_tracker T;
typedef std::deque<T, tracker_alloc<T> > X;
T::reset();
copy_constructor::throw_on(3);
allocation_tracker::resetCounts();
try
{
X a(7);
VERIFY(("no exception thrown", false));
}
catch (...)
{
}
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
}
void
test_copy_ctor_exception_safety()
{
typedef copy_tracker T;
typedef std::deque<T, tracker_alloc<T> > X;
allocation_tracker::resetCounts();
{
X a(7);
T::reset();
copy_constructor::throw_on(3);
try
{
X u(a);
VERIFY(("no exception thrown", false));
}
catch (...)
{
}
}
VERIFY(allocation_tracker::allocationTotal() == allocation_tracker::deallocationTotal());
}
int main()
{
requiredTypesCheck();
defaultConstructorCheckPOD();
defaultConstructorCheck();
test_default_ctor_exception_safety();
copyConstructorCheck();
test_copy_ctor_exception_safety();
fillConstructorCheck();
fillConstructorCheck2();
rangeConstructorCheckInputIterator();
rangeConstructorCheckForwardIterator();
copyAssignmentCheck();
fillAssignmentCheck();
fillAssignmentCheck2();
rangeAssignmentCheck();
rangeAssignmentCheckWithException();
test01();
return !test;
}