]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/testpwg.c
Merge changes from CUPS 1.5svn-r9041.
[thirdparty/cups.git] / cups / testpwg.c
1 /*
2 * "$Id$"
3 *
4 * PWG test program for CUPS.
5 *
6 * Copyright 2009-2010 by Apple Inc.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
13 *
14 * This file is subject to the Apple OS-Developed Software exception.
15 *
16 * Contents:
17 *
18 * main() - Main entry.
19 * test_pwg() - Test the PWG mapping functions.
20 */
21
22 /*
23 * Include necessary headers...
24 */
25
26 #include "pwg-private.h"
27
28
29 /*
30 * Local functions...
31 */
32
33 static int test_pwg(_pwg_t *pwg);
34
35
36 /*
37 * 'main()' - Main entry.
38 */
39
40 int /* O - Exit status */
41 main(int argc, /* I - Number of command-line args */
42 char *argv[]) /* I - Command-line arguments */
43 {
44 int status; /* Status of tests (0 = success, 1 = fail) */
45 const char *ppdfile; /* PPD filename */
46 ppd_file_t *ppd; /* PPD file */
47 _pwg_t *pwg; /* PWG mapping data */
48 _pwg_media_t *pwgmedia; /* PWG media size */
49
50
51 status = 0;
52
53 if (argc != 2)
54 {
55 puts("Usage: ./testpwg filename.ppd");
56 return (1);
57 }
58 else
59 ppdfile = argv[1];
60
61 printf("ppdOpenFile(%s): ", ppdfile);
62 if ((ppd = ppdOpenFile(ppdfile)) == NULL)
63 {
64 ppd_status_t err; /* Last error in file */
65 int line; /* Line number in file */
66
67
68 err = ppdLastError(&line);
69
70 printf("FAIL (%s on line %d)\n", ppdErrorString(err), line);
71
72 return (1);
73 }
74 else
75 puts("PASS");
76
77 fputs("_pwgCreateWithPPD(ppd): ", stdout);
78 if ((pwg = _pwgCreateWithPPD(ppd)) == NULL)
79 {
80 puts("FAIL");
81 status ++;
82 }
83 else
84 {
85 puts("PASS");
86 status += test_pwg(pwg);
87
88 /*
89 * _pwgDestroy should never fail...
90 */
91
92 fputs("_pwgDestroy(pwg): ", stdout);
93 _pwgDestroy(pwg);
94 puts("PASS");
95 }
96
97 fputs("_pwgMediaForSize(29700, 42000): ", stdout);
98 if ((pwgmedia = _pwgMediaForSize(29700, 42000)) == NULL)
99 {
100 puts("FAIL (not found)");
101 status ++;
102 }
103 else if (strcmp(pwgmedia->pwg, "iso_a3_297x420mm"))
104 {
105 printf("FAIL (%s)\n", pwgmedia->pwg);
106 status ++;
107 }
108 else
109 puts("PASS");
110
111 return (status);
112 }
113
114
115 /*
116 * 'test_pwg()' - Test the PWG mapping functions.
117 */
118
119 static int /* O - 1 on failure, 0 on success */
120 test_pwg(_pwg_t *pwg) /* I - PWG mapping data */
121 {
122 int i, /* Looping var */
123 status = 0; /* Return status */
124 _pwg_t *pwg2; /* Loaded data */
125 _pwg_size_t *size, /* Size from original */
126 *size2; /* Size from saved */
127 _pwg_map_t *map, /* Map from original */
128 *map2; /* Map from saved */
129
130
131 /*
132 * Verify that we can write and read back the same data...
133 */
134
135 fputs("_pwgWriteFile(test.pwg): ", stdout);
136 if (!_pwgWriteFile(pwg, "test.pwg"))
137 {
138 puts("FAIL");
139 status ++;
140 }
141 else
142 puts("PASS");
143
144 fputs("_pwgCreateWithFile(test.pwg): ", stdout);
145 if ((pwg2 = _pwgCreateWithFile("test.pwg")) == NULL)
146 {
147 puts("FAIL");
148 status ++;
149 }
150 else
151 {
152 if (pwg2->num_sizes != pwg->num_sizes)
153 {
154 if (!status)
155 puts("FAIL");
156
157 printf(" SAVED num_sizes=%d, ORIG num_sizes=%d\n", pwg2->num_sizes,
158 pwg->num_sizes);
159
160 status ++;
161 }
162 else
163 {
164 for (i = pwg->num_sizes, size = pwg->sizes, size2 = pwg2->sizes;
165 i > 0;
166 i --, size ++, size2 ++)
167 {
168 if (strcmp(size2->map.pwg, size->map.pwg) ||
169 strcmp(size2->map.ppd, size->map.ppd) ||
170 size2->width != size->width ||
171 size2->length != size->length ||
172 size2->left != size->left ||
173 size2->bottom != size->bottom ||
174 size2->right != size->right ||
175 size2->top != size->top)
176 {
177 if (!status)
178 puts("FAIL");
179
180 if (strcmp(size->map.pwg, size2->map.pwg))
181 printf(" SAVED size->map.pwg=\"%s\", ORIG "
182 "size->map.pwg=\"%s\"\n", size2->map.pwg, size->map.pwg);
183
184 if (strcmp(size2->map.ppd, size->map.ppd))
185 printf(" SAVED size->map.ppd=\"%s\", ORIG "
186 "size->map.ppd=\"%s\"\n", size2->map.ppd, size->map.ppd);
187
188 if (size2->width != size->width)
189 printf(" SAVED size->width=%d, ORIG size->width=%d\n",
190 size2->width, size->width);
191
192 if (size2->length != size->length)
193 printf(" SAVED size->length=%d, ORIG size->length=%d\n",
194 size2->length, size->length);
195
196 if (size2->left != size->left)
197 printf(" SAVED size->left=%d, ORIG size->left=%d\n",
198 size2->left, size->left);
199
200 if (size2->bottom != size->bottom)
201 printf(" SAVED size->bottom=%d, ORIG size->bottom=%d\n",
202 size2->bottom, size->bottom);
203
204 if (size2->right != size->right)
205 printf(" SAVED size->right=%d, ORIG size->right=%d\n",
206 size2->right, size->right);
207
208 if (size2->top != size->top)
209 printf(" SAVED size->top=%d, ORIG size->top=%d\n",
210 size2->top, size->top);
211
212 status ++;
213 break;
214 }
215 }
216
217 for (i = pwg->num_sources, map = pwg->sources, map2 = pwg2->sources;
218 i > 0;
219 i --, map ++, map2 ++)
220 {
221 if (strcmp(map2->pwg, map->pwg) ||
222 strcmp(map2->ppd, map->ppd))
223 {
224 if (!status)
225 puts("FAIL");
226
227 if (strcmp(map->pwg, map2->pwg))
228 printf(" SAVED source->pwg=\"%s\", ORIG source->pwg=\"%s\"\n",
229 map2->pwg, map->pwg);
230
231 if (strcmp(map2->ppd, map->ppd))
232 printf(" SAVED source->ppd=\"%s\", ORIG source->ppd=\"%s\"\n",
233 map2->ppd, map->ppd);
234
235 status ++;
236 break;
237 }
238 }
239
240 for (i = pwg->num_types, map = pwg->types, map2 = pwg2->types;
241 i > 0;
242 i --, map ++, map2 ++)
243 {
244 if (strcmp(map2->pwg, map->pwg) ||
245 strcmp(map2->ppd, map->ppd))
246 {
247 if (!status)
248 puts("FAIL");
249
250 if (strcmp(map->pwg, map2->pwg))
251 printf(" SAVED type->pwg=\"%s\", ORIG type->pwg=\"%s\"\n",
252 map2->pwg, map->pwg);
253
254 if (strcmp(map2->ppd, map->ppd))
255 printf(" SAVED type->ppd=\"%s\", ORIG type->ppd=\"%s\"\n",
256 map2->ppd, map->ppd);
257
258 status ++;
259 break;
260 }
261 }
262 }
263
264 if (!status)
265 puts("PASS");
266 }
267
268 return (status);
269 }
270
271
272 /*
273 * End of "$Id$".
274 */