]> git.sesse.net Git - vlc/blobdiff - test/libvlc/media_player.c
LibVLC core: remove exceptions
[vlc] / test / libvlc / media_player.c
index a09a0192be6f932fb4493b7f42118dabf082e16b..2137fa7210cc8176dea43a2d91f15486026a73d1 100644 (file)
@@ -33,34 +33,32 @@ static void test_media_player_play_stop(const char** argv, int argc)
     log ("Testing play and pause of %s\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 ();
 
-    mi = libvlc_media_player_new_from_media (md, &ex);
-    catch ();
+    mi = libvlc_media_player_new_from_media (md);
+    assert (mi != NULL);
 
     libvlc_media_release (md);
 
-    libvlc_media_player_play (mi, &ex);
-    catch ();
+    libvlc_media_player_play (mi);
 
-    /* FIXME: Do something clever */
-    sleep(1);
-
-    assert( libvlc_media_player_get_state (mi, &ex) != libvlc_Error );
-    catch ();
+    /* Wait a correct state */
+    libvlc_state_t state;
+    do {
+        state = libvlc_media_player_get_state (mi);
+    } while( state != libvlc_Playing &&
+             state != libvlc_Error &&
+             state != libvlc_Ended );
 
-    libvlc_media_player_stop (mi, &ex);
-    catch ();
+    assert( state == libvlc_Playing || state == libvlc_Ended );
 
+    libvlc_media_player_stop (mi);
     libvlc_media_player_release (mi);
-    catch ();
-
     libvlc_release (vlc);
-    catch ();
 }
 
 static void test_media_player_pause_stop(const char** argv, int argc)
@@ -70,41 +68,55 @@ static void test_media_player_pause_stop(const char** argv, int argc)
     libvlc_media_player_t *mi;
     const char * file = test_default_sample;
 
-    log ("Testing play and pause of %s\n", file);
+    log ("Testing pause and stop of %s\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 ();
 
-    mi = libvlc_media_player_new_from_media (md, &ex);
-    catch ();
+    mi = libvlc_media_player_new_from_media (md);
+    assert (mi != NULL);
 
     libvlc_media_release (md);
 
-    libvlc_media_player_play (mi, &ex);
-    catch ();
+    libvlc_media_player_play (mi);
 
-    /* FIXME: Do something clever */
-    sleep(1);
+    log ("Waiting for playing\n");
 
-    assert( libvlc_media_player_get_state (mi, &ex) == libvlc_Playing );
-    catch ();
+    /* Wait a correct state */
+    libvlc_state_t state;
+    do {
+        state = libvlc_media_player_get_state (mi);
+        catch ();
+    } while( state != libvlc_Playing &&
+             state != libvlc_Error &&
+             state != libvlc_Ended );
 
-    libvlc_media_player_pause (mi, &ex);
-    assert( libvlc_media_player_get_state (mi, &ex) == libvlc_Paused );
-    catch();
+    assert( state == libvlc_Playing || state == libvlc_Ended );
 
-    libvlc_media_player_stop (mi, &ex);
-    catch ();
+#if 0
+    /* This can't work because under some condition (short file, this is the case) this will be
+     * equivalent to a play() */
+    libvlc_media_player_pause (mi);
 
-    libvlc_media_player_release (mi);
-    catch ();
+    log ("Waiting for pause\n");
+
+    /* Wait a correct state */
+    do {
+        state = libvlc_media_player_get_state (mi);
+    } while( state != libvlc_Paused &&
+            state != libvlc_Error &&
+            state != libvlc_Ended );
 
+    assert( state == libvlc_Paused || state == libvlc_Ended );
+#endif
+    
+    libvlc_media_player_stop (mi);
+    libvlc_media_player_release (mi);
     libvlc_release (vlc);
-    catch ();
 }