Update contrib.
1 // Copyright (c) 2008-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 "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
15 // Test methods of the LString16, LString8, LString template class.
16 // The test cases below are template based allowing the same code to
17 // be used for testing both LString16 and LString8 classes.
18 // Appropriate LString and buffer types are passed as the template
19 // parameters in the call to each test case.
21 // LString16, LString8, LString.
23 // For LString8, LString16 and LString objects:
24 // - Test the Create and CreateMax methods by verifying the return value of
25 // KErrNone, the initial length and max length. Perform basic write and read
26 // operations and verify the results.
27 // - Test the CreateL and CreateMaxL methods by verifying the return value of
28 // KErrNone. Also force a heap error and verify return value of KErrNoMemory.
29 // - Test the Create(const TDesC_& aDesc) and Create(const TDesCX_ aDesc,
30 // TInt aMaxLength) methods by verifying the return value of KErrNone. Verify
31 // initial length, max length and initialisation.
32 // - Test the CreateL(const TDesC_& aDesc) and CreateMaxL(const TDesCX_ aDesc,
33 // TInt aMaxLength) methods by verifying the return value of KErrNone. Also
34 // force a heap error and verify return value of KErrNoMemory.
35 // - Test the Swap method by creating two initialised objects, calling Swap
36 // and confirming the results as expected.
37 // - Test the Assign method by performing an assign from a variety of sources
38 // and verifying the results are as expected.
39 // - Test the ReAlloc method in a variety of scenarios that decrease memory,
40 // increase memory and zero-length memory. Verify that the results are as
42 // - Test the ReAllocL by verifying the return value of KErrNone. Also force
43 // a heap error and verify return value of KErrNoMemory. Verify that the
44 // object is the same as before the failed ReAllocL call.
45 // - Test the CleanupClosePushL method via CleanupStack::PopAndDestroy().
46 // - Force the CleanupClosePushL to leave to check cleanup of LString.
47 // Platforms/Drives/Compatibility:
49 // Assumptions/Requirement/Pre-requisites:
50 // Failures and causes:
51 // Base Port information:
63 LOCAL_D RTest test(_L("T_LSTRING"));
65 /* This macro generates a TTEXT* from the string passed in.
66 * The TTEXT type is a template parameter defined for the calling function
67 * and an appropriate 8 or 16 bit string variant is created by this macro
70 #define _TS(a) ((const TTEXT*)RTest::String(sizeof(TTEXT),(TText8*)a,(TText16*)L ## a))
72 /* This macro generates a CHAR* from the string passed in.
73 * The CHAR type is a template parameter defined for the calling function
74 * and an appropriate 8(char)or 16(wchar_t) bit string variant is created by this macro
77 #define _CS(a) ((const CHAR*)RTest::String(sizeof(TTEXT),(TText8*)a,(TText16*)L ## a))
80 @SYMTestCaseID SYSLIB-EUSERHL-UT-4001
81 @SYMTestCaseDesc Tests constructors of LString classes
83 @SYMTestActions Creates LString objects using the different
85 @SYMTestExpectedResults All constructors create object object as expected
88 template<class LSTRING, class TBUF, class TTEXT, class HBUF, class CHAR >
89 LOCAL_C void TestConstructors(LSTRING*)
92 test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4001"));
94 test.Next(_L("LString_(const TDesC& aDes) constructor"));
95 const TBUF des (_TS("123456"));
96 const LSTRING lStr(des);
97 test(lStr.Length() == 6);
98 test(lStr.MaxLength() >= 6);
100 test.Next(_L("LString_(const LString16& aDes) constructor"));
102 test(lStr1.Length() == 6);
103 test(lStr1.MaxLength() >= 6);
105 test.Next(_L("LString_(const TUInt16* aString) constructor"));
106 LSTRING lStr2(lStr1.PtrZL());
107 test(lStr2.Length() == 6);
108 test(lStr2.MaxLength() >= 6);
110 test.Next(_L("LString_(HBufC_* aHBuf) constructor"));
112 HBUF* hBuf = HBUF::NewMax(12); //Create LString as EBufCPtr
114 test(lStr3.Length() == 12);
115 test(lStr3.MaxLength() >= 12);
117 hBuf = HBUF::NewMax(0);
118 LSTRING lStr4(hBuf); //The length of aHBuf is zero
119 test(lStr4.Length() == 0);
121 hBuf = NULL; //aHBuf is NULL
122 LSTRING lStr5((HBUF*)hBuf);
123 test(lStr5.Length() == 0);
124 test(lStr5.MaxLength() == 0);
126 test.Next(_L("LString_(TUInt16* aHeapCell, TInt aLength, TInt aMaxLength) constructor"));
129 heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16
130 LSTRING lStr6(heap, 12,24);
131 test(lStr6.Length() == 12);
132 test(lStr6.MaxLength() >= 24);
134 test.Next(_L("LString_(TUint* aHeapCell, TInt aMaxLength ) method"));
136 heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16
137 LSTRING lStr7(heap, 24);
138 test(lStr7.Length() == 0);
139 test(lStr7.MaxLength() >= 24);
141 test.Next(_L("LString_(char/wchar_t * aCharStr) constructor"));
143 LSTRING lStr8(_CS("0123456789"));
144 test(lStr8.Length() == 10);
145 test(lStr8.MaxLength() >= 10);
147 LSTRING lStr9(_CS("01234567890"));
148 test(lStr9.Length() == 11);
149 test(lStr9.MaxLength() >= 11);
155 Tests the following methods:
156 - TInt Assign(const LString_& lStr);
157 - TInt Assign(TUint* aHeapCell, TInt aMaxLength);
158 - TInt Assign(TUint* aHeapCell, TInt aLength, TInt aMaxLength);
159 - TInt Assign(HBufC& aHBuf);
160 - LString(HBufC_&) constructor.
163 @SYMTestCaseID SYSLIB-EUSERHL-UT-4002
164 @SYMTestCaseDesc Tests Assign methods of LString
165 @SYMTestPriority High
166 @SYMTestActions Creates LString objects and assigns data to the LString using
167 the LString::Assign overloads.
168 Checks that the data is assigned as expected.
169 Creates LString objects from HBufC* and verifies that object
170 is created as expected
171 @SYMTestExpectedResults LString objects are created and assigned as expected
174 template<class LSTRING, class TBUF, class TTEXT, class HBUF, class RBUF>
175 LOCAL_C void TestAssign(LSTRING*)
178 test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4002"));
180 TBUF des (_TS("123456"));
185 test.Next(_L("Assign(const LString_& aLString) method"));
189 // the assignment clears lStr2 so the two strings should be unequal
192 test.Next(_L("Assign(TUint* aHeapCell, TInt aLength, TInt aMaxLength ) method"));
194 heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16
195 lStr.Assign(heap, 12,24);
196 test(lStr.Length() == 12);
197 test(lStr.MaxLength() >= 24);
200 lStr.Assign(heap, 0,0);
201 test(lStr.Length() == 0);
202 test(lStr.MaxLength() == 0);
204 test.Next(_L("Assign(TUint* aHeapCell, TInt aMaxLength ) method"));
206 heap = (TTEXT*)User::Alloc(24*(TInt)sizeof(TTEXT)); //Allocate 48 bytes for 24 long LString16
207 lStr.Assign(heap, 24);
208 test(lStr.Length() == 0);
209 test(lStr.MaxLength() >= 24);
211 test.Next(_L("Assign(HBufC_* aHBuf) method"));
213 HBUF* hBuf = HBUF::NewMax(11);
214 lStr.Assign(hBuf); //Create LString as EBufCPtr type
215 test(lStr.Length() == 11);
216 test(lStr.MaxLength() >= 11); //There could me more allocated memory - see HBufC8::Des()
218 HBUF* hBuf2 = HBUF::NewMax(5);
219 lStr = hBuf2; //Create LString as EBufCPtr type
220 test(lStr.Length() == 5);
221 test(lStr.MaxLength() >= 5); //There could me more allocated memory - see HBufC8::Des()
223 test.Next(_L("Assign(const RBuf_& aRBuf) method"));
228 // the assignment trasnfers buf so the two strings should be equal
235 @SYMTestCaseID SYSLIB-EUSERHL-UT-4003
236 @SYMTestCaseDesc Tests AppendL methods of LString
237 @SYMTestPriority High
238 @SYMTestActions Creates LString objects and uses AppendL methods to append
240 Checks that the data is appended as expected.
241 @SYMTestExpectedResults LString objects are created and data appended as
242 expected with the strings grouwing as necessary to accomodate
246 template<class LSTRING, class TBUF, class TTEXT, class CHAR>
247 LOCAL_C void TestAppendL(LSTRING*)
249 test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4003"));
253 TBUF des(_TS("123456"));
254 TBUF des2(_TS("123456A"));
257 test.Next(_L("AppendL(const TDesc_& aDes) method"));
262 test.Next(_L("AppendL(const TUint16* aBuf, TInt aLength) method"));
266 lStr.AppendL(lStr2.PtrZL(),lStr2.Length());
269 test.Next(_L("AppendL(TChar aChar) method"));
276 test.Next(_L("ZeroTerminateL() method"));
279 lStr.ZeroTerminateL();
282 test.Next(_L("AppendL(char/wchar_t* aCharStr) method"));
284 LSTRING lStr3(_CS("0123456789"));
285 test(lStr3.Length() == 10);
286 test(lStr3.MaxLength() >= 10);
288 LSTRING lStr4(_CS("01234567890"));
289 test(lStr4.Length() == 11);
290 test(lStr4.MaxLength() >= 11);
292 lStr3.AppendL(_CS("0"),1);
293 test(lStr3 == lStr4);
295 lStr4.AppendL(_CS("0123456789"),10);
296 test(lStr4.Length() == 21);
297 test(lStr4.MaxLength() >= 21);
299 test.Next(_L("operator + (char/wchar_t* aCharStr) method"));
301 LSTRING lStr5(_CS("0123456789"));
302 test(lStr5.Length() == 10);
303 test(lStr5.MaxLength() >= 10);
305 LSTRING lStr6(_CS("01234567890"));
306 test(lStr6.Length() == 11);
307 test(lStr6.MaxLength() >= 11);
310 test(lStr5 == lStr6);
312 lStr6 +=_CS("0123456789");
313 test(lStr6.Length() == 21);
314 test(lStr6.MaxLength() >= 21);
319 Tests the following methods.
320 - TInt ReAlloc(TInt aMaxLength);
323 @SYMTestCaseID SYSLIB-EUSERHL-UT-4004
324 @SYMTestCaseDesc Tests ReAlloc methods of LString
325 @SYMTestPriority High
326 @SYMTestActions Creates LString objects and uses ReAlloc to decrease,
327 increase and zero memory. Validates that length and
328 maxlength are changed as expected
329 @SYMTestExpectedResults ReAlloc should change the length and maxLength
330 of the LString data as expected
333 template<class LSTRING, class TBUF, class TTEXT, class HBUF>
334 LOCAL_C void TestReAllocL(LSTRING*)
336 test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4004"));
338 test.Next(_L("ReAlloc(TInt aMaxLength) method"));
340 TBUF des (_TS("0123456"));
342 //reallocate EPtr type - decrease memory
345 test(lStr.ReAlloc(3)==KErrNone); //ReAlloc to EPtr
346 test(lStr.MaxLength()>=3);
347 test(lStr.Length()==3);
348 test(lStr[0] == (TTEXT)('0'));
349 test(lStr[2] == (TTEXT)('2'));
351 //reallocate EBufCPtr type - decrease memory
352 HBUF* hBuf = HBUF::NewMax(9);
353 *hBuf = _TS("012345678");
354 lStr.Assign(hBuf); //Create as EBufCPtr
356 test(lStr.ReAlloc(5)==KErrNone); //ReAlloc to EBufCPtr
357 test(lStr.MaxLength()>=5);//There could be more allocated memory - see HBufC8::Des()
358 test(lStr.Length()==5);
359 test(lStr[0] == (TTEXT)('0'));
360 test(lStr[4] == (TTEXT)('4'));
362 //reallocate EBufCPtr type - increase memory
363 hBuf = HBUF::NewMax(9);
364 *hBuf = _TS("012345678");
365 lStr.Assign(hBuf); //Create as EBufCPtr
366 test(lStr.ReAlloc(15)==KErrNone); //ReAlloc to EBufCPtr
367 test(lStr.MaxLength()>=15);//There could be more allocated memory - see HBufC8::Des()
368 test(lStr.Length()==9);
369 test(lStr[0] == (TTEXT)('0'));
370 test(lStr[8] == (TTEXT)('8'));
372 //reallocate EPtr type - to zero-length
375 test(lStr.ReAlloc(0)==KErrNone); //ReAlloc to EPtr
376 test(lStr.MaxLength()==0);
377 test(lStr.Length()==0);
379 //reallocate EBufCPtr type to zero-length
380 hBuf = HBUF::NewMax(9);
381 *hBuf = _TS("012345678");
382 lStr.Assign(hBuf); //Create as EBufCPtr
384 test(lStr.ReAlloc(0)==KErrNone); //ReAlloc to EPtr
385 test(lStr.MaxLength()==0);
386 test(lStr.Length()==0);
388 //reallocate from zero-length
390 test(lStr.ReAlloc(9)==KErrNone); //ReAlloc to EPtr
391 test(lStr.MaxLength() >=9);
392 test(lStr.Length()==0);
394 //reallocate from zero-length to zero-length
396 test(lStr.ReAlloc(0)==KErrNone); //ReAlloc to EPtr
397 test(lStr.Length() == 0);
398 test(lStr.MaxLength() == 0);
402 Tests the following methods.
403 - TInt ReAllocL(TInt aMaxLength);
406 @SYMTestCaseID SYSLIB-EUSERHL-UT-4005
407 @SYMTestCaseDesc Tests Leaving variant ReAllocL of LString
408 @SYMTestPriority High
409 @SYMTestActions Creates LString objects and uses ReAllocL to
410 increase memory under OOM conditions
411 Verifies that ReAllocL leaves with KErrNoMemory
412 @SYMTestExpectedResults Calls to ReAllocL that increase memory should
413 leave with KErrNoMemory under OOM conditions
416 template<class LSTRING, class TBUF, class TTEXT>
417 LOCAL_C void TestReAllocLeaving(LSTRING*)
420 test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4005"));
422 test.Next(_L("ReAllocL(TInt aMaxLength) method"));
426 TRAPD(ret, lStr.ReAllocL(6)); //ReAlloc buffer
427 test(KErrNone == ret);
431 TRAP(ret, lStr.ReAllocL(100)); //Realloc buffer. This should fail.
432 test(KErrNoMemory == ret);
435 test(lStr.MaxLength() >=6); //Check LString is the same as before ...
436 test(lStr.Length()==2); //... ReAlloc that failed.
437 test(lStr[0] == (TTEXT)('0'));
438 test(lStr[1] == (TTEXT)('1'));
443 Tests the following methods.
444 - void SwapL(LString& aBuf);
445 - void SwapL(TDes& aBuf);
448 @SYMTestCaseID SYSLIB-EUSERHL-UT-4006
449 @SYMTestCaseDesc Tests SwapL methods of LString
450 @SYMTestPriority High
451 @SYMTestActions Creates LString objects and uses SwapL to
452 swap string contents.
453 Verifies that contents are swapped and memory
454 reallocated where necessary
455 @SYMTestExpectedResults Calls to SwapL should swap string contents
456 and buffer should be automatically reallocated to fit the new data.
459 template<class LSTRING, class TBUF, class TTEXT>
460 LOCAL_C void TestSwapL(LSTRING*)
462 test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4006"));
464 LSTRING lStr1, lStr2;
465 TBUF des1(_TS("12"));
466 TBUF des2 (_TS("345678"));
467 TBUF des3 (_TS("12345678"));
468 TBUF swap_des = des2;
470 test.Next(_L("Swap(LString_& aLString) method"));
472 // assignment operation; implies deep copying
476 // swap LStrings with TDes
477 // lStr1 should grow to accommodate swap_des
478 lStr1.SwapL(swap_des);
480 test(swap_des==des1);
483 // lStr2 should grow to accommodate lStr1
494 Test assignemnt operator.
497 @SYMTestCaseID SYSLIB-EUSERHL-UT-4007
498 @SYMTestCaseDesc Tests Assignment operator for LString
499 @SYMTestPriority High
500 @SYMTestActions Creates LString objects and uses assignment to
501 change string contents.
502 Verifies that contents are swapped and memory
503 reallocated where necessary
504 @SYMTestExpectedResults Assignment operator should change string contents
505 and buffer should be automatically reallocated to fit the new data.
508 template<class LSTRING, class TBUF, class TBUFC, class TTEXT, class CHAR>
509 LOCAL_C void TestAssignmentOperatorL()
511 test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4007"));
513 test.Next(_L("Assignment operator"));
515 TBUF tdes(_TS("Modifiable descriptor"));
516 TBUFC tdesc(_TS("Non-modifiable descriptor"));
520 lStr2.CopyL(_TS("Buffer descriptor"), 17);
522 lStr = tdesc; test(lStr == tdesc);
523 lStr = tdes; test(lStr == tdes);
524 lStr = lStr2; test(lStr == lStr2);
527 lStr = lStr3.PtrZL(); test(lStr == tdes);
529 test.Next(_L("operator=(char/wchar_t* aCharStr) method"));
530 LSTRING lStr4(_CS("123456"));
531 LSTRING lStr5 = _CS("123456");
532 test(lStr4 == lStr5);
535 lStr6 = _CS("123456");
536 test(lStr4 == lStr6);
540 Test Capacity growth and compression
543 @SYMTestCaseID SYSLIB-EUSERHL-UT-4008
544 @SYMTestCaseDesc Tests capacity growth and compression for LString
545 @SYMTestPriority High
546 @SYMTestActions Creates an LString object then calls SetMaxLength and Compress
547 to increase or decrease underlying buffer size.
548 Tests that Length and Maxlength are modified as expected
549 @SYMTestExpectedResults SetMaxLength and Compress should resize the underlying
553 template<class LSTRING, class TBUF, class TTEXT>
554 LOCAL_C void TestCapacityChangesL(LSTRING*)
556 test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4008"));
558 test.Next(_L("Test capacity growth and compression on LString"));
560 LSTRING lStr(_TS("0123456"));
561 test(lStr.Length()==7);
562 test(lStr.MaxLength() >=7);
564 lStr.SetMaxLengthL(10);
565 test(lStr.Length()==7);
566 test(lStr.MaxLength() >=10);
568 lStr.SetMaxLengthL(6);
569 test(lStr.Length()==6);
570 test(lStr.MaxLength() >=6);
572 lStr.SetMaxLengthL(10);
573 test(lStr.Length()==6);
574 test(lStr.MaxLength() >=10);
576 //Call the same thing again to check the condition
577 //that required length is already set
578 lStr.SetMaxLengthL(10);
579 test(lStr.Length()==6);
580 test(lStr.MaxLength() >=10);
583 test(lStr.Length()==6);
584 test(lStr.MaxLength() >= 6);
586 //Call the same thing again to check the condition
587 //that the string is already compressed
589 test(lStr.Length()==6);
590 test(lStr.MaxLength() >= 6);
592 lStr.ReserveFreeCapacityL(15);
593 test(lStr.Length()==6);
594 test(lStr.MaxLength() >= 32);
597 test(lStr.Length()==0);
598 test(lStr.MaxLength() == 0);
604 Test copying from 16bit to 8bit and vice versa
607 @SYMTestCaseID SYSLIB-EUSERHL-UT-4009
608 @SYMTestCaseDesc Tests Copying between 8 and 16 bit LString variants
609 @SYMTestPriority High
610 @SYMTestActions Creates an LString8 and LString16 object and uses the cross-variant
611 Copy functions to copy data between the variants.
612 @SYMTestExpectedResults Data is successfully copied between the variants.
615 LOCAL_C void TestCrossCopyingL()
618 test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4009"));
620 test.Next(_L("Test cross copying on LString"));
622 LString8 lStr8("0123");
623 LString16 lStr16(L"01234567");
626 LString16 targetStr16;
628 targetStr8.CopyL(lStr16);
629 targetStr16.CopyL(lStr8);
634 Test creating an LString from a stream
637 @SYMTestCaseID SYSLIB-EUSERHL-UT-4010
638 @SYMTestCaseDesc Tests Creating an LString from a stream
639 @SYMTestPriority High
640 @SYMTestActions Creates a in-memory stream and writes some data to it.
641 Creates an LString from a readstream and verifies that the
642 contents of the LString match the data written to the stream.
643 @SYMTestExpectedResults The LString contents should match the data written
647 template<class LSTRING, class TTEXT>
648 LOCAL_C void TestReadFromStreamL()
650 test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4010"));
652 test.Next(_L("Test creating LString from a stream"));
655 fs.Connect() OR_LEAVE;
657 LSTRING outString = _TS("This is a test string written to a stream");
659 //Create a buffer to contain the stream
660 CBufFlat* buf = CBufFlat::NewL(outString.MaxLength());
662 //Create a write stream
663 RBufWriteStream outStream;
664 outStream.Open(*buf);
666 //write some data to the stream
667 outStream << outString;
671 RBufReadStream inStream;
674 //Create an LString from the stream
676 inString.CreateL(inStream,outString.Length());
677 test(inString == outString);
683 Test support for [wide]character strings.
684 APIs that modify data.
687 @SYMTestCaseID BASESRVCS-EUSERHL-UT-4068
688 @SYMTestCaseDesc Test the APIs provided to support wchar_t and char strings
689 @SYMTestPriority High
690 @SYMTestActions 1)Construct LString object from the supplied null terminated
692 2)Assign new string to the constructed LString object
693 3)Appends data onto the end of this LString object's data.
694 The length of this descriptor is incremented to reflect the new content.
695 4)Copy new data into the LString object, replacing any existing
696 data, and expanding its heap buffer to accommodate if necessary.
697 5)Insert contents into the LString
698 6)Replace data to the end of the LString object and justify it.
699 7)Append data of specified length, to the end of the LString object.
700 8)Justify data, to the end of the LString object.
701 9)Appends data onto the end of this descriptor's data and justifies it.
702 @SYMTestExpectedResults The LString contents should match the data expected after the operation.
706 template<class LSTRING, class TTEXT, class CHAR>
707 LOCAL_C void TestCharacterStringSupport_Modifiers(LSTRING*)
709 test.Next (_L ("@SYMTestCaseID:BASESRVCS-EUSERHL-UT-4068"));
711 // 1. test Constructor
712 // Constructs LString object from the supplied null terminated
714 test.Next(_L("LString_(char/wchar_t * aCharStr) constructor"));
715 LSTRING lStr(_CS("0123456789"));
716 test(lStr.Length() == 10);
717 test(lStr.MaxLength() >= 10);
718 test(lStr.Compare(_CS("0123456789")) == 0 );
719 // try strings ending with 0
720 LSTRING lStr1(_CS("01234567890"));
721 test(lStr1.Length() == 11);
722 test(lStr1.MaxLength() >= 11);
723 test(lStr1.Compare(_CS("01234567890")) == 0 );
725 // 2. test '=' operator
727 // Assign new string to the constructed LString object
728 test.Next(_L("LString_ operator '=' "));
729 lTestStr = _CS("Try a New String");
730 test(lTestStr.Compare(_CS("Try a New String")) == 0 );
731 test(lTestStr.Length() == 16);
732 test(lTestStr.MaxLength() >= 16);
734 // 3. test '+=' operator
735 // Appends data onto the end of this LString object's data.
736 // The length of this descriptor is incremented to reflect the new content.
737 test.Next(_L("LString_ operator '+=' "));
738 lTestStr += _CS("!!!");
739 test(lTestStr.Compare(_CS("Try a New String!!!")) == 0 );
740 test(lTestStr.Length() == 19);
741 test(lTestStr.MaxLength() >= 19);
743 // 4.Test "Copy()" Variants
746 // Copy new data into the LString object, replacing any existing
747 // data, and expanding its heap buffer to accommodate if necessary.
748 test.Next(_L("LString_ CopyL "));
749 lTestStr1.CopyL(_TS("Try a New String"));
750 test(lTestStr1.Compare(_TS("Try a New String")) == 0 );
751 test(lTestStr1.Length() == 16);
752 test(lTestStr1.MaxLength() >= 16);
754 // Copy folded(normalized) content
755 test.Next(_L("LString_ CopyFL "));
756 lTestStr1.CopyFL(_CS("Some RaNDom STRING"));
757 lTestStr2.CopyFL(_CS("SOME RaNDom string"));
758 test(lTestStr1.Compare(lTestStr2) == 0);
760 // Copy contents in Lower case
761 test.Next(_L("LString_ CopyLCL "));
762 lTestStr1.CopyLCL(_CS("SOME STRING IN UPPER CASE"));
763 test(lTestStr1 == _CS("some string in upper case"));
765 // Copy contents in Upper case
766 test.Next(_L("LString_ CopyUCL "));
767 lTestStr1.CopyUCL(_CS("some string in lower case"));
768 test(lTestStr1 == _CS("SOME STRING IN LOWER CASE"));
770 // Copy Capitalized contents
771 test.Next(_L("LString_ CopyCPL "));
772 lTestStr1.CopyCPL(_CS("some string in lower case"));
773 test(lTestStr1 == _CS("Some string in lower case"));
777 // Insert contents into a string
778 test.Next(_L("LString_ InsertL "));
779 lTestStr3 = _CS("Some Content Can Be Into This String");
780 lTestStr3.InsertL(20,_CS("Inserted "));
781 test(lTestStr3 == _CS("Some Content Can Be Inserted Into This String"));
785 // Replace contents form the string
786 test.Next(_L("LString_ ReplaceL "));
787 lTestStr4 = _CS("Some Content Can Be Decalper");
788 lTestStr4.ReplaceL(20,8,_CS("Replaced"));
789 test(lTestStr4 == _CS("Some Content Can Be Replaced"));
793 //Append data of specified length, to the end of the LString object.
794 test.Next(_L("LString_ AppendL(src,length)"));
795 lTestStr5.CopyL( _CS("Try appending "));
796 lTestStr5.AppendL(_CS("Try appending some more"),3);
797 test(lTestStr5 == _CS("Try appending Try"));
799 //Append data , to the end of the LString object.
800 test.Next(_L("LString_ AppendL(src)"));
801 lTestStr5.CopyL( _CS("Try appending "));
802 lTestStr5.AppendL(_CS("Try appending some more"));
803 test(lTestStr5 == _CS("Try appending Try appending some more"));
807 //Copy data into this descriptor and justifies it, replacing any existing data
808 test.Next(_L("LString_ JustifyL "));
809 lTestStr6.CopyL(_CS("Justified"));
810 lTestStr6.JustifyL(_CS("Just"),9,ERight,*(_TS("x")));
811 test(lTestStr6 == _CS("xxxxxJust"));
813 // 9. Test AppendJustify variants
815 // Append data to the end of the LString object and justify it.
816 test.Next(_L("LString_ AppendJustifyL(const char*,TInt aLength,TInt aWidth,TAlign anAlignment,TChar aFill)"));
817 lTestStr7.CopyL(_CS("One "));
818 lTestStr7.AppendJustifyL(_CS("Two "),KDefaultJustifyWidth,ERight,*(_TS("x")));
819 test(lTestStr7 == _TS("One Two "));
821 lTestStr7.CopyL(_CS("One "));
822 lTestStr7.AppendJustifyL(_CS("Two Three"),3,7,ERight,*(_TS("x")));
823 test(lTestStr7 == _CS("One xxxxTwo") );
825 // Append data to the end of the LString object and justify it.
826 test.Next(_L("LString_ AppendJustifyL(const char* aCharStr,TInt aWidth,TAlign anAlignment,TChar aFill)"));
827 lTestStr7.CopyL(_CS("One "));
828 lTestStr7.AppendJustifyL(_CS("Two Three"),KDefaultJustifyWidth,ERight,*(_TS("x")));
829 test(lTestStr7 == _TS("One Two Three"));
831 lTestStr7.CopyL(_CS("One "));
832 lTestStr7.AppendJustifyL(_CS("Two Three"),13,ERight,*(_TS("x")));
833 test(lTestStr7 == _CS("One xxxxTwo Three") );
837 Test support for [wide]character strings.
838 APIs that do not modify any data.
841 @SYMTestCaseID BASESRVCS-EUSERHL-UT-4069
842 @SYMTestCaseDesc Test the APIs provided to support wchar_t and char strings
843 @SYMTestPriority High
844 @SYMTestActions 1)Determine whether this descriptor's data is equal to the specified string's data.
845 2)Determine whether this descriptor's data is less than the specified string's data.
846 3)Determine whether this descriptor's data is less than or equal to the specified string's data.
847 4)Determine whether this descriptor's data is greater than the specified string's data.
848 5)Determine whether this descriptor's data is greater than or equal to the specified string's data.
849 6)Determine whether this descriptor's data is not equal to the specified string's data.
850 7)Compare this descriptor's data with the specified string's data.
851 8)Search this descriptor's data for a match with the match pattern supplied in the specified string's
852 9)Searches for the first occurrence of the specified data sequence within this descriptor
853 @SYMTestExpectedResults The operation/comparision must result in the desired output
856 template<class LSTRING,class TTEXT, class CHAR>
857 LOCAL_C void TestCharacterStringSupport_NonModifiers(LSTRING*)
859 test.Next (_L ("@SYMTestCaseID:BASESRVCS-EUSERHL-UT-4069"));
861 // 1.test '==' operator
863 lTestStr1.CopyL(_CS("Are they equal?? "));
864 test(lTestStr1 == _CS("Are they equal?? "));
865 lTestStr1.CopyL(_CS("12345670"));
866 test(lTestStr1 == _CS("12345670"));
868 // 2.test "<" operator
870 lTestStr2.CopyL(_CS("ABCDEFGH"));
871 test(lTestStr2 < _CS("abcdefgh"));
872 lTestStr2.CopyL(_CS(" Is this is smaller"));
873 test(lTestStr2 < _CS("No, larger of the string is greater than the smaller one"));
875 // 3.test "<=" operator
877 lTestStr3.CopyL(_CS("ABCDEFGH"));
878 test(lTestStr3 <= _CS("abcdefgh"));
879 lTestStr3.CopyL(_CS("equals"));
880 test(lTestStr3 <= _CS("equals"));
882 // 4.test ">" operator
884 lTestStr4.CopyL(_CS("abcdefgh"));
885 test(lTestStr4 > _CS("ABCDEFGH"));
886 lTestStr4.CopyL(_CS("No, larger of the string is greater than the smaller one"));
887 test(lTestStr4 > _CS("Is this smaller??"));
889 // 5.test ">=" operator
891 lTestStr5.CopyL(_CS("abcdefgh"));
892 test(lTestStr5 >= _CS("ABCDEFGH"));
893 lTestStr5.CopyL(_CS("equals"));
894 test(lTestStr5 >= _CS("equals"));
898 lTestStr6.CopyL(_CS("abcdefgh"));
899 test(lTestStr6 != _CS("ABCDEFGH"));
900 lTestStr6.CopyL(_CS("equals"));
901 test(!(lTestStr6 != _CS("equals")));
903 // 7.test Compare variants
906 lTestStr7.CopyL(_CS("abcdefgh"));
907 test(lTestStr7.Compare(_CS("ABCDEFGH")) > 0);
908 lTestStr7.CopyL(_CS("ABCDEFGH"));
909 test(lTestStr7.Compare(_CS("abcdefgh")) < 0);
910 lTestStr5.CopyL(_CS("equals"));
911 test(lTestStr5.Compare( _CS("equals")) == 0);
913 lTestStr7.CopyL(_CS("abcdefgh"));
914 test(lTestStr7.CompareF(_CS("ABcDeFgH")) == 0);
916 // 8.test Match variants
919 lTestStr8.CopyL(_CS("abcdefghijklmnopqrstuvwxyz"));
920 test(lTestStr8.Match(_CS("*ijk*"))== 8);
921 test(lTestStr8.Match(_CS("*i?k*"))== 8);
922 test(lTestStr8.Match(_CS("ijk*"))== KErrNotFound);
924 test(lTestStr8.MatchF(_CS("*IjK*"))== 8);
925 test(lTestStr8.MatchF(_CS("*I?k*"))== 8);
926 test(lTestStr8.MatchF(_CS("ijK*"))== KErrNotFound);
928 // 9.test Find variants
931 lTestStr9.CopyL(_CS("abcdefghijklmnopqrstuvwxyz"));
932 test(lTestStr9.Find(_CS("abcde")) == 0);
933 test(lTestStr9.Find(_CS("cde")) == 2);
934 test(lTestStr9.Find(_CS("efg22")) == KErrNotFound);
935 test(lTestStr9.Find(_CS("efg22"),3) == 4);
937 test(lTestStr9.FindF(_CS("aBcDe")) == 0);
938 test(lTestStr9.FindF(_CS("cDe")) == 2);
939 test(lTestStr9.FindF(_CS("eFg22")) == KErrNotFound);
940 test(lTestStr9.FindF(_CS("efG22"),3) == 4);
950 TestConstructors<LString8,TBuf8<11>,TText8, HBufC8, char>(r8);
951 TestSwapL<LString8,TBuf8<11>,TText8>(r8);
952 TestAssign<LString8,TBuf8<11>,TText8,HBufC8,RBuf8>(r8);
953 TestAppendL<LString8,TBuf8<11>,TText8, char>(r8);
954 TestReAllocL<LString8,TBuf8<11>,TText8,HBufC8>(r8);
955 TestReAllocLeaving<LString8,TBuf8<11>,TText8>(r8);
956 TestAssignmentOperatorL<LString8,TBuf8<32>,TBufC8<32>,TText8, char>();
957 TestCapacityChangesL<LString8,TBuf8<11>,TText8>(r8);
958 TestReadFromStreamL<LString8,TText8>();
959 TestCharacterStringSupport_Modifiers<LString8,TText8, char>(r8);
960 TestCharacterStringSupport_NonModifiers<LString8,TText8, char>(r8);
963 TestConstructors<LString16,TBuf16<11>,TText16,HBufC16, wchar_t>(r16);
964 TestSwapL<LString16,TBuf16<11>,TText16>(r16);
965 TestAssign<LString16,TBuf16<11>,TText16,HBufC16,RBuf16>(r16);
966 TestAppendL<LString16,TBuf16<11>, TText16,wchar_t>(r16);
967 TestReAllocL<LString16,TBuf16<11>,TText16,HBufC16>(r16);
968 TestReAllocLeaving<LString16,TBuf16<11>,TText16>(r16);
969 TestAssignmentOperatorL<LString16,TBuf16<32>,TBufC16<32>,TText16,wchar_t>();
970 TestCapacityChangesL<LString16,TBuf16<11>,TText16>(r16);
971 TestReadFromStreamL<LString16,TText16>();
972 TestCharacterStringSupport_Modifiers<LString16,TText16, wchar_t>(r16);
973 TestCharacterStringSupport_NonModifiers<LString16,TText16, wchar_t>(r16);
981 Test arithmetric operator overloads
985 GLDEF_C TInt E32Main()
988 CTrapCleanup* trapHandler=CTrapCleanup::New();
989 test(trapHandler!=NULL);
992 test.Start(_L("Testing LString8 & LString16 classes"));
996 TRAPD(err, RunTestsL());