Commit 01a95e76 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

test: Move testapi.c to /test and use a sample file that is not ogg for basic testing.

This sample is downloaded from streams.videolan.org. Feel free to find a better suited codec/demux combination.
libvlc test are now splitted a bit.
Tests that are specific to core and that don't need vlc's modules are kept in src/test.
parent 04e7bd84
......@@ -8,7 +8,7 @@
# - src (libvlc) is nedeed by modules, mozilla and bindings
# - libs/* are needed by modules
SUBDIRS = po libs/loader libs/srtp src modules \
projects/mozilla bindings projects/activex share doc
projects/mozilla bindings projects/activex share doc test
DIST_SUBDIRS = $(SUBDIRS) m4 extras/package/ipkg
EXTRA_DIST = \
......
......@@ -6226,6 +6226,7 @@ AC_CONFIG_FILES([
po/Makefile.in
share/Makefile
src/Makefile
test/Makefile
])
AC_CONFIG_FILES([
......
......@@ -33,6 +33,7 @@ add_subdirectory(libs/loader)
add_subdirectory(src)
add_subdirectory(modules)
add_subdirectory(po)
add_subdirectory(test)
# Enable uninstall
configure_file(
......
......@@ -270,19 +270,16 @@ set_target_properties(libvlc libvlc-control vlc PROPERTIES COMPILE_FLAGS
##########################################################
# Tests
add_executable(test_testapi control/testapi.c)
add_executable(test_i18n_atof test/i18n_atof.c)
add_executable(test_url test/url.c)
add_executable(test_utf8 test/utf8.c)
add_executable(test_dictionary test/dictionary.c)
target_link_libraries(test_testapi libvlc-control)
target_link_libraries(test_i18n_atof libvlc)
target_link_libraries(test_url libvlc)
target_link_libraries(test_utf8 libvlc)
target_link_libraries(test_dictionary libvlc)
add_test(test_control ${CMAKE_CURRENT_BINARY_DIR}/test_testapi)
add_test(test_i18n_atof ${CMAKE_CURRENT_BINARY_DIR}/test_i18n_atof)
add_test(test_url ${CMAKE_CURRENT_BINARY_DIR}/test_url)
add_test(test_utf8 ${CMAKE_CURRENT_BINARY_DIR}/test_utf8)
......
add_executable(test_libvlc_core libvlc/core.c)
add_executable(test_libvlc_events libvlc/events.c)
add_executable(test_libvlc_media_player libvlc/media_player.c
samples/test.sample)
add_executable(test_libvlc_media_list libvlc/media_list.c)
add_executable(test_libvlc_media_list_player libvlc/media_list_player.c
samples/test.sample)
target_link_libraries(test_libvlc_core libvlc-control)
target_link_libraries(test_libvlc_events libvlc-control)
target_link_libraries(test_libvlc_media_player libvlc-control)
target_link_libraries(test_libvlc_media_list libvlc-control)
target_link_libraries(test_libvlc_media_list_player libvlc-control)
set(SAMPLES_SERVER http://streams.videolan.org/streams-videolan/reference)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/samples/test.sample
COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/samples
COMMAND curl -L ${SAMPLES_SERVER}/avi/Hero-Div3.avi > ${CMAKE_CURRENT_BINARY_DIR}/samples/test.sample
)
add_test(test_libvlc_core
${CMAKE_CURRENT_BINARY_DIR}/test_libvlc_core)
add_test(test_libvlc_events
${CMAKE_CURRENT_BINARY_DIR}/test_libvlc_events)
add_test(test_libvlc_media_player
${CMAKE_CURRENT_BINARY_DIR}/test_libvlc_media_player)
add_test(test_libvlc_media_list
${CMAKE_CURRENT_BINARY_DIR}/test_libvlc_media_list)
add_test(test_libvlc_media_list_player
${CMAKE_CURRENT_BINARY_DIR}/test_libvlc_media_list_player)
......@@ -21,9 +21,9 @@ ln -sf ../$cmake_dir/CMakeLists/src_CMakeLists.txt src/CMakeLists.txt
echo "Removing old modules/gui/qt4/CMakeLists.txt"
rm -f modules/gui/qt4/CMakeLists.txt
echo "Installing libs/loaders/CMakeLists.txt"
rm -f libs/loaders/CMakeLists.txt
ln -s ../$cmake_dir/CMakeLists/libs_loaders_CMakeLists.txt libs/loaders/CMakeLists.txt
echo "Installing libs/loader/CMakeLists.txt"
rm -f libs/loader/CMakeLists.txt
ln -s ../../$cmake_dir/CMakeLists/libs_loaders_CMakeLists.txt libs/loader/CMakeLists.txt
echo "Installing modules/CMakeLists.txt"
rm -f modules/CMakeLists.txt
......@@ -33,7 +33,11 @@ echo "Installing po/CMakeLists.txt"
rm -f po/CMakeLists.txt
ln -s ../$cmake_dir/CMakeLists/po_CMakeLists.txt po/CMakeLists.txt
echo "Installing include/config.h.cmake"
echo "installing test/CMakeLists.txt"
rm -f test/CMakeLists.txt
ln -sf ../$cmake_dir/CMakeLists/test_CMakeLists.txt test/CMakeLists.txt
echo "installing include/config.h.cmake"
rm -f include/config.h.cmake
ln -sf ../$cmake_dir/config.h.cmake include/config.h.cmake
......
......@@ -442,7 +442,6 @@ check_PROGRAMS = \
test_url \
test_utf8 \
test_headers \
test_control \
$(NULL)
dist_check_SCRIPTS = check_symbols
......@@ -469,10 +468,6 @@ test_utf8_CFLAGS = $(CFLAGS_tests)
test_headers_SOURCES = test/headers.c
test_headers_CFLAGS = $(CFLAGS_tests)
test_control_SOURCES = control/testapi.c
test_control_LDADD = libvlc-control.la
test_control_CFLAGS = $(CFLAGS_tests)
check-local:
for h in `echo $(dist_pkginclude_HEADERS) $(pkginclude_HEADERS) | sed -e s,\.\./include/,,g`; \
do \
......
###############################################################################
# Automake targets and declarations
###############################################################################
AUTOMAKE_OPTIONS = subdir-objects
###############################################################################
# Unit/regression test
###############################################################################
check_PROGRAMS = \
test_libvlc_core \
test_libvlc_events \
test_libvlc_media_list \
test_libvlc_media_list_player \
test_libvlc_media_player \
$(NULL)
TESTS = samples $(check_PROGRAMS)
# Samples server
SAMPLES_SERVER=http://streams.videolan.org/streams-videolan/reference
samples/test.sample:
mkdir -p `basename $@`
curl $(SAMPLES_SERVER)/avi/Hero-Div3.avi > $@
samples: samples/test.sample
CFLAGS_tests = `$(VLC_CONFIG) --cflags libvlc`
test_libvlc_core_SOURCES = libvlc/core.c
test_libvlc_core_LDADD = $(top_builddir)/src/libvlc-control.la
test_libvlc_core_CFLAGS = $(CFLAGS_tests)
test_libvlc_events_SOURCES = libvlc/events.c
test_libvlc_events_LDADD = $(top_builddir)/src/libvlc-control.la
test_libvlc_events_CFLAGS = $(CFLAGS_tests)
test_libvlc_media_list_player_SOURCES = libvlc/media_list_player.c
test_libvlc_media_list_player_LDADD = $(top_builddir)/src/libvlc-control.la
test_libvlc_media_list_player_CFLAGS = $(CFLAGS_tests)
test_libvlc_media_list_SOURCES = libvlc/media_list.c
test_libvlc_media_list_LDADD = $(top_builddir)/src/libvlc-control.la
test_libvlc_media_list_CFLAGS = $(CFLAGS_tests)
test_libvlc_media_player_SOURCES = libvlc/media_player.c
test_libvlc_media_player_LDADD = $(top_builddir)/src/libvlc-control.la
test_libvlc_media_player_CFLAGS = $(CFLAGS_tests)
FORCE:
@echo "Generated source cannot be phony. Go away." >&2
@exit 1
.PHONY: FORCE
/*
* core.c - libvlc smoke test
*
* $Id$
*/
/**********************************************************************
* Copyright (C) 2007 Rémi Denis-Courmont. *
* This program is free software; you can redistribute and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation; 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, you can get it from: *
* http://www.gnu.org/copyleft/gpl.html *
**********************************************************************/
#include "test.h"
static void test_core (const char ** argv, int argc)
{
libvlc_instance_t *vlc;
int id;
log ("Testing core\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
libvlc_playlist_clear (vlc, &ex);
catch ();
id = libvlc_playlist_add_extended (vlc, "/dev/null", "Test", 0, NULL,
&ex);
catch ();
libvlc_playlist_clear (vlc, &ex);
catch ();
libvlc_retain (vlc);
libvlc_release (vlc);
libvlc_release (vlc);
}
int main (void)
{
test_init();
test_core (test_defaults_args, test_defaults_nargs);
return 0;
}
/*
* testapi.c - libvlc smoke test
* events.c - libvlc smoke test
*
* $Id$
*/
/**********************************************************************
* Copyright (C) 2007 Rémi Denis-Courmont. *
* Copyright (C) 2008 Pierre d'Herbemont. *
* This program is free software; you can redistribute and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation; version 2 of the license, or (at *
......@@ -21,192 +22,7 @@
* http://www.gnu.org/copyleft/gpl.html *
**********************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc/libvlc.h>
#undef NDEBUG
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static libvlc_exception_t ex;
#define log( ... ) printf( "testapi: " __VA_ARGS__ );
/* test if we have exception */
static bool have_exception (void)
{
if (libvlc_exception_raised (&ex))
{
libvlc_exception_clear (&ex);
return true;
}
else
return false;
}
static void catch (void)
{
if (libvlc_exception_raised (&ex))
{
fprintf (stderr, "Exception: %s\n",
libvlc_exception_get_message (&ex));
abort ();
}
assert (libvlc_exception_get_message (&ex) == NULL);
libvlc_exception_clear (&ex);
}
/* Test we have */
static void test_core (const char ** argv, int argc);
static void test_media_list (const char ** argv, int argc);
static void test_events (const char ** argv, int argc);
static void test_media_player_play_stop(const char** argv, int argc);
static void test_media_player_pause_stop(const char** argv, int argc);
static void test_media_list_player_pause_stop(const char** argv, int argc);
/* Tests implementations */
static void test_core (const char ** argv, int argc)
{
libvlc_instance_t *vlc;
int id;
log ("Testing core\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
libvlc_playlist_clear (vlc, &ex);
catch ();
id = libvlc_playlist_add_extended (vlc, "/dev/null", "Test", 0, NULL,
&ex);
catch ();
libvlc_playlist_clear (vlc, &ex);
catch ();
libvlc_retain (vlc);
libvlc_release (vlc);
libvlc_release (vlc);
}
static void test_media_list (const char ** argv, int argc)
{
libvlc_instance_t *vlc;
libvlc_media_t *md1, *md2, *md3, *md4;
libvlc_media_list_t *ml;
log ("Testing media_list\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
ml = libvlc_media_list_new (vlc, &ex);
catch ();
md1 = libvlc_media_new (vlc, "/dev/null", &ex);
catch ();
md2 = libvlc_media_new (vlc, "/dev/null", &ex);
catch ();
md3 = libvlc_media_new (vlc, "/dev/null", &ex);
catch ();
libvlc_media_list_add_media (ml, md1, &ex);
catch ();
libvlc_media_list_add_media (ml, md2, &ex);
catch ();
assert( libvlc_media_list_count (ml, &ex) == 2 );
catch ();
assert( libvlc_media_list_index_of_item (ml, md1, &ex) == 0 );
catch ();
assert( libvlc_media_list_index_of_item (ml, md2, &ex) == 1 );
catch ();
libvlc_media_list_remove_index (ml, 0, &ex); /* removing first item */
catch ();
/* test if second item was moved on first place */
assert( libvlc_media_list_index_of_item (ml, md2, &ex) == 0 );
catch ();
libvlc_media_list_add_media (ml, md1, &ex); /* add 2 items */
catch ();
libvlc_media_list_add_media (ml, md1, &ex);
catch ();
/* there should be 3 pieces */
assert( libvlc_media_list_count (ml, &ex) == 3 );
catch ();
libvlc_media_list_insert_media (ml, md3, 2, &ex);
catch ();
/* there should be 4 pieces */
assert( libvlc_media_list_count (ml, &ex) == 4 );
catch ();
/* test inserting on right place */
assert( libvlc_media_list_index_of_item (ml, md3, &ex) == 2 );
catch ();
/* test right returning descriptor*/
assert ( libvlc_media_list_item_at_index (ml, 0, &ex) == md2 );
catch ();
assert ( libvlc_media_list_item_at_index (ml, 2, &ex) == md3 );
catch ();
/* test if give exceptions, when it should */
/* have 4 items, so index 4 should give exception */
libvlc_media_list_remove_index (ml, 4, &ex);
assert (have_exception ());
libvlc_media_list_remove_index (ml, 100, &ex);
assert (have_exception ());
libvlc_media_list_remove_index (ml, -1, &ex);
assert (have_exception ());
/* getting non valid items */
libvlc_media_t * p_non_exist =
libvlc_media_list_item_at_index (ml, 4, &ex);
assert (have_exception ());
p_non_exist = libvlc_media_list_item_at_index (ml, 100, &ex);
assert (have_exception ());
p_non_exist = libvlc_media_list_item_at_index (ml, -1, &ex);
assert (have_exception ());
md4 = libvlc_media_new (vlc, "/dev/dsp", &ex);
catch ();
/* try to find non inserted item */
int i_non_exist = 0;
i_non_exist = libvlc_media_list_index_of_item (ml, md4, &ex);
assert ( i_non_exist == -1 );
libvlc_media_release (md1);
libvlc_media_release (md2);
libvlc_media_release (md3);
libvlc_media_release (md4);
libvlc_media_list_release (ml);
libvlc_release (vlc);
catch ();
}
#include "test.h"
/* This one is an internal API. We use it here to run tests that
* don't depends on playback, and only test the event framework */
......@@ -214,6 +30,7 @@ extern void libvlc_event_send( libvlc_event_manager_t *, libvlc_event_t *);
static void test_events_dummy_callback( const libvlc_event_t * event, void * user_data)
{
(void)event;
vlc_bool_t * callback_was_called = user_data;
*callback_was_called = VLC_TRUE;
}
......@@ -256,7 +73,7 @@ static void test_events (const char ** argv, int argc)
libvlc_MediaPlayerPositionChanged,
};
int i, mi_events_len = sizeof(mi_events)/sizeof(*mi_events);
log ("Testing events\n");
libvlc_exception_init (&ex);
......@@ -316,166 +133,11 @@ static void test_events (const char ** argv, int argc)
catch ();
}
static void test_media_player_play_stop(const char** argv, int argc)
int main (void)
{
libvlc_instance_t *vlc;
libvlc_media_t *md;
libvlc_media_player_t *mi;
const char * file = "file://../bindings/java/core/src/test/resources/raffa_voice.ogg";
log ("Testing play and pause of %s\n", file);
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
md = libvlc_media_new (vlc, file, &ex);
catch ();
mi = libvlc_media_player_new_from_media (md, &ex);
catch ();
libvlc_media_release (md);
libvlc_media_player_play (mi, &ex);
catch ();
/* FIXME: Do something clever */
sleep(1);
assert( libvlc_media_player_get_state (mi, &ex) != libvlc_Error );
catch ();
libvlc_media_player_stop (mi, &ex);
catch ();
libvlc_media_player_release (mi);
catch ();
libvlc_release (vlc);
catch ();
}
static void test_media_player_pause_stop(const char** argv, int argc)
{
libvlc_instance_t *vlc;
libvlc_media_t *md;
libvlc_media_player_t *mi;
const char * file = "file://../bindings/java/core/src/test/resources/raffa_voice.ogg";
log ("Testing play and pause of %s\n", file);
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
md = libvlc_media_new (vlc, file, &ex);
catch ();
mi = libvlc_media_player_new_from_media (md, &ex);
catch ();
libvlc_media_release (md);
libvlc_media_player_play (mi, &ex);
catch ();
/* FIXME: Do something clever */
sleep(1);
assert( libvlc_media_player_get_state (mi, &ex) == libvlc_Playing );
catch ();
libvlc_media_player_pause (mi, &ex);
assert( libvlc_media_player_get_state (mi, &ex) == libvlc_Paused );
catch();
libvlc_media_player_stop (mi, &ex);
catch ();
libvlc_media_player_release (mi);
catch ();
libvlc_release (vlc);
catch ();
}
static void test_media_list_player_pause_stop(const char** argv, int argc)
{
libvlc_instance_t *vlc;
libvlc_media_t *md;
libvlc_media_list_t *ml;
libvlc_media_list_player_t *mlp;
const char * file = "file://../bindings/java/core/src/test/resources/raffa_voice.ogg";
log ("Testing play and pause of %s using the media list.\n", file);
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
md = libvlc_media_new (vlc, file, &ex);
catch ();
ml = libvlc_media_list_new (vlc, &ex);
catch ();
mlp = libvlc_media_list_player_new (vlc, &ex);
libvlc_media_list_add_media( ml, md, &ex );
catch ();
libvlc_media_list_player_set_media_list( mlp, ml, &ex );
libvlc_media_list_player_play_item( mlp, md, &ex );
sleep(1); // play is asynchronous
catch ();
libvlc_media_list_player_pause (mlp, &ex);
catch();
libvlc_media_list_player_stop (mlp, &ex);
catch ();
libvlc_media_release (md);
libvlc_media_list_player_release (mlp);
catch ();
libvlc_release (vlc);
catch ();
}
int main (int argc, char *argv[])
{
const char *args[argc + 5];
int nlibvlc_args = sizeof (args) / sizeof (args[0]);
alarm (50); /* Make sure "make check" does not get stuck */
args[0] = "-vvv";
args[1] = "-I";
args[2] = "dummy";
args[3] = "--plugin-path=../modules";
args[4] = "--vout=dummy";
args[5] = "--aout=dummy";
for (int i = 1; i < argc; i++)
args[i + 3] = argv[i];
test_core (args, nlibvlc_args);
test_events (args, nlibvlc_args);
test_media_list (args, nlibvlc_args);
test_media_player_play_stop(args, nlibvlc_args);
test_init();
test_media_player_pause_stop(args, nlibvlc_args);
test_events (test_defaults_args, test_defaults_nargs);
test_media_list_player_pause_stop(args, nlibvlc_args);
return 0;
}
/*
* media_list.c - libvlc smoke test
*
* $Id$
*/
/**********************************************************************
* Copyright (C) 2007 Rémi Denis-Courmont. *
* This program is free software; you can redistribute and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation; 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, you can get it from: *
* http://www.gnu.org/copyleft/gpl.html *
**********************************************************************/
#include "test.h"
static void test_media_list (const char ** argv, int argc)
{
libvlc_instance_t *vlc;
libvlc_media_t *md1, *md2, *md3, *md4;
libvlc_media_list_t *ml;
log ("Testing media_list\n");
libvlc_exception_init (&ex);
vlc = libvlc_new (argc, argv, &ex);
catch ();
ml = libvlc_media_list_new (vlc, &ex);
catch ();
md1 = libvlc_media_new (vlc, "/dev/null", &ex);
catch ();
md2 = libvlc_media_new (vlc, "/dev/null", &ex);
catch ();
md3 = libvlc_media_new (vlc, "/dev/null", &ex);
catch ();
libvlc_media_list_add_media (ml, md1, &ex);
catch ();
libvlc_media_list_add_media (ml, md2, &ex);
catch ();
assert( libvlc_media_list_count (ml, &ex) == 2 );
catch ();
assert( libvlc_media_list_index_of_item (ml, md1, &ex) == 0 );
catch ();
assert( libvlc_media_list_index_of_item (ml, md2, &ex) == 1 );
catch ();
libvlc_media_list_remove_index (ml, 0, &ex); /* removing first item */
catch ();
/* test if second item was moved on first place */
assert( libvlc_media_list_index_of_item (ml, md2, &ex) == 0 );
catch ();
libvlc_media_list_add_media (ml, md1, &ex); /* add 2 items */
catch ();
libvlc_media_list_add_media (ml, md1, &ex);
catch ();
/* there should be 3 pieces */
assert( libvlc_media_list_count (ml, &ex) == 3 );
catch ();
libvlc_media_list_insert_media (ml, md3, 2, &ex);
catch ();
/* there should be 4 pieces */
assert( libvlc_media_list_count (ml, &ex) == 4 );
catch ();
/* test inserting on right place */
assert( libvlc_media_list_index_of_item (ml, md3, &ex) == 2 );
catch ();
/* test right returning descriptor*/
assert ( libvlc_media_list_item_at_index (ml, 0, &ex) == md2 );
catch ();
assert ( libvlc_media_list_item_at_index (ml, 2, &ex) == md3 );
catch ();
/* test if give exceptions, when it should */
/* have 4 items, so index 4 should give exception */
libvlc_media_list_remove_index (ml, 4, &ex);
assert (have_exception ());
libvlc_media_list_remove_index (ml, 100, &ex);
assert (have_exception ());
libvlc_media_list_remove_index (ml, -1, &ex);
assert (have_exception ());
/* getting non valid items */
libvlc_media_t * p_non_exist =
libvlc_media_list_item_at_index (ml, 4, &ex);