diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-01-13 21:30:16 -0900 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-01-13 21:30:16 -0900 |
| commit | 21f97ab98131d4841d1b199513a649f709bfa2b3 (patch) | |
| tree | 322e5921d0dfca9cec71d28da6d93d42ad94c989 /tests/test-url-desc2str.c | |
| parent | 8f60a9558933e80d3f93fbd3af55230f5b32108e (diff) | |
| download | tinyrad-21f97ab98131d4841d1b199513a649f709bfa2b3.tar.gz tinyrad-21f97ab98131d4841d1b199513a649f709bfa2b3.tar.bz2 tinyrad-21f97ab98131d4841d1b199513a649f709bfa2b3.tar.xz tinyrad-21f97ab98131d4841d1b199513a649f709bfa2b3.zip | |
tests: renaming 'tinyrad-url-desc2str' to 'test-url-desc2str'
Diffstat (limited to 'tests/test-url-desc2str.c')
| -rw-r--r-- | tests/test-url-desc2str.c | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/tests/test-url-desc2str.c b/tests/test-url-desc2str.c new file mode 100644 index 0000000..de4b0e6 --- /dev/null +++ b/tests/test-url-desc2str.c | |||
| @@ -0,0 +1,192 @@ | |||
| 1 | /* | ||
| 2 | * Tiny RADIUS Client Library | ||
| 3 | * Copyright (C) 2021 David M. Syzdek <david@syzdek.net>. | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions are | ||
| 8 | * met: | ||
| 9 | * | ||
| 10 | * * Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * * Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in the | ||
| 14 | * documentation and/or other materials provided with the distribution. | ||
| 15 | * * Neither the name of David M. Syzdek nor the | ||
| 16 | * names of its contributors may be used to endorse or promote products | ||
| 17 | * derived from this software without specific prior written permission. | ||
| 18 | * | ||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
| 20 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
| 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID M. SYZDEK BE LIABLE FOR | ||
| 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 29 | * SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | #define _TESTS_RADIUS_URL_C 1 | ||
| 32 | |||
| 33 | |||
| 34 | /////////////// | ||
| 35 | // // | ||
| 36 | // Headers // | ||
| 37 | // // | ||
| 38 | /////////////// | ||
| 39 | #pragma mark - Headers | ||
| 40 | |||
| 41 | #include <stdio.h> | ||
| 42 | #include <stdarg.h> | ||
| 43 | #include <stdlib.h> | ||
| 44 | #include <string.h> | ||
| 45 | #include <strings.h> | ||
| 46 | #include <unistd.h> | ||
| 47 | #include <getopt.h> | ||
| 48 | |||
| 49 | #ifdef HAVE_CONFIG_H | ||
| 50 | #include <config.h> | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #include <tinyrad.h> | ||
| 54 | |||
| 55 | #include "common.h" | ||
| 56 | |||
| 57 | |||
| 58 | /////////////////// | ||
| 59 | // // | ||
| 60 | // Definitions // | ||
| 61 | // // | ||
| 62 | /////////////////// | ||
| 63 | #pragma mark - Definitions | ||
| 64 | |||
| 65 | #undef PROGRAM_NAME | ||
| 66 | #define PROGRAM_NAME "radius-url" | ||
| 67 | |||
| 68 | |||
| 69 | ////////////////// | ||
| 70 | // // | ||
| 71 | // Prototypes // | ||
| 72 | // // | ||
| 73 | ////////////////// | ||
| 74 | #pragma mark - Prototypes | ||
| 75 | |||
| 76 | int main( int argc, char * argv[] ); | ||
| 77 | |||
| 78 | |||
| 79 | ///////////////// | ||
| 80 | // // | ||
| 81 | // Variables // | ||
| 82 | // // | ||
| 83 | ///////////////// | ||
| 84 | #pragma mark - Variables | ||
| 85 | |||
| 86 | |||
| 87 | ///////////////// | ||
| 88 | // // | ||
| 89 | // Functions // | ||
| 90 | // // | ||
| 91 | ///////////////// | ||
| 92 | #pragma mark - Functions | ||
| 93 | |||
| 94 | int main( int argc, char * argv[] ) | ||
| 95 | { | ||
| 96 | int opt; | ||
| 97 | int c; | ||
| 98 | int opt_index; | ||
| 99 | int opts; | ||
| 100 | size_t pos; | ||
| 101 | |||
| 102 | // getopt options | ||
| 103 | static char short_opt[] = "dhVvq"; | ||
| 104 | static struct option long_opt[] = | ||
| 105 | { | ||
| 106 | {"debug", no_argument, NULL, 'd' }, | ||
| 107 | {"help", no_argument, NULL, 'h' }, | ||
| 108 | {"quiet", no_argument, NULL, 'q' }, | ||
| 109 | {"silent", no_argument, NULL, 'q' }, | ||
| 110 | {"version", no_argument, NULL, 'V' }, | ||
| 111 | {"verbose", no_argument, NULL, 'v' }, | ||
| 112 | { NULL, 0, NULL, 0 } | ||
| 113 | }; | ||
| 114 | |||
| 115 | opt = TRAD_OFF; | ||
| 116 | tinyrad_set_option(NULL, TRAD_OPT_DEBUG_SYSLOG, &opt); | ||
| 117 | tinyrad_set_option(NULL, TRAD_OPT_DEBUG_IDENT, PROGRAM_NAME); | ||
| 118 | |||
| 119 | opts = TRAD_TEST_PARSE | TRAD_TEST_DESC2STR; | ||
| 120 | |||
| 121 | while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1) | ||
| 122 | { | ||
| 123 | switch(c) | ||
| 124 | { | ||
| 125 | case -1: /* no more arguments */ | ||
| 126 | case 0: /* long options toggles */ | ||
| 127 | break; | ||
| 128 | |||
| 129 | case 'd': | ||
| 130 | opt = TRAD_DEBUG_ANY; | ||
| 131 | tinyrad_set_option(NULL, TRAD_OPT_DEBUG_LEVEL, &opt); | ||
| 132 | break; | ||
| 133 | |||
| 134 | case 'h': | ||
| 135 | printf("Usage: %s [OPTIONS]\n", PROGRAM_NAME); | ||
| 136 | printf("OPTIONS:\n"); | ||
| 137 | printf(" -d, --debug print debug messages\n"); | ||
| 138 | printf(" -h, --help print this help and exit\n"); | ||
| 139 | printf(" -q, --quiet, --silent do not print messages\n"); | ||
| 140 | printf(" -V, --version print version number and exit\n"); | ||
| 141 | printf(" -v, --verbose print verbose messages\n"); | ||
| 142 | printf("URL SYNTAX:\n"); | ||
| 143 | printf(" radius://hostport/secret[?proto] (default proto: udp, port: 1812)\n"); | ||
| 144 | printf(" radius-acct://hostport/secret[?proto] (default proto: udp, port: 1813)\n"); | ||
| 145 | printf(" radsec://hostport/[?proto] (default proto: tcp, port: 2083)\n"); | ||
| 146 | printf(" radius-dynauth://hostport/secret[?proto] (default proto: udp, port: 3799)\n"); | ||
| 147 | printf("\n"); | ||
| 148 | return(0); | ||
| 149 | |||
| 150 | case 'q': | ||
| 151 | break; | ||
| 152 | |||
| 153 | case 'V': | ||
| 154 | printf("%s (%s) %s\n", PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION); | ||
| 155 | return(0); | ||
| 156 | |||
| 157 | case 'v': | ||
| 158 | opts |= TRAD_TEST_VERBOSE; | ||
| 159 | break; | ||
| 160 | |||
| 161 | case '?': | ||
| 162 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); | ||
| 163 | return(1); | ||
| 164 | |||
| 165 | default: | ||
| 166 | fprintf(stderr, "%s: unrecognized option `--%c'\n", PROGRAM_NAME, c); | ||
| 167 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); | ||
| 168 | return(1); | ||
| 169 | }; | ||
| 170 | }; | ||
| 171 | |||
| 172 | if (optind < argc) | ||
| 173 | { | ||
| 174 | while (optind < argc) | ||
| 175 | { | ||
| 176 | if ((our_urldesc_test_good(argv[optind], opts))) | ||
| 177 | return(1); | ||
| 178 | optind++; | ||
| 179 | }; | ||
| 180 | return(0); | ||
| 181 | }; | ||
| 182 | |||
| 183 | for(pos = 0; ((test_urldesc_strs_desc2str[pos])); pos++) | ||
| 184 | if ((our_urldesc_test_good(test_urldesc_strs_desc2str[pos], opts))) | ||
| 185 | return(1); | ||
| 186 | |||
| 187 | return(0); | ||
| 188 | } | ||
| 189 | |||
| 190 | |||
| 191 | /* end of source */ | ||
| 192 | |||
