libqaeda

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

test_test.c (1655B)


      1 #include <check.h>
      2 #include <stdlib.h>
      3 
      4 #include "lq/base.h"
      5 #include "lq/io.h"
      6 #include "lq/mem.h"
      7 #include "lq/store.h"
      8 
      9 // sha256sum "foo" 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
     10 static const char foosum[32] = {
     11 	0x2c, 0x26, 0xb4, 0x6b, 0x68, 0xff, 0xc6, 0x8f,
     12 	0xf9, 0x9b, 0x45, 0x3c, 0x1d, 0x30, 0x41, 0x34,
     13 	0x13, 0x42, 0x2d, 0x70, 0x64, 0x83, 0xbf, 0xa0,
     14 	0xf9, 0x8a, 0x5e, 0x88, 0x62, 0x66, 0xe7, 0xae,
     15 };
     16 
     17 
     18 START_TEST(check_hashmap) {
     19 	LQStore *store;
     20 	char path[LQ_PATH_MAX];
     21 	const char *k;
     22 	size_t kl;
     23 	char *v;
     24 	size_t vl;
     25 	int i;
     26 	char out[8192];
     27 	char in[8192];
     28 
     29 	lq_cpy(path, "/tmp/lq_test_XXXXXX", 20);
     30 	store = lq_store_new(mktempdir(path));
     31 	ck_assert_ptr_nonnull(store);
     32 
     33 	k = "foo";
     34 	kl = 3;
     35 	v = "bar";
     36 	vl = 3;
     37 	store->put(LQ_CONTENT_RAW, store, k, &kl, v, vl);
     38 
     39 	v = out;
     40 	vl = 8192;
     41 	store->get(LQ_CONTENT_RAW, store, k, kl, v, &vl);
     42 
     43 	k = foosum;
     44 	kl = 32;
     45 	for (i = 0; i < 8192; i++) {
     46 		in[i] = i % 256;
     47 	}
     48 	v = in;
     49 	vl = 8192;
     50 	store->put(LQ_CONTENT_KEY, store, k, &kl, v, vl);
     51 
     52 	v = out;
     53 	store->get(LQ_CONTENT_KEY, store, k, kl, v, &vl);
     54 
     55 	ck_assert_mem_eq(in, out, 8192);
     56 
     57 	store->free(store);
     58 }
     59 END_TEST
     60 
     61 
     62 Suite * common_suite(void) {
     63 	Suite *s;
     64 	TCase *tc;
     65 
     66 	s = suite_create("test");
     67 	tc = tcase_create("provisions");
     68 	tcase_add_test(tc, check_hashmap);
     69 	suite_add_tcase(s, tc);
     70 
     71 	return s;
     72 }
     73 
     74 int main(void) {
     75 	int r;
     76 	int n_fail;
     77 
     78 	Suite *s;
     79 	SRunner *sr;
     80 
     81 	r = lq_init();
     82 	if (r) {
     83 		return 1;
     84 	}
     85 
     86 	s = common_suite();	
     87 	sr = srunner_create(s);
     88 
     89 	srunner_run_all(sr, CK_VERBOSE);
     90 	n_fail = srunner_ntests_failed(sr);
     91 	srunner_free(sr);
     92 
     93 	return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
     94 }