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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [23_containers/] [map/] [modifiers/] [swap/] [3.cc] - Blame information for rev 424

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 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
// 23.3.1 map::swap
21
 
22
#include <map>
23
#include <testsuite_hooks.h>
24
#include <testsuite_allocator.h>
25
 
26
// uneq_allocator, two different personalities.
27
void
28
test01()
29
{
30
  bool test __attribute__((unused)) = true;
31
  using namespace std;
32
 
33
  typedef pair<const char, int> my_pair;
34
  typedef __gnu_test::uneq_allocator<my_pair> my_alloc;
35
  typedef map<char, int, less<char>, my_alloc> my_map;
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
  map<char, int> map01_ref;
48
  for (size_t i = 0; i < N1; ++i)
49
    map01_ref.insert(my_pair(title01[i], i));
50
  map<char, int> map02_ref;
51
  for (size_t i = 0; i < N2; ++i)
52
    map02_ref.insert(my_pair(title02[i], i));
53
  map<char, int> map03_ref;
54
  for (size_t i = 0; i < N3; ++i)
55
    map03_ref.insert(my_pair(title03[i], i));
56
  map<char, int> map04_ref;
57
  for (size_t i = 0; i < N4; ++i)
58
    map04_ref.insert(my_pair(title04[i], i));
59
 
60
  my_map::size_type size01, size02;
61
 
62
  my_alloc alloc01(1), alloc02(2);
63
  int personality01, personality02;
64
 
65
  my_map map01(less<char>(), alloc01);
66
  size01 = map01.size();
67
  personality01 = map01.get_allocator().get_personality();
68
  my_map map02(less<char>(), alloc02);
69
  size02 = map02.size();
70
  personality02 = map02.get_allocator().get_personality();
71
 
72
  map01.swap(map02);
73
  VERIFY( map01.size() == size02 );
74
  VERIFY( map01.empty() );
75
  VERIFY( map02.size() == size01 );
76
  VERIFY( map02.empty() );
77
  VERIFY( map01.get_allocator().get_personality() == personality02 );
78
  VERIFY( map02.get_allocator().get_personality() == personality01 );
79
 
80
  my_map map03(less<char>(), alloc02);
81
  size01 = map03.size();
82
  personality01 = map03.get_allocator().get_personality();
83
  my_map map04(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01);
84
  size02 = map04.size();
85
  personality02 = map04.get_allocator().get_personality();
86
 
87
  map03.swap(map04);
88
  VERIFY( map03.size() == size02 );
89
  VERIFY( equal(map03.begin(), map03.end(), map02_ref.begin()) );
90
  VERIFY( map04.size() == size01 );
91
  VERIFY( map04.empty() );
92
  VERIFY( map03.get_allocator().get_personality() == personality02 );
93
  VERIFY( map04.get_allocator().get_personality() == personality01 );
94
 
95
  my_map map05(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01);
96
  size01 = map05.size();
97
  personality01 = map05.get_allocator().get_personality();
98
  my_map map06(map02_ref.begin(), map02_ref.end(), less<char>(), alloc02);
99
  size02 = map06.size();
100
  personality02 = map06.get_allocator().get_personality();
101
 
102
  map05.swap(map06);
103
  VERIFY( map05.size() == size02 );
104
  VERIFY( equal(map05.begin(), map05.end(), map02_ref.begin()) );
105
  VERIFY( map06.size() == size01 );
106
  VERIFY( equal(map06.begin(), map06.end(), map01_ref.begin()) );
107
  VERIFY( map05.get_allocator().get_personality() == personality02 );
108
  VERIFY( map06.get_allocator().get_personality() == personality01 );
109
 
110
  my_map map07(map01_ref.begin(), map01_ref.end(), less<char>(), alloc02);
111
  size01 = map07.size();
112
  personality01 = map07.get_allocator().get_personality();
113
  my_map map08(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01);
114
  size02 = map08.size();
115
  personality02 = map08.get_allocator().get_personality();
116
 
117
  map07.swap(map08);
118
  VERIFY( map07.size() == size02 );
119
  VERIFY( equal(map07.begin(), map07.end(), map03_ref.begin()) );
120
  VERIFY( map08.size() == size01 );
121
  VERIFY( equal(map08.begin(), map08.end(), map01_ref.begin()) );
122
  VERIFY( map07.get_allocator().get_personality() == personality02 );
123
  VERIFY( map08.get_allocator().get_personality() == personality01 );
124
 
125
  my_map map09(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01);
126
  size01 = map09.size();
127
  personality01 = map09.get_allocator().get_personality();
128
  my_map map10(map04_ref.begin(), map04_ref.end(), less<char>(), alloc02);
129
  size02 = map10.size();
130
  personality02 = map10.get_allocator().get_personality();
131
 
132
  map09.swap(map10);
133
  VERIFY( map09.size() == size02 );
134
  VERIFY( equal(map09.begin(), map09.end(), map04_ref.begin()) );
135
  VERIFY( map10.size() == size01 );
136
  VERIFY( equal(map10.begin(), map10.end(), map03_ref.begin()) );
137
  VERIFY( map09.get_allocator().get_personality() == personality02 );
138
  VERIFY( map10.get_allocator().get_personality() == personality01 );
139
 
140
  my_map map11(map04_ref.begin(), map04_ref.end(), less<char>(), alloc02);
141
  size01 = map11.size();
142
  personality01 = map11.get_allocator().get_personality();
143
  my_map map12(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01);
144
  size02 = map12.size();
145
  personality02 = map12.get_allocator().get_personality();
146
 
147
  map11.swap(map12);
148
  VERIFY( map11.size() == size02 );
149
  VERIFY( equal(map11.begin(), map11.end(), map01_ref.begin()) );
150
  VERIFY( map12.size() == size01 );
151
  VERIFY( equal(map12.begin(), map12.end(), map04_ref.begin()) );
152
  VERIFY( map11.get_allocator().get_personality() == personality02 );
153
  VERIFY( map12.get_allocator().get_personality() == personality01 );
154
 
155
  my_map map13(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01);
156
  size01 = map13.size();
157
  personality01 = map13.get_allocator().get_personality();
158
  my_map map14(map03_ref.begin(), map03_ref.end(), less<char>(), alloc02);
159
  size02 = map14.size();
160
  personality02 = map14.get_allocator().get_personality();
161
 
162
  map13.swap(map14);
163
  VERIFY( map13.size() == size02 );
164
  VERIFY( equal(map13.begin(), map13.end(), map03_ref.begin()) );
165
  VERIFY( map14.size() == size01 );
166
  VERIFY( equal(map14.begin(), map14.end(), map03_ref.begin()) );
167
  VERIFY( map13.get_allocator().get_personality() == personality02 );
168
  VERIFY( map14.get_allocator().get_personality() == personality01 );
169
}
170
 
171
int main()
172
{
173
  test01();
174
  return 0;
175
}

powered by: WebSVN 2.1.0

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