os/textandloc/textandlocutils/numbergrouping/test/tsrc/tnumbergrouping.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <e32std.h>
    20 #include <e32base.h>
    21 #include <e32test.h>
    22 #include <NumberGrouping.h>
    23 
    24 ///////////////////////////////////////////////////////////////////////////////////////
    25 RTest TheTest(_L("TestNumberGrouping"));
    26 	
    27 ///////////////////////////////////////////////////////////////////////////////////////
    28 ///////////////////////////////////////////////////////////////////////////////////////
    29 //Tests macroses and functions.
    30 //If (!aValue) then the test will be panicked, the test data files will be deleted.
    31 static void Check(TInt aValue, TInt aLine)
    32 	{
    33 	if(!aValue)
    34 		{
    35 		TheTest(EFalse, aLine);
    36 		}
    37 	}
    38 //If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
    39 static void Check(TInt aValue, TInt aExpected, TInt aLine)
    40 	{
    41 	if(aValue != aExpected)
    42 		{
    43 		RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    44 		TheTest(EFalse, aLine);
    45 		}
    46 	}
    47 
    48 //Use these to test conditions.
    49 #define TEST(arg) ::Check((arg), __LINE__)
    50 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    51 
    52 _LIT( KNormalNumber, "13548130726" );
    53 _LIT( KMoreLengthNumber, "1354813072688" );
    54 _LIT( KLessLengthNumber, "135481307" );
    55 //_LIT( KNormalNumberSpace, "         " );
    56 //_LIT( KNormalNumberChar, "abcdefghijk" );
    57 //_LIT( KNoStandardNumber, "12  43 32" );
    58 
    59 LOCAL_C void TestNUMGRPINGInsertL()
    60     {
    61     TBool reserved( ETrue );
    62     TInt maxlength( 11 );
    63     CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength,
    64         reserved );
    65     
    66     TDesC testlesslengthnumber( KLessLengthNumber );
    67     numbergrouping->Set( KLessLengthNumber );
    68     
    69     TInt einsertposition( 13 );
    70     TInt err( KErrNone );
    71     TText value( 1 );
    72     
    73     err = numbergrouping->Insert( einsertposition, value );
    74     TEST(KErrIndexOutOfRange == err);
    75     
    76     einsertposition = 9;
    77     err = numbergrouping->Insert( 9 , value );
    78     TEST(KErrNone == err);
    79     
    80     einsertposition = -8;
    81     err = numbergrouping->Insert( -8, value );
    82     TEST(KErrIndexOutOfRange == err);
    83     
    84     CleanupStack::PopAndDestroy( numbergrouping );
    85     }
    86 
    87 LOCAL_C void TestNUMGRPINGDeleteL()
    88     {
    89     TBool reserved( ETrue );
    90     TInt maxlength( 11 );
    91     CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength,
    92         reserved );
    93     
    94     TDesC testnormalnumber( KNormalNumber );
    95     numbergrouping->Set( testnormalnumber );
    96     TInt einsertposition( 13 );
    97     TInt err( KErrNone );
    98     
    99     err = numbergrouping->Delete( einsertposition );
   100     TEST(KErrIndexOutOfRange == err);
   101     
   102     einsertposition = 7;
   103     err = numbergrouping->Delete( einsertposition );
   104     TEST(KErrNone == err);
   105     
   106     CleanupStack::PopAndDestroy( numbergrouping );
   107     }
   108 
   109 LOCAL_C void TestNUMGRPINGAppendL()
   110     {
   111     TBool reserved( ETrue );
   112     TInt maxlength( 11 );
   113     CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength, 
   114         reserved );
   115     
   116     TDesC testnormalnumber( KNormalNumber );
   117     numbergrouping->Set( testnormalnumber );
   118     
   119     TText value( 1 );
   120     TInt err( KErrNone );
   121     
   122     err = numbergrouping->Append( value );
   123     TEST(KErrOverflow == err);
   124     CleanupStack::PopAndDestroy( numbergrouping );
   125     
   126     CPNGNumberGrouping* numbergroup = CPNGNumberGrouping::NewLC( maxlength, 
   127         reserved );
   128     
   129     TDesC testlesslengthnumber( KLessLengthNumber );
   130     numbergroup->Set( testlesslengthnumber );
   131     
   132     err = numbergrouping->Append( value );
   133     TEST(KErrNone == err);
   134     
   135     CleanupStack::PopAndDestroy( numbergroup );
   136     }
   137   
   138 LOCAL_C void TestNUMGRPINGSetL()
   139     {
   140     TBool reserved( ETrue );
   141     TInt maxlength( 11 );
   142     CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength,
   143         reserved );
   144     
   145     TDesC testmorelengthnumber( KMoreLengthNumber );
   146     TDesC testnormalnumber( KNormalNumber );
   147     TDesC testlesslengthnumber( KLessLengthNumber );
   148     TInt err( KErrNone );
   149     
   150     err = numbergrouping->Set( testmorelengthnumber );
   151     TEST(KErrOverflow == err);
   152     
   153     err = numbergrouping->Set( testnormalnumber );
   154     TEST(KErrNone == err);
   155     
   156     err = numbergrouping->Set( testlesslengthnumber );
   157     TEST(KErrNone == err);
   158 
   159     CleanupStack::PopAndDestroy( numbergrouping );
   160     }
   161 
   162 LOCAL_C void DoE32MainL()
   163 	{
   164 	TheTest.Start(_L("TestNumberGrouping:\n"));
   165 
   166 	TestNUMGRPINGInsertL();
   167 	TestNUMGRPINGDeleteL();
   168 	TestNUMGRPINGAppendL();
   169 	TestNUMGRPINGSetL();
   170     }
   171 
   172 //  Global Functions
   173 
   174 GLDEF_C TInt E32Main()
   175 	{
   176 	__UHEAP_MARK;
   177 
   178 	TheTest.Title();
   179 
   180 	CTrapCleanup* trapCleanup=CTrapCleanup::New();
   181 	TEST(trapCleanup != NULL);
   182 
   183 	TRAPD(error, DoE32MainL());
   184 	TEST2(error, KErrNone);
   185 
   186 	delete trapCleanup;
   187 
   188 	TheTest.End();
   189 	TheTest.Close();
   190 
   191 	__UHEAP_MARKEND;
   192 	return KErrNone;
   193 	}