]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/testlang.c
cc7b4f699e8191a56832af8d02ce92bd9e65562d
[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 #include "ppd-private.h"
28
29
30 /*
31 * 'main()' - Load the specified language and show the strings for yes and no.
32 */
33
34 int /* O - Exit status */
35 main(int argc, /* I - Number of command-line arguments */
36 char *argv[]) /* I - Command-line arguments */
37 {
38 int i; /* Looping var */
39 int errors = 0; /* Number of errors */
40 cups_lang_t *language; /* Message catalog */
41 cups_lang_t *language2; /* Message catalog */
42 struct lconv *loc; /* Locale data */
43 char buffer[1024]; /* String buffer */
44 double number; /* Number */
45 static const char * const tests[] = /* Test strings */
46 {
47 "1",
48 "-1",
49 "3",
50 "5.125"
51 };
52
53
54 if (argc == 1)
55 {
56 language = cupsLangDefault();
57 language2 = cupsLangDefault();
58 }
59 else
60 {
61 language = cupsLangGet(argv[1]);
62 language2 = cupsLangGet(argv[1]);
63
64 setenv("LANG", argv[1], 1);
65 setenv("SOFTWARE", "CUPS/" CUPS_SVERSION, 1);
66 }
67
68 _cupsSetLocale(argv);
69
70 if (language != language2)
71 {
72 errors ++;
73
74 puts("**** ERROR: Language cache did not work! ****");
75 puts("First result from cupsLangGet:");
76 }
77
78 printf("Language = \"%s\"\n", language->language);
79 printf("Encoding = \"%s\"\n", _cupsEncodingName(language->encoding));
80 printf("No = \"%s\"\n", _cupsLangString(language, "No"));
81 printf("Yes = \"%s\"\n", _cupsLangString(language, "Yes"));
82
83 if (language != language2)
84 {
85 puts("Second result from cupsLangGet:");
86
87 printf("Language = \"%s\"\n", language2->language);
88 printf("Encoding = \"%s\"\n", _cupsEncodingName(language2->encoding));
89 printf("No = \"%s\"\n", _cupsLangString(language2, "No"));
90 printf("Yes = \"%s\"\n", _cupsLangString(language2, "Yes"));
91 }
92
93 loc = localeconv();
94
95 for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i ++)
96 {
97 number = _cupsStrScand(tests[i], NULL, loc);
98
99 printf("_cupsStrScand(\"%s\") number=%f\n", tests[i], number);
100
101 _cupsStrFormatd(buffer, buffer + sizeof(buffer), number, loc);
102
103 printf("_cupsStrFormatd(%f) buffer=\"%s\"\n", number, buffer);
104
105 if (strcmp(buffer, tests[i]))
106 {
107 errors ++;
108 puts("**** ERROR: Bad formatted number! ****");
109 }
110 }
111
112 if (argc == 3)
113 {
114 ppd_file_t *ppd; /* PPD file */
115 ppd_option_t *option; /* PageSize option */
116 ppd_choice_t *choice; /* PageSize/Letter choice */
117
118 if ((ppd = ppdOpenFile(argv[2])) == NULL)
119 {
120 printf("Unable to open PPD file \"%s\".\n", argv[2]);
121 errors ++;
122 }
123 else
124 {
125 ppdLocalize(ppd);
126
127 if ((option = ppdFindOption(ppd, "PageSize")) == NULL)
128 {
129 puts("No PageSize option.");
130 errors ++;
131 }
132 else
133 {
134 printf("PageSize: %s\n", option->text);
135
136 if ((choice = ppdFindChoice(option, "Letter")) == NULL)
137 {
138 puts("No Letter PageSize choice.");
139 errors ++;
140 }
141 else
142 {
143 printf("Letter: %s\n", choice->text);
144 }
145 }
146
147 ppdClose(ppd);
148 }
149 }
150
151 return (errors > 0);
152 }
153
154
155 /*
156 * End of "$Id$".
157 */