]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/testfile.c
Merge changes from CUPS trunk, r7566.
[thirdparty/cups.git] / cups / testfile.c
index d8a1b88c9535d7c57879684471921087e6bfa302..2140765c971d1392d9f749830b858e3f9cff4a33 100644 (file)
@@ -17,6 +17,7 @@
  * Contents:
  *
  *   main()             - Main entry.
+ *   count_lines()      - Count the number of lines in a file.
  *   random_tests()     - Do random access tests.
  *   read_write_tests() - Perform read/write tests.
  */
@@ -43,6 +44,7 @@
  * Local functions...
  */
 
+static int     count_lines(cups_file_t *fp);
 static int     random_tests(void);
 static int     read_write_tests(int compression);
 
@@ -57,8 +59,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 */
   int          fds[2];                 /* Open file descriptors */
   cups_file_t  *fdfile;                /* File opened with cupsFileOpenFd() */
+  int          count;                  /* Number of lines in file */
 
 
   if (argc == 1)
@@ -119,6 +123,55 @@ main(int  argc,                            /* I - Number of command-line arguments */
       puts("PASS");
     }
 
+   /*
+    * Count lines in euc-jp.txt, rewind, then count again.
+    */
+
+    fputs("\ncupsFileOpen(\"../data/euc-jp.txt\", \"r\"): ", stdout);
+
+    if ((fp = cupsFileOpen("../data/euc-jp.txt", "r")) == NULL)
+    {
+      puts("FAIL");
+      status ++;
+    }
+    else
+    {
+      puts("PASS");
+      fputs("cupsFileGets: ", stdout);
+
+      if ((count = count_lines(fp)) != 15184)
+      {
+        printf("FAIL (got %d lines, expected 15184)\n", count);
+       status ++;
+      }
+      else
+      {
+        puts("PASS");
+       fputs("cupsFileRewind: ", stdout);
+
+       if (cupsFileRewind(fp) != 0)
+       {
+         puts("FAIL");
+         status ++;
+       }
+       else
+       {
+         puts("PASS");
+         fputs("cupsFileGets: ", stdout);
+
+         if ((count = count_lines(fp)) != 15184)
+         {
+           printf("FAIL (got %d lines, expected 15184)\n", count);
+           status ++;
+         }
+         else
+           puts("PASS");
+        }
+      }
+
+      cupsFileClose(fp);
+    }
+
    /*
     * Test path functions...
     */
@@ -153,10 +206,8 @@ main(int  argc,                            /* I - Number of command-line arguments */
     * Cat the filename on the command-line...
     */
 
-    cups_file_t        *fp;                    /* File pointer */
     char       line[1024];             /* Line from file */
 
-
     if ((fp = cupsFileOpen(argv[1], "r")) == NULL)
     {
       perror(argv[1]);
@@ -180,6 +231,23 @@ main(int  argc,                            /* I - Number of command-line arguments */
 }
 
 
+/*
+ * 'count_lines()' - Count the number of lines in a file.
+ */
+
+static int                             /* O - Number of lines */
+count_lines(cups_file_t *fp)           /* I - File to read from */
+{
+  int  count;                          /* Number of lines */
+  char line[1024];                     /* Line buffer */
+
+
+  for (count = 0; cupsFileGets(fp, line, sizeof(line)); count ++);
+
+  return (count);
+}
+
+
 /*
  * 'random_tests()' - Do random access tests.
  */