1// 2005-12-23 Paolo Carlini <pcarlini@suse.de> 2 3// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. 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 8// Free Software Foundation; either version 3, or (at your option) 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 17// with this library; see the file COPYING3. If not see 18// <http://www.gnu.org/licenses/>. 19 20// 23.2.5 vector<bool>::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<bool> my_alloc; 34 typedef vector<bool, 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 vector<bool> vec01_ref; 47 for (size_t i = 0; i < N1; ++i) 48 vec01_ref.push_back(bool(title01[i] > 96 ? 1 : 0)); 49 vector<bool> vec02_ref; 50 for (size_t i = 0; i < N2; ++i) 51 vec02_ref.push_back(bool(title02[i] > 96 ? 1 : 0)); 52 vector<bool> vec03_ref; 53 for (size_t i = 0; i < N3; ++i) 54 vec03_ref.push_back(bool(title03[i] > 96 ? 1 : 0)); 55 vector<bool> vec04_ref; 56 for (size_t i = 0; i < N4; ++i) 57 vec04_ref.push_back(bool(title04[i] > 96 ? 1 : 0)); 58 59 my_vector::size_type size01, size02; 60 61 my_alloc alloc01(1), alloc02(2); 62 int personality01, personality02; 63 64 my_vector vec01(alloc01); 65 size01 = vec01.size(); 66 personality01 = vec01.get_allocator().get_personality(); 67 my_vector vec02(alloc02); 68 size02 = vec02.size(); 69 personality02 = vec02.get_allocator().get_personality(); 70 71 vec01.swap(vec02); 72 VERIFY( vec01.size() == size02 ); 73 VERIFY( vec01.empty() ); 74 VERIFY( vec02.size() == size01 ); 75 VERIFY( vec02.empty() ); 76 VERIFY( vec01.get_allocator().get_personality() == personality02 ); 77 VERIFY( vec02.get_allocator().get_personality() == personality01 ); 78 79 my_vector vec03(alloc02); 80 size01 = vec03.size(); 81 personality01 = vec03.get_allocator().get_personality(); 82 my_vector vec04(vec02_ref.begin(), vec02_ref.end(), alloc01); 83 size02 = vec04.size(); 84 personality02 = vec04.get_allocator().get_personality(); 85 86 vec03.swap(vec04); 87 VERIFY( vec03.size() == size02 ); 88 VERIFY( equal(vec03.begin(), vec03.end(), vec02_ref.begin()) ); 89 VERIFY( vec04.size() == size01 ); 90 VERIFY( vec04.empty() ); 91 VERIFY( vec03.get_allocator().get_personality() == personality02 ); 92 VERIFY( vec04.get_allocator().get_personality() == personality01 ); 93 94 my_vector vec05(vec01_ref.begin(), vec01_ref.end(), alloc01); 95 size01 = vec05.size(); 96 personality01 = vec05.get_allocator().get_personality(); 97 my_vector vec06(vec02_ref.begin(), vec02_ref.end(), alloc02); 98 size02 = vec06.size(); 99 personality02 = vec06.get_allocator().get_personality(); 100 101 vec05.swap(vec06); 102 VERIFY( vec05.size() == size02 ); 103 VERIFY( equal(vec05.begin(), vec05.end(), vec02_ref.begin()) ); 104 VERIFY( vec06.size() == size01 ); 105 VERIFY( equal(vec06.begin(), vec06.end(), vec01_ref.begin()) ); 106 VERIFY( vec05.get_allocator().get_personality() == personality02 ); 107 VERIFY( vec06.get_allocator().get_personality() == personality01 ); 108 109 my_vector vec07(vec01_ref.begin(), vec01_ref.end(), alloc02); 110 size01 = vec07.size(); 111 personality01 = vec07.get_allocator().get_personality(); 112 my_vector vec08(vec03_ref.begin(), vec03_ref.end(), alloc01); 113 size02 = vec08.size(); 114 personality02 = vec08.get_allocator().get_personality(); 115 116 vec07.swap(vec08); 117 VERIFY( vec07.size() == size02 ); 118 VERIFY( equal(vec07.begin(), vec07.end(), vec03_ref.begin()) ); 119 VERIFY( vec08.size() == size01 ); 120 VERIFY( equal(vec08.begin(), vec08.end(), vec01_ref.begin()) ); 121 VERIFY( vec07.get_allocator().get_personality() == personality02 ); 122 VERIFY( vec08.get_allocator().get_personality() == personality01 ); 123 124 my_vector vec09(vec03_ref.begin(), vec03_ref.end(), alloc01); 125 size01 = vec09.size(); 126 personality01 = vec09.get_allocator().get_personality(); 127 my_vector vec10(vec04_ref.begin(), vec04_ref.end(), alloc02); 128 size02 = vec10.size(); 129 personality02 = vec10.get_allocator().get_personality(); 130 131 vec09.swap(vec10); 132 VERIFY( vec09.size() == size02 ); 133 VERIFY( equal(vec09.begin(), vec09.end(), vec04_ref.begin()) ); 134 VERIFY( vec10.size() == size01 ); 135 VERIFY( equal(vec10.begin(), vec10.end(), vec03_ref.begin()) ); 136 VERIFY( vec09.get_allocator().get_personality() == personality02 ); 137 VERIFY( vec10.get_allocator().get_personality() == personality01 ); 138 139 my_vector vec11(vec04_ref.begin(), vec04_ref.end(), alloc02); 140 size01 = vec11.size(); 141 personality01 = vec11.get_allocator().get_personality(); 142 my_vector vec12(vec01_ref.begin(), vec01_ref.end(), alloc01); 143 size02 = vec12.size(); 144 personality02 = vec12.get_allocator().get_personality(); 145 146 vec11.swap(vec12); 147 VERIFY( vec11.size() == size02 ); 148 VERIFY( equal(vec11.begin(), vec11.end(), vec01_ref.begin()) ); 149 VERIFY( vec12.size() == size01 ); 150 VERIFY( equal(vec12.begin(), vec12.end(), vec04_ref.begin()) ); 151 VERIFY( vec11.get_allocator().get_personality() == personality02 ); 152 VERIFY( vec12.get_allocator().get_personality() == personality01 ); 153 154 my_vector vec13(vec03_ref.begin(), vec03_ref.end(), alloc01); 155 size01 = vec13.size(); 156 personality01 = vec13.get_allocator().get_personality(); 157 my_vector vec14(vec03_ref.begin(), vec03_ref.end(), alloc02); 158 size02 = vec14.size(); 159 personality02 = vec14.get_allocator().get_personality(); 160 161 vec13.swap(vec14); 162 VERIFY( vec13.size() == size02 ); 163 VERIFY( equal(vec13.begin(), vec13.end(), vec03_ref.begin()) ); 164 VERIFY( vec14.size() == size01 ); 165 VERIFY( equal(vec14.begin(), vec14.end(), vec03_ref.begin()) ); 166 VERIFY( vec13.get_allocator().get_personality() == personality02 ); 167 VERIFY( vec14.get_allocator().get_personality() == personality01 ); 168} 169 170int main() 171{ 172 test01(); 173 return 0; 174} 175