]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testoptions.c
2 * "$Id: testoptions.c 13138 2016-03-15 14:59:54Z msweet $"
4 * Option unit test program for CUPS.
6 * Copyright 2008-2016 by Apple Inc.
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
14 * This file is subject to the Apple OS-Developed Software exception.
18 * Include necessary headers...
21 #include "cups-private.h"
25 * 'main()' - Test option processing functions.
28 int /* O - Exit status */
29 main(int argc
, /* I - Number of command-line arguments */
30 char *argv
[]) /* I - Command-line arguments */
32 int status
= 0, /* Exit status */
33 num_options
; /* Number of options */
34 cups_option_t
*options
; /* Options */
35 const char *value
; /* Value of an option */
36 ipp_t
*request
; /* IPP request */
37 ipp_attribute_t
*attr
; /* IPP attribute */
38 int count
; /* Number of attributes */
47 fputs("cupsParseOptions: ", stdout
);
49 num_options
= cupsParseOptions("foo=1234 "
50 "bar=\"One Fish\",\"Two Fish\",\"Red Fish\","
52 "baz={param1=1 param2=2} "
55 "barfoo=\"\'BAR FOO\'\" "
56 "auth-info=user,pass\\\\,word\\\\\\\\", 0, &options
);
60 printf("FAIL (num_options=%d, expected 6)\n", num_options
);
63 else if ((value
= cupsGetOption("foo", num_options
, options
)) == NULL
||
64 strcmp(value
, "1234"))
66 printf("FAIL (foo=\"%s\", expected \"1234\")\n", value
);
69 else if ((value
= cupsGetOption("bar", num_options
, options
)) == NULL
||
70 strcmp(value
, "One Fish,Two Fish,Red Fish,Blue Fish"))
72 printf("FAIL (bar=\"%s\", expected \"One Fish,Two Fish,Red Fish,Blue "
76 else if ((value
= cupsGetOption("baz", num_options
, options
)) == NULL
||
77 strcmp(value
, "{param1=1 param2=2}"))
79 printf("FAIL (baz=\"%s\", expected \"{param1=1 param2=2}\")\n", value
);
82 else if ((value
= cupsGetOption("foobar", num_options
, options
)) == NULL
||
83 strcmp(value
, "FOO BAR"))
85 printf("FAIL (foobar=\"%s\", expected \"FOO BAR\")\n", value
);
88 else if ((value
= cupsGetOption("barfoo", num_options
, options
)) == NULL
||
89 strcmp(value
, "\'BAR FOO\'"))
91 printf("FAIL (barfoo=\"%s\", expected \"\'BAR FOO\'\")\n", value
);
94 else if ((value
= cupsGetOption("auth-info", num_options
, options
)) == NULL
||
95 strcmp(value
, "user,pass\\,word\\\\"))
97 printf("FAIL (auth-info=\"%s\", expected \"user,pass\\,word\\\\\")\n", value
);
103 fputs("cupsEncodeOptions2: ", stdout
);
105 ippSetOperation(request
, IPP_OP_PRINT_JOB
);
107 cupsEncodeOptions2(request
, num_options
, options
, IPP_TAG_JOB
);
108 for (count
= 0, attr
= ippFirstAttribute(request
); attr
; attr
= ippNextAttribute(request
), count
++);
111 printf("FAIL (%d attributes, expected 6)\n", count
);
114 else if ((attr
= ippFindAttribute(request
, "foo", IPP_TAG_ZERO
)) == NULL
)
116 puts("FAIL (Unable to find attribute \"foo\")");
119 else if (ippGetValueTag(attr
) != IPP_TAG_NAME
)
121 printf("FAIL (\"foo\" of type %s, expected name)\n", ippTagString(ippGetValueTag(attr
)));
124 else if (ippGetCount(attr
) != 1)
126 printf("FAIL (\"foo\" has %d values, expected 1)\n", (int)ippGetCount(attr
));
129 else if (strcmp(ippGetString(attr
, 0, NULL
), "1234"))
131 printf("FAIL (\"foo\" has value %s, expected 1234)\n", ippGetString(attr
, 0, NULL
));
134 else if ((attr
= ippFindAttribute(request
, "auth-info", IPP_TAG_ZERO
)) == NULL
)
136 puts("FAIL (Unable to find attribute \"auth-info\")");
139 else if (ippGetValueTag(attr
) != IPP_TAG_TEXT
)
141 printf("FAIL (\"auth-info\" of type %s, expected text)\n", ippTagString(ippGetValueTag(attr
)));
144 else if (ippGetCount(attr
) != 2)
146 printf("FAIL (\"auth-info\" has %d values, expected 2)\n", (int)ippGetCount(attr
));
149 else if (strcmp(ippGetString(attr
, 0, NULL
), "user"))
151 printf("FAIL (\"auth-info\"[0] has value \"%s\", expected \"user\")\n", ippGetString(attr
, 0, NULL
));
154 else if (strcmp(ippGetString(attr
, 1, NULL
), "pass,word\\"))
156 printf("FAIL (\"auth-info\"[1] has value \"%s\", expected \"pass,word\\\")\n", ippGetString(attr
, 1, NULL
));
164 int i
; /* Looping var */
165 cups_option_t
*option
; /* Current option */
168 num_options
= cupsParseOptions(argv
[1], 0, &options
);
170 for (i
= 0, option
= options
; i
< num_options
; i
++, option
++)
171 printf("options[%d].name=\"%s\", value=\"%s\"\n", i
, option
->name
,
180 * End of "$Id: testoptions.c 13138 2016-03-15 14:59:54Z msweet $".