1 |
424 |
jeremybenn |
// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
|
2 |
|
|
|
3 |
|
|
// Copyright (C) 2005, 2009 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 3, or (at your option)
|
9 |
|
|
// any later version.
|
10 |
|
|
|
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.
|
15 |
|
|
|
16 |
|
|
// You should have received a copy of the GNU General Public License along
|
17 |
|
|
// with this library; see the file COPYING3. If not see
|
18 |
|
|
// <http://www.gnu.org/licenses/>.
|
19 |
|
|
|
20 |
|
|
// 23.3.4 multiset::swap
|
21 |
|
|
|
22 |
|
|
#include <set>
|
23 |
|
|
#include <testsuite_hooks.h>
|
24 |
|
|
#include <testsuite_allocator.h>
|
25 |
|
|
|
26 |
|
|
// uneq_allocator, two different personalities.
|
27 |
|
|
void
|
28 |
|
|
test01()
|
29 |
|
|
{
|
30 |
|
|
bool test __attribute__((unused)) = true;
|
31 |
|
|
using namespace std;
|
32 |
|
|
|
33 |
|
|
typedef __gnu_test::uneq_allocator<char> my_alloc;
|
34 |
|
|
typedef multiset<char, less<char>, my_alloc> my_multiset;
|
35 |
|
|
|
36 |
|
|
const char title01[] = "Rivers of sand";
|
37 |
|
|
const char title02[] = "Concret PH";
|
38 |
|
|
const char title03[] = "Sonatas and Interludes for Prepared Piano";
|
39 |
|
|
const char title04[] = "never as tired as when i'm waking up";
|
40 |
|
|
|
41 |
|
|
const size_t N1 = sizeof(title01);
|
42 |
|
|
const size_t N2 = sizeof(title02);
|
43 |
|
|
const size_t N3 = sizeof(title03);
|
44 |
|
|
const size_t N4 = sizeof(title04);
|
45 |
|
|
|
46 |
|
|
const multiset<char> mset01_ref(title01, title01 + N1);
|
47 |
|
|
const multiset<char> mset02_ref(title02, title02 + N2);
|
48 |
|
|
const multiset<char> mset03_ref(title03, title03 + N3);
|
49 |
|
|
const multiset<char> mset04_ref(title04, title04 + N4);
|
50 |
|
|
|
51 |
|
|
my_multiset::size_type size01, size02;
|
52 |
|
|
|
53 |
|
|
my_alloc alloc01(1), alloc02(2);
|
54 |
|
|
int personality01, personality02;
|
55 |
|
|
|
56 |
|
|
my_multiset mset01(less<char>(), alloc01);
|
57 |
|
|
size01 = mset01.size();
|
58 |
|
|
personality01 = mset01.get_allocator().get_personality();
|
59 |
|
|
my_multiset mset02(less<char>(), alloc02);
|
60 |
|
|
size02 = mset02.size();
|
61 |
|
|
personality02 = mset02.get_allocator().get_personality();
|
62 |
|
|
|
63 |
|
|
mset01.swap(mset02);
|
64 |
|
|
VERIFY( mset01.size() == size02 );
|
65 |
|
|
VERIFY( mset01.empty() );
|
66 |
|
|
VERIFY( mset02.size() == size01 );
|
67 |
|
|
VERIFY( mset02.empty() );
|
68 |
|
|
VERIFY( mset01.get_allocator().get_personality() == personality02 );
|
69 |
|
|
VERIFY( mset02.get_allocator().get_personality() == personality01 );
|
70 |
|
|
|
71 |
|
|
my_multiset mset03(less<char>(), alloc02);
|
72 |
|
|
size01 = mset03.size();
|
73 |
|
|
personality01 = mset03.get_allocator().get_personality();
|
74 |
|
|
my_multiset mset04(title02, title02 + N2, less<char>(), alloc01);
|
75 |
|
|
size02 = mset04.size();
|
76 |
|
|
personality02 = mset04.get_allocator().get_personality();
|
77 |
|
|
|
78 |
|
|
mset03.swap(mset04);
|
79 |
|
|
VERIFY( mset03.size() == size02 );
|
80 |
|
|
VERIFY( equal(mset03.begin(), mset03.end(), mset02_ref.begin()) );
|
81 |
|
|
VERIFY( mset04.size() == size01 );
|
82 |
|
|
VERIFY( mset04.empty() );
|
83 |
|
|
VERIFY( mset03.get_allocator().get_personality() == personality02 );
|
84 |
|
|
VERIFY( mset04.get_allocator().get_personality() == personality01 );
|
85 |
|
|
|
86 |
|
|
my_multiset mset05(title01, title01 + N1, less<char>(), alloc01);
|
87 |
|
|
size01 = mset05.size();
|
88 |
|
|
personality01 = mset05.get_allocator().get_personality();
|
89 |
|
|
my_multiset mset06(title02, title02 + N2, less<char>(), alloc02);
|
90 |
|
|
size02 = mset06.size();
|
91 |
|
|
personality02 = mset06.get_allocator().get_personality();
|
92 |
|
|
|
93 |
|
|
mset05.swap(mset06);
|
94 |
|
|
VERIFY( mset05.size() == size02 );
|
95 |
|
|
VERIFY( equal(mset05.begin(), mset05.end(), mset02_ref.begin()) );
|
96 |
|
|
VERIFY( mset06.size() == size01 );
|
97 |
|
|
VERIFY( equal(mset06.begin(), mset06.end(), mset01_ref.begin()) );
|
98 |
|
|
VERIFY( mset05.get_allocator().get_personality() == personality02 );
|
99 |
|
|
VERIFY( mset06.get_allocator().get_personality() == personality01 );
|
100 |
|
|
|
101 |
|
|
my_multiset mset07(title01, title01 + N1, less<char>(), alloc02);
|
102 |
|
|
size01 = mset07.size();
|
103 |
|
|
personality01 = mset07.get_allocator().get_personality();
|
104 |
|
|
my_multiset mset08(title03, title03 + N3, less<char>(), alloc01);
|
105 |
|
|
size02 = mset08.size();
|
106 |
|
|
personality02 = mset08.get_allocator().get_personality();
|
107 |
|
|
|
108 |
|
|
mset07.swap(mset08);
|
109 |
|
|
VERIFY( mset07.size() == size02 );
|
110 |
|
|
VERIFY( equal(mset07.begin(), mset07.end(), mset03_ref.begin()) );
|
111 |
|
|
VERIFY( mset08.size() == size01 );
|
112 |
|
|
VERIFY( equal(mset08.begin(), mset08.end(), mset01_ref.begin()) );
|
113 |
|
|
VERIFY( mset07.get_allocator().get_personality() == personality02 );
|
114 |
|
|
VERIFY( mset08.get_allocator().get_personality() == personality01 );
|
115 |
|
|
|
116 |
|
|
my_multiset mset09(title03, title03 + N3, less<char>(), alloc01);
|
117 |
|
|
size01 = mset09.size();
|
118 |
|
|
personality01 = mset09.get_allocator().get_personality();
|
119 |
|
|
my_multiset mset10(title04, title04 + N4, less<char>(), alloc02);
|
120 |
|
|
size02 = mset10.size();
|
121 |
|
|
personality02 = mset10.get_allocator().get_personality();
|
122 |
|
|
|
123 |
|
|
mset09.swap(mset10);
|
124 |
|
|
VERIFY( mset09.size() == size02 );
|
125 |
|
|
VERIFY( equal(mset09.begin(), mset09.end(), mset04_ref.begin()) );
|
126 |
|
|
VERIFY( mset10.size() == size01 );
|
127 |
|
|
VERIFY( equal(mset10.begin(), mset10.end(), mset03_ref.begin()) );
|
128 |
|
|
VERIFY( mset09.get_allocator().get_personality() == personality02 );
|
129 |
|
|
VERIFY( mset10.get_allocator().get_personality() == personality01 );
|
130 |
|
|
|
131 |
|
|
my_multiset mset11(title04, title04 + N4, less<char>(), alloc02);
|
132 |
|
|
size01 = mset11.size();
|
133 |
|
|
personality01 = mset11.get_allocator().get_personality();
|
134 |
|
|
my_multiset mset12(title01, title01 + N1, less<char>(), alloc01);
|
135 |
|
|
size02 = mset12.size();
|
136 |
|
|
personality02 = mset12.get_allocator().get_personality();
|
137 |
|
|
|
138 |
|
|
mset11.swap(mset12);
|
139 |
|
|
VERIFY( mset11.size() == size02 );
|
140 |
|
|
VERIFY( equal(mset11.begin(), mset11.end(), mset01_ref.begin()) );
|
141 |
|
|
VERIFY( mset12.size() == size01 );
|
142 |
|
|
VERIFY( equal(mset12.begin(), mset12.end(), mset04_ref.begin()) );
|
143 |
|
|
VERIFY( mset11.get_allocator().get_personality() == personality02 );
|
144 |
|
|
VERIFY( mset12.get_allocator().get_personality() == personality01 );
|
145 |
|
|
|
146 |
|
|
my_multiset mset13(title03, title03 + N3, less<char>(), alloc01);
|
147 |
|
|
size01 = mset13.size();
|
148 |
|
|
personality01 = mset13.get_allocator().get_personality();
|
149 |
|
|
my_multiset mset14(title03, title03 + N3, less<char>(), alloc02);
|
150 |
|
|
size02 = mset14.size();
|
151 |
|
|
personality02 = mset14.get_allocator().get_personality();
|
152 |
|
|
|
153 |
|
|
mset13.swap(mset14);
|
154 |
|
|
VERIFY( mset13.size() == size02 );
|
155 |
|
|
VERIFY( equal(mset13.begin(), mset13.end(), mset03_ref.begin()) );
|
156 |
|
|
VERIFY( mset14.size() == size01 );
|
157 |
|
|
VERIFY( equal(mset14.begin(), mset14.end(), mset03_ref.begin()) );
|
158 |
|
|
VERIFY( mset13.get_allocator().get_personality() == personality02 );
|
159 |
|
|
VERIFY( mset14.get_allocator().get_personality() == personality01 );
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
int main()
|
163 |
|
|
{
|
164 |
|
|
test01();
|
165 |
|
|
return 0;
|
166 |
|
|
}
|