]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/nonmember.cc
re PR c++/10091 ([parisc] ICE in cp_expr_size, at cp/cp-lang.c:307)
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / nonmember.cc
CommitLineData
b2dad0e3
BK
1// 1998-10-01, 1999-06-25 bkoz
2
aefb3380 3// Copyright (C) 1998, 1999 Free Software Foundation, Inc.
b2dad0e3
BK
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 2, 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 COPYING. If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
21// 21.3.7.1 basic_string non-member functions
22
23// 21.3.7.2 operator==
24/*
25template<class charT, class traits, class Allocator>
26 bool operator==(const basic_string<charT,traits,Allocator>& lhs,
27 const basic_string<charT,traits,Allocator>& rhs);
28
29template<class charT, class traits, class Allocator>
30 bool operator==(const charT* lhs,
31 const basic_string<charT,traits,Allocator>& rhs);
32
33template<class charT, class traits, class Allocator>
34 bool operator==(const basic_string<charT,traits,Allocator>& lhs,
35 const charT* rhs);
36*/
37
38// 21.3.7.3 operator!=
39/*
40template<class charT, class traits, class Allocator>
41 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
42 const basic_string<charT,traits,Allocator>& rhs);
43
44template<class charT, class traits, class Allocator>
45 bool operator!=(const charT* lhs,
46 const basic_string<charT,traits,Allocator>& rhs);
47
48template<class charT, class traits, class Allocator>
49 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
50 const charT* rhs);
51*/
52
53// 21.3.7.4 operator<
54/*
55template<class charT, class traits, class Allocator>
56 bool operator< (const basic_string<charT,traits,Allocator>& lhs,
57 const basic_string<charT,traits,Allocator>& rhs);
58
59template<class charT, class traits, class Allocator>
60 bool operator< (const basic_string<charT,traits,Allocator>& lhs,
61 const charT* rhs);
62
63template<class charT, class traits, class Allocator>
64 bool operator< (const charT* lhs,
65 const basic_string<charT,traits,Allocator>& rhs);
66*/
67
68// 21.3.7.5 operator>
69/*
70template<class charT, class traits, class Allocator>
71 bool operator> (const basic_string<charT,traits,Allocator>& lhs,
72 const basic_string<charT,traits,Allocator>& rhs);
73
74template<class charT, class traits, class Allocator>
75 bool operator> (const basic_string<charT,traits,Allocator>& lhs,
76 const charT* rhs);
77
78template<class charT, class traits, class Allocator>
79 bool operator> (const charT* lhs,
80 const basic_string<charT,traits,Allocator>& rhs);
81*/
82
83//21.3.7.6 operator<=
84/*
85template<class charT, class traits, class Allocator>
86 bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
87 const basic_string<charT,traits,Allocator>& rhs);
88
89template<class charT, class traits, class Allocator>
90 bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
91 const charT* rhs);
92
93template<class charT, class traits, class Allocator>
94 bool operator<=(const charT* lhs,
95 const basic_string<charT,traits,Allocator>& rhs);
96*/
97
98// 21.3.7.7 operator>=
99/*
100template<class charT, class traits, class Allocator>
101 bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
102 const basic_string<charT,traits,Allocator>& rhs);
103
104template<class charT, class traits, class Allocator>
105 bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
106 const charT* rhs);
107
108template<class charT, class traits, class Allocator>
109 bool operator>=(const charT* lhs,
110 const basic_string<charT,traits,Allocator>& rhs);
111*/
112
113#include <string>
fe413112 114#include <testsuite_hooks.h>
b2dad0e3
BK
115
116int test01(void)
117{
118 bool test = true;
119 std::string str_0("costa rica");
120 std::string str_1("costa marbella");
121 std::string str_2("cost");
122 std::string str_3("costa ricans");
123 std::string str_4;
124
125 str_4 = str_0;
126 //comparisons between string objects
aa1b2f7d
BV
127 VERIFY( !(str_0 == str_1) );
128 VERIFY( !(str_0 == str_2) );
129 VERIFY( !(str_0 == str_3) );
130 VERIFY( !(str_1 == str_0) );
131 VERIFY( !(str_2 == str_0) );
132 VERIFY( !(str_3 == str_0) );
133 VERIFY( str_4 == str_0 );
134 VERIFY( str_0 == str_4 );
135
136 VERIFY( str_0 != str_1 );
137 VERIFY( str_0 != str_2 );
138 VERIFY( str_0 != str_3 );
139 VERIFY( str_1 != str_0 );
140 VERIFY( str_2 != str_0 );
141 VERIFY( str_3 != str_0 );
142 VERIFY( !(str_0 != str_4) );
143 VERIFY( !(str_4 != str_0) );
b2dad0e3 144
aa1b2f7d
BV
145 VERIFY( str_0 > str_1 ); //true cuz r>m
146 VERIFY( str_0 > str_2 );
147 VERIFY( !(str_0 > str_3) );
148 VERIFY( !(str_1 > str_0) ); //false cuz m<r
149 VERIFY( !(str_2 > str_0) );
150 VERIFY( str_3 > str_0 );
151 VERIFY( !(str_0 > str_4) );
152 VERIFY( !(str_4 > str_0) );
153
154 VERIFY( !(str_0 < str_1) ); //false cuz r>m
155 VERIFY( !(str_0 < str_2) );
156 VERIFY( str_0 < str_3 );
157 VERIFY( str_1 < str_0 ); //true cuz m<r
158 VERIFY( str_2 < str_0 );
159 VERIFY( !(str_3 < str_0) );
160 VERIFY( !(str_0 < str_4) );
161 VERIFY( !(str_4 < str_0) );
162
163 VERIFY( str_0 >= str_1 ); //true cuz r>m
164 VERIFY( str_0 >= str_2 );
165 VERIFY( !(str_0 >= str_3) );
166 VERIFY( !(str_1 >= str_0) );//false cuz m<r
167 VERIFY( !(str_2 >= str_0) );
168 VERIFY( str_3 >= str_0 );
169 VERIFY( str_0 >= str_4 );
170 VERIFY( str_4 >= str_0 );
171
172 VERIFY( !(str_0 <= str_1) );//false cuz r>m
173 VERIFY( !(str_0 <= str_2) );
174 VERIFY( str_0 <= str_3 );
175 VERIFY( str_1 <= str_0 );//true cuz m<r
176 VERIFY( str_2 <= str_0 );
177 VERIFY( !(str_3 <= str_0) );
178 VERIFY( str_0 <= str_4 );
179 VERIFY( str_4 <= str_0 );
b2dad0e3
BK
180
181 //comparisons between string object and string literal
aa1b2f7d
BV
182 VERIFY( !(str_0 == "costa marbella") );
183 VERIFY( !(str_0 == "cost") );
184 VERIFY( !(str_0 == "costa ricans") );
185 VERIFY( !("costa marbella" == str_0) );
186 VERIFY( !("cost" == str_0) );
187 VERIFY( !("costa ricans" == str_0) );
188 VERIFY( "costa rica" == str_0 );
189 VERIFY( str_0 == "costa rica" );
190
191 VERIFY( str_0 != "costa marbella" );
192 VERIFY( str_0 != "cost" );
193 VERIFY( str_0 != "costa ricans" );
194 VERIFY( "costa marbella" != str_0 );
195 VERIFY( "cost" != str_0 );
196 VERIFY( "costa ricans" != str_0 );
197 VERIFY( !("costa rica" != str_0) );
198 VERIFY( !(str_0 != "costa rica") );
199
200 VERIFY( str_0 > "costa marbella" ); //true cuz r>m
201 VERIFY( str_0 > "cost" );
202 VERIFY( !(str_0 > "costa ricans") );
203 VERIFY( !("costa marbella" > str_0) );//false cuz m<r
204 VERIFY( !("cost" > str_0) );
205 VERIFY( "costa ricans" > str_0 );
206 VERIFY( !("costa rica" > str_0) );
207 VERIFY( !(str_0 > "costa rica") );
208
209 VERIFY( !(str_0 < "costa marbella") );//false cuz r>m
210 VERIFY( !(str_0 < "cost") );
211 VERIFY( str_0 < "costa ricans" );
212 VERIFY( "costa marbella" < str_0 );//true cuz m<r
213 VERIFY( "cost" < str_0 );
214 VERIFY( !("costa ricans" < str_0) );
215 VERIFY( !("costa rica" < str_0) );
216 VERIFY( !(str_0 < "costa rica") );
217
218 VERIFY( str_0 >= "costa marbella" );//true cuz r>m
219 VERIFY( str_0 >= "cost" );
220 VERIFY( !(str_0 >= "costa ricans") );
221 VERIFY( !("costa marbella" >= str_0) );//false cuz m<r
222 VERIFY( !("cost" >= str_0) );
223 VERIFY( "costa ricans" >= str_0 );
224 VERIFY( "costa rica" >= str_0 );
225 VERIFY( str_0 >= "costa rica" );
226
227 VERIFY( !(str_0 <= "costa marbella") );//false cuz r>m
228 VERIFY( !(str_0 <= "cost") );
229 VERIFY( str_0 <= "costa ricans" );
230 VERIFY( "costa marbella" <= str_0 );//true cuz m<r
231 VERIFY( "cost" <= str_0 );
232 VERIFY( !("costa ricans" <= str_0) );
233 VERIFY( "costa rica" <= str_0 );
234 VERIFY( str_0 <= "costa rica" );
b2dad0e3
BK
235
236 // 21.3.7.1 operator+
237/*
238template<class charT, class traits, class Allocator>
239 basic_string<charT,traits,Allocator>
240 operator+(const basic_string<charT,traits,Allocator>& lhs,
241 const basic_string<charT,traits,Allocator>& rhs);
242
243template<class charT, class traits, class Allocator>
244 basic_string<charT,traits,Allocator>
245 operator+(const charT* lhs,
246 const basic_string<charT,traits,Allocator>& rhs);
247
248template<class charT, class traits, class Allocator>
249 basic_string<charT,traits,Allocator>
250 operator+(const basic_string<charT,traits,Allocator>& lhs,
251 const charT* rhs);
252
253template<class charT, class traits, class Allocator>
254 basic_string<charT,traits,Allocator>
255 operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
256
257template<class charT, class traits, class Allocator>
258 basic_string<charT,traits,Allocator>
259 operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs);
260*/
261
262 str_4 = str_0 + "ns";
aa1b2f7d 263 VERIFY( str_4 == str_3 );
b2dad0e3
BK
264
265 const std::string str_5(" marbella");
266 str_4 = "costa" + str_5;
aa1b2f7d 267 VERIFY( str_4 == str_1 );
b2dad0e3
BK
268
269 std::string str_6("ns");
270 str_4 = str_0 + str_6;
aa1b2f7d 271 VERIFY( str_4 == str_3 );
b2dad0e3
BK
272
273 str_4 = str_0 + 'n';
274 str_4 = str_4 + 's';
aa1b2f7d 275 VERIFY( str_4 == str_3 );
b2dad0e3
BK
276
277 str_4 = 'a' + str_6;
278 str_4 = 'c' + str_4;
279 str_4 = 'i' + str_4;
280 str_4 = 'r' + str_4;
281 str_4 = ' ' + str_4;
282 str_4 = 'a' + str_4;
283 str_4 = 't' + str_4;
284 str_4 = 's' + str_4;
285 str_4 = 'o' + str_4;
286 str_4 = 'c' + str_4;
aa1b2f7d 287 VERIFY( str_4 == str_3 );
b2dad0e3
BK
288
289#ifdef DEBUG_ASSERT
290 assert(test);
291#endif
292
293 return 0;
294}
295
04d930e6
BK
296int main()
297{
b2dad0e3 298 test01();
04d930e6 299 return 0;
b2dad0e3 300}