]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/testarray.c
Greatly simplify the man page handling.
[thirdparty/cups.git] / cups / testarray.c
index 52aedff509e891bc80312dafd6f46b8fa1c4d741..185fcbec57c0a621a0176aee5eb7ccc367840f21 100644 (file)
@@ -1,37 +1,20 @@
 /*
- * "$Id: testarray.c 6649 2007-07-11 21:46:42Z mike $"
+ * Array test program for CUPS.
  *
- *   Array test program for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007-2009 by Apple Inc.
- *   Copyright 1997-2006 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/".
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   main()        - Main entry.
- *   get_seconds() - Get the current time in seconds...
- *   load_words()  - Load words from a file.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <cups/string.h>
-#include <errno.h>
-#include "array.h"
+#include "string-private.h"
+#include "debug-private.h"
+#include "array-private.h"
 #include "dir.h"
-#include "debug.h"
 
 
 /*
@@ -47,8 +30,7 @@ static int    load_words(const char *filename, cups_array_t *array);
  */
 
 int                                    /* O - Exit status */
-main(int  argc,                                /* I - Number of command-line arguments */
-     char *argv[])                     /* I - Command-line arguments */
+main(void)
 {
   int          i;                      /* Looping var */
   cups_array_t *array,                 /* Test array */
@@ -142,7 +124,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
  /*
   * cupsArrayCount()
   */
+
   fputs("cupsArrayCount: ", stdout);
   if (cupsArrayCount(array) == 4)
     puts("PASS");
@@ -246,8 +228,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
     puts("PASS");
   else
   {
-    printf("FAIL (returned %p with %d elements, expected pointer with 4 elements)\n",
-           dup_array, cupsArrayCount(dup_array));
+    printf("FAIL (returned %p with %d elements, expected pointer with 4 elements)\n", (void *)dup_array, cupsArrayCount(dup_array));
     status ++;
   }
 
@@ -299,7 +280,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   {
     while ((dent = cupsDirRead(dir)) != NULL)
     {
-      i = strlen(dent->filename) - 2;
+      i = (int)strlen(dent->filename) - 2;
 
       if (i > 0 && dent->filename[i] == '.' &&
           (dent->filename[i + 1] == 'c' ||
@@ -322,7 +303,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       * the same buffer in the first place... :)
       */
 
-      strcpy(word, text);
+      strlcpy(word, text, sizeof(word));
 
      /*
       * Grab the next word and compare...
@@ -407,6 +388,88 @@ main(int  argc,                            /* I - Number of command-line arguments */
   cupsArrayDelete(array);
   cupsArrayDelete(dup_array);
 
+ /*
+  * Test the array with string functions...
+  */
+
+  fputs("_cupsArrayNewStrings(\" \\t\\nfoo bar\\tboo\\nfar\", ' '): ", stdout);
+  array = _cupsArrayNewStrings(" \t\nfoo bar\tboo\nfar", ' ');
+  if (!array)
+  {
+    status = 1;
+    puts("FAIL (unable to create array)");
+  }
+  else if (cupsArrayCount(array) != 4)
+  {
+    status = 1;
+    printf("FAIL (got %d elements, expected 4)\n", cupsArrayCount(array));
+  }
+  else if (strcmp(text = (char *)cupsArrayFirst(array), "bar"))
+  {
+    status = 1;
+    printf("FAIL (first element \"%s\", expected \"bar\")\n", text);
+  }
+  else if (strcmp(text = (char *)cupsArrayNext(array), "boo"))
+  {
+    status = 1;
+    printf("FAIL (first element \"%s\", expected \"boo\")\n", text);
+  }
+  else if (strcmp(text = (char *)cupsArrayNext(array), "far"))
+  {
+    status = 1;
+    printf("FAIL (first element \"%s\", expected \"far\")\n", text);
+  }
+  else if (strcmp(text = (char *)cupsArrayNext(array), "foo"))
+  {
+    status = 1;
+    printf("FAIL (first element \"%s\", expected \"foo\")\n", text);
+  }
+  else
+    puts("PASS");
+
+  fputs("_cupsArrayAddStrings(array, \"foo2,bar2\", ','): ", stdout);
+  _cupsArrayAddStrings(array, "foo2,bar2", ',');
+
+  if (cupsArrayCount(array) != 6)
+  {
+    status = 1;
+    printf("FAIL (got %d elements, expected 6)\n", cupsArrayCount(array));
+  }
+  else if (strcmp(text = (char *)cupsArrayFirst(array), "bar"))
+  {
+    status = 1;
+    printf("FAIL (first element \"%s\", expected \"bar\")\n", text);
+  }
+  else if (strcmp(text = (char *)cupsArrayNext(array), "bar2"))
+  {
+    status = 1;
+    printf("FAIL (first element \"%s\", expected \"bar2\")\n", text);
+  }
+  else if (strcmp(text = (char *)cupsArrayNext(array), "boo"))
+  {
+    status = 1;
+    printf("FAIL (first element \"%s\", expected \"boo\")\n", text);
+  }
+  else if (strcmp(text = (char *)cupsArrayNext(array), "far"))
+  {
+    status = 1;
+    printf("FAIL (first element \"%s\", expected \"far\")\n", text);
+  }
+  else if (strcmp(text = (char *)cupsArrayNext(array), "foo"))
+  {
+    status = 1;
+    printf("FAIL (first element \"%s\", expected \"foo\")\n", text);
+  }
+  else if (strcmp(text = (char *)cupsArrayNext(array), "foo2"))
+  {
+    status = 1;
+    printf("FAIL (first element \"%s\", expected \"foo2\")\n", text);
+  }
+  else
+    puts("PASS");
+
+  cupsArrayDelete(array);
+
  /*
   * Summarize the results and return...
   */
@@ -424,7 +487,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
  * 'get_seconds()' - Get the current time in seconds...
  */
 
-#ifdef WIN32
+#ifdef _WIN32
 #  include <windows.h>
 
 
@@ -445,7 +508,7 @@ get_seconds(void)
   gettimeofday(&curtime, NULL);
   return (curtime.tv_sec + 0.000001 * curtime.tv_usec);
 }
-#endif /* WIN32 */
+#endif /* _WIN32 */
 
 
 /*
@@ -476,8 +539,3 @@ load_words(const char   *filename,  /* I - File to load */
 
   return (1);
 }
-
-
-/*
- * End of "$Id: testarray.c 6649 2007-07-11 21:46:42Z mike $".
- */