1 /* 2 * Option unit test program for CUPS. 3 * 4 * Copyright 2008-2016 by Apple Inc. 5 * 6 * These coded instructions, statements, and computer programs are the 7 * property of Apple Inc. and are protected by Federal copyright 8 * law. Distribution and use rights are outlined in the file "LICENSE.txt" 9 * which should have been included with this file. If this file is 10 * missing or damaged, see the license at "http://www.cups.org/". 11 * 12 * This file is subject to the Apple OS-Developed Software exception. 13 */ 14 15 /* 16 * Include necessary headers... 17 */ 18 19 #include "cups-private.h" 20 21 22 /* 23 * 'main()' - Test option processing functions. 24 */ 25 26 int /* O - Exit status */ 27 main(int argc, /* I - Number of command-line arguments */ 28 char *argv[]) /* I - Command-line arguments */ 29 { 30 int status = 0, /* Exit status */ 31 num_options; /* Number of options */ 32 cups_option_t *options; /* Options */ 33 const char *value; /* Value of an option */ 34 ipp_t *request; /* IPP request */ 35 ipp_attribute_t *attr; /* IPP attribute */ 36 int count; /* Number of attributes */ 37 38 39 if (argc == 1) 40 { 41 /* 42 * cupsParseOptions() 43 */ 44 45 fputs("cupsParseOptions: ", stdout); 46 47 num_options = cupsParseOptions("foo=1234 " 48 "bar=\"One Fish\",\"Two Fish\",\"Red Fish\"," 49 "\"Blue Fish\" " 50 "baz={param1=1 param2=2} " 51 "foobar=FOO\\ BAR " 52 "barfoo=barfoo " 53 "barfoo=\"\'BAR FOO\'\" " 54 "auth-info=user,pass\\\\,word\\\\\\\\", 0, &options); 55 56 if (num_options != 6) 57 { 58 printf("FAIL (num_options=%d, expected 6)\n", num_options); 59 status ++; 60 } 61 else if ((value = cupsGetOption("foo", num_options, options)) == NULL || 62 strcmp(value, "1234")) 63 { 64 printf("FAIL (foo=\"%s\", expected \"1234\")\n", value); 65 status ++; 66 } 67 else if ((value = cupsGetOption("bar", num_options, options)) == NULL || 68 strcmp(value, "One Fish,Two Fish,Red Fish,Blue Fish")) 69 { 70 printf("FAIL (bar=\"%s\", expected \"One Fish,Two Fish,Red Fish,Blue " 71 "Fish\")\n", value); 72 status ++; 73 } 74 else if ((value = cupsGetOption("baz", num_options, options)) == NULL || 75 strcmp(value, "{param1=1 param2=2}")) 76 { 77 printf("FAIL (baz=\"%s\", expected \"{param1=1 param2=2}\")\n", value); 78 status ++; 79 } 80 else if ((value = cupsGetOption("foobar", num_options, options)) == NULL || 81 strcmp(value, "FOO BAR")) 82 { 83 printf("FAIL (foobar=\"%s\", expected \"FOO BAR\")\n", value); 84 status ++; 85 } 86 else if ((value = cupsGetOption("barfoo", num_options, options)) == NULL || 87 strcmp(value, "\'BAR FOO\'")) 88 { 89 printf("FAIL (barfoo=\"%s\", expected \"\'BAR FOO\'\")\n", value); 90 status ++; 91 } 92 else if ((value = cupsGetOption("auth-info", num_options, options)) == NULL || 93 strcmp(value, "user,pass\\,word\\\\")) 94 { 95 printf("FAIL (auth-info=\"%s\", expected \"user,pass\\,word\\\\\")\n", value); 96 status ++; 97 } 98 else 99 puts("PASS"); 100 101 fputs("cupsEncodeOptions2: ", stdout); 102 request = ippNew(); 103 ippSetOperation(request, IPP_OP_PRINT_JOB); 104 105 cupsEncodeOptions2(request, num_options, options, IPP_TAG_JOB); 106 for (count = 0, attr = ippFirstAttribute(request); attr; attr = ippNextAttribute(request), count ++); 107 if (count != 6) 108 { 109 printf("FAIL (%d attributes, expected 6)\n", count); 110 status ++; 111 } 112 else if ((attr = ippFindAttribute(request, "foo", IPP_TAG_ZERO)) == NULL) 113 { 114 puts("FAIL (Unable to find attribute \"foo\")"); 115 status ++; 116 } 117 else if (ippGetValueTag(attr) != IPP_TAG_NAME) 118 { 119 printf("FAIL (\"foo\" of type %s, expected name)\n", ippTagString(ippGetValueTag(attr))); 120 status ++; 121 } 122 else if (ippGetCount(attr) != 1) 123 { 124 printf("FAIL (\"foo\" has %d values, expected 1)\n", (int)ippGetCount(attr)); 125 status ++; 126 } 127 else if (strcmp(ippGetString(attr, 0, NULL), "1234")) 128 { 129 printf("FAIL (\"foo\" has value %s, expected 1234)\n", ippGetString(attr, 0, NULL)); 130 status ++; 131 } 132 else if ((attr = ippFindAttribute(request, "auth-info", IPP_TAG_ZERO)) == NULL) 133 { 134 puts("FAIL (Unable to find attribute \"auth-info\")"); 135 status ++; 136 } 137 else if (ippGetValueTag(attr) != IPP_TAG_TEXT) 138 { 139 printf("FAIL (\"auth-info\" of type %s, expected text)\n", ippTagString(ippGetValueTag(attr))); 140 status ++; 141 } 142 else if (ippGetCount(attr) != 2) 143 { 144 printf("FAIL (\"auth-info\" has %d values, expected 2)\n", (int)ippGetCount(attr)); 145 status ++; 146 } 147 else if (strcmp(ippGetString(attr, 0, NULL), "user")) 148 { 149 printf("FAIL (\"auth-info\"[0] has value \"%s\", expected \"user\")\n", ippGetString(attr, 0, NULL)); 150 status ++; 151 } 152 else if (strcmp(ippGetString(attr, 1, NULL), "pass,word\\")) 153 { 154 printf("FAIL (\"auth-info\"[1] has value \"%s\", expected \"pass,word\\\")\n", ippGetString(attr, 1, NULL)); 155 status ++; 156 } 157 else 158 puts("PASS"); 159 } 160 else 161 { 162 int i; /* Looping var */ 163 cups_option_t *option; /* Current option */ 164 165 166 num_options = cupsParseOptions(argv[1], 0, &options); 167 168 for (i = 0, option = options; i < num_options; i ++, option ++) 169 printf("options[%d].name=\"%s\", value=\"%s\"\n", i, option->name, 170 option->value); 171 } 172 173 exit (status); 174 } 175