test: Expanded and passing media_list_player queue item tests.
authorPierre d'Herbemont <pdherbemont@free.fr>
Mon, 24 Aug 2009 15:14:02 +0000 (17:14 +0200)
committerPierre d'Herbemont <pdherbemont@free.fr>
Mon, 24 Aug 2009 15:36:00 +0000 (17:36 +0200)
test/Makefile.am
test/libvlc/libvlc_additions.h [new file with mode: 0644]
test/libvlc/media_list_player.c

index 5b4cc5d..c1f089d 100644 (file)
@@ -4,6 +4,11 @@
 
 AUTOMAKE_OPTIONS = subdir-objects
 
+extra_check_verbose = $(extra_check_verbose_$(V))
+extra_check_verbose_ = $(extra_check_flags__$(AM_DEFAULT_VERBOSITY))
+extra_check_verbose_0 = @echo TEST $@
+extra_check_verbose__0 = $(extra_check_verbose_0)
+
 ###############################################################################
 # Unit/regression test
 ###############################################################################
@@ -26,7 +31,7 @@ EXTRA_PROGRAMS = \
 #check_DATA = samples/test.sample samples/meta.sample
 EXTRA_DIST = samples/empty.voc
 
-check_HEADERS = libvlc/test.h
+check_HEADERS = libvlc/test.h libvlc/libvlc_additions.h
 
 TESTS = $(check_PROGRAMS)
 
diff --git a/test/libvlc/libvlc_additions.h b/test/libvlc/libvlc_additions.h
new file mode 100644 (file)
index 0000000..4c8fb4c
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * libvlc_additions.c - Some helper method that should probably go into libvlc
+ */
+
+/**********************************************************************
+ *  Copyright (C) 2007 RĂ©mi Denis-Courmont.                           *
+ *  This program is free software; you can redistribute and/or modify *
+ *  it under the terms of the GNU General Public License as published *
+ *  by the Free Software Foundation; version 2 of the license, or (at *
+ *  your option) any later version.                                   *
+ *                                                                    *
+ *  This program is distributed in the hope that it will be useful,   *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              *
+ *  See the GNU General Public License for more details.              *
+ *                                                                    *
+ *  You should have received a copy of the GNU General Public License *
+ *  along with this program; if not, you can get it from:             *
+ *  http://www.gnu.org/copyleft/gpl.html                              *
+ **********************************************************************/
+
+static void* media_list_add_file_path(libvlc_instance_t *vlc, libvlc_media_list_t *ml, const char * file_path)
+{
+    libvlc_media_t *md = libvlc_media_new (vlc, file_path, &ex);
+    catch ();
+    
+    libvlc_media_list_add_media (ml, md, &ex);
+    catch ();
+    
+    libvlc_media_release (md);
+    return md;
+}
+
+static libvlc_media_list_player_t *media_list_player_with_root_media(libvlc_instance_t *vlc, libvlc_media_t *m)
+{
+    libvlc_media_list_t *ml;
+    libvlc_media_list_player_t *mlp;
+    
+    libvlc_exception_init (&ex);
+    
+    ml = libvlc_media_list_new (vlc, &ex);
+    catch ();
+    
+    mlp = libvlc_media_list_player_new (vlc, &ex);
+    
+    libvlc_media_list_add_media(ml, m, &ex);
+    catch ();
+    
+    libvlc_media_list_player_set_media_list(mlp, ml, &ex);
+    catch ();
+    
+    return mlp;
+}
+
index e3701a6..f649a23 100644 (file)
 #include <vlc_common.h>
 #include <vlc_mtime.h>
 
