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 as a non-empty allocator.
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
;
65 my_map
map01(less
<char>(), alloc01
);
66 size01
= map01
.size();
67 my_map
map02(less
<char>(), alloc01
);
68 size02
= map02
.size();
71 VERIFY( map01
.size() == size02
);
72 VERIFY( map01
.empty() );
73 VERIFY( map02
.size() == size01
);
74 VERIFY( map02
.empty() );
76 my_map
map03(less
<char>(), alloc01
);
77 size01
= map03
.size();
78 my_map
map04(map02_ref
.begin(), map02_ref
.end(), less
<char>(), alloc01
);
79 size02
= map04
.size();
82 VERIFY( map03
.size() == size02
);
83 VERIFY( equal(map03
.begin(), map03
.end(), map02_ref
.begin()) );
84 VERIFY( map04
.size() == size01
);
85 VERIFY( map04
.empty() );
87 my_map
map05(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc01
);
88 size01
= map05
.size();
89 my_map
map06(map02_ref
.begin(), map02_ref
.end(), less
<char>(), alloc01
);
90 size02
= map06
.size();
93 VERIFY( map05
.size() == size02
);
94 VERIFY( equal(map05
.begin(), map05
.end(), map02_ref
.begin()) );
95 VERIFY( map06
.size() == size01
);
96 VERIFY( equal(map06
.begin(), map06
.end(), map01_ref
.begin()) );
98 my_map
map07(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc01
);
99 size01
= map07
.size();
100 my_map
map08(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
101 size02
= map08
.size();
104 VERIFY( map07
.size() == size02
);
105 VERIFY( equal(map07
.begin(), map07
.end(), map03_ref
.begin()) );
106 VERIFY( map08
.size() == size01
);
107 VERIFY( equal(map08
.begin(), map08
.end(), map01_ref
.begin()) );
109 my_map
map09(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
110 size01
= map09
.size();
111 my_map
map10(map04_ref
.begin(), map04_ref
.end(), less
<char>(), alloc01
);
112 size02
= map10
.size();
115 VERIFY( map09
.size() == size02
);
116 VERIFY( equal(map09
.begin(), map09
.end(), map04_ref
.begin()) );
117 VERIFY( map10
.size() == size01
);
118 VERIFY( equal(map10
.begin(), map10
.end(), map03_ref
.begin()) );
120 my_map
map11(map04_ref
.begin(), map04_ref
.end(), less
<char>(), alloc01
);
121 size01
= map11
.size();
122 my_map
map12(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc01
);
123 size02
= map12
.size();
126 VERIFY( map11
.size() == size02
);
127 VERIFY( equal(map11
.begin(), map11
.end(), map01_ref
.begin()) );
128 VERIFY( map12
.size() == size01
);
129 VERIFY( equal(map12
.begin(), map12
.end(), map04_ref
.begin()) );
131 my_map
map13(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
132 size01
= map13
.size();
133 my_map
map14(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
134 size02
= map14
.size();
137 VERIFY( map13
.size() == size02
);
138 VERIFY( equal(map13
.begin(), map13
.end(), map03_ref
.begin()) );
139 VERIFY( map14
.size() == size01
);
140 VERIFY( equal(map14
.begin(), map14
.end(), map03_ref
.begin()) );