1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005 Free Software Foundation, Inc.
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)
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,
21 // 6.3.4.5 unordered_multiset::swap
23 #include <tr1/unordered_set>
25 #include <testsuite_hooks.h>
26 #include <testsuite_allocator.h>
28 // uneq_allocator, two different personalities.
32 bool test __attribute__((unused)) = true;
33 using namespace std::tr1;
37 typedef __gnu_test::uneq_allocator<char> my_alloc;
38 typedef unordered_multiset<char, hash<char>, equal_to<char>, my_alloc>
41 const char title01[] = "Rivers of sand";
42 const char title02[] = "Concret PH";
43 const char title03[] = "Sonatas and Interludes for Prepared Piano";
44 const char title04[] = "never as tired as when i'm waking up";
46 const size_t N1 = sizeof(title01);
47 const size_t N2 = sizeof(title02);
48 const size_t N3 = sizeof(title03);
49 const size_t N4 = sizeof(title04);
51 typedef multiset<char> my_mset;
52 const my_mset mset01_ref(title01, title01 + N1);
53 const my_mset mset02_ref(title02, title02 + N2);
54 const my_mset mset03_ref(title03, title03 + N3);
55 const my_mset mset04_ref(title04, title04 + N4);
57 my_umset::size_type size01, size02;
59 my_alloc alloc01(1), alloc02(2);
60 int personality01, personality02;
62 my_umset umset01(10, hash<char>(), equal_to<char>(), alloc01);
63 size01 = umset01.size();
64 personality01 = umset01.get_allocator().get_personality();
65 my_umset umset02(10, hash<char>(), equal_to<char>(), alloc02);
66 size02 = umset02.size();
67 personality02 = umset02.get_allocator().get_personality();
69 umset01.swap(umset02);
70 VERIFY( umset01.size() == size02 );
71 VERIFY( umset01.empty() );
72 VERIFY( umset02.size() == size01 );
73 VERIFY( umset02.empty() );
74 VERIFY( umset01.get_allocator().get_personality() == personality02 );
75 VERIFY( umset02.get_allocator().get_personality() == personality01 );
77 my_umset umset03(10, hash<char>(), equal_to<char>(), alloc02);
78 size01 = umset03.size();
79 personality01 = umset03.get_allocator().get_personality();
80 my_umset umset04(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(),
81 equal_to<char>(), alloc01);
82 size02 = umset04.size();
83 personality02 = umset04.get_allocator().get_personality();
85 umset03.swap(umset04);
86 VERIFY( umset03.size() == size02 );
87 VERIFY( my_mset(umset03.begin(), umset03.end()) == mset02_ref );
88 VERIFY( umset04.size() == size01 );
89 VERIFY( umset04.empty() );
90 VERIFY( umset03.get_allocator().get_personality() == personality02 );
91 VERIFY( umset04.get_allocator().get_personality() == personality01 );
93 my_umset umset05(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
94 equal_to<char>(), alloc01);
95 size01 = umset05.size();
96 personality01 = umset05.get_allocator().get_personality();
97 my_umset umset06(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(),
98 equal_to<char>(), alloc02);
99 size02 = umset06.size();
100 personality02 = umset06.get_allocator().get_personality();
102 umset05.swap(umset06);
103 VERIFY( umset05.size() == size02 );
104 VERIFY( my_mset(umset05.begin(), umset05.end()) == mset02_ref );
105 VERIFY( umset06.size() == size01 );
106 VERIFY( my_mset(umset06.begin(), umset06.end()) == mset01_ref );
107 VERIFY( umset05.get_allocator().get_personality() == personality02 );
108 VERIFY( umset06.get_allocator().get_personality() == personality01 );
110 my_umset umset07(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
111 equal_to<char>(), alloc02);
112 size01 = umset07.size();
113 personality01 = umset07.get_allocator().get_personality();
114 my_umset umset08(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
115 equal_to<char>(), alloc01);
116 size02 = umset08.size();
117 personality02 = umset08.get_allocator().get_personality();
119 umset07.swap(umset08);
120 VERIFY( umset07.size() == size02 );
121 VERIFY( my_mset(umset07.begin(), umset07.end()) == mset03_ref );
122 VERIFY( umset08.size() == size01 );
123 VERIFY( my_mset(umset08.begin(), umset08.end()) == mset01_ref );
124 VERIFY( umset07.get_allocator().get_personality() == personality02 );
125 VERIFY( umset08.get_allocator().get_personality() == personality01 );
127 my_umset umset09(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
128 equal_to<char>(), alloc01);
129 size01 = umset09.size();
130 personality01 = umset09.get_allocator().get_personality();
131 my_umset umset10(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(),
132 equal_to<char>(), alloc02);
133 size02 = umset10.size();
134 personality02 = umset10.get_allocator().get_personality();
136 umset09.swap(umset10);
137 VERIFY( umset09.size() == size02 );
138 VERIFY( my_mset(umset09.begin(), umset09.end()) == mset04_ref );
139 VERIFY( umset10.size() == size01 );
140 VERIFY( my_mset(umset10.begin(), umset10.end()) == mset03_ref );
141 VERIFY( umset09.get_allocator().get_personality() == personality02 );
142 VERIFY( umset10.get_allocator().get_personality() == personality01 );
144 my_umset umset11(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(),
145 equal_to<char>(), alloc02);
146 size01 = umset11.size();
147 personality01 = umset11.get_allocator().get_personality();
148 my_umset umset12(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
149 equal_to<char>(), alloc01);
150 size02 = umset12.size();
151 personality02 = umset12.get_allocator().get_personality();
153 umset11.swap(umset12);
154 VERIFY( umset11.size() == size02 );
155 VERIFY( my_mset(umset11.begin(), umset11.end()) == mset01_ref );
156 VERIFY( umset12.size() == size01 );
157 VERIFY( my_mset(umset12.begin(), umset12.end()) == mset04_ref );
158 VERIFY( umset11.get_allocator().get_personality() == personality02 );
159 VERIFY( umset12.get_allocator().get_personality() == personality01 );
161 my_umset umset13(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
162 equal_to<char>(), alloc01);
163 size01 = umset13.size();
164 personality01 = umset13.get_allocator().get_personality();
165 my_umset umset14(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
166 equal_to<char>(), alloc02);
167 size02 = umset14.size();
168 personality02 = umset14.get_allocator().get_personality();
170 umset13.swap(umset14);
171 VERIFY( umset13.size() == size02 );
172 VERIFY( my_mset(umset13.begin(), umset13.end()) == mset03_ref );
173 VERIFY( umset14.size() == size01 );
174 VERIFY( my_mset(umset14.begin(), umset14.end()) == mset03_ref );
175 VERIFY( umset13.get_allocator().get_personality() == personality02 );
176 VERIFY( umset14.get_allocator().get_personality() == personality01 );