OSDN Git Service

2005-12-09 Paolo Carlini <pcarlini@suse.de>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / insert / 25288.cc
1 // Copyright (C) 2005 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 // USA.
18
19 // 23.2.2.3 list modifiers [lib.list.modifiers]
20
21 #include <list>
22 #include <testsuite_hooks.h>
23 #include <testsuite_allocator.h>
24
25 // libstdc++/25288
26 void test01()
27 {
28   bool test __attribute__((unused)) = true;
29
30   typedef __gnu_test::throw_allocator<int> my_alloc;
31   typedef std::list<int, my_alloc > my_list;
32
33   for (int j = 0; j < 10; ++j)
34     for (int i = 0; i < 10; ++i)
35       {
36         my_alloc alloc1(j + i);
37         my_list list1(alloc1);
38         
39         for (int k = 0; k < j; ++k)
40           list1.push_back(-(k + 1));
41       
42         try
43           {
44             list1.insert(list1.begin(), 10, 99);
45             VERIFY( false );
46           }
47         catch (std::bad_alloc&)
48           {
49             VERIFY( true );
50           }
51         catch (...)
52           {
53             VERIFY( false );
54           }
55         
56         VERIFY( list1.size() == my_list::size_type(j) );
57         VERIFY( list1.size() == 0 || list1.back() == -j );
58         VERIFY( list1.size() == 0 || list1.front() == -1 );
59
60         my_alloc alloc2(j + i);
61         my_list list2(alloc2);
62         
63         const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
64         
65         for (int k = 0; k < j; ++k)
66           list2.push_back(-(k + 1));
67         
68         try
69           {
70             list2.insert(list2.begin(), data, data + 10);
71             VERIFY( false );
72           }
73         catch (std::bad_alloc&)
74           {
75             VERIFY( true );
76           }
77         catch (...)
78           {
79             VERIFY( false );
80           }
81
82         VERIFY( list2.size() == my_list::size_type(j) );
83         VERIFY( list2.size() == 0 || list2.back() == -j );
84         VERIFY( list2.size() == 0 || list2.front() == -1 );
85       }
86 }
87
88 int main()
89 {
90   test01();
91   return 0;
92 }