1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2018 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
26 // uneq_allocator, two different personalities.
32 typedef __gnu_test::uneq_allocator
<char> my_alloc
;
33 typedef set
<char, less
<char>, my_alloc
> my_set
;
35 const char title01
[] = "Rivers of sand";
36 const char title02
[] = "Concret PH";
37 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
38 const char title04
[] = "never as tired as when i'm waking up";
40 const size_t N1
= sizeof(title01
);
41 const size_t N2
= sizeof(title02
);
42 const size_t N3
= sizeof(title03
);
43 const size_t N4
= sizeof(title04
);
45 const set
<char> set01_ref(title01
, title01
+ N1
);
46 const set
<char> set02_ref(title02
, title02
+ N2
);
47 const set
<char> set03_ref(title03
, title03
+ N3
);
48 const set
<char> set04_ref(title04
, title04
+ N4
);
50 my_set::size_type size01
, size02
;
52 my_alloc
alloc01(1), alloc02(2);
53 int personality01
, personality02
;
55 my_set
set01(less
<char>(), alloc01
);
56 size01
= set01
.size();
57 personality01
= set01
.get_allocator().get_personality();
58 my_set
set02(less
<char>(), alloc02
);
59 size02
= set02
.size();
60 personality02
= set02
.get_allocator().get_personality();
63 VERIFY( set01
.size() == size02
);
64 VERIFY( set01
.empty() );
65 VERIFY( set02
.size() == size01
);
66 VERIFY( set02
.empty() );
67 VERIFY( set01
.get_allocator().get_personality() == personality02
);
68 VERIFY( set02
.get_allocator().get_personality() == personality01
);
70 my_set
set03(less
<char>(), alloc02
);
71 size01
= set03
.size();
72 personality01
= set03
.get_allocator().get_personality();
73 my_set
set04(title02
, title02
+ N2
, less
<char>(), alloc01
);
74 size02
= set04
.size();
75 personality02
= set04
.get_allocator().get_personality();
78 VERIFY( set03
.size() == size02
);
79 VERIFY( equal(set03
.begin(), set03
.end(), set02_ref
.begin()) );
80 VERIFY( set04
.size() == size01
);
81 VERIFY( set04
.empty() );
82 VERIFY( set03
.get_allocator().get_personality() == personality02
);
83 VERIFY( set04
.get_allocator().get_personality() == personality01
);
85 my_set
set05(title01
, title01
+ N1
, less
<char>(), alloc01
);
86 size01
= set05
.size();
87 personality01
= set05
.get_allocator().get_personality();
88 my_set
set06(title02
, title02
+ N2
, less
<char>(), alloc02
);
89 size02
= set06
.size();
90 personality02
= set06
.get_allocator().get_personality();
93 VERIFY( set05
.size() == size02
);
94 VERIFY( equal(set05
.begin(), set05
.end(), set02_ref
.begin()) );
95 VERIFY( set06
.size() == size01
);
96 VERIFY( equal(set06
.begin(), set06
.end(), set01_ref
.begin()) );
97 VERIFY( set05
.get_allocator().get_personality() == personality02
);
98 VERIFY( set06
.get_allocator().get_personality() == personality01
);
100 my_set
set07(title01
, title01
+ N1
, less
<char>(), alloc02
);
101 size01
= set07
.size();
102 personality01
= set07
.get_allocator().get_personality();
103 my_set
set08(title03
, title03
+ N3
, less
<char>(), alloc01
);
104 size02
= set08
.size();
105 personality02
= set08
.get_allocator().get_personality();
108 VERIFY( set07
.size() == size02
);
109 VERIFY( equal(set07
.begin(), set07
.end(), set03_ref
.begin()) );
110 VERIFY( set08
.size() == size01
);
111 VERIFY( equal(set08
.begin(), set08
.end(), set01_ref
.begin()) );
112 VERIFY( set07
.get_allocator().get_personality() == personality02
);
113 VERIFY( set08
.get_allocator().get_personality() == personality01
);
115 my_set
set09(title03
, title03
+ N3
, less
<char>(), alloc01
);
116 size01
= set09
.size();
117 personality01
= set09
.get_allocator().get_personality();
118 my_set
set10(title04
, title04
+ N4
, less
<char>(), alloc02
);
119 size02
= set10
.size();
120 personality02
= set10
.get_allocator().get_personality();
123 VERIFY( set09
.size() == size02
);
124 VERIFY( equal(set09
.begin(), set09
.end(), set04_ref
.begin()) );
125 VERIFY( set10
.size() == size01
);
126 VERIFY( equal(set10
.begin(), set10
.end(), set03_ref
.begin()) );
127 VERIFY( set09
.get_allocator().get_personality() == personality02
);
128 VERIFY( set10
.get_allocator().get_personality() == personality01
);
130 my_set
set11(title04
, title04
+ N4
, less
<char>(), alloc02
);
131 size01
= set11
.size();
132 personality01
= set11
.get_allocator().get_personality();
133 my_set
set12(title01
, title01
+ N1
, less
<char>(), alloc01
);
134 size02
= set12
.size();
135 personality02
= set12
.get_allocator().get_personality();
138 VERIFY( set11
.size() == size02
);
139 VERIFY( equal(set11
.begin(), set11
.end(), set01_ref
.begin()) );
140 VERIFY( set12
.size() == size01
);
141 VERIFY( equal(set12
.begin(), set12
.end(), set04_ref
.begin()) );
142 VERIFY( set11
.get_allocator().get_personality() == personality02
);
143 VERIFY( set12
.get_allocator().get_personality() == personality01
);
145 my_set
set13(title03
, title03
+ N3
, less
<char>(), alloc01
);
146 size01
= set13
.size();
147 personality01
= set13
.get_allocator().get_personality();
148 my_set
set14(title03
, title03
+ N3
, less
<char>(), alloc02
);
149 size02
= set14
.size();
150 personality02
= set14
.get_allocator().get_personality();
153 VERIFY( set13
.size() == size02
);
154 VERIFY( equal(set13
.begin(), set13
.end(), set03_ref
.begin()) );
155 VERIFY( set14
.size() == size01
);
156 VERIFY( equal(set14
.begin(), set14
.end(), set03_ref
.begin()) );
157 VERIFY( set13
.get_allocator().get_personality() == personality02
);
158 VERIFY( set14
.get_allocator().get_personality() == personality01
);