Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / testing / misctest.c
1 /*
2  * misctest.c
3  *
4  * Expected SUCCESSes for all tests:    0
5  *
6  * Returns:
7  *      Number of FAILUREs.
8  *
9  * Test of dump_snmpEngineID().                 SUCCESSes:  0
10  */
11
12 static char    *rcsid = "$Id: misctest.c,v 5.0 2002/04/20 07:30:22 hardaker Exp $";     /* */
13
14 #include <net-snmp/net-snmp-config.h>
15
16 #include <stdio.h>
17 #ifdef HAVE_NETINET_IN_H
18 #include <netinet/in.h>
19 #endif
20
21 #include "asn1.h"
22 #include "snmp_api.h"
23 #include "tools.h"
24 #include "transform_oids.h"
25 #include "callback.h"
26
27 #include <stdlib.h>
28
29 extern char    *optarg;
30 extern int      optind, optopt, opterr;
31
32
33
34 /*
35  * Globals, &c...
36  */
37 char           *local_progname;
38
39 #define USAGE   "Usage: %s [-h][-1a]"
40 #define OPTIONLIST      "1ah"
41
42 int             doalltests = 0, dodumpseid = 0;
43
44 #define ALLOPTIONS      (doalltests + dodumpseid)
45
46
47
48 #define LOCAL_MAXBUF    (1024 * 8)
49 #define NL              "\n"
50
51 #define OUTPUT(o)       fprintf(stdout, "\n\n%s\n\n", o);
52
53 #define SUCCESS(s)                                      \
54 {                                                       \
55         if (!failcount)                                 \
56                 fprintf(stdout, "\nSUCCESS: %s\n", s);  \
57 }
58
59 #define FAILED(e, f)                                    \
60 {                                                       \
61         if (e != SNMPERR_SUCCESS) {                     \
62                 fprintf(stdout, "\nFAILED: %s\n", f);   \
63                 failcount += 1;                         \
64         }                                               \
65 }
66
67
68
69
70 #define IDBLAT_4        "00010203"
71
72 #define IDVIOLATE1      "8000000300deedcafe"
73
74 #define IDIPv4          "80000003010a090807"
75 #define IDIPv6          "8000000302100f0e0d0c0b0a090807060504030201"
76 #define IDMAC           "8000000303ffeeddccbbaa"
77
78 #define IDTEXT          "8000000304"
79 #define PRINTABLE       "Let this be printable."
80
81 #define IDOCTETS_7      "80000003050001020304050607"
82
83 #define IDLOCAL_11      "8000000306000102030405060708090a0b"
84
85 #define IDIPv4_EXTRA3   "80000003010a090807010203"
86
87 #define ID_NUMSTRINGS           10
88
89
90
91
92 /*
93  * Prototypes.
94  */
95 void            usage(FILE * ofp);
96
97 int             test_dumpseid(void);
98
99
100
101
102
103 int
104 main(int argc, char **argv)
105 {
106     int             rval = SNMPERR_SUCCESS, failcount = 0;
107     char            ch;
108
109     local_progname = argv[0];
110
111     /*
112      * Parse.
113      */
114     while ((ch = getopt(argc, argv, OPTIONLIST)) != EOF) {
115         switch (ch) {
116         case '1':
117             dodumpseid = 1;
118             break;
119         case 'a':
120             doalltests = 1;
121             break;
122         case 'h':
123             rval = 0;
124         default:
125             usage(stdout);
126             exit(rval);
127         }
128
129         argc -= 1;
130         argv += 1;
131         if (optarg) {
132             argc -= 1;
133             argv += 1;
134             optarg = NULL;
135         }
136         optind = 1;
137     }                           /* endwhile getopt */
138
139     if ((argc > 1)) {
140         usage(stdout);
141         exit(1000);
142
143     } else if (ALLOPTIONS != 1) {
144         usage(stdout);
145         exit(1000);
146     }
147
148
149     /*
150      * Test stuff.
151      */
152     if (dodumpseid || doalltests) {
153         failcount += test_dumpseid();
154     }
155
156
157     /*
158      * Cleanup.
159      */
160     return failcount;
161
162 }                               /* end main() */
163
164
165
166
167
168 void
169 usage(FILE * ofp)
170 {
171     fprintf(ofp,
172             USAGE
173             "" NL
174             "   -1              Test dump_snmpEngineID()." NL
175             "   -a              All tests." NL
176             "   -h              Help." NL "" NL, local_progname);
177
178 }                               /* end usage() */
179
180
181
182
183 #ifdef EXAMPLE
184 /*******************************************************************-o-******
185  * test_dosomething
186  *
187  * Returns:
188  *      Number of failures.
189  *
190  *
191  * Test template.
192  */
193 int
194 test_dosomething(void)
195 {
196     int             rval = SNMPERR_SUCCESS, failcount = 0;
197
198     EM0(1, "UNIMPLEMENTED");    /* EM(1); /* */
199
200   test_dosomething_quit:
201     return failcount;
202
203 }                               /* end test_dosomething() */
204 #endif                          /* EXAMPLE */
205
206
207
208
209 /*******************************************************************-o-******
210  * test_dumpseid
211  *
212  * Returns:
213  *      Number of failures.
214  *
215  * Test dump_snmpEngineID().
216  */
217 int
218 test_dumpseid(void)
219 {
220     int                         /* rval = SNMPERR_SUCCESS, */
221                     failcount = 0, tlen, count = 0;
222
223     char            buf[SNMP_MAXBUF],
224         *s, *t, *ris, *rawid_set[ID_NUMSTRINGS + 1] = {
225         IDBLAT_4,
226         IDVIOLATE1,
227         IDIPv4,
228         IDIPv6,
229         IDMAC,
230         IDTEXT,
231         IDOCTETS_7,
232         IDLOCAL_11,
233         IDIPv4_EXTRA3,
234         NULL
235     };
236
237     OUTPUT("Test of dump_snmpEngineID.  "
238            "(Does not report failure or success.)");
239
240
241     while ((ris = rawid_set[count++])) {
242         tlen = hex_to_binary2(ris, strlen(ris), &t);
243
244         if (ris == IDTEXT) {
245             memset(buf, 0, SNMP_MAXBUF);
246             memcpy(buf, t, tlen);
247             tlen += sprintf(buf + tlen, "%s", PRINTABLE);
248
249             SNMP_FREE(t);
250             t = buf;
251         }
252 #ifdef SNMP_TESTING_CODE
253         s = dump_snmpEngineID(t, &tlen);
254         printf("%s    (len=%d)\n", s, tlen);
255 #endif
256
257         SNMP_FREE(s);
258         if (t != buf) {
259             SNMP_FREE(t);
260         }
261     }
262
263
264     return failcount;
265
266 }                               /* end test_dumpseid() */