diff options
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | tests/check/Makefile.am | 5 | ||||
-rw-r--r-- | tests/check/libs/gstnetmeta.c | 129 |
3 files changed, 139 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 433d4a586..f9f7ae176 100644 --- a/configure.ac +++ b/configure.ac @@ -556,6 +556,12 @@ if test "x$BUILD_TESTS" = "xyes"; then AC_DEFINE(HAVE_GSL, [1],[Have GSL library])) fi +dnl *** gio-unix-2.0 for tests/check/libs/gstnetmeta.c *** +translit(dnm, m, l) AM_CONDITIONAL(USE_GIO_UNIX_2_0, true) +AG_GST_CHECK_FEATURE(GIO_UNIX_2_0, [glib GIO unix], gio-unix-2.0, [ + AG_GST_PKG_CHECK_MODULES(GIO_UNIX_2_0, gio-unix-2.0 >= 2.24) +]) + dnl *** checks for types/defines *** dnl *** checks for structures *** diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index c4a0936e3..4c6ff790b 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -223,9 +223,12 @@ libs_controller_LDADD = \ libs_gstnetclientclock_LDADD = \ $(top_builddir)/libs/gst/net/libgstnet-@GST_API_VERSION@.la \ $(LDADD) + libs_gstnetmeta_LDADD = \ $(top_builddir)/libs/gst/net/libgstnet-@GST_API_VERSION@.la \ - $(GIO_LIBS) $(LDADD) + $(GIO_LIBS) $(GIO_UNIX_2_0_LIBS) $(LDADD) +libs_gstnetmeta_CFLAGS = \ + $(GIO_CFLAGS) $(GIO_UNIX_2_0_CFLAGS) $(AM_CFLAGS) libs_gstnettimeprovider_LDADD = \ $(top_builddir)/libs/gst/net/libgstnet-@GST_API_VERSION@.la \ $(GIO_LIBS) $(LDADD) diff --git a/tests/check/libs/gstnetmeta.c b/tests/check/libs/gstnetmeta.c index 17e33da1b..5a732bf90 100644 --- a/tests/check/libs/gstnetmeta.c +++ b/tests/check/libs/gstnetmeta.c @@ -25,7 +25,16 @@ #include <gst/check/gstcheck.h> #include <gst/check/gstconsistencychecker.h> #include <gst/net/gstnetaddressmeta.h> +#include <gst/net/gstnetcontrolmessagemeta.h> +#ifdef HAVE_GIO_UNIX_2_0 +#include <gio/gunixfdmessage.h> +#include <sys/socket.h> +#endif /* HAVE_GIO_UNIX_2_0 */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> static gboolean addr_string_cmp (GSocketAddress * addr_1, const gchar * saddr_2, guint16 port_2) @@ -120,6 +129,121 @@ GST_START_TEST (that_gsocketaddress_is_duplicated_with_buffer) GST_END_TEST; +#ifdef HAVE_GIO_UNIX_2_0 + +static int +get_inode_no (int fd) +{ + struct stat s; + fail_unless (fstat (fd, &s) == 0); + return s.st_ino; +} + + +static GSocketControlMessage * +create_tmpfile_fd_message (ino_t * inode_out) +{ + GSocketControlMessage *msg; + char tmpfilename[] = "/tmp/gst-tests-check-libs-gstnetmeta.XXXXXX"; + int fd; + + fd = mkstemp (tmpfilename); + fail_unless (fd > 0); + fail_unless (unlink (tmpfilename) == 0); + if (inode_out) + *inode_out = get_inode_no (fd); + + msg = g_unix_fd_message_new (); + fail_unless (g_unix_fd_message_append_fd ((GUnixFDMessage *) msg, fd, NULL)); + close (fd); + return msg; +} + + +static int +get_inode_no_from_control_message (GSocketControlMessage * msg) +{ + GUnixFDList *fdlist; + const gint *fds; + gint fds_len; + + fail_unless (g_socket_control_message_get_msg_type (msg) == SCM_RIGHTS); + + fdlist = g_unix_fd_message_get_fd_list ((GUnixFDMessage *) msg); + fds = g_unix_fd_list_peek_fds (fdlist, &fds_len); + fail_unless (fds_len == 1); + return get_inode_no (fds[0]); +} + + +GST_START_TEST (that_gsocketcontrolmessage_can_be_attached_to_buffer) +{ + GstBuffer *buf; + GSocketControlMessage *msg; + GstNetControlMessageMeta *meta = NULL; + ino_t orig_inode = 0; + + buf = gst_buffer_new (); + + msg = create_tmpfile_fd_message (&orig_inode); + meta = gst_buffer_add_net_control_message_meta (buf, msg); + g_clear_object (&msg); + + meta = gst_buffer_get_net_control_message_meta (buf); + fail_unless (meta != NULL); + fail_unless (get_inode_no_from_control_message (meta->message) == orig_inode); + gst_buffer_unref (buf); +} + +GST_END_TEST; + + +GST_START_TEST (that_gsocketcontrolmessage_can_be_removed_from_buffer) +{ + GstBuffer *buf; + GSocketControlMessage *msg; + GstNetControlMessageMeta *meta = NULL; + + buf = gst_buffer_new (); + + msg = create_tmpfile_fd_message (NULL); + meta = gst_buffer_add_net_control_message_meta (buf, msg); + g_clear_object (&msg); + + fail_unless (gst_buffer_remove_meta (buf, (GstMeta *) meta)); + gst_buffer_unref (buf); +} + +GST_END_TEST; + + +GST_START_TEST (that_gsocketcontrolmessage_is_duplicated_with_buffer) +{ + GstBuffer *buf1, *buf2; + GSocketControlMessage *msg; + GstNetControlMessageMeta *meta = NULL; + ino_t orig_inode; + + buf1 = gst_buffer_new (); + + msg = create_tmpfile_fd_message (&orig_inode); + meta = gst_buffer_add_net_control_message_meta (buf1, msg); + g_clear_object (&msg); + + buf2 = gst_buffer_copy (buf1); + gst_buffer_unref (buf1); + + meta = gst_buffer_get_net_control_message_meta (buf2); + fail_unless (meta != NULL); + + fail_unless (orig_inode == get_inode_no_from_control_message (meta->message)); + gst_buffer_unref (buf2); +} + +GST_END_TEST; +#endif /* HAVE_GIO_UNIX_2_0 */ + + static Suite * gst_basesrc_suite (void) { @@ -130,6 +254,11 @@ gst_basesrc_suite (void) tcase_add_test (tc, that_gsocketaddress_can_be_attached_to_buffer); tcase_add_test (tc, that_gsocketaddress_can_be_removed_from_buffer); tcase_add_test (tc, that_gsocketaddress_is_duplicated_with_buffer); +#ifdef HAVE_GIO_UNIX_2_0 + tcase_add_test (tc, that_gsocketcontrolmessage_can_be_attached_to_buffer); + tcase_add_test (tc, that_gsocketcontrolmessage_can_be_removed_from_buffer); + tcase_add_test (tc, that_gsocketcontrolmessage_is_duplicated_with_buffer); +#endif /* HAVE_GIO_UNIX_2_0 */ return s; } |