diff options
Diffstat (limited to 'Build/source/libs/icu/icu-src/source/test/cintltst/ulistfmttest.c')
-rw-r--r-- | Build/source/libs/icu/icu-src/source/test/cintltst/ulistfmttest.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/Build/source/libs/icu/icu-src/source/test/cintltst/ulistfmttest.c b/Build/source/libs/icu/icu-src/source/test/cintltst/ulistfmttest.c index 7fe549f43ba..b0a1f6bc349 100644 --- a/Build/source/libs/icu/icu-src/source/test/cintltst/ulistfmttest.c +++ b/Build/source/libs/icu/icu-src/source/test/cintltst/ulistfmttest.c @@ -20,6 +20,8 @@ static void TestUListFmt(void); static void TestUListFmtToValue(void); static void TestUListOpenStyled(void); +static void TestUList21871_A(void); +static void TestUList21871_B(void); void addUListFmtTest(TestNode** root); @@ -30,6 +32,8 @@ void addUListFmtTest(TestNode** root) TESTCASE(TestUListFmt); TESTCASE(TestUListFmtToValue); TESTCASE(TestUListOpenStyled); + TESTCASE(TestUList21871_A); + TESTCASE(TestUList21871_B); } static const UChar str0[] = { 0x41,0 }; /* "A" */ @@ -250,5 +254,103 @@ static void TestUListOpenStyled() { ulistfmt_closeResult(fl); } +#include <stdio.h> + +static void TestUList21871_A() { + UErrorCode status = U_ZERO_ERROR; + UListFormatter *fmt = ulistfmt_openForType("en", ULISTFMT_TYPE_AND, ULISTFMT_WIDTH_WIDE, &status); + assertSuccess("ulistfmt_openForType", &status); + + const UChar *strs[] = {u"A", u""}; + const int32_t lens[] = {1, 0}; + + UFormattedList *fl = ulistfmt_openResult(&status); + assertSuccess("ulistfmt_openResult", &status); + + ulistfmt_formatStringsToResult(fmt, strs, lens, 2, fl, &status); + assertSuccess("ulistfmt_formatStringsToResult", &status); + + const UFormattedValue *value = ulistfmt_resultAsValue(fl, &status); + assertSuccess("ulistfmt_resultAsValue", &status); + + { + int32_t len; + const UChar *str = ufmtval_getString(value, &len, &status); + assertUEquals("TEST ufmtval_getString", u"A and ", str); + } + + UConstrainedFieldPosition *fpos = ucfpos_open(&status); + assertSuccess("ucfpos_open", &status); + + ucfpos_constrainField(fpos, UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, &status); + assertSuccess("ucfpos_constrainField", &status); + + bool hasMore = ufmtval_nextPosition(value, fpos, &status); + assertSuccess("ufmtval_nextPosition", &status); + assertTrue("hasMore 1", hasMore); + + int32_t beginIndex, endIndex; + ucfpos_getIndexes(fpos, &beginIndex, &endIndex, &status); + assertSuccess("ufmtval_nextPosition", &status); + assertIntEquals("TEST beginIndex", 0, beginIndex); + assertIntEquals("TEST endIndex", 1, endIndex); + + hasMore = ufmtval_nextPosition(value, fpos, &status); + assertSuccess("ufmtval_nextPosition", &status); + assertTrue("hasMore 2", !hasMore); + + ucfpos_close(fpos); + ulistfmt_closeResult(fl); + ulistfmt_close(fmt); +} + +static void TestUList21871_B() { + UErrorCode status = U_ZERO_ERROR; + UListFormatter *fmt = ulistfmt_openForType("en", ULISTFMT_TYPE_AND, ULISTFMT_WIDTH_WIDE, &status); + assertSuccess("ulistfmt_openForType", &status); + + const UChar *strs[] = {u"", u"B"}; + const int32_t lens[] = {0, 1}; + + UFormattedList *fl = ulistfmt_openResult(&status); + assertSuccess("ulistfmt_openResult", &status); + + ulistfmt_formatStringsToResult(fmt, strs, lens, 2, fl, &status); + assertSuccess("ulistfmt_formatStringsToResult", &status); + + const UFormattedValue *value = ulistfmt_resultAsValue(fl, &status); + assertSuccess("ulistfmt_resultAsValue", &status); + + { + int32_t len; + const UChar *str = ufmtval_getString(value, &len, &status); + assertUEquals("TEST ufmtval_getString", u" and B", str); + } + + UConstrainedFieldPosition *fpos = ucfpos_open(&status); + assertSuccess("ucfpos_open", &status); + + ucfpos_constrainField(fpos, UFIELD_CATEGORY_LIST, ULISTFMT_ELEMENT_FIELD, &status); + assertSuccess("ucfpos_constrainField", &status); + + bool hasMore = ufmtval_nextPosition(value, fpos, &status); + assertSuccess("ufmtval_nextPosition", &status); + assertTrue("hasMore 1", hasMore); + + int32_t beginIndex, endIndex; + ucfpos_getIndexes(fpos, &beginIndex, &endIndex, &status); + assertSuccess("ucfpos_getIndexes", &status); + assertIntEquals("TEST beginIndex", 5, beginIndex); + assertIntEquals("TEST endIndex", 6, endIndex); + + hasMore = ufmtval_nextPosition(value, fpos, &status); + assertSuccess("ufmtval_nextPosition", &status); + assertTrue("hasMore 2", !hasMore); + + ucfpos_close(fpos); + ulistfmt_closeResult(fl); + ulistfmt_close(fmt); +} + #endif /* #if !UCONFIG_NO_FORMATTING */ |