From b774d66a9a2a48e42fc20c54a16e12ae840d1a83 Mon Sep 17 00:00:00 2001 From: Filippo Carone Date: Sun, 20 Jul 2008 17:26:42 +0200 Subject: [PATCH] jvlc: download a sample file to run tests, if needed --- .../java/org/videolan/jvlc/MediaListTest.java | 2 +- .../test/java/org/videolan/jvlc/VLMTest.java | 10 +- .../internal/AbstractVLCInternalTest.java | 136 ++++++++++++++++++ .../jvlc/internal/LibVlcMediaPlayerTest.java | 30 +--- .../jvlc/internal/MediaDescriptorTest.java | 24 +--- .../jvlc/internal/MediaListPlayerTest.java | 27 +--- .../videolan/jvlc/internal/MediaListTest.java | 22 +-- .../jvlc/internal/VLMInternalTest.java | 45 ++++++ .../java/core/src/test/resources/log4j.xml | 18 +++ bindings/java/core/src/test/resources/sample | 0 10 files changed, 210 insertions(+), 104 deletions(-) create mode 100644 bindings/java/core/src/test/java/org/videolan/jvlc/internal/AbstractVLCInternalTest.java create mode 100644 bindings/java/core/src/test/java/org/videolan/jvlc/internal/VLMInternalTest.java create mode 100644 bindings/java/core/src/test/resources/log4j.xml create mode 100644 bindings/java/core/src/test/resources/sample 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 index e0817dbdaa..e73e528170 100644 --- a/bindings/java/core/src/test/java/org/videolan/jvlc/MediaListTest.java +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/MediaListTest.java @@ -40,7 +40,7 @@ public class MediaListTest @Before public void setup() { - jvlc = new JVLC("-vvv -I dummy --aout=dummy --vout=dummy"); + jvlc = new JVLC("-vvv --ignore-config --no-media-library -I dummy --aout=dummy --vout=dummy"); } @Test diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/VLMTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/VLMTest.java index c3938ae503..a2d140a920 100644 --- a/bindings/java/core/src/test/java/org/videolan/jvlc/VLMTest.java +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/VLMTest.java @@ -43,8 +43,8 @@ public class VLMTest @Before public void setup() { - jvlc = new JVLC("-I dummy --aout=dummy --vout=dummy"); - jvlc.setLogVerbosity(LoggerVerbosityLevel.INFO); + jvlc = new JVLC("--ignore-config --no-media-library -I dummy --aout=dummy --vout=dummy"); + jvlc.setLogVerbosity(LoggerVerbosityLevel.DEBUG); } @After @@ -87,7 +87,7 @@ public class VLMTest public void testPlayMedia() { VLM vlm = jvlc.getVLM(); - vlm.addBroadcast(mediaName, "file://" + mrl, "", null, true, false); + vlm.addBroadcast(mediaName, mrl, "", null, true, false); vlm.playMedia(mediaName); } @@ -101,12 +101,14 @@ public class VLMTest } @Test - public void testStopMedia() + public void testStopMedia() throws Exception { VLM vlm = jvlc.getVLM(); vlm.addBroadcast(mediaName, "file://" + mrl, "", null, true, false); vlm.playMedia(mediaName); + Thread.sleep(2000); vlm.stopMedia(mediaName); + jvlc.release(); } @Test diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/AbstractVLCInternalTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/AbstractVLCInternalTest.java new file mode 100644 index 0000000000..03f1587528 --- /dev/null +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/AbstractVLCInternalTest.java @@ -0,0 +1,136 @@ +/***************************************************************************** + * VLMInternalTest.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.internal; + +import java.io.BufferedOutputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.net.URLConnection; + +import junit.framework.Assert; + +import org.apache.commons.io.IOUtils; +import org.junit.After; +import org.junit.Before; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.videolan.jvlc.internal.LibVlc.LibVlcInstance; +import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t; + + +public abstract class AbstractVLCInternalTest +{ + + protected LibVlc libvlc = LibVlc.SYNC_INSTANCE; + + protected LibVlcInstance libvlcInstance; + + protected String mrl; + + protected libvlc_exception_t exception; + + private String address = "http://streams.videolan.org/streams-videolan/reference/avi/Hero-Div3.avi"; + + /** + * Logger. + */ + private Logger log = LoggerFactory.getLogger(AbstractVLCInternalTest.class); + + @Before + public void testSetup() + { + exception = new libvlc_exception_t(); + libvlcInstance = libvlc.libvlc_new(0, new String[]{ + "-vvv", + "--ignore-config", + "--no-media-library", + "-I", + "dummy", + "--aout=dummy", + "--vout=dummy" }, exception); + libvlc.libvlc_exception_clear(exception); + downloadSample(); + } + + @After + public void tearDown() + { + libvlc.libvlc_release(libvlcInstance); + libvlc.libvlc_exception_clear(exception); + } + + protected void catchException(libvlc_exception_t exception) + { + Assert.assertEquals(libvlc.libvlc_exception_get_message(exception), 0, libvlc + .libvlc_exception_raised(exception)); + } + + private void downloadSample() + { + OutputStream out = null; + URLConnection conn = null; + InputStream in = null; + URL sampleResource = this.getClass().getResource("/sample.avi"); + if (sampleResource != null) + { + log.debug("Sample file already downloaded"); + mrl = sampleResource.getPath(); + return; + } + try + { + log.info("Downloading sample: {}", address); + String testResoucesPath = this.getClass().getResource("/sample").getPath(); + URL url = new URL(address); + out = new BufferedOutputStream(new FileOutputStream(testResoucesPath + ".avi")); + conn = url.openConnection(); + in = conn.getInputStream(); + byte[] buffer = new byte[1024]; + int numRead; + long numWritten = 0; + while ((numRead = in.read(buffer)) != -1) + { + out.write(buffer, 0, numRead); + numWritten += numRead; + } + log.info("Sample downloaded."); + mrl = testResoucesPath + ".avi"; + } + catch (Exception e) + { + log.error("{}", e); + } + finally + { + IOUtils.closeQuietly(in); + IOUtils.closeQuietly(out); + } + } + +} diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/LibVlcMediaPlayerTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/LibVlcMediaPlayerTest.java index e421e23947..bb66411528 100644 --- a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/LibVlcMediaPlayerTest.java +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/LibVlcMediaPlayerTest.java @@ -25,42 +25,14 @@ package org.videolan.jvlc.internal; -import org.junit.After; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; -import org.videolan.jvlc.internal.LibVlc.LibVlcInstance; import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor; import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance; -import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t; -public class LibVlcMediaPlayerTest +public class LibVlcMediaPlayerTest extends AbstractVLCInternalTest { - - private LibVlc libvlc = LibVlc.SYNC_INSTANCE; - - private LibVlcInstance libvlcInstance; - - private String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath(); - - private libvlc_exception_t exception; - - @Before - public void testSetup() - { - exception = new libvlc_exception_t(); - libvlcInstance = libvlc.libvlc_new(0, new String[]{"-vvv","-I","dummy","-aout=dummy","-vout=dummy"}, exception); - libvlc.libvlc_exception_clear(exception); - } - - @After - public void tearDown() - { - libvlc.libvlc_release(libvlcInstance); - libvlc.libvlc_exception_clear(exception); - } - @Test public void mediaInstanceNew() { diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaDescriptorTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaDescriptorTest.java index daee8613a8..204201400c 100644 --- a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaDescriptorTest.java +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaDescriptorTest.java @@ -27,36 +27,14 @@ package org.videolan.jvlc.internal; import junit.framework.Assert; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import org.videolan.jvlc.internal.LibVlc.LibVlcInstance; import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor; import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t; -public class MediaDescriptorTest +public class MediaDescriptorTest extends AbstractVLCInternalTest { - private LibVlc libvlc = LibVlc.SYNC_INSTANCE; - - private LibVlcInstance libvlcInstance; - - private String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath(); - - @Before - public void testSetup() - { - libvlc_exception_t exception = new libvlc_exception_t(); - libvlcInstance = libvlc.libvlc_new(0, new String[]{"-I","dummy","--aout=dummy","--vout=dummy"}, exception); - } - - @After - public void tearDown() - { - libvlc.libvlc_release(libvlcInstance); - } - @Test public void mediaDescriptorNew() throws Exception { diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java index 14000484b1..e79aee422d 100644 --- a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java @@ -27,10 +27,7 @@ package org.videolan.jvlc.internal; import junit.framework.Assert; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import org.videolan.jvlc.internal.LibVlc.LibVlcInstance; import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor; import org.videolan.jvlc.internal.LibVlc.LibVlcMediaInstance; import org.videolan.jvlc.internal.LibVlc.LibVlcMediaList; @@ -38,30 +35,8 @@ import org.videolan.jvlc.internal.LibVlc.LibVlcMediaListPlayer; import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t; -public class MediaListPlayerTest +public class MediaListPlayerTest extends AbstractVLCInternalTest { - - private LibVlc libvlc = LibVlc.SYNC_INSTANCE; - - private LibVlcInstance libvlcInstance; - - private String mrl = this.getClass().getResource("/raffa_voice.ogg").getPath(); - - @Before - public void testSetup() throws Exception - { - libvlc_exception_t exception = new libvlc_exception_t(); - libvlcInstance = libvlc.libvlc_new(0, new String[]{"-I", "dummy", "--aout=dummy", "--vout=dummy" }, exception); - // use the following line to use your audio card. - // libvlcInstance = libvlc.libvlc_new(0, new String[]{}, exception); - } - - @After - public void tearDown() - { - libvlc.libvlc_release(libvlcInstance); - } - @Test public void mediaListPlayerNewTest() { 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 b40aceac84..c9acec0180 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 @@ -27,35 +27,15 @@ package org.videolan.jvlc.internal; import junit.framework.Assert; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import org.videolan.jvlc.internal.LibVlc.LibVlcInstance; import org.videolan.jvlc.internal.LibVlc.LibVlcMediaDescriptor; import org.videolan.jvlc.internal.LibVlc.LibVlcMediaList; import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t; -public class MediaListTest +public class MediaListTest extends AbstractVLCInternalTest { - private LibVlc libvlc = LibVlc.SYNC_INSTANCE; - - private LibVlcInstance libvlcInstance; - - @Before - public void testSetup() - { - libvlc_exception_t exception = new libvlc_exception_t(); - libvlcInstance = libvlc.libvlc_new(0, new String[]{"-I","dummy","--aout=dummy","--vout=dummy"}, exception); - } - - @After - public void tearDown() - { - libvlc.libvlc_release(libvlcInstance); - } - @Test public void mediaListNew() { diff --git a/bindings/java/core/src/test/java/org/videolan/jvlc/internal/VLMInternalTest.java b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/VLMInternalTest.java new file mode 100644 index 0000000000..82c7cb223d --- /dev/null +++ b/bindings/java/core/src/test/java/org/videolan/jvlc/internal/VLMInternalTest.java @@ -0,0 +1,45 @@ +/***************************************************************************** + * VLMInternalTest.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.internal; + +import org.junit.Test; +import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t; + + +public class VLMInternalTest extends AbstractVLCInternalTest +{ + + @Test + public void testVLMPlay() + { + libvlc_exception_t exception = new libvlc_exception_t(); + libvlc.libvlc_vlm_add_broadcast(libvlcInstance, "test", "file://" + mrl, "", 0, null, 1, 0, exception); + libvlc.libvlc_vlm_play_media(libvlcInstance, mrl, exception); + catchException(exception); + libvlc.libvlc_vlm_stop_media(libvlcInstance, mrl, exception); + } + +} diff --git a/bindings/java/core/src/test/resources/log4j.xml b/bindings/java/core/src/test/resources/log4j.xml new file mode 100644 index 0000000000..3a06d4a2de --- /dev/null +++ b/bindings/java/core/src/test/resources/log4j.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bindings/java/core/src/test/resources/sample b/bindings/java/core/src/test/resources/sample new file mode 100644 index 0000000000..e69de29bb2 -- 2.39.2