Debian Codegraph @

testing/fulltests/unit-tests/T005table_dataset_cagentlib.c

raw
1 /* HEADER Testing table_dataset */
2
3 /*
4 * Note: the primary purpose of this unit test is to verify whether all memory
5 * that is allocated for storing a table dataset is freed properly. Feel free
6 * to extend this unit test such that it tests more of the table dataset code.
7 */
8
9 enum { COL3 = 2, COL4 = 3, COL5 = 4, };
10
11 static const oid Oid[] = { 1, 3, 6, 1, 3, 277 };
12 netsnmp_table_data_set* tds;
13 netsnmp_handler_registration* th;
14 netsnmp_table_row* row;
15 int32_t ival;
16 int32_t i, j;
17
18 SOCK_STARTUP;
19
20 init_agent("snmpd");
21 init_snmp("snmpd");
22
23 tds = netsnmp_create_table_data_set("table_dataset unit-test");
24 OK(tds, "table data set creation");
25
26 netsnmp_table_dataset_add_index(tds, ASN_INTEGER);
27 netsnmp_table_dataset_add_index(tds, ASN_INTEGER);
28 netsnmp_table_set_add_default_row(tds, COL3, ASN_INTEGER, FALSE, NULL, 0);
29 netsnmp_table_set_add_default_row(tds, COL4, ASN_COUNTER, FALSE, NULL, 0);
30 netsnmp_table_set_add_default_row(tds, COL5, ASN_OCTET_STR, FALSE, NULL, 0);
31
32 th = netsnmp_create_handler_registration("unit-test handler", NULL, Oid,
33 OID_LENGTH(Oid), HANDLER_CAN_RWRITE);
34 OK(th, "table handler registration");
35
36 OK(netsnmp_register_table_data_set(th, tds, NULL) == SNMPERR_SUCCESS,
37 "table data set registration");
38
39 for (i = 1; i <= 2; i++) {
40 for (j = 1; j <= 2; j++) {
41 row = netsnmp_create_table_data_row();
42 netsnmp_table_row_add_index(row, ASN_INTEGER, &i, sizeof(i));
43 netsnmp_table_row_add_index(row, ASN_INTEGER, &j, sizeof(j));
44 netsnmp_table_dataset_add_row(tds, row);
45
46 ival = 10 * i + j;
47 OK(netsnmp_set_row_column(row, COL3, ASN_INTEGER, &ival, sizeof(ival))
48 == SNMPERR_SUCCESS, "set INTEGER column");
49 OK(netsnmp_set_row_column(row, COL5, ASN_OCTET_STR, "test",
50 sizeof("test") - 1)
51 == SNMPERR_SUCCESS, "set OCTET_STR column");
52 }
53 }
54
55 netsnmp_delete_table_data_set(tds);
56
57 snmp_shutdown("snmpd");
58 shutdown_agent();
59
60 SOCK_CLEANUP;
61
62 OK(TRUE, "done");