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