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