author | William Roberts <williamr@symbian.org> |
Fri, 23 Jul 2010 10:28:58 +0100 | |
changeset 224 | da1922ac85fb |
parent 109 | b3a1d9898418 |
child 231 | 75252ea6123b |
permissions | -rw-r--r-- |
0 | 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 "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-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 __VC32__ |
|
79 |
// Solve compilation problem caused by non-English locale |
|
80 |
#pragma setlocale("english") |
|
81 |
#endif |
|
82 |
||
83 |
LOCAL_D RTest test(_L("T_BUF")); |
|
84 |
||
85 |
#pragma warning(disable: 4127) // disabling warning "conditional expression is constant" |
|
86 |
#pragma warning(disable: 4310) // disabling warning "cast truncates constant value" |
|
87 |
||
88 |
#undef _TL |
|
89 |
#define _TL(a) DESTEMPLATE((S*)RTest::String(sizeof(S),(TText8*)a,(TText16*)L ## a)) |
|
90 |
#undef _TS |
|
91 |
#define _TS(a) ((const S*)RTest::String(sizeof(S),(TText8*)a,(TText16*)L ## a)) |
|
92 |
||
93 |
template<class T,class S,class DESTEMPLATE> |
|
94 |
class TestTBuf |
|
95 |
{ |
|
96 |
public: |
|
97 |
TestTBuf(TInt aLength); // Test class constructor. |
|
98 |
void Test1(); // Tests all functions of the class. |
|
99 |
void Test2(); // Tests all constructors. |
|
100 |
void Test3(); // Tests all assignment operators |
|
101 |
void Test4(); // Tests all comparison operators |
|
102 |
void Test5(); // Tests all property access |
|
103 |
void Test6(); // Tests all fill and swap |
|
104 |
void Test7(); // Tests all conversion |
|
105 |
void Test8(); // Tests all comparison |
|
106 |
void Test9(); // Tests all matching |
|
107 |
void Test10(); // Tests all locating |
|
108 |
void Test11(); // Tests all Copying |
|
109 |
void Test12(); // Tests all finding |
|
110 |
void Test13(); // Tests all basic like ops |
|
111 |
void Test14(); // Tests all formating |
|
112 |
void Test15(); // Tests all replacing |
|
113 |
void test_TBuf(); // Test all classes |
|
114 |
protected: |
|
115 |
void Test1List(T* a,T* b,...); |
|
116 |
void Test14_ReorderedParameterFormatting(TInt aDummyParameter, ...); |
|
117 |
private: |
|
118 |
TInt iMaxBufLength; |
|
119 |
}; |
|
120 |
||
121 |
void TestEq(const TDesC8& a, const TDesC8& b, TInt aLine) |
|
122 |
{ |
|
123 |
if (a!=b) |
|
124 |
{ |
|
125 |
TBuf<256> buf; |
|
126 |
test.Printf(_L("LINE %d:\n"),aLine); |
|
127 |
buf.Copy(a); |
|
128 |
test.Printf(_L("a=%S\n"),&buf); |
|
129 |
buf.Copy(b); |
|
130 |
test.Printf(_L("b=%S\n"),&buf); |
|
131 |
test(0); |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
void TestEq(const TDesC16& a, const TDesC16& b, TInt aLine) |
|
136 |
{ |
|
137 |
if (a!=b) |
|
138 |
{ |
|
139 |
test.Printf(_L("LINE %d:\n"),aLine); |
|
140 |
test.Printf(_L("a=%S\n"),&a); |
|
141 |
test.Printf(_L("b=%S\n"),&b); |
|
142 |
test(0); |
|
143 |
} |
|
144 |
} |
|
145 |
||
146 |
#define TESTEQ(a,b) TestEq((a),(b),__LINE__) |
|
147 |
||
148 |
template <class T,class S,class DESTEMPLATE> |
|
149 |
GLDEF_C TestTBuf<T,S,DESTEMPLATE>::TestTBuf(TInt aLength) |
|
150 |
// Constructor. |
|
151 |
: iMaxBufLength(aLength) |
|
152 |
{} |
|
153 |
||
154 |
template <class T,class S,class DESTEMPLATE> |
|
155 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test1List(T* a,T* b,...) |
|
156 |
// Test the format with list functions. |
|
157 |
{ |
|
158 |
VA_LIST list; |
|
159 |
VA_START(list,b); |
|
160 |
a->Format(*b,list); |
|
161 |
VA_START(list,b); |
|
162 |
a->AppendFormat(*b,list); |
|
163 |
VA_START(list,b); |
|
164 |
a->Format(_TL("%d"),list); |
|
165 |
VA_START(list,b); |
|
166 |
a->AppendFormat(_TL("%d"),list); |
|
167 |
} |
|
168 |
||
169 |
template <class T,class S,class DESTEMPLATE> |
|
170 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test1() |
|
171 |
// Tests all functions of the class. |
|
172 |
{ |
|
173 |
test.Start(_L("Constructors")); |
|
174 |
T a; |
|
175 |
T b; |
|
176 |
T c(_TL("AB")); |
|
177 |
T d(c); |
|
178 |
||
179 |
// To avoid unused warning |
|
180 |
a.Length(); |
|
181 |
b.Length(); |
|
182 |
c.Length(); |
|
183 |
d.Length(); |
|
184 |
||
185 |
test.Next(_L("Copy operators")); |
|
186 |
a=_TL("DE"); |
|
187 |
b=c; |
|
188 |
a+=_TL("DE"); |
|
189 |
b+=c; |
|
190 |
||
191 |
test.Next(_L("Comparison operators")); |
|
192 |
TInt t=(a<b); |
|
193 |
t=(a<_TL("AB")); |
|
194 |
t=(_TL("AB")<a); |
|
195 |
t=(a<=b); |
|
196 |
t=(a<=_TL("AB")); |
|
197 |
t=(_TL("AB")<=a); |
|
198 |
t=(a>b); |
|
199 |
t=(a>_TL("AB")); |
|
200 |
t=(_TL("AB")>a); |
|
201 |
t=(a>=b); |
|
202 |
t=(a>=_TL("AB")); |
|
203 |
t=(_TL("AB")>=a); |
|
204 |
t=(a==b); |
|
205 |
t=(a==_TL("AB")); |
|
206 |
t=(_TL("AB")==a); |
|
207 |
t=(a!=_TL("AB")); |
|
208 |
t=(_TL("AB")!=a); |
|
209 |
||
210 |
test.Next(_L("Property access")); |
|
211 |
a[0]='A'; |
|
212 |
a.Ptr(); |
|
213 |
TInt i=a.MaxLength()-a.Length(); |
|
214 |
i=a.Size(); |
|
215 |
a.Zero(); |
|
216 |
a.SetLength(2); |
|
217 |
||
218 |
test.Next(_L("Fill & swap")); |
|
219 |
a.Fill(' '); |
|
220 |
a.Fill(' ',iMaxBufLength); |
|
221 |
a.FillZ(); |
|
222 |
a.FillZ(iMaxBufLength); |
|
223 |
a.Swap(b); |
|
224 |
||
225 |
test.Next(_L("Conversion")); |
|
226 |
a.Fold(); |
|
227 |
a.Collate(); |
|
228 |
a.LowerCase(); |
|
229 |
a.UpperCase(); |
|
230 |
a.Capitalize(); |
|
231 |
||
232 |
test.Next(_L("Comparison")); |
|
233 |
a.Compare(b); |
|
234 |
a.Compare(_TL("AB")); |
|
235 |
a.CompareF(b); |
|
236 |
a.CompareF(_TL("AB")); |
|
237 |
a.CompareC(b); |
|
238 |
a.CompareC(_TL("AB")); |
|
239 |
||
240 |
test.Next(_L("Matching")); |
|
241 |
a.Match(b); |
|
242 |
a.Match(_TL("AB")); |
|
243 |
a.MatchF(b); |
|
244 |
a.MatchF(_TL("AB")); |
|
245 |
||
246 |
T buf(_TL("abcdef")); |
|
247 |
TInt res = buf.MatchF(_TL("abc*def")); |
|
248 |
test(res == 0); |
|
249 |
||
250 |
a.MatchC(b); |
|
251 |
a.MatchC(_TL("AB")); |
|
252 |
||
253 |
test.Next(_L("Locating")); |
|
254 |
a.Locate('A'); |
|
255 |
a.LocateF('A'); |
|
256 |
a.LocateReverse('A'); |
|
257 |
a.LocateReverseF('A'); |
|
258 |
||
259 |
test.Next(_L("Copying")); |
|
260 |
a.Copy(b); |
|
261 |
a.Copy(_TL("AB")); |
|
262 |
// a.Copy(_TL("AB"),1); |
|
263 |
a.CopyF(b); |
|
264 |
a.CopyF(_TL("AB")); |
|
265 |
a.CopyC(b); |
|
266 |
a.CopyC(_TL("AB")); |
|
267 |
a.CopyLC(b); |
|
268 |
a.CopyLC(_TL("AB")); |
|
269 |
a.CopyUC(b); |
|
270 |
a.CopyUC(_TL("AB")); |
|
271 |
a.CopyCP(b); |
|
272 |
a.CopyCP(_TL("AB")); |
|
273 |
||
274 |
test.Next(_L("Finding")); |
|
275 |
a.Find(b); |
|
276 |
a.Find(_TL("AB")); |
|
277 |
a.FindF(b); |
|
278 |
a.FindF(_TL("AB")); |
|
279 |
a.FindC(b); |
|
280 |
a.FindC(_TL("AB")); |
|
281 |
||
282 |
test.Next(_L("Basic like ops")); |
|
283 |
a.Repeat(b); |
|
284 |
a.Repeat(_TL("AB")); |
|
285 |
a.TrimLeft(); |
|
286 |
a.TrimRight(); |
|
287 |
a.Trim(); |
|
288 |
b=_TL("AA"); |
|
289 |
a.Insert(0,b); |
|
290 |
a.Delete(0,2); |
|
291 |
b = a.Left(1); |
|
292 |
b = a.Right(1); |
|
293 |
b = a.Mid(0,1); |
|
294 |
||
295 |
test.Next(_L("Formating")); |
|
296 |
a.Justify(_TL("AB"),10,ELeft,' '); |
|
297 |
a.Justify(b,10,ELeft,' '); |
|
298 |
b.Fill('A',2); |
|
299 |
a.Zero(); |
|
300 |
a.AppendJustify(_TL("AB"),10,ELeft,' '); |
|
301 |
a.AppendJustify(b,10,ELeft,' '); |
|
302 |
TInt v1=10; |
|
303 |
a.Num(v1); |
|
304 |
a.AppendNum(v1); |
|
305 |
TInt v2=10; |
|
306 |
a.Num((TUint)v2,EHex); |
|
307 |
a.AppendNum((TUint)v2,EHex); |
|
308 |
a.NumUC((TUint)v2,EHex); |
|
309 |
a.AppendNumUC((TUint)v2,EHex); |
|
310 |
TReal v3=10.0; |
|
311 |
TRealFormat ff; |
|
312 |
ff.iType=KRealFormatFixed; |
|
313 |
ff.iWidth=10; |
|
314 |
ff.iPlaces=2; |
|
315 |
ff.iPoint='.'; |
|
316 |
ff.iTriad=','; |
|
317 |
ff.iTriLen=3; |
|
318 |
a.Num(v3,ff); |
|
319 |
a.AppendNum(v3,ff); |
|
320 |
a.Format(_TL("%d"),12); |
|
321 |
a.AppendFormat(_TL("%d"),12); |
|
322 |
b=_TL("%d"); |
|
323 |
a.Format(b,12); |
|
324 |
a.AppendFormat(b,12); |
|
325 |
Test1List(&a,&b,12); |
|
326 |
||
327 |
test.Next(_L("Replacing")); |
|
328 |
a=_TL("AAC"); |
|
329 |
b=_TL("B"); |
|
330 |
a.Replace(1,1,b); |
|
331 |
test.End(); |
|
332 |
} |
|
333 |
||
334 |
template <class T,class S,class DESTEMPLATE> |
|
335 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test2() |
|
336 |
// Tests all constructors. |
|
337 |
{ |
|
338 |
test.Start(_L("Default")); |
|
339 |
T a; |
|
340 |
test(a.MaxLength()==iMaxBufLength); |
|
341 |
test(a.Length()==0); |
|
342 |
||
343 |
test.Next(_L("By length")); |
|
344 |
T b(iMaxBufLength>>1); |
|
345 |
test(b.MaxLength()==iMaxBufLength); |
|
346 |
test(b.Length()==(iMaxBufLength>>1)); |
|
347 |
||
348 |
test.Next(_L("By string")); |
|
349 |
T c(_TL("AB")); |
|
350 |
test(c.MaxLength()==iMaxBufLength); |
|
351 |
test(c.Length()==2); |
|
352 |
test(c[0]=='A'); |
|
353 |
test(c[1]=='B'); |
|
354 |
||
355 |
test.Next(_L("By buffer reference")); |
|
356 |
T d(c); |
|
357 |
test(d.MaxLength()==iMaxBufLength); |
|
358 |
test(d.Length()==2); |
|
359 |
test(d[0]=='A'); |
|
360 |
test(d[1]=='B'); |
|
361 |
test.End(); |
|
362 |
} |
|
363 |
||
364 |
template <class T,class S,class DESTEMPLATE> |
|
365 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test3() |
|
366 |
// Tests all assignment operators |
|
367 |
{ |
|
368 |
test.Start(_L("By String")); |
|
369 |
T a; |
|
370 |
a=_TL("AB"); |
|
371 |
a+=_TL("CD"); |
|
372 |
test(a.Length()==4); |
|
373 |
test(a==_TL("ABCD")); |
|
374 |
||
375 |
test.Next(_L("By buffer")); |
|
376 |
T b; |
|
377 |
b=a; |
|
378 |
b+=a; |
|
379 |
test(b.Length()==8); |
|
380 |
test(b==_TL("ABCDABCD")); |
|
381 |
// |
|
382 |
test.End(); |
|
383 |
} |
|
384 |
||
385 |
template <class T,class S,class DESTEMPLATE> |
|
386 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test4() |
|
387 |
// Test all comparison operators |
|
388 |
{ |
|
389 |
test.Start(_L("By NULL string")); |
|
390 |
T a; |
|
391 |
test(a==_TL("")); // NULL strings |
|
392 |
test(!(a!=_TL(""))); |
|
393 |
test(a<=_TL("")); |
|
394 |
test(a>=_TL("")); |
|
395 |
test(!(a<_TL(""))); |
|
396 |
test(!(a>_TL(""))); |
|
397 |
test(_TL("")==a); |
|
398 |
test(!(_TL("")!=a)); |
|
399 |
test(_TL("")<=a); |
|
400 |
test(_TL("")>=a); |
|
401 |
test(!(_TL("")<a)); |
|
402 |
test(!(_TL("")>a)); |
|
403 |
||
404 |
test.Next(_L("By string or buffer")); |
|
405 |
a=_TL("abc"); |
|
406 |
test(a==_TL("abc")); // == |
|
407 |
test(!(a==_TL("xyz"))); |
|
408 |
test(!(a==_TL("aa"))); |
|
409 |
test(_TL("abc")==a); |
|
410 |
test(!(_TL("xyz")==a)); |
|
411 |
test(!(_TL("aa")==a)); |
|
412 |
test(a!=_TL("xyz")); // != |
|
413 |
test(!(a!=_TL("abc"))); |
|
414 |
test(a!=_TL("aa")); |
|
415 |
test(_TL("xyz")!=a); |
|
416 |
test(!(_TL("abc")!=a)); |
|
417 |
test(_TL("aa")!=a); |
|
418 |
test(a<_TL("x")); // < |
|
419 |
test(!(a<_TL("abc"))); |
|
420 |
test(!(a<_TL("aa"))); |
|
421 |
test(_TL("aa")<a); |
|
422 |
test(!(_TL("abc")<a)); |
|
423 |
test(!(_TL("xyz")<a)); |
|
424 |
test(a>_TL("aa")); // > |
|
425 |
test(!(a>_TL("abc"))); |
|
426 |
test(!(a>_TL("xyz"))); |
|
427 |
test(_TL("xyz")>a); |
|
428 |
test(!(_TL("abc")>a)); |
|
429 |
test(!(_TL("aa")>a)); |
|
430 |
test(a>=_TL("abc")); // >= |
|
431 |
test(!(a>=_TL("xyz"))); |
|
432 |
test(a>=_TL("aa")); |
|
433 |
test(_TL("abc")>=a); |
|
434 |
test(!(_TL("aaa")>=a)); |
|
435 |
test(_TL("xyz")>=a); |
|
436 |
test(a<=_TL("abc")); // <= |
|
437 |
test(!(a<=_TL("aa"))); |
|
438 |
test(a<=_TL("xyz")); |
|
439 |
test(_TL("abc")<=a); |
|
440 |
test(!(_TL("xyz")<=a)); |
|
441 |
test(_TL("aa")<=a); |
|
442 |
||
443 |
test.Next(_L("By special characters")); |
|
444 |
a=_TL("!@#$%^&*()"); |
|
445 |
test(a==_TL("!@#$%^&*()")); |
|
446 |
test.End(); |
|
447 |
} |
|
448 |
||
449 |
template <class T,class S,class DESTEMPLATE> |
|
450 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test5() |
|
451 |
// Test all property access |
|
452 |
{ |
|
453 |
test.Start(_L("Length and Size")); |
|
454 |
T a; |
|
455 |
TInt maxLength=a.MaxLength(); |
|
456 |
TInt i; |
|
457 |
for (i=0;i<maxLength;i++) |
|
458 |
{ |
|
459 |
test(a.Length()==i); // Length |
|
460 |
test(a.Size()==(TInt)(sizeof(S)*i)); // Size |
|
461 |
a.AppendNum(i%10); |
|
462 |
} |
|
463 |
const T b=a; |
|
464 |
for (i=0;i<maxLength;i++) |
|
465 |
{ |
|
466 |
test(a[i]=='0'+(i%10)); // At |
|
467 |
test(b[i]=='0'+(i%10)); // AtConst |
|
468 |
} |
|
469 |
test(a[0]==*a.Ptr()); //Ptr |
|
470 |
a.SetLength(0); // SetLength |
|
471 |
test(a.Length()==0); |
|
472 |
a.SetLength(maxLength-1); |
|
473 |
test(a.Length()==maxLength-1); |
|
474 |
a.Zero(); // Null |
|
475 |
test(a.Length()==0); |
|
476 |
test.End(); |
|
477 |
} |
|
478 |
||
479 |
template <class T,class S,class DESTEMPLATE> |
|
480 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test6() |
|
481 |
// Fill and Swap |
|
482 |
{ |
|
483 |
test.Start(_L("Fill and Swap")); |
|
484 |
T a,b; |
|
485 |
TChar chr; |
|
486 |
TInt j; |
|
487 |
TInt maxLength=a.MaxLength(); |
|
488 |
for (TInt i=0;i<maxLength;i++) |
|
489 |
{ |
|
490 |
chr=(i%10)+'0'; |
|
491 |
a.SetLength(i); |
|
492 |
a.Fill(chr); // Fill(TChar) |
|
493 |
b.Swap(a); |
|
494 |
test(b.Length()==i); // Swap |
|
495 |
j=0; |
|
496 |
while (j<i) |
|
497 |
test(b[j++]=='0'+(i%10)); |
|
498 |
b.FillZ(); // FillZ() |
|
499 |
a.Swap(b); |
|
500 |
j=0; |
|
501 |
while (j<i) |
|
502 |
test(a[j++]==0); |
|
503 |
a.Fill(chr,i); // Fill(TChar,TUint) |
|
504 |
j=0; |
|
505 |
while (j<i) |
|
506 |
test(a[j++]=='0'+(i%10)); |
|
507 |
a.FillZ(i); // FillZ(TUint) |
|
508 |
j=0; |
|
509 |
while (j<i) |
|
510 |
test(a[j++]==0); |
|
511 |
} |
|
512 |
test.End(); |
|
513 |
} |
|
514 |
||
515 |
template <class T,class S,class DESTEMPLATE> |
|
516 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test7() |
|
517 |
// Conversion operators |
|
518 |
{ |
|
519 |
test.Start(_L("Fold, collate ...")); |
|
520 |
T a; |
|
521 |
T b; |
|
522 |
a=_TL("abc AbC"); |
|
523 |
b=_TL("ABC ABC"); |
|
524 |
a.Fold(); |
|
525 |
b.Fold(); |
|
526 |
test(a==b); |
|
527 |
a=_TL("abc AbC"); |
|
528 |
b=_TL("ABC ABC"); |
|
529 |
a.Collate(); |
|
530 |
b.Collate(); |
|
531 |
test(a==b); |
|
532 |
a.LowerCase(); |
|
533 |
test(a==_TL("abc abc")); |
|
534 |
a.Capitalize(); |
|
535 |
test(a==_TL("Abc abc")); |
|
536 |
a.UpperCase(); |
|
537 |
test(a==_TL("ABC ABC")); |
|
538 |
test.End(); |
|
539 |
} |
|
540 |
||
541 |
template <class T,class S,class DESTEMPLATE> |
|
542 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test8() |
|
543 |
// Comparison |
|
544 |
{ |
|
545 |
test.Start(_L("By string")); |
|
546 |
T a; |
|
547 |
a=_TL("abc AbC"); |
|
548 |
test(a.Compare(_TL("abc AbC"))==0); |
|
549 |
test(a.CompareF(_TL("ABC aBc"))==0); |
|
550 |
test(a.Compare(_TL("xyz"))!=0); |
|
551 |
test(a.CompareC(_TL("xyz"))!=0); |
|
552 |
test(a.CompareF(_TL("xyz"))!=0); |
|
553 |
||
554 |
test.Next(_L("By buffer")); |
|
555 |
T b; |
|
556 |
T c; |
|
557 |
a=_TL("abc AbC"); |
|
558 |
b=_TL("abc AbC"); |
|
559 |
c=_TL("xyz"); |
|
560 |
test(a.Compare(b)==0); |
|
561 |
test(a.Compare(c)!=0); |
|
562 |
b=_TL("ABC aBc"); |
|
563 |
test(a.CompareC(c)!=0); |
|
564 |
test(a.CompareF(b)==0); |
|
565 |
test(a.CompareF(c)!=0); |
|
566 |
||
567 |
test.End(); |
|
568 |
} |
|
569 |
||
570 |
template <class T,class S,class DESTEMPLATE> |
|
571 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test9() |
|
572 |
// Matching (need to test explicit result as error KErrNotFound = KMaxTUint |
|
573 |
// and so registers as TRUE. (test parameter is TUint) ) |
|
574 |
{ |
|
575 |
test.Start(_L("By string")); |
|
576 |
T a; |
|
577 |
a=_TL("abc AbC"); |
|
578 |
test(a.Match(_TL("abc AbC"))==0); |
|
579 |
test(a.MatchC(_TL("ABC aBc"))==0); |
|
580 |
test(a.MatchF(_TL("ABC aBc"))==0); |
|
581 |
test(a.Match(_TL("xyz"))==KErrNotFound); |
|
582 |
test(a.MatchC(_TL("xyz"))==KErrNotFound); |
|
583 |
test(a.MatchF(_TL("xyz"))==KErrNotFound); |
|
584 |
||
585 |
test.Next(_L("By buffer")); |
|
586 |
T b; |
|
587 |
T c; |
|
588 |
a=_TL("abc AbC"); |
|
589 |
b=_TL("abc AbC"); |
|
590 |
c=_TL("xyz"); |
|
591 |
test(a.Match(b)==0); |
|
592 |
test(a.Match(c)==KErrNotFound); |
|
593 |
b=_TL("ABC aBc"); |
|
594 |
test(a.MatchC(b)==0); |
|
595 |
test(a.MatchC(c)==KErrNotFound); |
|
596 |
test(a.MatchF(b)==0); |
|
597 |
test(a.MatchF(c)==KErrNotFound); |
|
598 |
||
599 |
test.Next(_L("Wildcards")); |
|
600 |
a=_TL("abcxyz"); |
|
601 |
test(a.Match(_TL("abc*"))==0); |
|
602 |
test(a.Match(_TL("abw*"))==KErrNotFound); |
|
603 |
a=_TL("abcdefg"); |
|
604 |
test(a.Match(_TL("a*fg"))==0); |
|
605 |
test(a.Match(_TL("a*f"))==KErrNotFound); |
|
606 |
test(a.Match(_TL("abc*fgh"))==KErrNotFound); |
|
607 |
a=_TL("abcdef"); |
|
608 |
test(a.Match(_TL("abc?ef"))==0); |
|
609 |
test(a.Match(_TL("abc?xf"))==KErrNotFound); |
|
610 |
||
611 |
a=_TL("a(01)"); |
|
612 |
test(a.Match(_TL("*(01)"))==1); |
|
613 |
test(a.Match(_TL("?(01)"))==0); |
|
614 |
test(a.Match(_TL("?(*)"))==0); |
|
615 |
test(a.Match(_TL("?(**)"))==0); |
|
616 |
||
617 |
test(a.Match(_TL("?(\?\?)"))==0); |
|
618 |
test(a.Match(_TL("*(*)"))>=0); |
|
619 |
test(a.Match(_TL("*(0?)"))>=0); |
|
620 |
test(a.Match(_TL("a(\?\?)"))==0); |
|
621 |
test(a.Match(_TL("*(\?\?)"))>=0); |
|
622 |
||
623 |
test.Next(_L("wild cards with collated comparison")); |
|
624 |
a = _TL("abcdefghijkl"); |
|
625 |
test(a.MatchC(_TL("abc*")) == 0); |
|
626 |
test(a.MatchC(_TL("abc")) == KErrNotFound); |
|
627 |
test(a.MatchC(_TL("xyz")) == KErrNotFound); |
|
628 |
test(a.MatchC(_TL("*def")) == KErrNotFound); |
|
629 |
test(a.MatchC(_TL("*def*")) == 3); |
|
630 |
test(a.MatchC(_TL("*d?f*")) == 3); |
|
631 |
test(a.MatchC(_TL("a*kl")) == 0); |
|
632 |
test(a.MatchC(_TL("*e*?l")) == 4); |
|
633 |
test(a.MatchC(_TL("abc*dEf*")) == 0); |
|
634 |
||
635 |
||
636 |
T candidate; |
|
637 |
T search; |
|
638 |
||
639 |
candidate = _TL(""); |
|
640 |
search = _TL("**"); |
|
641 |
test(candidate.MatchC(search) == 0); |
|
642 |
||
643 |
candidate = _TL(""); |
|
644 |
search = _TL("*"); |
|
645 |
test(candidate.MatchC(search) == 0); |
|
646 |
||
647 |
candidate = _TL("abcd"); |
|
648 |
search = _TL("*abc*cd"); |
|
649 |
test(candidate.MatchC(search) == KErrNotFound); |
|
650 |
||
651 |
if (sizeof(S) == 2) |
|
652 |
{ |
|
653 |
test.Next(_L("Unicode MatchC and FindC treat base+accent as equal to composed character")); |
|
654 |
TPtrC p = _L("te\x302te"); |
|
655 |
test(p.MatchC(_L("t\xeate")) == 0); |
|
656 |
test(p.FindC(_L("t\xeate")) == 0); |
|
657 |
} |
|
658 |
||
659 |
test.End(); |
|
660 |
} |
|
661 |
||
662 |
template <class T,class S,class DESTEMPLATE> |
|
663 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test10() |
|
664 |
// Locating |
|
665 |
{ |
|
666 |
T a; |
|
667 |
TChar b; |
|
668 |
||
669 |
test.Start(_L("First Char")); |
|
670 |
b='a'; |
|
671 |
a=_TL("axaxa"); |
|
672 |
test(a.Locate(b)==0); |
|
673 |
test(a.LocateF(b)==0); |
|
674 |
test(a.LocateReverse(b)==4); |
|
675 |
test(a.LocateReverseF(b)==4); |
|
676 |
||
677 |
test.Next(_L("Middle Char")); |
|
678 |
a=_TL("xaxa"); |
|
679 |
test(a.Locate(b)==1); |
|
680 |
test(a.LocateF(b)==1); |
|
681 |
a=_TL("axax"); |
|
682 |
test(a.LocateReverse(b)==2); |
|
683 |
test(a.LocateReverseF(b)==2); |
|
684 |
||
685 |
test.Next(_L("Last Char")); |
|
686 |
a=_TL("xxa"); |
|
687 |
test(a.Locate(b)==2); |
|
688 |
test(a.LocateF(b)==2); |
|
689 |
a=_TL("axx"); |
|
690 |
test(a.LocateReverse(b)==0); |
|
691 |
test(a.LocateReverseF(b)==0); |
|
692 |
||
693 |
test.Next(_L("Test for failure of locate")); |
|
694 |
a=_TL("xxx"); |
|
695 |
test(a.Locate(b)==KErrNotFound); |
|
696 |
test(a.LocateF(b)==KErrNotFound); |
|
697 |
test(a.LocateReverse(b)==KErrNotFound); |
|
698 |
test(a.LocateReverseF(b)==KErrNotFound); |
|
699 |
||
700 |
test.End(); |
|
701 |
} |
|
702 |
||
703 |
template <class T,class S,class DESTEMPLATE> |
|
704 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test11() |
|
705 |
// Copying |
|
706 |
{ |
|
707 |
T a, b; |
|
708 |
||
709 |
test.Start(_L("By String")); |
|
710 |
a.Copy(_TL("abc")); |
|
711 |
test(a.Length()==3); |
|
712 |
test(a==_TL("abc")); |
|
713 |
a.CopyF(_TL("abc")); |
|
714 |
test(a.Length()==3); |
|
715 |
b.CopyF(_TL("ABC")); |
|
716 |
test(a==b); |
|
717 |
a.CopyLC(_TL("AbC")); |
|
718 |
test(a==_TL("abc")); |
|
719 |
test(a.Length()==3); |
|
720 |
a.CopyC(_TL("abc")); |
|
721 |
b.CopyC(_TL("ABC")); |
|
722 |
test(a==b); |
|
723 |
test(a.Length()==3); |
|
724 |
a.CopyCP(_TL("abc")); |
|
725 |
test(a==_TL("Abc")); |
|
726 |
test(a.Length()==3); |
|
727 |
a.CopyUC(_TL("aBc")); |
|
728 |
test(a==_TL("ABC")); |
|
729 |
test(a.Length()==3); |
|
730 |
// a.Copy(_TL("abc"),3); |
|
731 |
// test(a==_TL("abc")); |
|
732 |
// test(a.Length()==3); |
|
733 |
// a.Copy(_TL("abcd"),3); |
|
734 |
// test(a==_TL("abc")); |
|
735 |
// test(a.Length()==3); |
|
736 |
||
737 |
test.Next(_L("By buffer")); |
|
738 |
b=_TL("abc"); |
|
739 |
a.Copy(b); |
|
740 |
test(a==_TL("abc")); |
|
741 |
test(a.Length()==3); |
|
742 |
a=_TL(""); |
|
743 |
a.CopyF(b); |
|
744 |
b.CopyF(_TL("ABC")); |
|
745 |
test(a==b); |
|
746 |
test(a.Length()==3); |
|
747 |
a=_TL(""); |
|
748 |
b=_TL("AbC"); |
|
749 |
a.CopyLC(b); |
|
750 |
test(a==_TL("abc")); |
|
751 |
test(a.Length()==3); |
|
752 |
a=_TL(""); |
|
753 |
b=_TL("abC"); |
|
754 |
a.CopyC(b); |
|
755 |
b.CopyC(_TL("ABC")); |
|
756 |
test(a==b); |
|
757 |
test(a.Length()==3); |
|
758 |
a=_TL(""); |
|
759 |
b=_TL("abC"); |
|
760 |
a.CopyCP(b); |
|
761 |
test(a==_TL("Abc")); |
|
762 |
test(a.Length()==3); |
|
763 |
a=_TL(""); |
|
764 |
b=_TL("aBc"); |
|
765 |
a.CopyUC(b); |
|
766 |
test(a.Length()==3); |
|
767 |
test(a==_TL("ABC")); |
|
768 |
||
769 |
test.End(); |
|
770 |
} |
|
771 |
||
772 |
||
773 |
template <class T,class S,class DESTEMPLATE> |
|
774 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test12() |
|
775 |
// Finding |
|
776 |
{ |
|
777 |
test.Start(_L("By String")); |
|
778 |
T a,b; |
|
779 |
a=_TL("abccef"); |
|
780 |
test(a.Find(_TL(""))==0); |
|
781 |
test(a.Find(_TL("abc"))==0); |
|
782 |
test(a.Find(_TL("cce"))==2); |
|
783 |
test(a.Find(_TL("cef"))==3); |
|
784 |
test(a.Find(_TL("efg"))==KErrNotFound); |
|
785 |
test(a.Find(_TL("xxx"))==KErrNotFound); |
|
786 |
test(a.FindF(_TL(""))==0); |
|
787 |
test(a.FindF(_TL("AbC"))==0); |
|
788 |
test(a.FindF(_TL("CcE"))==2); |
|
789 |
test(a.FindF(_TL("CeF"))==3); |
|
790 |
test(a.FindF(_TL("efg"))==KErrNotFound); |
|
791 |
test(a.FindF(_TL("xxx"))==KErrNotFound); |
|
792 |
test(a.FindC(_TL(""))==0); |
|
793 |
test(a.FindC(_TL("aBc"))==0); |
|
794 |
test(a.FindC(_TL("cce"))==2); |
|
795 |
test(a.FindC(_TL("cEf"))==3); |
|
796 |
test(a.FindC(_TL("efg"))==KErrNotFound); |
|
797 |
test(a.FindC(_TL("xxx"))==KErrNotFound); |
|
798 |
||
799 |
test.Next(_L("By buffer")); |
|
800 |
test(a.Find(b)==0); |
|
801 |
test(a.FindF(b)==0); |
|
802 |
test(a.FindC(b)==0); |
|
803 |
b=_TL("xxx"); |
|
804 |
test(a.Find(b)==KErrNotFound); |
|
805 |
test(a.FindF(b)==KErrNotFound); |
|
806 |
test(a.FindC(b)==KErrNotFound); |
|
807 |
b=_TL("efg"); |
|
808 |
test(a.Find(b)==KErrNotFound); |
|
809 |
test(a.FindF(b)==KErrNotFound); |
|
810 |
test(a.FindC(b)==KErrNotFound); |
|
811 |
b=_TL("abc"); |
|
812 |
test(a.Find(b)==0); |
|
813 |
b=_TL("cce"); |
|
814 |
test(a.Find(b)==2); |
|
815 |
b=_TL("cef"); |
|
816 |
test(a.Find(b)==3); |
|
817 |
b=_TL("AbC"); |
|
818 |
test(a.FindF(b)==0); |
|
819 |
b=_TL("CcE"); |
|
820 |
test(a.FindF(b)==2); |
|
821 |
b=_TL("CeF"); |
|
822 |
test(a.FindF(b)==3); |
|
823 |
b=_TL("aBc"); |
|
824 |
test(a.FindC(b)==0); |
|
825 |
b=_TL("cCe"); |
|
826 |
test(a.FindC(b)==2); |
|
827 |
b=_TL("cEf"); |
|
828 |
test(a.FindC(b)==3); |
|
829 |
||
830 |
test.End(); |
|
831 |
} |
|
832 |
||
833 |
template <class T,class S,class DESTEMPLATE> |
|
834 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test13() |
|
835 |
// Basic like ops |
|
836 |
{ |
|
837 |
test.Start(_L("Repeat, trim, insert and delete")); |
|
838 |
T a,b; |
|
839 |
TInt max=a.MaxLength(); |
|
840 |
b=_TL("abc"); |
|
841 |
a.Repeat(_TL("abc")); |
|
842 |
test(a==_TL("")); |
|
843 |
a.Repeat(b); |
|
844 |
test(a==_TL("")); |
|
845 |
for (TInt j=1;j<max;j++) // ?? Cannot SetLength = MaxLength |
|
846 |
{ |
|
847 |
a.SetLength(j); |
|
848 |
a.Repeat(_TL("abc")); |
|
849 |
TInt i; |
|
850 |
for (i=0;i<j;i++) |
|
851 |
test(a[i]==b[i%3]); |
|
852 |
a=_TL(""); |
|
853 |
a.SetLength(j); |
|
854 |
a.Repeat(b); |
|
855 |
for (i=0;i<j;i++) |
|
856 |
test(a[i]==b[i%3]); |
|
857 |
a=_TL(""); |
|
858 |
} |
|
859 |
a=_TL("\t\n ab \t\n "); |
|
860 |
a.TrimLeft(); |
|
861 |
test(a==_TL("ab \t\n ")); |
|
862 |
test(a.Length()==6); |
|
863 |
a=_TL("\t\n ab \t\n "); |
|
864 |
a.TrimRight(); |
|
865 |
test(a==_TL("\t\n ab")); |
|
866 |
test(a.Length()==6); |
|
867 |
a=_TL(" \t\n ab \t \n"); |
|
868 |
a.Trim(); |
|
869 |
test(a==_TL("ab")); |
|
870 |
a.Trim(); |
|
871 |
test(a==_TL("ab")); |
|
872 |
a=_TL("abc"); |
|
873 |
b=_TL("123"); |
|
874 |
a.Insert(1,b); |
|
875 |
test(a==_TL("a123bc")); |
|
876 |
test(a.Length()==6); |
|
877 |
b=_TL(""); |
|
878 |
a.Insert(4,b); |
|
879 |
test(a==_TL("a123bc")); |
|
880 |
test(a.Length()==6); |
|
881 |
a.Insert(0,b); |
|
882 |
test(a==_TL("a123bc")); |
|
883 |
test(a.Length()==6); |
|
884 |
a.Delete(1,3); |
|
885 |
test(a==_TL("abc")); |
|
886 |
test(a.Length()==3); |
|
887 |
a.Delete(0,3); |
|
888 |
test(a==_TL("")); |
|
889 |
test(a.Length()==0); |
|
890 |
||
891 |
test.Next(_L("TrimAll")); |
|
892 |
a=_TL(""); |
|
893 |
a.TrimAll(); |
|
894 |
test(a==_TL("")); |
|
895 |
a=_TL(" "); |
|
896 |
a.TrimAll(); |
|
897 |
test(a==_TL("")); |
|
898 |
a=_TL(" "); |
|
899 |
a.TrimAll(); |
|
900 |
test(a==_TL("")); |
|
901 |
a=_TL(" ab cd ef g"); |
|
902 |
a.TrimAll(); |
|
903 |
test(a==_TL("ab cd ef g")); |
|
904 |
a=_TL("abcdef"); |
|
905 |
a.TrimAll(); |
|
906 |
test(a==_TL("abcdef")); |
|
907 |
a=_TL("a b\t cd\t\tef"); |
|
908 |
a.TrimAll(); |
|
909 |
test(a==_TL("a b\tcd\tef")); |
|
910 |
a=_TL("abcdef \t ghijk"); |
|
911 |
a.TrimAll(); |
|
912 |
test(a==_TL("abcdef ghijk")); |
|
913 |
a=_TL("abcdef g"); |
|
914 |
a.TrimAll(); |
|
915 |
test(a==_TL("abcdef g")); |
|
916 |
a=_TL("ab cd ef gh ij"); |
|
917 |
a.TrimAll(); |
|
918 |
test(a==_TL("ab cd ef gh ij")); |
|
919 |
a=_TL("a b c defg h i jk l mno pqr stu vw xyz"); |
|
920 |
a.TrimAll(); |
|
921 |
test(a==_TL("a b c defg h i jk l mno pqr stu vw xyz")); |
|
922 |
||
923 |
test.Next(_L("Right, Left and Mid")); |
|
924 |
a=_TL("abcdef"); |
|
925 |
b = a.Left(3); |
|
926 |
test(b==_TL("abc")); |
|
927 |
test(b.Length()==3); |
|
928 |
b = a.Right(3); |
|
929 |
test(b==_TL("def")); |
|
930 |
b = a.Mid(2); |
|
931 |
test(b==_TL("cdef")); |
|
932 |
test(b.Length()==4); |
|
933 |
b = a.Left(2); |
|
934 |
test(b==_TL("ab")); |
|
935 |
test(b.Length()==2); |
|
936 |
b = a.Right(2); |
|
937 |
test(b==_TL("ef")); |
|
938 |
b = a.Mid(2,1); |
|
939 |
test(b==_TL("c")); |
|
940 |
test(b.Length()==1); |
|
941 |
b = a.Left(6); |
|
942 |
test(b==_TL("abcdef")); |
|
943 |
test(b.Length()==6); |
|
944 |
b=_TL(""); |
|
945 |
b.SetLength(4); |
|
946 |
b = a.Right(6); |
|
947 |
test(b==_TL("abcdef")); |
|
948 |
test(b.Length()==6); |
|
949 |
a = a.Left(6); |
|
950 |
test(a==_TL("abcdef")); |
|
951 |
b=_TL(""); |
|
952 |
b = a.Mid(0,6); |
|
953 |
test(b==_TL("abcdef")); |
|
954 |
test.End(); |
|
955 |
} |
|
956 |
||
957 |
template <class T,class S,class DESTEMPLATE> |
|
958 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test14() |
|
959 |
// Formating operations |
|
960 |
{ |
|
961 |
test.Start(_L("Justify")); |
|
962 |
T a,b,d; |
|
963 |
TInt aWidth; |
|
964 |
TChar c; |
|
965 |
a=_TL("wxyz"); |
|
966 |
b=_TL("abc"); |
|
967 |
d=_TL("linearisation"); |
|
968 |
const S* pD=_TS("299792458"); |
|
969 |
c='x'; |
|
970 |
aWidth=KDefaultJustifyWidth; // Left justified, Default width |
|
971 |
a.Justify(b,aWidth,ELeft,c); |
|
972 |
test(a==b); |
|
973 |
test(a.Length()==3); |
|
974 |
a.AppendJustify(b,aWidth,ELeft,c); |
|
975 |
test(a==_TL("abcabc")); |
|
976 |
test(a.Length()==6); |
|
977 |
aWidth=1; // Width < String length |
|
978 |
a.Justify(b,aWidth,ELeft,c); |
|
979 |
test(a==_TL("a")); |
|
980 |
test(a.Length()==1); |
|
981 |
a.AppendJustify(b,aWidth,ELeft,c); |
|
982 |
test(a==_TL("aa")); |
|
983 |
test(a.Length()==2); |
|
984 |
aWidth=5; // Width > String length |
|
985 |
a.Justify(b,aWidth,ELeft,c); |
|
986 |
test(a==_TL("abcxx")); |
|
987 |
test(a.Length()==5); |
|
988 |
a.AppendJustify(b,aWidth,ELeft,c); |
|
989 |
test(a==_TL("abcxxabcxx")); |
|
990 |
test(a.Length()==10); |
|
991 |
||
992 |
aWidth=KDefaultJustifyWidth; // Right justified, Default width |
|
993 |
a.Justify(b,aWidth,ERight,c); |
|
994 |
test(a==b); |
|
995 |
test(a.Length()==3); |
|
996 |
a.AppendJustify(b,aWidth,ERight,c); |
|
997 |
test(a==_TL("abcabc")); |
|
998 |
test(a.Length()==6); |
|
999 |
aWidth=1; // Right justified, Width < String length |
|
1000 |
a.Justify(b,aWidth,ERight,c); |
|
1001 |
test(a==_TL("a")); |
|
1002 |
test(a.Length()==1); |
|
1003 |
a.AppendJustify(b,aWidth,ERight,c); |
|
1004 |
test(a==_TL("aa")); |
|
1005 |
test(a.Length()==2); |
|
1006 |
aWidth=5; // Right justified, width > String length |
|
1007 |
a.Justify(b,aWidth,ERight,c); |
|
1008 |
test(a==_TL("xxabc")); |
|
1009 |
test(a.Length()==5); |
|
1010 |
a.AppendJustify(b,aWidth,ERight,c); |
|
1011 |
test(a==_TL("xxabcxxabc")); |
|
1012 |
test(a.Length()==10); |
|
1013 |
||
1014 |
aWidth=KDefaultJustifyWidth; // Center justified, Default width |
|
1015 |
a.Justify(b,aWidth,ECenter,c); |
|
1016 |
test(a==b); |
|
1017 |
test(a.Length()==3); |
|
1018 |
a.AppendJustify(b,aWidth,ECenter,c); |
|
1019 |
test(a==_TL("abcabc")); |
|
1020 |
test(a.Length()==6); |
|
1021 |
aWidth=1; // Centre justified, width < String length |
|
1022 |
a.Justify(b,aWidth,ECenter,c); |
|
1023 |
test(a==_TL("a")); |
|
1024 |
test(a.Length()==1); |
|
1025 |
a.AppendJustify(b,aWidth,ECenter,c); |
|
1026 |
test(a==_TL("aa")); |
|
1027 |
test(a.Length()==2); |
|
1028 |
aWidth=5; // Centre justified, width > String length |
|
1029 |
a.Justify(b,aWidth,ECenter,c); |
|
1030 |
test(a==_TL("xabcx")); |
|
1031 |
test(a.Length()==5); |
|
1032 |
a.AppendJustify(b,aWidth,ECenter,c); |
|
1033 |
test(a==_TL("xabcxxabcx")); |
|
1034 |
test(a.Length()==10); |
|
1035 |
||
1036 |
test.Next(_L("Num")); |
|
1037 |
TInt j=-2147483647-1; |
|
1038 |
a.Num(j); |
|
1039 |
test(a==_TL("-2147483648")); |
|
1040 |
test(a.Length()==11); |
|
1041 |
TUint i=2147483648u; |
|
1042 |
a.Num(i); |
|
1043 |
test(a==_TL("2147483648")); |
|
1044 |
test(a.Length()==10); |
|
1045 |
if (a.MaxLength()>31) |
|
1046 |
{ |
|
1047 |
a.Num(i,EBinary); |
|
1048 |
test(a==_TL("10000000000000000000000000000000")); |
|
1049 |
test(a.Length()==32); |
|
1050 |
a=_TL(""); |
|
1051 |
a.NumUC(i,EBinary); |
|
1052 |
test(a==_TL("10000000000000000000000000000000")); |
|
1053 |
test(a.Length()==32); |
|
1054 |
} |
|
1055 |
i=31; |
|
1056 |
a.Num(i,EBinary); |
|
1057 |
test(a==_TL("11111")); |
|
1058 |
test(a.Length()==5); |
|
1059 |
a=_TL(""); |
|
1060 |
a.NumUC(i,EBinary); |
|
1061 |
test(a==_TL("11111")); |
|
1062 |
test(a.Length()==5); |
|
1063 |
i=2147483648u; |
|
1064 |
a.Num(i,EOctal); |
|
1065 |
test(a==_TL("20000000000")); |
|
1066 |
test(a.Length()==11); |
|
1067 |
a=_TL(""); |
|
1068 |
a.NumUC(i,EOctal); |
|
1069 |
test(a==_TL("20000000000")); |
|
1070 |
test(a.Length()==11); |
|
1071 |
a.Num(i,EDecimal); |
|
1072 |
test(a==_TL("2147483648")); |
|
1073 |
test(a.Length()==10); |
|
1074 |
a=_TL(""); |
|
1075 |
a.NumUC(i,EDecimal); |
|
1076 |
test(a==_TL("2147483648")); |
|
1077 |
test(a.Length()==10); |
|
1078 |
a.Num(i,EHex); |
|
1079 |
test(a==_TL("80000000")); |
|
1080 |
test(a.Length()==8); |
|
1081 |
a=_TL(""); |
|
1082 |
a.NumUC(i,EHex); |
|
1083 |
test(a==_TL("80000000")); |
|
1084 |
test(a.Length()==8); |
|
1085 |
i=0; |
|
1086 |
a.Num(i); |
|
1087 |
test(a==_TL("0")); |
|
1088 |
test(a.Length()==1); |
|
1089 |
a=_TL("abc"); |
|
1090 |
a.Num(i,EBinary); |
|
1091 |
test(a==_TL("0")); |
|
1092 |
test(a.Length()==1); |
|
1093 |
a=_TL("abc"); |
|
1094 |
a.NumUC(i,EBinary); |
|
1095 |
test(a==_TL("0")); |
|
1096 |
test(a.Length()==1); |
|
1097 |
a=_TL("abc"); |
|
1098 |
a.Num(i,EOctal); |
|
1099 |
test(a==_TL("0")); |
|
1100 |
test(a.Length()==1); |
|
1101 |
a=_TL(""); |
|
1102 |
a.NumUC(i,EOctal); |
|
1103 |
test(a==_TL("0")); |
|
1104 |
test(a.Length()==1); |
|
1105 |
a=_TL("abc"); |
|
1106 |
a.Num(i,EDecimal); |
|
1107 |
test(a==_TL("0")); |
|
1108 |
test(a.Length()==1); |
|
1109 |
a=_TL(""); |
|
1110 |
a.NumUC(i,EDecimal); |
|
1111 |
test(a==_TL("0")); |
|
1112 |
test(a.Length()==1); |
|
1113 |
a=_TL("abc"); |
|
1114 |
a.Num(i,EHex); |
|
1115 |
test(a==_TL("0")); |
|
1116 |
test(a.Length()==1); |
|
1117 |
a=_TL(""); |
|
1118 |
a.NumUC(i,EHex); |
|
1119 |
test(a==_TL("0")); |
|
1120 |
test(a.Length()==1); |
|
1121 |
// TInt i=a.Num(6.2,format); NOT IMPLEMENTED |
|
1122 |
a.AppendNum(j); |
|
1123 |
test(a==_TL("0-2147483648")); |
|
1124 |
test(a.Length()==12); |
|
1125 |
a=_TL("abc"); |
|
1126 |
i=4294967295u; |
|
1127 |
a.AppendNum(i); |
|
1128 |
test(a==_TL("abc4294967295")); |
|
1129 |
test(a.Length()==13); |
|
1130 |
j=2147483647; |
|
1131 |
a=_TL("abc"); |
|
1132 |
a.AppendNum(j); |
|
1133 |
test(a==_TL("abc2147483647")); |
|
1134 |
test(a.Length()==13); |
|
1135 |
a=_TL("a"); |
|
1136 |
i=180150000; |
|
1137 |
if (a.MaxLength()>28) |
|
1138 |
{ |
|
1139 |
a.AppendNum(i,EBinary); |
|
1140 |
test(a==_TL("a1010101111001101111011110000")); |
|
1141 |
test(a.Length()==29); |
|
1142 |
} |
|
1143 |
a=_TL("a"); |
|
1144 |
a.AppendNum(15,EBinary); |
|
1145 |
test(a==_TL("a1111")); |
|
1146 |
test(a.Length()==5); |
|
1147 |
a=_TL("a"); |
|
1148 |
a.AppendNum(i,EDecimal); |
|
1149 |
test(a==_TL("a180150000")); |
|
1150 |
test(a.Length()==10); |
|
1151 |
a=_TL("a"); |
|
1152 |
a.AppendNum(i,EOctal); |
|
1153 |
test(a==_TL("a1257157360")); |
|
1154 |
test(a.Length()==11); |
|
1155 |
a=_TL("a"); |
|
1156 |
a.AppendNumUC(i,EHex); |
|
1157 |
test(a==_TL("aABCDEF0")); |
|
1158 |
test(a.Length()==8); |
|
1159 |
// i=a.AppendNum(6.32, format); NOT IMPLEMENTED |
|
1160 |
||
1161 |
test.Next(_L("Format")); |
|
1162 |
a=_TL(""); |
|
1163 |
b=_TL("cde"); |
|
1164 |
a.Format(_TL("%S"),&b); |
|
1165 |
test(a==b); |
|
1166 |
test(a.Length()==3); |
|
1167 |
DESTEMPLATE xyz=_TL("xyzwpq"); |
|
1168 |
a.Format(_TL("%S"),&xyz); |
|
1169 |
test(a==_TL("xyzwpq")); |
|
1170 |
test(a.Length()==6); |
|
1171 |
DESTEMPLATE cde=_TL("cde"); |
|
1172 |
a.Format(_TL("ab %-x5S"),&cde); |
|
1173 |
test(a==_TL("ab cdexx")); |
|
1174 |
test(a.Length()==8); |
|
1175 |
a.Format(_TL("ab %=x5S"),&cde); |
|
1176 |
test(a==_TL("ab xcdex")); |
|
1177 |
test(a.Length()==8); |
|
1178 |
a.Format(_TL("ab %+x5S"),&cde); |
|
1179 |
test(a==_TL("ab xxcde")); |
|
1180 |
test(a.Length()==8); |
|
1181 |
a.Format(_TL("ab %5S"),&cde); |
|
1182 |
test(a==_TL("ab cde")); |
|
1183 |
test(a.Length()==8); |
|
1184 |
a.Format(_TL("ab %-**S"),'x',5,&cde); |
|
1185 |
test(a==_TL("ab cdexx")); |
|
1186 |
test(a.Length()==8); |
|
1187 |
a.Format(_TL("ab %*S"),5,&cde); |
|
1188 |
test(a==_TL("ab cde")); |
|
1189 |
test(a.Length()==8); |
|
1190 |
a=_TL("xyz"); |
|
1191 |
a.Format(_TL("ab %-x5S"),&b); |
|
1192 |
test(a==_TL("ab cdexx")); |
|
1193 |
test(a.Length()==8); |
|
1194 |
a=_TL("xyz"); |
|
1195 |
a.Format(_TL("ab %-**S"),'x',5,&b); |
|
1196 |
test(a==_TL("ab cdexx")); |
|
1197 |
test(a.Length()==8); |
|
1198 |
a=_TL("xyz"); |
|
1199 |
a.Format(_TL("ab %*S"),5,&b); |
|
1200 |
test(a==_TL("ab cde")); |
|
1201 |
test(a.Length()==8); |
|
1202 |
||
1203 |
DESTEMPLATE fred=_TL("fred"); |
|
1204 |
a.Format(_TL("%+0*S"),10,&fred); |
|
1205 |
test(a==_TL("000000fred")); |
|
1206 |
test(a.Length()==10); |
|
1207 |
a.Format(_TL("%-0*S"),7,&fred); |
|
1208 |
test(a==_TL("fred000")); |
|
1209 |
test(a.Length()==7); |
|
1210 |
a.Format(_TL("%0*S"),11,&fred); |
|
1211 |
test(a==_TL("0000000fred")); |
|
1212 |
test(a.Length()==11); |
|
1213 |
a.Format(_TL("c=%s"),pD); |
|
1214 |
TESTEQ(a,_TL("c=299792458")); |
|
1215 |
a.Format(_TL("c=%10.6s"),pD); |
|
1216 |
test(a==_TL("c= 299792")); |
|
1217 |
a.Format(_TL("c=%*.*s"),5,4,pD); |
|
1218 |
test(a==_TL("c= 2997")); |
|
1219 |
a.Format(_TL("%S"),&d); |
|
1220 |
test(a==_TL("linearisation")); |
|
1221 |
a.Format(_TL("%10.6S"),&d); |
|
1222 |
test(a==_TL(" linear")); |
|
1223 |
a.Format(_TL("%*.*S"),5,4,&d); |
|
1224 |
test(a==_TL(" line")); |
|
1225 |
a.Format(_TL("%*.*Sed"),10,8,&d); |
|
1226 |
test(a==_TL(" linearised")); |
|
1227 |
a.Format(_TL("%*.*S"),14,20,&d); |
|
1228 |
test(a==_TL(" linearisation")); |
|
1229 |
||
1230 |
a.Format(_TL("ab %-,5b"),7); |
|
1231 |
test(a==_TL("ab 111,,")); |
|
1232 |
test(a.Length()==8); |
|
1233 |
a.Format(_TL("ab %=,5O"),31); |
|
1234 |
test(a==_TL("ab ,37,,")); |
|
1235 |
test(a.Length()==8); |
|
1236 |
a.Format(_TL("ab %+xlx"),TInt64(171)); |
|
1237 |
test(a==_TL("ab ab")); |
|
1238 |
test(a.Length()==5); |
|
1239 |
a.Format(_TL("ab %+xlX %+xlx"),TInt64(171),TInt64(171)); |
|
1240 |
TESTEQ(a,_TL("ab AB ab")); |
|
1241 |
test(a.Length()==8); |
|
1242 |
a.Format(_TL("ab %lu"),MAKE_TINT64((TUint)(KMinTInt),0)); |
|
1243 |
test(a==_TL("ab 9223372036854775808")); |
|
1244 |
test(a.Length()==22); |
|
1245 |
a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMinTInt),1)); |
|
1246 |
test(a==_TL("ab -9223372036854775807")); |
|
1247 |
test(a.Length()==23); |
|
1248 |
a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMinTInt),0)); |
|
1249 |
test(a==_TL("ab -9223372036854775808")); |
|
1250 |
test(a.Length()==23); |
|
1251 |
a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint)); |
|
1252 |
test(a==_TL("ab 9223372036854775807")); |
|
1253 |
test(a.Length()==22); |
|
1254 |
a.Format(_TL("ab %ld"),MAKE_TINT64(KMaxTUint,KMaxTUint)); |
|
1255 |
test(a==_TL("ab -1")); |
|
1256 |
test(a.Length()==5); |
|
1257 |
a.Format(_TL("ab %lu"),MAKE_TINT64(KMaxTUint,KMaxTUint)); |
|
1258 |
test(a==_TL("ab 18446744073709551615")); |
|
1259 |
test(a.Length()==23); |
|
1260 |
a.Format(_TL("ab %ld"),TInt64(0)); |
|
1261 |
test(a==_TL("ab 0")); |
|
1262 |
test(a.Length()==4); |
|
1263 |
a.Format(_TL("ab %lb"),TInt64(0)); |
|
1264 |
test(a==_TL("ab 0")); |
|
1265 |
test(a.Length()==4); |
|
1266 |
a.Format(_TL("ab %lx"),TInt64(0)); |
|
1267 |
test(a==_TL("ab 0")); |
|
1268 |
test(a.Length()==4); |
|
1269 |
a.Format(_TL("ab %lo"),TInt64(0)); |
|
1270 |
test(a==_TL("ab 0")); |
|
1271 |
test(a.Length()==4); |
|
1272 |
a.Format(_TL("ab %lu"),TInt64(0)); |
|
1273 |
test(a==_TL("ab 0")); |
|
1274 |
test(a.Length()==4); |
|
1275 |
a.Format(_TL("ab %lb"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint)); |
|
1276 |
test(a==_TL("ab 111111111111111111111111111111111111111111111111111111111111111")); |
|
1277 |
test(a.Length()==66); |
|
1278 |
a.Format(_TL("ab %lb"),MAKE_TINT64(KMaxTUint,KMaxTUint)); |
|
1279 |
test(a==_TL("ab 1111111111111111111111111111111111111111111111111111111111111111")); |
|
1280 |
test(a.Length()==67); |
|
1281 |
a.Format(_TL("ab %lx"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint)); |
|
1282 |
test(a==_TL("ab 7fffffffffffffff")); |
|
1283 |
test(a.Length()==19); |
|
1284 |
a.Format(_TL("ab %lx"),MAKE_TINT64(KMaxTUint,KMaxTUint)); |
|
1285 |
test(a==_TL("ab ffffffffffffffff")); |
|
1286 |
test(a.Length()==19); |
|
1287 |
a.Format(_TL("ab %lo"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint)); |
|
1288 |
test(a==_TL("ab 777777777777777777777")); |
|
1289 |
test(a.Length()==24); |
|
1290 |
// tests which excercise any 8 byte alignment requirement on 64bit integers |
|
1291 |
a.Format(_TL("%li%S"),MAKE_TINT64(1,2),&fred); |
|
1292 |
test(a==_TL("4294967298fred")); |
|
1293 |
a.Format(_TL("%S%li%S"),&fred,MAKE_TINT64(1,2),&fred); |
|
1294 |
test(a==_TL("fred4294967298fred")); |
|
1295 |
a.Format(_TL("%lu%S"),MAKE_TINT64(1,2),&fred); |
|
1296 |
test(a==_TL("4294967298fred")); |
|
1297 |
a.Format(_TL("%S%lu%S"),&fred,MAKE_TINT64(1,2),&fred); |
|
1298 |
test(a==_TL("fred4294967298fred")); |
|
1299 |
||
1300 |
a.Format(_TL("ab %U"),233); |
|
1301 |
test(a==_TL("ab 233")); |
|
1302 |
test(a.Length()==6); |
|
1303 |
a.Format(_TL("ab %*d"),5,-131); |
|
1304 |
test(a==_TL("ab -131")); |
|
1305 |
test(a.Length()==8); |
|
1306 |
a.Format(_TL("ab%c"),'x'); |
|
1307 |
test(a==_TL("abx")); |
|
1308 |
test(a.Length()==3); |
|
1309 |
a.Format(_TL("%W"),-131); |
|
1310 |
test(*(TInt32*)a.Ptr()==-131); |
|
1311 |
a.Format(_TL("%M"),-131); |
|
1312 |
test(*(TInt32*)a.Ptr()==2113929215); |
|
1313 |
a.Format(_TL("%w"),-131); |
|
1314 |
test(*(TInt16*)a.Ptr()==-131); |
|
1315 |
a.Format(_TL("%m"),-131); |
|
1316 |
test(*(TInt16*)a.Ptr()==32255); |
|
1317 |
a=_TL("xyz"); |
|
1318 |
a.AppendFormat(_TL("ab %+xlx"),TInt64(171)); |
|
1319 |
test(a==_TL("xyzab ab")); |
|
1320 |
test(a.Length()==8); |
|
1321 |
a=_TL("xyz"); |
|
1322 |
a.AppendFormat(_TL("ab %5S"),&b); |
|
1323 |
test(a==_TL("xyzab cde")); |
|
1324 |
test(a.Length()==11); |
|
1325 |
a=_TL("xyz"); |
|
1326 |
a.AppendFormat(_TL("%W"),-131); |
|
1327 |
// test(*(TInt32*)(a.Ptr()+3)==-131); // Alignment-safe version: |
|
1328 |
TInt val; |
|
1329 |
Mem::Copy(&val,&a[3],4); |
|
1330 |
test(val==-131); |
|
1331 |
a=_TL("xyz"); |
|
1332 |
// a.Append(_TL("abc"),3); |
|
1333 |
// test(a==_TL("xyzabc")); |
|
1334 |
||
1335 |
a.Format(_TL("")); |
|
1336 |
test(a==_TL("")); |
|
1337 |
a.Format(_TL(""),9,5); |
|
1338 |
test(a==_TL("")); |
|
1339 |
a.Format(_TL("qwerty")); |
|
1340 |
test(a==_TL("qwerty")); |
|
1341 |
a.Format(_TL("qwerty"),9,5); |
|
1342 |
test(a==_TL("qwerty")); |
|
1343 |
a.Format(_TL("%$1$d%$2$d"),9,5); |
|
1344 |
test(a==_TL("95")); |
|
1345 |
test(a.Length()==2); |
|
1346 |
a.Format(_TL("%$2$d%$1$d"),9,5); |
|
1347 |
test(a==_TL("59")); |
|
1348 |
test(a.Length()==2); |
|
1349 |
b=_TL("eb"); |
|
1350 |
a.Format(_TL("%$1$S%$2$d"),&b,205); |
|
1351 |
test(a==_TL("eb205")); |
|
1352 |
test(a.Length()==5); |
|
1353 |
a.Format(_TL("%$2$d%$1$S"),&b,205); |
|
1354 |
test(a==_TL("205eb")); |
|
1355 |
test(a.Length()==5); |
|
1356 |
b=_TL("ebdb"); |
|
1357 |
||
1358 |
// Cannot do this on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime". |
|
1359 |
#if !(defined(__GCC32__) && defined(__X86__)) |
|
1360 |
const TAny* const zeroTerminatedString=(sizeof(S)==2)? (const TAny*)_S16(":-)E"): (const TAny*)_S8(":-)E"); |
|
1361 |
const TInt dummyParameter=0; |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1362 |
#ifdef __ARMCC__ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1363 |
#pragma push |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1364 |
#pragma diag_suppress 1446 |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1365 |
#endif |
0 | 1366 |
Test14_ReorderedParameterFormatting(dummyParameter, 0x20ac, 11, 3, 13.89543, zeroTerminatedString, '!', TInt64(199), 2, &b, 6, 30005, TRealX(0.125), 0x8bdd); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1367 |
#ifdef __ARMCC__ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1368 |
#pragma pop |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1369 |
#endif |
0 | 1370 |
#endif |
1371 |
||
1372 |
test.Next(_L("Print some numbers")); |
|
1373 |
TInt64 TI64 = MAKE_TINT64(0x101010u,0x10101010u); |
|
1374 |
test.Printf(_L(" %%ld: %ld\n"),TI64); |
|
1375 |
test.Printf(_L(" %%lu: %lu\n"),TI64); |
|
1376 |
test.Printf(_L(" %%lx: %lx\n"),TI64); |
|
1377 |
test.Printf(_L(" %%lb: %lb\n"),TI64); |
|
1378 |
test.Printf(_L(" %%lo: %lo\n\n"),TI64); |
|
1379 |
TI64 = UI64LIT(0xabcdef12345678); |
|
1380 |
test.Printf(_L(" %%ld: %ld\n"),TI64); |
|
1381 |
test.Printf(_L(" %%lu: %lu\n"),TI64); |
|
1382 |
test.Printf(_L(" %%lx: %lx\n"),TI64); |
|
1383 |
test.Printf(_L(" %%lb: %lb\n"),TI64); |
|
1384 |
test.Printf(_L(" %%lo: %lo\n\n"),TI64); |
|
1385 |
TI64 = UI64LIT(0x7fffffffffffffff); |
|
1386 |
test.Printf(_L(" %%ld: %ld\n"),TI64); |
|
1387 |
test.Printf(_L(" %%lu: %lu\n"),TI64); |
|
1388 |
test.Printf(_L(" %%lx: %lx\n"),TI64); |
|
1389 |
test.Printf(_L(" %%lb: %lb\n"),TI64); |
|
1390 |
test.Printf(_L(" %%lo: %lo\n\n"),TI64); |
|
1391 |
TI64 = UI64LIT(0x8000000000000000); |
|
1392 |
test.Printf(_L(" %%ld: %ld\n"),TI64); |
|
1393 |
test.Printf(_L(" %%lu: %lu\n"),TI64); |
|
1394 |
test.Printf(_L(" %%lx: %lx\n"),TI64); |
|
1395 |
test.Printf(_L(" %%lb: %lb\n"),TI64); |
|
1396 |
test.Printf(_L(" %%lo: %lo\n\n"),TI64); |
|
1397 |
TI64 = UI64LIT(0xffffffffffffffff); |
|
1398 |
test.Printf(_L(" %%ld: %ld\n"),TI64); |
|
1399 |
test.Printf(_L(" %%lu: %lu\n"),TI64); |
|
1400 |
test.Printf(_L(" %%lx: %lx\n"),TI64); |
|
1401 |
test.Printf(_L(" %%lb: %lb\n"),TI64); |
|
1402 |
test.Printf(_L(" %%lo: %lo\n\n"),TI64); |
|
1403 |
||
1404 |
test.Next(_L("Regression tests")); |
|
1405 |
a.Format(_TL("[%-A4p]")); |
|
1406 |
test(a==_TL("[AAAA]")); |
|
1407 |
||
1408 |
test.End(); |
|
1409 |
} |
|
1410 |
||
1411 |
template <class T,class S,class DESTEMPLATE> |
|
1412 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test14_ReorderedParameterFormatting(TInt aDummyParameter, ...) |
|
1413 |
{ |
|
1414 |
VA_LIST parameterList; |
|
1415 |
T generated; |
|
1416 |
T expected; |
|
1417 |
||
1418 |
VA_START(parameterList, aDummyParameter); |
|
1419 |
generated.FormatList(_TL("\t%-**.*fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%.3Fyyyyyyy%c"), parameterList); |
|
1420 |
test(generated.Length()==61); |
|
1421 |
expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www!!199eeeeebrrrrr007535tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1422 |
test(generated.Left(generated.Length()-1)==expected); |
|
1423 |
test(generated[generated.Length()-1]==(S)0x8bdd); |
|
1424 |
||
1425 |
VA_START(parameterList, aDummyParameter); |
|
1426 |
generated.FormatList(_TL("\t%$1$-**.*fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%$6$.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%$6$.3Fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%$1$-**.*fyyyyyyy%c"), parameterList); |
|
1434 |
test(generated.Length()==61); |
|
1435 |
expected.Format(_TL("\t0.125qq:-)www!!199eeeeebrrrrr007535tttttt13.895%c%c%c%c%cyyyyyyy"), (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%-**.*fqq%.3swww%$5$0*xeeee%.*Srrrrr%$3$+*5Ldtttttt%.3Fyyyyyyy%c"), parameterList); |
|
1441 |
test(generated.Length()==61); |
|
1442 |
expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www007535eeeeebrrrrr!!199tttttt0.125yyyyyyy"), (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%$4$.*Swww%+*5Ldeeee%$2$.3srrrrr%0*xtttttt%.3Fyyyyyyy%c"), parameterList); |
|
1448 |
test(generated.Length()==61); |
|
1449 |
expected.Format(_TL("\t13.895%c%c%c%c%cqqebwww!!199eeee:-)rrrrr007535tttttt0.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%.3swww%+*5Ldeeee%$7$crrrrr%0*xtttttt%.3Fyyyyyyy%$4$.*S"), parameterList); |
|
1455 |
test(generated.Length()==61); |
|
1456 |
expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www!!199eeee"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1457 |
test(generated.Left(29)==expected); |
|
1458 |
test(generated[29]==(S)0x8bdd); |
|
1459 |
test(generated.Mid(29+1)==_TL("rrrrr007535tttttt0.125yyyyyyyeb")); |
|
1460 |
||
1461 |
VA_START(parameterList, aDummyParameter); |
|
1462 |
generated.FormatList(_TL("\t%$4$.*Sqq%.3swww%+*5Ldeeee%$6$.3Frrrrr%0*xtttttt%$1$-**.*fyyyyyyy%c"), parameterList); |
|
1463 |
test(generated.Length()==61); |
|
1464 |
expected.Format(_TL("\tebqq:-)www!!199eeee0.125rrrrr007535tttttt13.895%c%c%c%c%cyyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1465 |
test(generated.Left(generated.Length()-1)==expected); |
|
1466 |
test(generated[generated.Length()-1]==(S)0x8bdd); |
|
1467 |
||
1468 |
VA_START(parameterList, aDummyParameter); |
|
1469 |
generated.FormatList(_TL("\t%$7$cqq%$6$.3Fwww%$5$0*xeeee%.*Srrrrr%$3$+*5Ldtttttt%$2$.3syyyyyyy%$1$-**.*f"), parameterList); |
|
1470 |
test(generated.Length()==61); |
|
1471 |
test(generated.Left(1)==_TL("\t")); |
|
1472 |
test(generated[1]==(S)0x8bdd); |
|
1473 |
expected.Format(_TL("qq0.125www007535eeeeebrrrrr!!199tttttt:-)yyyyyyy13.895%c%c%c%c%c"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1474 |
test(generated.Mid(2)==expected); |
|
1475 |
||
1476 |
VA_START(parameterList, aDummyParameter); |
|
1477 |
generated.FormatList(_TL("\t%$7$cqq%$6$.3Fwww%$5$0*xeeee%$4$.*Srrrrr%$3$+*5Ldtttttt%$2$.3syyyyyyy%$1$-**.*f"), parameterList); |
|
1478 |
test(generated.Length()==61); |
|
1479 |
test(generated.Left(1)==_TL("\t")); |
|
1480 |
test(generated[1]==(S)0x8bdd); |
|
1481 |
expected.Format(_TL("qq0.125www007535eeeeebrrrrr!!199tttttt:-)yyyyyyy13.895%c%c%c%c%c"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac); |
|
1482 |
test(generated.Mid(2)==expected); |
|
1483 |
} |
|
1484 |
||
1485 |
template <class T,class S,class DESTEMPLATE> |
|
1486 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test15() |
|
1487 |
// Replacing |
|
1488 |
{ |
|
1489 |
test.Start(_L("Replace")); |
|
1490 |
T a,b; |
|
1491 |
test(a.MaxLength()>=9); |
|
1492 |
a=_TL("abccccc"); |
|
1493 |
b=_TL("def"); |
|
1494 |
a.Replace(3,4,b); // Replace with smaller in middle (insert and delete) |
|
1495 |
test(a==_TL("abcdef")); |
|
1496 |
a.Replace(1,1,b); // Replace with larger in middle (insert and delete) |
|
1497 |
test(a==_TL("adefcdef")); |
|
1498 |
a.Replace(0,8,_TL("")); // Replace complete string (delete) |
|
1499 |
test(a==_TL("")); |
|
1500 |
a.Replace(0,0,b); // Replace at beginning (insert) |
|
1501 |
test(a==b); |
|
1502 |
a.Replace(3,0,_TL("xyz")); // Replace at end (append) |
|
1503 |
test(a==_TL("defxyz")); |
|
1504 |
a.Replace(0,0,_TL("")); // Replace nothing at beginning (do nothing) |
|
1505 |
test(a==_TL("defxyz")); |
|
1506 |
a.Replace(6,0,_TL("")); // Replace nothing at end (do nothing) |
|
1507 |
test(a==_TL("defxyz")); |
|
1508 |
//a.Replace(6,1,_TL("")); // this will panic - no char after end to replace |
|
1509 |
//a.Replace(0,7,_TL("")); // this will panic - aint 7 chars to replace |
|
1510 |
test.End(); |
|
1511 |
} |
|
1512 |
||
1513 |
template<class T,class S,class DESTEMPLATE> |
|
1514 |
GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::test_TBuf() |
|
1515 |
// Test the TBuf class. |
|
1516 |
{ |
|
1517 |
test.Start(_L("All operations")); |
|
1518 |
Test1(); |
|
1519 |
test.Next(_L("Constructors")); |
|
1520 |
Test2(); |
|
1521 |
test.Next(_L("Additional tests")); |
|
1522 |
Test3(); |
|
1523 |
test.Next(_L("Comparison operators")); |
|
1524 |
Test4(); |
|
1525 |
test.Next(_L("Property access")); |
|
1526 |
Test5(); |
|
1527 |
test.Next(_L("Fill and swap")); |
|
1528 |
Test6(); |
|
1529 |
test.Next(_L("Conversion operators")); |
|
1530 |
Test7(); |
|
1531 |
test.Next(_L("Comparison")); |
|
1532 |
Test8(); |
|
1533 |
test.Next(_L("Matching")); |
|
1534 |
Test9(); |
|
1535 |
test.Next(_L("Locating")); |
|
1536 |
Test10(); |
|
1537 |
test.Next(_L("Copying")); |
|
1538 |
Test11(); |
|
1539 |
test.Next(_L("Finding")); |
|
1540 |
Test12(); |
|
1541 |
test.Next(_L("Basic like ops")); |
|
1542 |
Test13(); |
|
1543 |
test.Next(_L("Formating")); |
|
1544 |
Test14(); |
|
1545 |
test.Next(_L("Replacing")); |
|
1546 |
Test15(); |
|
1547 |
test.End(); |
|
1548 |
} |
|
1549 |
||
1550 |
LOCAL_C void testFormat() |
|
1551 |
{ |
|
1552 |
TBuf<0x100> aa; |
|
1553 |
aa.Format(_L("x%- 5fx"), 6.2345678); |
|
1554 |
test(aa==_L("x6.234568x")); |
|
1555 |
aa.Format(_L("x%+ 5fx"), 6.2345678); |
|
1556 |
test(aa==_L("x6.234568x")); |
|
1557 |
aa.Format(_L("x% 5fx"), 6.2345678); |
|
1558 |
test(aa==_L("x6.234568x")); |
|
1559 |
aa.Format(_L("x%= 5fx"), 6.2345678); |
|
1560 |
test(aa==_L("x6.234568x")); |
|
1561 |
aa.Format(_L("x%- 10fx"), 6.2345); |
|
1562 |
test(aa==_L("x6.234500 x")); |
|
1563 |
aa.Format(_L("x%+ 10fx"), 6.2345); |
|
1564 |
test(aa==_L("x 6.234500x")); |
|
1565 |
aa.Format(_L("x% 10fx"), 6.2345); |
|
1566 |
test(aa==_L("x 6.234500x")); |
|
1567 |
aa.Format(_L("x%= 10fx"), 6.2345); |
|
1568 |
test(aa==_L("x 6.234500 x")); |
|
1569 |
aa.Format(_L("x%10fx"), 12345352342.545); |
|
1570 |
test(aa==_L("x12,345,352,342.545000x")); |
|
1571 |
aa.Format(_L("x%20.9fx"), 1.0123456789); |
|
1572 |
test(aa==_L("x 1.012345679x")); |
|
1573 |
aa.Format(_L("x%5.1fx"), 1.99); |
|
1574 |
test(aa==_L("x 2.0x")); |
|
1575 |
||
1576 |
// Cannot do these on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime". |
|
1577 |
#if !(defined(__GCC32__) && defined(__X86__)) |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1578 |
#ifdef __ARMCC__ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1579 |
#pragma push |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1580 |
#pragma diag_suppress 1446 |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1581 |
#endif |
0 | 1582 |
aa.Format(_L("x%- 5Fx"), TRealX(6.2345678)); |
1583 |
test(aa==_L("x6.234568x")); |
|
1584 |
aa.Format(_L("x%+ 5Fx"), TRealX(6.2345678)); |
|
1585 |
test(aa==_L("x6.234568x")); |
|
1586 |
aa.Format(_L("x% 5Fx"), TRealX(6.2345678)); |
|
1587 |
test(aa==_L("x6.234568x")); |
|
1588 |
aa.Format(_L("x%= 5Fx"), TRealX(6.2345678)); |
|
1589 |
test(aa==_L("x6.234568x")); |
|
1590 |
aa.Format(_L("x%- 10Fx"), TRealX(6.2345)); |
|
1591 |
test(aa==_L("x6.234500 x")); |
|
1592 |
aa.Format(_L("x%+ 10Fx"), TRealX(6.2345)); |
|
1593 |
test(aa==_L("x 6.234500x")); |
|
1594 |
aa.Format(_L("x% 10Fx"), TRealX(6.2345)); |
|
1595 |
test(aa==_L("x 6.234500x")); |
|
1596 |
aa.Format(_L("x%+010Fx"), TRealX(6.2345)); |
|
1597 |
test(aa==_L("x006.234500x")); |
|
1598 |
aa.Format(_L("x%+10Fx"), TRealX(6.2345)); |
|
1599 |
test(aa==_L("x 6.234500x")); |
|
1600 |
aa.Format(_L("x%10Fx"), TRealX(6.2345)); |
|
1601 |
test(aa==_L("x 6.234500x")); |
|
1602 |
aa.Format(_L("x%010Fx"), TRealX(6.2345)); |
|
1603 |
test(aa==_L("x006.234500x")); |
|
1604 |
aa.Format(_L("x%= 10Fx"), TRealX(6.2345)); |
|
1605 |
test(aa==_L("x 6.234500 x")); |
|
1606 |
aa.Format(_L("x%10Fx"), TRealX(12345352342.545)); |
|
1607 |
test(aa==_L("x12,345,352,342.545000x")); |
|
1608 |
aa.Format(_L("x%20.9Fx"), TRealX(1.0123456789)); |
|
1609 |
test(aa==_L("x 1.012345679x")); |
|
1610 |
aa.Format(_L("x%5.1Fx"), TRealX(1.99)); |
|
1611 |
test(aa==_L("x 2.0x")); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1612 |
#ifdef __ARMCC__ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1613 |
#pragma pop |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1614 |
#endif |
0 | 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 |