OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [tr1/] [6_containers/] [unordered_multiset/] [swap/] [2.cc] - Blame information for rev 742

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// 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, two different personalities.
28
void
29
test01()
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), alloc02(2);
59
  int personality01, personality02;
60
 
61
  my_umset umset01(10, hash<char>(), equal_to<char>(), alloc01);
62
  size01 = umset01.size();
63
  personality01 = umset01.get_allocator().get_personality();
64
  my_umset umset02(10, hash<char>(), equal_to<char>(), alloc02);
65
  size02 = umset02.size();
66
  personality02 = umset02.get_allocator().get_personality();
67
 
68
  umset01.swap(umset02);
69
  VERIFY( umset01.size() == size02 );
70
  VERIFY( umset01.empty() );
71
  VERIFY( umset02.size() == size01 );
72
  VERIFY( umset02.empty() );
73
  VERIFY( umset01.get_allocator().get_personality() == personality02 );
74
  VERIFY( umset02.get_allocator().get_personality() == personality01 );
75
 
76
  my_umset umset03(10, hash<char>(), equal_to<char>(), alloc02);
77
  size01 = umset03.size();
78
  personality01 = umset03.get_allocator().get_personality();
79
  my_umset umset04(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(),
80
                   equal_to<char>(), alloc01);
81
  size02 = umset04.size();
82
  personality02 = umset04.get_allocator().get_personality();
83
 
84
  umset03.swap(umset04);
85
  VERIFY( umset03.size() == size02 );
86
  VERIFY( my_mset(umset03.begin(), umset03.end()) == mset02_ref );
87
  VERIFY( umset04.size() == size01 );
88
  VERIFY( umset04.empty() );
89
  VERIFY( umset03.get_allocator().get_personality() == personality02 );
90
  VERIFY( umset04.get_allocator().get_personality() == personality01 );
91
 
92
  my_umset umset05(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
93
                   equal_to<char>(), alloc01);
94
  size01 = umset05.size();
95
  personality01 = umset05.get_allocator().get_personality();
96
  my_umset umset06(mset02_ref.begin(), mset02_ref.end(), 10, hash<char>(),
97
                   equal_to<char>(), alloc02);
98
  size02 = umset06.size();
99
  personality02 = umset06.get_allocator().get_personality();
100
 
101
  umset05.swap(umset06);
102
  VERIFY( umset05.size() == size02 );
103
  VERIFY( my_mset(umset05.begin(), umset05.end()) == mset02_ref );
104
  VERIFY( umset06.size() == size01 );
105
  VERIFY( my_mset(umset06.begin(), umset06.end()) == mset01_ref );
106
  VERIFY( umset05.get_allocator().get_personality() == personality02 );
107
  VERIFY( umset06.get_allocator().get_personality() == personality01 );
108
 
109
  my_umset umset07(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
110
                   equal_to<char>(), alloc02);
111
  size01 = umset07.size();
112
  personality01 = umset07.get_allocator().get_personality();
113
  my_umset umset08(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
114
                   equal_to<char>(), alloc01);
115
  size02 = umset08.size();
116
  personality02 = umset08.get_allocator().get_personality();
117
 
118
  umset07.swap(umset08);
119
  VERIFY( umset07.size() == size02 );
120
  VERIFY( my_mset(umset07.begin(), umset07.end()) == mset03_ref );
121
  VERIFY( umset08.size() == size01 );
122
  VERIFY( my_mset(umset08.begin(), umset08.end()) == mset01_ref );
123
  VERIFY( umset07.get_allocator().get_personality() == personality02 );
124
  VERIFY( umset08.get_allocator().get_personality() == personality01 );
125
 
126
  my_umset umset09(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
127
                   equal_to<char>(), alloc01);
128
  size01 = umset09.size();
129
  personality01 = umset09.get_allocator().get_personality();
130
  my_umset umset10(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(),
131
                   equal_to<char>(), alloc02);
132
  size02 = umset10.size();
133
  personality02 = umset10.get_allocator().get_personality();
134
 
135
  umset09.swap(umset10);
136
  VERIFY( umset09.size() == size02 );
137
  VERIFY( my_mset(umset09.begin(), umset09.end()) == mset04_ref );
138
  VERIFY( umset10.size() == size01 );
139
  VERIFY( my_mset(umset10.begin(), umset10.end()) == mset03_ref );
140
  VERIFY( umset09.get_allocator().get_personality() == personality02 );
141
  VERIFY( umset10.get_allocator().get_personality() == personality01 );
142
 
143
  my_umset umset11(mset04_ref.begin(), mset04_ref.end(), 10, hash<char>(),
144
                   equal_to<char>(), alloc02);
145
  size01 = umset11.size();
146
  personality01 = umset11.get_allocator().get_personality();
147
  my_umset umset12(mset01_ref.begin(), mset01_ref.end(), 10, hash<char>(),
148
                   equal_to<char>(), alloc01);
149
  size02 = umset12.size();
150
  personality02 = umset12.get_allocator().get_personality();
151
 
152
  umset11.swap(umset12);
153
  VERIFY( umset11.size() == size02 );
154
  VERIFY( my_mset(umset11.begin(), umset11.end()) == mset01_ref );
155
  VERIFY( umset12.size() == size01 );
156
  VERIFY( my_mset(umset12.begin(), umset12.end()) == mset04_ref );
157
  VERIFY( umset11.get_allocator().get_personality() == personality02 );
158
  VERIFY( umset12.get_allocator().get_personality() == personality01 );
159
 
160
  my_umset umset13(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
161
                   equal_to<char>(), alloc01);
162
  size01 = umset13.size();
163
  personality01 = umset13.get_allocator().get_personality();
164
  my_umset umset14(mset03_ref.begin(), mset03_ref.end(), 10, hash<char>(),
165
                   equal_to<char>(), alloc02);
166
  size02 = umset14.size();
167
  personality02 = umset14.get_allocator().get_personality();
168
 
169
  umset13.swap(umset14);
170
  VERIFY( umset13.size() == size02 );
171
  VERIFY( my_mset(umset13.begin(), umset13.end()) == mset03_ref );
172
  VERIFY( umset14.size() == size01 );
173
  VERIFY( my_mset(umset14.begin(), umset14.end()) == mset03_ref );
174
  VERIFY( umset13.get_allocator().get_personality() == personality02 );
175
  VERIFY( umset14.get_allocator().get_personality() == personality01 );
176
}
177
 
178
int main()
179
{
180
  test01();
181
  return 0;
182
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.