]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testfile.c
2 * "$Id: testfile.c 6962 2007-09-17 20:35:47Z mike $"
4 * File test program for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * main() - Main entry.
20 * read_write_tests() - Perform read/write tests.
24 * Include necessary headers...
36 #endif /* HAVE_LIBZ */
43 static int read_write_tests(int compression
);
47 * 'main()' - Main entry.
50 int /* O - Exit status */
51 main(int argc
, /* I - Number of command-line arguments */
52 char *argv
[]) /* I - Command-line arguments */
54 int status
; /* Exit status */
55 char filename
[1024]; /* Filename buffer */
61 * Do uncompressed file tests...
64 status
= read_write_tests(0);
68 * Do compressed file tests...
73 status
+= read_write_tests(1);
74 #endif /* HAVE_LIBZ */
77 * Test path functions...
80 fputs("cupsFileFind: ", stdout
);
82 if (cupsFileFind("notepad.exe", "C:/WINDOWS", 1, filename
, sizeof(filename
)) &&
83 cupsFileFind("notepad.exe", "C:/WINDOWS;C:/WINDOWS/SYSTEM32", 1, filename
, sizeof(filename
)))
85 if (cupsFileFind("cat", "/bin", 1, filename
, sizeof(filename
)) &&
86 cupsFileFind("cat", "/bin:/usr/bin", 1, filename
, sizeof(filename
)))
88 printf("PASS (%s)\n", filename
);
96 * Summarize the results and return...
100 puts("\nALL TESTS PASSED!");
102 printf("\n%d TEST(S) FAILED!\n", status
);
107 * Cat the filename on the command-line...
110 cups_file_t
*fp
; /* File pointer */
111 char line
[1024]; /* Line from file */
114 if ((fp
= cupsFileOpen(argv
[1], "r")) == NULL
)
123 while (cupsFileGets(fp
, line
, sizeof(line
)))
126 if (!cupsFileEOF(fp
))
138 * 'read_write_tests()' - Perform read/write tests.
141 static int /* O - Status */
142 read_write_tests(int compression
) /* I - Use compression? */
144 int i
; /* Looping var */
145 cups_file_t
*fp
; /* First file */
146 int status
; /* Exit status */
147 char line
[1024], /* Line from file */
148 *value
; /* Directive value from line */
149 int linenum
; /* Line number */
150 unsigned char readbuf
[8192], /* Read buffer */
151 writebuf
[8192]; /* Write buffer */
152 int byte
; /* Byte from file */
153 static const char *partial_line
= "partial line";
158 * No errors so far...
164 * Initialize the write buffer with random data...
168 srand((unsigned)time(NULL
));
173 for (i
= 0; i
< (int)sizeof(writebuf
); i
++)
174 writebuf
[i
] = rand();
177 * cupsFileOpen(write)
180 printf("cupsFileOpen(write%s): ", compression
? " compressed" : "");
182 fp
= cupsFileOpen(compression
? "testfile.dat.gz" : "testfile.dat",
183 compression
? "w9" : "w");
189 * cupsFileCompression()
192 fputs("cupsFileCompression(): ", stdout
);
194 if (cupsFileCompression(fp
) == compression
)
198 printf("FAIL (Got %d, expected %d)\n", cupsFileCompression(fp
),
207 fputs("cupsFilePuts(): ", stdout
);
209 if (cupsFilePuts(fp
, "# Hello, World\n") > 0)
213 printf("FAIL (%s)\n", strerror(errno
));
221 fputs("cupsFilePrintf(): ", stdout
);
223 for (i
= 0; i
< 1000; i
++)
224 if (cupsFilePrintf(fp
, "TestLine %d\n", i
) < 0)
231 printf("FAIL (%s)\n", strerror(errno
));
239 fputs("cupsFilePutChar(): ", stdout
);
241 for (i
= 0; i
< 256; i
++)
242 if (cupsFilePutChar(fp
, i
) < 0)
249 printf("FAIL (%s)\n", strerror(errno
));
257 fputs("cupsFileWrite(): ", stdout
);
259 for (i
= 0; i
< 10000; i
++)
260 if (cupsFileWrite(fp
, (char *)writebuf
, sizeof(writebuf
)) < 0)
267 printf("FAIL (%s)\n", strerror(errno
));
272 * cupsFilePuts() with partial line...
275 fputs("cupsFilePuts(\"partial line\"): ", stdout
);
277 if (cupsFilePuts(fp
, partial_line
) > 0)
281 printf("FAIL (%s)\n", strerror(errno
));
289 fputs("cupsFileClose(): ", stdout
);
291 if (!cupsFileClose(fp
))
295 printf("FAIL (%s)\n", strerror(errno
));
301 printf("FAIL (%s)\n", strerror(errno
));
309 fputs("cupsFileOpen(read): ", stdout
);
311 fp
= cupsFileOpen(compression
? "testfile.dat.gz" : "testfile.dat", "r");
320 fputs("cupsFileGets(): ", stdout
);
322 if (cupsFileGets(fp
, line
, sizeof(line
)))
328 printf("FAIL (Got line \"%s\", expected comment line)\n", line
);
334 printf("FAIL (%s)\n", strerror(errno
));
339 * cupsFileCompression()
342 fputs("cupsFileCompression(): ", stdout
);
344 if (cupsFileCompression(fp
) == compression
)
348 printf("FAIL (Got %d, expected %d)\n", cupsFileCompression(fp
),
359 fputs("cupsFileGetConf(): ", stdout
);
361 for (i
= 0; i
< 1000; i
++)
362 if (!cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
364 else if (strcasecmp(line
, "TestLine") || !value
|| atoi(value
) != i
||
372 printf("FAIL (Line %d, directive \"%s\", value \"%s\")\n", linenum
,
373 line
, value
? value
: "(null)");
378 printf("FAIL (%s)\n", strerror(errno
));
386 fputs("cupsFileGetChar(): ", stdout
);
389 puts("\ni byte\n----- -----");
391 for (i
= 0; i
< 256; i
++)
393 byte
= cupsFileGetChar(fp
);
395 printf("%-5d %-5d\n", i
, byte
);
401 for (i
= 0; i
< 256; i
++)
402 if ((byte
= cupsFileGetChar(fp
)) != i
)
410 printf("FAIL (Got %d, expected %d)\n", byte
, i
);
415 printf("FAIL (%s)\n", strerror(errno
));
423 fputs("cupsFileRead(): ", stdout
);
425 for (i
= 0; i
< 10000; i
++)
426 if ((byte
= cupsFileRead(fp
, (char *)readbuf
, sizeof(readbuf
))) < 0)
428 else if (memcmp(readbuf
, writebuf
, sizeof(readbuf
)))
435 printf("FAIL (Pass %d, ", i
);
437 for (i
= 0; i
< (int)sizeof(readbuf
); i
++)
438 if (readbuf
[i
] != writebuf
[i
])
441 printf("match failed at offset %d - got %02X, expected %02X)\n",
442 i
, readbuf
[i
], writebuf
[i
]);
446 printf("FAIL (%s)\n", strerror(errno
));
451 * cupsFileGetChar() with partial line...
454 fputs("cupsFileGetChar(partial line): ", stdout
);
456 for (i
= 0; i
< strlen(partial_line
); i
++)
457 if ((byte
= cupsFileGetChar(fp
)) < 0)
459 else if (byte
!= partial_line
[i
])
462 if (!partial_line
[i
])
466 printf("FAIL (got '%c', expected '%c')\n", byte
, partial_line
[i
]);
474 fputs("cupsFileClose(): ", stdout
);
476 if (!cupsFileClose(fp
))
480 printf("FAIL (%s)\n", strerror(errno
));
486 printf("FAIL (%s)\n", strerror(errno
));
491 * Return the test status...
499 * End of "$Id: testfile.c 6962 2007-09-17 20:35:47Z mike $".