summaryrefslogtreecommitdiff
path: root/cups/testlang.c
diff options
context:
space:
mode:
authorMichael Sweet <michael.r.sweet@gmail.com>2017-08-28 12:19:58 -0400
committerMichael Sweet <michael.r.sweet@gmail.com>2017-08-28 12:19:58 -0400
commit9964a31a77305de422bb778be1fa136d600f7089 (patch)
tree255c1d0ef7494344fe2535a8cf5c5ff58dbd6c52 /cups/testlang.c
parent7c7347a3464562d0ba72631e7a7c47d918910ad6 (diff)
downloadcups-9964a31a77305de422bb778be1fa136d600f7089.tar.gz
Fix the localization unit test on Linux (Issue #5097)
Makefile needed to create locale directory for tests. Also, localization test needs to allow string pointers to match for the POSIX locale and differ for other languages.
Diffstat (limited to 'cups/testlang.c')
-rw-r--r--cups/testlang.c67
1 files changed, 46 insertions, 21 deletions
diff --git a/cups/testlang.c b/cups/testlang.c
index e205711e6..5d9a4719a 100644
--- a/cups/testlang.c
+++ b/cups/testlang.c
@@ -25,6 +25,13 @@
/*
+ * Local functions...
+ */
+
+static int test_string(cups_lang_t *language, const char *msgid);
+
+
+/*
* 'main()' - Load the specified language and show the strings for yes and no.
*/
@@ -37,8 +44,6 @@ main(int argc, /* I - Number of command-line arguments */
cups_lang_t *language; /* Message catalog */
cups_lang_t *language2; /* Message catalog */
struct lconv *loc; /* Locale data */
- const char *msgid, /* String identifier */
- *msgstr; /* Localized string */
char buffer[1024]; /* String buffer */
double number; /* Number */
static const char * const tests[] = /* Test strings */
@@ -77,25 +82,8 @@ main(int argc, /* I - Number of command-line arguments */
printf("Language = \"%s\"\n", language->language);
printf("Encoding = \"%s\"\n", _cupsEncodingName(language->encoding));
- msgid = "No";
- msgstr = _cupsLangString(language, msgid);
- if (msgid == msgstr)
- {
- printf("%-8s = \"%s\" (FAIL)\n", msgid, msgstr);
- errors ++;
- }
- else
- printf("%-8s = \"%s\" (PASS)\n", msgid, msgstr);
-
- msgid = "Yes";
- msgstr = _cupsLangString(language, msgid);
- if (msgid == msgstr)
- {
- printf("%-8s = \"%s\" (FAIL)\n", msgid, msgstr);
- errors ++;
- }
- else
- printf("%-8s = \"%s\" (PASS)\n", msgid, msgstr);
+ errors += test_string(language, "No");
+ errors += test_string(language, "Yes");
if (language != language2)
{
@@ -259,3 +247,40 @@ main(int argc, /* I - Number of command-line arguments */
return (errors > 0);
}
+
+
+/*
+ * 'test_string()' - Test the localization of a string.
+ */
+
+static int /* O - 1 on failure, 0 on success */
+test_string(cups_lang_t *language, /* I - Language */
+ const char *msgid) /* I - Message */
+{
+ const char *msgstr; /* Localized string */
+
+
+ /*
+ * Get the localized string and then see if we got what we expected.
+ *
+ * For the POSIX locale, the string pointers should be the same.
+ * For any other locale, the string pointers should be different.
+ */
+
+ msgstr = _cupsLangString(language, msgid);
+ if (strcmp(language->language, "C") && msgid == msgstr)
+ {
+ printf("%-8s = \"%s\" (FAIL - no message catalog loaded)\n", msgid, msgstr);
+ return (1);
+ }
+ else if (!strcmp(language->language, "C") && msgid != msgstr)
+ {
+ printf("%-8s = \"%s\" (FAIL - POSIX locale is localized)\n", msgid, msgstr);
+ return (1);
+ }
+
+ printf("%-8s = \"%s\" (PASS)\n", msgid, msgstr);
+
+ return (0);
+}
+