]> git.sesse.net Git - vlc/blob - bindings/java/core/src/test/java/org/videolan/jvlc/internal/LibVlcMediaPlayerTest.java
jvlc: wait for correct player status before releasing libvlc
[vlc] / bindings / java / core / src / test / java / org / videolan / jvlc / internal / LibVlcMediaPlayerTest.java
1 /*****************************************************************************
2  * LibVlcMediaInstanceTest.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 org.junit.Assert;
29 import org.junit.Test;
30 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor;
31 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance;
32
33
34 public class LibVlcMediaPlayerTest extends AbstractVLCInternalTest
35 {
36     @Test
37     public void mediaInstanceNew()
38     {
39         LibVlcMediaInstance instance = libvlc.libvlc_media_player_new(libvlcInstance, exception);
40         Assert.assertNotNull(instance);
41         Assert.assertEquals(0, exception.raised);
42     }
43     
44     @Test
45     public void mediaInstancePlayBad()
46     {
47         LibVlcMediaInstance instance = libvlc.libvlc_media_player_new(libvlcInstance, exception);
48         libvlc.libvlc_media_player_play(instance, exception);
49         Assert.assertEquals(1, exception.raised); // no associated media descriptor
50     }
51     
52     @Test
53     public void mediaInstancePlay()
54     {
55         LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
56         LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
57         libvlc.libvlc_media_player_play(mi, exception);
58         Assert.assertEquals(0, exception.raised);
59     }
60     
61     @Test
62     public void mediaInstancePauseBad()
63     {
64         LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
65         LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
66         libvlc.libvlc_media_player_pause(mi, exception);
67         Assert.assertEquals(1, exception.raised);
68     }
69     
70     @Test
71     public void mediaInstancePause()
72     {
73         LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
74         LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
75         libvlc.libvlc_media_player_play(mi, exception);
76         libvlc.libvlc_media_player_pause(mi, exception);
77         Assert.assertEquals(0, exception.raised);
78     }
79     
80     @Test
81     public void mediaInstanceSetPosition()
82     {
83         LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
84         LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
85         libvlc.libvlc_media_player_play(mi, exception);
86         libvlc.libvlc_media_player_set_position(mi, 0.5f, exception);
87         Assert.assertEquals(0, exception.raised);
88         float position = libvlc.libvlc_media_player_get_position(mi, exception);
89         Assert.assertTrue("Position is: " + position, position >= 0.5f);
90     }
91     
92     @Test
93     public void mediaInstanceStop()
94     {
95         LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
96         LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
97         libvlc.libvlc_media_player_stop(mi, exception);
98         Assert.assertEquals(0, exception.raised);
99     }
100     
101     @Test
102     public void mediaInstanceStop2() throws Exception
103     {
104         LibVlcMediaDescriptor md = libvlc.libvlc_media_new(libvlcInstance, mrl, exception);
105         LibVlcMediaInstance mi = libvlc.libvlc_media_player_new_from_media(md, exception);
106         libvlc.libvlc_media_player_play(mi, exception);
107         Thread.sleep(100);
108         libvlc.libvlc_media_player_stop(mi, exception);
109         Thread.sleep(500);
110         Assert.assertEquals(0, exception.raised);
111     }
112     
113 }