diff --git a/tests/test-registrable-domain.c b/tests/test-registrable-domain.c index c075500..715498c 100644 --- a/tests/test-registrable-domain.c +++ b/tests/test-registrable-domain.c @@ -38,6 +38,11 @@ #include #include +#ifdef WITH_LIBICU +# include +# include +#endif + #include static int @@ -61,6 +66,26 @@ static void test(const psl_ctx_t *psl, const char *domain, const char *expected_ /* if we found utf-8, make sure to convert domain correctly to lowercase */ /* does it work, if we are not in a utf-8 env ? */ if (utf8) { +#ifdef WITH_LIBICU + UErrorCode status = 0; + UChar utf16_dst[64], utf16_src[64]; + int32_t utf16_src_length; + + /* UTF-8 to lowercase conversion */ + u_strFromUTF8(utf16_src, sizeof(utf16_src)/sizeof(utf16_src[0]), &utf16_src_length, domain, (int32_t) strlen(domain), &status); + if (U_SUCCESS(status)) { + int32_t dst_length = u_strToLower(utf16_dst, sizeof(utf16_dst)/sizeof(utf16_dst[0]), utf16_src, -1, "en", &status); + if (U_SUCCESS(status)) { + u_strToUTF8(lookupname, (int32_t) sizeof(lookupname), NULL, utf16_dst, dst_length, &status); + if (U_SUCCESS(status)) { + domain = lookupname; + } else + fprintf(stderr, "Failed to convert UTF-16 to UTF-8 (status %d)\n", status); + } else + fprintf(stderr, "Failed to convert to ASCII (status %d)\n", status); + } else + fprintf(stderr, "Failed to convert UTF-8 to UTF-16 (status %d)\n", status); +#else FILE *pp; size_t cmdsize = 48 + strlen(domain); char *cmd = alloca(cmdsize); @@ -71,6 +96,7 @@ static void test(const psl_ctx_t *psl, const char *domain, const char *expected_ domain = lookupname; pclose(pp); } +#endif } }