1 // 1998-10-01, 1999-06-25 bkoz
3 // Copyright (C) 1998, 1999, 2003 Free Software Foundation, Inc.
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)
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.
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,
21 // 21.3.7.1 basic_string non-member functions
23 // 21.3.7.2 operator==
25 template<class charT, class traits, class Allocator>
26 bool operator==(const basic_string<charT,traits,Allocator>& lhs,
27 const basic_string<charT,traits,Allocator>& rhs);
29 template<class charT, class traits, class Allocator>
30 bool operator==(const charT* lhs,
31 const basic_string<charT,traits,Allocator>& rhs);
33 template<class charT, class traits, class Allocator>
34 bool operator==(const basic_string<charT,traits,Allocator>& lhs,
38 // 21.3.7.3 operator!=
40 template<class charT, class traits, class Allocator>
41 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
42 const basic_string<charT,traits,Allocator>& rhs);
44 template<class charT, class traits, class Allocator>
45 bool operator!=(const charT* lhs,
46 const basic_string<charT,traits,Allocator>& rhs);
48 template<class charT, class traits, class Allocator>
49 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
55 template<class charT, class traits, class Allocator>
56 bool operator< (const basic_string<charT,traits,Allocator>& lhs,
57 const basic_string<charT,traits,Allocator>& rhs);
59 template<class charT, class traits, class Allocator>
60 bool operator< (const basic_string<charT,traits,Allocator>& lhs,
63 template<class charT, class traits, class Allocator>
64 bool operator< (const charT* lhs,
65 const basic_string<charT,traits,Allocator>& rhs);
70 template<class charT, class traits, class Allocator>
71 bool operator> (const basic_string<charT,traits,Allocator>& lhs,
72 const basic_string<charT,traits,Allocator>& rhs);
74 template<class charT, class traits, class Allocator>
75 bool operator> (const basic_string<charT,traits,Allocator>& lhs,
78 template<class charT, class traits, class Allocator>
79 bool operator> (const charT* lhs,
80 const basic_string<charT,traits,Allocator>& rhs);
85 template<class charT, class traits, class Allocator>
86 bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
87 const basic_string<charT,traits,Allocator>& rhs);
89 template<class charT, class traits, class Allocator>
90 bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
93 template<class charT, class traits, class Allocator>
94 bool operator<=(const charT* lhs,
95 const basic_string<charT,traits,Allocator>& rhs);
98 // 21.3.7.7 operator>=
100 template<class charT, class traits, class Allocator>
101 bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
102 const basic_string<charT,traits,Allocator>& rhs);
104 template<class charT, class traits, class Allocator>
105 bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
108 template<class charT, class traits, class Allocator>
109 bool operator>=(const charT* lhs,
110 const basic_string<charT,traits,Allocator>& rhs);
114 #include <testsuite_hooks.h>
119 std::wstring str_0(L"costa rica");
120 std::wstring str_1(L"costa marbella");
121 std::wstring str_2(L"cost");
122 std::wstring str_3(L"costa ricans");
126 //comparisons between string objects
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 );
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) );
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) );
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) );
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 );
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 );
181 //comparisons between string object and string literal
182 VERIFY( !(str_0 == L"costa marbella") );
183 VERIFY( !(str_0 == L"cost") );
184 VERIFY( !(str_0 == L"costa ricans") );
185 VERIFY( !(L"costa marbella" == str_0) );
186 VERIFY( !(L"cost" == str_0) );
187 VERIFY( !(L"costa ricans" == str_0) );
188 VERIFY( L"costa rica" == str_0 );
189 VERIFY( str_0 == L"costa rica" );
191 VERIFY( str_0 != L"costa marbella" );
192 VERIFY( str_0 != L"cost" );
193 VERIFY( str_0 != L"costa ricans" );
194 VERIFY( L"costa marbella" != str_0 );
195 VERIFY( L"cost" != str_0 );
196 VERIFY( L"costa ricans" != str_0 );
197 VERIFY( !(L"costa rica" != str_0) );
198 VERIFY( !(str_0 != L"costa rica") );
200 VERIFY( str_0 > L"costa marbella" ); //true cuz r>m
201 VERIFY( str_0 > L"cost" );
202 VERIFY( !(str_0 > L"costa ricans") );
203 VERIFY( !(L"costa marbella" > str_0) );//false cuz m<r
204 VERIFY( !(L"cost" > str_0) );
205 VERIFY( L"costa ricans" > str_0 );
206 VERIFY( !(L"costa rica" > str_0) );
207 VERIFY( !(str_0 > L"costa rica") );
209 VERIFY( !(str_0 < L"costa marbella") );//false cuz r>m
210 VERIFY( !(str_0 < L"cost") );
211 VERIFY( str_0 < L"costa ricans" );
212 VERIFY( L"costa marbella" < str_0 );//true cuz m<r
213 VERIFY( L"cost" < str_0 );
214 VERIFY( !(L"costa ricans" < str_0) );
215 VERIFY( !(L"costa rica" < str_0) );
216 VERIFY( !(str_0 < L"costa rica") );
218 VERIFY( str_0 >= L"costa marbella" );//true cuz r>m
219 VERIFY( str_0 >= L"cost" );
220 VERIFY( !(str_0 >= L"costa ricans") );
221 VERIFY( !(L"costa marbella" >= str_0) );//false cuz m<r
222 VERIFY( !(L"cost" >= str_0) );
223 VERIFY( L"costa ricans" >= str_0 );
224 VERIFY( L"costa rica" >= str_0 );
225 VERIFY( str_0 >= L"costa rica" );
227 VERIFY( !(str_0 <= L"costa marbella") );//false cuz r>m
228 VERIFY( !(str_0 <= L"cost") );
229 VERIFY( str_0 <= L"costa ricans" );
230 VERIFY( L"costa marbella" <= str_0 );//true cuz m<r
231 VERIFY( L"cost" <= str_0 );
232 VERIFY( !(L"costa ricans" <= str_0) );
233 VERIFY( L"costa rica" <= str_0 );
234 VERIFY( str_0 <= L"costa rica" );
236 // 21.3.7.1 operator+
238 template<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);
243 template<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);
248 template<class charT, class traits, class Allocator>
249 basic_string<charT,traits,Allocator>
250 operator+(const basic_string<charT,traits,Allocator>& lhs,
253 template<class charT, class traits, class Allocator>
254 basic_string<charT,traits,Allocator>
255 operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
257 template<class charT, class traits, class Allocator>
258 basic_string<charT,traits,Allocator>
259 operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs);
262 str_4 = str_0 + L"ns";
263 VERIFY( str_4 == str_3 );
265 const std::wstring str_5(L" marbella");
266 str_4 = L"costa" + str_5;
267 VERIFY( str_4 == str_1 );
269 std::wstring str_6(L"ns");
270 str_4 = str_0 + str_6;
271 VERIFY( str_4 == str_3 );
273 str_4 = str_0 + L'n';
274 str_4 = str_4 + L's';
275 VERIFY( str_4 == str_3 );
277 str_4 = L'a' + str_6;
278 str_4 = L'c' + str_4;
279 str_4 = L'i' + str_4;
280 str_4 = L'r' + str_4;
281 str_4 = L' ' + str_4;
282 str_4 = L'a' + str_4;
283 str_4 = L't' + str_4;
284 str_4 = L's' + str_4;
285 str_4 = L'o' + str_4;
286 str_4 = L'c' + str_4;
287 VERIFY( str_4 == str_3 );