]> git.sesse.net Git - vlc/blobdiff - test/libvlc/media_list_player.c
LibVLC core: remove exceptions
[vlc] / test / libvlc / media_list_player.c
index f649a23982b39524bf3b3fffa3103bb23f8258bb..7e0717ac3577c534300ca81c055cb12dcebee00d 100644 (file)
 
 #include "libvlc_additions.h"
 
+/*
+    HACK - FIX ME
+    This allows for the direct addition of subitems in the playback options test.
+    This would not be necessary if there were an add subitems function.
+*/
+#include "../../src/control/media_internal.h"
+
 struct check_items_order_data {
     bool done_playing;
     unsigned count;
@@ -64,16 +71,16 @@ static void check_items_order_callback(const libvlc_event_t * p_event, void * us
     assert(checks->index < checks->count);
     if (checks->items[checks->index] != md)
     {
-        char *title = libvlc_media_get_meta(md, libvlc_meta_Title, NULL);
+        char *title = libvlc_media_get_meta(md, libvlc_meta_Title);
         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);
+
+    char *title = libvlc_media_get_meta(md, libvlc_meta_Title);
     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");
@@ -88,24 +95,24 @@ static void test_media_list_player_items_queue(const char** argv, int argc)
     libvlc_media_t *md;
     libvlc_media_list_t *ml;
     libvlc_media_list_player_t *mlp;
-    
+
     const char * file = test_default_sample;
-    
+
     log ("Testing media player item queue-ing\n");
-    
+
     libvlc_exception_init (&ex);
-    vlc = libvlc_new (argc, argv, &ex);
-    catch ();
-    
+    vlc = libvlc_new (argc, argv);
+    assert (vlc != NULL);
+
     md = libvlc_media_new (vlc, file, &ex);
     catch ();
-    
-    ml = libvlc_media_list_new (vlc, &ex);
-    catch ();
-    
+
+    ml = libvlc_media_list_new (vlc);
+    assert (ml != NULL);
+
     mlp = libvlc_media_list_player_new (vlc, &ex);
     catch ();
-    
+
     libvlc_media_list_add_media (ml, md, &ex);
     catch ();
 
@@ -126,18 +133,18 @@ static void test_media_list_player_items_queue(const char** argv, int argc)
     queue_expected_item(&check, node);
 
     // Add items to that node
-    libvlc_media_list_t *subitems = libvlc_media_subitems(node, &ex);
-    catch ();
+    libvlc_media_list_t *subitems = libvlc_media_subitems(node);
     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);
 
     libvlc_event_manager_t * em = libvlc_media_list_player_event_manager(mlp);
-    libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet, check_items_order_callback, &check, &ex);
-    catch ();
+    int val = libvlc_event_attach(em, libvlc_MediaListPlayerNextItemSet,
+                                  check_items_order_callback, &check);
+    assert(val == 0);
 
     libvlc_media_list_player_play(mlp, &ex);
     catch ();
@@ -145,14 +152,89 @@ static void test_media_list_player_items_queue(const char** argv, int argc)
     // Wait until all item are read
     wait_queued_items(&check);
 
