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,
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
27 // uneq_allocator, two different personalities.
31 bool test
__attribute__((unused
)) = true;
34 typedef pair
<const char, int> my_pair
;
35 typedef __gnu_test::uneq_allocator
<my_pair
> my_alloc
;
36 typedef map
<char, int, less
<char>, my_alloc
> my_map
;
38 const char title01
[] = "Rivers of sand";
39 const char title02
[] = "Concret PH";
40 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
41 const char title04
[] = "never as tired as when i'm waking up";
43 const size_t N1
= sizeof(title01
);
44 const size_t N2
= sizeof(title02
);
45 const size_t N3
= sizeof(title03
);
46 const size_t N4
= sizeof(title04
);
48 map
<char, int> map01_ref
;
49 for (size_t i
= 0; i
< N1
; ++i
)
50 map01_ref
.insert(my_pair(title01
[i
], i
));
51 map
<char, int> map02_ref
;
52 for (size_t i
= 0; i
< N2
; ++i
)
53 map02_ref
.insert(my_pair(title02
[i
], i
));
54 map
<char, int> map03_ref
;
55 for (size_t i
= 0; i
< N3
; ++i
)
56 map03_ref
.insert(my_pair(title03
[i
], i
));
57 map
<char, int> map04_ref
;
58 for (size_t i
= 0; i
< N4
; ++i
)
59 map04_ref
.insert(my_pair(title04
[i
], i
));
61 my_map::size_type size01
, size02
;
63 my_alloc
alloc01(1), alloc02(2);
64 int personality01
, personality02
;
66 my_map
map01(less
<char>(), alloc01
);
67 size01
= map01
.size();
68 personality01
= map01
.get_allocator().get_personality();
69 my_map
map02(less
<char>(), alloc02
);
70 size02
= map02
.size();
71 personality02
= map02
.get_allocator().get_personality();
74 VERIFY( map01
.size() == size02
);
75 VERIFY( map01
.empty() );
76 VERIFY( map02
.size() == size01
);
77 VERIFY( map02
.empty() );
78 VERIFY( map01
.get_allocator().get_personality() == personality02
);
79 VERIFY( map02
.get_allocator().get_personality() == personality01
);
81 my_map
map03(less
<char>(), alloc02
);
82 size01
= map03
.size();
83 personality01
= map03
.get_allocator().get_personality();
84 my_map
map04(map02_ref
.begin(), map02_ref
.end(), less
<char>(), alloc01
);
85 size02
= map04
.size();
86 personality02
= map04
.get_allocator().get_personality();
89 VERIFY( map03
.size() == size02
);
90 VERIFY( equal(map03
.begin(), map03
.end(), map02_ref
.begin()) );
91 VERIFY( map04
.size() == size01
);
92 VERIFY( map04
.empty() );
93 VERIFY( map03
.get_allocator().get_personality() == personality02
);
94 VERIFY( map04
.get_allocator().get_personality() == personality01
);
96 my_map
map05(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc01
);
97 size01
= map05
.size();
98 personality01
= map05
.get_allocator().get_personality();
99 my_map
map06(map02_ref
.begin(), map02_ref
.end(), less
<char>(), alloc02
);
100 size02
= map06
.size();
101 personality02
= map06
.get_allocator().get_personality();
104 VERIFY( map05
.size() == size02
);
105 VERIFY( equal(map05
.begin(), map05
.end(), map02_ref
.begin()) );
106 VERIFY( map06
.size() == size01
);
107 VERIFY( equal(map06
.begin(), map06
.end(), map01_ref
.begin()) );
108 VERIFY( map05
.get_allocator().get_personality() == personality02
);
109 VERIFY( map06
.get_allocator().get_personality() == personality01
);
111 my_map
map07(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc02
);
112 size01
= map07
.size();
113 personality01
= map07
.get_allocator().get_personality();
114 my_map
map08(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
115 size02
= map08
.size();
116 personality02
= map08
.get_allocator().get_personality();
119 VERIFY( map07
.size() == size02
);
120 VERIFY( equal(map07
.begin(), map07
.end(), map03_ref
.begin()) );
121 VERIFY( map08
.size() == size01
);
122 VERIFY( equal(map08
.begin(), map08
.end(), map01_ref
.begin()) );
123 VERIFY( map07
.get_allocator().get_personality() == personality02
);
124 VERIFY( map08
.get_allocator().get_personality() == personality01
);
126 my_map
map09(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
127 size01
= map09
.size();
128 personality01
= map09
.get_allocator().get_personality();
129 my_map
map10(map04_ref
.begin(), map04_ref
.end(), less
<char>(), alloc02
);
130 size02
= map10
.size();
131 personality02
= map10
.get_allocator().get_personality();
134 VERIFY( map09
.size() == size02
);
135 VERIFY( equal(map09
.begin(), map09
.end(), map04_ref
.begin()) );
136 VERIFY( map10
.size() == size01
);
137 VERIFY( equal(map10
.begin(), map10
.end(), map03_ref
.begin()) );
138 VERIFY( map09
.get_allocator().get_personality() == personality02
);
139 VERIFY( map10
.get_allocator().get_personality() == personality01
);
141 my_map
map11(map04_ref
.begin(), map04_ref
.end(), less
<char>(), alloc02
);
142 size01
= map11
.size();
143 personality01
= map11
.get_allocator().get_personality();
144 my_map
map12(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc01
);
145 size02
= map12
.size();
146 personality02
= map12
.get_allocator().get_personality();
149 VERIFY( map11
.size() == size02
);
150 VERIFY( equal(map11
.begin(), map11
.end(), map01_ref
.begin()) );
151 VERIFY( map12
.size() == size01
);
152 VERIFY( equal(map12
.begin(), map12
.end(), map04_ref
.begin()) );
153 VERIFY( map11
.get_allocator().get_personality() == personality02
);
154 VERIFY( map12
.get_allocator().get_personality() == personality01
);
156 my_map
map13(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
157 size01
= map13
.size();
158 personality01
= map13
.get_allocator().get_personality();
159 my_map
map14(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc02
);
160 size02
= map14
.size();
161 personality02
= map14
.get_allocator().get_personality();
164 VERIFY( map13
.size() == size02
);
165 VERIFY( equal(map13
.begin(), map13
.end(), map03_ref
.begin()) );
166 VERIFY( map14
.size() == size01
);
167 VERIFY( equal(map14
.begin(), map14
.end(), map03_ref
.begin()) );
168 VERIFY( map13
.get_allocator().get_personality() == personality02
);
169 VERIFY( map14
.get_allocator().get_personality() == personality01
);