]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Add test for some minor bugs
authorViktor Krykun <viktor@krykun.com>
Fri, 15 Jun 2012 07:23:46 +0000 (10:23 +0300)
committerTravis Cross <tc@traviscross.com>
Mon, 11 Feb 2013 16:41:54 +0000 (16:41 +0000)
Modified-by: Travis Cross <tc@traviscross.com>
Signed-off-by: Travis Cross <tc@traviscross.com>
libs/libzrtp/test/minor_bugs_test.c [new file with mode: 0644]

diff --git a/libs/libzrtp/test/minor_bugs_test.c b/libs/libzrtp/test/minor_bugs_test.c
new file mode 100644 (file)
index 0000000..2bf46b2
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
+ * Copyright (c) 2006-2009 Philip R. Zimmermann.  All rights reserved.
+ * Contact: http://philzimmermann.com
+ * For licensing and other legal details, see the file zrtp_legal.c.
+ *
+ * Viktor Krykun <v.krikun at zfoneproject.com>
+ */
+
+#include <setjmp.h>
+#include <stdio.h>
+
+#include "zrtp.h"
+#include "cmockery/cmockery.h"
+
+zrtp_global_t *zrtp;
+
+void setup() {
+       zrtp_status_t s;
+       zrtp_config_t zrtp_config;
+
+       zrtp_config_defaults(&zrtp_config);
+
+       s = zrtp_init(&zrtp_config, &zrtp);
+       assert_int_equal(s, zrtp_status_ok);
+}
+
+void teardown() {
+       zrtp_down(zrtp);
+}
+
+
+static void session_init_fails_with_no_dh2k() {
+       zrtp_profile_t profile;
+       zrtp_status_t s;
+
+       zrtp_session_t *new_session;
+
+       /* Let's initialize ZRTP session with default profile first */
+       zrtp_profile_defaults(&profile, zrtp);
+
+       new_session = NULL;
+       s = zrtp_session_init(zrtp,
+                       &profile,
+                       ZRTP_SIGNALING_ROLE_INITIATOR,
+                       &new_session);
+
+       assert_int_equal(zrtp_status_ok, s);
+       assert_non_null(new_session);
+
+       /* Then disable DH2K and leave just mandatory parameters  */
+       profile.pk_schemes[0] = ZRTP_PKTYPE_DH3072;
+       profile.pk_schemes[1] = ZRTP_PKTYPE_MULT;
+       profile.pk_schemes[2] = 0;
+
+       new_session = NULL;
+       s = zrtp_session_init(zrtp,
+                       &profile,
+                       ZRTP_SIGNALING_ROLE_INITIATOR,
+                       &new_session);
+
+       assert_int_equal(zrtp_status_ok, s);
+       assert_non_null(new_session);
+
+       /* Let's try to disable Multi key exchange, it should produce an error. */
+       profile.pk_schemes[0] = ZRTP_PKTYPE_DH3072;
+       profile.pk_schemes[1] = 0;
+
+       new_session = NULL;
+       s = zrtp_session_init(zrtp,
+                       &profile,
+                       ZRTP_SIGNALING_ROLE_INITIATOR,
+                       &new_session);
+
+       assert_int_not_equal(zrtp_status_ok, s);
+       assert_null(new_session);
+
+       /* Profile checking with one of mandatory components missing should return error too. */
+       s = zrtp_profile_check(&profile, zrtp);
+       assert_int_not_equal(zrtp_status_ok, s);
+
+       /* NOTE: we ignore memory leaks and don't destroy ZRTP sessions to make test sources cleaner */
+}
+
+
+int main(void) {
+       const UnitTest tests[] = {
+               unit_test_setup_teardown(session_init_fails_with_no_dh2k, setup, teardown),
+       };
+
+       return run_tests(tests);
+}