]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/testoptions.c
Import experimental work-in-progress HTTP/2 branch
[thirdparty/cups.git] / cups / testoptions.c
1 /*
2 * "$Id: testoptions.c 13138 2016-03-15 14:59:54Z msweet $"
3 *
4 * Option unit test program for CUPS.
5 *
6 * Copyright 2008-2016 by Apple Inc.
7 *
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/".
13 *
14 * This file is subject to the Apple OS-Developed Software exception.
15 */
16
17 /*
18 * Include necessary headers...
19 */
20
21 #include "cups-private.h"
22
23
24 /*
25 * 'main()' - Test option processing functions.
26 */
27
28 int /* O - Exit status */
29 main(int argc, /* I - Number of command-line arguments */
30 char *argv[]) /* I - Command-line arguments */
31 {
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 */
39
40
41 if (argc == 1)
42 {
43 /*
44 * cupsParseOptions()
45 */
46
47 fputs("cupsParseOptions: ", stdout);
48
49 num_options = cupsParseOptions("foo=1234 "
50 "bar=\"One Fish\",\"Two Fish\",\"Red Fish\","
51 "\"Blue Fish\" "
52 "baz={param1=1 param2=2} "
53 "foobar=FOO\\ BAR "
54 "barfoo=barfoo "
55 "barfoo=\"\'BAR FOO\'\" "
56 "auth-info=user,pass\\\\,word\\\\\\\\", 0, &options);
57
58 if (num_options != 6)
59 {
60 printf("FAIL (num_options=%d, expected 6)\n", num_options);
61 status ++;
62 }
63 else if ((value = cupsGetOption("foo", num_options, options)) == NULL ||
64 strcmp(value, "1234"))
65 {
66 printf("FAIL (foo=\"%s\", expected \"1234\")\n", value);
67 status ++;
68 }
69 else if ((value = cupsGetOption("bar", num_options, options)) == NULL ||
70 strcmp(value, "One Fish,Two Fish,Red Fish,Blue Fish"))
71 {
72 printf("FAIL (bar=\"%s\", expected \"One Fish,Two Fish,Red Fish,Blue "
73 "Fish\")\n", value);
74 status ++;
75 }
76 else if ((value = cupsGetOption("baz", num_options, options)) == NULL ||
77 strcmp(value, "{param1=1 param2=2}"))
78 {
79 printf("FAIL (baz=\"%s\", expected \"{param1=1 param2=2}\")\n", value);
80 status ++;
81 }
82 else if ((value = cupsGetOption("foobar", num_options, options)) == NULL ||
83 strcmp(value, "FOO BAR"))
84 {
85 printf("FAIL (foobar=\"%s\", expected \"FOO BAR\")\n", value);
86 status ++;
87 }
88 else if ((value = cupsGetOption("barfoo", num_options, options)) == NULL ||
89 strcmp(value, "\'BAR FOO\'"))
90 {
91 printf("FAIL (barfoo=\"%s\", expected \"\'BAR FOO\'\")\n", value);
92 status ++;
93 }
94 else if ((value = cupsGetOption("auth-info", num_options, options)) == NULL ||
95 strcmp(value, "user,pass\\,word\\\\"))
96 {
97 printf("FAIL (auth-info=\"%s\", expected \"user,pass\\,word\\\\\")\n", value);
98 status ++;
99 }
100 else
101 puts("PASS");
102
103 fputs("cupsEncodeOptions2: ", stdout);
104 request = ippNew();
105 ippSetOperation(request, IPP_OP_PRINT_JOB);
106
107 cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB);
108 for (count = 0, attr = ippFirstAttribute(request); attr; attr = ippNextAttribute(request), count ++);
109 if (count != 6)
110 {
111 printf("FAIL (%d attributes, expected 6)\n", count);
112 status ++;
113 }
114 else if ((attr = ippFindAttribute(request, "foo", IPP_TAG_ZERO)) == NULL)
115 {
116 puts("FAIL (Unable to find attribute \"foo\")");
117 status ++;
118 }
119 else if (ippGetValueTag(attr) != IPP_TAG_NAME)
120 {
121 printf("FAIL (\"foo\" of type %s, expected name)\n", ippTagString(ippGetValueTag(attr)));
122 status ++;
123 }
124 else if (ippGetCount(attr) != 1)
125 {
126 printf("FAIL (\"foo\" has %d values, expected 1)\n", (int)ippGetCount(attr));
127 status ++;
128 }
129 else if (strcmp(ippGetString(attr, 0, NULL), "1234"))
130 {
131 printf("FAIL (\"foo\" has value %s, expected 1234)\n", ippGetString(attr, 0, NULL));
132 status ++;
133 }
134 else if ((attr = ippFindAttribute(request, "auth-info", IPP_TAG_ZERO)) == NULL)
135 {
136 puts("FAIL (Unable to find attribute \"auth-info\")");
137 status ++;
138 }
139 else if (ippGetValueTag(attr) != IPP_TAG_TEXT)
140 {
141 printf("FAIL (\"auth-info\" of type %s, expected text)\n", ippTagString(ippGetValueTag(attr)));
142 status ++;
143 }
144 else if (ippGetCount(attr) != 2)
145 {
146 printf("FAIL (\"auth-info\" has %d values, expected 2)\n", (int)ippGetCount(attr));
147 status ++;
148 }
149 else if (strcmp(ippGetString(attr, 0, NULL), "user"))
150 {
151 printf("FAIL (\"auth-info\"[0] has value \"%s\", expected \"user\")\n", ippGetString(attr, 0, NULL));
152 status ++;
153 }
154 else if (strcmp(ippGetString(attr, 1, NULL), "pass,word\\"))
155 {
156 printf("FAIL (\"auth-info\"[1] has value \"%s\", expected \"pass,word\\\")\n", ippGetString(attr, 1, NULL));
157 status ++;
158 }
159 else
160 puts("PASS");
161 }
162 else
163 {
164 int i; /* Looping var */
165 cups_option_t *option; /* Current option */
166
167
168 num_options = cupsParseOptions(argv[1], 0, &options);
169
170 for (i = 0, option = options; i < num_options; i ++, option ++)
171 printf("options[%d].name=\"%s\", value=\"%s\"\n", i, option->name,
172 option->value);
173 }
174
175 exit (status);
176 }
177
178
179 /*
180 * End of "$Id: testoptions.c 13138 2016-03-15 14:59:54Z msweet $".
181 */