librlp

C library for the Recursive Length Prefix (RLP) serialization format
git clone git://git.defalsify.org/librlp.git
Info | Log | Files | Refs | README | LICENSE

check_bits.c (1243B)


      1 #include <check.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 #include "bits.h"
      6 
      7 START_TEST(le_test) {
      8 	char v[10];
      9 	int r;
     10 
     11 	memset(v, 0, 10);
     12 
     13 	r = intbits_le(0, NULL);
     14 	ck_assert_int_eq(r, 0);
     15 
     16 	r = intbits_le(10, (char*)v);
     17 	ck_assert_int_eq(r, 1);
     18 
     19 	v[0] = 2;
     20 	r = intbits_le(10, (char*)v);
     21 	ck_assert_int_eq(r, 2);
     22 
     23 	v[1] = 2;
     24 	r = intbits_le(10, v);
     25 	ck_assert_int_eq(r, 10);
     26 	r = intbytes_le(10, v);
     27 	ck_assert_int_eq(r, 2);
     28 
     29 	v[9] = 7;
     30 	r = intbits_le(10, v);
     31 	ck_assert_int_eq(r, 75);
     32 	r = intbytes_le(10, v);
     33 	ck_assert_int_eq(r, 10);
     34 }
     35 END_TEST
     36 
     37 
     38 START_TEST(le_boundary_test) {
     39 	char v[10];
     40 	int r;
     41 
     42 	memset(v, 0, 10);
     43 
     44 
     45 	v[1] = 0x80;
     46 	r = intbytes_le(10, v);
     47 	ck_assert_int_eq(r, 2);
     48 
     49 	v[2] = 0x01;
     50 	r = intbytes_le(10, v);
     51 	ck_assert_int_eq(r, 3);
     52 
     53 }
     54 END_TEST
     55 
     56 
     57 Suite *bits_suite(void) {
     58 	Suite *s;
     59 	TCase *tc;
     60 
     61 	s = suite_create("Rlp");
     62 	tc = tcase_create("Init");
     63 
     64 	tcase_add_test(tc, le_test);
     65 	tcase_add_test(tc, le_boundary_test);
     66 	suite_add_tcase(s, tc);
     67 
     68 	return s;
     69 }
     70 
     71 
     72 int main(void) {
     73 	int num_fail;
     74 
     75 	Suite *s;
     76 	SRunner *sr;
     77 
     78 	s = bits_suite();
     79 	sr = srunner_create(s);
     80 
     81 	srunner_run_all(sr, CK_VERBOSE);
     82 	num_fail = srunner_ntests_failed(sr);
     83 	srunner_free(sr);
     84 
     85 	return (num_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
     86 }