]> git.sesse.net Git - vlc/blob - test/libvlc/media_player.c
test: Move testapi.c to /test and use a sample file that is not ogg for basic testing.
[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, &ex);
37     catch ();
38
39     md = libvlc_media_new (vlc, file, &ex);
40     catch ();
41
42     mi = libvlc_media_player_new_from_media (md, &ex);
43     catch ();
44
45     libvlc_media_release (md);
46
47     libvlc_media_player_play (mi, &ex);
48     catch ();
49
50     /* FIXME: Do something clever */
51     sleep(1);
52
53     assert( libvlc_media_player_get_state (mi, &ex) != libvlc_Error );
54     catch ();
55
56     libvlc_media_player_stop (mi, &ex);
57     catch ();
58
59     libvlc_media_player_release (mi);
60     catch ();
61
62     libvlc_release (vlc);
63     catch ();
64 }
65
66 static void test_media_player_pause_stop(const char** argv, int argc)
67 {
68     libvlc_instance_t *vlc;
69     libvlc_media_t *md;
70     libvlc_media_player_t *mi;
71     const char * file = test_default_sample;
72
73     log ("Testing play and pause of %s\n", file);
74
75     libvlc_exception_init (&ex);
76     vlc = libvlc_new (argc, argv, &ex);
77     catch ();
78
79     md = libvlc_media_new (vlc, file, &ex);
80     catch ();
81
82     mi = libvlc_media_player_new_from_media (md, &ex);
83     catch ();
84
85     libvlc_media_release (md);
86
87     libvlc_media_player_play (mi, &ex);
88     catch ();
89
90     /* FIXME: Do something clever */
91     sleep(1);
92
93     assert( libvlc_media_player_get_state (mi, &ex) == libvlc_Playing );
94     catch ();
95
96     libvlc_media_player_pause (mi, &ex);
97     assert( libvlc_media_player_get_state (mi, &ex) == libvlc_Paused );
98     catch();
99
100     libvlc_media_player_stop (mi, &ex);
101     catch ();
102
103     libvlc_media_player_release (mi);
104     catch ();
105
106     libvlc_release (vlc);
107     catch ();
108 }
109
110
111 int main (void)
112 {
113     test_init();
114
115     test_media_player_play_stop (test_defaults_args, test_defaults_nargs);
116     test_media_player_pause_stop (test_defaults_args, test_defaults_nargs);
117
118     return 0;
119 }