]> git.sesse.net Git - vlc/blob - test/libvlc/media_player.c
LibVLC core: remove exceptions
[vlc] / test / libvlc / media_player.c
1 /*
2  * media_player.c - libvlc smoke test
3  *
4  * $Id$
5  */
6
7 /**********************************************************************
8  *  Copyright (C) 2007 RĂ©mi Denis-Courmont.                           *
9  *  This program is free software; you can redistribute and/or modify *
10  *  it under the terms of the GNU General Public License as published *
11  *  by the Free Software Foundation; version 2 of the license, or (at *
12  *  your option) any later version.                                   *
13  *                                                                    *
14  *  This program is distributed in the hope that it will be useful,   *
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.              *
17  *  See the GNU General Public License for more details.              *
18  *                                                                    *
19  *  You should have received a copy of the GNU General Public License *
20  *  along with this program; if not, you can get it from:             *
21  *  http://www.gnu.org/copyleft/gpl.html                              *
22  **********************************************************************/
23
24 #include "test.h"
25
26 static void test_media_player_play_stop(const char** argv, int argc)
27 {
28     libvlc_instance_t *vlc;
29     libvlc_media_t *md;
30     libvlc_media_player_t *mi;
31     const char * file = test_default_sample;
32
33     log ("Testing play and pause of %s\n", file);
34
35     libvlc_exception_init (&ex);
36     vlc = libvlc_new (argc, argv);
37     assert (vlc != NULL);
38
39     md = libvlc_media_new (vlc, file, &ex);
40     catch ();
41
42     mi = libvlc_media_player_new_from_media (md);
43     assert (mi != NULL);
44
45     libvlc_media_release (md);
46
47     libvlc_media_player_play (mi);
48
49     /* Wait a correct state */
50     libvlc_state_t state;
51     do {
52         state = libvlc_media_player_get_state (mi);
53     } while( state != libvlc_Playing &&
54              state != libvlc_Error &&
55              state != libvlc_Ended );
56
57     assert( state == libvlc_Playing || state == libvlc_Ended );
58
59     libvlc_media_player_stop (mi);
60     libvlc_media_player_release (mi);
61     libvlc_release (vlc);
62 }
63
64 static void test_media_player_pause_stop(const char** argv, int argc)
65 {
66     libvlc_instance_t *vlc;
67     libvlc_media_t *md;
68     libvlc_media_player_t *mi;
69     const char * file = test_default_sample;
70
71     log ("Testing pause and stop of %s\n", file);
72
73     libvlc_exception_init (&ex);
74     vlc = libvlc_new (argc, argv);
75     assert (vlc != NULL);
76
77     md = libvlc_media_new (vlc, file, &ex);
78     catch ();
79
80     mi = libvlc_media_player_new_from_media (md);
81     assert (mi != NULL);
82
83     libvlc_media_release (md);
84
85     libvlc_media_player_play (mi);
86
87     log ("Waiting for playing\n");
88
89     /* Wait a correct state */
90     libvlc_state_t state;
91     do {
92         state = libvlc_media_player_get_state (mi);
93         catch ();
94     } while( state != libvlc_Playing &&
95              state != libvlc_Error &&
96              state != libvlc_Ended );
97
98     assert( state == libvlc_Playing || state == libvlc_Ended );
99
100 #if 0
101     /* This can't work because under some condition (short file, this is the case) this will be
102      * equivalent to a play() */
103     libvlc_media_player_pause (mi);
104
105     log ("Waiting for pause\n");
106
107     /* Wait a correct state */
108     do {
109         state = libvlc_media_player_get_state (mi);
110     } while( state != libvlc_Paused &&
111             state != libvlc_Error &&
112             state != libvlc_Ended );
113
114     assert( state == libvlc_Paused || state == libvlc_Ended );
115 #endif
116     
117     libvlc_media_player_stop (mi);
118     libvlc_media_player_release (mi);
119     libvlc_release (vlc);
120 }
121
122
123 int main (void)
124 {
125     test_init();
126
127     test_media_player_play_stop (test_defaults_args, test_defaults_nargs);
128     test_media_player_pause_stop (test_defaults_args, test_defaults_nargs);
129
130     return 0;
131 }