]> git.sesse.net Git - vlc/blob - bindings/java/core/src/test/java/org/videolan/jvlc/MediaListTest.java
more unit test and functions for media list
[vlc] / bindings / java / core / src / test / java / org / videolan / jvlc / MediaListTest.java
1 /*****************************************************************************
2  * MediaListTest.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;
27
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31
32
33 public class MediaListTest
34 {
35
36     private JVLC jvlc;
37     
38     private String mrl = getClass().getResource("/raffa_voice.ogg").getFile();
39     
40     @Before
41     public void setup()
42     {
43         jvlc = new JVLC();
44     }
45     
46     @Test
47     public void mediaListAddMedia()
48     {
49         MediaList mlist = new MediaList(jvlc);
50         mlist.addMedia(mrl);
51         Assert.assertEquals(1, mlist.size());
52     }
53     
54     @Test
55     public void mediaListAddMedia2()
56     {
57         MediaList mlist = new MediaList(jvlc);
58         mlist.addMedia(mrl);
59         Assert.assertEquals(1, mlist.size());
60         mlist.addMedia(mrl);
61         Assert.assertEquals(1, mlist.size());
62         mlist.addMedia(new MediaDescriptor(jvlc, mrl));
63         Assert.assertEquals(1, mlist.size());
64         mlist.addMedia("non-existing");
65         Assert.assertEquals(2, mlist.size());
66     }
67     
68     @Test
69     public void mediaListRemoveMedia()
70     {
71         MediaList mlist = new MediaList(jvlc);
72         mlist.addMedia(mrl);
73         Assert.assertEquals(1, mlist.size());
74         mlist.removeMedia(0);
75         Assert.assertEquals(0, mlist.size());
76     }
77
78     @Test
79     public void mediaListRemoveMedia2()
80     {
81         MediaList mlist = new MediaList(jvlc);
82         mlist.addMedia(mrl);
83         Assert.assertEquals(1, mlist.size());
84         mlist.removeMedia(0);
85         Assert.assertEquals(0, mlist.size());
86         
87         mlist.addMedia(mrl);
88         mlist.removeMedia(0);
89         Assert.assertEquals(0, mlist.size());
90         
91         mlist.addMedia(new MediaDescriptor(jvlc, mrl));
92         mlist.removeMedia(0);
93         Assert.assertEquals(0, mlist.size());
94         
95         mlist.addMedia(new MediaDescriptor(jvlc, mrl));
96         mlist.removeMedia(mrl);
97         Assert.assertEquals(0, mlist.size());
98         
99         mlist.addMedia(new MediaDescriptor(jvlc, mrl));
100         mlist.removeMedia(new MediaDescriptor(jvlc, mrl));
101         Assert.assertEquals(0, mlist.size());
102     }
103     
104     @Test
105     public void mediaListRemoveNonExistingMedia()
106     {
107         MediaList mlist = new MediaList(jvlc);
108         boolean result = mlist.removeMedia(3);
109         Assert.assertFalse(result);
110     }
111     
112     @Test
113     public void mediaListIndexOfNonExistingMediaDescriptor()
114     {
115         MediaList mlist = new MediaList(jvlc);
116         MediaDescriptor md = new MediaDescriptor(jvlc, "dummy");
117         int result = mlist.indexOf(md);
118         Assert.assertEquals(-1, result);
119     }
120     
121     @Test(expected = IndexOutOfBoundsException.class)
122     public void mediaListGetMediaDesciptorAtInvalidIndex()
123     {
124         MediaList mlist = new MediaList(jvlc);
125         mlist.getMediaDescriptorAtIndex(5);
126     }
127     
128     @Test(expected = IndexOutOfBoundsException.class)
129     public void mediaListGetMediaDesciptorAtInvalidIndex2()
130     {
131         MediaList mlist = new MediaList(jvlc);
132         mlist.getMediaDescriptorAtIndex(-5);
133     }
134     
135     @Test(expected = IndexOutOfBoundsException.class)
136     public void mediaListGetMediaDesciptorAtInvalidIndex3()
137     {
138         MediaList mlist = new MediaList(jvlc);
139         mlist.getMediaDescriptorAtIndex(0);
140     }
141 }