]>
Commit | Line | Data |
---|---|---|
20fbc903 | 1 | /* |
14fa491e | 2 | * Option unit test program for CUPS. |
20fbc903 | 3 | * |
14fa491e | 4 | * Copyright 2008-2016 by Apple Inc. |
20fbc903 | 5 | * |
e3101897 | 6 | * Licensed under Apache License v2.0. See the file "LICENSE" for more information. |
20fbc903 MS |
7 | */ |
8 | ||
9 | /* | |
10 | * Include necessary headers... | |
11 | */ | |
12 | ||
71e16022 | 13 | #include "cups-private.h" |
20fbc903 MS |
14 | |
15 | ||
16 | /* | |
17 | * 'main()' - Test option processing functions. | |
18 | */ | |
19 | ||
20 | int /* O - Exit status */ | |
21 | main(int argc, /* I - Number of command-line arguments */ | |
22 | char *argv[]) /* I - Command-line arguments */ | |
23 | { | |
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 */ | |
14fa491e MS |
28 | ipp_t *request; /* IPP request */ |
29 | ipp_attribute_t *attr; /* IPP attribute */ | |
30 | int count; /* Number of attributes */ | |
20fbc903 MS |
31 | |
32 | ||
33 | if (argc == 1) | |
34 | { | |
35 | /* | |
36 | * cupsParseOptions() | |
37 | */ | |
38 | ||
39 | fputs("cupsParseOptions: ", stdout); | |
40 | ||
41 | num_options = cupsParseOptions("foo=1234 " | |
42 | "bar=\"One Fish\",\"Two Fish\",\"Red Fish\"," | |
43 | "\"Blue Fish\" " | |
44 | "baz={param1=1 param2=2} " | |
45 | "foobar=FOO\\ BAR " | |
46 | "barfoo=barfoo " | |
14fa491e MS |
47 | "barfoo=\"\'BAR FOO\'\" " |
48 | "auth-info=user,pass\\\\,word\\\\\\\\", 0, &options); | |
20fbc903 | 49 | |
14fa491e | 50 | if (num_options != 6) |
20fbc903 | 51 | { |
14fa491e | 52 | printf("FAIL (num_options=%d, expected 6)\n", num_options); |
20fbc903 MS |
53 | status ++; |
54 | } | |
55 | else if ((value = cupsGetOption("foo", num_options, options)) == NULL || | |
56 | strcmp(value, "1234")) | |
57 | { | |
58 | printf("FAIL (foo=\"%s\", expected \"1234\")\n", value); | |
59 | status ++; | |
60 | } | |
61 | else if ((value = cupsGetOption("bar", num_options, options)) == NULL || | |
62 | strcmp(value, "One Fish,Two Fish,Red Fish,Blue Fish")) | |
63 | { | |
64 | printf("FAIL (bar=\"%s\", expected \"One Fish,Two Fish,Red Fish,Blue " | |
65 | "Fish\")\n", value); | |
66 | status ++; | |
67 | } | |
68 | else if ((value = cupsGetOption("baz", num_options, options)) == NULL || | |
69 | strcmp(value, "{param1=1 param2=2}")) | |
70 | { | |
71 | printf("FAIL (baz=\"%s\", expected \"{param1=1 param2=2}\")\n", value); | |
72 | status ++; | |
73 | } | |
74 | else if ((value = cupsGetOption("foobar", num_options, options)) == NULL || | |
75 | strcmp(value, "FOO BAR")) | |
76 | { | |
77 | printf("FAIL (foobar=\"%s\", expected \"FOO BAR\")\n", value); | |
78 | status ++; | |
79 | } | |
80 | else if ((value = cupsGetOption("barfoo", num_options, options)) == NULL || | |
81 | strcmp(value, "\'BAR FOO\'")) | |
82 | { | |
83 | printf("FAIL (barfoo=\"%s\", expected \"\'BAR FOO\'\")\n", value); | |
84 | status ++; | |
85 | } | |
14fa491e MS |
86 | else if ((value = cupsGetOption("auth-info", num_options, options)) == NULL || |
87 | strcmp(value, "user,pass\\,word\\\\")) | |
88 | { | |
89 | printf("FAIL (auth-info=\"%s\", expected \"user,pass\\,word\\\\\")\n", value); | |
90 | status ++; | |
91 | } | |
92 | else | |
93 | puts("PASS"); | |
94 | ||
95 | fputs("cupsEncodeOptions2: ", stdout); | |
96 | request = ippNew(); | |
97 | ippSetOperation(request, IPP_OP_PRINT_JOB); | |
98 | ||
99 | cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB); | |
100 | for (count = 0, attr = ippFirstAttribute(request); attr; attr = ippNextAttribute(request), count ++); | |
101 | if (count != 6) | |
102 | { | |
103 | printf("FAIL (%d attributes, expected 6)\n", count); | |
104 | status ++; | |
105 | } | |
106 | else if ((attr = ippFindAttribute(request, "foo", IPP_TAG_ZERO)) == NULL) | |
107 | { | |
108 | puts("FAIL (Unable to find attribute \"foo\")"); | |
109 | status ++; | |
110 | } | |
111 | else if (ippGetValueTag(attr) != IPP_TAG_NAME) | |
112 | { | |
113 | printf("FAIL (\"foo\" of type %s, expected name)\n", ippTagString(ippGetValueTag(attr))); | |
114 | status ++; | |
115 | } | |
116 | else if (ippGetCount(attr) != 1) | |
117 | { | |
118 | printf("FAIL (\"foo\" has %d values, expected 1)\n", (int)ippGetCount(attr)); | |
119 | status ++; | |
120 | } | |
121 | else if (strcmp(ippGetString(attr, 0, NULL), "1234")) | |
122 | { | |
123 | printf("FAIL (\"foo\" has value %s, expected 1234)\n", ippGetString(attr, 0, NULL)); | |
124 | status ++; | |
125 | } | |
126 | else if ((attr = ippFindAttribute(request, "auth-info", IPP_TAG_ZERO)) == NULL) | |
127 | { | |
128 | puts("FAIL (Unable to find attribute \"auth-info\")"); | |
129 | status ++; | |
130 | } | |
131 | else if (ippGetValueTag(attr) != IPP_TAG_TEXT) | |
132 | { | |
133 | printf("FAIL (\"auth-info\" of type %s, expected text)\n", ippTagString(ippGetValueTag(attr))); | |
134 | status ++; | |
135 | } | |
136 | else if (ippGetCount(attr) != 2) | |
137 | { | |
138 | printf("FAIL (\"auth-info\" has %d values, expected 2)\n", (int)ippGetCount(attr)); | |
139 | status ++; | |
140 | } | |
141 | else if (strcmp(ippGetString(attr, 0, NULL), "user")) | |
142 | { | |
143 | printf("FAIL (\"auth-info\"[0] has value \"%s\", expected \"user\")\n", ippGetString(attr, 0, NULL)); | |
144 | status ++; | |
145 | } | |
146 | else if (strcmp(ippGetString(attr, 1, NULL), "pass,word\\")) | |
147 | { | |
148 | printf("FAIL (\"auth-info\"[1] has value \"%s\", expected \"pass,word\\\")\n", ippGetString(attr, 1, NULL)); | |
149 | status ++; | |
150 | } | |
20fbc903 MS |
151 | else |
152 | puts("PASS"); | |
153 | } | |
154 | else | |
155 | { | |
156 | int i; /* Looping var */ | |
157 | cups_option_t *option; /* Current option */ | |
158 | ||
159 | ||
160 | num_options = cupsParseOptions(argv[1], 0, &options); | |
161 | ||
162 | for (i = 0, option = options; i < num_options; i ++, option ++) | |
163 | printf("options[%d].name=\"%s\", value=\"%s\"\n", i, option->name, | |
164 | option->value); | |
165 | } | |
166 | ||
167 | exit (status); | |
168 | } |