]>
Commit | Line | Data |
---|---|---|
20fbc903 MS |
1 | /* |
2 | * "$Id$" | |
3 | * | |
4 | * Option test program for the Common UNIX Printing System (CUPS). | |
5 | * | |
6 | * Copyright 2008 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 | * Contents: | |
17 | * | |
18 | * main() - Test option processing functions. | |
19 | */ | |
20 | ||
21 | /* | |
22 | * Include necessary headers... | |
23 | */ | |
24 | ||
25 | #include "string.h" | |
26 | #include "cups.h" | |
27 | ||
28 | ||
29 | /* | |
30 | * 'main()' - Test option processing functions. | |
31 | */ | |
32 | ||
33 | int /* O - Exit status */ | |
34 | main(int argc, /* I - Number of command-line arguments */ | |
35 | char *argv[]) /* I - Command-line arguments */ | |
36 | { | |
37 | int status = 0, /* Exit status */ | |
38 | num_options; /* Number of options */ | |
39 | cups_option_t *options; /* Options */ | |
40 | const char *value; /* Value of an option */ | |
41 | ||
42 | ||
43 | if (argc == 1) | |
44 | { | |
45 | /* | |
46 | * cupsParseOptions() | |
47 | */ | |
48 | ||
49 | fputs("cupsParseOptions: ", stdout); | |
50 | ||
51 | num_options = cupsParseOptions("foo=1234 " | |
52 | "bar=\"One Fish\",\"Two Fish\",\"Red Fish\"," | |
53 | "\"Blue Fish\" " | |
54 | "baz={param1=1 param2=2} " | |
55 | "foobar=FOO\\ BAR " | |
56 | "barfoo=barfoo " | |
57 | "barfoo=\"\'BAR FOO\'\"", 0, &options); | |
58 | ||
59 | if (num_options != 5) | |
60 | { | |
61 | printf("FAIL (num_options=%d, expected 5)\n", num_options); | |
62 | status ++; | |
63 | } | |
64 | else if ((value = cupsGetOption("foo", num_options, options)) == NULL || | |
65 | strcmp(value, "1234")) | |
66 | { | |
67 | printf("FAIL (foo=\"%s\", expected \"1234\")\n", value); | |
68 | status ++; | |
69 | } | |
70 | else if ((value = cupsGetOption("bar", num_options, options)) == NULL || | |
71 | strcmp(value, "One Fish,Two Fish,Red Fish,Blue Fish")) | |
72 | { | |
73 | printf("FAIL (bar=\"%s\", expected \"One Fish,Two Fish,Red Fish,Blue " | |
74 | "Fish\")\n", value); | |
75 | status ++; | |
76 | } | |
77 | else if ((value = cupsGetOption("baz", num_options, options)) == NULL || | |
78 | strcmp(value, "{param1=1 param2=2}")) | |
79 | { | |
80 | printf("FAIL (baz=\"%s\", expected \"{param1=1 param2=2}\")\n", value); | |
81 | status ++; | |
82 | } | |
83 | else if ((value = cupsGetOption("foobar", num_options, options)) == NULL || | |
84 | strcmp(value, "FOO BAR")) | |
85 | { | |
86 | printf("FAIL (foobar=\"%s\", expected \"FOO BAR\")\n", value); | |
87 | status ++; | |
88 | } | |
89 | else if ((value = cupsGetOption("barfoo", num_options, options)) == NULL || | |
90 | strcmp(value, "\'BAR FOO\'")) | |
91 | { | |
92 | printf("FAIL (barfoo=\"%s\", expected \"\'BAR FOO\'\")\n", value); | |
93 | status ++; | |
94 | } | |
95 | else | |
96 | puts("PASS"); | |
97 | } | |
98 | else | |
99 | { | |
100 | int i; /* Looping var */ | |
101 | cups_option_t *option; /* Current option */ | |
102 | ||
103 | ||
104 | num_options = cupsParseOptions(argv[1], 0, &options); | |
105 | ||
106 | for (i = 0, option = options; i < num_options; i ++, option ++) | |
107 | printf("options[%d].name=\"%s\", value=\"%s\"\n", i, option->name, | |
108 | option->value); | |
109 | } | |
110 | ||
111 | exit (status); | |
112 | } | |
113 | ||
114 | ||
115 | /* | |
116 | * End of "$Id$". | |
117 | */ |