1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 *
6 * Copyright (C) 2012-2016, International Business Machines
7 * Corporation and others. All Rights Reserved.
8 *
9 *******************************************************************************
10 * file name: listformattertest.cpp
11 * encoding: UTF-8
12 * tab size: 8 (not used)
13 * indentation:4
14 *
15 * created on: 2012aug27
16 * created by: Umesh P. Nair
17 */
18
19 #include "listformattertest.h"
20 #include "unicode/ulistformatter.h"
21 #include <string.h>
22
23 #if !UCONFIG_NO_FORMATTING
24
25 namespace {
attrString(int32_t attrId)26 const char* attrString(int32_t attrId) {
27 switch (attrId) {
28 case ULISTFMT_LITERAL_FIELD: return "literal";
29 case ULISTFMT_ELEMENT_FIELD: return "element";
30 default: return "xxx";
31 }
32 }
33 } // namespace
34
ExpectPositions(FieldPositionIterator & iter,int32_t * values,int32_t tupleCount)35 void ListFormatterTest::ExpectPositions(FieldPositionIterator& iter,
36 int32_t *values, int32_t tupleCount) {
37 UBool found[10];
38 FieldPosition fp;
39 if (tupleCount > 10) {
40 assertTrue("internal error, tupleCount too large", FALSE);
41 } else {
42 for (int i = 0; i < tupleCount; ++i) {
43 found[i] = FALSE;
44 }
45 }
46 while (iter.next(fp)) {
47 UBool ok = FALSE;
48 int32_t id = fp.getField();
49 int32_t start = fp.getBeginIndex();
50 int32_t limit = fp.getEndIndex();
51 char buf[128];
52 sprintf(buf, "%24s %3d %3d %3d", attrString(id), id, start, limit);
53 logln(buf);
54 for (int i = 0; i < tupleCount; ++i) {
55 if (found[i]) {
56 continue;
57 }
58 if (values[i*3] == id && values[i*3+1] == start && values[i*3+2] == limit) {
59 found[i] = ok = TRUE;
60 break;
61 }
62 }
63 assertTrue((UnicodeString)"found [" + attrString(id) + "," + start + "," + limit + "]", ok);
64 }
65 // check that all were found
66 UBool ok = TRUE;
67 for (int i = 0; i < tupleCount; ++i) {
68 if (!found[i]) {
69 ok = FALSE;
70 assertTrue((UnicodeString) "missing [" + attrString(values[i*3]) + "," + values[i*3+1] +
71 "," + values[i*3+2] + "]", found[i]);
72 }
73 }
74 assertTrue("no expected values were missing", ok);
75 }
76
ListFormatterTest()77 ListFormatterTest::ListFormatterTest() :
78 prefix("Prefix: ", -1, US_INV),
79 one("Alice", -1, US_INV), two("Bob", -1, US_INV),
80 three("Charlie", -1, US_INV), four("Delta", -1, US_INV) {
81 }
82
CheckFormatting(const ListFormatter * formatter,UnicodeString data[],int32_t dataSize,const UnicodeString & expected_result,const char * testName)83 void ListFormatterTest::CheckFormatting(const ListFormatter* formatter, UnicodeString data[], int32_t dataSize,
84 const UnicodeString& expected_result, const char* testName) {
85 UnicodeString actualResult(prefix);
86 IcuTestErrorCode errorCode(*this, testName);
87 formatter->format(data, dataSize, actualResult, errorCode);
88 UnicodeString expectedStringWithPrefix = prefix + expected_result;
89 if (expectedStringWithPrefix != actualResult) {
90 errln(UnicodeString("Expected: |") + expectedStringWithPrefix + "|, Actual: |" + actualResult + "|");
91 }
92 }
93
CheckFourCases(const char * locale_string,UnicodeString one,UnicodeString two,UnicodeString three,UnicodeString four,UnicodeString results[4],const char * testName)94 void ListFormatterTest::CheckFourCases(const char* locale_string, UnicodeString one, UnicodeString two,
95 UnicodeString three, UnicodeString four, UnicodeString results[4], const char* testName) {
96 IcuTestErrorCode errorCode(*this, testName);
97 LocalPointer<ListFormatter> formatter(ListFormatter::createInstance(Locale(locale_string), errorCode));
98 if (U_FAILURE(errorCode)) {
99 dataerrln("ListFormatter::createInstance(Locale(\"%s\"), errorCode) failed in CheckFourCases: %s", locale_string, u_errorName(errorCode));
100 return;
101 }
102 UnicodeString input1[] = {one};
103 CheckFormatting(formatter.getAlias(), input1, 1, results[0], testName);
104
105 UnicodeString input2[] = {one, two};
106 CheckFormatting(formatter.getAlias(), input2, 2, results[1], testName);
107
108 UnicodeString input3[] = {one, two, three};
109 CheckFormatting(formatter.getAlias(), input3, 3, results[2], testName);
110
111 UnicodeString input4[] = {one, two, three, four};
112 CheckFormatting(formatter.getAlias(), input4, 4, results[3], testName);
113 }
114
RecordFourCases(const Locale & locale,UnicodeString one,UnicodeString two,UnicodeString three,UnicodeString four,UnicodeString results[4],const char * testName)115 UBool ListFormatterTest::RecordFourCases(const Locale& locale, UnicodeString one, UnicodeString two,
116 UnicodeString three, UnicodeString four, UnicodeString results[4], const char* testName) {
117 IcuTestErrorCode errorCode(*this, testName);
118 LocalPointer<ListFormatter> formatter(ListFormatter::createInstance(locale, errorCode));
119 if (U_FAILURE(errorCode)) {
120 dataerrln("ListFormatter::createInstance(\"%s\", errorCode) failed in RecordFourCases: %s", locale.getName(), u_errorName(errorCode));
121 return FALSE;
122 }
123 UnicodeString input1[] = {one};
124 formatter->format(input1, 1, results[0], errorCode);
125 UnicodeString input2[] = {one, two};
126 formatter->format(input2, 2, results[1], errorCode);
127 UnicodeString input3[] = {one, two, three};
128 formatter->format(input3, 3, results[2], errorCode);
129 UnicodeString input4[] = {one, two, three, four};
130 formatter->format(input4, 4, results[3], errorCode);
131 if (U_FAILURE(errorCode)) {
132 errln("RecordFourCases failed: %s", u_errorName(errorCode));
133 return FALSE;
134 }
135 return TRUE;
136 }
137
TestRoot()138 void ListFormatterTest::TestRoot() {
139 UnicodeString results[4] = {
140 one,
141 one + ", " + two,
142 one + ", " + two + ", " + three,
143 one + ", " + two + ", " + three + ", " + four
144 };
145
146 CheckFourCases("", one, two, three, four, results, "TestRoot()");
147 }
148
149 // Bogus locale should fallback to root.
TestBogus()150 void ListFormatterTest::TestBogus() {
151 UnicodeString results[4];
152 if (RecordFourCases(Locale::getDefault(), one, two, three, four, results, "TestBogus()")) {
153 CheckFourCases("ex_PY", one, two, three, four, results, "TestBogus()");
154 }
155 }
156
157 // Formatting in English.
158 // "and" is used before the last element, and all elements up to (and including) the penultimate are followed by a comma.
TestEnglish()159 void ListFormatterTest::TestEnglish() {
160 UnicodeString results[4] = {
161 one,
162 one + " and " + two,
163 one + ", " + two + ", and " + three,
164 one + ", " + two + ", " + three + ", and " + four
165 };
166
167 CheckFourCases("en", one, two, three, four, results, "TestEnglish()");
168 }
169
Test9946()170 void ListFormatterTest::Test9946() {
171 IcuTestErrorCode errorCode(*this, "Test9946()");
172 LocalPointer<ListFormatter> formatter(ListFormatter::createInstance(Locale("en"), errorCode));
173 if (U_FAILURE(errorCode)) {
174 dataerrln(
175 "ListFormatter::createInstance(Locale(\"en\"), errorCode) failed in Test9946: %s",
176 u_errorName(errorCode));
177 return;
178 }
179 UnicodeString data[3] = {"{0}", "{1}", "{2}"};
180 UnicodeString actualResult;
181 formatter->format(data, 3, actualResult, errorCode);
182 if (U_FAILURE(errorCode)) {
183 dataerrln(
184 "ListFormatter::createInstance(Locale(\"en\"), errorCode) failed in Test9946: %s",
185 u_errorName(errorCode));
186 return;
187 }
188 UnicodeString expected("{0}, {1}, and {2}");
189 if (expected != actualResult) {
190 errln("Expected " + expected + ", got " + actualResult);
191 }
192 }
193
TestEnglishUS()194 void ListFormatterTest::TestEnglishUS() {
195 UnicodeString results[4] = {
196 one,
197 one + " and " + two,
198 one + ", " + two + ", and " + three,
199 one + ", " + two + ", " + three + ", and " + four
200 };
201
202 CheckFourCases("en_US", one, two, three, four, results, "TestEnglishUS()");
203 }
204
205 // Tests resource loading and inheritance when region sublocale
206 // has only partial data for the listPattern element (overriding
207 // some of the parent data). #12994
TestEnglishGB()208 void ListFormatterTest::TestEnglishGB() {
209 UnicodeString results[4] = {
210 one,
211 one + " and " + two,
212 one + ", " + two + " and " + three,
213 one + ", " + two + ", " + three + " and " + four
214 };
215
216 CheckFourCases("en_GB", one, two, three, four, results, "TestEnglishGB()");
217 }
218
TestFieldPositionIteratorWontCrash()219 void ListFormatterTest::TestFieldPositionIteratorWontCrash() {
220 IcuTestErrorCode errorCode(*this, "TestFieldPositionIteratorWontCrash()");
221 LocalPointer<ListFormatter> formatter(
222 ListFormatter::createInstance(Locale("en"), errorCode));
223 if (U_FAILURE(errorCode)) {
224 dataerrln(
225 "ListFormatter::createInstance(Locale(\"en\"), errorCode) failed in "
226 "TestFieldPositionIteratorWontCrash: %s",
227 u_errorName(errorCode));
228 return;
229 }
230 UnicodeString data[3] = {"a", "bbb", "cc"};
231 UnicodeString actualResult;
232 // make sure NULL as FieldPositionIterator won't caused crash.
233 formatter->format(data, 3, actualResult, nullptr, errorCode);
234 if (U_FAILURE(errorCode)) {
235 dataerrln(
236 "ListFormatter::format(data, 3, nullptr, errorCode) "
237 "failed in TestFieldPositionIteratorWontCrash: %s",
238 u_errorName(errorCode));
239 return;
240 }
241 }
242
RunTestFieldPositionIteratorWithFormatter(ListFormatter * formatter,UnicodeString data[],int32_t n,int32_t expected[],int32_t tupleCount,UnicodeString & appendTo,const char16_t * expectedFormatted,const char * testName)243 void ListFormatterTest::RunTestFieldPositionIteratorWithFormatter(
244 ListFormatter* formatter,
245 UnicodeString data[], int32_t n, int32_t expected[], int32_t tupleCount,
246 UnicodeString& appendTo, const char16_t *expectedFormatted,
247 const char* testName) {
248 IcuTestErrorCode errorCode(*this, testName);
249 FieldPositionIterator iter;
250 formatter->format(data, n, appendTo, &iter, errorCode);
251 if (U_FAILURE(errorCode)) {
252 dataerrln(
253 "ListFormatter::format(data, %d, &iter, errorCode) "
254 "failed in %s: %s", n, testName, u_errorName(errorCode));
255 return;
256 }
257 if (appendTo != expectedFormatted) {
258 errln(UnicodeString("Expected: |") + expectedFormatted + "|, Actual: |" + appendTo + "|");
259 }
260 ExpectPositions(iter, expected, tupleCount);
261 }
262
RunTestFieldPositionIteratorWithNItemsPatternShift(UnicodeString data[],int32_t n,int32_t expected[],int32_t tupleCount,UnicodeString & appendTo,const char16_t * expectedFormatted,const char * testName)263 void ListFormatterTest::RunTestFieldPositionIteratorWithNItemsPatternShift(
264 UnicodeString data[], int32_t n, int32_t expected[], int32_t tupleCount,
265 UnicodeString& appendTo, const char16_t *expectedFormatted,
266 const char* testName) {
267 IcuTestErrorCode errorCode(*this, testName);
268 LocalPointer<ListFormatter> formatter(
269 ListFormatter::createInstance(Locale("ur", "IN"), "unit-narrow", errorCode));
270 if (U_FAILURE(errorCode)) {
271 dataerrln(
272 "ListFormatter::createInstance(Locale(\"ur\", \"IN\"), \"unit-narrow\", errorCode) failed in "
273 "%s: %s", testName, u_errorName(errorCode));
274 return;
275 }
276 RunTestFieldPositionIteratorWithFormatter(
277 formatter.getAlias(),
278 data, n, expected, tupleCount, appendTo, expectedFormatted, testName);
279 }
280
RunTestFieldPositionIteratorWithNItems(UnicodeString data[],int32_t n,int32_t expected[],int32_t tupleCount,UnicodeString & appendTo,const char16_t * expectedFormatted,const char * testName)281 void ListFormatterTest::RunTestFieldPositionIteratorWithNItems(
282 UnicodeString data[], int32_t n, int32_t expected[], int32_t tupleCount,
283 UnicodeString& appendTo, const char16_t *expectedFormatted,
284 const char* testName) {
285 IcuTestErrorCode errorCode(*this, testName);
286 LocalPointer<ListFormatter> formatter(
287 ListFormatter::createInstance(Locale("en"), errorCode));
288 if (U_FAILURE(errorCode)) {
289 dataerrln(
290 "ListFormatter::createInstance(Locale(\"en\"), errorCode) failed in "
291 "%s: %s", testName, u_errorName(errorCode));
292 return;
293 }
294 RunTestFieldPositionIteratorWithFormatter(
295 formatter.getAlias(),
296 data, n, expected, tupleCount, appendTo, expectedFormatted, testName);
297 }
298
TestFieldPositionIteratorWith3ItemsAndDataBefore()299 void ListFormatterTest::TestFieldPositionIteratorWith3ItemsAndDataBefore() {
300 // 0 1 2
301 // 0123456789012345678901234567
302 // "Hello World: a, bbb, and cc"
303 UnicodeString data[3] = {"a", "bbb", "cc"};
304 int32_t expected[] = {
305 ULISTFMT_ELEMENT_FIELD, 13, 14,
306 ULISTFMT_LITERAL_FIELD, 14, 16,
307 ULISTFMT_ELEMENT_FIELD, 16, 19,
308 ULISTFMT_LITERAL_FIELD, 19, 25,
309 ULISTFMT_ELEMENT_FIELD, 25, 27
310 };
311 int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
312 UnicodeString appendTo(u"Hello World: ");
313 RunTestFieldPositionIteratorWithNItems(
314 data, 3, expected, tupleCount, appendTo,
315 u"Hello World: a, bbb, and cc",
316 "TestFieldPositionIteratorWith3ItemsAndDataBefore");
317 }
318
TestFieldPositionIteratorWith3Items()319 void ListFormatterTest::TestFieldPositionIteratorWith3Items() {
320 // 0 1
321 // 012345678901234
322 // "a, bbb, and cc"
323 UnicodeString data[3] = {"a", "bbb", "cc"};
324 int32_t expected[] = {
325 ULISTFMT_ELEMENT_FIELD, 0, 1,
326 ULISTFMT_LITERAL_FIELD, 1, 3,
327 ULISTFMT_ELEMENT_FIELD, 3, 6,
328 ULISTFMT_LITERAL_FIELD, 6, 12,
329 ULISTFMT_ELEMENT_FIELD, 12, 14
330 };
331 int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
332 UnicodeString appendTo;
333 RunTestFieldPositionIteratorWithNItems(
334 data, 3, expected, tupleCount, appendTo,
335 u"a, bbb, and cc",
336 "TestFieldPositionIteratorWith3Items");
337 }
338
TestFieldPositionIteratorWith3ItemsPatternShift()339 void ListFormatterTest::TestFieldPositionIteratorWith3ItemsPatternShift() {
340 // 0 1
341 // 012345678901234
342 // "cc bbb a"
343 UnicodeString data[3] = {"a", "bbb", "cc"};
344 int32_t expected[] = {
345 ULISTFMT_ELEMENT_FIELD, 7, 8,
346 ULISTFMT_LITERAL_FIELD, 6, 7,
347 ULISTFMT_ELEMENT_FIELD, 3, 6,
348 ULISTFMT_LITERAL_FIELD, 2, 3,
349 ULISTFMT_ELEMENT_FIELD, 0, 2
350 };
351 int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
352 UnicodeString appendTo;
353 RunTestFieldPositionIteratorWithNItemsPatternShift(
354 data, 3, expected, tupleCount, appendTo,
355 u"cc bbb a",
356 "TestFieldPositionIteratorWith3ItemsPatternShift");
357 }
358
TestFieldPositionIteratorWith2ItemsAndDataBefore()359 void ListFormatterTest::TestFieldPositionIteratorWith2ItemsAndDataBefore() {
360 // 0 1
361 // 0123456789012345
362 // "Foo: bbb and cc"
363 UnicodeString data[2] = {"bbb", "cc"};
364 int32_t expected[] = {
365 ULISTFMT_ELEMENT_FIELD, 5, 8,
366 ULISTFMT_LITERAL_FIELD, 8, 13,
367 ULISTFMT_ELEMENT_FIELD, 13, 15
368 };
369 int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
370 UnicodeString appendTo("Foo: ");
371 RunTestFieldPositionIteratorWithNItems(
372 data, 2, expected, tupleCount, appendTo,
373 u"Foo: bbb and cc",
374 "TestFieldPositionIteratorWith2ItemsAndDataBefore");
375 }
376
TestFieldPositionIteratorWith2Items()377 void ListFormatterTest::TestFieldPositionIteratorWith2Items() {
378 // 0 1
379 // 01234567890
380 // "bbb and cc"
381 UnicodeString data[2] = {"bbb", "cc"};
382 int32_t expected[] = {
383 ULISTFMT_ELEMENT_FIELD, 0, 3,
384 ULISTFMT_LITERAL_FIELD, 3, 8,
385 ULISTFMT_ELEMENT_FIELD, 8, 10
386 };
387 int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
388 UnicodeString appendTo;
389 RunTestFieldPositionIteratorWithNItems(
390 data, 2, expected, tupleCount, appendTo,
391 u"bbb and cc",
392 "TestFieldPositionIteratorWith2Items");
393 }
394
TestFieldPositionIteratorWith2ItemsPatternShift()395 void ListFormatterTest::TestFieldPositionIteratorWith2ItemsPatternShift() {
396 // 0 1
397 // 01234567890
398 // "cc bbb"
399 UnicodeString data[2] = {"bbb", "cc"};
400 int32_t expected[] = {
401 ULISTFMT_ELEMENT_FIELD, 3, 6,
402 ULISTFMT_LITERAL_FIELD, 2, 3,
403 ULISTFMT_ELEMENT_FIELD, 0, 2
404 };
405 int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
406 UnicodeString appendTo;
407 RunTestFieldPositionIteratorWithNItemsPatternShift(
408 data, 2, expected, tupleCount, appendTo,
409 u"cc bbb",
410 "TestFieldPositionIteratorWith2ItemsPatternShift");
411 }
412
TestFieldPositionIteratorWith1ItemAndDataBefore()413 void ListFormatterTest::TestFieldPositionIteratorWith1ItemAndDataBefore() {
414 // 012345678
415 // "Hello cc"
416 UnicodeString data[1] = {"cc"};
417 int32_t expected[] = {
418 ULISTFMT_ELEMENT_FIELD, 6, 8
419 };
420 int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
421 UnicodeString appendTo("Hello ");
422 RunTestFieldPositionIteratorWithNItems(
423 data, 1, expected, tupleCount, appendTo,
424 u"Hello cc",
425 "TestFieldPositionIteratorWith1ItemAndDataBefore");
426 }
427
TestFieldPositionIteratorWith1Item()428 void ListFormatterTest::TestFieldPositionIteratorWith1Item() {
429 // 012
430 // "cc"
431 UnicodeString data[1] = {"cc"};
432 int32_t expected[] = {
433 ULISTFMT_ELEMENT_FIELD, 0, 2
434 };
435 int32_t tupleCount = sizeof(expected)/(3 * sizeof(*expected));
436 UnicodeString appendTo;
437 RunTestFieldPositionIteratorWithNItems(
438 data, 1, expected, tupleCount, appendTo,
439 u"cc",
440 "TestFieldPositionIteratorWith1Item");
441 }
442
443 // Tests resource loading and inheritance when region sublocale
444 // has only partial data for the listPattern element (overriding
445 // some of the parent data). #12994
TestNynorsk()446 void ListFormatterTest::TestNynorsk() {
447 UnicodeString results[4] = {
448 one,
449 one + " og " + two,
450 one + ", " + two + " og " + three,
451 one + ", " + two + ", " + three + " og " + four
452 };
453
454 CheckFourCases("nn", one, two, three, four, results, "TestNynorsk()");
455 }
456
457 // Tests resource loading and inheritance when region sublocale
458 // has only partial data for the listPattern element (overriding
459 // some of the parent data). #12994
TestChineseTradHK()460 void ListFormatterTest::TestChineseTradHK() {
461 UnicodeString and_string = UnicodeString("\\u53CA", -1, US_INV).unescape();
462 UnicodeString comma_string = UnicodeString("\\u3001", -1, US_INV).unescape();
463 UnicodeString results[4] = {
464 one,
465 one + and_string + two,
466 one + comma_string + two + and_string + three,
467 one + comma_string + two + comma_string + three + and_string + four
468 };
469
470 CheckFourCases("zh_Hant_HK", one, two, three, four, results, "TestChineseTradHK()");
471 }
472
473 // Formatting in Russian.
474 // "\\u0438" is used before the last element, and all elements up to (but not including) the penultimate are followed by a comma.
TestRussian()475 void ListFormatterTest::TestRussian() {
476 UnicodeString and_string = UnicodeString(" \\u0438 ", -1, US_INV).unescape();
477 UnicodeString results[4] = {
478 one,
479 one + and_string + two,
480 one + ", " + two + and_string + three,
481 one + ", " + two + ", " + three + and_string + four
482 };
483
484 CheckFourCases("ru", one, two, three, four, results, "TestRussian()");
485 }
486
487 // Formatting in Malayalam.
488 // For two elements, "\\u0d15\\u0d42\\u0d1f\\u0d3e\\u0d24\\u0d46" is inserted in between.
489 // For more than two elements, comma is inserted between all elements up to (and including) the penultimate,
490 // and the word \\u0d0e\\u0d28\\u0d4d\\u0d28\\u0d3f\\u0d35 is inserted in the end.
TestMalayalam()491 void ListFormatterTest::TestMalayalam() {
492 UnicodeString pair_string = UnicodeString(" \\u0d15\\u0d42\\u0d1f\\u0d3e\\u0d24\\u0d46 ", -1, US_INV).unescape();
493 UnicodeString total_string = UnicodeString(" \\u0d0e\\u0d28\\u0d4d\\u0d28\\u0d3f\\u0d35", -1, US_INV).unescape();
494 UnicodeString results[4] = {
495 one,
496 one + pair_string + two,
497 one + ", " + two + ", " + three + total_string,
498 one + ", " + two + ", " + three + ", " + four + total_string
499 };
500
501 CheckFourCases("ml", one, two, three, four, results, "TestMalayalam()");
502 }
503
504 // Formatting in Zulu.
505 // "and" is used before the last element, and all elements up to (and including) the penultimate are followed by a comma.
TestZulu()506 void ListFormatterTest::TestZulu() {
507 UnicodeString results[4] = {
508 one,
509 one + " ne-" + two,
510 one + ", " + two + ", ne-" + three,
511 one + ", " + two + ", " + three + ", ne-" + four
512 };
513
514 CheckFourCases("zu", one, two, three, four, results, "TestZulu()");
515 }
516
TestOutOfOrderPatterns()517 void ListFormatterTest::TestOutOfOrderPatterns() {
518 UnicodeString results[4] = {
519 one,
520 two + " after " + one,
521 three + " in the last after " + two + " after the first " + one,
522 four + " in the last after " + three + " after " + two + " after the first " + one
523 };
524
525 IcuTestErrorCode errorCode(*this, "TestOutOfOrderPatterns()");
526 ListFormatData data("{1} after {0}", "{1} after the first {0}",
527 "{1} after {0}", "{1} in the last after {0}");
528 ListFormatter formatter(data, errorCode);
529
530 UnicodeString input1[] = {one};
531 CheckFormatting(&formatter, input1, 1, results[0], "TestOutOfOrderPatterns()");
532
533 UnicodeString input2[] = {one, two};
534 CheckFormatting(&formatter, input2, 2, results[1], "TestOutOfOrderPatterns()");
535
536 UnicodeString input3[] = {one, two, three};
537 CheckFormatting(&formatter, input3, 3, results[2], "TestOutOfOrderPatterns()");
538
539 UnicodeString input4[] = {one, two, three, four};
540 CheckFormatting(&formatter, input4, 4, results[3], "TestOutOfOrderPatterns()");
541 }
542
runIndexedTest(int32_t index,UBool exec,const char * & name,char *)543 void ListFormatterTest::runIndexedTest(int32_t index, UBool exec,
544 const char* &name, char* /*par */) {
545 switch(index) {
546 case 0: name = "TestRoot"; if (exec) TestRoot(); break;
547 case 1: name = "TestBogus"; if (exec) TestBogus(); break;
548 case 2: name = "TestEnglish"; if (exec) TestEnglish(); break;
549 case 3: name = "TestEnglishUS"; if (exec) TestEnglishUS(); break;
550 case 4: name = "TestRussian"; if (exec) TestRussian(); break;
551 case 5: name = "TestMalayalam"; if (exec) TestMalayalam(); break;
552 case 6: name = "TestZulu"; if (exec) TestZulu(); break;
553 case 7: name = "TestOutOfOrderPatterns"; if (exec) TestOutOfOrderPatterns(); break;
554 case 8: name = "Test9946"; if (exec) Test9946(); break;
555 case 9: name = "TestEnglishGB"; if (exec) TestEnglishGB(); break;
556 case 10: name = "TestNynorsk"; if (exec) TestNynorsk(); break;
557 case 11: name = "TestChineseTradHK"; if (exec) TestChineseTradHK(); break;
558 case 12: name = "TestFieldPositionIteratorWontCrash";
559 if (exec) TestFieldPositionIteratorWontCrash();
560 break;
561 case 13: name = "TestFieldPositionIteratorWith1Item";
562 if (exec) TestFieldPositionIteratorWith1Item();
563 break;
564 case 14: name = "TestFieldPositionIteratorWith1ItemAndDataBefore";
565 if (exec) TestFieldPositionIteratorWith1ItemAndDataBefore();
566 break;
567 case 15: name = "TestFieldPositionIteratorWith2Items";
568 if (exec) TestFieldPositionIteratorWith2Items();
569 break;
570 case 16: name = "TestFieldPositionIteratorWith2ItemsAndDataBefore";
571 if (exec) TestFieldPositionIteratorWith2ItemsAndDataBefore();
572 break;
573 case 17: name = "TestFieldPositionIteratorWith2ItemsPatternShift";
574 if (exec) TestFieldPositionIteratorWith2ItemsPatternShift();
575 break;
576 case 18: name = "TestFieldPositionIteratorWith3Items";
577 if (exec) TestFieldPositionIteratorWith3Items();
578 break;
579 case 19: name = "TestFieldPositionIteratorWith3ItemsAndDataBefore";
580 if (exec) TestFieldPositionIteratorWith3ItemsAndDataBefore();
581 break;
582 case 20: name = "TestFieldPositionIteratorWith3ItemsPatternShift";
583 if (exec) TestFieldPositionIteratorWith3ItemsPatternShift();
584 break;
585 default: name = ""; break;
586 }
587 }
588
589 #endif /* #if !UCONFIG_NO_FORMATTING */
590