/*
- * "$Id$"
- *
* File test program for CUPS.
*
- * Copyright 2007-2014 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products.
- *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law. Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file. If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 1997-2007 by Easy Software Products.
*
- * This file is subject to the Apple OS-Developed Software exception.
+ * Licensed under Apache License v2.0. See the file "LICENSE" for more
+ * information.
*/
/*
#include "file.h"
#include <stdlib.h>
#include <time.h>
-#ifdef HAVE_LIBZ
-# include <zlib.h>
-#endif /* HAVE_LIBZ */
-#ifdef WIN32
+#ifdef _WIN32
# include <io.h>
#else
# include <unistd.h>
-#endif /* WIN32 */
+#endif /* _WIN32 */
#include <fcntl.h>
int status; /* Exit status */
char filename[1024]; /* Filename buffer */
cups_file_t *fp; /* File pointer */
-#ifndef WIN32
+#ifndef _WIN32
int fds[2]; /* Open file descriptors */
cups_file_t *fdfile; /* File opened with cupsFileOpenFd() */
-#endif /* !WIN32 */
+#endif /* !_WIN32 */
int count; /* Number of lines in file */
status += random_tests();
-#ifndef WIN32
+#ifndef _WIN32
/*
* Test fdopen and close without reading...
*/
puts("PASS");
}
-#endif /* !WIN32 */
+#endif /* !_WIN32 */
/*
- * Count lines in psglyphs, rewind, then count again.
+ * Count lines in test file, rewind, then count again.
*/
- fputs("\ncupsFileOpen(\"../data/media.defs\", \"r\"): ", stdout);
+ fputs("\ncupsFileOpen(\"testfile.txt\", \"r\"): ", stdout);
- if ((fp = cupsFileOpen("../data/media.defs", "r")) == NULL)
+ if ((fp = cupsFileOpen("testfile.txt", "r")) == NULL)
{
puts("FAIL");
status ++;
puts("PASS");
fputs("cupsFileGets: ", stdout);
- if ((count = count_lines(fp)) != 208)
+ if ((count = count_lines(fp)) != 477)
{
- printf("FAIL (got %d lines, expected 208)\n", count);
+ printf("FAIL (got %d lines, expected 477)\n", count);
status ++;
}
else
puts("PASS");
fputs("cupsFileGets: ", stdout);
- if ((count = count_lines(fp)) != 208)
+ if ((count = count_lines(fp)) != 477)
{
- printf("FAIL (got %d lines, expected 208)\n", count);
+ printf("FAIL (got %d lines, expected 477)\n", count);
status ++;
}
else
*/
fputs("\ncupsFileFind: ", stdout);
-#ifdef WIN32
+#ifdef _WIN32
if (cupsFileFind("notepad.exe", "C:/WINDOWS", 1, filename, sizeof(filename)) &&
cupsFileFind("notepad.exe", "C:/WINDOWS;C:/WINDOWS/SYSTEM32", 1, filename, sizeof(filename)))
#else
if (cupsFileFind("cat", "/bin", 1, filename, sizeof(filename)) &&
cupsFileFind("cat", "/bin:/usr/bin", 1, filename, sizeof(filename)))
-#endif /* WIN32 */
+#endif /* _WIN32 */
printf("PASS (%s)\n", filename);
else
{
* Cat the filename on the command-line...
*/
- char line[1024]; /* Line from file */
+ char line[8192]; /* Line from file */
if ((fp = cupsFileOpen(argv[1], "r")) == NULL)
{
perror(argv[1]);
status = 1;
}
- else
+ else if (argc == 2)
{
status = 0;
cupsFileClose(fp);
}
+ else
+ {
+ status = 0;
+ ssize_t bytes;
+
+ while ((bytes = cupsFileRead(fp, line, sizeof(line))) > 0)
+ printf("%s: %d bytes\n", argv[1], (int)bytes);
+
+ if (cupsFileEOF(fp))
+ printf("%s: EOF\n", argv[1]);
+ else
+ perror(argv[1]);
+
+ cupsFileClose(fp);
+ }
}
return (status);
* Remove the test file...
*/
- unlink(compression ? "testfile.dat.gz" : "testfile.dat");
+ if (!status)
+ unlink(compression ? "testfile.dat.gz" : "testfile.dat");
/*
* Return the test status...
return (status);
}
-
-
-/*
- * End of "$Id$".
- */