]> git.sesse.net Git - vlc/commitdiff
jvlc: download a sample file to run tests, if needed
authorFilippo Carone <littlejohn@videolan.org>
Sun, 20 Jul 2008 15:26:42 +0000 (17:26 +0200)
committerFilippo Carone <littlejohn@videolan.org>
Sun, 20 Jul 2008 15:27:40 +0000 (17:27 +0200)
bindings/java/core/src/test/java/org/videolan/jvlc/MediaListTest.java
bindings/java/core/src/test/java/org/videolan/jvlc/VLMTest.java
bindings/java/core/src/test/java/org/videolan/jvlc/internal/AbstractVLCInternalTest.java [new file with mode: 0644]
bindings/java/core/src/test/java/org/videolan/jvlc/internal/LibVlcMediaPlayerTest.java
bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaDescriptorTest.java
bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListPlayerTest.java
bindings/java/core/src/test/java/org/videolan/jvlc/internal/MediaListTest.java
bindings/java/core/src/test/java/org/videolan/jvlc/internal/VLMInternalTest.java [new file with mode: 0644]
bindings/java/core/src/test/resources/log4j.xml [new file with mode: 0644]
bindings/java/core/src/test/resources/sample [new file with mode: 0644]

index e0817dbdaa7c898f022923d15f7b62bc888b3474..e73e5281701e37b7dd4e91b20e8c209deaf70dec 100644 (file)
@@ -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
index c3938ae503e049ac98c2c419c70282922acf6e55..a2d140a920119a1d73a22e8821ff206a1cfffab8 100644 (file)
@@ -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 (file)
index 0000000..03f1587
--- /dev/null
@@ -0,0 +1,136 @@
+/*****************************************************************************
+ * VLMInternalTest.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.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);
+        }
+    }
+
+}
index e421e23947ba1341485bbbe880c103106745799b..bb66411528d0e8a169b6fe66dd6e07d677e4fe97 100644 (file)
 
 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()
     {
index daee8613a82368732bd28542defe35fbe8011daf..204201400c28e77da0089fcd4dd6081767b455d9 100644 (file)
@@ -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
     {
index 14000484b16bbda6da19778c720c98a912b835f6..e79aee422da3560906f512046849d8fed54adf3d 100644 (file)
@@ -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()
     {
index b40aceac84c09d1ea41e8f524221a9882562e182..c9acec01809963676a7acba9774c6f85a7fbb002 100644 (file)
@@ -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 (file)
index 0000000..82c7cb2
--- /dev/null
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * VLMInternalTest.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.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 (file)
index 0000000..3a06d4a
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration>
+  <!-- log4j test configuration -->
+  <appender name="test-appender" class="org.apache.log4j.ConsoleAppender">
+    <layout class="org.apache.log4j.PatternLayout">
+      <param name="ConversionPattern" value="%-5p %c.%M(%C{1}.java:%L)   %m%n" />
+      <!-- <param name="ConversionPattern" value="%-5p %m%n" />-->
+    </layout>
+  </appender>
+  <category name="org.videolan">
+    <priority value="info" />
+  </category>
+  <root>
+    <priority value="debug" />
+    <appender-ref ref="test-appender" />
+  </root>
+</log4j:configuration>
\ 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 (file)
index 0000000..e69de29