Update contrib.
1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\buffer\t_buf.cpp
16 // Test methods of the TBuf16, TBuf8, TBuf template class.
18 // TBuf16, TBuf8, TBuf.
20 // - Create some 16 bit modifiable descriptors, 8 bit modifiable descriptors
21 // of fixed length, Build-independent modifiable descriptors, initialize
22 // with different strings and check for
23 // - Comparison operators,
24 // - Property access methods,
25 // - Fill & swap methods,
26 // - Conversion methods,
27 // - Comparison methods,
28 // - Pattern Matching methods,
29 // - Pattern Locating methods,
31 // - Find, FindC, FindF methods,
32 // - Repeat, Trim, TrimLeft, TrimRight, Insert, Delete, Left,
33 // Right, Mid methods,
34 // - Formatting methods,
35 // - Replace methods are as expected.
36 // - Construct some descriptors with buffer length, string and buffer reference and
37 // verify that they are created successfully.
38 // - Test assignment operators and comparison operators for different descriptors.
39 // - Initialize some descriptors and check descriptors' maximum length, length and
40 // size are as expected.
41 // - Check Fill and Swap methods are as expected.
42 // - Test Fold, Collate, LowerCase, UpperCase methods are as expected.
43 // - Test Comparison methods are as expected.
44 // - Test pattern matching for simple string, wild cards with collated comparison. Verify that the
45 // return value is KErrNotFound when pattern doesn't match.
46 // - Check Locating methods by searching character in forward and backward direction and
47 // verify the return value is KErrNotFound when unavailable character is searched.
48 // - Check copying strings and converting those into lower and upper case strings are
50 // - Check Find methods by searching string and verify the return value is KErrNotFound when
51 // unavailable string is searched.
52 // - Check Repeat, Trim, Insert and Delete methods are as expected.
53 // - Check the formatting operations are as expected.
54 // - Check integer to decimal character representation is as expected.
55 // - Check integer to character representation with different number system is as expected.
56 // - Check string formatting with variable parameter list is as expected
57 // - Check Replace method by replacing string at different places in a string is as expected.
58 // - Check the conversion of real numbers, extended precision real numbers into string
59 // format is as expected.
60 // - Check Format and FormatList methods are as expected.
61 // - Check Format of TReal is as expected.
62 // - Check the non-leaving and leaving descriptors overflow handlers are as expected.
63 // Platforms/Drives/Compatibility:
65 // Assumptions/Requirement/Pre-requisites:
66 // Failures and causes:
67 // Base Port information:
79 // Solve compilation problem caused by non-English locale
80 #pragma setlocale("english")
83 LOCAL_D RTest test(_L("T_BUF"));
85 #pragma warning(disable: 4127) // disabling warning "conditional expression is constant"
86 #pragma warning(disable: 4310) // disabling warning "cast truncates constant value"
89 #define _TL(a) DESTEMPLATE((S*)RTest::String(sizeof(S),(TText8*)a,(TText16*)L ## a))
91 #define _TS(a) ((const S*)RTest::String(sizeof(S),(TText8*)a,(TText16*)L ## a))
93 template<class T,class S,class DESTEMPLATE>
97 TestTBuf(TInt aLength); // Test class constructor.
98 void Test1(); // Tests all functions of the class.
99 void Test2(); // Tests all constructors.
100 void Test3(); // Tests all assignment operators
101 void Test4(); // Tests all comparison operators
102 void Test5(); // Tests all property access
103 void Test6(); // Tests all fill and swap
104 void Test7(); // Tests all conversion
105 void Test8(); // Tests all comparison
106 void Test9(); // Tests all matching
107 void Test10(); // Tests all locating
108 void Test11(); // Tests all Copying
109 void Test12(); // Tests all finding
110 void Test13(); // Tests all basic like ops
111 void Test14(); // Tests all formating
112 void Test15(); // Tests all replacing
113 void test_TBuf(); // Test all classes
115 void Test1List(T* a,T* b,...);
116 void Test14_ReorderedParameterFormatting(TInt aDummyParameter, ...);
121 void TestEq(const TDesC8& a, const TDesC8& b, TInt aLine)
126 test.Printf(_L("LINE %d:\n"),aLine);
128 test.Printf(_L("a=%S\n"),&buf);
130 test.Printf(_L("b=%S\n"),&buf);
135 void TestEq(const TDesC16& a, const TDesC16& b, TInt aLine)
139 test.Printf(_L("LINE %d:\n"),aLine);
140 test.Printf(_L("a=%S\n"),&a);
141 test.Printf(_L("b=%S\n"),&b);
146 #define TESTEQ(a,b) TestEq((a),(b),__LINE__)
148 template <class T,class S,class DESTEMPLATE>
149 GLDEF_C TestTBuf<T,S,DESTEMPLATE>::TestTBuf(TInt aLength)
151 : iMaxBufLength(aLength)
154 template <class T,class S,class DESTEMPLATE>
155 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test1List(T* a,T* b,...)
156 // Test the format with list functions.
162 a->AppendFormat(*b,list);
164 a->Format(_TL("%d"),list);
166 a->AppendFormat(_TL("%d"),list);
169 template <class T,class S,class DESTEMPLATE>
170 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test1()
171 // Tests all functions of the class.
173 test.Start(_L("Constructors"));
179 // To avoid unused warning
185 test.Next(_L("Copy operators"));
191 test.Next(_L("Comparison operators"));
210 test.Next(_L("Property access"));
213 TInt i=a.MaxLength()-a.Length();
218 test.Next(_L("Fill & swap"));
220 a.Fill(' ',iMaxBufLength);
222 a.FillZ(iMaxBufLength);
225 test.Next(_L("Conversion"));
232 test.Next(_L("Comparison"));
234 a.Compare(_TL("AB"));
236 a.CompareF(_TL("AB"));
238 a.CompareC(_TL("AB"));
240 test.Next(_L("Matching"));
246 T buf(_TL("abcdef"));
247 TInt res = buf.MatchF(_TL("abc*def"));
253 test.Next(_L("Locating"));
256 a.LocateReverse('A');
257 a.LocateReverseF('A');
259 test.Next(_L("Copying"));
262 // a.Copy(_TL("AB"),1);
274 test.Next(_L("Finding"));
282 test.Next(_L("Basic like ops"));
295 test.Next(_L("Formating"));
296 a.Justify(_TL("AB"),10,ELeft,' ');
297 a.Justify(b,10,ELeft,' ');
300 a.AppendJustify(_TL("AB"),10,ELeft,' ');
301 a.AppendJustify(b,10,ELeft,' ');
306 a.Num((TUint)v2,EHex);
307 a.AppendNum((TUint)v2,EHex);
308 a.NumUC((TUint)v2,EHex);
309 a.AppendNumUC((TUint)v2,EHex);
312 ff.iType=KRealFormatFixed;
320 a.Format(_TL("%d"),12);
321 a.AppendFormat(_TL("%d"),12);
324 a.AppendFormat(b,12);
327 test.Next(_L("Replacing"));
334 template <class T,class S,class DESTEMPLATE>
335 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test2()
336 // Tests all constructors.
338 test.Start(_L("Default"));
340 test(a.MaxLength()==iMaxBufLength);
343 test.Next(_L("By length"));
344 T b(iMaxBufLength>>1);
345 test(b.MaxLength()==iMaxBufLength);
346 test(b.Length()==(iMaxBufLength>>1));
348 test.Next(_L("By string"));
350 test(c.MaxLength()==iMaxBufLength);
355 test.Next(_L("By buffer reference"));
357 test(d.MaxLength()==iMaxBufLength);
364 template <class T,class S,class DESTEMPLATE>
365 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test3()
366 // Tests all assignment operators
368 test.Start(_L("By String"));
373 test(a==_TL("ABCD"));
375 test.Next(_L("By buffer"));
380 test(b==_TL("ABCDABCD"));
385 template <class T,class S,class DESTEMPLATE>
386 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test4()
387 // Test all comparison operators
389 test.Start(_L("By NULL string"));
391 test(a==_TL("")); // NULL strings
404 test.Next(_L("By string or buffer"));
406 test(a==_TL("abc")); // ==
407 test(!(a==_TL("xyz")));
408 test(!(a==_TL("aa")));
410 test(!(_TL("xyz")==a));
411 test(!(_TL("aa")==a));
412 test(a!=_TL("xyz")); // !=
413 test(!(a!=_TL("abc")));
416 test(!(_TL("abc")!=a));
418 test(a<_TL("x")); // <
419 test(!(a<_TL("abc")));
420 test(!(a<_TL("aa")));
422 test(!(_TL("abc")<a));
423 test(!(_TL("xyz")<a));
424 test(a>_TL("aa")); // >
425 test(!(a>_TL("abc")));
426 test(!(a>_TL("xyz")));
428 test(!(_TL("abc")>a));
429 test(!(_TL("aa")>a));
430 test(a>=_TL("abc")); // >=
431 test(!(a>=_TL("xyz")));
434 test(!(_TL("aaa")>=a));
436 test(a<=_TL("abc")); // <=
437 test(!(a<=_TL("aa")));
440 test(!(_TL("xyz")<=a));
443 test.Next(_L("By special characters"));
445 test(a==_TL("!@#$%^&*()"));
449 template <class T,class S,class DESTEMPLATE>
450 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test5()
451 // Test all property access
453 test.Start(_L("Length and Size"));
455 TInt maxLength=a.MaxLength();
457 for (i=0;i<maxLength;i++)
459 test(a.Length()==i); // Length
460 test(a.Size()==(TInt)(sizeof(S)*i)); // Size
464 for (i=0;i<maxLength;i++)
466 test(a[i]=='0'+(i%10)); // At
467 test(b[i]=='0'+(i%10)); // AtConst
469 test(a[0]==*a.Ptr()); //Ptr
470 a.SetLength(0); // SetLength
472 a.SetLength(maxLength-1);
473 test(a.Length()==maxLength-1);
479 template <class T,class S,class DESTEMPLATE>
480 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test6()
483 test.Start(_L("Fill and Swap"));
487 TInt maxLength=a.MaxLength();
488 for (TInt i=0;i<maxLength;i++)
492 a.Fill(chr); // Fill(TChar)
494 test(b.Length()==i); // Swap
497 test(b[j++]=='0'+(i%10));
498 b.FillZ(); // FillZ()
503 a.Fill(chr,i); // Fill(TChar,TUint)
506 test(a[j++]=='0'+(i%10));
507 a.FillZ(i); // FillZ(TUint)
515 template <class T,class S,class DESTEMPLATE>
516 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test7()
517 // Conversion operators
519 test.Start(_L("Fold, collate ..."));
533 test(a==_TL("abc abc"));
535 test(a==_TL("Abc abc"));
537 test(a==_TL("ABC ABC"));
541 template <class T,class S,class DESTEMPLATE>
542 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test8()
545 test.Start(_L("By string"));
548 test(a.Compare(_TL("abc AbC"))==0);
549 test(a.CompareF(_TL("ABC aBc"))==0);
550 test(a.Compare(_TL("xyz"))!=0);
551 test(a.CompareC(_TL("xyz"))!=0);
552 test(a.CompareF(_TL("xyz"))!=0);
554 test.Next(_L("By buffer"));
560 test(a.Compare(b)==0);
561 test(a.Compare(c)!=0);
563 test(a.CompareC(c)!=0);
564 test(a.CompareF(b)==0);
565 test(a.CompareF(c)!=0);
570 template <class T,class S,class DESTEMPLATE>
571 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test9()
572 // Matching (need to test explicit result as error KErrNotFound = KMaxTUint
573 // and so registers as TRUE. (test parameter is TUint) )
575 test.Start(_L("By string"));
578 test(a.Match(_TL("abc AbC"))==0);
579 test(a.MatchC(_TL("ABC aBc"))==0);
580 test(a.MatchF(_TL("ABC aBc"))==0);
581 test(a.Match(_TL("xyz"))==KErrNotFound);
582 test(a.MatchC(_TL("xyz"))==KErrNotFound);
583 test(a.MatchF(_TL("xyz"))==KErrNotFound);
585 test.Next(_L("By buffer"));
592 test(a.Match(c)==KErrNotFound);
594 test(a.MatchC(b)==0);
595 test(a.MatchC(c)==KErrNotFound);
596 test(a.MatchF(b)==0);
597 test(a.MatchF(c)==KErrNotFound);
599 test.Next(_L("Wildcards"));
601 test(a.Match(_TL("abc*"))==0);
602 test(a.Match(_TL("abw*"))==KErrNotFound);
604 test(a.Match(_TL("a*fg"))==0);
605 test(a.Match(_TL("a*f"))==KErrNotFound);
606 test(a.Match(_TL("abc*fgh"))==KErrNotFound);
608 test(a.Match(_TL("abc?ef"))==0);
609 test(a.Match(_TL("abc?xf"))==KErrNotFound);
612 test(a.Match(_TL("*(01)"))==1);
613 test(a.Match(_TL("?(01)"))==0);
614 test(a.Match(_TL("?(*)"))==0);
615 test(a.Match(_TL("?(**)"))==0);
617 test(a.Match(_TL("?(\?\?)"))==0);
618 test(a.Match(_TL("*(*)"))>=0);
619 test(a.Match(_TL("*(0?)"))>=0);
620 test(a.Match(_TL("a(\?\?)"))==0);
621 test(a.Match(_TL("*(\?\?)"))>=0);
623 test.Next(_L("wild cards with collated comparison"));
624 a = _TL("abcdefghijkl");
625 test(a.MatchC(_TL("abc*")) == 0);
626 test(a.MatchC(_TL("abc")) == KErrNotFound);
627 test(a.MatchC(_TL("xyz")) == KErrNotFound);
628 test(a.MatchC(_TL("*def")) == KErrNotFound);
629 test(a.MatchC(_TL("*def*")) == 3);
630 test(a.MatchC(_TL("*d?f*")) == 3);
631 test(a.MatchC(_TL("a*kl")) == 0);
632 test(a.MatchC(_TL("*e*?l")) == 4);
633 test(a.MatchC(_TL("abc*dEf*")) == 0);
641 test(candidate.MatchC(search) == 0);
645 test(candidate.MatchC(search) == 0);
647 candidate = _TL("abcd");
648 search = _TL("*abc*cd");
649 test(candidate.MatchC(search) == KErrNotFound);
653 test.Next(_L("Unicode MatchC and FindC treat base+accent as equal to composed character"));
654 TPtrC p = _L("te\x302te");
655 test(p.MatchC(_L("t\xeate")) == 0);
656 test(p.FindC(_L("t\xeate")) == 0);
662 template <class T,class S,class DESTEMPLATE>
663 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test10()
669 test.Start(_L("First Char"));
672 test(a.Locate(b)==0);
673 test(a.LocateF(b)==0);
674 test(a.LocateReverse(b)==4);
675 test(a.LocateReverseF(b)==4);
677 test.Next(_L("Middle Char"));
679 test(a.Locate(b)==1);
680 test(a.LocateF(b)==1);
682 test(a.LocateReverse(b)==2);
683 test(a.LocateReverseF(b)==2);
685 test.Next(_L("Last Char"));
687 test(a.Locate(b)==2);
688 test(a.LocateF(b)==2);
690 test(a.LocateReverse(b)==0);
691 test(a.LocateReverseF(b)==0);
693 test.Next(_L("Test for failure of locate"));
695 test(a.Locate(b)==KErrNotFound);
696 test(a.LocateF(b)==KErrNotFound);
697 test(a.LocateReverse(b)==KErrNotFound);
698 test(a.LocateReverseF(b)==KErrNotFound);
703 template <class T,class S,class DESTEMPLATE>
704 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test11()
709 test.Start(_L("By String"));
717 a.CopyLC(_TL("AbC"));
724 a.CopyCP(_TL("abc"));
727 a.CopyUC(_TL("aBc"));
730 // a.Copy(_TL("abc"),3);
731 // test(a==_TL("abc"));
732 // test(a.Length()==3);
733 // a.Copy(_TL("abcd"),3);
734 // test(a==_TL("abc"));
735 // test(a.Length()==3);
737 test.Next(_L("By buffer"));
773 template <class T,class S,class DESTEMPLATE>
774 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test12()
777 test.Start(_L("By String"));
780 test(a.Find(_TL(""))==0);
781 test(a.Find(_TL("abc"))==0);
782 test(a.Find(_TL("cce"))==2);
783 test(a.Find(_TL("cef"))==3);
784 test(a.Find(_TL("efg"))==KErrNotFound);
785 test(a.Find(_TL("xxx"))==KErrNotFound);
786 test(a.FindF(_TL(""))==0);
787 test(a.FindF(_TL("AbC"))==0);
788 test(a.FindF(_TL("CcE"))==2);
789 test(a.FindF(_TL("CeF"))==3);
790 test(a.FindF(_TL("efg"))==KErrNotFound);
791 test(a.FindF(_TL("xxx"))==KErrNotFound);
792 test(a.FindC(_TL(""))==0);
793 test(a.FindC(_TL("aBc"))==0);
794 test(a.FindC(_TL("cce"))==2);
795 test(a.FindC(_TL("cEf"))==3);
796 test(a.FindC(_TL("efg"))==KErrNotFound);
797 test(a.FindC(_TL("xxx"))==KErrNotFound);
799 test.Next(_L("By buffer"));
804 test(a.Find(b)==KErrNotFound);
805 test(a.FindF(b)==KErrNotFound);
806 test(a.FindC(b)==KErrNotFound);
808 test(a.Find(b)==KErrNotFound);
809 test(a.FindF(b)==KErrNotFound);
810 test(a.FindC(b)==KErrNotFound);
833 template <class T,class S,class DESTEMPLATE>
834 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test13()
837 test.Start(_L("Repeat, trim, insert and delete"));
839 TInt max=a.MaxLength();
841 a.Repeat(_TL("abc"));
845 for (TInt j=1;j<max;j++) // ?? Cannot SetLength = MaxLength
848 a.Repeat(_TL("abc"));
859 a=_TL("\t\n ab \t\n ");
861 test(a==_TL("ab \t\n "));
863 a=_TL("\t\n ab \t\n ");
865 test(a==_TL("\t\n ab"));
867 a=_TL(" \t\n ab \t \n");
875 test(a==_TL("a123bc"));
879 test(a==_TL("a123bc"));
882 test(a==_TL("a123bc"));
891 test.Next(_L("TrimAll"));
901 a=_TL(" ab cd ef g");
903 test(a==_TL("ab cd ef g"));
906 test(a==_TL("abcdef"));
907 a=_TL("a b\t cd\t\tef");
909 test(a==_TL("a b\tcd\tef"));
910 a=_TL("abcdef \t ghijk");
912 test(a==_TL("abcdef ghijk"));
915 test(a==_TL("abcdef g"));
916 a=_TL("ab cd ef gh ij");
918 test(a==_TL("ab cd ef gh ij"));
919 a=_TL("a b c defg h i jk l mno pqr stu vw xyz");
921 test(a==_TL("a b c defg h i jk l mno pqr stu vw xyz"));
923 test.Next(_L("Right, Left and Mid"));
931 test(b==_TL("cdef"));
942 test(b==_TL("abcdef"));
947 test(b==_TL("abcdef"));
950 test(a==_TL("abcdef"));
953 test(b==_TL("abcdef"));
957 template <class T,class S,class DESTEMPLATE>
958 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test14()
959 // Formating operations
961 test.Start(_L("Justify"));
967 d=_TL("linearisation");
968 const S* pD=_TS("299792458");
970 aWidth=KDefaultJustifyWidth; // Left justified, Default width
971 a.Justify(b,aWidth,ELeft,c);
974 a.AppendJustify(b,aWidth,ELeft,c);
975 test(a==_TL("abcabc"));
977 aWidth=1; // Width < String length
978 a.Justify(b,aWidth,ELeft,c);
981 a.AppendJustify(b,aWidth,ELeft,c);
984 aWidth=5; // Width > String length
985 a.Justify(b,aWidth,ELeft,c);
986 test(a==_TL("abcxx"));
988 a.AppendJustify(b,aWidth,ELeft,c);
989 test(a==_TL("abcxxabcxx"));
990 test(a.Length()==10);
992 aWidth=KDefaultJustifyWidth; // Right justified, Default width
993 a.Justify(b,aWidth,ERight,c);
996 a.AppendJustify(b,aWidth,ERight,c);
997 test(a==_TL("abcabc"));
999 aWidth=1; // Right justified, Width < String length
1000 a.Justify(b,aWidth,ERight,c);
1002 test(a.Length()==1);
1003 a.AppendJustify(b,aWidth,ERight,c);
1005 test(a.Length()==2);
1006 aWidth=5; // Right justified, width > String length
1007 a.Justify(b,aWidth,ERight,c);
1008 test(a==_TL("xxabc"));
1009 test(a.Length()==5);
1010 a.AppendJustify(b,aWidth,ERight,c);
1011 test(a==_TL("xxabcxxabc"));
1012 test(a.Length()==10);
1014 aWidth=KDefaultJustifyWidth; // Center justified, Default width
1015 a.Justify(b,aWidth,ECenter,c);
1017 test(a.Length()==3);
1018 a.AppendJustify(b,aWidth,ECenter,c);
1019 test(a==_TL("abcabc"));
1020 test(a.Length()==6);
1021 aWidth=1; // Centre justified, width < String length
1022 a.Justify(b,aWidth,ECenter,c);
1024 test(a.Length()==1);
1025 a.AppendJustify(b,aWidth,ECenter,c);
1027 test(a.Length()==2);
1028 aWidth=5; // Centre justified, width > String length
1029 a.Justify(b,aWidth,ECenter,c);
1030 test(a==_TL("xabcx"));
1031 test(a.Length()==5);
1032 a.AppendJustify(b,aWidth,ECenter,c);
1033 test(a==_TL("xabcxxabcx"));
1034 test(a.Length()==10);
1036 test.Next(_L("Num"));
1037 TInt j=-2147483647-1;
1039 test(a==_TL("-2147483648"));
1040 test(a.Length()==11);
1041 TUint i=2147483648u;
1043 test(a==_TL("2147483648"));
1044 test(a.Length()==10);
1045 if (a.MaxLength()>31)
1048 test(a==_TL("10000000000000000000000000000000"));
1049 test(a.Length()==32);
1052 test(a==_TL("10000000000000000000000000000000"));
1053 test(a.Length()==32);
1057 test(a==_TL("11111"));
1058 test(a.Length()==5);
1061 test(a==_TL("11111"));
1062 test(a.Length()==5);
1065 test(a==_TL("20000000000"));
1066 test(a.Length()==11);
1069 test(a==_TL("20000000000"));
1070 test(a.Length()==11);
1072 test(a==_TL("2147483648"));
1073 test(a.Length()==10);
1075 a.NumUC(i,EDecimal);
1076 test(a==_TL("2147483648"));
1077 test(a.Length()==10);
1079 test(a==_TL("80000000"));
1080 test(a.Length()==8);
1083 test(a==_TL("80000000"));
1084 test(a.Length()==8);
1088 test(a.Length()==1);
1092 test(a.Length()==1);
1096 test(a.Length()==1);
1100 test(a.Length()==1);
1104 test(a.Length()==1);
1108 test(a.Length()==1);
1110 a.NumUC(i,EDecimal);
1112 test(a.Length()==1);
1116 test(a.Length()==1);
1120 test(a.Length()==1);
1121 // TInt i=a.Num(6.2,format); NOT IMPLEMENTED
1123 test(a==_TL("0-2147483648"));
1124 test(a.Length()==12);
1128 test(a==_TL("abc4294967295"));
1129 test(a.Length()==13);
1133 test(a==_TL("abc2147483647"));
1134 test(a.Length()==13);
1137 if (a.MaxLength()>28)
1139 a.AppendNum(i,EBinary);
1140 test(a==_TL("a1010101111001101111011110000"));
1141 test(a.Length()==29);
1144 a.AppendNum(15,EBinary);
1145 test(a==_TL("a1111"));
1146 test(a.Length()==5);
1148 a.AppendNum(i,EDecimal);
1149 test(a==_TL("a180150000"));
1150 test(a.Length()==10);
1152 a.AppendNum(i,EOctal);
1153 test(a==_TL("a1257157360"));
1154 test(a.Length()==11);
1156 a.AppendNumUC(i,EHex);
1157 test(a==_TL("aABCDEF0"));
1158 test(a.Length()==8);
1159 // i=a.AppendNum(6.32, format); NOT IMPLEMENTED
1161 test.Next(_L("Format"));
1164 a.Format(_TL("%S"),&b);
1166 test(a.Length()==3);
1167 DESTEMPLATE xyz=_TL("xyzwpq");
1168 a.Format(_TL("%S"),&xyz);
1169 test(a==_TL("xyzwpq"));
1170 test(a.Length()==6);
1171 DESTEMPLATE cde=_TL("cde");
1172 a.Format(_TL("ab %-x5S"),&cde);
1173 test(a==_TL("ab cdexx"));
1174 test(a.Length()==8);
1175 a.Format(_TL("ab %=x5S"),&cde);
1176 test(a==_TL("ab xcdex"));
1177 test(a.Length()==8);
1178 a.Format(_TL("ab %+x5S"),&cde);
1179 test(a==_TL("ab xxcde"));
1180 test(a.Length()==8);
1181 a.Format(_TL("ab %5S"),&cde);
1182 test(a==_TL("ab cde"));
1183 test(a.Length()==8);
1184 a.Format(_TL("ab %-**S"),'x',5,&cde);
1185 test(a==_TL("ab cdexx"));
1186 test(a.Length()==8);
1187 a.Format(_TL("ab %*S"),5,&cde);
1188 test(a==_TL("ab cde"));
1189 test(a.Length()==8);
1191 a.Format(_TL("ab %-x5S"),&b);
1192 test(a==_TL("ab cdexx"));
1193 test(a.Length()==8);
1195 a.Format(_TL("ab %-**S"),'x',5,&b);
1196 test(a==_TL("ab cdexx"));
1197 test(a.Length()==8);
1199 a.Format(_TL("ab %*S"),5,&b);
1200 test(a==_TL("ab cde"));
1201 test(a.Length()==8);
1203 DESTEMPLATE fred=_TL("fred");
1204 a.Format(_TL("%+0*S"),10,&fred);
1205 test(a==_TL("000000fred"));
1206 test(a.Length()==10);
1207 a.Format(_TL("%-0*S"),7,&fred);
1208 test(a==_TL("fred000"));
1209 test(a.Length()==7);
1210 a.Format(_TL("%0*S"),11,&fred);
1211 test(a==_TL("0000000fred"));
1212 test(a.Length()==11);
1213 a.Format(_TL("c=%s"),pD);
1214 TESTEQ(a,_TL("c=299792458"));
1215 a.Format(_TL("c=%10.6s"),pD);
1216 test(a==_TL("c= 299792"));
1217 a.Format(_TL("c=%*.*s"),5,4,pD);
1218 test(a==_TL("c= 2997"));
1219 a.Format(_TL("%S"),&d);
1220 test(a==_TL("linearisation"));
1221 a.Format(_TL("%10.6S"),&d);
1222 test(a==_TL(" linear"));
1223 a.Format(_TL("%*.*S"),5,4,&d);
1224 test(a==_TL(" line"));
1225 a.Format(_TL("%*.*Sed"),10,8,&d);
1226 test(a==_TL(" linearised"));
1227 a.Format(_TL("%*.*S"),14,20,&d);
1228 test(a==_TL(" linearisation"));
1230 a.Format(_TL("ab %-,5b"),7);
1231 test(a==_TL("ab 111,,"));
1232 test(a.Length()==8);
1233 a.Format(_TL("ab %=,5O"),31);
1234 test(a==_TL("ab ,37,,"));
1235 test(a.Length()==8);
1236 a.Format(_TL("ab %+xlx"),TInt64(171));
1237 test(a==_TL("ab ab"));
1238 test(a.Length()==5);
1239 a.Format(_TL("ab %+xlX %+xlx"),TInt64(171),TInt64(171));
1240 TESTEQ(a,_TL("ab AB ab"));
1241 test(a.Length()==8);
1242 a.Format(_TL("ab %lu"),MAKE_TINT64((TUint)(KMinTInt),0));
1243 test(a==_TL("ab 9223372036854775808"));
1244 test(a.Length()==22);
1245 a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMinTInt),1));
1246 test(a==_TL("ab -9223372036854775807"));
1247 test(a.Length()==23);
1248 a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMinTInt),0));
1249 test(a==_TL("ab -9223372036854775808"));
1250 test(a.Length()==23);
1251 a.Format(_TL("ab %ld"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint));
1252 test(a==_TL("ab 9223372036854775807"));
1253 test(a.Length()==22);
1254 a.Format(_TL("ab %ld"),MAKE_TINT64(KMaxTUint,KMaxTUint));
1255 test(a==_TL("ab -1"));
1256 test(a.Length()==5);
1257 a.Format(_TL("ab %lu"),MAKE_TINT64(KMaxTUint,KMaxTUint));
1258 test(a==_TL("ab 18446744073709551615"));
1259 test(a.Length()==23);
1260 a.Format(_TL("ab %ld"),TInt64(0));
1261 test(a==_TL("ab 0"));
1262 test(a.Length()==4);
1263 a.Format(_TL("ab %lb"),TInt64(0));
1264 test(a==_TL("ab 0"));
1265 test(a.Length()==4);
1266 a.Format(_TL("ab %lx"),TInt64(0));
1267 test(a==_TL("ab 0"));
1268 test(a.Length()==4);
1269 a.Format(_TL("ab %lo"),TInt64(0));
1270 test(a==_TL("ab 0"));
1271 test(a.Length()==4);
1272 a.Format(_TL("ab %lu"),TInt64(0));
1273 test(a==_TL("ab 0"));
1274 test(a.Length()==4);
1275 a.Format(_TL("ab %lb"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint));
1276 test(a==_TL("ab 111111111111111111111111111111111111111111111111111111111111111"));
1277 test(a.Length()==66);
1278 a.Format(_TL("ab %lb"),MAKE_TINT64(KMaxTUint,KMaxTUint));
1279 test(a==_TL("ab 1111111111111111111111111111111111111111111111111111111111111111"));
1280 test(a.Length()==67);
1281 a.Format(_TL("ab %lx"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint));
1282 test(a==_TL("ab 7fffffffffffffff"));
1283 test(a.Length()==19);
1284 a.Format(_TL("ab %lx"),MAKE_TINT64(KMaxTUint,KMaxTUint));
1285 test(a==_TL("ab ffffffffffffffff"));
1286 test(a.Length()==19);
1287 a.Format(_TL("ab %lo"),MAKE_TINT64((TUint)(KMaxTInt),KMaxTUint));
1288 test(a==_TL("ab 777777777777777777777"));
1289 test(a.Length()==24);
1290 // tests which excercise any 8 byte alignment requirement on 64bit integers
1291 a.Format(_TL("%li%S"),MAKE_TINT64(1,2),&fred);
1292 test(a==_TL("4294967298fred"));
1293 a.Format(_TL("%S%li%S"),&fred,MAKE_TINT64(1,2),&fred);
1294 test(a==_TL("fred4294967298fred"));
1295 a.Format(_TL("%lu%S"),MAKE_TINT64(1,2),&fred);
1296 test(a==_TL("4294967298fred"));
1297 a.Format(_TL("%S%lu%S"),&fred,MAKE_TINT64(1,2),&fred);
1298 test(a==_TL("fred4294967298fred"));
1300 a.Format(_TL("ab %U"),233);
1301 test(a==_TL("ab 233"));
1302 test(a.Length()==6);
1303 a.Format(_TL("ab %*d"),5,-131);
1304 test(a==_TL("ab -131"));
1305 test(a.Length()==8);
1306 a.Format(_TL("ab%c"),'x');
1307 test(a==_TL("abx"));
1308 test(a.Length()==3);
1309 a.Format(_TL("%W"),-131);
1310 test(*(TInt32*)a.Ptr()==-131);
1311 a.Format(_TL("%M"),-131);
1312 test(*(TInt32*)a.Ptr()==2113929215);
1313 a.Format(_TL("%w"),-131);
1314 test(*(TInt16*)a.Ptr()==-131);
1315 a.Format(_TL("%m"),-131);
1316 test(*(TInt16*)a.Ptr()==32255);
1318 a.AppendFormat(_TL("ab %+xlx"),TInt64(171));
1319 test(a==_TL("xyzab ab"));
1320 test(a.Length()==8);
1322 a.AppendFormat(_TL("ab %5S"),&b);
1323 test(a==_TL("xyzab cde"));
1324 test(a.Length()==11);
1326 a.AppendFormat(_TL("%W"),-131);
1327 // test(*(TInt32*)(a.Ptr()+3)==-131); // Alignment-safe version:
1329 Mem::Copy(&val,&a[3],4);
1332 // a.Append(_TL("abc"),3);
1333 // test(a==_TL("xyzabc"));
1337 a.Format(_TL(""),9,5);
1339 a.Format(_TL("qwerty"));
1340 test(a==_TL("qwerty"));
1341 a.Format(_TL("qwerty"),9,5);
1342 test(a==_TL("qwerty"));
1343 a.Format(_TL("%$1$d%$2$d"),9,5);
1345 test(a.Length()==2);
1346 a.Format(_TL("%$2$d%$1$d"),9,5);
1348 test(a.Length()==2);
1350 a.Format(_TL("%$1$S%$2$d"),&b,205);
1351 test(a==_TL("eb205"));
1352 test(a.Length()==5);
1353 a.Format(_TL("%$2$d%$1$S"),&b,205);
1354 test(a==_TL("205eb"));
1355 test(a.Length()==5);
1358 // Cannot do this on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime".
1359 #if !(defined(__GCC32__) && defined(__X86__))
1360 const TAny* const zeroTerminatedString=(sizeof(S)==2)? (const TAny*)_S16(":-)E"): (const TAny*)_S8(":-)E");
1361 const TInt dummyParameter=0;
1362 Test14_ReorderedParameterFormatting(dummyParameter, 0x20ac, 11, 3, 13.89543, zeroTerminatedString, '!', TInt64(199), 2, &b, 6, 30005, TRealX(0.125), 0x8bdd);
1365 test.Next(_L("Print some numbers"));
1366 TInt64 TI64 = MAKE_TINT64(0x101010u,0x10101010u);
1367 test.Printf(_L(" %%ld: %ld\n"),TI64);
1368 test.Printf(_L(" %%lu: %lu\n"),TI64);
1369 test.Printf(_L(" %%lx: %lx\n"),TI64);
1370 test.Printf(_L(" %%lb: %lb\n"),TI64);
1371 test.Printf(_L(" %%lo: %lo\n\n"),TI64);
1372 TI64 = UI64LIT(0xabcdef12345678);
1373 test.Printf(_L(" %%ld: %ld\n"),TI64);
1374 test.Printf(_L(" %%lu: %lu\n"),TI64);
1375 test.Printf(_L(" %%lx: %lx\n"),TI64);
1376 test.Printf(_L(" %%lb: %lb\n"),TI64);
1377 test.Printf(_L(" %%lo: %lo\n\n"),TI64);
1378 TI64 = UI64LIT(0x7fffffffffffffff);
1379 test.Printf(_L(" %%ld: %ld\n"),TI64);
1380 test.Printf(_L(" %%lu: %lu\n"),TI64);
1381 test.Printf(_L(" %%lx: %lx\n"),TI64);
1382 test.Printf(_L(" %%lb: %lb\n"),TI64);
1383 test.Printf(_L(" %%lo: %lo\n\n"),TI64);
1384 TI64 = UI64LIT(0x8000000000000000);
1385 test.Printf(_L(" %%ld: %ld\n"),TI64);
1386 test.Printf(_L(" %%lu: %lu\n"),TI64);
1387 test.Printf(_L(" %%lx: %lx\n"),TI64);
1388 test.Printf(_L(" %%lb: %lb\n"),TI64);
1389 test.Printf(_L(" %%lo: %lo\n\n"),TI64);
1390 TI64 = UI64LIT(0xffffffffffffffff);
1391 test.Printf(_L(" %%ld: %ld\n"),TI64);
1392 test.Printf(_L(" %%lu: %lu\n"),TI64);
1393 test.Printf(_L(" %%lx: %lx\n"),TI64);
1394 test.Printf(_L(" %%lb: %lb\n"),TI64);
1395 test.Printf(_L(" %%lo: %lo\n\n"),TI64);
1397 test.Next(_L("Regression tests"));
1398 a.Format(_TL("[%-A4p]"));
1399 test(a==_TL("[AAAA]"));
1404 template <class T,class S,class DESTEMPLATE>
1405 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test14_ReorderedParameterFormatting(TInt aDummyParameter, ...)
1407 VA_LIST parameterList;
1411 VA_START(parameterList, aDummyParameter);
1412 generated.FormatList(_TL("\t%-**.*fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%.3Fyyyyyyy%c"), parameterList);
1413 test(generated.Length()==61);
1414 expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www!!199eeeeebrrrrr007535tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
1415 test(generated.Left(generated.Length()-1)==expected);
1416 test(generated[generated.Length()-1]==(S)0x8bdd);
1418 VA_START(parameterList, aDummyParameter);
1419 generated.FormatList(_TL("\t%$1$-**.*fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%$6$.3Fyyyyyyy%c"), parameterList);
1420 test(generated.Length()==61);
1421 expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www!!199eeeeebrrrrr007535tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
1422 test(generated.Left(generated.Length()-1)==expected);
1423 test(generated[generated.Length()-1]==(S)0x8bdd);
1425 VA_START(parameterList, aDummyParameter);
1426 generated.FormatList(_TL("\t%$6$.3Fqq%.3swww%+*5Ldeeee%.*Srrrrr%0*xtttttt%$1$-**.*fyyyyyyy%c"), parameterList);
1427 test(generated.Length()==61);
1428 expected.Format(_TL("\t0.125qq:-)www!!199eeeeebrrrrr007535tttttt13.895%c%c%c%c%cyyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
1429 test(generated.Left(generated.Length()-1)==expected);
1430 test(generated[generated.Length()-1]==(S)0x8bdd);
1432 VA_START(parameterList, aDummyParameter);
1433 generated.FormatList(_TL("\t%-**.*fqq%.3swww%$5$0*xeeee%.*Srrrrr%$3$+*5Ldtttttt%.3Fyyyyyyy%c"), parameterList);
1434 test(generated.Length()==61);
1435 expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www007535eeeeebrrrrr!!199tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
1436 test(generated.Left(generated.Length()-1)==expected);
1437 test(generated[generated.Length()-1]==(S)0x8bdd);
1439 VA_START(parameterList, aDummyParameter);
1440 generated.FormatList(_TL("\t%-**.*fqq%$4$.*Swww%+*5Ldeeee%$2$.3srrrrr%0*xtttttt%.3Fyyyyyyy%c"), parameterList);
1441 test(generated.Length()==61);
1442 expected.Format(_TL("\t13.895%c%c%c%c%cqqebwww!!199eeee:-)rrrrr007535tttttt0.125yyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
1443 test(generated.Left(generated.Length()-1)==expected);
1444 test(generated[generated.Length()-1]==(S)0x8bdd);
1446 VA_START(parameterList, aDummyParameter);
1447 generated.FormatList(_TL("\t%-**.*fqq%.3swww%+*5Ldeeee%$7$crrrrr%0*xtttttt%.3Fyyyyyyy%$4$.*S"), parameterList);
1448 test(generated.Length()==61);
1449 expected.Format(_TL("\t13.895%c%c%c%c%cqq:-)www!!199eeee"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
1450 test(generated.Left(29)==expected);
1451 test(generated[29]==(S)0x8bdd);
1452 test(generated.Mid(29+1)==_TL("rrrrr007535tttttt0.125yyyyyyyeb"));
1454 VA_START(parameterList, aDummyParameter);
1455 generated.FormatList(_TL("\t%$4$.*Sqq%.3swww%+*5Ldeeee%$6$.3Frrrrr%0*xtttttt%$1$-**.*fyyyyyyy%c"), parameterList);
1456 test(generated.Length()==61);
1457 expected.Format(_TL("\tebqq:-)www!!199eeee0.125rrrrr007535tttttt13.895%c%c%c%c%cyyyyyyy"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
1458 test(generated.Left(generated.Length()-1)==expected);
1459 test(generated[generated.Length()-1]==(S)0x8bdd);
1461 VA_START(parameterList, aDummyParameter);
1462 generated.FormatList(_TL("\t%$7$cqq%$6$.3Fwww%$5$0*xeeee%.*Srrrrr%$3$+*5Ldtttttt%$2$.3syyyyyyy%$1$-**.*f"), parameterList);
1463 test(generated.Length()==61);
1464 test(generated.Left(1)==_TL("\t"));
1465 test(generated[1]==(S)0x8bdd);
1466 expected.Format(_TL("qq0.125www007535eeeeebrrrrr!!199tttttt:-)yyyyyyy13.895%c%c%c%c%c"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
1467 test(generated.Mid(2)==expected);
1469 VA_START(parameterList, aDummyParameter);
1470 generated.FormatList(_TL("\t%$7$cqq%$6$.3Fwww%$5$0*xeeee%$4$.*Srrrrr%$3$+*5Ldtttttt%$2$.3syyyyyyy%$1$-**.*f"), parameterList);
1471 test(generated.Length()==61);
1472 test(generated.Left(1)==_TL("\t"));
1473 test(generated[1]==(S)0x8bdd);
1474 expected.Format(_TL("qq0.125www007535eeeeebrrrrr!!199tttttt:-)yyyyyyy13.895%c%c%c%c%c"), (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac, (S)0x20ac);
1475 test(generated.Mid(2)==expected);
1478 template <class T,class S,class DESTEMPLATE>
1479 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::Test15()
1482 test.Start(_L("Replace"));
1484 test(a.MaxLength()>=9);
1487 a.Replace(3,4,b); // Replace with smaller in middle (insert and delete)
1488 test(a==_TL("abcdef"));
1489 a.Replace(1,1,b); // Replace with larger in middle (insert and delete)
1490 test(a==_TL("adefcdef"));
1491 a.Replace(0,8,_TL("")); // Replace complete string (delete)
1493 a.Replace(0,0,b); // Replace at beginning (insert)
1495 a.Replace(3,0,_TL("xyz")); // Replace at end (append)
1496 test(a==_TL("defxyz"));
1497 a.Replace(0,0,_TL("")); // Replace nothing at beginning (do nothing)
1498 test(a==_TL("defxyz"));
1499 a.Replace(6,0,_TL("")); // Replace nothing at end (do nothing)
1500 test(a==_TL("defxyz"));
1501 //a.Replace(6,1,_TL("")); // this will panic - no char after end to replace
1502 //a.Replace(0,7,_TL("")); // this will panic - aint 7 chars to replace
1506 template<class T,class S,class DESTEMPLATE>
1507 GLDEF_C void TestTBuf<T,S,DESTEMPLATE>::test_TBuf()
1508 // Test the TBuf class.
1510 test.Start(_L("All operations"));
1512 test.Next(_L("Constructors"));
1514 test.Next(_L("Additional tests"));
1516 test.Next(_L("Comparison operators"));
1518 test.Next(_L("Property access"));
1520 test.Next(_L("Fill and swap"));
1522 test.Next(_L("Conversion operators"));
1524 test.Next(_L("Comparison"));
1526 test.Next(_L("Matching"));
1528 test.Next(_L("Locating"));
1530 test.Next(_L("Copying"));
1532 test.Next(_L("Finding"));
1534 test.Next(_L("Basic like ops"));
1536 test.Next(_L("Formating"));
1538 test.Next(_L("Replacing"));
1543 LOCAL_C void testFormat()
1546 aa.Format(_L("x%- 5fx"), 6.2345678);
1547 test(aa==_L("x6.234568x"));
1548 aa.Format(_L("x%+ 5fx"), 6.2345678);
1549 test(aa==_L("x6.234568x"));
1550 aa.Format(_L("x% 5fx"), 6.2345678);
1551 test(aa==_L("x6.234568x"));
1552 aa.Format(_L("x%= 5fx"), 6.2345678);
1553 test(aa==_L("x6.234568x"));
1554 aa.Format(_L("x%- 10fx"), 6.2345);
1555 test(aa==_L("x6.234500 x"));
1556 aa.Format(_L("x%+ 10fx"), 6.2345);
1557 test(aa==_L("x 6.234500x"));
1558 aa.Format(_L("x% 10fx"), 6.2345);
1559 test(aa==_L("x 6.234500x"));
1560 aa.Format(_L("x%= 10fx"), 6.2345);
1561 test(aa==_L("x 6.234500 x"));
1562 aa.Format(_L("x%10fx"), 12345352342.545);
1563 test(aa==_L("x12,345,352,342.545000x"));
1564 aa.Format(_L("x%20.9fx"), 1.0123456789);
1565 test(aa==_L("x 1.012345679x"));
1566 aa.Format(_L("x%5.1fx"), 1.99);
1567 test(aa==_L("x 2.0x"));
1569 // Cannot do these on GCC (X86) because of "Cannot pass objects of non-POD type through '...'. Call will abort at runtime".
1570 #if !(defined(__GCC32__) && defined(__X86__))
1571 aa.Format(_L("x%- 5Fx"), TRealX(6.2345678));
1572 test(aa==_L("x6.234568x"));
1573 aa.Format(_L("x%+ 5Fx"), TRealX(6.2345678));
1574 test(aa==_L("x6.234568x"));
1575 aa.Format(_L("x% 5Fx"), TRealX(6.2345678));
1576 test(aa==_L("x6.234568x"));
1577 aa.Format(_L("x%= 5Fx"), TRealX(6.2345678));
1578 test(aa==_L("x6.234568x"));
1579 aa.Format(_L("x%- 10Fx"), TRealX(6.2345));
1580 test(aa==_L("x6.234500 x"));
1581 aa.Format(_L("x%+ 10Fx"), TRealX(6.2345));
1582 test(aa==_L("x 6.234500x"));
1583 aa.Format(_L("x% 10Fx"), TRealX(6.2345));
1584 test(aa==_L("x 6.234500x"));
1585 aa.Format(_L("x%+010Fx"), TRealX(6.2345));
1586 test(aa==_L("x006.234500x"));
1587 aa.Format(_L("x%+10Fx"), TRealX(6.2345));
1588 test(aa==_L("x 6.234500x"));
1589 aa.Format(_L("x%10Fx"), TRealX(6.2345));
1590 test(aa==_L("x 6.234500x"));
1591 aa.Format(_L("x%010Fx"), TRealX(6.2345));
1592 test(aa==_L("x006.234500x"));
1593 aa.Format(_L("x%= 10Fx"), TRealX(6.2345));
1594 test(aa==_L("x 6.234500 x"));
1595 aa.Format(_L("x%10Fx"), TRealX(12345352342.545));
1596 test(aa==_L("x12,345,352,342.545000x"));
1597 aa.Format(_L("x%20.9Fx"), TRealX(1.0123456789));
1598 test(aa==_L("x 1.012345679x"));
1599 aa.Format(_L("x%5.1Fx"), TRealX(1.99));
1600 test(aa==_L("x 2.0x"));
1603 aa.Format(_L("x%- 5ex"), 6.2345678);
1604 test(aa==_L("x6.234568E+00x"));
1605 aa.Format(_L("x%+ 5ex"), 6.2345678);
1606 test(aa==_L("x6.234568E+00x"));
1607 aa.Format(_L("x% 5ex"), 6.2345678);
1608 test(aa==_L("x6.234568E+00x"));
1609 aa.Format(_L("x%= 5ex"), 6.2345678);
1610 test(aa==_L("x6.234568E+00x"));
1611 aa.Format(_L("x%- 14ex"), 6.2345);
1612 test(aa==_L("x6.234500E+00 x"));
1613 aa.Format(_L("x%+ 14ex"), 6.2345);
1614 test(aa==_L("x 6.234500E+00x"));
1615 aa.Format(_L("x% 14ex"), 6.2345);
1616 test(aa==_L("x 6.234500E+00x"));
1617 aa.Format(_L("x%= 14ex"), 6.2345);
1618 test(aa==_L("x 6.234500E+00 x"));
1619 aa.Format(_L("x%10ex"), 12345352342.545);
1620 test(aa==_L("x1.234535E+10x"));
1621 aa.Format(_L("x%20.9ex"), 1.0123456789);
1622 test(aa==_L("x 1.012345679E+00x"));
1623 aa.Format(_L("x%5.1ex"), 1.99);
1624 test(aa==_L("x2.0E+00x"));
1628 class TO8 : public TDes8Overflow
1631 virtual void Overflow(TDes8 &aDes);
1634 void TO8::Overflow(TDes8 &aDes)
1636 aDes=_L8("OVERFLOW");
1639 class TO8L : public TDes8Overflow
1642 virtual void Overflow(TDes8 &aDes);
1645 void TO8L::Overflow(TDes8 &/*aDes*/)
1647 User::Leave(KErrOverflow);
1650 class TO16 : public TDes16Overflow
1653 virtual void Overflow(TDes16 &aDes);
1656 void TO16::Overflow(TDes16 &aDes)
1658 aDes=_L16("OVERFLOW");
1661 class TO16L : public TDes16Overflow
1664 virtual void Overflow(TDes16 &aDes);
1667 void TO16L::Overflow(TDes16 &/*aDes*/)
1669 User::Leave(KErrOverflow);
1672 void append8(TDes8 &aBuf, TDes8Overflow *aHandler, TRefByValue<const TDesC8> aFmt, ...)
1675 VA_START(list, aFmt);
1676 aBuf.AppendFormatList(aFmt, list, aHandler);
1679 void append16(TDes16 &aBuf, TDes16Overflow *aHandler, TRefByValue<const TDesC16> aFmt, ...)
1682 VA_START(list, aFmt);
1683 aBuf.AppendFormatList(aFmt, list, aHandler);
1688 test.Start(_L("Test no overflow"));
1689 TBuf8<16> buf=_L8("A ");
1690 append8(buf, NULL, _L8("Descriptor"));
1691 test(buf==_L8("A Descriptor"));
1693 test.Printf(_L("Use a non-leaving overflow handler\n"));
1694 test.Next(_L("Force overflow with no conversions"));
1696 append8(buf, &overflow, _L8("12345678901234567"));
1697 test(buf==_L8("OVERFLOW"));
1699 test.Next(_L("Force overflow with decimal conversion"));
1700 buf=_L8("A Descriptor");
1701 append8(buf, &overflow, _L8("%d"), 12345678);
1702 test(buf==_L8("OVERFLOW"));
1704 test.Printf(_L("Use a leaving overflow handler\n"));
1705 test.Next(_L("AppendFormatList with no overflow"));
1706 buf=_L8("A Descriptor");
1708 TRAPD(r, append8(buf, &overflowLeave, _L8("ONE")));
1710 test(buf==_L8("A DescriptorONE"));
1711 test.Next(_L("Force overflow with hexadecimal conversion"));
1712 buf=_L8("A Descriptor");
1713 TRAP(r, append8(buf, &overflowLeave, _L8("%08x"), 0));
1714 test(r==KErrOverflow);
1716 test.Printf(_L("Repeat tests with TBuf16\n"));
1717 test.Next(_L("Test no overflow"));
1718 TBuf16<16> buf=_L16("A ");
1719 append16(buf, NULL, _L16("Descriptor"));
1720 test(buf==_L16("A Descriptor"));
1722 test.Printf(_L("Use a non-leaving overflow handler\n"));
1723 test.Next(_L("Force overflow with no conversions"));
1725 append16(buf, &overflow, _L16("12345678901234567"));
1726 test(buf==_L16("OVERFLOW"));
1728 test.Next(_L("Force overflow with decimal conversion"));
1729 buf=_L16("A Descriptor");
1730 append16(buf, &overflow, _L16("%d"), 12345678);
1731 test(buf==_L16("OVERFLOW"));
1733 test.Printf(_L("Use a leaving overflow handler\n"));
1734 test.Next(_L("AppendFormatList with no overflow"));
1735 buf=_L16("A Descriptor");
1736 TO16L overflowLeave;
1737 TRAPD(r, append16(buf, &overflowLeave, _L16("ONE")));
1739 test(buf==_L16("A DescriptorONE"));
1740 test.Next(_L("Force overflow with hexadecimal conversion"));
1741 buf=_L16("A Descriptor");
1742 TRAP(r, append16(buf, &overflowLeave, _L16("%08x"), 0));
1743 test(r==KErrOverflow);
1748 void testIgnoreOverflow()
1750 test.Start(_L("Test no overflow"));
1751 TBuf8<16> buf=_L8("A ");
1752 append8(buf, NULL, _L8("Descriptor"));
1753 test(buf==_L8("A Descriptor"));
1755 test.Printf(_L("Use a non-leaving overflow handler\n"));
1756 test.Next(_L("Force overflow with no conversions"));
1757 TDes8IgnoreOverflow overflow;
1758 append8(buf, &overflow, _L8("12345678901234567"));
1759 test(buf==_L8("A Descriptor1234"));
1761 test.Next(_L("Force overflow with decimal conversion"));
1762 buf=_L8("A Descriptor");
1763 append8(buf, &overflow, _L8("%d"), 123456789);
1764 test(buf==_L8("A Descriptor"));
1766 //test.Printf(_L("Repeat tests with TBuf16\n"));
1767 test.Next(_L("Test no overflow"));
1768 TBuf16<17> buf2=_L16("A ");
1769 append16(buf2, NULL, _L16("Descriptor"));
1770 test(buf2==_L16("A Descriptor"));
1772 test.Printf(_L("Use a non-leaving overflow handler\n"));
1773 test.Next(_L("Force overflow with no conversions"));
1774 TDes16IgnoreOverflow overflow2;
1775 append16(buf2, &overflow2, _L16("12345678901234567"));
1776 test(buf2==_L16("A Descriptor12345"));
1778 test.Next(_L("Force overflow with decimal conversion"));
1779 buf2=_L16("A Descriptor");
1780 append16(buf2, &overflow2, _L16("%d"), 123456789);
1781 test(buf2==_L16("A Descriptor"));
1786 void testAppendFormatIgnoreOverflow()
1788 test.Start(_L("Test no overflow"));
1790 buf.AppendFormat(_L8("A Descriptor"));
1791 test(buf==_L8("A Descriptor"));
1793 test.Next(_L("Force overflow with no conversions"));
1794 TDes8IgnoreOverflow overflow;
1795 buf.AppendFormat(_L8("123456789012345679"),&overflow);
1796 test(buf==_L8("A Descriptor1234"));
1798 test.Next(_L("Force overflow with decimal conversion"));
1799 buf = _L8("Symbian OS");
1800 buf.AppendFormat(_L8("%d"), &overflow, 1234567);
1801 test(buf==_L8("Symbian OS"));
1803 test.Next(_L("Test no overflow"));
1805 buf2.AppendFormat(_L16("A Descriptor"));
1806 test(buf2==_L16("A Descriptor"));
1808 test.Next(_L("Force overflow with no conversions"));
1809 TDes16IgnoreOverflow overflow2;
1810 buf2.AppendFormat(_L16("123456789012345679"),&overflow2);
1811 test(buf2==_L16("A Descriptor1234"));
1813 test.Next(_L("Force overflow with decimal conversion"));
1814 buf2 = _L16("Symbian OS");
1815 buf2.AppendFormat(_L16("%d"), &overflow2, 1234567);
1816 test(buf2==_L16("Symbian OS"));
1823 // INC061330 AV28Crit: NTT - TInt TDesC16.FindC -method is giving strange output values
1824 // This test should pass with "ELangPrcChinese" locale.
1827 TLanguage defaultLang = User::Language();
1829 TInt err = HAL::Set(HAL::ELanguageIndex, ELangPrcChinese);
1830 test(err == KErrNone);
1832 TBuf<50> libraryName;
1834 libraryName.Format(_L("ELOCL.%02d"), ELangPrcChinese);
1837 err=UserSvr::ChangeLocale(KNullDesC);
1838 test(err==KErrNone);
1840 //Now change to chinese locale
1841 err = UserSvr::ChangeLocale(libraryName);
1842 if(err==KErrNotFound)
1844 test.Printf(_L("TEST CASE NOT RUN BECAUSE ELangPrcChinese LOCALE NOT FOUND!\n"));
1845 HAL::Set(HAL::ELanguageIndex, defaultLang);
1848 test(err == KErrNone);
1850 TLanguage lang = User::Language();
1851 test(lang == ELangPrcChinese);
1854 _LIT(KBuf, "hello");
1856 pos = KBuf().FindC(_L("a"));
1857 test(pos == KErrNotFound);
1859 pos = KBuf().FindC(_L("zzz"));
1860 test(pos == KErrNotFound);
1862 pos = KBuf().FindC(_L("."));
1863 test(pos == KErrNotFound);
1865 pos = KBuf().FindC(_L(":"));
1866 test(pos == KErrNotFound);
1868 pos = KBuf().FindC(_L("hela"));
1869 test(pos == KErrNotFound);
1872 err=UserSvr::ChangeLocale(KNullDesC);
1873 test(err==KErrNone);
1875 //Now revert to the original default english locale
1876 libraryName.Format(_L("ELOCL.%02d"), defaultLang);
1877 test(err == KErrNone);
1878 err = UserSvr::ChangeLocale(libraryName);
1879 test(err == KErrNone);
1881 lang = User::Language();
1882 test(lang == defaultLang);
1885 #pragma warning( disable : 4702) //Unreachable code
1886 #pragma warning( disable : 4710) //Function not expanded
1888 GLDEF_C TInt E32Main()
1889 // Test the TBuf type.
1893 test.Start(_L("class TBuf16<0x50>"));
1894 TestTBuf<TBuf16<0x50>,TText16,TPtrC16> c(0x50);
1897 test.Next(_L("class TBuf8<0x50>"));
1898 TestTBuf<TBuf8<0x50>,TText8,TPtrC8> b(0x50);
1901 test.Next(_L("class TBuf<0x50>"));
1902 TestTBuf<TBuf<0x50>,TText,TPtrC> a(0x50);
1905 test.Next(_L("TReal formating"));
1908 test.Next(_L("Test overflow handler"));
1911 test.Next(_L("Test ignore overflow handler"));
1912 testIgnoreOverflow();
1914 test.Next(_L("Test Format ignore overflow handler"));
1915 testAppendFormatIgnoreOverflow();
1917 test.Next(_L("INC061330"));
1925 //#pragma warning( default : 4702)
1926 //#pragma warning( default : 4710)