sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\locale\t_currencyformat.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Test the currency formatting capabilities of the locale class.
|
sl@0
|
17 |
// API Information:
|
sl@0
|
18 |
// TLocale.
|
sl@0
|
19 |
// Details:
|
sl@0
|
20 |
// - Set the currency symbol position before the currency amount.
|
sl@0
|
21 |
// - Set no space between the currency symbol and the currency amount.
|
sl@0
|
22 |
// - Set 2 decimal places to currency values.
|
sl@0
|
23 |
// - Set negative currency value to be enclosed in brackets without a minus sign.
|
sl@0
|
24 |
// - Allow triads in currency values.
|
sl@0
|
25 |
// - Set comma as separator to separate groups of three digits to the left of the decimal
|
sl@0
|
26 |
// separator.
|
sl@0
|
27 |
// - Set dot as separator to separate a whole number from its fractional part.
|
sl@0
|
28 |
// - Set currency symbol to pound.
|
sl@0
|
29 |
// - Test some simple English Locale currency formats and check it is as expected.
|
sl@0
|
30 |
// - Render a currency value as text, based on the locale's currency and numeric format
|
sl@0
|
31 |
// settings and check the Overflow handling capability is as expected.
|
sl@0
|
32 |
// - Change a variety of locale settings and verify currency formatting is as expected.
|
sl@0
|
33 |
// - Change a variety of locale settings display the results.
|
sl@0
|
34 |
// Platforms/Drives/Compatibility:
|
sl@0
|
35 |
// All
|
sl@0
|
36 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
37 |
// Failures and causes:
|
sl@0
|
38 |
// Base Port information:
|
sl@0
|
39 |
//
|
sl@0
|
40 |
//
|
sl@0
|
41 |
|
sl@0
|
42 |
#include <e32test.h>
|
sl@0
|
43 |
#include <e32std.h>
|
sl@0
|
44 |
#include <e32std_private.h>
|
sl@0
|
45 |
|
sl@0
|
46 |
#ifdef __VC32__
|
sl@0
|
47 |
// Solve compilation problem caused by non-English locale
|
sl@0
|
48 |
#pragma setlocale("english")
|
sl@0
|
49 |
#endif
|
sl@0
|
50 |
|
sl@0
|
51 |
_LIT(KNewLine, "\n");
|
sl@0
|
52 |
LOCAL_D RTest test(_L("T_CurrencyFormat"));
|
sl@0
|
53 |
LOCAL_D TLocale locale;
|
sl@0
|
54 |
|
sl@0
|
55 |
|
sl@0
|
56 |
class TTestOverflowHandler : public TDesOverflow
|
sl@0
|
57 |
{
|
sl@0
|
58 |
void Overflow(TDes& aDes);
|
sl@0
|
59 |
};
|
sl@0
|
60 |
|
sl@0
|
61 |
void TTestOverflowHandler::Overflow(TDes& aDes)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
test.Printf(_L(" %S is too large... Overflow Handled!!"), &aDes);
|
sl@0
|
64 |
test.Printf(KNewLine);
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
|
sl@0
|
68 |
void SetEnglishCurrency()
|
sl@0
|
69 |
{
|
sl@0
|
70 |
locale.SetCurrencySymbolPosition(ELocaleBefore);
|
sl@0
|
71 |
locale.SetCurrencySpaceBetween(EFalse);
|
sl@0
|
72 |
locale.SetCurrencyDecimalPlaces(2);
|
sl@0
|
73 |
locale.SetCurrencyNegativeInBrackets(ETrue);
|
sl@0
|
74 |
locale.SetCurrencyTriadsAllowed(ETrue);
|
sl@0
|
75 |
locale.SetThousandsSeparator(',');
|
sl@0
|
76 |
locale.SetDecimalSeparator('.');
|
sl@0
|
77 |
User::SetCurrencySymbol(_L("\xA3"));
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
void TestSimpleEnglishCurrencyFormat()
|
sl@0
|
81 |
{
|
sl@0
|
82 |
|
sl@0
|
83 |
TBuf<32> fcurrency;
|
sl@0
|
84 |
// Set a few of the locale variables and then test that formatting the amount
|
sl@0
|
85 |
// returns what we expected.....
|
sl@0
|
86 |
test.Start(_L("Testing simple English Locale currency formats"));
|
sl@0
|
87 |
locale.FormatCurrency(fcurrency, 4000);
|
sl@0
|
88 |
test(fcurrency==_L("\xA3\x34\x30.00"));
|
sl@0
|
89 |
|
sl@0
|
90 |
locale.FormatCurrency(fcurrency, -567654);
|
sl@0
|
91 |
test(fcurrency==_L("(\xA3\x35,676.54)"));
|
sl@0
|
92 |
|
sl@0
|
93 |
locale.FormatCurrency(fcurrency,2);
|
sl@0
|
94 |
test(fcurrency==_L("\xA3\x30.02"));
|
sl@0
|
95 |
|
sl@0
|
96 |
locale.FormatCurrency(fcurrency,12500000);
|
sl@0
|
97 |
test(fcurrency==_L("\xA3\x31\x32\x35,000.00"));
|
sl@0
|
98 |
|
sl@0
|
99 |
locale.FormatCurrency(fcurrency, 00001);
|
sl@0
|
100 |
test(fcurrency==_L("\xA3\x30.01"));
|
sl@0
|
101 |
test.Printf(_L("SimplEnglishCurrencyPass"));
|
sl@0
|
102 |
}
|
sl@0
|
103 |
|
sl@0
|
104 |
void TestOverflowCapacity()
|
sl@0
|
105 |
{
|
sl@0
|
106 |
// try to test each stage that overflow at occur
|
sl@0
|
107 |
TBuf<10> smallcurrency;
|
sl@0
|
108 |
TTestOverflowHandler handler;
|
sl@0
|
109 |
test.Next(_L("Testing the Overflow handling capability"));
|
sl@0
|
110 |
// test the overflow handling capability
|
sl@0
|
111 |
|
sl@0
|
112 |
locale.SetCurrencyDecimalPlaces(11);
|
sl@0
|
113 |
locale.FormatCurrency(smallcurrency,handler,1);
|
sl@0
|
114 |
test(smallcurrency!=_L("0.00000000001"));
|
sl@0
|
115 |
locale.SetCurrencyDecimalPlaces(2);
|
sl@0
|
116 |
|
sl@0
|
117 |
locale.FormatCurrency(smallcurrency,handler, -1234567890);
|
sl@0
|
118 |
test(smallcurrency!=_L("(\xA3\x31\x32\x33\x34\x35\x36\x37\x38.90)"));
|
sl@0
|
119 |
|
sl@0
|
120 |
locale.FormatCurrency(smallcurrency, handler, 95000000);
|
sl@0
|
121 |
test(smallcurrency!=_L("\xA3\x39\x35\x30,000.00"));
|
sl@0
|
122 |
|
sl@0
|
123 |
locale.SetCurrencySpaceBetween(ETrue);
|
sl@0
|
124 |
locale.FormatCurrency(smallcurrency, handler, 2000000);
|
sl@0
|
125 |
test(smallcurrency!=_L("\xA3 20,000.00"));
|
sl@0
|
126 |
|
sl@0
|
127 |
locale.FormatCurrency(smallcurrency, handler, -240000);
|
sl@0
|
128 |
test(smallcurrency!=_L("(\xA3 2,400.00)"));
|
sl@0
|
129 |
|
sl@0
|
130 |
User::SetCurrencySymbol(_L("Fake\xA3"));
|
sl@0
|
131 |
locale.FormatCurrency(smallcurrency, handler, 240);
|
sl@0
|
132 |
test(smallcurrency==_L("Fake\xA3 2.40"));
|
sl@0
|
133 |
|
sl@0
|
134 |
locale.SetCurrencySpaceBetween(EFalse);
|
sl@0
|
135 |
locale.FormatCurrency(smallcurrency, handler, -240);
|
sl@0
|
136 |
test(smallcurrency!=_L("(Fake\xA3\x32.40)"));
|
sl@0
|
137 |
|
sl@0
|
138 |
test.Printf(_L("Overflow Pass"));
|
sl@0
|
139 |
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
void TestChangeInformation()
|
sl@0
|
143 |
{
|
sl@0
|
144 |
TBuf<32> fcurrency;
|
sl@0
|
145 |
// Make changes to the locale currency informationa and check formatting
|
sl@0
|
146 |
test.Next(_L("Changing locale information and testing currency Formatting "));
|
sl@0
|
147 |
// Change the format, add space in between
|
sl@0
|
148 |
locale.SetCurrencySpaceBetween(ETrue);
|
sl@0
|
149 |
locale.FormatCurrency(fcurrency,450);
|
sl@0
|
150 |
test(fcurrency==_L("\xA3 4.50"));
|
sl@0
|
151 |
// change the position of the CurrencySymbol
|
sl@0
|
152 |
locale.SetCurrencySymbolPosition(ELocaleAfter);
|
sl@0
|
153 |
locale.FormatCurrency(fcurrency, 300000);
|
sl@0
|
154 |
test(fcurrency==_L("3,000.00 \xA3"));
|
sl@0
|
155 |
// test the negative format implementation
|
sl@0
|
156 |
locale.FormatCurrency(fcurrency , -3000);
|
sl@0
|
157 |
test(fcurrency!=_L("-30.00 \xA3"));
|
sl@0
|
158 |
test(fcurrency==_L("(30.00 \xA3)"));
|
sl@0
|
159 |
// call the deprecated function to check for compatability
|
sl@0
|
160 |
locale.SetCurrencyNegativeInBrackets(ETrue);
|
sl@0
|
161 |
locale.SetNegativeLoseSpace(ETrue);
|
sl@0
|
162 |
locale.SetNegativeCurrencySymbolOpposite(ETrue);
|
sl@0
|
163 |
locale.FormatCurrency(fcurrency,-2500);
|
sl@0
|
164 |
locale.SetNegativeCurrencySymbolOpposite(EFalse);
|
sl@0
|
165 |
locale.SetNegativeLoseSpace(EFalse);
|
sl@0
|
166 |
test(fcurrency==_L("(\xA3\x32\x35.00)"));
|
sl@0
|
167 |
|
sl@0
|
168 |
locale.SetCurrencySymbolPosition(ELocaleBefore);
|
sl@0
|
169 |
locale.FormatCurrency(fcurrency, 300000);
|
sl@0
|
170 |
test(fcurrency==_L("\xA3 3,000.00"));
|
sl@0
|
171 |
// test the negative format implementation
|
sl@0
|
172 |
locale.FormatCurrency(fcurrency , -3000);
|
sl@0
|
173 |
test(fcurrency!=_L("-30.00 \xA3"));
|
sl@0
|
174 |
test(fcurrency==_L("(\xA3 30.00)"));
|
sl@0
|
175 |
// call the deprecated function to check for compatability
|
sl@0
|
176 |
locale.SetCurrencyNegativeInBrackets(ETrue);
|
sl@0
|
177 |
locale.SetNegativeLoseSpace(ETrue);
|
sl@0
|
178 |
locale.SetNegativeCurrencySymbolOpposite(ETrue);
|
sl@0
|
179 |
locale.FormatCurrency(fcurrency,-2500);
|
sl@0
|
180 |
locale.SetNegativeCurrencySymbolOpposite(EFalse);
|
sl@0
|
181 |
test(fcurrency==_L("(25.00\xA3)"));
|
sl@0
|
182 |
// test the New NegativeCurrencyFormat
|
sl@0
|
183 |
locale.SetNegativeCurrencyFormat(TLocale::EInterveningMinusSign);
|
sl@0
|
184 |
locale.FormatCurrency(fcurrency,-32500);
|
sl@0
|
185 |
test(fcurrency==_L("\xA3-325.00"));
|
sl@0
|
186 |
// test the decimal places implementation
|
sl@0
|
187 |
locale.SetCurrencyDecimalPlaces(6);
|
sl@0
|
188 |
locale.FormatCurrency(fcurrency,-32500);
|
sl@0
|
189 |
locale.SetNegativeLoseSpace(EFalse);
|
sl@0
|
190 |
test(fcurrency==_L("\xA3-0.032500"));
|
sl@0
|
191 |
// testing Thousandseparators and triads
|
sl@0
|
192 |
locale.SetCurrencyDecimalPlaces(2);
|
sl@0
|
193 |
locale.SetThousandsSeparator(' ');
|
sl@0
|
194 |
locale.SetCurrencySymbolPosition(ELocaleAfter);
|
sl@0
|
195 |
locale.FormatCurrency(fcurrency, 300000000);
|
sl@0
|
196 |
test(fcurrency==_L("3 000 000.00 \xA3"));
|
sl@0
|
197 |
|
sl@0
|
198 |
locale.SetCurrencyTriadsAllowed(EFalse);
|
sl@0
|
199 |
locale.FormatCurrency(fcurrency, 300000000);
|
sl@0
|
200 |
test(fcurrency==_L("3000000.00 \xA3"));
|
sl@0
|
201 |
// test the other NegativeCurrencyFormat Options
|
sl@0
|
202 |
locale.SetNegativeCurrencyFormat(TLocale::ETrailingMinusSign);
|
sl@0
|
203 |
locale.FormatCurrency(fcurrency, -24000000);
|
sl@0
|
204 |
test(fcurrency==_L("240000.00 \xA3-"));
|
sl@0
|
205 |
|
sl@0
|
206 |
locale.SetNegativeCurrencyFormat(TLocale::EInterveningMinusSign);
|
sl@0
|
207 |
locale.FormatCurrency(fcurrency, -40000000);
|
sl@0
|
208 |
test(fcurrency== _L("400000.00- \xA3"));
|
sl@0
|
209 |
// change the currency symbol
|
sl@0
|
210 |
User::SetCurrencySymbol(_L("NZ$"));
|
sl@0
|
211 |
locale.FormatCurrency(fcurrency,250000);
|
sl@0
|
212 |
test(fcurrency!=_L("2,500.00 \xA3"));
|
sl@0
|
213 |
test(fcurrency==_L("2500.00 NZ$"));
|
sl@0
|
214 |
// move the currency symbol forward
|
sl@0
|
215 |
locale.SetCurrencySymbolPosition(ELocaleBefore);
|
sl@0
|
216 |
locale.FormatCurrency(fcurrency,300);
|
sl@0
|
217 |
test(fcurrency==_L("NZ$ 3.00"));
|
sl@0
|
218 |
|
sl@0
|
219 |
locale.SetCurrencySpaceBetween(EFalse);
|
sl@0
|
220 |
locale.FormatCurrency(fcurrency, 43020);
|
sl@0
|
221 |
test(fcurrency==_L("NZ$430.20"));
|
sl@0
|
222 |
|
sl@0
|
223 |
locale.SetCurrencyTriadsAllowed(ETrue);
|
sl@0
|
224 |
locale.SetThousandsSeparator(',');
|
sl@0
|
225 |
locale.SetCurrencySpaceBetween(ETrue);
|
sl@0
|
226 |
locale.FormatCurrency(fcurrency,-2450000);
|
sl@0
|
227 |
test(fcurrency==_L("NZ$ -24,500.00"));
|
sl@0
|
228 |
locale.SetNegativeCurrencySymbolOpposite(EFalse);
|
sl@0
|
229 |
|
sl@0
|
230 |
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
void TestDisplyCurrencyFormats()
|
sl@0
|
234 |
{
|
sl@0
|
235 |
|
sl@0
|
236 |
// Display Differenct locale currency as a test
|
sl@0
|
237 |
test.Next(_L("Samples of a few Currency formats that can be displayed"));
|
sl@0
|
238 |
TBuf<32> fcurrency;
|
sl@0
|
239 |
locale.FormatCurrency (fcurrency, 2500000);
|
sl@0
|
240 |
test.Printf(fcurrency);
|
sl@0
|
241 |
test.Printf(KNewLine);
|
sl@0
|
242 |
locale.SetCurrencySpaceBetween(EFalse);
|
sl@0
|
243 |
User::SetCurrencySymbol(_L("\xA3"));
|
sl@0
|
244 |
locale.SetCurrencySymbolPosition(ELocaleAfter);
|
sl@0
|
245 |
locale.FormatCurrency (fcurrency, 2500000);
|
sl@0
|
246 |
test.Printf(fcurrency);
|
sl@0
|
247 |
test.Printf(KNewLine);
|
sl@0
|
248 |
locale.SetCurrencySymbolPosition(ELocaleBefore);
|
sl@0
|
249 |
User::SetCurrencySymbol(_L("$"));
|
sl@0
|
250 |
locale.SetNegativeCurrencyFormat(TLocale::EInBrackets);
|
sl@0
|
251 |
locale.FormatCurrency (fcurrency, -2500000);
|
sl@0
|
252 |
test.Printf(fcurrency);
|
sl@0
|
253 |
test.Printf(KNewLine);
|
sl@0
|
254 |
locale.SetNegativeCurrencyFormat(TLocale::ELeadingMinusSign);
|
sl@0
|
255 |
locale.FormatCurrency (fcurrency, -2500000);
|
sl@0
|
256 |
test.Printf(fcurrency);
|
sl@0
|
257 |
test.Printf(KNewLine);
|
sl@0
|
258 |
locale.SetNegativeCurrencySymbolOpposite(ETrue);
|
sl@0
|
259 |
locale.SetNegativeLoseSpace(ETrue);
|
sl@0
|
260 |
locale.FormatCurrency (fcurrency, -2500000);
|
sl@0
|
261 |
test.Printf(fcurrency);
|
sl@0
|
262 |
test.Printf(KNewLine);
|
sl@0
|
263 |
locale.SetNegativeCurrencySymbolOpposite(EFalse);
|
sl@0
|
264 |
locale.SetNegativeCurrencyFormat(TLocale::EInterveningMinusSign);
|
sl@0
|
265 |
locale.FormatCurrency (fcurrency, -2500000);
|
sl@0
|
266 |
test.Printf(fcurrency);
|
sl@0
|
267 |
test.Printf(KNewLine);
|
sl@0
|
268 |
//******************
|
sl@0
|
269 |
|
sl@0
|
270 |
locale.SetCurrencySymbolPosition(ELocaleAfter);
|
sl@0
|
271 |
User::SetCurrencySymbol(_L("$"));
|
sl@0
|
272 |
locale.SetNegativeCurrencyFormat(TLocale::EInBrackets);
|
sl@0
|
273 |
locale.SetNegativeLoseSpace(ETrue);
|
sl@0
|
274 |
locale.FormatCurrency (fcurrency, -2500000);
|
sl@0
|
275 |
test.Printf(fcurrency);
|
sl@0
|
276 |
test.Printf(KNewLine);
|
sl@0
|
277 |
locale.SetNegativeCurrencyFormat(TLocale::ELeadingMinusSign);
|
sl@0
|
278 |
locale.FormatCurrency (fcurrency, -2500000);
|
sl@0
|
279 |
test.Printf(fcurrency);
|
sl@0
|
280 |
test.Printf(KNewLine);
|
sl@0
|
281 |
locale.SetNegativeCurrencySymbolOpposite(ETrue);
|
sl@0
|
282 |
locale.SetNegativeLoseSpace(ETrue);
|
sl@0
|
283 |
locale.FormatCurrency (fcurrency, -2500000);
|
sl@0
|
284 |
test.Printf(fcurrency);
|
sl@0
|
285 |
test.Printf(KNewLine);
|
sl@0
|
286 |
locale.SetNegativeCurrencySymbolOpposite(EFalse);
|
sl@0
|
287 |
locale.SetNegativeCurrencyFormat(TLocale::EInterveningMinusSign);
|
sl@0
|
288 |
locale.FormatCurrency (fcurrency, -2500000);
|
sl@0
|
289 |
test.Printf(fcurrency);
|
sl@0
|
290 |
test.Printf(KNewLine);
|
sl@0
|
291 |
|
sl@0
|
292 |
//******************
|
sl@0
|
293 |
TInt64 x=25000000;
|
sl@0
|
294 |
x*=10000;
|
sl@0
|
295 |
locale.FormatCurrency (fcurrency,x );
|
sl@0
|
296 |
test.Printf(fcurrency);
|
sl@0
|
297 |
test.Printf(KNewLine);
|
sl@0
|
298 |
|
sl@0
|
299 |
|
sl@0
|
300 |
}
|
sl@0
|
301 |
|
sl@0
|
302 |
GLDEF_C TInt E32Main(void)
|
sl@0
|
303 |
{
|
sl@0
|
304 |
|
sl@0
|
305 |
// Call all the tests from here
|
sl@0
|
306 |
test.Title();
|
sl@0
|
307 |
SetEnglishCurrency();
|
sl@0
|
308 |
TestSimpleEnglishCurrencyFormat();
|
sl@0
|
309 |
TestOverflowCapacity();
|
sl@0
|
310 |
SetEnglishCurrency();
|
sl@0
|
311 |
TestChangeInformation();
|
sl@0
|
312 |
TestDisplyCurrencyFormats();
|
sl@0
|
313 |
test.End();
|
sl@0
|
314 |
return KErrNone;
|
sl@0
|
315 |
}
|