[vlc-devel] [PATCH 3/3] test: add test_media_subitems
Thomas Guillem
thomas at gllm.fr
Wed Nov 4 19:35:51 CET 2015
Test media subitems when parsing a directory via a path and via a fd.
---
test/libvlc/media.c | 130 ++++++++++++++++++++++++++++++++++
test/samples/subitems/directory/.keep | 0
test/samples/subitems/file.jpg | 0
test/samples/subitems/file.mkv | 0
test/samples/subitems/file.mp3 | 0
test/samples/subitems/file.png | 0
test/samples/subitems/file.ts | 0
7 files changed, 130 insertions(+)
create mode 100644 test/samples/subitems/directory/.keep
create mode 100644 test/samples/subitems/file.jpg
create mode 100644 test/samples/subitems/file.mkv
create mode 100644 test/samples/subitems/file.mp3
create mode 100644 test/samples/subitems/file.png
create mode 100644 test/samples/subitems/file.ts
diff --git a/test/libvlc/media.c b/test/libvlc/media.c
index 2a6e13f..3fe4186 100644
--- a/test/libvlc/media.c
+++ b/test/libvlc/media.c
@@ -21,6 +21,10 @@
* http://www.gnu.org/copyleft/gpl.html *
**********************************************************************/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
#include "test.h"
#include <vlc_common.h>
@@ -90,11 +94,137 @@ static void test_media_preparsed(const char** argv, int argc)
libvlc_release (vlc);
}
+#define TEST_SUBITEMS_COUNT 6
+struct
+{
+ const char *file;
+ libvlc_media_type_t type;
+} test_media_subitems_list[TEST_SUBITEMS_COUNT] =
+{
+ { "directory", libvlc_media_type_directory, },
+ { "file.jpg", libvlc_media_type_file },
+ { "file.mkv", libvlc_media_type_file },
+ { "file.mp3", libvlc_media_type_file },
+ { "file.png", libvlc_media_type_file },
+ { "file.ts", libvlc_media_type_file },
+};
+
+struct test_media_subitems_sys
+{
+ vlc_mutex_t lock;
+ vlc_cond_t wait;
+ bool subitems_tree_added;
+ bool subitems_found[TEST_SUBITEMS_COUNT];
+};
+
+static void subitem_tree_added(const libvlc_event_t *event, void *user_data)
+{
+ (void)event;
+
+ struct test_media_subitems_sys *sys = user_data;
+
+ vlc_mutex_lock (&sys->lock);
+ sys->subitems_tree_added = true;
+ vlc_cond_signal (&sys->wait);
+ vlc_mutex_unlock (&sys->lock);
+}
+
+static void subitem_added(const libvlc_event_t *event, void *user_data)
+{
+#ifdef _WIN32
+#define FILE_SEPARATOR '\\'
+#else
+#define FILE_SEPARATOR '/'
+#endif
+ struct test_media_subitems_sys *sys = user_data;
+ libvlc_media_t *m = event->u.media_subitem_added.new_child;
+ assert (m);
+
+ char *mrl = libvlc_media_get_mrl (m);
+ assert (mrl);
+
+ const char *file = strrchr (mrl, FILE_SEPARATOR);
+ assert (file);
+ file++;
+ log ("subitem_added, file: %s\n", file);
+
+ for (unsigned i = 0; i < TEST_SUBITEMS_COUNT; ++i)
+ {
+ if (strcmp (test_media_subitems_list[i].file, file) == 0)
+ {
+ assert (!sys->subitems_found[i]);
+ assert (libvlc_media_get_type(m) == test_media_subitems_list[i].type);
+ sys->subitems_found[i] = true;
+ }
+ }
+ free (mrl);
+#undef FILE_SEPARATOR
+}
+
+static void test_media_subitems_media(libvlc_media_t *media)
+{
+ libvlc_media_add_option(media, ":ignore-filetypes= ");
+
+ struct test_media_subitems_sys subitems_sys, *sys = &subitems_sys;
+ sys->subitems_tree_added = false;
+ vlc_mutex_init (&sys->lock);
+ vlc_cond_init (&sys->wait);
+ memset(&sys->subitems_found, 0, sizeof(sys->subitems_found));
+
+ libvlc_event_manager_t *em = libvlc_media_event_manager (media);
+ libvlc_event_attach (em, libvlc_MediaSubItemTreeAdded, subitem_tree_added, sys);
+ libvlc_event_attach (em, libvlc_MediaSubItemAdded, subitem_added, sys);
+
+ libvlc_media_parse_async(media);
+
+ vlc_mutex_lock (&sys->lock);
+ while (!sys->subitems_tree_added)
+ vlc_cond_wait (&sys->wait, &sys->lock);
+ vlc_mutex_unlock (&sys->lock);
+
+ for (unsigned i = 0; i < TEST_SUBITEMS_COUNT; ++i)
+ {
+ log ("test if %s was added\n", test_media_subitems_list[i].file);
+ assert (sys->subitems_found[i]);
+ }
+
+ vlc_mutex_destroy (&sys->lock);
+ vlc_cond_destroy (&sys->wait);
+}
+
+static void test_media_subitems(const char** argv, int argc)
+{
+ const char *subitems_path = SRCDIR"/samples/subitems";
+
+ libvlc_instance_t *vlc = libvlc_new (argc, argv);
+ assert (vlc != NULL);
+ libvlc_media_t *media;
+
+ log ("Testing media_subitems: %s\n", subitems_path);
+ media = libvlc_media_new_path (vlc, subitems_path);
+ assert (media != NULL);
+ test_media_subitems_media (media);
+ libvlc_media_release (media);
+
+ int fd = open (subitems_path, O_RDONLY);
+ log ("Testing media_subitems: %s (fd = %d)\n", subitems_path, fd);
+ assert (fd >= 0);
+ media = libvlc_media_new_fd (vlc, fd);
+ assert (media != NULL);
+ test_media_subitems_media (media);
+ libvlc_media_release (media);
+ close (fd);
+
+
+ libvlc_release (vlc);
+}
+
int main (void)
{
test_init();
test_media_preparsed (test_defaults_args, test_defaults_nargs);
+ test_media_subitems (test_defaults_args, test_defaults_nargs);
return 0;
}
diff --git a/test/samples/subitems/directory/.keep b/test/samples/subitems/directory/.keep
new file mode 100644
index 0000000..e69de29
diff --git a/test/samples/subitems/file.jpg b/test/samples/subitems/file.jpg
new file mode 100644
index 0000000..e69de29
diff --git a/test/samples/subitems/file.mkv b/test/samples/subitems/file.mkv
new file mode 100644
index 0000000..e69de29
diff --git a/test/samples/subitems/file.mp3 b/test/samples/subitems/file.mp3
new file mode 100644
index 0000000..e69de29
diff --git a/test/samples/subitems/file.png b/test/samples/subitems/file.png
new file mode 100644
index 0000000..e69de29
diff --git a/test/samples/subitems/file.ts b/test/samples/subitems/file.ts
new file mode 100644
index 0000000..e69de29
--
2.1.4
More information about the vlc-devel
mailing list