]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/testppd.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / testppd.c
1 /*
2 * "$Id: testppd.c 5484 2006-05-02 20:38:12Z mike $"
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
48 /*
49 * Test data...
50 */
51
52 static 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"
62 "} stopped cleartomark\n";
63
64
65 /*
66 * 'main()' - Main entry.
67 */
68
69 int /* O - Exit status */
70 main(int argc, /* I - Number of command-line arguments */
71 char *argv[]) /* I - Command-line arguments */
72 {
73 ppd_file_t *ppd; /* PPD file loaded from disk */
74 int status; /* Status of tests (0 = success, 1 = fail) */
75 int conflicts; /* Number of conflicts */
76 char *s; /* String */
77
78
79 status = 0;
80
81 if (argc == 1)
82 {
83 fputs("ppdOpenFile: ", stdout);
84
85 if ((ppd = ppdOpenFile("test.ppd")) != NULL)
86 puts("PASS");
87 else
88 {
89 ppd_status_t err; /* Last error in file */
90 int line; /* Line number in file */
91
92
93 status ++;
94 err = ppdLastError(&line);
95
96 printf("FAIL (%s on line %d)\n", ppdErrorString(err), line);
97 }
98
99 fputs("ppdMarkDefaults: ", stdout);
100 ppdMarkDefaults(ppd);
101
102 if ((conflicts = ppdConflicts(ppd)) == 0)
103 puts("PASS");
104 else
105 {
106 status ++;
107 printf("FAIL (%d conflicts)\n", conflicts);
108 }
109
110 fputs("ppdEmitString: ", stdout);
111 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
112 !strcmp(s, default_code))
113 puts("PASS");
114 else
115 {
116 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
117 (int)strlen(default_code));
118
119 if (s)
120 puts(s);
121 }
122
123 if (s)
124 free(s);
125
126 ppdClose(ppd);
127 }
128 else
129 {
130 if ((ppd = ppdOpenFile(argv[1])) == NULL)
131 {
132 ppd_status_t err; /* Last error in file */
133 int line; /* Line number in file */
134
135
136 status ++;
137 err = ppdLastError(&line);
138
139 printf("%s: %s on line %d\n", argv[1], ppdErrorString(err), line);
140 }
141 else
142 {
143 int i, j, k; /* Looping vars */
144 ppd_group_t *group; /* Option group */
145 ppd_option_t *option; /* Option */
146
147
148 ppdLocalize(ppd);
149
150 for (i = ppd->num_groups, group = ppd->groups;
151 i > 0;
152 i --, group ++)
153 {
154 printf("%s (%s):\n", group->name, group->text);
155
156 for (j = group->num_options, option = group->options;
157 j > 0;
158 j --, option ++)
159 {
160 printf(" %s (%s):\n", option->keyword, option->text);
161
162 for (k = 0; k < option->num_choices; k ++)
163 printf(" - %s (%s)\n", option->choices[k].choice,
164 option->choices[k].text);
165 }
166 }
167 }
168 }
169
170 return (status);
171 }
172
173
174 /*
175 * End of "$Id: testppd.c 5484 2006-05-02 20:38:12Z mike $".
176 */