1 #include "iwkv.h"
2 #include "iwlog.h"
3 #include "iwutils.h"
4 #include "iwcfg.h"
5 #include "iwkv_tests.h"
6
init_suite()7 int init_suite() {
8 iwrc rc = iwkv_init();
9 return rc;
10 }
11
clean_suite()12 int clean_suite() {
13 return 0;
14 }
15
iwkv_test9_1()16 static void iwkv_test9_1() {
17 IWKV_OPTS opts = {
18 .path = "iwkv_test9_1.db",
19 .oflags = IWKV_TRUNC
20 };
21 IWKV kv = NULL;
22 iwrc rc = iwkv_open(&opts, &kv);
23 assert(rc == 0);
24 IWDB db = NULL;
25 rc = iwkv_db(kv, 1, 0, &db);
26 assert(rc == 0);
27
28 {
29 unsigned char ip1[4] = { 1, 0, 142, 235 };
30 IWKV_val ikey, ival;
31 ikey.data = ip1;
32 ikey.size = 4;
33 ival.data = (void *)"";
34 ival.size = 0;
35 iwkv_opflags opflags = IWKV_NO_OVERWRITE;
36 iwrc rc = iwkv_put(db, &ikey, &ival, opflags);
37 CU_ASSERT_EQUAL(rc, 0);
38 }
39
40 {
41 unsigned char ip2[4] = { 1, 0, 145, 2 };
42 IWKV_val ikey, ival;
43 ikey.data = ip2;
44 ikey.size = 4;
45 ival.data = (void *)"";
46 ival.size = 0;
47 iwkv_opflags opflags = IWKV_NO_OVERWRITE;
48 iwrc rc = iwkv_put(db, &ikey, &ival, opflags);
49 CU_ASSERT_EQUAL(rc, 0);
50 }
51 iwkv_close(&kv);
52
53 }
54
55
main()56 int main() {
57 CU_pSuite pSuite = NULL;
58
59 /* Initialize the CUnit test registry */
60 if (CUE_SUCCESS != CU_initialize_registry()) return CU_get_error();
61
62 /* Add a suite to the registry */
63 pSuite = CU_add_suite("iwkv_test9", init_suite, clean_suite);
64
65 if (NULL == pSuite) {
66 CU_cleanup_registry();
67 return CU_get_error();
68 }
69
70 /* Add the tests to the suite */
71 if (
72 (NULL == CU_add_test(pSuite, "iwkv_test9_1", iwkv_test9_1))
73 ) {
74 CU_cleanup_registry();
75 return CU_get_error();
76 }
77
78 /* Run all tests using the CUnit Basic interface */
79 CU_basic_set_mode(CU_BRM_VERBOSE);
80 CU_basic_run_tests();
81 int ret = CU_get_error() || CU_get_number_of_failures();
82 CU_cleanup_registry();
83 return ret;
84 }
85