]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/cintltst/cmeasureformattest.c
ICU-57166.0.1.tar.gz
[apple/icu.git] / icuSources / test / cintltst / cmeasureformattest.c
CommitLineData
2ca993e8
A
1/********************************************************************
2 * Copyright (c) 2015-2016, Apple Inc. All Rights Reserved.
3 ********************************************************************/
4/* C API TEST FOR APPLE MEASUREFORMAT C WRAPPER */
5
6#include "unicode/utypes.h"
7#include <unistd.h>
8
9#if !UCONFIG_NO_FORMATTING
10
11#include "unicode/uameasureformat.h"
12#include "unicode/ustring.h"
a62d09fc 13#include "unicode/uloc.h"
2ca993e8
A
14#include "cintltst.h"
15#include "cmemory.h"
16#include "cstring.h"
17
18static void TestUAMeasureFormat(void);
a62d09fc 19static void TestUAMeasFmtOpenAllLocs(void);
2ca993e8
A
20static void TestUAGetUnitsForUsage(void);
21static void TestUAGetCategoryForUnit(void);
22
23void addMeasureFormatTest(TestNode** root);
24
25#define TESTCASE(x) addTest(root, &x, "tsformat/cmeasureformattest/" #x)
26
27void addMeasureFormatTest(TestNode** root)
28{
29 TESTCASE(TestUAMeasureFormat);
a62d09fc 30 TESTCASE(TestUAMeasFmtOpenAllLocs);
2ca993e8
A
31 TESTCASE(TestUAGetUnitsForUsage);
32 TESTCASE(TestUAGetCategoryForUnit);
33}
34
35typedef struct {
36 UAMeasureUnit unit;
37 float value;
38 const char * expectFmt_wide_2;
39 const char * expectFmt_wide_0;
40 const char * expectFmt_shrt_X;
41 const char * expectFmt_shrt_1;
42 const char * expectFmt_narr_0;
43 const char * expectFmt_numr_0;
44 int32_t beginInt_wide_0;
45 int32_t endInt_wide_0;
46 int32_t beginInt_numr_0;
47 int32_t endInt_numr_0;
48} SingleUnitFormat;
49
50typedef struct {
51 UAMeasureUnit unit;
52 const char * expectName_wide;
53 const char * expectName_shrt;
54 const char * expectName_narr;
55} SingleUnitName;
56
57typedef struct {
58 const UAMeasure* measures;
59 int32_t measureCount;
60 const char * expectFmt_wide_2;
61 const char * expectFmt_wide_0;
62 const char * expectFmt_shrt_X;
63 const char * expectFmt_shrt_1;
64 const char * expectFmt_shrtr_1;
65 const char * expectFmt_narr_0;
66 const char * expectFmt_numr_0;
67 int32_t ranges_wide_2[8][3];
68 int32_t ranges_shrtr_1[8][3];
69 int32_t ranges_numr_0[8][3];
70} MultipleUnitFormat;
71
72typedef struct {
73 const UAMeasureUnit* units;
74 int32_t unitCount;
75 UAMeasureNameListStyle listStyle;
76 const char * expectName_wide;
77 const char * expectName_shrt;
78 const char * expectName_narr;
79} MultipleUnitName;
80
81typedef struct {
82 const char * locale;
83 const SingleUnitFormat * singleUnitFormatTests; // may be NULL
84 const SingleUnitName * singleUnitNameTests; // may be NULL
85 const MultipleUnitFormat * multipleUnitFormatTests; // may be NULL
86 const MultipleUnitName * multipleUnitNameTests; // may be NULL
87} LocaleWidthNumFmtItem;
88
89static const SingleUnitFormat en_singFmt[] = {
90// unit value wide_2 wide_0 shrt_X shrt_1 narr_0 numr_0 wide_0 narr_0
91 { UAMEASUNIT_DURATION_MINUTE, 0.0, "0.00 minutes", "0 minutes", "0 min", "0.0 min", "0m", "0m", 0,1, 0,1 },
92 { UAMEASUNIT_DURATION_MINUTE, 1.0, "1.00 minutes", "1 minute", "1 min", "1.0 min", "1m", "1m", 0,1, 0,1 },
93 { UAMEASUNIT_DURATION_MINUTE, 5.25, "5.25 minutes", "5 minutes", "5.25 min", "5.2 min", "5m", "5m", 0,1, 0,1 },
94 { UAMEASUNIT_DURATION_DAY, 5.25, "5.25 days", "5 days", "5.25 days", "5.2 days", "5d", "5d", 0,1, 0,1 },
95 { UAMEASUNIT_DURATION_WEEK, 5.25, "5.25 weeks", "5 weeks", "5.25 wks", "5.2 wks", "5w", "5w", 0,1, 0,1 },
96 { UAMEASUNIT_DURATION_CENTURY, 37.203, "37.20 centuries", "37 centuries", "37.203 c", "37.2 c", "37 c", "37 c", 0,2, 0,2 },
97 { UAMEASUNIT_LENGTH_CENTIMETER, 37.203, "37.20 centimeters", "37 centimeters", "37.203 cm", "37.2 cm", "37cm", "37cm", 0,2, 0,2 },
98 { UAMEASUNIT_SPEED_KILOMETER_PER_HOUR, 37.203, "37.20 kilometers per hour", "37 kilometers per hour", "37.203 kph", "37.2 kph", "37kph", "37kph", 0,2, 0,2 },
99 { UAMEASUNIT_TEMPERATURE_CELSIUS, 37.203, "37.20 degrees Celsius", "37 degrees Celsius", "37.203\\u00B0C", "37.2\\u00B0C", "37\\u00B0C", "37\\u00B0", 0,2, 0,2 },
100 { UAMEASUNIT_TEMPERATURE_FAHRENHEIT, 37.203, "37.20 degrees Fahrenheit", "37 degrees Fahrenheit", "37.203\\u00B0F", "37.2\\u00B0F", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
101 { UAMEASUNIT_TEMPERATURE_GENERIC, 37.203, "37.20\\u00B0", "37\\u00B0", "37.203\\u00B0", "37.2\\u00B0", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
102 { UAMEASUNIT_VOLUME_LITER, 37.203, "37.20 liters", "37 liters", "37.203 L", "37.2 L", "37L", "37L", 0,2, 0,2 },
103 { UAMEASUNIT_ENERGY_FOODCALORIE, 37.203, "37.20 Calories", "37 Calories", "37.203 Cal", "37.2 Cal", "37Cal", "37Cal", 0,2, 0,2 },
104 { UAMEASUNIT_ENERGY_JOULE, 37.203, "37.20 joules", "37 joules", "37.203 J", "37.2 J", "37J", "37J", 0,2, 0,2 },
105 { UAMEASUNIT_DIGITAL_MEGABYTE, 37.203, "37.20 megabytes", "37 megabytes", "37.203 MB", "37.2 MB", "37MB", "37MB", 0,2, 0,2 },
106 { (UAMeasureUnit)0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
107};
108
109static const SingleUnitFormat en_GB_singFmt[] = {
110// unit value wide_2 wide_0 shrt_X shrt_1 narr_0 numr_0 wide_0 narr_0
111 { UAMEASUNIT_DURATION_MINUTE, 0.0, "0.00 minutes", "0 minutes", "0 min", "0.0 min", "0m", "0m", 0,1, 0,1 },
112 { UAMEASUNIT_DURATION_MINUTE, 1.0, "1.00 minutes", "1 minute", "1 min", "1.0 min", "1m", "1m", 0,1, 0,1 },
113 { UAMEASUNIT_DURATION_MINUTE, 5.25, "5.25 minutes", "5 minutes", "5.25 min", "5.2 min", "5m", "5m", 0,1, 0,1 },
114 { UAMEASUNIT_LENGTH_CENTIMETER, 37.203, "37.20 centimetres", "37 centimetres", "37.203 cm", "37.2 cm", "37cm", "37cm", 0,2, 0,2 },
115 { UAMEASUNIT_TEMPERATURE_CELSIUS, 37.203, "37.20 degrees Celsius", "37 degrees Celsius", "37.203\\u00B0C", "37.2\\u00B0C", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
116 { UAMEASUNIT_TEMPERATURE_FAHRENHEIT, 37.203, "37.20 degrees Fahrenheit", "37 degrees Fahrenheit", "37.203\\u00B0F", "37.2\\u00B0F", "37\\u00B0F", "37\\u00B0", 0,2, 0,2 },
117 { UAMEASUNIT_TEMPERATURE_GENERIC, 37.203, "37.20\\u00B0", "37\\u00B0", "37.203\\u00B0", "37.2\\u00B0", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
118 { UAMEASUNIT_VOLUME_LITER, 37.203, "37.20 litres", "37 litres", "37.203 l", "37.2 l", "37l", "37l", 0,2, 0,2 },
119 { UAMEASUNIT_ENERGY_FOODCALORIE, 37.203, "37.20 Calories", "37 Calories", "37.203 Cal", "37.2 Cal", "37Cal", "37Cal", 0,2, 0,2 },
120 { (UAMeasureUnit)0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
121};
122
123static const SingleUnitFormat fr_singFmt[] = {
124// unit value wide_2 wide_0 shrt_X shrt_1 narr_0 numr_0 wide_0 narr_0
125 { UAMEASUNIT_DURATION_MINUTE, 0.0, "0,00 minute", "0 minute", "0 mn", "0,0 mn", "0mn", "0mn", 0,1, 0,1 },
126 { UAMEASUNIT_DURATION_MINUTE, 1.0, "1,00 minute", "1 minute", "1 mn", "1,0 mn", "1mn", "1mn", 0,1, 0,1 },
127 { UAMEASUNIT_DURATION_MINUTE, 5.25, "5,25 minutes", "5 minutes", "5,25 mn", "5,2 mn", "5mn", "5mn", 0,1, 0,1 },
128 { UAMEASUNIT_LENGTH_CENTIMETER, 37.203, "37,20 centim\\u00E8tres", "37 centim\\u00E8tres", "37,203 cm", "37,2 cm", "37 cm", "37 cm", 0,2, 0,2 },
129 { UAMEASUNIT_TEMPERATURE_CELSIUS, 37.203, "37,20 degr\\u00E9s Celsius", "37 degr\\u00E9s Celsius", "37,203 \\u00B0C", "37,2 \\u00B0C", "37\\u00B0C", "37\\u00B0", 0,2, 0,2 },
130 { UAMEASUNIT_TEMPERATURE_FAHRENHEIT, 37.203, "37,20 degr\\u00E9s Fahrenheit", "37 degr\\u00E9s Fahrenheit", "37,203 \\u00B0F", "37,2 \\u00B0F", "37\\u00B0F", "37\\u00B0", 0,2, 0,2 },
131 { UAMEASUNIT_TEMPERATURE_GENERIC, 37.203, "37,20 degr\\u00E9s", "37 degr\\u00E9s", "37,203\\u00B0", "37,2\\u00B0", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
132 { UAMEASUNIT_VOLUME_LITER, 37.203, "37,20 litres", "37 litres", "37,203 l", "37,2 l", "37 l", "37 l", 0,2, 0,2 },
133 { UAMEASUNIT_ENERGY_FOODCALORIE, 37.203, "37,20 kilocalories", "37 kilocalories", "37,203 kcal", "37,2 kcal", "37 kcal", "37 kcal", 0,2, 0,2 },
134 { (UAMeasureUnit)0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
135};
136
137static const SingleUnitFormat fr_CA_singFmt[] = {
138// unit value wide_2 wide_0 shrt_X shrt_1 narr_0 numr_0 wide_0 narr_0
139 { UAMEASUNIT_DURATION_MINUTE, 0.0, "0,00 minute", "0 minute", "0 min", "0,0 min", "0m", "0m", 0,1, 0,1 },
140 { UAMEASUNIT_DURATION_MINUTE, 1.0, "1,00 minute", "1 minute", "1 min", "1,0 min", "1m", "1m", 0,1, 0,1 },
141 { UAMEASUNIT_DURATION_MINUTE, 5.25, "5,25 minutes", "5 minutes", "5,25 min", "5,2 min", "5m", "5m", 0,1, 0,1 },
142 { UAMEASUNIT_LENGTH_CENTIMETER, 37.203, "37,20 centim\\u00E8tres", "37 centim\\u00E8tres", "37,203 cm", "37,2 cm", "37 cm", "37 cm", 0,2, 0,2 },
143 { UAMEASUNIT_TEMPERATURE_CELSIUS, 37.203, "37,20 degr\\u00E9s Celsius", "37 degr\\u00E9s Celsius", "37,203 \\u00B0C", "37,2 \\u00B0C", "37 \\u00B0C", "37\\u00B0", 0,2, 0,2 },
144 { UAMEASUNIT_TEMPERATURE_FAHRENHEIT, 37.203, "37,20 degr\\u00E9s Fahrenheit", "37 degr\\u00E9s Fahrenheit", "37,203 \\u00B0F", "37,2 \\u00B0F", "37\\u00B0F", "37\\u00B0", 0,2, 0,2 },
145 { UAMEASUNIT_TEMPERATURE_GENERIC, 37.203, "37,20\\u00B0", "37\\u00B0", "37,203\\u00B0", "37,2\\u00B0", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
146 { UAMEASUNIT_VOLUME_LITER, 37.203, "37,20 litres", "37 litres", "37,203 L", "37,2 L", "37L", "37L", 0,2, 0,2 },
147 { UAMEASUNIT_ENERGY_FOODCALORIE, 37.203, "37,20 kilocalories", "37 kilocalories", "37,203 kcal", "37,2 kcal", "37 kcal", "37 kcal", 0,2, 0,2 },
148 { (UAMeasureUnit)0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
149};
150
151static const SingleUnitFormat cs_singFmt[] = {
152// unit value wide_2 wide_0 shrt_X shrt_1 narr_0 numr_0 wide_0 narr_0
153 { UAMEASUNIT_DURATION_MINUTE, 0.0, "0,00 minuty", "0 minut", "0 min", "0,0 min", "0 m", "0 m", 0,1, 0,1 }, // other for integer, else many
154 { UAMEASUNIT_DURATION_MINUTE, 1.0, "1,00 minuty", "1 minuta", "1 min", "1,0 min", "1 m", "1 m", 0,1, 0,1 }, // one for integer, else many
155 { UAMEASUNIT_DURATION_MINUTE, 2.0, "2,00 minuty", "2 minuty", "2 min", "2,0 min", "2 m", "2 m", 0,1, 0,1 }, // few for integer, else many
156 { UAMEASUNIT_DURATION_MINUTE, 8.5, "8,50 minuty", "8 minut", "8,5 min", "8,5 min", "8 m", "8 m", 0,1, 0,1 }, // other for integer, else many
157 { (UAMeasureUnit)0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
158};
159
160static const SingleUnitName en_singNam[] = {
161// unit wide shrt narr
162 { UAMEASUNIT_DURATION_MINUTE, "minutes", "min", "min" },
163 { UAMEASUNIT_DURATION_CENTURY, "centuries", "c", "c" },
164 { UAMEASUNIT_LENGTH_CENTIMETER, "centimeters", "cm", "cm" },
165 { UAMEASUNIT_SPEED_KILOMETER_PER_HOUR, "kilometers per hour", "km/hour", "km/hr" },
166 { UAMEASUNIT_TEMPERATURE_CELSIUS, "degrees Celsius", "deg. C", "\\u00B0C" },
167 { UAMEASUNIT_TEMPERATURE_FAHRENHEIT, "degrees Fahrenheit", "deg. F", "\\u00B0F" },
168 { UAMEASUNIT_TEMPERATURE_GENERIC, "\\u00B0", "\\u00B0", "\\u00B0" },
169 { UAMEASUNIT_VOLUME_LITER, "liters", "liters", "liter" },
170 { UAMEASUNIT_ENERGY_FOODCALORIE, "Calories", "Cal", "Cal" },
171 { UAMEASUNIT_ENERGY_JOULE, "joules", "joules", "joule" },
172 { UAMEASUNIT_DIGITAL_MEGABYTE, "megabytes", "MByte", "MByte" },
173 { (UAMeasureUnit)0, NULL, NULL, NULL }
174};
175
176static const SingleUnitName en_GB_singNam[] = {
177// unit wide shrt narr
178 { UAMEASUNIT_DURATION_MINUTE, "minutes", "min", "min" },
179 { UAMEASUNIT_LENGTH_CENTIMETER, "centimetres", "cm", "cm" },
180 { UAMEASUNIT_TEMPERATURE_CELSIUS, "degrees Celsius", "deg. C", "\\u00B0C" },
181 { UAMEASUNIT_TEMPERATURE_FAHRENHEIT, "degrees Fahrenheit", "deg. F", "\\u00B0F" },
182 { UAMEASUNIT_TEMPERATURE_GENERIC, "\\u00B0", "\\u00B0", "\\u00B0" },
183 { UAMEASUNIT_VOLUME_LITER, "litres", "litres", "litre" },
184 { UAMEASUNIT_ENERGY_FOODCALORIE, "Calories", "Cal", "Cal" },
185 { (UAMeasureUnit)0, NULL, NULL, NULL }
186};
187
188static const UAMeasure meas_hrMnSc[] = { {37.3,UAMEASUNIT_DURATION_HOUR}, {12.1,UAMEASUNIT_DURATION_MINUTE}, {5.32,UAMEASUNIT_DURATION_SECOND} };
189static const UAMeasure meas_hrMn[] = { {37.3,UAMEASUNIT_DURATION_HOUR}, {12.1,UAMEASUNIT_DURATION_MINUTE} };
190static const UAMeasure meas_mCm[] = { {37.3,UAMEASUNIT_LENGTH_METER}, {12.1,UAMEASUNIT_LENGTH_CENTIMETER} };
191static const UAMeasure meas_cm[] = { {12.1,UAMEASUNIT_LENGTH_CENTIMETER} };
192static const UAMeasure meas_2hrMn[] = { {2.0,UAMEASUNIT_DURATION_HOUR}, {12.1,UAMEASUNIT_DURATION_MINUTE} };
193static const UAMeasure meas_moDys[] = { {1.0,UAMEASUNIT_DURATION_MONTH}, {2.0,UAMEASUNIT_DURATION_DAY} };
194
195static const MultipleUnitFormat en_multFmt[] = {
196// measures count wide_2 wide_0 shrt_X shrt_1 shrtr_1 narr_0 numr_0
197 { meas_hrMnSc, UPRV_LENGTHOF(meas_hrMnSc), "37 hours, 12 minutes, 5.32 seconds", "37 hours, 12 minutes, 5 seconds", "37 hr, 12 min, 5.32 sec", "37 hr, 12 min, 5.3 sec", "37hr 12min 5.3sec", "37h 12m 5s", "13:12:05",
198 /* ranges_wide_2: */ {{UAMEASUNIT_DURATION_HOUR,0,8},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE,10,20},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG,10,12},{UAMEASUNIT_DURATION_SECOND,22,34},{UAMEASUNIT_DURATION_SECOND|UAMEASFMT_NUMERIC_FIELD_FLAG,22,26}},
199 /* ranges_shrtr_1: */ {{UAMEASUNIT_DURATION_HOUR,0,4},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE, 5,10},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG, 5, 7},{UAMEASUNIT_DURATION_SECOND,11,17},{UAMEASUNIT_DURATION_SECOND|UAMEASFMT_NUMERIC_FIELD_FLAG,11,14}},
200 /* ranges_numr_0: */ {{UAMEASUNIT_DURATION_HOUR,0,2},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE, 3, 5},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG, 3, 5},{UAMEASUNIT_DURATION_SECOND, 6, 8},{UAMEASUNIT_DURATION_SECOND|UAMEASFMT_NUMERIC_FIELD_FLAG, 6, 8}} },
201 { meas_hrMn, UPRV_LENGTHOF(meas_hrMn), "37 hours, 12.10 minutes", "37 hours, 12 minutes", "37 hr, 12.1 min", "37 hr, 12.1 min", "37hr 12.1min", "37h 12m", "13:12",
202 /* ranges_wide_2: */ {{UAMEASUNIT_DURATION_HOUR,0,8},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE,10,23},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG,10,15}},
203 /* ranges_shrtr_1: */ {{UAMEASUNIT_DURATION_HOUR,0,4},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE, 5,12},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG, 5, 9}},
204 /* ranges_numr_0: */ {{UAMEASUNIT_DURATION_HOUR,0,2},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE, 3, 5},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG, 3, 5}} },
205 { meas_mCm, UPRV_LENGTHOF(meas_mCm), "37 meters, 12.10 centimeters", "37 meters, 12 centimeters", "37 m, 12.1 cm", "37 m, 12.1 cm", "37m 12.1cm", "37m 12cm", "37m 12cm",
206 /* ranges_wide_2: */ {{UAMEASUNIT_LENGTH_METER,0,9},{UAMEASUNIT_LENGTH_METER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_LENGTH_CENTIMETER,11,28},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG,11,16}},
207 /* ranges_shrtr_1: */ {{UAMEASUNIT_LENGTH_METER,0,3},{UAMEASUNIT_LENGTH_METER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_LENGTH_CENTIMETER, 4,10},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG, 4, 8}},
208 /* ranges_numr_0: */ {{UAMEASUNIT_LENGTH_METER,0,3},{UAMEASUNIT_LENGTH_METER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_LENGTH_CENTIMETER, 4, 8},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG, 4, 6}} },
209 { meas_cm, UPRV_LENGTHOF(meas_cm), "12.10 centimeters", "12 centimeters", "12.1 cm", "12.1 cm", "12.1cm", "12cm", "12cm",
210 /* ranges_wide_2: */ {{UAMEASUNIT_LENGTH_CENTIMETER,0,17},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,5}},
211 /* ranges_shrtr_1: */ {{UAMEASUNIT_LENGTH_CENTIMETER,0, 6},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,4}},
212 /* ranges_numr_0: */ {{UAMEASUNIT_LENGTH_CENTIMETER,0, 4},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2}} },
213 { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL }
214};
215
216static const MultipleUnitFormat en_GB_multFmt[] = {
217// measures count wide_2 wide_0 shrt_X shrt_1 shrtr_1 narr_0 numr_0
218 { meas_hrMnSc, UPRV_LENGTHOF(meas_hrMnSc), "37 hours, 12 minutes, 5.32 seconds", "37 hours, 12 minutes, 5 seconds", "37 hrs, 12 min, 5.32 secs", "37 hrs, 12 min, 5.3 secs", "37hrs 12min 5.3secs", "37h 12m 5s", "13:12:05",
219 /* ranges_wide_2: */ {{UAMEASUNIT_DURATION_HOUR,0,8},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE,10,20},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG,10,12},{UAMEASUNIT_DURATION_SECOND,22,34},{UAMEASUNIT_DURATION_SECOND|UAMEASFMT_NUMERIC_FIELD_FLAG,22,26}},
220 /* ranges_shrtr_1: */ {{UAMEASUNIT_DURATION_HOUR,0,5},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE, 6,11},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG, 6, 8},{UAMEASUNIT_DURATION_SECOND,12,19},{UAMEASUNIT_DURATION_SECOND|UAMEASFMT_NUMERIC_FIELD_FLAG,12,15}},
221 /* ranges_numr_0: */ {{UAMEASUNIT_DURATION_HOUR,0,2},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE, 3, 5},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG, 3, 5},{UAMEASUNIT_DURATION_SECOND, 6, 8},{UAMEASUNIT_DURATION_SECOND|UAMEASFMT_NUMERIC_FIELD_FLAG, 6, 8}} },
222 { meas_hrMn, UPRV_LENGTHOF(meas_hrMn), "37 hours, 12.10 minutes", "37 hours, 12 minutes", "37 hrs, 12.1 min", "37 hrs, 12.1 min", "37hrs 12.1min", "37h 12m", "13:12",
223 /* ranges_wide_2: */ {{UAMEASUNIT_DURATION_HOUR,0,8},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE,10,23},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG,10,15}},
224 /* ranges_shrtr_1: */ {{UAMEASUNIT_DURATION_HOUR,0,5},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE, 6,13},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG, 6,10}},
225 /* ranges_numr_0: */ {{UAMEASUNIT_DURATION_HOUR,0,2},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_DURATION_MINUTE, 3, 5},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG, 3, 5}} },
226 { meas_mCm, UPRV_LENGTHOF(meas_mCm), "37 metres, 12.10 centimetres", "37 metres, 12 centimetres", "37 m, 12.1 cm", "37 m, 12.1 cm", "37m 12.1cm", "37m 12cm", "37m 12cm",
227 /* ranges_wide_2: */ {{UAMEASUNIT_LENGTH_METER,0,9},{UAMEASUNIT_LENGTH_METER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_LENGTH_CENTIMETER,11,28},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG,11,16}},
228 /* ranges_shrtr_1: */ {{UAMEASUNIT_LENGTH_METER,0,3},{UAMEASUNIT_LENGTH_METER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_LENGTH_CENTIMETER, 4,10},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG, 4, 8}},
229 /* ranges_numr_0: */ {{UAMEASUNIT_LENGTH_METER,0,3},{UAMEASUNIT_LENGTH_METER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2},{UAMEASUNIT_LENGTH_CENTIMETER, 4, 8},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG, 4, 6}} },
230 { meas_cm, UPRV_LENGTHOF(meas_cm), "12.10 centimetres", "12 centimetres", "12.1 cm", "12.1 cm", "12.1cm", "12cm", "12cm",
231 /* ranges_wide_2: */ {{UAMEASUNIT_LENGTH_CENTIMETER,0,17},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,5}},
232 /* ranges_shrtr_1: */ {{UAMEASUNIT_LENGTH_CENTIMETER,0, 6},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,4}},
233 /* ranges_numr_0: */ {{UAMEASUNIT_LENGTH_CENTIMETER,0, 4},{UAMEASUNIT_LENGTH_CENTIMETER|UAMEASFMT_NUMERIC_FIELD_FLAG,0,2}} },
234 { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL }
235};
236
237static const MultipleUnitFormat he_multFmt[] = {
238// measures count wide_2 wide_0
239 { meas_2hrMn, UPRV_LENGTHOF(meas_2hrMn), "\\u05E9\\u05E2\\u05EA\\u05D9\\u05D9\\u05DD \\u05D512.10 \\u05D3\\u05E7\\u05D5\\u05EA", "\\u05E9\\u05E2\\u05EA\\u05D9\\u05D9\\u05DD \\u05D512 \\u05D3\\u05E7\\u05D5\\u05EA",
240 /* shrt_X, shrt_1*/ "\\u05E9\\u05E2\\u05EA\\u05D9\\u05D9\\u05DD \\u05D512.1 \\u05D3\\u05E7\\u05F3", "\\u05E9\\u05E2\\u05EA\\u05D9\\u05D9\\u05DD \\u05D512.1 \\u05D3\\u05E7\\u05F3",
241 /* shrtr_1, narr_0, numr_0*/ "\\u05E9\\u05E2\\u05EA\\u05D9\\u05D9\\u05DD \\u05D512.1 \\u05D3\\u05E7\\u05F3", "\\u05E9\\u05E2\\u05EA\\u05D9\\u05D9\\u05DD \\u05D512 \\u05D3\\u05E7\\u05F3", "2:12",
242 /* ranges_wide_2: */ {{UAMEASUNIT_DURATION_HOUR,0,6},{UAMEASUNIT_DURATION_MINUTE,8,18},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG,8,13}},
243 /* ranges_shrtr_1: */ {{UAMEASUNIT_DURATION_HOUR,0,6},{UAMEASUNIT_DURATION_MINUTE,8,16},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG,8,12}},
244 /* ranges_numr_0: */ {{UAMEASUNIT_DURATION_HOUR,0,1},{UAMEASUNIT_DURATION_HOUR|UAMEASFMT_NUMERIC_FIELD_FLAG,0,1},{UAMEASUNIT_DURATION_MINUTE,2,4},{UAMEASUNIT_DURATION_MINUTE|UAMEASFMT_NUMERIC_FIELD_FLAG,2,4}} },
245};
246
247static const MultipleUnitFormat hi_multFmt[] = {
248// measures count wide_2 wide_0
249 { meas_moDys, UPRV_LENGTHOF(meas_moDys), "\\u0967 \\u092E\\u093E\\u0939 \\u0914\\u0930 \\u0968.\\u0966\\u0966 \\u0926\\u093F\\u0928", "\\u0967 \\u092E\\u093E\\u0939 \\u0914\\u0930 \\u0968 \\u0926\\u093F\\u0928",
250 /* shrt_X, shrt_1*/ "\\u0967 \\u092E\\u093E\\u0939, \\u0968 \\u0926\\u093F\\u0928", "\\u0967 \\u092E\\u093E\\u0939, \\u0968.\\u0966 \\u0926\\u093F\\u0928",
251 /* shrtr_1, narr_0, numr_0*/ "\\u0967 \\u092E\\u093E\\u0939, \\u0968.\\u0966 \\u0926\\u093F\\u0928", "\\u0967 \\u092E\\u093E\\u0939, \\u0968 \\u0926\\u093F\\u0928", "\\u0967 \\u092E\\u093E\\u0939, \\u0968 \\u0926\\u093F\\u0928",
252 /* ranges_wide_2: */ {{UAMEASUNIT_DURATION_MONTH,0,5},{UAMEASUNIT_DURATION_MONTH|UAMEASFMT_NUMERIC_FIELD_FLAG,0,1},{UAMEASUNIT_DURATION_DAY,9,17},{UAMEASUNIT_DURATION_DAY|UAMEASFMT_NUMERIC_FIELD_FLAG,9,13}},
253 /* ranges_shrtr_1: */ {{UAMEASUNIT_DURATION_MONTH,0,5},{UAMEASUNIT_DURATION_MONTH|UAMEASFMT_NUMERIC_FIELD_FLAG,0,1},{UAMEASUNIT_DURATION_DAY,7,14},{UAMEASUNIT_DURATION_DAY|UAMEASFMT_NUMERIC_FIELD_FLAG,7,10}},
254 /* ranges_numr_0: */ {{UAMEASUNIT_DURATION_MONTH,0,5},{UAMEASUNIT_DURATION_MONTH|UAMEASFMT_NUMERIC_FIELD_FLAG,0,1},{UAMEASUNIT_DURATION_DAY,7,12},{UAMEASUNIT_DURATION_DAY|UAMEASFMT_NUMERIC_FIELD_FLAG,7,8}} },
255};
256
257static const UAMeasureUnit unit_hrMnSc[] = { UAMEASUNIT_DURATION_HOUR, UAMEASUNIT_DURATION_MINUTE, UAMEASUNIT_DURATION_SECOND };
258static const UAMeasureUnit unit_hrMn[] = { UAMEASUNIT_DURATION_HOUR, UAMEASUNIT_DURATION_MINUTE };
259static const UAMeasureUnit unit_mCm[] = { UAMEASUNIT_LENGTH_METER, UAMEASUNIT_LENGTH_CENTIMETER };
260
261static const MultipleUnitName en_multNam[] = {
262// units count listStyle wide shrt narr
263 { unit_hrMnSc, UPRV_LENGTHOF(unit_hrMnSc), UAMEASNAME_LIST_STANDARD, "hours, minutes, and seconds", "hours, min, and secs", "hour, min, and sec" },
264 { unit_hrMnSc, UPRV_LENGTHOF(unit_hrMnSc), UAMEASNAME_LIST_MATCHUNITS, "hours, minutes, seconds", "hours, min, secs", "hour min sec" },
265 { unit_hrMn, UPRV_LENGTHOF(unit_hrMn), UAMEASNAME_LIST_STANDARD, "hours and minutes", "hours and min", "hour and min" },
266 { unit_hrMn, UPRV_LENGTHOF(unit_hrMn), UAMEASNAME_LIST_MATCHUNITS, "hours, minutes", "hours, min", "hour min" },
267 { unit_mCm, UPRV_LENGTHOF(unit_mCm), UAMEASNAME_LIST_STANDARD, "meters and centimeters", "meters and cm", "meter and cm" },
268 { unit_mCm, UPRV_LENGTHOF(unit_mCm), UAMEASNAME_LIST_MATCHUNITS, "meters, centimeters", "meters, cm", "meter cm" },
269 { NULL, 0, (UAMeasureNameListStyle)0, NULL, NULL, NULL }
270};
271
272static const MultipleUnitName en_GB_multNam[] = {
273// units count listStyle wide shrt narr
274 { unit_hrMnSc, UPRV_LENGTHOF(unit_hrMnSc), UAMEASNAME_LIST_STANDARD, "hours, minutes and seconds", "hours, min and secs", "hour, min and sec" },
275 { unit_hrMnSc, UPRV_LENGTHOF(unit_hrMnSc), UAMEASNAME_LIST_MATCHUNITS, "hours, minutes, seconds", "hours, min, secs", "hour min sec" },
276 { unit_hrMn, UPRV_LENGTHOF(unit_hrMn), UAMEASNAME_LIST_STANDARD, "hours and minutes", "hours and min", "hour and min" },
277 { unit_hrMn, UPRV_LENGTHOF(unit_hrMn), UAMEASNAME_LIST_MATCHUNITS, "hours, minutes", "hours, min", "hour min" },
278 { unit_mCm, UPRV_LENGTHOF(unit_mCm), UAMEASNAME_LIST_STANDARD, "metres and centimetres", "metres and cm", "m and cm" },
279 { unit_mCm, UPRV_LENGTHOF(unit_mCm), UAMEASNAME_LIST_MATCHUNITS, "metres, centimetres", "metres, cm", "m cm" },
280 { NULL, 0, (UAMeasureNameListStyle)0, NULL, NULL, NULL }
281};
282
283static const MultipleUnitName ja_multNam[] = {
284// units count listStyle wide shrt narr
285 { unit_hrMnSc, UPRV_LENGTHOF(unit_hrMnSc), UAMEASNAME_LIST_STANDARD, "\\u6642\\u9593\\u3001\\u5206\\u3001\\u79D2", "\\u6642\\u9593\\u3001\\u5206\\u3001\\u79D2", "\\u6642\\u9593\\u3001\\u5206\\u3001\\u79D2" },
286 { unit_hrMnSc, UPRV_LENGTHOF(unit_hrMnSc), UAMEASNAME_LIST_MATCHUNITS, "\\u6642\\u9593 \\u5206 \\u79D2", "\\u6642\\u9593 \\u5206 \\u79D2", "\\u6642\\u9593\\u5206\\u79D2" },
287 { unit_hrMn, UPRV_LENGTHOF(unit_hrMn), UAMEASNAME_LIST_STANDARD, "\\u6642\\u9593\\u3001\\u5206", "\\u6642\\u9593\\u3001\\u5206", "\\u6642\\u9593\\u3001\\u5206" },
288 { unit_hrMn, UPRV_LENGTHOF(unit_hrMn), UAMEASNAME_LIST_MATCHUNITS, "\\u6642\\u9593 \\u5206", "\\u6642\\u9593 \\u5206", "\\u6642\\u9593\\u5206" },
289 { unit_mCm, UPRV_LENGTHOF(unit_mCm), UAMEASNAME_LIST_STANDARD, "\\u30E1\\u30FC\\u30C8\\u30EB\\u3001\\u30BB\\u30F3\\u30C1\\u30E1\\u30FC\\u30C8\\u30EB", "m\\u3001cm", "m\\u3001cm" },
290 { unit_mCm, UPRV_LENGTHOF(unit_mCm), UAMEASNAME_LIST_MATCHUNITS, "\\u30E1\\u30FC\\u30C8\\u30EB \\u30BB\\u30F3\\u30C1\\u30E1\\u30FC\\u30C8\\u30EB", "m cm", "mcm" },
291 { NULL, 0, (UAMeasureNameListStyle)0, NULL, NULL, NULL }
292};
293
294static const LocaleWidthNumFmtItem lwnItems[] = {
295 // ============= TIER 0,1 and subocales
296 { "en", en_singFmt, en_singNam, en_multFmt, en_multNam }, // en: try plural cases for 1, other
297 { "en_GB", en_GB_singFmt, en_GB_singNam, en_GB_multFmt, en_GB_multNam },
298 { "en_AU", NULL, NULL, NULL, NULL },
299 { "de", NULL, NULL, NULL, NULL }, // de: try plural cases for 1, other
300 { "fr", fr_singFmt, NULL, NULL, NULL }, // fr: try plural cases for 1, other
301 { "fr_CA", fr_CA_singFmt, NULL, NULL, NULL },
302 { "ja", NULL, NULL, NULL, ja_multNam }, // ja: try plural cases for other only
303 { "zh_Hans", NULL, NULL, NULL, NULL }, // zh_Hans: try plural cases for other only
304
305 // ============= TIER 2,3 and sublocales
306 { "ar", NULL, NULL, NULL, NULL }, // ar: try plural cases for 0, 1, 2, 3, 11, 100
307 { "ca", NULL, NULL, NULL, NULL }, // ca: try plural cases for 1, other
308 { "cs", cs_singFmt, NULL, NULL, NULL }, // cs: try plural cases for 1, 2, 8.5, 5
309 { "da", NULL, NULL, NULL, NULL }, // da: try plural cases for 1, other
310 { "el", NULL, NULL, NULL, NULL }, // el: try plural cases for 1, other
311 { "es", NULL, NULL, NULL, NULL }, // es: try plural cases for 1, other
312 { "es_MX", NULL, NULL, NULL, NULL },
313 { "fi", NULL, NULL, NULL, NULL }, // fi: try plural cases for 1, other
314 { "he", NULL, NULL, he_multFmt, NULL }, // he: try plural cases for 1, 2, 20, 3
315 { "hi", NULL, NULL, hi_multFmt, NULL }, // hi: try plural cases for 1 (covers 0.0-1.0), other
316 { "hr", NULL, NULL, NULL, NULL }, // hr: try plural cases for 1, 2, 5
317 { "hu", NULL, NULL, NULL, NULL }, // hu: try plural cases for 1, other
318 { "id", NULL, NULL, NULL, NULL }, // id: try plural cases for other only
319 { "it", NULL, NULL, NULL, NULL }, // it: try plural cases for 1, other
320 { "ko", NULL, NULL, NULL, NULL }, // ko: try plural cases for other only
321 { "ms", NULL, NULL, NULL, NULL }, // ms: try plural cases for other only
322 { "nb", NULL, NULL, NULL, NULL }, // nb: try plural cases for 1, other
323 { "nl", NULL, NULL, NULL, NULL }, // nl: try plural cases for 1, other
324 { "pl", NULL, NULL, NULL, NULL }, // pl: try plural cases for 1, 2, 5, 8.5
325 { "pt", NULL, NULL, NULL, NULL }, // pt: try plural cases for 1, other
326 { "pt_PT", NULL, NULL, NULL, NULL },
327 { "ro", NULL, NULL, NULL, NULL }, // ro: try plural cases for 1, 2, 20
328 { "ru", NULL, NULL, NULL, NULL }, // ru: try plural cases for 1, 2, 5, 8.5
329 { "sk", NULL, NULL, NULL, NULL }, // sk: try plural cases for 1, 2, 8.5, 5
330 { "sv", NULL, NULL, NULL, NULL }, // sv: try plural cases for 1, other
331 { "th", NULL, NULL, NULL, NULL }, // th: try plural cases for other only
332 { "tr", NULL, NULL, NULL, NULL }, // tr: try plural cases for 1, other
333 { "uk", NULL, NULL, NULL, NULL }, // uk: try plural cases for 1, 2, 5, 8.5
334 { "vi", NULL, NULL, NULL, NULL }, // vi: try plural cases for other only
335 { "zh_Hant", NULL, NULL, NULL, NULL }, // zh_Hant: try plural cases for other only
336 { "zh_Hant_HK", NULL, NULL, NULL, NULL },
337
338 // =============TERMINATOR
339 { NULL, NULL, NULL, NULL, NULL }
340};
341
342enum { kUBufMax = 96, kBBufMax = 192 };
343
344
345static void TestUAMeasureFormat()
346{
347 const LocaleWidthNumFmtItem * itemPtr;
348 log_verbose("\nTesting uameasfmt functions\n");
349 for (itemPtr = lwnItems; itemPtr->locale != NULL; itemPtr++) {
350 UChar uget[kUBufMax];
351 UChar uexp[kUBufMax];
352 char bget[kBBufMax];
353 char bexp[kBBufMax];
354 int32_t ugetLen, uexpLen;
355 UErrorCode status = U_ZERO_ERROR;
356 UNumberFormat* numfmt_0;
357 UNumberFormat* numfmt_1;
358 UNumberFormat* numfmt_2;
359 UAMeasureFormat* measfmt_wide_2;
360 UAMeasureFormat* measfmt_wide_0;
361 UAMeasureFormat* measfmt_shrt_X;
362 UAMeasureFormat* measfmt_shrt_1;
363 UAMeasureFormat* measfmt_shrtr_1;
364 UAMeasureFormat* measfmt_narr_0;
365 UAMeasureFormat* measfmt_numr_0;
366
367 numfmt_0 = unum_open(UNUM_DECIMAL, NULL, 0, itemPtr->locale, NULL, &status);
368 if ( U_FAILURE(status) ) {
369 log_data_err("FAIL: unum_open(UNUM_DECIMAL,...) fails for locale %s: %s\n",
370 itemPtr->locale, u_errorName(status) );
371 continue;
372 }
373 numfmt_1 = unum_clone(numfmt_0, &status);
374 numfmt_2 = unum_clone(numfmt_0, &status);
375 if ( U_FAILURE(status) ) {
376 log_err("FAIL: unum_clone fails for locale %s: %s\n",
377 itemPtr->locale, u_errorName(status) );
378 unum_close(numfmt_0);
379 continue;
380 }
381 unum_setAttribute(numfmt_0, UNUM_MIN_FRACTION_DIGITS, 0);
382 unum_setAttribute(numfmt_0, UNUM_MAX_FRACTION_DIGITS, 0);
383 unum_setAttribute(numfmt_0, UNUM_ROUNDING_MODE, UNUM_ROUND_DOWN);
384 unum_setAttribute(numfmt_1, UNUM_MIN_FRACTION_DIGITS, 1);
385 unum_setAttribute(numfmt_1, UNUM_MAX_FRACTION_DIGITS, 1);
386 unum_setAttribute(numfmt_1, UNUM_ROUNDING_MODE, UNUM_ROUND_DOWN);
387 unum_setAttribute(numfmt_2, UNUM_MIN_FRACTION_DIGITS, 2);
388 unum_setAttribute(numfmt_2, UNUM_MAX_FRACTION_DIGITS, 2);
389 unum_setAttribute(numfmt_2, UNUM_ROUNDING_MODE, UNUM_ROUND_DOWN);
390
391 measfmt_wide_2 = uameasfmt_open(itemPtr->locale, UAMEASFMT_WIDTH_WIDE, unum_clone(numfmt_2, &status), &status); // wide, num fmt with 2 decimals
392 measfmt_wide_0 = uameasfmt_open(itemPtr->locale, UAMEASFMT_WIDTH_WIDE, unum_clone(numfmt_0, &status), &status); // wide, num fmt with 0 decimals
393 measfmt_shrt_X = uameasfmt_open(itemPtr->locale, UAMEASFMT_WIDTH_SHORT, NULL, &status); // short, default num fmt
394 measfmt_shrt_1 = uameasfmt_open(itemPtr->locale, UAMEASFMT_WIDTH_SHORT, unum_clone(numfmt_1, &status), &status); // short, num fmt with 1 decimal
395 measfmt_shrtr_1 = uameasfmt_open(itemPtr->locale, UAMEASFMT_WIDTH_SHORTER, unum_clone(numfmt_1, &status), &status); // shorter, num fmt with 1 decimal
396 measfmt_narr_0 = uameasfmt_open(itemPtr->locale, UAMEASFMT_WIDTH_NARROW, unum_clone(numfmt_0, &status), &status); // narrow, num fmt with 0 decimal
397 measfmt_numr_0 = uameasfmt_open(itemPtr->locale, UAMEASFMT_WIDTH_NUMERIC, unum_clone(numfmt_0, &status), &status); // numeric, num fmt with 0 decimal
398
399 if ( U_FAILURE(status) ) {
400 log_data_err("FAIL: uameasfmt_open fails for locale %s, various widths and number formatters: %s\n",
401 itemPtr->locale, u_errorName(status) );
402 unum_close(numfmt_0);
403 unum_close(numfmt_1);
404 unum_close(numfmt_2);
405 continue;
406 }
407
408 if (itemPtr->singleUnitFormatTests != NULL) {
409 const SingleUnitFormat * singFmtPtr;
410 for (singFmtPtr = itemPtr->singleUnitFormatTests; singFmtPtr->expectFmt_wide_2 != 0; singFmtPtr++) {
411 UFieldPosition fpos = { UNUM_INTEGER_FIELD, 0, 0 };
412 // wide_2
413 status = U_ZERO_ERROR;
414 ugetLen = uameasfmt_formatGetPosition(measfmt_wide_2, singFmtPtr->value, singFmtPtr->unit, uget, kUBufMax, NULL, &status);
415 if ( U_FAILURE(status) ) {
416 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format wide_2 for unit %d:%d, status %s\n",
417 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF, u_errorName(status));
418 } else {
419 uexpLen = u_unescape(singFmtPtr->expectFmt_wide_2, uexp, kUBufMax);
420 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
421 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
422 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
423 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format wide_2 for unit %d:%d, expected \"%s\", got \"%s\"\n",
424 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF, bexp, bget);
425 }
426 }
427 // wide_0
428 status = U_ZERO_ERROR;
429 fpos.beginIndex = -1;
430 fpos.endIndex = -1;
431 ugetLen = uameasfmt_formatGetPosition(measfmt_wide_0, singFmtPtr->value, singFmtPtr->unit, uget, kUBufMax, &fpos, &status);
432 if ( U_FAILURE(status) ) {
433 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format wide_0 for unit %d:%d, status %s\n",
434 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF, u_errorName(status));
435 } else {
436 uexpLen = u_unescape(singFmtPtr->expectFmt_wide_0, uexp, kUBufMax);
437 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 || fpos.beginIndex != singFmtPtr->beginInt_wide_0 || fpos.endIndex != singFmtPtr->endInt_wide_0) {
438 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
439 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
440 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format wide_0 for unit %d:%d,\n expect \"%s\" int pos [%d:%d],\n get \"%s\" int pos [%d:%d]\n",
441 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF,
442 bexp, singFmtPtr->beginInt_wide_0, singFmtPtr->endInt_wide_0,
443 bget, fpos.beginIndex, fpos.endIndex);
444 }
445 }
446 // shrt_X
447 status = U_ZERO_ERROR;
448 ugetLen = uameasfmt_formatGetPosition(measfmt_shrt_X, singFmtPtr->value, singFmtPtr->unit, uget, kUBufMax, NULL, &status);
449 if ( U_FAILURE(status) ) {
450 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format shrt_X for unit %d:%d, status %s\n",
451 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF, u_errorName(status));
452 } else {
453 uexpLen = u_unescape(singFmtPtr->expectFmt_shrt_X, uexp, kUBufMax);
454 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
455 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
456 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
457 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format shrt_X for unit %d:%d, expected \"%s\", got \"%s\"\n",
458 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF, bexp, bget);
459 }
460 }
461 // shrt_1
462 status = U_ZERO_ERROR;
463 ugetLen = uameasfmt_formatGetPosition(measfmt_shrt_1, singFmtPtr->value, singFmtPtr->unit, uget, kUBufMax, NULL, &status);
464 if ( U_FAILURE(status) ) {
465 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format shrt_1 for unit %d:%d, status %s\n",
466 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF, u_errorName(status));
467 } else {
468 uexpLen = u_unescape(singFmtPtr->expectFmt_shrt_1, uexp, kUBufMax);
469 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
470 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
471 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
472 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format shrt_1 for unit %d:%d, expected \"%s\", got \"%s\"\n",
473 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF, bexp, bget);
474 }
475 }
476 // narr_0
477 status = U_ZERO_ERROR;
478 ugetLen = uameasfmt_formatGetPosition(measfmt_narr_0, singFmtPtr->value, singFmtPtr->unit, uget, kUBufMax, NULL, &status);
479 if ( U_FAILURE(status) ) {
480 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format narr_0 for unit %d:%d, status %s\n",
481 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF, u_errorName(status));
482 } else {
483 uexpLen = u_unescape(singFmtPtr->expectFmt_narr_0, uexp, kUBufMax);
484 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
485 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
486 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
487 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format narr_0 for unit %d:%d, expected \"%s\", got \"%s\"\n",
488 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF, bexp, bget);
489 }
490 }
491 // numr_0
492 status = U_ZERO_ERROR;
493 fpos.beginIndex = -1;
494 fpos.endIndex = -1;
495 ugetLen = uameasfmt_formatGetPosition(measfmt_numr_0, singFmtPtr->value, singFmtPtr->unit, uget, kUBufMax, &fpos, &status);
496 if ( U_FAILURE(status) ) {
497 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format numr_0 for unit %d:%d, status %s\n",
498 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF, u_errorName(status));
499 } else {
500 uexpLen = u_unescape(singFmtPtr->expectFmt_numr_0, uexp, kUBufMax);
501 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 || fpos.beginIndex != singFmtPtr->beginInt_numr_0 || fpos.endIndex != singFmtPtr->endInt_numr_0) {
502 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
503 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
504 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format numr_0 for unit %d:%d,\n expect \"%s\" int pos [%d:%d],\n get \"%s\" int pos [%d:%d]\n",
505 itemPtr->locale, ((int)singFmtPtr->unit) >> 8, ((int)singFmtPtr->unit) & 0xFF,
506 bexp, singFmtPtr->beginInt_numr_0, singFmtPtr->endInt_numr_0,
507 bget, fpos.beginIndex, fpos.endIndex);
508 }
509 }
510 }
511 }
512
513 if (itemPtr->singleUnitNameTests != NULL) {
514 const SingleUnitName * singNamPtr;
515 for (singNamPtr = itemPtr->singleUnitNameTests; singNamPtr->expectName_wide != 0; singNamPtr++) {
516 // wide
517 status = U_ZERO_ERROR;
518 ugetLen = uameasfmt_getUnitName(measfmt_wide_2, singNamPtr->unit, uget, kUBufMax, &status);
519 if ( U_FAILURE(status) ) {
520 log_err("FAIL: uameasfmt_getUnitName locale %s, single name wide for unit %d:%d, status %s\n",
521 itemPtr->locale, ((int)singNamPtr->unit) >> 8, ((int)singNamPtr->unit) & 0xFF, u_errorName(status));
522 } else {
523 uexpLen = u_unescape(singNamPtr->expectName_wide, uexp, kUBufMax);
524 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
525 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
526 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
527 log_err("FAIL: uameasfmt_getUnitName locale %s, single name wide for unit %d:%d, expected \"%s\", got \"%s\"\n",
528 itemPtr->locale, ((int)singNamPtr->unit) >> 8, ((int)singNamPtr->unit) & 0xFF, bexp, bget);
529 }
530 }
531 // shrt
532 status = U_ZERO_ERROR;
533 ugetLen = uameasfmt_getUnitName(measfmt_shrt_X, singNamPtr->unit, uget, kUBufMax, &status);
534 if ( U_FAILURE(status) ) {
535 log_err("FAIL: uameasfmt_getUnitName locale %s, single name shrt for unit %d:%d, status %s\n",
536 itemPtr->locale, ((int)singNamPtr->unit) >> 8, ((int)singNamPtr->unit) & 0xFF, u_errorName(status));
537 } else {
538 uexpLen = u_unescape(singNamPtr->expectName_shrt, uexp, kUBufMax);
539 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
540 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
541 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
542 log_err("FAIL: uameasfmt_getUnitName locale %s, single name shrt for unit %d:%d, expected \"%s\", got \"%s\"\n",
543 itemPtr->locale, ((int)singNamPtr->unit) >> 8, ((int)singNamPtr->unit) & 0xFF, bexp, bget);
544 }
545 }
546 // narr
547 status = U_ZERO_ERROR;
548 ugetLen = uameasfmt_getUnitName(measfmt_narr_0, singNamPtr->unit, uget, kUBufMax, &status);
549 if ( U_FAILURE(status) ) {
550 log_err("FAIL: uameasfmt_getUnitName locale %s, single name narr for unit %d:%d, status %s\n",
551 itemPtr->locale, ((int)singNamPtr->unit) >> 8, ((int)singNamPtr->unit) & 0xFF, u_errorName(status));
552 } else {
553 uexpLen = u_unescape(singNamPtr->expectName_narr, uexp, kUBufMax);
554 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
555 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
556 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
557 log_err("FAIL: uameasfmt_getUnitName locale %s, single name narr for unit %d:%d, expected \"%s\", got \"%s\"\n",
558 itemPtr->locale, ((int)singNamPtr->unit) >> 8, ((int)singNamPtr->unit) & 0xFF, bexp, bget);
559 }
560 }
561 }
562 }
563
564 if (itemPtr->multipleUnitFormatTests != NULL) {
565 status = U_ZERO_ERROR;
566 UFieldPositionIterator* fpositer = ufieldpositer_open(&status);
567 if ( U_FAILURE(status) ) {
568 log_err("FAIL: ufieldpositer_open, status %s\n", u_errorName(status));
569 } else {
570 const MultipleUnitFormat * multFmtPtr;
571 for (multFmtPtr = itemPtr->multipleUnitFormatTests; multFmtPtr->measures != 0; multFmtPtr++) {
572 // wide_2
573 status = U_ZERO_ERROR;
574 ugetLen = uameasfmt_formatMultipleForFields(measfmt_wide_2, multFmtPtr->measures, multFmtPtr->measureCount, uget, kUBufMax, fpositer, &status);
575 if ( U_FAILURE(status) ) {
576 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format wide_2 for measureCount %d, status %s\n",
577 itemPtr->locale, multFmtPtr->measureCount, u_errorName(status));
578 } else {
579 uexpLen = u_unescape(multFmtPtr->expectFmt_wide_2, uexp, kUBufMax);
580 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
581 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
582 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
583 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format wide_2 for measureCount %d, expected \"%s\", got \"%s\"\n",
584 itemPtr->locale, multFmtPtr->measureCount, bexp, bget);
585 } else {
586 // check fpositer
587 int32_t field, beginIndex, endIndex, count;
588 for (count = 0; (field = ufieldpositer_next(fpositer, &beginIndex, &endIndex)) >= 0; count++) {
589 if (field != multFmtPtr->ranges_wide_2[count][0] || beginIndex != multFmtPtr->ranges_wide_2[count][1] || endIndex != multFmtPtr->ranges_wide_2[count][2]) {
590 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format wide_2 for measureCount %d,\n expect field %0X range %d..%d,\n get field %0X range %d..%d\n",
591 itemPtr->locale, multFmtPtr->measureCount,
592 multFmtPtr->ranges_wide_2[count][0], multFmtPtr->ranges_wide_2[count][1], multFmtPtr->ranges_wide_2[count][2],
593 field, beginIndex, endIndex);
594 break;
595 }
596 }
597 }
598 }
599 // wide_0
600 status = U_ZERO_ERROR;
601 ugetLen = uameasfmt_formatMultipleForFields(measfmt_wide_0, multFmtPtr->measures, multFmtPtr->measureCount, uget, kUBufMax, NULL, &status);
602 if ( U_FAILURE(status) ) {
603 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format wide_0 for measureCount %d, status %s\n",
604 itemPtr->locale, multFmtPtr->measureCount, u_errorName(status));
605 } else {
606 uexpLen = u_unescape(multFmtPtr->expectFmt_wide_0, uexp, kUBufMax);
607 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
608 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
609 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
610 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format wide_0 for measureCount %d, expected \"%s\", got \"%s\"\n",
611 itemPtr->locale, multFmtPtr->measureCount, bexp, bget);
612 }
613 }
614 // shrt_X
615 status = U_ZERO_ERROR;
616 ugetLen = uameasfmt_formatMultipleForFields(measfmt_shrt_X, multFmtPtr->measures, multFmtPtr->measureCount, uget, kUBufMax, NULL, &status);
617 if ( U_FAILURE(status) ) {
618 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrt_X for measureCount %d, status %s\n",
619 itemPtr->locale, multFmtPtr->measureCount, u_errorName(status));
620 } else {
621 uexpLen = u_unescape(multFmtPtr->expectFmt_shrt_X, uexp, kUBufMax);
622 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
623 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
624 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
625 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrt_X for measureCount %d, expected \"%s\", got \"%s\"\n",
626 itemPtr->locale, multFmtPtr->measureCount, bexp, bget);
627 }
628 }
629 // shrt_1
630 status = U_ZERO_ERROR;
631 ugetLen = uameasfmt_formatMultipleForFields(measfmt_shrt_1, multFmtPtr->measures, multFmtPtr->measureCount, uget, kUBufMax, NULL, &status);
632 if ( U_FAILURE(status) ) {
633 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrt_1 for measureCount %d, status %s\n",
634 itemPtr->locale, multFmtPtr->measureCount, u_errorName(status));
635 } else {
636 uexpLen = u_unescape(multFmtPtr->expectFmt_shrt_1, uexp, kUBufMax);
637 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
638 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
639 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
640 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrt_1 for measureCount %d, expected \"%s\", got \"%s\"\n",
641 itemPtr->locale, multFmtPtr->measureCount, bexp, bget);
642 }
643 }
644 // shrtr_1
645 status = U_ZERO_ERROR;
646 ugetLen = uameasfmt_formatMultipleForFields(measfmt_shrtr_1, multFmtPtr->measures, multFmtPtr->measureCount, uget, kUBufMax, fpositer, &status);
647 if ( U_FAILURE(status) ) {
648 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrtr_1 for measureCount %d, status %s\n",
649 itemPtr->locale, multFmtPtr->measureCount, u_errorName(status));
650 } else {
651 uexpLen = u_unescape(multFmtPtr->expectFmt_shrtr_1, uexp, kUBufMax);
652 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
653 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
654 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
655 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrtr_1 for measureCount %d, expected \"%s\", got \"%s\"\n",
656 itemPtr->locale, multFmtPtr->measureCount, bexp, bget);
657 } else {
658 // check fpositer
659 int32_t field, beginIndex, endIndex, count;
660 for (count = 0; (field = ufieldpositer_next(fpositer, &beginIndex, &endIndex)) >= 0; count++) {
661 if (field != multFmtPtr->ranges_shrtr_1[count][0] || beginIndex != multFmtPtr->ranges_shrtr_1[count][1] || endIndex != multFmtPtr->ranges_shrtr_1[count][2]) {
662 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrtr_1 for measureCount %d,\n expect field %0X range %d..%d,\n get field %0X range %d..%d\n",
663 itemPtr->locale, multFmtPtr->measureCount,
664 multFmtPtr->ranges_shrtr_1[count][0], multFmtPtr->ranges_shrtr_1[count][1], multFmtPtr->ranges_shrtr_1[count][2],
665 field, beginIndex, endIndex);
666 break;
667 }
668 }
669 }
670 }
671 // narr_0
672 status = U_ZERO_ERROR;
673 ugetLen = uameasfmt_formatMultipleForFields(measfmt_narr_0, multFmtPtr->measures, multFmtPtr->measureCount, uget, kUBufMax, NULL, &status);
674 if ( U_FAILURE(status) ) {
675 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format narr_0 for measureCount %d, status %s\n",
676 itemPtr->locale, multFmtPtr->measureCount, u_errorName(status));
677 } else {
678 uexpLen = u_unescape(multFmtPtr->expectFmt_narr_0, uexp, kUBufMax);
679 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
680 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
681 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
682 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format narr_0 for measureCount %d, expected \"%s\", got \"%s\"\n",
683 itemPtr->locale, multFmtPtr->measureCount, bexp, bget);
684 }
685 }
686 // numr_0
687 status = U_ZERO_ERROR;
688 ugetLen = uameasfmt_formatMultipleForFields(measfmt_numr_0, multFmtPtr->measures, multFmtPtr->measureCount, uget, kUBufMax, fpositer, &status);
689 if ( U_FAILURE(status) ) {
690 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format numr_0 for measureCount %d, status %s\n",
691 itemPtr->locale, multFmtPtr->measureCount, u_errorName(status));
692 } else {
693 uexpLen = u_unescape(multFmtPtr->expectFmt_numr_0, uexp, kUBufMax);
694 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
695 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
696 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
697 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format numr_0 for measureCount %d, expected \"%s\", got \"%s\"\n",
698 itemPtr->locale, multFmtPtr->measureCount, bexp, bget);
699 } else {
700 // check fpositer
701 int32_t field, beginIndex, endIndex, count;
702 for (count = 0; (field = ufieldpositer_next(fpositer, &beginIndex, &endIndex)) >= 0; count++) {
703 if (field != multFmtPtr->ranges_numr_0[count][0] || beginIndex != multFmtPtr->ranges_numr_0[count][1] || endIndex != multFmtPtr->ranges_numr_0[count][2]) {
704 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format numr_0 for measureCount %d,\n expect field %0X range %d..%d,\n get field %0X range %d..%d\n",
705 itemPtr->locale, multFmtPtr->measureCount,
706 multFmtPtr->ranges_numr_0[count][0], multFmtPtr->ranges_numr_0[count][1], multFmtPtr->ranges_numr_0[count][2],
707 field, beginIndex, endIndex);
708 break;
709 }
710 }
711 }
712 }
713 }
714 ufieldpositer_close(fpositer);
715 }
716 }
717
718 if (itemPtr->multipleUnitNameTests != NULL) {
719 const MultipleUnitName * multNamPtr;
720 for (multNamPtr = itemPtr->multipleUnitNameTests; multNamPtr->units != 0; multNamPtr++) {
721 // wide
722 status = U_ZERO_ERROR;
723 ugetLen = uameasfmt_getMultipleUnitNames(measfmt_wide_2, multNamPtr->units, multNamPtr->unitCount, multNamPtr->listStyle, uget, kUBufMax, &status);
724 if ( U_FAILURE(status) ) {
725 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name wide for unitCount %d, listStyle %d, status %s\n",
726 itemPtr->locale, multNamPtr->unitCount, multNamPtr->listStyle, u_errorName(status));
727 } else {
728 uexpLen = u_unescape(multNamPtr->expectName_wide, uexp, kUBufMax);
729 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
730 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
731 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
732 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name wide for unitCount %d, listStyle %d, expected \"%s\", got \"%s\"\n",
733 itemPtr->locale, multNamPtr->unitCount, multNamPtr->listStyle, bexp, bget);
734 }
735 }
736 // shrt
737 status = U_ZERO_ERROR;
738 ugetLen = uameasfmt_getMultipleUnitNames(measfmt_shrt_X, multNamPtr->units, multNamPtr->unitCount, multNamPtr->listStyle, uget, kUBufMax, &status);
739 if ( U_FAILURE(status) ) {
740 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name shrt for unitCount %d, listStyle %d, status %s\n",
741 itemPtr->locale, multNamPtr->unitCount, multNamPtr->listStyle, u_errorName(status));
742 } else {
743 uexpLen = u_unescape(multNamPtr->expectName_shrt, uexp, kUBufMax);
744 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
745 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
746 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
747 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name shrt for unitCount %d, listStyle %d, expected \"%s\", got \"%s\"\n",
748 itemPtr->locale, multNamPtr->unitCount, multNamPtr->listStyle, bexp, bget);
749 }
750 }
751 // narr
752 status = U_ZERO_ERROR;
753 ugetLen = uameasfmt_getMultipleUnitNames(measfmt_narr_0, multNamPtr->units, multNamPtr->unitCount, multNamPtr->listStyle, uget, kUBufMax, &status);
754 if ( U_FAILURE(status) ) {
755 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name narr for unitCount %d, listStyle %d, status %s\n",
756 itemPtr->locale, multNamPtr->unitCount, multNamPtr->listStyle, u_errorName(status));
757 } else {
758 uexpLen = u_unescape(multNamPtr->expectName_narr, uexp, kUBufMax);
759 if (ugetLen != uexpLen || u_strcmp(uget, uexp) != 0 ) {
760 u_strToUTF8(bexp, kBBufMax, NULL, uexp, uexpLen, &status);
761 u_strToUTF8(bget, kBBufMax, NULL, uget, ugetLen, &status);
762 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name narr for unitCount %d, listStyle %d, expected \"%s\", got \"%s\"\n",
763 itemPtr->locale, multNamPtr->unitCount, multNamPtr->listStyle, bexp, bget);
764 }
765 }
766 }
767 }
768
769 uameasfmt_close(measfmt_wide_2);
770 uameasfmt_close(measfmt_wide_0);
771 uameasfmt_close(measfmt_shrt_X);
772 uameasfmt_close(measfmt_shrt_1);
773 uameasfmt_close(measfmt_shrtr_1);
774 uameasfmt_close(measfmt_narr_0);
775 uameasfmt_close(measfmt_numr_0);
776
777 unum_close(numfmt_0);
778 unum_close(numfmt_1);
779 unum_close(numfmt_2);
780 }
781 /* sleep to check leaks etc */
782 sleep(8);
783}
784
a62d09fc
A
785static void TestUAMeasFmtOpenAllLocs()
786{
787 int32_t iLoc, nLoc = uloc_countAvailable();
788 for (iLoc = 0; iLoc <= nLoc; iLoc++) {
789 const char *loc = (iLoc < nLoc)? uloc_getAvailable(iLoc): "xyz" /* something bogus */;
790 if (loc != NULL) {
791 UAMeasureFormat* measfmt;
792 UErrorCode status;
793
794 status = U_ZERO_ERROR;
795 measfmt = uameasfmt_open(loc, UAMEASFMT_WIDTH_WIDE, NULL, &status);
796 if ( U_SUCCESS(status) ) {
797 uameasfmt_close(measfmt);
798 } else {
799 log_data_err("FAIL: uameasfmt_open fails for locale %-10s, width WIDE : %s\n", loc, u_errorName(status) );
800 }
801
802 status = U_ZERO_ERROR;
803 measfmt = uameasfmt_open(loc, UAMEASFMT_WIDTH_SHORT, NULL, &status);
804 if ( U_SUCCESS(status) ) {
805 uameasfmt_close(measfmt);
806 } else {
807 log_data_err("FAIL: uameasfmt_open fails for locale %-10s, width SHORT : %s\n", loc, u_errorName(status) );
808 }
809
810 status = U_ZERO_ERROR;
811 measfmt = uameasfmt_open(loc, UAMEASFMT_WIDTH_NARROW, NULL, &status);
812 if ( U_SUCCESS(status) ) {
813 uameasfmt_close(measfmt);
814 } else {
815 log_data_err("FAIL: uameasfmt_open fails for locale %-10s, width NARROW : %s\n", loc, u_errorName(status) );
816 }
817
818
819 status = U_ZERO_ERROR;
820 measfmt = uameasfmt_open(loc, UAMEASFMT_WIDTH_NUMERIC, NULL, &status);
821 if ( U_SUCCESS(status) ) {
822 uameasfmt_close(measfmt);
823 } else {
824 log_data_err("FAIL: uameasfmt_open fails for locale %-10s, width NUMERIC: %s\n", loc, u_errorName(status) );
825 }
826 }
827 }
828}
829
2ca993e8
A
830enum { kMeasureUnitMax = 3 };
831
832typedef struct {
833 const char* locale;
834 const char* category;
835 const char* usage;
836 int32_t unitCount;
837 UAMeasureUnit units[kMeasureUnitMax];
838} UnitsForUsageItem;
839
840static const UnitsForUsageItem unitsForUsageItems[] = {
841 { "en_US", "length", "person", 1, { UAMEASUNIT_LENGTH_INCH } },
842 { "en_US", "length", "person-informal", 2, { UAMEASUNIT_LENGTH_FOOT, UAMEASUNIT_LENGTH_INCH } },
843 { "en_US", "length", "person-small", 1, { UAMEASUNIT_LENGTH_INCH } },
844 { "fr_FR", "length", "person", 2, { UAMEASUNIT_LENGTH_METER, UAMEASUNIT_LENGTH_CENTIMETER } },
845 { "fr_FR", "length", "person-informal", 2, { UAMEASUNIT_LENGTH_METER, UAMEASUNIT_LENGTH_CENTIMETER } },
846 { "fr_FR", "length", "person-small", 1, { UAMEASUNIT_LENGTH_CENTIMETER } },
847 { "fr_FR@rg=USZZZZ", "length", "person", 1, { UAMEASUNIT_LENGTH_INCH } },
848 { "fr_FR@rg=USZZZZ", "length", "person-informal", 2, { UAMEASUNIT_LENGTH_FOOT, UAMEASUNIT_LENGTH_INCH } },
849 { "fr_FR@rg=USZZZZ", "length", "person-small", 1, { UAMEASUNIT_LENGTH_INCH } },
850 { "en_IN", "pressure","baromtrc", 1, { UAMEASUNIT_PRESSURE_INCH_HG } },
851 { "es_MX", "pressure","baromtrc", 1, { UAMEASUNIT_PRESSURE_MILLIMETER_OF_MERCURY } },
852 { "fr_FR", "pressure","baromtrc", 1, { UAMEASUNIT_PRESSURE_HECTOPASCAL } },
853 { "pt"/*BR*/, "pressure","baromtrc", 1, { UAMEASUNIT_PRESSURE_MILLIBAR } },
854 { "en_US", "length", NULL, 1, { UAMEASUNIT_LENGTH_FOOT } },
855 { "en_US", "length", "large", 1, { UAMEASUNIT_LENGTH_MILE } },
856 { "en_US", "length", "small", 1, { UAMEASUNIT_LENGTH_INCH } },
857 { "fr_FR", "length", NULL, 1, { UAMEASUNIT_LENGTH_METER } },
858 { "fr_FR", "length", "large", 1, { UAMEASUNIT_LENGTH_KILOMETER } },
859 { "fr_FR", "length", "small", 1, { UAMEASUNIT_LENGTH_CENTIMETER } },
860 { "en_US", "xxxxxxxx","yyyyyyyy", 0, { (UAMeasureUnit)0 } },
861{ NULL, NULL, NULL, 0, { (UAMeasureUnit)0 } }
862};
863
864static void TestUAGetUnitsForUsage()
865{
866 const UnitsForUsageItem* itemPtr = unitsForUsageItems;
867 for (; itemPtr->locale != NULL; itemPtr++) {
868 UAMeasureUnit units[kMeasureUnitMax];
869 UErrorCode status = U_ZERO_ERROR;
870 int32_t unitsCount = uameasfmt_getUnitsForUsage(itemPtr->locale, itemPtr->category, itemPtr->usage,
871 units, kMeasureUnitMax, &status);
872 if ( U_FAILURE(status) ) {
873 if (itemPtr->unitCount != 0) {
874 log_err("FAIL: uameasfmt_getUnitsForUsage locale %s, category %s-%s, status %s\n",
875 itemPtr->locale, itemPtr->category, itemPtr->usage, u_errorName(status));
876 }
877 } else if (itemPtr->unitCount == 0) {
878 log_err("FAIL: uameasfmt_getUnitsForUsage locale %s, category %s-%s, expected failure, got status %s\n",
879 itemPtr->locale, itemPtr->category, itemPtr->usage, u_errorName(status));
880 } else if (unitsCount != itemPtr->unitCount) {
881 log_err("FAIL: uameasfmt_getUnitsForUsage locale %s, category %s-%s, expected count %d, got %d\n",
882 itemPtr->locale, itemPtr->category, itemPtr->usage, itemPtr->unitCount, unitsCount);
883 } else if (units[0] != itemPtr->units[0] || (unitsCount == 2 && units[1] != itemPtr->units[1])) {
884 log_err("FAIL: uameasfmt_getUnitsForUsage locale %s, category %s-%s, expected units x%04X ..., got x%04X ...\n",
885 itemPtr->locale, itemPtr->category, itemPtr->usage, itemPtr->units[0], units[0]);
886 }
887 }
888}
889
890typedef struct {
891 UAMeasureUnit unit;
892 const char* category;
893} CategoryForUnit;
894
895static const CategoryForUnit categoryForUnitItems[] = {
896 { UAMEASUNIT_VOLUME_LITER, "volume" },
897 { UAMEASUNIT_LENGTH_METER, "length" },
898 { UAMEASUNIT_PRESSURE_HECTOPASCAL, "pressure" },
899 { UAMEASUNIT_CONCENTRATION_MILLIMOLE_PER_LITER, "concentr" },
900 { (UAMeasureUnit)0, NULL }
901};
902
903static void TestUAGetCategoryForUnit()
904{
905 const CategoryForUnit* itemPtr = categoryForUnitItems;
906 for (; itemPtr->category != NULL; itemPtr++) {
907 UErrorCode status = U_ZERO_ERROR;
908 const char *category = uameasfmt_getUnitCategory(itemPtr->unit, &status);
909 if ( U_FAILURE(status) ) {
910 log_err("FAIL: uameasfmt_getUnitCategory unit %d:%d, got status %s\n",
911 ((int)itemPtr->unit) >> 8, ((int)itemPtr->unit) & 0xFF, u_errorName(status));
912 } else if (category == NULL) {
913 log_err("FAIL: uameasfmt_getUnitCategory unit %d:%d, got NULL return\n",
914 ((int)itemPtr->unit) >> 8, ((int)itemPtr->unit) & 0xFF);
915 } else if (uprv_strcmp(category, itemPtr->category) != 0) {
916 log_err("FAIL: uameasfmt_getUnitCategory unit %d:%d, expected %s, got %s\n",
917 ((int)itemPtr->unit) >> 8, ((int)itemPtr->unit) & 0xFF, itemPtr->category, category);
918 }
919 }
920}
921
922#endif /* #if !UCONFIG_NO_FORMATTING */