|
1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test\buffer\t_buf.cpp |
|
15 // Overview: |
|
16 // Test methods of the TBuf16, TBuf8, TBuf template class. |
|
17 // API Information: |
|
18 // TBuf16, TBuf8, TBuf. |
|
19 // Details : |
|
20 // - Create some 16 bit modifiable descriptors, 8 bit modifiable descriptors |
|
21 // of fixed length, Build-independent modifiable descriptors, initialize |
|
22 // with different strings and check for |
|
23 // - Comparison operators, |
|
24 // - Property access methods, |
|
25 // - Fill & swap methods, |
|
26 // - Conversion methods, |
|
27 // - Comparison methods, |
|
28 // - Pattern Matching methods, |
|
29 // - Pattern Locating methods, |
|
30 // - Copying methods, |
|
31 // - Find, FindC, FindF methods, |
|
32 // - Repeat, Trim, TrimLeft, TrimRight, Insert, Delete, Left, |
|
33 // Right, Mid methods, |
|
34 // - Formatting methods, |
|
35 // - Replace methods are as expected. |
|
36 // - Construct some descriptors with buffer length, string and buffer reference and |
|
37 // verify that they are created successfully. |
|
38 // - Test assignment operators and comparison operators for different descriptors. |
|
39 // - Initialize some descriptors and check descriptors' maximum length, length and |
|
40 // size are as expected. |
|
41 // - Check Fill and Swap methods are as expected. |
|
42 // - Test Fold, Collate, LowerCase, UpperCase methods are as expected. |
|
43 // - Test Comparison methods are as expected. |
|
44 // - Test pattern matching for simple string, wild cards with collated comparison. Verify that the |
|
45 // return value is KErrNotFound when pattern doesn't match. |
|
46 // - Check Locating methods by searching character in forward and backward direction and |
|
47 // verify the return value is KErrNotFound when unavailable character is searched. |
|
48 // - Check copying strings and converting those into lower and upper case strings are |
|
49 // as expected. |
|
50 // - Check Find methods by searching string and verify the return value is KErrNotFound when |
|
51 // unavailable string is searched. |
|
52 // - Check Repeat, Trim, Insert and Delete methods are as expected. |
|
53 // - Check the formatting operations are as expected. |
|
54 // - Check integer to decimal character representation is as expected. |
|
55 // - Check integer to character representation with different number system is as expected. |
|
56 // - Check string formatting with variable parameter list is as expected |
|
57 // - Check Replace method by replacing string at different places in a string is as expected. |
|
58 // - Check the conversion of real numbers, extended precision real numbers into string |
|
59 // format is as expected. |
|
60 // - Check Format and FormatList methods are as expected. |
|
61 // - Check Format of TReal is as expected. |
|
62 // - Check the non-leaving and leaving descriptors overflow handlers are as expected. |
|
63 // Platforms/Drives/Compatibility: |
|
64 // All |
|
65 // Assumptions/Requirement/Pre-requisites: |
|
66 // Failures and causes: |
|
67 // Base Port information: |
|
68 // |
|
69 // |
|
70 |
|
71 #include <e32test.h> |
|
72 #include <e32math.h> |
|
73 #include <hal.h> |
|
74 #include <hal_data.h> |
|
75 #include <hal_data.h> |
|
76 #include <e32svr.h> |
|
77 |
|
78 #ifdef __TOOLS2__ |
|
79 EXPORT_C TInt HAL::Set(HAL::TAttribute aAttribute, TInt aValue) |
|
80 { |
|
81 return KErrNone; |
|
82 } |
|
83 |
|
84 EXPORT_C TInt UserSvr::ChangeLocale(const TDesC& aLocaleDllName) |
|
85 { |
|
86 if (aLocaleDllName.Length() == 0) |
|
87 return KErrNone; |
|
88 return KErrNotFound; |
|
89 } |
|
90 #endif |
|
91 |
|
92 #ifdef __VC32__ |
|
93 // Solve compilation problem caused by non-English locale |
|
94 #pragma setlocale("english") |
|
95 #endif |
|
96 |
|
97 LOCAL_D RTest test(_L("T_BUF")); |
|
98 |
|
99 #pragma warning(disable: 4127) // disabling warning "conditional expression is constant" |
|
100 #pragma warning(disable: 4310) // disabling warning "cast truncates constant value" |
|
101 |
|
102 #undef _TL |
|
103 #define _TL(a) DESTEMPLATE((S*)RTest::String(sizeof(S),(TText8*)a,(TText16*)L ## a)) |
|
104 #undef _TS |
|
105 #define _TS(a) ((const S*)RTest::String(sizeof(S),(TText8*)a,(TText16*)L ## a)) |
|
106 |
|
107 template<class T,class S,class DESTEMPLATE> |
|
108 class TestTBuf |
|
109 { |
|
110 public: |
|
111 TestTBuf(TInt aLength); // Test class constructor. |
|
112 void Test1(); // Tests all functions of the class. |
|
113 void Test2(); // Tests all constructors. |
|
114 void Test3(); // Tests all assignment operators |
|
115 void Test4(); // Tests all comparison operators |
|
116 void Test5(); // Tests all property access |
|
117 void Test6(); // Tests all fill and swap |
|
118 void Test7(); // Tests all conversion |
|
119 void Test8(); // Tests all comparison |
|
120 void Test9(); // Tests all matching |
|
121 void Test10(); // Tests all locating |
|
122 void Test11(); // Tests all Copying |
|
123 void Test12(); // Tests all finding |
|
124 void Test13(); // Tests all basic like ops |
|
125 void Test14(); // Tests all formating |
|
126 void Test15(); // Tests all replacing |
|
127 void test_TBuf(); // Test all classes |
|
128 protected: |
|
129 void Test1List(T* a,T* b,...); |
|
130 void Test14_ReorderedParameterFormatting(TInt aDummyParameter, ...); |
|
131 private: |
|
132 TInt iMaxBufLength; |
|
133 }; |
|
134 |
|
135 void TestEq(const TDesC8& a, const TDesC8& b, TInt aLine) |
|
136 { |
|
137 if (a!=b) |
|
138 { |
|
139 TBuf<256> buf; |
|
140 test.Printf(_L("LINE %d:\n"),aLine); |
|
141 buf.Copy(a); |
|
142 test.Printf(_L("a=%S\n"),&buf); |
|
143 buf.Copy(b); |
|
144 test.Printf(_L("b=%S\n"),&buf); |
|
145 test(0); |
|
146 } |
|
147 } |
|
148 |
|
149 void TestEq(const TDesC16& a, const TDesC16& b, TInt aLine) |
|
150 { |
|
151 if (a!=b) |
|
152 { |
|
153 test.Printf(_L("LINE %d:\n"),aLine); |
|
154 test.Printf(_L("a=%S\n"),&a); |
|
155 test.Printf(_L("b=%S\n"),&b); |
|
156 test(0); |
|
157 } |
|
158 } |
|
159 |
|
160 #define TESTEQ(a,b) TestEq((a),(b),__LINE__) |
|
161 |
|
162 template <class T,class S,class DESTEMPLATE> |
|
163 GLDEF_C TestTBuf<T,S,DESTEMPLATE>::TestTBuf(TInt aLength) |
|
164 // Constructor. |
|
165 : iMaxBufLength(aLength) |
|
166 {} |
|
167 |
|
168 template <class T,class S,class DESTEMPLATE> |
|
169 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test1List(T* a,T* b,...) |
|
170 // Test the format with list functions. |
|
171 { |
|
172 VA_LIST list; |
|
173 VA_START(list,b); |
|
174 a->Format(*b,list); |
|
175 VA_START(list,b); |
|
176 a->AppendFormat(*b,list); |
|
177 VA_START(list,b); |
|
178 a->Format(_TL("%d"),list); |
|
179 VA_START(list,b); |
|
180 a->AppendFormat(_TL("%d"),list); |
|
181 } |
|
182 |
|
183 template <class T,class S,class DESTEMPLATE> |
|
184 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test1() |
|
185 // Tests all functions of the class. |
|
186 { |
|
187 test.Start(_L("Constructors")); |
|
188 T a; |
|
189 T b; |
|
190 T c(_TL("AB")); |
|
191 T d(c); |
|
192 |
|
193 // To avoid unused warning |
|
194 a.Length(); |
|
195 b.Length(); |
|
196 c.Length(); |
|
197 d.Length(); |
|
198 |
|
199 test.Next(_L("Copy operators")); |
|
200 a=_TL("DE"); |
|
201 b=c; |
|
202 a+=_TL("DE"); |
|
203 b+=c; |
|
204 |
|
205 test.Next(_L("Comparison operators")); |
|
206 TInt t=(a<b); |
|
207 t=(a<_TL("AB")); |
|
208 t=(_TL("AB")<a); |
|
209 t=(a<=b); |
|
210 t=(a<=_TL("AB")); |
|
211 t=(_TL("AB")<=a); |
|
212 t=(a>b); |
|
213 t=(a>_TL("AB")); |
|
214 t=(_TL("AB")>a); |
|
215 t=(a>=b); |
|
216 t=(a>=_TL("AB")); |
|
217 t=(_TL("AB")>=a); |
|
218 t=(a==b); |
|
219 t=(a==_TL("AB")); |
|
220 t=(_TL("AB")==a); |
|
221 t=(a!=_TL("AB")); |
|
222 t=(_TL("AB")!=a); |
|
223 |
|
224 test.Next(_L("Property access")); |
|
225 a[0]='A'; |
|
226 a.Ptr(); |
|
227 TInt i=a.MaxLength()-a.Length(); |
|
228 i=a.Size(); |
|
229 a.Zero(); |
|
230 a.SetLength(2); |
|
231 |
|
232 test.Next(_L("Fill & swap")); |
|
233 a.Fill(' '); |
|
234 a.Fill(' ',iMaxBufLength); |
|
235 a.FillZ(); |
|
236 a.FillZ(iMaxBufLength); |
|
237 a.Swap(b); |
|
238 |
|
239 test.Next(_L("Conversion")); |
|
240 a.Fold(); |
|
241 a.Collate(); |
|
242 a.LowerCase(); |
|
243 a.UpperCase(); |
|
244 a.Capitalize(); |
|
245 |
|
246 test.Next(_L("Comparison")); |
|
247 a.Compare(b); |
|
248 a.Compare(_TL("AB")); |
|
249 a.CompareF(b); |
|
250 a.CompareF(_TL("AB")); |
|
251 a.CompareC(b); |
|
252 a.CompareC(_TL("AB")); |
|
253 |
|
254 test.Next(_L("Matching")); |
|
255 a.Match(b); |
|
256 a.Match(_TL("AB")); |
|
257 a.MatchF(b); |
|
258 a.MatchF(_TL("AB")); |
|
259 |
|
260 T buf(_TL("abcdef")); |
|
261 TInt res = buf.MatchF(_TL("abc*def")); |
|
262 test(res == 0); |
|
263 |
|
264 a.MatchC(b); |
|
265 a.MatchC(_TL("AB")); |
|
266 |
|
267 test.Next(_L("Locating")); |
|
268 a.Locate('A'); |
|
269 a.LocateF('A'); |
|
270 a.LocateReverse('A'); |
|
271 a.LocateReverseF('A'); |
|
272 |
|
273 test.Next(_L("Copying")); |
|
274 a.Copy(b); |
|
275 a.Copy(_TL("AB")); |
|
276 // a.Copy(_TL("AB"),1); |
|
277 a.CopyF(b); |
|
278 a.CopyF(_TL("AB")); |
|
279 a.CopyC(b); |
|
280 a.CopyC(_TL("AB")); |
|
281 a.CopyLC(b); |
|
282 a.CopyLC(_TL("AB")); |
|
283 a.CopyUC(b); |
|
284 a.CopyUC(_TL("AB")); |
|
285 a.CopyCP(b); |
|
286 a.CopyCP(_TL("AB")); |
|
287 |
|
288 test.Next(_L("Finding")); |
|
289 a.Find(b); |
|
290 a.Find(_TL("AB")); |
|
291 a.FindF(b); |
|
292 a.FindF(_TL("AB")); |
|
293 a.FindC(b); |
|
294 a.FindC(_TL("AB")); |
|
295 |
|
296 test.Next(_L("Basic like ops")); |
|
297 a.Repeat(b); |
|
298 a.Repeat(_TL("AB")); |
|
299 a.TrimLeft(); |
|
300 a.TrimRight(); |
|
301 a.Trim(); |
|
302 b=_TL("AA"); |
|
303 a.Insert(0,b); |
|
304 a.Delete(0,2); |
|
305 b = a.Left(1); |
|
306 b = a.Right(1); |
|
307 b = a.Mid(0,1); |
|
308 |
|
309 test.Next(_L("Formating")); |
|
310 a.Justify(_TL("AB"),10,ELeft,' '); |
|
311 a.Justify(b,10,ELeft,' '); |
|
312 b.Fill('A',2); |
|
313 a.Zero(); |
|
314 a.AppendJustify(_TL("AB"),10,ELeft,' '); |
|
315 a.AppendJustify(b,10,ELeft,' '); |
|
316 TInt v1=10; |
|
317 a.Num(v1); |
|
318 a.AppendNum(v1); |
|
319 TInt v2=10; |
|
320 a.Num((TUint)v2,EHex); |
|
321 a.AppendNum((TUint)v2,EHex); |
|
322 a.NumUC((TUint)v2,EHex); |
|
323 a.AppendNumUC((TUint)v2,EHex); |
|
324 TReal v3=10.0; |
|
325 TRealFormat ff; |
|
326 ff.iType=KRealFormatFixed; |
|
327 ff.iWidth=10; |
|
328 ff.iPlaces=2; |
|
329 ff.iPoint='.'; |
|
330 ff.iTriad=','; |
|
331 ff.iTriLen=3; |
|
332 a.Num(v3,ff); |
|
333 a.AppendNum(v3,ff); |
|
334 a.Format(_TL("%d"),12); |
|
335 a.AppendFormat(_TL("%d"),12); |
|
336 b=_TL("%d"); |
|
337 a.Format(b,12); |
|
338 a.AppendFormat(b,12); |
|
339 Test1List(&a,&b,12); |
|
340 |
|
341 test.Next(_L("Replacing")); |
|
342 a=_TL("AAC"); |
|
343 b=_TL("B"); |
|
344 a.Replace(1,1,b); |
|
345 test.End(); |
|
346 } |
|
347 |
|
348 template <class T,class S,class DESTEMPLATE> |
|
349 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test2() |
|
350 // Tests all constructors. |
|
351 { |
|
352 test.Start(_L("Default")); |
|
353 T a; |
|
354 test(a.MaxLength()==iMaxBufLength); |
|
355 test(a.Length()==0); |
|
356 |
|
357 test.Next(_L("By length")); |
|
358 T b(iMaxBufLength>>1); |
|
359 test(b.MaxLength()==iMaxBufLength); |
|
360 test(b.Length()==(iMaxBufLength>>1)); |
|
361 |
|
362 test.Next(_L("By string")); |
|
363 T c(_TL("AB")); |
|
364 test(c.MaxLength()==iMaxBufLength); |
|
365 test(c.Length()==2); |
|
366 test(c[0]=='A'); |
|
367 test(c[1]=='B'); |
|
368 |
|
369 test.Next(_L("By buffer reference")); |
|
370 T d(c); |
|
371 test(d.MaxLength()==iMaxBufLength); |
|
372 test(d.Length()==2); |
|
373 test(d[0]=='A'); |
|
374 test(d[1]=='B'); |
|
375 test.End(); |
|
376 } |
|
377 |
|
378 template <class T,class S,class DESTEMPLATE> |
|
379 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test3() |
|
380 // Tests all assignment operators |
|
381 { |
|
382 test.Start(_L("By String")); |
|
383 T a; |
|
384 a=_TL("AB"); |
|
385 a+=_TL("CD"); |
|
386 test(a.Length()==4); |
|
387 test(a==_TL("ABCD")); |
|
388 |
|
389 test.Next(_L("By buffer")); |
|
390 T b; |
|
391 b=a; |
|
392 b+=a; |
|
393 test(b.Length()==8); |
|
394 test(b==_TL("ABCDABCD")); |
|
395 // |
|
396 test.End(); |
|
397 } |
|
398 |
|
399 template <class T,class S,class DESTEMPLATE> |
|
400 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test4() |
|
401 // Test all comparison operators |
|
402 { |
|
403 test.Start(_L("By NULL string")); |
|
404 T a; |
|
405 test(a==_TL("")); // NULL strings |
|
406 test(!(a!=_TL(""))); |
|
407 test(a<=_TL("")); |
|
408 test(a>=_TL("")); |
|
409 test(!(a<_TL(""))); |
|
410 test(!(a>_TL(""))); |
|
411 test(_TL("")==a); |
|
412 test(!(_TL("")!=a)); |
|
413 test(_TL("")<=a); |
|
414 test(_TL("")>=a); |
|
415 test(!(_TL("")<a)); |
|
416 test(!(_TL("")>a)); |
|
417 |
|
418 test.Next(_L("By string or buffer")); |
|
419 a=_TL("abc"); |
|
420 test(a==_TL("abc")); // == |
|
421 test(!(a==_TL("xyz"))); |
|
422 test(!(a==_TL("aa"))); |
|
423 test(_TL("abc")==a); |
|
424 test(!(_TL("xyz")==a)); |
|
425 test(!(_TL("aa")==a)); |
|
426 test(a!=_TL("xyz")); // != |
|
427 test(!(a!=_TL("abc"))); |
|
428 test(a!=_TL("aa")); |
|
429 test(_TL("xyz")!=a); |
|
430 test(!(_TL("abc")!=a)); |
|
431 test(_TL("aa")!=a); |
|
432 test(a<_TL("x")); // < |
|
433 test(!(a<_TL("abc"))); |
|
434 test(!(a<_TL("aa"))); |
|
435 test(_TL("aa")<a); |
|
436 test(!(_TL("abc")<a)); |
|
437 test(!(_TL("xyz")<a)); |
|
438 test(a>_TL("aa")); // > |
|
439 test(!(a>_TL("abc"))); |
|
440 test(!(a>_TL("xyz"))); |
|
441 test(_TL("xyz")>a); |
|
442 test(!(_TL("abc")>a)); |
|
443 test(!(_TL("aa")>a)); |
|
444 test(a>=_TL("abc")); // >= |
|
445 test(!(a>=_TL("xyz"))); |
|
446 test(a>=_TL("aa")); |
|
447 test(_TL("abc")>=a); |
|
448 test(!(_TL("aaa")>=a)); |
|
449 test(_TL("xyz")>=a); |
|
450 test(a<=_TL("abc")); // <= |
|
451 test(!(a<=_TL("aa"))); |
|
452 test(a<=_TL("xyz")); |
|
453 test(_TL("abc")<=a); |
|
454 test(!(_TL("xyz")<=a)); |
|
455 test(_TL("aa")<=a); |
|
456 |
|
457 test.Next(_L("By special characters")); |
|
458 a=_TL("!@#$%^&*()"); |
|
459 test(a==_TL("!@#$%^&*()")); |
|
460 test.End(); |
|
461 } |
|
462 |
|
463 template <class T,class S,class DESTEMPLATE> |
|
464 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test5() |
|
465 // Test all property access |
|
466 { |
|
467 test.Start(_L("Length and Size")); |
|
468 T a; |
|
469 TInt maxLength=a.MaxLength(); |
|
470 TInt i; |
|
471 for (i=0;i<maxLength;i++) |
|
472 { |
|
473 test(a.Length()==i); // Length |
|
474 test(a.Size()==(TInt)(sizeof(S)*i)); // Size |
|
475 a.AppendNum(i%10); |
|
476 } |
|
477 const T b=a; |
|
478 for (i=0;i<maxLength;i++) |
|
479 { |
|
480 test(a[i]=='0'+(i%10)); // At |
|
481 test(b[i]=='0'+(i%10)); // AtConst |
|
482 } |
|
483 test(a[0]==*a.Ptr()); //Ptr |
|
484 a.SetLength(0); // SetLength |
|
485 test(a.Length()==0); |
|
486 a.SetLength(maxLength-1); |
|
487 test(a.Length()==maxLength-1); |
|
488 a.Zero(); // Null |
|
489 test(a.Length()==0); |
|
490 test.End(); |
|
491 } |
|
492 |
|
493 template <class T,class S,class DESTEMPLATE> |
|
494 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test6() |
|
495 // Fill and Swap |
|
496 { |
|
497 test.Start(_L("Fill and Swap")); |
|
498 T a,b; |
|
499 TChar chr; |
|
500 TInt j; |
|
501 TInt maxLength=a.MaxLength(); |
|
502 for (TInt i=0;i<maxLength;i++) |
|
503 { |
|
504 chr=(i%10)+'0'; |
|
505 a.SetLength(i); |
|
506 a.Fill(chr); // Fill(TChar) |
|
507 b.Swap(a); |
|
508 test(b.Length()==i); // Swap |
|
509 j=0; |
|
510 while (j<i) |
|
511 test(b[j++]=='0'+(i%10)); |
|
512 b.FillZ(); // FillZ() |
|
513 a.Swap(b); |
|
514 j=0; |
|
515 while (j<i) |
|
516 test(a[j++]==0); |
|
517 a.Fill(chr,i); // Fill(TChar,TUint) |
|
518 j=0; |
|
519 while (j<i) |
|
520 test(a[j++]=='0'+(i%10)); |
|
521 a.FillZ(i); // FillZ(TUint) |
|
522 j=0; |
|
523 while (j<i) |
|
524 test(a[j++]==0); |
|
525 } |
|
526 test.End(); |
|
527 } |
|
528 |
|
529 template <class T,class S,class DESTEMPLATE> |
|
530 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test7() |
|
531 // Conversion operators |
|
532 { |
|
533 test.Start(_L("Fold, collate ...")); |
|
534 T a; |
|
535 T b; |
|
536 a=_TL("abc AbC"); |
|
537 b=_TL("ABC ABC"); |
|
538 a.Fold(); |
|
539 b.Fold(); |
|
540 test(a==b); |
|
541 a=_TL("abc AbC"); |
|
542 b=_TL("ABC ABC"); |
|
543 a.Collate(); |
|
544 b.Collate(); |
|
545 test(a==b); |
|
546 a.LowerCase(); |
|
547 test(a==_TL("abc abc")); |
|
548 a.Capitalize(); |
|
549 test(a==_TL("Abc abc")); |
|
550 a.UpperCase(); |
|
551 test(a==_TL("ABC ABC")); |
|
552 test.End(); |
|
553 } |
|
554 |
|
555 template <class T,class S,class DESTEMPLATE> |
|
556 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test8() |
|
557 // Comparison |
|
558 { |
|
559 test.Start(_L("By string")); |
|
560 T a; |
|
561 a=_TL("abc AbC"); |
|
562 test(a.Compare(_TL("abc AbC"))==0); |
|
563 test(a.CompareF(_TL("ABC aBc"))==0); |
|
564 test(a.Compare(_TL("xyz"))!=0); |
|
565 test(a.CompareC(_TL("xyz"))!=0); |
|
566 test(a.CompareF(_TL("xyz"))!=0); |
|
567 |
|
568 test.Next(_L("By buffer")); |
|
569 T b; |
|
570 T c; |
|
571 a=_TL("abc AbC"); |
|
572 b=_TL("abc AbC"); |
|
573 c=_TL("xyz"); |
|
574 test(a.Compare(b)==0); |
|
575 test(a.Compare(c)!=0); |
|
576 b=_TL("ABC aBc"); |
|
577 test(a.CompareC(c)!=0); |
|
578 test(a.CompareF(b)==0); |
|
579 test(a.CompareF(c)!=0); |
|
580 |
|
581 test.End(); |
|
582 } |
|
583 |
|
584 template <class T,class S,class DESTEMPLATE> |
|
585 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test9() |
|
586 // Matching (need to test explicit result as error KErrNotFound = KMaxTUint |
|
587 // and so registers as TRUE. (test parameter is TUint) ) |
|
588 { |
|
589 test.Start(_L("By string")); |
|
590 T a; |
|
591 a=_TL("abc AbC"); |
|
592 test(a.Match(_TL("abc AbC"))==0); |
|
593 test(a.MatchC(_TL("ABC aBc"))==0); |
|
594 test(a.MatchF(_TL("ABC aBc"))==0); |
|
595 test(a.Match(_TL("xyz"))==KErrNotFound); |
|
596 test(a.MatchC(_TL("xyz"))==KErrNotFound); |
|
597 test(a.MatchF(_TL("xyz"))==KErrNotFound); |
|
598 |
|
599 test.Next(_L("By buffer")); |
|
600 T b; |
|
601 T c; |
|
602 a=_TL("abc AbC"); |
|
603 b=_TL("abc AbC"); |
|
604 c=_TL("xyz"); |
|
605 test(a.Match(b)==0); |
|
606 test(a.Match(c)==KErrNotFound); |
|
607 b=_TL("ABC aBc"); |
|
608 test(a.MatchC(b)==0); |
|
609 test(a.MatchC(c)==KErrNotFound); |
|
610 test(a.MatchF(b)==0); |
|
611 test(a.MatchF(c)==KErrNotFound); |
|
612 |
|
613 test.Next(_L("Wildcards")); |
|
614 a=_TL("abcxyz"); |
|
615 test(a.Match(_TL("abc*"))==0); |
|
616 test(a.Match(_TL("abw*"))==KErrNotFound); |
|
617 a=_TL("abcdefg"); |
|
618 test(a.Match(_TL("a*fg"))==0); |
|
619 test(a.Match(_TL("a*f"))==KErrNotFound); |
|
620 test(a.Match(_TL("abc*fgh"))==KErrNotFound); |
|
621 a=_TL("abcdef"); |
|
622 test(a.Match(_TL("abc?ef"))==0); |
|
623 test(a.Match(_TL("abc?xf"))==KErrNotFound); |
|
624 |
|
625 a=_TL("a(01)"); |
|
626 test(a.Match(_TL("*(01)"))==1); |
|
627 test(a.Match(_TL("?(01)"))==0); |
|
628 test(a.Match(_TL("?(*)"))==0); |
|
629 test(a.Match(_TL("?(**)"))==0); |
|
630 |
|
631 test(a.Match(_TL("?(\?\?)"))==0); |
|
632 test(a.Match(_TL("*(*)"))>=0); |
|
633 test(a.Match(_TL("*(0?)"))>=0); |
|
634 test(a.Match(_TL("a(\?\?)"))==0); |
|
635 test(a.Match(_TL("*(\?\?)"))>=0); |
|
636 |
|
637 test.Next(_L("wild cards with collated comparison")); |
|
638 a = _TL("abcdefghijkl"); |
|
639 test(a.MatchC(_TL("abc*")) == 0); |
|
640 test(a.MatchC(_TL("abc")) == KErrNotFound); |
|
641 test(a.MatchC(_TL("xyz")) == KErrNotFound); |
|
642 test(a.MatchC(_TL("*def")) == KErrNotFound); |
|
643 test(a.MatchC(_TL("*def*")) == 3); |
|
644 test(a.MatchC(_TL("*d?f*")) == 3); |
|
645 test(a.MatchC(_TL("a*kl")) == 0); |
|
646 test(a.MatchC(_TL("*e*?l")) == 4); |
|
647 test(a.MatchC(_TL("abc*dEf*")) == 0); |
|
648 |
|
649 |
|
650 T candidate; |
|
651 T search; |
|
652 |
|
653 candidate = _TL(""); |
|
654 search = _TL("**"); |
|
655 test(candidate.MatchC(search) == 0); |
|
656 |
|
657 candidate = _TL(""); |
|
658 search = _TL("*"); |
|
659 test(candidate.MatchC(search) == 0); |
|
660 |
|
661 candidate = _TL("abcd"); |
|
662 search = _TL("*abc*cd"); |
|
663 test(candidate.MatchC(search) == KErrNotFound); |
|
664 |
|
665 if (sizeof(S) == 2) |
|
666 { |
|
667 test.Next(_L("Unicode MatchC and FindC treat base+accent as equal to composed character")); |
|
668 TPtrC p = _L("te\x302te"); |
|
669 test(p.MatchC(_L("t\xeate")) == 0); |
|
670 test(p.FindC(_L("t\xeate")) == 0); |
|
671 } |
|
672 |
|
673 test.End(); |
|
674 } |
|
675 |
|
676 template <class T,class S,class DESTEMPLATE> |
|
677 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test10() |
|
678 // Locating |
|
679 { |
|
680 T a; |
|
681 TChar b; |
|
682 |
|
683 test.Start(_L("First Char")); |
|
684 b='a'; |
|
685 a=_TL("axaxa"); |
|
686 test(a.Locate(b)==0); |
|
687 test(a.LocateF(b)==0); |
|
688 test(a.LocateReverse(b)==4); |
|
689 test(a.LocateReverseF(b)==4); |
|
690 |
|
691 test.Next(_L("Middle Char")); |
|
692 a=_TL("xaxa"); |
|
693 test(a.Locate(b)==1); |
|
694 test(a.LocateF(b)==1); |
|
695 a=_TL("axax"); |
|
696 test(a.LocateReverse(b)==2); |
|
697 test(a.LocateReverseF(b)==2); |
|
698 |
|
699 test.Next(_L("Last Char")); |
|
700 a=_TL("xxa"); |
|
701 test(a.Locate(b)==2); |
|
702 test(a.LocateF(b)==2); |
|
703 a=_TL("axx"); |
|
704 test(a.LocateReverse(b)==0); |
|
705 test(a.LocateReverseF(b)==0); |
|
706 |
|
707 test.Next(_L("Test for failure of locate")); |
|
708 a=_TL("xxx"); |
|
709 test(a.Locate(b)==KErrNotFound); |
|
710 test(a.LocateF(b)==KErrNotFound); |
|
711 test(a.LocateReverse(b)==KErrNotFound); |
|
712 test(a.LocateReverseF(b)==KErrNotFound); |
|
713 |
|
714 test.End(); |
|
715 } |
|
716 |
|
717 template <class T,class S,class DESTEMPLATE> |
|
718 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test11() |
|
719 // Copying |
|
720 { |
|
721 T a, b; |
|
722 |
|
723 test.Start(_L("By String")); |
|
724 a.Copy(_TL("abc")); |
|
725 test(a.Length()==3); |
|
726 test(a==_TL("abc")); |
|
727 a.CopyF(_TL("abc")); |
|
728 test(a.Length()==3); |
|
729 b.CopyF(_TL("ABC")); |
|
730 test(a==b); |
|
731 a.CopyLC(_TL("AbC")); |
|
732 test(a==_TL("abc")); |
|
733 test(a.Length()==3); |
|
734 a.CopyC(_TL("abc")); |
|
735 b.CopyC(_TL("ABC")); |
|
736 test(a==b); |
|
737 test(a.Length()==3); |
|
738 a.CopyCP(_TL("abc")); |
|
739 test(a==_TL("Abc")); |
|
740 test(a.Length()==3); |
|
741 a.CopyUC(_TL("aBc")); |
|
742 test(a==_TL("ABC")); |
|
743 test(a.Length()==3); |
|
744 // a.Copy(_TL("abc"),3); |
|
745 // test(a==_TL("abc")); |
|
746 // test(a.Length()==3); |
|
747 // a.Copy(_TL("abcd"),3); |
|
748 // test(a==_TL("abc")); |
|
749 // test(a.Length()==3); |
|
750 |
|
751 test.Next(_L("By buffer")); |
|
752 b=_TL("abc"); |
|
753 a.Copy(b); |
|
754 test(a==_TL("abc")); |
|
755 test(a.Length()==3); |
|
756 a=_TL(""); |
|
757 a.CopyF(b); |
|
758 b.CopyF(_TL("ABC")); |
|
759 test(a==b); |
|
760 test(a.Length()==3); |
|
761 a=_TL(""); |
|
762 b=_TL("AbC"); |
|
763 a.CopyLC(b); |
|
764 test(a==_TL("abc")); |
|
765 test(a.Length()==3); |
|
766 a=_TL(""); |
|
767 b=_TL("abC"); |
|
768 a.CopyC(b); |
|
769 b.CopyC(_TL("ABC")); |
|
770 test(a==b); |
|
771 test(a.Length()==3); |
|
772 a=_TL(""); |
|
773 b=_TL("abC"); |
|
774 a.CopyCP(b); |
|
775 test(a==_TL("Abc")); |
|
776 test(a.Length()==3); |
|
777 a=_TL(""); |
|
778 b=_TL("aBc"); |
|
779 a.CopyUC(b); |
|
780 test(a.Length()==3); |
|
781 test(a==_TL("ABC")); |
|
782 |
|
783 test.End(); |
|
784 } |
|
785 |
|
786 |
|
787 template <class T,class S,class DESTEMPLATE> |
|
788 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test12() |
|
789 // Finding |
|
790 { |
|
791 test.Start(_L("By String")); |
|
792 T a,b; |
|
793 a=_TL("abccef"); |
|
794 test(a.Find(_TL(""))==0); |
|
795 test(a.Find(_TL("abc"))==0); |
|
796 test(a.Find(_TL("cce"))==2); |
|
797 test(a.Find(_TL("cef"))==3); |
|
798 test(a.Find(_TL("efg"))==KErrNotFound); |
|
799 test(a.Find(_TL("xxx"))==KErrNotFound); |
|
800 test(a.FindF(_TL(""))==0); |
|
801 test(a.FindF(_TL("AbC"))==0); |
|
802 test(a.FindF(_TL("CcE"))==2); |
|
803 test(a.FindF(_TL("CeF"))==3); |
|
804 test(a.FindF(_TL("efg"))==KErrNotFound); |
|
805 test(a.FindF(_TL("xxx"))==KErrNotFound); |
|
806 test(a.FindC(_TL(""))==0); |
|
807 test(a.FindC(_TL("aBc"))==0); |
|
808 test(a.FindC(_TL("cce"))==2); |
|
809 test(a.FindC(_TL("cEf"))==3); |
|
810 test(a.FindC(_TL("efg"))==KErrNotFound); |
|
811 test(a.FindC(_TL("xxx"))==KErrNotFound); |
|
812 |
|
813 test.Next(_L("By buffer")); |
|
814 test(a.Find(b)==0); |
|
815 test(a.FindF(b)==0); |
|
816 test(a.FindC(b)==0); |
|
817 b=_TL("xxx"); |
|
818 test(a.Find(b)==KErrNotFound); |
|
819 test(a.FindF(b)==KErrNotFound); |
|
820 test(a.FindC(b)==KErrNotFound); |
|
821 b=_TL("efg"); |
|
822 test(a.Find(b)==KErrNotFound); |
|
823 test(a.FindF(b)==KErrNotFound); |
|
824 test(a.FindC(b)==KErrNotFound); |
|
825 b=_TL("abc"); |
|
826 test(a.Find(b)==0); |
|
827 b=_TL("cce"); |
|
828 test(a.Find(b)==2); |
|
829 b=_TL("cef"); |
|
830 test(a.Find(b)==3); |
|
831 b=_TL("AbC"); |
|
832 test(a.FindF(b)==0); |
|
833 b=_TL("CcE"); |
|
834 test(a.FindF(b)==2); |
|
835 b=_TL("CeF"); |
|
836 test(a.FindF(b)==3); |
|
837 b=_TL("aBc"); |
|
838 test(a.FindC(b)==0); |
|
839 b=_TL("cCe"); |
|
840 test(a.FindC(b)==2); |
|
841 b=_TL("cEf"); |
|
842 test(a.FindC(b)==3); |
|
843 |
|
844 test.End(); |
|
845 } |
|
846 |
|
847 template <class T,class S,class DESTEMPLATE> |
|
848 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test13() |
|
849 // Basic like ops |
|
850 { |
|
851 test.Start(_L("Repeat, trim, insert and delete")); |
|
852 T a,b; |
|
853 TInt max=a.MaxLength(); |
|
854 b=_TL("abc"); |
|
855 a.Repeat(_TL("abc")); |
|
856 test(a==_TL("")); |
|
857 a.Repeat(b); |
|
858 test(a==_TL("")); |
|
859 for (TInt j=1;j<max;j++) // ?? Cannot SetLength = MaxLength |
|
860 { |
|
861 a.SetLength(j); |
|
862 a.Repeat(_TL("abc")); |
|
863 TInt i; |
|
864 for (i=0;i<j;i++) |
|
865 test(a[i]==b[i%3]); |
|
866 a=_TL(""); |
|
867 a.SetLength(j); |
|
868 a.Repeat(b); |
|
869 for (i=0;i<j;i++) |
|
870 test(a[i]==b[i%3]); |
|
871 a=_TL(""); |
|
872 } |
|
873 a=_TL("\t\n ab \t\n "); |
|
874 a.TrimLeft(); |
|
875 test(a==_TL("ab \t\n ")); |
|
876 test(a.Length()==6); |
|
877 a=_TL("\t\n ab \t\n "); |
|
878 a.TrimRight(); |
|
879 test(a==_TL("\t\n ab")); |
|
880 test(a.Length()==6); |
|
881 a=_TL(" \t\n ab \t \n"); |
|
882 a.Trim(); |
|
883 test(a==_TL("ab")); |
|
884 a.Trim(); |
|
885 test(a==_TL("ab")); |
|
886 a=_TL("abc"); |
|
887 b=_TL("123"); |
|
888 a.Insert(1,b); |
|
889 test(a==_TL("a123bc")); |
|
890 test(a.Length()==6); |
|
891 b=_TL(""); |
|
892 a.Insert(4,b); |
|
893 test(a==_TL("a123bc")); |
|
894 test(a.Length()==6); |
|
895 a.Insert(0,b); |
|
896 test(a==_TL("a123bc")); |
|
897 test(a.Length()==6); |
|
898 a.Delete(1,3); |
|
899 test(a==_TL("abc")); |
|
900 test(a.Length()==3); |
|
901 a.Delete(0,3); |
|
902 test(a==_TL("")); |
|
903 test(a.Length()==0); |
|
904 |
|
905 test.Next(_L("TrimAll")); |
|
906 a=_TL(""); |
|
907 a.TrimAll(); |
|
908 test(a==_TL("")); |
|
909 a=_TL(" "); |
|
910 a.TrimAll(); |
|
911 test(a==_TL("")); |
|
912 a=_TL(" "); |
|
913 a.TrimAll(); |
|
914 test(a==_TL("")); |
|
915 a=_TL(" ab cd ef g"); |
|
916 a.TrimAll(); |
|
917 test(a==_TL("ab cd ef g")); |
|
918 a=_TL("abcdef"); |
|
919 a.TrimAll(); |
|
920 test(a==_TL("abcdef")); |
|
921 a=_TL("a b\t cd\t\tef"); |
|
922 a.TrimAll(); |
|
923 test(a==_TL("a b\tcd\tef")); |
|
924 a=_TL("abcdef \t ghijk"); |
|
925 a.TrimAll(); |
|
926 test(a==_TL("abcdef ghijk")); |
|
927 a=_TL("abcdef g"); |
|
928 a.TrimAll(); |
|
929 test(a==_TL("abcdef g")); |
|
930 a=_TL("ab cd ef gh ij"); |
|
931 a.TrimAll(); |
|
932 test(a==_TL("ab cd ef gh ij")); |
|
933 a=_TL("a b c defg h i jk l mno pqr stu vw xyz"); |
|
934 a.TrimAll(); |
|
935 test(a==_TL("a b c defg h i jk l mno pqr stu vw xyz")); |
|
936 |
|
937 test.Next(_L("Right, Left and Mid")); |
|
938 a=_TL("abcdef"); |
|
939 b = a.Left(3); |
|
940 test(b==_TL("abc")); |
|
941 test(b.Length()==3); |
|
942 b = a.Right(3); |
|
943 test(b==_TL("def")); |
|
944 b = a.Mid(2); |
|
945 test(b==_TL("cdef")); |
|
946 test(b.Length()==4); |
|
947 b = a.Left(2); |
|
948 test(b==_TL("ab")); |
|
949 test(b.Length()==2); |
|
950 b = a.Right(2); |
|
951 test(b==_TL("ef")); |
|
952 b = a.Mid(2,1); |
|
953 test(b==_TL("c")); |
|
954 test(b.Length()==1); |
|
955 b = a.Left(6); |
|
956 test(b==_TL("abcdef")); |
|
957 test(b.Length()==6); |
|
958 b=_TL(""); |
|
959 b.SetLength(4); |
|
960 b = a.Right(6); |
|
961 test(b==_TL("abcdef")); |
|
962 test(b.Length()==6); |
|
963 a = a.Left(6); |
|
964 test(a==_TL("abcdef")); |
|
965 b=_TL(""); |
|
966 b = a.Mid(0,6); |
|
967 test(b==_TL("abcdef")); |
|
968 test.End(); |
|
969 } |
|
970 |
|
971 template <class T,class S,class DESTEMPLATE> |
|
972 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test14() |
|
973 // Formating operations |
|
974 { |
|
975 test.Start(_L("Justify")); |
|
976 T a,b,d; |
|
977 TInt aWidth; |
|
978 TChar c; |
|
979 a=_TL("wxyz"); |
|
980 b=_TL("abc"); |
|
981 d=_TL("linearisation"); |
|
982 const S* pD=_TS("299792458"); |
|
983 c='x'; |
|
984 aWidth=KDefaultJustifyWidth; // Left justified, Default width |
|
985 a.Justify(b,aWidth,ELeft,c); |
|
986 test(a==b); |
|
987 test(a.Length()==3); |
|
988 a.AppendJustify(b,aWidth,ELeft,c); |
|
989 test(a==_TL("abcabc")); |
|
990 test(a.Length()==6); |
|
991 aWidth=1; // Width < String length |
|
992 a.Justify(b,aWidth,ELeft,c); |
|
993 test(a==_TL("a")); |
|
994 test(a.Length()==1); |
|
995 a.AppendJustify(b,aWidth,ELeft,c); |
|
996 test(a==_TL("aa")); |
|
997 test(a.Length()==2); |
|
998 aWidth=5; // Width > String length |
|
999 a.Justify(b,aWidth,ELeft,c); |
|
1000 test(a==_TL("abcxx")); |
|
1001 test(a.Length()==5); |
|
1002 a.AppendJustify(b,aWidth,ELeft,c); |
|
1003 test(a==_TL("abcxxabcxx")); |
|
1004 test(a.Length()==10); |
|
1005 |
|
1006 aWidth=KDefaultJustifyWidth; // Right justified, Default width |
|
1007 a.Justify(b,aWidth,ERight,c); |
|
1008 test(a==b); |
|
1009 test(a.Length()==3); |
|
1010 a.AppendJustify(b,aWidth,ERight,c); |
|
1011 test(a==_TL("abcabc")); |
|
1012 test(a.Length()==6); |
|
1013 aWidth=1; // Right justified, Width < String length |
|
1014 a.Justify(b,aWidth,ERight,c); |
|
1015 test(a==_TL("a")); |
|
1016 test(a.Length()==1); |
|
1017 a.AppendJustify(b,aWidth,ERight,c); |
|
1018 test(a==_TL("aa")); |
|
1019 test(a.Length()==2); |
|
1020 aWidth=5; // Right justified, width > String length |
|
1021 a.Justify(b,aWidth,ERight,c); |
|
1022 test(a==_TL("xxabc")); |
|
1023 test(a.Length()==5); |
|
1024 a.AppendJustify(b,aWidth,ERight,c); |
|
1025 test(a==_TL("xxabcxxabc")); |
|
1026 test(a.Length()==10); |
|
1027 |
|
1028 aWidth=KDefaultJustifyWidth; // Center justified, Default width |
|
1029 a.Justify(b,aWidth,ECenter,c); |
|
1030 test(a==b); |
|
1031 test(a.Length()==3); |
|
1032 a.AppendJustify(b,aWidth,ECenter,c); |
|
1033 test(a==_TL("abcabc")); |
|
1034 test(a.Length()==6); |
|
1035 aWidth=1; // Centre justified, width < String length |
|
1036 a.Justify(b,aWidth,ECenter,c); |
|
1037 test(a==_TL("a")); |
|
1038 test(a.Length()==1); |
|
1039 a.AppendJustify(b,aWidth,ECenter,c); |
|
1040 test(a==_TL("aa")); |
|
1041 test(a.Length()==2); |
|
1042 aWidth=5; // Centre justified, width > String length |
|
1043 a.Justify(b,aWidth,ECenter,c); |
|
1044 test(a==_TL("xabcx")); |
|
1045 test(a.Length()==5); |
|
1046 a.AppendJustify(b,aWidth,ECenter,c); |
|
1047 test(a==_TL("xabcxxabcx")); |
|
1048 test(a.Length()==10); |
|
1049 |
|
1050 test.Next(_L("Num")); |
|
1051 TInt j=-2147483647-1; |
|
1052 a.Num(j); |
|
1053 test(a==_TL("-2147483648")); |
|
1054 test(a.Length()==11); |
|
1055 TUint i=2147483648u; |
|
1056 a.Num(i); |
|
1057 test(a==_TL("2147483648")); |
|
1058 test(a.Length()==10); |
|
1059 if (a.MaxLength()>31) |
|
1060 { |
|
1061 a.Num(i,EBinary); |
|
1062 test(a==_TL("10000000000000000000000000000000")); |
|
1063 test(a.Length()==32); |
|
1064 a=_TL(""); |
|
1065 a.NumUC(i,EBinary); |
|
1066 test(a==_TL("10000000000000000000000000000000")); |
|
1067 test(a.Length()==32); |
|
1068 } |
|
1069 i=31; |
|
1070 a.Num(i,EBinary); |
|
1071 test(a==_TL("11111")); |
|
1072 test(a.Length()==5); |
|
1073 a=_TL(""); |
|
1074 a.NumUC(i,EBinary); |
|
1075 test(a==_TL("11111")); |
|
1076 test(a.Length()==5); |
|
1077 i=2147483648u; |
|
1078 a.Num(i,EOctal); |
|
1079 test(a==_TL("20000000000")); |
|
1080 test(a.Length()==11); |
|
1081 a=_TL(""); |
|
1082 a.NumUC(i,EOctal); |
|
1083 test(a==_TL("20000000000")); |
|
1084 test(a.Length()==11); |
|
1085 a.Num(i,EDecimal); |
|
1086 test(a==_TL("2147483648")); |
|
1087 test(a.Length()==10); |
|
1088 a=_TL(""); |
|
1089 a.NumUC(i,EDecimal); |
|
1090 test(a==_TL("2147483648")); |
|
1091 test(a.Length()==10); |
|
1092 a.Num(i,EHex); |
|
1093 test(a==_TL("80000000")); |
|
1094 test(a.Length()==8); |
|
1095 a=_TL(""); |
|
1096 a.NumUC(i,EHex); |
|
1097 test(a==_TL("80000000")); |
|
1098 test(a.Length()==8); |
|
1099 i=0; |
|
1100 a.Num(i); |
|
1101 test(a==_TL("0")); |
|
1102 test(a.Length()==1); |
|
1103 a=_TL("abc"); |
|
1104 a.Num(i,EBinary); |
|
1105 test(a==_TL("0")); |
|
1106 test(a.Length()==1); |
|
1107 a=_TL("abc"); |
|
1108 a.NumUC(i,EBinary); |
|
1109 test(a==_TL("0")); |
|
1110 test(a.Length()==1); |
|
1111 a=_TL("abc"); |
|
1112 a.Num(i,EOctal); |
|
1113 test(a==_TL("0")); |
|
1114 test(a.Length()==1); |
|
1115 a=_TL(""); |
|
1116 a.NumUC(i,EOctal); |
|
1117 test(a==_TL("0")); |
|
1118 test(a.Length()==1); |
|
1119 a=_TL("abc"); |
|
1120 a.Num(i,EDecimal); |
|
1121 test(a==_TL("0")); |
|
1122 test(a.Length()==1); |
|
1123 a=_TL(""); |
|
1124 a.NumUC(i,EDecimal); |
|
1125 test(a==_TL("0")); |
|
1126 test(a.Length()==1); |
|
1127 a=_TL("abc"); |
|
1128 a.Num(i,EHex); |
|
1129 test(a==_TL("0")); |
|
1130 test(a.Length()==1); |
|
1131 a=_TL(""); |
|
1132 a.NumUC(i,EHex); |
|
1133 test(a==_TL("0")); |
|
1134 test(a.Length()==1); |
|
1135 // TInt i=a.Num(6.2,format); NOT IMPLEMENTED |
|
1136 a.AppendNum(j); |
|
1137 test(a==_TL("0-2147483648")); |
|
1138 test(a.Length()==12); |
|
1139 a=_TL("abc"); |
|
1140 i=4294967295u; |
|
1141 a.AppendNum(i); |
|
1142 test(a==_TL("abc4294967295")); |
|
1143 test(a.Length()==13); |
|
1144 j=2147483647; |
|
1145 a=_TL("abc"); |
|
1146 a.AppendNum(j); |
|
1147 test(a==_TL("abc2147483647")); |
|
1148 test(a.Length()==13); |
|
1149 a=_TL("a"); |
|
1150 i=180150000; |
|
1151 if (a.MaxLength()>28) |
|
1152 { |
|
1153 a.AppendNum(i,EBinary); |
|
1154 test(a==_TL("a1010101111001101111011110000")); |
|
1155 test(a.Length()==29); |
|
1156 } |
|
1157 a=_TL("a"); |
|
1158 a.AppendNum(15,EBinary); |
|
1159 test(a==_TL("a1111")); |
|
1160 test(a.Length()==5); |
|
1161 a=_TL("a"); |
|
1162 a.AppendNum(i,EDecimal); |
|
1163 test(a==_TL("a180150000")); |
|
1164 test(a.Length()==10); |
|
1165 a=_TL("a"); |
|
1166 a.AppendNum(i,EOctal); |
|
1167 test(a==_TL("a1257157360")); |
|
1168 test(a.Length()==11); |
|
1169 a=_TL("a"); |
|
1170 a.AppendNumUC(i,EHex); |
|
1171 test(a==_TL("aABCDEF0")); |
|
1172 test(a.Length()==8); |
|
1173 // i=a.AppendNum(6.32, format); NOT IMPLEMENTED |
|
1174 |
|
1175 test.Next(_L("Format")); |
|
1176 a=_TL(""); |
|
1177 b=_TL("cde"); |
|
1178 a.Format(_TL("%S"),&b); |
|
1179 test(a==b); |
|
1180 test(a.Length()==3); |
|
1181 DESTEMPLATE xyz=_TL("xyzwpq"); |
|
1182 a.Format(_TL("%S"),&xyz); |
|
1183 test(a==_TL("xyzwpq")); |
|
1184 test(a.Length()==6); |
|
1185 DESTEMPLATE cde=_TL("cde"); |
|
1186 a.Format(_TL("ab %-x5S"),&cde); |
|
1187 test(a==_TL("ab cdexx")); |
|
1188 test(a.Length()==8); |
|
1189 a.Format(_TL("ab %=x5S"),&cde); |
|
1190 test(a==_TL("ab xcdex")); |
|
1191 test(a.Length()==8); |
|
1192 a.Format(_TL("ab %+x5S"),&cde); |
|
1193 test(a==_TL("ab xxcde")); |
|
1194 test(a.Length()==8); |
|
1195 a.Format(_TL("ab %5S"),&cde); |
|
1196 test(a==_TL("ab cde")); |
|
1197 test(a.Length()==8); |
|
1198 a.Format(_TL("ab %-**S"),'x',5,&cde); |
|
1199 test(a==_TL("ab cdexx")); |
|
1200 test(a.Length()==8); |
|
1201 a.Format(_TL("ab %*S"),5,&cde); |
|
1202 test(a==_TL("ab cde")); |
|
1203 test(a.Length()==8); |
|
1204 a=_TL("xyz"); |
|
1205 a.Format(_TL("ab %-x5S"),&b); |
|
1206 test(a==_TL("ab cdexx")); |
|
1207 test(a.Length()==8); |
|
1208 a=_TL("xyz"); |
|
1209 a.Format(_TL("ab %-**S"),'x',5,&b); |
|
1210 test(a==_TL("ab cdexx")); |
|
1211 test(a.Length()==8); |
|
1212 a=_TL("xyz"); |
|
1213 a.Format(_TL("ab %*S"),5,&b); |
|
1214 test(a==_TL("ab cde")); |
|
1215 test(a.Length()==8); |
|
1216 |
|
1217 DESTEMPLATE fred=_TL("fred"); |
|
1218 a.Format(_TL("%+0*S"),10,&fred); |
|
1219 test(a==_TL("000000fred")); |
|
1220 test(a.Length()==10); |
|
1221 a.Format(_TL("%-0*S"),7,&fred); |
|
1222 test(a==_TL("fred000")); |
|
1223 test(a.Length()==7); |
|
1224 a.Format(_TL("%0*S"),11,&fred); |
|
1225 test(a==_TL("0000000fred")); |
|
1226 test(a.Length()==11); |
|
1227 a.Format(_TL("c=%s"),pD); |
|
1228 TESTEQ(a,_TL("c=299792458")); |
|
1229 a.Format(_TL("c=%10.6s"),pD); |
|
1230 test(a==_TL("c= 299792")); |
|
1231 a.Format(_TL("c=%*.*s"),5,4,pD); |
|
1232 test(a==_TL("c= 2997")); |
|
1233 a.Format(_TL("%S"),&d); |
|
1234 test(a==_TL("linearisation")); |
|
1235 a.Format(_TL("%10.6S"),&d); |
|
1236 test(a==_TL(" linear")); |
|
1237 a.Format(_TL("%*.*S"),5,4,&d); |
|
1238 test(a==_TL(" line")); |
|
1239 a.Format(_TL("%*.*Sed"),10,8,&d); |
|
1240 test(a==_TL(" linearised")); |
|
1241 a.Format(_TL("%*.*S"),14,20,&d); |
|
1242 test(a==_TL(" linearisation")); |
|
1243 |
|
1244 a.Format(_TL("ab %-,5b"),7); |
|
1245 test(a==_TL("ab 111,,")); |
|
1246 test(a.Length()==8); |
|
1247 a.Format(_TL("ab %=,5O"),31); |
|
1248 test(a==_TL("ab ,37,,")); |
|
1249 test(a.Length()==8); |
|
1250 a.Format(_TL("ab %+xlx"),TInt64(171)); |
|
1251 test(a==_TL("ab ab")); |
|
1252 test(a.Length()==5); |
|
1253 a.Format(_TL("ab %+xlX %+xlx"),TInt64(171),TInt64(171)); |
|
1254 TESTEQ(a,_TL("ab AB ab")); |
|
1255 test(a.Length()==8); |
|
1256 a.Format(_TL("ab %lu"),MAKE_TINT64((TUint)(KMinTInt),0)); |
|
1257 test(a==_TL("ab 9223372036854775808")); |
|
1258 test(a.Length()==22); |
|
1259 a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMinTInt),1)); |
|
1260 test(a==_TL("ab -9223372036854775807")); |
|
1261 test(a.Length()==23); |
|
1262 a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMinTInt),0)); |
|
1263 test(a==_TL("ab -9223372036854775808")); |
|
1264 test(a.Length()==23); |
|
1265 a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint)); |
|
1266 test(a==_TL("ab 9223372036854775807")); |
|
1267 test(a.Length()==22); |
|
1268 a.Format(_TL("ab %ld"),MAKE_TINT64(KMaxTUint,KMaxTUint)); |
|
1269 test(a==_TL("ab -1")); |
|
1270 test(a.Length()==5); |
|
1271 a.Format(_TL("ab %lu"),MAKE_TINT64(KMaxTUint,KMaxTUint)); |
|
1272 test(a==_TL("ab 18446744073709551615")); |
|
1273 test(a.Length()==23); |
|
1274 a.Format(_TL("ab %ld"),TInt64(0)); |
|
1275 test(a==_TL("ab 0")); |
|
1276 test(a.Length()==4); |
|
1277 a.Format(_TL("ab %lb"),TInt64(0)); |
|
1278 test(a==_TL("ab 0")); |
|
1279 test(a.Length()==4); |
|
1280 a.Format(_TL("ab %lx"),TInt64(0)); |
|
1281 test(a==_TL("ab 0")); |
|
1282 test(a.Length()==4); |
|
1283 a.Format(_TL("ab %lo"),TInt64(0)); |
|
1284 test(a==_TL("ab 0")); |
|
1285 test(a.Length()==4); |
|
1286 a.Format(_TL("ab %lu"),TInt64(0)); |
|
1287 test(a==_TL("ab 0")); |
|
1288 test(a.Length()==4); |
|
1289 a.Format(_TL("ab %lb"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint)); |
|
1290 test(a==_TL("ab 111111111111111111111111111111111111111111111111111111111111111")); |
|
1291 test(a.Length()==66); |
|
1292 a.Format(_TL("ab %lb"),MAKE_TINT64(KMaxTUint,KMaxTUint)); |
|
1293 test(a==_TL("ab 1111111111111111111111111111111111111111111111111111111111111111")); |
|
1294 test(a.Length()==67); |
|
1295 a.Format(_TL("ab %lx"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint)); |
|
1296 test(a==_TL("ab 7fffffffffffffff")); |
|
1297 test(a.Length()==19); |
|
1298 a.Format(_TL("ab %lx"),MAKE_TINT64(KMaxTUint,KMaxTUint)); |
|
1299 test(a==_TL("ab ffffffffffffffff")); |
|
1300 test(a.Length()==19); |
|
1301 a.Format(_TL("ab %lo"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint)); |
|
1302 test(a==_TL("ab 777777777777777777777")); |
|
1303 test(a.Length()==24); |
|
1304 // tests which excercise any 8 byte alignment requirement on 64bit integers |
|
1305 a.Format(_TL("%li%S"),MAKE_TINT64(1,2),&fred); |
|
1306 test(a==_TL("4294967298fred")); |
|
1307 a.Format(_TL("%S%li%S"),&fred,MAKE_TINT64(1,2),&fred); |
|
1308 test(a==_TL("fred4294967298fred")); |
|
1309 a.Format(_TL("%lu%S"),MAKE_TINT64(1,2),&fred); |
|
1310 test(a==_TL("4294967298fred")); |
|
1311 a.Format(_TL("%S%lu%S"),&fred,MAKE_TINT64(1,2),&fred); |
|
1312 test(a==_TL("fred4294967298fred")); |
|
1313 |
|
1314 a.Format(_TL("ab %U"),233); |
|
1315 test(a==_TL("ab 233")); |
|
1316 test(a.Length()==6); |
|
1317 a.Format(_TL("ab %*d"),5,-131); |
|
1318 test(a==_TL("ab -131")); |
|
1319 test(a.Length()==8); |
|
1320 a.Format(_TL("ab%c"),'x'); |
|
1321 test(a==_TL("abx")); |
|
1322 test(a.Length()==3); |
|
1323 a.Format(_TL("%W"),-131); |
|
1324 test(*(TInt32*)a.Ptr()==-131); |
|
1325 a.Format(_TL("%M"),-131); |
|
1326 test(*(TInt32*)a.Ptr()==2113929215); |
|
1327 a.Format(_TL("%w"),-131); |
|
1328 test(*(TInt16*)a.Ptr()==-131); |
|
1329 a.Format(_TL("%m"),-131); |
|
1330 test(*(TInt16*)a.Ptr()==32255); |
|
1331 a=_TL("xyz"); |
|
1332 a.AppendFormat(_TL("ab %+xlx"),TInt64(171)); |
|
1333 test(a==_TL("xyzab ab")); |
|
1334 test(a.Length()==8); |
|
1335 a=_TL("xyz"); |
|
1336 a.AppendFormat(_TL("ab %5S"),&b); |
|
1337 test(a==_TL("xyzab cde")); |
|
1338 test(a.Length()==11); |
|
1339 a=_TL("xyz"); |
|
1340 a.AppendFormat(_TL("%W"),-131); |
|
1341 // test(*(TInt32*)(a.Ptr()+3)==-131); // Alignment-safe version: |
|
1342 TInt val; |
|
1343 Mem::Copy(&val,&a[3],4); |
|
1344 test(val==-131); |
|
1345 a=_TL("xyz"); |
|
1346 // a.Append(_TL("abc"),3); |
|
1347 // test(a==_TL("xyzabc")); |
|
1348 |
|
1349 a.Format(_TL("")); |
|
1350 test(a==_TL("")); |
|
1351 a.Format(_TL(""),9,5); |
|
1352 test(a==_TL("")); |
|
1353 a.Format(_TL("qwerty")); |
|
1354 test(a==_TL("qwerty")); |
|
1355 a.Format(_TL("qwerty"),9,5); |
|
1356 test(a==_TL("qwerty")); |
|
1357 a.Format(_TL("%$1$d%$2$d"),9,5); |
|
1358 test(a==_TL("95")); |
|
1359 test(a.Length()==2); |
|
1360 a.Format(_TL("%$2$d%$1$d"),9,5); |
|
1361 test(a==_TL("59")); |
|
1362 test(a.Length()==2); |
|
1363 b=_TL("eb"); |
|
1364 a.Format(_TL("%$1$S%$2$d"),&b,205); |
|
1365 test(a==_TL("eb205")); |
|
1366 test(a.Length()==5); |
|
1367 a.Format(_TL("%$2$d%$1$S"),&b,205); |
|
1368 test(a==_TL("205eb")); |
|
1369 test(a.Length()==5); |
|
1370 b=_TL("ebdb"); |
|
1371 |
|
1372 // Cannot do this on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime". |
|
1373 #if !(defined(__GCC32__) && defined(__X86__)) |
|
1374 const TAny* const zeroTerminatedString=(sizeof(S)==2)? (const TAny*)_S16(":-)E"): (const TAny*)_S8(":-)E"); |
|
1375 const TInt dummyParameter=0; |
|
1376 Test14_ReorderedParameterFormatting(dummyParameter, 0x20ac, 11, 3, 13.89543, zeroTerminatedString, '!', TInt64(199), 2, &b, 6, 30005, TRealX(0.125), 0x8bdd); |
|
1377 #endif |
|
1378 |
|
1379 test.Next(_L("Print some numbers")); |
|
1380 TInt64 TI64 = MAKE_TINT64(0x101010u,0x10101010u); |
|
1381 test.Printf(_L(" %%ld: %ld\n"),TI64); |
|
1382 test.Printf(_L(" %%lu: %lu\n"),TI64); |
|
1383 test.Printf(_L(" %%lx: %lx\n"),TI64); |
|
1384 test.Printf(_L(" %%lb: %lb\n"),TI64); |
|
1385 test.Printf(_L(" %%lo: %lo\n\n"),TI64); |
|
1386 TI64 = UI64LIT(0xabcdef12345678); |
|
1387 test.Printf(_L(" %%ld: %ld\n"),TI64); |
|
1388 test.Printf(_L(" %%lu: %lu\n"),TI64); |
|
1389 test.Printf(_L(" %%lx: %lx\n"),TI64); |
|
1390 test.Printf(_L(" %%lb: %lb\n"),TI64); |
|
1391 test.Printf(_L(" %%lo: %lo\n\n"),TI64); |
|
1392 TI64 = UI64LIT(0x7fffffffffffffff); |
|
1393 test.Printf(_L(" %%ld: %ld\n"),TI64); |
|
1394 test.Printf(_L(" %%lu: %lu\n"),TI64); |
|
1395 test.Printf(_L(" %%lx: %lx\n"),TI64); |
|
1396 test.Printf(_L(" %%lb: %lb\n"),TI64); |
|
1397 test.Printf(_L(" %%lo: %lo\n\n"),TI64); |
|
1398 TI64 = UI64LIT(0x8000000000000000); |
|
1399 test.Printf(_L(" %%ld: %ld\n"),TI64); |
|
1400 test.Printf(_L(" %%lu: %lu\n"),TI64); |
|
1401 test.Printf(_L(" %%lx: %lx\n"),TI64); |
|
1402 test.Printf(_L(" %%lb: %lb\n"),TI64); |
|
1403 test.Printf(_L(" %%lo: %lo\n\n"),TI64); |
|
1404 TI64 = UI64LIT(0xffffffffffffffff); |
|
1405 test.Printf(_L(" %%ld: %ld\n"),TI64); |
|
1406 test.Printf(_L(" %%lu: %lu\n"),TI64); |
|
1407 test.Printf(_L(" %%lx: %lx\n"),TI64); |
|
1408 test.Printf(_L(" %%lb: %lb\n"),TI64); |
|
1409 test.Printf(_L(" %%lo: %lo\n\n"),TI64); |
|
1410 |
|
1411 test.Next(_L("Regression tests")); |
|
1412 a.Format(_TL("[%-A4p]")); |
|
1413 test(a==_TL("[AAAA]")); |
|
1414 |
|
1415 test.End(); |
|
1416 } |
|
1417 |
|
1418 template <class T,class S,class DESTEMPLATE> |
|
1419 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test14_ReorderedParameterFormatting(TInt aDummyParameter, ...) |
|
1420 { |
|
1421 VA_LIST parameterList; |
|
1422 T generated; |
|
1423 T expected; |
|
1424 |
|
1425 VA_START(parameterList, aDummyParameter); |
|
1426 generated.FormatList(_TL("\t%-**.*fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%.3Fyyyyyyy%c"), parameterList); |
|
1427 test(generated.Length()==61); |
|
1428 expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www!!199eeeeebrrrrr007535tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1429 test(generated.Left(generated.Length()-1)==expected); |
|
1430 test(generated[generated.Length()-1]==(S)0x8bdd); |
|
1431 |
|
1432 VA_START(parameterList, aDummyParameter); |
|
1433 generated.FormatList(_TL("\t%$1$-**.*fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%$6$.3Fyyyyyyy%c"), parameterList); |
|
1434 test(generated.Length()==61); |
|
1435 expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www!!199eeeeebrrrrr007535tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1436 test(generated.Left(generated.Length()-1)==expected); |
|
1437 test(generated[generated.Length()-1]==(S)0x8bdd); |
|
1438 |
|
1439 VA_START(parameterList, aDummyParameter); |
|
1440 generated.FormatList(_TL("\t%$6$.3Fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%$1$-**.*fyyyyyyy%c"), parameterList); |
|
1441 test(generated.Length()==61); |
|
1442 expected.Format(_TL("\t0.125qq:-)www!!199eeeeebrrrrr007535tttttt13.895%c%c%c%c%cyyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1443 test(generated.Left(generated.Length()-1)==expected); |
|
1444 test(generated[generated.Length()-1]==(S)0x8bdd); |
|
1445 |
|
1446 VA_START(parameterList, aDummyParameter); |
|
1447 generated.FormatList(_TL("\t%-**.*fqq%.3swww%$5$0*xeeee%.*Srrrrr%$3$+*5Ldtttttt%.3Fyyyyyyy%c"), parameterList); |
|
1448 test(generated.Length()==61); |
|
1449 expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www007535eeeeebrrrrr!!199tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1450 test(generated.Left(generated.Length()-1)==expected); |
|
1451 test(generated[generated.Length()-1]==(S)0x8bdd); |
|
1452 |
|
1453 VA_START(parameterList, aDummyParameter); |
|
1454 generated.FormatList(_TL("\t%-**.*fqq%$4$.*Swww%+*5Ldeeee%$2$.3srrrrr%0*xtttttt%.3Fyyyyyyy%c"), parameterList); |
|
1455 test(generated.Length()==61); |
|
1456 expected.Format(_TL("\t13.895%c%c%c%c%cqqebwww!!199eeee:-)rrrrr007535tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1457 test(generated.Left(generated.Length()-1)==expected); |
|
1458 test(generated[generated.Length()-1]==(S)0x8bdd); |
|
1459 |
|
1460 VA_START(parameterList, aDummyParameter); |
|
1461 generated.FormatList(_TL("\t%-**.*fqq%.3swww%+*5Ldeeee%$7$crrrrr%0*xtttttt%.3Fyyyyyyy%$4$.*S"), parameterList); |
|
1462 test(generated.Length()==61); |
|
1463 expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www!!199eeee"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1464 test(generated.Left(29)==expected); |
|
1465 test(generated[29]==(S)0x8bdd); |
|
1466 test(generated.Mid(29+1)==_TL("rrrrr007535tttttt0.125yyyyyyyeb")); |
|
1467 |
|
1468 VA_START(parameterList, aDummyParameter); |
|
1469 generated.FormatList(_TL("\t%$4$.*Sqq%.3swww%+*5Ldeeee%$6$.3Frrrrr%0*xtttttt%$1$-**.*fyyyyyyy%c"), parameterList); |
|
1470 test(generated.Length()==61); |
|
1471 expected.Format(_TL("\tebqq:-)www!!199eeee0.125rrrrr007535tttttt13.895%c%c%c%c%cyyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1472 test(generated.Left(generated.Length()-1)==expected); |
|
1473 test(generated[generated.Length()-1]==(S)0x8bdd); |
|
1474 |
|
1475 VA_START(parameterList, aDummyParameter); |
|
1476 generated.FormatList(_TL("\t%$7$cqq%$6$.3Fwww%$5$0*xeeee%.*Srrrrr%$3$+*5Ldtttttt%$2$.3syyyyyyy%$1$-**.*f"), parameterList); |
|
1477 test(generated.Length()==61); |
|
1478 test(generated.Left(1)==_TL("\t")); |
|
1479 test(generated[1]==(S)0x8bdd); |
|
1480 expected.Format(_TL("qq0.125www007535eeeeebrrrrr!!199tttttt:-)yyyyyyy13.895%c%c%c%c%c"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1481 test(generated.Mid(2)==expected); |
|
1482 |
|
1483 VA_START(parameterList, aDummyParameter); |
|
1484 generated.FormatList(_TL("\t%$7$cqq%$6$.3Fwww%$5$0*xeeee%$4$.*Srrrrr%$3$+*5Ldtttttt%$2$.3syyyyyyy%$1$-**.*f"), parameterList); |
|
1485 test(generated.Length()==61); |
|
1486 test(generated.Left(1)==_TL("\t")); |
|
1487 test(generated[1]==(S)0x8bdd); |
|
1488 expected.Format(_TL("qq0.125www007535eeeeebrrrrr!!199tttttt:-)yyyyyyy13.895%c%c%c%c%c"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1489 test(generated.Mid(2)==expected); |
|
1490 } |
|
1491 |
|
1492 template <class T,class S,class DESTEMPLATE> |
|
1493 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test15() |
|
1494 // Replacing |
|
1495 { |
|
1496 test.Start(_L("Replace")); |
|
1497 T a,b; |
|
1498 test(a.MaxLength()>=9); |
|
1499 a=_TL("abccccc"); |
|
1500 b=_TL("def"); |
|
1501 a.Replace(3,4,b); // Replace with smaller in middle (insert and delete) |
|
1502 test(a==_TL("abcdef")); |
|
1503 a.Replace(1,1,b); // Replace with larger in middle (insert and delete) |
|
1504 test(a==_TL("adefcdef")); |
|
1505 a.Replace(0,8,_TL("")); // Replace complete string (delete) |
|
1506 test(a==_TL("")); |
|
1507 a.Replace(0,0,b); // Replace at beginning (insert) |
|
1508 test(a==b); |
|
1509 a.Replace(3,0,_TL("xyz")); // Replace at end (append) |
|
1510 test(a==_TL("defxyz")); |
|
1511 a.Replace(0,0,_TL("")); // Replace nothing at beginning (do nothing) |
|
1512 test(a==_TL("defxyz")); |
|
1513 a.Replace(6,0,_TL("")); // Replace nothing at end (do nothing) |
|
1514 test(a==_TL("defxyz")); |
|
1515 //a.Replace(6,1,_TL("")); // this will panic - no char after end to replace |
|
1516 //a.Replace(0,7,_TL("")); // this will panic - aint 7 chars to replace |
|
1517 test.End(); |
|
1518 } |
|
1519 |
|
1520 template<class T,class S,class DESTEMPLATE> |
|
1521 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::test_TBuf() |
|
1522 // Test the TBuf class. |
|
1523 { |
|
1524 test.Start(_L("All operations")); |
|
1525 Test1(); |
|
1526 test.Next(_L("Constructors")); |
|
1527 Test2(); |
|
1528 test.Next(_L("Additional tests")); |
|
1529 Test3(); |
|
1530 test.Next(_L("Comparison operators")); |
|
1531 Test4(); |
|
1532 test.Next(_L("Property access")); |
|
1533 Test5(); |
|
1534 test.Next(_L("Fill and swap")); |
|
1535 Test6(); |
|
1536 test.Next(_L("Conversion operators")); |
|
1537 Test7(); |
|
1538 test.Next(_L("Comparison")); |
|
1539 Test8(); |
|
1540 test.Next(_L("Matching")); |
|
1541 Test9(); |
|
1542 test.Next(_L("Locating")); |
|
1543 Test10(); |
|
1544 test.Next(_L("Copying")); |
|
1545 Test11(); |
|
1546 test.Next(_L("Finding")); |
|
1547 Test12(); |
|
1548 test.Next(_L("Basic like ops")); |
|
1549 Test13(); |
|
1550 test.Next(_L("Formating")); |
|
1551 Test14(); |
|
1552 test.Next(_L("Replacing")); |
|
1553 Test15(); |
|
1554 test.End(); |
|
1555 } |
|
1556 |
|
1557 LOCAL_C void testFormat() |
|
1558 { |
|
1559 TBuf<0x100> aa; |
|
1560 aa.Format(_L("x%- 5fx"), 6.2345678); |
|
1561 test(aa==_L("x6.234568x")); |
|
1562 aa.Format(_L("x%+ 5fx"), 6.2345678); |
|
1563 test(aa==_L("x6.234568x")); |
|
1564 aa.Format(_L("x% 5fx"), 6.2345678); |
|
1565 test(aa==_L("x6.234568x")); |
|
1566 aa.Format(_L("x%= 5fx"), 6.2345678); |
|
1567 test(aa==_L("x6.234568x")); |
|
1568 aa.Format(_L("x%- 10fx"), 6.2345); |
|
1569 test(aa==_L("x6.234500 x")); |
|
1570 aa.Format(_L("x%+ 10fx"), 6.2345); |
|
1571 test(aa==_L("x 6.234500x")); |
|
1572 aa.Format(_L("x% 10fx"), 6.2345); |
|
1573 test(aa==_L("x 6.234500x")); |
|
1574 aa.Format(_L("x%= 10fx"), 6.2345); |
|
1575 test(aa==_L("x 6.234500 x")); |
|
1576 aa.Format(_L("x%10fx"), 12345352342.545); |
|
1577 test(aa==_L("x12,345,352,342.545000x")); |
|
1578 aa.Format(_L("x%20.9fx"), 1.0123456789); |
|
1579 test(aa==_L("x 1.012345679x")); |
|
1580 aa.Format(_L("x%5.1fx"), 1.99); |
|
1581 test(aa==_L("x 2.0x")); |
|
1582 |
|
1583 // Cannot do these on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime". |
|
1584 #if !(defined(__GCC32__) && defined(__X86__)) |
|
1585 aa.Format(_L("x%- 5Fx"), TRealX(6.2345678)); |
|
1586 test(aa==_L("x6.234568x")); |
|
1587 aa.Format(_L("x%+ 5Fx"), TRealX(6.2345678)); |
|
1588 test(aa==_L("x6.234568x")); |
|
1589 aa.Format(_L("x% 5Fx"), TRealX(6.2345678)); |
|
1590 test(aa==_L("x6.234568x")); |
|
1591 aa.Format(_L("x%= 5Fx"), TRealX(6.2345678)); |
|
1592 test(aa==_L("x6.234568x")); |
|
1593 aa.Format(_L("x%- 10Fx"), TRealX(6.2345)); |
|
1594 test(aa==_L("x6.234500 x")); |
|
1595 aa.Format(_L("x%+ 10Fx"), TRealX(6.2345)); |
|
1596 test(aa==_L("x 6.234500x")); |
|
1597 aa.Format(_L("x% 10Fx"), TRealX(6.2345)); |
|
1598 test(aa==_L("x 6.234500x")); |
|
1599 aa.Format(_L("x%+010Fx"), TRealX(6.2345)); |
|
1600 test(aa==_L("x006.234500x")); |
|
1601 aa.Format(_L("x%+10Fx"), TRealX(6.2345)); |
|
1602 test(aa==_L("x 6.234500x")); |
|
1603 aa.Format(_L("x%10Fx"), TRealX(6.2345)); |
|
1604 test(aa==_L("x 6.234500x")); |
|
1605 aa.Format(_L("x%010Fx"), TRealX(6.2345)); |
|
1606 test(aa==_L("x006.234500x")); |
|
1607 aa.Format(_L("x%= 10Fx"), TRealX(6.2345)); |
|
1608 test(aa==_L("x 6.234500 x")); |
|
1609 aa.Format(_L("x%10Fx"), TRealX(12345352342.545)); |
|
1610 test(aa==_L("x12,345,352,342.545000x")); |
|
1611 aa.Format(_L("x%20.9Fx"), TRealX(1.0123456789)); |
|
1612 test(aa==_L("x 1.012345679x")); |
|
1613 aa.Format(_L("x%5.1Fx"), TRealX(1.99)); |
|
1614 test(aa==_L("x 2.0x")); |
|
1615 #endif |
|
1616 |
|
1617 aa.Format(_L("x%- 5ex"), 6.2345678); |
|
1618 test(aa==_L("x6.234568E+00x")); |
|
1619 aa.Format(_L("x%+ 5ex"), 6.2345678); |
|
1620 test(aa==_L("x6.234568E+00x")); |
|
1621 aa.Format(_L("x% 5ex"), 6.2345678); |
|
1622 test(aa==_L("x6.234568E+00x")); |
|
1623 aa.Format(_L("x%= 5ex"), 6.2345678); |
|
1624 test(aa==_L("x6.234568E+00x")); |
|
1625 aa.Format(_L("x%- 14ex"), 6.2345); |
|
1626 test(aa==_L("x6.234500E+00 x")); |
|
1627 aa.Format(_L("x%+ 14ex"), 6.2345); |
|
1628 test(aa==_L("x 6.234500E+00x")); |
|
1629 aa.Format(_L("x% 14ex"), 6.2345); |
|
1630 test(aa==_L("x 6.234500E+00x")); |
|
1631 aa.Format(_L("x%= 14ex"), 6.2345); |
|
1632 test(aa==_L("x 6.234500E+00 x")); |
|
1633 aa.Format(_L("x%10ex"), 12345352342.545); |
|
1634 test(aa==_L("x1.234535E+10x")); |
|
1635 aa.Format(_L("x%20.9ex"), 1.0123456789); |
|
1636 test(aa==_L("x 1.012345679E+00x")); |
|
1637 aa.Format(_L("x%5.1ex"), 1.99); |
|
1638 test(aa==_L("x2.0E+00x")); |
|
1639 } |
|
1640 |
|
1641 |
|
1642 class TO8 : public TDes8Overflow |
|
1643 { |
|
1644 public: |
|
1645 virtual void Overflow(TDes8 &aDes); |
|
1646 }; |
|
1647 |
|
1648 void TO8::Overflow(TDes8 &aDes) |
|
1649 { |
|
1650 aDes=_L8("OVERFLOW"); |
|
1651 } |
|
1652 |
|
1653 class TO8L : public TDes8Overflow |
|
1654 { |
|
1655 public: |
|
1656 virtual void Overflow(TDes8 &aDes); |
|
1657 }; |
|
1658 |
|
1659 void TO8L::Overflow(TDes8 &/*aDes*/) |
|
1660 { |
|
1661 User::Leave(KErrOverflow); |
|
1662 } |
|
1663 |
|
1664 class TO16 : public TDes16Overflow |
|
1665 { |
|
1666 public: |
|
1667 virtual void Overflow(TDes16 &aDes); |
|
1668 }; |
|
1669 |
|
1670 void TO16::Overflow(TDes16 &aDes) |
|
1671 { |
|
1672 aDes=_L16("OVERFLOW"); |
|
1673 } |
|
1674 |
|
1675 class TO16L : public TDes16Overflow |
|
1676 { |
|
1677 public: |
|
1678 virtual void Overflow(TDes16 &aDes); |
|
1679 }; |
|
1680 |
|
1681 void TO16L::Overflow(TDes16 &/*aDes*/) |
|
1682 { |
|
1683 User::Leave(KErrOverflow); |
|
1684 } |
|
1685 |
|
1686 void append8(TDes8 &aBuf, TDes8Overflow *aHandler, TRefByValue<const TDesC8> aFmt, ...) |
|
1687 { |
|
1688 VA_LIST list; |
|
1689 VA_START(list, aFmt); |
|
1690 aBuf.AppendFormatList(aFmt, list, aHandler); |
|
1691 } |
|
1692 |
|
1693 void append16(TDes16 &aBuf, TDes16Overflow *aHandler, TRefByValue<const TDesC16> aFmt, ...) |
|
1694 { |
|
1695 VA_LIST list; |
|
1696 VA_START(list, aFmt); |
|
1697 aBuf.AppendFormatList(aFmt, list, aHandler); |
|
1698 } |
|
1699 |
|
1700 void testOverflow() |
|
1701 { |
|
1702 test.Start(_L("Test no overflow")); |
|
1703 TBuf8<16> buf=_L8("A "); |
|
1704 append8(buf, NULL, _L8("Descriptor")); |
|
1705 test(buf==_L8("A Descriptor")); |
|
1706 |
|
1707 test.Printf(_L("Use a non-leaving overflow handler\n")); |
|
1708 test.Next(_L("Force overflow with no conversions")); |
|
1709 TO8 overflow; |
|
1710 append8(buf, &overflow, _L8("12345678901234567")); |
|
1711 test(buf==_L8("OVERFLOW")); |
|
1712 |
|
1713 test.Next(_L("Force overflow with decimal conversion")); |
|
1714 buf=_L8("A Descriptor"); |
|
1715 append8(buf, &overflow, _L8("%d"), 12345678); |
|
1716 test(buf==_L8("OVERFLOW")); |
|
1717 |
|
1718 test.Printf(_L("Use a leaving overflow handler\n")); |
|
1719 test.Next(_L("AppendFormatList with no overflow")); |
|
1720 buf=_L8("A Descriptor"); |
|
1721 TO8L overflowLeave; |
|
1722 TRAPD(r, append8(buf, &overflowLeave, _L8("ONE"))); |
|
1723 test(r==KErrNone); |
|
1724 test(buf==_L8("A DescriptorONE")); |
|
1725 test.Next(_L("Force overflow with hexadecimal conversion")); |
|
1726 buf=_L8("A Descriptor"); |
|
1727 TRAP(r, append8(buf, &overflowLeave, _L8("%08x"), 0)); |
|
1728 test(r==KErrOverflow); |
|
1729 { |
|
1730 test.Printf(_L("Repeat tests with TBuf16\n")); |
|
1731 test.Next(_L("Test no overflow")); |
|
1732 TBuf16<16> buf=_L16("A "); |
|
1733 append16(buf, NULL, _L16("Descriptor")); |
|
1734 test(buf==_L16("A Descriptor")); |
|
1735 |
|
1736 test.Printf(_L("Use a non-leaving overflow handler\n")); |
|
1737 test.Next(_L("Force overflow with no conversions")); |
|
1738 TO16 overflow; |
|
1739 append16(buf, &overflow, _L16("12345678901234567")); |
|
1740 test(buf==_L16("OVERFLOW")); |
|
1741 |
|
1742 test.Next(_L("Force overflow with decimal conversion")); |
|
1743 buf=_L16("A Descriptor"); |
|
1744 append16(buf, &overflow, _L16("%d"), 12345678); |
|
1745 test(buf==_L16("OVERFLOW")); |
|
1746 |
|
1747 test.Printf(_L("Use a leaving overflow handler\n")); |
|
1748 test.Next(_L("AppendFormatList with no overflow")); |
|
1749 buf=_L16("A Descriptor"); |
|
1750 TO16L overflowLeave; |
|
1751 TRAPD(r, append16(buf, &overflowLeave, _L16("ONE"))); |
|
1752 test(r==KErrNone); |
|
1753 test(buf==_L16("A DescriptorONE")); |
|
1754 test.Next(_L("Force overflow with hexadecimal conversion")); |
|
1755 buf=_L16("A Descriptor"); |
|
1756 TRAP(r, append16(buf, &overflowLeave, _L16("%08x"), 0)); |
|
1757 test(r==KErrOverflow); |
|
1758 } |
|
1759 test.End(); |
|
1760 } |
|
1761 |
|
1762 void testIgnoreOverflow() |
|
1763 { |
|
1764 test.Start(_L("Test no overflow")); |
|
1765 TBuf8<16> buf=_L8("A "); |
|
1766 append8(buf, NULL, _L8("Descriptor")); |
|
1767 test(buf==_L8("A Descriptor")); |
|
1768 |
|
1769 test.Printf(_L("Use a non-leaving overflow handler\n")); |
|
1770 test.Next(_L("Force overflow with no conversions")); |
|
1771 TDes8IgnoreOverflow overflow; |
|
1772 append8(buf, &overflow, _L8("12345678901234567")); |
|
1773 test(buf==_L8("A Descriptor1234")); |
|
1774 |
|
1775 test.Next(_L("Force overflow with decimal conversion")); |
|
1776 buf=_L8("A Descriptor"); |
|
1777 append8(buf, &overflow, _L8("%d"), 123456789); |
|
1778 test(buf==_L8("A Descriptor")); |
|
1779 |
|
1780 //test.Printf(_L("Repeat tests with TBuf16\n")); |
|
1781 test.Next(_L("Test no overflow")); |
|
1782 TBuf16<17> buf2=_L16("A "); |
|
1783 append16(buf2, NULL, _L16("Descriptor")); |
|
1784 test(buf2==_L16("A Descriptor")); |
|
1785 |
|
1786 test.Printf(_L("Use a non-leaving overflow handler\n")); |
|
1787 test.Next(_L("Force overflow with no conversions")); |
|
1788 TDes16IgnoreOverflow overflow2; |
|
1789 append16(buf2, &overflow2, _L16("12345678901234567")); |
|
1790 test(buf2==_L16("A Descriptor12345")); |
|
1791 |
|
1792 test.Next(_L("Force overflow with decimal conversion")); |
|
1793 buf2=_L16("A Descriptor"); |
|
1794 append16(buf2, &overflow2, _L16("%d"), 123456789); |
|
1795 test(buf2==_L16("A Descriptor")); |
|
1796 |
|
1797 test.End(); |
|
1798 } |
|
1799 |
|
1800 void testAppendFormatIgnoreOverflow() |
|
1801 { |
|
1802 test.Start(_L("Test no overflow")); |
|
1803 TBuf8<16> buf; |
|
1804 buf.AppendFormat(_L8("A Descriptor")); |
|
1805 test(buf==_L8("A Descriptor")); |
|
1806 |
|
1807 test.Next(_L("Force overflow with no conversions")); |
|
1808 TDes8IgnoreOverflow overflow; |
|
1809 buf.AppendFormat(_L8("123456789012345679"),&overflow); |
|
1810 test(buf==_L8("A Descriptor1234")); |
|
1811 |
|
1812 test.Next(_L("Force overflow with decimal conversion")); |
|
1813 buf = _L8("Symbian OS"); |
|
1814 buf.AppendFormat(_L8("%d"), &overflow, 1234567); |
|
1815 test(buf==_L8("Symbian OS")); |
|
1816 |
|
1817 test.Next(_L("Test no overflow")); |
|
1818 TBuf16<16> buf2; |
|
1819 buf2.AppendFormat(_L16("A Descriptor")); |
|
1820 test(buf2==_L16("A Descriptor")); |
|
1821 |
|
1822 test.Next(_L("Force overflow with no conversions")); |
|
1823 TDes16IgnoreOverflow overflow2; |
|
1824 buf2.AppendFormat(_L16("123456789012345679"),&overflow2); |
|
1825 test(buf2==_L16("A Descriptor1234")); |
|
1826 |
|
1827 test.Next(_L("Force overflow with decimal conversion")); |
|
1828 buf2 = _L16("Symbian OS"); |
|
1829 buf2.AppendFormat(_L16("%d"), &overflow2, 1234567); |
|
1830 test(buf2==_L16("Symbian OS")); |
|
1831 |
|
1832 test.End(); |
|
1833 |
|
1834 |
|
1835 } |
|
1836 |
|
1837 // INC061330 AV28Crit: NTT - TInt TDesC16.FindC -method is giving strange output values |
|
1838 // This test should pass with "ELangPrcChinese" locale. |
|
1839 void INC061330() |
|
1840 { |
|
1841 TLanguage defaultLang = User::Language(); |
|
1842 |
|
1843 TInt err = HAL::Set(HAL::ELanguageIndex, ELangPrcChinese); |
|
1844 test(err == KErrNone); |
|
1845 |
|
1846 TBuf<50> libraryName; |
|
1847 |
|
1848 libraryName.Format(_L("ELOCL.%02d"), ELangPrcChinese); |
|
1849 |
|
1850 //Reset the locale |
|
1851 err=UserSvr::ChangeLocale(KNullDesC); |
|
1852 test(err==KErrNone); |
|
1853 |
|
1854 //Now change to chinese locale |
|
1855 err = UserSvr::ChangeLocale(libraryName); |
|
1856 if(err==KErrNotFound) |
|
1857 { |
|
1858 test.Printf(_L("TEST CASE NOT RUN BECAUSE ELangPrcChinese LOCALE NOT FOUND!\n")); |
|
1859 HAL::Set(HAL::ELanguageIndex, defaultLang); |
|
1860 return; |
|
1861 } |
|
1862 test(err == KErrNone); |
|
1863 |
|
1864 TLanguage lang = User::Language(); |
|
1865 test(lang == ELangPrcChinese); |
|
1866 |
|
1867 TInt pos; |
|
1868 _LIT(KBuf, "hello"); |
|
1869 |
|
1870 pos = KBuf().FindC(_L("a")); |
|
1871 test(pos == KErrNotFound); |
|
1872 |
|
1873 pos = KBuf().FindC(_L("zzz")); |
|
1874 test(pos == KErrNotFound); |
|
1875 |
|
1876 pos = KBuf().FindC(_L(".")); |
|
1877 test(pos == KErrNotFound); |
|
1878 |
|
1879 pos = KBuf().FindC(_L(":")); |
|
1880 test(pos == KErrNotFound); |
|
1881 |
|
1882 pos = KBuf().FindC(_L("hela")); |
|
1883 test(pos == KErrNotFound); |
|
1884 |
|
1885 //Reset the locale |
|
1886 err=UserSvr::ChangeLocale(KNullDesC); |
|
1887 test(err==KErrNone); |
|
1888 |
|
1889 //Now revert to the original default english locale |
|
1890 libraryName.Format(_L("ELOCL.%02d"), defaultLang); |
|
1891 test(err == KErrNone); |
|
1892 err = UserSvr::ChangeLocale(libraryName); |
|
1893 test(err == KErrNone); |
|
1894 |
|
1895 lang = User::Language(); |
|
1896 test(lang == defaultLang); |
|
1897 } |
|
1898 #ifndef _DEBUG |
|
1899 #pragma warning( disable : 4702) //Unreachable code |
|
1900 #pragma warning( disable : 4710) //Function not expanded |
|
1901 #endif |
|
1902 GLDEF_C TInt E32Main() |
|
1903 // Test the TBuf type. |
|
1904 { |
|
1905 test.Title(); |
|
1906 |
|
1907 test.Start(_L("class TBuf16<0x50>")); |
|
1908 TestTBuf<TBuf16<0x50>,TText16,TPtrC16> c(0x50); |
|
1909 c.test_TBuf(); |
|
1910 |
|
1911 test.Next(_L("class TBuf8<0x50>")); |
|
1912 TestTBuf<TBuf8<0x50>,TText8,TPtrC8> b(0x50); |
|
1913 b.test_TBuf(); |
|
1914 |
|
1915 test.Next(_L("class TBuf<0x50>")); |
|
1916 TestTBuf<TBuf<0x50>,TText,TPtrC> a(0x50); |
|
1917 a.test_TBuf(); |
|
1918 |
|
1919 test.Next(_L("TReal formating")); |
|
1920 testFormat(); |
|
1921 |
|
1922 test.Next(_L("Test overflow handler")); |
|
1923 testOverflow(); |
|
1924 |
|
1925 test.Next(_L("Test ignore overflow handler")); |
|
1926 testIgnoreOverflow(); |
|
1927 |
|
1928 test.Next(_L("Test Format ignore overflow handler")); |
|
1929 testAppendFormatIgnoreOverflow(); |
|
1930 |
|
1931 test.Next(_L("INC061330")); |
|
1932 INC061330(); |
|
1933 |
|
1934 test.End(); |
|
1935 |
|
1936 return(KErrNone); |
|
1937 } |
|
1938 |
|
1939 //#pragma warning( default : 4702) |
|
1940 //#pragma warning( default : 4710) |
|
1941 |
|
1942 |