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