]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/testarray.c
Update svn:keyword properties.
[thirdparty/cups.git] / cups / testarray.c
index 912035d517a6bcb3179a5c088defaf2cce08c451..d3e677427827fe43c434ac1cfb301043a75388ce 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: testarray.c 5258 2006-03-09 15:40:56Z mike $"
+ * "$Id$"
  *
- *   Array test program for the Common UNIX Printing System (CUPS).
+ *   Array test program for CUPS.
  *
+ *   Copyright 2007-2012 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   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.
  *
  * 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"
 
 
 /*
@@ -123,14 +111,6 @@ main(int  argc,                            /* I - Number of command-line arguments */
   }
   else
   {
-#ifdef DEBUG
-    putchar('\n');
-    for (text = (char *)cupsArrayFirst(array), i = 0;
-         text;
-        text = (char *)cupsArrayNext(array), i ++)
-      printf("    #1  array[%d]=\"%s\"\n", i, text);
-#endif /* DEBUG */
-
     if (!cupsArrayAdd(array, strdup("Two Fish")))
     {
       puts("FAIL (\"Two Fish\")");
@@ -138,13 +118,6 @@ main(int  argc,                            /* I - Number of command-line arguments */
     }
     else
     {
-#ifdef DEBUG
-      for (text = (char *)cupsArrayFirst(array), i = 0;
-           text;
-          text = (char *)cupsArrayNext(array), i ++)
-       printf("    #2  array[%d]=\"%s\"\n", i, text);
-#endif /* DEBUG */
-
       if (!cupsArrayAdd(array, strdup("Red Fish")))
       {
        puts("FAIL (\"Red Fish\")");
@@ -152,29 +125,13 @@ main(int  argc,                           /* I - Number of command-line arguments */
       }
       else
       {
-#ifdef DEBUG
-       for (text = (char *)cupsArrayFirst(array), i = 0;
-             text;
-            text = (char *)cupsArrayNext(array), i ++)
-         printf("    #3  array[%d]=\"%s\"\n", i, text);
-#endif /* DEBUG */
-
         if (!cupsArrayAdd(array, strdup("Blue Fish")))
        {
          puts("FAIL (\"Blue Fish\")");
          status ++;
        }
        else
-       {
-#ifdef DEBUG
-         for (text = (char *)cupsArrayFirst(array), i = 0;
-               text;
-              text = (char *)cupsArrayNext(array), i ++)
-           printf("    #4  array[%d]=\"%s\"\n", i, text);
-#endif /* DEBUG */
-
          puts("PASS");
-       }
       }
     }
   }
@@ -182,7 +139,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
  /*
   * cupsArrayCount()
   */
+
   fputs("cupsArrayCount: ", stdout);
   if (cupsArrayCount(array) == 4)
     puts("PASS");
@@ -362,7 +319,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...
@@ -447,6 +404,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...
   */
@@ -500,8 +539,6 @@ load_words(const char   *filename,  /* I - File to load */
   char         word[256];              /* Word from file */
 
 
-  DEBUG_printf(("    Loading \"%s\"...\n", filename));
-
   if ((fp = fopen(filename, "r")) == NULL)
   {
     perror(filename);
@@ -511,11 +548,7 @@ load_words(const char   *filename, /* I - File to load */
   while (fscanf(fp, "%255s", word) == 1)
   {
     if (!cupsArrayFind(array, word))
-    {
-      DEBUG_printf(("    Adding \"%s\"...\n", word));
-
       cupsArrayAdd(array, strdup(word));
-    }
   }
 
   fclose(fp);
@@ -525,5 +558,5 @@ load_words(const char   *filename,  /* I - File to load */
 
 
 /*
- * End of "$Id: testarray.c 5258 2006-03-09 15:40:56Z mike $".
+ * End of "$Id$".
  */