First public contribution.
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #include <NumberGrouping.h>
24 ///////////////////////////////////////////////////////////////////////////////////////
25 RTest TheTest(_L("TestNumberGrouping"));
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)
35 TheTest(EFalse, aLine);
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)
41 if(aValue != aExpected)
43 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
44 TheTest(EFalse, aLine);
48 //Use these to test conditions.
49 #define TEST(arg) ::Check((arg), __LINE__)
50 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
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" );
59 LOCAL_C void TestNUMGRPINGInsertL()
61 TBool reserved( ETrue );
63 CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength,
66 TDesC testlesslengthnumber( KLessLengthNumber );
67 numbergrouping->Set( KLessLengthNumber );
69 TInt einsertposition( 13 );
73 err = numbergrouping->Insert( einsertposition, value );
74 TEST(KErrIndexOutOfRange == err);
77 err = numbergrouping->Insert( 9 , value );
78 TEST(KErrNone == err);
81 err = numbergrouping->Insert( -8, value );
82 TEST(KErrIndexOutOfRange == err);
84 CleanupStack::PopAndDestroy( numbergrouping );
87 LOCAL_C void TestNUMGRPINGDeleteL()
89 TBool reserved( ETrue );
91 CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength,
94 TDesC testnormalnumber( KNormalNumber );
95 numbergrouping->Set( testnormalnumber );
96 TInt einsertposition( 13 );
99 err = numbergrouping->Delete( einsertposition );
100 TEST(KErrIndexOutOfRange == err);
103 err = numbergrouping->Delete( einsertposition );
104 TEST(KErrNone == err);
106 CleanupStack::PopAndDestroy( numbergrouping );
109 LOCAL_C void TestNUMGRPINGAppendL()
111 TBool reserved( ETrue );
112 TInt maxlength( 11 );
113 CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength,
116 TDesC testnormalnumber( KNormalNumber );
117 numbergrouping->Set( testnormalnumber );
120 TInt err( KErrNone );
122 err = numbergrouping->Append( value );
123 TEST(KErrOverflow == err);
124 CleanupStack::PopAndDestroy( numbergrouping );
126 CPNGNumberGrouping* numbergroup = CPNGNumberGrouping::NewLC( maxlength,
129 TDesC testlesslengthnumber( KLessLengthNumber );
130 numbergroup->Set( testlesslengthnumber );
132 err = numbergrouping->Append( value );
133 TEST(KErrNone == err);
135 CleanupStack::PopAndDestroy( numbergroup );
138 LOCAL_C void TestNUMGRPINGSetL()
140 TBool reserved( ETrue );
141 TInt maxlength( 11 );
142 CPNGNumberGrouping* numbergrouping = CPNGNumberGrouping::NewLC( maxlength,
145 TDesC testmorelengthnumber( KMoreLengthNumber );
146 TDesC testnormalnumber( KNormalNumber );
147 TDesC testlesslengthnumber( KLessLengthNumber );
148 TInt err( KErrNone );
150 err = numbergrouping->Set( testmorelengthnumber );
151 TEST(KErrOverflow == err);
153 err = numbergrouping->Set( testnormalnumber );
154 TEST(KErrNone == err);
156 err = numbergrouping->Set( testlesslengthnumber );
157 TEST(KErrNone == err);
159 CleanupStack::PopAndDestroy( numbergrouping );
162 LOCAL_C void DoE32MainL()
164 TheTest.Start(_L("TestNumberGrouping:\n"));
166 TestNUMGRPINGInsertL();
167 TestNUMGRPINGDeleteL();
168 TestNUMGRPINGAppendL();
174 GLDEF_C TInt E32Main()
180 CTrapCleanup* trapCleanup=CTrapCleanup::New();
181 TEST(trapCleanup != NULL);
183 TRAPD(error, DoE32MainL());
184 TEST2(error, KErrNone);