diff options
author | Michael Sweet <michael.r.sweet@gmail.com> | 2017-07-04 18:10:34 -0400 |
---|---|---|
committer | Michael Sweet <michael.r.sweet@gmail.com> | 2017-07-04 18:10:34 -0400 |
commit | 1a9743f9d739a791fee756d3cab2ea228ed347c1 (patch) | |
tree | 4c4bd6534866d862e598ad8c661163e9a91eedd6 /cups/testlang.c | |
parent | 534dfe8e941c50491fed4304dfaa38cdf4b1fbe1 (diff) | |
download | cups-1a9743f9d739a791fee756d3cab2ea228ed347c1.tar.gz |
Update language unit test to iterate over all macOS language IDs to validate
that libcups can handle them all (which it currently does not...)
Diffstat (limited to 'cups/testlang.c')
-rw-r--r-- | cups/testlang.c | 95 |
1 files changed, 94 insertions, 1 deletions
diff --git a/cups/testlang.c b/cups/testlang.c index 9e543a8b2..d6c9fddaa 100644 --- a/cups/testlang.c +++ b/cups/testlang.c @@ -1,7 +1,7 @@ /* * Localization test program for CUPS. * - * Copyright 2007-2015 by Apple Inc. + * Copyright 2007-2017 by Apple Inc. * Copyright 1997-2006 by Easy Software Products. * * These coded instructions, statements, and computer programs are the @@ -19,6 +19,9 @@ #include "cups-private.h" #include "ppd-private.h" +#ifdef __APPLE__ +# include <CoreFoundation/CoreFoundation.h> +#endif /* __APPLE__ */ /* @@ -143,6 +146,96 @@ main(int argc, /* I - Number of command-line arguments */ ppdClose(ppd); } } +#ifdef __APPLE__ + else + { + /* + * Test all possible language IDs for compatibility with _cupsAppleLocale... + */ + + CFIndex j, /* Looping var */ + num_locales; /* Number of locales */ + CFArrayRef locales; /* Locales */ + CFStringRef locale_id, /* Current locale ID */ + language_id; /* Current language ID */ + char locale_str[256], /* Locale ID C string */ + language_str[256], /* Language ID C string */ + *bufptr; /* Pointer to ".UTF-8" in POSIX locale */ + size_t buflen; /* Length of POSIX locale */ +# if TEST_COUNTRY_CODES + CFIndex k, /* Looping var */ + num_country_codes; /* Number of country codes */ + CFArrayRef country_codes; /* Country codes */ + CFStringRef country_code, /* Current country code */ + temp_id; /* Temporary language ID */ + char country_str[256]; /* Country code C string */ +# endif /* TEST_COUNTRY_CODES */ + + locales = CFLocaleCopyAvailableLocaleIdentifiers(); + num_locales = CFArrayGetCount(locales); + +# if TEST_COUNTRY_CODES + country_codes = CFLocaleCopyISOCountryCodes(); + num_country_codes = CFArrayGetCount(country_codes); +# endif /* TEST_COUNTRY_CODES */ + + printf("%d locales are available:\n", (int)num_locales); + + for (j = 0; j < num_locales; j ++) + { + locale_id = CFArrayGetValueAtIndex(locales, j); + language_id = CFLocaleCreateCanonicalLanguageIdentifierFromString(kCFAllocatorDefault, locale_id); + + if (!locale_id || !CFStringGetCString(locale_id, locale_str, (CFIndex)sizeof(locale_str), kCFStringEncodingASCII)) + { + printf("%d: FAIL (unable to get locale ID string)\n", (int)j + 1); + errors ++; + continue; + } + + if (!language_id || !CFStringGetCString(language_id, language_str, (CFIndex)sizeof(language_str), kCFStringEncodingASCII)) + { + printf("%d %s: FAIL (unable to get language ID string)\n", (int)j + 1, locale_str); + errors ++; + continue; + } + + if (!_cupsAppleLocale(language_id, buffer, sizeof(buffer))) + { + printf("%d %s(%s): FAIL (unable to convert language ID string to POSIX locale)\n", (int)j + 1, locale_str, language_str); + errors ++; + continue; + } + + if ((bufptr = strstr(buffer, ".UTF-8")) != NULL) + buflen = (size_t)(bufptr - buffer); + else + buflen = strlen(buffer); + + if ((language = cupsLangGet(buffer)) == NULL) + { + printf("%d %s(%s): FAIL (unable to load POSIX locale \"%s\")\n", (int)j + 1, locale_str, language_str, buffer); + errors ++; + continue; + } + + if (strncasecmp(language->language, buffer, buflen)) + { + printf("%d %s(%s): FAIL (unable to load POSIX locale \"%s\", got \"%s\")\n", (int)j + 1, locale_str, language_str, buffer, language->language); + errors ++; + continue; + } + + printf("%d %s(%s): PASS (POSIX locale is \"%s\")\n", (int)j + 1, locale_str, language_str, buffer); + } + + CFRelease(locales); + +# if TEST_COUNTRY_CODES + CFRelease(country_codes); +# endif /* TEST_COUNTRY_CODES */ + } +#endif /* __APPLE__ */ return (errors > 0); } |