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