aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
authorDavid M. Syzdek <david@syzdek.net>2022-01-28 02:52:28 -0900
committerDavid M. Syzdek <david@syzdek.net>2022-01-28 02:52:28 -0900
commit39ec5192f98155e09dd0e3c7d492a9bd64352e53 (patch)
tree8e78d56351da80e7cfb27630924f119276bbe456 /tests
parent3ec91709f77c70d37eb0d00cab6c9c8681a5c7e5 (diff)
downloadtinyrad-39ec5192f98155e09dd0e3c7d492a9bd64352e53.tar.gz
tinyrad-39ec5192f98155e09dd0e3c7d492a9bd64352e53.tar.bz2
tinyrad-39ec5192f98155e09dd0e3c7d492a9bd64352e53.tar.xz
tinyrad-39ec5192f98155e09dd0e3c7d492a9bd64352e53.zip
tests: adding test-dict-vendors
Diffstat (limited to 'tests')
-rw-r--r--tests/dict-data.c45
-rw-r--r--tests/dict-data.h8
-rw-r--r--tests/test-dict-vendors.c289
3 files changed, 342 insertions, 0 deletions
diff --git a/tests/dict-data.c b/tests/dict-data.c
index 08ab24e..3c42cdd 100644
--- a/tests/dict-data.c
+++ b/tests/dict-data.c
@@ -206,6 +206,51 @@ our_dict_diag_attr(
206} 206}
207 207
208 208
209void
210our_dict_diag_vendor(
211 unsigned opts,
212 const TinyRadDictVendorDef * def,
213 TinyRadDictVendor * vendor )
214{
215 char * vendor_name;
216 uint8_t vendor_type_octets;
217 uint8_t vendor_len_octets;
218 uint32_t vendor_id;
219 unsigned vendor_ref_count;
220
221 if ((def))
222 {
223 our_verbose(opts, "Vendor Definition");
224 our_verbose(opts, " Name: %s", def->name);
225 our_verbose(opts, " Vendor ID: %" PRIu32, def->vendor_id);
226 our_verbose(opts, " Vendor Type: %" PRIu32, def->vendor_type_octs);
227 our_verbose(opts, " Data Type: %" PRIu32, def->vendor_len_octs);
228 };
229
230 if ((vendor))
231 {
232 vendor_name = NULL;
233 vendor_id = 0;
234 vendor_type_octets = 0;
235 vendor_len_octets = 0;
236 vendor_ref_count = 0;
237 tinyrad_dict_vendor_info(vendor, TRAD_DICT_OPT_NAME, &vendor_name);
238 tinyrad_dict_vendor_info(vendor, TRAD_DICT_OPT_VEND_ID, &vendor_id);
239 tinyrad_dict_vendor_info(vendor, TRAD_DICT_OPT_TYPE_OCTS, &vendor_type_octets);
240 tinyrad_dict_vendor_info(vendor, TRAD_DICT_OPT_LEN_OCTS, &vendor_len_octets);
241 tinyrad_dict_vendor_info(vendor, TRAD_DICT_OPT_REF_COUNT, &vendor_ref_count);
242 our_verbose(opts, "Vendor Object");
243 our_verbose(opts, " Name: %s", (((vendor_name)) ? vendor_name : ""));
244 our_verbose(opts, " Vendor ID: %" PRIu32, vendor_id);
245 our_verbose(opts, " Type Octets: %" PRIu32, vendor_type_octets);
246 our_verbose(opts, " Length Octets: %" PRIu32, vendor_len_octets);
247 our_verbose(opts, " Reference Count: %u", vendor_ref_count);
248 };
249
250 return;
251}
252
253
209int 254int
210our_dict_initialize( 255our_dict_initialize(
211 unsigned opts, 256 unsigned opts,
diff --git a/tests/dict-data.h b/tests/dict-data.h
index 6f0b2f3..563ffe5 100644
--- a/tests/dict-data.h
+++ b/tests/dict-data.h
@@ -83,6 +83,14 @@ our_dict_diag_attr(
83 const TinyRadDictAttrDef * def, 83 const TinyRadDictAttrDef * def,
84 TinyRadDictAttr * attr ); 84 TinyRadDictAttr * attr );
85 85
86
87void
88our_dict_diag_vendor(
89 unsigned opts,
90 const TinyRadDictVendorDef * def,
91 TinyRadDictVendor * vendor );
92
93
86int 94int
87our_dict_initialize( 95our_dict_initialize(
88 unsigned opts, 96 unsigned opts,
diff --git a/tests/test-dict-vendors.c b/tests/test-dict-vendors.c
new file mode 100644
index 0000000..7bad594
--- /dev/null
+++ b/tests/test-dict-vendors.c
@@ -0,0 +1,289 @@
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_TINYRAD_DICT_VENDORS_C 1
32
33
34///////////////
35// //
36// Headers //
37// //
38///////////////
39#pragma mark - Headers
40
41#include "common.h"
42
43#include <stdio.h>
44#include <stdarg.h>
45#include <stdlib.h>
46#include <string.h>
47#include <strings.h>
48#include <unistd.h>
49#include <getopt.h>
50#include <assert.h>
51
52#include <tinyrad.h>
53
54#include "dict-data.h"
55
56
57///////////////////
58// //
59// Definitions //
60// //
61///////////////////
62#pragma mark - Definitions
63
64#undef PROGRAM_NAME
65#define PROGRAM_NAME "tinyrad-dict-vendors"
66
67
68//////////////////
69// //
70// Prototypes //
71// //
72//////////////////
73#pragma mark - Prototypes
74
75int
76main(
77 int argc,
78 char * argv[] );
79
80int
81my_verify_vendor(
82 unsigned opts,
83 const TinyRadDictVendorDef * def,
84 TinyRadDictVendor * vendor );
85
86
87/////////////////
88// //
89// Functions //
90// //
91/////////////////
92#pragma mark - Functions
93
94int
95main(
96 int argc,
97 char * argv[] )
98{
99 int opt;
100 int c;
101 int opt_index;
102 size_t pos;
103 unsigned opts;
104 TinyRadDict * dict;
105 TinyRadDictVendor * vendor;
106 const TinyRadDictVendorDef * def;
107
108 // getopt options
109 static char short_opt[] = "dhVvq";
110 static struct option long_opt[] =
111 {
112 {"debug", no_argument, NULL, 'd' },
113 {"help", no_argument, NULL, 'h' },
114 {"quiet", no_argument, NULL, 'q' },
115 {"silent", no_argument, NULL, 'q' },
116 {"version", no_argument, NULL, 'V' },
117 {"verbose", no_argument, NULL, 'v' },
118 { NULL, 0, NULL, 0 }
119 };
120
121 our_initialize(PROGRAM_NAME);
122
123 opts = TRAD_TEST_DFLT_DICT;
124
125 while((c = getopt_long(argc, argv, short_opt, long_opt, &opt_index)) != -1)
126 {
127 switch(c)
128 {
129 case -1: /* no more arguments */
130 case 0: /* long options toggles */
131 break;
132
133 case 'd':
134 opt = TRAD_DEBUG_ANY;
135 tinyrad_set_option(NULL, TRAD_OPT_DEBUG_LEVEL, &opt);
136 break;
137
138 case 'h':
139 printf("Usage: %s [OPTIONS]\n", PROGRAM_NAME);
140 printf("OPTIONS:\n");
141 printf(" -d, --debug print debug messages\n");
142 printf(" -h, --help print this help and exit\n");
143 printf(" -q, --quiet, --silent do not print messages\n");
144 printf(" -V, --version print version number and exit\n");
145 printf(" -v, --verbose print verbose messages\n");
146 printf("\n");
147 return(0);
148
149 case 'q':
150 opts |= TRAD_TEST_QUIET;
151 opts &= ~TRAD_TEST_VERBOSE;
152 break;
153
154 case 'V':
155 printf("%s (%s) %s\n", PROGRAM_NAME, PACKAGE_NAME, PACKAGE_VERSION);
156 return(0);
157
158 case 'v':
159 opts |= TRAD_TEST_VERBOSE;
160 opts &= ~TRAD_TEST_QUIET;
161 break;
162
163 case '?':
164 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
165 return(1);
166
167 default:
168 fprintf(stderr, "%s: unrecognized option `--%c'\n", PROGRAM_NAME, c);
169 fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME);
170 return(1);
171 };
172 };
173
174 // initialize test dictionary
175 if ((our_dict_initialize(opts, &dict)))
176 return(1);
177
178 our_verbose(opts, "Vendor format: vendor id/name");
179
180 // verifies default attributes in dictionary by name
181 for(pos = 0; ((tinyrad_dict_default_vendors[pos].name)); pos++)
182 {
183 def = &tinyrad_dict_default_vendors[pos];
184 our_verbose( opts, "default attribute search by name %8" PRIu32 " %s ...", def->vendor_id, def->name);
185 vendor = tinyrad_dict_vendor_get(dict, def->name, 0);
186 if ((my_verify_vendor(opts, def, vendor)))
187 {
188 tinyrad_dict_vendor_destroy(vendor);
189 tinyrad_dict_destroy(dict);
190 return(1);
191 };
192 };
193
194 // verifies test attributes in dictionary by type
195 for(pos = 0; ((tinyrad_dict_default_vendors[pos].name)); pos++)
196 {
197 def = &tinyrad_dict_default_vendors[pos];
198 our_verbose( opts, "default attribute search by id %8" PRIu32 " %s ...", def->vendor_id, def->name);
199 vendor = tinyrad_dict_vendor_get(dict, NULL, (uint32_t)def->vendor_id);
200 if ((my_verify_vendor(opts, def, vendor)))
201 {
202 tinyrad_dict_vendor_destroy(vendor);
203 tinyrad_dict_destroy(dict);
204 return(1);
205 };
206 };
207
208 // verifies test attributes in dictionary by name
209 for(pos = 0; ((test_dict_data_vendors[pos].name)); pos++)
210 {
211 def = &test_dict_data_vendors[pos];
212 our_verbose( opts, "test attribute search by name %8" PRIu32 " %s ...", def->vendor_id, def->name);
213 vendor = tinyrad_dict_vendor_get(dict, def->name, 0);
214 if ((my_verify_vendor(opts, def, vendor)))
215 {
216 tinyrad_dict_vendor_destroy(vendor);
217 tinyrad_dict_destroy(dict);
218 return(1);
219 };
220 };
221
222 // verifies default attributes in dictionary by type
223 for(pos = 0; ((test_dict_data_vendors[pos].name)); pos++)
224 {
225 def = &test_dict_data_vendors[pos];
226 our_verbose( opts, "test attribute search by id %8" PRIu32 " %s ...", def->vendor_id, def->name);
227 vendor = tinyrad_dict_vendor_get(dict, NULL, (uint32_t)def->vendor_id);
228 if ((my_verify_vendor(opts, def, vendor)))
229 {
230 tinyrad_dict_vendor_destroy(vendor);
231 tinyrad_dict_destroy(dict);
232 return(1);
233 };
234 };
235
236 // cleans up dictionary
237 tinyrad_dict_destroy(dict);
238
239 return(0);
240}
241
242
243int
244my_verify_vendor(
245 unsigned opts,
246 const TinyRadDictVendorDef * def,
247 TinyRadDictVendor * vendor )
248{
249 uint8_t u8;
250 uint32_t u32;
251
252 assert(def != NULL);
253
254 if (!(vendor))
255 {
256 our_dict_diag_vendor(opts, def, NULL);
257 return(our_error(opts, NULL, "vendor was not found"));
258 };
259
260 // compare vendor ID
261 tinyrad_dict_vendor_info(vendor, TRAD_DICT_OPT_VEND_ID, &u32);
262 if (def->vendor_id != u32)
263 {
264 our_dict_diag_vendor(opts, def, vendor);
265 return(our_error(opts, NULL, "vendor ID do not match"));
266 };
267
268 // compare vendor type octets
269 tinyrad_dict_vendor_info(vendor, TRAD_DICT_OPT_TYPE_OCTS, &u8);
270 if (def->vendor_type_octs != u8)
271 {
272 our_dict_diag_vendor(opts, def, vendor);
273 return(our_error(opts, NULL, "attribute type octets do not match"));
274 };
275
276 // compare vendor len octets
277 tinyrad_dict_vendor_info(vendor, TRAD_DICT_OPT_LEN_OCTS, &u8);
278 if (def->vendor_len_octs != u8)
279 {
280 our_dict_diag_vendor(opts, def, vendor);
281 return(our_error(opts, NULL, "attribute len octets do not match"));
282 };
283
284 return(0);
285}
286
287
288/* end of source */
289