[vlc-devel] [PATCH 2/2] test/media: test libvlc_media_player_dump

Thomas Guillem thomas at gllm.fr
Thu May 19 16:47:07 CEST 2016


---
 test/Makefile.am           |  2 +-
 test/libvlc/media_player.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/test/Makefile.am b/test/Makefile.am
index f8d4125..b0d06a1 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -79,7 +79,7 @@ test_libvlc_media_list_player_LDADD = $(LIBVLC)
 test_libvlc_media_list_SOURCES = libvlc/media_list.c
 test_libvlc_media_list_LDADD = $(LIBVLC)
 test_libvlc_media_player_SOURCES = libvlc/media_player.c
-test_libvlc_media_player_LDADD = $(LIBVLC)
+test_libvlc_media_player_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_libvlc_meta_SOURCES = libvlc/meta.c
 test_libvlc_meta_LDADD = $(LIBVLC)
 test_src_misc_variables_SOURCES = src/misc/variables.c
diff --git a/test/libvlc/media_player.c b/test/libvlc/media_player.c
index 43dd44c..b5a0b1c 100644
--- a/test/libvlc/media_player.c
+++ b/test/libvlc/media_player.c
@@ -23,6 +23,13 @@
 
 #include "test.h"
 
+#include <vlc_common.h>
+#include <vlc_fs.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
 static void wait_playing(libvlc_media_player_t *mp)
 {
     libvlc_state_t state;
@@ -176,6 +183,92 @@ static void test_media_player_pause_stop(const char** argv, int argc)
     libvlc_release (vlc);
 }
 
+static void mp_ev_callback (const libvlc_event_t *ev, void *data)
+{
+    (void) ev;
+    vlc_sem_t *sem = data;
+    vlc_sem_post (sem);
+}
+
+static void test_media_player_dump (const char** argv, int argc)
+{
+    libvlc_instance_t *vlc;
+    libvlc_media_t *md;
+    libvlc_media_player_t *mi;
+    libvlc_event_manager_t *ev_manager;
+    vlc_sem_t sem;
+    const char * file = SRCDIR"/samples/image.jpg";
+    char tmp_path[] = "/tmp/libvlc_XXXXXX";
+    const char *paths[] = { file, tmp_path };
+    int fds[2];
+    int tmp_fd, ret;
+
+    log ("Testing dumping of %s\n", file);
+    tmp_fd = vlc_mkstemp (tmp_path);
+    assert (tmp_fd != -1);
+
+    vlc = libvlc_new (argc, argv);
+    assert (vlc != NULL);
+
+    md = libvlc_media_new_path (vlc, file);
+    assert (md != NULL);
+
+    mi = libvlc_media_player_new_from_media (md);
+    assert (mi != NULL);
+    libvlc_media_release (md);
+
+    vlc_sem_init (&sem, 0);
+
+    ev_manager = libvlc_media_player_event_manager (mi);
+    assert (ev_manager != NULL );
+    libvlc_event_attach (ev_manager, libvlc_MediaPlayerEndReached,
+                         mp_ev_callback, &sem);
+    libvlc_event_attach (ev_manager, libvlc_MediaPlayerEncounteredError,
+                         mp_ev_callback, &sem);
+
+
+    ret = libvlc_media_player_dump (mi, tmp_path);
+    assert (ret == 0);
+
+    /* Wait for end or error */
+    vlc_sem_wait (&sem);
+    vlc_sem_destroy (&sem);
+
+    libvlc_media_player_stop (mi);
+    libvlc_media_player_release (mi);
+    libvlc_release (vlc);
+
+    log ("Testing that %s and %s are the same\n", paths[0], paths[1]);
+    for (unsigned int i = 0; i < 2; ++i)
+    {
+        fds[i] = vlc_open (paths[i], O_RDONLY);
+        assert (fds[i] != -1);
+    }
+
+    for (;;)
+    {
+        ssize_t count0, count1;
+        uint8_t buf0[8192];
+        uint8_t buf1[8192];
+
+        count0 = read (fds[0], buf0, 8192);
+        assert (count0 >= 0);
+
+        count1 = read (fds[1], buf1, 8192);
+        assert (count1 >= 0);
+
+        assert (count0 == count1);
+
+        if (count0 == 0)
+            break;
+        assert (memcmp(buf0, buf1, count0) == 0);
+    }
+
+    for (unsigned int i = 0; i < 2; ++i)
+        vlc_close (fds[i]);
+
+    vlc_close (tmp_fd);
+}
 
 int main (void)
 {
@@ -184,6 +277,7 @@ int main (void)
     test_media_player_set_media (test_defaults_args, test_defaults_nargs);
     test_media_player_play_stop (test_defaults_args, test_defaults_nargs);
     test_media_player_pause_stop (test_defaults_args, test_defaults_nargs);
+    test_media_player_dump (test_defaults_args, test_defaults_nargs);
 
     return 0;
 }
-- 
2.8.1



More information about the vlc-devel mailing list