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