mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 09:10:36 +00:00
tests: udpsrc: split out socket setup
This commit is contained in:
parent
e6f77948ac
commit
7b1774513e
1 changed files with 63 additions and 51 deletions
|
@ -26,38 +26,53 @@ static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS_ANY);
|
GST_STATIC_CAPS_ANY);
|
||||||
|
|
||||||
GST_START_TEST (test_udpsrc_empty_packet)
|
static gboolean
|
||||||
|
udpsrc_setup (GstElement ** udpsrc, GSocket ** socket,
|
||||||
|
GstPad ** sinkpad, GSocketAddress ** sa)
|
||||||
{
|
{
|
||||||
GstElement *udpsrc;
|
GInetAddress *ia;
|
||||||
GSocket *socket;
|
|
||||||
GstPad *sinkpad;
|
|
||||||
int port = 0;
|
int port = 0;
|
||||||
|
gchar *s;
|
||||||
|
|
||||||
udpsrc = gst_check_setup_element ("udpsrc");
|
*udpsrc = gst_check_setup_element ("udpsrc");
|
||||||
fail_unless (udpsrc != NULL);
|
fail_unless (*udpsrc != NULL);
|
||||||
g_object_set (udpsrc, "port", 0, NULL);
|
g_object_set (*udpsrc, "port", 0, NULL);
|
||||||
|
|
||||||
sinkpad = gst_check_setup_sink_pad_by_name (udpsrc, &sinktemplate, "src");
|
*sinkpad = gst_check_setup_sink_pad_by_name (*udpsrc, &sinktemplate, "src");
|
||||||
fail_unless (sinkpad != NULL);
|
fail_unless (*sinkpad != NULL);
|
||||||
gst_pad_set_active (sinkpad, TRUE);
|
gst_pad_set_active (*sinkpad, TRUE);
|
||||||
|
|
||||||
gst_element_set_state (udpsrc, GST_STATE_PLAYING);
|
gst_element_set_state (*udpsrc, GST_STATE_PLAYING);
|
||||||
g_object_get (udpsrc, "port", &port, NULL);
|
g_object_get (*udpsrc, "port", &port, NULL);
|
||||||
GST_INFO ("udpsrc port = %d", port);
|
GST_INFO ("udpsrc port = %d", port);
|
||||||
|
|
||||||
socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
|
*socket = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_DATAGRAM,
|
||||||
G_SOCKET_PROTOCOL_UDP, NULL);
|
G_SOCKET_PROTOCOL_UDP, NULL);
|
||||||
|
|
||||||
if (socket != NULL) {
|
if (*socket == NULL) {
|
||||||
GSocketAddress *sa;
|
GST_WARNING ("Could not create IPv4 UDP socket for unit test");
|
||||||
GInetAddress *ia;
|
return FALSE;
|
||||||
gchar *s;
|
}
|
||||||
|
|
||||||
ia = g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4);
|
ia = g_inet_address_new_loopback (G_SOCKET_FAMILY_IPV4);
|
||||||
s = g_inet_address_to_string (ia);
|
s = g_inet_address_to_string (ia);
|
||||||
GST_LOG ("inet address %s", s);
|
GST_LOG ("inet address %s", s);
|
||||||
g_free (s);
|
g_free (s);
|
||||||
sa = g_inet_socket_address_new (ia, port);
|
*sa = g_inet_socket_address_new (ia, port);
|
||||||
|
g_object_unref (ia);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_START_TEST (test_udpsrc_empty_packet)
|
||||||
|
{
|
||||||
|
GSocketAddress *sa = NULL;
|
||||||
|
GstElement *udpsrc = NULL;
|
||||||
|
GSocket *socket = NULL;
|
||||||
|
GstPad *sinkpad = NULL;
|
||||||
|
|
||||||
|
if (!udpsrc_setup (&udpsrc, &socket, &sinkpad, &sa))
|
||||||
|
goto no_socket;
|
||||||
|
|
||||||
if (g_socket_send_to (socket, sa, "HeLL0", 0, NULL, NULL) == 0) {
|
if (g_socket_send_to (socket, sa, "HeLL0", 0, NULL, NULL) == 0) {
|
||||||
GST_INFO ("sent 0 bytes");
|
GST_INFO ("sent 0 bytes");
|
||||||
|
@ -93,11 +108,7 @@ GST_START_TEST (test_udpsrc_empty_packet)
|
||||||
GST_WARNING ("send_to(0 bytes) failed");
|
GST_WARNING ("send_to(0 bytes) failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (sa);
|
no_socket:
|
||||||
g_object_unref (ia);
|
|
||||||
} else {
|
|
||||||
GST_WARNING ("Could not create IPv4 UDP socket for unit test");
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_element_set_state (udpsrc, GST_STATE_NULL);
|
gst_element_set_state (udpsrc, GST_STATE_NULL);
|
||||||
|
|
||||||
|
@ -105,6 +116,7 @@ GST_START_TEST (test_udpsrc_empty_packet)
|
||||||
gst_check_teardown_element (udpsrc);
|
gst_check_teardown_element (udpsrc);
|
||||||
|
|
||||||
g_object_unref (socket);
|
g_object_unref (socket);
|
||||||
|
g_object_unref (sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
Loading…
Reference in a new issue