1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2014-2016, International Business Machines Corporation and *
6 * others. All Rights Reserved. *
7 *******************************************************************************
8 *
9 * File MEASFMTTEST.CPP
10 *
11 *******************************************************************************
12 */
13 #include <stdio.h>
14 #include <stdlib.h>
15
16 #include "intltest.h"
17
18 #if !UCONFIG_NO_FORMATTING
19
20 #include "unicode/decimfmt.h"
21 #include "unicode/measfmt.h"
22 #include "unicode/measure.h"
23 #include "unicode/measunit.h"
24 #include "unicode/strenum.h"
25 #include "unicode/tmunit.h"
26 #include "unicode/plurrule.h"
27 #include "unicode/ustring.h"
28 #include "charstr.h"
29 #include "cstr.h"
30 #include "unicode/reldatefmt.h"
31
32 struct ExpectedResult {
33 const Measure *measures;
34 int32_t count;
35 const char *expected;
36 };
37
38 class MeasureFormatTest : public IntlTest {
39 public:
MeasureFormatTest()40 MeasureFormatTest() {
41 }
42
43 void runIndexedTest(int32_t index, UBool exec, const char *&name, char *par=0);
44 private:
45 void TestBasic();
46 void TestCompatible53();
47 void TestCompatible54();
48 void TestCompatible55();
49 void TestCompatible56();
50 void TestCompatible57();
51 void TestCompatible58();
52 void TestCompatible59();
53 void TestCompatible63();
54 void TestGetAvailable();
55 void TestExamplesInDocs();
56 void TestFormatPeriodEn();
57 void Test10219FractionalPlurals();
58 void TestGreek();
59 void TestFormatSingleArg();
60 void TestFormatMeasuresZeroArg();
61 void TestSimplePer();
62 void TestNumeratorPlurals();
63 void TestMultiples();
64 void TestManyLocaleDurations();
65 void TestGram();
66 void TestCurrencies();
67 void TestDisplayNames();
68 void TestFieldPosition();
69 void TestFieldPositionMultiple();
70 void TestBadArg();
71 void TestEquality();
72 void TestGroupingSeparator();
73 void TestDoubleZero();
74 void TestUnitPerUnitResolution();
75 void TestIndividualPluralFallback();
76 void verifyFormat(
77 const char *description,
78 const MeasureFormat &fmt,
79 const Measure *measures,
80 int32_t measureCount,
81 const char *expected);
82 void verifyFormatWithPrefix(
83 const char *description,
84 const MeasureFormat &fmt,
85 const UnicodeString &prefix,
86 const Measure *measures,
87 int32_t measureCount,
88 const char *expected);
89 void verifyFormat(
90 const char *description,
91 const MeasureFormat &fmt,
92 const ExpectedResult *expectedResults,
93 int32_t count);
94 void helperTestSimplePer(
95 const Locale &locale,
96 UMeasureFormatWidth width,
97 double value,
98 const MeasureUnit &unit,
99 const MeasureUnit &perUnit,
100 const char *expected);
101 void helperTestSimplePer(
102 const Locale &locale,
103 UMeasureFormatWidth width,
104 double value,
105 const MeasureUnit &unit,
106 const MeasureUnit &perUnit,
107 const char *expected,
108 int32_t field,
109 int32_t expected_start,
110 int32_t expected_end);
111 void helperTestMultiples(
112 const Locale &locale,
113 UMeasureFormatWidth width,
114 const char *expected);
115 void helperTestManyLocaleDurations(
116 const char *localeID,
117 UMeasureFormatWidth width,
118 const Measure *measures,
119 int32_t measureCount,
120 const char *expected);
121 void helperTestDisplayName(
122 const MeasureUnit *unit,
123 const char *localeID,
124 UMeasureFormatWidth width,
125 const char *expected);
126 void verifyFieldPosition(
127 const char *description,
128 const MeasureFormat &fmt,
129 const UnicodeString &prefix,
130 const Measure *measures,
131 int32_t measureCount,
132 NumberFormat::EAlignmentFields field,
133 int32_t start,
134 int32_t end);
135 };
136
runIndexedTest(int32_t index,UBool exec,const char * & name,char *)137 void MeasureFormatTest::runIndexedTest(
138 int32_t index, UBool exec, const char *&name, char *) {
139 if (exec) {
140 logln("TestSuite MeasureFormatTest: ");
141 }
142 TESTCASE_AUTO_BEGIN;
143 TESTCASE_AUTO(TestBasic);
144 TESTCASE_AUTO(TestCompatible53);
145 TESTCASE_AUTO(TestCompatible54);
146 TESTCASE_AUTO(TestCompatible55);
147 TESTCASE_AUTO(TestCompatible56);
148 TESTCASE_AUTO(TestCompatible57);
149 TESTCASE_AUTO(TestCompatible58);
150 TESTCASE_AUTO(TestCompatible59);
151 TESTCASE_AUTO(TestCompatible63);
152 TESTCASE_AUTO(TestGetAvailable);
153 TESTCASE_AUTO(TestExamplesInDocs);
154 TESTCASE_AUTO(TestFormatPeriodEn);
155 TESTCASE_AUTO(Test10219FractionalPlurals);
156 TESTCASE_AUTO(TestGreek);
157 TESTCASE_AUTO(TestFormatSingleArg);
158 TESTCASE_AUTO(TestFormatMeasuresZeroArg);
159 TESTCASE_AUTO(TestSimplePer);
160 TESTCASE_AUTO(TestNumeratorPlurals);
161 TESTCASE_AUTO(TestMultiples);
162 TESTCASE_AUTO(TestManyLocaleDurations);
163 TESTCASE_AUTO(TestGram);
164 TESTCASE_AUTO(TestCurrencies);
165 TESTCASE_AUTO(TestDisplayNames);
166 TESTCASE_AUTO(TestFieldPosition);
167 TESTCASE_AUTO(TestFieldPositionMultiple);
168 TESTCASE_AUTO(TestBadArg);
169 TESTCASE_AUTO(TestEquality);
170 TESTCASE_AUTO(TestGroupingSeparator);
171 TESTCASE_AUTO(TestDoubleZero);
172 TESTCASE_AUTO(TestUnitPerUnitResolution);
173 TESTCASE_AUTO(TestIndividualPluralFallback);
174 TESTCASE_AUTO_END;
175 }
176
TestCompatible53()177 void MeasureFormatTest::TestCompatible53() {
178 UErrorCode status = U_ZERO_ERROR;
179 LocalPointer<MeasureUnit> measureUnit;
180 measureUnit.adoptInstead(MeasureUnit::createGForce(status));
181 measureUnit.adoptInstead(MeasureUnit::createArcMinute(status));
182 measureUnit.adoptInstead(MeasureUnit::createArcSecond(status));
183 measureUnit.adoptInstead(MeasureUnit::createDegree(status));
184 measureUnit.adoptInstead(MeasureUnit::createAcre(status));
185 measureUnit.adoptInstead(MeasureUnit::createHectare(status));
186 measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status));
187 measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status));
188 measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status));
189 measureUnit.adoptInstead(MeasureUnit::createSquareMile(status));
190 measureUnit.adoptInstead(MeasureUnit::createDay(status));
191 measureUnit.adoptInstead(MeasureUnit::createHour(status));
192 measureUnit.adoptInstead(MeasureUnit::createMillisecond(status));
193 measureUnit.adoptInstead(MeasureUnit::createMinute(status));
194 measureUnit.adoptInstead(MeasureUnit::createMonth(status));
195 measureUnit.adoptInstead(MeasureUnit::createSecond(status));
196 measureUnit.adoptInstead(MeasureUnit::createWeek(status));
197 measureUnit.adoptInstead(MeasureUnit::createYear(status));
198 measureUnit.adoptInstead(MeasureUnit::createCentimeter(status));
199 measureUnit.adoptInstead(MeasureUnit::createFoot(status));
200 measureUnit.adoptInstead(MeasureUnit::createInch(status));
201 measureUnit.adoptInstead(MeasureUnit::createKilometer(status));
202 measureUnit.adoptInstead(MeasureUnit::createLightYear(status));
203 measureUnit.adoptInstead(MeasureUnit::createMeter(status));
204 measureUnit.adoptInstead(MeasureUnit::createMile(status));
205 measureUnit.adoptInstead(MeasureUnit::createMillimeter(status));
206 measureUnit.adoptInstead(MeasureUnit::createPicometer(status));
207 measureUnit.adoptInstead(MeasureUnit::createYard(status));
208 measureUnit.adoptInstead(MeasureUnit::createGram(status));
209 measureUnit.adoptInstead(MeasureUnit::createKilogram(status));
210 measureUnit.adoptInstead(MeasureUnit::createOunce(status));
211 measureUnit.adoptInstead(MeasureUnit::createPound(status));
212 measureUnit.adoptInstead(MeasureUnit::createHorsepower(status));
213 measureUnit.adoptInstead(MeasureUnit::createKilowatt(status));
214 measureUnit.adoptInstead(MeasureUnit::createWatt(status));
215 measureUnit.adoptInstead(MeasureUnit::createHectopascal(status));
216 measureUnit.adoptInstead(MeasureUnit::createInchHg(status));
217 measureUnit.adoptInstead(MeasureUnit::createMillibar(status));
218 measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status));
219 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status));
220 measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status));
221 measureUnit.adoptInstead(MeasureUnit::createCelsius(status));
222 measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status));
223 measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status));
224 measureUnit.adoptInstead(MeasureUnit::createCubicMile(status));
225 measureUnit.adoptInstead(MeasureUnit::createLiter(status));
226 assertSuccess("", status);
227 }
228
TestCompatible54()229 void MeasureFormatTest::TestCompatible54() {
230 UErrorCode status = U_ZERO_ERROR;
231 LocalPointer<MeasureUnit> measureUnit;
232 measureUnit.adoptInstead(MeasureUnit::createGForce(status));
233 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecondSquared(status));
234 measureUnit.adoptInstead(MeasureUnit::createArcMinute(status));
235 measureUnit.adoptInstead(MeasureUnit::createArcSecond(status));
236 measureUnit.adoptInstead(MeasureUnit::createDegree(status));
237 measureUnit.adoptInstead(MeasureUnit::createRadian(status));
238 measureUnit.adoptInstead(MeasureUnit::createAcre(status));
239 measureUnit.adoptInstead(MeasureUnit::createHectare(status));
240 measureUnit.adoptInstead(MeasureUnit::createSquareCentimeter(status));
241 measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status));
242 measureUnit.adoptInstead(MeasureUnit::createSquareInch(status));
243 measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status));
244 measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status));
245 measureUnit.adoptInstead(MeasureUnit::createSquareMile(status));
246 measureUnit.adoptInstead(MeasureUnit::createSquareYard(status));
247 measureUnit.adoptInstead(MeasureUnit::createLiterPerKilometer(status));
248 measureUnit.adoptInstead(MeasureUnit::createMilePerGallon(status));
249 measureUnit.adoptInstead(MeasureUnit::createBit(status));
250 measureUnit.adoptInstead(MeasureUnit::createByte(status));
251 measureUnit.adoptInstead(MeasureUnit::createGigabit(status));
252 measureUnit.adoptInstead(MeasureUnit::createGigabyte(status));
253 measureUnit.adoptInstead(MeasureUnit::createKilobit(status));
254 measureUnit.adoptInstead(MeasureUnit::createKilobyte(status));
255 measureUnit.adoptInstead(MeasureUnit::createMegabit(status));
256 measureUnit.adoptInstead(MeasureUnit::createMegabyte(status));
257 measureUnit.adoptInstead(MeasureUnit::createTerabit(status));
258 measureUnit.adoptInstead(MeasureUnit::createTerabyte(status));
259 measureUnit.adoptInstead(MeasureUnit::createDay(status));
260 measureUnit.adoptInstead(MeasureUnit::createHour(status));
261 measureUnit.adoptInstead(MeasureUnit::createMicrosecond(status));
262 measureUnit.adoptInstead(MeasureUnit::createMillisecond(status));
263 measureUnit.adoptInstead(MeasureUnit::createMinute(status));
264 measureUnit.adoptInstead(MeasureUnit::createMonth(status));
265 measureUnit.adoptInstead(MeasureUnit::createNanosecond(status));
266 measureUnit.adoptInstead(MeasureUnit::createSecond(status));
267 measureUnit.adoptInstead(MeasureUnit::createWeek(status));
268 measureUnit.adoptInstead(MeasureUnit::createYear(status));
269 measureUnit.adoptInstead(MeasureUnit::createAmpere(status));
270 measureUnit.adoptInstead(MeasureUnit::createMilliampere(status));
271 measureUnit.adoptInstead(MeasureUnit::createOhm(status));
272 measureUnit.adoptInstead(MeasureUnit::createVolt(status));
273 measureUnit.adoptInstead(MeasureUnit::createCalorie(status));
274 measureUnit.adoptInstead(MeasureUnit::createFoodcalorie(status));
275 measureUnit.adoptInstead(MeasureUnit::createJoule(status));
276 measureUnit.adoptInstead(MeasureUnit::createKilocalorie(status));
277 measureUnit.adoptInstead(MeasureUnit::createKilojoule(status));
278 measureUnit.adoptInstead(MeasureUnit::createKilowattHour(status));
279 measureUnit.adoptInstead(MeasureUnit::createGigahertz(status));
280 measureUnit.adoptInstead(MeasureUnit::createHertz(status));
281 measureUnit.adoptInstead(MeasureUnit::createKilohertz(status));
282 measureUnit.adoptInstead(MeasureUnit::createMegahertz(status));
283 measureUnit.adoptInstead(MeasureUnit::createAstronomicalUnit(status));
284 measureUnit.adoptInstead(MeasureUnit::createCentimeter(status));
285 measureUnit.adoptInstead(MeasureUnit::createDecimeter(status));
286 measureUnit.adoptInstead(MeasureUnit::createFathom(status));
287 measureUnit.adoptInstead(MeasureUnit::createFoot(status));
288 measureUnit.adoptInstead(MeasureUnit::createFurlong(status));
289 measureUnit.adoptInstead(MeasureUnit::createInch(status));
290 measureUnit.adoptInstead(MeasureUnit::createKilometer(status));
291 measureUnit.adoptInstead(MeasureUnit::createLightYear(status));
292 measureUnit.adoptInstead(MeasureUnit::createMeter(status));
293 measureUnit.adoptInstead(MeasureUnit::createMicrometer(status));
294 measureUnit.adoptInstead(MeasureUnit::createMile(status));
295 measureUnit.adoptInstead(MeasureUnit::createMillimeter(status));
296 measureUnit.adoptInstead(MeasureUnit::createNanometer(status));
297 measureUnit.adoptInstead(MeasureUnit::createNauticalMile(status));
298 measureUnit.adoptInstead(MeasureUnit::createParsec(status));
299 measureUnit.adoptInstead(MeasureUnit::createPicometer(status));
300 measureUnit.adoptInstead(MeasureUnit::createYard(status));
301 measureUnit.adoptInstead(MeasureUnit::createLux(status));
302 measureUnit.adoptInstead(MeasureUnit::createCarat(status));
303 measureUnit.adoptInstead(MeasureUnit::createGram(status));
304 measureUnit.adoptInstead(MeasureUnit::createKilogram(status));
305 measureUnit.adoptInstead(MeasureUnit::createMetricTon(status));
306 measureUnit.adoptInstead(MeasureUnit::createMicrogram(status));
307 measureUnit.adoptInstead(MeasureUnit::createMilligram(status));
308 measureUnit.adoptInstead(MeasureUnit::createOunce(status));
309 measureUnit.adoptInstead(MeasureUnit::createOunceTroy(status));
310 measureUnit.adoptInstead(MeasureUnit::createPound(status));
311 measureUnit.adoptInstead(MeasureUnit::createStone(status));
312 measureUnit.adoptInstead(MeasureUnit::createTon(status));
313 measureUnit.adoptInstead(MeasureUnit::createGigawatt(status));
314 measureUnit.adoptInstead(MeasureUnit::createHorsepower(status));
315 measureUnit.adoptInstead(MeasureUnit::createKilowatt(status));
316 measureUnit.adoptInstead(MeasureUnit::createMegawatt(status));
317 measureUnit.adoptInstead(MeasureUnit::createMilliwatt(status));
318 measureUnit.adoptInstead(MeasureUnit::createWatt(status));
319 measureUnit.adoptInstead(MeasureUnit::createHectopascal(status));
320 measureUnit.adoptInstead(MeasureUnit::createInchHg(status));
321 measureUnit.adoptInstead(MeasureUnit::createMillibar(status));
322 measureUnit.adoptInstead(MeasureUnit::createMillimeterOfMercury(status));
323 measureUnit.adoptInstead(MeasureUnit::createPoundPerSquareInch(status));
324 measureUnit.adoptInstead(MeasureUnit::createKarat(status));
325 measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status));
326 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status));
327 measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status));
328 measureUnit.adoptInstead(MeasureUnit::createCelsius(status));
329 measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status));
330 measureUnit.adoptInstead(MeasureUnit::createKelvin(status));
331 measureUnit.adoptInstead(MeasureUnit::createAcreFoot(status));
332 measureUnit.adoptInstead(MeasureUnit::createBushel(status));
333 measureUnit.adoptInstead(MeasureUnit::createCentiliter(status));
334 measureUnit.adoptInstead(MeasureUnit::createCubicCentimeter(status));
335 measureUnit.adoptInstead(MeasureUnit::createCubicFoot(status));
336 measureUnit.adoptInstead(MeasureUnit::createCubicInch(status));
337 measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status));
338 measureUnit.adoptInstead(MeasureUnit::createCubicMeter(status));
339 measureUnit.adoptInstead(MeasureUnit::createCubicMile(status));
340 measureUnit.adoptInstead(MeasureUnit::createCubicYard(status));
341 measureUnit.adoptInstead(MeasureUnit::createCup(status));
342 measureUnit.adoptInstead(MeasureUnit::createDeciliter(status));
343 measureUnit.adoptInstead(MeasureUnit::createFluidOunce(status));
344 measureUnit.adoptInstead(MeasureUnit::createGallon(status));
345 measureUnit.adoptInstead(MeasureUnit::createHectoliter(status));
346 measureUnit.adoptInstead(MeasureUnit::createLiter(status));
347 measureUnit.adoptInstead(MeasureUnit::createMegaliter(status));
348 measureUnit.adoptInstead(MeasureUnit::createMilliliter(status));
349 measureUnit.adoptInstead(MeasureUnit::createPint(status));
350 measureUnit.adoptInstead(MeasureUnit::createQuart(status));
351 measureUnit.adoptInstead(MeasureUnit::createTablespoon(status));
352 measureUnit.adoptInstead(MeasureUnit::createTeaspoon(status));
353 assertSuccess("", status);
354 }
355
TestCompatible55()356 void MeasureFormatTest::TestCompatible55() {
357 UErrorCode status = U_ZERO_ERROR;
358 LocalPointer<MeasureUnit> measureUnit;
359 measureUnit.adoptInstead(MeasureUnit::createGForce(status));
360 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecondSquared(status));
361 measureUnit.adoptInstead(MeasureUnit::createArcMinute(status));
362 measureUnit.adoptInstead(MeasureUnit::createArcSecond(status));
363 measureUnit.adoptInstead(MeasureUnit::createDegree(status));
364 measureUnit.adoptInstead(MeasureUnit::createRadian(status));
365 measureUnit.adoptInstead(MeasureUnit::createAcre(status));
366 measureUnit.adoptInstead(MeasureUnit::createHectare(status));
367 measureUnit.adoptInstead(MeasureUnit::createSquareCentimeter(status));
368 measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status));
369 measureUnit.adoptInstead(MeasureUnit::createSquareInch(status));
370 measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status));
371 measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status));
372 measureUnit.adoptInstead(MeasureUnit::createSquareMile(status));
373 measureUnit.adoptInstead(MeasureUnit::createSquareYard(status));
374 measureUnit.adoptInstead(MeasureUnit::createLiterPerKilometer(status));
375 measureUnit.adoptInstead(MeasureUnit::createMilePerGallon(status));
376 measureUnit.adoptInstead(MeasureUnit::createBit(status));
377 measureUnit.adoptInstead(MeasureUnit::createByte(status));
378 measureUnit.adoptInstead(MeasureUnit::createGigabit(status));
379 measureUnit.adoptInstead(MeasureUnit::createGigabyte(status));
380 measureUnit.adoptInstead(MeasureUnit::createKilobit(status));
381 measureUnit.adoptInstead(MeasureUnit::createKilobyte(status));
382 measureUnit.adoptInstead(MeasureUnit::createMegabit(status));
383 measureUnit.adoptInstead(MeasureUnit::createMegabyte(status));
384 measureUnit.adoptInstead(MeasureUnit::createTerabit(status));
385 measureUnit.adoptInstead(MeasureUnit::createTerabyte(status));
386 measureUnit.adoptInstead(MeasureUnit::createDay(status));
387 measureUnit.adoptInstead(MeasureUnit::createHour(status));
388 measureUnit.adoptInstead(MeasureUnit::createMicrosecond(status));
389 measureUnit.adoptInstead(MeasureUnit::createMillisecond(status));
390 measureUnit.adoptInstead(MeasureUnit::createMinute(status));
391 measureUnit.adoptInstead(MeasureUnit::createMonth(status));
392 measureUnit.adoptInstead(MeasureUnit::createNanosecond(status));
393 measureUnit.adoptInstead(MeasureUnit::createSecond(status));
394 measureUnit.adoptInstead(MeasureUnit::createWeek(status));
395 measureUnit.adoptInstead(MeasureUnit::createYear(status));
396 measureUnit.adoptInstead(MeasureUnit::createAmpere(status));
397 measureUnit.adoptInstead(MeasureUnit::createMilliampere(status));
398 measureUnit.adoptInstead(MeasureUnit::createOhm(status));
399 measureUnit.adoptInstead(MeasureUnit::createVolt(status));
400 measureUnit.adoptInstead(MeasureUnit::createCalorie(status));
401 measureUnit.adoptInstead(MeasureUnit::createFoodcalorie(status));
402 measureUnit.adoptInstead(MeasureUnit::createJoule(status));
403 measureUnit.adoptInstead(MeasureUnit::createKilocalorie(status));
404 measureUnit.adoptInstead(MeasureUnit::createKilojoule(status));
405 measureUnit.adoptInstead(MeasureUnit::createKilowattHour(status));
406 measureUnit.adoptInstead(MeasureUnit::createGigahertz(status));
407 measureUnit.adoptInstead(MeasureUnit::createHertz(status));
408 measureUnit.adoptInstead(MeasureUnit::createKilohertz(status));
409 measureUnit.adoptInstead(MeasureUnit::createMegahertz(status));
410 measureUnit.adoptInstead(MeasureUnit::createAstronomicalUnit(status));
411 measureUnit.adoptInstead(MeasureUnit::createCentimeter(status));
412 measureUnit.adoptInstead(MeasureUnit::createDecimeter(status));
413 measureUnit.adoptInstead(MeasureUnit::createFathom(status));
414 measureUnit.adoptInstead(MeasureUnit::createFoot(status));
415 measureUnit.adoptInstead(MeasureUnit::createFurlong(status));
416 measureUnit.adoptInstead(MeasureUnit::createInch(status));
417 measureUnit.adoptInstead(MeasureUnit::createKilometer(status));
418 measureUnit.adoptInstead(MeasureUnit::createLightYear(status));
419 measureUnit.adoptInstead(MeasureUnit::createMeter(status));
420 measureUnit.adoptInstead(MeasureUnit::createMicrometer(status));
421 measureUnit.adoptInstead(MeasureUnit::createMile(status));
422 measureUnit.adoptInstead(MeasureUnit::createMillimeter(status));
423 measureUnit.adoptInstead(MeasureUnit::createNanometer(status));
424 measureUnit.adoptInstead(MeasureUnit::createNauticalMile(status));
425 measureUnit.adoptInstead(MeasureUnit::createParsec(status));
426 measureUnit.adoptInstead(MeasureUnit::createPicometer(status));
427 measureUnit.adoptInstead(MeasureUnit::createYard(status));
428 measureUnit.adoptInstead(MeasureUnit::createLux(status));
429 measureUnit.adoptInstead(MeasureUnit::createCarat(status));
430 measureUnit.adoptInstead(MeasureUnit::createGram(status));
431 measureUnit.adoptInstead(MeasureUnit::createKilogram(status));
432 measureUnit.adoptInstead(MeasureUnit::createMetricTon(status));
433 measureUnit.adoptInstead(MeasureUnit::createMicrogram(status));
434 measureUnit.adoptInstead(MeasureUnit::createMilligram(status));
435 measureUnit.adoptInstead(MeasureUnit::createOunce(status));
436 measureUnit.adoptInstead(MeasureUnit::createOunceTroy(status));
437 measureUnit.adoptInstead(MeasureUnit::createPound(status));
438 measureUnit.adoptInstead(MeasureUnit::createStone(status));
439 measureUnit.adoptInstead(MeasureUnit::createTon(status));
440 measureUnit.adoptInstead(MeasureUnit::createGigawatt(status));
441 measureUnit.adoptInstead(MeasureUnit::createHorsepower(status));
442 measureUnit.adoptInstead(MeasureUnit::createKilowatt(status));
443 measureUnit.adoptInstead(MeasureUnit::createMegawatt(status));
444 measureUnit.adoptInstead(MeasureUnit::createMilliwatt(status));
445 measureUnit.adoptInstead(MeasureUnit::createWatt(status));
446 measureUnit.adoptInstead(MeasureUnit::createHectopascal(status));
447 measureUnit.adoptInstead(MeasureUnit::createInchHg(status));
448 measureUnit.adoptInstead(MeasureUnit::createMillibar(status));
449 measureUnit.adoptInstead(MeasureUnit::createMillimeterOfMercury(status));
450 measureUnit.adoptInstead(MeasureUnit::createPoundPerSquareInch(status));
451 measureUnit.adoptInstead(MeasureUnit::createKarat(status));
452 measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status));
453 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status));
454 measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status));
455 measureUnit.adoptInstead(MeasureUnit::createCelsius(status));
456 measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status));
457 measureUnit.adoptInstead(MeasureUnit::createGenericTemperature(status));
458 measureUnit.adoptInstead(MeasureUnit::createKelvin(status));
459 measureUnit.adoptInstead(MeasureUnit::createAcreFoot(status));
460 measureUnit.adoptInstead(MeasureUnit::createBushel(status));
461 measureUnit.adoptInstead(MeasureUnit::createCentiliter(status));
462 measureUnit.adoptInstead(MeasureUnit::createCubicCentimeter(status));
463 measureUnit.adoptInstead(MeasureUnit::createCubicFoot(status));
464 measureUnit.adoptInstead(MeasureUnit::createCubicInch(status));
465 measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status));
466 measureUnit.adoptInstead(MeasureUnit::createCubicMeter(status));
467 measureUnit.adoptInstead(MeasureUnit::createCubicMile(status));
468 measureUnit.adoptInstead(MeasureUnit::createCubicYard(status));
469 measureUnit.adoptInstead(MeasureUnit::createCup(status));
470 measureUnit.adoptInstead(MeasureUnit::createDeciliter(status));
471 measureUnit.adoptInstead(MeasureUnit::createFluidOunce(status));
472 measureUnit.adoptInstead(MeasureUnit::createGallon(status));
473 measureUnit.adoptInstead(MeasureUnit::createHectoliter(status));
474 measureUnit.adoptInstead(MeasureUnit::createLiter(status));
475 measureUnit.adoptInstead(MeasureUnit::createMegaliter(status));
476 measureUnit.adoptInstead(MeasureUnit::createMilliliter(status));
477 measureUnit.adoptInstead(MeasureUnit::createPint(status));
478 measureUnit.adoptInstead(MeasureUnit::createQuart(status));
479 measureUnit.adoptInstead(MeasureUnit::createTablespoon(status));
480 measureUnit.adoptInstead(MeasureUnit::createTeaspoon(status));
481 assertSuccess("", status);
482 }
483
TestCompatible56()484 void MeasureFormatTest::TestCompatible56() {
485 UErrorCode status = U_ZERO_ERROR;
486 LocalPointer<MeasureUnit> measureUnit;
487 measureUnit.adoptInstead(MeasureUnit::createGForce(status));
488 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecondSquared(status));
489 measureUnit.adoptInstead(MeasureUnit::createArcMinute(status));
490 measureUnit.adoptInstead(MeasureUnit::createArcSecond(status));
491 measureUnit.adoptInstead(MeasureUnit::createDegree(status));
492 measureUnit.adoptInstead(MeasureUnit::createRadian(status));
493 measureUnit.adoptInstead(MeasureUnit::createRevolutionAngle(status));
494 measureUnit.adoptInstead(MeasureUnit::createAcre(status));
495 measureUnit.adoptInstead(MeasureUnit::createHectare(status));
496 measureUnit.adoptInstead(MeasureUnit::createSquareCentimeter(status));
497 measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status));
498 measureUnit.adoptInstead(MeasureUnit::createSquareInch(status));
499 measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status));
500 measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status));
501 measureUnit.adoptInstead(MeasureUnit::createSquareMile(status));
502 measureUnit.adoptInstead(MeasureUnit::createSquareYard(status));
503 measureUnit.adoptInstead(MeasureUnit::createLiterPer100Kilometers(status));
504 measureUnit.adoptInstead(MeasureUnit::createLiterPerKilometer(status));
505 measureUnit.adoptInstead(MeasureUnit::createMilePerGallon(status));
506 measureUnit.adoptInstead(MeasureUnit::createBit(status));
507 measureUnit.adoptInstead(MeasureUnit::createByte(status));
508 measureUnit.adoptInstead(MeasureUnit::createGigabit(status));
509 measureUnit.adoptInstead(MeasureUnit::createGigabyte(status));
510 measureUnit.adoptInstead(MeasureUnit::createKilobit(status));
511 measureUnit.adoptInstead(MeasureUnit::createKilobyte(status));
512 measureUnit.adoptInstead(MeasureUnit::createMegabit(status));
513 measureUnit.adoptInstead(MeasureUnit::createMegabyte(status));
514 measureUnit.adoptInstead(MeasureUnit::createTerabit(status));
515 measureUnit.adoptInstead(MeasureUnit::createTerabyte(status));
516 measureUnit.adoptInstead(MeasureUnit::createCentury(status));
517 measureUnit.adoptInstead(MeasureUnit::createDay(status));
518 measureUnit.adoptInstead(MeasureUnit::createHour(status));
519 measureUnit.adoptInstead(MeasureUnit::createMicrosecond(status));
520 measureUnit.adoptInstead(MeasureUnit::createMillisecond(status));
521 measureUnit.adoptInstead(MeasureUnit::createMinute(status));
522 measureUnit.adoptInstead(MeasureUnit::createMonth(status));
523 measureUnit.adoptInstead(MeasureUnit::createNanosecond(status));
524 measureUnit.adoptInstead(MeasureUnit::createSecond(status));
525 measureUnit.adoptInstead(MeasureUnit::createWeek(status));
526 measureUnit.adoptInstead(MeasureUnit::createYear(status));
527 measureUnit.adoptInstead(MeasureUnit::createAmpere(status));
528 measureUnit.adoptInstead(MeasureUnit::createMilliampere(status));
529 measureUnit.adoptInstead(MeasureUnit::createOhm(status));
530 measureUnit.adoptInstead(MeasureUnit::createVolt(status));
531 measureUnit.adoptInstead(MeasureUnit::createCalorie(status));
532 measureUnit.adoptInstead(MeasureUnit::createFoodcalorie(status));
533 measureUnit.adoptInstead(MeasureUnit::createJoule(status));
534 measureUnit.adoptInstead(MeasureUnit::createKilocalorie(status));
535 measureUnit.adoptInstead(MeasureUnit::createKilojoule(status));
536 measureUnit.adoptInstead(MeasureUnit::createKilowattHour(status));
537 measureUnit.adoptInstead(MeasureUnit::createGigahertz(status));
538 measureUnit.adoptInstead(MeasureUnit::createHertz(status));
539 measureUnit.adoptInstead(MeasureUnit::createKilohertz(status));
540 measureUnit.adoptInstead(MeasureUnit::createMegahertz(status));
541 measureUnit.adoptInstead(MeasureUnit::createAstronomicalUnit(status));
542 measureUnit.adoptInstead(MeasureUnit::createCentimeter(status));
543 measureUnit.adoptInstead(MeasureUnit::createDecimeter(status));
544 measureUnit.adoptInstead(MeasureUnit::createFathom(status));
545 measureUnit.adoptInstead(MeasureUnit::createFoot(status));
546 measureUnit.adoptInstead(MeasureUnit::createFurlong(status));
547 measureUnit.adoptInstead(MeasureUnit::createInch(status));
548 measureUnit.adoptInstead(MeasureUnit::createKilometer(status));
549 measureUnit.adoptInstead(MeasureUnit::createLightYear(status));
550 measureUnit.adoptInstead(MeasureUnit::createMeter(status));
551 measureUnit.adoptInstead(MeasureUnit::createMicrometer(status));
552 measureUnit.adoptInstead(MeasureUnit::createMile(status));
553 measureUnit.adoptInstead(MeasureUnit::createMileScandinavian(status));
554 measureUnit.adoptInstead(MeasureUnit::createMillimeter(status));
555 measureUnit.adoptInstead(MeasureUnit::createNanometer(status));
556 measureUnit.adoptInstead(MeasureUnit::createNauticalMile(status));
557 measureUnit.adoptInstead(MeasureUnit::createParsec(status));
558 measureUnit.adoptInstead(MeasureUnit::createPicometer(status));
559 measureUnit.adoptInstead(MeasureUnit::createYard(status));
560 measureUnit.adoptInstead(MeasureUnit::createLux(status));
561 measureUnit.adoptInstead(MeasureUnit::createCarat(status));
562 measureUnit.adoptInstead(MeasureUnit::createGram(status));
563 measureUnit.adoptInstead(MeasureUnit::createKilogram(status));
564 measureUnit.adoptInstead(MeasureUnit::createMetricTon(status));
565 measureUnit.adoptInstead(MeasureUnit::createMicrogram(status));
566 measureUnit.adoptInstead(MeasureUnit::createMilligram(status));
567 measureUnit.adoptInstead(MeasureUnit::createOunce(status));
568 measureUnit.adoptInstead(MeasureUnit::createOunceTroy(status));
569 measureUnit.adoptInstead(MeasureUnit::createPound(status));
570 measureUnit.adoptInstead(MeasureUnit::createStone(status));
571 measureUnit.adoptInstead(MeasureUnit::createTon(status));
572 measureUnit.adoptInstead(MeasureUnit::createGigawatt(status));
573 measureUnit.adoptInstead(MeasureUnit::createHorsepower(status));
574 measureUnit.adoptInstead(MeasureUnit::createKilowatt(status));
575 measureUnit.adoptInstead(MeasureUnit::createMegawatt(status));
576 measureUnit.adoptInstead(MeasureUnit::createMilliwatt(status));
577 measureUnit.adoptInstead(MeasureUnit::createWatt(status));
578 measureUnit.adoptInstead(MeasureUnit::createHectopascal(status));
579 measureUnit.adoptInstead(MeasureUnit::createInchHg(status));
580 measureUnit.adoptInstead(MeasureUnit::createMillibar(status));
581 measureUnit.adoptInstead(MeasureUnit::createMillimeterOfMercury(status));
582 measureUnit.adoptInstead(MeasureUnit::createPoundPerSquareInch(status));
583 measureUnit.adoptInstead(MeasureUnit::createKarat(status));
584 measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status));
585 measureUnit.adoptInstead(MeasureUnit::createKnot(status));
586 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status));
587 measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status));
588 measureUnit.adoptInstead(MeasureUnit::createCelsius(status));
589 measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status));
590 measureUnit.adoptInstead(MeasureUnit::createGenericTemperature(status));
591 measureUnit.adoptInstead(MeasureUnit::createKelvin(status));
592 measureUnit.adoptInstead(MeasureUnit::createAcreFoot(status));
593 measureUnit.adoptInstead(MeasureUnit::createBushel(status));
594 measureUnit.adoptInstead(MeasureUnit::createCentiliter(status));
595 measureUnit.adoptInstead(MeasureUnit::createCubicCentimeter(status));
596 measureUnit.adoptInstead(MeasureUnit::createCubicFoot(status));
597 measureUnit.adoptInstead(MeasureUnit::createCubicInch(status));
598 measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status));
599 measureUnit.adoptInstead(MeasureUnit::createCubicMeter(status));
600 measureUnit.adoptInstead(MeasureUnit::createCubicMile(status));
601 measureUnit.adoptInstead(MeasureUnit::createCubicYard(status));
602 measureUnit.adoptInstead(MeasureUnit::createCup(status));
603 measureUnit.adoptInstead(MeasureUnit::createCupMetric(status));
604 measureUnit.adoptInstead(MeasureUnit::createDeciliter(status));
605 measureUnit.adoptInstead(MeasureUnit::createFluidOunce(status));
606 measureUnit.adoptInstead(MeasureUnit::createGallon(status));
607 measureUnit.adoptInstead(MeasureUnit::createHectoliter(status));
608 measureUnit.adoptInstead(MeasureUnit::createLiter(status));
609 measureUnit.adoptInstead(MeasureUnit::createMegaliter(status));
610 measureUnit.adoptInstead(MeasureUnit::createMilliliter(status));
611 measureUnit.adoptInstead(MeasureUnit::createPint(status));
612 measureUnit.adoptInstead(MeasureUnit::createPintMetric(status));
613 measureUnit.adoptInstead(MeasureUnit::createQuart(status));
614 measureUnit.adoptInstead(MeasureUnit::createTablespoon(status));
615 measureUnit.adoptInstead(MeasureUnit::createTeaspoon(status));
616 assertSuccess("", status);
617 }
618
TestCompatible57()619 void MeasureFormatTest::TestCompatible57() {
620 UErrorCode status = U_ZERO_ERROR;
621 LocalPointer<MeasureUnit> measureUnit;
622 measureUnit.adoptInstead(MeasureUnit::createGForce(status));
623 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecondSquared(status));
624 measureUnit.adoptInstead(MeasureUnit::createArcMinute(status));
625 measureUnit.adoptInstead(MeasureUnit::createArcSecond(status));
626 measureUnit.adoptInstead(MeasureUnit::createDegree(status));
627 measureUnit.adoptInstead(MeasureUnit::createRadian(status));
628 measureUnit.adoptInstead(MeasureUnit::createRevolutionAngle(status));
629 measureUnit.adoptInstead(MeasureUnit::createAcre(status));
630 measureUnit.adoptInstead(MeasureUnit::createHectare(status));
631 measureUnit.adoptInstead(MeasureUnit::createSquareCentimeter(status));
632 measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status));
633 measureUnit.adoptInstead(MeasureUnit::createSquareInch(status));
634 measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status));
635 measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status));
636 measureUnit.adoptInstead(MeasureUnit::createSquareMile(status));
637 measureUnit.adoptInstead(MeasureUnit::createSquareYard(status));
638 measureUnit.adoptInstead(MeasureUnit::createKarat(status));
639 measureUnit.adoptInstead(MeasureUnit::createMilligramPerDeciliter(status));
640 measureUnit.adoptInstead(MeasureUnit::createMillimolePerLiter(status));
641 measureUnit.adoptInstead(MeasureUnit::createPartPerMillion(status));
642 measureUnit.adoptInstead(MeasureUnit::createLiterPer100Kilometers(status));
643 measureUnit.adoptInstead(MeasureUnit::createLiterPerKilometer(status));
644 measureUnit.adoptInstead(MeasureUnit::createMilePerGallon(status));
645 measureUnit.adoptInstead(MeasureUnit::createMilePerGallonImperial(status));
646 measureUnit.adoptInstead(MeasureUnit::createBit(status));
647 measureUnit.adoptInstead(MeasureUnit::createByte(status));
648 measureUnit.adoptInstead(MeasureUnit::createGigabit(status));
649 measureUnit.adoptInstead(MeasureUnit::createGigabyte(status));
650 measureUnit.adoptInstead(MeasureUnit::createKilobit(status));
651 measureUnit.adoptInstead(MeasureUnit::createKilobyte(status));
652 measureUnit.adoptInstead(MeasureUnit::createMegabit(status));
653 measureUnit.adoptInstead(MeasureUnit::createMegabyte(status));
654 measureUnit.adoptInstead(MeasureUnit::createTerabit(status));
655 measureUnit.adoptInstead(MeasureUnit::createTerabyte(status));
656 measureUnit.adoptInstead(MeasureUnit::createCentury(status));
657 measureUnit.adoptInstead(MeasureUnit::createDay(status));
658 measureUnit.adoptInstead(MeasureUnit::createHour(status));
659 measureUnit.adoptInstead(MeasureUnit::createMicrosecond(status));
660 measureUnit.adoptInstead(MeasureUnit::createMillisecond(status));
661 measureUnit.adoptInstead(MeasureUnit::createMinute(status));
662 measureUnit.adoptInstead(MeasureUnit::createMonth(status));
663 measureUnit.adoptInstead(MeasureUnit::createNanosecond(status));
664 measureUnit.adoptInstead(MeasureUnit::createSecond(status));
665 measureUnit.adoptInstead(MeasureUnit::createWeek(status));
666 measureUnit.adoptInstead(MeasureUnit::createYear(status));
667 measureUnit.adoptInstead(MeasureUnit::createAmpere(status));
668 measureUnit.adoptInstead(MeasureUnit::createMilliampere(status));
669 measureUnit.adoptInstead(MeasureUnit::createOhm(status));
670 measureUnit.adoptInstead(MeasureUnit::createVolt(status));
671 measureUnit.adoptInstead(MeasureUnit::createCalorie(status));
672 measureUnit.adoptInstead(MeasureUnit::createFoodcalorie(status));
673 measureUnit.adoptInstead(MeasureUnit::createJoule(status));
674 measureUnit.adoptInstead(MeasureUnit::createKilocalorie(status));
675 measureUnit.adoptInstead(MeasureUnit::createKilojoule(status));
676 measureUnit.adoptInstead(MeasureUnit::createKilowattHour(status));
677 measureUnit.adoptInstead(MeasureUnit::createGigahertz(status));
678 measureUnit.adoptInstead(MeasureUnit::createHertz(status));
679 measureUnit.adoptInstead(MeasureUnit::createKilohertz(status));
680 measureUnit.adoptInstead(MeasureUnit::createMegahertz(status));
681 measureUnit.adoptInstead(MeasureUnit::createAstronomicalUnit(status));
682 measureUnit.adoptInstead(MeasureUnit::createCentimeter(status));
683 measureUnit.adoptInstead(MeasureUnit::createDecimeter(status));
684 measureUnit.adoptInstead(MeasureUnit::createFathom(status));
685 measureUnit.adoptInstead(MeasureUnit::createFoot(status));
686 measureUnit.adoptInstead(MeasureUnit::createFurlong(status));
687 measureUnit.adoptInstead(MeasureUnit::createInch(status));
688 measureUnit.adoptInstead(MeasureUnit::createKilometer(status));
689 measureUnit.adoptInstead(MeasureUnit::createLightYear(status));
690 measureUnit.adoptInstead(MeasureUnit::createMeter(status));
691 measureUnit.adoptInstead(MeasureUnit::createMicrometer(status));
692 measureUnit.adoptInstead(MeasureUnit::createMile(status));
693 measureUnit.adoptInstead(MeasureUnit::createMileScandinavian(status));
694 measureUnit.adoptInstead(MeasureUnit::createMillimeter(status));
695 measureUnit.adoptInstead(MeasureUnit::createNanometer(status));
696 measureUnit.adoptInstead(MeasureUnit::createNauticalMile(status));
697 measureUnit.adoptInstead(MeasureUnit::createParsec(status));
698 measureUnit.adoptInstead(MeasureUnit::createPicometer(status));
699 measureUnit.adoptInstead(MeasureUnit::createYard(status));
700 measureUnit.adoptInstead(MeasureUnit::createLux(status));
701 measureUnit.adoptInstead(MeasureUnit::createCarat(status));
702 measureUnit.adoptInstead(MeasureUnit::createGram(status));
703 measureUnit.adoptInstead(MeasureUnit::createKilogram(status));
704 measureUnit.adoptInstead(MeasureUnit::createMetricTon(status));
705 measureUnit.adoptInstead(MeasureUnit::createMicrogram(status));
706 measureUnit.adoptInstead(MeasureUnit::createMilligram(status));
707 measureUnit.adoptInstead(MeasureUnit::createOunce(status));
708 measureUnit.adoptInstead(MeasureUnit::createOunceTroy(status));
709 measureUnit.adoptInstead(MeasureUnit::createPound(status));
710 measureUnit.adoptInstead(MeasureUnit::createStone(status));
711 measureUnit.adoptInstead(MeasureUnit::createTon(status));
712 measureUnit.adoptInstead(MeasureUnit::createGigawatt(status));
713 measureUnit.adoptInstead(MeasureUnit::createHorsepower(status));
714 measureUnit.adoptInstead(MeasureUnit::createKilowatt(status));
715 measureUnit.adoptInstead(MeasureUnit::createMegawatt(status));
716 measureUnit.adoptInstead(MeasureUnit::createMilliwatt(status));
717 measureUnit.adoptInstead(MeasureUnit::createWatt(status));
718 measureUnit.adoptInstead(MeasureUnit::createHectopascal(status));
719 measureUnit.adoptInstead(MeasureUnit::createInchHg(status));
720 measureUnit.adoptInstead(MeasureUnit::createMillibar(status));
721 measureUnit.adoptInstead(MeasureUnit::createMillimeterOfMercury(status));
722 measureUnit.adoptInstead(MeasureUnit::createPoundPerSquareInch(status));
723 measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status));
724 measureUnit.adoptInstead(MeasureUnit::createKnot(status));
725 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status));
726 measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status));
727 measureUnit.adoptInstead(MeasureUnit::createCelsius(status));
728 measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status));
729 measureUnit.adoptInstead(MeasureUnit::createGenericTemperature(status));
730 measureUnit.adoptInstead(MeasureUnit::createKelvin(status));
731 measureUnit.adoptInstead(MeasureUnit::createAcreFoot(status));
732 measureUnit.adoptInstead(MeasureUnit::createBushel(status));
733 measureUnit.adoptInstead(MeasureUnit::createCentiliter(status));
734 measureUnit.adoptInstead(MeasureUnit::createCubicCentimeter(status));
735 measureUnit.adoptInstead(MeasureUnit::createCubicFoot(status));
736 measureUnit.adoptInstead(MeasureUnit::createCubicInch(status));
737 measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status));
738 measureUnit.adoptInstead(MeasureUnit::createCubicMeter(status));
739 measureUnit.adoptInstead(MeasureUnit::createCubicMile(status));
740 measureUnit.adoptInstead(MeasureUnit::createCubicYard(status));
741 measureUnit.adoptInstead(MeasureUnit::createCup(status));
742 measureUnit.adoptInstead(MeasureUnit::createCupMetric(status));
743 measureUnit.adoptInstead(MeasureUnit::createDeciliter(status));
744 measureUnit.adoptInstead(MeasureUnit::createFluidOunce(status));
745 measureUnit.adoptInstead(MeasureUnit::createGallon(status));
746 measureUnit.adoptInstead(MeasureUnit::createGallonImperial(status));
747 measureUnit.adoptInstead(MeasureUnit::createHectoliter(status));
748 measureUnit.adoptInstead(MeasureUnit::createLiter(status));
749 measureUnit.adoptInstead(MeasureUnit::createMegaliter(status));
750 measureUnit.adoptInstead(MeasureUnit::createMilliliter(status));
751 measureUnit.adoptInstead(MeasureUnit::createPint(status));
752 measureUnit.adoptInstead(MeasureUnit::createPintMetric(status));
753 measureUnit.adoptInstead(MeasureUnit::createQuart(status));
754 measureUnit.adoptInstead(MeasureUnit::createTablespoon(status));
755 measureUnit.adoptInstead(MeasureUnit::createTeaspoon(status));
756 assertSuccess("", status);
757 }
758
TestCompatible58()759 void MeasureFormatTest::TestCompatible58() {
760 UErrorCode status = U_ZERO_ERROR;
761 LocalPointer<MeasureUnit> measureUnit;
762 measureUnit.adoptInstead(MeasureUnit::createGForce(status));
763 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecondSquared(status));
764 measureUnit.adoptInstead(MeasureUnit::createArcMinute(status));
765 measureUnit.adoptInstead(MeasureUnit::createArcSecond(status));
766 measureUnit.adoptInstead(MeasureUnit::createDegree(status));
767 measureUnit.adoptInstead(MeasureUnit::createRadian(status));
768 measureUnit.adoptInstead(MeasureUnit::createRevolutionAngle(status));
769 measureUnit.adoptInstead(MeasureUnit::createAcre(status));
770 measureUnit.adoptInstead(MeasureUnit::createHectare(status));
771 measureUnit.adoptInstead(MeasureUnit::createSquareCentimeter(status));
772 measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status));
773 measureUnit.adoptInstead(MeasureUnit::createSquareInch(status));
774 measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status));
775 measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status));
776 measureUnit.adoptInstead(MeasureUnit::createSquareMile(status));
777 measureUnit.adoptInstead(MeasureUnit::createSquareYard(status));
778 measureUnit.adoptInstead(MeasureUnit::createKarat(status));
779 measureUnit.adoptInstead(MeasureUnit::createMilligramPerDeciliter(status));
780 measureUnit.adoptInstead(MeasureUnit::createMillimolePerLiter(status));
781 measureUnit.adoptInstead(MeasureUnit::createPartPerMillion(status));
782 measureUnit.adoptInstead(MeasureUnit::createLiterPer100Kilometers(status));
783 measureUnit.adoptInstead(MeasureUnit::createLiterPerKilometer(status));
784 measureUnit.adoptInstead(MeasureUnit::createMilePerGallon(status));
785 measureUnit.adoptInstead(MeasureUnit::createMilePerGallonImperial(status));
786 // measureUnit.adoptInstead(MeasureUnit::createEast(status));
787 // measureUnit.adoptInstead(MeasureUnit::createNorth(status));
788 // measureUnit.adoptInstead(MeasureUnit::createSouth(status));
789 // measureUnit.adoptInstead(MeasureUnit::createWest(status));
790 measureUnit.adoptInstead(MeasureUnit::createBit(status));
791 measureUnit.adoptInstead(MeasureUnit::createByte(status));
792 measureUnit.adoptInstead(MeasureUnit::createGigabit(status));
793 measureUnit.adoptInstead(MeasureUnit::createGigabyte(status));
794 measureUnit.adoptInstead(MeasureUnit::createKilobit(status));
795 measureUnit.adoptInstead(MeasureUnit::createKilobyte(status));
796 measureUnit.adoptInstead(MeasureUnit::createMegabit(status));
797 measureUnit.adoptInstead(MeasureUnit::createMegabyte(status));
798 measureUnit.adoptInstead(MeasureUnit::createTerabit(status));
799 measureUnit.adoptInstead(MeasureUnit::createTerabyte(status));
800 measureUnit.adoptInstead(MeasureUnit::createCentury(status));
801 measureUnit.adoptInstead(MeasureUnit::createDay(status));
802 measureUnit.adoptInstead(MeasureUnit::createHour(status));
803 measureUnit.adoptInstead(MeasureUnit::createMicrosecond(status));
804 measureUnit.adoptInstead(MeasureUnit::createMillisecond(status));
805 measureUnit.adoptInstead(MeasureUnit::createMinute(status));
806 measureUnit.adoptInstead(MeasureUnit::createMonth(status));
807 measureUnit.adoptInstead(MeasureUnit::createNanosecond(status));
808 measureUnit.adoptInstead(MeasureUnit::createSecond(status));
809 measureUnit.adoptInstead(MeasureUnit::createWeek(status));
810 measureUnit.adoptInstead(MeasureUnit::createYear(status));
811 measureUnit.adoptInstead(MeasureUnit::createAmpere(status));
812 measureUnit.adoptInstead(MeasureUnit::createMilliampere(status));
813 measureUnit.adoptInstead(MeasureUnit::createOhm(status));
814 measureUnit.adoptInstead(MeasureUnit::createVolt(status));
815 measureUnit.adoptInstead(MeasureUnit::createCalorie(status));
816 measureUnit.adoptInstead(MeasureUnit::createFoodcalorie(status));
817 measureUnit.adoptInstead(MeasureUnit::createJoule(status));
818 measureUnit.adoptInstead(MeasureUnit::createKilocalorie(status));
819 measureUnit.adoptInstead(MeasureUnit::createKilojoule(status));
820 measureUnit.adoptInstead(MeasureUnit::createKilowattHour(status));
821 measureUnit.adoptInstead(MeasureUnit::createGigahertz(status));
822 measureUnit.adoptInstead(MeasureUnit::createHertz(status));
823 measureUnit.adoptInstead(MeasureUnit::createKilohertz(status));
824 measureUnit.adoptInstead(MeasureUnit::createMegahertz(status));
825 measureUnit.adoptInstead(MeasureUnit::createAstronomicalUnit(status));
826 measureUnit.adoptInstead(MeasureUnit::createCentimeter(status));
827 measureUnit.adoptInstead(MeasureUnit::createDecimeter(status));
828 measureUnit.adoptInstead(MeasureUnit::createFathom(status));
829 measureUnit.adoptInstead(MeasureUnit::createFoot(status));
830 measureUnit.adoptInstead(MeasureUnit::createFurlong(status));
831 measureUnit.adoptInstead(MeasureUnit::createInch(status));
832 measureUnit.adoptInstead(MeasureUnit::createKilometer(status));
833 measureUnit.adoptInstead(MeasureUnit::createLightYear(status));
834 measureUnit.adoptInstead(MeasureUnit::createMeter(status));
835 measureUnit.adoptInstead(MeasureUnit::createMicrometer(status));
836 measureUnit.adoptInstead(MeasureUnit::createMile(status));
837 measureUnit.adoptInstead(MeasureUnit::createMileScandinavian(status));
838 measureUnit.adoptInstead(MeasureUnit::createMillimeter(status));
839 measureUnit.adoptInstead(MeasureUnit::createNanometer(status));
840 measureUnit.adoptInstead(MeasureUnit::createNauticalMile(status));
841 measureUnit.adoptInstead(MeasureUnit::createParsec(status));
842 measureUnit.adoptInstead(MeasureUnit::createPicometer(status));
843 measureUnit.adoptInstead(MeasureUnit::createYard(status));
844 measureUnit.adoptInstead(MeasureUnit::createLux(status));
845 measureUnit.adoptInstead(MeasureUnit::createCarat(status));
846 measureUnit.adoptInstead(MeasureUnit::createGram(status));
847 measureUnit.adoptInstead(MeasureUnit::createKilogram(status));
848 measureUnit.adoptInstead(MeasureUnit::createMetricTon(status));
849 measureUnit.adoptInstead(MeasureUnit::createMicrogram(status));
850 measureUnit.adoptInstead(MeasureUnit::createMilligram(status));
851 measureUnit.adoptInstead(MeasureUnit::createOunce(status));
852 measureUnit.adoptInstead(MeasureUnit::createOunceTroy(status));
853 measureUnit.adoptInstead(MeasureUnit::createPound(status));
854 measureUnit.adoptInstead(MeasureUnit::createStone(status));
855 measureUnit.adoptInstead(MeasureUnit::createTon(status));
856 measureUnit.adoptInstead(MeasureUnit::createGigawatt(status));
857 measureUnit.adoptInstead(MeasureUnit::createHorsepower(status));
858 measureUnit.adoptInstead(MeasureUnit::createKilowatt(status));
859 measureUnit.adoptInstead(MeasureUnit::createMegawatt(status));
860 measureUnit.adoptInstead(MeasureUnit::createMilliwatt(status));
861 measureUnit.adoptInstead(MeasureUnit::createWatt(status));
862 measureUnit.adoptInstead(MeasureUnit::createHectopascal(status));
863 measureUnit.adoptInstead(MeasureUnit::createInchHg(status));
864 measureUnit.adoptInstead(MeasureUnit::createMillibar(status));
865 measureUnit.adoptInstead(MeasureUnit::createMillimeterOfMercury(status));
866 measureUnit.adoptInstead(MeasureUnit::createPoundPerSquareInch(status));
867 measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status));
868 measureUnit.adoptInstead(MeasureUnit::createKnot(status));
869 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status));
870 measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status));
871 measureUnit.adoptInstead(MeasureUnit::createCelsius(status));
872 measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status));
873 measureUnit.adoptInstead(MeasureUnit::createGenericTemperature(status));
874 measureUnit.adoptInstead(MeasureUnit::createKelvin(status));
875 measureUnit.adoptInstead(MeasureUnit::createAcreFoot(status));
876 measureUnit.adoptInstead(MeasureUnit::createBushel(status));
877 measureUnit.adoptInstead(MeasureUnit::createCentiliter(status));
878 measureUnit.adoptInstead(MeasureUnit::createCubicCentimeter(status));
879 measureUnit.adoptInstead(MeasureUnit::createCubicFoot(status));
880 measureUnit.adoptInstead(MeasureUnit::createCubicInch(status));
881 measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status));
882 measureUnit.adoptInstead(MeasureUnit::createCubicMeter(status));
883 measureUnit.adoptInstead(MeasureUnit::createCubicMile(status));
884 measureUnit.adoptInstead(MeasureUnit::createCubicYard(status));
885 measureUnit.adoptInstead(MeasureUnit::createCup(status));
886 measureUnit.adoptInstead(MeasureUnit::createCupMetric(status));
887 measureUnit.adoptInstead(MeasureUnit::createDeciliter(status));
888 measureUnit.adoptInstead(MeasureUnit::createFluidOunce(status));
889 measureUnit.adoptInstead(MeasureUnit::createGallon(status));
890 measureUnit.adoptInstead(MeasureUnit::createGallonImperial(status));
891 measureUnit.adoptInstead(MeasureUnit::createHectoliter(status));
892 measureUnit.adoptInstead(MeasureUnit::createLiter(status));
893 measureUnit.adoptInstead(MeasureUnit::createMegaliter(status));
894 measureUnit.adoptInstead(MeasureUnit::createMilliliter(status));
895 measureUnit.adoptInstead(MeasureUnit::createPint(status));
896 measureUnit.adoptInstead(MeasureUnit::createPintMetric(status));
897 measureUnit.adoptInstead(MeasureUnit::createQuart(status));
898 measureUnit.adoptInstead(MeasureUnit::createTablespoon(status));
899 measureUnit.adoptInstead(MeasureUnit::createTeaspoon(status));
900 assertSuccess("", status);
901 }
902
TestCompatible59()903 void MeasureFormatTest::TestCompatible59() {
904 UErrorCode status = U_ZERO_ERROR;
905 LocalPointer<MeasureUnit> measureUnit;
906 measureUnit.adoptInstead(MeasureUnit::createGForce(status));
907 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecondSquared(status));
908 measureUnit.adoptInstead(MeasureUnit::createArcMinute(status));
909 measureUnit.adoptInstead(MeasureUnit::createArcSecond(status));
910 measureUnit.adoptInstead(MeasureUnit::createDegree(status));
911 measureUnit.adoptInstead(MeasureUnit::createRadian(status));
912 measureUnit.adoptInstead(MeasureUnit::createRevolutionAngle(status));
913 measureUnit.adoptInstead(MeasureUnit::createAcre(status));
914 measureUnit.adoptInstead(MeasureUnit::createHectare(status));
915 measureUnit.adoptInstead(MeasureUnit::createSquareCentimeter(status));
916 measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status));
917 measureUnit.adoptInstead(MeasureUnit::createSquareInch(status));
918 measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status));
919 measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status));
920 measureUnit.adoptInstead(MeasureUnit::createSquareMile(status));
921 measureUnit.adoptInstead(MeasureUnit::createSquareYard(status));
922 measureUnit.adoptInstead(MeasureUnit::createKarat(status));
923 measureUnit.adoptInstead(MeasureUnit::createMilligramPerDeciliter(status));
924 measureUnit.adoptInstead(MeasureUnit::createMillimolePerLiter(status));
925 measureUnit.adoptInstead(MeasureUnit::createPartPerMillion(status));
926 measureUnit.adoptInstead(MeasureUnit::createLiterPer100Kilometers(status));
927 measureUnit.adoptInstead(MeasureUnit::createLiterPerKilometer(status));
928 measureUnit.adoptInstead(MeasureUnit::createMilePerGallon(status));
929 measureUnit.adoptInstead(MeasureUnit::createMilePerGallonImperial(status));
930 measureUnit.adoptInstead(MeasureUnit::createBit(status));
931 measureUnit.adoptInstead(MeasureUnit::createByte(status));
932 measureUnit.adoptInstead(MeasureUnit::createGigabit(status));
933 measureUnit.adoptInstead(MeasureUnit::createGigabyte(status));
934 measureUnit.adoptInstead(MeasureUnit::createKilobit(status));
935 measureUnit.adoptInstead(MeasureUnit::createKilobyte(status));
936 measureUnit.adoptInstead(MeasureUnit::createMegabit(status));
937 measureUnit.adoptInstead(MeasureUnit::createMegabyte(status));
938 measureUnit.adoptInstead(MeasureUnit::createTerabit(status));
939 measureUnit.adoptInstead(MeasureUnit::createTerabyte(status));
940 measureUnit.adoptInstead(MeasureUnit::createCentury(status));
941 measureUnit.adoptInstead(MeasureUnit::createDay(status));
942 measureUnit.adoptInstead(MeasureUnit::createHour(status));
943 measureUnit.adoptInstead(MeasureUnit::createMicrosecond(status));
944 measureUnit.adoptInstead(MeasureUnit::createMillisecond(status));
945 measureUnit.adoptInstead(MeasureUnit::createMinute(status));
946 measureUnit.adoptInstead(MeasureUnit::createMonth(status));
947 measureUnit.adoptInstead(MeasureUnit::createNanosecond(status));
948 measureUnit.adoptInstead(MeasureUnit::createSecond(status));
949 measureUnit.adoptInstead(MeasureUnit::createWeek(status));
950 measureUnit.adoptInstead(MeasureUnit::createYear(status));
951 measureUnit.adoptInstead(MeasureUnit::createAmpere(status));
952 measureUnit.adoptInstead(MeasureUnit::createMilliampere(status));
953 measureUnit.adoptInstead(MeasureUnit::createOhm(status));
954 measureUnit.adoptInstead(MeasureUnit::createVolt(status));
955 measureUnit.adoptInstead(MeasureUnit::createCalorie(status));
956 measureUnit.adoptInstead(MeasureUnit::createFoodcalorie(status));
957 measureUnit.adoptInstead(MeasureUnit::createJoule(status));
958 measureUnit.adoptInstead(MeasureUnit::createKilocalorie(status));
959 measureUnit.adoptInstead(MeasureUnit::createKilojoule(status));
960 measureUnit.adoptInstead(MeasureUnit::createKilowattHour(status));
961 measureUnit.adoptInstead(MeasureUnit::createGigahertz(status));
962 measureUnit.adoptInstead(MeasureUnit::createHertz(status));
963 measureUnit.adoptInstead(MeasureUnit::createKilohertz(status));
964 measureUnit.adoptInstead(MeasureUnit::createMegahertz(status));
965 measureUnit.adoptInstead(MeasureUnit::createAstronomicalUnit(status));
966 measureUnit.adoptInstead(MeasureUnit::createCentimeter(status));
967 measureUnit.adoptInstead(MeasureUnit::createDecimeter(status));
968 measureUnit.adoptInstead(MeasureUnit::createFathom(status));
969 measureUnit.adoptInstead(MeasureUnit::createFoot(status));
970 measureUnit.adoptInstead(MeasureUnit::createFurlong(status));
971 measureUnit.adoptInstead(MeasureUnit::createInch(status));
972 measureUnit.adoptInstead(MeasureUnit::createKilometer(status));
973 measureUnit.adoptInstead(MeasureUnit::createLightYear(status));
974 measureUnit.adoptInstead(MeasureUnit::createMeter(status));
975 measureUnit.adoptInstead(MeasureUnit::createMicrometer(status));
976 measureUnit.adoptInstead(MeasureUnit::createMile(status));
977 measureUnit.adoptInstead(MeasureUnit::createMileScandinavian(status));
978 measureUnit.adoptInstead(MeasureUnit::createMillimeter(status));
979 measureUnit.adoptInstead(MeasureUnit::createNanometer(status));
980 measureUnit.adoptInstead(MeasureUnit::createNauticalMile(status));
981 measureUnit.adoptInstead(MeasureUnit::createParsec(status));
982 measureUnit.adoptInstead(MeasureUnit::createPicometer(status));
983 measureUnit.adoptInstead(MeasureUnit::createPoint(status));
984 measureUnit.adoptInstead(MeasureUnit::createYard(status));
985 measureUnit.adoptInstead(MeasureUnit::createLux(status));
986 measureUnit.adoptInstead(MeasureUnit::createCarat(status));
987 measureUnit.adoptInstead(MeasureUnit::createGram(status));
988 measureUnit.adoptInstead(MeasureUnit::createKilogram(status));
989 measureUnit.adoptInstead(MeasureUnit::createMetricTon(status));
990 measureUnit.adoptInstead(MeasureUnit::createMicrogram(status));
991 measureUnit.adoptInstead(MeasureUnit::createMilligram(status));
992 measureUnit.adoptInstead(MeasureUnit::createOunce(status));
993 measureUnit.adoptInstead(MeasureUnit::createOunceTroy(status));
994 measureUnit.adoptInstead(MeasureUnit::createPound(status));
995 measureUnit.adoptInstead(MeasureUnit::createStone(status));
996 measureUnit.adoptInstead(MeasureUnit::createTon(status));
997 measureUnit.adoptInstead(MeasureUnit::createGigawatt(status));
998 measureUnit.adoptInstead(MeasureUnit::createHorsepower(status));
999 measureUnit.adoptInstead(MeasureUnit::createKilowatt(status));
1000 measureUnit.adoptInstead(MeasureUnit::createMegawatt(status));
1001 measureUnit.adoptInstead(MeasureUnit::createMilliwatt(status));
1002 measureUnit.adoptInstead(MeasureUnit::createWatt(status));
1003 measureUnit.adoptInstead(MeasureUnit::createHectopascal(status));
1004 measureUnit.adoptInstead(MeasureUnit::createInchHg(status));
1005 measureUnit.adoptInstead(MeasureUnit::createMillibar(status));
1006 measureUnit.adoptInstead(MeasureUnit::createMillimeterOfMercury(status));
1007 measureUnit.adoptInstead(MeasureUnit::createPoundPerSquareInch(status));
1008 measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status));
1009 measureUnit.adoptInstead(MeasureUnit::createKnot(status));
1010 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status));
1011 measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status));
1012 measureUnit.adoptInstead(MeasureUnit::createCelsius(status));
1013 measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status));
1014 measureUnit.adoptInstead(MeasureUnit::createGenericTemperature(status));
1015 measureUnit.adoptInstead(MeasureUnit::createKelvin(status));
1016 measureUnit.adoptInstead(MeasureUnit::createAcreFoot(status));
1017 measureUnit.adoptInstead(MeasureUnit::createBushel(status));
1018 measureUnit.adoptInstead(MeasureUnit::createCentiliter(status));
1019 measureUnit.adoptInstead(MeasureUnit::createCubicCentimeter(status));
1020 measureUnit.adoptInstead(MeasureUnit::createCubicFoot(status));
1021 measureUnit.adoptInstead(MeasureUnit::createCubicInch(status));
1022 measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status));
1023 measureUnit.adoptInstead(MeasureUnit::createCubicMeter(status));
1024 measureUnit.adoptInstead(MeasureUnit::createCubicMile(status));
1025 measureUnit.adoptInstead(MeasureUnit::createCubicYard(status));
1026 measureUnit.adoptInstead(MeasureUnit::createCup(status));
1027 measureUnit.adoptInstead(MeasureUnit::createCupMetric(status));
1028 measureUnit.adoptInstead(MeasureUnit::createDeciliter(status));
1029 measureUnit.adoptInstead(MeasureUnit::createFluidOunce(status));
1030 measureUnit.adoptInstead(MeasureUnit::createGallon(status));
1031 measureUnit.adoptInstead(MeasureUnit::createGallonImperial(status));
1032 measureUnit.adoptInstead(MeasureUnit::createHectoliter(status));
1033 measureUnit.adoptInstead(MeasureUnit::createLiter(status));
1034 measureUnit.adoptInstead(MeasureUnit::createMegaliter(status));
1035 measureUnit.adoptInstead(MeasureUnit::createMilliliter(status));
1036 measureUnit.adoptInstead(MeasureUnit::createPint(status));
1037 measureUnit.adoptInstead(MeasureUnit::createPintMetric(status));
1038 measureUnit.adoptInstead(MeasureUnit::createQuart(status));
1039 measureUnit.adoptInstead(MeasureUnit::createTablespoon(status));
1040 measureUnit.adoptInstead(MeasureUnit::createTeaspoon(status));
1041 assertSuccess("", status);
1042 }
1043
1044 // Note that TestCompatible60(), TestCompatible61(), TestCompatible62()
1045 // would be the same as TestCompatible59(), no need to add them.
1046
TestCompatible63()1047 void MeasureFormatTest::TestCompatible63() {
1048 UErrorCode status = U_ZERO_ERROR;
1049 LocalPointer<MeasureUnit> measureUnit;
1050 measureUnit.adoptInstead(MeasureUnit::createGForce(status));
1051 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecondSquared(status));
1052 measureUnit.adoptInstead(MeasureUnit::createArcMinute(status));
1053 measureUnit.adoptInstead(MeasureUnit::createArcSecond(status));
1054 measureUnit.adoptInstead(MeasureUnit::createDegree(status));
1055 measureUnit.adoptInstead(MeasureUnit::createRadian(status));
1056 measureUnit.adoptInstead(MeasureUnit::createRevolutionAngle(status));
1057 measureUnit.adoptInstead(MeasureUnit::createAcre(status));
1058 measureUnit.adoptInstead(MeasureUnit::createHectare(status));
1059 measureUnit.adoptInstead(MeasureUnit::createSquareCentimeter(status));
1060 measureUnit.adoptInstead(MeasureUnit::createSquareFoot(status));
1061 measureUnit.adoptInstead(MeasureUnit::createSquareInch(status));
1062 measureUnit.adoptInstead(MeasureUnit::createSquareKilometer(status));
1063 measureUnit.adoptInstead(MeasureUnit::createSquareMeter(status));
1064 measureUnit.adoptInstead(MeasureUnit::createSquareMile(status));
1065 measureUnit.adoptInstead(MeasureUnit::createSquareYard(status));
1066 measureUnit.adoptInstead(MeasureUnit::createKarat(status));
1067 measureUnit.adoptInstead(MeasureUnit::createMilligramPerDeciliter(status));
1068 measureUnit.adoptInstead(MeasureUnit::createMillimolePerLiter(status));
1069 measureUnit.adoptInstead(MeasureUnit::createPartPerMillion(status));
1070 measureUnit.adoptInstead(MeasureUnit::createPercent(status));
1071 measureUnit.adoptInstead(MeasureUnit::createPermille(status));
1072 measureUnit.adoptInstead(MeasureUnit::createLiterPer100Kilometers(status));
1073 measureUnit.adoptInstead(MeasureUnit::createLiterPerKilometer(status));
1074 measureUnit.adoptInstead(MeasureUnit::createMilePerGallon(status));
1075 measureUnit.adoptInstead(MeasureUnit::createMilePerGallonImperial(status));
1076 measureUnit.adoptInstead(MeasureUnit::createBit(status));
1077 measureUnit.adoptInstead(MeasureUnit::createByte(status));
1078 measureUnit.adoptInstead(MeasureUnit::createGigabit(status));
1079 measureUnit.adoptInstead(MeasureUnit::createGigabyte(status));
1080 measureUnit.adoptInstead(MeasureUnit::createKilobit(status));
1081 measureUnit.adoptInstead(MeasureUnit::createKilobyte(status));
1082 measureUnit.adoptInstead(MeasureUnit::createMegabit(status));
1083 measureUnit.adoptInstead(MeasureUnit::createMegabyte(status));
1084 measureUnit.adoptInstead(MeasureUnit::createPetabyte(status));
1085 measureUnit.adoptInstead(MeasureUnit::createTerabit(status));
1086 measureUnit.adoptInstead(MeasureUnit::createTerabyte(status));
1087 measureUnit.adoptInstead(MeasureUnit::createCentury(status));
1088 measureUnit.adoptInstead(MeasureUnit::createDay(status));
1089 measureUnit.adoptInstead(MeasureUnit::createHour(status));
1090 measureUnit.adoptInstead(MeasureUnit::createMicrosecond(status));
1091 measureUnit.adoptInstead(MeasureUnit::createMillisecond(status));
1092 measureUnit.adoptInstead(MeasureUnit::createMinute(status));
1093 measureUnit.adoptInstead(MeasureUnit::createMonth(status));
1094 measureUnit.adoptInstead(MeasureUnit::createNanosecond(status));
1095 measureUnit.adoptInstead(MeasureUnit::createSecond(status));
1096 measureUnit.adoptInstead(MeasureUnit::createWeek(status));
1097 measureUnit.adoptInstead(MeasureUnit::createYear(status));
1098 measureUnit.adoptInstead(MeasureUnit::createAmpere(status));
1099 measureUnit.adoptInstead(MeasureUnit::createMilliampere(status));
1100 measureUnit.adoptInstead(MeasureUnit::createOhm(status));
1101 measureUnit.adoptInstead(MeasureUnit::createVolt(status));
1102 measureUnit.adoptInstead(MeasureUnit::createCalorie(status));
1103 measureUnit.adoptInstead(MeasureUnit::createFoodcalorie(status));
1104 measureUnit.adoptInstead(MeasureUnit::createJoule(status));
1105 measureUnit.adoptInstead(MeasureUnit::createKilocalorie(status));
1106 measureUnit.adoptInstead(MeasureUnit::createKilojoule(status));
1107 measureUnit.adoptInstead(MeasureUnit::createKilowattHour(status));
1108 measureUnit.adoptInstead(MeasureUnit::createGigahertz(status));
1109 measureUnit.adoptInstead(MeasureUnit::createHertz(status));
1110 measureUnit.adoptInstead(MeasureUnit::createKilohertz(status));
1111 measureUnit.adoptInstead(MeasureUnit::createMegahertz(status));
1112 measureUnit.adoptInstead(MeasureUnit::createAstronomicalUnit(status));
1113 measureUnit.adoptInstead(MeasureUnit::createCentimeter(status));
1114 measureUnit.adoptInstead(MeasureUnit::createDecimeter(status));
1115 measureUnit.adoptInstead(MeasureUnit::createFathom(status));
1116 measureUnit.adoptInstead(MeasureUnit::createFoot(status));
1117 measureUnit.adoptInstead(MeasureUnit::createFurlong(status));
1118 measureUnit.adoptInstead(MeasureUnit::createInch(status));
1119 measureUnit.adoptInstead(MeasureUnit::createKilometer(status));
1120 measureUnit.adoptInstead(MeasureUnit::createLightYear(status));
1121 measureUnit.adoptInstead(MeasureUnit::createMeter(status));
1122 measureUnit.adoptInstead(MeasureUnit::createMicrometer(status));
1123 measureUnit.adoptInstead(MeasureUnit::createMile(status));
1124 measureUnit.adoptInstead(MeasureUnit::createMileScandinavian(status));
1125 measureUnit.adoptInstead(MeasureUnit::createMillimeter(status));
1126 measureUnit.adoptInstead(MeasureUnit::createNanometer(status));
1127 measureUnit.adoptInstead(MeasureUnit::createNauticalMile(status));
1128 measureUnit.adoptInstead(MeasureUnit::createParsec(status));
1129 measureUnit.adoptInstead(MeasureUnit::createPicometer(status));
1130 measureUnit.adoptInstead(MeasureUnit::createPoint(status));
1131 measureUnit.adoptInstead(MeasureUnit::createYard(status));
1132 measureUnit.adoptInstead(MeasureUnit::createLux(status));
1133 measureUnit.adoptInstead(MeasureUnit::createCarat(status));
1134 measureUnit.adoptInstead(MeasureUnit::createGram(status));
1135 measureUnit.adoptInstead(MeasureUnit::createKilogram(status));
1136 measureUnit.adoptInstead(MeasureUnit::createMetricTon(status));
1137 measureUnit.adoptInstead(MeasureUnit::createMicrogram(status));
1138 measureUnit.adoptInstead(MeasureUnit::createMilligram(status));
1139 measureUnit.adoptInstead(MeasureUnit::createOunce(status));
1140 measureUnit.adoptInstead(MeasureUnit::createOunceTroy(status));
1141 measureUnit.adoptInstead(MeasureUnit::createPound(status));
1142 measureUnit.adoptInstead(MeasureUnit::createStone(status));
1143 measureUnit.adoptInstead(MeasureUnit::createTon(status));
1144 measureUnit.adoptInstead(MeasureUnit::createGigawatt(status));
1145 measureUnit.adoptInstead(MeasureUnit::createHorsepower(status));
1146 measureUnit.adoptInstead(MeasureUnit::createKilowatt(status));
1147 measureUnit.adoptInstead(MeasureUnit::createMegawatt(status));
1148 measureUnit.adoptInstead(MeasureUnit::createMilliwatt(status));
1149 measureUnit.adoptInstead(MeasureUnit::createWatt(status));
1150 measureUnit.adoptInstead(MeasureUnit::createAtmosphere(status));
1151 measureUnit.adoptInstead(MeasureUnit::createHectopascal(status));
1152 measureUnit.adoptInstead(MeasureUnit::createInchHg(status));
1153 measureUnit.adoptInstead(MeasureUnit::createMillibar(status));
1154 measureUnit.adoptInstead(MeasureUnit::createMillimeterOfMercury(status));
1155 measureUnit.adoptInstead(MeasureUnit::createPoundPerSquareInch(status));
1156 measureUnit.adoptInstead(MeasureUnit::createKilometerPerHour(status));
1157 measureUnit.adoptInstead(MeasureUnit::createKnot(status));
1158 measureUnit.adoptInstead(MeasureUnit::createMeterPerSecond(status));
1159 measureUnit.adoptInstead(MeasureUnit::createMilePerHour(status));
1160 measureUnit.adoptInstead(MeasureUnit::createCelsius(status));
1161 measureUnit.adoptInstead(MeasureUnit::createFahrenheit(status));
1162 measureUnit.adoptInstead(MeasureUnit::createGenericTemperature(status));
1163 measureUnit.adoptInstead(MeasureUnit::createKelvin(status));
1164 measureUnit.adoptInstead(MeasureUnit::createAcreFoot(status));
1165 measureUnit.adoptInstead(MeasureUnit::createBushel(status));
1166 measureUnit.adoptInstead(MeasureUnit::createCentiliter(status));
1167 measureUnit.adoptInstead(MeasureUnit::createCubicCentimeter(status));
1168 measureUnit.adoptInstead(MeasureUnit::createCubicFoot(status));
1169 measureUnit.adoptInstead(MeasureUnit::createCubicInch(status));
1170 measureUnit.adoptInstead(MeasureUnit::createCubicKilometer(status));
1171 measureUnit.adoptInstead(MeasureUnit::createCubicMeter(status));
1172 measureUnit.adoptInstead(MeasureUnit::createCubicMile(status));
1173 measureUnit.adoptInstead(MeasureUnit::createCubicYard(status));
1174 measureUnit.adoptInstead(MeasureUnit::createCup(status));
1175 measureUnit.adoptInstead(MeasureUnit::createCupMetric(status));
1176 measureUnit.adoptInstead(MeasureUnit::createDeciliter(status));
1177 measureUnit.adoptInstead(MeasureUnit::createFluidOunce(status));
1178 measureUnit.adoptInstead(MeasureUnit::createGallon(status));
1179 measureUnit.adoptInstead(MeasureUnit::createGallonImperial(status));
1180 measureUnit.adoptInstead(MeasureUnit::createHectoliter(status));
1181 measureUnit.adoptInstead(MeasureUnit::createLiter(status));
1182 measureUnit.adoptInstead(MeasureUnit::createMegaliter(status));
1183 measureUnit.adoptInstead(MeasureUnit::createMilliliter(status));
1184 measureUnit.adoptInstead(MeasureUnit::createPint(status));
1185 measureUnit.adoptInstead(MeasureUnit::createPintMetric(status));
1186 measureUnit.adoptInstead(MeasureUnit::createQuart(status));
1187 measureUnit.adoptInstead(MeasureUnit::createTablespoon(status));
1188 measureUnit.adoptInstead(MeasureUnit::createTeaspoon(status));
1189 assertSuccess("", status);
1190 }
1191
TestBasic()1192 void MeasureFormatTest::TestBasic() {
1193 UErrorCode status = U_ZERO_ERROR;
1194 MeasureUnit *ptr1 = MeasureUnit::createArcMinute(status);
1195 MeasureUnit *ptr2 = MeasureUnit::createArcMinute(status);
1196 if (!(*ptr1 == *ptr2)) {
1197 errln("Expect == to work.");
1198 }
1199 if (*ptr1 != *ptr2) {
1200 errln("Expect != to work.");
1201 }
1202 MeasureUnit *ptr3 = MeasureUnit::createMeter(status);
1203 if (*ptr1 == *ptr3) {
1204 errln("Expect == to work.");
1205 }
1206 if (!(*ptr1 != *ptr3)) {
1207 errln("Expect != to work.");
1208 }
1209 MeasureUnit *ptr4 = (MeasureUnit *) ptr1->clone();
1210 if (*ptr1 != *ptr4) {
1211 errln("Expect clone to work.");
1212 }
1213 MeasureUnit stack;
1214 stack = *ptr1;
1215 if (*ptr1 != stack) {
1216 errln("Expect assignment to work.");
1217 }
1218
1219 delete ptr1;
1220 delete ptr2;
1221 delete ptr3;
1222 delete ptr4;
1223 }
1224
TestGetAvailable()1225 void MeasureFormatTest::TestGetAvailable() {
1226 MeasureUnit *units = NULL;
1227 UErrorCode status = U_ZERO_ERROR;
1228 int32_t totalCount = MeasureUnit::getAvailable(units, 0, status);
1229 while (status == U_BUFFER_OVERFLOW_ERROR) {
1230 status = U_ZERO_ERROR;
1231 delete [] units;
1232 units = new MeasureUnit[totalCount];
1233 totalCount = MeasureUnit::getAvailable(units, totalCount, status);
1234 }
1235 if (U_FAILURE(status)) {
1236 dataerrln("Failure creating format object - %s", u_errorName(status));
1237 delete [] units;
1238 return;
1239 }
1240 if (totalCount < 200) {
1241 errln("Expect at least 200 measure units including currencies.");
1242 }
1243 delete [] units;
1244 StringEnumeration *types = MeasureUnit::getAvailableTypes(status);
1245 if (U_FAILURE(status)) {
1246 dataerrln("Failure getting types - %s", u_errorName(status));
1247 delete types;
1248 return;
1249 }
1250 if (types->count(status) < 10) {
1251 errln("Expect at least 10 distinct unit types.");
1252 }
1253 units = NULL;
1254 int32_t unitCapacity = 0;
1255 int32_t unitCountSum = 0;
1256 for (
1257 const char* type = types->next(NULL, status);
1258 type != NULL;
1259 type = types->next(NULL, status)) {
1260 int32_t unitCount = MeasureUnit::getAvailable(type, units, unitCapacity, status);
1261 while (status == U_BUFFER_OVERFLOW_ERROR) {
1262 status = U_ZERO_ERROR;
1263 delete [] units;
1264 units = new MeasureUnit[unitCount];
1265 unitCapacity = unitCount;
1266 unitCount = MeasureUnit::getAvailable(type, units, unitCapacity, status);
1267 }
1268 if (U_FAILURE(status)) {
1269 dataerrln("Failure getting units - %s", u_errorName(status));
1270 delete [] units;
1271 delete types;
1272 return;
1273 }
1274 if (unitCount < 1) {
1275 errln("Expect at least one unit count per type.");
1276 }
1277 unitCountSum += unitCount;
1278 }
1279 if (unitCountSum != totalCount) {
1280 errln("Expected total unit count to equal sum of unit counts by type.");
1281 }
1282 delete [] units;
1283 delete types;
1284 }
1285
TestExamplesInDocs()1286 void MeasureFormatTest::TestExamplesInDocs() {
1287 UErrorCode status = U_ZERO_ERROR;
1288 MeasureFormat fmtFr(Locale::getFrench(), UMEASFMT_WIDTH_SHORT, status);
1289 MeasureFormat fmtFrFull(
1290 Locale::getFrench(), UMEASFMT_WIDTH_WIDE, status);
1291 MeasureFormat fmtFrNarrow(
1292 Locale::getFrench(), UMEASFMT_WIDTH_NARROW, status);
1293 MeasureFormat fmtEn(Locale::getUS(), UMEASFMT_WIDTH_WIDE, status);
1294 if (!assertSuccess("Error creating formatters", status)) {
1295 return;
1296 }
1297 Measure measureC((double)23, MeasureUnit::createCelsius(status), status);
1298 Measure measureF((double)70, MeasureUnit::createFahrenheit(status), status);
1299 Measure feetAndInches[] = {
1300 Measure((double)70, MeasureUnit::createFoot(status), status),
1301 Measure((double)5.3, MeasureUnit::createInch(status), status)};
1302 Measure footAndInch[] = {
1303 Measure((double)1, MeasureUnit::createFoot(status), status),
1304 Measure((double)1, MeasureUnit::createInch(status), status)};
1305 Measure inchAndFeet[] = {
1306 Measure((double)1, MeasureUnit::createInch(status), status),
1307 Measure((double)2, MeasureUnit::createFoot(status), status)};
1308 if (!assertSuccess("Error creating measurements.", status)) {
1309 return;
1310 }
1311 verifyFormat(
1312 "Celsius",
1313 fmtFr,
1314 &measureC,
1315 1,
1316 "23\\u202F\\u00B0C");
1317 verifyFormatWithPrefix(
1318 "Celsius",
1319 fmtFr,
1320 "Prefix: ",
1321 &measureC,
1322 1,
1323 "Prefix: 23\\u202F\\u00B0C");
1324 verifyFormat(
1325 "Fahrenheit",
1326 fmtFr,
1327 &measureF,
1328 1,
1329 "70\\u202F\\u00B0F");
1330 verifyFormat(
1331 "Feet and inches",
1332 fmtFrFull,
1333 feetAndInches,
1334 UPRV_LENGTHOF(feetAndInches),
1335 "70 pieds et 5,3\\u00A0pouces");
1336 verifyFormatWithPrefix(
1337 "Feet and inches",
1338 fmtFrFull,
1339 "Prefix: ",
1340 feetAndInches,
1341 UPRV_LENGTHOF(feetAndInches),
1342 "Prefix: 70 pieds et 5,3\\u00A0pouces");
1343 verifyFormat(
1344 "Foot and inch",
1345 fmtFrFull,
1346 footAndInch,
1347 UPRV_LENGTHOF(footAndInch),
1348 "1\\u00A0pied et 1\\u00A0pouce");
1349 verifyFormat(
1350 "Foot and inch narrow",
1351 fmtFrNarrow,
1352 footAndInch,
1353 UPRV_LENGTHOF(footAndInch),
1354 "1\\u2032 1\\u2033");
1355 verifyFormat(
1356 "Inch and feet",
1357 fmtEn,
1358 inchAndFeet,
1359 UPRV_LENGTHOF(inchAndFeet),
1360 "1 inch, 2 feet");
1361 }
1362
TestFormatPeriodEn()1363 void MeasureFormatTest::TestFormatPeriodEn() {
1364 UErrorCode status = U_ZERO_ERROR;
1365 Measure t_19m[] = {Measure((double)19, MeasureUnit::createMinute(status), status)};
1366 Measure t_1h_23_5s[] = {
1367 Measure((double)1.0, MeasureUnit::createHour(status), status),
1368 Measure((double)23.5, MeasureUnit::createSecond(status), status)
1369 };
1370 Measure t_1h_23_5m[] = {
1371 Measure((double)1.0, MeasureUnit::createHour(status), status),
1372 Measure((double)23.5, MeasureUnit::createMinute(status), status)
1373 };
1374 Measure t_1h_0m_23s[] = {
1375 Measure(
1376 (double)1.0,
1377 TimeUnit::createInstance(
1378 TimeUnit::UTIMEUNIT_HOUR, status),
1379 status),
1380 Measure(
1381 (double)0.0,
1382 TimeUnit::createInstance(
1383 TimeUnit::UTIMEUNIT_MINUTE, status),
1384 status),
1385 Measure(
1386 (double)23.0,
1387 TimeUnit::createInstance(
1388 TimeUnit::UTIMEUNIT_SECOND, status),
1389 status)
1390 };
1391 Measure t_2y_5M_3w_4d[] = {
1392 Measure(2.0, MeasureUnit::createYear(status), status),
1393 Measure(5.0, MeasureUnit::createMonth(status), status),
1394 Measure(3.0, MeasureUnit::createWeek(status), status),
1395 Measure(4.0, MeasureUnit::createDay(status), status)
1396 };
1397 Measure t_1m_59_9996s[] = {
1398 Measure(1.0, MeasureUnit::createMinute(status), status),
1399 Measure(59.9996, MeasureUnit::createSecond(status), status)
1400 };
1401 Measure t_5h_17m[] = {
1402 Measure(5.0, MeasureUnit::createHour(status), status),
1403 Measure(17.0, MeasureUnit::createMinute(status), status)
1404 };
1405 Measure t_neg5h_17m[] = {
1406 Measure(-5.0, MeasureUnit::createHour(status), status),
1407 Measure(17.0, MeasureUnit::createMinute(status), status)
1408 };
1409 Measure t_19m_28s[] = {
1410 Measure(19.0, MeasureUnit::createMinute(status), status),
1411 Measure(28.0, MeasureUnit::createSecond(status), status)
1412 };
1413 Measure t_0h_0m_9s[] = {
1414 Measure(0.0, MeasureUnit::createHour(status), status),
1415 Measure(0.0, MeasureUnit::createMinute(status), status),
1416 Measure(9.0, MeasureUnit::createSecond(status), status)
1417 };
1418 Measure t_0h_0m_17s[] = {
1419 Measure(0.0, MeasureUnit::createHour(status), status),
1420 Measure(0.0, MeasureUnit::createMinute(status), status),
1421 Measure(17.0, MeasureUnit::createSecond(status), status)
1422 };
1423 Measure t_6h_56_92m[] = {
1424 Measure(6.0, MeasureUnit::createHour(status), status),
1425 Measure(56.92, MeasureUnit::createMinute(status), status)
1426 };
1427 Measure t_3h_4s_5m[] = {
1428 Measure(3.0, MeasureUnit::createHour(status), status),
1429 Measure(4.0, MeasureUnit::createSecond(status), status),
1430 Measure(5.0, MeasureUnit::createMinute(status), status)
1431 };
1432 Measure t_6_7h_56_92m[] = {
1433 Measure(6.7, MeasureUnit::createHour(status), status),
1434 Measure(56.92, MeasureUnit::createMinute(status), status)
1435 };
1436
1437 Measure t_3h_5h[] = {
1438 Measure(3.0, MeasureUnit::createHour(status), status),
1439 Measure(5.0, MeasureUnit::createHour(status), status)
1440 };
1441
1442 if (!assertSuccess("Error creating Measure objects", status)) {
1443 return;
1444 }
1445
1446 ExpectedResult fullData[] = {
1447 {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1 minute, 59.9996 seconds"},
1448 {t_19m, UPRV_LENGTHOF(t_19m), "19 minutes"},
1449 {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1 hour, 23.5 seconds"},
1450 {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1 hour, 23.5 minutes"},
1451 {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1 hour, 0 minutes, 23 seconds"},
1452 {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2 years, 5 months, 3 weeks, 4 days"}};
1453
1454 ExpectedResult abbrevData[] = {
1455 {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1 min, 59.9996 sec"},
1456 {t_19m, UPRV_LENGTHOF(t_19m), "19 min"},
1457 {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1 hr, 23.5 sec"},
1458 {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1 hr, 23.5 min"},
1459 {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1 hr, 0 min, 23 sec"},
1460 {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2 yrs, 5 mths, 3 wks, 4 days"}};
1461
1462 ExpectedResult narrowData[] = {
1463 {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1m 59.9996s"},
1464 {t_19m, UPRV_LENGTHOF(t_19m), "19m"},
1465 {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1h 23.5s"},
1466 {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1h 23.5m"},
1467 {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1h 0m 23s"},
1468 {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2y 5m 3w 4d"}};
1469
1470 ExpectedResult numericData[] = {
1471 {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1:59.9996"},
1472 {t_19m, UPRV_LENGTHOF(t_19m), "19m"},
1473 {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1:00:23.5"},
1474 {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1:23.5"},
1475 {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1:00:23"},
1476 {t_5h_17m, UPRV_LENGTHOF(t_5h_17m), "5:17"},
1477 {t_neg5h_17m, UPRV_LENGTHOF(t_neg5h_17m), "-5h 17m"},
1478 {t_19m_28s, UPRV_LENGTHOF(t_19m_28s), "19:28"},
1479 {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2y 5m 3w 4d"},
1480 {t_0h_0m_9s, UPRV_LENGTHOF(t_0h_0m_9s), "0:00:09"},
1481 {t_6h_56_92m, UPRV_LENGTHOF(t_6h_56_92m), "6:56.92"},
1482 {t_6_7h_56_92m, UPRV_LENGTHOF(t_6_7h_56_92m), "6:56.92"},
1483 {t_3h_4s_5m, UPRV_LENGTHOF(t_3h_4s_5m), "3h 4s 5m"},
1484 {t_3h_5h, UPRV_LENGTHOF(t_3h_5h), "3h 5h"}};
1485
1486 ExpectedResult fullDataDe[] = {
1487 {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1 Minute, 59,9996 Sekunden"},
1488 {t_19m, UPRV_LENGTHOF(t_19m), "19 Minuten"},
1489 {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1 Stunde, 23,5 Sekunden"},
1490 {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1 Stunde, 23,5 Minuten"},
1491 {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1 Stunde, 0 Minuten und 23 Sekunden"},
1492 {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2 Jahre, 5 Monate, 3 Wochen und 4 Tage"}};
1493
1494 ExpectedResult numericDataDe[] = {
1495 {t_1m_59_9996s, UPRV_LENGTHOF(t_1m_59_9996s), "1:59,9996"},
1496 {t_19m, UPRV_LENGTHOF(t_19m), "19 Min."},
1497 {t_1h_23_5s, UPRV_LENGTHOF(t_1h_23_5s), "1:00:23,5"},
1498 {t_1h_23_5m, UPRV_LENGTHOF(t_1h_23_5m), "1:23,5"},
1499 {t_1h_0m_23s, UPRV_LENGTHOF(t_1h_0m_23s), "1:00:23"},
1500 {t_5h_17m, UPRV_LENGTHOF(t_5h_17m), "5:17"},
1501 {t_19m_28s, UPRV_LENGTHOF(t_19m_28s), "19:28"},
1502 {t_2y_5M_3w_4d, UPRV_LENGTHOF(t_2y_5M_3w_4d), "2 J, 5 M, 3 W und 4 T"},
1503 {t_0h_0m_17s, UPRV_LENGTHOF(t_0h_0m_17s), "0:00:17"},
1504 {t_6h_56_92m, UPRV_LENGTHOF(t_6h_56_92m), "6:56,92"},
1505 {t_3h_5h, UPRV_LENGTHOF(t_3h_5h), "3 Std., 5 Std."}};
1506
1507 Locale en(Locale::getEnglish());
1508 LocalPointer<NumberFormat> nf(NumberFormat::createInstance(en, status));
1509 if (U_FAILURE(status)) {
1510 dataerrln("Error creating number format en object - %s", u_errorName(status));
1511 return;
1512 }
1513 nf->setMaximumFractionDigits(4);
1514 MeasureFormat mf(en, UMEASFMT_WIDTH_WIDE, (NumberFormat *) nf->clone(), status);
1515 if (!assertSuccess("Error creating measure format en WIDE", status)) {
1516 return;
1517 }
1518 verifyFormat("en WIDE", mf, fullData, UPRV_LENGTHOF(fullData));
1519
1520 // exercise copy constructor
1521 {
1522 MeasureFormat mf2(mf);
1523 verifyFormat("en WIDE copy", mf2, fullData, UPRV_LENGTHOF(fullData));
1524 }
1525 // exercise clone
1526 {
1527 MeasureFormat *mf3 = (MeasureFormat *) mf.clone();
1528 verifyFormat("en WIDE copy", *mf3, fullData, UPRV_LENGTHOF(fullData));
1529 delete mf3;
1530 }
1531 mf = MeasureFormat(en, UMEASFMT_WIDTH_SHORT, (NumberFormat *) nf->clone(), status);
1532 if (!assertSuccess("Error creating measure format en SHORT", status)) {
1533 return;
1534 }
1535 verifyFormat("en SHORT", mf, abbrevData, UPRV_LENGTHOF(abbrevData));
1536 mf = MeasureFormat(en, UMEASFMT_WIDTH_NARROW, (NumberFormat *) nf->clone(), status);
1537 if (!assertSuccess("Error creating measure format en NARROW", status)) {
1538 return;
1539 }
1540 verifyFormat("en NARROW", mf, narrowData, UPRV_LENGTHOF(narrowData));
1541 mf = MeasureFormat(en, UMEASFMT_WIDTH_NUMERIC, (NumberFormat *) nf->clone(), status);
1542 if (!assertSuccess("Error creating measure format en NUMERIC", status)) {
1543 return;
1544 }
1545 verifyFormat("en NUMERIC", mf, numericData, UPRV_LENGTHOF(numericData));
1546
1547 Locale de(Locale::getGerman());
1548 nf.adoptInstead(NumberFormat::createInstance(de, status));
1549 if (!assertSuccess("Error creating number format de object", status)) {
1550 return;
1551 }
1552 nf->setMaximumFractionDigits(4);
1553 mf = MeasureFormat(de, UMEASFMT_WIDTH_WIDE, (NumberFormat *) nf->clone(), status);
1554 if (!assertSuccess("Error creating measure format de WIDE", status)) {
1555 return;
1556 }
1557 verifyFormat("de WIDE", mf, fullDataDe, UPRV_LENGTHOF(fullDataDe));
1558 mf = MeasureFormat(de, UMEASFMT_WIDTH_NUMERIC, (NumberFormat *) nf->clone(), status);
1559 if (!assertSuccess("Error creating measure format de NUMERIC", status)) {
1560 return;
1561 }
1562 verifyFormat("de NUMERIC", mf, numericDataDe, UPRV_LENGTHOF(numericDataDe));
1563 }
1564
Test10219FractionalPlurals()1565 void MeasureFormatTest::Test10219FractionalPlurals() {
1566 Locale en(Locale::getEnglish());
1567 double values[] = {1.588, 1.011};
1568 const char *expected[2][3] = {
1569 {"1 minute", "1.5 minutes", "1.58 minutes"},
1570 {"1 minute", "1.0 minutes", "1.01 minutes"}
1571 };
1572 UErrorCode status = U_ZERO_ERROR;
1573 for (int j = 0; j < UPRV_LENGTHOF(values); j++) {
1574 for (int i = 0; i < UPRV_LENGTHOF(expected[j]); i++) {
1575 DecimalFormat *df =
1576 (DecimalFormat *) NumberFormat::createInstance(en, status);
1577 if (U_FAILURE(status)) {
1578 dataerrln("Error creating Number format - %s", u_errorName(status));
1579 return;
1580 }
1581 df->setRoundingMode(DecimalFormat::kRoundDown);
1582 df->setMinimumFractionDigits(i);
1583 df->setMaximumFractionDigits(i);
1584 MeasureFormat mf(en, UMEASFMT_WIDTH_WIDE, df, status);
1585 if (!assertSuccess("Error creating Measure format", status)) {
1586 return;
1587 }
1588 Measure measure(values[j], MeasureUnit::createMinute(status), status);
1589 if (!assertSuccess("Error creating Measure unit", status)) {
1590 return;
1591 }
1592 verifyFormat("Test10219", mf, &measure, 1, expected[j][i]);
1593 }
1594 }
1595 }
1596
toMeasureUnit(MeasureUnit * adopted)1597 static MeasureUnit toMeasureUnit(MeasureUnit *adopted) {
1598 MeasureUnit result(*adopted);
1599 delete adopted;
1600 return result;
1601 }
1602
TestGreek()1603 void MeasureFormatTest::TestGreek() {
1604 Locale locales[] = {Locale("el_GR"), Locale("el")};
1605 UErrorCode status = U_ZERO_ERROR;
1606 MeasureUnit units[] = {
1607 toMeasureUnit(MeasureUnit::createSecond(status)),
1608 toMeasureUnit(MeasureUnit::createMinute(status)),
1609 toMeasureUnit(MeasureUnit::createHour(status)),
1610 toMeasureUnit(MeasureUnit::createDay(status)),
1611 toMeasureUnit(MeasureUnit::createWeek(status)),
1612 toMeasureUnit(MeasureUnit::createMonth(status)),
1613 toMeasureUnit(MeasureUnit::createYear(status))};
1614 if (!assertSuccess("Error creating Measure units", status)) {
1615 return;
1616 }
1617 UMeasureFormatWidth styles[] = {
1618 UMEASFMT_WIDTH_WIDE,
1619 UMEASFMT_WIDTH_SHORT};
1620 int32_t numbers[] = {1, 7};
1621 const char *expected[] = {
1622 // "el_GR" 1 wide
1623 "1 \\u03B4\\u03B5\\u03C5\\u03C4\\u03B5\\u03C1\\u03CC\\u03BB\\u03B5\\u03C0\\u03C4\\u03BF",
1624 "1 \\u03BB\\u03B5\\u03C0\\u03C4\\u03CC",
1625 "1 \\u03CE\\u03C1\\u03B1",
1626 "1 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B1",
1627 "1 \\u03B5\\u03B2\\u03B4\\u03BF\\u03BC\\u03AC\\u03B4\\u03B1",
1628 "1 \\u03BC\\u03AE\\u03BD\\u03B1\\u03C2",
1629 "1 \\u03AD\\u03C4\\u03BF\\u03C2",
1630 // "el_GR" 1 short
1631 "1 \\u03B4\\u03B5\\u03C5\\u03C4.",
1632 "1 \\u03BB\\u03B5\\u03C0.",
1633 "1 \\u03CE\\u03C1\\u03B1",
1634 "1 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B1",
1635 "1 \\u03B5\\u03B2\\u03B4.",
1636 "1 \\u03BC\\u03AE\\u03BD.",
1637 "1 \\u03AD\\u03C4.", // year (one)
1638 // "el_GR" 7 wide
1639 "7 \\u03B4\\u03B5\\u03C5\\u03C4\\u03B5\\u03C1\\u03CC\\u03BB\\u03B5\\u03C0\\u03C4\\u03B1",
1640 "7 \\u03BB\\u03B5\\u03C0\\u03C4\\u03AC",
1641 "7 \\u03CE\\u03C1\\u03B5\\u03C2",
1642 "7 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B5\\u03C2",
1643 "7 \\u03B5\\u03B2\\u03B4\\u03BF\\u03BC\\u03AC\\u03B4\\u03B5\\u03C2",
1644 "7 \\u03BC\\u03AE\\u03BD\\u03B5\\u03C2",
1645 "7 \\u03AD\\u03C4\\u03B7",
1646 // "el_GR" 7 short
1647 "7 \\u03B4\\u03B5\\u03C5\\u03C4.",
1648 "7 \\u03BB\\u03B5\\u03C0.",
1649 "7 \\u03CE\\u03C1.", // hour (other)
1650 "7 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B5\\u03C2",
1651 "7 \\u03B5\\u03B2\\u03B4.",
1652 "7 \\u03BC\\u03AE\\u03BD.",
1653 "7 \\u03AD\\u03C4.", // year (other)
1654
1655 // "el" 1 wide
1656 "1 \\u03B4\\u03B5\\u03C5\\u03C4\\u03B5\\u03C1\\u03CC\\u03BB\\u03B5\\u03C0\\u03C4\\u03BF",
1657 "1 \\u03BB\\u03B5\\u03C0\\u03C4\\u03CC",
1658 "1 \\u03CE\\u03C1\\u03B1",
1659 "1 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B1",
1660 "1 \\u03B5\\u03B2\\u03B4\\u03BF\\u03BC\\u03AC\\u03B4\\u03B1",
1661 "1 \\u03BC\\u03AE\\u03BD\\u03B1\\u03C2",
1662 "1 \\u03AD\\u03C4\\u03BF\\u03C2",
1663 // "el" 1 short
1664 "1 \\u03B4\\u03B5\\u03C5\\u03C4.",
1665 "1 \\u03BB\\u03B5\\u03C0.",
1666 "1 \\u03CE\\u03C1\\u03B1",
1667 "1 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B1",
1668 "1 \\u03B5\\u03B2\\u03B4.",
1669 "1 \\u03BC\\u03AE\\u03BD.",
1670 "1 \\u03AD\\u03C4.", // year (one)
1671 // "el" 7 wide
1672 "7 \\u03B4\\u03B5\\u03C5\\u03C4\\u03B5\\u03C1\\u03CC\\u03BB\\u03B5\\u03C0\\u03C4\\u03B1",
1673 "7 \\u03BB\\u03B5\\u03C0\\u03C4\\u03AC",
1674 "7 \\u03CE\\u03C1\\u03B5\\u03C2",
1675 "7 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B5\\u03C2",
1676 "7 \\u03B5\\u03B2\\u03B4\\u03BF\\u03BC\\u03AC\\u03B4\\u03B5\\u03C2",
1677 "7 \\u03BC\\u03AE\\u03BD\\u03B5\\u03C2",
1678 "7 \\u03AD\\u03C4\\u03B7",
1679 // "el" 7 short
1680 "7 \\u03B4\\u03B5\\u03C5\\u03C4.",
1681 "7 \\u03BB\\u03B5\\u03C0.",
1682 "7 \\u03CE\\u03C1.", // hour (other)
1683 "7 \\u03B7\\u03BC\\u03AD\\u03C1\\u03B5\\u03C2",
1684 "7 \\u03B5\\u03B2\\u03B4.",
1685 "7 \\u03BC\\u03AE\\u03BD.",
1686 "7 \\u03AD\\u03C4."}; // year (other)
1687
1688 int32_t counter = 0;
1689 for (int32_t locIndex = 0; locIndex < UPRV_LENGTHOF(locales); ++locIndex ) {
1690 for( int32_t numIndex = 0; numIndex < UPRV_LENGTHOF(numbers); ++numIndex ) {
1691 for ( int32_t styleIndex = 0; styleIndex < UPRV_LENGTHOF(styles); ++styleIndex ) {
1692 for ( int32_t unitIndex = 0; unitIndex < UPRV_LENGTHOF(units); ++unitIndex ) {
1693 Measure measure(numbers[numIndex], new MeasureUnit(units[unitIndex]), status);
1694 if (!assertSuccess("Error creating Measure", status)) {
1695 return;
1696 }
1697 MeasureFormat fmt(locales[locIndex], styles[styleIndex], status);
1698 if (!assertSuccess("Error creating Measure format", status)) {
1699 return;
1700 }
1701 verifyFormat("TestGreek", fmt, &measure, 1, expected[counter]);
1702 ++counter;
1703 }
1704 }
1705 }
1706 }
1707 }
1708
TestFormatSingleArg()1709 void MeasureFormatTest::TestFormatSingleArg() {
1710 UErrorCode status = U_ZERO_ERROR;
1711 MeasureFormat fmt("en", UMEASFMT_WIDTH_WIDE, status);
1712 if (!assertSuccess("Error creating formatter", status)) {
1713 return;
1714 }
1715 UnicodeString buffer;
1716 FieldPosition pos(FieldPosition::DONT_CARE);
1717 fmt.format(
1718 new Measure(3.5, MeasureUnit::createFoot(status), status),
1719 buffer,
1720 pos,
1721 status);
1722 if (!assertSuccess("Error formatting", status)) {
1723 return;
1724 }
1725 assertEquals(
1726 "TestFormatSingleArg",
1727 UnicodeString("3.5 feet"),
1728 buffer);
1729 }
1730
TestFormatMeasuresZeroArg()1731 void MeasureFormatTest::TestFormatMeasuresZeroArg() {
1732 UErrorCode status = U_ZERO_ERROR;
1733 MeasureFormat fmt("en", UMEASFMT_WIDTH_WIDE, status);
1734 verifyFormat("TestFormatMeasuresZeroArg", fmt, NULL, 0, "");
1735 }
1736
TestSimplePer()1737 void MeasureFormatTest::TestSimplePer() {
1738 Locale en("en");
1739 UErrorCode status = U_ZERO_ERROR;
1740 LocalPointer<MeasureUnit> second(MeasureUnit::createSecond(status));
1741 LocalPointer<MeasureUnit> minute(MeasureUnit::createMinute(status));
1742 LocalPointer<MeasureUnit> pound(MeasureUnit::createPound(status));
1743 if (!assertSuccess("", status)) {
1744 return;
1745 }
1746
1747 helperTestSimplePer(
1748 en, UMEASFMT_WIDTH_WIDE,
1749 1.0, *pound, *second, "1 pound per second");
1750 helperTestSimplePer(
1751 en, UMEASFMT_WIDTH_WIDE,
1752 2.0, *pound, *second, "2 pounds per second");
1753 helperTestSimplePer(
1754 en, UMEASFMT_WIDTH_WIDE,
1755 1.0, *pound, *minute, "1 pound per minute");
1756 helperTestSimplePer(
1757 en, UMEASFMT_WIDTH_WIDE,
1758 2.0, *pound, *minute, "2 pounds per minute");
1759
1760 helperTestSimplePer(
1761 en, UMEASFMT_WIDTH_SHORT, 1.0, *pound, *second, "1 lb/s");
1762 helperTestSimplePer(
1763 en, UMEASFMT_WIDTH_SHORT, 2.0, *pound, *second, "2 lb/s");
1764 helperTestSimplePer(
1765 en, UMEASFMT_WIDTH_SHORT, 1.0, *pound, *minute, "1 lb/min");
1766 helperTestSimplePer(
1767 en, UMEASFMT_WIDTH_SHORT, 2.0, *pound, *minute, "2 lb/min");
1768
1769 helperTestSimplePer(
1770 en, UMEASFMT_WIDTH_NARROW, 1.0, *pound, *second, "1#/s");
1771 helperTestSimplePer(
1772 en, UMEASFMT_WIDTH_NARROW, 2.0, *pound, *second, "2#/s");
1773 helperTestSimplePer(
1774 en, UMEASFMT_WIDTH_NARROW, 1.0, *pound, *minute, "1#/min");
1775 helperTestSimplePer(
1776 en, UMEASFMT_WIDTH_NARROW, 2.0, *pound, *minute, "2#/min");
1777
1778 helperTestSimplePer(
1779 en, UMEASFMT_WIDTH_SHORT,
1780 23.3, *pound, *second, "23.3 lb/s",
1781 NumberFormat::kDecimalSeparatorField,
1782 2, 3);
1783
1784 helperTestSimplePer(
1785 en, UMEASFMT_WIDTH_SHORT,
1786 23.3, *pound, *second, "23.3 lb/s",
1787 NumberFormat::kIntegerField,
1788 0, 2);
1789
1790 helperTestSimplePer(
1791 en, UMEASFMT_WIDTH_SHORT,
1792 23.3, *pound, *minute, "23.3 lb/min",
1793 NumberFormat::kDecimalSeparatorField,
1794 2, 3);
1795
1796 helperTestSimplePer(
1797 en, UMEASFMT_WIDTH_SHORT,
1798 23.3, *pound, *minute, "23.3 lb/min",
1799 NumberFormat::kIntegerField,
1800 0, 2);
1801 }
1802
TestNumeratorPlurals()1803 void MeasureFormatTest::TestNumeratorPlurals() {
1804 Locale pl("pl");
1805 UErrorCode status = U_ZERO_ERROR;
1806 LocalPointer<MeasureUnit> second(MeasureUnit::createSecond(status));
1807 LocalPointer<MeasureUnit> foot(MeasureUnit::createFoot(status));
1808 if (!assertSuccess("", status)) {
1809 return;
1810 }
1811
1812 helperTestSimplePer(
1813 pl,
1814 UMEASFMT_WIDTH_WIDE,
1815 1.0, *foot, *second, "1 stopa na sekund\\u0119");
1816 helperTestSimplePer(
1817 pl,
1818 UMEASFMT_WIDTH_WIDE,
1819 2.0, *foot, *second, "2 stopy na sekund\\u0119");
1820 helperTestSimplePer(
1821 pl,
1822 UMEASFMT_WIDTH_WIDE,
1823 5.0, *foot, *second, "5 st\\u00f3p na sekund\\u0119");
1824 helperTestSimplePer(
1825 pl, UMEASFMT_WIDTH_WIDE,
1826 1.5, *foot, *second, "1,5 stopy na sekund\\u0119");
1827 }
1828
helperTestSimplePer(const Locale & locale,UMeasureFormatWidth width,double value,const MeasureUnit & unit,const MeasureUnit & perUnit,const char * expected)1829 void MeasureFormatTest::helperTestSimplePer(
1830 const Locale &locale,
1831 UMeasureFormatWidth width,
1832 double value,
1833 const MeasureUnit &unit,
1834 const MeasureUnit &perUnit,
1835 const char *expected) {
1836 helperTestSimplePer(
1837 locale,
1838 width,
1839 value,
1840 unit,
1841 perUnit,
1842 expected,
1843 FieldPosition::DONT_CARE,
1844 0,
1845 0);
1846 }
1847
helperTestSimplePer(const Locale & locale,UMeasureFormatWidth width,double value,const MeasureUnit & unit,const MeasureUnit & perUnit,const char * expected,int32_t field,int32_t expected_start,int32_t expected_end)1848 void MeasureFormatTest::helperTestSimplePer(
1849 const Locale &locale,
1850 UMeasureFormatWidth width,
1851 double value,
1852 const MeasureUnit &unit,
1853 const MeasureUnit &perUnit,
1854 const char *expected,
1855 int32_t field,
1856 int32_t expected_start,
1857 int32_t expected_end) {
1858 UErrorCode status = U_ZERO_ERROR;
1859 FieldPosition pos(field);
1860 MeasureFormat fmt(locale, width, status);
1861 if (!assertSuccess("Error creating format object", status)) {
1862 return;
1863 }
1864 Measure measure(value, (MeasureUnit *) unit.clone(), status);
1865 if (!assertSuccess("Error creating measure object", status)) {
1866 return;
1867 }
1868 UnicodeString prefix("prefix: ");
1869 UnicodeString buffer(prefix);
1870 fmt.formatMeasurePerUnit(
1871 measure,
1872 perUnit,
1873 buffer,
1874 pos,
1875 status);
1876 if (!assertSuccess("Error formatting measures with per", status)) {
1877 return;
1878 }
1879 UnicodeString uexpected(expected);
1880 uexpected = prefix + uexpected;
1881 assertEquals(
1882 "TestSimplePer",
1883 uexpected.unescape(),
1884 buffer);
1885 if (field != FieldPosition::DONT_CARE) {
1886 assertEquals(
1887 "Start", expected_start, pos.getBeginIndex() - prefix.length());
1888 assertEquals(
1889 "End", expected_end, pos.getEndIndex() - prefix.length());
1890 }
1891 }
1892
TestMultiples()1893 void MeasureFormatTest::TestMultiples() {
1894 Locale ru("ru");
1895 Locale en("en");
1896 helperTestMultiples(en, UMEASFMT_WIDTH_WIDE, "2 miles, 1 foot, 2.3 inches");
1897 helperTestMultiples(en, UMEASFMT_WIDTH_SHORT, "2 mi, 1 ft, 2.3 in");
1898 helperTestMultiples(en, UMEASFMT_WIDTH_NARROW, "2mi 1\\u2032 2.3\\u2033");
1899 helperTestMultiples(ru, UMEASFMT_WIDTH_WIDE, "2 \\u043C\\u0438\\u043B\\u0438 1 \\u0444\\u0443\\u0442 2,3 \\u0434\\u044E\\u0439\\u043C\\u0430");
1900 helperTestMultiples(ru, UMEASFMT_WIDTH_SHORT, "2 \\u043C\\u0438\\u043B\\u0438 1 \\u0444\\u0442 2,3 \\u0434\\u044E\\u0439\\u043C.");
1901 helperTestMultiples(ru, UMEASFMT_WIDTH_NARROW, "2 \\u043C\\u0438\\u043B\\u044C 1 \\u0444\\u0442 2,3 \\u0434\\u044E\\u0439\\u043C\\u0430");
1902 }
1903
helperTestMultiples(const Locale & locale,UMeasureFormatWidth width,const char * expected)1904 void MeasureFormatTest::helperTestMultiples(
1905 const Locale &locale,
1906 UMeasureFormatWidth width,
1907 const char *expected) {
1908 UErrorCode status = U_ZERO_ERROR;
1909 FieldPosition pos(FieldPosition::DONT_CARE);
1910 MeasureFormat fmt(locale, width, status);
1911 if (!assertSuccess("Error creating format object", status)) {
1912 return;
1913 }
1914 Measure measures[] = {
1915 Measure(2.0, MeasureUnit::createMile(status), status),
1916 Measure(1.0, MeasureUnit::createFoot(status), status),
1917 Measure(2.3, MeasureUnit::createInch(status), status)};
1918 if (!assertSuccess("Error creating measures", status)) {
1919 return;
1920 }
1921 UnicodeString buffer;
1922 fmt.formatMeasures(measures, UPRV_LENGTHOF(measures), buffer, pos, status);
1923 if (!assertSuccess("Error formatting measures", status)) {
1924 return;
1925 }
1926 assertEquals("TestMultiples", UnicodeString(expected).unescape(), buffer);
1927 }
1928
TestManyLocaleDurations()1929 void MeasureFormatTest::TestManyLocaleDurations() {
1930 UErrorCode status = U_ZERO_ERROR;
1931 Measure measures[] = {
1932 Measure(5.0, MeasureUnit::createHour(status), status),
1933 Measure(37.0, MeasureUnit::createMinute(status), status)};
1934 if (!assertSuccess("Error creating measures", status)) {
1935 return;
1936 }
1937 helperTestManyLocaleDurations("da", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5 t og 37 min");
1938 helperTestManyLocaleDurations("da", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5.37");
1939 helperTestManyLocaleDurations("de", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5 Std., 37 Min.");
1940 helperTestManyLocaleDurations("de", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1941 helperTestManyLocaleDurations("en", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5h 37m");
1942 helperTestManyLocaleDurations("en", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1943 helperTestManyLocaleDurations("en_GB", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5h 37m");
1944 helperTestManyLocaleDurations("en_GB", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1945 helperTestManyLocaleDurations("es", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5h 37min");
1946 helperTestManyLocaleDurations("es", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1947 helperTestManyLocaleDurations("fi", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5t 37min");
1948 helperTestManyLocaleDurations("fi", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5.37");
1949 helperTestManyLocaleDurations("fr", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5h 37\\u202Fmin");
1950 helperTestManyLocaleDurations("fr", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1951 helperTestManyLocaleDurations("is", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5 klst. og 37 m\\u00EDn.");
1952 helperTestManyLocaleDurations("is", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1953 helperTestManyLocaleDurations("ja", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5h37m");
1954 helperTestManyLocaleDurations("ja", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1955 helperTestManyLocaleDurations("nb", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5t, 37m");
1956 helperTestManyLocaleDurations("nb", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1957 helperTestManyLocaleDurations("nl", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5 u, 37 m");
1958 helperTestManyLocaleDurations("nl", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1959 helperTestManyLocaleDurations("nn", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5t og 37m");
1960 helperTestManyLocaleDurations("nn", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1961 helperTestManyLocaleDurations("sv", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5h 37m");
1962 helperTestManyLocaleDurations("sv", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1963 helperTestManyLocaleDurations("zh", UMEASFMT_WIDTH_NARROW, measures, UPRV_LENGTHOF(measures), "5\\u5C0F\\u65F637\\u5206\\u949F");
1964 helperTestManyLocaleDurations("zh", UMEASFMT_WIDTH_NUMERIC, measures, UPRV_LENGTHOF(measures), "5:37");
1965 }
1966
helperTestManyLocaleDurations(const char * localeID,UMeasureFormatWidth width,const Measure * measures,int32_t measureCount,const char * expected)1967 void MeasureFormatTest::helperTestManyLocaleDurations( const char *localeID,
1968 UMeasureFormatWidth width,
1969 const Measure *measures,
1970 int32_t measureCount,
1971 const char *expected) {
1972 UErrorCode status = U_ZERO_ERROR;
1973 MeasureFormat fmt(Locale(localeID), width, status);
1974 if (U_FAILURE(status)) {
1975 errln("Could not create MeasureFormat for locale %s, width %d, status: %s", localeID, (int)width, u_errorName(status));
1976 return;
1977 }
1978 UnicodeString buffer;
1979 FieldPosition pos(FieldPosition::DONT_CARE);
1980 fmt.formatMeasures(measures, measureCount, buffer, pos, status);
1981 if (U_FAILURE(status)) {
1982 errln("MeasureFormat::formatMeasures failed for locale %s, width %d, status: %s", localeID, (int)width, u_errorName(status));
1983 return;
1984 }
1985 UnicodeString expStr(UnicodeString(expected).unescape());
1986 if (buffer != expStr) {
1987 errln("MeasureFormat::formatMeasures for locale " + UnicodeString(localeID) + ", width " + width + ", expected \"" + expStr + "\", got \"" + buffer + "\"");
1988 }
1989 }
1990
TestGram()1991 void MeasureFormatTest::TestGram() {
1992 UErrorCode status = U_ZERO_ERROR;
1993 MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status);
1994 if (!assertSuccess("Error creating format object", status)) {
1995 return;
1996 }
1997 Measure gram((double)1, MeasureUnit::createGram(status), status);
1998 Measure gforce((double)1, MeasureUnit::createGForce(status), status);
1999 if (!assertSuccess("Error creating measures", status)) {
2000 return;
2001 }
2002 verifyFormat("TestGram", fmt, &gram, 1, "1 g");
2003 verifyFormat("TestGram", fmt, &gforce, 1, "1 G");
2004 }
2005
TestCurrencies()2006 void MeasureFormatTest::TestCurrencies() {
2007 UChar USD[4] = {};
2008 u_uastrcpy(USD, "USD");
2009 UErrorCode status = U_ZERO_ERROR;
2010 CurrencyUnit USD_unit(USD, status);
2011 assertEquals("Currency Unit", USD, USD_unit.getISOCurrency());
2012 if (!assertSuccess("Error creating CurrencyUnit", status)) {
2013 return;
2014 }
2015 CurrencyAmount USD_1(1.0, USD, status);
2016 assertEquals("Currency Code", USD, USD_1.getISOCurrency());
2017 CurrencyAmount USD_2(2.0, USD, status);
2018 CurrencyAmount USD_NEG_1(-1.0, USD, status);
2019 if (!assertSuccess("Error creating currencies", status)) {
2020 return;
2021 }
2022 Locale en("en");
2023 MeasureFormat fmt(en, UMEASFMT_WIDTH_WIDE, status);
2024 if (!assertSuccess("Error creating format object", status)) {
2025 return;
2026 }
2027 verifyFormat("TestCurrenciesWide", fmt, &USD_NEG_1, 1, "-1.00 US dollars");
2028 verifyFormat("TestCurrenciesWide", fmt, &USD_1, 1, "1.00 US dollars");
2029 verifyFormat("TestCurrenciesWide", fmt, &USD_2, 1, "2.00 US dollars");
2030 fmt = MeasureFormat(en, UMEASFMT_WIDTH_SHORT, status);
2031 if (!assertSuccess("Error creating format object", status)) {
2032 return;
2033 }
2034 verifyFormat("TestCurrenciesShort", fmt, &USD_NEG_1, 1, "-USD\\u00A01.00");
2035 verifyFormat("TestCurrenciesShort", fmt, &USD_1, 1, "USD\\u00A01.00");
2036 verifyFormat("TestCurrenciesShort", fmt, &USD_2, 1, "USD\\u00A02.00");
2037 fmt = MeasureFormat(en, UMEASFMT_WIDTH_NARROW, status);
2038 if (!assertSuccess("Error creating format object", status)) {
2039 return;
2040 }
2041 verifyFormat("TestCurrenciesNarrow", fmt, &USD_NEG_1, 1, "-$1.00");
2042 verifyFormat("TestCurrenciesNarrow", fmt, &USD_1, 1, "$1.00");
2043 verifyFormat("TestCurrenciesNarrow", fmt, &USD_2, 1, "$2.00");
2044 fmt = MeasureFormat(en, UMEASFMT_WIDTH_NUMERIC, status);
2045 if (!assertSuccess("Error creating format object", status)) {
2046 return;
2047 }
2048 verifyFormat("TestCurrenciesNumeric", fmt, &USD_NEG_1, 1, "-$1.00");
2049 verifyFormat("TestCurrenciesNumeric", fmt, &USD_1, 1, "$1.00");
2050 verifyFormat("TestCurrenciesNumeric", fmt, &USD_2, 1, "$2.00");
2051 }
2052
TestDisplayNames()2053 void MeasureFormatTest::TestDisplayNames() {
2054 UErrorCode status = U_ZERO_ERROR;
2055 helperTestDisplayName( MeasureUnit::createYear(status), "en", UMEASFMT_WIDTH_WIDE, "years" );
2056 helperTestDisplayName( MeasureUnit::createYear(status), "ja", UMEASFMT_WIDTH_WIDE, "\\u5E74" );
2057 helperTestDisplayName( MeasureUnit::createYear(status), "es", UMEASFMT_WIDTH_WIDE, "a\\u00F1os" );
2058 helperTestDisplayName( MeasureUnit::createYear(status), "pt", UMEASFMT_WIDTH_WIDE, "anos" );
2059 helperTestDisplayName( MeasureUnit::createYear(status), "pt-PT", UMEASFMT_WIDTH_WIDE, "anos" );
2060 helperTestDisplayName( MeasureUnit::createAmpere(status), "en", UMEASFMT_WIDTH_WIDE, "amperes" );
2061 helperTestDisplayName( MeasureUnit::createAmpere(status), "ja", UMEASFMT_WIDTH_WIDE, "\\u30A2\\u30F3\\u30DA\\u30A2" );
2062 helperTestDisplayName( MeasureUnit::createAmpere(status), "es", UMEASFMT_WIDTH_WIDE, "amperios" );
2063 helperTestDisplayName( MeasureUnit::createAmpere(status), "pt", UMEASFMT_WIDTH_WIDE, "amperes" );
2064 helperTestDisplayName( MeasureUnit::createAmpere(status), "pt-PT", UMEASFMT_WIDTH_WIDE, "amperes" );
2065 helperTestDisplayName( MeasureUnit::createMeterPerSecondSquared(status), "pt", UMEASFMT_WIDTH_WIDE, "metros por segundo ao quadrado" );
2066 helperTestDisplayName( MeasureUnit::createMeterPerSecondSquared(status), "pt-PT", UMEASFMT_WIDTH_WIDE, "metros por segundo quadrado" );
2067 helperTestDisplayName( MeasureUnit::createSquareKilometer(status), "pt", UMEASFMT_WIDTH_NARROW, "km\\u00B2" );
2068 helperTestDisplayName( MeasureUnit::createSquareKilometer(status), "pt", UMEASFMT_WIDTH_SHORT, "km\\u00B2" );
2069 helperTestDisplayName( MeasureUnit::createSquareKilometer(status), "pt", UMEASFMT_WIDTH_WIDE, "quil\\u00F4metros quadrados" );
2070 helperTestDisplayName( MeasureUnit::createSecond(status), "pt-PT", UMEASFMT_WIDTH_NARROW, "s" );
2071 helperTestDisplayName( MeasureUnit::createSecond(status), "pt-PT", UMEASFMT_WIDTH_SHORT, "s" );
2072 helperTestDisplayName( MeasureUnit::createSecond(status), "pt-PT", UMEASFMT_WIDTH_WIDE, "segundos" );
2073 helperTestDisplayName( MeasureUnit::createSecond(status), "pt", UMEASFMT_WIDTH_NARROW, "seg" );
2074 helperTestDisplayName( MeasureUnit::createSecond(status), "pt", UMEASFMT_WIDTH_SHORT, "seg" );
2075 helperTestDisplayName( MeasureUnit::createSecond(status), "pt", UMEASFMT_WIDTH_WIDE, "segundos" );
2076 assertSuccess("Error creating measure units", status);
2077 }
2078
helperTestDisplayName(const MeasureUnit * unit,const char * localeID,UMeasureFormatWidth width,const char * expected)2079 void MeasureFormatTest::helperTestDisplayName(const MeasureUnit *unit,
2080 const char *localeID,
2081 UMeasureFormatWidth width,
2082 const char *expected) {
2083 UErrorCode status = U_ZERO_ERROR;
2084 MeasureFormat fmt(Locale(localeID), width, status);
2085 if (U_FAILURE(status)) {
2086 errln("Could not create MeasureFormat for locale %s, width %d, status: %s",
2087 localeID, (int)width, u_errorName(status));
2088 return;
2089 }
2090
2091 UnicodeString dnam = fmt.getUnitDisplayName(*unit, status);
2092 if (U_FAILURE(status)) {
2093 errln("MeasureFormat::getUnitDisplayName failed for unit %s-%s, locale %s, width %d, status: %s",
2094 unit->getType(), unit->getSubtype(), localeID, (int)width, u_errorName(status));
2095 return;
2096 }
2097
2098 UnicodeString expStr(UnicodeString(expected).unescape());
2099 if (dnam != expStr) {
2100 errln("MeasureFormat::getUnitDisplayName for unit %s-%s, locale %s, width %d: expected \"%s\", got \"%s\"",
2101 unit->getType(), unit->getSubtype(), localeID, (int)width, CStr(expStr)(), CStr(dnam)());
2102 }
2103
2104 // Delete the measure unit
2105 delete unit;
2106 }
2107
TestFieldPosition()2108 void MeasureFormatTest::TestFieldPosition() {
2109 UErrorCode status = U_ZERO_ERROR;
2110 MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status);
2111 if (!assertSuccess("Error creating format object", status)) {
2112 return;
2113 }
2114 Measure measure(43.5, MeasureUnit::createFoot(status), status);
2115 if (!assertSuccess("Error creating measure object 1", status)) {
2116 return;
2117 }
2118 UnicodeString prefix("123456: ");
2119 verifyFieldPosition(
2120 "",
2121 fmt,
2122 prefix,
2123 &measure,
2124 1,
2125 NumberFormat::kDecimalSeparatorField,
2126 10,
2127 11);
2128 measure = Measure(43.0, MeasureUnit::createFoot(status), status);
2129 if (!assertSuccess("Error creating measure object 2", status)) {
2130 return;
2131 }
2132 verifyFieldPosition(
2133 "",
2134 fmt,
2135 prefix,
2136 &measure,
2137 1,
2138 NumberFormat::kDecimalSeparatorField,
2139 0,
2140 0);
2141 }
2142
TestFieldPositionMultiple()2143 void MeasureFormatTest::TestFieldPositionMultiple() {
2144 UErrorCode status = U_ZERO_ERROR;
2145 MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status);
2146 if (!assertSuccess("Error creating format object", status)) {
2147 return;
2148 }
2149 Measure first[] = {
2150 Measure((double)354, MeasureUnit::createMeter(status), status),
2151 Measure((double)23, MeasureUnit::createCentimeter(status), status)};
2152 Measure second[] = {
2153 Measure((double)354, MeasureUnit::createMeter(status), status),
2154 Measure((double)23, MeasureUnit::createCentimeter(status), status),
2155 Measure((double)5.4, MeasureUnit::createMillimeter(status), status)};
2156 Measure third[] = {
2157 Measure((double)3, MeasureUnit::createMeter(status), status),
2158 Measure((double)23, MeasureUnit::createCentimeter(status), status),
2159 Measure((double)5, MeasureUnit::createMillimeter(status), status)};
2160 if (!assertSuccess("Error creating measure objects", status)) {
2161 return;
2162 }
2163 UnicodeString prefix("123456: ");
2164 verifyFieldPosition(
2165 "Integer",
2166 fmt,
2167 prefix,
2168 first,
2169 UPRV_LENGTHOF(first),
2170 NumberFormat::kIntegerField,
2171 8,
2172 11);
2173 verifyFieldPosition(
2174 "Decimal separator",
2175 fmt,
2176 prefix,
2177 second,
2178 UPRV_LENGTHOF(second),
2179 NumberFormat::kDecimalSeparatorField,
2180 23,
2181 24);
2182 verifyFieldPosition(
2183 "no decimal separator",
2184 fmt,
2185 prefix,
2186 third,
2187 UPRV_LENGTHOF(third),
2188 NumberFormat::kDecimalSeparatorField,
2189 0,
2190 0);
2191 }
2192
TestBadArg()2193 void MeasureFormatTest::TestBadArg() {
2194 UErrorCode status = U_ZERO_ERROR;
2195 MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status);
2196 if (!assertSuccess("Error creating format object", status)) {
2197 return;
2198 }
2199 FieldPosition pos(FieldPosition::DONT_CARE);
2200 UnicodeString buffer;
2201 fmt.format(
2202 9.3,
2203 buffer,
2204 pos,
2205 status);
2206 if (status != U_ILLEGAL_ARGUMENT_ERROR) {
2207 errln("Expected ILLEGAL_ARGUMENT_ERROR");
2208 }
2209 }
2210
TestEquality()2211 void MeasureFormatTest::TestEquality() {
2212 UErrorCode status = U_ZERO_ERROR;
2213 NumberFormat* nfeq = NumberFormat::createInstance("en", status);
2214 NumberFormat* nfne = NumberFormat::createInstance("fr", status);
2215 MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status);
2216 MeasureFormat fmtEq2("en", UMEASFMT_WIDTH_SHORT, nfeq, status);
2217 MeasureFormat fmtne1("en", UMEASFMT_WIDTH_WIDE, status);
2218 MeasureFormat fmtne2("fr", UMEASFMT_WIDTH_SHORT, status);
2219 MeasureFormat fmtne3("en", UMEASFMT_WIDTH_SHORT, nfne, status);
2220 if (U_FAILURE(status)) {
2221 dataerrln("Error creating MeasureFormats - %s", u_errorName(status));
2222 return;
2223 }
2224 MeasureFormat fmtEq(fmt);
2225 assertTrue("Equal", fmt == fmtEq);
2226 assertTrue("Equal2", fmt == fmtEq2);
2227 assertFalse("Equal Neg", fmt != fmtEq);
2228 assertTrue("Not Equal 1", fmt != fmtne1);
2229 assertFalse("Not Equal Neg 1", fmt == fmtne1);
2230 assertTrue("Not Equal 2", fmt != fmtne2);
2231 assertTrue("Not Equal 3", fmt != fmtne3);
2232 }
2233
TestGroupingSeparator()2234 void MeasureFormatTest::TestGroupingSeparator() {
2235 UErrorCode status = U_ZERO_ERROR;
2236 Locale en("en");
2237 MeasureFormat fmt(en, UMEASFMT_WIDTH_SHORT, status);
2238 if (!assertSuccess("Error creating format object", status)) {
2239 return;
2240 }
2241 Measure ms[] = {
2242 Measure((int32_t)INT32_MAX, MeasureUnit::createYear(status), status),
2243 Measure((int32_t)INT32_MIN, MeasureUnit::createMonth(status), status),
2244 Measure(-987.0, MeasureUnit::createDay(status), status),
2245 Measure(1362.0, MeasureUnit::createHour(status), status),
2246 Measure(987.0, MeasureUnit::createMinute(status), status)};
2247 FieldPosition pos(NumberFormat::kGroupingSeparatorField);
2248 UnicodeString appendTo;
2249 fmt.formatMeasures(ms, 5, appendTo, pos, status);
2250 if (!assertSuccess("Error formatting", status)) {
2251 return;
2252 }
2253 assertEquals(
2254 "grouping separator",
2255 "2,147,483,647 yrs, -2,147,483,648 mths, -987 days, 1,362 hr, 987 min",
2256 appendTo);
2257 assertEquals("begin index", 1, pos.getBeginIndex());
2258 assertEquals("end index", 2, pos.getEndIndex());
2259 }
2260
TestDoubleZero()2261 void MeasureFormatTest::TestDoubleZero() {
2262 UErrorCode status = U_ZERO_ERROR;
2263 Measure measures[] = {
2264 Measure(4.7, MeasureUnit::createHour(status), status),
2265 Measure(23.0, MeasureUnit::createMinute(status), status),
2266 Measure(16.0, MeasureUnit::createSecond(status), status)};
2267 Locale en("en");
2268 NumberFormat *nf = NumberFormat::createInstance(en, status);
2269 MeasureFormat fmt("en", UMEASFMT_WIDTH_WIDE, nf, status);
2270 UnicodeString appendTo;
2271 FieldPosition pos(FieldPosition::DONT_CARE);
2272 if (U_FAILURE(status)) {
2273 dataerrln("Error creating formatter - %s", u_errorName(status));
2274 return;
2275 }
2276 nf->setMinimumFractionDigits(2);
2277 nf->setMaximumFractionDigits(2);
2278 fmt.formatMeasures(measures, UPRV_LENGTHOF(measures), appendTo, pos, status);
2279 if (!assertSuccess("Error formatting", status)) {
2280 return;
2281 }
2282 assertEquals(
2283 "TestDoubleZero",
2284 UnicodeString("4 hours, 23 minutes, 16.00 seconds"),
2285 appendTo);
2286 measures[0] = Measure(-4.7, MeasureUnit::createHour(status), status);
2287 appendTo.remove();
2288 fmt.formatMeasures(measures, UPRV_LENGTHOF(measures), appendTo, pos, status);
2289 if (!assertSuccess("Error formatting", status)) {
2290 return;
2291 }
2292 assertEquals(
2293 "TestDoubleZero",
2294 UnicodeString("-4 hours, 23 minutes, 16.00 seconds"),
2295 appendTo);
2296 }
2297
TestUnitPerUnitResolution()2298 void MeasureFormatTest::TestUnitPerUnitResolution() {
2299 UErrorCode status = U_ZERO_ERROR;
2300 Locale en("en");
2301 MeasureFormat fmt("en", UMEASFMT_WIDTH_SHORT, status);
2302 Measure measure(50.0, MeasureUnit::createPound(status), status);
2303 LocalPointer<MeasureUnit> sqInch(MeasureUnit::createSquareInch(status));
2304 if (!assertSuccess("Create of format unit and per unit", status)) {
2305 return;
2306 }
2307 FieldPosition pos(FieldPosition::DONT_CARE);
2308 UnicodeString actual;
2309 fmt.formatMeasurePerUnit(
2310 measure,
2311 *sqInch,
2312 actual,
2313 pos,
2314 status);
2315 assertEquals("", "50 psi", actual);
2316 }
2317
TestIndividualPluralFallback()2318 void MeasureFormatTest::TestIndividualPluralFallback() {
2319 // See ticket #11986 "incomplete fallback in MeasureFormat".
2320 // In CLDR 28, fr_CA temperature-generic/short has only the "one" form,
2321 // and falls back to fr for the "other" form.
2322 IcuTestErrorCode errorCode(*this, "TestIndividualPluralFallback");
2323 MeasureFormat mf("fr_CA", UMEASFMT_WIDTH_SHORT, errorCode);
2324 LocalPointer<Measure> twoDeg(
2325 new Measure(2.0, MeasureUnit::createGenericTemperature(errorCode), errorCode), errorCode);
2326 UnicodeString expected = UNICODE_STRING_SIMPLE("2\\u00B0").unescape();
2327 UnicodeString actual;
2328 assertEquals("2 deg temp in fr_CA", expected, mf.format(twoDeg.orphan(), actual, errorCode), TRUE);
2329 }
2330
verifyFieldPosition(const char * description,const MeasureFormat & fmt,const UnicodeString & prefix,const Measure * measures,int32_t measureCount,NumberFormat::EAlignmentFields field,int32_t start,int32_t end)2331 void MeasureFormatTest::verifyFieldPosition(
2332 const char *description,
2333 const MeasureFormat &fmt,
2334 const UnicodeString &prefix,
2335 const Measure *measures,
2336 int32_t measureCount,
2337 NumberFormat::EAlignmentFields field,
2338 int32_t start,
2339 int32_t end) {
2340 // 8 char lead
2341 UnicodeString result(prefix);
2342 FieldPosition pos(field);
2343 UErrorCode status = U_ZERO_ERROR;
2344 CharString ch;
2345 const char *descPrefix = ch.append(description, status)
2346 .append(": ", status).data();
2347 CharString beginIndex;
2348 beginIndex.append(descPrefix, status).append("beginIndex", status);
2349 CharString endIndex;
2350 endIndex.append(descPrefix, status).append("endIndex", status);
2351 fmt.formatMeasures(measures, measureCount, result, pos, status);
2352 if (!assertSuccess("Error formatting", status)) {
2353 return;
2354 }
2355 assertEquals(beginIndex.data(), start, pos.getBeginIndex());
2356 assertEquals(endIndex.data(), end, pos.getEndIndex());
2357 }
2358
verifyFormat(const char * description,const MeasureFormat & fmt,const Measure * measures,int32_t measureCount,const char * expected)2359 void MeasureFormatTest::verifyFormat(
2360 const char *description,
2361 const MeasureFormat &fmt,
2362 const Measure *measures,
2363 int32_t measureCount,
2364 const char *expected) {
2365 verifyFormatWithPrefix(
2366 description,
2367 fmt,
2368 "",
2369 measures,
2370 measureCount,
2371 expected);
2372 }
2373
verifyFormatWithPrefix(const char * description,const MeasureFormat & fmt,const UnicodeString & prefix,const Measure * measures,int32_t measureCount,const char * expected)2374 void MeasureFormatTest::verifyFormatWithPrefix(
2375 const char *description,
2376 const MeasureFormat &fmt,
2377 const UnicodeString &prefix,
2378 const Measure *measures,
2379 int32_t measureCount,
2380 const char *expected) {
2381 UnicodeString result(prefix);
2382 FieldPosition pos(FieldPosition::DONT_CARE);
2383 UErrorCode status = U_ZERO_ERROR;
2384 fmt.formatMeasures(measures, measureCount, result, pos, status);
2385 if (!assertSuccess("Error formatting", status)) {
2386 return;
2387 }
2388 assertEquals(description, ctou(expected), result);
2389 }
2390
verifyFormat(const char * description,const MeasureFormat & fmt,const ExpectedResult * expectedResults,int32_t count)2391 void MeasureFormatTest::verifyFormat(
2392 const char *description,
2393 const MeasureFormat &fmt,
2394 const ExpectedResult *expectedResults,
2395 int32_t count) {
2396 for (int32_t i = 0; i < count; ++i) {
2397 verifyFormat(description, fmt, expectedResults[i].measures, expectedResults[i].count, expectedResults[i].expected);
2398 }
2399 }
2400
createMeasureFormatTest()2401 extern IntlTest *createMeasureFormatTest() {
2402 return new MeasureFormatTest();
2403 }
2404
2405 #endif
2406
2407