]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/testlang.c
Additional fixes for Hong Kong locale (<rdar://problem/22130168>)
[thirdparty/cups.git] / cups / testlang.c
1 /*
2 * "$Id$"
3 *
4 * Localization test program for CUPS.
5 *
6 * Copyright 2007-2015 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 *
17 * Contents:
18 *
19 * main() - Load the specified language and show the strings for yes and no.
20 */
21
22 /*
23 * Include necessary headers...
24 */
25
26 #include "cups-private.h"
27
28
29 /*
30 * 'main()' - Load the specified language and show the strings for yes and no.
31 */
32
33 int /* O - Exit status */
34 main(int argc, /* I - Number of command-line arguments */
35 char *argv[]) /* I - Command-line arguments */
36 {
37 int i; /* Looping var */
38 int errors = 0; /* Number of errors */
39 cups_lang_t *language; /* Message catalog */
40 cups_lang_t *language2; /* Message catalog */
41 struct lconv *loc; /* Locale data */
42 char buffer[1024]; /* String buffer */
43 double number; /* Number */
44 static const char * const tests[] = /* Test strings */
45 {
46 "1",
47 "-1",
48 "3",
49 "5.125"
50 };
51
52
53 if (argc == 1)
54 {
55 language = cupsLangDefault();
56 language2 = cupsLangDefault();
57 }
58 else
59 {
60 language = cupsLangGet(argv[1]);
61 language2 = cupsLangGet(argv[1]);
62
63 setenv("LANG", argv[1], 1);
64 setenv("SOFTWARE", "CUPS/" CUPS_SVERSION, 1);
65 }
66
67 _cupsSetLocale(argv);
68
69 if (language != language2)
70 {
71 errors ++;
72
73 puts("**** ERROR: Language cache did not work! ****");
74 puts("First result from cupsLangGet:");
75 }
76
77 printf("Language = \"%s\"\n", language->language);
78 printf("Encoding = \"%s\"\n", _cupsEncodingName(language->encoding));
79 printf("No = \"%s\"\n", _cupsLangString(language, "No"));
80 printf("Yes = \"%s\"\n", _cupsLangString(language, "Yes"));
81
82 if (language != language2)
83 {
84 puts("Second result from cupsLangGet:");
85
86 printf("Language = \"%s\"\n", language2->language);
87 printf("Encoding = \"%s\"\n", _cupsEncodingName(language2->encoding));
88 printf("No = \"%s\"\n", _cupsLangString(language2, "No"));
89 printf("Yes = \"%s\"\n", _cupsLangString(language2, "Yes"));
90 }
91
92 loc = localeconv();
93
94 for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i ++)
95 {
96 number = _cupsStrScand(tests[i], NULL, loc);
97
98 printf("_cupsStrScand(\"%s\") number=%f\n", tests[i], number);
99
100 _cupsStrFormatd(buffer, buffer + sizeof(buffer), number, loc);
101
102 printf("_cupsStrFormatd(%f) buffer=\"%s\"\n", number, buffer);
103
104 if (strcmp(buffer, tests[i]))
105 {
106 errors ++;
107 puts("**** ERROR: Bad formatted number! ****");
108 }
109 }
110
111 if (argc == 3)
112 {
113 ppd_file_t *ppd; /* PPD file */
114 ppd_option_t *option; /* PageSize option */
115 ppd_choice_t *choice; /* PageSize/Letter choice */
116
117 if ((ppd = ppdOpenFile(argv[2])) == NULL)
118 {
119 printf("Unable to open PPD file \"%s\".\n", argv[2]);
120 errors ++;
121 }
122 else
123 {
124 ppdLocalize(ppd);
125
126 if ((option = ppdFindOption(ppd, "PageSize")) == NULL)
127 {
128 puts("No PageSize option.");
129 errors ++;
130 }
131 else
132 {
133 printf("PageSize: %s\n", option->text);
134
135 if ((choice = ppdFindChoice(option, "Letter")) == NULL)
136 {
137 puts("No Letter PageSize choice.");
138 errors ++;
139 }
140 else
141 {
142 printf("Letter: %s\n", choice->text);
143 }
144 }
145
146 ppdClose(ppd);
147 }
148 }
149
150 return (errors > 0);
151 }
152
153
154 /*
155 * End of "$Id$".
156 */