]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testppd.c
Remove svn:keywords since they cause svn_load_dirs.pl to complain about every file.
[thirdparty/cups.git] / cups / testppd.c
CommitLineData
fa73b229 1/*
c07d5b2d 2 * "$Id: testppd.c 181 2006-06-22 20:01:18Z jlovell $"
fa73b229 3 *
4 * PPD test program for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2006 by Easy Software Products.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * This file is subject to the Apple OS-Developed Software exception.
25 *
26 * Contents:
27 *
28 * main() - Main entry.
29 */
30
31/*
32 * Include necessary headers...
33 */
34
35#include <stdio.h>
36#include <stdlib.h>
37#include <cups/string.h>
38#include <errno.h>
39#include "ppd.h"
40#ifdef WIN32
41# include <io.h>
42#else
43# include <unistd.h>
44# include <fcntl.h>
45#endif /* WIN32 */
46
47
e1d6a774 48/*
49 * Test data...
50 */
51
52static const char *default_code =
53 "[{\n"
54 "%%BeginFeature: *PageRegion Letter\n"
55 "PageRegion=Letter\n"
56 "%%EndFeature\n"
57 "} stopped cleartomark\n"
58 "[{\n"
59 "%%BeginFeature: *InputSlot Tray\n"
60 "InputSlot=Tray\n"
61 "%%EndFeature\n"
ed486911 62 "} stopped cleartomark\n"
63 "[{\n"
64 "%%BeginFeature: *IntOption None\n"
65 "%%EndFeature\n"
66 "} stopped cleartomark\n"
67 "[{\n"
68 "%%BeginFeature: *StringOption None\n"
69 "%%EndFeature\n"
70 "} stopped cleartomark\n";
71
72static const char *custom_code =
73 "[{\n"
74 "%%BeginFeature: *CustomPageSize True\n"
75 "500\n"
76 "400\n"
77 "0\n"
78 "0\n"
79 "0\n"
80 "PageSize=Custom\n"
81 "%%EndFeature\n"
82 "} stopped cleartomark\n"
83 "[{\n"
84 "%%BeginFeature: *InputSlot Tray\n"
85 "InputSlot=Tray\n"
86 "%%EndFeature\n"
87 "} stopped cleartomark\n"
88 "[{\n"
89 "%%BeginFeature: *IntOption None\n"
90 "%%EndFeature\n"
91 "} stopped cleartomark\n"
92 "[{\n"
93 "%%BeginFeature: *StringOption None\n"
94 "%%EndFeature\n"
e1d6a774 95 "} stopped cleartomark\n";
96
97
fa73b229 98/*
99 * 'main()' - Main entry.
100 */
101
102int /* O - Exit status */
103main(int argc, /* I - Number of command-line arguments */
104 char *argv[]) /* I - Command-line arguments */
105{
106 ppd_file_t *ppd; /* PPD file loaded from disk */
107 int status; /* Status of tests (0 = success, 1 = fail) */
e1d6a774 108 int conflicts; /* Number of conflicts */
109 char *s; /* String */
fa73b229 110
111
112 status = 0;
113
a74454a7 114 if (argc == 1)
fa73b229 115 {
a74454a7 116 fputs("ppdOpenFile: ", stdout);
117
118 if ((ppd = ppdOpenFile("test.ppd")) != NULL)
119 puts("PASS");
120 else
121 {
122 ppd_status_t err; /* Last error in file */
123 int line; /* Line number in file */
124
125
126 status ++;
127 err = ppdLastError(&line);
128
129 printf("FAIL (%s on line %d)\n", ppdErrorString(err), line);
130 }
131
132 fputs("ppdMarkDefaults: ", stdout);
133 ppdMarkDefaults(ppd);
134
135 if ((conflicts = ppdConflicts(ppd)) == 0)
136 puts("PASS");
137 else
138 {
139 status ++;
140 printf("FAIL (%d conflicts)\n", conflicts);
141 }
142
ed486911 143 fputs("ppdEmitString (defaults): ", stdout);
a74454a7 144 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
145 !strcmp(s, default_code))
146 puts("PASS");
147 else
148 {
149 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
150 (int)strlen(default_code));
151
152 if (s)
153 puts(s);
ed486911 154 }
155
156 if (s)
157 free(s);
158
159 fputs("ppdEmitString (custom size): ", stdout);
160 ppdMarkOption(ppd, "PageSize", "Custom.400x500");
161
162 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
163 !strcmp(s, custom_code))
164 puts("PASS");
165 else
166 {
167 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
168 (int)strlen(custom_code));
169
170 if (s)
171 puts(s);
a74454a7 172 }
fa73b229 173
a74454a7 174 if (s)
175 free(s);
e1d6a774 176
a74454a7 177 ppdClose(ppd);
e1d6a774 178 }
e1d6a774 179 else
180 {
a74454a7 181 if ((ppd = ppdOpenFile(argv[1])) == NULL)
182 {
183 ppd_status_t err; /* Last error in file */
184 int line; /* Line number in file */
185
186
187 status ++;
188 err = ppdLastError(&line);
189
190 printf("%s: %s on line %d\n", argv[1], ppdErrorString(err), line);
191 }
192 else
193 {
194 int i, j, k; /* Looping vars */
195 ppd_group_t *group; /* Option group */
196 ppd_option_t *option; /* Option */
197
198
199 ppdLocalize(ppd);
200
201 for (i = ppd->num_groups, group = ppd->groups;
202 i > 0;
203 i --, group ++)
204 {
205 printf("%s (%s):\n", group->name, group->text);
206
207 for (j = group->num_options, option = group->options;
208 j > 0;
209 j --, option ++)
210 {
211 printf(" %s (%s):\n", option->keyword, option->text);
212
213 for (k = 0; k < option->num_choices; k ++)
214 printf(" - %s (%s)\n", option->choices[k].choice,
215 option->choices[k].text);
216 }
217 }
218 }
e1d6a774 219 }
220
fa73b229 221 return (status);
222}
223
224
225/*
c07d5b2d 226 * End of "$Id: testppd.c 181 2006-06-22 20:01:18Z jlovell $".
fa73b229 227 */