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