VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/tests/windows/nsStringTest2.h@ 8234

Last change on this file since 8234 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1/********************************************************************************************
2 *
3 * MODULES NOTES:
4 *
5 * This file is designed to help test the new nsString classes.
6 *
7 * Contributor(s):
8 * Rick Gessner <rickg@netscape.com>
9 *
10 * History:
11 *
12 * 02.29.2000: Original files (rickg)
13 * 03.02.2000: Flesh out the interface to be compatible with old library (rickg)
14 *
15 ********************************************************************************************/
16
17#ifndef _STRINGTEST2
18#define _STRINGTEST2
19
20
21#include "nsString.h"
22#include <time.h>
23
24#define USE_STL
25
26#ifdef USE_STL
27#include <string>
28using namespace std;
29#endif
30
31#define USE_WIDE 1
32#ifdef USE_WIDE
33 #define stringtype nsString
34 #define astringtype nsAutoString
35 #define chartype PRUnichar
36#else
37 #define stringtype nsCString
38 #define astringtype nsCAutoString
39 #define chartype char
40#endif
41
42#include <stdio.h>
43const double gTicks = 1.0e-7;
44
45
46
47
48
49/********************************************************
50
51 This class's only purpose in life is to test the
52 netscape string library. We exercise the string
53 API's here, and do a bit of performance testing
54 against the standard c++ library string (from STL).
55
56 ********************************************************/
57class CStringTester {
58
59public:
60
61 int TestI18nString();
62
63};
64
65
66
67
68//test 1: unicode char is stripped correctly using StripChars()
69void nsStringTest1(){
70 PRUnichar test[]={0x0041,0x0051,0x0052,0x0000};
71 nsString T(test);
72 PRUnichar result[]={0x0051,0x0052,0x0000};
73 nsString R(result);
74 T.StripChars("ABC");
75 NS_ASSERTION(T.Equals(R), "Test 1: Unicode comparison error");
76}
77//test 2: unicode char is not matched and stripped when high-order byte is not 0x00
78void nsStringTest2(){
79 PRUnichar test[]={0x4e41,0x4e51,0x4e52,0x4e53,0x0000};
80 nsAutoString T(test);
81 PRUnichar result[]={0x4e41,0x4e51,0x4e52,0x4e53,0x0000};
82 nsAutoString R(result);
83 T.StripChars("ABC");
84 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
85}
86 //test 3: unicode char is not matched and stripped when high-order byte is 0xFF
87void nsStringTest3(){
88
89 PRUnichar test[] = {0xFF41,0x4e51,0x4e52,0x4e53,0x0000};
90 nsAutoString T(test);
91 PRUnichar result[] = {0xFF41,0x4e51,0x4e52,0x4e53,0x0000};
92 nsAutoString R(test);
93 T.StripChars("ABC");
94 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
95}
96void nsStringTest4(){
97 //test 4: unicode char is matched and stripped correctly using StripChar()
98 PRUnichar test[] = {0x0041,0x0051,0x0052,0x0000};
99 nsAutoString T(test);
100 PRUnichar result[] = {0x0051,0x0052,0x0000};
101 nsAutoString R(result);
102 T.StripChar('A');
103 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
104}
105void nsStringTest5(){
106 //test 5: unicode char is not matched and stripped when high-order byte is not 0x00
107
108 PRUnichar test[]={0x4e41,0x4e51,0x4e52,0x4e53,0x0000};
109 nsAutoString T(test);
110 PRUnichar result[]={0x4e41,0x4e51,0x4e52,0x4e53,0x0000};
111 nsAutoString R(result);
112 T.StripChar('A');
113 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
114}
115void nsStringTest6(){
116 //test 6: unicode char is not matched and stripped when high-order byte is 0xFF
117
118 PRUnichar test[] = {0xFF41,0x4e51,0x4e52,0x4e53,0x0000};
119 nsAutoString T(test);
120 PRUnichar result[] = {0xFF41,0x4e51,0x4e52,0x4e53,0x0000};
121 nsAutoString R(result);
122 T.StripChar('A');
123 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
124}
125void nsStringTest7(){
126 //test 7: unicode char is matched and replaced correctly using ReplaceChar()
127
128 PRUnichar test[] = {0x0041,0x0051,0x0052,0x0000};
129 nsAutoString T(test);
130 PRUnichar result[] = {0x0050,0x0051,0x0052,0x0000};
131 nsAutoString R(result);
132 T.ReplaceChar('A',0x50);
133 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
134}
135void nsStringTest8(){
136 //test 8: unicode char is not matched or replaced when high-order byte != 0x00
137
138 PRUnichar test[] = {0x4e41,0x4e51,0x4e52,0x4e53,0x0000};
139 nsAutoString T(test);
140 PRUnichar result[] = {0x4e41,0x4e51,0x4e52,0x4e53,0x0000};
141 nsAutoString R(result);
142 T.ReplaceChar('A',0x50);
143 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
144}
145void nsStringTest9(){
146 //test 9: unicode char is not matched or replaced when high-order byte matches search char
147
148 PRUnichar test[] = {0x4150,0x4e51,0x4e52,0x4e53,0x0000};
149 nsAutoString T(test);
150 PRUnichar result[] = {0x4150,0x4e51,0x4e52,0x4e53,0x0000};
151 nsAutoString R(result);
152 T.ReplaceChar('A',0x50);
153 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
154}
155void nsStringTest10(){
156 //test 10: unicode char is not matched or replaced when high-order byte == 0xFF
157
158 PRUnichar test[] = {0xFFc1,0x4e51,0x4e52,0x4e53,0x0000};
159 nsAutoString T(test);
160 PRUnichar result[] = {0xFFc1,0x4e51,0x4e52,0x4e53,0x0000};
161 nsAutoString R(result);
162 T.ReplaceChar('A',0x50);
163 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
164}
165
166void nsStringTest11(){
167 //test 11: unicode char is correctly replaced when parameter 1 is a string
168
169 PRUnichar test[] = {0x0041,0x0051,0x0052,0x0000};
170 nsAutoString T(test);
171 PRUnichar result[] = {0x0050,0x0051,0x0052,0x0000};
172 nsAutoString R(result);
173 T.ReplaceChar("ABC",0x50);
174 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
175}
176void nsStringTest12(){
177 //test 12: unicode char is not replaced when high-order byte != 0x00
178
179 PRUnichar test[] = {0x4e41,0x0051,0x0052,0x0000};
180 nsAutoString T(test);
181 PRUnichar result[] = {0x4e41,0x0051,0x0052,0x0000};
182 nsAutoString R(result);
183 T.ReplaceChar("ABC",0x50);
184 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
185
186}
187void nsStringTest13(){
188 //test 13: unicode char is not replaced when high-order byte matches char in search string
189 PRUnichar test[] = {0x4150,0x4e51,0x4e52,0x4e53,0x0000};
190 nsAutoString T(test);
191 PRUnichar result[] = {0x4150,0x4e51,0x4e52,0x4e53,0x0000};
192 nsAutoString R(result);
193 T.ReplaceChar("ABC",'T');
194 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
195
196}
197void nsStringTest14(){
198 PRUnichar test[] = {0xFFc2,0x4e51,0x4e52,0x4e53,0x0000};
199 nsAutoString T(test);
200 PRUnichar result[] = {0xFFc2,0x4e51,0x4e52,0x4e53,0x0000};
201 nsAutoString R(result);
202 T.ReplaceChar("ABC",'T');
203 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
204}
205void nsStringTest15(){
206 PRUnichar test[] = {0xFFc2,0x4e51,0x4e52,0x4e53,0x0000};
207 nsAutoString T(test);
208 PRUnichar result[] = {0xFFc2,0x4e51,0x4e52,0x4e53,0x0000};
209 nsAutoString R(result);
210 PRUnichar s = 0xc2; //compiler error on this line
211 T.ReplaceChar(s,'T');
212 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
213}
214
215void nsStringTest16(){
216 /* TESTS for ReplaceSubstring()*/
217
218 PRUnichar test[] = {0x0041,0x0042,0x0043,0x0044,0x0045,0x0000};
219 nsAutoString T(test);
220 PRUnichar result[] = {0x0044,0x0045,0x0046,0x0044,0x0045};
221 nsAutoString R(result);
222 T.ReplaceSubstring("ABC","DEF");
223 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
224
225}
226void nsStringTest17(){
227
228 PRUnichar test[] = {0x0041,0x4e42,0x0043,0x0044,0x0045,0x0000};
229 nsAutoString T(test);
230 PRUnichar result[] = {0x0041,0x4e42,0x0043,0x0044,0x0045,0x0000};
231 nsAutoString R(result);
232 T.ReplaceSubstring("ABC","DEF");
233 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
234}
235void nsStringTest18(){
236 /*TESTS for Trim()*/
237
238 PRUnichar test[] = {0x0041,0x4e51,0x4e52,0x4e53,0x0000};
239 nsAutoString T(test);
240 PRUnichar result[] = {0x4e51,0x4e52,0x4e53,0x0000};
241 nsAutoString R (result);
242 T.Trim("ABC");
243 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
244}
245void nsStringTest19(){
246 PRUnichar test[] = {0x4e41,0x4e51,0x4e52,0x4e53,0x0000};
247 nsAutoString T(test);
248 PRUnichar result[] = {0x4e41,0x4e51,0x4e52,0x4e53,0x0000};
249 nsAutoString R(result);
250 T.Trim("ABC");
251 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
252}
253void nsStringTest22(){
254 PRUnichar test[] = {0x4e51,0x4e52,0x4e53,0x4e41,0x0000};
255 nsAutoString T(test);
256 PRUnichar result[] = {0x4e51,0x4e52,0x4e53,0x4e41,0x0000};
257 nsAutoString R(result);
258 T.Trim("ABC");
259 NS_ASSERTION(T.Equals(R), "Unicode comparison error");
260
261}
262//void nsStringTest23(){
263// PRUnichar test[] = {0x4e51,0x4e52,0x4e53,0x4e22,0x0000};
264// nsAutoString T(test);
265// PRUnichar s(0x4e22);
266// PRUnichar result[] = {0x4e51,0x4e52,0x4e53,0x0000};
267// nsAutoString R(result);
268// T.Trim(s,PR_TRUE,PR_TRUE,PR_FALSE);
269// NS_ASSERTION(T.Equals(R), "Unicode comparison error");
270//}
271void nsStringTest24(){
272 /*TESTS for Find()*/
273 PRUnichar test[] = {0x0041,0x0042,0x0043,0x0051,0x0052,0x0000};
274 nsAutoString T(test);
275 NS_ASSERTION(T.Find("ABC") == 0, "Unicode comparison error");
276
277}
278void nsStringTest25(){
279 PRUnichar test[] = {0x4e41,0x4e42,0x4e43,0x4e53,0x0000};
280 nsAutoString T(test);
281 NS_ASSERTION(T.Find("ABC") == -1, "Unicode comparison error");
282
283}
284void nsStringTest26(){
285 PRUnichar test[] = {0xFFc1,0x0051,0x0052,0x0053,0x0000};
286 nsAutoString T(test);
287 PRUnichar str[] = {0xc1,0x51,0x52};
288 nsAutoString S(str);
289 NS_ASSERTION(T.Find(S) == -1, "Unicode comparison error");
290}
291void nsStringTest27(){
292 /*TESTS for FindChar()*/
293
294 PRUnichar test[] = {0x0041,0x0051,0x0052,0x0000};
295 nsAutoString T(test);
296 NS_ASSERTION(T.FindChar('A') == 0, "Unicode comparison error");
297}
298void nsStringTest28(){
299 PRUnichar test[] = {0x4e41,0x4e42,0x4e43,0x4e53,0x0000};
300 nsAutoString T(test);
301 NS_ASSERTION(T.FindChar('A') == -1, "Unicode comparison error");
302}
303void nsStringTest29(){
304 PRUnichar test[] = {0xFFc1,0x4e51,0x4e52,0x4e53,0x0000};
305 nsAutoString T(test);
306 NS_ASSERTION(T.FindChar(0xc1) == -1, "Unicode comparison error");
307
308}
309void nsStringTest30(){
310 PRUnichar test[] = {0x4132,0x0051,0x0052,0x0000};
311 nsAutoString T(test);
312 NS_ASSERTION(T.FindChar('A1') == -1, "Unicode comparison error");
313}
314 /*TESTS for FindCharInSet()*/
315void nsStringTest31(){
316 PRUnichar test[] = {0x0041,0x0051,0x0052,0x0000};
317 nsAutoString T(test);
318 NS_ASSERTION(T.FindCharInSet("ABC") == 0, "Unicode comparison error");
319}
320void nsStringTest32(){
321 PRUnichar test[] = {0x4e41,0x4e42,0x4e43,0x4e53,0x0000};
322 nsAutoString T(test);
323 NS_ASSERTION(T.FindCharInSet("ABC") == -1, "Unicode comparison error");
324
325}
326void nsStringTest33(){
327 PRUnichar test[] = {0xFFc1,0x4e51,0x4e52,0x4e53,0x0000};
328 nsAutoString T(test);
329 PRUnichar str[] = {0xc1,0x51,0x52};
330 nsAutoString s(str);
331 NS_ASSERTION(T.FindCharInSet(s) == -1, "Unicode comparison error");
332}
333void nsStringTest34(){
334 PRUnichar test[] = {0x4132,0x5132,0x5232,0x0000};
335 nsAutoString T(test);
336 NS_ASSERTION(T.FindCharInSet("ABC") == -1, "Unicode comparison error");
337}
338 /*TESTS for RFind()*/
339void nsStringTest35(){
340
341 PRUnichar test[] = {0x0051,0x0052,0x0041,0x0042,0x0043,0x0000};
342 nsAutoString T(test);
343 NS_ASSERTION(T.RFind("ABC") == 2, "Unicode comparison error");
344}
345void nsStringTest36(){
346 PRUnichar test[] = {0x4e41,0x4e42,0x4e43,0x4e53,0x0000};
347 nsAutoString T(test);
348 NS_ASSERTION(T.RFind("ABC") == -1, "Unicode comparison error");
349}
350void nsStringTest37(){
351 PRUnichar test[] = {0xFFc1,0xFFc2,0xFFc3,0x4e53,0x0000};
352 nsAutoString T(test);
353 PRUnichar str[] = {0xc1,0xc2,0xc3};
354 nsAutoString s(str);
355 NS_ASSERTION(T.RFind(s) == -1, "Unicode comparison error");
356}
357 /*TESTS for RFindCharInSet*/
358void nsStringTest38(){
359
360 PRUnichar test[] = {0x0041,0x0042,0x0043,0x0000};
361 nsAutoString T(test);
362 int res = T.RFindCharInSet("ABC");
363 NS_ASSERTION(res==0, "Unicode comparison error");
364}
365void nsStringTest39(){
366 PRUnichar test[] = {0x4e41,0x4e42,0x4e43,0x4e53,0x0000};
367 nsAutoString T(test);
368 NS_ASSERTION(T.RFindCharInSet("ABC") == -1, "Unicode comparison error");
369}
370void nsStringTest40(){
371 PRUnichar test[] = {0xFFc1,0x4e51,0x4e52,0x4e53,0x0000};
372 nsAutoString T(test);
373 PRUnichar str[] = {0xc1,0xc2,0xc3};
374 nsAutoString s(str);
375 NS_ASSERTION(T.RFindCharInSet(s) == -1, "Unicode comparison error");
376}
377void nsStringTest41(){
378 PRUnichar test[] = {0x4132,0x0051,0x0052,0x0000};
379 nsAutoString T(test);
380 NS_ASSERTION(T.RFindCharInSet("ABC") == -1, "Unicode comparison error");
381}
382 /* TESTS for Compare() */
383void nsStringTest42(){
384 PRUnichar test[] = {0x0041,0x0042,0x0043,0x0000};
385 nsAutoString T(test);
386 NS_ASSERTION(T.Compare("ABC") == 0, "Unicode comparison error");
387}
388void nsStringTest43(){
389 PRUnichar test[] = {0xc341,0xc342,0xc343};
390 nsAutoString T(test);
391 NS_ASSERTION(T.Compare("ABC") == 1, "Unicode comparison error");
392}
393
394
395int CStringTester::TestI18nString(){
396 nsStringTest1();
397 nsStringTest2();
398 nsStringTest3();
399 nsStringTest4();
400 nsStringTest5();
401 nsStringTest6();
402 nsStringTest7();
403 nsStringTest8();
404 nsStringTest9();
405 nsStringTest10();
406 nsStringTest11();
407 nsStringTest12();
408 nsStringTest13();
409 nsStringTest14();
410 nsStringTest15();
411 nsStringTest16();
412 nsStringTest17();
413 nsStringTest18();
414 nsStringTest19();
415 //nsStringTest20();
416 //nsStringTest21();
417 nsStringTest22();
418 //nsStringTest23();
419 nsStringTest24();
420 nsStringTest25();
421 nsStringTest26();
422 nsStringTest27();
423 nsStringTest28();
424 nsStringTest29();
425 nsStringTest30();
426 nsStringTest31();
427 nsStringTest32();
428 nsStringTest33();
429 nsStringTest34();
430 nsStringTest35();
431 nsStringTest36();
432 nsStringTest37();
433 nsStringTest38();
434 nsStringTest39();
435 nsStringTest40();
436 nsStringTest41();
437 nsStringTest42();
438 nsStringTest43();
439
440 return 0;
441}
442
443#endif
444
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette