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