diff options
author | Victor Chang <vichang@google.com> | 2022-04-25 09:38:54 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-04-25 09:38:54 +0000 |
commit | eb33baa492d32e77733f632e675548e1fa7fed21 (patch) | |
tree | 23ba6a0c8f20ab03ea66d39926bb447b821c8de5 | |
parent | 8ac0b73d8f35248fbca6acc885771084cca21f4b (diff) | |
parent | 2919e5e2c836e90846fd2cec07fdce939241c8fc (diff) | |
download | icu-eb33baa492d32e77733f632e675548e1fa7fed21.tar.gz |
Cherry-pick: ICU-21875 improve C API coverage am: 2919e5e2c8
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/icu/+/17918903
Change-Id: I1d131b7bb5c447441777f0ccfaeee61068af8948
Ignore-AOSP-First: this is an automerge
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | icu4c/source/test/cintltst/cbiditst.c | 9 | ||||
-rw-r--r-- | icu4c/source/test/cintltst/cloctst.c | 20 | ||||
-rw-r--r-- | icu4c/source/test/cintltst/cnormtst.c | 53 | ||||
-rw-r--r-- | icu4c/source/test/cintltst/utexttst.c | 20 |
4 files changed, 100 insertions, 2 deletions
diff --git a/icu4c/source/test/cintltst/cbiditst.c b/icu4c/source/test/cintltst/cbiditst.c index 6d233130f..38be9c505 100644 --- a/icu4c/source/test/cintltst/cbiditst.c +++ b/icu4c/source/test/cintltst/cbiditst.c @@ -4591,6 +4591,15 @@ testClassOverride(void) { ubidi_close(pBiDi); return; } + // Quick callback test (API coverage). + if (ubidi_getCustomizedClass(pBiDi, u'A')!=AL || + ubidi_getCustomizedClass(pBiDi, u'H')!=R || + ubidi_getCustomizedClass(pBiDi, u'^')!=PDF || + ubidi_getCustomizedClass(pBiDi, u'~')!=BN) { + log_err("ubidi_getCustomizedClass() returns different values than " + "expected from overrideBidiClass() customClasses[]\n"); + } + verifyCallbackParams(oldFn, oldContext, NULL, NULL, 0); ubidi_getClassCallback(pBiDi, &oldFn, &oldContext); diff --git a/icu4c/source/test/cintltst/cloctst.c b/icu4c/source/test/cintltst/cloctst.c index c5f351c88..c8bfce680 100644 --- a/icu4c/source/test/cintltst/cloctst.c +++ b/icu4c/source/test/cintltst/cloctst.c @@ -3207,6 +3207,18 @@ static void TestAcceptLanguage(void) { } } } + + // API coverage + status = U_ZERO_ERROR; + static const char *const supported[] = { "en-US", "en-GB", "de-DE", "ja-JP" }; + const char * desired[] = { "de-LI", "en-IN", "zu", "fr" }; + available = uenum_openCharStringsEnumeration(supported, UPRV_LENGTHOF(supported), &status); + tmp[0]=0; + rc = uloc_acceptLanguage(tmp, 199, &outResult, desired, UPRV_LENGTHOF(desired), available, &status); + if (U_FAILURE(status) || rc != 5 || uprv_strcmp(tmp, "de_DE") != 0 || outResult == ULOC_ACCEPT_FAILED) { + log_err("uloc_acceptLanguage() failed to do a simple match\n"); + } + uenum_close(available); } static const char* LOCALE_ALIAS[][2] = { @@ -7053,6 +7065,14 @@ static void TestUldnNameVariants() { u_errorName(status) ); continue; } + // API coverage: Expect to get back the dialect handling which is + // the first item in the displayOptions test data. + UDialectHandling dh = uldn_getDialectHandling(uldn); + UDisplayContext dhContext = (UDisplayContext)dh; // same numeric values + if (dhContext != uloPtr->displayOptions[0]) { + log_err("uldn_getDialectHandling()=%03X != expected UDisplayContext %03X\n", + dhContext, uloPtr->displayOptions[0]); + } const UldnItem * itemPtr = uloPtr->testItems; int32_t itemCount = uloPtr->countItems; for (; itemCount-- > 0; itemPtr++) { diff --git a/icu4c/source/test/cintltst/cnormtst.c b/icu4c/source/test/cintltst/cnormtst.c index c16f8a628..c7830073b 100644 --- a/icu4c/source/test/cintltst/cnormtst.c +++ b/icu4c/source/test/cintltst/cnormtst.c @@ -65,6 +65,7 @@ TestGetRawDecomposition(void); static void TestAppendRestoreMiddle(void); static void TestGetEasyToUseInstance(void); +static void TestAPICoverage(void); static const char* const canonTests[][3] = { /* Input*/ /*Decomposed*/ /*Composed*/ @@ -156,6 +157,7 @@ void addNormTest(TestNode** root) addTest(root, &TestGetRawDecomposition, "tsnorm/cnormtst/TestGetRawDecomposition"); addTest(root, &TestAppendRestoreMiddle, "tsnorm/cnormtst/TestAppendRestoreMiddle"); addTest(root, &TestGetEasyToUseInstance, "tsnorm/cnormtst/TestGetEasyToUseInstance"); + addTest(root, &TestAPICoverage, "tsnorm/cnormtst/TestAPICoverage"); } static const char* const modeStrings[]={ @@ -1698,4 +1700,55 @@ TestGetEasyToUseInstance() { } } +static void +TestAPICoverage() { + UErrorCode errorCode = U_ZERO_ERROR; + const UNormalizer2 *n2 = unorm2_getNFDInstance(&errorCode); + if (U_FAILURE(errorCode)) { + log_err_status(errorCode, "unorm2_getNFDInstance() failed: %s\n", u_errorName(errorCode)); + return; + } + + if (!unorm2_hasBoundaryBefore(n2, u'C') || unorm2_hasBoundaryBefore(n2, 0x300)) { + log_err("unorm2_hasBoundaryBefore() returns unexpected results\n"); + } + + if (!unorm2_hasBoundaryAfter(n2, u'C') || unorm2_hasBoundaryAfter(n2, 0x300)) { + log_err("unorm2_hasBoundaryAfter() returns unexpected results\n"); + } + + if (!unorm2_isInert(n2, 0x50005) || unorm2_isInert(n2, 0x300)) { + log_err("unorm2_isInert() returns unexpected results\n"); + } + + errorCode = U_ZERO_ERROR; + if (!unorm2_isNormalized(n2, u"c\u0327\u0300", 3, &errorCode) || + unorm2_isNormalized(n2, u"c\u0300\u0327", 3, &errorCode) || + U_FAILURE(errorCode)) { + log_err("unorm2_isNormalized() returns unexpected results\n"); + } + + errorCode = U_ZERO_ERROR; + if (unorm2_quickCheck(n2, u"c\u0327\u0300", 3, &errorCode) == UNORM_NO || + unorm2_quickCheck(n2, u"c\u0300\u0327", 3, &errorCode) == UNORM_YES || + U_FAILURE(errorCode)) { + log_err("unorm2_quickCheck() returns unexpected results\n"); + } + + errorCode = U_ZERO_ERROR; + if (unorm2_spanQuickCheckYes(n2, u"c\u0327\u0300", 3, &errorCode) != 3 || + unorm2_spanQuickCheckYes(n2, u"c\u0300\u0327", 3, &errorCode) != 1 || + U_FAILURE(errorCode)) { + log_err("unorm2_spanQuickCheckYes() returns unexpected results\n"); + } + + errorCode = U_ZERO_ERROR; + UChar first[10] = { u'c', 0x300, 0, 0, 0, 0, 0, 0, 0, 0 }; + int32_t length = unorm2_normalizeSecondAndAppend( + n2, first, 2, UPRV_LENGTHOF(first), u"\u0327d", 2, &errorCode); + if (U_FAILURE(errorCode) || length != 4 || u_strcmp(first, u"c\u0327\u0300d") != 0) { + log_err("unorm2_normalizeSecondAndAppend() returns unexpected results\n"); + } +} + #endif /* #if !UCONFIG_NO_NORMALIZATION */ diff --git a/icu4c/source/test/cintltst/utexttst.c b/icu4c/source/test/cintltst/utexttst.c index 8f3974c90..6ee85c705 100644 --- a/icu4c/source/test/cintltst/utexttst.c +++ b/icu4c/source/test/cintltst/utexttst.c @@ -292,6 +292,22 @@ static void TestAPI(void) { utext_close(uta); } - + { + // utext_equals() checks for the same type of text provider, + // same string pointer(!), and same index. + status = U_ZERO_ERROR; + const UChar *s = u"aßカ🚲"; + UText *ut1 = utext_openUChars(NULL, s, -1, &status); + UText *ut2 = utext_openUChars(NULL, s, 5, &status); + TEST_SUCCESS(status); + TEST_ASSERT(utext_equals(ut1, ut2)); + UChar32 c = utext_next32(ut1); + TEST_ASSERT(c == u'a'); + TEST_ASSERT(!utext_equals(ut1, ut2)); // indexes out of sync + c = utext_next32(ut2); + TEST_ASSERT(c == u'a'); + TEST_ASSERT(utext_equals(ut1, ut2)); // back in sync + utext_close(ut1); + utext_close(ut2); + } } - |