]> git.sesse.net Git - vlc/blob - bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java
unit tests update
[vlc] / bindings / java / core / src / test / java / org / videolan / jvlc / internal / MediaListPlayerTest.java
1 /*****************************************************************************
2  * MediaListPlayerTest.java: VLC Java Bindings
3  *****************************************************************************
4  * Copyright (C) 1998-2008 the VideoLAN team
5  *
6  * Authors: Filippo Carone <filippo@carone.org>
7  *
8  *
9  * $Id $
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 package org.videolan.jvlc.internal;
27
28 import junit.framework.Assert;
29
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
34 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor;
35 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance;
36 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaList;
37 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaListPlayer;
38 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
39
40
41 public class MediaListPlayerTest
42 {
43
44     private LibVlc libvlc = LibVlc.SYNC_INSTANCE;
45
46     private LibVlcInstance libvlcInstance;
47
48     private String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath();
49
50     @Before
51     public void testSetup() throws Exception
52     {
53         libvlc_exception_t exception = new libvlc_exception_t();
54         libvlcInstance = libvlc.libvlc_new(0, new String[]{"-vvv","-I","dummy","--aout=dummy","--vout=dummy"}, exception);
55         // use the following line to use your audio card.
56         // libvlcInstance = libvlc.libvlc_new(0, new String[]{}, exception);
57     }
58
59     @After
60     public void tearDown()
61     {
62         libvlc.libvlc_release(libvlcInstance);
63     }
64
65     @Test
66     public void mediaListPlayerNewTest()
67     {
68         libvlc_exception_t exception = new libvlc_exception_t();
69         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
70         Assert.assertNotNull(mediaListPlayer);
71         Assert.assertEquals(0, exception.raised);
72     }
73
74     @Test
75     public void mediaListPlayerSetMediaListTest()
76     {
77         libvlc_exception_t exception = new libvlc_exception_t();
78         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
79         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
80         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
81         Assert.assertEquals(0, exception.raised);
82     }
83
84     @Test
85     public void mediaListPlayerSetMediaListTest2()
86     {
87         libvlc_exception_t exception = new libvlc_exception_t();
88         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
89         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
90         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
91         libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
92         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
93         Assert.assertEquals(0, exception.raised);
94     }
95
96     @Test
97     public void mediaListPlayerIsNotPlayingTest()
98     {
99         libvlc_exception_t exception = new libvlc_exception_t();
100         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
101         int result = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
102         Assert.assertEquals(0, result);
103         Assert.assertEquals(0, exception.raised);
104     }
105
106     @Test
107     public void mediaListPlayerPlayNoItemTest()
108     {
109         libvlc_exception_t exception = new libvlc_exception_t();
110         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
111         libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
112         Assert.assertEquals(1, exception.raised);
113     }
114
115     /**
116      * this fails: see https://trac.videolan.org/vlc/ticket/1527
117      */
118 //    @Test
119     public void mediaListPlayerPlay()
120     {
121         libvlc_exception_t exception = new libvlc_exception_t();
122         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
123         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
124         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
125         libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
126         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
127         libvlc.libvlc_media_list_player_play(mediaListPlayer, exception);
128         Assert.assertEquals("Exception message: " + exception.message + ".\n", 0, exception.raised);
129     }
130
131     @Test
132     public void mediaListPlayerPlayItemAtIndex() throws Exception
133     {
134         libvlc_exception_t exception = new libvlc_exception_t();
135         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
136         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
137         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
138         libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
139         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
140         libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
141         while (true)
142         {
143             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
144             if (exception.raised == 1)
145             {
146                 throw new RuntimeException("Native exception thrown");
147             }
148             if (playing == 1)
149             {
150                 break;
151             }
152             Thread.sleep(150);
153         }
154         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
155
156     }
157
158     @Test
159     public void mediaListPlayerPlayItem() throws Exception
160     {
161         libvlc_exception_t exception = new libvlc_exception_t();
162         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
163         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
164         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
165         libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
166         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
167         libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
168         Assert.assertEquals(0, exception.raised);
169         while (true)
170         {
171             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
172             if (exception.raised == 1)
173             {
174                 throw new RuntimeException("Native exception thrown");
175             }
176             if (playing == 1)
177             {
178                 break;
179             }
180             Thread.sleep(150);
181         }
182         // FIXME give stats the time to run... there's probably a race condition in misc/stats.c:259 that
183         // needs to be fixed
184         Thread.sleep(400);
185         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
186         libvlc.libvlc_media_list_player_release(mediaListPlayer);
187     }
188
189     @Test
190     public void mediaListPlayerGetStateStopped()
191     {
192         libvlc_exception_t exception = new libvlc_exception_t();
193         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
194         int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
195         Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), state);
196     }
197
198     @Test
199     public void mediaListPlayerPause() throws Exception
200     {
201         libvlc_exception_t exception = new libvlc_exception_t();
202         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
203         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
204         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
205         libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
206         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
207         libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
208         while (true)
209         {
210             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
211             if (exception.raised == 1)
212             {
213                 throw new RuntimeException("Native exception thrown");
214             }            
215             if (playing == 1)
216             {
217                 break;
218             }
219             Thread.sleep(150);
220         }
221         libvlc.libvlc_media_list_player_pause(mediaListPlayer, exception);
222         Assert.assertEquals(0, exception.raised);
223         while (true)
224         {
225             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
226             if (exception.raised == 1)
227             {
228                 throw new RuntimeException("Native exception thrown");
229             }            
230             if (playing == 0)
231             {
232                 break;
233             }
234             Thread.sleep(150);
235         }
236         int state = libvlc.libvlc_media_list_player_get_state(mediaListPlayer, exception);
237         Assert.assertEquals("Expected state: " + LibVlcState.libvlc_Paused +".\n", LibVlcState.libvlc_Paused.ordinal(), state);
238         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
239         libvlc.libvlc_media_list_player_release(mediaListPlayer);
240     }
241
242     
243     @Test
244     public void mediaListPlayerSetMediaInstance()
245     {
246         libvlc_exception_t exception = new libvlc_exception_t();
247         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
248         LibVlcMediaDescriptor md = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
249         LibVlcMediaInstance mi = libvlc.libvlc_media_instance_new_from_media_descriptor(md, exception);
250         libvlc.libvlc_media_list_player_set_media_instance(mediaListPlayer, mi, exception);
251         Assert.assertEquals(0, exception.raised);
252     }
253     
254     @Test
255     public void mediaListPlayerNextNoItems()
256     {
257         libvlc_exception_t exception = new libvlc_exception_t();
258         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
259         libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
260         Assert.assertEquals(1, exception.raised);
261     }
262     
263     /**
264      * fails, see https://trac.videolan.org/vlc/ticket/1535
265      */
266 //    @Test
267     public void mediaListPlayerNext() throws Exception
268     {
269         libvlc_exception_t exception = new libvlc_exception_t();
270         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
271         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
272         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
273         libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
274         libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
275         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
276         libvlc.libvlc_media_list_player_play_item_at_index(mediaListPlayer, 0, exception);
277         Thread.sleep(150);
278         libvlc.libvlc_media_list_player_next(mediaListPlayer, exception);
279         Assert.assertEquals(0, exception.raised);
280     }
281
282     @Test
283     public void mediaListPlayerIsPlaying() throws Exception
284     {
285         libvlc_exception_t exception = new libvlc_exception_t();
286         LibVlcMediaListPlayer mediaListPlayer = libvlc.libvlc_media_list_player_new(libvlcInstance, exception);
287         LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
288         LibVlcMediaDescriptor mediaDescriptor = libvlc.libvlc_media_descriptor_new(libvlcInstance, mrl, exception);
289         libvlc.libvlc_media_list_add_media_descriptor(mediaList, mediaDescriptor, exception);
290         libvlc.libvlc_media_list_player_set_media_list(mediaListPlayer, mediaList, exception);
291         libvlc.libvlc_media_list_player_play_item(mediaListPlayer, mediaDescriptor, exception);
292
293         while (true)
294         {
295             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
296             Assert.assertEquals(0, exception.raised);
297             if (playing == 1)
298             {
299                 break;
300             }
301             Thread.sleep(150);
302         }
303         Assert.assertEquals("Expected state: " + LibVlcState.libvlc_Playing +".\n", LibVlcState.libvlc_Playing.ordinal(), libvlc.libvlc_media_list_player_get_state(
304             mediaListPlayer,
305             exception));
306         
307         libvlc.libvlc_media_list_player_stop(mediaListPlayer, exception);
308         while (true)
309         {
310             int playing = libvlc.libvlc_media_list_player_is_playing(mediaListPlayer, exception);
311             Assert.assertEquals(0, exception.raised);
312             if (playing == 0)
313             {
314                 break;
315             }
316             Thread.sleep(150);
317         }
318         Assert.assertEquals(LibVlcState.libvlc_Stopped.ordinal(), libvlc.libvlc_media_list_player_get_state(
319             mediaListPlayer,
320             exception));
321     }
322
323
324
325 }