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;
33 using namespace std::tr1
;
38 typedef pair
<const char, int> my_pair
;
39 typedef __gnu_test::uneq_allocator
<my_pair
> my_alloc
;
40 typedef unordered_map
<char, int, hash
<char>, equal_to
<char>, my_alloc
>
43 const char title01
[] = "Rivers of sand";
44 const char title02
[] = "Concret PH";
45 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
46 const char title04
[] = "never as tired as when i'm waking up";
48 const size_t N1
= sizeof(title01
);
49 const size_t N2
= sizeof(title02
);
50 const size_t N3
= sizeof(title03
);
51 const size_t N4
= sizeof(title04
);
53 typedef map
<char, int> my_map
;
55 for (size_t i
= 0; i
< N1
; ++i
)
56 map01_ref
.insert(my_pair(title01
[i
], i
));
58 for (size_t i
= 0; i
< N2
; ++i
)
59 map02_ref
.insert(my_pair(title02
[i
], i
));
61 for (size_t i
= 0; i
< N3
; ++i
)
62 map03_ref
.insert(my_pair(title03
[i
], i
));
64 for (size_t i
= 0; i
< N4
; ++i
)
65 map04_ref
.insert(my_pair(title04
[i
], i
));
67 my_umap::size_type size01
, size02
;
69 my_alloc
alloc01(1), alloc02(2);
70 int personality01
, personality02
;
72 my_umap
umap01(10, hash
<char>(), equal_to
<char>(), alloc01
);
73 size01
= umap01
.size();
74 personality01
= umap01
.get_allocator().get_personality();
75 my_umap
umap02(10, hash
<char>(), equal_to
<char>(), alloc02
);
76 size02
= umap02
.size();
77 personality02
= umap02
.get_allocator().get_personality();
80 VERIFY( umap01
.size() == size02
);
81 VERIFY( umap01
.empty() );
82 VERIFY( umap02
.size() == size01
);
83 VERIFY( umap02
.empty() );
84 VERIFY( umap01
.get_allocator().get_personality() == personality02
);
85 VERIFY( umap02
.get_allocator().get_personality() == personality01
);
87 my_umap
umap03(10, hash
<char>(), equal_to
<char>(), alloc02
);
88 size01
= umap03
.size();
89 personality01
= umap03
.get_allocator().get_personality();
90 my_umap
umap04(map02_ref
.begin(), map02_ref
.end(), 10, hash
<char>(),
91 equal_to
<char>(), alloc01
);
92 size02
= umap04
.size();
93 personality02
= umap04
.get_allocator().get_personality();
96 VERIFY( umap03
.size() == size02
);
97 VERIFY( my_map(umap03
.begin(), umap03
.end()) == map02_ref
);
98 VERIFY( umap04
.size() == size01
);
99 VERIFY( umap04
.empty() );
100 VERIFY( umap03
.get_allocator().get_personality() == personality02
);
101 VERIFY( umap04
.get_allocator().get_personality() == personality01
);
103 my_umap
umap05(map01_ref
.begin(), map01_ref
.end(), 10, hash
<char>(),
104 equal_to
<char>(), alloc01
);
105 size01
= umap05
.size();
106 personality01
= umap05
.get_allocator().get_personality();
107 my_umap
umap06(map02_ref
.begin(), map02_ref
.end(), 10, hash
<char>(),
108 equal_to
<char>(), alloc02
);
109 size02
= umap06
.size();
110 personality02
= umap06
.get_allocator().get_personality();
113 VERIFY( umap05
.size() == size02
);
114 VERIFY( my_map(umap05
.begin(), umap05
.end()) == map02_ref
);
115 VERIFY( umap06
.size() == size01
);
116 VERIFY( my_map(umap06
.begin(), umap06
.end()) == map01_ref
);
117 VERIFY( umap05
.get_allocator().get_personality() == personality02
);
118 VERIFY( umap06
.get_allocator().get_personality() == personality01
);
120 my_umap
umap07(map01_ref
.begin(), map01_ref
.end(), 10, hash
<char>(),
121 equal_to
<char>(), alloc02
);
122 size01
= umap07
.size();
123 personality01
= umap07
.get_allocator().get_personality();
124 my_umap
umap08(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
125 equal_to
<char>(), alloc01
);
126 size02
= umap08
.size();
127 personality02
= umap08
.get_allocator().get_personality();
130 VERIFY( umap07
.size() == size02
);
131 VERIFY( my_map(umap07
.begin(), umap07
.end()) == map03_ref
);
132 VERIFY( umap08
.size() == size01
);
133 VERIFY( my_map(umap08
.begin(), umap08
.end()) == map01_ref
);
134 VERIFY( umap07
.get_allocator().get_personality() == personality02
);
135 VERIFY( umap08
.get_allocator().get_personality() == personality01
);
137 my_umap
umap09(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
138 equal_to
<char>(), alloc01
);
139 size01
= umap09
.size();
140 personality01
= umap09
.get_allocator().get_personality();
141 my_umap
umap10(map04_ref
.begin(), map04_ref
.end(), 10, hash
<char>(),
142 equal_to
<char>(), alloc02
);
143 size02
= umap10
.size();
144 personality02
= umap10
.get_allocator().get_personality();
147 VERIFY( umap09
.size() == size02
);
148 VERIFY( my_map(umap09
.begin(), umap09
.end()) == map04_ref
);
149 VERIFY( umap10
.size() == size01
);
150 VERIFY( my_map(umap10
.begin(), umap10
.end()) == map03_ref
);
151 VERIFY( umap09
.get_allocator().get_personality() == personality02
);
152 VERIFY( umap10
.get_allocator().get_personality() == personality01
);
154 my_umap
umap11(map04_ref
.begin(), map04_ref
.end(), 10, hash
<char>(),
155 equal_to
<char>(), alloc02
);
156 size01
= umap11
.size();
157 personality01
= umap11
.get_allocator().get_personality();
158 my_umap
umap12(map01_ref
.begin(), map01_ref
.end(), 10, hash
<char>(),
159 equal_to
<char>(), alloc01
);
160 size02
= umap12
.size();
161 personality02
= umap12
.get_allocator().get_personality();
164 VERIFY( umap11
.size() == size02
);
165 VERIFY( my_map(umap11
.begin(), umap11
.end()) == map01_ref
);
166 VERIFY( umap12
.size() == size01
);
167 VERIFY( my_map(umap12
.begin(), umap12
.end()) == map04_ref
);
168 VERIFY( umap11
.get_allocator().get_personality() == personality02
);
169 VERIFY( umap12
.get_allocator().get_personality() == personality01
);
171 my_umap
umap13(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
172 equal_to
<char>(), alloc01
);
173 size01
= umap13
.size();
174 personality01
= umap13
.get_allocator().get_personality();
175 my_umap
umap14(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
176 equal_to
<char>(), alloc02
);
177 size02
= umap14
.size();
178 personality02
= umap14
.get_allocator().get_personality();
181 VERIFY( umap13
.size() == size02
);
182 VERIFY( my_map(umap13
.begin(), umap13
.end()) == map03_ref
);
183 VERIFY( umap14
.size() == size01
);
184 VERIFY( my_map(umap14
.begin(), umap14
.end()) == map03_ref
);
185 VERIFY( umap13
.get_allocator().get_personality() == personality02
);
186 VERIFY( umap14
.get_allocator().get_personality() == personality01
);