]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testlang.c
2 * Localization test program for CUPS.
4 * Copyright 2007-2017 by Apple Inc.
5 * Copyright 1997-2006 by Easy Software Products.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
13 * This file is subject to the Apple OS-Developed Software exception.
17 * Include necessary headers...
20 #include "cups-private.h"
21 #include "ppd-private.h"
23 # include <CoreFoundation/CoreFoundation.h>
24 #endif /* __APPLE__ */
28 * 'main()' - Load the specified language and show the strings for yes and no.
31 int /* O - Exit status */
32 main(int argc
, /* I - Number of command-line arguments */
33 char *argv
[]) /* I - Command-line arguments */
35 int i
; /* Looping var */
36 int errors
= 0; /* Number of errors */
37 cups_lang_t
*language
; /* Message catalog */
38 cups_lang_t
*language2
; /* Message catalog */
39 struct lconv
*loc
; /* Locale data */
40 const char *msgid
, /* String identifier */
41 *msgstr
; /* Localized string */
42 char buffer
[1024]; /* String buffer */
43 double number
; /* Number */
44 static const char * const tests
[] = /* Test strings */
55 language
= cupsLangDefault();
56 language2
= cupsLangDefault();
60 language
= cupsLangGet(argv
[1]);
61 language2
= cupsLangGet(argv
[1]);
63 setenv("LANG", argv
[1], 1);
64 setenv("SOFTWARE", "CUPS/" CUPS_SVERSION
, 1);
69 if (language
!= language2
)
73 puts("**** ERROR: Language cache did not work! ****");
74 puts("First result from cupsLangGet:");
77 printf("Language = \"%s\"\n", language
->language
);
78 printf("Encoding = \"%s\"\n", _cupsEncodingName(language
->encoding
));
81 msgstr
= _cupsLangString(language
, msgid
);
84 printf("%-8s = \"%s\" (FAIL)\n", msgid
, msgstr
);
88 printf("%-8s = \"%s\" (PASS)\n", msgid
, msgstr
);
91 msgstr
= _cupsLangString(language
, msgid
);
94 printf("%-8s = \"%s\" (FAIL)\n", msgid
, msgstr
);
98 printf("%-8s = \"%s\" (PASS)\n", msgid
, msgstr
);
100 if (language
!= language2
)
102 puts("Second result from cupsLangGet:");
104 printf("Language = \"%s\"\n", language2
->language
);
105 printf("Encoding = \"%s\"\n", _cupsEncodingName(language2
->encoding
));
106 printf("No = \"%s\"\n", _cupsLangString(language2
, "No"));
107 printf("Yes = \"%s\"\n", _cupsLangString(language2
, "Yes"));
112 for (i
= 0; i
< (int)(sizeof(tests
) / sizeof(tests
[0])); i
++)
114 number
= _cupsStrScand(tests
[i
], NULL
, loc
);
116 printf("_cupsStrScand(\"%s\") number=%f\n", tests
[i
], number
);
118 _cupsStrFormatd(buffer
, buffer
+ sizeof(buffer
), number
, loc
);
120 printf("_cupsStrFormatd(%f) buffer=\"%s\"\n", number
, buffer
);
122 if (strcmp(buffer
, tests
[i
]))
125 puts("**** ERROR: Bad formatted number! ****");
131 ppd_file_t
*ppd
; /* PPD file */
132 ppd_option_t
*option
; /* PageSize option */
133 ppd_choice_t
*choice
; /* PageSize/Letter choice */
135 if ((ppd
= ppdOpenFile(argv
[2])) == NULL
)
137 printf("Unable to open PPD file \"%s\".\n", argv
[2]);
144 if ((option
= ppdFindOption(ppd
, "PageSize")) == NULL
)
146 puts("No PageSize option.");
151 printf("PageSize: %s\n", option
->text
);
153 if ((choice
= ppdFindChoice(option
, "Letter")) == NULL
)
155 puts("No Letter PageSize choice.");
160 printf("Letter: %s\n", choice
->text
);
164 printf("media-empty: %s\n", ppdLocalizeIPPReason(ppd
, "media-empty", NULL
, buffer
, sizeof(buffer
)));
173 * Test all possible language IDs for compatibility with _cupsAppleLocale...
176 CFIndex j
, /* Looping var */
177 num_locales
; /* Number of locales */
178 CFArrayRef locales
; /* Locales */
179 CFStringRef locale_id
, /* Current locale ID */
180 language_id
; /* Current language ID */
181 char locale_str
[256], /* Locale ID C string */
182 language_str
[256], /* Language ID C string */
183 *bufptr
; /* Pointer to ".UTF-8" in POSIX locale */
184 size_t buflen
; /* Length of POSIX locale */
185 # if TEST_COUNTRY_CODES
186 CFIndex k
, /* Looping var */
187 num_country_codes
; /* Number of country codes */
188 CFArrayRef country_codes
; /* Country codes */
189 CFStringRef country_code
, /* Current country code */
190 temp_id
; /* Temporary language ID */
191 char country_str
[256]; /* Country code C string */
192 # endif /* TEST_COUNTRY_CODES */
194 locales
= CFLocaleCopyAvailableLocaleIdentifiers();
195 num_locales
= CFArrayGetCount(locales
);
197 # if TEST_COUNTRY_CODES
198 country_codes
= CFLocaleCopyISOCountryCodes();
199 num_country_codes
= CFArrayGetCount(country_codes
);
200 # endif /* TEST_COUNTRY_CODES */
202 printf("%d locales are available:\n", (int)num_locales
);
204 for (j
= 0; j
< num_locales
; j
++)
206 locale_id
= CFArrayGetValueAtIndex(locales
, j
);
207 language_id
= CFLocaleCreateCanonicalLanguageIdentifierFromString(kCFAllocatorDefault
, locale_id
);
209 if (!locale_id
|| !CFStringGetCString(locale_id
, locale_str
, (CFIndex
)sizeof(locale_str
), kCFStringEncodingASCII
))
211 printf("%d: FAIL (unable to get locale ID string)\n", (int)j
+ 1);
216 if (!language_id
|| !CFStringGetCString(language_id
, language_str
, (CFIndex
)sizeof(language_str
), kCFStringEncodingASCII
))
218 printf("%d %s: FAIL (unable to get language ID string)\n", (int)j
+ 1, locale_str
);
223 if (!_cupsAppleLocale(language_id
, buffer
, sizeof(buffer
)))
225 printf("%d %s(%s): FAIL (unable to convert language ID string to POSIX locale)\n", (int)j
+ 1, locale_str
, language_str
);
230 if ((bufptr
= strstr(buffer
, ".UTF-8")) != NULL
)
231 buflen
= (size_t)(bufptr
- buffer
);
233 buflen
= strlen(buffer
);
235 if ((language
= cupsLangGet(buffer
)) == NULL
)
237 printf("%d %s(%s): FAIL (unable to load POSIX locale \"%s\")\n", (int)j
+ 1, locale_str
, language_str
, buffer
);
242 if (strncasecmp(language
->language
, buffer
, buflen
))
244 printf("%d %s(%s): FAIL (unable to load POSIX locale \"%s\", got \"%s\")\n", (int)j
+ 1, locale_str
, language_str
, buffer
, language
->language
);
249 printf("%d %s(%s): PASS (POSIX locale is \"%s\")\n", (int)j
+ 1, locale_str
, language_str
, buffer
);
254 # if TEST_COUNTRY_CODES
255 CFRelease(country_codes
);
256 # endif /* TEST_COUNTRY_CODES */
258 #endif /* __APPLE__ */