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.4 unordered_map::swap
23 #include <tr1/unordered_map>
25 #include <testsuite_hooks.h>
26 #include <testsuite_allocator.h>
28 // uneq_allocator, two different personalities.
32 bool test
__attribute__((unused
)) = true;
36 typedef pair
<const char, int> my_pair
;
37 typedef __gnu_test::uneq_allocator
<my_pair
> my_alloc
;
38 typedef unordered_map
<char, int, 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 map
<char, int> my_map
;
53 for (size_t i
= 0; i
< N1
; ++i
)
54 map01_ref
.insert(my_pair(title01
[i
], i
));
56 for (size_t i
= 0; i
< N2
; ++i
)
57 map02_ref
.insert(my_pair(title02
[i
], i
));
59 for (size_t i
= 0; i
< N3
; ++i
)
60 map03_ref
.insert(my_pair(title03
[i
], i
));
62 for (size_t i
= 0; i
< N4
; ++i
)
63 map04_ref
.insert(my_pair(title04
[i
], i
));
65 my_umap::size_type size01
, size02
;
67 my_alloc
alloc01(1), alloc02(2);
68 int personality01
, personality02
;
70 my_umap
umap01(10, hash
<char>(), equal_to
<char>(), alloc01
);
71 size01
= umap01
.size();
72 personality01
= umap01
.get_allocator().get_personality();
73 my_umap
umap02(10, hash
<char>(), equal_to
<char>(), alloc02
);
74 size02
= umap02
.size();
75 personality02
= umap02
.get_allocator().get_personality();
78 VERIFY( umap01
.size() == size02
);
79 VERIFY( umap01
.empty() );
80 VERIFY( umap02
.size() == size01
);
81 VERIFY( umap02
.empty() );
82 VERIFY( umap01
.get_allocator().get_personality() == personality02
);
83 VERIFY( umap02
.get_allocator().get_personality() == personality01
);
85 my_umap
umap03(10, hash
<char>(), equal_to
<char>(), alloc02
);
86 size01
= umap03
.size();
87 personality01
= umap03
.get_allocator().get_personality();
88 my_umap
umap04(map02_ref
.begin(), map02_ref
.end(), 10, hash
<char>(),
89 equal_to
<char>(), alloc01
);
90 size02
= umap04
.size();
91 personality02
= umap04
.get_allocator().get_personality();
94 VERIFY( umap03
.size() == size02
);
95 VERIFY( my_map(umap03
.begin(), umap03
.end()) == map02_ref
);
96 VERIFY( umap04
.size() == size01
);
97 VERIFY( umap04
.empty() );
98 VERIFY( umap03
.get_allocator().get_personality() == personality02
);
99 VERIFY( umap04
.get_allocator().get_personality() == personality01
);
101 my_umap
umap05(map01_ref
.begin(), map01_ref
.end(), 10, hash
<char>(),
102 equal_to
<char>(), alloc01
);
103 size01
= umap05
.size();
104 personality01
= umap05
.get_allocator().get_personality();
105 my_umap
umap06(map02_ref
.begin(), map02_ref
.end(), 10, hash
<char>(),
106 equal_to
<char>(), alloc02
);
107 size02
= umap06
.size();
108 personality02
= umap06
.get_allocator().get_personality();
111 VERIFY( umap05
.size() == size02
);
112 VERIFY( my_map(umap05
.begin(), umap05
.end()) == map02_ref
);
113 VERIFY( umap06
.size() == size01
);
114 VERIFY( my_map(umap06
.begin(), umap06
.end()) == map01_ref
);
115 VERIFY( umap05
.get_allocator().get_personality() == personality02
);
116 VERIFY( umap06
.get_allocator().get_personality() == personality01
);
118 my_umap
umap07(map01_ref
.begin(), map01_ref
.end(), 10, hash
<char>(),
119 equal_to
<char>(), alloc02
);
120 size01
= umap07
.size();
121 personality01
= umap07
.get_allocator().get_personality();
122 my_umap
umap08(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
123 equal_to
<char>(), alloc01
);
124 size02
= umap08
.size();
125 personality02
= umap08
.get_allocator().get_personality();
128 VERIFY( umap07
.size() == size02
);
129 VERIFY( my_map(umap07
.begin(), umap07
.end()) == map03_ref
);
130 VERIFY( umap08
.size() == size01
);
131 VERIFY( my_map(umap08
.begin(), umap08
.end()) == map01_ref
);
132 VERIFY( umap07
.get_allocator().get_personality() == personality02
);
133 VERIFY( umap08
.get_allocator().get_personality() == personality01
);
135 my_umap
umap09(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
136 equal_to
<char>(), alloc01
);
137 size01
= umap09
.size();
138 personality01
= umap09
.get_allocator().get_personality();
139 my_umap
umap10(map04_ref
.begin(), map04_ref
.end(), 10, hash
<char>(),
140 equal_to
<char>(), alloc02
);
141 size02
= umap10
.size();
142 personality02
= umap10
.get_allocator().get_personality();
145 VERIFY( umap09
.size() == size02
);
146 VERIFY( my_map(umap09
.begin(), umap09
.end()) == map04_ref
);
147 VERIFY( umap10
.size() == size01
);
148 VERIFY( my_map(umap10
.begin(), umap10
.end()) == map03_ref
);
149 VERIFY( umap09
.get_allocator().get_personality() == personality02
);
150 VERIFY( umap10
.get_allocator().get_personality() == personality01
);
152 my_umap
umap11(map04_ref
.begin(), map04_ref
.end(), 10, hash
<char>(),
153 equal_to
<char>(), alloc02
);
154 size01
= umap11
.size();
155 personality01
= umap11
.get_allocator().get_personality();
156 my_umap
umap12(map01_ref
.begin(), map01_ref
.end(), 10, hash
<char>(),
157 equal_to
<char>(), alloc01
);
158 size02
= umap12
.size();
159 personality02
= umap12
.get_allocator().get_personality();
162 VERIFY( umap11
.size() == size02
);
163 VERIFY( my_map(umap11
.begin(), umap11
.end()) == map01_ref
);
164 VERIFY( umap12
.size() == size01
);
165 VERIFY( my_map(umap12
.begin(), umap12
.end()) == map04_ref
);
166 VERIFY( umap11
.get_allocator().get_personality() == personality02
);
167 VERIFY( umap12
.get_allocator().get_personality() == personality01
);
169 my_umap
umap13(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
170 equal_to
<char>(), alloc01
);
171 size01
= umap13
.size();
172 personality01
= umap13
.get_allocator().get_personality();
173 my_umap
umap14(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
174 equal_to
<char>(), alloc02
);
175 size02
= umap14
.size();
176 personality02
= umap14
.get_allocator().get_personality();
179 VERIFY( umap13
.size() == size02
);
180 VERIFY( my_map(umap13
.begin(), umap13
.end()) == map03_ref
);
181 VERIFY( umap14
.size() == size01
);
182 VERIFY( my_map(umap14
.begin(), umap14
.end()) == map03_ref
);
183 VERIFY( umap13
.get_allocator().get_personality() == personality02
);
184 VERIFY( umap14
.get_allocator().get_personality() == personality01
);