Commit 53f6d534 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

test: Expanded and passing media_list_player queue item tests.

parent bd90c7fd
...@@ -4,6 +4,11 @@ ...@@ -4,6 +4,11 @@
AUTOMAKE_OPTIONS = subdir-objects 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 # Unit/regression test
############################################################################### ###############################################################################
...@@ -26,7 +31,7 @@ EXTRA_PROGRAMS = \ ...@@ -26,7 +31,7 @@ EXTRA_PROGRAMS = \
#check_DATA = samples/test.sample samples/meta.sample #check_DATA = samples/test.sample samples/meta.sample
EXTRA_DIST = samples/empty.voc EXTRA_DIST = samples/empty.voc
check_HEADERS = libvlc/test.h check_HEADERS = libvlc/test.h libvlc/libvlc_additions.h
TESTS = $(check_PROGRAMS) TESTS = $(check_PROGRAMS)
......
/*
* 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;
}
...@@ -27,33 +27,59 @@ ...@@ -27,33 +27,59 @@
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_mtime.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) #include "libvlc_additions.h"
{
libvlc_media_t *md = libvlc_media_new (vlc, file_path, &ex);
catch ();
libvlc_media_list_add_media (ml, md, &ex); struct check_items_order_data {
catch (); bool done_playing;
unsigned count;
unsigned index;
void * items[16];
};
libvlc_media_release (md); static inline void check_data_init(struct check_items_order_data *check)
return md; {
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 inline void wait_queued_items(struct check_items_order_data *check)
static const unsigned items_count = 4; {
static void * items[4]; // Wait dummily for check_items_order_callback() to flag 'done_playing':
static unsigned current_index = 0; 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; libvlc_media_t *md = p_event->u.media_list_player_next_item_set.item;
current_index++; assert(checks->index < checks->count);
assert(current_index < items_count); if (checks->items[checks->index] != md)
assert(items[current_index] == md); {
log ("Item %d was correctly queued\n", current_index); char *title = libvlc_media_get_meta(md, libvlc_meta_Title, NULL);
if (current_index == (items_count - 1)) log ("Got items %s\n", title);
done_playing = true; 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) 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) ...@@ -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); libvlc_media_list_add_media (ml, md, &ex);
catch (); catch ();
items[0] = md; static struct check_items_order_data check;
check_data_init(&check);
queue_expected_item(&check, md);
// Add three more media // Add three more media
items[1] = media_list_add_file_path (vlc, ml, file); queue_expected_item(&check, media_list_add_file_path (vlc, ml, file));
items[2] = media_list_add_file_path (vlc, ml, file); queue_expected_item(&check, 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));
// 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_media_list_player_set_media_list (mlp, ml, &ex);
libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp); 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 (); catch ();
libvlc_media_list_player_play_item (mlp, md, &ex); libvlc_media_list_player_play(mlp, &ex);
catch (); catch ();
// Wait dummily for next_item_callback() to flag 'done_playing': // Wait until all item are read
while (!done_playing) wait_queued_items(&check);
msleep(100000);
libvlc_media_list_player_stop (mlp, &ex); libvlc_media_list_player_stop (mlp, &ex);
catch (); catch ();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment