]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/21_strings/nonmember.cc
libstdc++-v3: New directory.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / nonmember.cc
CommitLineData
b2dad0e3
BK
1// 1998-10-01, 1999-06-25 bkoz
2
3// Copyright (C) 1998-1999 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 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>
114#ifdef DEBUG_ASSERT
115#include <assert.h>
116#endif
117
118int test01(void)
119{
120 bool test = true;
121 std::string str_0("costa rica");
122 std::string str_1("costa marbella");
123 std::string str_2("cost");
124 std::string str_3("costa ricans");
125 std::string str_4;
126
127 str_4 = str_0;
128 //comparisons between string objects
129 test &= !(str_0 == str_1);
130 test &= !(str_0 == str_2);
131 test &= !(str_0 == str_3);
132 test &= !(str_1 == str_0);
133 test &= !(str_2 == str_0);
134 test &= !(str_3 == str_0);
135 test &= str_4 == str_0;
136 test &= str_0 == str_4;
137
138 test &= str_0 != str_1;
139 test &= str_0 != str_2;
140 test &= str_0 != str_3;
141 test &= str_1 != str_0;
142 test &= str_2 != str_0;
143 test &= str_3 != str_0;
144 test &= !(str_0 != str_4);
145 test &= !(str_4 != str_0);
146
147 test &= str_0 > str_1; //true cuz r>m
148 test &= str_0 > str_2;
149 test &= !(str_0 > str_3);
150 test &= !(str_1 > str_0); //false cuz m<r
151 test &= !(str_2 > str_0);
152 test &= str_3 > str_0;
153 test &= !(str_0 > str_4);
154 test &= !(str_4 > str_0);
155
156 test &= !(str_0 < str_1); //false cuz r>m
157 test &= !(str_0 < str_2);
158 test &= str_0 < str_3;
159 test &= str_1 < str_0; //true cuz m<r
160 test &= str_2 < str_0;
161 test &= !(str_3 < str_0);
162 test &= !(str_0 < str_4);
163 test &= !(str_4 < str_0);
164
165 test &= str_0 >= str_1; //true cuz r>m
166 test &= str_0 >= str_2;
167 test &= !(str_0 >= str_3);
168 test &= !(str_1 >= str_0);//false cuz m<r
169 test &= !(str_2 >= str_0);
170 test &= str_3 >= str_0;
171 test &= str_0 >= str_4;
172 test &= str_4 >= str_0;
173
174 test &= !(str_0 <= str_1);//false cuz r>m
175 test &= !(str_0 <= str_2);
176 test &= str_0 <= str_3;
177 test &= str_1 <= str_0;//true cuz m<r
178 test &= str_2 <= str_0;
179 test &= !(str_3 <= str_0);
180 test &= str_0 <= str_4;
181 test &= str_4 <= str_0;
182
183 //comparisons between string object and string literal
184 test &= !(str_0 == "costa marbella");
185 test &= !(str_0 == "cost");
186 test &= !(str_0 == "costa ricans");
187 test &= !("costa marbella" == str_0);
188 test &= !("cost" == str_0);
189 test &= !("costa ricans" == str_0);
190 test &= "costa rica" == str_0;
191 test &= str_0 == "costa rica";
192
193 test &= str_0 != "costa marbella";
194 test &= str_0 != "cost";
195 test &= str_0 != "costa ricans";
196 test &= "costa marbella" != str_0;
197 test &= "cost" != str_0;
198 test &= "costa ricans" != str_0;
199 test &= !("costa rica" != str_0);
200 test &= !(str_0 != "costa rica");
201
202 test &= str_0 > "costa marbella"; //true cuz r>m
203 test &= str_0 > "cost";
204 test &= !(str_0 > "costa ricans");
205 test &= !("costa marbella" > str_0);//false cuz m<r
206 test &= !("cost" > str_0);
207 test &= "costa ricans" > str_0;
208 test &= !("costa rica" > str_0);
209 test &= !(str_0 > "costa rica");
210
211 test &= !(str_0 < "costa marbella");//false cuz r>m
212 test &= !(str_0 < "cost");
213 test &= str_0 < "costa ricans";
214 test &= "costa marbella" < str_0;//true cuz m<r
215 test &= "cost" < str_0;
216 test &= !("costa ricans" < str_0);
217 test &= !("costa rica" < str_0);
218 test &= !(str_0 < "costa rica");
219
220 test &= str_0 >= "costa marbella";//true cuz r>m
221 test &= str_0 >= "cost";
222 test &= !(str_0 >= "costa ricans");
223 test &= !("costa marbella" >= str_0);//false cuz m<r
224 test &= !("cost" >= str_0);
225 test &= "costa ricans" >= str_0;
226 test &= "costa rica" >= str_0;
227 test &= str_0 >= "costa rica";
228
229 test &= !(str_0 <= "costa marbella");//false cuz r>m
230 test &= !(str_0 <= "cost");
231 test &= str_0 <= "costa ricans";
232 test &= "costa marbella" <= str_0;//true cuz m<r
233 test &= "cost" <= str_0;
234 test &= !("costa ricans" <= str_0);
235 test &= "costa rica" <= str_0;
236 test &= str_0 <= "costa rica";
237
238 // 21.3.7.1 operator+
239/*
240template<class charT, class traits, class Allocator>
241 basic_string<charT,traits,Allocator>
242 operator+(const basic_string<charT,traits,Allocator>& lhs,
243 const basic_string<charT,traits,Allocator>& rhs);
244
245template<class charT, class traits, class Allocator>
246 basic_string<charT,traits,Allocator>
247 operator+(const charT* lhs,
248 const basic_string<charT,traits,Allocator>& rhs);
249
250template<class charT, class traits, class Allocator>
251 basic_string<charT,traits,Allocator>
252 operator+(const basic_string<charT,traits,Allocator>& lhs,
253 const charT* rhs);
254
255template<class charT, class traits, class Allocator>
256 basic_string<charT,traits,Allocator>
257 operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
258
259template<class charT, class traits, class Allocator>
260 basic_string<charT,traits,Allocator>
261 operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs);
262*/
263
264 str_4 = str_0 + "ns";
265 test &= str_4 == str_3;
266
267 const std::string str_5(" marbella");
268 str_4 = "costa" + str_5;
269 test &= str_4 == str_1;
270
271 std::string str_6("ns");
272 str_4 = str_0 + str_6;
273 test &= str_4 == str_3;
274
275 str_4 = str_0 + 'n';
276 str_4 = str_4 + 's';
277 test &= str_4 == str_3;
278
279 str_4 = 'a' + str_6;
280 str_4 = 'c' + str_4;
281 str_4 = 'i' + str_4;
282 str_4 = 'r' + str_4;
283 str_4 = ' ' + str_4;
284 str_4 = 'a' + str_4;
285 str_4 = 't' + str_4;
286 str_4 = 's' + str_4;
287 str_4 = 'o' + str_4;
288 str_4 = 'c' + str_4;
289 test &= str_4 == str_3;
290
291#ifdef DEBUG_ASSERT
292 assert(test);
293#endif
294
295 return 0;
296}
297
298int main() {
299 test01();
300}
301
302
303
304
305
306