OSDN Git Service

2003-07-31 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / 3.cc
1 // Copyright (C) 2001, 2003 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 2, 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 COPYING.  If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
18
19 // 23.2.2.3 list modifiers [lib.list.modifiers]
20
21 #include <list>
22 #include <testsuite_hooks.h>
23
24 typedef __gnu_test::copy_tracker  T;
25
26 bool test = true;
27
28
29 // This test verifies the following.
30 //
31 // 23.2.2.3     void push_front(const T& x)
32 // 23.2.2.3     void push_back(const T& x)
33 // 23.2.2.3 (1) iterator and reference non-invalidation 
34 // 23.2.2.3 (1) exception effects
35 // 23.2.2.3 (2) complexity requirements
36 //
37 // 23.2.2.3     void pop_front()
38 // 23.2.2.3     void pop_back()
39 // 23.2.2.3 (3) iterator and reference non-invalidation 
40 // 23.2.2.3 (5) complexity requirements
41 //
42 // 23.2.2       const_iterator begin() const
43 // 23.2.2       iterator end() 
44 // 23.2.2       const_reverse_iterator rbegin() const
45 // 23.2.2       _reference front() 
46 // 23.2.2       const_reference front() const
47 // 23.2.2       reference back() 
48 // 23.2.2       const_reference back() const
49 //
50 void
51 test01()
52 {
53   std::list<T> list0101;
54   std::list<T>::const_iterator i;
55   std::list<T>::const_reverse_iterator j;
56   std::list<T>::iterator k;
57   T::reset();
58
59   list0101.push_back(T(1));     // list should be [1]
60   VERIFY(list0101.size() == 1);
61   VERIFY(T::copyCount() == 1);
62
63   k = list0101.end();
64   --k;
65   VERIFY(k->id() == 1);
66   VERIFY(k->id() == list0101.front().id());
67   VERIFY(k->id() == list0101.back().id());
68
69   list0101.push_front(T(2));    // list should be [2 1]
70   VERIFY(list0101.size() == 2);
71   VERIFY(T::copyCount() == 2);
72   VERIFY(k->id() == 1);
73
74   list0101.push_back(T(3));     // list should be [2 1 3]
75   VERIFY(list0101.size() == 3);
76   VERIFY(T::copyCount() == 3);
77   VERIFY(k->id() == 1);
78
79   try
80   {
81     list0101.push_back(T(4, true));
82     VERIFY(("no exception thrown", false));
83   }
84   catch (...)
85   {
86     VERIFY(list0101.size() == 3);
87     VERIFY(T::copyCount() == 4);
88   }
89
90   i = list0101.begin();
91   VERIFY(i->id() == 2);
92   VERIFY(i->id() == list0101.front().id());
93
94   j = list0101.rbegin();
95   VERIFY(j->id() == 3);
96   VERIFY(j->id() == list0101.back().id());
97
98   ++i;
99   VERIFY(i->id() == 1);
100
101   ++j;
102   VERIFY(j->id() == 1);
103
104   T::reset();
105
106   list0101.pop_back();          // list should be [2 1]
107   VERIFY(list0101.size() == 2);
108   VERIFY(T::dtorCount() == 1);
109   VERIFY(i->id() == 1);
110   VERIFY(k->id() == 1);
111
112   list0101.pop_front();          // list should be [1]
113   VERIFY(list0101.size() == 1);
114   VERIFY(T::dtorCount() == 2);
115   VERIFY(i->id() == 1);
116   VERIFY(k->id() == 1);
117 }
118
119 int main()
120 {
121   test01();
122   return 0;
123 }
124 // vi:set sw=2 ts=2: