]>
Commit | Line | Data |
---|---|---|
a29fd7dd | 1 | /* |
503b54c9 | 2 | * Test program for PPD data encoding example code. |
a29fd7dd | 3 | * |
503b54c9 | 4 | * Compile with: |
a29fd7dd | 5 | * |
503b54c9 | 6 | * gcc -o testppdx -D_PPD_DEPRECATED="" -g testppdx.c ppdx.c -lcups -lz |
a29fd7dd | 7 | * |
503b54c9 | 8 | * Copyright 2012 by Apple Inc. |
a29fd7dd | 9 | * |
e3101897 | 10 | * Licensed under Apache License v2.0. See the file "LICENSE" for more information. |
a29fd7dd MS |
11 | */ |
12 | ||
13 | /* | |
14 | * Include necessary headers... | |
15 | */ | |
16 | ||
17 | #include <stdio.h> | |
18 | #include <string.h> | |
19 | #include "ppdx.h" | |
20 | ||
21 | ||
22 | /* | |
23 | * 'main()' - Read data from a test PPD file and write out new chunks. | |
24 | */ | |
25 | ||
26 | int /* O - Exit status */ | |
27 | main(void) | |
28 | { | |
29 | int status = 0; /* Exit status */ | |
30 | FILE *fp; /* File to read */ | |
31 | char contents[8193], /* Contents of file */ | |
32 | *data; /* Data from PPD */ | |
33 | size_t contsize, /* File size */ | |
34 | datasize; /* Data size */ | |
35 | ppd_file_t *ppd; /* Test PPD */ | |
36 | ||
37 | ||
38 | /* | |
39 | * Open the PPD and get the data from it... | |
40 | */ | |
41 | ||
42 | ppd = ppdOpenFile("testppdx.ppd"); | |
43 | data = ppdxReadData(ppd, "EXData", &datasize); | |
44 | ||
45 | /* | |
46 | * Open this source file and read it... | |
47 | */ | |
48 | ||
49 | fp = fopen("testppdx.c", "r"); | |
50 | if (fp) | |
51 | { | |
52 | contsize = fread(contents, 1, sizeof(contents) - 1, fp); | |
53 | fclose(fp); | |
54 | contents[contsize] = '\0'; | |
55 | } | |
56 | else | |
57 | { | |
58 | contents[0] = '\0'; | |
59 | contsize = 0; | |
60 | } | |
61 | ||
62 | /* | |
63 | * Compare data... | |
64 | */ | |
65 | ||
66 | if (data) | |
67 | { | |
68 | if (contsize != datasize) | |
69 | { | |
70 | fprintf(stderr, "ERROR: PPD has %ld bytes, test file is %ld bytes.\n", | |
71 | (long)datasize, (long)contsize); | |
72 | status = 1; | |
73 | } | |
74 | else if (strcmp(contents, data)) | |
75 | { | |
76 | fputs("ERROR: PPD and test file are not the same.\n", stderr); | |
77 | status = 1; | |
78 | } | |
79 | ||
80 | if (status) | |
81 | { | |
82 | if ((fp = fopen("testppdx.dat", "wb")) != NULL) | |
83 | { | |
84 | fwrite(data, 1, datasize, fp); | |
85 | fclose(fp); | |
86 | fputs("ERROR: See testppdx.dat for data from PPD.\n", stderr); | |
87 | } | |
88 | else | |
89 | perror("Unable to open 'testppdx.dat'"); | |
90 | } | |
91 | ||
92 | free(data); | |
93 | } | |
94 | ||
95 | printf("Encoding %ld bytes for PPD...\n", (long)contsize); | |
96 | ||
97 | ppdxWriteData("EXData", contents, contsize); | |
98 | ||
99 | return (1); | |
100 | } |