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