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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [23_containers/] [set/] [modifiers/] [swap/] [2.cc] - Blame information for rev 816

Go to most recent revision | 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.3 set::swap
21
 
22
#include <set>
23
#include <testsuite_hooks.h>
24
#include <testsuite_allocator.h>
25
 
26
// uneq_allocator as a non-empty allocator.
27
void
28
test01()
29
{
30
  bool test __attribute__((unused)) = true;
31
  using namespace std;
32
 
33
  typedef __gnu_test::uneq_allocator<char> my_alloc;
34
  typedef set<char, less<char>, my_alloc> my_set;
35
 
36
  const char title01[] = "Rivers of sand";
37
  const char title02[] = "Concret PH";
38
  const char title03[] = "Sonatas and Interludes for Prepared Piano";
39
  const char title04[] = "never as tired as when i'm waking up";
40
 
41
  const size_t N1 = sizeof(title01);
42
  const size_t N2 = sizeof(title02);
43
  const size_t N3 = sizeof(title03);
44
  const size_t N4 = sizeof(title04);
45
 
46
  const set<char> set01_ref(title01, title01 + N1);
47
  const set<char> set02_ref(title02, title02 + N2);
48
  const set<char> set03_ref(title03, title03 + N3);
49
  const set<char> set04_ref(title04, title04 + N4);
50
 
51
  my_set::size_type size01, size02;
52
 
53
  my_alloc alloc01(1);
54
 
55
  my_set set01(less<char>(), alloc01);
56
  size01 = set01.size();
57
  my_set set02(less<char>(), alloc01);
58
  size02 = set02.size();
59
 
60
  set01.swap(set02);
61
  VERIFY( set01.size() == size02 );
62
  VERIFY( set01.empty() );
63
  VERIFY( set02.size() == size01 );
64
  VERIFY( set02.empty() );
65
 
66
  my_set set03(less<char>(), alloc01);
67
  size01 = set03.size();
68
  my_set set04(title02, title02 + N2, less<char>(), alloc01);
69
  size02 = set04.size();
70
 
71
  set03.swap(set04);
72
  VERIFY( set03.size() == size02 );
73
  VERIFY( equal(set03.begin(), set03.end(), set02_ref.begin()) );
74
  VERIFY( set04.size() == size01 );
75
  VERIFY( set04.empty() );
76
 
77
  my_set set05(title01, title01 + N1, less<char>(), alloc01);
78
  size01 = set05.size();
79
  my_set set06(title02, title02 + N2, less<char>(), alloc01);
80
  size02 = set06.size();
81
 
82
  set05.swap(set06);
83
  VERIFY( set05.size() == size02 );
84
  VERIFY( equal(set05.begin(), set05.end(), set02_ref.begin()) );
85
  VERIFY( set06.size() == size01 );
86
  VERIFY( equal(set06.begin(), set06.end(), set01_ref.begin()) );
87
 
88
  my_set set07(title01, title01 + N1, less<char>(), alloc01);
89
  size01 = set07.size();
90
  my_set set08(title03, title03 + N3, less<char>(), alloc01);
91
  size02 = set08.size();
92
 
93
  set07.swap(set08);
94
  VERIFY( set07.size() == size02 );
95
  VERIFY( equal(set07.begin(), set07.end(), set03_ref.begin()) );
96
  VERIFY( set08.size() == size01 );
97
  VERIFY( equal(set08.begin(), set08.end(), set01_ref.begin()) );
98
 
99
  my_set set09(title03, title03 + N3, less<char>(), alloc01);
100
  size01 = set09.size();
101
  my_set set10(title04, title04 + N4, less<char>(), alloc01);
102
  size02 = set10.size();
103
 
104
  set09.swap(set10);
105
  VERIFY( set09.size() == size02 );
106
  VERIFY( equal(set09.begin(), set09.end(), set04_ref.begin()) );
107
  VERIFY( set10.size() == size01 );
108
  VERIFY( equal(set10.begin(), set10.end(), set03_ref.begin()) );
109
 
110
  my_set set11(title04, title04 + N4, less<char>(), alloc01);
111
  size01 = set11.size();
112
  my_set set12(title01, title01 + N1, less<char>(), alloc01);
113
  size02 = set12.size();
114
 
115
  set11.swap(set12);
116
  VERIFY( set11.size() == size02 );
117
  VERIFY( equal(set11.begin(), set11.end(), set01_ref.begin()) );
118
  VERIFY( set12.size() == size01 );
119
  VERIFY( equal(set12.begin(), set12.end(), set04_ref.begin()) );
120
 
121
  my_set set13(title03, title03 + N3, less<char>(), alloc01);
122
  size01 = set13.size();
123
  my_set set14(title03, title03 + N3, less<char>(), alloc01);
124
  size02 = set14.size();
125
 
126
  set13.swap(set14);
127
  VERIFY( set13.size() == size02 );
128
  VERIFY( equal(set13.begin(), set13.end(), set03_ref.begin()) );
129
  VERIFY( set14.size() == size01 );
130
  VERIFY( equal(set14.begin(), set14.end(), set03_ref.begin()) );
131
}
132
 
133
int main()
134
{
135
  test01();
136
  return 0;
137
}

powered by: WebSVN 2.1.0

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