]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testfile.c
4 * File test program for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products.
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 are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
24 * This file is subject to the Apple OS-Developed Software exception.
28 * main() - Main entry.
32 * Include necessary headers...
44 #endif /* HAVE_LIBZ */
51 static int read_write_tests(int compression
);
55 * 'main()' - Main entry.
58 int /* O - Exit status */
59 main(int argc
, /* I - Number of command-line arguments */
60 char *argv
[]) /* I - Command-line arguments */
62 int status
; /* Exit status */
63 char filename
[1024]; /* Filename buffer */
69 * Do uncompressed file tests...
72 status
= read_write_tests(0);
76 * Do compressed file tests...
81 status
+= read_write_tests(1);
82 #endif /* HAVE_LIBZ */
85 * Test path functions...
88 fputs("cupsFileFind: ", stdout
);
89 if (cupsFileFind("cat", "/bin", 1, filename
, sizeof(filename
)) &&
90 cupsFileFind("cat", "/bin:/usr/bin", 1, filename
, sizeof(filename
)))
91 printf("PASS (%s)\n", filename
);
99 * Summarize the results and return...
103 puts("\nALL TESTS PASSED!");
105 printf("\n%d TEST(S) FAILED!\n", status
);
110 * Cat the filename on the command-line...
113 cups_file_t
*fp
; /* File pointer */
114 char line
[1024]; /* Line from file */
117 if ((fp
= cupsFileOpen(argv
[1], "r")) == NULL
)
126 while (cupsFileGets(fp
, line
, sizeof(line
)))
129 if (!cupsFileEOF(fp
))
141 * 'read_write_tests()' - Perform read/write tests.
144 static int /* O - Status */
145 read_write_tests(int compression
) /* I - Use compression? */
147 int i
; /* Looping var */
148 cups_file_t
*fp
; /* First file */
149 int status
; /* Exit status */
150 char line
[1024], /* Line from file */
151 *value
; /* Directive value from line */
152 int linenum
; /* Line number */
153 unsigned char readbuf
[8192], /* Read buffer */
154 writebuf
[8192]; /* Write buffer */
155 int byte
; /* Byte from file */
159 * No errors so far...
165 * Initialize the write buffer with random data...
169 for (i
= 0; i
< (int)sizeof(writebuf
); i
++)
170 writebuf
[i
] = rand();
173 * cupsFileOpen(write)
176 printf("cupsFileOpen(write%s): ", compression
? " compressed" : "");
178 fp
= cupsFileOpen(compression
? "testfile.dat.gz" : "testfile.dat",
179 compression
? "w9" : "w");
185 * cupsFileCompression()
188 fputs("cupsFileCompression(): ", stdout
);
190 if (cupsFileCompression(fp
) == compression
)
194 printf("FAIL (Got %d, expected %d)\n", cupsFileCompression(fp
),
203 fputs("cupsFilePuts(): ", stdout
);
205 if (cupsFilePuts(fp
, "# Hello, World\n") > 0)
209 printf("FAIL (%s)\n", strerror(errno
));
217 fputs("cupsFilePrintf(): ", stdout
);
219 for (i
= 0; i
< 1000; i
++)
220 if (cupsFilePrintf(fp
, "TestLine %d\n", i
) < 0)
227 printf("FAIL (%s)\n", strerror(errno
));
235 fputs("cupsFilePutChar(): ", stdout
);
237 for (i
= 0; i
< 256; i
++)
238 if (cupsFilePutChar(fp
, i
) < 0)
245 printf("FAIL (%s)\n", strerror(errno
));
253 fputs("cupsFileWrite(): ", stdout
);
255 for (i
= 0; i
< 100; i
++)
256 if (cupsFileWrite(fp
, (char *)writebuf
, sizeof(writebuf
)) < 0)
263 printf("FAIL (%s)\n", strerror(errno
));
271 fputs("cupsFileClose(): ", stdout
);
273 if (!cupsFileClose(fp
))
277 printf("FAIL (%s)\n", strerror(errno
));
283 printf("FAIL (%s)\n", strerror(errno
));
291 fputs("cupsFileOpen(read): ", stdout
);
293 fp
= cupsFileOpen(compression
? "testfile.dat.gz" : "testfile.dat", "r");
302 fputs("cupsFileGets(): ", stdout
);
304 if (cupsFileGets(fp
, line
, sizeof(line
)))
310 printf("FAIL (Got line \"%s\", expected comment line)\n", line
);
316 printf("FAIL (%s)\n", strerror(errno
));
321 * cupsFileCompression()
324 fputs("cupsFileCompression(): ", stdout
);
326 if (cupsFileCompression(fp
) == compression
)
330 printf("FAIL (Got %d, expected %d)\n", cupsFileCompression(fp
),
341 fputs("cupsFileGetConf(): ", stdout
);
343 for (i
= 0; i
< 1000; i
++)
344 if (!cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
346 else if (strcasecmp(line
, "TestLine") || !value
|| atoi(value
) != i
||
354 printf("FAIL (Line %d, directive \"%s\", value \"%s\")\n", linenum
,
355 line
, value
? value
: "(null)");
360 printf("FAIL (%s)\n", strerror(errno
));
368 fputs("cupsGetChar(): ", stdout
);
370 for (i
= 0; i
< 256; i
++)
371 if ((byte
= cupsFileGetChar(fp
)) != i
)
378 printf("FAIL (Got %d, expected %d)\n", byte
, i
);
383 printf("FAIL (%s)\n", strerror(errno
));
391 fputs("cupsFileRead(): ", stdout
);
393 for (i
= 0; i
< 100; i
++)
394 if ((byte
= cupsFileRead(fp
, (char *)readbuf
, sizeof(readbuf
))) < 0)
396 else if (memcmp(readbuf
, writebuf
, sizeof(readbuf
)))
403 printf("FAIL (Pass %d, ", i
);
405 for (i
= 0; i
< (int)sizeof(readbuf
); i
++)
406 if (readbuf
[i
] != writebuf
[i
])
409 printf("match failed at offset %d - got %02X, expected %02X)\n",
410 i
, readbuf
[i
], writebuf
[i
]);
414 printf("FAIL (%s)\n", strerror(errno
));
422 fputs("cupsFileClose(): ", stdout
);
424 if (!cupsFileClose(fp
))
428 printf("FAIL (%s)\n", strerror(errno
));
434 printf("FAIL (%s)\n", strerror(errno
));
439 * Return the test status...