Commit 5f584e4c authored by Filippo Carone's avatar Filippo Carone

more unit tests

parent 5a0c3a51
......@@ -84,6 +84,7 @@ public class MediaDescriptor
}
/**
* Returns the instance.
* @return the instance
......
......@@ -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<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);
}
}
/*****************************************************************************
* 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);
}
}
/*****************************************************************************
* 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());
}
}
......@@ -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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment