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