OSDN Git Service

d250db8c9076f5c132838c66be7d57fa96f85490
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / 1.cc
1 // Copyright (C) 2001, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library.  This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without Pred the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3.  If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // 23.2.2.3 list modifiers [lib.list.modifiers]
19
20 #include <list>
21 #include <testsuite_hooks.h>
22
23 typedef __gnu_test::copy_tracker  T;
24
25 bool test __attribute__((unused)) = true;
26
27 // range and fill insert/erase + clear
28 // missing: o  fill insert disguised as a range insert in all its variants
29 //          o  exception effects
30 void
31 test03()
32 {
33   std::list<T> list0301;
34   T::reset();
35
36   // fill insert at beginning of list / empty list
37   list0301.insert(list0301.begin(), 3, T(11)); // should be [11 11 11]
38   VERIFY(list0301.size() == 3);
39   VERIFY(T::copyCount() == 3);
40
41   // save iterators to verify post-insert validity
42   std::list<T>::iterator b = list0301.begin();          
43   std::list<T>::iterator m = list0301.end(); --m;          
44   std::list<T>::iterator e = list0301.end();
45
46   // fill insert at end of list
47   T::reset();
48   list0301.insert(list0301.end(), 3, T(13)); // should be [11 11 11 13 13 13]
49   VERIFY(list0301.size() == 6);
50   VERIFY(T::copyCount() == 3);
51   VERIFY(b == list0301.begin() && b->id() == 11);
52   VERIFY(e == list0301.end());
53   VERIFY(m->id() == 11);
54
55   // fill insert in the middle of list
56   ++m;
57   T::reset();
58   list0301.insert(m, 3, T(12)); // should be [11 11 11 12 12 12 13 13 13]
59   VERIFY(list0301.size() == 9);
60   VERIFY(T::copyCount() == 3);
61   VERIFY(b == list0301.begin() && b->id() == 11);
62   VERIFY(e == list0301.end());
63   VERIFY(m->id() == 13);
64
65   // single erase
66   T::reset();
67   m = list0301.erase(m); // should be [11 11 11 12 12 12 13 13]
68   VERIFY(list0301.size() == 8);
69   VERIFY(T::dtorCount() == 1);
70   VERIFY(b == list0301.begin() && b->id() == 11);
71   VERIFY(e == list0301.end());
72   VERIFY(m->id() == 13);
73
74   // range erase
75   T::reset();
76   m = list0301.erase(list0301.begin(), m); // should be [13 13]
77   VERIFY(list0301.size() == 2);
78   VERIFY(T::dtorCount() == 6);
79   VERIFY(m->id() == 13);
80
81   // range fill at beginning
82   const int A[] = {321, 322, 333};
83   const int N = sizeof(A) / sizeof(int);
84   T::reset();
85   b = list0301.begin();          
86   list0301.insert(b, A, A + N); // should be [321 322 333 13 13]
87   VERIFY(list0301.size() == 5);
88   VERIFY(T::copyCount() == 3);
89   VERIFY(m->id() == 13);
90   
91   // range fill at end
92   T::reset();
93   list0301.insert(e, A, A + N); // should be [321 322 333 13 13 321 322 333]
94   VERIFY(list0301.size() == 8);
95   VERIFY(T::copyCount() == 3);
96   VERIFY(e == list0301.end());
97   VERIFY(m->id() == 13);
98   
99   // range fill in middle
100   T::reset();
101   list0301.insert(m, A, A + N); 
102   VERIFY(list0301.size() == 11);
103   VERIFY(T::copyCount() == 3);
104   VERIFY(e == list0301.end());
105   VERIFY(m->id() == 13);
106
107   T::reset();
108   list0301.clear();
109   VERIFY(list0301.size() == 0);
110   VERIFY(T::dtorCount() == 11);
111   VERIFY(e == list0301.end());
112 }
113
114 int main()
115 {
116   test03();
117   return 0;
118 }