]> git.sesse.net Git - vlc/blob - test/libvlc/media_player.c
libvlc: Add a test for media_player_set_media().
[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_set_media(const char** argv, int argc)
27 {
28     const char * file = test_default_sample;
29
30     log ("Testing set_media\n");
31
32     libvlc_instance_t *vlc = libvlc_new (argc, argv);
33     assert (vlc != NULL);
34
35     libvlc_media_t *md = libvlc_media_new (vlc, file);
36     assert (md != NULL);
37
38     libvlc_media_player_t *mp = libvlc_media_player_new (vlc);
39     assert (mp != NULL);
40
41     libvlc_media_player_set_media (mp, md);
42
43     libvlc_media_release (md);
44
45     libvlc_media_player_play (mp);
46
47     /* Wait a correct state */
48     libvlc_state_t state;
49     do {
50         state = libvlc_media_player_get_state (mp);
51     } while(state != libvlc_Playing &&
52             state != libvlc_Error &&
53             state != libvlc_Ended );
54
55     assert(state == libvlc_Playing || state == libvlc_Ended);
56
57     libvlc_media_player_stop (mp);
58     libvlc_media_player_release (mp);
59     libvlc_release (vlc);
60 }
61
62 static void test_media_player_play_stop(const char** argv, int argc)
63 {
64     libvlc_instance_t *vlc;
65     libvlc_media_t *md;
66     libvlc_media_player_t *mi;
67     const char * file = test_default_sample;
68
69     log ("Testing play and pause of %s\n", file);
70
71     vlc = libvlc_new (argc, argv);
72     assert (vlc != NULL);
73
74     md = libvlc_media_new (vlc, file);
75     assert (md != NULL);
76
77     mi = libvlc_media_player_new_from_media (md);
78     assert (mi != NULL);
79
80     libvlc_media_release (md);
81
82     libvlc_media_player_play (mi);
83
84     /* Wait a correct state */
85     libvlc_state_t state;
86     do {
87         state = libvlc_media_player_get_state (mi);
88     } while( state != libvlc_Playing &&
89              state != libvlc_Error &&
90              state != libvlc_Ended );
91
92     assert( state == libvlc_Playing || state == libvlc_Ended );
93
94     libvlc_media_player_stop (mi);
95     libvlc_media_player_release (mi);
96     libvlc_release (vlc);
97 }
98
99 static void test_media_player_pause_stop(const char** argv, int argc)
100 {
101     libvlc_instance_t *vlc;
102     libvlc_media_t *md;
103     libvlc_media_player_t *mi;
104     const char * file = test_default_sample;
105
106     log ("Testing pause and stop of %s\n", file);
107
108     vlc = libvlc_new (argc, argv);
109     assert (vlc != NULL);
110
111     md = libvlc_media_new (vlc, file);
112     assert (md != NULL);
113
114     mi = libvlc_media_player_new_from_media (md);
115     assert (mi != NULL);
116
117     libvlc_media_release (md);
118
119     libvlc_media_player_play (mi);
120
121     log ("Waiting for playing\n");
122
123     /* Wait a correct state */
124     libvlc_state_t state;
125     do {
126         state = libvlc_media_player_get_state (mi);
127     } while( state != libvlc_Playing &&
128              state != libvlc_Error &&
129              state != libvlc_Ended );
130
131     assert( state == libvlc_Playing || state == libvlc_Ended );
132
133 #if 0
134     /* This can't work because under some condition (short file, this is the case) this will be
135      * equivalent to a play() */
136     libvlc_media_player_pause (mi);
137
138     log ("Waiting for pause\n");
139
140     /* Wait a correct state */
141     do {
142         state = libvlc_media_player_get_state (mi);
143     } while( state != libvlc_Paused &&
144             state != libvlc_Error &&
145             state != libvlc_Ended );
146
147     assert( state == libvlc_Paused || state == libvlc_Ended );
148 #endif
149
150     libvlc_media_player_stop (mi);
151     libvlc_media_player_release (mi);
152     libvlc_release (vlc);
153 }
154
155
156 int main (void)
157 {
158     test_init();
159
160     test_media_player_set_media (test_defaults_args, test_defaults_nargs);
161     test_media_player_play_stop (test_defaults_args, test_defaults_nargs);
162     test_media_player_pause_stop (test_defaults_args, test_defaults_nargs);
163
164     return 0;
165 }