-    libvlc_media_list_player_stop (mlp, &ex);
-    catch ();
+    libvlc_media_list_player_stop (mlp);
+    while (libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
 
     libvlc_media_list_player_release (mlp);
-    catch ();
-    
     libvlc_release (vlc);
+}
+
+static void test_media_list_player_previous(const char** argv, int argc)
+{
+    libvlc_instance_t *vlc;
+    libvlc_media_t *md;
+    libvlc_media_list_t *ml;
+    libvlc_media_list_player_t *mlp;
+
+    const char * file = test_default_sample;
+
+    log ("Testing media player previous()\n");
+
+    libvlc_exception_init (&ex);
+    vlc = libvlc_new (argc, argv);
+    assert (vlc != NULL);
+
+    md = libvlc_media_new (vlc, file, &ex);
+    catch ();
+
+    ml = libvlc_media_list_new (vlc);
+    assert (ml != NULL);
+
+    mlp = libvlc_media_list_player_new (vlc, &ex);
+    catch ();
+
+    libvlc_media_list_add_media (ml, md, &ex);
     catch ();
+
+    // Add three media
+    media_list_add_file_path (vlc, ml, file);
+    media_list_add_file_path (vlc, ml, file);
+    media_list_add_file_path (vlc, ml, file);
+
+    libvlc_media_list_player_set_media_list (mlp, ml);
+
+    libvlc_media_list_player_play_item (mlp, md, &ex);
+    catch ();
+
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_release (md);
+
+    libvlc_media_list_player_previous (mlp, &ex);
+    catch ();
+
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_list_player_pause (mlp, &ex);
+    catch();
+
+    libvlc_media_list_player_previous (mlp, &ex);
+    catch ();
+
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_list_player_stop (mlp);
+
+    while (libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_list_player_previous (mlp, &ex);
+    catch ();
+
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_list_player_stop (mlp);
+
+    while (libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_list_player_release (mlp);
+    libvlc_release (vlc);
 }
 
 static void test_media_list_player_next(const char** argv, int argc)
@@ -161,21 +243,21 @@ static void test_media_list_player_next(const char** argv, int argc)
     libvlc_media_t *md;
     libvlc_media_list_t *ml;
     libvlc_media_list_player_t *mlp;
-    
+
     const char * file = test_default_sample;
-    
+
     log ("Testing media player next()\n");
-    
+
     libvlc_exception_init (&ex);
-    vlc = libvlc_new (argc, argv, &ex);
-    catch ();
-    
+    vlc = libvlc_new (argc, argv);
+    assert (vlc != NULL);
+
     md = libvlc_media_new (vlc, file, &ex);
     catch ();
-    
-    ml = libvlc_media_list_new (vlc, &ex);
-    catch ();
-    
+
+    ml = libvlc_media_list_new (vlc);
+    assert (ml != NULL);
+
     mlp = libvlc_media_list_player_new (vlc, &ex);
     catch ();
 
@@ -187,39 +269,48 @@ static void test_media_list_player_next(const char** argv, int argc)
     media_list_add_file_path (vlc, ml, file);
     media_list_add_file_path (vlc, ml, file);
 
-    libvlc_media_list_player_set_media_list (mlp, ml, &ex);
-    
+    libvlc_media_list_player_set_media_list (mlp, ml);
+
     libvlc_media_list_player_play_item (mlp, md, &ex);
     catch ();
 
     libvlc_media_release (md);
 
-    msleep(100000);
-    
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
     libvlc_media_list_player_next (mlp, &ex);
     catch ();
 
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
     libvlc_media_list_player_pause (mlp, &ex);
     catch();
 
-    msleep(100000);
-    
     libvlc_media_list_player_next (mlp, &ex);
     catch ();
-    
-    libvlc_media_list_player_stop (mlp, &ex);
-    catch ();
 
-    msleep(100000);
-    
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_list_player_stop (mlp);
+
+    while (libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
     libvlc_media_list_player_next (mlp, &ex);
     catch ();
-        
+
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_list_player_stop (mlp);
+    while (libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
     libvlc_media_list_player_release (mlp);
-    catch ();
-    
     libvlc_release (vlc);
-    catch ();
 }
 
 static void test_media_list_player_pause_stop(const char** argv, int argc)
@@ -234,38 +325,39 @@ static void test_media_list_player_pause_stop(const char** argv, int argc)
     log ("Testing play and pause of %s using the media list.\n", file);
 
     libvlc_exception_init (&ex);
-    vlc = libvlc_new (argc, argv, &ex);
-    catch ();
+    vlc = libvlc_new (argc, argv);
+    assert (vlc != NULL);
 
     md = libvlc_media_new (vlc, file, &ex);
     catch ();
 
-    ml = libvlc_media_list_new (vlc, &ex);
-    catch ();
+    ml = libvlc_media_list_new (vlc);
+    assert (ml != NULL);
 
     mlp = libvlc_media_list_player_new (vlc, &ex);
 
     libvlc_media_list_add_media( ml, md, &ex );
     catch ();
 
-    libvlc_media_list_player_set_media_list( mlp, ml, &ex );
+    libvlc_media_list_player_set_media_list( mlp, ml );
 
     libvlc_media_list_player_play_item( mlp, md, &ex );
     catch ();
 
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
     libvlc_media_list_player_pause (mlp, &ex);
     catch();
 
-    libvlc_media_list_player_stop (mlp, &ex);
-    catch ();
+    libvlc_media_list_player_stop (mlp);
 
-    libvlc_media_release (md);
+    while (libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
 
+    libvlc_media_release (md);
     libvlc_media_list_player_release (mlp);
-    catch ();
-
     libvlc_release (vlc);
-    catch ();
 }
 
 static void test_media_list_player_play_item_at_index(const char** argv, int argc)
@@ -281,13 +373,13 @@ static void test_media_list_player_play_item_at_index(const char** argv, int arg
 
     libvlc_exception_init (&ex);
     vlc = libvlc_new (argc, argv, &ex);
-    catch ();
+    assert (vlc != NULL);
 
     md = libvlc_media_new (vlc, file, &ex);
     catch ();
 
-    ml = libvlc_media_list_new (vlc, &ex);
-    catch ();
+    ml = libvlc_media_list_new (vlc);
+    assert (ml != NULL);
 
     mlp = libvlc_media_list_player_new (vlc, &ex);
 
@@ -297,22 +389,187 @@ static void test_media_list_player_play_item_at_index(const char** argv, int arg
         catch ();
     }
 
-    libvlc_media_list_player_set_media_list( mlp, ml, &ex );
+    libvlc_media_list_player_set_media_list( mlp, ml );
 
     libvlc_media_list_player_play_item_at_index( mlp, 0, &ex );
     catch ();
 
-    libvlc_media_list_player_stop (mlp, &ex);
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_list_player_stop (mlp);
+
+    while (libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_release (md);
+    libvlc_media_list_player_release (mlp);
+    libvlc_release (vlc);
+}
+
+static void test_media_list_player_playback_options (const char** argv, int argc)
+{
+    libvlc_instance_t *vlc;
+    libvlc_media_t *md;
+    libvlc_media_t *md2;
+    libvlc_media_t *md3;
+    libvlc_media_t *md4;
+    libvlc_media_t *md5;
+    libvlc_media_list_t *ml;
+    libvlc_media_list_t *ml2;
+    libvlc_media_list_t *ml3;
+    libvlc_media_list_t *ml4;
+    libvlc_media_list_t *ml5;
+    libvlc_media_list_t *ml6;
+    libvlc_media_list_player_t *mlp;
+
+    const char * file = test_default_sample;
+
+    log ("Testing media player playback options()\n");
+
+    libvlc_exception_init (&ex);
+    vlc = libvlc_new (argc, argv);
+    assert (vlc != NULL);
+
+    /*
+     *   Create the following media tree:
+     *
+     *  ml1:            0 ---- 1 ---- 2
+     *                 /       |       \
+     *  ml2&4:      0 -- 1     |   0 -- 1 -- 2
+     *                         |
+     *  ml3:    0 -- 1 -- 2 -- 3 -- 4 -- 5 -- 6
+     *                    |                   |
+     *  ml5&6:            0                 0 -- 1
+     */
+
+    md = libvlc_media_new (vlc, file, &ex);
+    catch ();
+
+    md2 = libvlc_media_new (vlc, file, &ex);
     catch ();
 
+    md3 = libvlc_media_new (vlc, file, &ex);
+    catch ();
+
+    md4 = libvlc_media_new (vlc, file, &ex);
+    catch ();
+
+    md5 = libvlc_media_new (vlc, file, &ex);
+    catch ();
+
+    ml = libvlc_media_list_new (vlc);
+    assert (ml != NULL);
+
+    ml2 = libvlc_media_list_new (vlc);
+    assert (ml2 != NULL);
+
+    ml3 = libvlc_media_list_new (vlc);
+    assert (ml3 != NULL);
+
+    ml4 = libvlc_media_list_new (vlc);
+    assert (ml4 != NULL);
+
+    ml5 = libvlc_media_list_new (vlc);
+    assert (ml5 != NULL);
+
+    ml6 = libvlc_media_list_new (vlc);
+    assert (ml6 != NULL);
+
+    media_list_add_file_path (vlc, ml2, file);
+    media_list_add_file_path (vlc, ml2, file);
+
+    media_list_add_file_path (vlc, ml3, file);
+    media_list_add_file_path (vlc, ml3, file);
+    libvlc_media_list_add_media (ml3, md4, &ex);
+    catch ();
+    media_list_add_file_path (vlc, ml3, file);
+    media_list_add_file_path (vlc, ml3, file);
+    media_list_add_file_path (vlc, ml3, file);
+    libvlc_media_list_add_media (ml3, md5, &ex);
+    catch ();
+
+    media_list_add_file_path (vlc, ml4, file);
+    media_list_add_file_path (vlc, ml4, file);
+    media_list_add_file_path (vlc, ml4, file);
+
+    media_list_add_file_path (vlc, ml5, file);
+
+    media_list_add_file_path (vlc, ml6, file);
+    media_list_add_file_path (vlc, ml6, file);
+
+    md->p_subitems = ml2;
+    md2->p_subitems = ml3;
+    md3->p_subitems = ml4;
+    md4->p_subitems = ml5;
+    md5->p_subitems = ml6;
+
+    libvlc_media_list_add_media (ml, md, &ex);
+    catch ();
+
+    libvlc_media_list_add_media (ml, md2, &ex);
+    catch ();
+
+    libvlc_media_list_add_media (ml, md3, &ex);
+    catch ();
+
+    mlp = libvlc_media_list_player_new (vlc, &ex);
+    catch ();
+
+    libvlc_media_list_player_set_media_list (mlp, ml);
+
+    // Test default playback mode
+    libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_default);
+
+    libvlc_media_list_player_play_item (mlp, md, &ex);
+    catch ();
+
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
     libvlc_media_release (md);
+    libvlc_media_release (md2);
+    libvlc_media_release (md3);
+    libvlc_media_release (md4);
+    libvlc_media_release (md5);
+
+    libvlc_media_list_player_stop (mlp);
+
+    while (libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    // Test looping playback mode
+    log ("Testing media player playback option - Loop\n");
+    libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_loop);
+
+    libvlc_media_list_player_play_item (mlp, md, &ex);
     catch ();
 
-    libvlc_media_list_player_release (mlp);
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_list_player_stop (mlp);
+
+    while (libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    // Test repeat playback mode
+    log ("Testing media player playback option - Repeat\n");
+    libvlc_media_list_player_set_playback_mode(mlp, libvlc_playback_mode_repeat);
+
+    libvlc_media_list_player_play_item (mlp, md, &ex);
     catch ();
 
+    while (!libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_list_player_stop (mlp);
+
+    while (libvlc_media_list_player_is_playing (mlp))
+        sched_yield();
+
+    libvlc_media_list_player_release (mlp);
     libvlc_release (vlc);
-    catch ();
 }
 
 
@@ -322,7 +579,9 @@ int main (void)
 
     test_media_list_player_pause_stop (test_defaults_args, test_defaults_nargs);
     test_media_list_player_play_item_at_index (test_defaults_args, test_defaults_nargs);
+    test_media_list_player_previous (test_defaults_args, test_defaults_nargs);
     test_media_list_player_next (test_defaults_args, test_defaults_nargs);
     test_media_list_player_items_queue (test_defaults_args, test_defaults_nargs);
+    test_media_list_player_playback_options (test_defaults_args, test_defaults_nargs);
     return 0;
 }