1 /*
2  * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
3  * Copyright (c) 2006-2009 Philip R. Zimmermann.  All rights reserved.
4  * Contact: http://philzimmermann.com
5  * For licensing and other legal details, see the file zrtp_legal.c.
6  *
7  * Viktor Krykun <v.krikun at zfoneproject.com>
8  */
9 
10 #include <setjmp.h>
11 #include <stdio.h>
12 
13 #include "zrtp.h"
14 #include "cmockery/cmockery.h"
15 
16 zrtp_global_t *zrtp;
17 
setup()18 void setup() {
19 	zrtp_status_t s;
20 	zrtp_config_t zrtp_config;
21 
22 	zrtp_config_defaults(&zrtp_config);
23 
24 	s = zrtp_init(&zrtp_config, &zrtp);
25 	assert_int_equal(s, zrtp_status_ok);
26 }
27 
teardown()28 void teardown() {
29 	zrtp_down(zrtp);
30 }
31 
sha1_hash_test()32 static void sha1_hash_test() {
33 	zrtp_hash_t *hash =  zrtp_comp_find(ZRTP_CC_HASH, ZRTP_SRTP_HASH_HMAC_SHA1, zrtp);
34 	assert_non_null(hash);
35 	hash->hash_self_test(hash);
36 }
37 
sha1_hmac_test()38 static void sha1_hmac_test() {
39 	zrtp_hash_t *hash =  zrtp_comp_find(ZRTP_CC_HASH, ZRTP_SRTP_HASH_HMAC_SHA1, zrtp);
40 	assert_non_null(hash);
41 	hash->hmac_self_test(hash);
42 }
43 
sha256_hash_test()44 static void sha256_hash_test() {
45 	zrtp_hash_t *hash =  zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA256, zrtp);
46 	assert_non_null(hash);
47 	hash->hash_self_test(hash);
48 }
49 
sha256_hmac_test()50 static void sha256_hmac_test() {
51 	zrtp_hash_t *hash =  zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA256, zrtp);
52 	assert_non_null(hash);
53 	hash->hmac_self_test(hash);
54 }
55 
sha384_hash_test()56 static void sha384_hash_test() {
57 	zrtp_hash_t *hash =  zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA384, zrtp);
58 	assert_non_null(hash);
59 	hash->hash_self_test(hash);
60 }
61 
sha384_hmac_test()62 static void sha384_hmac_test() {
63 	zrtp_hash_t *hash =  zrtp_comp_find(ZRTP_CC_HASH, ZRTP_HASH_SHA384, zrtp);
64 	assert_non_null(hash);
65 	hash->hmac_self_test(hash);
66 }
67 
68 
main(void)69 int main(void) {
70 	const UnitTest tests[] = {
71 		unit_test_setup_teardown(sha1_hash_test, setup, teardown),
72 		unit_test_setup_teardown(sha1_hmac_test, setup, teardown),
73 		unit_test_setup_teardown(sha256_hash_test, setup, teardown),
74 		unit_test_setup_teardown(sha256_hmac_test, setup, teardown),
75 		unit_test_setup_teardown(sha384_hash_test, setup, teardown),
76 		unit_test_setup_teardown(sha384_hmac_test, setup, teardown),
77   	};
78 
79 	return run_tests(tests);
80 }
81