Update contrib.
1 // Copyright (c) 1995-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\buffer\t_des.cpp
16 // Test methods of the TDes template class.
20 // - Test assigning TPtrs in various ways and confirm results are as expected.
21 // - Test locating in reverse on an empty TPtr, verify it returns KErrNoFound.
22 // - For TBuf, TBuf8 and TBuf16 objects:
23 // - Construct a default TBuf object and verify Length and MaxLength values are
25 // - Construct a TBuf object with length and verify Length and MaxLength values
27 // - Construct a TBuf object over a string, verify Length and MaxLength values
28 // are as expected. Verify the string data is correct.
29 // - Construct a TBuf object over a descriptor, verify Length and MaxLength values
30 // are as expected. Verify the data is correct.
31 // - Construct a TBuf object over a buffer, verify Length and MaxLength values
32 // are as expected. Verify the data is correct.
33 // - Construct a TBuf object and assign a string to it, verify Length and MaxLength
34 // values are as expected. Verify the data is correct.
35 // - Construct a TBuf object and assign a descriptor to it, verify Length and MaxLength
36 // values are as expected. Verify the data is correct.
37 // - Construct a TBuf object and assign a buffer to it, verify Length and MaxLength
38 // values are as expected. Verify the data is correct.
39 // - Check the available user heap space and check for memory leaks by comparing it to
41 // - For TPtrC, TPtrC8 and TPtrC16 objects:
42 // - Verify the invariant for a null pointer descriptor
43 // - Construct a TPtrC object over a constant string, verify Length and string data
45 // - Construct a TPtrC object over a constant descriptor, verify Length and data are
47 // - Construct a TPtrC object over a constant buffer with length, verify Length and
49 // - Check the available user heap space and check for memory leaks by comparing it to
51 // - For TPtr, TPtr8 and TPtr16 objects:
52 // - Verify the invariant for a null pointer descriptor
53 // - Construct a TPtr object over a buffer with length and maxlength, verify Length,
54 // MaxLength and data are correct.
55 // - Construct a TPtr object over a buffer with maxlength, verify Length, MaxLength
56 // and Ptr are correct.
57 // - Construct a TPtr object and assign a string to it. Verify Length, MaxLength and
58 // the string data are correct.
59 // - Construct a TPtr object and assign a buffer to it. Verify Length, MaxLength and
60 // the data are correct.
61 // - Construct a TPtr object and assign a descriptor to it. Verify Length, MaxLength
62 // and the data are correct.
63 // - Check the available user heap space and check for memory leaks by comparing it to
65 // - Verify the TPtr copy constructor by setting and checking a text string.
66 // - For TBufC, TBufC8 and TBufC16 objects:
67 // - Construct a default TBufC object. Verify default Length is as expected.
68 // - Construct a TBufC object over a string, verify Length and data are correct.
69 // - Construct a TBufC object over a TBufC, verify Length and data are correct.
70 // - Construct a TBufC object and assign a string to it, verify Length and data
72 // - Construct a TBufC object and assign a descriptor to it, verify Length and data
74 // - Construct a TBufC object and assign a TBufC to it, verify Length and data
76 // - Check the available user heap space and check for memory leaks by comparing it to
78 // - For HBufC, HBufC8 and HBufC16 objects:
79 // - Create a new descriptor using the New() method, verify non-NULL return value.
80 // - Construct a HBufC object and assign a string to it, verify Length and data
82 // - Construct a HBufC object and assign a descriptor to it, verify Length and data
84 // - Construct a HBufC object and assign a HBufC to it, verify Length and data
86 // - Construct a HBufC object and call ReAlloc method, verify Length and data are
88 // - Check the available user heap space and check for memory leaks by comparing it to
90 // - Test ASCII destination with Unicode source. Verify string results are as expected.
91 // - For TLitC, TLitC8 and TLitC16 objects:
92 // - Verify member operators.
93 // - Assign and validate literal values
94 // - For TBuf, TBuf8 and TBuf16 objects, test TDes derived objects that return TPtrs.
95 // - Extract and verify the left portion of the descriptor (LeftTPtr).
96 // - Extract and verify the right portion of the descriptor (RightTPtr).
97 // - Extract and verify the middle portion of the descriptor (MidTPtr).
98 // - For TPtr, TPtr8 and TPtr16 objects, test TDes derived objects that return TPtrs.
99 // - Extract and verify the left portion of the descriptor (LeftTPtr).
100 // - Extract and verify the right portion of the descriptor (RightTPtr).
101 // - Extract and verify the middle portion of the descriptor (MidTPtr).
102 // Platforms/Drives/Compatibility:
104 // Assumptions/Requirement/Pre-requisites:
105 // Failures and causes:
106 // Base Port information:
112 LOCAL_D RTest test(_L("T_DES"));
114 template<class T,class S, class L, class R>
118 TestTDes(); // Test class constructor.
153 void test_TPtrC(); // Test TPtrC classes
154 void test_TPtr(); // Test TPtr classes
155 void test_TBuf(); // Test TBuf classes
156 void test_TBufC(); // Test TBufC classes
157 void test_HBufC(); // Test HBufC classes
158 void test_TBufReturningModifiable();
159 void test_TPtrReturningModifiable();
160 void test_TDesReturningModifiable(const T& a, R& b);
161 void testHeapSpace(TInt);
164 template <class T, class S, class L, class R>
165 GLDEF_C TestTDes<T,S,L,R>::TestTDes()
171 template <class T,class S,class L,class R>
172 GLDEF_C void TestTDes<T,S,L,R>::testHeapSpace(TInt startAvail)
174 // Test no memory leakage has occured
178 test.Next(_L("Testing for memory leaks"));
180 endAvail=User::Available(temp);
181 test(endAvail==startAvail);
184 template <class T, class S, class L, class R>
185 GLDEF_C void TestTDes<T,S,L,R>::Test1()
187 // Constructs a view over a constant string
192 a.__DbgTestInvariant();
195 test(*(a.Ptr()+1)=='B');
196 test(*(a.Ptr()+2)=='c');
199 template<class T, class S, class L, class R>
200 GLDEF_C void TestTDes<T,S,L,R>::Test2()
202 // Constructs a view over a descriptor
207 aDes.__DbgTestInvariant();
209 b.__DbgTestInvariant();
210 test(b.Length()==aDes.Length());
211 test(*b.Ptr()==*aDes.Ptr());
212 test(*(b.Ptr()+1)==*(aDes.Ptr()+1));
213 test(*(b.Ptr()+2)==*(aDes.Ptr()+2));
216 template<class T, class S, class L, class R>
217 GLDEF_C void TestTDes<T,S,L,R>::Test3()
219 // Constructs a view over a length specified buffer
223 S* aBuf = _TL("ABCDEF");
225 aDes.__DbgTestInvariant();
226 test(aDes.Length()==6);
227 for(S count=0; count<aDes.Length(); count++)
228 test(*(aDes.Ptr()+count)==('A' + count));
229 test(aDes.Ptr()==aBuf);
232 template<class T, class S, class L, class R>
233 GLDEF_C void TestTDes<T,S,L,R>::Test4()
235 // Constructs a r/w view over a buffer with length & maxlength
241 T aDesW(aBuf,6,0x0A);
242 aDesW.__DbgTestInvariant();
243 test(aDesW.Length()==6);
244 for(S count=0; count<aDesW.Length(); count++)
245 test(*(aDesW.Ptr()+count)==('L' + count));
246 test(aDesW.Ptr()==aBuf);
247 test(aDesW.MaxLength()==0x0A);
250 template<class T, class S, class L, class R>
251 GLDEF_C void TestTDes<T,S,L,R>::Test5()
253 // Constructs a r/w view over a buffer with maxlength
260 aDesW.__DbgTestInvariant();
261 test(aDesW.Length()==0);
262 test(aDesW.MaxLength()==0x06);
263 test(aDesW.Ptr()==aBuf);
266 template<class T, class S, class L, class R>
267 GLDEF_C void TestTDes<T,S,L,R>::Test6()
269 // Constructs a r/w view over a LcbBase with maxlength
272 // Cant use yet, see calling function
275 template<class T, class S, class L, class R>
276 GLDEF_C void TestTDes<T,S,L,R>::Test7()
278 // Constructs a default TBuf view
283 aBuf.__DbgTestInvariant();
284 test(aBuf.Length()==0);
285 test(aBuf.MaxLength()==0x40);
288 template<class T, class S, class L, class R>
289 GLDEF_C void TestTDes<T,S,L,R>::Test8()
291 // Constructs a TBuf view with length
296 aBuf.__DbgTestInvariant();
297 test(aBuf.Length()==10);
298 test(aBuf.MaxLength()==0x40);
301 template<class T, class S, class L, class R>
302 GLDEF_C void TestTDes<T,S,L,R>::Test9()
304 // Constructs a TBuf view over a string
308 T aBuf(_TL("ABCDEF"));
309 aBuf.__DbgTestInvariant();
310 test(aBuf.Length()==6);
311 test(aBuf.MaxLength()==0x40);
312 for(S count=0;count<aBuf.Length();count++)
313 test(*(aBuf.Ptr()+count)==('A' + count));
316 template<class T, class S, class L, class R>
317 GLDEF_C void TestTDes<T,S,L,R>::Test10()
319 // Constructs a TBuf view over a descriptor
323 R aDesR(_TL("ABCDEF"));
324 aDesR.__DbgTestInvariant();
326 aBuf.__DbgTestInvariant();
327 test(aBuf.MaxLength()==0x40);
328 test(aBuf.Length()==aDesR.Length());
329 test(aBuf.Length()==6);
330 for(S count=0;count<aBuf.Length();count++)
332 test(*(aBuf.Ptr()+count)==('A' + count));
333 test(*(aBuf.Ptr()+count)==*(aDesR.Ptr()+count));
337 template<class T, class S, class L, class R>
338 GLDEF_C void TestTDes<T,S,L,R>::Test11()
340 // Constructs a TBuf view over a buffer
344 T aBuf(_TL("ABCDEF"));
345 aBuf.__DbgTestInvariant();
347 bBuf.__DbgTestInvariant();
348 test(bBuf.MaxLength()==aBuf.MaxLength());
349 test(bBuf.MaxLength()==0x40);
350 test(bBuf.Length()==aBuf.Length());
351 test(bBuf.Length()==6);
352 for(S count=0;count<bBuf.Length();count++)
354 test(*(bBuf.Ptr()+count)==('A' + count));
355 test(*(bBuf.Ptr()+count)==*(aBuf.Ptr()+count));
359 template<class T,class S,class L,class R>
360 GLDEF_C void TestTDes<T,S,L,R>::Test12()
362 // Exercise the default TBufC constructor
367 buf.__DbgTestInvariant();
368 test(buf.Length()==0);
371 template<class T,class S,class L,class R>
372 GLDEF_C void TestTDes<T,S,L,R>::Test13()
374 // Constructor over a string
378 S* pString=(_TL("12"));
380 buf.__DbgTestInvariant();
381 test(buf.Length()==2);
382 test(*(buf.Ptr())=='1');
383 test(*(buf.Ptr()+1)=='2');
386 template<class T,class S,class L,class R>
387 GLDEF_C void TestTDes<T,S,L,R>::Test14()
389 // Constructor over a TDesC (TPtrC)
393 R des(_TL("Test 14"));
394 des.__DbgTestInvariant();
396 buf.__DbgTestInvariant();
397 test(buf.Length()==7);
398 test(buf.Length()==des.Length());
399 test(*(buf.Ptr())=='T');
400 test(*(buf.Ptr()+1)=='e');
401 test(*(buf.Ptr()+2)=='s');
402 test(*(buf.Ptr()+3)=='t');
403 test(*(buf.Ptr()+4)==' ');
404 test(*(buf.Ptr()+5)=='1');
405 test(*(buf.Ptr()+6)=='4');
409 template<class T,class S,class L,class R>
410 GLDEF_C void TestTDes<T,S,L,R>::Test15()
412 // Constructor over a TBufC
416 T oldBuf(_TL("Test 15"));
417 oldBuf.__DbgTestInvariant();
419 newBuf.__DbgTestInvariant();
420 test(newBuf.Length()==8);
421 test(newBuf.Length()==oldBuf.Length());
422 test(*(newBuf.Ptr())=='T');
423 test(*(newBuf.Ptr()+1)=='e');
424 test(*(newBuf.Ptr()+2)=='s');
425 test(*(newBuf.Ptr()+3)=='t');
426 test(*(newBuf.Ptr()+4)==' ');
427 test(*(newBuf.Ptr()+5)==' ');
428 test(*(newBuf.Ptr()+6)=='1');
429 test(*(newBuf.Ptr()+7)=='5');
432 template<class T,class S,class L,class R>
433 GLDEF_C void TestTDes<T,S,L,R>::Test16()
435 // New operator - without leave
439 T* pBuf=T::New(0x40);
441 pBuf->__DbgTestInvariant();
445 template<class T,class S,class L,class R>
446 GLDEF_C void TestTDes<T,S,L,R>::Test17()
448 // NewL operator - forcing a leave
454 Reinstate if some method is found of forcing alloc fail
455 This test no longer works due to heap growing functionality of E32 057
459 TInt available=User::Available(temp);
460 TAny* pDummy=User::Alloc(available);
461 TRAPD(ret,pBuf=T::NewL(0x40))
462 test(ret==KErrNoMemory);
467 template<class T,class S,class L,class R>
468 GLDEF_C void TestTDes<T,S,L,R>::Test18()
470 // NewL operator - forcing success
475 TRAPD(ret,pBuf=T::NewL(0x40))
478 pBuf->__DbgTestInvariant();
482 template<class T, class S, class L, class R>
483 GLDEF_C void TestTDes<T,S,L,R>::TestA()
490 Mem::Copy(myBuf,_TL("ABCDEF"),7*sizeof(S));
491 T aDes(myBuf,0x06,0x06);
493 aDes.__DbgTestInvariant();
494 test(aDes.Length()==6);
495 test(aDes.MaxLength()==0x06);
497 for(;count<aDes.Length(); count++)
499 test(*(aDes.Ptr()+count)==('Z'-count));
502 aDes.__DbgTestInvariant();
503 test(aDes.Length()==3);
504 test(aDes.MaxLength()==0x06);
505 for(count=0; count<aDes.Length(); count++)
507 test(*(aDes.Ptr()+count)==('1'+count));
512 template<class T, class S, class L, class R>
513 GLDEF_C void TestTDes<T,S,L,R>::TestB()
519 Mem::Copy(aBuf,_TL("ZYXWVUTSRQ"),11*sizeof(S));
520 Mem::Copy(bBuf,_TL("ABCDEFGHIJ"),11*sizeof(S));
521 T aDes(aBuf,0x0A,0x0A);
524 aDes.__DbgTestInvariant();
525 bDes.__DbgTestInvariant();
526 test(aDes.Length()==bDes.Length());
527 test(aDes.MaxLength()==0x0A);
528 test(bDes.MaxLength()==0x0A);
529 for(S count=0; count<bDes.Length(); count++)
531 test(*(aDes.Ptr()+count)==*(bDes.Ptr()+count));
537 template<class T, class S, class L, class R>
538 GLDEF_C void TestTDes<T,S,L,R>::TestC()
542 R aDesR(_TL("1234567890"));
543 Mem::Copy(aBuf,_TL("ABCDEFGHIJ"),11*sizeof(S));
544 T aDes(aBuf,0x0A,0x0A);
546 aDes.__DbgTestInvariant();
547 test(aDes.Length()==aDesR.Length());
548 test(aDes.MaxLength()==0x0A);
549 for(S count=0; count<aDes.Length(); count++)
551 test(*(aDes.Ptr()+count)==*(aDesR.Ptr()+count));
556 template<class T, class S, class L, class R>
557 GLDEF_C void TestTDes<T,S,L,R>::TestD()
558 // TBuf string Assignment
561 aBuf=(_TL("ABCDEF"));
562 aBuf.__DbgTestInvariant();
563 test(aBuf.Length()==6);
564 test(aBuf.MaxLength()==0x40);
565 for(S count=0; count<aBuf.Length(); count++)
567 test(*(aBuf.Ptr()+count)==('A'+count));
572 template<class T, class S, class L, class R>
573 GLDEF_C void TestTDes<T,S,L,R>::TestE()
574 // TBuf descriptor Assignment
576 R aDesR(_TL("ABCDEF"));
579 aBuf.__DbgTestInvariant();
580 test(aBuf.MaxLength()==0x40);
581 test(aBuf.Length()==aDesR.Length());
582 test(aBuf.Length()==6);
583 for(S count=0;count<aBuf.Length();count++)
585 test(*(aBuf.Ptr()+count)==('A' + count));
586 test(*(aBuf.Ptr()+count)==*(aDesR.Ptr()+count));
591 template<class T, class S, class L, class R>
592 GLDEF_C void TestTDes<T,S,L,R>::TestF()
593 // TBuf buffer Assignment
595 T aBuf(_TL("ABCDEF"));
598 bBuf.__DbgTestInvariant();
599 test(bBuf.MaxLength()==aBuf.MaxLength());
600 test(bBuf.MaxLength()==0x40);
601 test(bBuf.Length()==aBuf.Length());
602 test(bBuf.Length()==6);
603 for(S count=0;count<bBuf.Length();count++)
605 test(*(bBuf.Ptr()+count)==('A' + count));
606 test(*(bBuf.Ptr()+count)==*(aBuf.Ptr()+count));
611 template<class T, class S, class L, class R>
612 GLDEF_C void TestTDes<T,S,L,R>::TestG()
613 // TBufC string assignment test
615 S* pString=_TL("TestG");
618 test(buf.Length()==0);
620 buf.__DbgTestInvariant();
621 test(buf.Length()==5);
622 test(*(buf.Ptr())=='T');
623 test(*(buf.Ptr()+1)=='e');
624 test(*(buf.Ptr()+2)=='s');
625 test(*(buf.Ptr()+3)=='t');
626 test(*(buf.Ptr()+4)=='G');
630 template<class T, class S, class L, class R>
631 GLDEF_C void TestTDes<T,S,L,R>::TestH()
632 // TBufC descriptor assignment
637 test(buf.Length()==0);
639 buf.__DbgTestInvariant();
640 test(buf.Length()==5);
641 test(buf.Length()==des.Length());
642 test(*(buf.Ptr())=='T');
643 test(*(buf.Ptr()+1)=='e');
644 test(*(buf.Ptr()+2)=='s');
645 test(*(buf.Ptr()+3)=='t');
646 test(*(buf.Ptr()+4)=='H');
649 template<class T, class S, class L, class R>
650 GLDEF_C void TestTDes<T,S,L,R>::TestI()
651 // TBufC TBufC assignment
653 T oldBuf(_TL("TEsti"));
656 test(newBuf.Length()==0);
658 newBuf.__DbgTestInvariant();
659 test(newBuf.Length()==5);
660 test(newBuf.Length()==oldBuf.Length());
661 test(*(newBuf.Ptr())=='T');
662 test(*(newBuf.Ptr()+1)=='E');
663 test(*(newBuf.Ptr()+2)=='s');
664 test(*(newBuf.Ptr()+3)=='t');
665 test(*(newBuf.Ptr()+4)=='i');
668 template<class T,class S,class L,class R>
669 GLDEF_C void TestTDes<T,S,L,R>::TestJ()
671 // HBufC string assignment
675 S* pString=_TL("tEStJ");
677 TRAPD(ret,pBuf=T::NewL(0x40))
681 pBuf->__DbgTestInvariant();
682 test(pBuf->Length()==5);
683 test(*(pBuf->Ptr())=='t');
684 test(*(pBuf->Ptr()+1)=='E');
685 test(*(pBuf->Ptr()+2)=='S');
686 test(*(pBuf->Ptr()+3)=='t');
687 test(*(pBuf->Ptr()+4)=='J');
691 template<class T,class S,class L,class R>
692 GLDEF_C void TestTDes<T,S,L,R>::TestK()
694 // HBufC descriptor assignment
700 TRAPD(ret,pBuf=T::NewL(0x40))
704 pBuf->__DbgTestInvariant();
705 test(pBuf->Length()==5);
706 test(pBuf->Length()==des.Length());
707 test(*(pBuf->Ptr())=='T');
708 test(*(pBuf->Ptr()+1)=='e');
709 test(*(pBuf->Ptr()+2)=='s');
710 test(*(pBuf->Ptr()+3)=='t');
711 test(*(pBuf->Ptr()+4)=='K');
715 template<class T,class S,class L,class R>
716 GLDEF_C void TestTDes<T,S,L,R>::TestL()
718 // HBufC HBufC assignment
722 S* pString=_TL("testl");
725 TRAPD(ret,pOldBuf=T::NewL(0x40))
727 TRAP(ret,pNewBuf=T::NewL(0x40))
733 pOldBuf->__DbgTestInvariant();
734 pNewBuf->__DbgTestInvariant();
735 test(pNewBuf->Length()==5);
736 test(pOldBuf->Length()==pNewBuf->Length());
737 test(*(pNewBuf->Ptr())=='t');
738 test(*(pNewBuf->Ptr()+1)=='e');
739 test(*(pNewBuf->Ptr()+2)=='s');
740 test(*(pNewBuf->Ptr()+3)=='t');
741 test(*(pNewBuf->Ptr()+4)=='l');
745 TRAP(ret,pOldBuf=T::NewMaxL(0x40))
747 TRAP(ret,pNewBuf=T::NewMaxL(0x40))
751 pOldBuf->__DbgTestInvariant();
752 pNewBuf->__DbgTestInvariant();
753 test(pNewBuf->Length()==0x40);
754 test(pOldBuf->Length()==0x40);
755 pNewBuf->Des().Zero();
756 pOldBuf->Des().Zero();
757 pOldBuf->__DbgTestInvariant();
758 pNewBuf->__DbgTestInvariant();
759 test(pNewBuf->Length()==0);
760 test(pOldBuf->Length()==0);
763 pOldBuf->__DbgTestInvariant();
764 pNewBuf->__DbgTestInvariant();
765 test(pNewBuf->Length()==5);
766 test(pOldBuf->Length()==pNewBuf->Length());
767 test(*(pNewBuf->Ptr())=='t');
768 test(*(pNewBuf->Ptr()+1)=='e');
769 test(*(pNewBuf->Ptr()+2)=='s');
770 test(*(pNewBuf->Ptr()+3)=='t');
771 test(*(pNewBuf->Ptr()+4)=='l');
776 template<class T,class S,class L,class R>
777 GLDEF_C void TestTDes<T,S,L,R>::TestM()
783 S* pString=_TL("TESTM");
789 pBuf->__DbgTestInvariant();
790 test(pBuf->Length()==5);
791 test(*(pBuf->Ptr())=='T');
792 test(*(pBuf->Ptr()+1)=='E');
793 test(*(pBuf->Ptr()+2)=='S');
794 test(*(pBuf->Ptr()+3)=='T');
795 test(*(pBuf->Ptr()+4)=='M');
799 template<class T,class S,class L,class R>
800 GLDEF_C void TestTDes<T,S,L,R>::TestN()
802 // HBufC ReAllocL - forcing a leave
808 Reinstate if some method is found of forcing alloc fail
809 This test no longer works due to heap growing functionality of E32 057
811 S* pString=_TL("tEStJ");
813 TInt available, temp;
818 available=User::Available(temp);
819 pDummy=User::Alloc(available);
820 TRAPD(ret,pBuf->ReAllocL(0x50))
821 test(ret==KErrNoMemory);
827 template<class T,class S,class L,class R>
828 GLDEF_C void TestTDes<T,S,L,R>::TestO()
829 // HBufC ReAllocL - forcing success
832 S* pString=_TL("tEStJ");
837 TRAPD(ret,pBuf->ReAllocL(0x40))
840 pBuf->__DbgTestInvariant();
841 test(pBuf->Length()==5);
842 test(*(pBuf->Ptr())=='t');
843 test(*(pBuf->Ptr()+1)=='E');
844 test(*(pBuf->Ptr()+2)=='S');
845 test(*(pBuf->Ptr()+3)=='t');
846 test(*(pBuf->Ptr()+4)=='J');
850 template<class T,class S,class L,class R>
851 GLDEF_C void TestTDes<T,S,L,R>::TestP()
852 // Invariant for null pointer descriptor
853 // Added to reproduce DEF023302
856 p.__DbgTestInvariant();
859 GLDEF_C void TestCopy16()
860 // Test TPtr16 copy constructor
862 TBuf16<0x20> buf(_S16("Paddington Station"));
863 TPtr16 ptr1((TText16*)buf.Ptr(),buf.Length(),buf.MaxLength());
864 ptr1.__DbgTestInvariant();
866 ptr2.__DbgTestInvariant();
873 ptr2.Append(_L16(" acid"));
874 test(ptr1==_L16("Paddington Bear"));
875 test(ptr2==_L16("Paddington Bear on acid"));
878 GLDEF_C void Test16To8()
879 // Test ASCII dest with Unicode source
881 TBuf8<0x20> buf(_S8("Paddington Station"));
882 TPtr8 ptr1((TText8*)buf.Ptr(),buf.Length(),buf.MaxLength());
883 ptr1.__DbgTestInvariant();
885 ptr2.__DbgTestInvariant();
892 ptr1.__DbgTestInvariant();
893 ptr2.Append(_L16(" acid"));
894 ptr2.__DbgTestInvariant();
895 test(ptr1==_L8("Paddington Bear"));
896 test(ptr2==_L8("Paddington Bear on acid"));
900 GLDEF_C void TestCopy8()
901 // Test TPtr8 copy constructor
903 TBuf8<0x20> buf(_S8("Paddington Station"));
904 TPtr8 ptr1((TText8*)buf.Ptr(),buf.Length(),buf.MaxLength());
912 ptr2.Append(_L8(" acid"));
913 ptr1.__DbgTestInvariant();
914 ptr2.__DbgTestInvariant();
915 test(ptr1==_L8("Paddington Bear"));
916 test(ptr2==_L8("Paddington Bear on acid"));
919 GLDEF_C void TestCopy()
920 // Test TPtr copy constructor
922 TBuf<0x20> buf(_S("Paddington Station"));
923 TPtr ptr1((TText*)buf.Ptr(),buf.Length(),buf.MaxLength());
931 ptr2.Append(_L(" acid"));
932 ptr1.__DbgTestInvariant();
933 ptr2.__DbgTestInvariant();
934 test(ptr1==_L("Paddington Bear"));
935 test(ptr2==_L("Paddington Bear on acid"));
938 template<class T, class S, class L, class R>
939 GLDEF_C void TestTDes<T,S,L,R>::test_TPtrC()
941 // Test the TDesC class special member functions
945 test.Start(_L("Invariant for null pointer descriptor"));
947 test.Next(_L("R/O view over constant string"));
949 test.Next(_L("R/O view over constant descriptor"));
951 test.Next(_L("R/O view over constant buffer with length"));
955 template<class T, class S, class L, class R>
956 GLDEF_C void TestTDes<T,S,L,R>::test_TPtr()
958 // Test the TPtr class special member functions
962 test.Start(_L("Invariant for null pointer descriptor"));
964 test.Next(_L("R/W view over buffer with length & maxlength"));
966 test.Next(_L("R/W view over buffer with maxlength"));
968 // Skipped the following test because Colly hasn't
969 // written the templates yet for the TBufC8 & 16 classes
970 // test.Next(_L("R/W view over LcbBase with maxlength"));
972 test.Next(_L("String assignment"));
974 test.Next(_L("DesW assignment"));
976 test.Next(_L("DesC assignment"));
980 template<class T, class S, class L, class R>
981 GLDEF_C void TestTDes<T,S,L,R>::test_TBuf()
983 // Test the TBuf class special member functions
987 test.Start(_L("TBuf default view, no params"));
989 test.Next(_L("TBuf view with a length"));
991 test.Next(_L("TBuf view over a string"));
993 test.Next(_L("TBuf view over a descriptor"));
995 test.Next(_L("TBuf view over a buffer"));
997 test.Next(_L("String assignment"));
999 test.Next(_L("Descriptor assignment"));
1001 test.Next(_L("Buffer assignment"));
1005 template<class T,class S,class L,class R>
1006 GLDEF_C void TestTDes<T,S,L,R>::test_TBufC()
1008 // Test the TBufC class methods
1012 test.Start(_L("Default constructor"));
1014 test.Next(_L("With a string"));
1016 test.Next(_L("With a Descriptor (TPtrC)"));
1018 test.Next(_L("With a TBufC"));
1020 test.Next(_L("String assignment"));
1022 test.Next(_L("Descriptor assignment (TPtrC)"));
1024 test.Next(_L("TBufC assignment"));
1028 template<class T,class S,class L,class R>
1029 GLDEF_C void TestTDes<T,S,L,R>::test_HBufC()
1031 // Test the HBufC class methods.
1035 test.Start(_L("New"));
1037 test.Next(_L("NewL - forcing a leave"));
1039 test.Next(_L("NewL - showing success"));
1041 test.Next(_L("String assignment"));
1043 test.Next(_L("Descriptor assignment"));
1045 test.Next(_L("HBufC assignment"));
1047 test.Next(_L("ReAlloc"));
1049 test.Next(_L("ReAllocL - forcing a leave"));
1051 test.Next(_L("ReAllocL - showing success"));
1055 template<class T,class S,class L,class R>
1056 GLDEF_C void TestTDes<T,S,L,R>::test_TBufReturningModifiable()
1060 a.Copy(_TL("abcdefg"));
1061 test_TDesReturningModifiable(a,b);
1064 template<class T,class S,class L,class R>
1065 GLDEF_C void TestTDes<T,S,L,R>::test_TPtrReturningModifiable()
1068 aBuf=_TL("abcdefg");
1071 test_TDesReturningModifiable(a,b);
1074 template<class T,class S,class L,class R>
1075 GLDEF_C void TestTDes<T,S,L,R>::test_TDesReturningModifiable(const T& a, R& b)
1077 test.Start(_L("Test TDes derived objects that return TPtrs"));
1079 test.Next(_L("LeftTPtr"));
1080 b.Set(a.LeftTPtr(3));
1081 b.__DbgTestInvariant();
1082 test(b == a.Left(3));
1084 b.Set(a.LeftTPtr(0));
1085 b.__DbgTestInvariant();
1086 test(b == a.Left(0));
1088 b.Set(a.LeftTPtr(7));
1089 b.__DbgTestInvariant();
1090 test(b == a.Left(7));
1093 b.__DbgTestInvariant();
1094 test(b == a.Left(7));
1096 test.Next(_L("RightTPtr"));
1097 b.Set(a.RightTPtr(5));
1098 b.__DbgTestInvariant();
1099 test(b == a.Right(5));
1101 b.Set(a.RightTPtr(7));
1102 b.__DbgTestInvariant();
1103 test(b == a.Right(7));
1105 b.Set(a.RightTPtr(0));
1106 b.__DbgTestInvariant();
1107 test(b == a.Right(0));
1109 b.Set(a.RightTPtr(42));
1110 b.__DbgTestInvariant();
1111 test(b == a.Right(42));
1113 test.Next(_L("MidTPtr"));
1114 b.Set(a.MidTPtr(5));
1115 b.__DbgTestInvariant();
1116 test(b == a.Mid(5));
1118 b.Set(a.MidTPtr(7));
1119 b.__DbgTestInvariant();
1120 test(b == a.Mid(7));
1122 b.Set(a.MidTPtr(0));
1123 b.__DbgTestInvariant();
1124 test(b == a.Mid(0));
1126 test.Next(_L("MidTPtr (2 parms)"));
1127 b.Set(a.MidTPtr(4,3));
1128 b.__DbgTestInvariant();
1129 test(b == a.Mid(4,3));
1130 test(b == a.Mid(4));
1132 b.Set(a.MidTPtr(0,0));
1133 b.__DbgTestInvariant();
1134 test(b == a.Mid(0,0));
1136 b.Set(a.MidTPtr(3,2));
1137 b.__DbgTestInvariant();
1138 test(b == a.Mid(3,2));
1140 b.Set(a.MidTPtr(7,0));
1141 b.__DbgTestInvariant();
1142 test(b == a.Mid(7,0));
1145 LOCAL_C void testAssignTPtr()
1147 // Test assigning TPtr's.
1151 TBufC<0x20> x(_S("Hello"));
1154 test(p==_L("Hello World"));
1155 test(x==_L("Hello World"));
1157 test(p==_L("Hello"));
1158 test(x==_L("Hello"));
1159 TBufC<0x20> y(_S("ByeBye"));
1164 test(q==_L("Hello World"));
1165 test(x==_L("Hello World"));
1166 test(y==_L("ByeBye"));
1167 q.Set((TText*)x.Ptr(),x.Length(),x.Des().MaxLength());
1168 test(q==_L("Hello World"));
1169 test(q.MaxLength()==0x20);
1172 test(x==_L("Hello World"));
1175 LOCAL_C void testTPtrLocateReverse()
1177 // Test locating in reverse on an empty TPtr
1182 test(a.LocateReverse('0')==KErrNotFound);
1183 test(a.LocateReverseF('0')==KErrNotFound);
1186 _LIT8(KLitTest1_8,"1");
1187 _LIT8(KLitTest12_8,"12");
1188 _LIT8(KLitTest123_8,"123");
1189 _LIT8(KLitTest1234_8,"1234");
1190 _LIT8(KLitTestalpha_8,"abcdefghijklmnopqrstuvwxyz");
1192 LOCAL_C const TDesC8& testByRef8(TRefByValue<const TDesC8> aRef)
1197 LOCAL_C void testTLitC8()
1199 test.Start(_L("All members"));
1200 test (_L8("")==KNullDesC8); // operator const TDesC8&
1201 test (KNullDesC8()==TPtrC8()); // operator()
1202 const TDesC8* pNull=&KNullDesC8; // operator&
1203 test (pNull->Compare(_L8(""))==0);
1204 test (&testByRef8(KNullDesC8)==&KNullDesC8); // operator const TRefByValue<const TDesC8>
1206 test.Next(_L("Literal values"));
1207 const TDesC8& t1=KLitTest1_8;
1208 test (t1.Length()==1);
1210 test (t1==_L8("1"));
1211 const TDesC8& t12=KLitTest12_8;
1212 test (t12.Length()==2);
1214 test (t12==_L8("12"));
1215 const TDesC8& t123=KLitTest123_8;
1216 test (t123.Length()==3);
1217 test (t123[0]=='1');
1218 test (t123==_L8("123"));
1219 const TDesC8& t1234=KLitTest1234_8;
1220 test (t1234.Length()==4);
1221 test (t1234[0]=='1');
1222 test (t1234==_L8("1234"));
1223 const TDesC8& talpha=KLitTestalpha_8;
1224 test (talpha.Length()==26);
1225 test (talpha[0]=='a');
1226 test (talpha==_L8("abcdefghijklmnopqrstuvwxyz"));
1231 _LIT16(KLitTest1_16,"1");
1232 _LIT16(KLitTest12_16,"12");
1233 _LIT16(KLitTest123_16,"123");
1234 _LIT16(KLitTest1234_16,"1234");
1235 _LIT16(KLitTestalpha_16,"abcdefghijklmnopqrstuvwxyz");
1237 LOCAL_C const TDesC16& testByRef16(TRefByValue<const TDesC16> aRef)
1242 LOCAL_C void testTLitC16()
1244 test.Start(_L("All members"));
1245 test (_L16("")==KNullDesC16); // operator const TDesC16&
1246 test (KNullDesC16()==TPtrC16()); // operator()
1247 const TDesC16* pNull=&KNullDesC16; // operator&
1248 test (pNull->Compare(_L16(""))==0);
1249 test (&testByRef16(KNullDesC16)==&KNullDesC16); // operator const TRefByValue<const TDesC16>
1251 test.Next(_L("Literal values"));
1252 const TDesC16& t1=KLitTest1_16;
1253 test (t1.Length()==1);
1255 test (t1==_L16("1"));
1256 const TDesC16& t12=KLitTest12_16;
1257 test (t12.Length()==2);
1259 test (t12==_L16("12"));
1260 const TDesC16& t123=KLitTest123_16;
1261 test (t123.Length()==3);
1262 test (t123[0]=='1');
1263 test (t123==_L16("123"));
1264 const TDesC16& t1234=KLitTest1234_16;
1265 test (t1234.Length()==4);
1266 test (t1234[0]=='1');
1267 test (t1234==_L16("1234"));
1268 const TDesC16& talpha=KLitTestalpha_16;
1269 test (talpha.Length()==26);
1270 test (talpha[0]=='a');
1271 test (talpha==_L16("abcdefghijklmnopqrstuvwxyz"));
1276 _LIT(KLitTest1,"1");
1277 _LIT(KLitTest12,"12");
1278 _LIT(KLitTest123,"123");
1279 _LIT(KLitTest1234,"1234");
1280 _LIT(KLitTestalpha,"abcdefghijklmnopqrstuvwxyz");
1282 LOCAL_C const TDesC& testByRef(TRefByValue<const TDesC> aRef)
1287 LOCAL_C void testTLitC()
1289 test.Start(_L("All members"));
1290 test (_L("")==KNullDesC); // operator const TDesC&
1291 test (KNullDesC()==TPtrC()); // operator()
1292 const TDesC* pNull=&KNullDesC; // operator&
1293 test (pNull->Compare(_L(""))==0);
1294 test (&testByRef(KNullDesC)==&KNullDesC); // operator const TRefByValue<const TDesC>
1295 #if defined(_UNICODE)
1296 test (_L16("")==KNullDesC); // operator const TDesC&
1297 test (KNullDesC()==TPtrC16()); // operator()
1298 const TDesC16* pNull16=&KNullDesC; // operator&
1299 test (pNull16->Compare(_L16(""))==0);
1300 test (&testByRef16(KNullDesC)==&KNullDesC); // operator const TRefByValue<const TDesC>
1302 test (_L8("")==KNullDesC); // operator const TDesC&
1303 test (KNullDesC()==TPtrC8()); // operator()
1304 const TDesC8* pNull8=&KNullDesC; // operator&
1305 test (pNull8->Compare(_L8(""))==0);
1306 test (&testByRef8(KNullDesC)==&KNullDesC); // operator const TRefByValue<const TDesC>
1309 test.Next(_L("Literal values"));
1310 const TDesC& t1=KLitTest1;
1311 test (t1.Length()==1);
1314 const TDesC& t12=KLitTest12;
1315 test (t12.Length()==2);
1317 test (t12==_L("12"));
1318 const TDesC& t123=KLitTest123;
1319 test (t123.Length()==3);
1320 test (t123[0]=='1');
1321 test (t123==_L("123"));
1322 const TDesC& t1234=KLitTest1234;
1323 test (t1234.Length()==4);
1324 test (t1234[0]=='1');
1325 test (t1234==_L("1234"));
1326 const TDesC& talpha=KLitTestalpha;
1327 test (talpha.Length()==26);
1328 test (talpha[0]=='a');
1329 test (talpha==_L("abcdefghijklmnopqrstuvwxyz"));
1334 LOCAL_C void testLiteral()
1336 test.Next(_L("class TLitC8"));
1338 test.Next(_L("class TLitC16"));
1340 test.Next(_L("class TLitC"));
1345 @SYMTestCaseID TI18N-TDESC-CIT-4012
1346 @SYMTestCaseDesc Check surrogate function
1347 @SYMTestPriority High
1348 @SYMTestActions Test Match, Locate, FindCorruptSurrogate, Match2
1349 @SYMTestExpectedResults It works as function specifies
1350 @SYMREQ REQ12064, REQ12065
1353 LOCAL_C void testSurrogateAwareInterfaces()
1355 test.Next(_L("new TDesC interfaces"));
1360 #pragma warning (disable: 4702)// Unreachable code
1361 #pragma warning (disable: 4701)// Local variable used without being initialized
1362 #pragma warning (disable: 4710)// Function not expanded
1365 GLDEF_C TInt E32Main()
1367 // Test the TDes type.
1372 TInt startAvail,temp;
1373 startAvail=User::Available(temp);
1375 test.Start(_L("Assigning TPtr's"));
1378 test.Next(_L("Locate reverse on empty TPtr"));
1379 testTPtrLocateReverse();
1381 test.Next(_L("class TBuf<0x40>"));
1382 TestTDes<TBuf<0x40>,TText,TUint, TPtrC> jj;
1384 jj.testHeapSpace(startAvail);
1387 test.Next(_L("class TBuf8<0x40>"));
1388 TestTDes<TBuf8<0x40>,TUint8,TUint8, TPtrC8> ii;
1390 ii.testHeapSpace(startAvail);
1393 test.Next(_L("class TBuf16<0x40>"));
1394 TestTDes<TBuf16<0x40>,TUint16,TUint16, TPtrC16> hh;
1396 hh.testHeapSpace(startAvail);
1399 test.Next(_L("class TPtrC"));
1400 TestTDes<TPtrC,TText,TUint, TPtrC> dd;
1402 dd.testHeapSpace(startAvail);
1405 test.Next(_L("class TPtrC8"));
1406 TestTDes<TPtrC8,TUint8,TUint8, TPtrC8> cc;
1408 cc.testHeapSpace(startAvail);
1411 test.Next(_L("class TPtrC16"));
1412 TestTDes<TPtrC16,TUint16,TUint16, TPtrC16> bb;
1414 bb.testHeapSpace(startAvail);
1417 test.Next(_L("class TPtr"));
1418 TestTDes<TPtr,TText,TUint, TPtrC> gg;
1420 gg.testHeapSpace(startAvail);
1421 test.Next(_L("Copy constructor"));
1425 test.Next(_L("class TPtr8"));
1426 TestTDes<TPtr8,TUint8,TUint8, TPtrC8> ff;
1428 ff.testHeapSpace(startAvail);
1429 test.Next(_L("Copy constructor"));
1433 test.Next(_L("class TPtr16"));
1434 TestTDes<TPtr16,TUint16,TUint16, TPtrC16> ee;
1436 ee.testHeapSpace(startAvail);
1437 test.Next(_L("Copy constructor"));
1441 test.Next(_L("class TBufC"));
1442 TestTDes<TBufC<0x40>, TText, TUint16, TPtrC> kk;
1444 kk.testHeapSpace(startAvail);
1447 test.Next(_L("class TBufC8"));
1448 TestTDes<TBufC8<0x40>, TUint8, TUint8, TPtrC8> ll;
1450 ll.testHeapSpace(startAvail);
1453 test.Next(_L("class TBufC16"));
1454 TestTDes<TBufC16<0x40>, TUint16, TUint16, TPtrC16> mm;
1456 mm.testHeapSpace(startAvail);
1459 test.Next(_L("class HBufC"));
1460 TestTDes<HBufC, TText, TUint, TPtrC> nn;
1462 nn.testHeapSpace(startAvail);
1465 test.Next(_L("class HBufC8"));
1466 TestTDes<HBufC8, TUint8, TUint8, TPtrC8> oo;
1468 oo.testHeapSpace(startAvail);
1471 test.Next(_L("Test Unicode to Ascii stuff"));
1474 test.Next(_L("class HBufC16"));
1475 TestTDes<HBufC16, TUint16, TUint16, TPtrC16> pp;
1477 pp.testHeapSpace(startAvail);
1482 test.Next(_L("class TBuf returning TPtr"));
1483 TestTDes<TBuf<0x40>, TText, TUint, TPtr> qq;
1484 qq.test_TBufReturningModifiable();
1487 test.Next(_L("class TBuf8 returning TPtr8"));
1488 TestTDes<TBuf8<0x40>, TText8, TUint8, TPtr8> rr;
1489 rr.test_TBufReturningModifiable();
1492 test.Next(_L("class TBuf16 returning TPtr16"));
1493 TestTDes<TBuf16<0x40>, TText16, TUint16, TPtr16> ss;
1494 ss.test_TBufReturningModifiable();
1497 test.Next(_L("class TPtr returning TPtr"));
1498 TestTDes<TPtr, TText, TUint, TPtr> tt;
1499 tt.test_TPtrReturningModifiable();
1502 test.Next(_L("class TPtr8 returning TPtr8"));
1503 TestTDes<TPtr8, TText8, TUint8, TPtr8> uu;
1504 uu.test_TPtrReturningModifiable();
1507 test.Next(_L("class TPtr16 returning TPtr16"));
1508 TestTDes<TPtr16, TText16, TUint16, TPtr16> vv;
1509 vv.test_TPtrReturningModifiable();
1512 testSurrogateAwareInterfaces();
1517 #pragma warning (default: 4702)// Unreachable code
1518 #pragma warning (default: 4701)// Local variable used without being initialized
1519 #pragma warning (default: 4710)// Function not expanded