Merge from mainline
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / modifiers / swap / 3.cc
blob714e0ccea3fc01f02aa327d5cd2ddd39e3ab20a5
1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // 23.2.2.3 list::swap
23 #include <list>
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
27 // uneq_allocator, two different personalities.
28 void
29 test01()
31 bool test __attribute__((unused)) = true;
32 using namespace std;
34 typedef __gnu_test::uneq_allocator<char> my_alloc;
35 typedef list<char, my_alloc> my_list;
37 const char title01[] = "Rivers of sand";
38 const char title02[] = "Concret PH";
39 const char title03[] = "Sonatas and Interludes for Prepared Piano";
40 const char title04[] = "never as tired as when i'm waking up";
42 const size_t N1 = sizeof(title01);
43 const size_t N2 = sizeof(title02);
44 const size_t N3 = sizeof(title03);
45 const size_t N4 = sizeof(title04);
47 my_list::size_type size01, size02;
49 my_alloc alloc01(1), alloc02(2);
50 int personality01, personality02;
52 my_list lis01(alloc01);
53 size01 = lis01.size();
54 personality01 = lis01.get_allocator().get_personality();
55 my_list lis02(alloc02);
56 size02 = lis02.size();
57 personality02 = lis02.get_allocator().get_personality();
59 lis01.swap(lis02);
60 VERIFY( lis01.size() == size02 );
61 VERIFY( lis01.empty() );
62 VERIFY( lis02.size() == size01 );
63 VERIFY( lis02.empty() );
64 VERIFY( lis01.get_allocator().get_personality() == personality02 );
65 VERIFY( lis02.get_allocator().get_personality() == personality01 );
67 my_list lis03(alloc02);
68 size01 = lis03.size();
69 personality01 = lis03.get_allocator().get_personality();
70 my_list lis04(title02, title02 + N2, alloc01);
71 size02 = lis04.size();
72 personality02 = lis04.get_allocator().get_personality();
74 lis03.swap(lis04);
75 VERIFY( lis03.size() == size02 );
76 VERIFY( equal(lis03.begin(), lis03.end(), title02) );
77 VERIFY( lis04.size() == size01 );
78 VERIFY( lis04.empty() );
79 VERIFY( lis03.get_allocator().get_personality() == personality02 );
80 VERIFY( lis04.get_allocator().get_personality() == personality01 );
82 my_list lis05(title01, title01 + N1, alloc01);
83 size01 = lis05.size();
84 personality01 = lis05.get_allocator().get_personality();
85 my_list lis06(title02, title02 + N2, alloc02);
86 size02 = lis06.size();
87 personality02 = lis06.get_allocator().get_personality();
89 lis05.swap(lis06);
90 VERIFY( lis05.size() == size02 );
91 VERIFY( equal(lis05.begin(), lis05.end(), title02) );
92 VERIFY( lis06.size() == size01 );
93 VERIFY( equal(lis06.begin(), lis06.end(), title01) );
94 VERIFY( lis05.get_allocator().get_personality() == personality02 );
95 VERIFY( lis06.get_allocator().get_personality() == personality01 );
97 my_list lis07(title01, title01 + N1, alloc02);
98 size01 = lis07.size();
99 personality01 = lis07.get_allocator().get_personality();
100 my_list lis08(title03, title03 + N3, alloc01);
101 size02 = lis08.size();
102 personality02 = lis08.get_allocator().get_personality();
104 lis07.swap(lis08);
105 VERIFY( lis07.size() == size02 );
106 VERIFY( equal(lis07.begin(), lis07.end(), title03) );
107 VERIFY( lis08.size() == size01 );
108 VERIFY( equal(lis08.begin(), lis08.end(), title01) );
109 VERIFY( lis07.get_allocator().get_personality() == personality02 );
110 VERIFY( lis08.get_allocator().get_personality() == personality01 );
112 my_list lis09(title03, title03 + N3, alloc01);
113 size01 = lis09.size();
114 personality01 = lis09.get_allocator().get_personality();
115 my_list lis10(title04, title04 + N4, alloc02);
116 size02 = lis10.size();
117 personality02 = lis10.get_allocator().get_personality();
119 lis09.swap(lis10);
120 VERIFY( lis09.size() == size02 );
121 VERIFY( equal(lis09.begin(), lis09.end(), title04) );
122 VERIFY( lis10.size() == size01 );
123 VERIFY( equal(lis10.begin(), lis10.end(), title03) );
124 VERIFY( lis09.get_allocator().get_personality() == personality02 );
125 VERIFY( lis10.get_allocator().get_personality() == personality01 );
127 my_list lis11(title04, title04 + N4, alloc02);
128 size01 = lis11.size();
129 personality01 = lis11.get_allocator().get_personality();
130 my_list lis12(title01, title01 + N1, alloc01);
131 size02 = lis12.size();
132 personality02 = lis12.get_allocator().get_personality();
134 lis11.swap(lis12);
135 VERIFY( lis11.size() == size02 );
136 VERIFY( equal(lis11.begin(), lis11.end(), title01) );
137 VERIFY( lis12.size() == size01 );
138 VERIFY( equal(lis12.begin(), lis12.end(), title04) );
139 VERIFY( lis11.get_allocator().get_personality() == personality02 );
140 VERIFY( lis12.get_allocator().get_personality() == personality01 );
142 my_list lis13(title03, title03 + N3, alloc01);
143 size01 = lis13.size();
144 personality01 = lis13.get_allocator().get_personality();
145 my_list lis14(title03, title03 + N3, alloc02);
146 size02 = lis14.size();
147 personality02 = lis14.get_allocator().get_personality();
149 lis13.swap(lis14);
150 VERIFY( lis13.size() == size02 );
151 VERIFY( equal(lis13.begin(), lis13.end(), title03) );
152 VERIFY( lis14.size() == size01 );
153 VERIFY( equal(lis14.begin(), lis14.end(), title03) );
154 VERIFY( lis13.get_allocator().get_personality() == personality02 );
155 VERIFY( lis14.get_allocator().get_personality() == personality01 );
158 int main()
160 test01();
161 return 0;