diff options
| author | David M. Syzdek <david@syzdek.net> | 2022-02-08 14:49:24 -0900 |
|---|---|---|
| committer | David M. Syzdek <david@syzdek.net> | 2022-02-08 14:49:24 -0900 |
| commit | f00cd15daf06f9880761cb9f5b5b33581e717b3c (patch) | |
| tree | 57e914301510cea3471c76e14655c864714ed4c6 /tests | |
| parent | 60b66a466bbb27ee983b0a0e3fbeb14f57593500 (diff) | |
| download | tinyrad-f00cd15daf06f9880761cb9f5b5b33581e717b3c.tar.gz tinyrad-f00cd15daf06f9880761cb9f5b5b33581e717b3c.tar.bz2 tinyrad-f00cd15daf06f9880761cb9f5b5b33581e717b3c.tar.xz tinyrad-f00cd15daf06f9880761cb9f5b5b33581e717b3c.zip | |
tests: adding test-assertions
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-assertions.c | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/tests/test-assertions.c b/tests/test-assertions.c new file mode 100644 index 0000000..80958fb --- /dev/null +++ b/tests/test-assertions.c | |||
| @@ -0,0 +1,164 @@ | |||
| 1 | /* | ||
| 2 | * Tiny RADIUS Client Library | ||
| 3 | * Copyright (C) 2022 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_TEST_ASSERTIONS_C 1 | ||
| 32 | |||
| 33 | |||
| 34 | /////////////// | ||
| 35 | // // | ||
| 36 | // Headers // | ||
| 37 | // // | ||
| 38 | /////////////// | ||
| 39 | #pragma mark - Headers | ||
| 40 | |||
| 41 | #undef NDEBUG | ||
| 42 | |||
| 43 | #include "common.h" | ||
| 44 | |||
| 45 | #include <stdio.h> | ||
| 46 | #include <getopt.h> | ||
| 47 | #include <assert.h> | ||
| 48 | |||
| 49 | #include <tinyrad.h> | ||
| 50 | |||
| 51 | |||
| 52 | /////////////////// | ||
| 53 | // // | ||
| 54 | // Definitions // | ||
| 55 | // // | ||
| 56 | /////////////////// | ||
| 57 | #pragma mark - Definitions | ||
| 58 | |||
| 59 | #undef PROGRAM_NAME | ||
| 60 | #define PROGRAM_NAME "test-assertions" | ||
| 61 | |||
| 62 | |||
| 63 | ////////////////// | ||
| 64 | // // | ||
| 65 | // Prototypes // | ||
| 66 | // // | ||
| 67 | ////////////////// | ||
| 68 | #pragma mark - Prototypes | ||
| 69 | |||
| 70 | int | ||
| 71 | main( | ||
| 72 | int argc, | ||
| 73 | char * argv[] ); | ||
| 74 | |||
| 75 | |||
| 76 | ///////////////// | ||
| 77 | // // | ||
| 78 | // Functions // | ||
| 79 | // // | ||
| 80 | ///////////////// | ||
| 81 | #pragma mark - Functions | ||
| 82 | |||
| 83 | int | ||
| 84 | main( | ||
| 85 | int argc, | ||
| 86 | char * argv[] ) | ||
| 87 | { | ||
| 88 | int c; | ||
| 89 | int opt_index; | ||
| 90 | unsigned opts; | ||
| 91 | |||
| 92 | // getopt options | ||
| 93 | static char short_opt[] = "dhVvq"; | ||
| 94 | static struct option long_opt[] = | ||
| 95 | { | ||
| 96 | {"debug", no_argument, NULL, 'd' }, | ||
| 97 | {"help", no_argument, NULL, 'h' }, | ||
| 98 | {"quiet", no_argument, NULL, 'q' }, | ||
| 99 | {"silent", no_argument, NULL, 'q' }, | ||
| 100 | {"version", no_argument, NULL, 'V' }, | ||
| 101 | {"verbose", no_argument, NULL, 'v' }, | ||
| 102 | { NULL, 0, NULL, 0 } | ||
| 103 | }; | ||
| 104 | |||
| 105 | opts = 0; | ||
| 106 | |||
| 107 | while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1) | ||
| 108 | { | ||
| 109 | switch(c) | ||
| 110 | { | ||
| 111 | case -1: /* no more arguments */ | ||
| 112 | case 0: /* long options toggles */ | ||
| 113 | break; | ||
| 114 | |||
| 115 | case 'd': | ||
| 116 | break; | ||
| 117 | |||
| 118 | case 'h': | ||
| 119 | printf("Usage: %s [OPTIONS]\n", PROGRAM_NAME); | ||
| 120 | printf("OPTIONS:\n"); | ||
| 121 | printf(" -d, --debug print debug messages\n"); | ||
| 122 | printf(" -h, --help print this help and exit\n"); | ||
| 123 | printf(" -q, --quiet, --silent do not print messages\n"); | ||
| 124 | printf(" -V, --version print version number and exit\n"); | ||
| 125 | printf(" -v, --verbose print verbose messages\n"); | ||
| 126 | printf("\n"); | ||
| 127 | return(0); | ||
| 128 | |||
| 129 | case 'q': | ||
| 130 | opts |= TRAD_TEST_QUIET; | ||
| 131 | opts &= ~TRAD_TEST_VERBOSE; | ||
| 132 | break; | ||
| 133 | |||
| 134 | case 'V': | ||
| 135 | printf("%s (%s) %s\n", PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION); | ||
| 136 | return(0); | ||
| 137 | |||
| 138 | case 'v': | ||
| 139 | opts |= TRAD_TEST_VERBOSE; | ||
| 140 | opts &= ~TRAD_TEST_QUIET; | ||
| 141 | break; | ||
| 142 | |||
| 143 | case '?': | ||
| 144 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); | ||
| 145 | return(1); | ||
| 146 | |||
| 147 | default: | ||
| 148 | fprintf(stderr, "%s: unrecognized option `--%c'\n", PROGRAM_NAME, c); | ||
| 149 | fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); | ||
| 150 | return(1); | ||
| 151 | }; | ||
| 152 | }; | ||
| 153 | |||
| 154 | tinyrad_assertions(); | ||
| 155 | |||
| 156 | if ((opts & TRAD_TEST_VERBOSE)) | ||
| 157 | printf("%s: It appears that the library's assertions appear correct.\n", PROGRAM_NAME); | ||
| 158 | |||
| 159 | return(0); | ||
| 160 | } | ||
| 161 | |||
| 162 | |||
| 163 | /* end of source */ | ||
| 164 | |||
