]> git.sesse.net Git - vlc/commitdiff
more unit tests
authorFilippo Carone <littlejohn@videolan.org>
Thu, 20 Mar 2008 23:32:47 +0000 (00:32 +0100)
committerFilippo Carone <littlejohn@videolan.org>
Thu, 20 Mar 2008 23:36:46 +0000 (00:36 +0100)
bindings/java/core/src/main/java/org/videolan/jvlc/MediaDescriptor.java
bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java
bindings/java/core/src/test/java/org/videolan/jvlc/JVLCTest.java [new file with mode: 0644]
bindings/java/core/src/test/java/org/videolan/jvlc/MediaListTest.java [new file with mode: 0644]
bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListTest.java

index a248d580160bfe27658bc12821c15f341cd6500e..961d8d96dde9548fa09b11f481a37cb781bf29c6 100644 (file)
@@ -84,6 +84,7 @@ public class MediaDescriptor
     }
 
     
+    
     /**
      * Returns the instance.
      * @return the instance
index bef31c4247015d0509d40e7f5b1f6e82b27c3a1f..979222cab0df9690ec098be37cda22fad4748273 100644 (file)
 
 package org.videolan.jvlc;
 
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+
 import org.videolan.jvlc.internal.LibVlc.LibVlcEventManager;
 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor;
 import org.videolan.jvlc.internal.LibVlc.LibVlcMediaList;
@@ -40,6 +44,8 @@ public class MediaList
 
     private final LibVlcEventManager eventManager;
 
+    private List<String> items = new ArrayList<String>();
+
     public MediaList(JVLC jvlc)
     {
         this.jvlc = jvlc;
@@ -56,6 +62,11 @@ public class MediaList
 
     public void addMediaDescriptor(MediaDescriptor descriptor)
     {
+        if (items.contains(descriptor.getMrl()))
+        {
+            return;
+        }
+        items.add(descriptor.getMrl());
         libvlc_exception_t exception = new libvlc_exception_t();
         jvlc.getLibvlc().libvlc_media_list_add_media_descriptor(instance, descriptor.getInstance(), exception);
     }
@@ -79,10 +90,33 @@ public class MediaList
         return new MediaDescriptor(jvlc, descriptor);
     }
 
-    public void remove(int index)
+    /**
+     * @param index The index of the media to remove
+     * @return True if the media was successfully removed, false otherwise.
+     */
+    public boolean removeMedia(int index)
     {
         libvlc_exception_t exception = new libvlc_exception_t();
         jvlc.getLibvlc().libvlc_media_list_remove_index(instance, index, exception);
+        if (exception.raised == 0)
+        {
+            items.remove(index);
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * @param media The media descriptor mrl
+     */
+    public boolean removeMedia(String mrl)
+    {
+        int index = items.indexOf(mrl);
+        if (index == -1)
+        {
+            return false;
+        }
+        return removeMedia(index);
     }
 
     public void insertMediaDescriptor(MediaDescriptor descriptor, int index)
@@ -112,4 +146,18 @@ public class MediaList
         return instance;
     }
 
+    /**
+     * @param mediaDescriptor
+     */
+    public boolean removeMedia(MediaDescriptor mediaDescriptor)
+    {
+        String mrl = mediaDescriptor.getMrl();
+        int index = items.indexOf(mrl);
+        if (index == -1)
+        {
+            return false;
+        }
+        return removeMedia(index);
+    }
+
 }
diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/JVLCTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/JVLCTest.java
new file mode 100644 (file)
index 0000000..64810c3
--- /dev/null
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * JVLCTest.java: VLC Java Bindings
+ *****************************************************************************
+ * Copyright (C) 1998-2008 the VideoLAN team
+ *
+ * Authors: Filippo Carone <filippo@carone.org>
+ *
+ *
+ * $Id $
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+package org.videolan.jvlc;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+
+public class JVLCTest
+{
+    
+    String mrl = getClass().getResource("/raffa_voice.ogg").getFile();
+    
+    @Test
+    public void jvlcNew()
+    {
+        JVLC jvlc = new JVLC();
+        Assert.assertNotNull(jvlc.getMediaList());
+    }
+    
+    @Test
+    public void jvlcPlay()
+    {
+        JVLC jvlc = new JVLC();
+        MediaInstance instance = jvlc.play(mrl);
+        Assert.assertNotNull(instance);
+    }
+    
+    
+
+}
diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/MediaListTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/MediaListTest.java
new file mode 100644 (file)
index 0000000..b5cb236
--- /dev/null
@@ -0,0 +1,106 @@
+/*****************************************************************************
+ * MediaListTest.java: VLC Java Bindings
+ *****************************************************************************
+ * Copyright (C) 1998-2008 the VideoLAN team
+ *
+ * Authors: Filippo Carone <filippo@carone.org>
+ *
+ *
+ * $Id $
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+package org.videolan.jvlc;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class MediaListTest
+{
+
+    private JVLC jvlc;
+    
+    private String mrl = getClass().getResource("/raffa_voice.ogg").getFile();
+    
+    @Before
+    public void setup()
+    {
+        jvlc = new JVLC();
+    }
+    
+    @Test
+    public void mediaListAddMedia()
+    {
+        MediaList mlist = new MediaList(jvlc);
+        mlist.addMedia(mrl);
+        Assert.assertEquals(1, mlist.itemsCount());
+    }
+    
+    @Test
+    public void mediaListAddMedia2()
+    {
+        MediaList mlist = new MediaList(jvlc);
+        mlist.addMedia(mrl);
+        Assert.assertEquals(1, mlist.itemsCount());
+        mlist.addMedia(mrl);
+        Assert.assertEquals(1, mlist.itemsCount());
+        mlist.addMediaDescriptor(new MediaDescriptor(jvlc, mrl));
+        Assert.assertEquals(1, mlist.itemsCount());
+        mlist.addMedia("non-existing");
+        Assert.assertEquals(2, mlist.itemsCount());
+    }
+    
+    @Test
+    public void mediaListRemoveMedia()
+    {
+        MediaList mlist = new MediaList(jvlc);
+        mlist.addMedia(mrl);
+        Assert.assertEquals(1, mlist.itemsCount());
+        mlist.removeMedia(0);
+        Assert.assertEquals(0, mlist.itemsCount());
+    }
+
+    @Test
+    public void mediaListRemoveMedia2()
+    {
+        MediaList mlist = new MediaList(jvlc);
+        mlist.addMedia(mrl);
+        Assert.assertEquals(1, mlist.itemsCount());
+        mlist.removeMedia(0);
+        Assert.assertEquals(0, mlist.itemsCount());
+        
+        mlist.addMedia(mrl);
+        mlist.removeMedia(0);
+        Assert.assertEquals(0, mlist.itemsCount());
+        
+        mlist.addMediaDescriptor(new MediaDescriptor(jvlc, mrl));
+        mlist.removeMedia(0);
+        Assert.assertEquals(0, mlist.itemsCount());
+        
+        mlist.addMediaDescriptor(new MediaDescriptor(jvlc, mrl));
+        mlist.removeMedia(mrl);
+        Assert.assertEquals(0, mlist.itemsCount());
+        
+        mlist.addMediaDescriptor(new MediaDescriptor(jvlc, mrl));
+        mlist.removeMedia(new MediaDescriptor(jvlc, mrl));
+        Assert.assertEquals(0, mlist.itemsCount());
+        
+    }
+    
+    
+}
index 5fec3e277f8ec1d3b356dd715fbc33ba442a9070..b34994a5b91e499e202d9b564d18f765e48a6d64 100644 (file)
@@ -125,4 +125,41 @@ public class MediaListTest
         Assert.assertEquals(0, exception.raised);
     }
 
+    @Test
+    public void mediaListRemoveIndexTest()
+    {
+        libvlc_exception_t exception = new libvlc_exception_t();
+        LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
+        String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath();
+        LibVlcMediaDescriptor libvlc_media_descriptor = libvlc.libvlc_media_descriptor_new(
+            libvlcInstance,
+            mrl,
+            exception);
+        libvlc.libvlc_media_list_add_media_descriptor(mediaList, libvlc_media_descriptor, exception);
+        libvlc.libvlc_media_list_remove_index(mediaList, 0, exception);
+        Assert.assertEquals(0, exception.raised);
+    }
+
+    @Test
+    public void mediaListRemoveIndexTest2()
+    {
+        libvlc_exception_t exception = new libvlc_exception_t();
+        LibVlcMediaList mediaList = libvlc.libvlc_media_list_new(libvlcInstance, exception);
+        String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath();
+        LibVlcMediaDescriptor libvlc_media_descriptor = libvlc.libvlc_media_descriptor_new(
+            libvlcInstance,
+            mrl,
+            exception);
+        libvlc.libvlc_media_list_add_media_descriptor(mediaList, libvlc_media_descriptor, exception);
+        libvlc.libvlc_media_list_remove_index(mediaList, 0, exception);
+        Assert.assertEquals(0, exception.raised);
+
+        libvlc_media_descriptor = libvlc.libvlc_media_descriptor_new(
+            libvlcInstance,
+            mrl,
+            exception);
+        libvlc.libvlc_media_list_add_media_descriptor(mediaList, libvlc_media_descriptor, exception);
+        libvlc.libvlc_media_list_remove_index(mediaList, 0, exception);
+    }   
+    
 }