1// 2007-02-22  Paolo Carlini  <pcarlini@suse.de>
2//
3// Copyright (C) 2007, 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  Class template unordered_multiset
21
22#include <tr1/unordered_set>
23#include <string>
24#include <testsuite_hooks.h>
25
26// In the occasion of libstdc++/25896
27void test01()
28{
29  bool test __attribute__((unused)) = true;
30
31  typedef std::tr1::unordered_multiset<std::string> Mset;
32  typedef Mset::iterator       iterator;
33  typedef Mset::const_iterator const_iterator;
34
35  Mset ms1;
36
37  ms1.insert("because to why");
38  ms1.insert("the stockholm syndrome");
39  ms1.insert("a cereous night");
40  ms1.insert("eeilo");
41  ms1.insert("protean");
42  ms1.insert("the way you are when");
43  ms1.insert("tillsammans");
44  ms1.insert("umbra/penumbra");
45  ms1.insert("belonging (no longer mix)");
46  ms1.insert("one line behind");
47  VERIFY( ms1.size() == 10 );
48
49  VERIFY( ms1.erase("eeilo") == 1 );
50  VERIFY( ms1.size() == 9 );
51  iterator it1 = ms1.find("eeilo");
52  VERIFY( it1 == ms1.end() );
53
54  VERIFY( ms1.erase("tillsammans") == 1 );
55  VERIFY( ms1.size() == 8 );
56  iterator it2 = ms1.find("tillsammans");
57  VERIFY( it2 == ms1.end() );
58
59  // Must work (see DR 526)
60  iterator it3 = ms1.find("belonging (no longer mix)");
61  VERIFY( it3 != ms1.end() );
62  VERIFY( ms1.erase(*it3) == 1 );
63  VERIFY( ms1.size() == 7 );
64  it3 = ms1.find("belonging (no longer mix)");
65  VERIFY( it3 == ms1.end() );
66
67  VERIFY( !ms1.erase("abra") );
68  VERIFY( ms1.size() == 7 );
69
70  VERIFY( !ms1.erase("eeilo") );
71  VERIFY( ms1.size() == 7 );
72
73  VERIFY( ms1.erase("because to why") == 1 );
74  VERIFY( ms1.size() == 6 );
75  iterator it4 = ms1.find("because to why");
76  VERIFY( it4 == ms1.end() );
77
78  iterator it5 = ms1.find("umbra/penumbra");
79  iterator it6 = ms1.find("one line behind");
80  VERIFY( it5 != ms1.end() );
81  VERIFY( it6 != ms1.end() );
82
83  VERIFY( ms1.find("the stockholm syndrome") != ms1.end() );
84  VERIFY( ms1.find("a cereous night") != ms1.end() );
85  VERIFY( ms1.find("the way you are when") != ms1.end() );
86  VERIFY( ms1.find("a cereous night") != ms1.end() );
87
88  VERIFY( ms1.erase(*it5) == 1 );
89  VERIFY( ms1.size() == 5 );
90  it5 = ms1.find("umbra/penumbra");
91  VERIFY( it5 == ms1.end() );
92
93  VERIFY( ms1.erase(*it6) == 1 );
94  VERIFY( ms1.size() == 4 );
95  it6 = ms1.find("one line behind");
96  VERIFY( it6 == ms1.end() );
97
98  iterator it7 = ms1.begin();
99  iterator it8 = it7;
100  ++it8;
101  iterator it9 = it8;
102  ++it9;
103
104  VERIFY( ms1.erase(*it8) == 1 );
105  VERIFY( ms1.size() == 3 );
106  VERIFY( ++it7 == it9 );
107
108  iterator it10 = it9;
109  ++it10;
110  iterator it11 = it10;
111
112  VERIFY( ms1.erase(*it9) == 1 );
113  VERIFY( ms1.size() == 2 );
114  VERIFY( ++it10 == ms1.end() );
115
116  VERIFY( ms1.erase(ms1.begin()) != ms1.end() );
117  VERIFY( ms1.size() == 1 );
118  VERIFY( ms1.begin() == it11 );
119
120  VERIFY( ms1.erase(*ms1.begin()) == 1 );
121  VERIFY( ms1.size() == 0 );
122  VERIFY( ms1.begin() == ms1.end() );
123}
124
125int main()
126{
127  test01();
128  return 0;
129}
130