From: Filippo Carone Date: Thu, 20 Mar 2008 23:32:47 +0000 (+0100) Subject: more unit tests X-Git-Tag: 0.9.0-test0~1965 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=5f584e4c451865ea350cd54e28a4d1417d50e9c6;p=vlc more unit tests --- diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaDescriptor.java b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaDescriptor.java index a248d58016..961d8d96dd 100644 --- a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaDescriptor.java +++ b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaDescriptor.java @@ -84,6 +84,7 @@ public class MediaDescriptor } + /** * Returns the instance. * @return the instance diff --git a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java index bef31c4247..979222cab0 100644 --- a/bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java +++ b/bindings/java/core/src/main/java/org/videolan/jvlc/MediaList.java @@ -25,6 +25,10 @@ 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 items = new ArrayList(); + 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 index 0000000000..64810c341b --- /dev/null +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/JVLCTest.java @@ -0,0 +1,55 @@ +/***************************************************************************** + * JVLCTest.java: VLC Java Bindings + ***************************************************************************** + * Copyright (C) 1998-2008 the VideoLAN team + * + * Authors: Filippo Carone + * + * + * $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 index 0000000000..b5cb23684f --- /dev/null +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/MediaListTest.java @@ -0,0 +1,106 @@ +/***************************************************************************** + * MediaListTest.java: VLC Java Bindings + ***************************************************************************** + * Copyright (C) 1998-2008 the VideoLAN team + * + * Authors: Filippo Carone + * + * + * $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()); + + } + + +} diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListTest.java index 5fec3e277f..b34994a5b9 100644 --- a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListTest.java +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListTest.java @@ -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); + } + }