]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testoptions.c
2 * Option unit test program for CUPS.
4 * Copyright 2008-2016 by Apple Inc.
6 * These coded instructions, statements, and computer programs are the
7 * property of Apple Inc. and are protected by Federal copyright
8 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
9 * which should have been included with this file. If this file is
10 * file is missing or damaged, see the license at "http://www.cups.org/".
12 * This file is subject to the Apple OS-Developed Software exception.
16 * Include necessary headers...
19 #include "cups-private.h"
23 * 'main()' - Test option processing functions.
26 int /* O - Exit status */
27 main(int argc
, /* I - Number of command-line arguments */
28 char *argv
[]) /* I - Command-line arguments */
30 int status
= 0, /* Exit status */
31 num_options
; /* Number of options */
32 cups_option_t
*options
; /* Options */
33 const char *value
; /* Value of an option */
34 ipp_t
*request
; /* IPP request */
35 ipp_attribute_t
*attr
; /* IPP attribute */
36 int count
; /* Number of attributes */
45 fputs("cupsParseOptions: ", stdout
);
47 num_options
= cupsParseOptions("foo=1234 "
48 "bar=\"One Fish\",\"Two Fish\",\"Red Fish\","
50 "baz={param1=1 param2=2} "
53 "barfoo=\"\'BAR FOO\'\" "
54 "auth-info=user,pass\\\\,word\\\\\\\\", 0, &options
);
58 printf("FAIL (num_options=%d, expected 6)\n", num_options
);
61 else if ((value
= cupsGetOption("foo", num_options
, options
)) == NULL
||
62 strcmp(value
, "1234"))
64 printf("FAIL (foo=\"%s\", expected \"1234\")\n", value
);
67 else if ((value
= cupsGetOption("bar", num_options
, options
)) == NULL
||
68 strcmp(value
, "One Fish,Two Fish,Red Fish,Blue Fish"))
70 printf("FAIL (bar=\"%s\", expected \"One Fish,Two Fish,Red Fish,Blue "
74 else if ((value
= cupsGetOption("baz", num_options
, options
)) == NULL
||
75 strcmp(value
, "{param1=1 param2=2}"))
77 printf("FAIL (baz=\"%s\", expected \"{param1=1 param2=2}\")\n", value
);
80 else if ((value
= cupsGetOption("foobar", num_options
, options
)) == NULL
||
81 strcmp(value
, "FOO BAR"))
83 printf("FAIL (foobar=\"%s\", expected \"FOO BAR\")\n", value
);
86 else if ((value
= cupsGetOption("barfoo", num_options
, options
)) == NULL
||
87 strcmp(value
, "\'BAR FOO\'"))
89 printf("FAIL (barfoo=\"%s\", expected \"\'BAR FOO\'\")\n", value
);
92 else if ((value
= cupsGetOption("auth-info", num_options
, options
)) == NULL
||
93 strcmp(value
, "user,pass\\,word\\\\"))
95 printf("FAIL (auth-info=\"%s\", expected \"user,pass\\,word\\\\\")\n", value
);
101 fputs("cupsEncodeOptions2: ", stdout
);
103 ippSetOperation(request
, IPP_OP_PRINT_JOB
);
105 cupsEncodeOptions2(request
, num_options
, options
, IPP_TAG_JOB
);
106 for (count
= 0, attr
= ippFirstAttribute(request
); attr
; attr
= ippNextAttribute(request
), count
++);
109 printf("FAIL (%d attributes, expected 6)\n", count
);
112 else if ((attr
= ippFindAttribute(request
, "foo", IPP_TAG_ZERO
)) == NULL
)
114 puts("FAIL (Unable to find attribute \"foo\")");
117 else if (ippGetValueTag(attr
) != IPP_TAG_NAME
)
119 printf("FAIL (\"foo\" of type %s, expected name)\n", ippTagString(ippGetValueTag(attr
)));
122 else if (ippGetCount(attr
) != 1)
124 printf("FAIL (\"foo\" has %d values, expected 1)\n", (int)ippGetCount(attr
));
127 else if (strcmp(ippGetString(attr
, 0, NULL
), "1234"))
129 printf("FAIL (\"foo\" has value %s, expected 1234)\n", ippGetString(attr
, 0, NULL
));
132 else if ((attr
= ippFindAttribute(request
, "auth-info", IPP_TAG_ZERO
)) == NULL
)
134 puts("FAIL (Unable to find attribute \"auth-info\")");
137 else if (ippGetValueTag(attr
) != IPP_TAG_TEXT
)
139 printf("FAIL (\"auth-info\" of type %s, expected text)\n", ippTagString(ippGetValueTag(attr
)));
142 else if (ippGetCount(attr
) != 2)
144 printf("FAIL (\"auth-info\" has %d values, expected 2)\n", (int)ippGetCount(attr
));
147 else if (strcmp(ippGetString(attr
, 0, NULL
), "user"))
149 printf("FAIL (\"auth-info\"[0] has value \"%s\", expected \"user\")\n", ippGetString(attr
, 0, NULL
));
152 else if (strcmp(ippGetString(attr
, 1, NULL
), "pass,word\\"))
154 printf("FAIL (\"auth-info\"[1] has value \"%s\", expected \"pass,word\\\")\n", ippGetString(attr
, 1, NULL
));
162 int i
; /* Looping var */
163 cups_option_t
*option
; /* Current option */
166 num_options
= cupsParseOptions(argv
[1], 0, &options
);
168 for (i
= 0, option
= options
; i
< num_options
; i
++, option
++)
169 printf("options[%d].name=\"%s\", value=\"%s\"\n", i
, option
->name
,