1 /*****************************************************************************
2 * VLMInternalTest.java: VLC Java Bindings
3 *****************************************************************************
4 * Copyright (C) 1998-2008 the VideoLAN team
6 * Authors: Filippo Carone <filippo@carone.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 package org.videolan.jvlc.internal;
28 import java.io.BufferedOutputStream;
29 import java.io.FileOutputStream;
30 import java.io.InputStream;
31 import java.io.OutputStream;
33 import java.net.URLConnection;
35 import junit.framework.Assert;
37 import org.apache.commons.io.IOUtils;
38 import org.junit.After;
39 import org.junit.Before;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42 import org.videolan.jvlc.internal.LibVlc.LibVlcInstance;
43 import org.videolan.jvlc.internal.LibVlc.libvlc_exception_t;
46 public abstract class AbstractVLCInternalTest
49 protected LibVlc libvlc = LibVlc.SYNC_INSTANCE;
51 protected LibVlcInstance libvlcInstance;
55 protected libvlc_exception_t exception;
57 private String address = "http://streams.videolan.org/streams-videolan/reference/avi/Hero-Div3.avi";
62 private Logger log = LoggerFactory.getLogger(AbstractVLCInternalTest.class);
65 public void testSetup()
67 exception = new libvlc_exception_t();
68 libvlcInstance = libvlc.libvlc_new(0, new String[]{
75 "--vout=dummy" }, exception);
76 libvlc.libvlc_exception_clear(exception);
81 public void tearDown()
83 libvlc.libvlc_release(libvlcInstance);
84 libvlc.libvlc_exception_clear(exception);
87 protected void catchException(libvlc_exception_t exception)
89 Assert.assertEquals(libvlc.libvlc_exception_get_message(exception), 0, libvlc
90 .libvlc_exception_raised(exception));
93 private void downloadSample()
95 OutputStream out = null;
96 URLConnection conn = null;
97 InputStream in = null;
98 URL sampleResource = this.getClass().getResource("/sample.avi");
99 if (sampleResource != null)
101 log.debug("Sample file already downloaded");
102 mrl = sampleResource.getPath();
107 log.info("Downloading sample: {}", address);
108 String testResoucesPath = this.getClass().getResource("/sample").getPath();
109 URL url = new URL(address);
110 out = new BufferedOutputStream(new FileOutputStream(testResoucesPath + ".avi"));
111 conn = url.openConnection();
112 in = conn.getInputStream();
113 byte[] buffer = new byte[1024];
116 while ((numRead = in.read(buffer)) != -1)
118 out.write(buffer, 0, numRead);
119 numWritten += numRead;
121 log.info("Sample downloaded.");
122 mrl = testResoucesPath + ".avi";
130 IOUtils.closeQuietly(in);
131 IOUtils.closeQuietly(out);