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