libqaeda

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

test_envelope.c (2513B)


      1 #include <check.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 //#include "lq/msg.h"
      6 #include "lq/cert.h"
      7 #include "lq/mem.h"
      8 //#include "lq/crypto.h"
      9 #include "lq/config.h"
     10 #include "lq/base.h"
     11 #include "lq/envelope.h"
     12 #include "lq/io.h"
     13 
     14 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.";
     15 const char *data_two = "Que trata de la condición y ejercicio del famoso hidalgo D. Quijote de la Mancha En un lugar de la Mancha, de cuyo nombre no quiero acordarme, no ha mucho tiempo que vivía un hidalgo de los de lanza en astillero, adarga antigua, rocín flaco y galgo corredor.";
     16 
     17 START_TEST(check_envelope) {
     18 	int r;
     19 	size_t c;
     20 	LQCert *cert;
     21 	LQEnvelope *env;
     22 	LQMsg *req;
     23 	char buf[4096];
     24 
     25 	req = lq_msg_new(data, strlen(data) + 1);
     26 	ck_assert_ptr_nonnull(req);
     27 
     28 	cert = lq_certificate_new(NULL);
     29 	ck_assert_ptr_nonnull(cert);
     30 
     31 	r = lq_certificate_request(cert, req, NULL);
     32 	c = LQ_BLOCKSIZE;
     33 	r = lq_certificate_serialize(cert, NULL, buf, &c);
     34 	ck_assert_int_eq(r, 0);
     35 
     36 	env = lq_envelope_new(cert, 500);
     37 	ck_assert_ptr_nonnull(env);
     38 	r = lq_envelope_attach(env, data, strlen(data) + 1);
     39 	ck_assert_int_eq(r, 0);
     40 	r = lq_envelope_attach(env, data_two, strlen(data_two) + 1);
     41 	ck_assert_int_eq(r, 0);
     42 
     43 	c = sizeof(buf);
     44 	r = lq_envelope_serialize(env, NULL, buf, &c);
     45 	ck_assert_int_eq(r, 0);
     46 	lq_envelope_free(env);
     47 
     48 	r = lq_envelope_deserialize(&env, NULL, buf, c);
     49 	ck_assert_int_eq(r, 0);
     50 	ck_assert_int_eq(env->hint, 500);
     51 	lq_envelope_free(env);
     52 }
     53 END_TEST
     54 
     55 
     56 Suite * common_suite(void) {
     57 	Suite *s;
     58 	TCase *tc;
     59 
     60 	s = suite_create("envelope");
     61 	tc = tcase_create("serialize");
     62 	tcase_add_test(tc, check_envelope);
     63 	suite_add_tcase(s, tc);
     64 
     65 	return s;
     66 }
     67 
     68 int main(void) {
     69 	int r;
     70 	int n_fail;
     71 	char path[LQ_PATH_MAX];
     72 
     73 	Suite *s;
     74 	SRunner *sr;
     75 
     76 	r = lq_init();
     77 	if (r) {
     78 		return 1;
     79 	}
     80 
     81 	lq_cpy(path, "/tmp/lqcrypto_test_XXXXXX", 26);
     82 	r = lq_crypto_init(mktempdir(path));
     83 	if (r) {
     84 		return 1;
     85 	}
     86 
     87 	s = common_suite();	
     88 	sr = srunner_create(s);
     89 
     90 	srunner_run_all(sr, CK_VERBOSE);
     91 	n_fail = srunner_ntests_failed(sr);
     92 	srunner_free(sr);
     93 
     94 	return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
     95 }