sl@0: // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\buffer\t_lex.cpp sl@0: // Overview: sl@0: // Test TLex and TLexMark classes. sl@0: // API Information: sl@0: // TLex, TLexMark. sl@0: // Details: sl@0: // - For Unicode, non Unicode and build independent variant of TLex class sl@0: // - Test that string-parsing methods are present. sl@0: // - Test the constructors with no parameter, by a string, with an empty TLex class, sl@0: // non-empty TLex class is as expected. sl@0: // - Test assignment operator of TLex, by initializing with TLex reference, string, sl@0: // TBuf reference and check it is as expected. sl@0: // - Check that Eos, Inc, Mark, Get, Peek, UnGet, SkipSpace, SkipSpaceAndMark, sl@0: // SkipCharacters, TokenLength, MarkedToken methods are as expected. sl@0: // - Initialize Lex string, assign different values, Parse to extract signed, sl@0: // unsigned integer of different lengths, using specified radix and verify sl@0: // that the return value is KErrNone when a valid string is parsed, KErrGeneral sl@0: // when invalid string is parsed, KErrOverflow when converted value is greater sl@0: // than the limit. sl@0: // - Refresh the contents with the system's locale settings, separate whole number from sl@0: // it's fractional part, change locale settings then parse a 64-bit floating point sl@0: // number and check that results are as expected. sl@0: // Platforms/Drives/Compatibility: sl@0: // All sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: sl@0: LOCAL_D RTest test(_L("T_LEX")); sl@0: sl@0: struct TLexMark8Dump sl@0: { sl@0: const TUint8* iPtr; sl@0: }; sl@0: sl@0: struct TLexMark16Dump sl@0: { sl@0: const TUint16* iPtr; sl@0: }; sl@0: sl@0: void TLexMark8::__DbgTest(void *pTLexMark8Dump) const sl@0: { sl@0: ((TLexMark8Dump*)pTLexMark8Dump)->iPtr=iPtr; sl@0: } sl@0: sl@0: void TLexMark16::__DbgTest(void *pTLexMark16Dump) const sl@0: { sl@0: ((TLexMark16Dump*)pTLexMark16Dump)->iPtr=iPtr; sl@0: } sl@0: sl@0: struct TLex8Dump sl@0: { sl@0: const TUint8* iNext; sl@0: const TUint8* iBuf; sl@0: const TUint8* iEnd; sl@0: TLexMark8Dump iMark; sl@0: }; sl@0: sl@0: struct TLex16Dump sl@0: { sl@0: const TUint16* iNext; sl@0: const TUint16* iBuf; sl@0: const TUint16* iEnd; sl@0: TLexMark16Dump iMark; sl@0: }; sl@0: sl@0: sl@0: void TLex8::__DbgTest(void* pTLex8Dump) const sl@0: { sl@0: ((TLex8Dump*)pTLex8Dump)->iNext=iNext; sl@0: ((TLex8Dump*)pTLex8Dump)->iBuf=iBuf; sl@0: ((TLex8Dump*)pTLex8Dump)->iEnd=iEnd; sl@0: iMark.__DbgTest(&((TLex8Dump*)pTLex8Dump)->iMark); sl@0: } sl@0: sl@0: void TLex16::__DbgTest(void* pTLex16Dump) const sl@0: { sl@0: ((TLex16Dump*)pTLex16Dump)->iNext=iNext; sl@0: ((TLex16Dump*)pTLex16Dump)->iBuf=iBuf; sl@0: ((TLex16Dump*)pTLex16Dump)->iEnd=iEnd; sl@0: iMark.__DbgTest(&((TLex16Dump*)pTLex16Dump)->iMark); sl@0: } sl@0: sl@0: sl@0: LOCAL_C void TestDes(const TUint16* start1, const TUint16* start2, const TUint16* end1, const TUint16* end2) sl@0: { sl@0: TPtrC16 des1(start1, end1-start1); sl@0: TPtrC16 des2(start2, end2-start2); sl@0: test(des1==des2); sl@0: } sl@0: LOCAL_C void TestDes(const TUint8* start1, const TUint8* start2, const TUint8* end1, const TUint8* end2) sl@0: { sl@0: TPtrC8 des1(start1, end1-start1); sl@0: TPtrC8 des2(start2, end2-start2); sl@0: test(des1==des2); sl@0: } sl@0: LOCAL_C void TestDes(const TUint16* start, const TUint16* end, const TUint16* string) sl@0: { sl@0: TPtrC16 des1(start, end-start); sl@0: TPtrC16 des2(string); sl@0: test(des1==des2); sl@0: } sl@0: LOCAL_C void TestDes(const TUint8* start, const TUint8* end, const TUint8* string) sl@0: { sl@0: TPtrC8 des1(start, end-start); sl@0: TPtrC8 des2(string); sl@0: test(des1==des2); sl@0: } sl@0: sl@0: sl@0: void _LL(TText8 array[], TText8 string[]) sl@0: { sl@0: sl@0: TInt index=0; sl@0: for(;string[index]; index++) sl@0: array[index]=string[index]; sl@0: array[index]='\0'; sl@0: } sl@0: sl@0: void _LL(TText16 array[], TText8 string[]) sl@0: { sl@0: sl@0: TInt index=0; sl@0: for(;string[index]; index++) sl@0: array[index]=string[index]; sl@0: array[index]='\0'; sl@0: } sl@0: sl@0: template sl@0: class TestTLex sl@0: { sl@0: public: sl@0: void Test1(); sl@0: void Test2(); sl@0: void Test3(); sl@0: void Test4(); sl@0: void Test5(); sl@0: protected: sl@0: void TestList(TLexType* object, TUint param, ...); sl@0: }; sl@0: sl@0: sl@0: //********************************* sl@0: // Test that methods are in the DLL sl@0: //********************************* sl@0: template sl@0: GLDEF_C void TestTLex::Test1() sl@0: { sl@0: test.Start(_L("Constructors")); sl@0: S String[100]; sl@0: _LL(&String[0], (TText8*)"hello"); sl@0: TBufType aTBufObject; sl@0: TLexType a; sl@0: TLexType b(a); sl@0: TLexType c(&String[0]); sl@0: TLexType d(aTBufObject); sl@0: d.Offset(); // Avoids 'unused' warning sl@0: TLexMarkType mark; sl@0: sl@0: test.Next(_L("Assignment operations")); sl@0: a=b; sl@0: a=&String[0]; sl@0: a=aTBufObject; sl@0: sl@0: test.Next(_L("Assorted")); sl@0: c.Eos(); sl@0: c.Mark(mark); sl@0: c.Mark(); sl@0: c.Inc(); sl@0: c.Get(); sl@0: (S)c.Peek(); sl@0: c.UnGet(); sl@0: c.UnGetToMark(mark); sl@0: c.UnGetToMark(); sl@0: c.SkipSpace(); sl@0: c.SkipSpaceAndMark(mark); sl@0: c.SkipSpaceAndMark(); sl@0: c.SkipCharacters(); sl@0: c.TokenLength(mark); sl@0: c.TokenLength(); sl@0: aTBufObject=c.MarkedToken(mark); sl@0: aTBufObject=c.MarkedToken(); sl@0: aTBufObject=c.NextToken(); sl@0: aTBufObject=c.Remainder(); sl@0: aTBufObject=c.RemainderFromMark(mark); sl@0: aTBufObject=c.RemainderFromMark(); sl@0: c.Offset(); sl@0: c.MarkedOffset(mark); sl@0: c.MarkedOffset(); sl@0: sl@0: test.Next(_L("Val")); sl@0: TInt TI=1; sl@0: c.Val(TI); sl@0: TInt8 TI8='a'; sl@0: c.Val(TI8); sl@0: TInt16 TI16=1; sl@0: c.Val(TI16); sl@0: TInt32 TI32=1; sl@0: c.Val(TI32); sl@0: TInt64 TI64=1; sl@0: c.Val(TI64); sl@0: TUint TU=1; sl@0: c.Val(TU); sl@0: TReal32 TR32=1.0F; sl@0: c.Val(TR32); sl@0: TReal64 TR64=1.0; sl@0: c.Val(TR64); sl@0: TUint8 TU8='a'; sl@0: TUint32 TU32=1; sl@0: TRadix TR=(TRadix)EDecimal; sl@0: TUint16 TU16=1; sl@0: sl@0: c.Val(TU8, TR); sl@0: c.Val(TU16, TR); sl@0: c.BoundedVal(TI32, TU); sl@0: c.BoundedVal(TU32, TR, TU); sl@0: c.BoundedVal(TI64, TR, TU); sl@0: sl@0: test.Next(_L("Assign")); sl@0: c.Assign(b); sl@0: c.Assign(&String[0]); sl@0: c.Assign(aTBufObject); sl@0: sl@0: test.Next(_L("Test Dumps")); sl@0: MarkDumpType mDump; sl@0: mark.__DbgTest(&mDump); sl@0: sl@0: DumpType dump; sl@0: c.__DbgTest(&dump); sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: /////////////////////////////////////// sl@0: // Test calling Convert() with a list sl@0: /////////////////////////////////////// sl@0: template sl@0: GLDEF_C void TestTLex::TestList(TLexType *object, TUint param, ...) sl@0: { sl@0: VA_LIST l; sl@0: TBufType b; sl@0: sl@0: VA_START(l, param); sl@0: object->Convert(b, l); sl@0: } sl@0: sl@0: sl@0: ///////////////////////// sl@0: // Test the constructors sl@0: //////////////////////// sl@0: template sl@0: GLDEF_C void TestTLex::Test2() sl@0: { sl@0: // Test constructors NOTE: there's no getters for iMark or iBuf sl@0: DumpType dump, dump2; sl@0: S String[40]; sl@0: sl@0: test.Start(_L("Constructors:")); // TLexx::TLexx() sl@0: test.Next(_L("By default")); sl@0: TLexType a; sl@0: a.__DbgTest(&dump); sl@0: test(dump.iBuf==NULL); sl@0: sl@0: test.Next(_L("By string")); // TLexx::TLexx(const TUintx*) sl@0: _LL(&String[0], (TText8*)"AB"); sl@0: TLexType b(&String[0]); sl@0: b.__DbgTest(&dump); sl@0: TestDes(dump.iNext, dump.iEnd, &String[0]); sl@0: TestDes(dump.iBuf, dump.iEnd, &String[0]); sl@0: TestDes(dump.iMark.iPtr, dump.iEnd, &String[0]); sl@0: sl@0: test.Next(_L("By TLex reference")); // TLexx::TLexx(const TLexx&) sl@0: // Test with an empty class sl@0: TLexType c, d(c); sl@0: c.__DbgTest(&dump); sl@0: d.__DbgTest(&dump2); sl@0: TestDes(dump.iNext, dump2.iNext, dump.iEnd, dump2.iEnd); sl@0: test(dump.iBuf==NULL); sl@0: test(dump.iBuf==dump2.iBuf); sl@0: TestDes(dump.iMark.iPtr, dump2.iMark.iPtr, dump.iEnd, dump2.iEnd); sl@0: sl@0: //Test with a non empty class sl@0: _LL(&String[0], (TText8*)"XYZ"); sl@0: TLexType e(&String[0]), f(e); sl@0: e.__DbgTest(&dump); sl@0: f.__DbgTest(&dump2); sl@0: TestDes(dump.iNext, dump.iEnd, &String[0]); sl@0: TestDes(dump.iNext, dump2.iNext, dump.iEnd, dump2.iEnd); sl@0: TestDes(dump.iBuf, dump2.iBuf, dump.iEnd, dump2.iEnd); sl@0: TestDes(dump.iMark.iPtr, dump2.iMark.iPtr, dump.iEnd, dump2.iEnd); sl@0: sl@0: test.Next(_L("By TBuf reference")); //TLexx::TLexx(const TBufBasex&) sl@0: _LL(&String[0], (TText8*)"Hello"); sl@0: TBufType aBuf(&String[0]); sl@0: TLexType g(aBuf); sl@0: g.__DbgTest(&dump); sl@0: TestDes(dump.iNext, dump.iEnd, &String[0]); sl@0: TestDes(dump.iBuf, dump.iEnd, &String[0]); sl@0: TestDes(dump.iMark.iPtr, dump.iEnd, &String[0]); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: //********************************* sl@0: // Test the = methods sl@0: //********************************* sl@0: template sl@0: GLDEF_C void TestTLex::Test3() sl@0: { sl@0: DumpType dump, dump2; sl@0: S String[40]; sl@0: sl@0: test.Start(_L("= operators")); sl@0: test.Next(_L("by TLex reference")); //TLexx::operator=(const TLexx&) sl@0: _LL(&String[0], (TText8*)"MNO"); sl@0: TLexType a(&String[0]), b; sl@0: b=a; sl@0: a.__DbgTest(&dump); sl@0: b.__DbgTest(&dump2); sl@0: TestDes(dump.iNext, dump2.iNext, dump.iEnd, dump2.iEnd); sl@0: TestDes(dump.iMark.iPtr, dump2.iMark.iPtr, dump.iEnd, dump2.iEnd); sl@0: TestDes(dump.iBuf, dump2.iBuf, dump.iEnd, dump2.iEnd); sl@0: sl@0: test.Next(_L("by string")); //TLexx::operator=(const TUintx*) sl@0: TLexType c; sl@0: _LL(&String[0], (TText8*)" abc"); sl@0: c=&String[0]; sl@0: c.__DbgTest(&dump); sl@0: TestDes(dump.iNext, dump.iEnd, &String[0]); sl@0: TestDes(dump.iBuf, dump.iEnd, &String[0]); sl@0: TestDes(dump.iMark.iPtr, dump.iEnd, &String[0]); sl@0: sl@0: test.Next(_L("by TBuf reference")); //TLexx::operator=(const TBufx&); sl@0: _LL(&String[0], (TText8*)"PQ R "); sl@0: TLexType d; sl@0: TBufType e(&String[0]); sl@0: d=e; sl@0: d.__DbgTest(&dump); sl@0: TestDes(dump.iNext, dump.iEnd, &String[0]); sl@0: TestDes(dump.iBuf, dump.iEnd, &String[0]); sl@0: TestDes(dump.iMark.iPtr, dump.iEnd, &String[0]); sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: //********************************* sl@0: // Test supporting methods sl@0: //********************************* sl@0: template sl@0: GLDEF_C void TestTLex::Test4() sl@0: { sl@0: S String[40]; sl@0: DumpType dump1,dump2; sl@0: MarkDumpType mDump; sl@0: sl@0: test.Start(_L("Supporting methods")); sl@0: test.Next(_L("Eos()")); sl@0: _LL(&String[0], (TText8*)"GGG"); sl@0: TLexType a, b(&String[0]); sl@0: test(a.Eos()==TRUE); sl@0: test(b.Eos()==FALSE); sl@0: sl@0: test.Next(_L("Inc()")); // Inc() increments iNext sl@0: _LL(&String[0], (TText8*)"mno"); sl@0: TLexType c(&String[0]); sl@0: c.__DbgTest(&dump1); sl@0: sl@0: TestDes(dump1.iNext, dump1.iEnd, &String[0]); sl@0: c.Inc(); sl@0: test((S)c.Peek()==String[1]); sl@0: c.Inc(); sl@0: test((S)c.Peek()==String[2]); sl@0: sl@0: test.Next(_L("Mark()")); // Mark() sets iMark=iNext sl@0: _LL(&String[0], (TText8*)"pqr"); sl@0: TLexType d(&String[0]); sl@0: d.Inc(); sl@0: d.__DbgTest(&dump1); sl@0: d.Mark(); sl@0: d.__DbgTest(&dump2); sl@0: TestDes(dump2.iMark.iPtr, dump1.iNext, dump2.iEnd, dump1.iEnd); sl@0: sl@0: test.Next(_L("Mark(mark)")); // Mark(aMark) sets aMark=iNext sl@0: _LL(&String[0], (TText8*)"pqr"); sl@0: TLexType d1(&String[0]); sl@0: TLexMarkType dm; sl@0: d1.Inc(); sl@0: d1.__DbgTest(&dump1); sl@0: d1.Mark(dm); sl@0: dm.__DbgTest(&mDump); sl@0: TestDes(mDump.iPtr, dump1.iNext, dump1.iEnd, dump1.iEnd); sl@0: sl@0: sl@0: test.Next(_L("Get()")); // Get() is {TChar c(*iNext);Inc(); return(c);} sl@0: _LL(&String[0], (TText8*)"s"); sl@0: TLexType e(&String[0]); sl@0: TChar temp=e.Get(); sl@0: test(temp=='s'); sl@0: e.Inc(); sl@0: temp=e.Get(); sl@0: test(temp==0); sl@0: sl@0: sl@0: test.Next(_L("Peek()")); // Peek() returns *iNext sl@0: TLexType f; sl@0: test(f.Peek()==0); sl@0: _LL(&String[0], (TText8*)"ab"); sl@0: TLexType g(&String[0]); sl@0: test((S)g.Peek()==String[0]); sl@0: sl@0: test.Next(_L("UnGet()")); // UnGet() is effectively if(iNext!=iBuf) iNext--; sl@0: _LL(&String[0], (TText8*)"abc"); sl@0: TLexType h(&String[0]); sl@0: h.Inc(); sl@0: test((S)h.Peek()==String[1]); sl@0: h.UnGet(); sl@0: test((S)h.Peek()==String[0]); sl@0: sl@0: test.Next(_L("SkipSpace()")); // SkipSpace() is while(Peek.IsSpace()) iNext++; sl@0: _LL(&String[0], (TText8*)" j kl"); sl@0: TLexType i(&String[0]); sl@0: i.SkipSpace(); sl@0: test((S)i.Peek()==String[2]); sl@0: i.Inc(); sl@0: i.SkipSpace(); sl@0: test((S)i.Peek()==String[5]); sl@0: sl@0: test.Next(_L("SkipSpaceAndMark()")); // while(Peek.IsSpace()) iNext++; iMark=iNext; sl@0: _LL(&String[0], (TText8*)" aaa"); sl@0: TLexType j(&String[0]); sl@0: j.SkipSpaceAndMark(); sl@0: j.__DbgTest(&dump1); sl@0: _LL(&String[0], (TText8*)"aaa"); sl@0: TestDes(dump1.iNext, dump1.iEnd, &String[0]); sl@0: TestDes(dump1.iMark.iPtr, dump1.iEnd, &String[0]); sl@0: sl@0: test.Next(_L("SkipSpaceAndMark(aMark)")); // while(Peek.IsSpace()) iNext++; iMark=iNext; sl@0: _LL(&String[0], (TText8*)" aaa"); sl@0: TLexType j1(&String[0]); sl@0: TLexMarkType jm; sl@0: j1.SkipSpaceAndMark(jm); sl@0: j1.__DbgTest(&dump1); sl@0: jm.__DbgTest(&mDump); sl@0: _LL(&String[0], (TText8*)"aaa"); sl@0: TestDes(dump1.iNext, dump1.iEnd, &String[0]); sl@0: TestDes(mDump.iPtr, dump1.iEnd, &String[0]); sl@0: sl@0: test.Next(_L("SkipCharacters()")); // Skips non whitespace characters sl@0: _LL(&String[0], (TText8*)"abc "); sl@0: TLexType k(&String[0]); sl@0: k.SkipCharacters(); sl@0: test((S)k.Peek()==String[3]); sl@0: sl@0: test.Next(_L("TokenLength()")); // returns iNext-iMark sl@0: _LL(&String[0], (TText8*)"GGG"); sl@0: TLexType l(&String[0]); sl@0: test(l.TokenLength()==0); sl@0: l.Inc(); sl@0: test(l.TokenLength()==1); sl@0: sl@0: test.Next(_L("MarkedToken()")); // Extract a marked token sl@0: _LL(&String[0], (TText8*)"ABCD"); sl@0: TLexType m(&String[0]); sl@0: TBufType Buf; sl@0: TLexMarkType mm; sl@0: m.Inc(); sl@0: m.Mark(); sl@0: m.Inc(); sl@0: m.Mark(mm); sl@0: m.Inc(); sl@0: Buf=m.MarkedToken(); sl@0: S String2[4]; sl@0: _LL(&String2[0], (TText8*)"BC"); sl@0: test(TDesType(&String2[0])==Buf); sl@0: _LL(&String2[0], (TText8*)"C"); sl@0: Buf=m.MarkedToken(mm); sl@0: test(TDesType(&String2[0])==Buf); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: //********************************* sl@0: // Test Val() sl@0: //********************************* sl@0: template sl@0: GLDEF_C void TestTLex::Test5() sl@0: { sl@0: S String[66]; sl@0: TInt ret; sl@0: TLexType Lex; sl@0: test.Start(_L("Val()")); sl@0: sl@0: ////////////////// sl@0: // Test Val(TInt8) sl@0: ///////////////// sl@0: test.Next(_L("Val(TInt8)")); sl@0: TInt8 T8; sl@0: _LL(&String[0], (TText8*)""); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrGeneral); sl@0: sl@0: _LL(&String[0], (TText8*)"abc"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrGeneral); sl@0: sl@0: _LL(&String[0], (TText8*)"-abc-"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrGeneral); sl@0: sl@0: _LL(&String[0], (TText8*)"+abc+"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrGeneral); sl@0: sl@0: _LL(&String[0], (TText8*)"0000000123abc"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrNone); sl@0: test(T8==123); sl@0: sl@0: _LL(&String[0], (TText8*)"000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrNone); sl@0: test(T8==0); sl@0: sl@0: _LL(&String[0], (TText8*)"+0"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrNone); sl@0: test(T8==0); sl@0: sl@0: _LL(&String[0], (TText8*)"-0"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrNone); sl@0: test(T8==0); sl@0: sl@0: _LL(&String[0], (TText8*)"+1 "); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrNone); sl@0: test(T8==1); sl@0: sl@0: _LL(&String[0], (TText8*)"-1 "); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrNone); sl@0: test(T8==-1); sl@0: sl@0: _LL(&String[0], (TText8*)"127"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrNone); sl@0: test(T8==127); sl@0: sl@0: _LL(&String[0], (TText8*)"128"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"-128"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrNone); sl@0: test(T8==-128); sl@0: sl@0: _LL(&String[0], (TText8*)"-129"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T8))==KErrOverflow); sl@0: sl@0: sl@0: /////////////////// sl@0: // Test Val(TInt16) sl@0: /////////////////// sl@0: test.Next(_L("Val(TInt16)")); sl@0: TInt16 T16; sl@0: _LL(&String[0], (TText8*)""); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T16))==KErrGeneral); sl@0: sl@0: _LL(&String[0], (TText8*)"32767"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T16))==KErrNone); sl@0: test(T16==32767); sl@0: sl@0: _LL(&String[0], (TText8*)"32768"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T16))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"-32768"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T16))==KErrNone); sl@0: test(T16==-32768); sl@0: sl@0: _LL(&String[0], (TText8*)"-32769"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T16))==KErrOverflow); sl@0: sl@0: sl@0: /////////////////// sl@0: // Test Val(TInt32) sl@0: /////////////////// sl@0: test.Next(_L("Val(TInt32)")); sl@0: TInt32 T32; sl@0: _LL(&String[0], (TText8*)""); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T32))==KErrGeneral); sl@0: sl@0: _LL(&String[0], (TText8*)"2147483647"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T32))==KErrNone); sl@0: test(T32==2147483647L); sl@0: sl@0: _LL(&String[0], (TText8*)"2147483648"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T32))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"-2147483648"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T32))==KErrNone); sl@0: test(T32==-2147483647-1); // the -1 prevents a (bug?) warning sl@0: sl@0: _LL(&String[0], (TText8*)"-2147483649"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T32))==KErrOverflow); sl@0: sl@0: sl@0: ///////////////// sl@0: // Test Val(TInt) sl@0: ///////////////// sl@0: test.Next(_L("Val(TInt)")); sl@0: TInt T; sl@0: _LL(&String[0], (TText8*)""); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T))==KErrGeneral); sl@0: sl@0: _LL(&String[0], (TText8*)"2147483647"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T))==KErrNone); sl@0: test(T==2147483647L); sl@0: sl@0: _LL(&String[0], (TText8*)"2147483648"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"-2147483648"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T))==KErrNone); sl@0: test(T==-2147483647-1); // the -1 prevents a (bug?) warning sl@0: sl@0: _LL(&String[0], (TText8*)"-2147483649"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T))==KErrOverflow); sl@0: sl@0: ///////////////// sl@0: // Test Val(TInt64) sl@0: ///////////////// sl@0: test.Next(_L("Val(TInt64)")); sl@0: TInt64 T64; sl@0: _LL(&String[0], (TText8*)""); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T64))==KErrGeneral); sl@0: sl@0: _LL(&String[0], (TText8*)"2147483647"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T64))==KErrNone); sl@0: test(T64==TInt(2147483647L)); sl@0: sl@0: _LL(&String[0], (TText8*)"2147483648"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T64))==KErrNone); sl@0: test(T64==MAKE_TINT64(0,0x80000000u)); sl@0: sl@0: _LL(&String[0], (TText8*)"-2147483648"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T64))==KErrNone); sl@0: test(T64==-2147483647-1); // the -1 prevents a (bug?) warning sl@0: sl@0: _LL(&String[0], (TText8*)"-2147483649"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T64))==KErrNone); sl@0: test(T64==MAKE_TINT64(0xffffffffu,0x7fffffffu)); sl@0: sl@0: _LL(&String[0], (TText8*)"9223372036854775807"); sl@0: Lex=&String[0]; sl@0: ret=Lex.Val(T64); sl@0: test.Printf(_L("ret=%d\n"),ret); sl@0: test(ret==KErrNone); sl@0: test.Printf(_L("%lx\n"),T64); sl@0: test(T64==MAKE_TINT64(0x7fffffffu,0xffffffffu)); sl@0: sl@0: _LL(&String[0], (TText8*)"9223372036854775808"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T64))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"-9223372036854775808"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T64))==KErrNone); sl@0: test(T64==MAKE_TINT64(0x80000000u,0x0)); sl@0: sl@0: _LL(&String[0], (TText8*)"-9223372036854775809"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(T64))==KErrOverflow); sl@0: sl@0: //////////////////// sl@0: // Test Val(TReal32) sl@0: ///////////////////// sl@0: // test.Next(_L("Val(TReal32)")); sl@0: // TReal32 TR32; sl@0: // test((ret=Lex.Val(TR32))==KErrNotSupported); sl@0: sl@0: sl@0: //////////////////// sl@0: // Test Val(TReal64) sl@0: /////////////////// sl@0: // test.Next(_L("Val(TReal64)")); sl@0: // TReal64 TR64; sl@0: // test((ret=Lex.Val(TR64))==KErrNotSupported); sl@0: sl@0: sl@0: /////////////////////////// sl@0: // Test Val(TUint8, TRadix) sl@0: /////////////////////////// sl@0: test.Next(_L("Val(TUint8, TRadix)")); sl@0: TUint8 TU8; sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EBinary))==KErrNone); sl@0: test(TU8==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EBinary))==KErrNone); sl@0: test(TU8==1); sl@0: sl@0: _LL(&String[0], (TText8*)"11111111"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EBinary))==KErrNone); sl@0: test(TU8==255); sl@0: sl@0: _LL(&String[0], (TText8*)"100000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EBinary))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EOctal))==KErrNone); sl@0: test(TU8==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EOctal))==KErrNone); sl@0: test(TU8==1); sl@0: sl@0: _LL(&String[0], (TText8*)"377"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EOctal))==KErrNone); sl@0: test(TU8==255); sl@0: sl@0: _LL(&String[0], (TText8*)"400"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EOctal))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EDecimal))==KErrNone); sl@0: test(TU8==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EDecimal))==KErrNone); sl@0: test(TU8==1); sl@0: sl@0: _LL(&String[0], (TText8*)"255"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EDecimal))==KErrNone); sl@0: test(TU8==255); sl@0: sl@0: _LL(&String[0], (TText8*)"256"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EDecimal))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EHex))==KErrNone); sl@0: test(TU8==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EHex))==KErrNone); sl@0: test(TU8==1); sl@0: sl@0: _LL(&String[0], (TText8*)"Ff"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EHex))==KErrNone); sl@0: test(TU8==255); sl@0: sl@0: _LL(&String[0], (TText8*)"100"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU8, (TRadix)EHex))==KErrOverflow); sl@0: sl@0: sl@0: sl@0: //////////////////////////// sl@0: // Test Val(TUint16, TRadix) sl@0: //////////////////////////// sl@0: test.Next(_L("Val(TUint16, TRadix)")); sl@0: TUint16 TU16; sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EBinary))==KErrNone); sl@0: test(TU16==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EBinary))==KErrNone); sl@0: test(TU16==1); sl@0: sl@0: _LL(&String[0], (TText8*)"1111111111111111"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EBinary))==KErrNone); sl@0: test(TU16==65535); sl@0: sl@0: _LL(&String[0], (TText8*)"10000000000000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EBinary))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EOctal))==KErrNone); sl@0: test(TU16==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EOctal))==KErrNone); sl@0: test(TU16==1); sl@0: sl@0: _LL(&String[0], (TText8*)"177777"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EOctal))==KErrNone); sl@0: test(TU16==65535); sl@0: sl@0: _LL(&String[0], (TText8*)"200000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EOctal))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EDecimal))==KErrNone); sl@0: test(TU16==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EDecimal))==KErrNone); sl@0: test(TU16==1); sl@0: sl@0: _LL(&String[0], (TText8*)"65535"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EDecimal))==KErrNone); sl@0: test(TU16==65535); sl@0: sl@0: _LL(&String[0], (TText8*)"65536"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EDecimal))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EHex))==KErrNone); sl@0: test(TU16==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EHex))==KErrNone); sl@0: test(TU16==1); sl@0: sl@0: _LL(&String[0], (TText8*)"ffFf"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EHex))==KErrNone); sl@0: test(TU16==65535); sl@0: sl@0: _LL(&String[0], (TText8*)"10000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU16, (TRadix)EHex))==KErrOverflow); sl@0: sl@0: sl@0: sl@0: //////////////////////////// sl@0: // Test Val(TUint32, TRadix) sl@0: //////////////////////////// sl@0: test.Next(_L("Val(TUint32, TRadix)")); sl@0: TUint32 TU32; sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EBinary))==KErrNone); sl@0: test(TU32==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EBinary))==KErrNone); sl@0: test(TU32==1); sl@0: sl@0: _LL(&String[0], (TText8*)"11111111111111111111111111111111"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EBinary))==KErrNone); sl@0: test(TU32==4294967295u); sl@0: sl@0: _LL(&String[0], (TText8*)"100000000000000000000000000000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EBinary))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EOctal))==KErrNone); sl@0: test(TU32==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EOctal))==KErrNone); sl@0: test(TU32==1); sl@0: sl@0: _LL(&String[0], (TText8*)"37777777777"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EOctal))==KErrNone); sl@0: test(TU32==4294967295u); sl@0: sl@0: _LL(&String[0], (TText8*)"40000000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EOctal))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EDecimal))==KErrNone); sl@0: test(TU32==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EDecimal))==KErrNone); sl@0: test(TU32==1); sl@0: sl@0: _LL(&String[0], (TText8*)"4294967295"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EDecimal))==KErrNone); sl@0: test(TU32==4294967295u); sl@0: sl@0: _LL(&String[0], (TText8*)"4294967296"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EDecimal))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EHex))==KErrNone); sl@0: test(TU32==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EHex))==KErrNone); sl@0: test(TU32==1); sl@0: sl@0: _LL(&String[0], (TText8*)"FFFFFFFF"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EHex))==KErrNone); sl@0: test(TU32==4294967295u); sl@0: sl@0: _LL(&String[0], (TText8*)"100000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU32, (TRadix)EHex))==KErrOverflow); sl@0: sl@0: /////////////////////////////////// sl@0: // Test Val(TInt64, TRadix) sl@0: /////////////////////////////////// sl@0: test.Next(_L("Val(TInt64,TRadix)")); sl@0: TInt64 TI64; sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrNone); sl@0: test(TI64==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrNone); sl@0: test(TI64==1); sl@0: sl@0: _LL(&String[0], (TText8*)"11111111111111111111111111111111"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrNone); sl@0: test(TI64==TInt64(0xffffffffu)); sl@0: sl@0: _LL(&String[0], (TText8*)"100000000000000000000000000000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrNone); sl@0: test(TI64==MAKE_TINT64(0x1,0x0)); sl@0: sl@0: _LL(&String[0], (TText8*)"1111111111111111111111111111111111111111111111111111111111111111"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrNone); sl@0: test(TI64==MAKE_TINT64(0xffffffffu,0xffffffffu)); sl@0: sl@0: _LL(&String[0], (TText8*)"10000000000000000000000000000000000000000000000000000000000000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EBinary))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrNone); sl@0: test(TI64==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrNone); sl@0: test(TI64==1); sl@0: sl@0: _LL(&String[0], (TText8*)"37777777777"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrNone); sl@0: test(TI64==TInt64(0xffffffffu)); sl@0: sl@0: _LL(&String[0], (TText8*)"40000000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrNone); sl@0: test(TI64==MAKE_TINT64(0x1,0x0)); sl@0: sl@0: _LL(&String[0], (TText8*)"1777777777777777777777"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrNone); sl@0: test(TI64==MAKE_TINT64(0xffffffffu,0xffffffffu)); sl@0: sl@0: _LL(&String[0], (TText8*)"2000000000000000000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EOctal))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrNone); sl@0: test(TI64==0); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; //************** iNext is set to "" by Val sl@0: test((ret=Lex.Val(TI64))==KErrNone); sl@0: test(TI64==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrNone); sl@0: test(TI64==1); sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64))==KErrNone); sl@0: test(TI64==1); sl@0: sl@0: _LL(&String[0], (TText8*)"4294967295"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrNone); sl@0: test(TI64==TInt64(0xffffffffu)); sl@0: _LL(&String[0], (TText8*)"4294967295"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64))==KErrNone); sl@0: test(TI64==TInt64(0xffffffffu)); sl@0: sl@0: _LL(&String[0], (TText8*)"4294967296"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrNone); sl@0: test(TI64==MAKE_TINT64(1,0)); sl@0: _LL(&String[0], (TText8*)"4294967296"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64))==KErrNone); sl@0: test(TI64==MAKE_TINT64(1,0)); sl@0: sl@0: _LL(&String[0], (TText8*)"18446744073709551615"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrNone); sl@0: test(TI64==MAKE_TINT64(0xffffffffu,0xffffffffu)); sl@0: _LL(&String[0], (TText8*)"18446744073709551616"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"-1"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EDecimal))==KErrGeneral); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrNone); sl@0: test(TI64==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrNone); sl@0: test(TI64==1); sl@0: sl@0: _LL(&String[0], (TText8*)"FFFFFFFF"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrNone); sl@0: test(TI64==TInt64(0xffffffffu)); sl@0: sl@0: _LL(&String[0], (TText8*)"100000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrNone); sl@0: test(TI64==MAKE_TINT64(1,0)); sl@0: sl@0: _LL(&String[0], (TText8*)"FFFFFFFFffffffff"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrNone); sl@0: test(TI64==MAKE_TINT64(0xffffffffu,0xffffffffu)); sl@0: sl@0: _LL(&String[0], (TText8*)"10000000000000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TI64, (TRadix)EHex))==KErrOverflow); sl@0: sl@0: sl@0: /////////////////////////////////// sl@0: // Test Val(TUint, TRadix=(TRadix)EDecimal) sl@0: /////////////////////////////////// sl@0: test.Next(_L("Val(TUint, TRadix=(TRadix)EDecimal)")); sl@0: TUint TU; sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EBinary))==KErrNone); sl@0: test(TU==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EBinary))==KErrNone); sl@0: test(TU==1); sl@0: sl@0: _LL(&String[0], (TText8*)"11111111111111111111111111111111"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EBinary))==KErrNone); sl@0: test(TU==4294967295u); sl@0: sl@0: _LL(&String[0], (TText8*)"100000000000000000000000000000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EBinary))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EOctal))==KErrNone); sl@0: test(TU==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EOctal))==KErrNone); sl@0: test(TU==1); sl@0: sl@0: _LL(&String[0], (TText8*)"37777777777"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EOctal))==KErrNone); sl@0: test(TU==4294967295u); sl@0: sl@0: _LL(&String[0], (TText8*)"40000000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EOctal))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EDecimal))==KErrNone); sl@0: test(TU==0); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; //************** iNext is set to "" by Val sl@0: test((ret=Lex.Val(TU))==KErrNone); sl@0: test(TU==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EDecimal))==KErrNone); sl@0: test(TU==1); sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU))==KErrNone); sl@0: test(TU==1); sl@0: sl@0: _LL(&String[0], (TText8*)"4294967295"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EDecimal))==KErrNone); sl@0: test(TU==4294967295u); sl@0: _LL(&String[0], (TText8*)"4294967295"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU))==KErrNone); sl@0: test(TU==4294967295u); sl@0: sl@0: _LL(&String[0], (TText8*)"4294967296"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EDecimal))==KErrOverflow); sl@0: _LL(&String[0], (TText8*)"4294967296"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"00"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EHex))==KErrNone); sl@0: test(TU==0); sl@0: sl@0: _LL(&String[0], (TText8*)"01"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EHex))==KErrNone); sl@0: test(TU==1); sl@0: sl@0: _LL(&String[0], (TText8*)"FFFFFFFF"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EHex))==KErrNone); sl@0: test(TU==4294967295u); sl@0: sl@0: _LL(&String[0], (TText8*)"100000000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.Val(TU, (TRadix)EHex))==KErrOverflow); sl@0: sl@0: sl@0: ///////////////////////////////// sl@0: // Test Val(TInt32, TUint aLimit) sl@0: ///////////////////////////////// sl@0: // This is called by several of the other Val methods and so has been indirectly tested already sl@0: test.Next(_L("Val(TInt32, TUint aLimit")); sl@0: sl@0: _LL(&String[0], (TText8*)"1000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(T32,1000))==KErrNone); sl@0: test(T32==1000); sl@0: sl@0: _LL(&String[0], (TText8*)"1001"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(T32, 1000))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"-1000"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(T32, 1000))==KErrNone); sl@0: test(T32==-1000); sl@0: sl@0: _LL(&String[0], (TText8*)"-1001"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(T32, 1000))==KErrNone); sl@0: test(T32==-1001); sl@0: sl@0: _LL(&String[0], (TText8*)"-1002"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(T32, 1000))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"0"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(T32, 0))==KErrNone); sl@0: test(T32==0); sl@0: sl@0: _LL(&String[0], (TText8*)"1"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(T32, 0))==KErrOverflow); sl@0: sl@0: sl@0: ///////////////////////////////////////////////// sl@0: // Test Val(TUInt32, TRadix aRadix, TUint aLimit) sl@0: //////////////////////////////////////////////// sl@0: // This is called by several of the other Val methods and so has been indirectly tested already sl@0: test.Next(_L("Val(TUInt32, TRadix, TUint)")); sl@0: sl@0: // Test bug found during previous testing sl@0: _LL(&String[0], (TText8*)"10"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TU32, (TRadix)EDecimal, 10))==KErrNone); sl@0: test(TU32==10); sl@0: sl@0: _LL(&String[0], (TText8*)"11"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TU32, (TRadix)EDecimal, 10))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"19"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TU32, (TRadix)EDecimal, 10))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"20"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TU32, (TRadix)EDecimal, 10))==KErrOverflow); sl@0: sl@0: ///////////////////////////////////////////////// sl@0: // Test Val(TInt64, TRadix aRadix, TInt64 aLimit) sl@0: //////////////////////////////////////////////// sl@0: test.Next(_L("Val(TInt64, TRadix, TInt64)")); sl@0: sl@0: _LL(&String[0], (TText8*)"10"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, 10))==KErrNone); sl@0: test(TI64==TInt64(10)); sl@0: sl@0: _LL(&String[0], (TText8*)"11"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, 10))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"19"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, 10))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"20"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, 10))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"34532739886900"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrNone); sl@0: test(TI64==MAKE_TINT64(0x1f68u,0x47b1af34u)); sl@0: sl@0: _LL(&String[0], (TText8*)"34532739886901"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"74532739886901"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"6901"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EDecimal, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrNone); sl@0: test(TI64==TInt64(6901)); sl@0: sl@0: _LL(&String[0], (TText8*)"1f6847b1af34"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EHex, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrNone); sl@0: test(TI64==MAKE_TINT64(0x1f68u,0x47b1af34u)); sl@0: sl@0: _LL(&String[0], (TText8*)"1f6847b1af35"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EHex, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"1f6847b1af340"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EHex, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"1e82791aed35"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, (TRadix)EHex, TInt64(0x56fba45u)))==KErrOverflow); sl@0: sl@0: ///////////////////////////////////////////////// sl@0: // Test Val(TInt64, TInt64 aLimit) sl@0: //////////////////////////////////////////////// sl@0: test.Next(_L("Val(TInt64, TInt64)")); sl@0: sl@0: _LL(&String[0], (TText8*)"10"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, 10))==KErrNone); sl@0: test(TI64==TInt64(10)); sl@0: sl@0: _LL(&String[0], (TText8*)"11"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, 10))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"19"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, 10))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"20"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, 10))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"34532739886900"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrNone); sl@0: test(TI64==MAKE_TINT64(0x1f68u,0x47b1af34u)); sl@0: sl@0: _LL(&String[0], (TText8*)"34532739886901"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"74532739886901"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrOverflow); sl@0: sl@0: _LL(&String[0], (TText8*)"6901"); sl@0: Lex=&String[0]; sl@0: test((ret=Lex.BoundedVal(TI64, MAKE_TINT64(0x1f68u,0x47b1af34u)))==KErrNone); sl@0: test(TI64==TInt64(6901)); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: void testLocale() sl@0: { sl@0: sl@0: TLocale current; sl@0: current.Refresh(); sl@0: TLocale loc; sl@0: loc.Refresh(); sl@0: sl@0: TReal64 v,v8; sl@0: TLex l; sl@0: TLex8 l8; sl@0: TInt r; sl@0: sl@0: loc.SetDecimalSeparator('.'); sl@0: loc.Set(); sl@0: l=_L("-12.34"); sl@0: l8=_L8("-12.34"); sl@0: r=l.Val(v); sl@0: r=l8.Val(v8); sl@0: test(r==KErrNone); sl@0: test(v==-12.34); sl@0: test(v==v8); sl@0: sl@0: l=_L("-12.34"); sl@0: l8=_L8("-12.34"); sl@0: r=l.Val(v,'.'); sl@0: r=l8.Val(v8,'.'); sl@0: test(r==KErrNone); sl@0: test(v==-12.34); sl@0: test(v==v8); sl@0: l=_L("-12.34"); sl@0: l8=_L8("-12.34"); sl@0: r=l.Val(v,','); sl@0: r=l8.Val(v8,','); sl@0: test(r==KErrNone); sl@0: test(v==-12); sl@0: test(v==v8); sl@0: sl@0: l=_L("-12,34"); sl@0: l8=_L8("-12,34"); sl@0: r=l.Val(v); sl@0: r=l8.Val(v8); sl@0: test(r==KErrNone); sl@0: test(v==-12); sl@0: test(v==v8); sl@0: l=_L("-12,34"); sl@0: l8=_L8("-12,34"); sl@0: r=l.Val(v,'.'); sl@0: r=l8.Val(v8,'.'); sl@0: test(r==KErrNone); sl@0: test(v==-12); sl@0: test(v==v8); sl@0: l=_L("-12,34"); sl@0: l8=_L8("-12,34"); sl@0: r=l.Val(v,','); sl@0: r=l8.Val(v8,','); sl@0: test(r==KErrNone); sl@0: test(v==-12.34); sl@0: test(v==v8); sl@0: sl@0: loc.SetDecimalSeparator(','); sl@0: loc.Set(); sl@0: l=_L("-12.34"); sl@0: l8=_L8("-12.34"); sl@0: r=l.Val(v); sl@0: r=l8.Val(v8); sl@0: test(r==KErrNone); sl@0: test(v==-12); sl@0: test(v==v8); sl@0: sl@0: l=_L("-12.34"); sl@0: l8=_L8("-12.34"); sl@0: r=l.Val(v,'.'); sl@0: r=l8.Val(v8,'.'); sl@0: test(r==KErrNone); sl@0: test(v==-12.34); sl@0: test(v==v8); sl@0: l=_L("-12.34"); sl@0: l8=_L8("-12.34"); sl@0: r=l.Val(v,','); sl@0: r=l8.Val(v8,','); sl@0: test(r==KErrNone); sl@0: test(v==-12); sl@0: test(v==v8); sl@0: sl@0: l=_L("-12,34"); sl@0: l8=_L8("-12,34"); sl@0: r=l.Val(v); sl@0: r=l8.Val(v8); sl@0: test(r==KErrNone); sl@0: test(v==-12.34); sl@0: l=_L("-12,34"); sl@0: l8=_L8("-12,34"); sl@0: r=l.Val(v,'.'); sl@0: r=l8.Val(v8,'.'); sl@0: test(r==KErrNone); sl@0: test(v==-12); sl@0: test(v==v8); sl@0: l=_L("-12,34"); sl@0: l8=_L8("-12,34"); sl@0: r=l.Val(v,','); sl@0: r=l8.Val(v8,','); sl@0: test(r==KErrNone); sl@0: test(v==-12.34); sl@0: test(v==v8); sl@0: sl@0: loc.Set(); sl@0: current.Set(); sl@0: } sl@0: sl@0: #pragma warning( disable : 4705 ) // statement has no effect sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: sl@0: test.Title(); sl@0: sl@0: test.Start(_L("********* TLEX **********")); sl@0: #if defined(_UNICODE) sl@0: TestTLex, TLex16Dump, TLexMark16Dump, TText> T; sl@0: #else sl@0: TestTLex, TLex8Dump, TLexMark8Dump, TText> T; sl@0: #endif sl@0: test.Next(_L("TText 1")); sl@0: T.Test1(); sl@0: test.Next(_L("TText 2")); sl@0: T.Test2(); sl@0: test.Next(_L("TText 3")); sl@0: T.Test3(); sl@0: test.Next(_L("TText 4")); sl@0: T.Test4(); sl@0: test.Next(_L("TText 5")); sl@0: T.Test5(); sl@0: sl@0: TestTLex, TLex8Dump, TLexMark8Dump, TText8> T8; sl@0: test.Next(_L("TText8 1")); sl@0: T8.Test1(); sl@0: test.Next(_L("TText8 2")); sl@0: T8.Test2(); sl@0: test.Next(_L("TText8 3")); sl@0: T8.Test3(); sl@0: test.Next(_L("TText8 4")); sl@0: T8.Test4(); sl@0: test.Next(_L("TText8 5")); sl@0: T8.Test5(); sl@0: sl@0: TestTLex, TLex16Dump, TLexMark16Dump, TText16> T16; sl@0: test.Next(_L("TText16 1")); sl@0: T16.Test1(); sl@0: test.Next(_L("TText16 2")); sl@0: T16.Test2(); sl@0: test.Next(_L("TText16 3")); sl@0: T16.Test3(); sl@0: test.Next(_L("TText16 4")); sl@0: T16.Test4(); sl@0: test.Next(_L("TText16 5")); sl@0: T16.Test5(); sl@0: sl@0: test.Next(_L("Test TLex in different locales")); sl@0: testLocale(); sl@0: sl@0: test.End(); sl@0: return(KErrNone); sl@0: } sl@0: #pragma warning( default : 4705 ) sl@0: