From 53f6d534117da9d35f5649c1d59e44c71953ae7c Mon Sep 17 00:00:00 2001 From: Pierre d'Herbemont Date: Mon, 24 Aug 2009 17:14:02 +0200 Subject: [PATCH] test: Expanded and passing media_list_player queue item tests. --- test/Makefile.am | 7 ++- test/libvlc/libvlc_additions.h | 54 +++++++++++++++++ test/libvlc/media_list_player.c | 102 ++++++++++++++++++++++---------- 3 files changed, 132 insertions(+), 31 deletions(-) create mode 100644 test/libvlc/libvlc_additions.h diff --git a/test/Makefile.am b/test/Makefile.am index 5b4cc5d127..c1f089daae 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -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 index 0000000000..4c8fb4cbc4 --- /dev/null +++ b/test/libvlc/libvlc_additions.h @@ -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; +} + diff --git a/test/libvlc/media_list_player.c b/test/libvlc/media_list_player.c index e3701a6e36..f649a23982 100644 --- a/test/libvlc/media_list_player.c +++ b/test/libvlc/media_list_player.c @@ -27,33 +27,59 @@ #include #include -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 (); -- 2.39.5