Commit b774d66a authored by Filippo Carone's avatar Filippo Carone

jvlc: download a sample file to run tests, if needed

parent 7e496b25
......@@ -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
......
......@@ -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
......
/*****************************************************************************
* 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);
}
}
}
......@@ -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()
{
......
......@@ -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
{
......
......@@ -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()
{
......
......@@ -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()
{
......
/*****************************************************************************
* 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);
}
}
<?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
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