OSDN Git Service

Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / insert / 25288.cc
1 // Copyright (C) 2005, 2006, 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 // { dg-require-time "" }
21
22 #include <list>
23 #include <testsuite_hooks.h>
24 #include <ext/throw_allocator.h>
25
26 // libstdc++/25288
27 void test01()
28 {
29   bool test __attribute__((unused)) = true;
30
31   typedef int value_type;
32   typedef __gnu_cxx::throw_allocator<value_type> allocator_type;
33   typedef std::list<value_type, allocator_type> list_type;
34
35   for (int j = 0; j < 10; ++j)
36     for (int i = 0; i < 10; ++i)
37       {
38         allocator_type alloc1;
39         allocator_type::zero_throw_prob_adjustor adjust1;
40         list_type list1(alloc1);
41         
42         for (int k = 0; k < j; ++k)
43           list1.push_back(value_type(-(k + 1)));
44       
45         try
46           {
47             alloc1.set_throw_prob(1);
48             list1.insert(list1.begin(), 10, 99);
49             VERIFY( false );
50           }
51         catch (__gnu_cxx::forced_exception_error&)
52           {
53             VERIFY( true );
54           }
55         catch (...)
56           {
57             VERIFY( false );
58           }
59         
60         VERIFY( list1.size() == list_type::size_type(j) );
61         VERIFY( list1.size() == 0 || list1.back() == -j );
62         VERIFY( list1.size() == 0 || list1.front() == -1 );
63
64         allocator_type alloc2;
65         allocator_type::zero_throw_prob_adjustor adjust2;
66         list_type list2(alloc2);
67         
68         const int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
69         
70         for (int k = 0; k < j; ++k)
71           list2.push_back(-(k + 1));
72         
73         try
74           {
75             alloc2.set_throw_prob(1);
76             list2.insert(list2.begin(), data, data + 10);
77             VERIFY( false );
78           }
79         catch (__gnu_cxx::forced_exception_error&)
80           {
81             VERIFY( true );
82           }
83         catch (...)
84           {
85             VERIFY( false );
86           }
87
88         VERIFY( list2.size() == list_type::size_type(j) );
89         VERIFY( list2.size() == 0 || list2.back() == -j );
90         VERIFY( list2.size() == 0 || list2.front() == -1 );
91       }
92 }
93
94 int main()
95 {
96   test01();
97   return 0;
98 }