]> git.sesse.net Git - vlc/blobdiff - src/control/testapi.c
new (failing) test for libvlc
[vlc] / src / control / testapi.c
index e4388ec98b5ef58b1e17101f33da8608242d685d..e863efbc041a0fb21ab4b8da646435db5a0e89bd 100644 (file)
@@ -37,6 +37,18 @@ static libvlc_exception_t ex;
 
 #define log( ... ) printf( "testapi: " __VA_ARGS__ );
 
+/* test if we have exception */
+static bool have_exception (void)
+{
+    if (libvlc_exception_raised (&ex))
+    {
+        libvlc_exception_clear (&ex);
+        return true;
+    }
+    else
+        return false;
+}
+
 static void catch (void)
 {
     if (libvlc_exception_raised (&ex))
@@ -50,9 +62,15 @@ static void catch (void)
     libvlc_exception_clear (&ex);
 }
 
+/* Test we have */
 static void test_core (const char ** argv, int argc);
 static void test_media_list (const char ** argv, int argc);
+static void test_events (const char ** argv, int argc);
+static void test_media_player_play_stop(const char** argv, int argc);
+static void test_media_player_pause_stop(const char** argv, int argc);
+static void test_media_list_player_pause_stop(const char** argv, int argc);
 
+/* Tests implementations */
 static void test_core (const char ** argv, int argc)
 {
     libvlc_instance_t *vlc;
@@ -82,7 +100,7 @@ static void test_core (const char ** argv, int argc)
 static void test_media_list (const char ** argv, int argc)
 {
     libvlc_instance_t *vlc;
-    libvlc_media_descriptor_t *md;
+    libvlc_media_t *md1, *md2, *md3, *md4;
     libvlc_media_list_t *ml;
 
     log ("Testing media_list\n");
@@ -94,60 +112,98 @@ static void test_media_list (const char ** argv, int argc)
     ml = libvlc_media_list_new (vlc, &ex);
     catch ();
 
-    md = libvlc_media_descriptor_new (vlc, "/dev/null", &ex);
+    md1 = libvlc_media_new (vlc, "/dev/null", &ex);
+    catch ();
+    md2 = libvlc_media_new (vlc, "/dev/null", &ex);
+    catch ();
+    md3 = libvlc_media_new (vlc, "/dev/null", &ex);
     catch ();
 
-    libvlc_media_list_add_media_descriptor (ml, md, &ex);
+    libvlc_media_list_add_media (ml, md1, &ex);
     catch ();
-    libvlc_media_list_add_media_descriptor (ml, md, &ex);
+    libvlc_media_list_add_media (ml, md2, &ex);
     catch ();
 
     assert( libvlc_media_list_count (ml, &ex) == 2 );
     catch ();
 
-    libvlc_media_descriptor_release (md);
-
-    libvlc_media_list_release (ml);
+    assert( libvlc_media_list_index_of_item (ml, md1, &ex) == 0 );
+    catch ();
 
-    libvlc_release (vlc);
+    assert( libvlc_media_list_index_of_item (ml, md2, &ex) == 1 );
     catch ();
-}
 
-static void test_file_playback (const char ** argv, int argc, const char * file)
-{
-    libvlc_instance_t *vlc;
-    libvlc_media_descriptor_t *md;
-    libvlc_media_instance_t *mi;
+    libvlc_media_list_remove_index (ml, 0, &ex);  /* removing first item */
+    catch ();
 
-    log ("Testing playback of %s\n", file);
+    /* test if second item was moved on first place */
+    assert( libvlc_media_list_index_of_item (ml, md2, &ex) == 0 );
+    catch ();
 
-    libvlc_exception_init (&ex);
-    vlc = libvlc_new (argc, argv, &ex);
+    libvlc_media_list_add_media (ml, md1, &ex); /* add 2 items */
+    catch ();
+    libvlc_media_list_add_media (ml, md1, &ex);
     catch ();
 
-    md = libvlc_media_descriptor_new (vlc, file, &ex);
+    /* there should be 3 pieces */
+    assert( libvlc_media_list_count (ml, &ex) == 3 );
     catch ();
 
-    mi = libvlc_media_instance_new_from_media_descriptor (md, &ex);
+    libvlc_media_list_insert_media (ml, md3, 2, &ex);
     catch ();
-    
-    libvlc_media_descriptor_release (md);
 
-    libvlc_media_instance_play (mi, &ex);
+    /* there should be 4 pieces */
+    assert( libvlc_media_list_count (ml, &ex) == 4 );
     catch ();
 
-    /* FIXME: Do something clever */
-    sleep(1);
+    /* test inserting on right place */
+    assert( libvlc_media_list_index_of_item (ml, md3, &ex) == 2 );
+    catch ();
 
-    assert( libvlc_media_instance_get_state (mi, &ex) != libvlc_Error );
+    /* test right returning descriptor*/
+    assert ( libvlc_media_list_item_at_index (ml, 0, &ex) == md2 );
     catch ();
 
-    libvlc_media_instance_stop (mi, &ex);
+    assert ( libvlc_media_list_item_at_index (ml, 2, &ex) == md3 );
     catch ();
 
-    libvlc_media_instance_release (mi);
+    /* test if give exceptions, when it should */
+    /* have 4 items, so index 4 should give exception */
+    libvlc_media_list_remove_index (ml, 4, &ex);
+    assert (have_exception ());
+
+    libvlc_media_list_remove_index (ml, 100, &ex);
+    assert (have_exception ());
+
+    libvlc_media_list_remove_index (ml, -1, &ex);
+    assert (have_exception ());
+
+    /* getting non valid items */
+    libvlc_media_t * p_non_exist =
+        libvlc_media_list_item_at_index (ml, 4, &ex);
+    assert (have_exception ());
+
+    p_non_exist = libvlc_media_list_item_at_index (ml, 100, &ex);
+    assert (have_exception ());
+
+    p_non_exist = libvlc_media_list_item_at_index (ml, -1, &ex);
+    assert (have_exception ());
+
+    md4 = libvlc_media_new (vlc, "/dev/dsp", &ex);
     catch ();
 
+    /* try to find non inserted item */
+    int i_non_exist = 0;
+    i_non_exist = libvlc_media_list_index_of_item (ml, md4, &ex);
+    assert ( i_non_exist == -1 );
+
+    libvlc_media_release (md1);
+    libvlc_media_release (md2);
+    libvlc_media_release (md3);
+    libvlc_media_release (md4);
+
+    libvlc_media_list_release (ml);
+
     libvlc_release (vlc);
     catch ();
 }
@@ -167,7 +223,7 @@ static void test_events_callback_and_detach( const libvlc_event_t * event, void
     vlc_bool_t * callback_was_called = user_data;
     libvlc_event_manager_t *em;
 
-    em = libvlc_media_instance_event_manager (event->p_obj, &ex);
+    em = libvlc_media_player_event_manager (event->p_obj, &ex);
     catch();
 
     libvlc_event_detach (em, event->type, test_events_callback_and_detach, user_data, &ex);
@@ -186,17 +242,18 @@ static void test_event_type_reception( libvlc_event_manager_t * em, libvlc_event
 static void test_events (const char ** argv, int argc)
 {
     libvlc_instance_t *vlc;
-    libvlc_media_instance_t *mi;
+    libvlc_media_player_t *mi;
     libvlc_event_manager_t *em;
     vlc_bool_t callback_was_called;
     libvlc_exception_t ex;
     libvlc_event_type_t mi_events[] = {
-        libvlc_MediaInstancePlayed,
-        libvlc_MediaInstancePaused,
-        libvlc_MediaInstanceReachedEnd,
-        libvlc_MediaInstanceEncounteredError,
-        libvlc_MediaInstanceTimeChanged,
-        libvlc_MediaInstancePositionChanged,
+        libvlc_MediaPlayerPlayed,
+        libvlc_MediaPlayerPaused,
+        libvlc_MediaPlayerEndReached,
+        libvlc_MediaPlayerStopped,
+        libvlc_MediaPlayerEncounteredError,
+        libvlc_MediaPlayerTimeChanged,
+        libvlc_MediaPlayerPositionChanged,
     };
     int i, mi_events_len = sizeof(mi_events)/sizeof(*mi_events);
     
@@ -206,10 +263,10 @@ static void test_events (const char ** argv, int argc)
     vlc = libvlc_new (argc, argv, &ex);
     catch ();
 
-    mi = libvlc_media_instance_new (vlc, &ex);
+    mi = libvlc_media_player_new (vlc, &ex);
     catch ();
 
-    em = libvlc_media_instance_event_manager (mi, &ex);
+    em = libvlc_media_player_event_manager (mi, &ex);
 
     log ("+ Testing attaching to Media Instance\n");
 
@@ -252,7 +309,7 @@ static void test_events (const char ** argv, int argc)
         catch ();
     }
 
-    libvlc_media_instance_release (mi);
+    libvlc_media_player_release (mi);
     catch ();
 
     libvlc_release (vlc);
@@ -261,45 +318,143 @@ static void test_events (const char ** argv, int argc)
 
 static void test_media_player_play_stop(const char** argv, int argc)
 {
+#if 0
     libvlc_instance_t *vlc;
-    libvlc_media_descriptor_t *md;
-    libvlc_media_instance_t *mi;
-    const char** file = "../bindings/java/core/src/test/resources/raffa_voice.ogg";
+    libvlc_media_t *md;
+    libvlc_media_player_t *mi;
+    const char * file = "file://../bindings/java/core/src/test/resources/raffa_voice.ogg";
 
-    log ("Testing playback of %s\n", file);
+    log ("Testing play and pause of %s\n", file);
 
     libvlc_exception_init (&ex);
     vlc = libvlc_new (argc, argv, &ex);
     catch ();
 
-    md = libvlc_media_descriptor_new (vlc, file, &ex);
+    md = libvlc_media_new (vlc, file, &ex);
     catch ();
 
-    mi = libvlc_media_instance_new_from_media_descriptor (md, &ex);
+    mi = libvlc_media_player_new_from_media (md, &ex);
     catch ();
     
-    libvlc_media_descriptor_release (md);
+    libvlc_media_release (md);
 
-    libvlc_media_instance_play (mi, &ex);
+    libvlc_media_player_play (mi, &ex);
     catch ();
 
     /* FIXME: Do something clever */
     sleep(1);
 
-    assert( libvlc_media_instance_get_state (mi, &ex) != libvlc_Error );
+    assert( libvlc_media_player_get_state (mi, &ex) != libvlc_Error );
     catch ();
 
-    libvlc_media_instance_stop (mi, &ex);
+    libvlc_media_player_stop (mi, &ex);
     catch ();
 
-    libvlc_media_instance_release (mi);
+    libvlc_media_player_release (mi);
     catch ();
 
     libvlc_release (vlc);
     catch ();
+#endif
+}
+
+static void test_media_player_pause_stop(const char** argv, int argc)
+{
+    libvlc_instance_t *vlc;
+    libvlc_media_t *md;
+    libvlc_media_player_t *mi;
+    const char * file = "file://../bindings/java/core/src/test/resources/raffa_voice.ogg";
+
+    log ("Testing play and pause of %s\n", file);
+
+    libvlc_exception_init (&ex);
+    vlc = libvlc_new (argc, argv, &ex);
+    catch ();
+
+    md = libvlc_media_new (vlc, file, &ex);
+    catch ();
+
+    mi = libvlc_media_player_new_from_media (md, &ex);
+    catch ();
     
+    libvlc_media_release (md);
+
+    libvlc_media_player_play (mi, &ex);
+    catch ();
+
+    /* FIXME: Do something clever */
+    sleep(1);
+
+    assert( libvlc_media_player_get_state (mi, &ex) == libvlc_Playing );
+    catch ();
+
+    libvlc_media_player_pause (mi, &ex);
+    assert( libvlc_media_player_get_state (mi, &ex) == libvlc_Paused );
+    catch();
+
+    libvlc_media_player_stop (mi, &ex);
+    catch ();
+
+    libvlc_media_player_release (mi);
+    catch ();
+
+    libvlc_release (vlc);
+    catch ();
 }
 
+static void test_media_list_player_pause_stop(const char** argv, int argc)
+{
+    libvlc_instance_t *vlc;
+    libvlc_media_t *md;
+    libvlc_media_player_t *mi;
+    libvlc_media_list_t *ml;
+    libvlc_media_list_player_t *mlp;
+    
+    const char * file = "file://../bindings/java/core/src/test/resources/raffa_voice.ogg";
+
+    log ("Testing play and pause of %s using the media list.\n", file);
+
+    libvlc_exception_init (&ex);
+    vlc = libvlc_new (argc, argv, &ex);
+    catch ();
+
+    md = libvlc_media_new (vlc, file, &ex);
+    catch ();
+
+    ml = libvlc_media_list_new (vlc, &ex);
+    catch ();
+    
+    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_play_item( mlp, md, &ex );
+
+    /* FIXME: Do something clever */
+    sleep(1);
+
+    assert( libvlc_media_player_get_state (mi, &ex) == libvlc_Playing );
+    catch ();
+
+    libvlc_media_player_pause (mi, &ex);
+    assert( libvlc_media_player_get_state (mi, &ex) == libvlc_Paused );
+    catch();
+
+    libvlc_media_player_stop (mi, &ex);
+    catch ();
+
+    libvlc_media_player_release (mi);
+    catch ();
+
+    libvlc_release (vlc);
+    catch ();
+}
+
+
+
 int main (int argc, char *argv[])
 {
     const char *args[argc + 5];
@@ -318,11 +473,15 @@ int main (int argc, char *argv[])
 
     test_core (args, nlibvlc_args);
 
-    test_media_player_play_stop(args, nlibvlc_args);
-
     test_events (args, nlibvlc_args);
 
     test_media_list (args, nlibvlc_args);
 
+    test_media_player_play_stop(args, nlibvlc_args);
+
+    test_media_player_pause_stop(args, nlibvlc_args);
+
+    test_media_list_player_pause_stop(args, nlibvlc_args);
+    
     return 0;
 }