sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Overview:
|
sl@0
|
15 |
// Test methods of the LString16, LString8, LString template class.
|
sl@0
|
16 |
// The test cases below are template based allowing the same code to
|
sl@0
|
17 |
// be used for testing both LString16 and LString8 classes.
|
sl@0
|
18 |
// Appropriate LString and buffer types are passed as the template
|
sl@0
|
19 |
// parameters in the call to each test case.
|
sl@0
|
20 |
// API Information:
|
sl@0
|
21 |
// LString16, LString8, LString.
|
sl@0
|
22 |
// Details:
|
sl@0
|
23 |
// For LString8, LString16 and LString objects:
|
sl@0
|
24 |
// - Test the Create and CreateMax methods by verifying the return value of
|
sl@0
|
25 |
// KErrNone, the initial length and max length. Perform basic write and read
|
sl@0
|
26 |
// operations and verify the results.
|
sl@0
|
27 |
// - Test the CreateL and CreateMaxL methods by verifying the return value of
|
sl@0
|
28 |
// KErrNone. Also force a heap error and verify return value of KErrNoMemory.
|
sl@0
|
29 |
// - Test the Create(const TDesC_& aDesc) and Create(const TDesCX_ aDesc,
|
sl@0
|
30 |
// TInt aMaxLength) methods by verifying the return value of KErrNone. Verify
|
sl@0
|
31 |
// initial length, max length and initialisation.
|
sl@0
|
32 |
// - Test the CreateL(const TDesC_& aDesc) and CreateMaxL(const TDesCX_ aDesc,
|
sl@0
|
33 |
// TInt aMaxLength) methods by verifying the return value of KErrNone. Also
|
sl@0
|
34 |
// force a heap error and verify return value of KErrNoMemory.
|
sl@0
|
35 |
// - Test the Swap method by creating two initialised objects, calling Swap
|
sl@0
|
36 |
// and confirming the results as expected.
|
sl@0
|
37 |
// - Test the Assign method by performing an assign from a variety of sources
|
sl@0
|
38 |
// and verifying the results are as expected.
|
sl@0
|
39 |
// - Test the ReAlloc method in a variety of scenarios that decrease memory,
|
sl@0
|
40 |
// increase memory and zero-length memory. Verify that the results are as
|
sl@0
|
41 |
// expected.
|
sl@0
|
42 |
// - Test the ReAllocL by verifying the return value of KErrNone. Also force
|
sl@0
|
43 |
// a heap error and verify return value of KErrNoMemory. Verify that the
|
sl@0
|
44 |
// object is the same as before the failed ReAllocL call.
|
sl@0
|
45 |
// - Test the CleanupClosePushL method via CleanupStack::PopAndDestroy().
|
sl@0
|
46 |
// - Force the CleanupClosePushL to leave to check cleanup of LString.
|
sl@0
|
47 |
// Platforms/Drives/Compatibility:
|
sl@0
|
48 |
// All
|
sl@0
|
49 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
50 |
// Failures and causes:
|
sl@0
|
51 |
// Base Port information:
|
sl@0
|
52 |
//
|
sl@0
|
53 |
//
|
sl@0
|
54 |
|
sl@0
|
55 |
#include <e32base.h>
|
sl@0
|
56 |
#include <e32math.h>
|
sl@0
|
57 |
#include <e32test.h>
|
sl@0
|
58 |
#include <euserhl.h>
|
sl@0
|
59 |
#include <u32std.h>
|
sl@0
|
60 |
#include <f32file.h>
|
sl@0
|
61 |
#include <s32mem.h>
|
sl@0
|
62 |
|
sl@0
|
63 |
LOCAL_D RTest test(_L("T_LSTRING"));
|
sl@0
|
64 |
|
sl@0
|
65 |
/* This macro generates a TTEXT* from the string passed in.
|
sl@0
|
66 |
* The TTEXT type is a template parameter defined for the calling function
|
sl@0
|
67 |
* and an appropriate 8 or 16 bit string variant is created by this macro
|
sl@0
|
68 |
*/
|
sl@0
|
69 |
#undef _TS
|
sl@0
|
70 |
#define _TS(a) ((const TTEXT*)RTest::String(sizeof(TTEXT),(TText8*)a,(TText16*)L ## a))
|
sl@0
|
71 |
|
sl@0
|
72 |
/* This macro generates a CHAR* from the string passed in.
|
sl@0
|
73 |
* The CHAR type is a template parameter defined for the calling function
|
sl@0
|
74 |
* and an appropriate 8(char)or 16(wchar_t) bit string variant is created by this macro
|
sl@0
|
75 |
*/
|
sl@0
|
76 |
#undef _CS
|
sl@0
|
77 |
#define _CS(a) ((const CHAR*)RTest::String(sizeof(TTEXT),(TText8*)a,(TText16*)L ## a))
|
sl@0
|
78 |
|
sl@0
|
79 |
/**
|
sl@0
|
80 |
@SYMTestCaseID SYSLIB-EUSERHL-UT-4001
|
sl@0
|
81 |
@SYMTestCaseDesc Tests constructors of LString classes
|
sl@0
|
82 |
@SYMTestPriority High
|
sl@0
|
83 |
@SYMTestActions Creates LString objects using the different
|
sl@0
|
84 |
constructors.
|
sl@0
|
85 |
@SYMTestExpectedResults All constructors create object object as expected
|
sl@0
|
86 |
@SYMREQ 10372
|
sl@0
|
87 |
*/
|
sl@0
|
88 |
template<class LSTRING, class TBUF, class TTEXT, class HBUF, class CHAR >
|
sl@0
|
89 |
LOCAL_C void TestConstructors(LSTRING*)
|
sl@0
|
90 |
{
|
sl@0
|
91 |
|
sl@0
|
92 |
test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4001"));
|
sl@0
|
93 |
|
sl@0
|
94 |
test.Next(_L("LString_(const TDesC& aDes) constructor"));
|
sl@0
|
95 |
const TBUF des (_TS("123456"));
|
sl@0
|
96 |
const LSTRING lStr(des);
|
sl@0
|
97 |
test(lStr.Length() == 6);
|
sl@0
|
98 |
test(lStr.MaxLength() >= 6);
|
sl@0
|
99 |
|
sl@0
|
100 |
test.Next(_L("LString_(const LString16& aDes) constructor"));
|
sl@0
|
101 |
LSTRING lStr1(lStr);
|
sl@0
|
102 |
test(lStr1.Length() == 6);
|
sl@0
|
103 |
test(lStr1.MaxLength() >= 6);
|
sl@0
|
104 |
|
sl@0
|
105 |
test.Next(_L("LString_(const TUInt16* aString) constructor"));
|
sl@0
|
106 |
LSTRING lStr2(lStr1.PtrZL());
|
sl@0
|
107 |
test(lStr2.Length() == 6);
|
sl@0
|
108 |
test(lStr2.MaxLength() >= 6);
|
sl@0
|
109 |
|
sl@0
|
110 |
test.Next(_L("LString_(HBufC_* aHBuf) constructor"));
|
sl@0
|
111 |
|
sl@0
|
112 |
HBUF* hBuf = HBUF::NewMax(12); //Create LString as EBufCPtr
|
sl@0
|
113 |
LSTRING lStr3(hBuf);
|
sl@0
|
114 |
test(lStr3.Length() == 12);
|
sl@0
|
115 |
test(lStr3.MaxLength() >= 12);
|
sl@0
|
116 |
|
sl@0
|
117 |
hBuf = HBUF::NewMax(0);
|
sl@0
|
118 |
LSTRING lStr4(hBuf); //The length of aHBuf is zero
|
sl@0
|
119 |
test(lStr4.Length() == 0);
|
sl@0
|
120 |
|
sl@0
|
121 |
hBuf = NULL; //aHBuf is NULL
|
sl@0
|
122 |
LSTRING lStr5((HBUF*)hBuf);
|
sl@0
|
123 |
test(lStr5.Length() == 0);
|
sl@0
|
124 |
test(lStr5.MaxLength() == 0);
|
sl@0
|
125 |
|
sl@0
|
126 |
test.Next(_L("LString_(TUInt16* aHeapCell, TInt aLength, TInt aMaxLength) constructor"));
|
sl@0
|
127 |
TTEXT* heap = NULL;
|
sl@0
|
128 |
|
sl@0
|
129 |
heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16
|
sl@0
|
130 |
LSTRING lStr6(heap, 12,24);
|
sl@0
|
131 |
test(lStr6.Length() == 12);
|
sl@0
|
132 |
test(lStr6.MaxLength() >= 24);
|
sl@0
|
133 |
|
sl@0
|
134 |
test.Next(_L("LString_(TUint* aHeapCell, TInt aMaxLength ) method"));
|
sl@0
|
135 |
|
sl@0
|
136 |
heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16
|
sl@0
|
137 |
LSTRING lStr7(heap, 24);
|
sl@0
|
138 |
test(lStr7.Length() == 0);
|
sl@0
|
139 |
test(lStr7.MaxLength() >= 24);
|
sl@0
|
140 |
|
sl@0
|
141 |
test.Next(_L("LString_(char/wchar_t * aCharStr) constructor"));
|
sl@0
|
142 |
|
sl@0
|
143 |
LSTRING lStr8(_CS("0123456789"));
|
sl@0
|
144 |
test(lStr8.Length() == 10);
|
sl@0
|
145 |
test(lStr8.MaxLength() >= 10);
|
sl@0
|
146 |
|
sl@0
|
147 |
LSTRING lStr9(_CS("01234567890"));
|
sl@0
|
148 |
test(lStr9.Length() == 11);
|
sl@0
|
149 |
test(lStr9.MaxLength() >= 11);
|
sl@0
|
150 |
}
|
sl@0
|
151 |
|
sl@0
|
152 |
|
sl@0
|
153 |
|
sl@0
|
154 |
/**
|
sl@0
|
155 |
Tests the following methods:
|
sl@0
|
156 |
- TInt Assign(const LString_& lStr);
|
sl@0
|
157 |
- TInt Assign(TUint* aHeapCell, TInt aMaxLength);
|
sl@0
|
158 |
- TInt Assign(TUint* aHeapCell, TInt aLength, TInt aMaxLength);
|
sl@0
|
159 |
- TInt Assign(HBufC& aHBuf);
|
sl@0
|
160 |
- LString(HBufC_&) constructor.
|
sl@0
|
161 |
*/
|
sl@0
|
162 |
/**
|
sl@0
|
163 |
@SYMTestCaseID SYSLIB-EUSERHL-UT-4002
|
sl@0
|
164 |
@SYMTestCaseDesc Tests Assign methods of LString
|
sl@0
|
165 |
@SYMTestPriority High
|
sl@0
|
166 |
@SYMTestActions Creates LString objects and assigns data to the LString using
|
sl@0
|
167 |
the LString::Assign overloads.
|
sl@0
|
168 |
Checks that the data is assigned as expected.
|
sl@0
|
169 |
Creates LString objects from HBufC* and verifies that object
|
sl@0
|
170 |
is created as expected
|
sl@0
|
171 |
@SYMTestExpectedResults LString objects are created and assigned as expected
|
sl@0
|
172 |
@SYMREQ 10372
|
sl@0
|
173 |
*/
|
sl@0
|
174 |
template<class LSTRING, class TBUF, class TTEXT, class HBUF, class RBUF>
|
sl@0
|
175 |
LOCAL_C void TestAssign(LSTRING*)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
|
sl@0
|
178 |
test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4002"));
|
sl@0
|
179 |
|
sl@0
|
180 |
TBUF des (_TS("123456"));
|
sl@0
|
181 |
LSTRING lStr2(des);
|
sl@0
|
182 |
TTEXT* heap = NULL;
|
sl@0
|
183 |
RBUF buf;
|
sl@0
|
184 |
|
sl@0
|
185 |
test.Next(_L("Assign(const LString_& aLString) method"));
|
sl@0
|
186 |
|
sl@0
|
187 |
LSTRING lStr;
|
sl@0
|
188 |
lStr.Assign(lStr2);
|
sl@0
|
189 |
// the assignment clears lStr2 so the two strings should be unequal
|
sl@0
|
190 |
test(lStr != lStr2);
|
sl@0
|
191 |
|
sl@0
|
192 |
test.Next(_L("Assign(TUint* aHeapCell, TInt aLength, TInt aMaxLength ) method"));
|
sl@0
|
193 |
|
sl@0
|
194 |
heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16
|
sl@0
|
195 |
lStr.Assign(heap, 12,24);
|
sl@0
|
196 |
test(lStr.Length() == 12);
|
sl@0
|
197 |
test(lStr.MaxLength() >= 24);
|
sl@0
|
198 |
|
sl@0
|
199 |
heap = NULL;
|
sl@0
|
200 |
lStr.Assign(heap, 0,0);
|
sl@0
|
201 |
test(lStr.Length() == 0);
|
sl@0
|
202 |
test(lStr.MaxLength() == 0);
|
sl@0
|
203 |
|
sl@0
|
204 |
test.Next(_L("Assign(TUint* aHeapCell, TInt aMaxLength ) method"));
|
sl@0
|
205 |
|
sl@0
|
206 |
heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16
|
sl@0
|
207 |
lStr.Assign(heap, 24);
|
sl@0
|
208 |
test(lStr.Length() == 0);
|
sl@0
|
209 |
test(lStr.MaxLength() >= 24);
|
sl@0
|
210 |
|
sl@0
|
211 |
test.Next(_L("Assign(HBufC_* aHBuf) method"));
|
sl@0
|
212 |
|
sl@0
|
213 |
HBUF* hBuf = HBUF::NewMax(11);
|
sl@0
|
214 |
lStr.Assign(hBuf); //Create LString as EBufCPtr type
|
sl@0
|
215 |
test(lStr.Length() == 11);
|
sl@0
|
216 |
test(lStr.MaxLength() >= 11); //There could me more allocated memory - see HBufC8::Des()
|
sl@0
|
217 |
|
sl@0
|
218 |
HBUF* hBuf2 = HBUF::NewMax(5);
|
sl@0
|
219 |
lStr = hBuf2; //Create LString as EBufCPtr type
|
sl@0
|
220 |
test(lStr.Length() == 5);
|
sl@0
|
221 |
test(lStr.MaxLength() >= 5); //There could me more allocated memory - see HBufC8::Des()
|
sl@0
|
222 |
|
sl@0
|
223 |
test.Next(_L("Assign(const RBuf_& aRBuf) method"));
|
sl@0
|
224 |
|
sl@0
|
225 |
buf.Create(des);
|
sl@0
|
226 |
lStr.Assign(buf);
|
sl@0
|
227 |
|
sl@0
|
228 |
// the assignment trasnfers buf so the two strings should be equal
|
sl@0
|
229 |
test(lStr == des);
|
sl@0
|
230 |
test(lStr != buf);
|
sl@0
|
231 |
|
sl@0
|
232 |
}
|
sl@0
|
233 |
|
sl@0
|
234 |
/**
|
sl@0
|
235 |
@SYMTestCaseID SYSLIB-EUSERHL-UT-4003
|
sl@0
|
236 |
@SYMTestCaseDesc Tests AppendL methods of LString
|
sl@0
|
237 |
@SYMTestPriority High
|
sl@0
|
238 |
@SYMTestActions Creates LString objects and uses AppendL methods to append
|
sl@0
|
239 |
data to the LString.
|
sl@0
|
240 |
Checks that the data is appended as expected.
|
sl@0
|
241 |
@SYMTestExpectedResults LString objects are created and data appended as
|
sl@0
|
242 |
expected with the strings grouwing as necessary to accomodate
|
sl@0
|
243 |
the new data.
|
sl@0
|
244 |
@SYMREQ 10372
|
sl@0
|
245 |
*/
|
sl@0
|
246 |
template<class LSTRING, class TBUF, class TTEXT, class CHAR>
|
sl@0
|
247 |
LOCAL_C void TestAppendL(LSTRING*)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4003"));
|
sl@0
|
250 |
|
sl@0
|
251 |
LSTRING lStr;
|
sl@0
|
252 |
LSTRING lStr2;
|
sl@0
|
253 |
TBUF des(_TS("123456"));
|
sl@0
|
254 |
TBUF des2(_TS("123456A"));
|
sl@0
|
255 |
|
sl@0
|
256 |
|
sl@0
|
257 |
test.Next(_L("AppendL(const TDesc_& aDes) method"));
|
sl@0
|
258 |
|
sl@0
|
259 |
lStr.AppendL(des);
|
sl@0
|
260 |
test(lStr == des);
|
sl@0
|
261 |
|
sl@0
|
262 |
test.Next(_L("AppendL(const TUint16* aBuf, TInt aLength) method"));
|
sl@0
|
263 |
|
sl@0
|
264 |
lStr2 = des;
|
sl@0
|
265 |
lStr.Reset();
|
sl@0
|
266 |
lStr.AppendL(lStr2.PtrZL(),lStr2.Length());
|
sl@0
|
267 |
test(lStr == des);
|
sl@0
|
268 |
|
sl@0
|
269 |
test.Next(_L("AppendL(TChar aChar) method"));
|
sl@0
|
270 |
|
sl@0
|
271 |
TChar c = 'A';
|
sl@0
|
272 |
lStr = des;
|
sl@0
|
273 |
lStr.AppendL(c);
|
sl@0
|
274 |
test(lStr == des2);
|
sl@0
|
275 |
|
sl@0
|
276 |
test.Next(_L("ZeroTerminateL() method"));
|
sl@0
|
277 |
|
sl@0
|
278 |
lStr = des;
|
sl@0
|
279 |
lStr.ZeroTerminateL();
|
sl@0
|
280 |
test(lStr == des);
|
sl@0
|
281 |
|
sl@0
|
282 |
test.Next(_L("AppendL(char/wchar_t* aCharStr) method"));
|
sl@0
|
283 |
|
sl@0
|
284 |
LSTRING lStr3(_CS("0123456789"));
|
sl@0
|
285 |
test(lStr3.Length() == 10);
|
sl@0
|
286 |
test(lStr3.MaxLength() >= 10);
|
sl@0
|
287 |
|
sl@0
|
288 |
LSTRING lStr4(_CS("01234567890"));
|
sl@0
|
289 |
test(lStr4.Length() == 11);
|
sl@0
|
290 |
test(lStr4.MaxLength() >= 11);
|
sl@0
|
291 |
|
sl@0
|
292 |
lStr3.AppendL(_CS("0"),1);
|
sl@0
|
293 |
test(lStr3 == lStr4);
|
sl@0
|
294 |
|
sl@0
|
295 |
lStr4.AppendL(_CS("0123456789"),10);
|
sl@0
|
296 |
test(lStr4.Length() == 21);
|
sl@0
|
297 |
test(lStr4.MaxLength() >= 21);
|
sl@0
|
298 |
|
sl@0
|
299 |
test.Next(_L("operator + (char/wchar_t* aCharStr) method"));
|
sl@0
|
300 |
|
sl@0
|
301 |
LSTRING lStr5(_CS("0123456789"));
|
sl@0
|
302 |
test(lStr5.Length() == 10);
|
sl@0
|
303 |
test(lStr5.MaxLength() >= 10);
|
sl@0
|
304 |
|
sl@0
|
305 |
LSTRING lStr6(_CS("01234567890"));
|
sl@0
|
306 |
test(lStr6.Length() == 11);
|
sl@0
|
307 |
test(lStr6.MaxLength() >= 11);
|
sl@0
|
308 |
|
sl@0
|
309 |
lStr5+=_CS("0");
|
sl@0
|
310 |
test(lStr5 == lStr6);
|
sl@0
|
311 |
|
sl@0
|
312 |
lStr6 +=_CS("0123456789");
|
sl@0
|
313 |
test(lStr6.Length() == 21);
|
sl@0
|
314 |
test(lStr6.MaxLength() >= 21);
|
sl@0
|
315 |
|
sl@0
|
316 |
}
|
sl@0
|
317 |
|
sl@0
|
318 |
/**
|
sl@0
|
319 |
Tests the following methods.
|
sl@0
|
320 |
- TInt ReAlloc(TInt aMaxLength);
|
sl@0
|
321 |
*/
|
sl@0
|
322 |
/**
|
sl@0
|
323 |
@SYMTestCaseID SYSLIB-EUSERHL-UT-4004
|
sl@0
|
324 |
@SYMTestCaseDesc Tests ReAlloc methods of LString
|
sl@0
|
325 |
@SYMTestPriority High
|
sl@0
|
326 |
@SYMTestActions Creates LString objects and uses ReAlloc to decrease,
|
sl@0
|
327 |
increase and zero memory. Validates that length and
|
sl@0
|
328 |
maxlength are changed as expected
|
sl@0
|
329 |
@SYMTestExpectedResults ReAlloc should change the length and maxLength
|
sl@0
|
330 |
of the LString data as expected
|
sl@0
|
331 |
@SYMREQ 10372
|
sl@0
|
332 |
*/
|
sl@0
|
333 |
template<class LSTRING, class TBUF, class TTEXT, class HBUF>
|
sl@0
|
334 |
LOCAL_C void TestReAllocL(LSTRING*)
|
sl@0
|
335 |
{
|
sl@0
|
336 |
test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4004"));
|
sl@0
|
337 |
|
sl@0
|
338 |
test.Next(_L("ReAlloc(TInt aMaxLength) method"));
|
sl@0
|
339 |
|
sl@0
|
340 |
TBUF des (_TS("0123456"));
|
sl@0
|
341 |
|
sl@0
|
342 |
//reallocate EPtr type - decrease memory
|
sl@0
|
343 |
LSTRING lStr(des);
|
sl@0
|
344 |
lStr.SetLengthL(3);
|
sl@0
|
345 |
test(lStr.ReAlloc(3)==KErrNone); //ReAlloc to EPtr
|
sl@0
|
346 |
test(lStr.MaxLength()>=3);
|
sl@0
|
347 |
test(lStr.Length()==3);
|
sl@0
|
348 |
test(lStr[0] == (TTEXT)('0'));
|
sl@0
|
349 |
test(lStr[2] == (TTEXT)('2'));
|
sl@0
|
350 |
|
sl@0
|
351 |
//reallocate EBufCPtr type - decrease memory
|
sl@0
|
352 |
HBUF* hBuf = HBUF::NewMax(9);
|
sl@0
|
353 |
*hBuf = _TS("012345678");
|
sl@0
|
354 |
lStr.Assign(hBuf); //Create as EBufCPtr
|
sl@0
|
355 |
lStr.SetLengthL(5);
|
sl@0
|
356 |
test(lStr.ReAlloc(5)==KErrNone); //ReAlloc to EBufCPtr
|
sl@0
|
357 |
test(lStr.MaxLength()>=5);//There could be more allocated memory - see HBufC8::Des()
|
sl@0
|
358 |
test(lStr.Length()==5);
|
sl@0
|
359 |
test(lStr[0] == (TTEXT)('0'));
|
sl@0
|
360 |
test(lStr[4] == (TTEXT)('4'));
|
sl@0
|
361 |
|
sl@0
|
362 |
//reallocate EBufCPtr type - increase memory
|
sl@0
|
363 |
hBuf = HBUF::NewMax(9);
|
sl@0
|
364 |
*hBuf = _TS("012345678");
|
sl@0
|
365 |
lStr.Assign(hBuf); //Create as EBufCPtr
|
sl@0
|
366 |
test(lStr.ReAlloc(15)==KErrNone); //ReAlloc to EBufCPtr
|
sl@0
|
367 |
test(lStr.MaxLength()>=15);//There could be more allocated memory - see HBufC8::Des()
|
sl@0
|
368 |
test(lStr.Length()==9);
|
sl@0
|
369 |
test(lStr[0] == (TTEXT)('0'));
|
sl@0
|
370 |
test(lStr[8] == (TTEXT)('8'));
|
sl@0
|
371 |
|
sl@0
|
372 |
//reallocate EPtr type - to zero-length
|
sl@0
|
373 |
lStr = des;
|
sl@0
|
374 |
lStr.SetLengthL(0);
|
sl@0
|
375 |
test(lStr.ReAlloc(0)==KErrNone); //ReAlloc to EPtr
|
sl@0
|
376 |
test(lStr.MaxLength()==0);
|
sl@0
|
377 |
test(lStr.Length()==0);
|
sl@0
|
378 |
|
sl@0
|
379 |
//reallocate EBufCPtr type to zero-length
|
sl@0
|
380 |
hBuf = HBUF::NewMax(9);
|
sl@0
|
381 |
*hBuf = _TS("012345678");
|
sl@0
|
382 |
lStr.Assign(hBuf); //Create as EBufCPtr
|
sl@0
|
383 |
lStr.SetLengthL(0);
|
sl@0
|
384 |
test(lStr.ReAlloc(0)==KErrNone); //ReAlloc to EPtr
|
sl@0
|
385 |
test(lStr.MaxLength()==0);
|
sl@0
|
386 |
test(lStr.Length()==0);
|
sl@0
|
387 |
|
sl@0
|
388 |
//reallocate from zero-length
|
sl@0
|
389 |
lStr.Reset();
|
sl@0
|
390 |
test(lStr.ReAlloc(9)==KErrNone); //ReAlloc to EPtr
|
sl@0
|
391 |
test(lStr.MaxLength() >=9);
|
sl@0
|
392 |
test(lStr.Length()==0);
|
sl@0
|
393 |
|
sl@0
|
394 |
//reallocate from zero-length to zero-length
|
sl@0
|
395 |
lStr.Reset();
|
sl@0
|
396 |
test(lStr.ReAlloc(0)==KErrNone); //ReAlloc to EPtr
|
sl@0
|
397 |
test(lStr.Length() == 0);
|
sl@0
|
398 |
test(lStr.MaxLength() == 0);
|
sl@0
|
399 |
}
|
sl@0
|
400 |
|
sl@0
|
401 |
/**
|
sl@0
|
402 |
Tests the following methods.
|
sl@0
|
403 |
- TInt ReAllocL(TInt aMaxLength);
|
sl@0
|
404 |
*/
|
sl@0
|
405 |
/**
|
sl@0
|
406 |
@SYMTestCaseID SYSLIB-EUSERHL-UT-4005
|
sl@0
|
407 |
@SYMTestCaseDesc Tests Leaving variant ReAllocL of LString
|
sl@0
|
408 |
@SYMTestPriority High
|
sl@0
|
409 |
@SYMTestActions Creates LString objects and uses ReAllocL to
|
sl@0
|
410 |
increase memory under OOM conditions
|
sl@0
|
411 |
Verifies that ReAllocL leaves with KErrNoMemory
|
sl@0
|
412 |
@SYMTestExpectedResults Calls to ReAllocL that increase memory should
|
sl@0
|
413 |
leave with KErrNoMemory under OOM conditions
|
sl@0
|
414 |
@SYMREQ 10372
|
sl@0
|
415 |
*/
|
sl@0
|
416 |
template<class LSTRING, class TBUF, class TTEXT>
|
sl@0
|
417 |
LOCAL_C void TestReAllocLeaving(LSTRING*)
|
sl@0
|
418 |
{
|
sl@0
|
419 |
|
sl@0
|
420 |
test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4005"));
|
sl@0
|
421 |
|
sl@0
|
422 |
test.Next(_L("ReAllocL(TInt aMaxLength) method"));
|
sl@0
|
423 |
TBUF des(_TS("01"));
|
sl@0
|
424 |
|
sl@0
|
425 |
LSTRING lStr(des);
|
sl@0
|
426 |
TRAPD(ret, lStr.ReAllocL(6)); //ReAlloc buffer
|
sl@0
|
427 |
test(KErrNone == ret);
|
sl@0
|
428 |
|
sl@0
|
429 |
#if defined(_DEBUG)
|
sl@0
|
430 |
__UHEAP_FAILNEXT(1);
|
sl@0
|
431 |
TRAP(ret, lStr.ReAllocL(100)); //Realloc buffer. This should fail.
|
sl@0
|
432 |
test(KErrNoMemory == ret);
|
sl@0
|
433 |
#endif //(_DEBUG)
|
sl@0
|
434 |
|
sl@0
|
435 |
test(lStr.MaxLength() >=6); //Check LString is the same as before ...
|
sl@0
|
436 |
test(lStr.Length()==2); //... ReAlloc that failed.
|
sl@0
|
437 |
test(lStr[0] == (TTEXT)('0'));
|
sl@0
|
438 |
test(lStr[1] == (TTEXT)('1'));
|
sl@0
|
439 |
}
|
sl@0
|
440 |
|
sl@0
|
441 |
|
sl@0
|
442 |
/**
|
sl@0
|
443 |
Tests the following methods.
|
sl@0
|
444 |
- void SwapL(LString& aBuf);
|
sl@0
|
445 |
- void SwapL(TDes& aBuf);
|
sl@0
|
446 |
*/
|
sl@0
|
447 |
/**
|
sl@0
|
448 |
@SYMTestCaseID SYSLIB-EUSERHL-UT-4006
|
sl@0
|
449 |
@SYMTestCaseDesc Tests SwapL methods of LString
|
sl@0
|
450 |
@SYMTestPriority High
|
sl@0
|
451 |
@SYMTestActions Creates LString objects and uses SwapL to
|
sl@0
|
452 |
swap string contents.
|
sl@0
|
453 |
Verifies that contents are swapped and memory
|
sl@0
|
454 |
reallocated where necessary
|
sl@0
|
455 |
@SYMTestExpectedResults Calls to SwapL should swap string contents
|
sl@0
|
456 |
and buffer should be automatically reallocated to fit the new data.
|
sl@0
|
457 |
@SYMREQ 10372
|
sl@0
|
458 |
*/
|
sl@0
|
459 |
template<class LSTRING, class TBUF, class TTEXT>
|
sl@0
|
460 |
LOCAL_C void TestSwapL(LSTRING*)
|
sl@0
|
461 |
{
|
sl@0
|
462 |
test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4006"));
|
sl@0
|
463 |
|
sl@0
|
464 |
LSTRING lStr1, lStr2;
|
sl@0
|
465 |
TBUF des1(_TS("12"));
|
sl@0
|
466 |
TBUF des2 (_TS("345678"));
|
sl@0
|
467 |
TBUF des3 (_TS("12345678"));
|
sl@0
|
468 |
TBUF swap_des = des2;
|
sl@0
|
469 |
|
sl@0
|
470 |
test.Next(_L("Swap(LString_& aLString) method"));
|
sl@0
|
471 |
|
sl@0
|
472 |
// assignment operation; implies deep copying
|
sl@0
|
473 |
lStr1 = des1;
|
sl@0
|
474 |
lStr2 = des2;
|
sl@0
|
475 |
|
sl@0
|
476 |
// swap LStrings with TDes
|
sl@0
|
477 |
// lStr1 should grow to accommodate swap_des
|
sl@0
|
478 |
lStr1.SwapL(swap_des);
|
sl@0
|
479 |
test(lStr1==des2);
|
sl@0
|
480 |
test(swap_des==des1);
|
sl@0
|
481 |
|
sl@0
|
482 |
// swap two LStrings
|
sl@0
|
483 |
// lStr2 should grow to accommodate lStr1
|
sl@0
|
484 |
lStr1 = des3;
|
sl@0
|
485 |
lStr1.SwapL(lStr2);
|
sl@0
|
486 |
|
sl@0
|
487 |
test(lStr1==des2);
|
sl@0
|
488 |
test(lStr2==des3);
|
sl@0
|
489 |
|
sl@0
|
490 |
}
|
sl@0
|
491 |
|
sl@0
|
492 |
|
sl@0
|
493 |
/**
|
sl@0
|
494 |
Test assignemnt operator.
|
sl@0
|
495 |
*/
|
sl@0
|
496 |
/**
|
sl@0
|
497 |
@SYMTestCaseID SYSLIB-EUSERHL-UT-4007
|
sl@0
|
498 |
@SYMTestCaseDesc Tests Assignment operator for LString
|
sl@0
|
499 |
@SYMTestPriority High
|
sl@0
|
500 |
@SYMTestActions Creates LString objects and uses assignment to
|
sl@0
|
501 |
change string contents.
|
sl@0
|
502 |
Verifies that contents are swapped and memory
|
sl@0
|
503 |
reallocated where necessary
|
sl@0
|
504 |
@SYMTestExpectedResults Assignment operator should change string contents
|
sl@0
|
505 |
and buffer should be automatically reallocated to fit the new data.
|
sl@0
|
506 |
@SYMREQ 10372
|
sl@0
|
507 |
*/
|
sl@0
|
508 |
template<class LSTRING, class TBUF, class TBUFC, class TTEXT, class CHAR>
|
sl@0
|
509 |
LOCAL_C void TestAssignmentOperatorL()
|
sl@0
|
510 |
{
|
sl@0
|
511 |
test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4007"));
|
sl@0
|
512 |
|
sl@0
|
513 |
test.Next(_L("Assignment operator"));
|
sl@0
|
514 |
|
sl@0
|
515 |
TBUF tdes(_TS("Modifiable descriptor"));
|
sl@0
|
516 |
TBUFC tdesc(_TS("Non-modifiable descriptor"));
|
sl@0
|
517 |
|
sl@0
|
518 |
LSTRING lStr(32);
|
sl@0
|
519 |
LSTRING lStr2(32);
|
sl@0
|
520 |
lStr2.CopyL(_TS("Buffer descriptor"), 17);
|
sl@0
|
521 |
|
sl@0
|
522 |
lStr = tdesc; test(lStr == tdesc);
|
sl@0
|
523 |
lStr = tdes; test(lStr == tdes);
|
sl@0
|
524 |
lStr = lStr2; test(lStr == lStr2);
|
sl@0
|
525 |
|
sl@0
|
526 |
LSTRING lStr3(tdes);
|
sl@0
|
527 |
lStr = lStr3.PtrZL(); test(lStr == tdes);
|
sl@0
|
528 |
|
sl@0
|
529 |
test.Next(_L("operator=(char/wchar_t* aCharStr) method"));
|
sl@0
|
530 |
LSTRING lStr4(_CS("123456"));
|
sl@0
|
531 |
LSTRING lStr5 = _CS("123456");
|
sl@0
|
532 |
test(lStr4 == lStr5);
|
sl@0
|
533 |
|
sl@0
|
534 |
LSTRING lStr6;
|
sl@0
|
535 |
lStr6 = _CS("123456");
|
sl@0
|
536 |
test(lStr4 == lStr6);
|
sl@0
|
537 |
}
|
sl@0
|
538 |
|
sl@0
|
539 |
/**
|
sl@0
|
540 |
Test Capacity growth and compression
|
sl@0
|
541 |
*/
|
sl@0
|
542 |
/**
|
sl@0
|
543 |
@SYMTestCaseID SYSLIB-EUSERHL-UT-4008
|
sl@0
|
544 |
@SYMTestCaseDesc Tests capacity growth and compression for LString
|
sl@0
|
545 |
@SYMTestPriority High
|
sl@0
|
546 |
@SYMTestActions Creates an LString object then calls SetMaxLength and Compress
|
sl@0
|
547 |
to increase or decrease underlying buffer size.
|
sl@0
|
548 |
Tests that Length and Maxlength are modified as expected
|
sl@0
|
549 |
@SYMTestExpectedResults SetMaxLength and Compress should resize the underlying
|
sl@0
|
550 |
buffer as expected.
|
sl@0
|
551 |
@SYMREQ 10372
|
sl@0
|
552 |
*/
|
sl@0
|
553 |
template<class LSTRING, class TBUF, class TTEXT>
|
sl@0
|
554 |
LOCAL_C void TestCapacityChangesL(LSTRING*)
|
sl@0
|
555 |
{
|
sl@0
|
556 |
test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4008"));
|
sl@0
|
557 |
|
sl@0
|
558 |
test.Next(_L("Test capacity growth and compression on LString"));
|
sl@0
|
559 |
|
sl@0
|
560 |
LSTRING lStr(_TS("0123456"));
|
sl@0
|
561 |
test(lStr.Length()==7);
|
sl@0
|
562 |
test(lStr.MaxLength() >=7);
|
sl@0
|
563 |
|
sl@0
|
564 |
lStr.SetMaxLengthL(10);
|
sl@0
|
565 |
test(lStr.Length()==7);
|
sl@0
|
566 |
test(lStr.MaxLength() >=10);
|
sl@0
|
567 |
|
sl@0
|
568 |
lStr.SetMaxLengthL(6);
|
sl@0
|
569 |
test(lStr.Length()==6);
|
sl@0
|
570 |
test(lStr.MaxLength() >=6);
|
sl@0
|
571 |
|
sl@0
|
572 |
lStr.SetMaxLengthL(10);
|
sl@0
|
573 |
test(lStr.Length()==6);
|
sl@0
|
574 |
test(lStr.MaxLength() >=10);
|
sl@0
|
575 |
|
sl@0
|
576 |
//Call the same thing again to check the condition
|
sl@0
|
577 |
//that required length is already set
|
sl@0
|
578 |
lStr.SetMaxLengthL(10);
|
sl@0
|
579 |
test(lStr.Length()==6);
|
sl@0
|
580 |
test(lStr.MaxLength() >=10);
|
sl@0
|
581 |
|
sl@0
|
582 |
lStr.Compress();
|
sl@0
|
583 |
test(lStr.Length()==6);
|
sl@0
|
584 |
test(lStr.MaxLength() >= 6);
|
sl@0
|
585 |
|
sl@0
|
586 |
//Call the same thing again to check the condition
|
sl@0
|
587 |
//that the string is already compressed
|
sl@0
|
588 |
lStr.Compress();
|
sl@0
|
589 |
test(lStr.Length()==6);
|
sl@0
|
590 |
test(lStr.MaxLength() >= 6);
|
sl@0
|
591 |
|
sl@0
|
592 |
lStr.ReserveFreeCapacityL(15);
|
sl@0
|
593 |
test(lStr.Length()==6);
|
sl@0
|
594 |
test(lStr.MaxLength() >= 32);
|
sl@0
|
595 |
|
sl@0
|
596 |
lStr.Reset();
|
sl@0
|
597 |
test(lStr.Length()==0);
|
sl@0
|
598 |
test(lStr.MaxLength() == 0);
|
sl@0
|
599 |
|
sl@0
|
600 |
}
|
sl@0
|
601 |
|
sl@0
|
602 |
|
sl@0
|
603 |
/**
|
sl@0
|
604 |
Test copying from 16bit to 8bit and vice versa
|
sl@0
|
605 |
*/
|
sl@0
|
606 |
/**
|
sl@0
|
607 |
@SYMTestCaseID SYSLIB-EUSERHL-UT-4009
|
sl@0
|
608 |
@SYMTestCaseDesc Tests Copying between 8 and 16 bit LString variants
|
sl@0
|
609 |
@SYMTestPriority High
|
sl@0
|
610 |
@SYMTestActions Creates an LString8 and LString16 object and uses the cross-variant
|
sl@0
|
611 |
Copy functions to copy data between the variants.
|
sl@0
|
612 |
@SYMTestExpectedResults Data is successfully copied between the variants.
|
sl@0
|
613 |
@SYMREQ 10372
|
sl@0
|
614 |
*/
|
sl@0
|
615 |
LOCAL_C void TestCrossCopyingL()
|
sl@0
|
616 |
{
|
sl@0
|
617 |
|
sl@0
|
618 |
test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4009"));
|
sl@0
|
619 |
|
sl@0
|
620 |
test.Next(_L("Test cross copying on LString"));
|
sl@0
|
621 |
|
sl@0
|
622 |
LString8 lStr8("0123");
|
sl@0
|
623 |
LString16 lStr16(L"01234567");
|
sl@0
|
624 |
|
sl@0
|
625 |
LString8 targetStr8;
|
sl@0
|
626 |
LString16 targetStr16;
|
sl@0
|
627 |
|
sl@0
|
628 |
targetStr8.CopyL(lStr16);
|
sl@0
|
629 |
targetStr16.CopyL(lStr8);
|
sl@0
|
630 |
}
|
sl@0
|
631 |
|
sl@0
|
632 |
|
sl@0
|
633 |
/**
|
sl@0
|
634 |
Test creating an LString from a stream
|
sl@0
|
635 |
*/
|
sl@0
|
636 |
/**
|
sl@0
|
637 |
@SYMTestCaseID SYSLIB-EUSERHL-UT-4010
|
sl@0
|
638 |
@SYMTestCaseDesc Tests Creating an LString from a stream
|
sl@0
|
639 |
@SYMTestPriority High
|
sl@0
|
640 |
@SYMTestActions Creates a in-memory stream and writes some data to it.
|
sl@0
|
641 |
Creates an LString from a readstream and verifies that the
|
sl@0
|
642 |
contents of the LString match the data written to the stream.
|
sl@0
|
643 |
@SYMTestExpectedResults The LString contents should match the data written
|
sl@0
|
644 |
to the stream.
|
sl@0
|
645 |
@SYMREQ 10372
|
sl@0
|
646 |
*/
|
sl@0
|
647 |
template<class LSTRING, class TTEXT>
|
sl@0
|
648 |
LOCAL_C void TestReadFromStreamL()
|
sl@0
|
649 |
{
|
sl@0
|
650 |
test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4010"));
|
sl@0
|
651 |
|
sl@0
|
652 |
test.Next(_L("Test creating LString from a stream"));
|
sl@0
|
653 |
|
sl@0
|
654 |
RFs fs;
|
sl@0
|
655 |
fs.Connect() OR_LEAVE;
|
sl@0
|
656 |
|
sl@0
|
657 |
LSTRING outString = _TS("This is a test string written to a stream");
|
sl@0
|
658 |
|
sl@0
|
659 |
//Create a buffer to contain the stream
|
sl@0
|
660 |
CBufFlat* buf = CBufFlat::NewL(outString.MaxLength());
|
sl@0
|
661 |
|
sl@0
|
662 |
//Create a write stream
|
sl@0
|
663 |
RBufWriteStream outStream;
|
sl@0
|
664 |
outStream.Open(*buf);
|
sl@0
|
665 |
|
sl@0
|
666 |
//write some data to the stream
|
sl@0
|
667 |
outStream << outString;
|
sl@0
|
668 |
outStream.CommitL();
|
sl@0
|
669 |
|
sl@0
|
670 |
//Open a readstream
|
sl@0
|
671 |
RBufReadStream inStream;
|
sl@0
|
672 |
inStream.Open(*buf);
|
sl@0
|
673 |
|
sl@0
|
674 |
//Create an LString from the stream
|
sl@0
|
675 |
LSTRING inString;
|
sl@0
|
676 |
inString.CreateL(inStream,outString.Length());
|
sl@0
|
677 |
test(inString == outString);
|
sl@0
|
678 |
|
sl@0
|
679 |
delete buf;
|
sl@0
|
680 |
}
|
sl@0
|
681 |
|
sl@0
|
682 |
/**
|
sl@0
|
683 |
Test support for [wide]character strings.
|
sl@0
|
684 |
APIs that modify data.
|
sl@0
|
685 |
*/
|
sl@0
|
686 |
/**
|
sl@0
|
687 |
@SYMTestCaseID BASESRVCS-EUSERHL-UT-4068
|
sl@0
|
688 |
@SYMTestCaseDesc Test the APIs provided to support wchar_t and char strings
|
sl@0
|
689 |
@SYMTestPriority High
|
sl@0
|
690 |
@SYMTestActions 1)Construct LString object from the supplied null terminated
|
sl@0
|
691 |
character string.
|
sl@0
|
692 |
2)Assign new string to the constructed LString object
|
sl@0
|
693 |
3)Appends data onto the end of this LString object's data.
|
sl@0
|
694 |
The length of this descriptor is incremented to reflect the new content.
|
sl@0
|
695 |
4)Copy new data into the LString object, replacing any existing
|
sl@0
|
696 |
data, and expanding its heap buffer to accommodate if necessary.
|
sl@0
|
697 |
5)Insert contents into the LString
|
sl@0
|
698 |
6)Replace data to the end of the LString object and justify it.
|
sl@0
|
699 |
7)Append data of specified length, to the end of the LString object.
|
sl@0
|
700 |
8)Justify data, to the end of the LString object.
|
sl@0
|
701 |
9)Appends data onto the end of this descriptor's data and justifies it.
|
sl@0
|
702 |
@SYMTestExpectedResults The LString contents should match the data expected after the operation.
|
sl@0
|
703 |
@SYMREQ 10372
|
sl@0
|
704 |
*/
|
sl@0
|
705 |
|
sl@0
|
706 |
template<class LSTRING, class TTEXT, class CHAR>
|
sl@0
|
707 |
LOCAL_C void TestCharacterStringSupport_Modifiers(LSTRING*)
|
sl@0
|
708 |
{
|
sl@0
|
709 |
test.Next (_L ("@SYMTestCaseID:BASESRVCS-EUSERHL-UT-4068"));
|
sl@0
|
710 |
|
sl@0
|
711 |
// 1. test Constructor
|
sl@0
|
712 |
// Constructs LString object from the supplied null terminated
|
sl@0
|
713 |
// character string
|
sl@0
|
714 |
test.Next(_L("LString_(char/wchar_t * aCharStr) constructor"));
|
sl@0
|
715 |
LSTRING lStr(_CS("0123456789"));
|
sl@0
|
716 |
test(lStr.Length() == 10);
|
sl@0
|
717 |
test(lStr.MaxLength() >= 10);
|
sl@0
|
718 |
test(lStr.Compare(_CS("0123456789")) == 0 );
|
sl@0
|
719 |
// try strings ending with 0
|
sl@0
|
720 |
LSTRING lStr1(_CS("01234567890"));
|
sl@0
|
721 |
test(lStr1.Length() == 11);
|
sl@0
|
722 |
test(lStr1.MaxLength() >= 11);
|
sl@0
|
723 |
test(lStr1.Compare(_CS("01234567890")) == 0 );
|
sl@0
|
724 |
|
sl@0
|
725 |
// 2. test '=' operator
|
sl@0
|
726 |
LSTRING lTestStr;
|
sl@0
|
727 |
// Assign new string to the constructed LString object
|
sl@0
|
728 |
test.Next(_L("LString_ operator '=' "));
|
sl@0
|
729 |
lTestStr = _CS("Try a New String");
|
sl@0
|
730 |
test(lTestStr.Compare(_CS("Try a New String")) == 0 );
|
sl@0
|
731 |
test(lTestStr.Length() == 16);
|
sl@0
|
732 |
test(lTestStr.MaxLength() >= 16);
|
sl@0
|
733 |
|
sl@0
|
734 |
// 3. test '+=' operator
|
sl@0
|
735 |
// Appends data onto the end of this LString object's data.
|
sl@0
|
736 |
// The length of this descriptor is incremented to reflect the new content.
|
sl@0
|
737 |
test.Next(_L("LString_ operator '+=' "));
|
sl@0
|
738 |
lTestStr += _CS("!!!");
|
sl@0
|
739 |
test(lTestStr.Compare(_CS("Try a New String!!!")) == 0 );
|
sl@0
|
740 |
test(lTestStr.Length() == 19);
|
sl@0
|
741 |
test(lTestStr.MaxLength() >= 19);
|
sl@0
|
742 |
|
sl@0
|
743 |
// 4.Test "Copy()" Variants
|
sl@0
|
744 |
LSTRING lTestStr1;
|
sl@0
|
745 |
LSTRING lTestStr2;
|
sl@0
|
746 |
// Copy new data into the LString object, replacing any existing
|
sl@0
|
747 |
// data, and expanding its heap buffer to accommodate if necessary.
|
sl@0
|
748 |
test.Next(_L("LString_ CopyL "));
|
sl@0
|
749 |
lTestStr1.CopyL(_TS("Try a New String"));
|
sl@0
|
750 |
test(lTestStr1.Compare(_TS("Try a New String")) == 0 );
|
sl@0
|
751 |
test(lTestStr1.Length() == 16);
|
sl@0
|
752 |
test(lTestStr1.MaxLength() >= 16);
|
sl@0
|
753 |
|
sl@0
|
754 |
// Copy folded(normalized) content
|
sl@0
|
755 |
test.Next(_L("LString_ CopyFL "));
|
sl@0
|
756 |
lTestStr1.CopyFL(_CS("Some RaNDom STRING"));
|
sl@0
|
757 |
lTestStr2.CopyFL(_CS("SOME RaNDom string"));
|
sl@0
|
758 |
test(lTestStr1.Compare(lTestStr2) == 0);
|
sl@0
|
759 |
|
sl@0
|
760 |
// Copy contents in Lower case
|
sl@0
|
761 |
test.Next(_L("LString_ CopyLCL "));
|
sl@0
|
762 |
lTestStr1.CopyLCL(_CS("SOME STRING IN UPPER CASE"));
|
sl@0
|
763 |
test(lTestStr1 == _CS("some string in upper case"));
|
sl@0
|
764 |
|
sl@0
|
765 |
// Copy contents in Upper case
|
sl@0
|
766 |
test.Next(_L("LString_ CopyUCL "));
|
sl@0
|
767 |
lTestStr1.CopyUCL(_CS("some string in lower case"));
|
sl@0
|
768 |
test(lTestStr1 == _CS("SOME STRING IN LOWER CASE"));
|
sl@0
|
769 |
|
sl@0
|
770 |
// Copy Capitalized contents
|
sl@0
|
771 |
test.Next(_L("LString_ CopyCPL "));
|
sl@0
|
772 |
lTestStr1.CopyCPL(_CS("some string in lower case"));
|
sl@0
|
773 |
test(lTestStr1 == _CS("Some string in lower case"));
|
sl@0
|
774 |
|
sl@0
|
775 |
// 5. Test Insert()
|
sl@0
|
776 |
LSTRING lTestStr3;
|
sl@0
|
777 |
// Insert contents into a string
|
sl@0
|
778 |
test.Next(_L("LString_ InsertL "));
|
sl@0
|
779 |
lTestStr3 = _CS("Some Content Can Be Into This String");
|
sl@0
|
780 |
lTestStr3.InsertL(20,_CS("Inserted "));
|
sl@0
|
781 |
test(lTestStr3 == _CS("Some Content Can Be Inserted Into This String"));
|
sl@0
|
782 |
|
sl@0
|
783 |
// 6. Test Replace()
|
sl@0
|
784 |
LSTRING lTestStr4;
|
sl@0
|
785 |
// Replace contents form the string
|
sl@0
|
786 |
test.Next(_L("LString_ ReplaceL "));
|
sl@0
|
787 |
lTestStr4 = _CS("Some Content Can Be Decalper");
|
sl@0
|
788 |
lTestStr4.ReplaceL(20,8,_CS("Replaced"));
|
sl@0
|
789 |
test(lTestStr4 == _CS("Some Content Can Be Replaced"));
|
sl@0
|
790 |
|
sl@0
|
791 |
// 7. Test Append()
|
sl@0
|
792 |
LSTRING lTestStr5;
|
sl@0
|
793 |
//Append data of specified length, to the end of the LString object.
|
sl@0
|
794 |
test.Next(_L("LString_ AppendL(src,length)"));
|
sl@0
|
795 |
lTestStr5.CopyL( _CS("Try appending "));
|
sl@0
|
796 |
lTestStr5.AppendL(_CS("Try appending some more"),3);
|
sl@0
|
797 |
test(lTestStr5 == _CS("Try appending Try"));
|
sl@0
|
798 |
|
sl@0
|
799 |
//Append data , to the end of the LString object.
|
sl@0
|
800 |
test.Next(_L("LString_ AppendL(src)"));
|
sl@0
|
801 |
lTestStr5.CopyL( _CS("Try appending "));
|
sl@0
|
802 |
lTestStr5.AppendL(_CS("Try appending some more"));
|
sl@0
|
803 |
test(lTestStr5 == _CS("Try appending Try appending some more"));
|
sl@0
|
804 |
|
sl@0
|
805 |
// 8. Test Justify()
|
sl@0
|
806 |
LSTRING lTestStr6;
|
sl@0
|
807 |
//Copy data into this descriptor and justifies it, replacing any existing data
|
sl@0
|
808 |
test.Next(_L("LString_ JustifyL "));
|
sl@0
|
809 |
lTestStr6.CopyL(_CS("Justified"));
|
sl@0
|
810 |
lTestStr6.JustifyL(_CS("Just"),9,ERight,*(_TS("x")));
|
sl@0
|
811 |
test(lTestStr6 == _CS("xxxxxJust"));
|
sl@0
|
812 |
|
sl@0
|
813 |
// 9. Test AppendJustify variants
|
sl@0
|
814 |
LSTRING lTestStr7;
|
sl@0
|
815 |
// Append data to the end of the LString object and justify it.
|
sl@0
|
816 |
test.Next(_L("LString_ AppendJustifyL(const char*,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)"));
|
sl@0
|
817 |
lTestStr7.CopyL(_CS("One "));
|
sl@0
|
818 |
lTestStr7.AppendJustifyL(_CS("Two "),KDefaultJustifyWidth,ERight,*(_TS("x")));
|
sl@0
|
819 |
test(lTestStr7 == _TS("One Two "));
|
sl@0
|
820 |
|
sl@0
|
821 |
lTestStr7.CopyL(_CS("One "));
|
sl@0
|
822 |
lTestStr7.AppendJustifyL(_CS("Two Three"),3,7,ERight,*(_TS("x")));
|
sl@0
|
823 |
test(lTestStr7 == _CS("One xxxxTwo") );
|
sl@0
|
824 |
|
sl@0
|
825 |
// Append data to the end of the LString object and justify it.
|
sl@0
|
826 |
test.Next(_L("LString_ AppendJustifyL(const char* aCharStr,TInt aWidth,TAlign anAlignment,TChar aFill)"));
|
sl@0
|
827 |
lTestStr7.CopyL(_CS("One "));
|
sl@0
|
828 |
lTestStr7.AppendJustifyL(_CS("Two Three"),KDefaultJustifyWidth,ERight,*(_TS("x")));
|
sl@0
|
829 |
test(lTestStr7 == _TS("One Two Three"));
|
sl@0
|
830 |
|
sl@0
|
831 |
lTestStr7.CopyL(_CS("One "));
|
sl@0
|
832 |
lTestStr7.AppendJustifyL(_CS("Two Three"),13,ERight,*(_TS("x")));
|
sl@0
|
833 |
test(lTestStr7 == _CS("One xxxxTwo Three") );
|
sl@0
|
834 |
}
|
sl@0
|
835 |
|
sl@0
|
836 |
/**
|
sl@0
|
837 |
Test support for [wide]character strings.
|
sl@0
|
838 |
APIs that do not modify any data.
|
sl@0
|
839 |
*/
|
sl@0
|
840 |
/**
|
sl@0
|
841 |
@SYMTestCaseID BASESRVCS-EUSERHL-UT-4069
|
sl@0
|
842 |
@SYMTestCaseDesc Test the APIs provided to support wchar_t and char strings
|
sl@0
|
843 |
@SYMTestPriority High
|
sl@0
|
844 |
@SYMTestActions 1)Determine whether this descriptor's data is equal to the specified string's data.
|
sl@0
|
845 |
2)Determine whether this descriptor's data is less than the specified string's data.
|
sl@0
|
846 |
3)Determine whether this descriptor's data is less than or equal to the specified string's data.
|
sl@0
|
847 |
4)Determine whether this descriptor's data is greater than the specified string's data.
|
sl@0
|
848 |
5)Determine whether this descriptor's data is greater than or equal to the specified string's data.
|
sl@0
|
849 |
6)Determine whether this descriptor's data is not equal to the specified string's data.
|
sl@0
|
850 |
7)Compare this descriptor's data with the specified string's data.
|
sl@0
|
851 |
8)Search this descriptor's data for a match with the match pattern supplied in the specified string's
|
sl@0
|
852 |
9)Searches for the first occurrence of the specified data sequence within this descriptor
|
sl@0
|
853 |
@SYMTestExpectedResults The operation/comparision must result in the desired output
|
sl@0
|
854 |
@SYMREQ 10372
|
sl@0
|
855 |
*/
|
sl@0
|
856 |
template<class LSTRING,class TTEXT, class CHAR>
|
sl@0
|
857 |
LOCAL_C void TestCharacterStringSupport_NonModifiers(LSTRING*)
|
sl@0
|
858 |
{
|
sl@0
|
859 |
test.Next (_L ("@SYMTestCaseID:BASESRVCS-EUSERHL-UT-4069"));
|
sl@0
|
860 |
|
sl@0
|
861 |
// 1.test '==' operator
|
sl@0
|
862 |
LSTRING lTestStr1;
|
sl@0
|
863 |
lTestStr1.CopyL(_CS("Are they equal?? "));
|
sl@0
|
864 |
test(lTestStr1 == _CS("Are they equal?? "));
|
sl@0
|
865 |
lTestStr1.CopyL(_CS("12345670"));
|
sl@0
|
866 |
test(lTestStr1 == _CS("12345670"));
|
sl@0
|
867 |
|
sl@0
|
868 |
// 2.test "<" operator
|
sl@0
|
869 |
LSTRING lTestStr2;
|
sl@0
|
870 |
lTestStr2.CopyL(_CS("ABCDEFGH"));
|
sl@0
|
871 |
test(lTestStr2 < _CS("abcdefgh"));
|
sl@0
|
872 |
lTestStr2.CopyL(_CS(" Is this is smaller"));
|
sl@0
|
873 |
test(lTestStr2 < _CS("No, larger of the string is greater than the smaller one"));
|
sl@0
|
874 |
|
sl@0
|
875 |
// 3.test "<=" operator
|
sl@0
|
876 |
LSTRING lTestStr3;
|
sl@0
|
877 |
lTestStr3.CopyL(_CS("ABCDEFGH"));
|
sl@0
|
878 |
test(lTestStr3 <= _CS("abcdefgh"));
|
sl@0
|
879 |
lTestStr3.CopyL(_CS("equals"));
|
sl@0
|
880 |
test(lTestStr3 <= _CS("equals"));
|
sl@0
|
881 |
|
sl@0
|
882 |
// 4.test ">" operator
|
sl@0
|
883 |
LSTRING lTestStr4;
|
sl@0
|
884 |
lTestStr4.CopyL(_CS("abcdefgh"));
|
sl@0
|
885 |
test(lTestStr4 > _CS("ABCDEFGH"));
|
sl@0
|
886 |
lTestStr4.CopyL(_CS("No, larger of the string is greater than the smaller one"));
|
sl@0
|
887 |
test(lTestStr4 > _CS("Is this smaller??"));
|
sl@0
|
888 |
|
sl@0
|
889 |
// 5.test ">=" operator
|
sl@0
|
890 |
LSTRING lTestStr5;
|
sl@0
|
891 |
lTestStr5.CopyL(_CS("abcdefgh"));
|
sl@0
|
892 |
test(lTestStr5 >= _CS("ABCDEFGH"));
|
sl@0
|
893 |
lTestStr5.CopyL(_CS("equals"));
|
sl@0
|
894 |
test(lTestStr5 >= _CS("equals"));
|
sl@0
|
895 |
|
sl@0
|
896 |
// 6.test "!="
|
sl@0
|
897 |
LSTRING lTestStr6;
|
sl@0
|
898 |
lTestStr6.CopyL(_CS("abcdefgh"));
|
sl@0
|
899 |
test(lTestStr6 != _CS("ABCDEFGH"));
|
sl@0
|
900 |
lTestStr6.CopyL(_CS("equals"));
|
sl@0
|
901 |
test(!(lTestStr6 != _CS("equals")));
|
sl@0
|
902 |
|
sl@0
|
903 |
// 7.test Compare variants
|
sl@0
|
904 |
LSTRING lTestStr7;
|
sl@0
|
905 |
// Compare strict
|
sl@0
|
906 |
lTestStr7.CopyL(_CS("abcdefgh"));
|
sl@0
|
907 |
test(lTestStr7.Compare(_CS("ABCDEFGH")) > 0);
|
sl@0
|
908 |
lTestStr7.CopyL(_CS("ABCDEFGH"));
|
sl@0
|
909 |
test(lTestStr7.Compare(_CS("abcdefgh")) < 0);
|
sl@0
|
910 |
lTestStr5.CopyL(_CS("equals"));
|
sl@0
|
911 |
test(lTestStr5.Compare( _CS("equals")) == 0);
|
sl@0
|
912 |
// Compare foalded
|
sl@0
|
913 |
lTestStr7.CopyL(_CS("abcdefgh"));
|
sl@0
|
914 |
test(lTestStr7.CompareF(_CS("ABcDeFgH")) == 0);
|
sl@0
|
915 |
|
sl@0
|
916 |
// 8.test Match variants
|
sl@0
|
917 |
LSTRING lTestStr8;
|
sl@0
|
918 |
// Match strict
|
sl@0
|
919 |
lTestStr8.CopyL(_CS("abcdefghijklmnopqrstuvwxyz"));
|
sl@0
|
920 |
test(lTestStr8.Match(_CS("*ijk*"))== 8);
|
sl@0
|
921 |
test(lTestStr8.Match(_CS("*i?k*"))== 8);
|
sl@0
|
922 |
test(lTestStr8.Match(_CS("ijk*"))== KErrNotFound);
|
sl@0
|
923 |
// Match Folded
|
sl@0
|
924 |
test(lTestStr8.MatchF(_CS("*IjK*"))== 8);
|
sl@0
|
925 |
test(lTestStr8.MatchF(_CS("*I?k*"))== 8);
|
sl@0
|
926 |
test(lTestStr8.MatchF(_CS("ijK*"))== KErrNotFound);
|
sl@0
|
927 |
|
sl@0
|
928 |
// 9.test Find variants
|
sl@0
|
929 |
LSTRING lTestStr9;
|
sl@0
|
930 |
// Find strict
|
sl@0
|
931 |
lTestStr9.CopyL(_CS("abcdefghijklmnopqrstuvwxyz"));
|
sl@0
|
932 |
test(lTestStr9.Find(_CS("abcde")) == 0);
|
sl@0
|
933 |
test(lTestStr9.Find(_CS("cde")) == 2);
|
sl@0
|
934 |
test(lTestStr9.Find(_CS("efg22")) == KErrNotFound);
|
sl@0
|
935 |
test(lTestStr9.Find(_CS("efg22"),3) == 4);
|
sl@0
|
936 |
// Find folded
|
sl@0
|
937 |
test(lTestStr9.FindF(_CS("aBcDe")) == 0);
|
sl@0
|
938 |
test(lTestStr9.FindF(_CS("cDe")) == 2);
|
sl@0
|
939 |
test(lTestStr9.FindF(_CS("eFg22")) == KErrNotFound);
|
sl@0
|
940 |
test(lTestStr9.FindF(_CS("efG22"),3) == 4);
|
sl@0
|
941 |
}
|
sl@0
|
942 |
|
sl@0
|
943 |
void RunTestsL()
|
sl@0
|
944 |
{
|
sl@0
|
945 |
|
sl@0
|
946 |
LString8* r8=0;
|
sl@0
|
947 |
LString16* r16=0;
|
sl@0
|
948 |
|
sl@0
|
949 |
// LString8 Tests
|
sl@0
|
950 |
TestConstructors<LString8,TBuf8<11>,TText8, HBufC8, char>(r8);
|
sl@0
|
951 |
TestSwapL<LString8,TBuf8<11>,TText8>(r8);
|
sl@0
|
952 |
TestAssign<LString8,TBuf8<11>,TText8,HBufC8,RBuf8>(r8);
|
sl@0
|
953 |
TestAppendL<LString8,TBuf8<11>,TText8, char>(r8);
|
sl@0
|
954 |
TestReAllocL<LString8,TBuf8<11>,TText8,HBufC8>(r8);
|
sl@0
|
955 |
TestReAllocLeaving<LString8,TBuf8<11>,TText8>(r8);
|
sl@0
|
956 |
TestAssignmentOperatorL<LString8,TBuf8<32>,TBufC8<32>,TText8, char>();
|
sl@0
|
957 |
TestCapacityChangesL<LString8,TBuf8<11>,TText8>(r8);
|
sl@0
|
958 |
TestReadFromStreamL<LString8,TText8>();
|
sl@0
|
959 |
TestCharacterStringSupport_Modifiers<LString8,TText8, char>(r8);
|
sl@0
|
960 |
TestCharacterStringSupport_NonModifiers<LString8,TText8, char>(r8);
|
sl@0
|
961 |
|
sl@0
|
962 |
// LString16 Tests
|
sl@0
|
963 |
TestConstructors<LString16,TBuf16<11>,TText16,HBufC16, wchar_t>(r16);
|
sl@0
|
964 |
TestSwapL<LString16,TBuf16<11>,TText16>(r16);
|
sl@0
|
965 |
TestAssign<LString16,TBuf16<11>,TText16,HBufC16,RBuf16>(r16);
|
sl@0
|
966 |
TestAppendL<LString16,TBuf16<11>, TText16,wchar_t>(r16);
|
sl@0
|
967 |
TestReAllocL<LString16,TBuf16<11>,TText16,HBufC16>(r16);
|
sl@0
|
968 |
TestReAllocLeaving<LString16,TBuf16<11>,TText16>(r16);
|
sl@0
|
969 |
TestAssignmentOperatorL<LString16,TBuf16<32>,TBufC16<32>,TText16,wchar_t>();
|
sl@0
|
970 |
TestCapacityChangesL<LString16,TBuf16<11>,TText16>(r16);
|
sl@0
|
971 |
TestReadFromStreamL<LString16,TText16>();
|
sl@0
|
972 |
TestCharacterStringSupport_Modifiers<LString16,TText16, wchar_t>(r16);
|
sl@0
|
973 |
TestCharacterStringSupport_NonModifiers<LString16,TText16, wchar_t>(r16);
|
sl@0
|
974 |
TestCrossCopyingL();
|
sl@0
|
975 |
}
|
sl@0
|
976 |
|
sl@0
|
977 |
|
sl@0
|
978 |
|
sl@0
|
979 |
|
sl@0
|
980 |
/**
|
sl@0
|
981 |
Test arithmetric operator overloads
|
sl@0
|
982 |
*/
|
sl@0
|
983 |
|
sl@0
|
984 |
|
sl@0
|
985 |
GLDEF_C TInt E32Main()
|
sl@0
|
986 |
{
|
sl@0
|
987 |
|
sl@0
|
988 |
CTrapCleanup* trapHandler=CTrapCleanup::New();
|
sl@0
|
989 |
test(trapHandler!=NULL);
|
sl@0
|
990 |
|
sl@0
|
991 |
test.Title();
|
sl@0
|
992 |
test.Start(_L("Testing LString8 & LString16 classes"));
|
sl@0
|
993 |
|
sl@0
|
994 |
__UHEAP_MARK;
|
sl@0
|
995 |
|
sl@0
|
996 |
TRAPD(err, RunTestsL());
|
sl@0
|
997 |
|
sl@0
|
998 |
__UHEAP_MARKEND;
|
sl@0
|
999 |
|
sl@0
|
1000 |
test.End();
|
sl@0
|
1001 |
|
sl@0
|
1002 |
delete trapHandler;
|
sl@0
|
1003 |
return(err);
|
sl@0
|
1004 |
}
|
sl@0
|
1005 |
|