1 /********************************************************************
2 * Copyright (c) 2015-2016, Apple Inc. All Rights Reserved.
3 ********************************************************************/
4 /* C API TEST FOR APPLE MEASUREFORMAT C WRAPPER */
6 #include "unicode/utypes.h"
8 #if U_PLATFORM_IS_DARWIN_BASED || U_PLATFORM_IS_LINUX_BASED || U_PLATFORM == U_PF_BSD || U_PLATFORM == U_PF_SOLARIS
12 #if !UCONFIG_NO_FORMATTING
14 #include "unicode/uameasureformat.h"
15 #include "unicode/ustring.h"
16 #include "unicode/uloc.h"
21 static void TestUAMeasureFormat(void);
22 static void TestUAMeasFmtOpenAllLocs(void);
23 static void TestUAGetUnitsForUsage(void);
24 static void TestUAGetCategoryForUnit(void);
26 void addMeasureFormatTest(TestNode
** root
);
28 #define TESTCASE(x) addTest(root, &x, "tsformat/cmeasureformattest/" #x)
30 void addMeasureFormatTest(TestNode
** root
)
32 TESTCASE(TestUAMeasureFormat
);
33 TESTCASE(TestUAMeasFmtOpenAllLocs
);
34 TESTCASE(TestUAGetUnitsForUsage
);
35 TESTCASE(TestUAGetCategoryForUnit
);
41 const char * expectFmt_wide_2
;
42 const char * expectFmt_wide_0
;
43 const char * expectFmt_shrt_X
;
44 const char * expectFmt_shrt_1
;
45 const char * expectFmt_narr_0
;
46 const char * expectFmt_numr_0
;
47 int32_t beginInt_wide_0
;
48 int32_t endInt_wide_0
;
49 int32_t beginInt_numr_0
;
50 int32_t endInt_numr_0
;
55 const char * expectName_wide
;
56 const char * expectName_shrt
;
57 const char * expectName_narr
;
61 const UAMeasure
* measures
;
63 const char * expectFmt_wide_2
;
64 const char * expectFmt_wide_0
;
65 const char * expectFmt_shrt_X
;
66 const char * expectFmt_shrt_1
;
67 const char * expectFmt_shrtr_1
;
68 const char * expectFmt_narr_0
;
69 const char * expectFmt_numr_0
;
70 int32_t ranges_wide_2
[8][3];
71 int32_t ranges_shrtr_1
[8][3];
72 int32_t ranges_numr_0
[8][3];
76 const UAMeasureUnit
* units
;
78 UAMeasureNameListStyle listStyle
;
79 const char * expectName_wide
;
80 const char * expectName_shrt
;
81 const char * expectName_narr
;
86 const SingleUnitFormat
* singleUnitFormatTests
; // may be NULL
87 const SingleUnitName
* singleUnitNameTests
; // may be NULL
88 const MultipleUnitFormat
* multipleUnitFormatTests
; // may be NULL
89 const MultipleUnitName
* multipleUnitNameTests
; // may be NULL
90 } LocaleWidthNumFmtItem
;
92 static const SingleUnitFormat en_singFmt
[] = {
93 // unit value wide_2 wide_0 shrt_X shrt_1 narr_0 numr_0 wide_0 narr_0
94 { UAMEASUNIT_DURATION_MINUTE
, 0.0, "0.00 minutes", "0 minutes", "0 min", "0.0 min", "0m", "0m", 0,1, 0,1 },
95 { UAMEASUNIT_DURATION_MINUTE
, 1.0, "1.00 minutes", "1 minute", "1 min", "1.0 min", "1m", "1m", 0,1, 0,1 },
96 { UAMEASUNIT_DURATION_MINUTE
, 5.25, "5.25 minutes", "5 minutes", "5.25 min", "5.2 min", "5m", "5m", 0,1, 0,1 },
97 { UAMEASUNIT_DURATION_DAY
, 5.25, "5.25 days", "5 days", "5.25 days", "5.2 days", "5d", "5d", 0,1, 0,1 },
98 { UAMEASUNIT_DURATION_WEEK
, 5.25, "5.25 weeks", "5 weeks", "5.25 wks", "5.2 wks", "5w", "5w", 0,1, 0,1 },
99 { UAMEASUNIT_DURATION_CENTURY
, 37.203, "37.20 centuries", "37 centuries", "37.203 c", "37.2 c", "37 c", "37 c", 0,2, 0,2 },
100 { UAMEASUNIT_LENGTH_CENTIMETER
, 37.203, "37.20 centimeters", "37 centimeters", "37.203 cm", "37.2 cm", "37cm", "37cm", 0,2, 0,2 },
101 { UAMEASUNIT_SPEED_KILOMETER_PER_HOUR
, 37.203, "37.20 kilometers per hour", "37 kilometers per hour", "37.203 km/h", "37.2 km/h", "37km/h", "37km/h", 0,2, 0,2 },
102 { 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 },
103 { 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 },
104 { UAMEASUNIT_TEMPERATURE_GENERIC
, 37.203, "37.20 degrees", "37 degrees", "37.203\\u00B0", "37.2\\u00B0", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
105 { UAMEASUNIT_VOLUME_LITER
, 37.203, "37.20 liters", "37 liters", "37.203 L", "37.2 L", "37L", "37L", 0,2, 0,2 },
106 { UAMEASUNIT_ENERGY_FOODCALORIE
, 37.203, "37.20 Calories", "37 Calories", "37.203 Cal", "37.2 Cal", "37Cal", "37Cal", 0,2, 0,2 },
107 { UAMEASUNIT_ENERGY_JOULE
, 37.203, "37.20 joules", "37 joules", "37.203 J", "37.2 J", "37J", "37J", 0,2, 0,2 },
108 { UAMEASUNIT_DIGITAL_MEGABYTE
, 37.203, "37.20 megabytes", "37 megabytes", "37.203 MB", "37.2 MB", "37MB", "37MB", 0,2, 0,2 },
109 { (UAMeasureUnit
)0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
112 static const SingleUnitFormat en_GB_singFmt
[] = {
113 // unit value wide_2 wide_0 shrt_X shrt_1 narr_0 numr_0 wide_0 narr_0
114 { UAMEASUNIT_DURATION_MINUTE
, 0.0, "0.00 minutes", "0 minutes", "0 min", "0.0 min", "0m", "0m", 0,1, 0,1 },
115 { UAMEASUNIT_DURATION_MINUTE
, 1.0, "1.00 minutes", "1 minute", "1 min", "1.0 min", "1m", "1m", 0,1, 0,1 },
116 { UAMEASUNIT_DURATION_MINUTE
, 5.25, "5.25 minutes", "5 minutes", "5.25 min", "5.2 min", "5m", "5m", 0,1, 0,1 },
117 { UAMEASUNIT_LENGTH_CENTIMETER
, 37.203, "37.20 centimetres", "37 centimetres", "37.203 cm", "37.2 cm", "37cm", "37cm", 0,2, 0,2 },
118 { 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 },
119 { 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 },
120 { UAMEASUNIT_TEMPERATURE_GENERIC
, 37.203, "37.20 degrees", "37 degrees", "37.203\\u00B0", "37.2\\u00B0", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
121 { UAMEASUNIT_VOLUME_LITER
, 37.203, "37.20 litres", "37 litres", "37.203 l", "37.2 l", "37l", "37l", 0,2, 0,2 },
122 { UAMEASUNIT_ENERGY_FOODCALORIE
, 37.203, "37.20 Calories", "37 Calories", "37.203 Cal", "37.2 Cal", "37Cal", "37Cal", 0,2, 0,2 },
123 { (UAMeasureUnit
)0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
126 static const SingleUnitFormat fr_singFmt
[] = {
127 // unit value wide_2 wide_0 shrt_X shrt_1 narr_0 numr_0 wide_0 narr_0
128 { UAMEASUNIT_DURATION_MINUTE
, 0.0, "0,00 minute", "0 minute", "0\\u00A0mn", "0,0\\u00A0mn", "0mn", "0mn", 0,1, 0,1 },
129 { UAMEASUNIT_DURATION_MINUTE
, 1.0, "1,00 minute", "1 minute", "1\\u00A0mn", "1,0\\u00A0mn", "1mn", "1mn", 0,1, 0,1 },
130 { UAMEASUNIT_DURATION_MINUTE
, 5.25, "5,25 minutes", "5 minutes", "5,25\\u00A0mn", "5,2\\u00A0mn", "5mn", "5mn", 0,1, 0,1 },
131 { UAMEASUNIT_LENGTH_CENTIMETER
, 37.203, "37,20\\u00A0centim\\u00E8tres", "37\\u00A0centim\\u00E8tres", "37,203\\u202Fcm", "37,2\\u202Fcm", "37 cm", "37 cm", 0,2, 0,2 },
132 { UAMEASUNIT_TEMPERATURE_CELSIUS
, 37.203, "37,20\\u00A0degr\\u00E9s Celsius","37\\u00A0degr\\u00E9s Celsius", "37,203\\u202F\\u00B0C", "37,2\\u202F\\u00B0C", "37\\u00B0C", "37\\u00B0", 0,2, 0,2 },
133 { UAMEASUNIT_TEMPERATURE_FAHRENHEIT
, 37.203, "37,20\\u00A0degr\\u00E9s Fahrenheit", "37\\u00A0degr\\u00E9s Fahrenheit", "37,203\\u202F\\u00B0F", "37,2\\u202F\\u00B0F", "37\\u202F\\u00B0F", "37\\u00B0", 0,2, 0,2 },
134 { UAMEASUNIT_TEMPERATURE_GENERIC
, 37.203, "37,20\\u00A0degr\\u00E9s", "37\\u00A0degr\\u00E9s", "37,203\\u00B0", "37,2\\u00B0", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
135 { UAMEASUNIT_VOLUME_LITER
, 37.203, "37,20\\u00A0litres", "37\\u00A0litres", "37,203\\u202Fl", "37,2\\u202Fl", "37 l", "37 l", 0,2, 0,2 },
136 { UAMEASUNIT_ENERGY_FOODCALORIE
, 37.203, "37,20\\u00A0kilocalories", "37\\u00A0kilocalories", "37,203\\u202Fkcal","37,2\\u202Fkcal","37\\u202Fkcal","37\\u202Fkcal", 0,2, 0,2 },
137 { (UAMeasureUnit
)0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
140 static const SingleUnitFormat fr_CA_singFmt
[] = {
141 // unit value wide_2 wide_0 shrt_X shrt_1 narr_0 numr_0 wide_0 narr_0
142 { UAMEASUNIT_DURATION_MINUTE
, 0.0, "0,00 minute", "0 minute", "0 min", "0,0 min", "0m", "0m", 0,1, 0,1 },
143 { UAMEASUNIT_DURATION_MINUTE
, 1.0, "1,00 minute", "1 minute", "1 min", "1,0 min", "1m", "1m", 0,1, 0,1 },
144 { UAMEASUNIT_DURATION_MINUTE
, 5.25, "5,25 minutes", "5 minutes", "5,25 min", "5,2 min", "5m", "5m", 0,1, 0,1 },
145 { 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 },
146 { UAMEASUNIT_TEMPERATURE_CELSIUS
, 37.203, "37,20 degr\\u00E9s Celsius", "37 degr\\u00E9s Celsius", "37,203\\u00A0\\u00B0C", "37,2\\u00A0\\u00B0C", "37\\u00A0\\u00B0C", "37\\u00B0", 0,2, 0,2 },
147 { UAMEASUNIT_TEMPERATURE_FAHRENHEIT
, 37.203, "37,20 degr\\u00E9s Fahrenheit", "37 degr\\u00E9s Fahrenheit", "37,203\\u00A0\\u00B0F", "37,2\\u00A0\\u00B0F", "37\\u00A0\\u00B0F", "37\\u00B0", 0,2, 0,2 },
148 { UAMEASUNIT_TEMPERATURE_GENERIC
, 37.203, "37,20\\u00B0", "37\\u00B0", "37,203\\u00B0", "37,2\\u00B0", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
149 { UAMEASUNIT_VOLUME_LITER
, 37.203, "37,20 litres", "37 litres", "37,203 L", "37,2 L", "37L", "37L", 0,2, 0,2 },
150 { UAMEASUNIT_ENERGY_FOODCALORIE
, 37.203, "37,20 calories", "37 calories", "37,203 cal", "37,2 cal", "37 cal", "37 cal", 0,2, 0,2 },
151 { (UAMeasureUnit
)0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
154 static const SingleUnitFormat zh_Hant_singFmt
[] = {
155 // unit value wide_2 wide_0 shrt_X shrt_1 narr_0 numr_0 wide_0 narr_0
156 { UAMEASUNIT_DURATION_MINUTE
, 5.25, "5.25\\u5206\\u9418", "5\\u5206\\u9418", "5.25\\u5206\\u9418", "5.2\\u5206\\u9418", "5\\u5206", "5\\u5206", 0,1, 0,1 },
157 { UAMEASUNIT_LENGTH_CENTIMETER
, 37.203, "37.20\\u516C\\u5206", "37\\u516C\\u5206", "37.203\\u516C\\u5206", "37.2\\u516C\\u5206", "37\\u516C\\u5206", "37\\u516C\\u5206", 0,2, 0,2 },
158 { UAMEASUNIT_TEMPERATURE_GENERIC
, 37.203, "37.20\\u00B0", "37\\u00B0", "37.203\\u00B0", "37.2\\u00B0", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
159 { UAMEASUNIT_ANGLE_DEGREE
, 37.203, "37.20\\u5EA6", "37\\u5EA6", "37.203\\u00B0", "37.2\\u00B0", "37\\u00B0", "37\\u00B0", 0,2, 0,2 },
160 { (UAMeasureUnit
)0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
163 static const SingleUnitFormat cs_singFmt
[] = {
164 // unit value wide_2 wide_0 shrt_X shrt_1 narr_0 numr_0 wide_0 narr_0
165 { 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
166 { 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
167 { 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
168 { 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
169 { (UAMeasureUnit
)0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
172 static const SingleUnitName en_singNam
[] = {
173 // unit wide shrt narr
174 { UAMEASUNIT_DURATION_MINUTE
, "minutes", "min", "min" },
175 { UAMEASUNIT_DURATION_CENTURY
, "centuries", "c", "c" },
176 { UAMEASUNIT_LENGTH_CENTIMETER
, "centimeters", "cm", "cm" },
177 { UAMEASUNIT_SPEED_KILOMETER_PER_HOUR
, "kilometers per hour", "km/hour", "km/hr" },
178 { UAMEASUNIT_TEMPERATURE_CELSIUS
, "degrees Celsius", "deg. C", "\\u00B0C" },
179 { UAMEASUNIT_TEMPERATURE_FAHRENHEIT
, "degrees Fahrenheit", "deg. F", "\\u00B0F" },
180 { UAMEASUNIT_TEMPERATURE_GENERIC
, "degrees", "deg.", "deg." },
181 { UAMEASUNIT_VOLUME_LITER
, "liters", "liters", "liter" },
182 { UAMEASUNIT_ENERGY_FOODCALORIE
, "Calories", "Cal", "Cal" },
183 { UAMEASUNIT_ENERGY_JOULE
, "joules", "joules", "joule" },
184 { UAMEASUNIT_DIGITAL_MEGABYTE
, "megabytes", "MByte", "MByte" },
185 { (UAMeasureUnit
)0, NULL
, NULL
, NULL
}
188 static const SingleUnitName en_GB_singNam
[] = {
189 // unit wide shrt narr
190 { UAMEASUNIT_DURATION_MINUTE
, "minutes", "min", "min" },
191 { UAMEASUNIT_LENGTH_CENTIMETER
, "centimetres", "cm", "cm" },
192 { UAMEASUNIT_TEMPERATURE_CELSIUS
, "degrees Celsius", "deg. C", "\\u00B0C" },
193 { UAMEASUNIT_TEMPERATURE_FAHRENHEIT
, "degrees Fahrenheit", "deg. F", "\\u00B0F" },
194 { UAMEASUNIT_TEMPERATURE_GENERIC
, "degrees", "deg.", "deg." },
195 { UAMEASUNIT_VOLUME_LITER
, "litres", "litres", "litre" },
196 { UAMEASUNIT_ENERGY_FOODCALORIE
, "Calories", "Cal", "Cal" },
197 { (UAMeasureUnit
)0, NULL
, NULL
, NULL
}
200 static const UAMeasure meas_hrMnSc
[] = { {37.3,UAMEASUNIT_DURATION_HOUR
}, {12.1,UAMEASUNIT_DURATION_MINUTE
}, {5.32,UAMEASUNIT_DURATION_SECOND
} };
201 static const UAMeasure meas_hrMn
[] = { {37.3,UAMEASUNIT_DURATION_HOUR
}, {12.1,UAMEASUNIT_DURATION_MINUTE
} };
202 static const UAMeasure meas_mCm
[] = { {37.3,UAMEASUNIT_LENGTH_METER
}, {12.1,UAMEASUNIT_LENGTH_CENTIMETER
} };
203 static const UAMeasure meas_cm
[] = { {12.1,UAMEASUNIT_LENGTH_CENTIMETER
} };
204 static const UAMeasure meas_2hrMn
[] = { {2.0,UAMEASUNIT_DURATION_HOUR
}, {12.1,UAMEASUNIT_DURATION_MINUTE
} };
205 static const UAMeasure meas_moDys
[] = { {1.0,UAMEASUNIT_DURATION_MONTH
}, {2.0,UAMEASUNIT_DURATION_DAY
} };
207 static const MultipleUnitFormat en_multFmt
[] = {
208 // measures count wide_2 wide_0 shrt_X shrt_1 shrtr_1 narr_0 numr_0
209 { 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",
210 /* 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}},
211 /* 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}},
212 /* 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}} },
213 { 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",
214 /* 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}},
215 /* 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}},
216 /* 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}} },
217 { 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",
218 /* 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}},
219 /* 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}},
220 /* 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}} },
221 { meas_cm
, UPRV_LENGTHOF(meas_cm
), "12.10 centimeters", "12 centimeters", "12.1 cm", "12.1 cm", "12.1cm", "12cm", "12cm",
222 /* ranges_wide_2: */ {{UAMEASUNIT_LENGTH_CENTIMETER
,0,17},{UAMEASUNIT_LENGTH_CENTIMETER
|UAMEASFMT_NUMERIC_FIELD_FLAG
,0,5}},
223 /* ranges_shrtr_1: */ {{UAMEASUNIT_LENGTH_CENTIMETER
,0, 6},{UAMEASUNIT_LENGTH_CENTIMETER
|UAMEASFMT_NUMERIC_FIELD_FLAG
,0,4}},
224 /* ranges_numr_0: */ {{UAMEASUNIT_LENGTH_CENTIMETER
,0, 4},{UAMEASUNIT_LENGTH_CENTIMETER
|UAMEASFMT_NUMERIC_FIELD_FLAG
,0,2}} },
225 { NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
228 static const MultipleUnitFormat en_GB_multFmt
[] = {
229 // measures count wide_2 wide_0 shrt_X shrt_1 shrtr_1 narr_0 numr_0
230 { 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",
231 /* 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}},
232 /* 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}},
233 /* 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}} },
234 { 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",
235 /* 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}},
236 /* 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}},
237 /* 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}} },
238 { 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",
239 /* 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}},
240 /* 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}},
241 /* 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}} },
242 { meas_cm
, UPRV_LENGTHOF(meas_cm
), "12.10 centimetres", "12 centimetres", "12.1 cm", "12.1 cm", "12.1cm", "12cm", "12cm",
243 /* ranges_wide_2: */ {{UAMEASUNIT_LENGTH_CENTIMETER
,0,17},{UAMEASUNIT_LENGTH_CENTIMETER
|UAMEASFMT_NUMERIC_FIELD_FLAG
,0,5}},
244 /* ranges_shrtr_1: */ {{UAMEASUNIT_LENGTH_CENTIMETER
,0, 6},{UAMEASUNIT_LENGTH_CENTIMETER
|UAMEASFMT_NUMERIC_FIELD_FLAG
,0,4}},
245 /* ranges_numr_0: */ {{UAMEASUNIT_LENGTH_CENTIMETER
,0, 4},{UAMEASUNIT_LENGTH_CENTIMETER
|UAMEASFMT_NUMERIC_FIELD_FLAG
,0,2}} },
246 { NULL
, 0, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
}
249 static const MultipleUnitFormat he_multFmt
[] = {
250 // measures count wide_2 wide_0
251 { 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",
252 /* 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",
253 /* 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",
254 /* ranges_wide_2: */ {{UAMEASUNIT_DURATION_HOUR
,0,6},{UAMEASUNIT_DURATION_MINUTE
,8,18},{UAMEASUNIT_DURATION_MINUTE
|UAMEASFMT_NUMERIC_FIELD_FLAG
,8,13}},
255 /* ranges_shrtr_1: */ {{UAMEASUNIT_DURATION_HOUR
,0,6},{UAMEASUNIT_DURATION_MINUTE
,8,16},{UAMEASUNIT_DURATION_MINUTE
|UAMEASFMT_NUMERIC_FIELD_FLAG
,8,12}},
256 /* 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}} },
259 static const MultipleUnitFormat hi_multFmt
[] = {
260 // measures count wide_2 wide_0
261 { meas_moDys
, UPRV_LENGTHOF(meas_moDys
), "1 \\u092E\\u093E\\u0939 \\u0914\\u0930 2.00 \\u0926\\u093F\\u0928", "1 \\u092E\\u093E\\u0939 \\u0914\\u0930 2 \\u0926\\u093F\\u0928",
262 /* shrt_X, shrt_1*/ "1 \\u092E\\u093E\\u0939, 2 \\u0926\\u093F\\u0928", "1 \\u092E\\u093E\\u0939, 2.0 \\u0926\\u093F\\u0928",
263 /* shrtr_1, narr_0, numr_0*/ "1 \\u092E\\u093E\\u0939, 2.0 \\u0926\\u093F\\u0928", "1 \\u092E\\u093E\\u0939, 2 \\u0926\\u093F\\u0928", "1 \\u092E\\u093E\\u0939, 2 \\u0926\\u093F\\u0928",
264 /* 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}},
265 /* 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}},
266 /* 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}} },
269 static const UAMeasureUnit unit_hrMnSc
[] = { UAMEASUNIT_DURATION_HOUR
, UAMEASUNIT_DURATION_MINUTE
, UAMEASUNIT_DURATION_SECOND
};
270 static const UAMeasureUnit unit_hrMn
[] = { UAMEASUNIT_DURATION_HOUR
, UAMEASUNIT_DURATION_MINUTE
};
271 static const UAMeasureUnit unit_mCm
[] = { UAMEASUNIT_LENGTH_METER
, UAMEASUNIT_LENGTH_CENTIMETER
};
273 static const MultipleUnitName en_multNam
[] = {
274 // units count listStyle wide shrt narr
275 { unit_hrMnSc
, UPRV_LENGTHOF(unit_hrMnSc
), UAMEASNAME_LIST_STANDARD
, "hours, minutes, and seconds", "hours, min, and secs", "hour, min, and sec" },
276 { unit_hrMnSc
, UPRV_LENGTHOF(unit_hrMnSc
), UAMEASNAME_LIST_MATCHUNITS
, "hours, minutes, seconds", "hours, min, secs", "hour min sec" },
277 { unit_hrMn
, UPRV_LENGTHOF(unit_hrMn
), UAMEASNAME_LIST_STANDARD
, "hours and minutes", "hours and min", "hour and min" },
278 { unit_hrMn
, UPRV_LENGTHOF(unit_hrMn
), UAMEASNAME_LIST_MATCHUNITS
, "hours, minutes", "hours, min", "hour min" },
279 { unit_mCm
, UPRV_LENGTHOF(unit_mCm
), UAMEASNAME_LIST_STANDARD
, "meters and centimeters", "meters and cm", "meter and cm" },
280 { unit_mCm
, UPRV_LENGTHOF(unit_mCm
), UAMEASNAME_LIST_MATCHUNITS
, "meters, centimeters", "meters, cm", "meter cm" },
281 { NULL
, 0, (UAMeasureNameListStyle
)0, NULL
, NULL
, NULL
}
284 static const MultipleUnitName en_GB_multNam
[] = {
285 // units count listStyle wide shrt narr
286 { unit_hrMnSc
, UPRV_LENGTHOF(unit_hrMnSc
), UAMEASNAME_LIST_STANDARD
, "hours, minutes and seconds", "hours, min and secs", "hour, min and sec" },
287 { unit_hrMnSc
, UPRV_LENGTHOF(unit_hrMnSc
), UAMEASNAME_LIST_MATCHUNITS
, "hours, minutes, seconds", "hours, min, secs", "hour min sec" },
288 { unit_hrMn
, UPRV_LENGTHOF(unit_hrMn
), UAMEASNAME_LIST_STANDARD
, "hours and minutes", "hours and min", "hour and min" },
289 { unit_hrMn
, UPRV_LENGTHOF(unit_hrMn
), UAMEASNAME_LIST_MATCHUNITS
, "hours, minutes", "hours, min", "hour min" },
290 { unit_mCm
, UPRV_LENGTHOF(unit_mCm
), UAMEASNAME_LIST_STANDARD
, "metres and centimetres", "metres and cm", "m and cm" },
291 { unit_mCm
, UPRV_LENGTHOF(unit_mCm
), UAMEASNAME_LIST_MATCHUNITS
, "metres, centimetres", "metres, cm", "m cm" },
292 { NULL
, 0, (UAMeasureNameListStyle
)0, NULL
, NULL
, NULL
}
295 static const MultipleUnitName ja_multNam
[] = {
296 // units count listStyle wide shrt narr
297 { 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" },
298 { unit_hrMnSc
, UPRV_LENGTHOF(unit_hrMnSc
), UAMEASNAME_LIST_MATCHUNITS
, "\\u6642\\u9593 \\u5206 \\u79D2", "\\u6642\\u9593 \\u5206 \\u79D2", "\\u6642\\u9593\\u5206\\u79D2" },
299 { unit_hrMn
, UPRV_LENGTHOF(unit_hrMn
), UAMEASNAME_LIST_STANDARD
, "\\u6642\\u9593\\u3001\\u5206", "\\u6642\\u9593\\u3001\\u5206", "\\u6642\\u9593\\u3001\\u5206" },
300 { unit_hrMn
, UPRV_LENGTHOF(unit_hrMn
), UAMEASNAME_LIST_MATCHUNITS
, "\\u6642\\u9593 \\u5206", "\\u6642\\u9593 \\u5206", "\\u6642\\u9593\\u5206" },
301 { 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" },
302 { unit_mCm
, UPRV_LENGTHOF(unit_mCm
), UAMEASNAME_LIST_MATCHUNITS
, "\\u30E1\\u30FC\\u30C8\\u30EB \\u30BB\\u30F3\\u30C1\\u30E1\\u30FC\\u30C8\\u30EB", "m cm", "mcm" },
303 { NULL
, 0, (UAMeasureNameListStyle
)0, NULL
, NULL
, NULL
}
306 static const LocaleWidthNumFmtItem lwnItems
[] = {
307 // ============= TIER 0,1 and subocales
308 { "en", en_singFmt
, en_singNam
, en_multFmt
, en_multNam
}, // en: try plural cases for 1, other
309 { "en_GB", en_GB_singFmt
, en_GB_singNam
, en_GB_multFmt
, en_GB_multNam
},
310 { "en_AU", NULL
, NULL
, NULL
, NULL
},
311 { "de", NULL
, NULL
, NULL
, NULL
}, // de: try plural cases for 1, other
312 { "fr", fr_singFmt
, NULL
, NULL
, NULL
}, // fr: try plural cases for 1, other
313 { "fr_CA", fr_CA_singFmt
, NULL
, NULL
, NULL
},
314 { "ja", NULL
, NULL
, NULL
, ja_multNam
}, // ja: try plural cases for other only
315 { "zh_Hans", NULL
, NULL
, NULL
, NULL
}, // zh_Hans: try plural cases for other only
317 // ============= TIER 2,3 and sublocales
318 { "ar", NULL
, NULL
, NULL
, NULL
}, // ar: try plural cases for 0, 1, 2, 3, 11, 100
319 { "ca", NULL
, NULL
, NULL
, NULL
}, // ca: try plural cases for 1, other
320 { "cs", cs_singFmt
, NULL
, NULL
, NULL
}, // cs: try plural cases for 1, 2, 8.5, 5
321 { "da", NULL
, NULL
, NULL
, NULL
}, // da: try plural cases for 1, other
322 { "el", NULL
, NULL
, NULL
, NULL
}, // el: try plural cases for 1, other
323 { "es", NULL
, NULL
, NULL
, NULL
}, // es: try plural cases for 1, other
324 { "es_MX", NULL
, NULL
, NULL
, NULL
},
325 { "fi", NULL
, NULL
, NULL
, NULL
}, // fi: try plural cases for 1, other
326 { "he", NULL
, NULL
, he_multFmt
, NULL
}, // he: try plural cases for 1, 2, 20, 3
327 { "hi", NULL
, NULL
, hi_multFmt
, NULL
}, // hi: try plural cases for 1 (covers 0.0-1.0), other
328 { "hr", NULL
, NULL
, NULL
, NULL
}, // hr: try plural cases for 1, 2, 5
329 { "hu", NULL
, NULL
, NULL
, NULL
}, // hu: try plural cases for 1, other
330 { "id", NULL
, NULL
, NULL
, NULL
}, // id: try plural cases for other only
331 { "it", NULL
, NULL
, NULL
, NULL
}, // it: try plural cases for 1, other
332 { "ko", NULL
, NULL
, NULL
, NULL
}, // ko: try plural cases for other only
333 { "ms", NULL
, NULL
, NULL
, NULL
}, // ms: try plural cases for other only
334 { "nb", NULL
, NULL
, NULL
, NULL
}, // nb: try plural cases for 1, other
335 { "nl", NULL
, NULL
, NULL
, NULL
}, // nl: try plural cases for 1, other
336 { "pl", NULL
, NULL
, NULL
, NULL
}, // pl: try plural cases for 1, 2, 5, 8.5
337 { "pt", NULL
, NULL
, NULL
, NULL
}, // pt: try plural cases for 1, other
338 { "pt_PT", NULL
, NULL
, NULL
, NULL
},
339 { "ro", NULL
, NULL
, NULL
, NULL
}, // ro: try plural cases for 1, 2, 20
340 { "ru", NULL
, NULL
, NULL
, NULL
}, // ru: try plural cases for 1, 2, 5, 8.5
341 { "sk", NULL
, NULL
, NULL
, NULL
}, // sk: try plural cases for 1, 2, 8.5, 5
342 { "sv", NULL
, NULL
, NULL
, NULL
}, // sv: try plural cases for 1, other
343 { "th", NULL
, NULL
, NULL
, NULL
}, // th: try plural cases for other only
344 { "tr", NULL
, NULL
, NULL
, NULL
}, // tr: try plural cases for 1, other
345 { "uk", NULL
, NULL
, NULL
, NULL
}, // uk: try plural cases for 1, 2, 5, 8.5
346 { "vi", NULL
, NULL
, NULL
, NULL
}, // vi: try plural cases for other only
347 { "zh_Hant", zh_Hant_singFmt
, NULL
, NULL
, NULL
}, // zh_Hant: try plural cases for other only
348 { "zh_Hant_HK", NULL
, NULL
, NULL
, NULL
},
350 // =============TERMINATOR
351 { NULL
, NULL
, NULL
, NULL
, NULL
}
354 enum { kUBufMax
= 96, kBBufMax
= 192 };
357 static void TestUAMeasureFormat()
359 const LocaleWidthNumFmtItem
* itemPtr
;
360 log_verbose("\nTesting uameasfmt functions\n");
361 for (itemPtr
= lwnItems
; itemPtr
->locale
!= NULL
; itemPtr
++) {
362 UChar uget
[kUBufMax
];
363 UChar uexp
[kUBufMax
];
366 int32_t ugetLen
, uexpLen
;
367 UErrorCode status
= U_ZERO_ERROR
;
368 UNumberFormat
* numfmt_0
;
369 UNumberFormat
* numfmt_1
;
370 UNumberFormat
* numfmt_2
;
371 UAMeasureFormat
* measfmt_wide_2
;
372 UAMeasureFormat
* measfmt_wide_0
;
373 UAMeasureFormat
* measfmt_shrt_X
;
374 UAMeasureFormat
* measfmt_shrt_1
;
375 UAMeasureFormat
* measfmt_shrtr_1
;
376 UAMeasureFormat
* measfmt_narr_0
;
377 UAMeasureFormat
* measfmt_numr_0
;
379 numfmt_0
= unum_open(UNUM_DECIMAL
, NULL
, 0, itemPtr
->locale
, NULL
, &status
);
380 if ( U_FAILURE(status
) ) {
381 log_data_err("FAIL: unum_open(UNUM_DECIMAL,...) fails for locale %s: %s\n",
382 itemPtr
->locale
, u_errorName(status
) );
385 numfmt_1
= unum_clone(numfmt_0
, &status
);
386 numfmt_2
= unum_clone(numfmt_0
, &status
);
387 if ( U_FAILURE(status
) ) {
388 log_err("FAIL: unum_clone fails for locale %s: %s\n",
389 itemPtr
->locale
, u_errorName(status
) );
390 unum_close(numfmt_0
);
393 unum_setAttribute(numfmt_0
, UNUM_MIN_FRACTION_DIGITS
, 0);
394 unum_setAttribute(numfmt_0
, UNUM_MAX_FRACTION_DIGITS
, 0);
395 unum_setAttribute(numfmt_0
, UNUM_ROUNDING_MODE
, UNUM_ROUND_DOWN
);
396 unum_setAttribute(numfmt_1
, UNUM_MIN_FRACTION_DIGITS
, 1);
397 unum_setAttribute(numfmt_1
, UNUM_MAX_FRACTION_DIGITS
, 1);
398 unum_setAttribute(numfmt_1
, UNUM_ROUNDING_MODE
, UNUM_ROUND_DOWN
);
399 unum_setAttribute(numfmt_2
, UNUM_MIN_FRACTION_DIGITS
, 2);
400 unum_setAttribute(numfmt_2
, UNUM_MAX_FRACTION_DIGITS
, 2);
401 unum_setAttribute(numfmt_2
, UNUM_ROUNDING_MODE
, UNUM_ROUND_DOWN
);
403 measfmt_wide_2
= uameasfmt_open(itemPtr
->locale
, UAMEASFMT_WIDTH_WIDE
, unum_clone(numfmt_2
, &status
), &status
); // wide, num fmt with 2 decimals
404 measfmt_wide_0
= uameasfmt_open(itemPtr
->locale
, UAMEASFMT_WIDTH_WIDE
, unum_clone(numfmt_0
, &status
), &status
); // wide, num fmt with 0 decimals
405 measfmt_shrt_X
= uameasfmt_open(itemPtr
->locale
, UAMEASFMT_WIDTH_SHORT
, NULL
, &status
); // short, default num fmt
406 measfmt_shrt_1
= uameasfmt_open(itemPtr
->locale
, UAMEASFMT_WIDTH_SHORT
, unum_clone(numfmt_1
, &status
), &status
); // short, num fmt with 1 decimal
407 measfmt_shrtr_1
= uameasfmt_open(itemPtr
->locale
, UAMEASFMT_WIDTH_SHORTER
, unum_clone(numfmt_1
, &status
), &status
); // shorter, num fmt with 1 decimal
408 measfmt_narr_0
= uameasfmt_open(itemPtr
->locale
, UAMEASFMT_WIDTH_NARROW
, unum_clone(numfmt_0
, &status
), &status
); // narrow, num fmt with 0 decimal
409 measfmt_numr_0
= uameasfmt_open(itemPtr
->locale
, UAMEASFMT_WIDTH_NUMERIC
, unum_clone(numfmt_0
, &status
), &status
); // numeric, num fmt with 0 decimal
411 if ( U_FAILURE(status
) ) {
412 log_data_err("FAIL: uameasfmt_open fails for locale %s, various widths and number formatters: %s\n",
413 itemPtr
->locale
, u_errorName(status
) );
414 unum_close(numfmt_0
);
415 unum_close(numfmt_1
);
416 unum_close(numfmt_2
);
420 if (itemPtr
->singleUnitFormatTests
!= NULL
) {
421 const SingleUnitFormat
* singFmtPtr
;
422 for (singFmtPtr
= itemPtr
->singleUnitFormatTests
; singFmtPtr
->expectFmt_wide_2
!= 0; singFmtPtr
++) {
423 UFieldPosition fpos
= { UNUM_INTEGER_FIELD
, 0, 0 };
425 status
= U_ZERO_ERROR
;
426 ugetLen
= uameasfmt_formatGetPosition(measfmt_wide_2
, singFmtPtr
->value
, singFmtPtr
->unit
, uget
, kUBufMax
, NULL
, &status
);
427 if ( U_FAILURE(status
) ) {
428 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format wide_2 for unit %d:%d, status %s\n",
429 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF, u_errorName(status
));
431 uexpLen
= u_unescape(singFmtPtr
->expectFmt_wide_2
, uexp
, kUBufMax
);
432 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
433 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
434 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
435 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format wide_2 for unit %d:%d, expected \"%s\", got \"%s\"\n",
436 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF, bexp
, bget
);
440 status
= U_ZERO_ERROR
;
441 fpos
.beginIndex
= -1;
443 ugetLen
= uameasfmt_formatGetPosition(measfmt_wide_0
, singFmtPtr
->value
, singFmtPtr
->unit
, uget
, kUBufMax
, &fpos
, &status
);
444 if ( U_FAILURE(status
) ) {
445 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format wide_0 for unit %d:%d, status %s\n",
446 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF, u_errorName(status
));
448 uexpLen
= u_unescape(singFmtPtr
->expectFmt_wide_0
, uexp
, kUBufMax
);
449 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 || fpos
.beginIndex
!= singFmtPtr
->beginInt_wide_0
|| fpos
.endIndex
!= singFmtPtr
->endInt_wide_0
) {
450 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
451 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
452 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",
453 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF,
454 bexp
, singFmtPtr
->beginInt_wide_0
, singFmtPtr
->endInt_wide_0
,
455 bget
, fpos
.beginIndex
, fpos
.endIndex
);
459 status
= U_ZERO_ERROR
;
460 ugetLen
= uameasfmt_formatGetPosition(measfmt_shrt_X
, singFmtPtr
->value
, singFmtPtr
->unit
, uget
, kUBufMax
, NULL
, &status
);
461 if ( U_FAILURE(status
) ) {
462 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format shrt_X for unit %d:%d, status %s\n",
463 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF, u_errorName(status
));
465 uexpLen
= u_unescape(singFmtPtr
->expectFmt_shrt_X
, uexp
, kUBufMax
);
466 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
467 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
468 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
469 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format shrt_X for unit %d:%d, expected \"%s\", got \"%s\"\n",
470 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF, bexp
, bget
);
474 status
= U_ZERO_ERROR
;
475 ugetLen
= uameasfmt_formatGetPosition(measfmt_shrt_1
, singFmtPtr
->value
, singFmtPtr
->unit
, uget
, kUBufMax
, NULL
, &status
);
476 if ( U_FAILURE(status
) ) {
477 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format shrt_1 for unit %d:%d, status %s\n",
478 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF, u_errorName(status
));
480 uexpLen
= u_unescape(singFmtPtr
->expectFmt_shrt_1
, uexp
, kUBufMax
);
481 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
482 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
483 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
484 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format shrt_1 for unit %d:%d, expected \"%s\", got \"%s\"\n",
485 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF, bexp
, bget
);
489 status
= U_ZERO_ERROR
;
490 ugetLen
= uameasfmt_formatGetPosition(measfmt_narr_0
, singFmtPtr
->value
, singFmtPtr
->unit
, uget
, kUBufMax
, NULL
, &status
);
491 if ( U_FAILURE(status
) ) {
492 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format narr_0 for unit %d:%d, status %s\n",
493 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF, u_errorName(status
));
495 uexpLen
= u_unescape(singFmtPtr
->expectFmt_narr_0
, uexp
, kUBufMax
);
496 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
497 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
498 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
499 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format narr_0 for unit %d:%d, expected \"%s\", got \"%s\"\n",
500 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF, bexp
, bget
);
504 status
= U_ZERO_ERROR
;
505 fpos
.beginIndex
= -1;
507 ugetLen
= uameasfmt_formatGetPosition(measfmt_numr_0
, singFmtPtr
->value
, singFmtPtr
->unit
, uget
, kUBufMax
, &fpos
, &status
);
508 if ( U_FAILURE(status
) ) {
509 log_err("FAIL: uameasfmt_formatGetPosition locale %s, single format numr_0 for unit %d:%d, status %s\n",
510 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF, u_errorName(status
));
512 uexpLen
= u_unescape(singFmtPtr
->expectFmt_numr_0
, uexp
, kUBufMax
);
513 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 || fpos
.beginIndex
!= singFmtPtr
->beginInt_numr_0
|| fpos
.endIndex
!= singFmtPtr
->endInt_numr_0
) {
514 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
515 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
516 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",
517 itemPtr
->locale
, ((int)singFmtPtr
->unit
) >> 8, ((int)singFmtPtr
->unit
) & 0xFF,
518 bexp
, singFmtPtr
->beginInt_numr_0
, singFmtPtr
->endInt_numr_0
,
519 bget
, fpos
.beginIndex
, fpos
.endIndex
);
525 if (itemPtr
->singleUnitNameTests
!= NULL
) {
526 const SingleUnitName
* singNamPtr
;
527 for (singNamPtr
= itemPtr
->singleUnitNameTests
; singNamPtr
->expectName_wide
!= 0; singNamPtr
++) {
529 status
= U_ZERO_ERROR
;
530 ugetLen
= uameasfmt_getUnitName(measfmt_wide_2
, singNamPtr
->unit
, uget
, kUBufMax
, &status
);
531 if ( U_FAILURE(status
) ) {
532 log_err("FAIL: uameasfmt_getUnitName locale %s, single name wide for unit %d:%d, status %s\n",
533 itemPtr
->locale
, ((int)singNamPtr
->unit
) >> 8, ((int)singNamPtr
->unit
) & 0xFF, u_errorName(status
));
535 uexpLen
= u_unescape(singNamPtr
->expectName_wide
, uexp
, kUBufMax
);
536 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
537 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
538 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
539 log_err("FAIL: uameasfmt_getUnitName locale %s, single name wide for unit %d:%d, expected \"%s\", got \"%s\"\n",
540 itemPtr
->locale
, ((int)singNamPtr
->unit
) >> 8, ((int)singNamPtr
->unit
) & 0xFF, bexp
, bget
);
544 status
= U_ZERO_ERROR
;
545 ugetLen
= uameasfmt_getUnitName(measfmt_shrt_X
, singNamPtr
->unit
, uget
, kUBufMax
, &status
);
546 if ( U_FAILURE(status
) ) {
547 log_err("FAIL: uameasfmt_getUnitName locale %s, single name shrt for unit %d:%d, status %s\n",
548 itemPtr
->locale
, ((int)singNamPtr
->unit
) >> 8, ((int)singNamPtr
->unit
) & 0xFF, u_errorName(status
));
550 uexpLen
= u_unescape(singNamPtr
->expectName_shrt
, uexp
, kUBufMax
);
551 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
552 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
553 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
554 log_err("FAIL: uameasfmt_getUnitName locale %s, single name shrt for unit %d:%d, expected \"%s\", got \"%s\"\n",
555 itemPtr
->locale
, ((int)singNamPtr
->unit
) >> 8, ((int)singNamPtr
->unit
) & 0xFF, bexp
, bget
);
559 status
= U_ZERO_ERROR
;
560 ugetLen
= uameasfmt_getUnitName(measfmt_narr_0
, singNamPtr
->unit
, uget
, kUBufMax
, &status
);
561 if ( U_FAILURE(status
) ) {
562 log_err("FAIL: uameasfmt_getUnitName locale %s, single name narr for unit %d:%d, status %s\n",
563 itemPtr
->locale
, ((int)singNamPtr
->unit
) >> 8, ((int)singNamPtr
->unit
) & 0xFF, u_errorName(status
));
565 uexpLen
= u_unescape(singNamPtr
->expectName_narr
, uexp
, kUBufMax
);
566 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
567 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
568 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
569 log_err("FAIL: uameasfmt_getUnitName locale %s, single name narr for unit %d:%d, expected \"%s\", got \"%s\"\n",
570 itemPtr
->locale
, ((int)singNamPtr
->unit
) >> 8, ((int)singNamPtr
->unit
) & 0xFF, bexp
, bget
);
576 if (itemPtr
->multipleUnitFormatTests
!= NULL
) {
577 status
= U_ZERO_ERROR
;
578 UFieldPositionIterator
* fpositer
= ufieldpositer_open(&status
);
579 if ( U_FAILURE(status
) ) {
580 log_err("FAIL: ufieldpositer_open, status %s\n", u_errorName(status
));
582 const MultipleUnitFormat
* multFmtPtr
;
583 for (multFmtPtr
= itemPtr
->multipleUnitFormatTests
; multFmtPtr
->measures
!= 0; multFmtPtr
++) {
585 status
= U_ZERO_ERROR
;
586 ugetLen
= uameasfmt_formatMultipleForFields(measfmt_wide_2
, multFmtPtr
->measures
, multFmtPtr
->measureCount
, uget
, kUBufMax
, fpositer
, &status
);
587 if ( U_FAILURE(status
) ) {
588 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format wide_2 for measureCount %d, status %s\n",
589 itemPtr
->locale
, multFmtPtr
->measureCount
, u_errorName(status
));
591 uexpLen
= u_unescape(multFmtPtr
->expectFmt_wide_2
, uexp
, kUBufMax
);
592 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
593 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
594 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
595 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format wide_2 for measureCount %d, expected \"%s\", got \"%s\"\n",
596 itemPtr
->locale
, multFmtPtr
->measureCount
, bexp
, bget
);
599 int32_t field
, beginIndex
, endIndex
, count
;
600 for (count
= 0; (field
= ufieldpositer_next(fpositer
, &beginIndex
, &endIndex
)) >= 0; count
++) {
601 if (field
!= multFmtPtr
->ranges_wide_2
[count
][0] || beginIndex
!= multFmtPtr
->ranges_wide_2
[count
][1] || endIndex
!= multFmtPtr
->ranges_wide_2
[count
][2]) {
602 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",
603 itemPtr
->locale
, multFmtPtr
->measureCount
,
604 multFmtPtr
->ranges_wide_2
[count
][0], multFmtPtr
->ranges_wide_2
[count
][1], multFmtPtr
->ranges_wide_2
[count
][2],
605 field
, beginIndex
, endIndex
);
612 status
= U_ZERO_ERROR
;
613 ugetLen
= uameasfmt_formatMultipleForFields(measfmt_wide_0
, multFmtPtr
->measures
, multFmtPtr
->measureCount
, uget
, kUBufMax
, NULL
, &status
);
614 if ( U_FAILURE(status
) ) {
615 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format wide_0 for measureCount %d, status %s\n",
616 itemPtr
->locale
, multFmtPtr
->measureCount
, u_errorName(status
));
618 uexpLen
= u_unescape(multFmtPtr
->expectFmt_wide_0
, uexp
, kUBufMax
);
619 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
620 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
621 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
622 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format wide_0 for measureCount %d, expected \"%s\", got \"%s\"\n",
623 itemPtr
->locale
, multFmtPtr
->measureCount
, bexp
, bget
);
627 status
= U_ZERO_ERROR
;
628 ugetLen
= uameasfmt_formatMultipleForFields(measfmt_shrt_X
, multFmtPtr
->measures
, multFmtPtr
->measureCount
, uget
, kUBufMax
, NULL
, &status
);
629 if ( U_FAILURE(status
) ) {
630 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrt_X for measureCount %d, status %s\n",
631 itemPtr
->locale
, multFmtPtr
->measureCount
, u_errorName(status
));
633 uexpLen
= u_unescape(multFmtPtr
->expectFmt_shrt_X
, uexp
, kUBufMax
);
634 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
635 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
636 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
637 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrt_X for measureCount %d, expected \"%s\", got \"%s\"\n",
638 itemPtr
->locale
, multFmtPtr
->measureCount
, bexp
, bget
);
642 status
= U_ZERO_ERROR
;
643 ugetLen
= uameasfmt_formatMultipleForFields(measfmt_shrt_1
, multFmtPtr
->measures
, multFmtPtr
->measureCount
, uget
, kUBufMax
, NULL
, &status
);
644 if ( U_FAILURE(status
) ) {
645 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrt_1 for measureCount %d, status %s\n",
646 itemPtr
->locale
, multFmtPtr
->measureCount
, u_errorName(status
));
648 uexpLen
= u_unescape(multFmtPtr
->expectFmt_shrt_1
, uexp
, kUBufMax
);
649 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
650 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
651 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
652 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrt_1 for measureCount %d, expected \"%s\", got \"%s\"\n",
653 itemPtr
->locale
, multFmtPtr
->measureCount
, bexp
, bget
);
657 status
= U_ZERO_ERROR
;
658 ugetLen
= uameasfmt_formatMultipleForFields(measfmt_shrtr_1
, multFmtPtr
->measures
, multFmtPtr
->measureCount
, uget
, kUBufMax
, fpositer
, &status
);
659 if ( U_FAILURE(status
) ) {
660 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrtr_1 for measureCount %d, status %s\n",
661 itemPtr
->locale
, multFmtPtr
->measureCount
, u_errorName(status
));
663 uexpLen
= u_unescape(multFmtPtr
->expectFmt_shrtr_1
, uexp
, kUBufMax
);
664 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
665 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
666 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
667 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format shrtr_1 for measureCount %d, expected \"%s\", got \"%s\"\n",
668 itemPtr
->locale
, multFmtPtr
->measureCount
, bexp
, bget
);
671 int32_t field
, beginIndex
, endIndex
, count
;
672 for (count
= 0; (field
= ufieldpositer_next(fpositer
, &beginIndex
, &endIndex
)) >= 0; count
++) {
673 if (field
!= multFmtPtr
->ranges_shrtr_1
[count
][0] || beginIndex
!= multFmtPtr
->ranges_shrtr_1
[count
][1] || endIndex
!= multFmtPtr
->ranges_shrtr_1
[count
][2]) {
674 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",
675 itemPtr
->locale
, multFmtPtr
->measureCount
,
676 multFmtPtr
->ranges_shrtr_1
[count
][0], multFmtPtr
->ranges_shrtr_1
[count
][1], multFmtPtr
->ranges_shrtr_1
[count
][2],
677 field
, beginIndex
, endIndex
);
684 status
= U_ZERO_ERROR
;
685 ugetLen
= uameasfmt_formatMultipleForFields(measfmt_narr_0
, multFmtPtr
->measures
, multFmtPtr
->measureCount
, uget
, kUBufMax
, NULL
, &status
);
686 if ( U_FAILURE(status
) ) {
687 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format narr_0 for measureCount %d, status %s\n",
688 itemPtr
->locale
, multFmtPtr
->measureCount
, u_errorName(status
));
690 uexpLen
= u_unescape(multFmtPtr
->expectFmt_narr_0
, uexp
, kUBufMax
);
691 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
692 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
693 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
694 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format narr_0 for measureCount %d, expected \"%s\", got \"%s\"\n",
695 itemPtr
->locale
, multFmtPtr
->measureCount
, bexp
, bget
);
699 status
= U_ZERO_ERROR
;
700 ugetLen
= uameasfmt_formatMultipleForFields(measfmt_numr_0
, multFmtPtr
->measures
, multFmtPtr
->measureCount
, uget
, kUBufMax
, fpositer
, &status
);
701 if ( U_FAILURE(status
) ) {
702 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format numr_0 for measureCount %d, status %s\n",
703 itemPtr
->locale
, multFmtPtr
->measureCount
, u_errorName(status
));
705 uexpLen
= u_unescape(multFmtPtr
->expectFmt_numr_0
, uexp
, kUBufMax
);
706 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
707 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
708 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
709 log_err("FAIL: uameasfmt_formatMultipleForFields locale %s, multiple format numr_0 for measureCount %d, expected \"%s\", got \"%s\"\n",
710 itemPtr
->locale
, multFmtPtr
->measureCount
, bexp
, bget
);
713 int32_t field
, beginIndex
, endIndex
, count
;
714 for (count
= 0; (field
= ufieldpositer_next(fpositer
, &beginIndex
, &endIndex
)) >= 0; count
++) {
715 if (field
!= multFmtPtr
->ranges_numr_0
[count
][0] || beginIndex
!= multFmtPtr
->ranges_numr_0
[count
][1] || endIndex
!= multFmtPtr
->ranges_numr_0
[count
][2]) {
716 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",
717 itemPtr
->locale
, multFmtPtr
->measureCount
,
718 multFmtPtr
->ranges_numr_0
[count
][0], multFmtPtr
->ranges_numr_0
[count
][1], multFmtPtr
->ranges_numr_0
[count
][2],
719 field
, beginIndex
, endIndex
);
726 ufieldpositer_close(fpositer
);
730 if (itemPtr
->multipleUnitNameTests
!= NULL
) {
731 const MultipleUnitName
* multNamPtr
;
732 for (multNamPtr
= itemPtr
->multipleUnitNameTests
; multNamPtr
->units
!= 0; multNamPtr
++) {
734 status
= U_ZERO_ERROR
;
735 ugetLen
= uameasfmt_getMultipleUnitNames(measfmt_wide_2
, multNamPtr
->units
, multNamPtr
->unitCount
, multNamPtr
->listStyle
, uget
, kUBufMax
, &status
);
736 if ( U_FAILURE(status
) ) {
737 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name wide for unitCount %d, listStyle %d, status %s\n",
738 itemPtr
->locale
, multNamPtr
->unitCount
, multNamPtr
->listStyle
, u_errorName(status
));
740 uexpLen
= u_unescape(multNamPtr
->expectName_wide
, uexp
, kUBufMax
);
741 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
742 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
743 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
744 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name wide for unitCount %d, listStyle %d, expected \"%s\", got \"%s\"\n",
745 itemPtr
->locale
, multNamPtr
->unitCount
, multNamPtr
->listStyle
, bexp
, bget
);
749 status
= U_ZERO_ERROR
;
750 ugetLen
= uameasfmt_getMultipleUnitNames(measfmt_shrt_X
, multNamPtr
->units
, multNamPtr
->unitCount
, multNamPtr
->listStyle
, uget
, kUBufMax
, &status
);
751 if ( U_FAILURE(status
) ) {
752 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name shrt for unitCount %d, listStyle %d, status %s\n",
753 itemPtr
->locale
, multNamPtr
->unitCount
, multNamPtr
->listStyle
, u_errorName(status
));
755 uexpLen
= u_unescape(multNamPtr
->expectName_shrt
, uexp
, kUBufMax
);
756 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
757 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
758 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
759 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name shrt for unitCount %d, listStyle %d, expected \"%s\", got \"%s\"\n",
760 itemPtr
->locale
, multNamPtr
->unitCount
, multNamPtr
->listStyle
, bexp
, bget
);
764 status
= U_ZERO_ERROR
;
765 ugetLen
= uameasfmt_getMultipleUnitNames(measfmt_narr_0
, multNamPtr
->units
, multNamPtr
->unitCount
, multNamPtr
->listStyle
, uget
, kUBufMax
, &status
);
766 if ( U_FAILURE(status
) ) {
767 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name narr for unitCount %d, listStyle %d, status %s\n",
768 itemPtr
->locale
, multNamPtr
->unitCount
, multNamPtr
->listStyle
, u_errorName(status
));
770 uexpLen
= u_unescape(multNamPtr
->expectName_narr
, uexp
, kUBufMax
);
771 if (ugetLen
!= uexpLen
|| u_strcmp(uget
, uexp
) != 0 ) {
772 u_strToUTF8(bexp
, kBBufMax
, NULL
, uexp
, uexpLen
, &status
);
773 u_strToUTF8(bget
, kBBufMax
, NULL
, uget
, ugetLen
, &status
);
774 log_err("FAIL: uameasfmt_getMultipleUnitNames locale %s, multiple name narr for unitCount %d, listStyle %d, expected \"%s\", got \"%s\"\n",
775 itemPtr
->locale
, multNamPtr
->unitCount
, multNamPtr
->listStyle
, bexp
, bget
);
781 uameasfmt_close(measfmt_wide_2
);
782 uameasfmt_close(measfmt_wide_0
);
783 uameasfmt_close(measfmt_shrt_X
);
784 uameasfmt_close(measfmt_shrt_1
);
785 uameasfmt_close(measfmt_shrtr_1
);
786 uameasfmt_close(measfmt_narr_0
);
787 uameasfmt_close(measfmt_numr_0
);
789 unum_close(numfmt_0
);
790 unum_close(numfmt_1
);
791 unum_close(numfmt_2
);
793 /* sleep to check leaks etc */
794 #if U_PLATFORM_IS_DARWIN_BASED || U_PLATFORM_IS_LINUX_BASED || U_PLATFORM == U_PF_BSD || U_PLATFORM == U_PF_SOLARIS
799 static void TestUAMeasFmtOpenAllLocs()
801 int32_t iLoc
, nLoc
= uloc_countAvailable();
802 for (iLoc
= 0; iLoc
<= nLoc
; iLoc
++) {
803 const char *loc
= (iLoc
< nLoc
)? uloc_getAvailable(iLoc
): "xyz" /* something bogus */;
805 UAMeasureFormat
* measfmt
;
808 status
= U_ZERO_ERROR
;
809 measfmt
= uameasfmt_open(loc
, UAMEASFMT_WIDTH_WIDE
, NULL
, &status
);
810 if ( U_SUCCESS(status
) ) {
811 uameasfmt_close(measfmt
);
813 log_data_err("FAIL: uameasfmt_open fails for locale %-10s, width WIDE : %s\n", loc
, u_errorName(status
) );
816 status
= U_ZERO_ERROR
;
817 measfmt
= uameasfmt_open(loc
, UAMEASFMT_WIDTH_SHORT
, NULL
, &status
);
818 if ( U_SUCCESS(status
) ) {
819 uameasfmt_close(measfmt
);
821 log_data_err("FAIL: uameasfmt_open fails for locale %-10s, width SHORT : %s\n", loc
, u_errorName(status
) );
824 status
= U_ZERO_ERROR
;
825 measfmt
= uameasfmt_open(loc
, UAMEASFMT_WIDTH_NARROW
, NULL
, &status
);
826 if ( U_SUCCESS(status
) ) {
827 uameasfmt_close(measfmt
);
829 log_data_err("FAIL: uameasfmt_open fails for locale %-10s, width NARROW : %s\n", loc
, u_errorName(status
) );
833 status
= U_ZERO_ERROR
;
834 measfmt
= uameasfmt_open(loc
, UAMEASFMT_WIDTH_NUMERIC
, NULL
, &status
);
835 if ( U_SUCCESS(status
) ) {
836 uameasfmt_close(measfmt
);
838 log_data_err("FAIL: uameasfmt_open fails for locale %-10s, width NUMERIC: %s\n", loc
, u_errorName(status
) );
844 enum { kMeasureUnitMax
= 3 };
848 const char* category
;
851 UAMeasureUnit units
[kMeasureUnitMax
];
854 static const UnitsForUsageItem unitsForUsageItems
[] = {
855 { "en_US", "length", "person", 1, { UAMEASUNIT_LENGTH_INCH
} },
856 { "en_US", "length", "person-informal", 2, { UAMEASUNIT_LENGTH_FOOT
, UAMEASUNIT_LENGTH_INCH
} },
857 { "en_US", "length", "person-small", 1, { UAMEASUNIT_LENGTH_INCH
} },
858 { "fr_FR", "length", "person", 2, { UAMEASUNIT_LENGTH_METER
, UAMEASUNIT_LENGTH_CENTIMETER
} },
859 { "fr_FR", "length", "person-informal", 2, { UAMEASUNIT_LENGTH_METER
, UAMEASUNIT_LENGTH_CENTIMETER
} },
860 { "fr_FR", "length", "person-small", 1, { UAMEASUNIT_LENGTH_CENTIMETER
} },
861 { "fr_FR@rg=USZZZZ", "length", "person", 1, { UAMEASUNIT_LENGTH_INCH
} },
862 { "fr_FR@rg=USZZZZ", "length", "person-informal", 2, { UAMEASUNIT_LENGTH_FOOT
, UAMEASUNIT_LENGTH_INCH
} },
863 { "fr_FR@rg=USZZZZ", "length", "person-small", 1, { UAMEASUNIT_LENGTH_INCH
} },
864 { "en_IN", "pressure","baromtrc", 1, { UAMEASUNIT_PRESSURE_HECTOPASCAL
} },
865 { "es_MX", "pressure","baromtrc", 1, { UAMEASUNIT_PRESSURE_MILLIMETER_OF_MERCURY
} },
866 { "fr_FR", "pressure","baromtrc", 1, { UAMEASUNIT_PRESSURE_HECTOPASCAL
} },
867 { "pt"/*BR*/, "pressure","baromtrc", 1, { UAMEASUNIT_PRESSURE_MILLIBAR
} },
868 { "en_US", "length", NULL
, 1, { UAMEASUNIT_LENGTH_FOOT
} },
869 { "en_US", "length", "large", 1, { UAMEASUNIT_LENGTH_MILE
} },
870 { "en_US", "length", "small", 1, { UAMEASUNIT_LENGTH_INCH
} },
871 { "fr_FR", "length", NULL
, 1, { UAMEASUNIT_LENGTH_METER
} },
872 { "fr_FR", "length", "large", 1, { UAMEASUNIT_LENGTH_KILOMETER
} },
873 { "fr_FR", "length", "small", 1, { UAMEASUNIT_LENGTH_CENTIMETER
} },
874 { "en_US", "xxxxxxxx","yyyyyyyy", 0, { (UAMeasureUnit
)0 } },
876 { "en_US@ms=metric", "length", "large", 1, { UAMEASUNIT_LENGTH_KILOMETER
} },
877 { "fr_FR@ms=ussystem", "length", "large", 1, { UAMEASUNIT_LENGTH_MILE
} },
878 { "en_GB@ms=metric", "concentr", "blood-glucose", 1, { UAMEASUNIT_CONCENTRATION_MILLIMOLE_PER_LITER
} },
879 { "en_US@ms=uksystem", "mass", "person", 2, { UAMEASUNIT_MASS_STONE
, UAMEASUNIT_MASS_POUND
} },
880 { "fr_FR", "mass", "person", 1, { UAMEASUNIT_MASS_KILOGRAM
} },
881 { "fr_FR@rg=USZZZZ", "mass", "person", 1, { UAMEASUNIT_MASS_POUND
} },
882 { "fr_FR@ms=uksystem;rg=USZZZZ", "mass", "person", 2, { UAMEASUNIT_MASS_STONE
, UAMEASUNIT_MASS_POUND
} },
884 { NULL
, NULL
, NULL
, 0, { (UAMeasureUnit
)0 } }
887 static void TestUAGetUnitsForUsage()
889 const UnitsForUsageItem
* itemPtr
= unitsForUsageItems
;
890 for (; itemPtr
->locale
!= NULL
; itemPtr
++) {
891 UAMeasureUnit units
[kMeasureUnitMax
];
892 UErrorCode status
= U_ZERO_ERROR
;
893 int32_t unitsCount
= uameasfmt_getUnitsForUsage(itemPtr
->locale
, itemPtr
->category
, itemPtr
->usage
,
894 units
, kMeasureUnitMax
, &status
);
895 if ( U_FAILURE(status
) ) {
896 if (itemPtr
->unitCount
!= 0) {
897 log_err("FAIL: uameasfmt_getUnitsForUsage locale %s, category %s-%s, status %s\n",
898 itemPtr
->locale
, itemPtr
->category
, itemPtr
->usage
, u_errorName(status
));
900 } else if (itemPtr
->unitCount
== 0) {
901 log_err("FAIL: uameasfmt_getUnitsForUsage locale %s, category %s-%s, expected failure, got status %s\n",
902 itemPtr
->locale
, itemPtr
->category
, itemPtr
->usage
, u_errorName(status
));
903 } else if (unitsCount
!= itemPtr
->unitCount
) {
904 log_err("FAIL: uameasfmt_getUnitsForUsage locale %s, category %s-%s, expected count %d, got %d\n",
905 itemPtr
->locale
, itemPtr
->category
, itemPtr
->usage
, itemPtr
->unitCount
, unitsCount
);
906 } else if (units
[0] != itemPtr
->units
[0] || (unitsCount
== 2 && units
[1] != itemPtr
->units
[1])) {
907 log_err("FAIL: uameasfmt_getUnitsForUsage locale %s, category %s-%s, expected units x%04X ..., got x%04X ...\n",
908 itemPtr
->locale
, itemPtr
->category
, itemPtr
->usage
, itemPtr
->units
[0], units
[0]);
915 const char* category
;
918 static const CategoryForUnit categoryForUnitItems
[] = {
919 { UAMEASUNIT_VOLUME_LITER
, "volume" },
920 { UAMEASUNIT_LENGTH_METER
, "length" },
921 { UAMEASUNIT_PRESSURE_HECTOPASCAL
, "pressure" },
922 { UAMEASUNIT_CONCENTRATION_MILLIMOLE_PER_LITER
, "concentr" },
923 { (UAMeasureUnit
)0, NULL
}
926 static void TestUAGetCategoryForUnit()
928 const CategoryForUnit
* itemPtr
= categoryForUnitItems
;
929 for (; itemPtr
->category
!= NULL
; itemPtr
++) {
930 UErrorCode status
= U_ZERO_ERROR
;
931 const char *category
= uameasfmt_getUnitCategory(itemPtr
->unit
, &status
);
932 if ( U_FAILURE(status
) ) {
933 log_err("FAIL: uameasfmt_getUnitCategory unit %d:%d, got status %s\n",
934 ((int)itemPtr
->unit
) >> 8, ((int)itemPtr
->unit
) & 0xFF, u_errorName(status
));
935 } else if (category
== NULL
) {
936 log_err("FAIL: uameasfmt_getUnitCategory unit %d:%d, got NULL return\n",
937 ((int)itemPtr
->unit
) >> 8, ((int)itemPtr
->unit
) & 0xFF);
938 } else if (uprv_strcmp(category
, itemPtr
->category
) != 0) {
939 log_err("FAIL: uameasfmt_getUnitCategory unit %d:%d, expected %s, got %s\n",
940 ((int)itemPtr
->unit
) >> 8, ((int)itemPtr
->unit
) & 0xFF, itemPtr
->category
, category
);
945 #endif /* #if !UCONFIG_NO_FORMATTING */