]>
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 * Licensed under Apache License v2.0. See the file "LICENSE" for more information.
10 * Include necessary headers...
13 #include "cups-private.h"
17 * 'main()' - Test option processing functions.
20 int /* O - Exit status */
21 main(int argc
, /* I - Number of command-line arguments */
22 char *argv
[]) /* I - Command-line arguments */
24 int status
= 0, /* Exit status */
25 num_options
; /* Number of options */
26 cups_option_t
*options
; /* Options */
27 const char *value
; /* Value of an option */
28 ipp_t
*request
; /* IPP request */
29 ipp_attribute_t
*attr
; /* IPP attribute */
30 int count
; /* Number of attributes */
39 fputs("cupsParseOptions: ", stdout
);
41 num_options
= cupsParseOptions("foo=1234 "
42 "bar=\"One Fish\",\"Two Fish\",\"Red Fish\","
44 "baz={param1=1 param2=2} "
47 "barfoo=\"\'BAR FOO\'\" "
48 "auth-info=user,pass\\\\,word\\\\\\\\", 0, &options
);
52 printf("FAIL (num_options=%d, expected 6)\n", num_options
);
55 else if ((value
= cupsGetOption("foo", num_options
, options
)) == NULL
||
56 strcmp(value
, "1234"))
58 printf("FAIL (foo=\"%s\", expected \"1234\")\n", value
);
61 else if ((value
= cupsGetOption("bar", num_options
, options
)) == NULL
||
62 strcmp(value
, "One Fish,Two Fish,Red Fish,Blue Fish"))
64 printf("FAIL (bar=\"%s\", expected \"One Fish,Two Fish,Red Fish,Blue "
68 else if ((value
= cupsGetOption("baz", num_options
, options
)) == NULL
||
69 strcmp(value
, "{param1=1 param2=2}"))
71 printf("FAIL (baz=\"%s\", expected \"{param1=1 param2=2}\")\n", value
);
74 else if ((value
= cupsGetOption("foobar", num_options
, options
)) == NULL
||
75 strcmp(value
, "FOO BAR"))
77 printf("FAIL (foobar=\"%s\", expected \"FOO BAR\")\n", value
);
80 else if ((value
= cupsGetOption("barfoo", num_options
, options
)) == NULL
||
81 strcmp(value
, "\'BAR FOO\'"))
83 printf("FAIL (barfoo=\"%s\", expected \"\'BAR FOO\'\")\n", value
);
86 else if ((value
= cupsGetOption("auth-info", num_options
, options
)) == NULL
||
87 strcmp(value
, "user,pass\\,word\\\\"))
89 printf("FAIL (auth-info=\"%s\", expected \"user,pass\\,word\\\\\")\n", value
);
95 fputs("cupsEncodeOptions2: ", stdout
);
97 ippSetOperation(request
, IPP_OP_PRINT_JOB
);
99 cupsEncodeOptions2(request
, num_options
, options
, IPP_TAG_JOB
);
100 for (count
= 0, attr
= ippFirstAttribute(request
); attr
; attr
= ippNextAttribute(request
), count
++);
103 printf("FAIL (%d attributes, expected 6)\n", count
);
106 else if ((attr
= ippFindAttribute(request
, "foo", IPP_TAG_ZERO
)) == NULL
)
108 puts("FAIL (Unable to find attribute \"foo\")");
111 else if (ippGetValueTag(attr
) != IPP_TAG_NAME
)
113 printf("FAIL (\"foo\" of type %s, expected name)\n", ippTagString(ippGetValueTag(attr
)));
116 else if (ippGetCount(attr
) != 1)
118 printf("FAIL (\"foo\" has %d values, expected 1)\n", (int)ippGetCount(attr
));
121 else if (strcmp(ippGetString(attr
, 0, NULL
), "1234"))
123 printf("FAIL (\"foo\" has value %s, expected 1234)\n", ippGetString(attr
, 0, NULL
));
126 else if ((attr
= ippFindAttribute(request
, "auth-info", IPP_TAG_ZERO
)) == NULL
)
128 puts("FAIL (Unable to find attribute \"auth-info\")");
131 else if (ippGetValueTag(attr
) != IPP_TAG_TEXT
)
133 printf("FAIL (\"auth-info\" of type %s, expected text)\n", ippTagString(ippGetValueTag(attr
)));
136 else if (ippGetCount(attr
) != 2)
138 printf("FAIL (\"auth-info\" has %d values, expected 2)\n", (int)ippGetCount(attr
));
141 else if (strcmp(ippGetString(attr
, 0, NULL
), "user"))
143 printf("FAIL (\"auth-info\"[0] has value \"%s\", expected \"user\")\n", ippGetString(attr
, 0, NULL
));
146 else if (strcmp(ippGetString(attr
, 1, NULL
), "pass,word\\"))
148 printf("FAIL (\"auth-info\"[1] has value \"%s\", expected \"pass,word\\\")\n", ippGetString(attr
, 1, NULL
));
156 int i
; /* Looping var */
157 cups_option_t
*option
; /* Current option */
160 num_options
= cupsParseOptions(argv
[1], 0, &options
);
162 for (i
= 0, option
= options
; i
< num_options
; i
++, option
++)
163 printf("options[%d].name=\"%s\", value=\"%s\"\n", i
, option
->name
,