Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: gcc/libstdc++-v3/testsuite/tr1/6_containers/unordered_map/swap/1.cc

Issue 3050029: [gcc] GCC 4.5.0=>4.5.1 (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/nacl-toolchain.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // 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 // 6.3.4.4 unordered_map::swap
21
22 #include <tr1/unordered_map>
23 #include <map>
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
26
27 // uneq_allocator as a non-empty allocator.
28 void
29 test01()
30 {
31 bool test __attribute__((unused)) = true;
32 using namespace std::tr1;
33 using std::pair;
34 using std::equal_to;
35 using std::map;
36
37 typedef pair<const char, int> my_pair;
38 typedef __gnu_test::uneq_allocator<my_pair> my_alloc;
39 typedef unordered_map<char, int, hash<char>, equal_to<char>, my_alloc>
40 my_umap;
41
42 const char title01[] = "Rivers of sand";
43 const char title02[] = "Concret PH";
44 const char title03[] = "Sonatas and Interludes for Prepared Piano";
45 const char title04[] = "never as tired as when i'm waking up";
46
47 const size_t N1 = sizeof(title01);
48 const size_t N2 = sizeof(title02);
49 const size_t N3 = sizeof(title03);
50 const size_t N4 = sizeof(title04);
51
52 typedef map<char, int> my_map;
53 my_map map01_ref;
54 for (size_t i = 0; i < N1; ++i)
55 map01_ref.insert(my_pair(title01[i], i));
56 my_map map02_ref;
57 for (size_t i = 0; i < N2; ++i)
58 map02_ref.insert(my_pair(title02[i], i));
59 my_map map03_ref;
60 for (size_t i = 0; i < N3; ++i)
61 map03_ref.insert(my_pair(title03[i], i));
62 my_map map04_ref;
63 for (size_t i = 0; i < N4; ++i)
64 map04_ref.insert(my_pair(title04[i], i));
65
66 my_umap::size_type size01, size02;
67
68 my_alloc alloc01(1);
69
70 my_umap umap01(10, hash<char>(), equal_to<char>(), alloc01);
71 size01 = umap01.size();
72 my_umap umap02(10, hash<char>(), equal_to<char>(), alloc01);
73 size02 = umap02.size();
74
75 umap01.swap(umap02);
76 VERIFY( umap01.size() == size02 );
77 VERIFY( umap01.empty() );
78 VERIFY( umap02.size() == size01 );
79 VERIFY( umap02.empty() );
80
81 my_umap umap03(10, hash<char>(), equal_to<char>(), alloc01);
82 size01 = umap03.size();
83 my_umap umap04(map02_ref.begin(), map02_ref.end(), 10, hash<char>(),
84 equal_to<char>(), alloc01);
85 size02 = umap04.size();
86
87 umap03.swap(umap04);
88 VERIFY( umap03.size() == size02 );
89 VERIFY( my_map(umap03.begin(), umap03.end()) == map02_ref );
90 VERIFY( umap04.size() == size01 );
91 VERIFY( umap04.empty() );
92
93 my_umap umap05(map01_ref.begin(), map01_ref.end(), 10, hash<char>(),
94 equal_to<char>(), alloc01);
95 size01 = umap05.size();
96 my_umap umap06(map02_ref.begin(), map02_ref.end(), 10, hash<char>(),
97 equal_to<char>(), alloc01);
98 size02 = umap06.size();
99
100 umap05.swap(umap06);
101 VERIFY( umap05.size() == size02 );
102 VERIFY( my_map(umap05.begin(), umap05.end()) == map02_ref );
103 VERIFY( umap06.size() == size01 );
104 VERIFY( my_map(umap06.begin(), umap06.end()) == map01_ref );
105
106 my_umap umap07(map01_ref.begin(), map01_ref.end(), 10, hash<char>(),
107 equal_to<char>(), alloc01);
108 size01 = umap07.size();
109 my_umap umap08(map03_ref.begin(), map03_ref.end(), 10, hash<char>(),
110 equal_to<char>(), alloc01);
111 size02 = umap08.size();
112
113 umap07.swap(umap08);
114 VERIFY( umap07.size() == size02 );
115 VERIFY( my_map(umap07.begin(), umap07.end()) == map03_ref );
116 VERIFY( umap08.size() == size01 );
117 VERIFY( my_map(umap08.begin(), umap08.end()) == map01_ref );
118
119 my_umap umap09(map03_ref.begin(), map03_ref.end(), 10, hash<char>(),
120 equal_to<char>(), alloc01);
121 size01 = umap09.size();
122 my_umap umap10(map04_ref.begin(), map04_ref.end(), 10, hash<char>(),
123 equal_to<char>(), alloc01);
124 size02 = umap10.size();
125
126 umap09.swap(umap10);
127 VERIFY( umap09.size() == size02 );
128 VERIFY( my_map(umap09.begin(), umap09.end()) == map04_ref );
129 VERIFY( umap10.size() == size01 );
130 VERIFY( my_map(umap10.begin(), umap10.end()) == map03_ref );
131
132 my_umap umap11(map04_ref.begin(), map04_ref.end(), 10, hash<char>(),
133 equal_to<char>(), alloc01);
134 size01 = umap11.size();
135 my_umap umap12(map01_ref.begin(), map01_ref.end(), 10, hash<char>(),
136 equal_to<char>(), alloc01);
137 size02 = umap12.size();
138
139 umap11.swap(umap12);
140 VERIFY( umap11.size() == size02 );
141 VERIFY( my_map(umap11.begin(), umap11.end()) == map01_ref );
142 VERIFY( umap12.size() == size01 );
143 VERIFY( my_map(umap12.begin(), umap12.end()) == map04_ref );
144
145 my_umap umap13(map03_ref.begin(), map03_ref.end(), 10, hash<char>(),
146 equal_to<char>(), alloc01);
147 size01 = umap13.size();
148 my_umap umap14(map03_ref.begin(), map03_ref.end(), 10, hash<char>(),
149 equal_to<char>(), alloc01);
150 size02 = umap14.size();
151
152 umap13.swap(umap14);
153 VERIFY( umap13.size() == size02 );
154 VERIFY( my_map(umap13.begin(), umap13.end()) == map03_ref );
155 VERIFY( umap14.size() == size01 );
156 VERIFY( my_map(umap14.begin(), umap14.end()) == map03_ref );
157 }
158
159 int main()
160 {
161 test01();
162 return 0;
163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698