diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-04-26 01:13:49 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-04-26 01:13:49 +0000 |
commit | d9b67dc833ef96a4507bc6102cf90cba2dd83365 (patch) | |
tree | 07390a9491962832ee93fdd42bcc900111f3c2dd | |
parent | a0b636f2b21b856c7a665975c954cbc71189d925 (diff) | |
parent | 125b1f9e4d0443709bd3f2ec808bd6b5d3dbde01 (diff) | |
download | icu-android-security-13.0.0_r4.tar.gz |
Snap for 8498890 from 125b1f9e4d0443709bd3f2ec808bd6b5d3dbde01 to tm-releaseandroid-vts-13.0_r1android-security-13.0.0_r9android-security-13.0.0_r8android-security-13.0.0_r7android-security-13.0.0_r6android-security-13.0.0_r5android-security-13.0.0_r4android-security-13.0.0_r3android-security-13.0.0_r2android-security-13.0.0_r18android-security-13.0.0_r17android-security-13.0.0_r16android-security-13.0.0_r15android-security-13.0.0_r14android-security-13.0.0_r13android-security-13.0.0_r12android-security-13.0.0_r11android-security-13.0.0_r10android-security-13.0.0_r1android-platform-13.0.0_r2android-platform-13.0.0_r1android-cts-13.0_r1android-13.0.0_r8android-13.0.0_r7android-13.0.0_r6android-13.0.0_r5android-13.0.0_r4android-13.0.0_r31android-13.0.0_r3android-13.0.0_r2android-13.0.0_r12android-13.0.0_r1android13-security-releaseandroid13-s3-releaseandroid13-s2-releaseandroid13-s1-releaseandroid13-release
Change-Id: I975b1309efd850b435a25ac038350e646bf9adc4
-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 | ||||
-rw-r--r-- | libicu/test/src/utrans_test.cpp | 38 |
5 files changed, 138 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); + } } - diff --git a/libicu/test/src/utrans_test.cpp b/libicu/test/src/utrans_test.cpp new file mode 100644 index 000000000..39445259d --- /dev/null +++ b/libicu/test/src/utrans_test.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <gtest/gtest.h> + +#include <unicode/uchar.h> +#include <unicode/ustring.h> +#include <unicode/utrans.h> + +TEST(Icu4cUTransliteratorTest, test_utrans_transUChars) { + UErrorCode status = U_ZERO_ERROR; + UChar id[] = u"Any-Upper"; + UTransliterator* utrans = utrans_openU(id, -1, UTRANS_FORWARD, NULL, 0, NULL, &status); + ASSERT_EQ(U_ZERO_ERROR, status); + + UChar str[] = u"HeLlO WoRlD!"; + int32_t len = sizeof(str) / sizeof(UChar) - 1; + + utrans_transUChars(utrans, str, NULL, len + 1 /*textCapacity*/, 0, &len, &status); + utrans_close(utrans); + UChar expected[] = u"HELLO WORLD!"; + ASSERT_EQ(U_ZERO_ERROR, status); + ASSERT_EQ(0, u_strcmp(expected, str)); +} + |