/*
- * "$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"
/*
}
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\")");
}
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\")");
}
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");
- }
}
}
}
/*
* cupsArrayCount()
*/
-
+
fputs("cupsArrayCount: ", stdout);
if (cupsArrayCount(array) == 4)
puts("PASS");
* the same buffer in the first place... :)
*/
- strcpy(word, text);
+ strlcpy(word, text, sizeof(word));
/*
* Grab the next word and compare...
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...
*/
char word[256]; /* Word from file */
- DEBUG_printf((" Loading \"%s\"...\n", filename));
-
if ((fp = fopen(filename, "r")) == NULL)
{
perror(filename);
while (fscanf(fp, "%255s", word) == 1)
{
if (!cupsArrayFind(array, word))
- {
- DEBUG_printf((" Adding \"%s\"...\n", word));
-
cupsArrayAdd(array, strdup(word));
- }
}
fclose(fp);
/*
- * End of "$Id: testarray.c 5258 2006-03-09 15:40:56Z mike $".
+ * End of "$Id$".
*/