]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testfile.c
2 * "$Id: testfile.c 6192 2007-01-10 19:26:48Z mike $"
4 * File test program for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2007 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
);
90 if (cupsFileFind("notepad.exe", "C:/WINDOWS", 1, filename
, sizeof(filename
)) &&
91 cupsFileFind("notepad.exe", "C:/WINDOWS;C:/WINDOWS/SYSTEM32", 1, filename
, sizeof(filename
)))
93 if (cupsFileFind("cat", "/bin", 1, filename
, sizeof(filename
)) &&
94 cupsFileFind("cat", "/bin:/usr/bin", 1, filename
, sizeof(filename
)))
96 printf("PASS (%s)\n", filename
);
104 * Summarize the results and return...
108 puts("\nALL TESTS PASSED!");
110 printf("\n%d TEST(S) FAILED!\n", status
);
115 * Cat the filename on the command-line...
118 cups_file_t
*fp
; /* File pointer */
119 char line
[1024]; /* Line from file */
122 if ((fp
= cupsFileOpen(argv
[1], "r")) == NULL
)
131 while (cupsFileGets(fp
, line
, sizeof(line
)))
134 if (!cupsFileEOF(fp
))
146 * 'read_write_tests()' - Perform read/write tests.
149 static int /* O - Status */
150 read_write_tests(int compression
) /* I - Use compression? */
152 int i
; /* Looping var */
153 cups_file_t
*fp
; /* First file */
154 int status
; /* Exit status */
155 char line
[1024], /* Line from file */
156 *value
; /* Directive value from line */
157 int linenum
; /* Line number */
158 unsigned char readbuf
[8192], /* Read buffer */
159 writebuf
[8192]; /* Write buffer */
160 int byte
; /* Byte from file */
164 * No errors so far...
170 * Initialize the write buffer with random data...
174 srand((unsigned)time(NULL
));
179 for (i
= 0; i
< (int)sizeof(writebuf
); i
++)
180 writebuf
[i
] = rand();
183 * cupsFileOpen(write)
186 printf("cupsFileOpen(write%s): ", compression
? " compressed" : "");
188 fp
= cupsFileOpen(compression
? "testfile.dat.gz" : "testfile.dat",
189 compression
? "w9" : "w");
195 * cupsFileCompression()
198 fputs("cupsFileCompression(): ", stdout
);
200 if (cupsFileCompression(fp
) == compression
)
204 printf("FAIL (Got %d, expected %d)\n", cupsFileCompression(fp
),
213 fputs("cupsFilePuts(): ", stdout
);
215 if (cupsFilePuts(fp
, "# Hello, World\n") > 0)
219 printf("FAIL (%s)\n", strerror(errno
));
227 fputs("cupsFilePrintf(): ", stdout
);
229 for (i
= 0; i
< 1000; i
++)
230 if (cupsFilePrintf(fp
, "TestLine %d\n", i
) < 0)
237 printf("FAIL (%s)\n", strerror(errno
));
245 fputs("cupsFilePutChar(): ", stdout
);
247 for (i
= 0; i
< 256; i
++)
248 if (cupsFilePutChar(fp
, i
) < 0)
255 printf("FAIL (%s)\n", strerror(errno
));
263 fputs("cupsFileWrite(): ", stdout
);
265 for (i
= 0; i
< 100; i
++)
266 if (cupsFileWrite(fp
, (char *)writebuf
, sizeof(writebuf
)) < 0)
273 printf("FAIL (%s)\n", strerror(errno
));
281 fputs("cupsFileClose(): ", stdout
);
283 if (!cupsFileClose(fp
))
287 printf("FAIL (%s)\n", strerror(errno
));
293 printf("FAIL (%s)\n", strerror(errno
));
301 fputs("cupsFileOpen(read): ", stdout
);
303 fp
= cupsFileOpen(compression
? "testfile.dat.gz" : "testfile.dat", "r");
312 fputs("cupsFileGets(): ", stdout
);
314 if (cupsFileGets(fp
, line
, sizeof(line
)))
320 printf("FAIL (Got line \"%s\", expected comment line)\n", line
);
326 printf("FAIL (%s)\n", strerror(errno
));
331 * cupsFileCompression()
334 fputs("cupsFileCompression(): ", stdout
);
336 if (cupsFileCompression(fp
) == compression
)
340 printf("FAIL (Got %d, expected %d)\n", cupsFileCompression(fp
),
351 fputs("cupsFileGetConf(): ", stdout
);
353 for (i
= 0; i
< 1000; i
++)
354 if (!cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
356 else if (strcasecmp(line
, "TestLine") || !value
|| atoi(value
) != i
||
364 printf("FAIL (Line %d, directive \"%s\", value \"%s\")\n", linenum
,
365 line
, value
? value
: "(null)");
370 printf("FAIL (%s)\n", strerror(errno
));
378 fputs("cupsFileGetChar(): ", stdout
);
381 puts("\ni byte\n----- -----");
383 for (i
= 0; i
< 256; i
++)
385 byte
= cupsFileGetChar(fp
);
387 printf("%-5d %-5d\n", i
, byte
);
393 for (i
= 0; i
< 256; i
++)
394 if ((byte
= cupsFileGetChar(fp
)) != i
)
402 printf("FAIL (Got %d, expected %d)\n", byte
, i
);
407 printf("FAIL (%s)\n", strerror(errno
));
415 fputs("cupsFileRead(): ", stdout
);
417 for (i
= 0; i
< 100; i
++)
418 if ((byte
= cupsFileRead(fp
, (char *)readbuf
, sizeof(readbuf
))) < 0)
420 else if (memcmp(readbuf
, writebuf
, sizeof(readbuf
)))
427 printf("FAIL (Pass %d, ", i
);
429 for (i
= 0; i
< (int)sizeof(readbuf
); i
++)
430 if (readbuf
[i
] != writebuf
[i
])
433 printf("match failed at offset %d - got %02X, expected %02X)\n",
434 i
, readbuf
[i
], writebuf
[i
]);
438 printf("FAIL (%s)\n", strerror(errno
));
446 fputs("cupsFileClose(): ", stdout
);
448 if (!cupsFileClose(fp
))
452 printf("FAIL (%s)\n", strerror(errno
));
458 printf("FAIL (%s)\n", strerror(errno
));
463 * Return the test status...
471 * End of "$Id: testfile.c 6192 2007-01-10 19:26:48Z mike $".