1// 2005-12-20  Paolo Carlini  <pcarlini@suse.de>
2
3// Copyright (C) 2005, 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// 6.3.4.5 unordered_multiset::swap
21
22#include <tr1/unordered_set>
23#include <set>
24#include <testsuite_hooks.h>
25#include <testsuite_allocator.h>
26
27// uneq_allocator as a non-empty allocator.
28void
29test01()
30{
31  bool test __attribute__((unused)) = true;
32  using namespace std::tr1;
33  using std::equal_to;
34  using std::multiset;
35
36  typedef __gnu_test::uneq_allocator<char> my_alloc;
37  typedef unordered_multiset<char, hash<char>, equal_to<char>, my_alloc>
38    my_umset;
39
40  const char title01[] = "Rivers of sand";
41  const char title02[] = "Concret PH";
42  const char title03[] = "Sonatas and Interludes for Prepared Piano";
43  const char title04[] = "never as tired as when i'm waking up";
44
45  const size_t N1 = sizeof(title01);
46  const size_t N2 = sizeof(title02);
47  const size_t N3 = sizeof(title03);
48  const size_t N4 = sizeof(title04);
49
50  typedef multiset<char> my_mset;
51  const my_mset mset01_ref(title01, title01 + N1);
52  const my_mset mset02_ref(title02, title02 + N2);
53  const my_mset mset03_ref(title03, title03 + N3);
54  const my_mset mset04_ref(title04, title04 + N4);
55
56  my_umset::size_type size01, size02;
57
58  my_alloc alloc01(1);
59
60  my_umset umset01(10, hash<char>(), equal_to<char>(), alloc01);
61  size01 = umset01.size();
62  my_umset umset02(10, hash<char>(), equal_to<char>(), alloc01);
63  size02 = umset02.size();
64
65  umset01.swap(umset02);
66  VERIFY( umset01.size() == size02 );
67  VERIFY( umset01.empty() );
68  VERIFY( umset02.size() == size01 );
69  VERIFY( umset02.empty() );
70
71  my_umset umset03(10, hash<char>(), equal_to<char>(), alloc01);
72  size01 = umset03.size();
73  my_umset umset04(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(),
74		   equal_to<char>(), alloc01);
75  size02 = umset04.size();
76
77  umset03.swap(umset04);
78  VERIFY( umset03.size() == size02 );
79  VERIFY( my_mset(umset03.begin(), umset03.end()) == mset02_ref );
80  VERIFY( umset04.size() == size01 );
81  VERIFY( umset04.empty() );
82
83  my_umset umset05(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
84		   equal_to<char>(), alloc01);
85  size01 = umset05.size();
86  my_umset umset06(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(),
87		   equal_to<char>(), alloc01);
88  size02 = umset06.size();
89
90  umset05.swap(umset06);
91  VERIFY( umset05.size() == size02 );
92  VERIFY( my_mset(umset05.begin(), umset05.end()) == mset02_ref );
93  VERIFY( umset06.size() == size01 );
94  VERIFY( my_mset(umset06.begin(), umset06.end()) == mset01_ref );
95
96  my_umset umset07(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
97		   equal_to<char>(), alloc01);
98  size01 = umset07.size();
99  my_umset umset08(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
100		   equal_to<char>(), alloc01);
101  size02 = umset08.size();
102
103  umset07.swap(umset08);
104  VERIFY( umset07.size() == size02 );
105  VERIFY( my_mset(umset07.begin(), umset07.end()) == mset03_ref );
106  VERIFY( umset08.size() == size01 );
107  VERIFY( my_mset(umset08.begin(), umset08.end()) == mset01_ref );
108
109  my_umset umset09(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
110		   equal_to<char>(), alloc01);
111  size01 = umset09.size();
112  my_umset umset10(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(),
113		   equal_to<char>(), alloc01);
114  size02 = umset10.size();
115
116  umset09.swap(umset10);
117  VERIFY( umset09.size() == size02 );
118  VERIFY( my_mset(umset09.begin(), umset09.end()) == mset04_ref );
119  VERIFY( umset10.size() == size01 );
120  VERIFY( my_mset(umset10.begin(), umset10.end()) == mset03_ref );
121
122  my_umset umset11(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(),
123		   equal_to<char>(), alloc01);
124  size01 = umset11.size();
125  my_umset umset12(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
126		   equal_to<char>(), alloc01);
127  size02 = umset12.size();
128
129  umset11.swap(umset12);
130  VERIFY( umset11.size() == size02 );
131  VERIFY( my_mset(umset11.begin(), umset11.end()) == mset01_ref );
132  VERIFY( umset12.size() == size01 );
133  VERIFY( my_mset(umset12.begin(), umset12.end()) == mset04_ref );
134
135  my_umset umset13(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
136		   equal_to<char>(), alloc01);
137  size01 = umset13.size();
138  my_umset umset14(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
139		   equal_to<char>(), alloc01);
140  size02 = umset14.size();
141
142  umset13.swap(umset14);
143  VERIFY( umset13.size() == size02 );
144  VERIFY( my_mset(umset13.begin(), umset13.end()) == mset03_ref );
145  VERIFY( umset14.size() == size01 );
146  VERIFY( my_mset(umset14.begin(), umset14.end()) == mset03_ref );
147}
148
149int main()
150{
151  test01();
152  return 0;
153}
154