Snap for 8498890 from 125b1f9e4d0443709bd3f2ec808bd6b5d3dbde01 to tm-release

Change-Id: I975b1309efd850b435a25ac038350e646bf9adc4
diff --git a/icu4c/source/test/cintltst/cbiditst.c b/icu4c/source/test/cintltst/cbiditst.c
index 6d23313..38be9c5 100644
--- a/icu4c/source/test/cintltst/cbiditst.c
+++ b/icu4c/source/test/cintltst/cbiditst.c
@@ -4591,6 +4591,15 @@
         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 c5f351c..c8bfce6 100644
--- a/icu4c/source/test/cintltst/cloctst.c
+++ b/icu4c/source/test/cintltst/cloctst.c
@@ -3207,6 +3207,18 @@
             }
         }
     }
+
+    // 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 @@
                     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 c16f8a6..c783007 100644
--- a/icu4c/source/test/cintltst/cnormtst.c
+++ b/icu4c/source/test/cintltst/cnormtst.c
@@ -65,6 +65,7 @@
 
 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 @@
     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 @@
     }
 }
 
+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 8f3974c..6ee85c7 100644
--- a/icu4c/source/test/cintltst/utexttst.c
+++ b/icu4c/source/test/cintltst/utexttst.c
@@ -292,6 +292,22 @@
         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 0000000..3944525
--- /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));
+}
+