mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2025-01-06 03:25:31 +00:00
tests: Test SDP messages
This commit is contained in:
parent
2506827c17
commit
9502d10970
1 changed files with 126 additions and 0 deletions
126
tests/test-sip.c
126
tests/test-sip.c
|
@ -7,11 +7,14 @@
|
|||
*/
|
||||
|
||||
#include "calls-provider.h"
|
||||
#include "calls-sip-media-manager.h"
|
||||
#include "calls-sip-provider.h"
|
||||
#include "calls-sip-origin.h"
|
||||
#include "calls-sip-util.h"
|
||||
#include "gst-rfc3551.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <sofia-sip/su_uniqueid.h>
|
||||
#include <libpeas/peas.h>
|
||||
|
||||
|
@ -168,6 +171,127 @@ tear_down_sip_origins (SipFixture *fixture,
|
|||
tear_down_sip_provider (fixture, user_data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
find_string_in_sdp_message (const char *sdp,
|
||||
const char *string)
|
||||
{
|
||||
char **split_string = NULL;
|
||||
gboolean found = FALSE;
|
||||
|
||||
split_string = g_strsplit (sdp, "\r\n", -1);
|
||||
|
||||
for (guint i = 0; split_string[i] != NULL; i++) {
|
||||
if (g_strcmp0 (split_string[i], string) == 0) {
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev (split_string);
|
||||
return found;
|
||||
}
|
||||
|
||||
static void
|
||||
test_sip_media_manager ()
|
||||
{
|
||||
g_autoptr (CallsSipMediaManager) manager = calls_sip_media_manager_default ();
|
||||
char *sdp_message = NULL;
|
||||
GList *codecs = NULL;
|
||||
|
||||
/* Check single codecs */
|
||||
codecs = g_list_append (NULL, media_codec_by_name ("PCMA"));
|
||||
|
||||
/* PCMA RTP */
|
||||
sdp_message =
|
||||
calls_sip_media_manager_get_capabilities (manager, 40002, FALSE, codecs);
|
||||
|
||||
g_assert_true (sdp_message);
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"m=audio 40002 RTP/AVP 8"));
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"a=rtpmap:8 PCMA/8000"));
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"a=rtcp:40003"));
|
||||
|
||||
g_free (sdp_message);
|
||||
|
||||
/* PCMA SRTP */
|
||||
sdp_message =
|
||||
calls_sip_media_manager_get_capabilities (manager, 42002, TRUE, codecs);
|
||||
g_assert_true (sdp_message);
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"m=audio 42002 RTP/SAVP 8"));
|
||||
|
||||
g_clear_pointer (&codecs, g_list_free);
|
||||
g_free (sdp_message);
|
||||
|
||||
/* G722 RTP */
|
||||
codecs = g_list_append (NULL, media_codec_by_name ("G722"));
|
||||
|
||||
sdp_message =
|
||||
calls_sip_media_manager_get_capabilities (manager, 42042, FALSE, codecs);
|
||||
|
||||
g_assert_true (sdp_message);
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"m=audio 42042 RTP/AVP 9"));
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"a=rtpmap:9 G722/8000"));
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"a=rtcp:42043"));
|
||||
|
||||
g_clear_pointer (&codecs, g_list_free);
|
||||
g_free (sdp_message);
|
||||
|
||||
/* G722 PCMU PCMA RTP (in this order) */
|
||||
codecs = g_list_append (NULL, media_codec_by_name ("G722"));
|
||||
codecs = g_list_append (codecs, media_codec_by_name ("PCMU"));
|
||||
codecs = g_list_append (codecs, media_codec_by_name ("PCMA"));
|
||||
|
||||
sdp_message =
|
||||
calls_sip_media_manager_get_capabilities (manager, 33340, FALSE, codecs);
|
||||
|
||||
g_assert_true (sdp_message);
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"m=audio 33340 RTP/AVP 9 0 8"));
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"a=rtpmap:9 G722/8000"));
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"a=rtpmap:0 PCMU/8000"));
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"a=rtpmap:8 PCMA/8000"));
|
||||
|
||||
g_clear_pointer (&codecs, g_list_free);
|
||||
g_free (sdp_message);
|
||||
|
||||
/* GSM PCMA G722 PCMU (in this order) */
|
||||
codecs = g_list_append (NULL, media_codec_by_name ("GSM"));
|
||||
codecs = g_list_append (codecs, media_codec_by_name ("PCMA"));
|
||||
codecs = g_list_append (codecs, media_codec_by_name ("G722"));
|
||||
codecs = g_list_append (codecs, media_codec_by_name ("PCMU"));
|
||||
|
||||
sdp_message =
|
||||
calls_sip_media_manager_get_capabilities (manager, 18098, TRUE, codecs);
|
||||
|
||||
g_assert_true (sdp_message);
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"m=audio 18098 RTP/SAVP 3 8 9 0"));
|
||||
|
||||
g_clear_pointer (&codecs, g_list_free);
|
||||
g_free (sdp_message);
|
||||
|
||||
g_test_expect_message ("CallsSipMediaManager", G_LOG_LEVEL_WARNING,
|
||||
"No supported codecs found. Can't build meaningful SDP message");
|
||||
sdp_message =
|
||||
calls_sip_media_manager_get_capabilities (manager, 25048, FALSE, NULL);
|
||||
|
||||
g_test_assert_expected_messages ();
|
||||
g_assert_true (sdp_message);
|
||||
g_assert_true (find_string_in_sdp_message (sdp_message,
|
||||
"m=audio 0 RTP/AVP"));
|
||||
|
||||
g_free (sdp_message);
|
||||
}
|
||||
|
||||
gint
|
||||
main (gint argc,
|
||||
gchar *argv[])
|
||||
|
@ -195,5 +319,7 @@ main (gint argc,
|
|||
g_test_add ("/Calls/SIP/calls_direct_call", SipFixture, NULL,
|
||||
setup_sip_origins, test_sip_call_direct_calls, tear_down_sip_origins);
|
||||
|
||||
g_test_add_func ("/Calls/SIP/media_manager", test_sip_media_manager);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue