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