mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 07:39:16 +00:00
ICU-21875 improve C API coverage
This commit is contained in:
parent
29111fd195
commit
bfca3ccaac
4 changed files with 100 additions and 2 deletions
|
@ -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);
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue