]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/3.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / modifiers / swap / 3.cc
CommitLineData
6399fdee 1// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
2
f1717362 3// Copyright (C) 2005-2016 Free Software Foundation, Inc.
6399fdee 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
6bc9506f 8// Free Software Foundation; either version 3, or (at your option)
6399fdee 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
6bc9506f 17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
6399fdee 19
20// 23.2.4.3 vector::swap
21
22#include <vector>
23#include <testsuite_hooks.h>
24#include <testsuite_allocator.h>
25
26// uneq_allocator, two different personalities.
27void
28test01()
29{
30 bool test __attribute__((unused)) = true;
31 using namespace std;
32
33 typedef __gnu_test::uneq_allocator<char> my_alloc;
34 typedef vector<char, my_alloc> my_vector;
35
36 const char title01[] = "Rivers of sand";
37 const char title02[] = "Concret PH";
38 const char title03[] = "Sonatas and Interludes for Prepared Piano";
39 const char title04[] = "never as tired as when i'm waking up";
40
41 const size_t N1 = sizeof(title01);
42 const size_t N2 = sizeof(title02);
43 const size_t N3 = sizeof(title03);
44 const size_t N4 = sizeof(title04);
45
46 my_vector::size_type size01, size02;
47
48 my_alloc alloc01(1), alloc02(2);
49 int personality01, personality02;
50
51 my_vector vec01(alloc01);
52 size01 = vec01.size();
53 personality01 = vec01.get_allocator().get_personality();
54 my_vector vec02(alloc02);
55 size02 = vec02.size();
56 personality02 = vec02.get_allocator().get_personality();
57
58 vec01.swap(vec02);
59 VERIFY( vec01.size() == size02 );
60 VERIFY( vec01.empty() );
61 VERIFY( vec02.size() == size01 );
62 VERIFY( vec02.empty() );
63 VERIFY( vec01.get_allocator().get_personality() == personality02 );
64 VERIFY( vec02.get_allocator().get_personality() == personality01 );
65
66 my_vector vec03(alloc02);
67 size01 = vec03.size();
68 personality01 = vec03.get_allocator().get_personality();
69 my_vector vec04(title02, title02 + N2, alloc01);
70 size02 = vec04.size();
71 personality02 = vec04.get_allocator().get_personality();
72
73 vec03.swap(vec04);
74 VERIFY( vec03.size() == size02 );
75 VERIFY( equal(vec03.begin(), vec03.end(), title02) );
76 VERIFY( vec04.size() == size01 );
77 VERIFY( vec04.empty() );
78 VERIFY( vec03.get_allocator().get_personality() == personality02 );
79 VERIFY( vec04.get_allocator().get_personality() == personality01 );
80
81 my_vector vec05(title01, title01 + N1, alloc01);
82 size01 = vec05.size();
83 personality01 = vec05.get_allocator().get_personality();
84 my_vector vec06(title02, title02 + N2, alloc02);
85 size02 = vec06.size();
86 personality02 = vec06.get_allocator().get_personality();
87
88 vec05.swap(vec06);
89 VERIFY( vec05.size() == size02 );
90 VERIFY( equal(vec05.begin(), vec05.end(), title02) );
91 VERIFY( vec06.size() == size01 );
92 VERIFY( equal(vec06.begin(), vec06.end(), title01) );
93 VERIFY( vec05.get_allocator().get_personality() == personality02 );
94 VERIFY( vec06.get_allocator().get_personality() == personality01 );
95
96 my_vector vec07(title01, title01 + N1, alloc02);
97 size01 = vec07.size();
98 personality01 = vec07.get_allocator().get_personality();
99 my_vector vec08(title03, title03 + N3, alloc01);
100 size02 = vec08.size();
101 personality02 = vec08.get_allocator().get_personality();
102
103 vec07.swap(vec08);
104 VERIFY( vec07.size() == size02 );
105 VERIFY( equal(vec07.begin(), vec07.end(), title03) );
106 VERIFY( vec08.size() == size01 );
107 VERIFY( equal(vec08.begin(), vec08.end(), title01) );
108 VERIFY( vec07.get_allocator().get_personality() == personality02 );
109 VERIFY( vec08.get_allocator().get_personality() == personality01 );
110
111 my_vector vec09(title03, title03 + N3, alloc01);
112 size01 = vec09.size();
113 personality01 = vec09.get_allocator().get_personality();
114 my_vector vec10(title04, title04 + N4, alloc02);
115 size02 = vec10.size();
116 personality02 = vec10.get_allocator().get_personality();
117
118 vec09.swap(vec10);
119 VERIFY( vec09.size() == size02 );
120 VERIFY( equal(vec09.begin(), vec09.end(), title04) );
121 VERIFY( vec10.size() == size01 );
122 VERIFY( equal(vec10.begin(), vec10.end(), title03) );
123 VERIFY( vec09.get_allocator().get_personality() == personality02 );
124 VERIFY( vec10.get_allocator().get_personality() == personality01 );
125
126 my_vector vec11(title04, title04 + N4, alloc02);
127 size01 = vec11.size();
128 personality01 = vec11.get_allocator().get_personality();
129 my_vector vec12(title01, title01 + N1, alloc01);
130 size02 = vec12.size();
131 personality02 = vec12.get_allocator().get_personality();
132
133 vec11.swap(vec12);
134 VERIFY( vec11.size() == size02 );
135 VERIFY( equal(vec11.begin(), vec11.end(), title01) );
136 VERIFY( vec12.size() == size01 );
137 VERIFY( equal(vec12.begin(), vec12.end(), title04) );
138 VERIFY( vec11.get_allocator().get_personality() == personality02 );
139 VERIFY( vec12.get_allocator().get_personality() == personality01 );
140
141 my_vector vec13(title03, title03 + N3, alloc01);
142 size01 = vec13.size();
143 personality01 = vec13.get_allocator().get_personality();
144 my_vector vec14(title03, title03 + N3, alloc02);
145 size02 = vec14.size();
146 personality02 = vec14.get_allocator().get_personality();
147
148 vec13.swap(vec14);
149 VERIFY( vec13.size() == size02 );
150 VERIFY( equal(vec13.begin(), vec13.end(), title03) );
151 VERIFY( vec14.size() == size01 );
152 VERIFY( equal(vec14.begin(), vec14.end(), title03) );
153 VERIFY( vec13.get_allocator().get_personality() == personality02 );
154 VERIFY( vec14.get_allocator().get_personality() == personality01 );
155}
156
157int main()
158{
159 test01();
160 return 0;
161}