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