test_store.c (1693B)
1 #include <check.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 #include "lq/store.h" 6 #include "lq/mem.h" 7 #include "lq/io.h" 8 9 10 extern LQStore LQFileContent; 11 12 START_TEST(check_store_count) { 13 int r; 14 LQStore store; 15 char *k; 16 char *v; 17 size_t kl; 18 size_t vl; 19 char path[LQ_PATH_MAX]; 20 21 lq_cpy(&store, &LQFileContent, sizeof(LQStore)); 22 lq_cpy(path, "/tmp/lqstore_file_XXXXXX", 25); 23 store.userdata = mktempdir(path); 24 *((char*)(store.userdata+24)) = '/'; 25 *((char*)(store.userdata+25)) = 0x0; 26 27 k = "aaa"; 28 v = "foo"; 29 kl = 3; 30 vl = 3; 31 store.put(LQ_CONTENT_RAW, &store, k, &kl, v, vl), 32 33 k = "ab"; 34 v = "bar"; 35 kl = 2; 36 vl = 3; 37 store.put(LQ_CONTENT_RAW, &store, k, &kl, v, vl), 38 39 k = "aaa"; 40 v = "inky"; 41 kl = 3; 42 vl = 4; 43 store.put(LQ_CONTENT_MSG, &store, k, &kl, v, vl), 44 45 k = "aab"; 46 v = "pinky"; 47 kl = 3; 48 vl = 5; 49 store.put(LQ_CONTENT_MSG, &store, k, &kl, v, vl), 50 51 k = "b"; 52 v = "blinky"; 53 kl = 1; 54 vl = 6; 55 store.put(LQ_CONTENT_MSG, &store, k, &kl, v, vl), 56 57 k = "bbc"; 58 v = "clyde"; 59 kl = 3; 60 vl = 5; 61 store.put(LQ_CONTENT_MSG, &store, k, &kl, v, vl), 62 63 k = "bbc"; 64 v = "clyde"; 65 kl = 3; 66 vl = 5; 67 store.put(LQ_CONTENT_CERT, &store, k, &kl, v, vl), 68 69 r = store.count(LQ_CONTENT_MSG, &store, "aa", 2); 70 71 ck_assert_int_eq(r, 2); 72 } 73 END_TEST 74 75 Suite * common_suite(void) { 76 Suite *s; 77 TCase *tc; 78 79 s = suite_create("store"); 80 tc = tcase_create("files"); 81 tcase_add_test(tc, check_store_count); 82 suite_add_tcase(s, tc); 83 84 return s; 85 } 86 87 int main(void) { 88 int n_fail; 89 90 Suite *s; 91 SRunner *sr; 92 93 s = common_suite(); 94 sr = srunner_create(s); 95 96 srunner_run_all(sr, CK_VERBOSE); 97 n_fail = srunner_ntests_failed(sr); 98 srunner_free(sr); 99 100 return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 101 }