]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
61515785 | 2 | * "$Id: testraster.c 10996 2013-05-29 11:51:34Z msweet $" |
ef416fc2 | 3 | * |
71e16022 | 4 | * Raster test program routines for CUPS. |
ef416fc2 | 5 | * |
c8fef167 | 6 | * Copyright 2007-2011 by Apple Inc. |
f7deaa1a | 7 | * Copyright 1997-2007 by Easy Software Products. |
ef416fc2 | 8 | * |
9 | * These coded instructions, statements, and computer programs are the | |
bc44d920 | 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/". | |
ef416fc2 | 14 | * |
15 | * This file is subject to the Apple OS-Developed Software exception. | |
16 | * | |
17 | * Contents: | |
18 | * | |
db0bd74a MS |
19 | * main() - Test the raster functions. |
20 | * do_ppd_tests() - Test the default option commands in a PPD file. | |
21 | * do_ps_tests() - Test standard PostScript commands. | |
f14324a7 | 22 | * do_ras_file() - Test reading of a raster file. |
db0bd74a MS |
23 | * do_raster_tests() - Test reading and writing of raster data. |
24 | * print_changes() - Print differences in the page header. | |
ef416fc2 | 25 | */ |
26 | ||
27 | /* | |
28 | * Include necessary headers... | |
29 | */ | |
30 | ||
a4845881 | 31 | #include <cups/raster-private.h> |
ef416fc2 | 32 | |
33 | ||
34 | /* | |
b86bc4cf | 35 | * Test PS commands and header... |
36 | */ | |
37 | ||
f7deaa1a | 38 | static const char *dsc_code = |
39 | "[{\n" | |
40 | "%%BeginFeature: *PageSize Tabloid\n" | |
41 | "<</PageSize[792 1224]>>setpagedevice\n" | |
42 | "%%EndFeature\n" | |
43 | "} stopped cleartomark\n"; | |
44 | static const char *setpagedevice_code = | |
b86bc4cf | 45 | "<<" |
46 | "/MediaClass(Media Class)" | |
47 | "/MediaColor((Media Color))" | |
48 | "/MediaType(Media\\\\Type)" | |
49 | "/OutputType<416263>" | |
50 | "/AdvanceDistance 1000" | |
51 | "/AdvanceMedia 1" | |
52 | "/Collate false" | |
53 | "/CutMedia 2" | |
54 | "/Duplex true" | |
55 | "/HWResolution[100 200]" | |
56 | "/InsertSheet true" | |
57 | "/Jog 3" | |
58 | "/LeadingEdge 1" | |
59 | "/ManualFeed true" | |
60 | "/MediaPosition 8#777" | |
61 | "/MediaWeight 16#fe01" | |
62 | "/MirrorPrint true" | |
63 | "/NegativePrint true" | |
64 | "/NumCopies 1" | |
65 | "/Orientation 1" | |
66 | "/OutputFaceUp true" | |
67 | "/PageSize[612 792.1]" | |
68 | "/Separations true" | |
69 | "/TraySwitch true" | |
70 | "/Tumble true" | |
71 | "/cupsMediaType 2" | |
72 | "/cupsColorOrder 1" | |
73 | "/cupsColorSpace 1" | |
74 | "/cupsCompression 1" | |
75 | "/cupsRowCount 1" | |
76 | "/cupsRowFeed 1" | |
77 | "/cupsRowStep 1" | |
78 | "/cupsBorderlessScalingFactor 1.001" | |
79 | "/cupsInteger0 1" | |
80 | "/cupsInteger1 2" | |
81 | "/cupsInteger2 3" | |
82 | "/cupsInteger3 4" | |
83 | "/cupsInteger4 5" | |
84 | "/cupsInteger5 6" | |
85 | "/cupsInteger6 7" | |
86 | "/cupsInteger7 8" | |
87 | "/cupsInteger8 9" | |
88 | "/cupsInteger9 10" | |
89 | "/cupsInteger10 11" | |
90 | "/cupsInteger11 12" | |
91 | "/cupsInteger12 13" | |
92 | "/cupsInteger13 14" | |
93 | "/cupsInteger14 15" | |
94 | "/cupsInteger15 16" | |
95 | "/cupsReal0 1.1" | |
96 | "/cupsReal1 2.1" | |
97 | "/cupsReal2 3.1" | |
98 | "/cupsReal3 4.1" | |
99 | "/cupsReal4 5.1" | |
100 | "/cupsReal5 6.1" | |
101 | "/cupsReal6 7.1" | |
102 | "/cupsReal7 8.1" | |
103 | "/cupsReal8 9.1" | |
104 | "/cupsReal9 10.1" | |
105 | "/cupsReal10 11.1" | |
106 | "/cupsReal11 12.1" | |
107 | "/cupsReal12 13.1" | |
108 | "/cupsReal13 14.1" | |
109 | "/cupsReal14 15.1" | |
110 | "/cupsReal15 16.1" | |
111 | "/cupsString0(1)" | |
112 | "/cupsString1(2)" | |
113 | "/cupsString2(3)" | |
114 | "/cupsString3(4)" | |
115 | "/cupsString4(5)" | |
116 | "/cupsString5(6)" | |
117 | "/cupsString6(7)" | |
118 | "/cupsString7(8)" | |
119 | "/cupsString8(9)" | |
120 | "/cupsString9(10)" | |
121 | "/cupsString10(11)" | |
122 | "/cupsString11(12)" | |
123 | "/cupsString12(13)" | |
124 | "/cupsString13(14)" | |
125 | "/cupsString14(15)" | |
126 | "/cupsString15(16)" | |
127 | "/cupsMarkerType(Marker Type)" | |
128 | "/cupsRenderingIntent(Rendering Intent)" | |
129 | "/cupsPageSizeName(Letter)" | |
130 | "/cupsPreferredBitsPerColor 17" | |
131 | ">> setpagedevice"; | |
132 | ||
f7deaa1a | 133 | static cups_page_header2_t setpagedevice_header = |
b86bc4cf | 134 | { |
135 | "Media Class", /* MediaClass */ | |
136 | "(Media Color)", /* MediaColor */ | |
137 | "Media\\Type", /* MediaType */ | |
138 | "Abc", /* OutputType */ | |
139 | 1000, /* AdvanceDistance */ | |
140 | CUPS_ADVANCE_FILE, /* AdvanceMedia */ | |
141 | CUPS_FALSE, /* Collate */ | |
142 | CUPS_CUT_JOB, /* CutMedia */ | |
143 | CUPS_TRUE, /* Duplex */ | |
144 | { 100, 200 }, /* HWResolution */ | |
145 | { 0, 0, 0, 0 }, /* ImagingBoundingBox */ | |
146 | CUPS_TRUE, /* InsertSheet */ | |
147 | CUPS_JOG_SET, /* Jog */ | |
148 | CUPS_EDGE_RIGHT, /* LeadingEdge */ | |
149 | { 0, 0 }, /* Margins */ | |
150 | CUPS_TRUE, /* ManualFeed */ | |
151 | 0777, /* MediaPosition */ | |
152 | 0xfe01, /* MediaWeight */ | |
153 | CUPS_TRUE, /* MirrorPrint */ | |
154 | CUPS_TRUE, /* NegativePrint */ | |
155 | 1, /* NumCopies */ | |
156 | CUPS_ORIENT_90, /* Orientation */ | |
157 | CUPS_TRUE, /* OutputFaceUp */ | |
158 | { 612, 792 }, /* PageSize */ | |
159 | CUPS_TRUE, /* Separations */ | |
160 | CUPS_TRUE, /* TraySwitch */ | |
161 | CUPS_TRUE, /* Tumble */ | |
162 | 0, /* cupsWidth */ | |
163 | 0, /* cupsHeight */ | |
164 | 2, /* cupsMediaType */ | |
165 | 0, /* cupsBitsPerColor */ | |
166 | 0, /* cupsBitsPerPixel */ | |
167 | 0, /* cupsBytesPerLine */ | |
168 | CUPS_ORDER_BANDED, /* cupsColorOrder */ | |
169 | CUPS_CSPACE_RGB, /* cupsColorSpace */ | |
170 | 1, /* cupsCompression */ | |
171 | 1, /* cupsRowCount */ | |
172 | 1, /* cupsRowFeed */ | |
173 | 1, /* cupsRowStep */ | |
174 | 0, /* cupsNumColors */ | |
175 | 1.001, /* cupsBorderlessScalingFactor */ | |
176 | { 612.0, 792.1 }, /* cupsPageSize */ | |
177 | { 0.0, 0.0, 0.0, 0.0 }, /* cupsImagingBBox */ | |
178 | { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, | |
179 | /* cupsInteger[16] */ | |
180 | { 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 9.1, 10.1, 11.1, 12.1, 13.1, | |
181 | 14.1, 15.1, 16.1 }, /* cupsReal[16] */ | |
182 | { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", | |
183 | "14", "15", "16" }, /* cupsString[16] */ | |
184 | "Marker Type", /* cupsMarkerType */ | |
185 | "Rendering Intent", /* cupsRenderingIntent */ | |
186 | "Letter" /* cupsPageSizeName */ | |
187 | }; | |
188 | ||
189 | ||
190 | /* | |
191 | * Local functions... | |
192 | */ | |
193 | ||
f7deaa1a | 194 | static int do_ppd_tests(const char *filename, int num_options, |
195 | cups_option_t *options); | |
196 | static int do_ps_tests(void); | |
f14324a7 | 197 | static int do_ras_file(const char *filename); |
db0bd74a | 198 | static int do_raster_tests(cups_mode_t mode); |
b86bc4cf | 199 | static void print_changes(cups_page_header2_t *header, |
200 | cups_page_header2_t *expected); | |
201 | ||
202 | ||
203 | /* | |
204 | * 'main()' - Test the raster functions. | |
ef416fc2 | 205 | */ |
206 | ||
207 | int /* O - Exit status */ | |
f7deaa1a | 208 | main(int argc, /* I - Number of command-line args */ |
209 | char *argv[]) /* I - Command-line arguments */ | |
ef416fc2 | 210 | { |
f7deaa1a | 211 | int errors; /* Number of errors */ |
f14324a7 | 212 | const char *ext; /* Filename extension */ |
f7deaa1a | 213 | |
214 | ||
215 | if (argc == 1) | |
216 | { | |
217 | errors = do_ps_tests(); | |
db0bd74a MS |
218 | errors += do_raster_tests(CUPS_RASTER_WRITE); |
219 | errors += do_raster_tests(CUPS_RASTER_WRITE_COMPRESSED); | |
c8fef167 | 220 | errors += do_raster_tests(CUPS_RASTER_WRITE_PWG); |
f7deaa1a | 221 | } |
222 | else | |
223 | { | |
224 | int i; /* Looping var */ | |
225 | int num_options; /* Number of options */ | |
226 | cups_option_t *options; /* Options */ | |
227 | ||
228 | ||
229 | for (errors = 0, num_options = 0, options = NULL, i = 1; i < argc; i ++) | |
230 | { | |
231 | if (argv[i][0] == '-') | |
232 | { | |
233 | if (argv[i][1] == 'o') | |
234 | { | |
235 | if (argv[i][2]) | |
236 | num_options = cupsParseOptions(argv[i] + 2, num_options, &options); | |
237 | else | |
238 | { | |
239 | i ++; | |
240 | if (i < argc) | |
241 | num_options = cupsParseOptions(argv[i], num_options, &options); | |
242 | else | |
243 | { | |
244 | puts("Usage: testraster [-o name=value ...] [filename.ppd ...]"); | |
f14324a7 | 245 | puts(" testraster [filename.ras ...]"); |
f7deaa1a | 246 | return (1); |
247 | } | |
248 | } | |
249 | } | |
250 | else | |
251 | { | |
252 | puts("Usage: testraster [-o name=value ...] [filename.ppd ...]"); | |
f14324a7 | 253 | puts(" testraster [filename.ras ...]"); |
f7deaa1a | 254 | return (1); |
255 | } | |
256 | } | |
f14324a7 MS |
257 | else if ((ext = strrchr(argv[i], '.')) != NULL) |
258 | { | |
259 | if (!strcmp(ext, ".ppd")) | |
260 | errors += do_ppd_tests(argv[i], num_options, options); | |
261 | else | |
262 | errors += do_ras_file(argv[i]); | |
263 | } | |
f7deaa1a | 264 | else |
f14324a7 MS |
265 | { |
266 | puts("Usage: testraster [-o name=value ...] [filename.ppd ...]"); | |
267 | puts(" testraster [filename.ras ...]"); | |
268 | return (1); | |
269 | } | |
f7deaa1a | 270 | } |
271 | ||
272 | cupsFreeOptions(num_options, options); | |
273 | } | |
274 | ||
275 | return (errors); | |
276 | } | |
277 | ||
278 | ||
279 | /* | |
280 | * 'do_ppd_tests()' - Test the default option commands in a PPD file. | |
281 | */ | |
282 | ||
283 | static int /* O - Number of errors */ | |
284 | do_ppd_tests(const char *filename, /* I - PPD file */ | |
285 | int num_options, /* I - Number of options */ | |
286 | cups_option_t *options) /* I - Options */ | |
287 | { | |
288 | ppd_file_t *ppd; /* PPD file data */ | |
289 | cups_page_header2_t header; /* Page header */ | |
290 | ||
291 | ||
292 | printf("\"%s\": ", filename); | |
293 | fflush(stdout); | |
294 | ||
295 | if ((ppd = ppdOpenFile(filename)) == NULL) | |
296 | { | |
297 | ppd_status_t status; /* Status from PPD loader */ | |
298 | int line; /* Line number containing error */ | |
299 | ||
300 | ||
301 | status = ppdLastError(&line); | |
302 | ||
303 | puts("FAIL (bad PPD file)"); | |
304 | printf(" %s on line %d\n", ppdErrorString(status), line); | |
305 | ||
306 | return (1); | |
307 | } | |
308 | ||
309 | ppdMarkDefaults(ppd); | |
310 | cupsMarkOptions(ppd, num_options, options); | |
b86bc4cf | 311 | |
f7deaa1a | 312 | if (cupsRasterInterpretPPD(&header, ppd, 0, NULL, NULL)) |
313 | { | |
314 | puts("FAIL (error from function)"); | |
315 | puts(cupsRasterErrorString()); | |
316 | ||
317 | return (1); | |
318 | } | |
319 | else | |
320 | { | |
321 | puts("PASS"); | |
322 | ||
323 | return (0); | |
324 | } | |
325 | } | |
326 | ||
327 | ||
328 | /* | |
329 | * 'do_ps_tests()' - Test standard PostScript commands. | |
330 | */ | |
331 | ||
332 | static int | |
333 | do_ps_tests(void) | |
334 | { | |
335 | cups_page_header2_t header; /* Page header */ | |
336 | int preferred_bits; /* Preferred bits */ | |
337 | int errors = 0; /* Number of errors */ | |
b86bc4cf | 338 | |
b86bc4cf | 339 | |
340 | /* | |
341 | * Test PS exec code... | |
342 | */ | |
343 | ||
344 | fputs("_cupsRasterExecPS(\"setpagedevice\"): ", stdout); | |
345 | fflush(stdout); | |
346 | ||
347 | memset(&header, 0, sizeof(header)); | |
348 | header.Collate = CUPS_TRUE; | |
349 | preferred_bits = 0; | |
350 | ||
f7deaa1a | 351 | if (_cupsRasterExecPS(&header, &preferred_bits, setpagedevice_code)) |
b86bc4cf | 352 | { |
353 | puts("FAIL (error from function)"); | |
f7deaa1a | 354 | puts(cupsRasterErrorString()); |
b86bc4cf | 355 | errors ++; |
356 | } | |
f7deaa1a | 357 | else if (preferred_bits != 17 || |
358 | memcmp(&header, &setpagedevice_header, sizeof(header))) | |
b86bc4cf | 359 | { |
360 | puts("FAIL (bad header)"); | |
361 | ||
362 | if (preferred_bits != 17) | |
363 | printf(" cupsPreferredBitsPerColor %d, expected 17\n", | |
364 | preferred_bits); | |
365 | ||
f7deaa1a | 366 | print_changes(&setpagedevice_header, &header); |
b86bc4cf | 367 | errors ++; |
368 | } | |
369 | else | |
370 | puts("PASS"); | |
f14324a7 | 371 | |
b86bc4cf | 372 | fputs("_cupsRasterExecPS(\"roll\"): ", stdout); |
373 | fflush(stdout); | |
374 | ||
375 | if (_cupsRasterExecPS(&header, &preferred_bits, | |
376 | "792 612 0 0 0\n" | |
377 | "pop pop pop\n" | |
378 | "<</PageSize[5 -2 roll]/ImagingBBox null>>" | |
379 | "setpagedevice\n")) | |
380 | { | |
381 | puts("FAIL (error from function)"); | |
f7deaa1a | 382 | puts(cupsRasterErrorString()); |
b86bc4cf | 383 | errors ++; |
384 | } | |
385 | else if (header.PageSize[0] != 792 || header.PageSize[1] != 612) | |
386 | { | |
387 | printf("FAIL (PageSize [%d %d], expected [792 612])\n", header.PageSize[0], | |
388 | header.PageSize[1]); | |
389 | errors ++; | |
390 | } | |
391 | else | |
392 | puts("PASS"); | |
393 | ||
394 | fputs("_cupsRasterExecPS(\"dup index\"): ", stdout); | |
395 | fflush(stdout); | |
396 | ||
397 | if (_cupsRasterExecPS(&header, &preferred_bits, | |
398 | "true false dup\n" | |
399 | "<</Collate 4 index" | |
400 | "/Duplex 5 index" | |
401 | "/Tumble 6 index>>setpagedevice\n" | |
402 | "pop pop pop")) | |
403 | { | |
404 | puts("FAIL (error from function)"); | |
f7deaa1a | 405 | puts(cupsRasterErrorString()); |
b86bc4cf | 406 | errors ++; |
407 | } | |
408 | else | |
409 | { | |
410 | if (!header.Collate) | |
411 | { | |
412 | printf("FAIL (Collate false, expected true)\n"); | |
413 | errors ++; | |
414 | } | |
415 | ||
416 | if (header.Duplex) | |
417 | { | |
418 | printf("FAIL (Duplex true, expected false)\n"); | |
419 | errors ++; | |
420 | } | |
421 | ||
422 | if (header.Tumble) | |
423 | { | |
424 | printf("FAIL (Tumble true, expected false)\n"); | |
425 | errors ++; | |
426 | } | |
427 | ||
428 | if(header.Collate && !header.Duplex && !header.Tumble) | |
429 | puts("PASS"); | |
430 | } | |
431 | ||
f7deaa1a | 432 | fputs("_cupsRasterExecPS(\"%%Begin/EndFeature code\"): ", stdout); |
433 | fflush(stdout); | |
434 | ||
435 | if (_cupsRasterExecPS(&header, &preferred_bits, dsc_code)) | |
436 | { | |
437 | puts("FAIL (error from function)"); | |
438 | puts(cupsRasterErrorString()); | |
439 | errors ++; | |
440 | } | |
441 | else if (header.PageSize[0] != 792 || header.PageSize[1] != 1224) | |
442 | { | |
443 | printf("FAIL (bad PageSize [%d %d], expected [792 1224])\n", | |
444 | header.PageSize[0], header.PageSize[1]); | |
445 | errors ++; | |
446 | } | |
447 | else | |
448 | puts("PASS"); | |
449 | ||
f14324a7 MS |
450 | return (errors); |
451 | } | |
b86bc4cf | 452 | |
b86bc4cf | 453 | |
f14324a7 MS |
454 | /* |
455 | * 'do_ras_file()' - Test reading of a raster file. | |
456 | */ | |
b86bc4cf | 457 | |
f14324a7 MS |
458 | static int /* O - Number of errors */ |
459 | do_ras_file(const char *filename) /* I - Filename */ | |
460 | { | |
461 | unsigned y; /* Looping vars */ | |
462 | int fd; /* File descriptor */ | |
463 | cups_raster_t *ras; /* Raster stream */ | |
464 | cups_page_header2_t header; /* Page header */ | |
465 | unsigned char *data; /* Raster data */ | |
466 | int errors = 0; /* Number of errors */ | |
467 | unsigned pages = 0; /* Number of pages */ | |
b86bc4cf | 468 | |
b86bc4cf | 469 | |
f14324a7 | 470 | if ((fd = open(filename, O_RDONLY)) < 0) |
b86bc4cf | 471 | { |
f14324a7 MS |
472 | printf("%s: %s\n", filename, strerror(errno)); |
473 | return (1); | |
b86bc4cf | 474 | } |
f14324a7 MS |
475 | |
476 | if ((ras = cupsRasterOpen(fd, CUPS_RASTER_READ)) == NULL) | |
b86bc4cf | 477 | { |
f14324a7 MS |
478 | printf("%s: cupsRasterOpen failed.\n", filename); |
479 | close(fd); | |
480 | return (1); | |
b86bc4cf | 481 | } |
b86bc4cf | 482 | |
f14324a7 | 483 | printf("%s:\n", filename); |
b86bc4cf | 484 | |
f14324a7 | 485 | while (cupsRasterReadHeader2(ras, &header)) |
b86bc4cf | 486 | { |
f14324a7 MS |
487 | pages ++; |
488 | data = malloc(header.cupsBytesPerLine); | |
b86bc4cf | 489 | |
f14324a7 MS |
490 | printf(" Page %u: %ux%ux%u@%ux%udpi", pages, |
491 | header.cupsWidth, header.cupsHeight, header.cupsBitsPerPixel, | |
492 | header.HWResolution[0], header.HWResolution[1]); | |
493 | fflush(stdout); | |
b86bc4cf | 494 | |
f14324a7 MS |
495 | for (y = 0; y < header.cupsHeight; y ++) |
496 | if (cupsRasterReadPixels(ras, data, header.cupsBytesPerLine) < | |
497 | header.cupsBytesPerLine) | |
498 | break; | |
499 | ||
500 | if (y < header.cupsHeight) | |
501 | printf(" ERROR AT LINE %d\n", y); | |
502 | else | |
503 | putchar('\n'); | |
504 | ||
505 | free(data); | |
b86bc4cf | 506 | } |
f14324a7 MS |
507 | |
508 | cupsRasterClose(ras); | |
509 | close(fd); | |
b86bc4cf | 510 | |
f7deaa1a | 511 | return (errors); |
512 | } | |
513 | ||
514 | ||
515 | /* | |
516 | * 'do_raster_tests()' - Test reading and writing of raster data. | |
517 | */ | |
518 | ||
519 | static int /* O - Number of errors */ | |
db0bd74a | 520 | do_raster_tests(cups_mode_t mode) /* O - Write mode */ |
f7deaa1a | 521 | { |
522 | int page, x, y; /* Looping vars */ | |
523 | FILE *fp; /* Raster file */ | |
524 | cups_raster_t *r; /* Raster stream */ | |
525 | cups_page_header2_t header, /* Page header */ | |
526 | expected; /* Expected page header */ | |
527 | unsigned char data[2048]; /* Raster data */ | |
528 | int errors = 0; /* Number of errors */ | |
529 | ||
530 | ||
b86bc4cf | 531 | /* |
532 | * Test writing... | |
533 | */ | |
ef416fc2 | 534 | |
db0bd74a MS |
535 | printf("cupsRasterOpen(%s): ", |
536 | mode == CUPS_RASTER_WRITE ? "CUPS_RASTER_WRITE" : | |
c8fef167 MS |
537 | mode == CUPS_RASTER_WRITE ? "CUPS_RASTER_WRITE_COMPRESSED" : |
538 | "CUPS_RASTER_WRITE_PWG"); | |
b86bc4cf | 539 | fflush(stdout); |
ef416fc2 | 540 | |
541 | if ((fp = fopen("test.raster", "wb")) == NULL) | |
542 | { | |
b86bc4cf | 543 | printf("FAIL (%s)\n", strerror(errno)); |
ef416fc2 | 544 | return (1); |
545 | } | |
546 | ||
db0bd74a | 547 | if ((r = cupsRasterOpen(fileno(fp), mode)) == NULL) |
ef416fc2 | 548 | { |
b86bc4cf | 549 | printf("FAIL (%s)\n", strerror(errno)); |
ef416fc2 | 550 | fclose(fp); |
551 | return (1); | |
552 | } | |
553 | ||
b86bc4cf | 554 | puts("PASS"); |
555 | ||
ef416fc2 | 556 | for (page = 0; page < 4; page ++) |
557 | { | |
558 | memset(&header, 0, sizeof(header)); | |
559 | header.cupsWidth = 256; | |
560 | header.cupsHeight = 256; | |
561 | header.cupsBytesPerLine = 256; | |
562 | ||
563 | if (page & 1) | |
564 | { | |
565 | header.cupsBytesPerLine *= 2; | |
566 | header.cupsColorSpace = CUPS_CSPACE_CMYK; | |
567 | header.cupsColorOrder = CUPS_ORDER_CHUNKED; | |
b86bc4cf | 568 | header.cupsNumColors = 4; |
ef416fc2 | 569 | } |
570 | else | |
571 | { | |
572 | header.cupsColorSpace = CUPS_CSPACE_K; | |
573 | header.cupsColorOrder = CUPS_ORDER_BANDED; | |
b86bc4cf | 574 | header.cupsNumColors = 1; |
ef416fc2 | 575 | } |
576 | ||
577 | if (page & 2) | |
578 | { | |
579 | header.cupsBytesPerLine *= 2; | |
580 | header.cupsBitsPerColor = 16; | |
581 | header.cupsBitsPerPixel = (page & 1) ? 64 : 16; | |
582 | } | |
583 | else | |
584 | { | |
585 | header.cupsBitsPerColor = 8; | |
586 | header.cupsBitsPerPixel = (page & 1) ? 32 : 8; | |
587 | } | |
588 | ||
b86bc4cf | 589 | if (cupsRasterWriteHeader2(r, &header)) |
590 | puts("cupsRasterWriteHeader2: PASS"); | |
591 | else | |
592 | { | |
593 | puts("cupsRasterWriteHeader2: FAIL"); | |
594 | errors ++; | |
595 | } | |
ef416fc2 | 596 | |
b86bc4cf | 597 | fputs("cupsRasterWritePixels: ", stdout); |
598 | fflush(stdout); | |
ef416fc2 | 599 | |
b86bc4cf | 600 | memset(data, 0, header.cupsBytesPerLine); |
ef416fc2 | 601 | for (y = 0; y < 64; y ++) |
b86bc4cf | 602 | if (!cupsRasterWritePixels(r, data, header.cupsBytesPerLine)) |
603 | break; | |
ef416fc2 | 604 | |
b86bc4cf | 605 | if (y < 64) |
606 | { | |
607 | puts("FAIL"); | |
608 | errors ++; | |
609 | } | |
610 | else | |
611 | { | |
612 | for (x = 0; x < header.cupsBytesPerLine; x ++) | |
613 | data[x] = x; | |
ef416fc2 | 614 | |
b86bc4cf | 615 | for (y = 0; y < 64; y ++) |
616 | if (!cupsRasterWritePixels(r, data, header.cupsBytesPerLine)) | |
617 | break; | |
ef416fc2 | 618 | |
b86bc4cf | 619 | if (y < 64) |
620 | { | |
621 | puts("FAIL"); | |
622 | errors ++; | |
623 | } | |
624 | else | |
625 | { | |
626 | memset(data, 255, header.cupsBytesPerLine); | |
627 | for (y = 0; y < 64; y ++) | |
628 | if (!cupsRasterWritePixels(r, data, header.cupsBytesPerLine)) | |
629 | break; | |
630 | ||
631 | if (y < 64) | |
632 | { | |
633 | puts("FAIL"); | |
634 | errors ++; | |
635 | } | |
636 | else | |
637 | { | |
638 | for (x = 0; x < header.cupsBytesPerLine; x ++) | |
639 | data[x] = x / 4; | |
640 | ||
641 | for (y = 0; y < 64; y ++) | |
642 | if (!cupsRasterWritePixels(r, data, header.cupsBytesPerLine)) | |
643 | break; | |
644 | ||
645 | if (y < 64) | |
646 | { | |
647 | puts("FAIL"); | |
648 | errors ++; | |
649 | } | |
650 | else | |
651 | puts("PASS"); | |
652 | } | |
653 | } | |
654 | } | |
ef416fc2 | 655 | } |
656 | ||
657 | cupsRasterClose(r); | |
658 | fclose(fp); | |
659 | ||
b86bc4cf | 660 | /* |
661 | * Test reading... | |
662 | */ | |
663 | ||
664 | fputs("cupsRasterOpen(CUPS_RASTER_READ): ", stdout); | |
665 | fflush(stdout); | |
666 | ||
ef416fc2 | 667 | if ((fp = fopen("test.raster", "rb")) == NULL) |
668 | { | |
b86bc4cf | 669 | printf("FAIL (%s)\n", strerror(errno)); |
ef416fc2 | 670 | return (1); |
671 | } | |
672 | ||
673 | if ((r = cupsRasterOpen(fileno(fp), CUPS_RASTER_READ)) == NULL) | |
674 | { | |
b86bc4cf | 675 | printf("FAIL (%s)\n", strerror(errno)); |
ef416fc2 | 676 | fclose(fp); |
677 | return (1); | |
678 | } | |
679 | ||
b86bc4cf | 680 | puts("PASS"); |
681 | ||
ef416fc2 | 682 | for (page = 0; page < 4; page ++) |
683 | { | |
b86bc4cf | 684 | memset(&expected, 0, sizeof(expected)); |
685 | expected.cupsWidth = 256; | |
686 | expected.cupsHeight = 256; | |
687 | expected.cupsBytesPerLine = 256; | |
ef416fc2 | 688 | |
771bd8cb MS |
689 | if (mode == CUPS_RASTER_WRITE_PWG) |
690 | { | |
691 | strlcpy(expected.MediaClass, "PwgRaster", sizeof(expected.MediaClass)); | |
692 | expected.cupsInteger[7] = 0xffffff; | |
693 | } | |
694 | ||
b86bc4cf | 695 | if (page & 1) |
ef416fc2 | 696 | { |
b86bc4cf | 697 | expected.cupsBytesPerLine *= 2; |
698 | expected.cupsColorSpace = CUPS_CSPACE_CMYK; | |
699 | expected.cupsColorOrder = CUPS_ORDER_CHUNKED; | |
700 | expected.cupsNumColors = 4; | |
701 | } | |
702 | else | |
703 | { | |
704 | expected.cupsColorSpace = CUPS_CSPACE_K; | |
705 | expected.cupsColorOrder = CUPS_ORDER_BANDED; | |
706 | expected.cupsNumColors = 1; | |
ef416fc2 | 707 | } |
708 | ||
b86bc4cf | 709 | if (page & 2) |
710 | { | |
711 | expected.cupsBytesPerLine *= 2; | |
712 | expected.cupsBitsPerColor = 16; | |
713 | expected.cupsBitsPerPixel = (page & 1) ? 64 : 16; | |
714 | } | |
715 | else | |
ef416fc2 | 716 | { |
b86bc4cf | 717 | expected.cupsBitsPerColor = 8; |
718 | expected.cupsBitsPerPixel = (page & 1) ? 32 : 8; | |
719 | } | |
ef416fc2 | 720 | |
b86bc4cf | 721 | fputs("cupsRasterReadHeader2: ", stdout); |
722 | fflush(stdout); | |
ef416fc2 | 723 | |
b86bc4cf | 724 | if (!cupsRasterReadHeader2(r, &header)) |
725 | { | |
726 | puts("FAIL (read error)"); | |
727 | errors ++; | |
728 | break; | |
ef416fc2 | 729 | } |
730 | ||
b86bc4cf | 731 | if (memcmp(&header, &expected, sizeof(header))) |
ef416fc2 | 732 | { |
b86bc4cf | 733 | puts("FAIL (bad page header)"); |
734 | errors ++; | |
735 | print_changes(&header, &expected); | |
ef416fc2 | 736 | } |
737 | ||
b86bc4cf | 738 | fputs("cupsRasterReadPixels: ", stdout); |
739 | fflush(stdout); | |
740 | ||
ef416fc2 | 741 | for (y = 0; y < 64; y ++) |
742 | { | |
b86bc4cf | 743 | if (!cupsRasterReadPixels(r, data, header.cupsBytesPerLine)) |
744 | { | |
745 | puts("FAIL (read error)"); | |
746 | errors ++; | |
747 | break; | |
748 | } | |
ef416fc2 | 749 | |
b86bc4cf | 750 | if (data[0] != 0 || memcmp(data, data + 1, header.cupsBytesPerLine - 1)) |
751 | { | |
752 | printf("FAIL (raster line %d corrupt)\n", y); | |
753 | errors ++; | |
754 | break; | |
755 | } | |
756 | } | |
757 | ||
758 | if (y == 64) | |
759 | { | |
760 | for (y = 0; y < 64; y ++) | |
761 | { | |
762 | if (!cupsRasterReadPixels(r, data, header.cupsBytesPerLine)) | |
763 | { | |
764 | puts("FAIL (read error)"); | |
765 | errors ++; | |
ef416fc2 | 766 | break; |
b86bc4cf | 767 | } |
768 | ||
769 | for (x = 0; x < header.cupsBytesPerLine; x ++) | |
770 | if (data[x] != (x & 255)) | |
771 | break; | |
ef416fc2 | 772 | |
b86bc4cf | 773 | if (x < header.cupsBytesPerLine) |
774 | { | |
775 | printf("FAIL (raster line %d corrupt)\n", y + 64); | |
776 | errors ++; | |
777 | break; | |
778 | } | |
779 | } | |
780 | ||
781 | if (y == 64) | |
782 | { | |
783 | for (y = 0; y < 64; y ++) | |
784 | { | |
785 | if (!cupsRasterReadPixels(r, data, header.cupsBytesPerLine)) | |
786 | { | |
787 | puts("FAIL (read error)"); | |
788 | errors ++; | |
789 | break; | |
790 | } | |
791 | ||
792 | if (data[0] != 255 || memcmp(data, data + 1, header.cupsBytesPerLine - 1)) | |
793 | { | |
794 | printf("fail (raster line %d corrupt)\n", y + 128); | |
795 | errors ++; | |
796 | break; | |
797 | } | |
798 | } | |
799 | ||
800 | if (y == 64) | |
801 | { | |
802 | for (y = 0; y < 64; y ++) | |
803 | { | |
804 | if (!cupsRasterReadPixels(r, data, header.cupsBytesPerLine)) | |
805 | { | |
806 | puts("FAIL (read error)"); | |
807 | errors ++; | |
808 | break; | |
809 | } | |
810 | ||
811 | for (x = 0; x < header.cupsBytesPerLine; x ++) | |
812 | if (data[x] != ((x / 4) & 255)) | |
813 | break; | |
814 | ||
815 | if (x < header.cupsBytesPerLine) | |
816 | { | |
817 | printf("FAIL (raster line %d corrupt)\n", y + 192); | |
818 | errors ++; | |
819 | break; | |
820 | } | |
821 | } | |
822 | ||
823 | if (y == 64) | |
824 | puts("PASS"); | |
825 | } | |
826 | } | |
ef416fc2 | 827 | } |
828 | } | |
829 | ||
830 | cupsRasterClose(r); | |
831 | fclose(fp); | |
832 | ||
f7deaa1a | 833 | return (errors); |
b86bc4cf | 834 | } |
835 | ||
836 | ||
b86bc4cf | 837 | /* |
838 | * 'print_changes()' - Print differences in the page header. | |
839 | */ | |
840 | ||
841 | static void | |
842 | print_changes( | |
843 | cups_page_header2_t *header, /* I - Actual page header */ | |
844 | cups_page_header2_t *expected) /* I - Expected page header */ | |
845 | { | |
846 | int i; /* Looping var */ | |
847 | ||
848 | ||
849 | if (strcmp(header->MediaClass, expected->MediaClass)) | |
850 | printf(" MediaClass (%s), expected (%s)\n", header->MediaClass, | |
851 | expected->MediaClass); | |
852 | ||
853 | if (strcmp(header->MediaColor, expected->MediaColor)) | |
854 | printf(" MediaColor (%s), expected (%s)\n", header->MediaColor, | |
855 | expected->MediaColor); | |
856 | ||
857 | if (strcmp(header->MediaType, expected->MediaType)) | |
858 | printf(" MediaType (%s), expected (%s)\n", header->MediaType, | |
859 | expected->MediaType); | |
860 | ||
861 | if (strcmp(header->OutputType, expected->OutputType)) | |
862 | printf(" OutputType (%s), expected (%s)\n", header->OutputType, | |
863 | expected->OutputType); | |
864 | ||
865 | if (header->AdvanceDistance != expected->AdvanceDistance) | |
866 | printf(" AdvanceDistance %d, expected %d\n", header->AdvanceDistance, | |
867 | expected->AdvanceDistance); | |
868 | ||
869 | if (header->AdvanceMedia != expected->AdvanceMedia) | |
870 | printf(" AdvanceMedia %d, expected %d\n", header->AdvanceMedia, | |
871 | expected->AdvanceMedia); | |
872 | ||
873 | if (header->Collate != expected->Collate) | |
874 | printf(" Collate %d, expected %d\n", header->Collate, | |
875 | expected->Collate); | |
876 | ||
877 | if (header->CutMedia != expected->CutMedia) | |
878 | printf(" CutMedia %d, expected %d\n", header->CutMedia, | |
879 | expected->CutMedia); | |
880 | ||
881 | if (header->Duplex != expected->Duplex) | |
882 | printf(" Duplex %d, expected %d\n", header->Duplex, | |
883 | expected->Duplex); | |
884 | ||
885 | if (header->HWResolution[0] != expected->HWResolution[0] || | |
886 | header->HWResolution[1] != expected->HWResolution[1]) | |
887 | printf(" HWResolution [%d %d], expected [%d %d]\n", | |
888 | header->HWResolution[0], header->HWResolution[1], | |
889 | expected->HWResolution[0], expected->HWResolution[1]); | |
890 | ||
891 | if (memcmp(header->ImagingBoundingBox, expected->ImagingBoundingBox, | |
892 | sizeof(header->ImagingBoundingBox))) | |
893 | printf(" ImagingBoundingBox [%d %d %d %d], expected [%d %d %d %d]\n", | |
894 | header->ImagingBoundingBox[0], | |
895 | header->ImagingBoundingBox[1], | |
896 | header->ImagingBoundingBox[2], | |
897 | header->ImagingBoundingBox[3], | |
898 | expected->ImagingBoundingBox[0], | |
899 | expected->ImagingBoundingBox[1], | |
900 | expected->ImagingBoundingBox[2], | |
901 | expected->ImagingBoundingBox[3]); | |
902 | ||
903 | if (header->InsertSheet != expected->InsertSheet) | |
904 | printf(" InsertSheet %d, expected %d\n", header->InsertSheet, | |
905 | expected->InsertSheet); | |
906 | ||
907 | if (header->Jog != expected->Jog) | |
908 | printf(" Jog %d, expected %d\n", header->Jog, | |
909 | expected->Jog); | |
910 | ||
911 | if (header->LeadingEdge != expected->LeadingEdge) | |
912 | printf(" LeadingEdge %d, expected %d\n", header->LeadingEdge, | |
913 | expected->LeadingEdge); | |
914 | ||
915 | if (header->Margins[0] != expected->Margins[0] || | |
916 | header->Margins[1] != expected->Margins[1]) | |
917 | printf(" Margins [%d %d], expected [%d %d]\n", | |
918 | header->Margins[0], header->Margins[1], | |
919 | expected->Margins[0], expected->Margins[1]); | |
920 | ||
921 | if (header->ManualFeed != expected->ManualFeed) | |
922 | printf(" ManualFeed %d, expected %d\n", header->ManualFeed, | |
923 | expected->ManualFeed); | |
924 | ||
925 | if (header->MediaPosition != expected->MediaPosition) | |
926 | printf(" MediaPosition %d, expected %d\n", header->MediaPosition, | |
927 | expected->MediaPosition); | |
928 | ||
929 | if (header->MediaWeight != expected->MediaWeight) | |
930 | printf(" MediaWeight %d, expected %d\n", header->MediaWeight, | |
931 | expected->MediaWeight); | |
932 | ||
933 | if (header->MirrorPrint != expected->MirrorPrint) | |
934 | printf(" MirrorPrint %d, expected %d\n", header->MirrorPrint, | |
935 | expected->MirrorPrint); | |
936 | ||
937 | if (header->NegativePrint != expected->NegativePrint) | |
938 | printf(" NegativePrint %d, expected %d\n", header->NegativePrint, | |
939 | expected->NegativePrint); | |
940 | ||
941 | if (header->NumCopies != expected->NumCopies) | |
942 | printf(" NumCopies %d, expected %d\n", header->NumCopies, | |
943 | expected->NumCopies); | |
944 | ||
945 | if (header->Orientation != expected->Orientation) | |
946 | printf(" Orientation %d, expected %d\n", header->Orientation, | |
947 | expected->Orientation); | |
948 | ||
949 | if (header->OutputFaceUp != expected->OutputFaceUp) | |
950 | printf(" OutputFaceUp %d, expected %d\n", header->OutputFaceUp, | |
951 | expected->OutputFaceUp); | |
952 | ||
953 | if (header->PageSize[0] != expected->PageSize[0] || | |
954 | header->PageSize[1] != expected->PageSize[1]) | |
955 | printf(" PageSize [%d %d], expected [%d %d]\n", | |
956 | header->PageSize[0], header->PageSize[1], | |
957 | expected->PageSize[0], expected->PageSize[1]); | |
958 | ||
959 | if (header->Separations != expected->Separations) | |
960 | printf(" Separations %d, expected %d\n", header->Separations, | |
961 | expected->Separations); | |
962 | ||
963 | if (header->TraySwitch != expected->TraySwitch) | |
964 | printf(" TraySwitch %d, expected %d\n", header->TraySwitch, | |
965 | expected->TraySwitch); | |
966 | ||
967 | if (header->Tumble != expected->Tumble) | |
968 | printf(" Tumble %d, expected %d\n", header->Tumble, | |
969 | expected->Tumble); | |
970 | ||
971 | if (header->cupsWidth != expected->cupsWidth) | |
972 | printf(" cupsWidth %d, expected %d\n", header->cupsWidth, | |
973 | expected->cupsWidth); | |
974 | ||
975 | if (header->cupsHeight != expected->cupsHeight) | |
976 | printf(" cupsHeight %d, expected %d\n", header->cupsHeight, | |
977 | expected->cupsHeight); | |
978 | ||
979 | if (header->cupsMediaType != expected->cupsMediaType) | |
980 | printf(" cupsMediaType %d, expected %d\n", header->cupsMediaType, | |
981 | expected->cupsMediaType); | |
982 | ||
983 | if (header->cupsBitsPerColor != expected->cupsBitsPerColor) | |
984 | printf(" cupsBitsPerColor %d, expected %d\n", header->cupsBitsPerColor, | |
985 | expected->cupsBitsPerColor); | |
986 | ||
987 | if (header->cupsBitsPerPixel != expected->cupsBitsPerPixel) | |
988 | printf(" cupsBitsPerPixel %d, expected %d\n", header->cupsBitsPerPixel, | |
989 | expected->cupsBitsPerPixel); | |
990 | ||
991 | if (header->cupsBytesPerLine != expected->cupsBytesPerLine) | |
992 | printf(" cupsBytesPerLine %d, expected %d\n", header->cupsBytesPerLine, | |
993 | expected->cupsBytesPerLine); | |
994 | ||
995 | if (header->cupsColorOrder != expected->cupsColorOrder) | |
996 | printf(" cupsColorOrder %d, expected %d\n", header->cupsColorOrder, | |
997 | expected->cupsColorOrder); | |
998 | ||
999 | if (header->cupsColorSpace != expected->cupsColorSpace) | |
1000 | printf(" cupsColorSpace %d, expected %d\n", header->cupsColorSpace, | |
1001 | expected->cupsColorSpace); | |
1002 | ||
1003 | if (header->cupsCompression != expected->cupsCompression) | |
1004 | printf(" cupsCompression %d, expected %d\n", header->cupsCompression, | |
1005 | expected->cupsCompression); | |
1006 | ||
1007 | if (header->cupsRowCount != expected->cupsRowCount) | |
1008 | printf(" cupsRowCount %d, expected %d\n", header->cupsRowCount, | |
1009 | expected->cupsRowCount); | |
1010 | ||
1011 | if (header->cupsRowFeed != expected->cupsRowFeed) | |
1012 | printf(" cupsRowFeed %d, expected %d\n", header->cupsRowFeed, | |
1013 | expected->cupsRowFeed); | |
1014 | ||
1015 | if (header->cupsRowStep != expected->cupsRowStep) | |
1016 | printf(" cupsRowStep %d, expected %d\n", header->cupsRowStep, | |
1017 | expected->cupsRowStep); | |
1018 | ||
1019 | if (header->cupsNumColors != expected->cupsNumColors) | |
1020 | printf(" cupsNumColors %d, expected %d\n", header->cupsNumColors, | |
1021 | expected->cupsNumColors); | |
1022 | ||
1023 | if (header->cupsBorderlessScalingFactor != | |
1024 | expected->cupsBorderlessScalingFactor) | |
1025 | printf(" cupsBorderlessScalingFactor %g, expected %g\n", | |
1026 | header->cupsBorderlessScalingFactor, | |
1027 | expected->cupsBorderlessScalingFactor); | |
1028 | ||
1029 | if (header->cupsPageSize[0] != expected->cupsPageSize[0] || | |
1030 | header->cupsPageSize[1] != expected->cupsPageSize[1]) | |
1031 | printf(" cupsPageSize [%g %g], expected [%g %g]\n", | |
1032 | header->cupsPageSize[0], header->cupsPageSize[1], | |
1033 | expected->cupsPageSize[0], expected->cupsPageSize[1]); | |
1034 | ||
1035 | if (header->cupsImagingBBox[0] != expected->cupsImagingBBox[0] || | |
1036 | header->cupsImagingBBox[1] != expected->cupsImagingBBox[1] || | |
1037 | header->cupsImagingBBox[2] != expected->cupsImagingBBox[2] || | |
1038 | header->cupsImagingBBox[3] != expected->cupsImagingBBox[3]) | |
1039 | printf(" cupsImagingBBox [%g %g %g %g], expected [%g %g %g %g]\n", | |
1040 | header->cupsImagingBBox[0], header->cupsImagingBBox[1], | |
1041 | header->cupsImagingBBox[2], header->cupsImagingBBox[3], | |
1042 | expected->cupsImagingBBox[0], expected->cupsImagingBBox[1], | |
1043 | expected->cupsImagingBBox[2], expected->cupsImagingBBox[3]); | |
1044 | ||
1045 | for (i = 0; i < 16; i ++) | |
1046 | if (header->cupsInteger[i] != expected->cupsInteger[i]) | |
1047 | printf(" cupsInteger%d %d, expected %d\n", i, header->cupsInteger[i], | |
1048 | expected->cupsInteger[i]); | |
1049 | ||
1050 | for (i = 0; i < 16; i ++) | |
1051 | if (header->cupsReal[i] != expected->cupsReal[i]) | |
1052 | printf(" cupsReal%d %g, expected %g\n", i, header->cupsReal[i], | |
1053 | expected->cupsReal[i]); | |
1054 | ||
1055 | for (i = 0; i < 16; i ++) | |
1056 | if (strcmp(header->cupsString[i], expected->cupsString[i])) | |
1057 | printf(" cupsString%d (%s), expected (%s)\n", i, | |
1058 | header->cupsString[i], expected->cupsString[i]); | |
1059 | ||
1060 | if (strcmp(header->cupsMarkerType, expected->cupsMarkerType)) | |
1061 | printf(" cupsMarkerType (%s), expected (%s)\n", header->cupsMarkerType, | |
1062 | expected->cupsMarkerType); | |
1063 | ||
1064 | if (strcmp(header->cupsRenderingIntent, expected->cupsRenderingIntent)) | |
1065 | printf(" cupsRenderingIntent (%s), expected (%s)\n", | |
1066 | header->cupsRenderingIntent, | |
1067 | expected->cupsRenderingIntent); | |
1068 | ||
1069 | if (strcmp(header->cupsPageSizeName, expected->cupsPageSizeName)) | |
1070 | printf(" cupsPageSizeName (%s), expected (%s)\n", | |
1071 | header->cupsPageSizeName, | |
1072 | expected->cupsPageSizeName); | |
ef416fc2 | 1073 | } |
1074 | ||
1075 | ||
1076 | /* | |
61515785 | 1077 | * End of "$Id: testraster.c 10996 2013-05-29 11:51:34Z msweet $". |
ef416fc2 | 1078 | */ |