Debian Codegraph @

testing/fulltests/unit-tests/T021binary_array_oid_duplicates_clib.c

raw
1 /* HEADER Testing duplicate handling in binary OID array */
2
3 /* Much copied from T012 */
4 static const char test_name[] = "binary-array-of-OIDs-duplicate-test";
5 oid o1 = 1;
6 oid o2 = 2;
7 oid o3 = 6;
8 oid o4 = 8;
9 oid o5 = 9;
10 oid ox = 7;
11 oid oy = 10;
12 netsnmp_index i1, i2, i3, i4, i5, ix, iy, *ip;
13 netsnmp_index *b[] = { &i4, &i2, &i3, &i1, &i5 };
14 netsnmp_container *c;
15 int i;
16
17 init_snmp(test_name);
18
19 c = netsnmp_container_get_binary_array();
20 c->compare = netsnmp_compare_netsnmp_index;
21 netsnmp_binary_array_options_set(c, 1,
22 CONTAINER_KEY_ALLOW_DUPLICATES);
23
24 i1.oids = &o1;
25 i2.oids = &o2;
26 i3.oids = &o3;
27 i4.oids = &o4;
28 i5.oids = &o5;
29 ix.oids = &ox;
30 iy.oids = &oy;
31 i1.len = i2.len = i3.len = i4.len = i5.len = ix.len = iy.len = 1;
32
33 for (i = 0; i < sizeof(b)/sizeof(b[0]); ++i)
34 CONTAINER_INSERT(c, b[i]);
35
36 #define MAX_ROUNDS 6
37 /* Insert some duplicates of i4; also insert a duplicate of
38 * i1 to move the contents of the array around. */
39 for (i = 0; i < MAX_ROUNDS; ++i) {
40 switch (i) {
41 case 0:
42 /* First round: no insert */
43 break;
44 case 1:
45 case 2:
46 case 4:
47 case 5:
48 /* Insert another duplicate of our target object */
49 CONTAINER_INSERT(c, &i4);
50 break;
51 case 3:
52 /* Insert a dulicate of an earlier OID, so that it
53 * changes the binary search behavior */
54 CONTAINER_INSERT(c, &i1);
55 break;
56 }
57 /* Primary requirement: getnext returns the next value! */
58 ip = CONTAINER_FIND(c, &i4);
59 OKF(ip, ("FIND returned a value"));
60 OKF(c->compare(&i4, ip) == 0,
61 ("FIND returned oid %" NETSNMP_PRIo "d", ip->oids[0]));
62 ip = CONTAINER_NEXT(c, &i4);
63 OKF(ip, ("NEXT returned a value"));
64 OKF(c->compare(&i5, ip) == 0,
65 ("NEXT returned index 5 = %" NETSNMP_PRIo "d", i5.oids[0]));
66 }
67
68 while ((ip = CONTAINER_FIRST(c)))
69 CONTAINER_REMOVE(c, ip);
70 CONTAINER_FREE(c);
71
72 snmp_shutdown(test_name);