test_msg.c (1993B)
1 #include <check.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 #include "lq/msg.h" 6 #include "lq/crypto.h" 7 #include "lq/io.h" 8 #include "lq/mem.h" 9 10 extern LQStore LQDummyContent; 11 extern LQStore LQFileContent; 12 13 const char *data = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; 14 15 START_TEST(check_msg_symmetric) { 16 int r; 17 size_t c; 18 char buf[4096]; 19 char path[1024]; 20 char *p; 21 LQMsg *msg; 22 LQResolve resolve; 23 LQResolve resolve_dummy; 24 LQStore *store; 25 26 lq_cpy(path, "/tmp/lqstore_file_XXXXXX", 25); 27 p = mktempdir(path); 28 *(p+24) = '/'; 29 *(p+25) = 0x0; 30 store = lq_store_new(p); 31 ck_assert_ptr_nonnull(store->userdata); 32 33 resolve_dummy.store = &LQDummyContent; 34 resolve_dummy.next = NULL; 35 resolve.store = store; 36 resolve.next = &resolve_dummy; 37 msg = lq_msg_new(data, strlen(data) + 1); 38 msg->pubkey = lq_publickey_new(data); 39 40 c = 4096; 41 r = lq_msg_serialize(msg, buf, &c, &resolve); 42 ck_assert_int_eq(r, 0); 43 lq_msg_free(msg); 44 45 r = lq_msg_deserialize(&msg, buf, c, &resolve); 46 ck_assert_ptr_nonnull(msg); 47 ck_assert_int_eq(r, 0); 48 lq_msg_free(msg); 49 resolve.store->free(resolve.store); 50 resolve_dummy.store->free(resolve_dummy.store); 51 } 52 END_TEST 53 54 Suite * common_suite(void) { 55 Suite *s; 56 TCase *tc; 57 58 s = suite_create("msg"); 59 tc = tcase_create("serialize"); 60 tcase_add_test(tc, check_msg_symmetric); 61 suite_add_tcase(s, tc); 62 63 return s; 64 } 65 66 int main(void) { 67 int n_fail; 68 69 Suite *s; 70 SRunner *sr; 71 72 s = common_suite(); 73 sr = srunner_create(s); 74 75 srunner_run_all(sr, CK_VERBOSE); 76 n_fail = srunner_ntests_failed(sr); 77 srunner_free(sr); 78 79 return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 80 }