kerneltest/e32test/buffer/t_lex.cpp
changeset 271 dc268b18d709
parent 0 a41df078684a
equal deleted inserted replaced
269:d57b86b1867a 271:dc268b18d709
     1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1994-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    22 // - Test the constructors with no parameter, by a string, with an empty TLex class, 
    22 // - Test the constructors with no parameter, by a string, with an empty TLex class, 
    23 // non-empty TLex class is as expected.
    23 // non-empty TLex class is as expected.
    24 // - Test assignment operator of TLex, by initializing with TLex reference, string, 
    24 // - Test assignment operator of TLex, by initializing with TLex reference, string, 
    25 // TBuf reference and check it is as expected.
    25 // TBuf reference and check it is as expected.
    26 // - Check that Eos, Inc, Mark, Get, Peek, UnGet, SkipSpace, SkipSpaceAndMark, 
    26 // - Check that Eos, Inc, Mark, Get, Peek, UnGet, SkipSpace, SkipSpaceAndMark, 
    27 // SkipCharacters, TokenLength, MarkedToken methods are as expected.
    27 // SkipAndMark, SkipCharacters, TokenLength, MarkedToken methods are as expected.
    28 // - Initialize Lex string, assign different values, Parse to extract signed, 
    28 // - Initialize Lex string, assign different values, Parse to extract signed, 
    29 // unsigned integer of different lengths, using specified radix and verify 
    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 
    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 
    31 // when invalid string is parsed, KErrOverflow when converted value is greater 
    32 // than the limit. 
    32 // than the limit. 
   182 	test.Next(_L("Assorted"));
   182 	test.Next(_L("Assorted"));
   183 	c.Eos();
   183 	c.Eos();
   184 	c.Mark(mark);
   184 	c.Mark(mark);
   185 	c.Mark();
   185 	c.Mark();
   186 	c.Inc();
   186 	c.Inc();
       
   187 	c.Inc(2);
   187 	c.Get();
   188 	c.Get();
   188 	(S)c.Peek();
   189 	(S)c.Peek();
   189 	c.UnGet();
   190 	c.UnGet();
   190 	c.UnGetToMark(mark);
   191 	c.UnGetToMark(mark);
   191 	c.UnGetToMark();
   192 	c.UnGetToMark();
   192 	c.SkipSpace();
   193 	c.SkipSpace();
   193 	c.SkipSpaceAndMark(mark);
   194 	c.SkipSpaceAndMark(mark);
   194 	c.SkipSpaceAndMark();
   195 	c.SkipSpaceAndMark();
       
   196 	c.SkipAndMark(2,mark);
   195 	c.SkipCharacters();
   197 	c.SkipCharacters();
   196 	c.TokenLength(mark);
   198 	c.TokenLength(mark);
   197 	c.TokenLength();
   199 	c.TokenLength();
   198 	aTBufObject=c.MarkedToken(mark);
   200 	aTBufObject=c.MarkedToken(mark);
   199 	aTBufObject=c.MarkedToken();
   201 	aTBufObject=c.MarkedToken();
   218 	c.Val(TI64);
   220 	c.Val(TI64);
   219 	TUint TU=1;
   221 	TUint TU=1;
   220 	c.Val(TU);
   222 	c.Val(TU);
   221 	TReal32 TR32=1.0F;
   223 	TReal32 TR32=1.0F;
   222 	c.Val(TR32);
   224 	c.Val(TR32);
       
   225 	c.Val(TR32,'.');
   223 	TReal64 TR64=1.0;
   226 	TReal64 TR64=1.0;
   224 	c.Val(TR64);
   227 	c.Val(TR64);
   225 	TUint8 TU8='a';
   228 	TUint8 TU8='a';
   226 	TUint32 TU32=1;
   229 	TUint32 TU32=1;
   227 	TRadix TR=(TRadix)EDecimal;
   230 	TRadix TR=(TRadix)EDecimal;
   386 	TestDes(dump1.iNext, dump1.iEnd, &String[0]);
   389 	TestDes(dump1.iNext, dump1.iEnd, &String[0]);
   387 	c.Inc();
   390 	c.Inc();
   388 	test((S)c.Peek()==String[1]);
   391 	test((S)c.Peek()==String[1]);
   389 	c.Inc();
   392 	c.Inc();
   390 	test((S)c.Peek()==String[2]);
   393 	test((S)c.Peek()==String[2]);
       
   394 	
       
   395 	test.Next(_L("Inc(aNumber)"));    // Inc(aNumber) increments iNext
       
   396 	_LL(&String[0], (TText8*)"mno");
       
   397 	TLexType c1(&String[0]);
       
   398 	c1.__DbgTest(&dump1);
       
   399 
       
   400 	TestDes(dump1.iNext, dump1.iEnd, &String[0]);
       
   401 	c1.Inc(1);
       
   402 	test((S)c1.Peek()==String[1]);
       
   403 	c1.Inc(1);
       
   404 	test((S)c1.Peek()==String[2]);
   391 
   405 
   392 	test.Next(_L("Mark()"));		//	Mark() sets iMark=iNext
   406 	test.Next(_L("Mark()"));		//	Mark() sets iMark=iNext
   393 	_LL(&String[0], (TText8*)"pqr");
   407 	_LL(&String[0], (TText8*)"pqr");
   394 	TLexType d(&String[0]);
   408 	TLexType d(&String[0]);
   395 	d.Inc();
   409 	d.Inc();
   457 	TLexType j1(&String[0]);
   471 	TLexType j1(&String[0]);
   458 	TLexMarkType jm;
   472 	TLexMarkType jm;
   459 	j1.SkipSpaceAndMark(jm);
   473 	j1.SkipSpaceAndMark(jm);
   460 	j1.__DbgTest(&dump1);
   474 	j1.__DbgTest(&dump1);
   461 	jm.__DbgTest(&mDump);
   475 	jm.__DbgTest(&mDump);
       
   476 	_LL(&String[0], (TText8*)"aaa");
       
   477 	TestDes(dump1.iNext, dump1.iEnd, &String[0]);
       
   478 	TestDes(mDump.iPtr, dump1.iEnd, &String[0]);
       
   479 	
       
   480 	test.Next(_L("SkipAndMark(4, aMark)"));  // Skips number of characters
       
   481 	_LL(&String[0], (TText8*)"abcdaaa");
       
   482 	TLexType j2(&String[0]);
       
   483 	TLexMarkType jmt;
       
   484 	j2.SkipAndMark(4, jmt);
       
   485 	j2.__DbgTest(&dump1);
       
   486 	jmt.__DbgTest(&mDump);
   462 	_LL(&String[0], (TText8*)"aaa");
   487 	_LL(&String[0], (TText8*)"aaa");
   463 	TestDes(dump1.iNext, dump1.iEnd, &String[0]);
   488 	TestDes(dump1.iNext, dump1.iEnd, &String[0]);
   464 	TestDes(mDump.iPtr, dump1.iEnd, &String[0]);
   489 	TestDes(mDump.iPtr, dump1.iEnd, &String[0]);
   465 
   490 
   466 	test.Next(_L("SkipCharacters()"));	// Skips non whitespace characters
   491 	test.Next(_L("SkipCharacters()"));	// Skips non whitespace characters
   712 	Lex=&String[0];
   737 	Lex=&String[0];
   713 	test((ret=Lex.Val(T64))==KErrOverflow);
   738 	test((ret=Lex.Val(T64))==KErrOverflow);
   714 
   739 
   715 	////////////////////					
   740 	////////////////////					
   716 	// Test Val(TReal32)
   741 	// Test Val(TReal32)
       
   742 	// 32-bit floating point number.
   717 	/////////////////////
   743 	/////////////////////
   718 //	test.Next(_L("Val(TReal32)"));
   744 	test.Next(_L("Val(TReal32)"));
   719 //	TReal32 TR32;
   745 	TReal32 TR32 = 0;
   720 //	test((ret=Lex.Val(TR32))==KErrNotSupported);
   746 	
   721 
   747 	_LL(&String[0], (TText8*)"92.2337203685477");
   722 
   748 	Lex=&String[0];
       
   749 	test((ret=Lex.Val(TR32))==KErrNone);
       
   750 				
       
   751 	_LL(&String[0], (TText8*)"92.2337203685477");
       
   752 	Lex=&String[0];
       
   753 	test((ret=Lex.Val(TR32,'.'))==KErrNone);
       
   754 			
       
   755 	_LL(&String[0], (TText8*)"0.2337285477");
       
   756 	Lex=&String[0];
       
   757 	test((ret=Lex.Val(TR32,'.'))==KErrNone);
       
   758 		
       
   759 	_LL(&String[0], (TText8*)"23");
       
   760 	Lex=&String[0];
       
   761 	test((ret=Lex.Val(TR32,'.'))==KErrNone);
       
   762 		
       
   763 	_LL(&String[0], (TText8*)"0");
       
   764 	Lex=&String[0];
       
   765 	test((ret=Lex.Val(TR32,'.'))==KErrNone);
       
   766 		
       
   767 	_LL(&String[0], (TText8*)"-324.27890");
       
   768 	Lex=&String[0];
       
   769 	test((ret=Lex.Val(TR32,'.'))==KErrNone);
       
   770 	
   723 	////////////////////
   771 	////////////////////
   724 	// Test Val(TReal64)
   772 	// Test Val(TReal)
       
   773 	// 64-bit floating point number. Identical to TReal64.
   725 	///////////////////
   774 	///////////////////
   726 //	test.Next(_L("Val(TReal64)"));
   775 	test.Next(_L("Val(TReal)"));
   727 //	TReal64 TR64;
   776 	TReal TR64 = 0;
   728 //	test((ret=Lex.Val(TR64))==KErrNotSupported);
   777 
   729 
   778 	_LL(&String[0], (TText8*)"92.2337203685477");
   730 
   779 	Lex=&String[0];
       
   780 	test((ret=Lex.Val(TR64))==KErrNone);
       
   781 		            
       
   782 	_LL(&String[0], (TText8*)"92.2337203685477");
       
   783 	Lex=&String[0];
       
   784 	test((ret=Lex.Val(TR64,'.'))==KErrNone);
       
   785 		       
       
   786 	_LL(&String[0], (TText8*)"0.2337285477");
       
   787 	Lex=&String[0];
       
   788 	test((ret=Lex.Val(TR64,'.'))==KErrNone);
       
   789 		    
       
   790 	_LL(&String[0], (TText8*)"23");
       
   791 	Lex=&String[0];
       
   792 	test((ret=Lex.Val(TR64,'.'))==KErrNone);
       
   793 		    
       
   794 	_LL(&String[0], (TText8*)"0");
       
   795 	Lex=&String[0];
       
   796 	test((ret=Lex.Val(TR64,'.'))==KErrNone);
       
   797 		    
       
   798 	_LL(&String[0], (TText8*)"-324.27890");
       
   799 	Lex=&String[0];
       
   800 	test((ret=Lex.Val(TR64,'.'))==KErrNone);
       
   801 	
       
   802 	
   731 	///////////////////////////
   803 	///////////////////////////
   732 	// Test Val(TUint8, TRadix)
   804 	// Test Val(TUint8, TRadix)
   733 	///////////////////////////
   805 	///////////////////////////
   734 	test.Next(_L("Val(TUint8, TRadix)"));
   806 	test.Next(_L("Val(TUint8, TRadix)"));
   735 	TUint8 TU8;
   807 	TUint8 TU8;