1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/textandlocutils/numbergrouping/test/tsrc/tnumbergrouping.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,193 @@
1.4 +/*
1.5 +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <e32std.h>
1.23 +#include <e32base.h>
1.24 +#include <e32test.h>
1.25 +#include <NumberGrouping.h>
1.26 +
1.27 +///////////////////////////////////////////////////////////////////////////////////////
1.28 +RTest TheTest(_L("TestNumberGrouping"));
1.29 +
1.30 +///////////////////////////////////////////////////////////////////////////////////////
1.31 +///////////////////////////////////////////////////////////////////////////////////////
1.32 +//Tests macroses and functions.
1.33 +//If (!aValue) then the test will be panicked, the test data files will be deleted.
1.34 +static void Check(TInt aValue, TInt aLine)
1.35 + {
1.36 + if(!aValue)
1.37 + {
1.38 + TheTest(EFalse, aLine);
1.39 + }
1.40 + }
1.41 +//If (aValue != aExpected) then the test will be panicked, the test data files will be deleted.
1.42 +static void Check(TInt aValue, TInt aExpected, TInt aLine)
1.43 + {
1.44 + if(aValue != aExpected)
1.45 + {
1.46 + RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
1.47 + TheTest(EFalse, aLine);
1.48 + }
1.49 + }
1.50 +
1.51 +//Use these to test conditions.
1.52 +#define TEST(arg) ::Check((arg), __LINE__)
1.53 +#define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
1.54 +
1.55 +_LIT( KNormalNumber, "13548130726" );
1.56 +_LIT( KMoreLengthNumber, "1354813072688" );
1.57 +_LIT( KLessLengthNumber, "135481307" );
1.58 +//_LIT( KNormalNumberSpace, " " );
1.59 +//_LIT( KNormalNumberChar, "abcdefghijk" );
1.60 +//_LIT( KNoStandardNumber, "12 43 32" );
1.61 +
1.62 +LOCAL_C void TestNUMGRPINGInsertL()
1.63 + {
1.64 + TBool reserved( ETrue );
1.65 + TInt maxlength( 11 );
1.66 + CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength,
1.67 + reserved );
1.68 +
1.69 + TDesC testlesslengthnumber( KLessLengthNumber );
1.70 + numbergrouping->Set( KLessLengthNumber );
1.71 +
1.72 + TInt einsertposition( 13 );
1.73 + TInt err( KErrNone );
1.74 + TText value( 1 );
1.75 +
1.76 + err = numbergrouping->Insert( einsertposition, value );
1.77 + TEST(KErrIndexOutOfRange == err);
1.78 +
1.79 + einsertposition = 9;
1.80 + err = numbergrouping->Insert( 9 , value );
1.81 + TEST(KErrNone == err);
1.82 +
1.83 + einsertposition = -8;
1.84 + err = numbergrouping->Insert( -8, value );
1.85 + TEST(KErrIndexOutOfRange == err);
1.86 +
1.87 + CleanupStack::PopAndDestroy( numbergrouping );
1.88 + }
1.89 +
1.90 +LOCAL_C void TestNUMGRPINGDeleteL()
1.91 + {
1.92 + TBool reserved( ETrue );
1.93 + TInt maxlength( 11 );
1.94 + CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength,
1.95 + reserved );
1.96 +
1.97 + TDesC testnormalnumber( KNormalNumber );
1.98 + numbergrouping->Set( testnormalnumber );
1.99 + TInt einsertposition( 13 );
1.100 + TInt err( KErrNone );
1.101 +
1.102 + err = numbergrouping->Delete( einsertposition );
1.103 + TEST(KErrIndexOutOfRange == err);
1.104 +
1.105 + einsertposition = 7;
1.106 + err = numbergrouping->Delete( einsertposition );
1.107 + TEST(KErrNone == err);
1.108 +
1.109 + CleanupStack::PopAndDestroy( numbergrouping );
1.110 + }
1.111 +
1.112 +LOCAL_C void TestNUMGRPINGAppendL()
1.113 + {
1.114 + TBool reserved( ETrue );
1.115 + TInt maxlength( 11 );
1.116 + CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength,
1.117 + reserved );
1.118 +
1.119 + TDesC testnormalnumber( KNormalNumber );
1.120 + numbergrouping->Set( testnormalnumber );
1.121 +
1.122 + TText value( 1 );
1.123 + TInt err( KErrNone );
1.124 +
1.125 + err = numbergrouping->Append( value );
1.126 + TEST(KErrOverflow == err);
1.127 + CleanupStack::PopAndDestroy( numbergrouping );
1.128 +
1.129 + CPNGNumberGrouping* numbergroup = CPNGNumberGrouping::NewLC( maxlength,
1.130 + reserved );
1.131 +
1.132 + TDesC testlesslengthnumber( KLessLengthNumber );
1.133 + numbergroup->Set( testlesslengthnumber );
1.134 +
1.135 + err = numbergrouping->Append( value );
1.136 + TEST(KErrNone == err);
1.137 +
1.138 + CleanupStack::PopAndDestroy( numbergroup );
1.139 + }
1.140 +
1.141 +LOCAL_C void TestNUMGRPINGSetL()
1.142 + {
1.143 + TBool reserved( ETrue );
1.144 + TInt maxlength( 11 );
1.145 + CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength,
1.146 + reserved );
1.147 +
1.148 + TDesC testmorelengthnumber( KMoreLengthNumber );
1.149 + TDesC testnormalnumber( KNormalNumber );
1.150 + TDesC testlesslengthnumber( KLessLengthNumber );
1.151 + TInt err( KErrNone );
1.152 +
1.153 + err = numbergrouping->Set( testmorelengthnumber );
1.154 + TEST(KErrOverflow == err);
1.155 +
1.156 + err = numbergrouping->Set( testnormalnumber );
1.157 + TEST(KErrNone == err);
1.158 +
1.159 + err = numbergrouping->Set( testlesslengthnumber );
1.160 + TEST(KErrNone == err);
1.161 +
1.162 + CleanupStack::PopAndDestroy( numbergrouping );
1.163 + }
1.164 +
1.165 +LOCAL_C void DoE32MainL()
1.166 + {
1.167 + TheTest.Start(_L("TestNumberGrouping:\n"));
1.168 +
1.169 + TestNUMGRPINGInsertL();
1.170 + TestNUMGRPINGDeleteL();
1.171 + TestNUMGRPINGAppendL();
1.172 + TestNUMGRPINGSetL();
1.173 + }
1.174 +
1.175 +// Global Functions
1.176 +
1.177 +GLDEF_C TInt E32Main()
1.178 + {
1.179 + __UHEAP_MARK;
1.180 +
1.181 + TheTest.Title();
1.182 +
1.183 + CTrapCleanup* trapCleanup=CTrapCleanup::New();
1.184 + TEST(trapCleanup != NULL);
1.185 +
1.186 + TRAPD(error, DoE32MainL());
1.187 + TEST2(error, KErrNone);
1.188 +
1.189 + delete trapCleanup;
1.190 +
1.191 + TheTest.End();
1.192 + TheTest.Close();
1.193 +
1.194 + __UHEAP_MARKEND;
1.195 + return KErrNone;
1.196 + }