engine_helpers.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include <setjmp.h> /*chmockery dependency*/
  10. #include <stdio.h> /*chmockery dependency*/
  11. #include <unistd.h> /*for usleep*/
  12. #include "cmockery/cmockery.h"
  13. #include "test_engine.h"
  14. static zrtp_test_id_t g_alice, g_bob;
  15. static zrtp_test_id_t g_alice_sid, g_bob_sid;
  16. static zrtp_test_id_t g_secure_audio_channel;
  17. static void prepare_alice_bob() {
  18. zrtp_status_t s;
  19. zrtp_test_session_cfg_t session_config;
  20. zrtp_test_session_config_defaults(&session_config);
  21. /*
  22. * Create two test sessions, one for Alice and one for Bob and link them
  23. * into test secure channel
  24. */
  25. s = zrtp_test_session_create(g_alice, &session_config, &g_alice_sid);
  26. assert_int_equal(zrtp_status_ok, s);
  27. assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_alice_sid);
  28. s = zrtp_test_session_create(g_bob, &session_config, &g_bob_sid);
  29. assert_int_equal(zrtp_status_ok, s);
  30. assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_bob_sid);
  31. s = zrtp_test_channel_create2(g_alice_sid, g_bob_sid, 0, &g_secure_audio_channel);
  32. assert_int_equal(zrtp_status_ok, s);
  33. assert_int_not_equal(ZRTP_TEST_UNKNOWN_ID, g_secure_audio_channel);
  34. }
  35. static void release_alice_bob() {
  36. zrtp_test_session_destroy(g_alice_sid);
  37. zrtp_test_session_destroy(g_bob_sid);
  38. zrtp_test_channel_destroy(g_secure_audio_channel);
  39. }
  40. static void start_alice_bob_and_wait4secure() {
  41. zrtp_status_t s;
  42. zrtp_test_channel_info_t channel_info;
  43. /* Everything is ready. Let's start the stream and give it few seconds to switch secure. */
  44. s = zrtp_test_channel_start(g_secure_audio_channel);
  45. assert_int_equal(zrtp_status_ok, s);
  46. unsigned i = 30;
  47. for (; i>0; i--) {
  48. usleep(100*1000);
  49. }
  50. s = zrtp_test_channel_get(g_secure_audio_channel, &channel_info);
  51. assert_int_equal(zrtp_status_ok, s);
  52. assert_true(channel_info.is_secure);
  53. }