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.3 set::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 set<char, less<char>, my_alloc> my_set;
|
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 set<char> set01_ref(title01, title01 + N1);
|
47 |
|
|
const set<char> set02_ref(title02, title02 + N2);
|
48 |
|
|
const set<char> set03_ref(title03, title03 + N3);
|
49 |
|
|
const set<char> set04_ref(title04, title04 + N4);
|
50 |
|
|
|
51 |
|
|
my_set::size_type size01, size02;
|
52 |
|
|
|
53 |
|
|
my_alloc alloc01(1), alloc02(2);
|
54 |
|
|
int personality01, personality02;
|
55 |
|
|
|
56 |
|
|
my_set set01(less<char>(), alloc01);
|
57 |
|
|
size01 = set01.size();
|
58 |
|
|
personality01 = set01.get_allocator().get_personality();
|
59 |
|
|
my_set set02(less<char>(), alloc02);
|
60 |
|
|
size02 = set02.size();
|
61 |
|
|
personality02 = set02.get_allocator().get_personality();
|
62 |
|
|
|
63 |
|
|
set01.swap(set02);
|
64 |
|
|
VERIFY( set01.size() == size02 );
|
65 |
|
|
VERIFY( set01.empty() );
|
66 |
|
|
VERIFY( set02.size() == size01 );
|
67 |
|
|
VERIFY( set02.empty() );
|
68 |
|
|
VERIFY( set01.get_allocator().get_personality() == personality02 );
|
69 |
|
|
VERIFY( set02.get_allocator().get_personality() == personality01 );
|
70 |
|
|
|
71 |
|
|
my_set set03(less<char>(), alloc02);
|
72 |
|
|
size01 = set03.size();
|
73 |
|
|
personality01 = set03.get_allocator().get_personality();
|
74 |
|
|
my_set set04(title02, title02 + N2, less<char>(), alloc01);
|
75 |
|
|
size02 = set04.size();
|
76 |
|
|
personality02 = set04.get_allocator().get_personality();
|
77 |
|
|
|
78 |
|
|
set03.swap(set04);
|
79 |
|
|
VERIFY( set03.size() == size02 );
|
80 |
|
|
VERIFY( equal(set03.begin(), set03.end(), set02_ref.begin()) );
|
81 |
|
|
VERIFY( set04.size() == size01 );
|
82 |
|
|
VERIFY( set04.empty() );
|
83 |
|
|
VERIFY( set03.get_allocator().get_personality() == personality02 );
|
84 |
|
|
VERIFY( set04.get_allocator().get_personality() == personality01 );
|
85 |
|
|
|
86 |
|
|
my_set set05(title01, title01 + N1, less<char>(), alloc01);
|
87 |
|
|
size01 = set05.size();
|
88 |
|
|
personality01 = set05.get_allocator().get_personality();
|
89 |
|
|
my_set set06(title02, title02 + N2, less<char>(), alloc02);
|
90 |
|
|
size02 = set06.size();
|
91 |
|
|
personality02 = set06.get_allocator().get_personality();
|
92 |
|
|
|
93 |
|
|
set05.swap(set06);
|
94 |
|
|
VERIFY( set05.size() == size02 );
|
95 |
|
|
VERIFY( equal(set05.begin(), set05.end(), set02_ref.begin()) );
|
96 |
|
|
VERIFY( set06.size() == size01 );
|
97 |
|
|
VERIFY( equal(set06.begin(), set06.end(), set01_ref.begin()) );
|
98 |
|
|
VERIFY( set05.get_allocator().get_personality() == personality02 );
|
99 |
|
|
VERIFY( set06.get_allocator().get_personality() == personality01 );
|
100 |
|
|
|
101 |
|
|
my_set set07(title01, title01 + N1, less<char>(), alloc02);
|
102 |
|
|
size01 = set07.size();
|
103 |
|
|
personality01 = set07.get_allocator().get_personality();
|
104 |
|
|
my_set set08(title03, title03 + N3, less<char>(), alloc01);
|
105 |
|
|
size02 = set08.size();
|
106 |
|
|
personality02 = set08.get_allocator().get_personality();
|
107 |
|
|
|
108 |
|
|
set07.swap(set08);
|
109 |
|
|
VERIFY( set07.size() == size02 );
|
110 |
|
|
VERIFY( equal(set07.begin(), set07.end(), set03_ref.begin()) );
|
111 |
|
|
VERIFY( set08.size() == size01 );
|
112 |
|
|
VERIFY( equal(set08.begin(), set08.end(), set01_ref.begin()) );
|
113 |
|
|
VERIFY( set07.get_allocator().get_personality() == personality02 );
|
114 |
|
|
VERIFY( set08.get_allocator().get_personality() == personality01 );
|
115 |
|
|
|
116 |
|
|
my_set set09(title03, title03 + N3, less<char>(), alloc01);
|
117 |
|
|
size01 = set09.size();
|
118 |
|
|
personality01 = set09.get_allocator().get_personality();
|
119 |
|
|
my_set set10(title04, title04 + N4, less<char>(), alloc02);
|
120 |
|
|
size02 = set10.size();
|
121 |
|
|
personality02 = set10.get_allocator().get_personality();
|
122 |
|
|
|
123 |
|
|
set09.swap(set10);
|
124 |
|
|
VERIFY( set09.size() == size02 );
|
125 |
|
|
VERIFY( equal(set09.begin(), set09.end(), set04_ref.begin()) );
|
126 |
|
|
VERIFY( set10.size() == size01 );
|
127 |
|
|
VERIFY( equal(set10.begin(), set10.end(), set03_ref.begin()) );
|
128 |
|
|
VERIFY( set09.get_allocator().get_personality() == personality02 );
|
129 |
|
|
VERIFY( set10.get_allocator().get_personality() == personality01 );
|
130 |
|
|
|
131 |
|
|
my_set set11(title04, title04 + N4, less<char>(), alloc02);
|
132 |
|
|
size01 = set11.size();
|
133 |
|
|
personality01 = set11.get_allocator().get_personality();
|
134 |
|
|
my_set set12(title01, title01 + N1, less<char>(), alloc01);
|
135 |
|
|
size02 = set12.size();
|
136 |
|
|
personality02 = set12.get_allocator().get_personality();
|
137 |
|
|
|
138 |
|
|
set11.swap(set12);
|
139 |
|
|
VERIFY( set11.size() == size02 );
|
140 |
|
|
VERIFY( equal(set11.begin(), set11.end(), set01_ref.begin()) );
|
141 |
|
|
VERIFY( set12.size() == size01 );
|
142 |
|
|
VERIFY( equal(set12.begin(), set12.end(), set04_ref.begin()) );
|
143 |
|
|
VERIFY( set11.get_allocator().get_personality() == personality02 );
|
144 |
|
|
VERIFY( set12.get_allocator().get_personality() == personality01 );
|
145 |
|
|
|
146 |
|
|
my_set set13(title03, title03 + N3, less<char>(), alloc01);
|
147 |
|
|
size01 = set13.size();
|
148 |
|
|
personality01 = set13.get_allocator().get_personality();
|
149 |
|
|
my_set set14(title03, title03 + N3, less<char>(), alloc02);
|
150 |
|
|
size02 = set14.size();
|
151 |
|
|
personality02 = set14.get_allocator().get_personality();
|
152 |
|
|
|
153 |
|
|
set13.swap(set14);
|
154 |
|
|
VERIFY( set13.size() == size02 );
|
155 |
|
|
VERIFY( equal(set13.begin(), set13.end(), set03_ref.begin()) );
|
156 |
|
|
VERIFY( set14.size() == size01 );
|
157 |
|
|
VERIFY( equal(set14.begin(), set14.end(), set03_ref.begin()) );
|
158 |
|
|
VERIFY( set13.get_allocator().get_personality() == personality02 );
|
159 |
|
|
VERIFY( set14.get_allocator().get_personality() == personality01 );
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
int main()
|
163 |
|
|
{
|
164 |
|
|
test01();
|
165 |
|
|
return 0;
|
166 |
|
|
}
|