]> git.ipfire.org Git - thirdparty/freeswitch.git/blame - libs/libzrtp/test/engine_helpers.c
[mod_http_cache] Fix leaking curl handle in http_get()
[thirdparty/freeswitch.git] / libs / libzrtp / test / engine_helpers.c
CommitLineData
02b3b806
VK
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> /*chmockery dependency*/
11#include <stdio.h> /*chmockery dependency*/
12#include <unistd.h> /*for usleep*/
13
14#include "cmockery/cmockery.h"
15#include "test_engine.h"
16
17static zrtp_test_id_t g_alice, g_bob;
18static zrtp_test_id_t g_alice_sid, g_bob_sid;
19static zrtp_test_id_t g_secure_audio_channel;
20
21
22static void prepare_alice_bob() {
23 zrtp_status_t s;
24
25 zrtp_test_session_cfg_t session_config;
26 zrtp_test_session_config_defaults(&session_config);
27
28 /*
29 * Create two test sessions, one for Alice and one for Bob and link them
30 * into test secure channel
31 */
32 s = zrtp_test_session_create(g_alice, &session_config, &g_alice_sid);
33 assert_int_equal(zrtp_status_ok, s);
34 assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice_sid);
35
36 s = zrtp_test_session_create(g_bob, &session_config, &g_bob_sid);
37 assert_int_equal(zrtp_status_ok, s);
38 assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob_sid);
39
40 s = zrtp_test_channel_create2(g_alice_sid, g_bob_sid, 0, &g_secure_audio_channel);
41 assert_int_equal(zrtp_status_ok, s);
42 assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_secure_audio_channel);
43}
44
45static void release_alice_bob() {
46 zrtp_test_session_destroy(g_alice_sid);
47 zrtp_test_session_destroy(g_bob_sid);
48
49 zrtp_test_channel_destroy(g_secure_audio_channel);
50}
51
52static void start_alice_bob_and_wait4secure() {
53 zrtp_status_t s;
54 zrtp_test_channel_info_t channel_info;
55
56 /* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
57 s = zrtp_test_channel_start(g_secure_audio_channel);
58 assert_int_equal(zrtp_status_ok, s);
59
60 unsigned i = 30;
61 for (; i>0; i--) {
62 usleep(100*1000);
63 }
64
65 s = zrtp_test_channel_get(g_secure_audio_channel, &channel_info);
66 assert_int_equal(zrtp_status_ok, s);
67
68 assert_true(channel_info.is_secure);
69}