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 // 23.2.4.3 vector::swap
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
27 // uneq_allocator, two different personalities.
31 bool test
__attribute__((unused
)) = true;
34 typedef __gnu_test::uneq_allocator
<char> my_alloc
;
35 typedef vector
<char, my_alloc
> my_vector
;
37 const char title01
[] = "Rivers of sand";
38 const char title02
[] = "Concret PH";
39 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
40 const char title04
[] = "never as tired as when i'm waking up";
42 const size_t N1
= sizeof(title01
);
43 const size_t N2
= sizeof(title02
);
44 const size_t N3
= sizeof(title03
);
45 const size_t N4
= sizeof(title04
);
47 my_vector::size_type size01
, size02
;
49 my_alloc
alloc01(1), alloc02(2);
50 int personality01
, personality02
;
52 my_vector
vec01(alloc01
);
53 size01
= vec01
.size();
54 personality01
= vec01
.get_allocator().get_personality();
55 my_vector
vec02(alloc02
);
56 size02
= vec02
.size();
57 personality02
= vec02
.get_allocator().get_personality();
60 VERIFY( vec01
.size() == size02
);
61 VERIFY( vec01
.empty() );
62 VERIFY( vec02
.size() == size01
);
63 VERIFY( vec02
.empty() );
64 VERIFY( vec01
.get_allocator().get_personality() == personality02
);
65 VERIFY( vec02
.get_allocator().get_personality() == personality01
);
67 my_vector
vec03(alloc02
);
68 size01
= vec03
.size();
69 personality01
= vec03
.get_allocator().get_personality();
70 my_vector
vec04(title02
, title02
+ N2
, alloc01
);
71 size02
= vec04
.size();
72 personality02
= vec04
.get_allocator().get_personality();
75 VERIFY( vec03
.size() == size02
);
76 VERIFY( equal(vec03
.begin(), vec03
.end(), title02
) );
77 VERIFY( vec04
.size() == size01
);
78 VERIFY( vec04
.empty() );
79 VERIFY( vec03
.get_allocator().get_personality() == personality02
);
80 VERIFY( vec04
.get_allocator().get_personality() == personality01
);
82 my_vector
vec05(title01
, title01
+ N1
, alloc01
);
83 size01
= vec05
.size();
84 personality01
= vec05
.get_allocator().get_personality();
85 my_vector
vec06(title02
, title02
+ N2
, alloc02
);
86 size02
= vec06
.size();
87 personality02
= vec06
.get_allocator().get_personality();
90 VERIFY( vec05
.size() == size02
);
91 VERIFY( equal(vec05
.begin(), vec05
.end(), title02
) );
92 VERIFY( vec06
.size() == size01
);
93 VERIFY( equal(vec06
.begin(), vec06
.end(), title01
) );
94 VERIFY( vec05
.get_allocator().get_personality() == personality02
);
95 VERIFY( vec06
.get_allocator().get_personality() == personality01
);
97 my_vector
vec07(title01
, title01
+ N1
, alloc02
);
98 size01
= vec07
.size();
99 personality01
= vec07
.get_allocator().get_personality();
100 my_vector
vec08(title03
, title03
+ N3
, alloc01
);
101 size02
= vec08
.size();
102 personality02
= vec08
.get_allocator().get_personality();
105 VERIFY( vec07
.size() == size02
);
106 VERIFY( equal(vec07
.begin(), vec07
.end(), title03
) );
107 VERIFY( vec08
.size() == size01
);
108 VERIFY( equal(vec08
.begin(), vec08
.end(), title01
) );
109 VERIFY( vec07
.get_allocator().get_personality() == personality02
);
110 VERIFY( vec08
.get_allocator().get_personality() == personality01
);
112 my_vector
vec09(title03
, title03
+ N3
, alloc01
);
113 size01
= vec09
.size();
114 personality01
= vec09
.get_allocator().get_personality();
115 my_vector
vec10(title04
, title04
+ N4
, alloc02
);
116 size02
= vec10
.size();
117 personality02
= vec10
.get_allocator().get_personality();
120 VERIFY( vec09
.size() == size02
);
121 VERIFY( equal(vec09
.begin(), vec09
.end(), title04
) );
122 VERIFY( vec10
.size() == size01
);
123 VERIFY( equal(vec10
.begin(), vec10
.end(), title03
) );
124 VERIFY( vec09
.get_allocator().get_personality() == personality02
);
125 VERIFY( vec10
.get_allocator().get_personality() == personality01
);
127 my_vector
vec11(title04
, title04
+ N4
, alloc02
);
128 size01
= vec11
.size();
129 personality01
= vec11
.get_allocator().get_personality();
130 my_vector
vec12(title01
, title01
+ N1
, alloc01
);
131 size02
= vec12
.size();
132 personality02
= vec12
.get_allocator().get_personality();
135 VERIFY( vec11
.size() == size02
);
136 VERIFY( equal(vec11
.begin(), vec11
.end(), title01
) );
137 VERIFY( vec12
.size() == size01
);
138 VERIFY( equal(vec12
.begin(), vec12
.end(), title04
) );
139 VERIFY( vec11
.get_allocator().get_personality() == personality02
);
140 VERIFY( vec12
.get_allocator().get_personality() == personality01
);
142 my_vector
vec13(title03
, title03
+ N3
, alloc01
);
143 size01
= vec13
.size();
144 personality01
= vec13
.get_allocator().get_personality();
145 my_vector
vec14(title03
, title03
+ N3
, alloc02
);
146 size02
= vec14
.size();
147 personality02
= vec14
.get_allocator().get_personality();
150 VERIFY( vec13
.size() == size02
);
151 VERIFY( equal(vec13
.begin(), vec13
.end(), title03
) );
152 VERIFY( vec14
.size() == size01
);
153 VERIFY( equal(vec14
.begin(), vec14
.end(), title03
) );
154 VERIFY( vec13
.get_allocator().get_personality() == personality02
);
155 VERIFY( vec14
.get_allocator().get_personality() == personality01
);