Debian Codegraph @

testing/fulltests/unit-tests/T020netsnmp_sprint_realloc_objid_tree_clib.c

raw
1 /* HEADER Testing netsnmp_sprint_realloc_objid_tree() */
2
3 static const oid objid1[] = {
4 1, 3, 6, 1, 2, 1, 4, 32, 1, 5, 1, 1, 4, 127, 0, 0, 0, 8
5 };
6 static const oid objid2[] = {
7 1, 3, 6, 1, 2, 1, 4, 32, 1, 5, 1, 2, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8 0, 0, 0, 0, 1, 128
9 };
10 static const oid objid3[] = {
11 1, 3, 6, 1, 2, 1, 4, 32, 1, 5, 1, 1, 4, 255, 255, 255, 255, 8
12 };
13 static const oid objid4[] = {
14 1, 3, 6, 1, 2, 1, 4, 32, 1, 5, 1, 2, 16, 255, 255, 255, 255, 255, 255, 255,
15 255, 255, 255, 255, 255, 255, 255, 255, 255, 128
16 };
17 static const oid objid5[] = {
18 1, 3, 6, 1, 2, 1, 4, 32, 1, 5, 1, 1, 4, 256, 256, 256, 256, 8
19 };
20 static const oid objid6[] = {
21 1, 3, 6, 1, 2, 1, 4, 32, 1, 5, 1, 2, 16, 256, 256, 256, 256, 256, 256, 256,
22 256, 256, 256, 256, 256, 256, 256, 256, 256, 128
23 };
24 static const oid objid7[] = {
25 1, 3, 6, 1, 2, 1, 4, 32, 1, 5, 1, 1, 4, -1, -1, -1, -1, 8
26 };
27 static const oid objid8[] = {
28 1, 3, 6, 1, 2, 1, 4, 32, 1, 5, 1, 2, 16, -1, -1, -1, -1, -1, -1, -1, -1,
29 -1, -1, -1, -1, -1, -1, -1, -1, 128
30
31 };
32 struct objid_data { oid const *oid; int len; const char *str; };
33 static const struct objid_data objid_array[] = {
34 { objid1, sizeof(objid1) / sizeof(objid1[0]),
35 "IP-MIB::ipAddressPrefixOrigin.1.ipv4.\"127.0.0.0\".8" },
36 { objid2, sizeof(objid2) / sizeof(objid2[0]),
37 "IP-MIB::ipAddressPrefixOrigin.1.ipv6."
38 "\"00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:01\".128" },
39 { objid3, sizeof(objid3) / sizeof(objid3[0]),
40 "IP-MIB::ipAddressPrefixOrigin.1.ipv4.\"255.255.255.255\".8" },
41 { objid4, sizeof(objid4) / sizeof(objid4[0]),
42 "IP-MIB::ipAddressPrefixOrigin.1.ipv6."
43 "\"ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff\".128" },
44 { objid5, sizeof(objid5) / sizeof(objid5[0]),
45 "IP-MIB::ipAddressPrefixOrigin.1.ipv4.\"....\".8" },
46 { objid6, sizeof(objid6) / sizeof(objid6[0]),
47 "IP-MIB::ipAddressPrefixOrigin.1.ipv6.\"................\".128" },
48 { objid7, sizeof(objid7) / sizeof(objid7[0]),
49 "IP-MIB::ipAddressPrefixOrigin.1.ipv4.\"....\".8" },
50 { objid8, sizeof(objid8) / sizeof(objid8[0]),
51 "IP-MIB::ipAddressPrefixOrigin.1.ipv6.\"................\".128" },
52 };
53 struct tree *tree;
54 char *buf;
55 size_t buf_len, out_len;
56 int buf_overflow, i;
57 char mibdir[PATH_MAX];
58
59 snprintf(mibdir, sizeof(mibdir), "%s/%s", ABS_SRCDIR, "mibs");
60 netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIBDIRS, mibdir);
61
62 init_snmp("T020");
63
64 for (i = 0; i < sizeof(objid_array) / sizeof(objid_array[0]); i++) {
65 buf = NULL;
66 buf_len = out_len = buf_overflow = 0;
67 tree = netsnmp_sprint_realloc_objid_tree((u_char **) &buf, &buf_len,
68 &out_len, 1/*allow_realloc*/,
69 &buf_overflow,
70 objid_array[i].oid,
71 objid_array[i].len);
72 OK(!!objid_array[i].str == !!tree,
73 "netsnmp_sprint_realloc_objid_tree() return value");
74 if (objid_array[i].str && tree) {
75 OKF(strcmp(objid_array[i].str, buf) == 0,
76 ("Mismatch: expected %s but got %s", objid_array[i].str,
77 buf ? (const char *)buf : "(NULL)"));
78 }
79 free(buf);
80 }
81
82 snmp_shutdown("T020");