]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testfile.c
2 * "$Id: testfile.c 5057 2006-02-02 20:38:29Z mike $"
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...
49 static int read_write_tests(int compression
);
53 * 'main()' - Main entry.
56 int /* O - Exit status */
57 main(int argc
, /* I - Number of command-line arguments */
58 char *argv
[]) /* I - Command-line arguments */
60 int status
; /* Exit status */
61 char filename
[1024]; /* Filename buffer */
67 * Do uncompressed file tests...
70 status
= read_write_tests(0);
74 * Do compressed file tests...
79 status
+= read_write_tests(1);
80 #endif /* HAVE_LIBZ */
83 * Test path functions...
86 fputs("cupsFileFind: ", stdout
);
87 if (cupsFileFind("cat", "/bin", 1, filename
, sizeof(filename
)) &&
88 cupsFileFind("cat", "/bin:/usr/bin", 1, filename
, sizeof(filename
)))
89 printf("PASS (%s)\n", filename
);
97 * Summarize the results and return...
101 puts("\nALL TESTS PASSED!");
103 printf("\n%d TEST(S) FAILED!\n", status
);
108 * Cat the filename on the command-line...
111 cups_file_t
*fp
; /* File pointer */
112 char line
[1024]; /* Line from file */
115 if ((fp
= cupsFileOpen(argv
[1], "r")) == NULL
)
124 while (cupsFileGets(fp
, line
, sizeof(line
)))
127 if (!cupsFileEOF(fp
))
139 * 'read_write_tests()' - Perform read/write tests.
142 static int /* O - Status */
143 read_write_tests(int compression
) /* I - Use compression? */
145 int i
; /* Looping var */
146 cups_file_t
*fp
; /* First file */
147 int status
; /* Exit status */
148 char line
[1024], /* Line from file */
149 *value
; /* Directive value from line */
150 int linenum
; /* Line number */
151 unsigned char readbuf
[8192], /* Read buffer */
152 writebuf
[8192]; /* Write buffer */
153 int byte
; /* Byte from file */
157 * No errors so far...
163 * Initialize the write buffer with random data...
167 for (i
= 0; i
< (int)sizeof(writebuf
); i
++)
168 writebuf
[i
] = rand();
171 * cupsFileOpen(write)
174 printf("cupsFileOpen(write%s): ", compression
? " compressed" : "");
176 fp
= cupsFileOpen(compression
? "testfile.dat.gz" : "testfile.dat",
177 compression
? "w9" : "w");
183 * cupsFileCompression()
186 fputs("cupsFileCompression(): ", stdout
);
188 if (cupsFileCompression(fp
) == compression
)
192 printf("FAIL (Got %d, expected %d)\n", cupsFileCompression(fp
),
201 fputs("cupsFilePuts(): ", stdout
);
203 if (cupsFilePuts(fp
, "# Hello, World\n") > 0)
207 printf("FAIL (%s)\n", strerror(errno
));
215 fputs("cupsFilePrintf(): ", stdout
);
217 for (i
= 0; i
< 1000; i
++)
218 if (cupsFilePrintf(fp
, "TestLine %d\n", i
) < 0)
225 printf("FAIL (%s)\n", strerror(errno
));
233 fputs("cupsFilePutChar(): ", stdout
);
235 for (i
= 0; i
< 256; i
++)
236 if (cupsFilePutChar(fp
, i
) < 0)
243 printf("FAIL (%s)\n", strerror(errno
));
251 fputs("cupsFileWrite(): ", stdout
);
253 for (i
= 0; i
< 100; i
++)
254 if (cupsFileWrite(fp
, (char *)writebuf
, sizeof(writebuf
)) < 0)
261 printf("FAIL (%s)\n", strerror(errno
));
269 fputs("cupsFileClose(): ", stdout
);
271 if (!cupsFileClose(fp
))
275 printf("FAIL (%s)\n", strerror(errno
));
281 printf("FAIL (%s)\n", strerror(errno
));
289 fputs("cupsFileOpen(read): ", stdout
);
291 fp
= cupsFileOpen(compression
? "testfile.dat.gz" : "testfile.dat", "r");
300 fputs("cupsFileGets(): ", stdout
);
302 if (cupsFileGets(fp
, line
, sizeof(line
)))
308 printf("FAIL (Got line \"%s\", expected comment line)\n", line
);
314 printf("FAIL (%s)\n", strerror(errno
));
319 * cupsFileCompression()
322 fputs("cupsFileCompression(): ", stdout
);
324 if (cupsFileCompression(fp
) == compression
)
328 printf("FAIL (Got %d, expected %d)\n", cupsFileCompression(fp
),
339 fputs("cupsFileGetConf(): ", stdout
);
341 for (i
= 0; i
< 1000; i
++)
342 if (!cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
344 else if (strcasecmp(line
, "TestLine") || !value
|| atoi(value
) != i
||
352 printf("FAIL (Line %d, directive \"%s\", value \"%s\")\n", linenum
,
353 line
, value
? value
: "(null)");
358 printf("FAIL (%s)\n", strerror(errno
));
366 fputs("cupsGetChar(): ", stdout
);
368 for (i
= 0; i
< 256; i
++)
369 if ((byte
= cupsFileGetChar(fp
)) != i
)
376 printf("FAIL (Got %d, expected %d)\n", byte
, i
);
381 printf("FAIL (%s)\n", strerror(errno
));
389 fputs("cupsFileRead(): ", stdout
);
391 for (i
= 0; i
< 100; i
++)
392 if ((byte
= cupsFileRead(fp
, (char *)readbuf
, sizeof(readbuf
))) < 0)
394 else if (memcmp(readbuf
, writebuf
, sizeof(readbuf
)))
401 printf("FAIL (Pass %d, ", i
);
403 for (i
= 0; i
< (int)sizeof(readbuf
); i
++)
404 if (readbuf
[i
] != writebuf
[i
])
407 printf("match failed at offset %d - got %02X, expected %02X)\n",
408 i
, readbuf
[i
], writebuf
[i
]);
412 printf("FAIL (%s)\n", strerror(errno
));
420 fputs("cupsFileClose(): ", stdout
);
422 if (!cupsFileClose(fp
))
426 printf("FAIL (%s)\n", strerror(errno
));
432 printf("FAIL (%s)\n", strerror(errno
));
437 * Return the test status...
445 * End of "$Id: testfile.c 5057 2006-02-02 20:38:29Z mike $".