X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=cups%2Ftestoptions.c;h=1cc2f74a5c8a9494ac5bfb53fd388a67673a1f29;hb=f950947148bd1867c247a211af7404056b2b2e36;hp=39aa0089f462a218855518d8221a4a35c2f753d7;hpb=20fbc9034781e607f8063453c8a52ec73fc5c293;p=thirdparty%2Fcups.git diff --git a/cups/testoptions.c b/cups/testoptions.c index 39aa0089f..1cc2f74a5 100644 --- a/cups/testoptions.c +++ b/cups/testoptions.c @@ -1,29 +1,16 @@ /* - * "$Id$" + * Option unit test program for CUPS. * - * Option test program for the Common UNIX Printing System (CUPS). + * Copyright 2008-2016 by Apple Inc. * - * Copyright 2008 by Apple Inc. - * - * 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() - Test option processing functions. + * Licensed under Apache License v2.0. See the file "LICENSE" for more information. */ /* * Include necessary headers... */ -#include "string.h" -#include "cups.h" +#include "cups-private.h" /* @@ -38,6 +25,9 @@ main(int argc, /* I - Number of command-line arguments */ num_options; /* Number of options */ cups_option_t *options; /* Options */ const char *value; /* Value of an option */ + ipp_t *request; /* IPP request */ + ipp_attribute_t *attr; /* IPP attribute */ + int count; /* Number of attributes */ if (argc == 1) @@ -54,11 +44,12 @@ main(int argc, /* I - Number of command-line arguments */ "baz={param1=1 param2=2} " "foobar=FOO\\ BAR " "barfoo=barfoo " - "barfoo=\"\'BAR FOO\'\"", 0, &options); + "barfoo=\"\'BAR FOO\'\" " + "auth-info=user,pass\\\\,word\\\\\\\\", 0, &options); - if (num_options != 5) + if (num_options != 6) { - printf("FAIL (num_options=%d, expected 5)\n", num_options); + printf("FAIL (num_options=%d, expected 6)\n", num_options); status ++; } else if ((value = cupsGetOption("foo", num_options, options)) == NULL || @@ -92,6 +83,71 @@ main(int argc, /* I - Number of command-line arguments */ printf("FAIL (barfoo=\"%s\", expected \"\'BAR FOO\'\")\n", value); status ++; } + else if ((value = cupsGetOption("auth-info", num_options, options)) == NULL || + strcmp(value, "user,pass\\,word\\\\")) + { + printf("FAIL (auth-info=\"%s\", expected \"user,pass\\,word\\\\\")\n", value); + status ++; + } + else + puts("PASS"); + + fputs("cupsEncodeOptions2: ", stdout); + request = ippNew(); + ippSetOperation(request, IPP_OP_PRINT_JOB); + + cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB); + for (count = 0, attr = ippFirstAttribute(request); attr; attr = ippNextAttribute(request), count ++); + if (count != 6) + { + printf("FAIL (%d attributes, expected 6)\n", count); + status ++; + } + else if ((attr = ippFindAttribute(request, "foo", IPP_TAG_ZERO)) == NULL) + { + puts("FAIL (Unable to find attribute \"foo\")"); + status ++; + } + else if (ippGetValueTag(attr) != IPP_TAG_NAME) + { + printf("FAIL (\"foo\" of type %s, expected name)\n", ippTagString(ippGetValueTag(attr))); + status ++; + } + else if (ippGetCount(attr) != 1) + { + printf("FAIL (\"foo\" has %d values, expected 1)\n", (int)ippGetCount(attr)); + status ++; + } + else if (strcmp(ippGetString(attr, 0, NULL), "1234")) + { + printf("FAIL (\"foo\" has value %s, expected 1234)\n", ippGetString(attr, 0, NULL)); + status ++; + } + else if ((attr = ippFindAttribute(request, "auth-info", IPP_TAG_ZERO)) == NULL) + { + puts("FAIL (Unable to find attribute \"auth-info\")"); + status ++; + } + else if (ippGetValueTag(attr) != IPP_TAG_TEXT) + { + printf("FAIL (\"auth-info\" of type %s, expected text)\n", ippTagString(ippGetValueTag(attr))); + status ++; + } + else if (ippGetCount(attr) != 2) + { + printf("FAIL (\"auth-info\" has %d values, expected 2)\n", (int)ippGetCount(attr)); + status ++; + } + else if (strcmp(ippGetString(attr, 0, NULL), "user")) + { + printf("FAIL (\"auth-info\"[0] has value \"%s\", expected \"user\")\n", ippGetString(attr, 0, NULL)); + status ++; + } + else if (strcmp(ippGetString(attr, 1, NULL), "pass,word\\")) + { + printf("FAIL (\"auth-info\"[1] has value \"%s\", expected \"pass,word\\\")\n", ippGetString(attr, 1, NULL)); + status ++; + } else puts("PASS"); } @@ -110,8 +166,3 @@ main(int argc, /* I - Number of command-line arguments */ exit (status); } - - -/* - * End of "$Id$". - */