check_chunk.c (937B)
1 #include <check.h> 2 #include <stdlib.h> 3 4 #include "common.h" 5 #include "hex.h" 6 #include "def.h" 7 #include "chunk.h" 8 #include "bmt_malloc.h" 9 10 11 START_TEST(check_chunk_verify) { 12 int r; 13 swarm_chunk_t chunk; 14 15 hex2bin(HASH_OF_FOO, chunk.hash); 16 memset(chunk.span, 0, SWARM_DATA_LENGTH_TYPESIZE); 17 chunk.span[0] = 3; 18 chunk.payload = "foo"; 19 chunk.payload_sz = 3; 20 21 r = chunk_verify(&chunk); 22 ck_assert_int_eq(r, 0); 23 24 chunk.span[0] = 4; 25 r = chunk_verify(&chunk); 26 ck_assert_int_eq(r, 1); 27 } 28 END_TEST 29 30 31 Suite * common_suite(void) { 32 Suite *s; 33 TCase *tc; 34 35 s = suite_create("chunk"); 36 tc = tcase_create("core"); 37 tcase_add_test(tc, check_chunk_verify); 38 suite_add_tcase(s, tc); 39 40 return s; 41 } 42 43 int main(void) { 44 int n_fail; 45 46 Suite *s; 47 SRunner *sr; 48 49 s = common_suite(); 50 sr = srunner_create(s); 51 52 srunner_run_all(sr, CK_VERBOSE); 53 n_fail = srunner_ntests_failed(sr); 54 srunner_free(sr); 55 56 return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 57 }