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