list_capacity.cc: New file.
2001-11-22 Stephen M. Webb <stephen@bregmasoft.com> * testsuite/23_containers/list_capacity.cc: New file. * testsuite/23_containers/list_ctor.cc: New file. * testsuite/23_containers/list_modifiers.cc: New file. * testsuite/23_containers/list_operators.cc: New file. 2001-11-22 Stephen M. Webb <stephen@bregmasoft.com> * include/bits/stl_list.h: Reformatted according to C++STYLE rules. (size): Replaced nonstandard distance() call with the standard one. (transfer): Uglified to _M_transfer. From-SVN: r47277
This commit is contained in:
parent
60f4621c9a
commit
1fc610939a
6 changed files with 1841 additions and 696 deletions
|
@ -1,3 +1,16 @@
|
|||
2001-11-22 Stephen M. Webb <stephen@bregmasoft.com>
|
||||
|
||||
* testsuite/23_containers/list_capacity.cc: New file.
|
||||
* testsuite/23_containers/list_ctor.cc: New file.
|
||||
* testsuite/23_containers/list_modifiers.cc: New file.
|
||||
* testsuite/23_containers/list_operators.cc: New file.
|
||||
|
||||
2001-11-22 Stephen M. Webb <stephen@bregmasoft.com>
|
||||
|
||||
* include/bits/stl_list.h: Reformatted according to C++STYLE rules.
|
||||
(size): Replaced nonstandard distance() call with the standard one.
|
||||
(transfer): Uglified to _M_transfer.
|
||||
|
||||
2001-11-21 Paolo Carlini <pcarlini@unitus.it>
|
||||
|
||||
PR libstdc++/4548
|
||||
|
|
File diff suppressed because it is too large
Load diff
70
libstdc++-v3/testsuite/23_containers/list_capacity.cc
Normal file
70
libstdc++-v3/testsuite/23_containers/list_capacity.cc
Normal file
|
@ -0,0 +1,70 @@
|
|||
// Copyright (C) 2001 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)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without Pred 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// 23.2.2.2 list capacity [lib.list.capacity]
|
||||
|
||||
#include <list>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
bool test = true;
|
||||
|
||||
// This test verifies the following.
|
||||
//
|
||||
// 23.2.2 bool empty() const
|
||||
// 23.2.2 size_type size() const
|
||||
// 23.2.2 iterator begin()
|
||||
// 23.2.2 iterator end()
|
||||
// 23.2.2.3 void push_back(const T&)
|
||||
// 23.2.2 size_type max_size() const
|
||||
// 23.2.2.2 void resize(size_type s, T c = T())
|
||||
//
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::list<int> list0101;
|
||||
VERIFY(list0101.empty());
|
||||
VERIFY(list0101.size() == 0);
|
||||
|
||||
list0101.push_back(1);
|
||||
VERIFY(!list0101.empty());
|
||||
VERIFY(list0101.size() == 1);
|
||||
|
||||
list0101.resize(3, 2);
|
||||
VERIFY(!list0101.empty());
|
||||
VERIFY(list0101.size() == 3);
|
||||
|
||||
std::list<int>::iterator i = list0101.begin();
|
||||
VERIFY(*i == 1); ++i;
|
||||
VERIFY(*i == 2); ++i;
|
||||
VERIFY(*i == 2); ++i;
|
||||
VERIFY(i == list0101.end());
|
||||
|
||||
list0101.resize(0);
|
||||
VERIFY(list0101.empty());
|
||||
VERIFY(list0101.size() == 0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
test01();
|
||||
|
||||
return !test;
|
||||
}
|
||||
|
||||
// vi:set sw=2 ts=2:
|
332
libstdc++-v3/testsuite/23_containers/list_ctor.cc
Normal file
332
libstdc++-v3/testsuite/23_containers/list_ctor.cc
Normal file
|
@ -0,0 +1,332 @@
|
|||
// Copyright (C) 2001 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)
|
||||
// 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// 23.2.2.1 list constructors, copy, and assignment
|
||||
|
||||
#include <list>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
bool test = true;
|
||||
|
||||
// A nontrivial type.
|
||||
template<typename T>
|
||||
struct A { };
|
||||
|
||||
// Another nontrivial type
|
||||
struct B { };
|
||||
|
||||
// A nontrivial type convertible from an int
|
||||
struct C {
|
||||
C(int i) : i_(i) { }
|
||||
bool operator==(const C& rhs) { return i_ == rhs.i_; }
|
||||
int i_;
|
||||
};
|
||||
|
||||
// Default constructor, basic properties
|
||||
//
|
||||
// This test verifies the following.
|
||||
// 23.2.2.1 explicit list(const a& = Allocator())
|
||||
// 23.1 (7) iterator behaviour of empty containers
|
||||
// 23.2.2 iterator begin()
|
||||
// 23.2.2 iterator end()
|
||||
// 23.2.2 size_type size() const
|
||||
// 23.2.2 existence of required typedefs
|
||||
//
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::list< A<B> > list0101;
|
||||
VERIFY(list0101.begin() == list0101.end());
|
||||
VERIFY(list0101.size() == 0);
|
||||
|
||||
// check type definitions -- will fail compile if missing
|
||||
typedef std::list< A<B> >::reference reference;
|
||||
typedef std::list< A<B> >::const_reference const_reference;
|
||||
typedef std::list< A<B> >::iterator iterator;
|
||||
typedef std::list< A<B> >::const_iterator const_iterator;
|
||||
typedef std::list< A<B> >::size_type size_type;
|
||||
typedef std::list< A<B> >::difference_type difference_type;
|
||||
typedef std::list< A<B> >::value_type value_type;
|
||||
typedef std::list< A<B> >::allocator_type allocator_type;
|
||||
typedef std::list< A<B> >::pointer pointer;
|
||||
typedef std::list< A<B> >::const_pointer const_pointer;
|
||||
typedef std::list< A<B> >::reverse_iterator reverse_iterator;
|
||||
typedef std::list< A<B> >::const_reverse_iterator const_reverse_iterator;
|
||||
|
||||
// allocator checks?
|
||||
}
|
||||
|
||||
// Fill constructor
|
||||
//
|
||||
// This test verifies the following.
|
||||
// 23.2.2.1 explicit list(size_type n, const T& v = T(), const a& = Allocator())
|
||||
// 23.2.2 const_iterator begin() const
|
||||
// 23.2.2 const_iterator end() const
|
||||
// 23.2.2 size_type size() const
|
||||
//
|
||||
void
|
||||
test02()
|
||||
{
|
||||
const int LIST_SIZE = 5;
|
||||
const int INIT_VALUE = 7;
|
||||
int count;
|
||||
std::list<int>::const_iterator i;
|
||||
|
||||
// nontrivial value_type
|
||||
std::list< A<B> > list0201(LIST_SIZE);
|
||||
|
||||
// default value
|
||||
std::list<int> list0202(LIST_SIZE);
|
||||
for (i = list0202.begin(), count = 0;
|
||||
i != list0202.end();
|
||||
++i, ++count)
|
||||
VERIFY(*i == 0);
|
||||
VERIFY(count == LIST_SIZE);
|
||||
VERIFY(list0202.size() == LIST_SIZE);
|
||||
|
||||
// explicit value
|
||||
std::list<int> list0203(LIST_SIZE, INIT_VALUE);
|
||||
for (i = list0203.begin(), count = 0;
|
||||
i != list0203.end();
|
||||
++i, ++count)
|
||||
VERIFY(*i == INIT_VALUE);
|
||||
VERIFY(count == LIST_SIZE);
|
||||
VERIFY(list0203.size() == LIST_SIZE);
|
||||
}
|
||||
|
||||
// Fill constructor disguised as a range constructor
|
||||
void
|
||||
test02D()
|
||||
{
|
||||
const int LIST_SIZE = 5;
|
||||
const int INIT_VALUE = 7;
|
||||
int count = 0;
|
||||
std::list<C> list0204(LIST_SIZE, INIT_VALUE);
|
||||
std::list<C>::iterator i = list0204.begin();
|
||||
for (; i != list0204.end(); ++i, ++count)
|
||||
VERIFY(*i == INIT_VALUE);
|
||||
VERIFY(count == LIST_SIZE);
|
||||
VERIFY(list0204.size() == LIST_SIZE);
|
||||
}
|
||||
|
||||
// Range constructor
|
||||
//
|
||||
// This test verifies the following.
|
||||
// 23.2.2.1 template list(InputIterator f, InputIterator l, const Allocator& a = Allocator())
|
||||
// 23.2.2 const_iterator begin() const
|
||||
// 23.2.2 const_iterator end() const
|
||||
// 23.2.2 size_type size() const
|
||||
//
|
||||
void
|
||||
test03()
|
||||
{
|
||||
const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
|
||||
const int N = sizeof(A) / sizeof(int);
|
||||
int count;
|
||||
std::list<int>::const_iterator i;
|
||||
|
||||
// construct from a dissimilar range
|
||||
std::list<int> list0301(A, A + N);
|
||||
for (i = list0301.begin(), count = 0;
|
||||
i != list0301.end();
|
||||
++i, ++count)
|
||||
VERIFY(*i == A[count]);
|
||||
VERIFY(count == N);
|
||||
VERIFY(list0301.size() == N);
|
||||
|
||||
// construct from a similar range
|
||||
std::list<int> list0302(list0301.begin(), list0301.end());
|
||||
for (i = list0302.begin(), count = 0;
|
||||
i != list0302.end();
|
||||
++i, ++count)
|
||||
VERIFY(*i == A[count]);
|
||||
VERIFY(count == N);
|
||||
VERIFY(list0302.size() == N);
|
||||
}
|
||||
|
||||
// Copy constructor
|
||||
//
|
||||
// This test verifies the following.
|
||||
// 23.2.2.1 list(const list& x)
|
||||
// 23.2.2 reverse_iterator rbegin()
|
||||
// 23.2.2 reverse_iterator rend()
|
||||
// 23.2.2 size_type size() const
|
||||
//
|
||||
void
|
||||
test04()
|
||||
{
|
||||
const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
|
||||
const int N = sizeof(A) / sizeof(int);
|
||||
int count;
|
||||
std::list<int>::reverse_iterator i;
|
||||
std::list<int> list0401(A, A + N);
|
||||
|
||||
std::list<int> list0402(list0401);
|
||||
for (i = list0401.rbegin(), count = N - 1;
|
||||
i != list0401.rend();
|
||||
++i, --count)
|
||||
VERIFY(*i == A[count]);
|
||||
VERIFY(count == -1);
|
||||
VERIFY(list0401.size() == N);
|
||||
}
|
||||
|
||||
// Range assign
|
||||
//
|
||||
// This test verifies the following.
|
||||
// 23.2.2.1 void assign(InputIterator f, InputIterator l)
|
||||
// 23.2.2 const_iterator begin() const
|
||||
// 23.2.2 const_iterator end() const
|
||||
// 23.2.2 size_type size() const
|
||||
//
|
||||
void
|
||||
test05()
|
||||
{
|
||||
const int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
|
||||
const int B[] = {101, 102, 103, 104, 105};
|
||||
const int N = sizeof(A) / sizeof(int);
|
||||
const int M = sizeof(B) / sizeof(int);
|
||||
int count;
|
||||
std::list<int>::const_iterator i;
|
||||
|
||||
std::list<int> list0501;
|
||||
|
||||
// make it bigger
|
||||
list0501.assign(A, A + N);
|
||||
for (i = list0501.begin(), count = 0;
|
||||
i != list0501.end();
|
||||
++i, ++count)
|
||||
VERIFY(*i == A[count]);
|
||||
VERIFY(count == N);
|
||||
VERIFY(list0501.size() == N);
|
||||
|
||||
// make it smaller
|
||||
list0501.assign(B, B + M);
|
||||
for (i = list0501.begin(), count = 0;
|
||||
i != list0501.end();
|
||||
++i, ++count)
|
||||
VERIFY(*i == B[count]);
|
||||
VERIFY(count == M);
|
||||
VERIFY(list0501.size() == M);
|
||||
}
|
||||
|
||||
// Fill assign
|
||||
//
|
||||
// This test verifies the following.
|
||||
// 23.2.2.1 void assign(size_type n, const T& v)
|
||||
// 23.2.2 const_iterator begin() const
|
||||
// 23.2.2 const_iterator end() const
|
||||
// 23.2.2 size_type size() const
|
||||
//
|
||||
void
|
||||
test06()
|
||||
{
|
||||
const int BIG_LIST_SIZE = 11;
|
||||
const int BIG_INIT_VALUE = 7;
|
||||
const int SMALL_LIST_SIZE = 5;
|
||||
const int SMALL_INIT_VALUE = 17;
|
||||
int count;
|
||||
std::list<int>::const_iterator i;
|
||||
|
||||
std::list<int> list0601;
|
||||
VERIFY(list0601.size() == 0);
|
||||
|
||||
// make it bigger
|
||||
list0601.assign(BIG_LIST_SIZE, BIG_INIT_VALUE);
|
||||
for (i = list0601.begin(), count = 0;
|
||||
i != list0601.end();
|
||||
++i, ++count)
|
||||
VERIFY(*i == BIG_INIT_VALUE);
|
||||
VERIFY(count == BIG_LIST_SIZE);
|
||||
VERIFY(list0601.size() == BIG_LIST_SIZE);
|
||||
|
||||
// make it shrink
|
||||
list0601.assign(SMALL_LIST_SIZE, SMALL_INIT_VALUE);
|
||||
for (i = list0601.begin(), count = 0;
|
||||
i != list0601.end();
|
||||
++i, ++count)
|
||||
VERIFY(*i == SMALL_INIT_VALUE);
|
||||
VERIFY(count == SMALL_LIST_SIZE);
|
||||
VERIFY(list0601.size() == SMALL_LIST_SIZE);
|
||||
}
|
||||
|
||||
// Fill Assignment disguised as a Range Assignment
|
||||
void
|
||||
test06D()
|
||||
{
|
||||
const int LIST_SIZE = 5;
|
||||
const int INIT_VALUE = 7;
|
||||
int count = 0;
|
||||
std::list<C> list0604;
|
||||
VERIFY(list0604.size() == 0);
|
||||
|
||||
list0604.assign(LIST_SIZE, INIT_VALUE);
|
||||
std::list<C>::iterator i = list0604.begin();
|
||||
for (; i != list0604.end(); ++i, ++count)
|
||||
VERIFY(*i == INIT_VALUE);
|
||||
VERIFY(count == LIST_SIZE);
|
||||
VERIFY(list0604.size() == LIST_SIZE);
|
||||
}
|
||||
|
||||
// Assignment operator
|
||||
//
|
||||
// This test verifies the following.
|
||||
// 23.2.2 operator=(const list& x)
|
||||
// 23.2.2 iterator begin()
|
||||
// 23.2.2 iterator end()
|
||||
// 23.2.2 size_type size() const
|
||||
// 23.2.2 bool operator==(const list& x, const list& y)
|
||||
//
|
||||
void
|
||||
test07()
|
||||
{
|
||||
const int A[] = {701, 702, 703, 704, 705};
|
||||
const int N = sizeof(A) / sizeof(int);
|
||||
int count;
|
||||
std::list<int>::iterator i;
|
||||
|
||||
std::list<int> list0701(A, A + N);
|
||||
VERIFY(list0701.size() == N);
|
||||
|
||||
std::list<int> list0702;
|
||||
VERIFY(list0702.size() == 0);
|
||||
|
||||
list0702 = list0701;
|
||||
VERIFY(list0702.size() == N);
|
||||
for (i = list0702.begin(), count = 0;
|
||||
i != list0702.end();
|
||||
++i, ++count)
|
||||
VERIFY(*i == A[count]);
|
||||
VERIFY(count == N);
|
||||
VERIFY(list0702 == list0701);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
test02D();
|
||||
test03();
|
||||
test04();
|
||||
test05();
|
||||
test06();
|
||||
test06D();
|
||||
test07();
|
||||
|
||||
return !test;
|
||||
}
|
||||
// vi:set sw=2 ts=2:
|
325
libstdc++-v3/testsuite/23_containers/list_modifiers.cc
Normal file
325
libstdc++-v3/testsuite/23_containers/list_modifiers.cc
Normal file
|
@ -0,0 +1,325 @@
|
|||
// Copyright (C) 2001 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)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without Pred 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// 23.2.2.3 list modifiers [lib.list.modifiers]
|
||||
|
||||
#include <list>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
bool test = true;
|
||||
|
||||
// Here's 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.
|
||||
class T
|
||||
{
|
||||
public:
|
||||
// default constructor
|
||||
T(int anId, bool throwOnDemand = false)
|
||||
: itsId(anId), willThrow(throwOnDemand)
|
||||
{ }
|
||||
|
||||
// copy constructor
|
||||
T(const T& rhs)
|
||||
: itsId(rhs.id()), willThrow(rhs.willThrow)
|
||||
{
|
||||
++itsCopyCount;
|
||||
if (willThrow)
|
||||
throw "exception";
|
||||
}
|
||||
|
||||
~T()
|
||||
{ ++itsDtorCount; }
|
||||
|
||||
int
|
||||
id() const
|
||||
{ return itsId; }
|
||||
|
||||
private:
|
||||
const int itsId;
|
||||
const bool willThrow;
|
||||
|
||||
public:
|
||||
static void
|
||||
reset()
|
||||
{ itsCopyCount = 0; itsDtorCount = 0; }
|
||||
|
||||
static int
|
||||
copyCount()
|
||||
{ return itsCopyCount; }
|
||||
|
||||
static int
|
||||
dtorCount()
|
||||
{ return itsDtorCount; }
|
||||
|
||||
private:
|
||||
static int itsCopyCount;
|
||||
static int itsDtorCount;
|
||||
};
|
||||
|
||||
int T::itsCopyCount = 0;
|
||||
int T::itsDtorCount = 0;
|
||||
|
||||
|
||||
// This test verifies the following.
|
||||
//
|
||||
// 23.2.2.3 void push_front(const T& x)
|
||||
// 23.2.2.3 void push_back(const T& x)
|
||||
// 23.2.2.3 (1) iterator and reference non-invalidation
|
||||
// 23.2.2.3 (1) exception effects
|
||||
// 23.2.2.3 (2) complexity requirements
|
||||
//
|
||||
// 23.2.2.3 void pop_front()
|
||||
// 23.2.2.3 void pop_back()
|
||||
// 23.2.2.3 (3) iterator and reference non-invalidation
|
||||
// 23.2.2.3 (5) complexity requirements
|
||||
//
|
||||
// 23.2.2 const_iterator begin() const
|
||||
// 23.2.2 iterator end()
|
||||
// 23.2.2 const_reverse_iterator rbegin() const
|
||||
// 23.2.2 _reference front()
|
||||
// 23.2.2 const_reference front() const
|
||||
// 23.2.2 reference back()
|
||||
// 23.2.2 const_reference back() const
|
||||
//
|
||||
void
|
||||
test01()
|
||||
{
|
||||
std::list<T> list0101;
|
||||
std::list<T>::const_iterator i;
|
||||
std::list<T>::const_reverse_iterator j;
|
||||
std::list<T>::iterator k;
|
||||
T::reset();
|
||||
|
||||
list0101.push_back(T(1)); // list should be [1]
|
||||
VERIFY(list0101.size() == 1);
|
||||
VERIFY(T::copyCount() == 1);
|
||||
|
||||
k = list0101.end();
|
||||
--k;
|
||||
VERIFY(k->id() == 1);
|
||||
VERIFY(k->id() == list0101.front().id());
|
||||
VERIFY(k->id() == list0101.back().id());
|
||||
|
||||
list0101.push_front(T(2)); // list should be [2 1]
|
||||
VERIFY(list0101.size() == 2);
|
||||
VERIFY(T::copyCount() == 2);
|
||||
VERIFY(k->id() == 1);
|
||||
|
||||
list0101.push_back(T(3)); // list should be [2 1 3]
|
||||
VERIFY(list0101.size() == 3);
|
||||
VERIFY(T::copyCount() == 3);
|
||||
VERIFY(k->id() == 1);
|
||||
|
||||
try
|
||||
{
|
||||
list0101.push_back(T(4, true));
|
||||
VERIFY(("no exception thrown", false));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
VERIFY(list0101.size() == 3);
|
||||
VERIFY(T::copyCount() == 4);
|
||||
}
|
||||
|
||||
i = list0101.begin();
|
||||
VERIFY(i->id() == 2);
|
||||
VERIFY(i->id() == list0101.front().id());
|
||||
|
||||
j = list0101.rbegin();
|
||||
VERIFY(j->id() == 3);
|
||||
VERIFY(j->id() == list0101.back().id());
|
||||
|
||||
++i;
|
||||
VERIFY(i->id() == 1);
|
||||
|
||||
++j;
|
||||
VERIFY(j->id() == 1);
|
||||
|
||||
T::reset();
|
||||
|
||||
list0101.pop_back(); // list should be [2 1]
|
||||
VERIFY(list0101.size() == 2);
|
||||
VERIFY(T::dtorCount() == 1);
|
||||
VERIFY(i->id() == 1);
|
||||
VERIFY(j->id() == 1);
|
||||
VERIFY(k->id() == 1);
|
||||
|
||||
list0101.pop_front(); // list should be [1]
|
||||
VERIFY(list0101.size() == 1);
|
||||
VERIFY(T::dtorCount() == 2);
|
||||
VERIFY(i->id() == 1);
|
||||
VERIFY(j->id() == 1);
|
||||
VERIFY(k->id() == 1);
|
||||
}
|
||||
|
||||
// general single insert/erase + swap
|
||||
void
|
||||
test02()
|
||||
{
|
||||
std::list<T> list0201;
|
||||
T::reset();
|
||||
|
||||
list0201.insert(list0201.begin(), T(1)); // list should be [1]
|
||||
VERIFY(list0201.size() == 1);
|
||||
VERIFY(T::copyCount() == 1);
|
||||
|
||||
list0201.insert(list0201.end(), T(2)); // list should be [1 2]
|
||||
VERIFY(list0201.size() == 2);
|
||||
VERIFY(T::copyCount() == 2);
|
||||
|
||||
std::list<T>::iterator i = list0201.begin();
|
||||
std::list<T>::const_iterator j = i;
|
||||
VERIFY(i->id() == 1); ++i;
|
||||
VERIFY(i->id() == 2);
|
||||
|
||||
list0201.insert(i, T(3)); // list should be [1 3 2]
|
||||
VERIFY(list0201.size() == 3);
|
||||
VERIFY(T::copyCount() == 3);
|
||||
|
||||
std::list<T>::const_iterator k = i;
|
||||
VERIFY(i->id() == 2); --i;
|
||||
VERIFY(i->id() == 3); --i;
|
||||
VERIFY(i->id() == 1);
|
||||
VERIFY(j->id() == 1);
|
||||
|
||||
++i; // will point to '3'
|
||||
T::reset();
|
||||
list0201.erase(i); // should be [1 2]
|
||||
VERIFY(list0201.size() == 2);
|
||||
VERIFY(T::dtorCount() == 1);
|
||||
VERIFY(k->id() == 2);
|
||||
VERIFY(j->id() == 1);
|
||||
|
||||
std::list<T> list0202;
|
||||
T::reset();
|
||||
VERIFY(list0202.size() == 0);
|
||||
VERIFY(T::copyCount() == 0);
|
||||
VERIFY(T::dtorCount() == 0);
|
||||
|
||||
// member swap
|
||||
list0202.swap(list0201);
|
||||
VERIFY(list0201.size() == 0);
|
||||
VERIFY(list0202.size() == 2);
|
||||
VERIFY(T::copyCount() == 0);
|
||||
VERIFY(T::dtorCount() == 0);
|
||||
|
||||
// specialized swap
|
||||
swap(list0201, list0202);
|
||||
VERIFY(list0201.size() == 2);
|
||||
VERIFY(list0202.size() == 0);
|
||||
VERIFY(T::copyCount() == 0);
|
||||
VERIFY(T::dtorCount() == 0);
|
||||
}
|
||||
|
||||
// range and fill insert/erase + clear
|
||||
// missing: o fill insert disguised as a range insert in all its variants
|
||||
// o exception effects
|
||||
void
|
||||
test03()
|
||||
{
|
||||
std::list<T> list0301;
|
||||
T::reset();
|
||||
|
||||
// fill insert at beginning of list / empty list
|
||||
list0301.insert(list0301.begin(), 3, T(11)); // should be [11 11 11]
|
||||
VERIFY(list0301.size() == 3);
|
||||
VERIFY(T::copyCount() == 3);
|
||||
|
||||
// save iterators to verify post-insert validity
|
||||
std::list<T>::iterator b = list0301.begin();
|
||||
std::list<T>::iterator m = list0301.end(); --m;
|
||||
std::list<T>::iterator e = list0301.end();
|
||||
|
||||
// fill insert at end of list
|
||||
T::reset();
|
||||
list0301.insert(list0301.end(), 3, T(13)); // should be [11 11 11 13 13 13]
|
||||
VERIFY(list0301.size() == 6);
|
||||
VERIFY(T::copyCount() == 3);
|
||||
VERIFY(b == list0301.begin() && b->id() == 11);
|
||||
VERIFY(e == list0301.end());
|
||||
VERIFY(m->id() == 11);
|
||||
|
||||
// fill insert in the middle of list
|
||||
++m;
|
||||
T::reset();
|
||||
list0301.insert(m, 3, T(12)); // should be [11 11 11 12 12 12 13 13 13]
|
||||
VERIFY(list0301.size() == 9);
|
||||
VERIFY(T::copyCount() == 3);
|
||||
VERIFY(b == list0301.begin() && b->id() == 11);
|
||||
VERIFY(e == list0301.end());
|
||||
VERIFY(m->id() == 13);
|
||||
|
||||
// single erase
|
||||
T::reset();
|
||||
m = list0301.erase(m); // should be [11 11 11 12 12 12 13 13]
|
||||
VERIFY(list0301.size() == 8);
|
||||
VERIFY(T::dtorCount() == 1);
|
||||
VERIFY(b == list0301.begin() && b->id() == 11);
|
||||
VERIFY(e == list0301.end());
|
||||
VERIFY(m->id() == 13);
|
||||
|
||||
// range erase
|
||||
T::reset();
|
||||
m = list0301.erase(list0301.begin(), m); // should be [13 13]
|
||||
VERIFY(list0301.size() == 2);
|
||||
VERIFY(T::dtorCount() == 6);
|
||||
VERIFY(m->id() == 13);
|
||||
|
||||
// range fill at beginning
|
||||
const int A[] = {321, 322, 333};
|
||||
const int N = sizeof(A) / sizeof(int);
|
||||
T::reset();
|
||||
b = list0301.begin();
|
||||
list0301.insert(b, A, A + N); // should be [321 322 333 13 13]
|
||||
VERIFY(list0301.size() == 5);
|
||||
VERIFY(T::copyCount() == 3);
|
||||
VERIFY(m->id() == 13);
|
||||
|
||||
// range fill at end
|
||||
T::reset();
|
||||
list0301.insert(e, A, A + N); // should be [321 322 333 13 13 321 322 333]
|
||||
VERIFY(list0301.size() == 8);
|
||||
VERIFY(T::copyCount() == 3);
|
||||
VERIFY(e == list0301.end());
|
||||
VERIFY(m->id() == 13);
|
||||
|
||||
// range fill in middle
|
||||
T::reset();
|
||||
list0301.insert(m, A, A + N);
|
||||
VERIFY(list0301.size() == 11);
|
||||
VERIFY(T::copyCount() == 3);
|
||||
VERIFY(e == list0301.end());
|
||||
VERIFY(m->id() == 13);
|
||||
|
||||
T::reset();
|
||||
list0301.clear();
|
||||
VERIFY(list0301.size() == 0);
|
||||
VERIFY(T::dtorCount() == 11);
|
||||
VERIFY(e == list0301.end());
|
||||
}
|
||||
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
test03();
|
||||
|
||||
return !test;
|
||||
}
|
||||
// vi:set sw=2 ts=2:
|
211
libstdc++-v3/testsuite/23_containers/list_operators.cc
Normal file
211
libstdc++-v3/testsuite/23_containers/list_operators.cc
Normal file
|
@ -0,0 +1,211 @@
|
|||
// Copyright (C) 2001 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)
|
||||
// any later version.
|
||||
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without Pred 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 COPYING. If not, write to the Free
|
||||
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
// USA.
|
||||
|
||||
// 23.2.2.4 list operations [lib.list.ops]
|
||||
|
||||
#include <list>
|
||||
#include <testsuite_hooks.h>
|
||||
|
||||
bool test = true;
|
||||
|
||||
// splice(p, x) + remove + reverse
|
||||
void
|
||||
test01()
|
||||
{
|
||||
const int K = 417;
|
||||
const int A[] = {1, 2, 3, 4, 5};
|
||||
const int B[] = {K, K, K, K, K};
|
||||
const int N = sizeof(A) / sizeof(int);
|
||||
const int M = sizeof(B) / sizeof(int);
|
||||
|
||||
std::list<int> list0101(A, A + N);
|
||||
std::list<int> list0102(B, B + M);
|
||||
std::list<int>::iterator p = list0101.begin();
|
||||
|
||||
VERIFY(list0101.size() == N);
|
||||
VERIFY(list0102.size() == M);
|
||||
|
||||
++p;
|
||||
list0101.splice(p, list0102); // [1 K K K K K 2 3 4 5]
|
||||
VERIFY(list0101.size() == N + M);
|
||||
VERIFY(list0102.size() == 0);
|
||||
|
||||
// remove range from middle
|
||||
list0101.remove(K);
|
||||
VERIFY(list0101.size() == N);
|
||||
|
||||
// remove first element
|
||||
list0101.remove(1);
|
||||
VERIFY(list0101.size() == N - 1);
|
||||
|
||||
// remove last element
|
||||
list0101.remove(5);
|
||||
VERIFY(list0101.size() == N - 2);
|
||||
|
||||
// reverse
|
||||
list0101.reverse();
|
||||
p = list0101.begin();
|
||||
VERIFY(*p == 4); ++p;
|
||||
VERIFY(*p == 3); ++p;
|
||||
VERIFY(*p == 2); ++p;
|
||||
VERIFY(p == list0101.end());
|
||||
}
|
||||
|
||||
// splice(p, x, i) + remove_if + operator==
|
||||
void
|
||||
test02()
|
||||
{
|
||||
const int A[] = {1, 2, 3, 4, 5};
|
||||
const int B[] = {2, 1, 3, 4, 5};
|
||||
const int C[] = {1, 3, 4, 5, 2};
|
||||
const int N = sizeof(A) / sizeof(int);
|
||||
std::list<int> list0201(A, A + N);
|
||||
std::list<int> list0202(A, A + N);
|
||||
std::list<int> list0203(B, B + N);
|
||||
std::list<int> list0204(C, C + N);
|
||||
std::list<int>::iterator i = list0201.begin();
|
||||
|
||||
// result should be unchanged
|
||||
list0201.splice(list0201.begin(), list0201, i);
|
||||
VERIFY(list0201 == list0202);
|
||||
|
||||
// result should be [2 1 3 4 5]
|
||||
++i;
|
||||
list0201.splice(list0201.begin(), list0201, i);
|
||||
VERIFY(list0201 != list0202);
|
||||
VERIFY(list0201 == list0203);
|
||||
|
||||
// result should be [1 3 4 5 2]
|
||||
list0201.splice(list0201.end(), list0201, i);
|
||||
VERIFY(list0201 == list0204);
|
||||
}
|
||||
|
||||
// splice(p, x, f, l) + sort + merge + unique
|
||||
void
|
||||
test03()
|
||||
{
|
||||
const int A[] = {103, 203, 603, 303, 403, 503};
|
||||
const int B[] = {417, 417, 417, 417, 417};
|
||||
const int E[] = {103, 417, 417, 203, 603, 303, 403, 503};
|
||||
const int F[] = {103, 203, 303, 403, 417, 417, 503, 603};
|
||||
const int C[] = {103, 203, 303, 403, 417, 417, 417, 417, 417, 503, 603};
|
||||
const int D[] = {103, 203, 303, 403, 417, 503, 603};
|
||||
const int N = sizeof(A) / sizeof(int);
|
||||
const int M = sizeof(B) / sizeof(int);
|
||||
const int P = sizeof(C) / sizeof(int);
|
||||
const int Q = sizeof(D) / sizeof(int);
|
||||
const int R = sizeof(E) / sizeof(int);
|
||||
|
||||
std::list<int> list0301(A, A + N);
|
||||
std::list<int> list0302(B, B + M);
|
||||
std::list<int> list0303(C, C + P);
|
||||
std::list<int> list0304(D, D + Q);
|
||||
std::list<int> list0305(E, E + R);
|
||||
std::list<int> list0306(F, F + R);
|
||||
std::list<int>::iterator p = list0301.begin();
|
||||
std::list<int>::iterator q = list0302.begin();
|
||||
|
||||
++p; ++q; ++q;
|
||||
list0301.splice(p, list0302, list0302.begin(), q);
|
||||
VERIFY(list0301 == list0305);
|
||||
VERIFY(list0301.size() == N + 2);
|
||||
VERIFY(list0302.size() == M - 2);
|
||||
|
||||
list0301.sort();
|
||||
VERIFY(list0301 == list0306);
|
||||
|
||||
list0301.merge(list0302);
|
||||
VERIFY(list0301.size() == N + M);
|
||||
VERIFY(list0302.size() == 0);
|
||||
VERIFY(list0301 == list0303);
|
||||
|
||||
list0301.unique();
|
||||
VERIFY(list0301 == list0304);
|
||||
}
|
||||
|
||||
// A comparison predicate to order by rightmost digit. Tracks call counts for
|
||||
// performance checks.
|
||||
struct CompLastLt
|
||||
{
|
||||
bool operator()(const int x, const int y) { ++itsCount; return x % 10 < y % 10; }
|
||||
static int count() { return itsCount; }
|
||||
static void reset() { itsCount = 0; }
|
||||
static int itsCount;
|
||||
};
|
||||
|
||||
int CompLastLt::itsCount;
|
||||
|
||||
struct CompLastEq
|
||||
{
|
||||
bool operator()(const int x, const int y) { ++itsCount; return x % 10 == y % 10; }
|
||||
static int count() { return itsCount; }
|
||||
static void reset() { itsCount = 0; }
|
||||
static int itsCount;
|
||||
};
|
||||
|
||||
int CompLastEq::itsCount;
|
||||
|
||||
// sort(pred) + merge(pred) + unique(pred)
|
||||
// also checks performance requirements
|
||||
void
|
||||
test04()
|
||||
{
|
||||
const int A[] = {1, 2, 3, 4, 5, 6};
|
||||
const int B[] = {12, 15, 13, 14, 11};
|
||||
const int C[] = {11, 12, 13, 14, 15};
|
||||
const int D[] = {1, 11, 2, 12, 3, 13, 4, 14, 5, 15, 6};
|
||||
const int N = sizeof(A) / sizeof(int);
|
||||
const int M = sizeof(B) / sizeof(int);
|
||||
const int Q = sizeof(D) / sizeof(int);
|
||||
|
||||
std::list<int> list0401(A, A + N);
|
||||
std::list<int> list0402(B, B + M);
|
||||
std::list<int> list0403(C, C + M);
|
||||
std::list<int> list0404(D, D + Q);
|
||||
std::list<int> list0405(A, A + N);
|
||||
|
||||
// sort B
|
||||
CompLastLt lt;
|
||||
|
||||
CompLastLt::reset();
|
||||
list0402.sort(lt);
|
||||
VERIFY(list0402 == list0403);
|
||||
|
||||
CompLastLt::reset();
|
||||
list0401.merge(list0402, lt);
|
||||
VERIFY(list0401 == list0404);
|
||||
VERIFY(lt.count() <= (N + M - 1));
|
||||
|
||||
CompLastEq eq;
|
||||
|
||||
CompLastEq::reset();
|
||||
list0401.unique(eq);
|
||||
VERIFY(list0401 == list0405);
|
||||
VERIFY(eq.count() == (N + M - 1));
|
||||
}
|
||||
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
test03();
|
||||
test04();
|
||||
|
||||
return !test;
|
||||
}
|
||||
// vi:set sw=2 ts=2:
|
Loading…
Add table
Reference in a new issue