]>
Commit | Line | Data |
---|---|---|
f7ace77f PC |
1 | // 2005-12-20 Paolo Carlini <pcarlini@suse.de> |
2 | ||
3 | // Copyright (C) 2005 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 2, 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 COPYING. If not, write to the Free | |
18 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
19 | // USA. | |
20 | ||
21 | // 23.3.4 multiset::swap | |
22 | ||
23 | #include <set> | |
24 | #include <testsuite_hooks.h> | |
25 | #include <testsuite_allocator.h> | |
26 | ||
27 | // uneq_allocator as a non-empty allocator. | |
28 | void | |
29 | test01() | |
30 | { | |
31 | bool test __attribute__((unused)) = true; | |
32 | using namespace std; | |
33 | ||
34 | typedef __gnu_test::uneq_allocator<char> my_alloc; | |
35 | typedef multiset<char, less<char>, my_alloc> my_multiset; | |
36 | ||
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"; | |
41 | ||
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); | |
46 | ||
47 | const multiset<char> mset01_ref(title01, title01 + N1); | |
48 | const multiset<char> mset02_ref(title02, title02 + N2); | |
49 | const multiset<char> mset03_ref(title03, title03 + N3); | |
50 | const multiset<char> mset04_ref(title04, title04 + N4); | |
51 | ||
52 | my_multiset::size_type size01, size02; | |
53 | ||
54 | my_alloc alloc01(1); | |
55 | ||
56 | my_multiset mset01(less<char>(), alloc01); | |
57 | size01 = mset01.size(); | |
58 | my_multiset mset02(less<char>(), alloc01); | |
59 | size02 = mset02.size(); | |
60 | ||
61 | mset01.swap(mset02); | |
62 | VERIFY( mset01.size() == size02 ); | |
63 | VERIFY( mset01.empty() ); | |
64 | VERIFY( mset02.size() == size01 ); | |
65 | VERIFY( mset02.empty() ); | |
66 | ||
67 | my_multiset mset03(less<char>(), alloc01); | |
68 | size01 = mset03.size(); | |
69 | my_multiset mset04(title02, title02 + N2, less<char>(), alloc01); | |
70 | size02 = mset04.size(); | |
71 | ||
72 | mset03.swap(mset04); | |
73 | VERIFY( mset03.size() == size02 ); | |
74 | VERIFY( equal(mset03.begin(), mset03.end(), mset02_ref.begin()) ); | |
75 | VERIFY( mset04.size() == size01 ); | |
76 | VERIFY( mset04.empty() ); | |
77 | ||
78 | my_multiset mset05(title01, title01 + N1, less<char>(), alloc01); | |
79 | size01 = mset05.size(); | |
80 | my_multiset mset06(title02, title02 + N2, less<char>(), alloc01); | |
81 | size02 = mset06.size(); | |
82 | ||
83 | mset05.swap(mset06); | |
84 | VERIFY( mset05.size() == size02 ); | |
85 | VERIFY( equal(mset05.begin(), mset05.end(), mset02_ref.begin()) ); | |
86 | VERIFY( mset06.size() == size01 ); | |
87 | VERIFY( equal(mset06.begin(), mset06.end(), mset01_ref.begin()) ); | |
88 | ||
89 | my_multiset mset07(title01, title01 + N1, less<char>(), alloc01); | |
90 | size01 = mset07.size(); | |
91 | my_multiset mset08(title03, title03 + N3, less<char>(), alloc01); | |
92 | size02 = mset08.size(); | |
93 | ||
94 | mset07.swap(mset08); | |
95 | VERIFY( mset07.size() == size02 ); | |
96 | VERIFY( equal(mset07.begin(), mset07.end(), mset03_ref.begin()) ); | |
97 | VERIFY( mset08.size() == size01 ); | |
98 | VERIFY( equal(mset08.begin(), mset08.end(), mset01_ref.begin()) ); | |
99 | ||
100 | my_multiset mset09(title03, title03 + N3, less<char>(), alloc01); | |
101 | size01 = mset09.size(); | |
102 | my_multiset mset10(title04, title04 + N4, less<char>(), alloc01); | |
103 | size02 = mset10.size(); | |
104 | ||
105 | mset09.swap(mset10); | |
106 | VERIFY( mset09.size() == size02 ); | |
107 | VERIFY( equal(mset09.begin(), mset09.end(), mset04_ref.begin()) ); | |
108 | VERIFY( mset10.size() == size01 ); | |
109 | VERIFY( equal(mset10.begin(), mset10.end(), mset03_ref.begin()) ); | |
110 | ||
111 | my_multiset mset11(title04, title04 + N4, less<char>(), alloc01); | |
112 | size01 = mset11.size(); | |
113 | my_multiset mset12(title01, title01 + N1, less<char>(), alloc01); | |
114 | size02 = mset12.size(); | |
115 | ||
116 | mset11.swap(mset12); | |
117 | VERIFY( mset11.size() == size02 ); | |
118 | VERIFY( equal(mset11.begin(), mset11.end(), mset01_ref.begin()) ); | |
119 | VERIFY( mset12.size() == size01 ); | |
120 | VERIFY( equal(mset12.begin(), mset12.end(), mset04_ref.begin()) ); | |
121 | ||
122 | my_multiset mset13(title03, title03 + N3, less<char>(), alloc01); | |
123 | size01 = mset13.size(); | |
124 | my_multiset mset14(title03, title03 + N3, less<char>(), alloc01); | |
125 | size02 = mset14.size(); | |
126 | ||
127 | mset13.swap(mset14); | |
128 | VERIFY( mset13.size() == size02 ); | |
129 | VERIFY( equal(mset13.begin(), mset13.end(), mset03_ref.begin()) ); | |
130 | VERIFY( mset14.size() == size01 ); | |
131 | VERIFY( equal(mset14.begin(), mset14.end(), mset03_ref.begin()) ); | |
132 | } | |
133 | ||
134 | int main() | |
135 | { | |
136 | test01(); | |
137 | return 0; | |
138 | } |