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_lex.cpp
16 // Test TLex and TLexMark classes.
20 // - For Unicode, non Unicode and build independent variant of TLex class
21 // - Test that string-parsing methods are present.
22 // - Test the constructors with no parameter, by a string, with an empty TLex class,
23 // non-empty TLex class is as expected.
24 // - Test assignment operator of TLex, by initializing with TLex reference, string,
25 // TBuf reference and check it is as expected.
26 // - Check that Eos, Inc, Mark, Get, Peek, UnGet, SkipSpace, SkipSpaceAndMark,
27 // SkipCharacters, TokenLength, MarkedToken methods are as expected.
28 // - Initialize Lex string, assign different values, Parse to extract signed,
29 // unsigned integer of different lengths, using specified radix and verify
30 // that the return value is KErrNone when a valid string is parsed, KErrGeneral
31 // when invalid string is parsed, KErrOverflow when converted value is greater
33 // - Refresh the contents with the system's locale settings, separate whole number from
34 // it's fractional part, change locale settings then parse a 64-bit floating point
35 // number and check that results are as expected.
36 // Platforms/Drives/Compatibility:
38 // Assumptions/Requirement/Pre-requisites:
39 // Failures and causes:
40 // Base Port information:
46 LOCAL_D RTest test(_L("T_LEX"));
58 void TLexMark8::__DbgTest(void *pTLexMark8Dump) const
60 ((TLexMark8Dump*)pTLexMark8Dump)->iPtr=iPtr;
63 void TLexMark16::__DbgTest(void *pTLexMark16Dump) const
65 ((TLexMark16Dump*)pTLexMark16Dump)->iPtr=iPtr;
85 void TLex8::__DbgTest(void* pTLex8Dump) const
87 ((TLex8Dump*)pTLex8Dump)->iNext=iNext;
88 ((TLex8Dump*)pTLex8Dump)->iBuf=iBuf;
89 ((TLex8Dump*)pTLex8Dump)->iEnd=iEnd;
90 iMark.__DbgTest(&((TLex8Dump*)pTLex8Dump)->iMark);
93 void TLex16::__DbgTest(void* pTLex16Dump) const
95 ((TLex16Dump*)pTLex16Dump)->iNext=iNext;
96 ((TLex16Dump*)pTLex16Dump)->iBuf=iBuf;
97 ((TLex16Dump*)pTLex16Dump)->iEnd=iEnd;
98 iMark.__DbgTest(&((TLex16Dump*)pTLex16Dump)->iMark);
102 LOCAL_C void TestDes(const TUint16* start1, const TUint16* start2, const TUint16* end1, const TUint16* end2)
104 TPtrC16 des1(start1, end1-start1);
105 TPtrC16 des2(start2, end2-start2);
108 LOCAL_C void TestDes(const TUint8* start1, const TUint8* start2, const TUint8* end1, const TUint8* end2)
110 TPtrC8 des1(start1, end1-start1);
111 TPtrC8 des2(start2, end2-start2);
114 LOCAL_C void TestDes(const TUint16* start, const TUint16* end, const TUint16* string)
116 TPtrC16 des1(start, end-start);
117 TPtrC16 des2(string);
120 LOCAL_C void TestDes(const TUint8* start, const TUint8* end, const TUint8* string)
122 TPtrC8 des1(start, end-start);
128 void _LL(TText8 array[], TText8 string[])
132 for(;string[index]; index++)
133 array[index]=string[index];
137 void _LL(TText16 array[], TText8 string[])
141 for(;string[index]; index++)
142 array[index]=string[index];
146 template<class TDesType, class TLexType, class TLexMarkType, class TBufType, class DumpType, class MarkDumpType, class S>
156 void TestList(TLexType* object, TUint param, ...);
160 //*********************************
161 // Test that methods are in the DLL
162 //*********************************
163 template<class TDesType, class TLexType, class TLexMarkType, class TBufType, class DumpType, class MarkDumpType, class S>
164 GLDEF_C void TestTLex<TDesType, TLexType, TLexMarkType, TBufType, DumpType, MarkDumpType, S>::Test1()
166 test.Start(_L("Constructors"));
168 _LL(&String[0], (TText8*)"hello");
169 TBufType aTBufObject;
172 TLexType c(&String[0]);
173 TLexType d(aTBufObject);
174 d.Offset(); // Avoids 'unused' warning
177 test.Next(_L("Assignment operations"));
182 test.Next(_L("Assorted"));
193 c.SkipSpaceAndMark(mark);
194 c.SkipSpaceAndMark();
198 aTBufObject=c.MarkedToken(mark);
199 aTBufObject=c.MarkedToken();
200 aTBufObject=c.NextToken();
201 aTBufObject=c.Remainder();
202 aTBufObject=c.RemainderFromMark(mark);
203 aTBufObject=c.RemainderFromMark();
205 c.MarkedOffset(mark);
208 test.Next(_L("Val"));
227 TRadix TR=(TRadix)EDecimal;
232 c.BoundedVal(TI32, TU);
233 c.BoundedVal(TU32, TR, TU);
234 c.BoundedVal(TI64, TR, TU);
236 test.Next(_L("Assign"));
238 c.Assign(&String[0]);
239 c.Assign(aTBufObject);
241 test.Next(_L("Test Dumps"));
243 mark.__DbgTest(&mDump);
251 ///////////////////////////////////////
252 // Test calling Convert() with a list
253 ///////////////////////////////////////
254 template<class TDesType, class TLexType, class TLexMarkType, class TBufType, class DumpType, class MarkDumpType, class S>
255 GLDEF_C void TestTLex<TDesType, TLexType, TLexMarkType, TBufType, DumpType, MarkDumpType, S>::TestList(TLexType *object, TUint param, ...)
261 object->Convert(b, l);
265 /////////////////////////
266 // Test the constructors
267 ////////////////////////
268 template<class TDesType, class TLexType, class TLexMarkType, class TBufType, class DumpType, class MarkDumpType, class S>
269 GLDEF_C void TestTLex<TDesType, TLexType, TLexMarkType, TBufType, DumpType, MarkDumpType, S>::Test2()
271 // Test constructors NOTE: there's no getters for iMark or iBuf
272 DumpType dump, dump2;
275 test.Start(_L("Constructors:")); // TLexx::TLexx()
276 test.Next(_L("By default"));
279 test(dump.iBuf==NULL);
281 test.Next(_L("By string")); // TLexx::TLexx(const TUintx*)
282 _LL(&String[0], (TText8*)"AB");
283 TLexType b(&String[0]);
285 TestDes(dump.iNext, dump.iEnd, &String[0]);
286 TestDes(dump.iBuf, dump.iEnd, &String[0]);
287 TestDes(dump.iMark.iPtr, dump.iEnd, &String[0]);
289 test.Next(_L("By TLex reference")); // TLexx::TLexx(const TLexx&)
290 // Test with an empty class
294 TestDes(dump.iNext, dump2.iNext, dump.iEnd, dump2.iEnd);
295 test(dump.iBuf==NULL);
296 test(dump.iBuf==dump2.iBuf);
297 TestDes(dump.iMark.iPtr, dump2.iMark.iPtr, dump.iEnd, dump2.iEnd);
299 //Test with a non empty class
300 _LL(&String[0], (TText8*)"XYZ");
301 TLexType e(&String[0]), f(e);
304 TestDes(dump.iNext, dump.iEnd, &String[0]);
305 TestDes(dump.iNext, dump2.iNext, dump.iEnd, dump2.iEnd);
306 TestDes(dump.iBuf, dump2.iBuf, dump.iEnd, dump2.iEnd);
307 TestDes(dump.iMark.iPtr, dump2.iMark.iPtr, dump.iEnd, dump2.iEnd);
309 test.Next(_L("By TBuf reference")); //TLexx::TLexx(const TBufBasex&)
310 _LL(&String[0], (TText8*)"Hello");
311 TBufType aBuf(&String[0]);
314 TestDes(dump.iNext, dump.iEnd, &String[0]);
315 TestDes(dump.iBuf, dump.iEnd, &String[0]);
316 TestDes(dump.iMark.iPtr, dump.iEnd, &String[0]);
322 //*********************************
323 // Test the = methods
324 //*********************************
325 template<class TDesType, class TLexType, class TLexMarkType, class TBufType, class DumpType, class MarkDumpType, class S>
326 GLDEF_C void TestTLex<TDesType, TLexType, TLexMarkType, TBufType, DumpType, MarkDumpType, S>::Test3()
328 DumpType dump, dump2;
331 test.Start(_L("= operators"));
332 test.Next(_L("by TLex reference")); //TLexx::operator=(const TLexx&)
333 _LL(&String[0], (TText8*)"MNO");
334 TLexType a(&String[0]), b;
338 TestDes(dump.iNext, dump2.iNext, dump.iEnd, dump2.iEnd);
339 TestDes(dump.iMark.iPtr, dump2.iMark.iPtr, dump.iEnd, dump2.iEnd);
340 TestDes(dump.iBuf, dump2.iBuf, dump.iEnd, dump2.iEnd);
342 test.Next(_L("by string")); //TLexx::operator=(const TUintx*)
344 _LL(&String[0], (TText8*)" abc");
347 TestDes(dump.iNext, dump.iEnd, &String[0]);
348 TestDes(dump.iBuf, dump.iEnd, &String[0]);
349 TestDes(dump.iMark.iPtr, dump.iEnd, &String[0]);
351 test.Next(_L("by TBuf reference")); //TLexx::operator=(const TBufx&);
352 _LL(&String[0], (TText8*)"PQ R ");
354 TBufType e(&String[0]);
357 TestDes(dump.iNext, dump.iEnd, &String[0]);
358 TestDes(dump.iBuf, dump.iEnd, &String[0]);
359 TestDes(dump.iMark.iPtr, dump.iEnd, &String[0]);
364 //*********************************
365 // Test supporting methods
366 //*********************************
367 template<class TDesType, class TLexType, class TLexMarkType, class TBufType, class DumpType, class MarkDumpType, class S>
368 GLDEF_C void TestTLex<TDesType, TLexType, TLexMarkType, TBufType, DumpType, MarkDumpType, S>::Test4()
371 DumpType dump1,dump2;
374 test.Start(_L("Supporting methods"));
375 test.Next(_L("Eos()"));
376 _LL(&String[0], (TText8*)"GGG");
377 TLexType a, b(&String[0]);
379 test(b.Eos()==FALSE);
381 test.Next(_L("Inc()")); // Inc() increments iNext
382 _LL(&String[0], (TText8*)"mno");
383 TLexType c(&String[0]);
386 TestDes(dump1.iNext, dump1.iEnd, &String[0]);
388 test((S)c.Peek()==String[1]);
390 test((S)c.Peek()==String[2]);
392 test.Next(_L("Mark()")); // Mark() sets iMark=iNext
393 _LL(&String[0], (TText8*)"pqr");
394 TLexType d(&String[0]);
399 TestDes(dump2.iMark.iPtr, dump1.iNext, dump2.iEnd, dump1.iEnd);
401 test.Next(_L("Mark(mark)")); // Mark(aMark) sets aMark=iNext
402 _LL(&String[0], (TText8*)"pqr");
403 TLexType d1(&String[0]);
406 d1.__DbgTest(&dump1);
408 dm.__DbgTest(&mDump);
409 TestDes(mDump.iPtr, dump1.iNext, dump1.iEnd, dump1.iEnd);
412 test.Next(_L("Get()")); // Get() is {TChar c(*iNext);Inc(); return(c);}
413 _LL(&String[0], (TText8*)"s");
414 TLexType e(&String[0]);
422 test.Next(_L("Peek()")); // Peek() returns *iNext
425 _LL(&String[0], (TText8*)"ab");
426 TLexType g(&String[0]);
427 test((S)g.Peek()==String[0]);
429 test.Next(_L("UnGet()")); // UnGet() is effectively if(iNext!=iBuf) iNext--;
430 _LL(&String[0], (TText8*)"abc");
431 TLexType h(&String[0]);
433 test((S)h.Peek()==String[1]);
435 test((S)h.Peek()==String[0]);
437 test.Next(_L("SkipSpace()")); // SkipSpace() is while(Peek.IsSpace()) iNext++;
438 _LL(&String[0], (TText8*)" j kl");
439 TLexType i(&String[0]);
441 test((S)i.Peek()==String[2]);
444 test((S)i.Peek()==String[5]);
446 test.Next(_L("SkipSpaceAndMark()")); // while(Peek.IsSpace()) iNext++; iMark=iNext;
447 _LL(&String[0], (TText8*)" aaa");
448 TLexType j(&String[0]);
449 j.SkipSpaceAndMark();
451 _LL(&String[0], (TText8*)"aaa");
452 TestDes(dump1.iNext, dump1.iEnd, &String[0]);
453 TestDes(dump1.iMark.iPtr, dump1.iEnd, &String[0]);
455 test.Next(_L("SkipSpaceAndMark(aMark)")); // while(Peek.IsSpace()) iNext++; iMark=iNext;
456 _LL(&String[0], (TText8*)" aaa");
457 TLexType j1(&String[0]);
459 j1.SkipSpaceAndMark(jm);
460 j1.__DbgTest(&dump1);
461 jm.__DbgTest(&mDump);
462 _LL(&String[0], (TText8*)"aaa");
463 TestDes(dump1.iNext, dump1.iEnd, &String[0]);
464 TestDes(mDump.iPtr, dump1.iEnd, &String[0]);
466 test.Next(_L("SkipCharacters()")); // Skips non whitespace characters
467 _LL(&String[0], (TText8*)"abc ");
468 TLexType k(&String[0]);
470 test((S)k.Peek()==String[3]);
472 test.Next(_L("TokenLength()")); // returns iNext-iMark
473 _LL(&String[0], (TText8*)"GGG");
474 TLexType l(&String[0]);
475 test(l.TokenLength()==0);
477 test(l.TokenLength()==1);
479 test.Next(_L("MarkedToken()")); // Extract a marked token
480 _LL(&String[0], (TText8*)"ABCD");
481 TLexType m(&String[0]);
491 _LL(&String2[0], (TText8*)"BC");
492 test(TDesType(&String2[0])==Buf);
493 _LL(&String2[0], (TText8*)"C");
494 Buf=m.MarkedToken(mm);
495 test(TDesType(&String2[0])==Buf);
501 //*********************************
503 //*********************************
504 template<class TDesType, class TLexType, class TLexMarkType, class TBufType, class DumpType, class MarkDumpType, class S>
505 GLDEF_C void TestTLex<TDesType, TLexType, TLexMarkType, TBufType, DumpType, MarkDumpType, S>::Test5()
510 test.Start(_L("Val()"));
515 test.Next(_L("Val(TInt8)"));
517 _LL(&String[0], (TText8*)"");
519 test((ret=Lex.Val(T8))==KErrGeneral);
521 _LL(&String[0], (TText8*)"abc");
523 test((ret=Lex.Val(T8))==KErrGeneral);
525 _LL(&String[0], (TText8*)"-abc-");
527 test((ret=Lex.Val(T8))==KErrGeneral);
529 _LL(&String[0], (TText8*)"+abc+");
531 test((ret=Lex.Val(T8))==KErrGeneral);
533 _LL(&String[0], (TText8*)"0000000123abc");
535 test((ret=Lex.Val(T8))==KErrNone);
538 _LL(&String[0], (TText8*)"000");
540 test((ret=Lex.Val(T8))==KErrNone);
543 _LL(&String[0], (TText8*)"+0");
545 test((ret=Lex.Val(T8))==KErrNone);
548 _LL(&String[0], (TText8*)"-0");
550 test((ret=Lex.Val(T8))==KErrNone);
553 _LL(&String[0], (TText8*)"+1 ");
555 test((ret=Lex.Val(T8))==KErrNone);
558 _LL(&String[0], (TText8*)"-1 ");
560 test((ret=Lex.Val(T8))==KErrNone);
563 _LL(&String[0], (TText8*)"127");
565 test((ret=Lex.Val(T8))==KErrNone);
568 _LL(&String[0], (TText8*)"128");
570 test((ret=Lex.Val(T8))==KErrOverflow);
572 _LL(&String[0], (TText8*)"-128");
574 test((ret=Lex.Val(T8))==KErrNone);
577 _LL(&String[0], (TText8*)"-129");
579 test((ret=Lex.Val(T8))==KErrOverflow);
585 test.Next(_L("Val(TInt16)"));
587 _LL(&String[0], (TText8*)"");
589 test((ret=Lex.Val(T16))==KErrGeneral);
591 _LL(&String[0], (TText8*)"32767");
593 test((ret=Lex.Val(T16))==KErrNone);
596 _LL(&String[0], (TText8*)"32768");
598 test((ret=Lex.Val(T16))==KErrOverflow);
600 _LL(&String[0], (TText8*)"-32768");
602 test((ret=Lex.Val(T16))==KErrNone);
605 _LL(&String[0], (TText8*)"-32769");
607 test((ret=Lex.Val(T16))==KErrOverflow);
613 test.Next(_L("Val(TInt32)"));
615 _LL(&String[0], (TText8*)"");
617 test((ret=Lex.Val(T32))==KErrGeneral);
619 _LL(&String[0], (TText8*)"2147483647");
621 test((ret=Lex.Val(T32))==KErrNone);
622 test(T32==2147483647L);
624 _LL(&String[0], (TText8*)"2147483648");
626 test((ret=Lex.Val(T32))==KErrOverflow);
628 _LL(&String[0], (TText8*)"-2147483648");
630 test((ret=Lex.Val(T32))==KErrNone);
631 test(T32==-2147483647-1); // the -1 prevents a (bug?) warning
633 _LL(&String[0], (TText8*)"-2147483649");
635 test((ret=Lex.Val(T32))==KErrOverflow);
641 test.Next(_L("Val(TInt)"));
643 _LL(&String[0], (TText8*)"");
645 test((ret=Lex.Val(T))==KErrGeneral);
647 _LL(&String[0], (TText8*)"2147483647");
649 test((ret=Lex.Val(T))==KErrNone);
650 test(T==2147483647L);
652 _LL(&String[0], (TText8*)"2147483648");
654 test((ret=Lex.Val(T))==KErrOverflow);
656 _LL(&String[0], (TText8*)"-2147483648");
658 test((ret=Lex.Val(T))==KErrNone);
659 test(T==-2147483647-1); // the -1 prevents a (bug?) warning
661 _LL(&String[0], (TText8*)"-2147483649");
663 test((ret=Lex.Val(T))==KErrOverflow);
668 test.Next(_L("Val(TInt64)"));
670 _LL(&String[0], (TText8*)"");
672 test((ret=Lex.Val(T64))==KErrGeneral);
674 _LL(&String[0], (TText8*)"2147483647");
676 test((ret=Lex.Val(T64))==KErrNone);
677 test(T64==TInt(2147483647L));
679 _LL(&String[0], (TText8*)"2147483648");
681 test((ret=Lex.Val(T64))==KErrNone);
682 test(T64==MAKE_TINT64(0,0x80000000u));
684 _LL(&String[0], (TText8*)"-2147483648");
686 test((ret=Lex.Val(T64))==KErrNone);
687 test(T64==-2147483647-1); // the -1 prevents a (bug?) warning
689 _LL(&String[0], (TText8*)"-2147483649");
691 test((ret=Lex.Val(T64))==KErrNone);
692 test(T64==MAKE_TINT64(0xffffffffu,0x7fffffffu));
694 _LL(&String[0], (TText8*)"9223372036854775807");
697 test.Printf(_L("ret=%d\n"),ret);
699 test.Printf(_L("%lx\n"),T64);
700 test(T64==MAKE_TINT64(0x7fffffffu,0xffffffffu));
702 _LL(&String[0], (TText8*)"9223372036854775808");
704 test((ret=Lex.Val(T64))==KErrOverflow);
706 _LL(&String[0], (TText8*)"-9223372036854775808");
708 test((ret=Lex.Val(T64))==KErrNone);
709 test(T64==MAKE_TINT64(0x80000000u,0x0));
711 _LL(&String[0], (TText8*)"-9223372036854775809");
713 test((ret=Lex.Val(T64))==KErrOverflow);
717 /////////////////////
718 // test.Next(_L("Val(TReal32)"));
720 // test((ret=Lex.Val(TR32))==KErrNotSupported);
726 // test.Next(_L("Val(TReal64)"));
728 // test((ret=Lex.Val(TR64))==KErrNotSupported);
731 ///////////////////////////
732 // Test Val(TUint8, TRadix)
733 ///////////////////////////
734 test.Next(_L("Val(TUint8, TRadix)"));
737 _LL(&String[0], (TText8*)"00");
739 test((ret=Lex.Val(TU8, (TRadix)EBinary))==KErrNone);
742 _LL(&String[0], (TText8*)"01");
744 test((ret=Lex.Val(TU8, (TRadix)EBinary))==KErrNone);
747 _LL(&String[0], (TText8*)"11111111");
749 test((ret=Lex.Val(TU8, (TRadix)EBinary))==KErrNone);
752 _LL(&String[0], (TText8*)"100000000");
754 test((ret=Lex.Val(TU8, (TRadix)EBinary))==KErrOverflow);
756 _LL(&String[0], (TText8*)"00");
758 test((ret=Lex.Val(TU8, (TRadix)EOctal))==KErrNone);
761 _LL(&String[0], (TText8*)"01");
763 test((ret=Lex.Val(TU8, (TRadix)EOctal))==KErrNone);
766 _LL(&String[0], (TText8*)"377");
768 test((ret=Lex.Val(TU8, (TRadix)EOctal))==KErrNone);
771 _LL(&String[0], (TText8*)"400");
773 test((ret=Lex.Val(TU8, (TRadix)EOctal))==KErrOverflow);
775 _LL(&String[0], (TText8*)"00");
777 test((ret=Lex.Val(TU8, (TRadix)EDecimal))==KErrNone);
780 _LL(&String[0], (TText8*)"01");
782 test((ret=Lex.Val(TU8, (TRadix)EDecimal))==KErrNone);
785 _LL(&String[0], (TText8*)"255");
787 test((ret=Lex.Val(TU8, (TRadix)EDecimal))==KErrNone);
790 _LL(&String[0], (TText8*)"256");
792 test((ret=Lex.Val(TU8, (TRadix)EDecimal))==KErrOverflow);
794 _LL(&String[0], (TText8*)"00");
796 test((ret=Lex.Val(TU8, (TRadix)EHex))==KErrNone);
799 _LL(&String[0], (TText8*)"01");
801 test((ret=Lex.Val(TU8, (TRadix)EHex))==KErrNone);
804 _LL(&String[0], (TText8*)"Ff");
806 test((ret=Lex.Val(TU8, (TRadix)EHex))==KErrNone);
809 _LL(&String[0], (TText8*)"100");
811 test((ret=Lex.Val(TU8, (TRadix)EHex))==KErrOverflow);
815 ////////////////////////////
816 // Test Val(TUint16, TRadix)
817 ////////////////////////////
818 test.Next(_L("Val(TUint16, TRadix)"));
821 _LL(&String[0], (TText8*)"00");
823 test((ret=Lex.Val(TU16, (TRadix)EBinary))==KErrNone);
826 _LL(&String[0], (TText8*)"01");
828 test((ret=Lex.Val(TU16, (TRadix)EBinary))==KErrNone);
831 _LL(&String[0], (TText8*)"1111111111111111");
833 test((ret=Lex.Val(TU16, (TRadix)EBinary))==KErrNone);
836 _LL(&String[0], (TText8*)"10000000000000000");
838 test((ret=Lex.Val(TU16, (TRadix)EBinary))==KErrOverflow);
840 _LL(&String[0], (TText8*)"00");
842 test((ret=Lex.Val(TU16, (TRadix)EOctal))==KErrNone);
845 _LL(&String[0], (TText8*)"01");
847 test((ret=Lex.Val(TU16, (TRadix)EOctal))==KErrNone);
850 _LL(&String[0], (TText8*)"177777");
852 test((ret=Lex.Val(TU16, (TRadix)EOctal))==KErrNone);
855 _LL(&String[0], (TText8*)"200000");
857 test((ret=Lex.Val(TU16, (TRadix)EOctal))==KErrOverflow);
859 _LL(&String[0], (TText8*)"00");
861 test((ret=Lex.Val(TU16, (TRadix)EDecimal))==KErrNone);
864 _LL(&String[0], (TText8*)"01");
866 test((ret=Lex.Val(TU16, (TRadix)EDecimal))==KErrNone);
869 _LL(&String[0], (TText8*)"65535");
871 test((ret=Lex.Val(TU16, (TRadix)EDecimal))==KErrNone);
874 _LL(&String[0], (TText8*)"65536");
876 test((ret=Lex.Val(TU16, (TRadix)EDecimal))==KErrOverflow);
878 _LL(&String[0], (TText8*)"00");
880 test((ret=Lex.Val(TU16, (TRadix)EHex))==KErrNone);
883 _LL(&String[0], (TText8*)"01");
885 test((ret=Lex.Val(TU16, (TRadix)EHex))==KErrNone);
888 _LL(&String[0], (TText8*)"ffFf");
890 test((ret=Lex.Val(TU16, (TRadix)EHex))==KErrNone);
893 _LL(&String[0], (TText8*)"10000");
895 test((ret=Lex.Val(TU16, (TRadix)EHex))==KErrOverflow);
899 ////////////////////////////
900 // Test Val(TUint32, TRadix)
901 ////////////////////////////
902 test.Next(_L("Val(TUint32, TRadix)"));
905 _LL(&String[0], (TText8*)"00");
907 test((ret=Lex.Val(TU32, (TRadix)EBinary))==KErrNone);
910 _LL(&String[0], (TText8*)"01");
912 test((ret=Lex.Val(TU32, (TRadix)EBinary))==KErrNone);
915 _LL(&String[0], (TText8*)"11111111111111111111111111111111");
917 test((ret=Lex.Val(TU32, (TRadix)EBinary))==KErrNone);
918 test(TU32==4294967295u);
920 _LL(&String[0], (TText8*)"100000000000000000000000000000000");
922 test((ret=Lex.Val(TU32, (TRadix)EBinary))==KErrOverflow);
924 _LL(&String[0], (TText8*)"00");
926 test((ret=Lex.Val(TU32, (TRadix)EOctal))==KErrNone);
929 _LL(&String[0], (TText8*)"01");
931 test((ret=Lex.Val(TU32, (TRadix)EOctal))==KErrNone);
934 _LL(&String[0], (TText8*)"37777777777");
936 test((ret=Lex.Val(TU32, (TRadix)EOctal))==KErrNone);
937 test(TU32==4294967295u);
939 _LL(&String[0], (TText8*)"40000000000");
941 test((ret=Lex.Val(TU32, (TRadix)EOctal))==KErrOverflow);
943 _LL(&String[0], (TText8*)"00");
945 test((ret=Lex.Val(TU32, (TRadix)EDecimal))==KErrNone);
948 _LL(&String[0], (TText8*)"01");
950 test((ret=Lex.Val(TU32, (TRadix)EDecimal))==KErrNone);
953 _LL(&String[0], (TText8*)"4294967295");
955 test((ret=Lex.Val(TU32, (TRadix)EDecimal))==KErrNone);
956 test(TU32==4294967295u);
958 _LL(&String[0], (TText8*)"4294967296");
960 test((ret=Lex.Val(TU32, (TRadix)EDecimal))==KErrOverflow);
962 _LL(&String[0], (TText8*)"00");
964 test((ret=Lex.Val(TU32, (TRadix)EHex))==KErrNone);
967 _LL(&String[0], (TText8*)"01");
969 test((ret=Lex.Val(TU32, (TRadix)EHex))==KErrNone);
972 _LL(&String[0], (TText8*)"FFFFFFFF");
974 test((ret=Lex.Val(TU32, (TRadix)EHex))==KErrNone);
975 test(TU32==4294967295u);
977 _LL(&String[0], (TText8*)"100000000");
979 test((ret=Lex.Val(TU32, (TRadix)EHex))==KErrOverflow);
981 ///////////////////////////////////
982 // Test Val(TInt64, TRadix)
983 ///////////////////////////////////
984 test.Next(_L("Val(TInt64,TRadix)"));
987 _LL(&String[0], (TText8*)"00");
989 test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrNone);
992 _LL(&String[0], (TText8*)"01");
994 test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrNone);
997 _LL(&String[0], (TText8*)"11111111111111111111111111111111");
999 test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrNone);
1000 test(TI64==TInt64(0xffffffffu));
1002 _LL(&String[0], (TText8*)"100000000000000000000000000000000");
1004 test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrNone);
1005 test(TI64==MAKE_TINT64(0x1,0x0));
1007 _LL(&String[0], (TText8*)"1111111111111111111111111111111111111111111111111111111111111111");
1009 test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrNone);
1010 test(TI64==MAKE_TINT64(0xffffffffu,0xffffffffu));
1012 _LL(&String[0], (TText8*)"10000000000000000000000000000000000000000000000000000000000000000");
1014 test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrOverflow);
1016 _LL(&String[0], (TText8*)"00");
1018 test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrNone);
1021 _LL(&String[0], (TText8*)"01");
1023 test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrNone);
1026 _LL(&String[0], (TText8*)"37777777777");
1028 test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrNone);
1029 test(TI64==TInt64(0xffffffffu));
1031 _LL(&String[0], (TText8*)"40000000000");
1033 test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrNone);
1034 test(TI64==MAKE_TINT64(0x1,0x0));
1036 _LL(&String[0], (TText8*)"1777777777777777777777");
1038 test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrNone);
1039 test(TI64==MAKE_TINT64(0xffffffffu,0xffffffffu));
1041 _LL(&String[0], (TText8*)"2000000000000000000000");
1043 test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrOverflow);
1045 _LL(&String[0], (TText8*)"00");
1047 test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrNone);
1050 _LL(&String[0], (TText8*)"00");
1051 Lex=&String[0]; //************** iNext is set to "" by Val
1052 test((ret=Lex.Val(TI64))==KErrNone);
1055 _LL(&String[0], (TText8*)"01");
1057 test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrNone);
1059 _LL(&String[0], (TText8*)"01");
1061 test((ret=Lex.Val(TI64))==KErrNone);
1064 _LL(&String[0], (TText8*)"4294967295");
1066 test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrNone);
1067 test(TI64==TInt64(0xffffffffu));
1068 _LL(&String[0], (TText8*)"4294967295");
1070 test((ret=Lex.Val(TI64))==KErrNone);
1071 test(TI64==TInt64(0xffffffffu));
1073 _LL(&String[0], (TText8*)"4294967296");
1075 test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrNone);
1076 test(TI64==MAKE_TINT64(1,0));
1077 _LL(&String[0], (TText8*)"4294967296");
1079 test((ret=Lex.Val(TI64))==KErrNone);
1080 test(TI64==MAKE_TINT64(1,0));
1082 _LL(&String[0], (TText8*)"18446744073709551615");
1084 test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrNone);
1085 test(TI64==MAKE_TINT64(0xffffffffu,0xffffffffu));
1086 _LL(&String[0], (TText8*)"18446744073709551616");
1088 test((ret=Lex.Val(TI64))==KErrOverflow);
1090 _LL(&String[0], (TText8*)"-1");
1092 test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrGeneral);
1094 _LL(&String[0], (TText8*)"00");
1096 test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrNone);
1099 _LL(&String[0], (TText8*)"01");
1101 test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrNone);
1104 _LL(&String[0], (TText8*)"FFFFFFFF");
1106 test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrNone);
1107 test(TI64==TInt64(0xffffffffu));
1109 _LL(&String[0], (TText8*)"100000000");
1111 test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrNone);
1112 test(TI64==MAKE_TINT64(1,0));
1114 _LL(&String[0], (TText8*)"FFFFFFFFffffffff");
1116 test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrNone);
1117 test(TI64==MAKE_TINT64(0xffffffffu,0xffffffffu));
1119 _LL(&String[0], (TText8*)"10000000000000000");
1121 test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrOverflow);
1124 ///////////////////////////////////
1125 // Test Val(TUint, TRadix=(TRadix)EDecimal)
1126 ///////////////////////////////////
1127 test.Next(_L("Val(TUint, TRadix=(TRadix)EDecimal)"));
1130 _LL(&String[0], (TText8*)"00");
1132 test((ret=Lex.Val(TU, (TRadix)EBinary))==KErrNone);
1135 _LL(&String[0], (TText8*)"01");
1137 test((ret=Lex.Val(TU, (TRadix)EBinary))==KErrNone);
1140 _LL(&String[0], (TText8*)"11111111111111111111111111111111");
1142 test((ret=Lex.Val(TU, (TRadix)EBinary))==KErrNone);
1143 test(TU==4294967295u);
1145 _LL(&String[0], (TText8*)"100000000000000000000000000000000");
1147 test((ret=Lex.Val(TU, (TRadix)EBinary))==KErrOverflow);
1149 _LL(&String[0], (TText8*)"00");
1151 test((ret=Lex.Val(TU, (TRadix)EOctal))==KErrNone);
1154 _LL(&String[0], (TText8*)"01");
1156 test((ret=Lex.Val(TU, (TRadix)EOctal))==KErrNone);
1159 _LL(&String[0], (TText8*)"37777777777");
1161 test((ret=Lex.Val(TU, (TRadix)EOctal))==KErrNone);
1162 test(TU==4294967295u);
1164 _LL(&String[0], (TText8*)"40000000000");
1166 test((ret=Lex.Val(TU, (TRadix)EOctal))==KErrOverflow);
1168 _LL(&String[0], (TText8*)"00");
1170 test((ret=Lex.Val(TU, (TRadix)EDecimal))==KErrNone);
1173 _LL(&String[0], (TText8*)"00");
1174 Lex=&String[0]; //************** iNext is set to "" by Val
1175 test((ret=Lex.Val(TU))==KErrNone);
1178 _LL(&String[0], (TText8*)"01");
1180 test((ret=Lex.Val(TU, (TRadix)EDecimal))==KErrNone);
1182 _LL(&String[0], (TText8*)"01");
1184 test((ret=Lex.Val(TU))==KErrNone);
1187 _LL(&String[0], (TText8*)"4294967295");
1189 test((ret=Lex.Val(TU, (TRadix)EDecimal))==KErrNone);
1190 test(TU==4294967295u);
1191 _LL(&String[0], (TText8*)"4294967295");
1193 test((ret=Lex.Val(TU))==KErrNone);
1194 test(TU==4294967295u);
1196 _LL(&String[0], (TText8*)"4294967296");
1198 test((ret=Lex.Val(TU, (TRadix)EDecimal))==KErrOverflow);
1199 _LL(&String[0], (TText8*)"4294967296");
1201 test((ret=Lex.Val(TU))==KErrOverflow);
1203 _LL(&String[0], (TText8*)"00");
1205 test((ret=Lex.Val(TU, (TRadix)EHex))==KErrNone);
1208 _LL(&String[0], (TText8*)"01");
1210 test((ret=Lex.Val(TU, (TRadix)EHex))==KErrNone);
1213 _LL(&String[0], (TText8*)"FFFFFFFF");
1215 test((ret=Lex.Val(TU, (TRadix)EHex))==KErrNone);
1216 test(TU==4294967295u);
1218 _LL(&String[0], (TText8*)"100000000");
1220 test((ret=Lex.Val(TU, (TRadix)EHex))==KErrOverflow);
1223 /////////////////////////////////
1224 // Test Val(TInt32, TUint aLimit)
1225 /////////////////////////////////
1226 // This is called by several of the other Val methods and so has been indirectly tested already
1227 test.Next(_L("Val(TInt32, TUint aLimit"));
1229 _LL(&String[0], (TText8*)"1000");
1231 test((ret=Lex.BoundedVal(T32,1000))==KErrNone);
1234 _LL(&String[0], (TText8*)"1001");
1236 test((ret=Lex.BoundedVal(T32, 1000))==KErrOverflow);
1238 _LL(&String[0], (TText8*)"-1000");
1240 test((ret=Lex.BoundedVal(T32, 1000))==KErrNone);
1243 _LL(&String[0], (TText8*)"-1001");
1245 test((ret=Lex.BoundedVal(T32, 1000))==KErrNone);
1248 _LL(&String[0], (TText8*)"-1002");
1250 test((ret=Lex.BoundedVal(T32, 1000))==KErrOverflow);
1252 _LL(&String[0], (TText8*)"0");
1254 test((ret=Lex.BoundedVal(T32, 0))==KErrNone);
1257 _LL(&String[0], (TText8*)"1");
1259 test((ret=Lex.BoundedVal(T32, 0))==KErrOverflow);
1262 /////////////////////////////////////////////////
1263 // Test Val(TUInt32, TRadix aRadix, TUint aLimit)
1264 ////////////////////////////////////////////////
1265 // This is called by several of the other Val methods and so has been indirectly tested already
1266 test.Next(_L("Val(TUInt32, TRadix, TUint)"));
1268 // Test bug found during previous testing
1269 _LL(&String[0], (TText8*)"10");
1271 test((ret=Lex.BoundedVal(TU32, (TRadix)EDecimal, 10))==KErrNone);
1274 _LL(&String[0], (TText8*)"11");
1276 test((ret=Lex.BoundedVal(TU32, (TRadix)EDecimal, 10))==KErrOverflow);
1278 _LL(&String[0], (TText8*)"19");
1280 test((ret=Lex.BoundedVal(TU32, (TRadix)EDecimal, 10))==KErrOverflow);
1282 _LL(&String[0], (TText8*)"20");
1284 test((ret=Lex.BoundedVal(TU32, (TRadix)EDecimal, 10))==KErrOverflow);
1286 /////////////////////////////////////////////////
1287 // Test Val(TInt64, TRadix aRadix, TInt64 aLimit)
1288 ////////////////////////////////////////////////
1289 test.Next(_L("Val(TInt64, TRadix, TInt64)"));
1291 _LL(&String[0], (TText8*)"10");
1293 test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, 10))==KErrNone);
1294 test(TI64==TInt64(10));
1296 _LL(&String[0], (TText8*)"11");
1298 test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, 10))==KErrOverflow);
1300 _LL(&String[0], (TText8*)"19");
1302 test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, 10))==KErrOverflow);
1304 _LL(&String[0], (TText8*)"20");
1306 test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, 10))==KErrOverflow);
1308 _LL(&String[0], (TText8*)"34532739886900");
1310 test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrNone);
1311 test(TI64==MAKE_TINT64(0x1f68u,0x47b1af34u));
1313 _LL(&String[0], (TText8*)"34532739886901");
1315 test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow);
1317 _LL(&String[0], (TText8*)"74532739886901");
1319 test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow);
1321 _LL(&String[0], (TText8*)"6901");
1323 test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrNone);
1324 test(TI64==TInt64(6901));
1326 _LL(&String[0], (TText8*)"1f6847b1af34");
1328 test((ret=Lex.BoundedVal(TI64, (TRadix)EHex, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrNone);
1329 test(TI64==MAKE_TINT64(0x1f68u,0x47b1af34u));
1331 _LL(&String[0], (TText8*)"1f6847b1af35");
1333 test((ret=Lex.BoundedVal(TI64, (TRadix)EHex, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow);
1335 _LL(&String[0], (TText8*)"1f6847b1af340");
1337 test((ret=Lex.BoundedVal(TI64, (TRadix)EHex, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow);
1339 _LL(&String[0], (TText8*)"1e82791aed35");
1341 test((ret=Lex.BoundedVal(TI64, (TRadix)EHex, TInt64(0x56fba45u)))==KErrOverflow);
1343 /////////////////////////////////////////////////
1344 // Test Val(TInt64, TInt64 aLimit)
1345 ////////////////////////////////////////////////
1346 test.Next(_L("Val(TInt64, TInt64)"));
1348 _LL(&String[0], (TText8*)"10");
1350 test((ret=Lex.BoundedVal(TI64, 10))==KErrNone);
1351 test(TI64==TInt64(10));
1353 _LL(&String[0], (TText8*)"11");
1355 test((ret=Lex.BoundedVal(TI64, 10))==KErrOverflow);
1357 _LL(&String[0], (TText8*)"19");
1359 test((ret=Lex.BoundedVal(TI64, 10))==KErrOverflow);
1361 _LL(&String[0], (TText8*)"20");
1363 test((ret=Lex.BoundedVal(TI64, 10))==KErrOverflow);
1365 _LL(&String[0], (TText8*)"34532739886900");
1367 test((ret=Lex.BoundedVal(TI64, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrNone);
1368 test(TI64==MAKE_TINT64(0x1f68u,0x47b1af34u));
1370 _LL(&String[0], (TText8*)"34532739886901");
1372 test((ret=Lex.BoundedVal(TI64, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow);
1374 _LL(&String[0], (TText8*)"74532739886901");
1376 test((ret=Lex.BoundedVal(TI64, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow);
1378 _LL(&String[0], (TText8*)"6901");
1380 test((ret=Lex.BoundedVal(TI64, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrNone);
1381 test(TI64==TInt64(6901));
1399 loc.SetDecimalSeparator('.');
1446 loc.SetDecimalSeparator(',');
1496 #pragma warning( disable : 4705 ) // statement has no effect
1497 GLDEF_C TInt E32Main()
1502 test.Start(_L("********* TLEX **********"));
1503 #if defined(_UNICODE)
1504 TestTLex<TPtrC, TLex, TLexMark, TBuf<0x40>, TLex16Dump, TLexMark16Dump, TText> T;
1506 TestTLex<TPtrC, TLex, TLexMark, TBuf<0x40>, TLex8Dump, TLexMark8Dump, TText> T;
1508 test.Next(_L("TText 1"));
1510 test.Next(_L("TText 2"));
1512 test.Next(_L("TText 3"));
1514 test.Next(_L("TText 4"));
1516 test.Next(_L("TText 5"));
1519 TestTLex<TPtrC8, TLex8, TLexMark8, TBuf8<0x40>, TLex8Dump, TLexMark8Dump, TText8> T8;
1520 test.Next(_L("TText8 1"));
1522 test.Next(_L("TText8 2"));
1524 test.Next(_L("TText8 3"));
1526 test.Next(_L("TText8 4"));
1528 test.Next(_L("TText8 5"));
1531 TestTLex<TPtrC16, TLex16, TLexMark16, TBuf16<0x40>, TLex16Dump, TLexMark16Dump, TText16> T16;
1532 test.Next(_L("TText16 1"));
1534 test.Next(_L("TText16 2"));
1536 test.Next(_L("TText16 3"));
1538 test.Next(_L("TText16 4"));
1540 test.Next(_L("TText16 5"));
1543 test.Next(_L("Test TLex in different locales"));
1549 #pragma warning( default : 4705 )