]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/testfile.c
Greatly simplify the man page handling.
[thirdparty/cups.git] / cups / testfile.c
index 8555e079df1a1c42bd463200c50767fd1862cd35..633415d5f80ce7f0528cb485969230251810d3e7 100644 (file)
@@ -1,18 +1,11 @@
 /*
- * "$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>
 
 
@@ -55,10 +45,10 @@ main(int  argc,                             /* I - Number of command-line arguments */
   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 */
 
 
@@ -86,7 +76,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
 
     status += random_tests();
 
-#ifndef WIN32
+#ifndef _WIN32
    /*
     * Test fdopen and close without reading...
     */
@@ -120,15 +110,15 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
       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 ++;
@@ -138,9 +128,9 @@ main(int  argc,                             /* I - Number of command-line arguments */
       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
@@ -158,9 +148,9 @@ main(int  argc,                             /* I - Number of command-line arguments */
          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
@@ -176,13 +166,13 @@ main(int  argc,                           /* I - Number of command-line arguments */
     */
 
     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
     {
@@ -205,14 +195,14 @@ main(int  argc,                           /* I - Number of command-line arguments */
     * 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;
 
@@ -224,6 +214,21 @@ main(int  argc,                            /* I - Number of command-line arguments */
 
       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);
@@ -798,7 +803,8 @@ read_write_tests(int compression)   /* I - Use compression? */
   * Remove the test file...
   */
 
-  unlink(compression ? "testfile.dat.gz" : "testfile.dat");
+  if (!status)
+    unlink(compression ? "testfile.dat.gz" : "testfile.dat");
 
  /*
   * Return the test status...
@@ -806,8 +812,3 @@ read_write_tests(int compression)   /* I - Use compression? */
 
   return (status);
 }
-
-
-/*
- * End of "$Id$".
- */