-static void* media_list_add_file_path(libvlc_instance_t *vlc, libvlc_media_list_t *ml, const char * file_path)
-{
-    libvlc_media_t *md = libvlc_media_new (vlc, file_path, &ex);
-    catch ();
+#include "libvlc_additions.h"
 
-    libvlc_media_list_add_media (ml, md, &ex);
-    catch ();
+struct check_items_order_data {
+    bool done_playing;
+    unsigned count;
+    unsigned index;
+    void * items[16];
+};
 
-    libvlc_media_release (md);
-    return md;
+static inline void check_data_init(struct check_items_order_data *check)
+{
+    check->index = 0;
+    check->count = 0;
+    check->done_playing = false;
+}
+
+static inline void queue_expected_item(struct check_items_order_data *check, void *item)
+{
+    assert(check->count < 16);
+    check->items[check->count] = item;
+    check->count++;
 }
 
-static bool done_playing = false;
-static const unsigned items_count = 4;
-static void * items[4];
-static unsigned current_index = 0;
+static inline void wait_queued_items(struct check_items_order_data *check)
+{
+    // Wait dummily for check_items_order_callback() to flag 'done_playing':
+    while (!check->done_playing)
+        msleep(100000);
+}
 
-static void next_item_callback(const libvlc_event_t * p_event, void * user_data)
+static void check_items_order_callback(const libvlc_event_t * p_event, void * user_data)
 {
-    (void)user_data;
+    struct check_items_order_data *checks = user_data;
     libvlc_media_t *md = p_event->u.media_list_player_next_item_set.item;
-    current_index++;
-    assert(current_index < items_count);    
-    assert(items[current_index] == md);
-    log ("Item %d was correctly queued\n", current_index);
-    if (current_index == (items_count - 1))
-        done_playing = true;
+    assert(checks->index < checks->count);
+    if (checks->items[checks->index] != md)
+    {
+        char *title = libvlc_media_get_meta(md, libvlc_meta_Title, NULL);
+        log ("Got items %s\n", title);
+        free(title);
+    }
+    assert(checks->items[checks->index] == md);
+    
+    char *title = libvlc_media_get_meta(md, libvlc_meta_Title, NULL);
+    log ("Item %d '%s' was correctly queued\n", checks->index, title);
+    free(title);
+    
+    if (checks->index == (checks->count - 1))
+    {
+        log ("Done playing with success\n");
+        checks->done_playing = true;
+    }
+    checks->index++;
 }
 
 static void test_media_list_player_items_queue(const char** argv, int argc)
@@ -82,26 +108,42 @@ static void test_media_list_player_items_queue(const char** argv, int argc)
     
     libvlc_media_list_add_media (ml, md, &ex);
     catch ();
-    
-    items[0] = md;
+
+    static struct check_items_order_data check;
+    check_data_init(&check);
+    queue_expected_item(&check, md);
 
     // Add three more media
-    items[1] = media_list_add_file_path (vlc, ml, file);
-    items[2] = media_list_add_file_path (vlc, ml, file);
-    items[3] = media_list_add_file_path (vlc, ml, file);
+    queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
+    queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
+    queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
+
+    // Add a node
+    libvlc_media_t *node = libvlc_media_new_as_node(vlc, "node", &ex);
+    catch ();
+    libvlc_media_list_add_media(ml, node, &ex);
+    catch ();
+    queue_expected_item(&check, node);
+
+    // Add items to that node
+    libvlc_media_list_t *subitems = libvlc_media_subitems(node, &ex);
+    catch ();
+    queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
+    queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
+    queue_expected_item(&check, media_list_add_file_path(vlc, subitems, file));
+    libvlc_media_list_release(subitems);
     
     libvlc_media_list_player_set_media_list (mlp, ml, &ex);
 
     libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp);
-    libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet, next_item_callback, NULL, &ex);
+    libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet, check_items_order_callback, &check, &ex);
     catch ();
 
-    libvlc_media_list_player_play_item (mlp, md, &ex);
+    libvlc_media_list_player_play(mlp, &ex);
     catch ();
 
-    // Wait dummily for next_item_callback() to flag 'done_playing':
-    while (!done_playing)
-        msleep(100000);
+    // Wait until all item are read
+    wait_queued_items(&check);
 
     libvlc_media_list_player_stop (mlp, &ex);
     catch ();