]>
Commit | Line | Data |
---|---|---|
57a6839d A |
1 | /* |
2 | ******************************************************************************* | |
2ca993e8 | 3 | * Copyright (C) 2014-2016, International Business Machines Corporation and * |
57a6839d A |
4 | * others. All Rights Reserved. * |
5 | ******************************************************************************* | |
6 | * | |
7 | * File MEASFMTTEST.CPP | |
8 | * | |
9 | ******************************************************************************* | |
10 | */ | |
11 | #include <stdio.h> | |
12 | #include <stdlib.h> | |
13 | ||
14 | #include "intltest.h" | |
15 | ||
16 | #if !UCONFIG_NO_FORMATTING | |
17 | ||
18 | #include "unicode/decimfmt.h" | |
19 | #include "unicode/measfmt.h" | |
20 | #include "unicode/measure.h" | |
21 | #include "unicode/measunit.h" | |
22 | #include "unicode/tmunit.h" | |
b331163b | 23 | #include "unicode/plurrule.h" |
57a6839d | 24 | #include "charstr.h" |
b331163b | 25 | #include "unicode/reldatefmt.h" |
57a6839d A |
26 | |
27 | struct ExpectedResult { | |
28 | const Measure *measures; | |
29 | int32_t count; | |
30 | const char *expected; | |
31 | }; | |
32 | ||
33 | class MeasureFormatTest : public IntlTest { | |
34 | public: | |
35 | MeasureFormatTest() { | |
36 | } | |
37 | ||
38 | void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par=0); | |
39 | private: | |
40 | void TestBasic(); | |
b331163b A |
41 | void TestCompatible53_1(); |
42 | void TestCompatible54_1(); | |
2ca993e8 A |
43 | void TestCompatible55_1(); |
44 | void TestCompatible56_1(); | |
45 | void TestCompatible57_1(); | |
57a6839d A |
46 | void TestGetAvailable(); |
47 | void TestExamplesInDocs(); | |
48 | void TestFormatPeriodEn(); | |
49 | void Test10219FractionalPlurals(); | |
50 | void TestGreek(); | |
51 | void TestFormatSingleArg(); | |
52 | void TestFormatMeasuresZeroArg(); | |
b331163b A |
53 | void TestSimplePer(); |
54 | void TestNumeratorPlurals(); | |
57a6839d | 55 | void TestMultiples(); |
2ca993e8 | 56 | void TestManyLocaleDurations(); |
57a6839d A |
57 | void TestGram(); |
58 | void TestCurrencies(); | |
59 | void TestFieldPosition(); | |
60 | void TestFieldPositionMultiple(); | |
61 | void TestBadArg(); | |
62 | void TestEquality(); | |
b331163b | 63 | void TestGroupingSeparator(); |
57a6839d | 64 | void TestDoubleZero(); |
b331163b | 65 | void TestUnitPerUnitResolution(); |
2ca993e8 | 66 | void TestIndividualPluralFallback(); |
57a6839d A |
67 | void verifyFormat( |
68 | const char *description, | |
69 | const MeasureFormat &fmt, | |
70 | const Measure *measures, | |
71 | int32_t measureCount, | |
72 | const char *expected); | |
73 | void verifyFormatWithPrefix( | |
74 | const char *description, | |
75 | const MeasureFormat &fmt, | |
76 | const UnicodeString &prefix, | |
77 | const Measure *measures, | |
78 | int32_t measureCount, | |
79 | const char *expected); | |
80 | void verifyFormat( | |
81 | const char *description, | |
82 | const MeasureFormat &fmt, | |
83 | const ExpectedResult *expectedResults, | |
84 | int32_t count); | |
b331163b A |
85 | void helperTestSimplePer( |
86 | const Locale &locale, | |
87 | UMeasureFormatWidth width, | |
88 | double value, | |
89 | const MeasureUnit &unit, | |
90 | const MeasureUnit &perUnit, | |
91 | const char *expected); | |
92 | void helperTestSimplePer( | |
93 | const Locale &locale, | |
94 | UMeasureFormatWidth width, | |
95 | double value, | |
96 | const MeasureUnit &unit, | |
97 | const MeasureUnit &perUnit, | |
98 | const char *expected, | |
99 | int32_t field, | |
100 | int32_t expected_start, | |
101 | int32_t expected_end); | |
57a6839d A |
102 | void helperTestMultiples( |
103 | const Locale &locale, | |
104 | UMeasureFormatWidth width, | |
105 | const char *expected); | |
2ca993e8 A |
106 | void helperTestManyLocaleDurations( |
107 | const char *localeID, | |
108 | UMeasureFormatWidth width, | |
109 | const Measure *measures, | |
110 | int32_t measureCount, | |
111 | const char *expected); | |
57a6839d A |
112 | void verifyFieldPosition( |
113 | const char *description, | |
114 | const MeasureFormat &fmt, | |
115 | const UnicodeString &prefix, | |
116 | const Measure *measures, | |
117 | int32_t measureCount, | |
118 | NumberFormat::EAlignmentFields field, | |
119 | int32_t start, | |
120 | int32_t end); | |
121 | }; | |
122 | ||
123 | void MeasureFormatTest::runIndexedTest( | |
124 | int32_t index, UBool exec, const char *&name, char *) { | |
125 | if (exec) { | |
126 | logln("TestSuite MeasureFormatTest: "); | |
127 | } | |
128 | TESTCASE_AUTO_BEGIN; | |
129 | TESTCASE_AUTO(TestBasic); | |
b331163b A |
130 | TESTCASE_AUTO(TestCompatible53_1); |
131 | TESTCASE_AUTO(TestCompatible54_1); | |
2ca993e8 A |
132 | TESTCASE_AUTO(TestCompatible55_1); |
133 | TESTCASE_AUTO(TestCompatible56_1); | |
134 | TESTCASE_AUTO(TestCompatible57_1); | |
57a6839d A |
135 | TESTCASE_AUTO(TestGetAvailable); |
136 | TESTCASE_AUTO(TestExamplesInDocs); | |
137 | TESTCASE_AUTO(TestFormatPeriodEn); | |
138 | TESTCASE_AUTO(Test10219FractionalPlurals); | |
139 | TESTCASE_AUTO(TestGreek); | |
140 | TESTCASE_AUTO(TestFormatSingleArg); | |
141 | TESTCASE_AUTO(TestFormatMeasuresZeroArg); | |
b331163b A |
142 | TESTCASE_AUTO(TestSimplePer); |
143 | TESTCASE_AUTO(TestNumeratorPlurals); | |
57a6839d | 144 | TESTCASE_AUTO(TestMultiples); |
2ca993e8 | 145 | TESTCASE_AUTO(TestManyLocaleDurations); |
57a6839d A |
146 | TESTCASE_AUTO(TestGram); |
147 | TESTCASE_AUTO(TestCurrencies); | |
148 | TESTCASE_AUTO(TestFieldPosition); | |
149 | TESTCASE_AUTO(TestFieldPositionMultiple); | |
150 | TESTCASE_AUTO(TestBadArg); | |
151 | TESTCASE_AUTO(TestEquality); | |
b331163b | 152 | TESTCASE_AUTO(TestGroupingSeparator); |
57a6839d | 153 | TESTCASE_AUTO(TestDoubleZero); |
b331163b | 154 | TESTCASE_AUTO(TestUnitPerUnitResolution); |
2ca993e8 | 155 | TESTCASE_AUTO(TestIndividualPluralFallback); |
57a6839d A |
156 | TESTCASE_AUTO_END; |
157 | } | |
158 | ||
b331163b A |
159 | void MeasureFormatTest::TestCompatible53_1() { |
160 | UErrorCode status = U_ZERO_ERROR; | |
161 | LocalPointer<MeasureUnit> measureUnit; | |
162 | measureUnit.adoptInstead(MeasureUnit::createGForce(status)); | |
163 | measureUnit.adoptInstead(MeasureUnit::createArcMinute(status)); | |
164 | measureUnit.adoptInstead(MeasureUnit::createArcSecond(status)); | |
165 | measureUnit.adoptInstead(MeasureUnit::createDegree(status)); | |
166 | measureUnit.adoptInstead(MeasureUnit::createAcre(status)); | |
167 | measureUnit.adoptInstead(MeasureUnit::createHectare(status)); | |
168 | measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status)); | |
169 | measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status)); | |
170 | measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status)); | |
171 | measureUnit.adoptInstead(MeasureUnit::createSquareMile(status)); | |
172 | measureUnit.adoptInstead(MeasureUnit::createDay(status)); | |
173 | measureUnit.adoptInstead(MeasureUnit::createHour(status)); | |
174 | measureUnit.adoptInstead(MeasureUnit::createMillisecond(status)); | |
175 | measureUnit.adoptInstead(MeasureUnit::createMinute(status)); | |
176 | measureUnit.adoptInstead(MeasureUnit::createMonth(status)); | |
177 | measureUnit.adoptInstead(MeasureUnit::createSecond(status)); | |
178 | measureUnit.adoptInstead(MeasureUnit::createWeek(status)); | |
179 | measureUnit.adoptInstead(MeasureUnit::createYear(status)); | |
180 | measureUnit.adoptInstead(MeasureUnit::createCentimeter(status)); | |
181 | measureUnit.adoptInstead(MeasureUnit::createFoot(status)); | |
182 | measureUnit.adoptInstead(MeasureUnit::createInch(status)); | |
183 | measureUnit.adoptInstead(MeasureUnit::createKilometer(status)); | |
184 | measureUnit.adoptInstead(MeasureUnit::createLightYear(status)); | |
185 | measureUnit.adoptInstead(MeasureUnit::createMeter(status)); | |
186 | measureUnit.adoptInstead(MeasureUnit::createMile(status)); | |
187 | measureUnit.adoptInstead(MeasureUnit::createMillimeter(status)); | |
188 | measureUnit.adoptInstead(MeasureUnit::createPicometer(status)); | |
189 | measureUnit.adoptInstead(MeasureUnit::createYard(status)); | |
190 | measureUnit.adoptInstead(MeasureUnit::createGram(status)); | |
191 | measureUnit.adoptInstead(MeasureUnit::createKilogram(status)); | |
192 | measureUnit.adoptInstead(MeasureUnit::createOunce(status)); | |
193 | measureUnit.adoptInstead(MeasureUnit::createPound(status)); | |
194 | measureUnit.adoptInstead(MeasureUnit::createHorsepower(status)); | |
195 | measureUnit.adoptInstead(MeasureUnit::createKilowatt(status)); | |
196 | measureUnit.adoptInstead(MeasureUnit::createWatt(status)); | |
197 | measureUnit.adoptInstead(MeasureUnit::createHectopascal(status)); | |
198 | measureUnit.adoptInstead(MeasureUnit::createInchHg(status)); | |
199 | measureUnit.adoptInstead(MeasureUnit::createMillibar(status)); | |
200 | measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status)); | |
201 | measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status)); | |
202 | measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status)); | |
203 | measureUnit.adoptInstead(MeasureUnit::createCelsius(status)); | |
204 | measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status)); | |
205 | measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status)); | |
206 | measureUnit.adoptInstead(MeasureUnit::createCubicMile(status)); | |
207 | measureUnit.adoptInstead(MeasureUnit::createLiter(status)); | |
208 | assertSuccess("", status); | |
209 | } | |
210 | ||
211 | void MeasureFormatTest::TestCompatible54_1() { | |
212 | UErrorCode status = U_ZERO_ERROR; | |
213 | LocalPointer<MeasureUnit> measureUnit; | |
214 | measureUnit.adoptInstead(MeasureUnit::createGForce(status)); | |
215 | measureUnit.adoptInstead(MeasureUnit::createMeterPerSecondSquared(status)); | |
216 | measureUnit.adoptInstead(MeasureUnit::createArcMinute(status)); | |
217 | measureUnit.adoptInstead(MeasureUnit::createArcSecond(status)); | |
218 | measureUnit.adoptInstead(MeasureUnit::createDegree(status)); | |
219 | measureUnit.adoptInstead(MeasureUnit::createRadian(status)); | |
220 | measureUnit.adoptInstead(MeasureUnit::createAcre(status)); | |
221 | measureUnit.adoptInstead(MeasureUnit::createHectare(status)); | |
222 | measureUnit.adoptInstead(MeasureUnit::createSquareCentimeter(status)); | |
223 | measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status)); | |
224 | measureUnit.adoptInstead(MeasureUnit::createSquareInch(status)); | |
225 | measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status)); | |
226 | measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status)); | |
227 | measureUnit.adoptInstead(MeasureUnit::createSquareMile(status)); | |
228 | measureUnit.adoptInstead(MeasureUnit::createSquareYard(status)); | |
229 | measureUnit.adoptInstead(MeasureUnit::createLiterPerKilometer(status)); | |
230 | measureUnit.adoptInstead(MeasureUnit::createMilePerGallon(status)); | |
231 | measureUnit.adoptInstead(MeasureUnit::createBit(status)); | |
232 | measureUnit.adoptInstead(MeasureUnit::createByte(status)); | |
233 | measureUnit.adoptInstead(MeasureUnit::createGigabit(status)); | |
234 | measureUnit.adoptInstead(MeasureUnit::createGigabyte(status)); | |
235 | measureUnit.adoptInstead(MeasureUnit::createKilobit(status)); | |
236 | measureUnit.adoptInstead(MeasureUnit::createKilobyte(status)); | |
237 | measureUnit.adoptInstead(MeasureUnit::createMegabit(status)); | |
238 | measureUnit.adoptInstead(MeasureUnit::createMegabyte(status)); | |
239 | measureUnit.adoptInstead(MeasureUnit::createTerabit(status)); | |
240 | measureUnit.adoptInstead(MeasureUnit::createTerabyte(status)); | |
241 | measureUnit.adoptInstead(MeasureUnit::createDay(status)); | |
242 | measureUnit.adoptInstead(MeasureUnit::createHour(status)); | |
243 | measureUnit.adoptInstead(MeasureUnit::createMicrosecond(status)); | |
244 | measureUnit.adoptInstead(MeasureUnit::createMillisecond(status)); | |
245 | measureUnit.adoptInstead(MeasureUnit::createMinute(status)); | |
246 | measureUnit.adoptInstead(MeasureUnit::createMonth(status)); | |
247 | measureUnit.adoptInstead(MeasureUnit::createNanosecond(status)); | |
248 | measureUnit.adoptInstead(MeasureUnit::createSecond(status)); | |
249 | measureUnit.adoptInstead(MeasureUnit::createWeek(status)); | |
250 | measureUnit.adoptInstead(MeasureUnit::createYear(status)); | |
251 | measureUnit.adoptInstead(MeasureUnit::createAmpere(status)); | |
252 | measureUnit.adoptInstead(MeasureUnit::createMilliampere(status)); | |
253 | measureUnit.adoptInstead(MeasureUnit::createOhm(status)); | |
254 | measureUnit.adoptInstead(MeasureUnit::createVolt(status)); | |
255 | measureUnit.adoptInstead(MeasureUnit::createCalorie(status)); | |
256 | measureUnit.adoptInstead(MeasureUnit::createFoodcalorie(status)); | |
257 | measureUnit.adoptInstead(MeasureUnit::createJoule(status)); | |
258 | measureUnit.adoptInstead(MeasureUnit::createKilocalorie(status)); | |
259 | measureUnit.adoptInstead(MeasureUnit::createKilojoule(status)); | |
260 | measureUnit.adoptInstead(MeasureUnit::createKilowattHour(status)); | |
261 | measureUnit.adoptInstead(MeasureUnit::createGigahertz(status)); | |
262 | measureUnit.adoptInstead(MeasureUnit::createHertz(status)); | |
263 | measureUnit.adoptInstead(MeasureUnit::createKilohertz(status)); | |
264 | measureUnit.adoptInstead(MeasureUnit::createMegahertz(status)); | |
265 | measureUnit.adoptInstead(MeasureUnit::createAstronomicalUnit(status)); | |
266 | measureUnit.adoptInstead(MeasureUnit::createCentimeter(status)); | |
267 | measureUnit.adoptInstead(MeasureUnit::createDecimeter(status)); | |
268 | measureUnit.adoptInstead(MeasureUnit::createFathom(status)); | |
269 | measureUnit.adoptInstead(MeasureUnit::createFoot(status)); | |
270 | measureUnit.adoptInstead(MeasureUnit::createFurlong(status)); | |
271 | measureUnit.adoptInstead(MeasureUnit::createInch(status)); | |
272 | measureUnit.adoptInstead(MeasureUnit::createKilometer(status)); | |
273 | measureUnit.adoptInstead(MeasureUnit::createLightYear(status)); | |
274 | measureUnit.adoptInstead(MeasureUnit::createMeter(status)); | |
275 | measureUnit.adoptInstead(MeasureUnit::createMicrometer(status)); | |
276 | measureUnit.adoptInstead(MeasureUnit::createMile(status)); | |
277 | measureUnit.adoptInstead(MeasureUnit::createMillimeter(status)); | |
278 | measureUnit.adoptInstead(MeasureUnit::createNanometer(status)); | |
279 | measureUnit.adoptInstead(MeasureUnit::createNauticalMile(status)); | |
280 | measureUnit.adoptInstead(MeasureUnit::createParsec(status)); | |
281 | measureUnit.adoptInstead(MeasureUnit::createPicometer(status)); | |
282 | measureUnit.adoptInstead(MeasureUnit::createYard(status)); | |
283 | measureUnit.adoptInstead(MeasureUnit::createLux(status)); | |
284 | measureUnit.adoptInstead(MeasureUnit::createCarat(status)); | |
285 | measureUnit.adoptInstead(MeasureUnit::createGram(status)); | |
286 | measureUnit.adoptInstead(MeasureUnit::createKilogram(status)); | |
287 | measureUnit.adoptInstead(MeasureUnit::createMetricTon(status)); | |
288 | measureUnit.adoptInstead(MeasureUnit::createMicrogram(status)); | |
289 | measureUnit.adoptInstead(MeasureUnit::createMilligram(status)); | |
290 | measureUnit.adoptInstead(MeasureUnit::createOunce(status)); | |
291 | measureUnit.adoptInstead(MeasureUnit::createOunceTroy(status)); | |
292 | measureUnit.adoptInstead(MeasureUnit::createPound(status)); | |
293 | measureUnit.adoptInstead(MeasureUnit::createStone(status)); | |
294 | measureUnit.adoptInstead(MeasureUnit::createTon(status)); | |
295 | measureUnit.adoptInstead(MeasureUnit::createGigawatt(status)); | |
296 | measureUnit.adoptInstead(MeasureUnit::createHorsepower(status)); | |
297 | measureUnit.adoptInstead(MeasureUnit::createKilowatt(status)); | |
298 | measureUnit.adoptInstead(MeasureUnit::createMegawatt(status)); | |
299 | measureUnit.adoptInstead(MeasureUnit::createMilliwatt(status)); | |
300 | measureUnit.adoptInstead(MeasureUnit::createWatt(status)); | |
301 | measureUnit.adoptInstead(MeasureUnit::createHectopascal(status)); | |
302 | measureUnit.adoptInstead(MeasureUnit::createInchHg(status)); | |
303 | measureUnit.adoptInstead(MeasureUnit::createMillibar(status)); | |
304 | measureUnit.adoptInstead(MeasureUnit::createMillimeterOfMercury(status)); | |
305 | measureUnit.adoptInstead(MeasureUnit::createPoundPerSquareInch(status)); | |
306 | measureUnit.adoptInstead(MeasureUnit::createKarat(status)); | |
307 | measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status)); | |
308 | measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status)); | |
309 | measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status)); | |
310 | measureUnit.adoptInstead(MeasureUnit::createCelsius(status)); | |
311 | measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status)); | |
312 | measureUnit.adoptInstead(MeasureUnit::createKelvin(status)); | |
313 | measureUnit.adoptInstead(MeasureUnit::createAcreFoot(status)); | |
314 | measureUnit.adoptInstead(MeasureUnit::createBushel(status)); | |
315 | measureUnit.adoptInstead(MeasureUnit::createCentiliter(status)); | |
316 | measureUnit.adoptInstead(MeasureUnit::createCubicCentimeter(status)); | |
317 | measureUnit.adoptInstead(MeasureUnit::createCubicFoot(status)); | |
318 | measureUnit.adoptInstead(MeasureUnit::createCubicInch(status)); | |
319 | measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status)); | |
320 | measureUnit.adoptInstead(MeasureUnit::createCubicMeter(status)); | |
321 | measureUnit.adoptInstead(MeasureUnit::createCubicMile(status)); | |
322 | measureUnit.adoptInstead(MeasureUnit::createCubicYard(status)); | |
323 | measureUnit.adoptInstead(MeasureUnit::createCup(status)); | |
324 | measureUnit.adoptInstead(MeasureUnit::createDeciliter(status)); | |
325 | measureUnit.adoptInstead(MeasureUnit::createFluidOunce(status)); | |
326 | measureUnit.adoptInstead(MeasureUnit::createGallon(status)); | |
327 | measureUnit.adoptInstead(MeasureUnit::createHectoliter(status)); | |
328 | measureUnit.adoptInstead(MeasureUnit::createLiter(status)); | |
329 | measureUnit.adoptInstead(MeasureUnit::createMegaliter(status)); | |
330 | measureUnit.adoptInstead(MeasureUnit::createMilliliter(status)); | |
331 | measureUnit.adoptInstead(MeasureUnit::createPint(status)); | |
332 | measureUnit.adoptInstead(MeasureUnit::createQuart(status)); | |
333 | measureUnit.adoptInstead(MeasureUnit::createTablespoon(status)); | |
334 | measureUnit.adoptInstead(MeasureUnit::createTeaspoon(status)); | |
335 | assertSuccess("", status); | |
336 | } | |
337 | ||
2ca993e8 A |
338 | void MeasureFormatTest::TestCompatible55_1() { |
339 | UErrorCode status = U_ZERO_ERROR; | |
340 | LocalPointer<MeasureUnit> measureUnit; | |
341 | measureUnit.adoptInstead(MeasureUnit::createGForce(status)); | |
342 | measureUnit.adoptInstead(MeasureUnit::createMeterPerSecondSquared(status)); | |
343 | measureUnit.adoptInstead(MeasureUnit::createArcMinute(status)); | |
344 | measureUnit.adoptInstead(MeasureUnit::createArcSecond(status)); | |
345 | measureUnit.adoptInstead(MeasureUnit::createDegree(status)); | |
346 | measureUnit.adoptInstead(MeasureUnit::createRadian(status)); | |
347 | measureUnit.adoptInstead(MeasureUnit::createAcre(status)); | |
348 | measureUnit.adoptInstead(MeasureUnit::createHectare(status)); | |
349 | measureUnit.adoptInstead(MeasureUnit::createSquareCentimeter(status)); | |
350 | measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status)); | |
351 | measureUnit.adoptInstead(MeasureUnit::createSquareInch(status)); | |
352 | measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status)); | |
353 | measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status)); | |
354 | measureUnit.adoptInstead(MeasureUnit::createSquareMile(status)); | |
355 | measureUnit.adoptInstead(MeasureUnit::createSquareYard(status)); | |
356 | measureUnit.adoptInstead(MeasureUnit::createLiterPerKilometer(status)); | |
357 | measureUnit.adoptInstead(MeasureUnit::createMilePerGallon(status)); | |
358 | measureUnit.adoptInstead(MeasureUnit::createBit(status)); | |
359 | measureUnit.adoptInstead(MeasureUnit::createByte(status)); | |
360 | measureUnit.adoptInstead(MeasureUnit::createGigabit(status)); | |
361 | measureUnit.adoptInstead(MeasureUnit::createGigabyte(status)); | |
362 | measureUnit.adoptInstead(MeasureUnit::createKilobit(status)); | |
363 | measureUnit.adoptInstead(MeasureUnit::createKilobyte(status)); | |
364 | measureUnit.adoptInstead(MeasureUnit::createMegabit(status)); | |
365 | measureUnit.adoptInstead(MeasureUnit::createMegabyte(status)); | |
366 | measureUnit.adoptInstead(MeasureUnit::createTerabit(status)); | |
367 | measureUnit.adoptInstead(MeasureUnit::createTerabyte(status)); | |
368 | measureUnit.adoptInstead(MeasureUnit::createDay(status)); | |
369 | measureUnit.adoptInstead(MeasureUnit::createHour(status)); | |
370 | measureUnit.adoptInstead(MeasureUnit::createMicrosecond(status)); | |
371 | measureUnit.adoptInstead(MeasureUnit::createMillisecond(status)); | |
372 | measureUnit.adoptInstead(MeasureUnit::createMinute(status)); | |
373 | measureUnit.adoptInstead(MeasureUnit::createMonth(status)); | |
374 | measureUnit.adoptInstead(MeasureUnit::createNanosecond(status)); | |
375 | measureUnit.adoptInstead(MeasureUnit::createSecond(status)); | |
376 | measureUnit.adoptInstead(MeasureUnit::createWeek(status)); | |
377 | measureUnit.adoptInstead(MeasureUnit::createYear(status)); | |
378 | measureUnit.adoptInstead(MeasureUnit::createAmpere(status)); | |
379 | measureUnit.adoptInstead(MeasureUnit::createMilliampere(status)); | |
380 | measureUnit.adoptInstead(MeasureUnit::createOhm(status)); | |
381 | measureUnit.adoptInstead(MeasureUnit::createVolt(status)); | |
382 | measureUnit.adoptInstead(MeasureUnit::createCalorie(status)); | |
383 | measureUnit.adoptInstead(MeasureUnit::createFoodcalorie(status)); | |
384 | measureUnit.adoptInstead(MeasureUnit::createJoule(status)); | |
385 | measureUnit.adoptInstead(MeasureUnit::createKilocalorie(status)); | |
386 | measureUnit.adoptInstead(MeasureUnit::createKilojoule(status)); | |
387 | measureUnit.adoptInstead(MeasureUnit::createKilowattHour(status)); | |
388 | measureUnit.adoptInstead(MeasureUnit::createGigahertz(status)); | |
389 | measureUnit.adoptInstead(MeasureUnit::createHertz(status)); | |
390 | measureUnit.adoptInstead(MeasureUnit::createKilohertz(status)); | |
391 | measureUnit.adoptInstead(MeasureUnit::createMegahertz(status)); | |
392 | measureUnit.adoptInstead(MeasureUnit::createAstronomicalUnit(status)); | |
393 | measureUnit.adoptInstead(MeasureUnit::createCentimeter(status)); | |
394 | measureUnit.adoptInstead(MeasureUnit::createDecimeter(status)); | |
395 | measureUnit.adoptInstead(MeasureUnit::createFathom(status)); | |
396 | measureUnit.adoptInstead(MeasureUnit::createFoot(status)); | |
397 | measureUnit.adoptInstead(MeasureUnit::createFurlong(status)); | |
398 | measureUnit.adoptInstead(MeasureUnit::createInch(status)); | |
399 | measureUnit.adoptInstead(MeasureUnit::createKilometer(status)); | |
400 | measureUnit.adoptInstead(MeasureUnit::createLightYear(status)); | |
401 | measureUnit.adoptInstead(MeasureUnit::createMeter(status)); | |
402 | measureUnit.adoptInstead(MeasureUnit::createMicrometer(status)); | |
403 | measureUnit.adoptInstead(MeasureUnit::createMile(status)); | |
404 | measureUnit.adoptInstead(MeasureUnit::createMillimeter(status)); | |
405 | measureUnit.adoptInstead(MeasureUnit::createNanometer(status)); | |
406 | measureUnit.adoptInstead(MeasureUnit::createNauticalMile(status)); | |
407 | measureUnit.adoptInstead(MeasureUnit::createParsec(status)); | |
408 | measureUnit.adoptInstead(MeasureUnit::createPicometer(status)); | |
409 | measureUnit.adoptInstead(MeasureUnit::createYard(status)); | |
410 | measureUnit.adoptInstead(MeasureUnit::createLux(status)); | |
411 | measureUnit.adoptInstead(MeasureUnit::createCarat(status)); | |
412 | measureUnit.adoptInstead(MeasureUnit::createGram(status)); | |
413 | measureUnit.adoptInstead(MeasureUnit::createKilogram(status)); | |
414 | measureUnit.adoptInstead(MeasureUnit::createMetricTon(status)); | |
415 | measureUnit.adoptInstead(MeasureUnit::createMicrogram(status)); | |
416 | measureUnit.adoptInstead(MeasureUnit::createMilligram(status)); | |
417 | measureUnit.adoptInstead(MeasureUnit::createOunce(status)); | |
418 | measureUnit.adoptInstead(MeasureUnit::createOunceTroy(status)); | |
419 | measureUnit.adoptInstead(MeasureUnit::createPound(status)); | |
420 | measureUnit.adoptInstead(MeasureUnit::createStone(status)); | |
421 | measureUnit.adoptInstead(MeasureUnit::createTon(status)); | |
422 | measureUnit.adoptInstead(MeasureUnit::createGigawatt(status)); | |
423 | measureUnit.adoptInstead(MeasureUnit::createHorsepower(status)); | |
424 | measureUnit.adoptInstead(MeasureUnit::createKilowatt(status)); | |
425 | measureUnit.adoptInstead(MeasureUnit::createMegawatt(status)); | |
426 | measureUnit.adoptInstead(MeasureUnit::createMilliwatt(status)); | |
427 | measureUnit.adoptInstead(MeasureUnit::createWatt(status)); | |
428 | measureUnit.adoptInstead(MeasureUnit::createHectopascal(status)); | |
429 | measureUnit.adoptInstead(MeasureUnit::createInchHg(status)); | |
430 | measureUnit.adoptInstead(MeasureUnit::createMillibar(status)); | |
431 | measureUnit.adoptInstead(MeasureUnit::createMillimeterOfMercury(status)); | |
432 | measureUnit.adoptInstead(MeasureUnit::createPoundPerSquareInch(status)); | |
433 | measureUnit.adoptInstead(MeasureUnit::createKarat(status)); | |
434 | measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status)); | |
435 | measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status)); | |
436 | measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status)); | |
437 | measureUnit.adoptInstead(MeasureUnit::createCelsius(status)); | |
438 | measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status)); | |
439 | measureUnit.adoptInstead(MeasureUnit::createGenericTemperature(status)); | |
440 | measureUnit.adoptInstead(MeasureUnit::createKelvin(status)); | |
441 | measureUnit.adoptInstead(MeasureUnit::createAcreFoot(status)); | |
442 | measureUnit.adoptInstead(MeasureUnit::createBushel(status)); | |
443 | measureUnit.adoptInstead(MeasureUnit::createCentiliter(status)); | |
444 | measureUnit.adoptInstead(MeasureUnit::createCubicCentimeter(status)); | |
445 | measureUnit.adoptInstead(MeasureUnit::createCubicFoot(status)); | |
446 | measureUnit.adoptInstead(MeasureUnit::createCubicInch(status)); | |
447 | measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status)); | |
448 | measureUnit.adoptInstead(MeasureUnit::createCubicMeter(status)); | |
449 | measureUnit.adoptInstead(MeasureUnit::createCubicMile(status)); | |
450 | measureUnit.adoptInstead(MeasureUnit::createCubicYard(status)); | |
451 | measureUnit.adoptInstead(MeasureUnit::createCup(status)); | |
452 | measureUnit.adoptInstead(MeasureUnit::createDeciliter(status)); | |
453 | measureUnit.adoptInstead(MeasureUnit::createFluidOunce(status)); | |
454 | measureUnit.adoptInstead(MeasureUnit::createGallon(status)); | |
455 | measureUnit.adoptInstead(MeasureUnit::createHectoliter(status)); | |
456 | measureUnit.adoptInstead(MeasureUnit::createLiter(status)); | |
457 | measureUnit.adoptInstead(MeasureUnit::createMegaliter(status)); | |
458 | measureUnit.adoptInstead(MeasureUnit::createMilliliter(status)); | |
459 | measureUnit.adoptInstead(MeasureUnit::createPint(status)); | |
460 | measureUnit.adoptInstead(MeasureUnit::createQuart(status)); | |
461 | measureUnit.adoptInstead(MeasureUnit::createTablespoon(status)); | |
462 | measureUnit.adoptInstead(MeasureUnit::createTeaspoon(status)); | |
463 | assertSuccess("", status); | |
464 | } | |
465 | ||
466 | void MeasureFormatTest::TestCompatible56_1() { | |
467 | UErrorCode status = U_ZERO_ERROR; | |
468 | LocalPointer<MeasureUnit> measureUnit; | |
469 | measureUnit.adoptInstead(MeasureUnit::createGForce(status)); | |
470 | measureUnit.adoptInstead(MeasureUnit::createMeterPerSecondSquared(status)); | |
471 | measureUnit.adoptInstead(MeasureUnit::createArcMinute(status)); | |
472 | measureUnit.adoptInstead(MeasureUnit::createArcSecond(status)); | |
473 | measureUnit.adoptInstead(MeasureUnit::createDegree(status)); | |
474 | measureUnit.adoptInstead(MeasureUnit::createRadian(status)); | |
475 | measureUnit.adoptInstead(MeasureUnit::createRevolutionAngle(status)); | |
476 | measureUnit.adoptInstead(MeasureUnit::createAcre(status)); | |
477 | measureUnit.adoptInstead(MeasureUnit::createHectare(status)); | |
478 | measureUnit.adoptInstead(MeasureUnit::createSquareCentimeter(status)); | |
479 | measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status)); | |
480 | measureUnit.adoptInstead(MeasureUnit::createSquareInch(status)); | |
481 | measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status)); | |
482 | measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status)); | |
483 | measureUnit.adoptInstead(MeasureUnit::createSquareMile(status)); | |
484 | measureUnit.adoptInstead(MeasureUnit::createSquareYard(status)); | |
485 | measureUnit.adoptInstead(MeasureUnit::createLiterPer100Kilometers(status)); | |
486 | measureUnit.adoptInstead(MeasureUnit::createLiterPerKilometer(status)); | |
487 | measureUnit.adoptInstead(MeasureUnit::createMilePerGallon(status)); | |
488 | measureUnit.adoptInstead(MeasureUnit::createBit(status)); | |
489 | measureUnit.adoptInstead(MeasureUnit::createByte(status)); | |
490 | measureUnit.adoptInstead(MeasureUnit::createGigabit(status)); | |
491 | measureUnit.adoptInstead(MeasureUnit::createGigabyte(status)); | |
492 | measureUnit.adoptInstead(MeasureUnit::createKilobit(status)); | |
493 | measureUnit.adoptInstead(MeasureUnit::createKilobyte(status)); | |
494 | measureUnit.adoptInstead(MeasureUnit::createMegabit(status)); | |
495 | measureUnit.adoptInstead(MeasureUnit::createMegabyte(status)); | |
496 | measureUnit.adoptInstead(MeasureUnit::createTerabit(status)); | |
497 | measureUnit.adoptInstead(MeasureUnit::createTerabyte(status)); | |
498 | measureUnit.adoptInstead(MeasureUnit::createCentury(status)); | |
499 | measureUnit.adoptInstead(MeasureUnit::createDay(status)); | |
500 | measureUnit.adoptInstead(MeasureUnit::createHour(status)); | |
501 | measureUnit.adoptInstead(MeasureUnit::createMicrosecond(status)); | |
502 | measureUnit.adoptInstead(MeasureUnit::createMillisecond(status)); | |
503 | measureUnit.adoptInstead(MeasureUnit::createMinute(status)); | |
504 | measureUnit.adoptInstead(MeasureUnit::createMonth(status)); | |
505 | measureUnit.adoptInstead(MeasureUnit::createNanosecond(status)); | |
506 | measureUnit.adoptInstead(MeasureUnit::createSecond(status)); | |
507 | measureUnit.adoptInstead(MeasureUnit::createWeek(status)); | |
508 | measureUnit.adoptInstead(MeasureUnit::createYear(status)); | |
509 | measureUnit.adoptInstead(MeasureUnit::createAmpere(status)); | |
510 | measureUnit.adoptInstead(MeasureUnit::createMilliampere(status)); | |
511 | measureUnit.adoptInstead(MeasureUnit::createOhm(status)); | |
512 | measureUnit.adoptInstead(MeasureUnit::createVolt(status)); | |
513 | measureUnit.adoptInstead(MeasureUnit::createCalorie(status)); | |
514 | measureUnit.adoptInstead(MeasureUnit::createFoodcalorie(status)); | |
515 | measureUnit.adoptInstead(MeasureUnit::createJoule(status)); | |
516 | measureUnit.adoptInstead(MeasureUnit::createKilocalorie(status)); | |
517 | measureUnit.adoptInstead(MeasureUnit::createKilojoule(status)); | |
518 | measureUnit.adoptInstead(MeasureUnit::createKilowattHour(status)); | |
519 | measureUnit.adoptInstead(MeasureUnit::createGigahertz(status)); | |
520 | measureUnit.adoptInstead(MeasureUnit::createHertz(status)); | |
521 | measureUnit.adoptInstead(MeasureUnit::createKilohertz(status)); | |
522 | measureUnit.adoptInstead(MeasureUnit::createMegahertz(status)); | |
523 | measureUnit.adoptInstead(MeasureUnit::createAstronomicalUnit(status)); | |
524 | measureUnit.adoptInstead(MeasureUnit::createCentimeter(status)); | |
525 | measureUnit.adoptInstead(MeasureUnit::createDecimeter(status)); | |
526 | measureUnit.adoptInstead(MeasureUnit::createFathom(status)); | |
527 | measureUnit.adoptInstead(MeasureUnit::createFoot(status)); | |
528 | measureUnit.adoptInstead(MeasureUnit::createFurlong(status)); | |
529 | measureUnit.adoptInstead(MeasureUnit::createInch(status)); | |
530 | measureUnit.adoptInstead(MeasureUnit::createKilometer(status)); | |
531 | measureUnit.adoptInstead(MeasureUnit::createLightYear(status)); | |
532 | measureUnit.adoptInstead(MeasureUnit::createMeter(status)); | |
533 | measureUnit.adoptInstead(MeasureUnit::createMicrometer(status)); | |
534 | measureUnit.adoptInstead(MeasureUnit::createMile(status)); | |
535 | measureUnit.adoptInstead(MeasureUnit::createMileScandinavian(status)); | |
536 | measureUnit.adoptInstead(MeasureUnit::createMillimeter(status)); | |
537 | measureUnit.adoptInstead(MeasureUnit::createNanometer(status)); | |
538 | measureUnit.adoptInstead(MeasureUnit::createNauticalMile(status)); | |
539 | measureUnit.adoptInstead(MeasureUnit::createParsec(status)); | |
540 | measureUnit.adoptInstead(MeasureUnit::createPicometer(status)); | |
541 | measureUnit.adoptInstead(MeasureUnit::createYard(status)); | |
542 | measureUnit.adoptInstead(MeasureUnit::createLux(status)); | |
543 | measureUnit.adoptInstead(MeasureUnit::createCarat(status)); | |
544 | measureUnit.adoptInstead(MeasureUnit::createGram(status)); | |
545 | measureUnit.adoptInstead(MeasureUnit::createKilogram(status)); | |
546 | measureUnit.adoptInstead(MeasureUnit::createMetricTon(status)); | |
547 | measureUnit.adoptInstead(MeasureUnit::createMicrogram(status)); | |
548 | measureUnit.adoptInstead(MeasureUnit::createMilligram(status)); | |
549 | measureUnit.adoptInstead(MeasureUnit::createOunce(status)); | |
550 | measureUnit.adoptInstead(MeasureUnit::createOunceTroy(status)); | |
551 | measureUnit.adoptInstead(MeasureUnit::createPound(status)); | |
552 | measureUnit.adoptInstead(MeasureUnit::createStone(status)); | |
553 | measureUnit.adoptInstead(MeasureUnit::createTon(status)); | |
554 | measureUnit.adoptInstead(MeasureUnit::createGigawatt(status)); | |
555 | measureUnit.adoptInstead(MeasureUnit::createHorsepower(status)); | |
556 | measureUnit.adoptInstead(MeasureUnit::createKilowatt(status)); | |
557 | measureUnit.adoptInstead(MeasureUnit::createMegawatt(status)); | |
558 | measureUnit.adoptInstead(MeasureUnit::createMilliwatt(status)); | |
559 | measureUnit.adoptInstead(MeasureUnit::createWatt(status)); | |
560 | measureUnit.adoptInstead(MeasureUnit::createHectopascal(status)); | |
561 | measureUnit.adoptInstead(MeasureUnit::createInchHg(status)); | |
562 | measureUnit.adoptInstead(MeasureUnit::createMillibar(status)); | |
563 | measureUnit.adoptInstead(MeasureUnit::createMillimeterOfMercury(status)); | |
564 | measureUnit.adoptInstead(MeasureUnit::createPoundPerSquareInch(status)); | |
565 | measureUnit.adoptInstead(MeasureUnit::createKarat(status)); | |
566 | measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status)); | |
567 | measureUnit.adoptInstead(MeasureUnit::createKnot(status)); | |
568 | measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status)); | |
569 | measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status)); | |
570 | measureUnit.adoptInstead(MeasureUnit::createCelsius(status)); | |
571 | measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status)); | |
572 | measureUnit.adoptInstead(MeasureUnit::createGenericTemperature(status)); | |
573 | measureUnit.adoptInstead(MeasureUnit::createKelvin(status)); | |
574 | measureUnit.adoptInstead(MeasureUnit::createAcreFoot(status)); | |
575 | measureUnit.adoptInstead(MeasureUnit::createBushel(status)); | |
576 | measureUnit.adoptInstead(MeasureUnit::createCentiliter(status)); | |
577 | measureUnit.adoptInstead(MeasureUnit::createCubicCentimeter(status)); | |
578 | measureUnit.adoptInstead(MeasureUnit::createCubicFoot(status)); | |
579 | measureUnit.adoptInstead(MeasureUnit::createCubicInch(status)); | |
580 | measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status)); | |
581 | measureUnit.adoptInstead(MeasureUnit::createCubicMeter(status)); | |
582 | measureUnit.adoptInstead(MeasureUnit::createCubicMile(status)); | |
583 | measureUnit.adoptInstead(MeasureUnit::createCubicYard(status)); | |
584 | measureUnit.adoptInstead(MeasureUnit::createCup(status)); | |
585 | measureUnit.adoptInstead(MeasureUnit::createCupMetric(status)); | |
586 | measureUnit.adoptInstead(MeasureUnit::createDeciliter(status)); | |
587 | measureUnit.adoptInstead(MeasureUnit::createFluidOunce(status)); | |
588 | measureUnit.adoptInstead(MeasureUnit::createGallon(status)); | |
589 | measureUnit.adoptInstead(MeasureUnit::createHectoliter(status)); | |
590 | measureUnit.adoptInstead(MeasureUnit::createLiter(status)); | |
591 | measureUnit.adoptInstead(MeasureUnit::createMegaliter(status)); | |
592 | measureUnit.adoptInstead(MeasureUnit::createMilliliter(status)); | |
593 | measureUnit.adoptInstead(MeasureUnit::createPint(status)); | |
594 | measureUnit.adoptInstead(MeasureUnit::createPintMetric(status)); | |
595 | measureUnit.adoptInstead(MeasureUnit::createQuart(status)); | |
596 | measureUnit.adoptInstead(MeasureUnit::createTablespoon(status)); | |
597 | measureUnit.adoptInstead(MeasureUnit::createTeaspoon(status)); | |
598 | assertSuccess("", status); | |
599 | } | |
600 | ||
601 | void MeasureFormatTest::TestCompatible57_1() { | |
602 | UErrorCode status = U_ZERO_ERROR; | |
603 | LocalPointer<MeasureUnit> measureUnit; | |
604 | measureUnit.adoptInstead(MeasureUnit::createGForce(status)); | |
605 | measureUnit.adoptInstead(MeasureUnit::createMeterPerSecondSquared(status)); | |
606 | measureUnit.adoptInstead(MeasureUnit::createArcMinute(status)); | |
607 | measureUnit.adoptInstead(MeasureUnit::createArcSecond(status)); | |
608 | measureUnit.adoptInstead(MeasureUnit::createDegree(status)); | |
609 | measureUnit.adoptInstead(MeasureUnit::createRadian(status)); | |
610 | measureUnit.adoptInstead(MeasureUnit::createRevolutionAngle(status)); | |
611 | measureUnit.adoptInstead(MeasureUnit::createAcre(status)); | |
612 | measureUnit.adoptInstead(MeasureUnit::createHectare(status)); | |
613 | measureUnit.adoptInstead(MeasureUnit::createSquareCentimeter(status)); | |
614 | measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status)); | |
615 | measureUnit.adoptInstead(MeasureUnit::createSquareInch(status)); | |
616 | measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status)); | |
617 | measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status)); | |
618 | measureUnit.adoptInstead(MeasureUnit::createSquareMile(status)); | |
619 | measureUnit.adoptInstead(MeasureUnit::createSquareYard(status)); | |
620 | measureUnit.adoptInstead(MeasureUnit::createKarat(status)); | |
621 | measureUnit.adoptInstead(MeasureUnit::createMilligramPerDeciliter(status)); | |
622 | measureUnit.adoptInstead(MeasureUnit::createMillimolePerLiter(status)); | |
623 | measureUnit.adoptInstead(MeasureUnit::createPartPerMillion(status)); | |
624 | measureUnit.adoptInstead(MeasureUnit::createLiterPer100Kilometers(status)); | |
625 | measureUnit.adoptInstead(MeasureUnit::createLiterPerKilometer(status)); | |
626 | measureUnit.adoptInstead(MeasureUnit::createMilePerGallon(status)); | |
627 | measureUnit.adoptInstead(MeasureUnit::createMilePerGallonImperial(status)); | |
628 | measureUnit.adoptInstead(MeasureUnit::createBit(status)); | |
629 | measureUnit.adoptInstead(MeasureUnit::createByte(status)); | |
630 | measureUnit.adoptInstead(MeasureUnit::createGigabit(status)); | |
631 | measureUnit.adoptInstead(MeasureUnit::createGigabyte(status)); | |
632 | measureUnit.adoptInstead(MeasureUnit::createKilobit(status)); | |
633 | measureUnit.adoptInstead(MeasureUnit::createKilobyte(status)); | |
634 | measureUnit.adoptInstead(MeasureUnit::createMegabit(status)); | |
635 | measureUnit.adoptInstead(MeasureUnit::createMegabyte(status)); | |
636 | measureUnit.adoptInstead(MeasureUnit::createTerabit(status)); | |
637 | measureUnit.adoptInstead(MeasureUnit::createTerabyte(status)); | |
638 | measureUnit.adoptInstead(MeasureUnit::createCentury(status)); | |
639 | measureUnit.adoptInstead(MeasureUnit::createDay(status)); | |
640 | measureUnit.adoptInstead(MeasureUnit::createHour(status)); | |
641 | measureUnit.adoptInstead(MeasureUnit::createMicrosecond(status)); | |
642 | measureUnit.adoptInstead(MeasureUnit::createMillisecond(status)); | |
643 | measureUnit.adoptInstead(MeasureUnit::createMinute(status)); | |
644 | measureUnit.adoptInstead(MeasureUnit::createMonth(status)); | |
645 | measureUnit.adoptInstead(MeasureUnit::createNanosecond(status)); | |
646 | measureUnit.adoptInstead(MeasureUnit::createSecond(status)); | |
647 | measureUnit.adoptInstead(MeasureUnit::createWeek(status)); | |
648 | measureUnit.adoptInstead(MeasureUnit::createYear(status)); | |
649 | measureUnit.adoptInstead(MeasureUnit::createAmpere(status)); | |
650 | measureUnit.adoptInstead(MeasureUnit::createMilliampere(status)); | |
651 | measureUnit.adoptInstead(MeasureUnit::createOhm(status)); | |
652 | measureUnit.adoptInstead(MeasureUnit::createVolt(status)); | |
653 | measureUnit.adoptInstead(MeasureUnit::createCalorie(status)); | |
654 | measureUnit.adoptInstead(MeasureUnit::createFoodcalorie(status)); | |
655 | measureUnit.adoptInstead(MeasureUnit::createJoule(status)); | |
656 | measureUnit.adoptInstead(MeasureUnit::createKilocalorie(status)); | |
657 | measureUnit.adoptInstead(MeasureUnit::createKilojoule(status)); | |
658 | measureUnit.adoptInstead(MeasureUnit::createKilowattHour(status)); | |
659 | measureUnit.adoptInstead(MeasureUnit::createGigahertz(status)); | |
660 | measureUnit.adoptInstead(MeasureUnit::createHertz(status)); | |
661 | measureUnit.adoptInstead(MeasureUnit::createKilohertz(status)); | |
662 | measureUnit.adoptInstead(MeasureUnit::createMegahertz(status)); | |
663 | measureUnit.adoptInstead(MeasureUnit::createAstronomicalUnit(status)); | |
664 | measureUnit.adoptInstead(MeasureUnit::createCentimeter(status)); | |
665 | measureUnit.adoptInstead(MeasureUnit::createDecimeter(status)); | |
666 | measureUnit.adoptInstead(MeasureUnit::createFathom(status)); | |
667 | measureUnit.adoptInstead(MeasureUnit::createFoot(status)); | |
668 | measureUnit.adoptInstead(MeasureUnit::createFurlong(status)); | |
669 | measureUnit.adoptInstead(MeasureUnit::createInch(status)); | |
670 | measureUnit.adoptInstead(MeasureUnit::createKilometer(status)); | |
671 | measureUnit.adoptInstead(MeasureUnit::createLightYear(status)); | |
672 | measureUnit.adoptInstead(MeasureUnit::createMeter(status)); | |
673 | measureUnit.adoptInstead(MeasureUnit::createMicrometer(status)); | |
674 | measureUnit.adoptInstead(MeasureUnit::createMile(status)); | |
675 | measureUnit.adoptInstead(MeasureUnit::createMileScandinavian(status)); | |
676 | measureUnit.adoptInstead(MeasureUnit::createMillimeter(status)); | |
677 | measureUnit.adoptInstead(MeasureUnit::createNanometer(status)); | |
678 | measureUnit.adoptInstead(MeasureUnit::createNauticalMile(status)); | |
679 | measureUnit.adoptInstead(MeasureUnit::createParsec(status)); | |
680 | measureUnit.adoptInstead(MeasureUnit::createPicometer(status)); | |
681 | measureUnit.adoptInstead(MeasureUnit::createYard(status)); | |
682 | measureUnit.adoptInstead(MeasureUnit::createLux(status)); | |
683 | measureUnit.adoptInstead(MeasureUnit::createCarat(status)); | |
684 | measureUnit.adoptInstead(MeasureUnit::createGram(status)); | |
685 | measureUnit.adoptInstead(MeasureUnit::createKilogram(status)); | |
686 | measureUnit.adoptInstead(MeasureUnit::createMetricTon(status)); | |
687 | measureUnit.adoptInstead(MeasureUnit::createMicrogram(status)); | |
688 | measureUnit.adoptInstead(MeasureUnit::createMilligram(status)); | |
689 | measureUnit.adoptInstead(MeasureUnit::createOunce(status)); | |
690 | measureUnit.adoptInstead(MeasureUnit::createOunceTroy(status)); | |
691 | measureUnit.adoptInstead(MeasureUnit::createPound(status)); | |
692 | measureUnit.adoptInstead(MeasureUnit::createStone(status)); | |
693 | measureUnit.adoptInstead(MeasureUnit::createTon(status)); | |
694 | measureUnit.adoptInstead(MeasureUnit::createGigawatt(status)); | |
695 | measureUnit.adoptInstead(MeasureUnit::createHorsepower(status)); | |
696 | measureUnit.adoptInstead(MeasureUnit::createKilowatt(status)); | |
697 | measureUnit.adoptInstead(MeasureUnit::createMegawatt(status)); | |
698 | measureUnit.adoptInstead(MeasureUnit::createMilliwatt(status)); | |
699 | measureUnit.adoptInstead(MeasureUnit::createWatt(status)); | |
700 | measureUnit.adoptInstead(MeasureUnit::createHectopascal(status)); | |
701 | measureUnit.adoptInstead(MeasureUnit::createInchHg(status)); | |
702 | measureUnit.adoptInstead(MeasureUnit::createMillibar(status)); | |
703 | measureUnit.adoptInstead(MeasureUnit::createMillimeterOfMercury(status)); | |
704 | measureUnit.adoptInstead(MeasureUnit::createPoundPerSquareInch(status)); | |
705 | measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status)); | |
706 | measureUnit.adoptInstead(MeasureUnit::createKnot(status)); | |
707 | measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status)); | |
708 | measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status)); | |
709 | measureUnit.adoptInstead(MeasureUnit::createCelsius(status)); | |
710 | measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status)); | |
711 | measureUnit.adoptInstead(MeasureUnit::createGenericTemperature(status)); | |
712 | measureUnit.adoptInstead(MeasureUnit::createKelvin(status)); | |
713 | measureUnit.adoptInstead(MeasureUnit::createAcreFoot(status)); | |
714 | measureUnit.adoptInstead(MeasureUnit::createBushel(status)); | |
715 | measureUnit.adoptInstead(MeasureUnit::createCentiliter(status)); | |
716 | measureUnit.adoptInstead(MeasureUnit::createCubicCentimeter(status)); | |
717 | measureUnit.adoptInstead(MeasureUnit::createCubicFoot(status)); | |
718 | measureUnit.adoptInstead(MeasureUnit::createCubicInch(status)); | |
719 | measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status)); | |
720 | measureUnit.adoptInstead(MeasureUnit::createCubicMeter(status)); | |
721 | measureUnit.adoptInstead(MeasureUnit::createCubicMile(status)); | |
722 | measureUnit.adoptInstead(MeasureUnit::createCubicYard(status)); | |
723 | measureUnit.adoptInstead(MeasureUnit::createCup(status)); | |
724 | measureUnit.adoptInstead(MeasureUnit::createCupMetric(status)); | |
725 | measureUnit.adoptInstead(MeasureUnit::createDeciliter(status)); | |
726 | measureUnit.adoptInstead(MeasureUnit::createFluidOunce(status)); | |
727 | measureUnit.adoptInstead(MeasureUnit::createGallon(status)); | |
728 | measureUnit.adoptInstead(MeasureUnit::createGallonImperial(status)); | |
729 | measureUnit.adoptInstead(MeasureUnit::createHectoliter(status)); | |
730 | measureUnit.adoptInstead(MeasureUnit::createLiter(status)); | |
731 | measureUnit.adoptInstead(MeasureUnit::createMegaliter(status)); | |
732 | measureUnit.adoptInstead(MeasureUnit::createMilliliter(status)); | |
733 | measureUnit.adoptInstead(MeasureUnit::createPint(status)); | |
734 | measureUnit.adoptInstead(MeasureUnit::createPintMetric(status)); | |
735 | measureUnit.adoptInstead(MeasureUnit::createQuart(status)); | |
736 | measureUnit.adoptInstead(MeasureUnit::createTablespoon(status)); | |
737 | measureUnit.adoptInstead(MeasureUnit::createTeaspoon(status)); | |
738 | assertSuccess("", status); | |
739 | } | |
740 | ||
57a6839d A |
741 | void MeasureFormatTest::TestBasic() { |
742 | UErrorCode status = U_ZERO_ERROR; | |
743 | MeasureUnit *ptr1 = MeasureUnit::createArcMinute(status); | |
744 | MeasureUnit *ptr2 = MeasureUnit::createArcMinute(status); | |
745 | if (!(*ptr1 == *ptr2)) { | |
746 | errln("Expect == to work."); | |
747 | } | |
748 | if (*ptr1 != *ptr2) { | |
749 | errln("Expect != to work."); | |
750 | } | |
751 | MeasureUnit *ptr3 = MeasureUnit::createMeter(status); | |
752 | if (*ptr1 == *ptr3) { | |
753 | errln("Expect == to work."); | |
754 | } | |
755 | if (!(*ptr1 != *ptr3)) { | |
756 | errln("Expect != to work."); | |
757 | } | |
758 | MeasureUnit *ptr4 = (MeasureUnit *) ptr1->clone(); | |
759 | if (*ptr1 != *ptr4) { | |
760 | errln("Expect clone to work."); | |
761 | } | |
762 | MeasureUnit stack; | |
763 | stack = *ptr1; | |
764 | if (*ptr1 != stack) { | |
765 | errln("Expect assignment to work."); | |
766 | } | |
767 | ||
768 | delete ptr1; | |
769 | delete ptr2; | |
770 | delete ptr3; | |
771 | delete ptr4; | |
772 | } | |
773 | ||
774 | void MeasureFormatTest::TestGetAvailable() { | |
775 | MeasureUnit *units = NULL; | |
776 | UErrorCode status = U_ZERO_ERROR; | |
777 | int32_t totalCount = MeasureUnit::getAvailable(units, 0, status); | |
778 | while (status == U_BUFFER_OVERFLOW_ERROR) { | |
779 | status = U_ZERO_ERROR; | |
780 | delete [] units; | |
781 | units = new MeasureUnit[totalCount]; | |
782 | totalCount = MeasureUnit::getAvailable(units, totalCount, status); | |
783 | } | |
784 | if (U_FAILURE(status)) { | |
785 | dataerrln("Failure creating format object - %s", u_errorName(status)); | |
786 | delete [] units; | |
787 | return; | |
788 | } | |
789 | if (totalCount < 200) { | |
790 | errln("Expect at least 200 measure units including currencies."); | |
791 | } | |
792 | delete [] units; | |
793 | StringEnumeration *types = MeasureUnit::getAvailableTypes(status); | |
794 | if (U_FAILURE(status)) { | |
795 | dataerrln("Failure getting types - %s", u_errorName(status)); | |
796 | delete types; | |
797 | return; | |
798 | } | |
799 | if (types->count(status) < 10) { | |
800 | errln("Expect at least 10 distinct unit types."); | |
801 | } | |
802 | units = NULL; | |
803 | int32_t unitCapacity = 0; | |
804 | int32_t unitCountSum = 0; | |
805 | for ( | |
806 | const char* type = types->next(NULL, status); | |
807 | type != NULL; | |
808 | type = types->next(NULL, status)) { | |
809 | int32_t unitCount = MeasureUnit::getAvailable(type, units, unitCapacity, status); | |
810 | while (status == U_BUFFER_OVERFLOW_ERROR) { | |
811 | status = U_ZERO_ERROR; | |
812 | delete [] units; | |
813 | units = new MeasureUnit[unitCount]; | |
814 | unitCapacity = unitCount; | |
815 | unitCount = MeasureUnit::getAvailable(type, units, unitCapacity, status); | |
816 | } | |
817 | if (U_FAILURE(status)) { | |
818 | dataerrln("Failure getting units - %s", u_errorName(status)); | |
819 | delete [] units; | |
820 | delete types; | |
821 | return; | |
822 | } | |
823 | if (unitCount < 1) { | |
824 | errln("Expect at least one unit count per type."); | |
825 | } | |
826 | unitCountSum += unitCount; | |
827 | } | |
828 | if (unitCountSum != totalCount) { | |
829 | errln("Expected total unit count to equal sum of unit counts by type."); | |
830 | } | |
831 | delete [] units; | |
832 | delete types; | |
833 | } | |
834 | ||
835 | void MeasureFormatTest::TestExamplesInDocs() { | |
836 | UErrorCode status = U_ZERO_ERROR; | |
837 | MeasureFormat fmtFr(Locale::getFrench(), UMEASFMT_WIDTH_SHORT, status); | |
838 | MeasureFormat fmtFrFull( | |
839 | Locale::getFrench(), UMEASFMT_WIDTH_WIDE, status); | |
840 | MeasureFormat fmtFrNarrow( | |
841 | Locale::getFrench(), UMEASFMT_WIDTH_NARROW, status); | |
842 | MeasureFormat fmtEn(Locale::getUS(), UMEASFMT_WIDTH_WIDE, status); | |
843 | if (!assertSuccess("Error creating formatters", status)) { | |
844 | return; | |
845 | } | |
846 | Measure measureC(23, MeasureUnit::createCelsius(status), status); | |
847 | Measure measureF(70, MeasureUnit::createFahrenheit(status), status); | |
848 | Measure feetAndInches[] = { | |
849 | Measure(70, MeasureUnit::createFoot(status), status), | |
850 | Measure(5.3, MeasureUnit::createInch(status), status)}; | |
851 | Measure footAndInch[] = { | |
852 | Measure(1, MeasureUnit::createFoot(status), status), | |
853 | Measure(1, MeasureUnit::createInch(status), status)}; | |
854 | Measure inchAndFeet[] = { | |
855 | Measure(1, MeasureUnit::createInch(status), status), | |
856 | Measure(2, MeasureUnit::createFoot(status), status)}; | |
857 | if (!assertSuccess("Error creating measurements.", status)) { | |
858 | return; | |
859 | } | |
860 | verifyFormat( | |
861 | "Celsius", | |
862 | fmtFr, | |
863 | &measureC, | |
864 | 1, | |
865 | "23 \\u00B0C"); | |
866 | verifyFormatWithPrefix( | |
867 | "Celsius", | |
868 | fmtFr, | |
869 | "Prefix: ", | |
870 | &measureC, | |
871 | 1, | |
872 | "Prefix: 23 \\u00B0C"); | |
873 | verifyFormat( | |
874 | "Fahrenheit", | |
875 | fmtFr, | |
876 | &measureF, | |
877 | 1, | |
878 | "70 \\u00B0F"); | |
879 | verifyFormat( | |
880 | "Feet and inches", | |
881 | fmtFrFull, | |
882 | feetAndInches, | |
b331163b | 883 | UPRV_LENGTHOF(feetAndInches), |
57a6839d A |
884 | "70 pieds et 5,3 pouces"); |
885 | verifyFormatWithPrefix( | |
886 | "Feet and inches", | |
887 | fmtFrFull, | |
888 | "Prefix: ", | |
889 | feetAndInches, | |
b331163b | 890 | UPRV_LENGTHOF(feetAndInches), |
57a6839d A |
891 | "Prefix: 70 pieds et 5,3 pouces"); |
892 | verifyFormat( | |
893 | "Foot and inch", | |
894 | fmtFrFull, | |
895 | footAndInch, | |
b331163b | 896 | UPRV_LENGTHOF(footAndInch), |
57a6839d A |
897 | "1 pied et 1 pouce"); |
898 | verifyFormat( | |
899 | "Foot and inch narrow", | |
900 | fmtFrNarrow, | |
901 | footAndInch, | |
b331163b | 902 | UPRV_LENGTHOF(footAndInch), |
57a6839d A |
903 | "1\\u2032 1\\u2033"); |
904 | verifyFormat( | |
905 | "Inch and feet", | |
906 | fmtEn, | |
907 | inchAndFeet, | |
b331163b | 908 | UPRV_LENGTHOF(inchAndFeet), |
57a6839d A |
909 | "1 inch, 2 feet"); |
910 | } | |
911 | ||
912 | void MeasureFormatTest::TestFormatPeriodEn() { | |
913 | UErrorCode status = U_ZERO_ERROR; | |
914 | Measure t_19m[] = {Measure(19, MeasureUnit::createMinute(status), status)}; | |
915 | Measure t_1h_23_5s[] = { | |
916 | Measure(1.0, MeasureUnit::createHour(status), status), | |
917 | Measure(23.5, MeasureUnit::createSecond(status), status) | |
918 | }; | |
919 | Measure t_1h_23_5m[] = { | |
920 | Measure(1.0, MeasureUnit::createHour(status), status), | |
921 | Measure(23.5, MeasureUnit::createMinute(status), status) | |
922 | }; | |
923 | Measure t_1h_0m_23s[] = { | |
924 | Measure( | |
925 | 1.0, | |
926 | TimeUnit::createInstance( | |
927 | TimeUnit::UTIMEUNIT_HOUR, status), | |
928 | status), | |
929 | Measure( | |
930 | 0.0, | |
931 | TimeUnit::createInstance( | |
932 | TimeUnit::UTIMEUNIT_MINUTE, status), | |
933 | status), | |
934 | Measure( | |
935 | 23, | |
936 | TimeUnit::createInstance( | |
937 | TimeUnit::UTIMEUNIT_SECOND, status), | |
938 | status) | |
939 | }; | |
940 | Measure t_2y_5M_3w_4d[] = { | |
941 | Measure(2.0, MeasureUnit::createYear(status), status), | |
942 | Measure(5.0, MeasureUnit::createMonth(status), status), | |
943 | Measure(3.0, MeasureUnit::createWeek(status), status), | |
944 | Measure(4.0, MeasureUnit::createDay(status), status) | |
945 | }; | |
946 | Measure t_1m_59_9996s[] = { | |
947 | Measure(1.0, MeasureUnit::createMinute(status), status), | |
948 | Measure(59.9996, MeasureUnit::createSecond(status), status) | |
949 | }; | |
950 | Measure t_5h_17m[] = { | |
951 | Measure(5.0, MeasureUnit::createHour(status), status), | |
952 | Measure(17.0, MeasureUnit::createMinute(status), status) | |
953 | }; | |
954 | Measure t_neg5h_17m[] = { | |
955 | Measure(-5.0, MeasureUnit::createHour(status), status), | |
956 | Measure(17.0, MeasureUnit::createMinute(status), status) | |
957 | }; | |
958 | Measure t_19m_28s[] = { | |
959 | Measure(19.0, MeasureUnit::createMinute(status), status), | |
960 | Measure(28.0, MeasureUnit::createSecond(status), status) | |
961 | }; | |
962 | Measure t_0h_0m_9s[] = { | |
963 | Measure(0.0, MeasureUnit::createHour(status), status), | |
964 | Measure(0.0, MeasureUnit::createMinute(status), status), | |
965 | Measure(9.0, MeasureUnit::createSecond(status), status) | |
966 | }; | |
967 | Measure t_0h_0m_17s[] = { | |
968 | Measure(0.0, MeasureUnit::createHour(status), status), | |
969 | Measure(0.0, MeasureUnit::createMinute(status), status), | |
970 | Measure(17.0, MeasureUnit::createSecond(status), status) | |
971 | }; | |
972 | Measure t_6h_56_92m[] = { | |
973 | Measure(6.0, MeasureUnit::createHour(status), status), | |
974 | Measure(56.92, MeasureUnit::createMinute(status), status) | |
975 | }; | |
976 | Measure t_3h_4s_5m[] = { | |
977 | Measure(3.0, MeasureUnit::createHour(status), status), | |
978 | Measure(4.0, MeasureUnit::createSecond(status), status), | |
979 | Measure(5.0, MeasureUnit::createMinute(status), status) | |
980 | }; | |
981 | Measure t_6_7h_56_92m[] = { | |
982 | Measure(6.7, MeasureUnit::createHour(status), status), | |
983 | Measure(56.92, MeasureUnit::createMinute(status), status) | |
984 | }; | |
985 | ||
986 | Measure t_3h_5h[] = { | |
987 | Measure(3.0, MeasureUnit::createHour(status), status), | |
988 | Measure(5.0, MeasureUnit::createHour(status), status) | |
989 | }; | |
990 | ||
991 | if (!assertSuccess("Error creating Measure objects", status)) { | |
992 | return; | |
993 | } | |
2ca993e8 | 994 | |
57a6839d | 995 | ExpectedResult fullData[] = { |
b331163b A |
996 | {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1 minute, 59.9996 seconds"}, |
997 | {t_19m, UPRV_LENGTHOF(t_19m), "19 minutes"}, | |
998 | {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1 hour, 23.5 seconds"}, | |
999 | {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1 hour, 23.5 minutes"}, | |
1000 | {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1 hour, 0 minutes, 23 seconds"}, | |
1001 | {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2 years, 5 months, 3 weeks, 4 days"}}; | |
57a6839d A |
1002 | |
1003 | ExpectedResult abbrevData[] = { | |
b331163b A |
1004 | {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1 min, 59.9996 sec"}, |
1005 | {t_19m, UPRV_LENGTHOF(t_19m), "19 min"}, | |
1006 | {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1 hr, 23.5 sec"}, | |
1007 | {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1 hr, 23.5 min"}, | |
1008 | {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1 hr, 0 min, 23 sec"}, | |
1009 | {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2 yrs, 5 mths, 3 wks, 4 days"}}; | |
57a6839d A |
1010 | |
1011 | ExpectedResult narrowData[] = { | |
b331163b A |
1012 | {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1m 59.9996s"}, |
1013 | {t_19m, UPRV_LENGTHOF(t_19m), "19m"}, | |
1014 | {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1h 23.5s"}, | |
1015 | {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1h 23.5m"}, | |
1016 | {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1h 0m 23s"}, | |
1017 | {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2y 5m 3w 4d"}}; | |
57a6839d A |
1018 | |
1019 | ExpectedResult numericData[] = { | |
b331163b A |
1020 | {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1:59.9996"}, |
1021 | {t_19m, UPRV_LENGTHOF(t_19m), "19m"}, | |
1022 | {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1:00:23.5"}, | |
1023 | {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1:23.5"}, | |
1024 | {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1:00:23"}, | |
1025 | {t_5h_17m, UPRV_LENGTHOF(t_5h_17m), "5:17"}, | |
1026 | {t_neg5h_17m, UPRV_LENGTHOF(t_neg5h_17m), "-5h 17m"}, | |
1027 | {t_19m_28s, UPRV_LENGTHOF(t_19m_28s), "19:28"}, | |
1028 | {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2y 5m 3w 4d"}, | |
1029 | {t_0h_0m_9s, UPRV_LENGTHOF(t_0h_0m_9s), "0:00:09"}, | |
1030 | {t_6h_56_92m, UPRV_LENGTHOF(t_6h_56_92m), "6:56.92"}, | |
1031 | {t_6_7h_56_92m, UPRV_LENGTHOF(t_6_7h_56_92m), "6:56.92"}, | |
1032 | {t_3h_4s_5m, UPRV_LENGTHOF(t_3h_4s_5m), "3h 4s 5m"}, | |
1033 | {t_3h_5h, UPRV_LENGTHOF(t_3h_5h), "3h 5h"}}; | |
57a6839d A |
1034 | |
1035 | ExpectedResult fullDataDe[] = { | |
b331163b A |
1036 | {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1 Minute und 59,9996 Sekunden"}, |
1037 | {t_19m, UPRV_LENGTHOF(t_19m), "19 Minuten"}, | |
1038 | {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1 Stunde und 23,5 Sekunden"}, | |
1039 | {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1 Stunde und 23,5 Minuten"}, | |
1040 | {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1 Stunde, 0 Minuten und 23 Sekunden"}, | |
1041 | {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2 Jahre, 5 Monate, 3 Wochen und 4 Tage"}}; | |
57a6839d A |
1042 | |
1043 | ExpectedResult numericDataDe[] = { | |
b331163b A |
1044 | {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1:59,9996"}, |
1045 | {t_19m, UPRV_LENGTHOF(t_19m), "19min"}, | |
1046 | {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1:00:23,5"}, | |
1047 | {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1:23,5"}, | |
1048 | {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1:00:23"}, | |
1049 | {t_5h_17m, UPRV_LENGTHOF(t_5h_17m), "5:17"}, | |
1050 | {t_19m_28s, UPRV_LENGTHOF(t_19m_28s), "19:28"}, | |
1051 | {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2J 5M 3W 4d"}, | |
1052 | {t_0h_0m_17s, UPRV_LENGTHOF(t_0h_0m_17s), "0:00:17"}, | |
1053 | {t_6h_56_92m, UPRV_LENGTHOF(t_6h_56_92m), "6:56,92"}, | |
1054 | {t_3h_5h, UPRV_LENGTHOF(t_3h_5h), "3h 5h"}}; | |
57a6839d A |
1055 | |
1056 | Locale en(Locale::getEnglish()); | |
1057 | LocalPointer<NumberFormat> nf(NumberFormat::createInstance(en, status)); | |
1058 | if (U_FAILURE(status)) { | |
1059 | dataerrln("Error creating number format en object - %s", u_errorName(status)); | |
1060 | return; | |
1061 | } | |
1062 | nf->setMaximumFractionDigits(4); | |
1063 | MeasureFormat mf(en, UMEASFMT_WIDTH_WIDE, (NumberFormat *) nf->clone(), status); | |
1064 | if (!assertSuccess("Error creating measure format en WIDE", status)) { | |
1065 | return; | |
1066 | } | |
b331163b | 1067 | verifyFormat("en WIDE", mf, fullData, UPRV_LENGTHOF(fullData)); |
57a6839d A |
1068 | |
1069 | // exercise copy constructor | |
1070 | { | |
1071 | MeasureFormat mf2(mf); | |
b331163b | 1072 | verifyFormat("en WIDE copy", mf2, fullData, UPRV_LENGTHOF(fullData)); |
57a6839d A |
1073 | } |
1074 | // exercise clone | |
1075 | { | |
1076 | MeasureFormat *mf3 = (MeasureFormat *) mf.clone(); | |
b331163b | 1077 | verifyFormat("en WIDE copy", *mf3, fullData, UPRV_LENGTHOF(fullData)); |
57a6839d A |
1078 | delete mf3; |
1079 | } | |
1080 | mf = MeasureFormat(en, UMEASFMT_WIDTH_SHORT, (NumberFormat *) nf->clone(), status); | |
1081 | if (!assertSuccess("Error creating measure format en SHORT", status)) { | |
1082 | return; | |
1083 | } | |
b331163b | 1084 | verifyFormat("en SHORT", mf, abbrevData, UPRV_LENGTHOF(abbrevData)); |
57a6839d A |
1085 | mf = MeasureFormat(en, UMEASFMT_WIDTH_NARROW, (NumberFormat *) nf->clone(), status); |
1086 | if (!assertSuccess("Error creating measure format en NARROW", status)) { | |
1087 | return; | |
1088 | } | |
b331163b | 1089 | verifyFormat("en NARROW", mf, narrowData, UPRV_LENGTHOF(narrowData)); |
57a6839d A |
1090 | mf = MeasureFormat(en, UMEASFMT_WIDTH_NUMERIC, (NumberFormat *) nf->clone(), status); |
1091 | if (!assertSuccess("Error creating measure format en NUMERIC", status)) { | |
1092 | return; | |
1093 | } | |
b331163b | 1094 | verifyFormat("en NUMERIC", mf, numericData, UPRV_LENGTHOF(numericData)); |
2ca993e8 | 1095 | |
57a6839d A |
1096 | Locale de(Locale::getGerman()); |
1097 | nf.adoptInstead(NumberFormat::createInstance(de, status)); | |
1098 | if (!assertSuccess("Error creating number format de object", status)) { | |
1099 | return; | |
1100 | } | |
1101 | nf->setMaximumFractionDigits(4); | |
1102 | mf = MeasureFormat(de, UMEASFMT_WIDTH_WIDE, (NumberFormat *) nf->clone(), status); | |
1103 | if (!assertSuccess("Error creating measure format de WIDE", status)) { | |
1104 | return; | |
1105 | } | |
b331163b | 1106 | verifyFormat("de WIDE", mf, fullDataDe, UPRV_LENGTHOF(fullDataDe)); |
57a6839d A |
1107 | mf = MeasureFormat(de, UMEASFMT_WIDTH_NUMERIC, (NumberFormat *) nf->clone(), status); |
1108 | if (!assertSuccess("Error creating measure format de NUMERIC", status)) { | |
1109 | return; | |
1110 | } | |
b331163b | 1111 | verifyFormat("de NUMERIC", mf, numericDataDe, UPRV_LENGTHOF(numericDataDe)); |
57a6839d A |
1112 | } |
1113 | ||
1114 | void MeasureFormatTest::Test10219FractionalPlurals() { | |
1115 | Locale en(Locale::getEnglish()); | |
1116 | double values[] = {1.588, 1.011}; | |
1117 | const char *expected[2][3] = { | |
1118 | {"1 minute", "1.5 minutes", "1.58 minutes"}, | |
1119 | {"1 minute", "1.0 minutes", "1.01 minutes"} | |
1120 | }; | |
1121 | UErrorCode status = U_ZERO_ERROR; | |
b331163b A |
1122 | for (int j = 0; j < UPRV_LENGTHOF(values); j++) { |
1123 | for (int i = 0; i < UPRV_LENGTHOF(expected[j]); i++) { | |
57a6839d A |
1124 | DecimalFormat *df = |
1125 | (DecimalFormat *) NumberFormat::createInstance(en, status); | |
1126 | if (U_FAILURE(status)) { | |
1127 | dataerrln("Error creating Number format - %s", u_errorName(status)); | |
1128 | return; | |
1129 | } | |
1130 | df->setRoundingMode(DecimalFormat::kRoundDown); | |
1131 | df->setMinimumFractionDigits(i); | |
1132 | df->setMaximumFractionDigits(i); | |
1133 | MeasureFormat mf(en, UMEASFMT_WIDTH_WIDE, df, status); | |
1134 | if (!assertSuccess("Error creating Measure format", status)) { | |
1135 | return; | |
1136 | } | |
1137 | Measure measure(values[j], MeasureUnit::createMinute(status), status); | |
1138 | if (!assertSuccess("Error creating Measure unit", status)) { | |
1139 | return; | |
1140 | } | |
1141 | verifyFormat("Test10219", mf, &measure, 1, expected[j][i]); | |
2ca993e8 | 1142 | } |
57a6839d A |
1143 | } |
1144 | } | |
1145 | ||
1146 | static MeasureUnit toMeasureUnit(MeasureUnit *adopted) { | |
1147 | MeasureUnit result(*adopted); | |
1148 | delete adopted; | |
1149 | return result; | |
1150 | } | |
1151 | ||
1152 | void MeasureFormatTest::TestGreek() { | |
1153 | Locale locales[] = {Locale("el_GR"), Locale("el")}; | |
1154 | UErrorCode status = U_ZERO_ERROR; | |
1155 | MeasureUnit units[] = { | |
1156 | toMeasureUnit(MeasureUnit::createSecond(status)), | |
1157 | toMeasureUnit(MeasureUnit::createMinute(status)), | |
1158 | toMeasureUnit(MeasureUnit::createHour(status)), | |
1159 | toMeasureUnit(MeasureUnit::createDay(status)), | |
1160 | toMeasureUnit(MeasureUnit::createWeek(status)), | |
1161 | toMeasureUnit(MeasureUnit::createMonth(status)), | |
1162 | toMeasureUnit(MeasureUnit::createYear(status))}; | |
1163 | if (!assertSuccess("Error creating Measure units", status)) { | |
1164 | return; | |
1165 | } | |
1166 | UMeasureFormatWidth styles[] = { | |
1167 | UMEASFMT_WIDTH_WIDE, | |
1168 | UMEASFMT_WIDTH_SHORT}; | |
1169 | int32_t numbers[] = {1, 7}; | |
1170 | const char *expected[] = { | |
b331163b | 1171 | // "el_GR" 1 wide |
57a6839d A |
1172 | "1 \\u03B4\\u03B5\\u03C5\\u03C4\\u03B5\\u03C1\\u03CC\\u03BB\\u03B5\\u03C0\\u03C4\\u03BF", |
1173 | "1 \\u03BB\\u03B5\\u03C0\\u03C4\\u03CC", | |
1174 | "1 \\u03CE\\u03C1\\u03B1", | |
1175 | "1 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B1", | |
1176 | "1 \\u03B5\\u03B2\\u03B4\\u03BF\\u03BC\\u03AC\\u03B4\\u03B1", | |
1177 | "1 \\u03BC\\u03AE\\u03BD\\u03B1\\u03C2", | |
1178 | "1 \\u03AD\\u03C4\\u03BF\\u03C2", | |
b331163b | 1179 | // "el_GR" 1 short |
57a6839d A |
1180 | "1 \\u03B4\\u03B5\\u03C5\\u03C4.", |
1181 | "1 \\u03BB\\u03B5\\u03C0.", | |
1182 | "1 \\u03CE\\u03C1\\u03B1", | |
1183 | "1 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B1", | |
1184 | "1 \\u03B5\\u03B2\\u03B4.", | |
1185 | "1 \\u03BC\\u03AE\\u03BD.", | |
b331163b A |
1186 | "1 \\u03AD\\u03C4.", // year (one) |
1187 | // "el_GR" 7 wide | |
57a6839d A |
1188 | "7 \\u03B4\\u03B5\\u03C5\\u03C4\\u03B5\\u03C1\\u03CC\\u03BB\\u03B5\\u03C0\\u03C4\\u03B1", |
1189 | "7 \\u03BB\\u03B5\\u03C0\\u03C4\\u03AC", | |
1190 | "7 \\u03CE\\u03C1\\u03B5\\u03C2", | |
1191 | "7 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B5\\u03C2", | |
1192 | "7 \\u03B5\\u03B2\\u03B4\\u03BF\\u03BC\\u03AC\\u03B4\\u03B5\\u03C2", | |
1193 | "7 \\u03BC\\u03AE\\u03BD\\u03B5\\u03C2", | |
1194 | "7 \\u03AD\\u03C4\\u03B7", | |
b331163b | 1195 | // "el_GR" 7 short |
57a6839d A |
1196 | "7 \\u03B4\\u03B5\\u03C5\\u03C4.", |
1197 | "7 \\u03BB\\u03B5\\u03C0.", | |
b331163b | 1198 | "7 \\u03CE\\u03C1.", // hour (other) |
57a6839d A |
1199 | "7 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B5\\u03C2", |
1200 | "7 \\u03B5\\u03B2\\u03B4.", | |
1201 | "7 \\u03BC\\u03AE\\u03BD.", | |
b331163b A |
1202 | "7 \\u03AD\\u03C4.", // year (other) |
1203 | ||
1204 | // "el" 1 wide | |
57a6839d A |
1205 | "1 \\u03B4\\u03B5\\u03C5\\u03C4\\u03B5\\u03C1\\u03CC\\u03BB\\u03B5\\u03C0\\u03C4\\u03BF", |
1206 | "1 \\u03BB\\u03B5\\u03C0\\u03C4\\u03CC", | |
1207 | "1 \\u03CE\\u03C1\\u03B1", | |
1208 | "1 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B1", | |
1209 | "1 \\u03B5\\u03B2\\u03B4\\u03BF\\u03BC\\u03AC\\u03B4\\u03B1", | |
1210 | "1 \\u03BC\\u03AE\\u03BD\\u03B1\\u03C2", | |
1211 | "1 \\u03AD\\u03C4\\u03BF\\u03C2", | |
b331163b | 1212 | // "el" 1 short |
57a6839d A |
1213 | "1 \\u03B4\\u03B5\\u03C5\\u03C4.", |
1214 | "1 \\u03BB\\u03B5\\u03C0.", | |
1215 | "1 \\u03CE\\u03C1\\u03B1", | |
1216 | "1 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B1", | |
1217 | "1 \\u03B5\\u03B2\\u03B4.", | |
1218 | "1 \\u03BC\\u03AE\\u03BD.", | |
b331163b A |
1219 | "1 \\u03AD\\u03C4.", // year (one) |
1220 | // "el" 7 wide | |
57a6839d A |
1221 | "7 \\u03B4\\u03B5\\u03C5\\u03C4\\u03B5\\u03C1\\u03CC\\u03BB\\u03B5\\u03C0\\u03C4\\u03B1", |
1222 | "7 \\u03BB\\u03B5\\u03C0\\u03C4\\u03AC", | |
1223 | "7 \\u03CE\\u03C1\\u03B5\\u03C2", | |
1224 | "7 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B5\\u03C2", | |
1225 | "7 \\u03B5\\u03B2\\u03B4\\u03BF\\u03BC\\u03AC\\u03B4\\u03B5\\u03C2", | |
1226 | "7 \\u03BC\\u03AE\\u03BD\\u03B5\\u03C2", | |
1227 | "7 \\u03AD\\u03C4\\u03B7", | |
b331163b | 1228 | // "el" 7 short |
57a6839d A |
1229 | "7 \\u03B4\\u03B5\\u03C5\\u03C4.", |
1230 | "7 \\u03BB\\u03B5\\u03C0.", | |
b331163b | 1231 | "7 \\u03CE\\u03C1.", // hour (other) |
57a6839d A |
1232 | "7 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B5\\u03C2", |
1233 | "7 \\u03B5\\u03B2\\u03B4.", | |
1234 | "7 \\u03BC\\u03AE\\u03BD.", | |
b331163b | 1235 | "7 \\u03AD\\u03C4."}; // year (other) |
57a6839d A |
1236 | |
1237 | int32_t counter = 0; | |
b331163b A |
1238 | for (int32_t locIndex = 0; locIndex < UPRV_LENGTHOF(locales); ++locIndex ) { |
1239 | for( int32_t numIndex = 0; numIndex < UPRV_LENGTHOF(numbers); ++numIndex ) { | |
1240 | for ( int32_t styleIndex = 0; styleIndex < UPRV_LENGTHOF(styles); ++styleIndex ) { | |
1241 | for ( int32_t unitIndex = 0; unitIndex < UPRV_LENGTHOF(units); ++unitIndex ) { | |
57a6839d A |
1242 | Measure measure(numbers[numIndex], new MeasureUnit(units[unitIndex]), status); |
1243 | if (!assertSuccess("Error creating Measure", status)) { | |
1244 | return; | |
1245 | } | |
1246 | MeasureFormat fmt(locales[locIndex], styles[styleIndex], status); | |
1247 | if (!assertSuccess("Error creating Measure format", status)) { | |
1248 | return; | |
1249 | } | |
1250 | verifyFormat("TestGreek", fmt, &measure, 1, expected[counter]); | |
1251 | ++counter; | |
1252 | } | |
1253 | } | |
1254 | } | |
1255 | } | |
1256 | } | |
1257 | ||
1258 | void MeasureFormatTest::TestFormatSingleArg() { | |
1259 | UErrorCode status = U_ZERO_ERROR; | |
1260 | MeasureFormat fmt("en", UMEASFMT_WIDTH_WIDE, status); | |
1261 | if (!assertSuccess("Error creating formatter", status)) { | |
1262 | return; | |
1263 | } | |
1264 | UnicodeString buffer; | |
1265 | FieldPosition pos(0); | |
1266 | fmt.format( | |
1267 | new Measure(3.5, MeasureUnit::createFoot(status), status), | |
1268 | buffer, | |
1269 | pos, | |
1270 | status); | |
1271 | if (!assertSuccess("Error formatting", status)) { | |
1272 | return; | |
1273 | } | |
1274 | assertEquals( | |
1275 | "TestFormatSingleArg", | |
1276 | UnicodeString("3.5 feet"), | |
1277 | buffer); | |
1278 | } | |
1279 | ||
1280 | void MeasureFormatTest::TestFormatMeasuresZeroArg() { | |
1281 | UErrorCode status = U_ZERO_ERROR; | |
1282 | MeasureFormat fmt("en", UMEASFMT_WIDTH_WIDE, status); | |
1283 | verifyFormat("TestFormatMeasuresZeroArg", fmt, NULL, 0, ""); | |
1284 | } | |
1285 | ||
b331163b A |
1286 | void MeasureFormatTest::TestSimplePer() { |
1287 | Locale en("en"); | |
1288 | UErrorCode status = U_ZERO_ERROR; | |
1289 | LocalPointer<MeasureUnit> second(MeasureUnit::createSecond(status)); | |
1290 | LocalPointer<MeasureUnit> minute(MeasureUnit::createMinute(status)); | |
1291 | LocalPointer<MeasureUnit> pound(MeasureUnit::createPound(status)); | |
1292 | if (!assertSuccess("", status)) { | |
1293 | return; | |
1294 | } | |
1295 | ||
1296 | helperTestSimplePer( | |
1297 | en, UMEASFMT_WIDTH_WIDE, | |
1298 | 1.0, *pound, *second, "1 pound per second"); | |
1299 | helperTestSimplePer( | |
1300 | en, UMEASFMT_WIDTH_WIDE, | |
1301 | 2.0, *pound, *second, "2 pounds per second"); | |
1302 | helperTestSimplePer( | |
1303 | en, UMEASFMT_WIDTH_WIDE, | |
1304 | 1.0, *pound, *minute, "1 pound per minute"); | |
1305 | helperTestSimplePer( | |
1306 | en, UMEASFMT_WIDTH_WIDE, | |
1307 | 2.0, *pound, *minute, "2 pounds per minute"); | |
1308 | ||
1309 | helperTestSimplePer( | |
2ca993e8 | 1310 | en, UMEASFMT_WIDTH_SHORT, 1.0, *pound, *second, "1 lb/s"); |
b331163b | 1311 | helperTestSimplePer( |
2ca993e8 | 1312 | en, UMEASFMT_WIDTH_SHORT, 2.0, *pound, *second, "2 lb/s"); |
b331163b A |
1313 | helperTestSimplePer( |
1314 | en, UMEASFMT_WIDTH_SHORT, 1.0, *pound, *minute, "1 lb/min"); | |
1315 | helperTestSimplePer( | |
1316 | en, UMEASFMT_WIDTH_SHORT, 2.0, *pound, *minute, "2 lb/min"); | |
1317 | ||
1318 | helperTestSimplePer( | |
1319 | en, UMEASFMT_WIDTH_NARROW, 1.0, *pound, *second, "1#/s"); | |
1320 | helperTestSimplePer( | |
1321 | en, UMEASFMT_WIDTH_NARROW, 2.0, *pound, *second, "2#/s"); | |
1322 | helperTestSimplePer( | |
2ca993e8 | 1323 | en, UMEASFMT_WIDTH_NARROW, 1.0, *pound, *minute, "1#/min"); |
b331163b | 1324 | helperTestSimplePer( |
2ca993e8 | 1325 | en, UMEASFMT_WIDTH_NARROW, 2.0, *pound, *minute, "2#/min"); |
b331163b A |
1326 | |
1327 | helperTestSimplePer( | |
1328 | en, UMEASFMT_WIDTH_SHORT, | |
2ca993e8 | 1329 | 23.3, *pound, *second, "23.3 lb/s", |
b331163b A |
1330 | NumberFormat::kDecimalSeparatorField, |
1331 | 2, 3); | |
1332 | ||
1333 | helperTestSimplePer( | |
1334 | en, UMEASFMT_WIDTH_SHORT, | |
2ca993e8 | 1335 | 23.3, *pound, *second, "23.3 lb/s", |
b331163b A |
1336 | NumberFormat::kIntegerField, |
1337 | 0, 2); | |
1338 | ||
1339 | helperTestSimplePer( | |
1340 | en, UMEASFMT_WIDTH_SHORT, | |
1341 | 23.3, *pound, *minute, "23.3 lb/min", | |
1342 | NumberFormat::kDecimalSeparatorField, | |
1343 | 2, 3); | |
1344 | ||
1345 | helperTestSimplePer( | |
1346 | en, UMEASFMT_WIDTH_SHORT, | |
1347 | 23.3, *pound, *minute, "23.3 lb/min", | |
1348 | NumberFormat::kIntegerField, | |
1349 | 0, 2); | |
1350 | } | |
1351 | ||
1352 | void MeasureFormatTest::TestNumeratorPlurals() { | |
1353 | Locale pl("pl"); | |
1354 | UErrorCode status = U_ZERO_ERROR; | |
1355 | LocalPointer<MeasureUnit> second(MeasureUnit::createSecond(status)); | |
1356 | LocalPointer<MeasureUnit> foot(MeasureUnit::createFoot(status)); | |
1357 | if (!assertSuccess("", status)) { | |
1358 | return; | |
1359 | } | |
1360 | ||
1361 | helperTestSimplePer( | |
1362 | pl, | |
1363 | UMEASFMT_WIDTH_WIDE, | |
1364 | 1.0, *foot, *second, "1 stopa na sekund\\u0119"); | |
1365 | helperTestSimplePer( | |
1366 | pl, | |
1367 | UMEASFMT_WIDTH_WIDE, | |
1368 | 2.0, *foot, *second, "2 stopy na sekund\\u0119"); | |
1369 | helperTestSimplePer( | |
1370 | pl, | |
1371 | UMEASFMT_WIDTH_WIDE, | |
1372 | 5.0, *foot, *second, "5 st\\u00f3p na sekund\\u0119"); | |
1373 | helperTestSimplePer( | |
1374 | pl, UMEASFMT_WIDTH_WIDE, | |
1375 | 1.5, *foot, *second, "1,5 stopy na sekund\\u0119"); | |
1376 | } | |
1377 | ||
1378 | void MeasureFormatTest::helperTestSimplePer( | |
1379 | const Locale &locale, | |
1380 | UMeasureFormatWidth width, | |
1381 | double value, | |
1382 | const MeasureUnit &unit, | |
1383 | const MeasureUnit &perUnit, | |
1384 | const char *expected) { | |
1385 | helperTestSimplePer( | |
1386 | locale, | |
1387 | width, | |
1388 | value, | |
1389 | unit, | |
1390 | perUnit, | |
1391 | expected, | |
1392 | FieldPosition::DONT_CARE, | |
1393 | 0, | |
1394 | 0); | |
1395 | } | |
1396 | ||
1397 | void MeasureFormatTest::helperTestSimplePer( | |
1398 | const Locale &locale, | |
1399 | UMeasureFormatWidth width, | |
1400 | double value, | |
1401 | const MeasureUnit &unit, | |
1402 | const MeasureUnit &perUnit, | |
1403 | const char *expected, | |
1404 | int32_t field, | |
1405 | int32_t expected_start, | |
1406 | int32_t expected_end) { | |
1407 | UErrorCode status = U_ZERO_ERROR; | |
1408 | FieldPosition pos(field); | |
1409 | MeasureFormat fmt(locale, width, status); | |
1410 | if (!assertSuccess("Error creating format object", status)) { | |
1411 | return; | |
1412 | } | |
1413 | Measure measure(value, (MeasureUnit *) unit.clone(), status); | |
1414 | if (!assertSuccess("Error creating measure object", status)) { | |
1415 | return; | |
1416 | } | |
1417 | UnicodeString prefix("prefix: "); | |
1418 | UnicodeString buffer(prefix); | |
1419 | fmt.formatMeasurePerUnit( | |
1420 | measure, | |
1421 | perUnit, | |
1422 | buffer, | |
1423 | pos, | |
1424 | status); | |
1425 | if (!assertSuccess("Error formatting measures with per", status)) { | |
1426 | return; | |
1427 | } | |
1428 | UnicodeString uexpected(expected); | |
1429 | uexpected = prefix + uexpected; | |
1430 | assertEquals( | |
1431 | "TestSimplePer", | |
1432 | uexpected.unescape(), | |
1433 | buffer); | |
1434 | if (field != FieldPosition::DONT_CARE) { | |
1435 | assertEquals( | |
1436 | "Start", expected_start, pos.getBeginIndex() - prefix.length()); | |
1437 | assertEquals( | |
1438 | "End", expected_end, pos.getEndIndex() - prefix.length()); | |
1439 | } | |
1440 | } | |
1441 | ||
57a6839d A |
1442 | void MeasureFormatTest::TestMultiples() { |
1443 | Locale ru("ru"); | |
1444 | Locale en("en"); | |
1445 | helperTestMultiples(en, UMEASFMT_WIDTH_WIDE, "2 miles, 1 foot, 2.3 inches"); | |
1446 | helperTestMultiples(en, UMEASFMT_WIDTH_SHORT, "2 mi, 1 ft, 2.3 in"); | |
1447 | helperTestMultiples(en, UMEASFMT_WIDTH_NARROW, "2mi 1\\u2032 2.3\\u2033"); | |
2ca993e8 | 1448 | helperTestMultiples(ru, UMEASFMT_WIDTH_WIDE, "2 \\u043C\\u0438\\u043B\\u0438, 1 \\u0444\\u0443\\u0442, 2,3 \\u0434\\u044E\\u0439\\u043C\\u0430"); |
b331163b | 1449 | helperTestMultiples(ru, UMEASFMT_WIDTH_SHORT, "2 \\u043C\\u0438\\u043B\\u0438, 1 \\u0444\\u0443\\u0442, 2,3 \\u0434\\u044E\\u0439\\u043C."); |
57a6839d A |
1450 | helperTestMultiples(ru, UMEASFMT_WIDTH_NARROW, "2 \\u043C\\u0438\\u043B\\u044C 1 \\u0444\\u0443\\u0442 2,3 \\u0434\\u044E\\u0439\\u043C\\u0430"); |
1451 | } | |
1452 | ||
1453 | void MeasureFormatTest::helperTestMultiples( | |
1454 | const Locale &locale, | |
1455 | UMeasureFormatWidth width, | |
1456 | const char *expected) { | |
1457 | UErrorCode status = U_ZERO_ERROR; | |
1458 | FieldPosition pos(0); | |
1459 | MeasureFormat fmt(locale, width, status); | |
1460 | if (!assertSuccess("Error creating format object", status)) { | |
1461 | return; | |
1462 | } | |
1463 | Measure measures[] = { | |
1464 | Measure(2, MeasureUnit::createMile(status), status), | |
1465 | Measure(1, MeasureUnit::createFoot(status), status), | |
1466 | Measure(2.3, MeasureUnit::createInch(status), status)}; | |
1467 | if (!assertSuccess("Error creating measures", status)) { | |
1468 | return; | |
1469 | } | |
1470 | UnicodeString buffer; | |
b331163b | 1471 | fmt.formatMeasures(measures, UPRV_LENGTHOF(measures), buffer, pos, status); |
57a6839d A |
1472 | if (!assertSuccess("Error formatting measures", status)) { |
1473 | return; | |
1474 | } | |
1475 | assertEquals("TestMultiples", UnicodeString(expected).unescape(), buffer); | |
1476 | } | |
1477 | ||
2ca993e8 A |
1478 | void MeasureFormatTest::TestManyLocaleDurations() { |
1479 | UErrorCode status = U_ZERO_ERROR; | |
1480 | Measure measures[] = { | |
1481 | Measure(5, MeasureUnit::createHour(status), status), | |
1482 | Measure(37, MeasureUnit::createMinute(status), status)}; | |
1483 | if (!assertSuccess("Error creating measures", status)) { | |
1484 | return; | |
1485 | } | |
1486 | helperTestManyLocaleDurations("da", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5 t. 37 m."); // Apple data change | |
1487 | helperTestManyLocaleDurations("da", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5.37"); | |
1488 | helperTestManyLocaleDurations("de", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5h 37min"); // Apple data change | |
1489 | helperTestManyLocaleDurations("de", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37"); | |
1490 | helperTestManyLocaleDurations("en", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5h 37m"); | |
1491 | helperTestManyLocaleDurations("en", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37"); | |
1492 | helperTestManyLocaleDurations("es", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5h 37min"); | |
1493 | helperTestManyLocaleDurations("es", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37"); | |
1494 | helperTestManyLocaleDurations("fi", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5t 37min"); | |
1495 | helperTestManyLocaleDurations("fi", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5.37"); | |
1496 | helperTestManyLocaleDurations("fr", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5h 37mn"); | |
1497 | helperTestManyLocaleDurations("fr", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "05:37"); | |
1498 | helperTestManyLocaleDurations("is", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5 klst. og 37 m\\u00EDn."); | |
1499 | helperTestManyLocaleDurations("is", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37"); | |
1500 | helperTestManyLocaleDurations("ja", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5\\u6642\\u959337\\u5206"); | |
1501 | helperTestManyLocaleDurations("ja", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37"); | |
1502 | helperTestManyLocaleDurations("nb", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5t, 37m"); | |
1503 | helperTestManyLocaleDurations("nb", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5.37"); | |
1504 | helperTestManyLocaleDurations("nl", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5 u, 37 m"); | |
1505 | helperTestManyLocaleDurations("nl", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37"); | |
1506 | helperTestManyLocaleDurations("nn", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5 h og 37 min"); | |
1507 | helperTestManyLocaleDurations("nn", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5.37"); | |
1508 | helperTestManyLocaleDurations("sv", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5h 37m"); | |
1509 | helperTestManyLocaleDurations("sv", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37"); | |
1510 | helperTestManyLocaleDurations("zh", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5\\u5C0F\\u65F637\\u5206\\u949F"); | |
1511 | helperTestManyLocaleDurations("zh", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37"); | |
1512 | } | |
1513 | ||
1514 | void MeasureFormatTest::helperTestManyLocaleDurations( const char *localeID, | |
1515 | UMeasureFormatWidth width, | |
1516 | const Measure *measures, | |
1517 | int32_t measureCount, | |
1518 | const char *expected) { | |
1519 | UErrorCode status = U_ZERO_ERROR; | |
1520 | MeasureFormat fmt(Locale(localeID), width, status); | |
1521 | if (U_FAILURE(status)) { | |
1522 | errln("Could not create MeasureFormat for locale %s, width %d, status: %s", localeID, (int)width, u_errorName(status)); | |
1523 | return; | |
1524 | } | |
1525 | UnicodeString buffer; | |
1526 | FieldPosition pos(0); | |
1527 | fmt.formatMeasures(measures, measureCount, buffer, pos, status); | |
1528 | if (U_FAILURE(status)) { | |
1529 | errln("MeasureFormat::formatMeasures failed for locale %s, width %d, status: %s", localeID, (int)width, u_errorName(status)); | |
1530 | return; | |
1531 | } | |
1532 | UnicodeString expStr(UnicodeString(expected).unescape()); | |
1533 | if (buffer != expStr) { | |
1534 | errln("MeasureFormat::formatMeasures for locale " + UnicodeString(localeID) + ", width " + width + ", expected \"" + expStr + "\", got \"" + buffer + "\""); | |
1535 | } | |
1536 | } | |
1537 | ||
57a6839d A |
1538 | void MeasureFormatTest::TestGram() { |
1539 | UErrorCode status = U_ZERO_ERROR; | |
1540 | MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status); | |
1541 | if (!assertSuccess("Error creating format object", status)) { | |
1542 | return; | |
1543 | } | |
1544 | Measure gram(1, MeasureUnit::createGram(status), status); | |
1545 | Measure gforce(1, MeasureUnit::createGForce(status), status); | |
1546 | if (!assertSuccess("Error creating measures", status)) { | |
1547 | return; | |
1548 | } | |
1549 | verifyFormat("TestGram", fmt, &gram, 1, "1 g"); | |
1550 | verifyFormat("TestGram", fmt, &gforce, 1, "1 G"); | |
1551 | } | |
1552 | ||
1553 | void MeasureFormatTest::TestCurrencies() { | |
1554 | UChar USD[] = {'U', 'S', 'D', 0}; | |
1555 | UErrorCode status = U_ZERO_ERROR; | |
1556 | CurrencyAmount USD_1(1.0, USD, status); | |
1557 | CurrencyAmount USD_2(2.0, USD, status); | |
1558 | CurrencyAmount USD_NEG_1(-1.0, USD, status); | |
1559 | if (!assertSuccess("Error creating measures", status)) { | |
1560 | return; | |
1561 | } | |
1562 | Locale en("en"); | |
1563 | MeasureFormat fmt(en, UMEASFMT_WIDTH_WIDE, status); | |
1564 | if (!assertSuccess("Error creating format object", status)) { | |
1565 | return; | |
1566 | } | |
1567 | verifyFormat("TestCurrenciesWide", fmt, &USD_NEG_1, 1, "-1.00 US dollars"); | |
1568 | verifyFormat("TestCurrenciesWide", fmt, &USD_1, 1, "1.00 US dollars"); | |
1569 | verifyFormat("TestCurrenciesWide", fmt, &USD_2, 1, "2.00 US dollars"); | |
1570 | fmt = MeasureFormat(en, UMEASFMT_WIDTH_SHORT, status); | |
1571 | if (!assertSuccess("Error creating format object", status)) { | |
1572 | return; | |
1573 | } | |
1574 | verifyFormat("TestCurrenciesShort", fmt, &USD_NEG_1, 1, "-USD1.00"); | |
1575 | verifyFormat("TestCurrenciesShort", fmt, &USD_1, 1, "USD1.00"); | |
1576 | verifyFormat("TestCurrenciesShort", fmt, &USD_2, 1, "USD2.00"); | |
1577 | fmt = MeasureFormat(en, UMEASFMT_WIDTH_NARROW, status); | |
1578 | if (!assertSuccess("Error creating format object", status)) { | |
1579 | return; | |
1580 | } | |
1581 | verifyFormat("TestCurrenciesNarrow", fmt, &USD_NEG_1, 1, "-$1.00"); | |
1582 | verifyFormat("TestCurrenciesNarrow", fmt, &USD_1, 1, "$1.00"); | |
1583 | verifyFormat("TestCurrenciesNarrow", fmt, &USD_2, 1, "$2.00"); | |
1584 | fmt = MeasureFormat(en, UMEASFMT_WIDTH_NUMERIC, status); | |
1585 | if (!assertSuccess("Error creating format object", status)) { | |
1586 | return; | |
1587 | } | |
1588 | verifyFormat("TestCurrenciesNumeric", fmt, &USD_NEG_1, 1, "-$1.00"); | |
1589 | verifyFormat("TestCurrenciesNumeric", fmt, &USD_1, 1, "$1.00"); | |
1590 | verifyFormat("TestCurrenciesNumeric", fmt, &USD_2, 1, "$2.00"); | |
1591 | } | |
1592 | ||
1593 | void MeasureFormatTest::TestFieldPosition() { | |
1594 | UErrorCode status = U_ZERO_ERROR; | |
1595 | MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status); | |
1596 | if (!assertSuccess("Error creating format object", status)) { | |
1597 | return; | |
1598 | } | |
1599 | Measure measure(43.5, MeasureUnit::createFoot(status), status); | |
1600 | if (!assertSuccess("Error creating measure object 1", status)) { | |
1601 | return; | |
1602 | } | |
1603 | UnicodeString prefix("123456: "); | |
1604 | verifyFieldPosition( | |
1605 | "", | |
1606 | fmt, | |
1607 | prefix, | |
1608 | &measure, | |
1609 | 1, | |
1610 | NumberFormat::kDecimalSeparatorField, | |
1611 | 10, | |
1612 | 11); | |
1613 | measure = Measure(43, MeasureUnit::createFoot(status), status); | |
1614 | if (!assertSuccess("Error creating measure object 2", status)) { | |
1615 | return; | |
1616 | } | |
1617 | verifyFieldPosition( | |
1618 | "", | |
1619 | fmt, | |
1620 | prefix, | |
1621 | &measure, | |
1622 | 1, | |
1623 | NumberFormat::kDecimalSeparatorField, | |
1624 | 0, | |
1625 | 0); | |
1626 | } | |
1627 | ||
1628 | void MeasureFormatTest::TestFieldPositionMultiple() { | |
1629 | UErrorCode status = U_ZERO_ERROR; | |
1630 | MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status); | |
1631 | if (!assertSuccess("Error creating format object", status)) { | |
1632 | return; | |
1633 | } | |
1634 | Measure first[] = { | |
1635 | Measure(354, MeasureUnit::createMeter(status), status), | |
1636 | Measure(23, MeasureUnit::createCentimeter(status), status)}; | |
1637 | Measure second[] = { | |
1638 | Measure(354, MeasureUnit::createMeter(status), status), | |
1639 | Measure(23, MeasureUnit::createCentimeter(status), status), | |
1640 | Measure(5.4, MeasureUnit::createMillimeter(status), status)}; | |
1641 | Measure third[] = { | |
1642 | Measure(3, MeasureUnit::createMeter(status), status), | |
1643 | Measure(23, MeasureUnit::createCentimeter(status), status), | |
1644 | Measure(5, MeasureUnit::createMillimeter(status), status)}; | |
1645 | if (!assertSuccess("Error creating measure objects", status)) { | |
1646 | return; | |
1647 | } | |
1648 | UnicodeString prefix("123456: "); | |
1649 | verifyFieldPosition( | |
1650 | "Integer", | |
1651 | fmt, | |
1652 | prefix, | |
1653 | first, | |
b331163b | 1654 | UPRV_LENGTHOF(first), |
57a6839d A |
1655 | NumberFormat::kIntegerField, |
1656 | 8, | |
1657 | 11); | |
1658 | verifyFieldPosition( | |
1659 | "Decimal separator", | |
1660 | fmt, | |
1661 | prefix, | |
1662 | second, | |
b331163b | 1663 | UPRV_LENGTHOF(second), |
57a6839d A |
1664 | NumberFormat::kDecimalSeparatorField, |
1665 | 23, | |
1666 | 24); | |
1667 | verifyFieldPosition( | |
1668 | "no decimal separator", | |
1669 | fmt, | |
1670 | prefix, | |
1671 | third, | |
b331163b | 1672 | UPRV_LENGTHOF(third), |
57a6839d A |
1673 | NumberFormat::kDecimalSeparatorField, |
1674 | 0, | |
1675 | 0); | |
1676 | } | |
1677 | ||
1678 | void MeasureFormatTest::TestBadArg() { | |
1679 | UErrorCode status = U_ZERO_ERROR; | |
1680 | MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status); | |
1681 | if (!assertSuccess("Error creating format object", status)) { | |
1682 | return; | |
1683 | } | |
1684 | FieldPosition pos(0); | |
1685 | UnicodeString buffer; | |
1686 | fmt.format( | |
1687 | 9.3, | |
1688 | buffer, | |
1689 | pos, | |
1690 | status); | |
1691 | if (status != U_ILLEGAL_ARGUMENT_ERROR) { | |
1692 | errln("Expected ILLEGAL_ARGUMENT_ERROR"); | |
1693 | } | |
1694 | } | |
1695 | ||
1696 | void MeasureFormatTest::TestEquality() { | |
1697 | UErrorCode status = U_ZERO_ERROR; | |
1698 | NumberFormat* nfeq = NumberFormat::createInstance("en", status); | |
1699 | NumberFormat* nfne = NumberFormat::createInstance("fr", status); | |
1700 | MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status); | |
1701 | MeasureFormat fmtEq2("en", UMEASFMT_WIDTH_SHORT, nfeq, status); | |
1702 | MeasureFormat fmtne1("en", UMEASFMT_WIDTH_WIDE, status); | |
1703 | MeasureFormat fmtne2("fr", UMEASFMT_WIDTH_SHORT, status); | |
1704 | MeasureFormat fmtne3("en", UMEASFMT_WIDTH_SHORT, nfne, status); | |
1705 | if (U_FAILURE(status)) { | |
1706 | dataerrln("Error creating MeasureFormats - %s", u_errorName(status)); | |
1707 | return; | |
1708 | } | |
1709 | MeasureFormat fmtEq(fmt); | |
1710 | assertTrue("Equal", fmt == fmtEq); | |
1711 | assertTrue("Equal2", fmt == fmtEq2); | |
1712 | assertFalse("Equal Neg", fmt != fmtEq); | |
1713 | assertTrue("Not Equal 1", fmt != fmtne1); | |
1714 | assertFalse("Not Equal Neg 1", fmt == fmtne1); | |
1715 | assertTrue("Not Equal 2", fmt != fmtne2); | |
1716 | assertTrue("Not Equal 3", fmt != fmtne3); | |
1717 | } | |
1718 | ||
b331163b A |
1719 | void MeasureFormatTest::TestGroupingSeparator() { |
1720 | UErrorCode status = U_ZERO_ERROR; | |
1721 | Locale en("en"); | |
1722 | MeasureFormat fmt(en, UMEASFMT_WIDTH_SHORT, status); | |
1723 | if (!assertSuccess("Error creating format object", status)) { | |
1724 | return; | |
1725 | } | |
1726 | Measure ms[] = { | |
1727 | Measure((int32_t)INT32_MAX, MeasureUnit::createYear(status), status), | |
1728 | Measure((int32_t)INT32_MIN, MeasureUnit::createMonth(status), status), | |
1729 | Measure(-987, MeasureUnit::createDay(status), status), | |
1730 | Measure(1362, MeasureUnit::createHour(status), status), | |
1731 | Measure(987, MeasureUnit::createMinute(status), status)}; | |
1732 | FieldPosition pos(NumberFormat::kGroupingSeparatorField); | |
1733 | UnicodeString appendTo; | |
1734 | fmt.formatMeasures(ms, 5, appendTo, pos, status); | |
1735 | if (!assertSuccess("Error formatting", status)) { | |
1736 | return; | |
1737 | } | |
1738 | assertEquals( | |
1739 | "grouping separator", | |
1740 | "2,147,483,647 yrs, -2,147,483,648 mths, -987 days, 1,362 hr, 987 min", | |
1741 | appendTo); | |
1742 | assertEquals("begin index", 9, pos.getBeginIndex()); | |
1743 | assertEquals("end index", 10, pos.getEndIndex()); | |
1744 | } | |
1745 | ||
57a6839d A |
1746 | void MeasureFormatTest::TestDoubleZero() { |
1747 | UErrorCode status = U_ZERO_ERROR; | |
1748 | Measure measures[] = { | |
1749 | Measure(4.7, MeasureUnit::createHour(status), status), | |
1750 | Measure(23, MeasureUnit::createMinute(status), status), | |
1751 | Measure(16, MeasureUnit::createSecond(status), status)}; | |
1752 | Locale en("en"); | |
1753 | NumberFormat *nf = NumberFormat::createInstance(en, status); | |
1754 | MeasureFormat fmt("en", UMEASFMT_WIDTH_WIDE, nf, status); | |
1755 | UnicodeString appendTo; | |
1756 | FieldPosition pos(FieldPosition::DONT_CARE); | |
1757 | if (U_FAILURE(status)) { | |
1758 | dataerrln("Error creating formatter - %s", u_errorName(status)); | |
1759 | return; | |
1760 | } | |
1761 | nf->setMinimumFractionDigits(2); | |
1762 | nf->setMaximumFractionDigits(2); | |
b331163b | 1763 | fmt.formatMeasures(measures, UPRV_LENGTHOF(measures), appendTo, pos, status); |
57a6839d A |
1764 | if (!assertSuccess("Error formatting", status)) { |
1765 | return; | |
1766 | } | |
1767 | assertEquals( | |
1768 | "TestDoubleZero", | |
1769 | UnicodeString("4 hours, 23 minutes, 16.00 seconds"), | |
1770 | appendTo); | |
1771 | measures[0] = Measure(-4.7, MeasureUnit::createHour(status), status); | |
1772 | appendTo.remove(); | |
b331163b | 1773 | fmt.formatMeasures(measures, UPRV_LENGTHOF(measures), appendTo, pos, status); |
57a6839d A |
1774 | if (!assertSuccess("Error formatting", status)) { |
1775 | return; | |
1776 | } | |
1777 | assertEquals( | |
1778 | "TestDoubleZero", | |
1779 | UnicodeString("-4 hours, 23 minutes, 16.00 seconds"), | |
1780 | appendTo); | |
1781 | } | |
1782 | ||
b331163b A |
1783 | void MeasureFormatTest::TestUnitPerUnitResolution() { |
1784 | UErrorCode status = U_ZERO_ERROR; | |
1785 | Locale en("en"); | |
1786 | MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status); | |
1787 | Measure measure(50, MeasureUnit::createPound(status), status); | |
1788 | LocalPointer<MeasureUnit> sqInch(MeasureUnit::createSquareInch(status)); | |
1789 | if (!assertSuccess("Create of format unit and per unit", status)) { | |
1790 | return; | |
1791 | } | |
1792 | FieldPosition pos(0); | |
1793 | UnicodeString actual; | |
1794 | fmt.formatMeasurePerUnit( | |
1795 | measure, | |
1796 | *sqInch, | |
1797 | actual, | |
1798 | pos, | |
1799 | status); | |
1800 | assertEquals("", "50 psi", actual); | |
1801 | } | |
1802 | ||
2ca993e8 A |
1803 | void MeasureFormatTest::TestIndividualPluralFallback() { |
1804 | // See ticket #11986 "incomplete fallback in MeasureFormat". | |
1805 | // In CLDR 28, fr_CA temperature-generic/short has only the "one" form, | |
1806 | // and falls back to fr for the "other" form. | |
1807 | IcuTestErrorCode errorCode(*this, "TestIndividualPluralFallback"); | |
1808 | MeasureFormat mf("fr_CA", UMEASFMT_WIDTH_SHORT, errorCode); | |
1809 | LocalPointer<Measure> twoDeg( | |
1810 | new Measure(2, MeasureUnit::createGenericTemperature(errorCode), errorCode), errorCode); | |
1811 | UnicodeString expected = UNICODE_STRING_SIMPLE("2\\u00B0").unescape(); | |
1812 | UnicodeString actual; | |
1813 | assertEquals("2 deg temp in fr_CA", expected, mf.format(twoDeg.orphan(), actual, errorCode), TRUE); | |
1814 | } | |
1815 | ||
57a6839d A |
1816 | void MeasureFormatTest::verifyFieldPosition( |
1817 | const char *description, | |
1818 | const MeasureFormat &fmt, | |
1819 | const UnicodeString &prefix, | |
1820 | const Measure *measures, | |
1821 | int32_t measureCount, | |
1822 | NumberFormat::EAlignmentFields field, | |
1823 | int32_t start, | |
1824 | int32_t end) { | |
1825 | // 8 char lead | |
1826 | UnicodeString result(prefix); | |
1827 | FieldPosition pos(field); | |
1828 | UErrorCode status = U_ZERO_ERROR; | |
1829 | CharString ch; | |
1830 | const char *descPrefix = ch.append(description, status) | |
1831 | .append(": ", status).data(); | |
1832 | CharString beginIndex; | |
1833 | beginIndex.append(descPrefix, status).append("beginIndex", status); | |
1834 | CharString endIndex; | |
1835 | endIndex.append(descPrefix, status).append("endIndex", status); | |
1836 | fmt.formatMeasures(measures, measureCount, result, pos, status); | |
1837 | if (!assertSuccess("Error formatting", status)) { | |
1838 | return; | |
1839 | } | |
1840 | assertEquals(beginIndex.data(), start, pos.getBeginIndex()); | |
1841 | assertEquals(endIndex.data(), end, pos.getEndIndex()); | |
1842 | } | |
1843 | ||
1844 | void MeasureFormatTest::verifyFormat( | |
1845 | const char *description, | |
1846 | const MeasureFormat &fmt, | |
1847 | const Measure *measures, | |
1848 | int32_t measureCount, | |
1849 | const char *expected) { | |
1850 | verifyFormatWithPrefix( | |
1851 | description, | |
1852 | fmt, | |
1853 | "", | |
1854 | measures, | |
1855 | measureCount, | |
1856 | expected); | |
1857 | } | |
1858 | ||
1859 | void MeasureFormatTest::verifyFormatWithPrefix( | |
1860 | const char *description, | |
1861 | const MeasureFormat &fmt, | |
1862 | const UnicodeString &prefix, | |
1863 | const Measure *measures, | |
1864 | int32_t measureCount, | |
1865 | const char *expected) { | |
1866 | UnicodeString result(prefix); | |
1867 | FieldPosition pos(0); | |
1868 | UErrorCode status = U_ZERO_ERROR; | |
1869 | fmt.formatMeasures(measures, measureCount, result, pos, status); | |
1870 | if (!assertSuccess("Error formatting", status)) { | |
1871 | return; | |
1872 | } | |
1873 | assertEquals(description, UnicodeString(expected).unescape(), result); | |
1874 | } | |
1875 | ||
1876 | void MeasureFormatTest::verifyFormat( | |
1877 | const char *description, | |
1878 | const MeasureFormat &fmt, | |
1879 | const ExpectedResult *expectedResults, | |
1880 | int32_t count) { | |
1881 | for (int32_t i = 0; i < count; ++i) { | |
1882 | verifyFormat(description, fmt, expectedResults[i].measures, expectedResults[i].count, expectedResults[i].expected); | |
1883 | } | |
1884 | } | |
1885 | ||
1886 | extern IntlTest *createMeasureFormatTest() { | |
1887 | return new MeasureFormatTest(); | |
1888 | } | |
1889 | ||
1890 | #endif | |
1891 |