Skip to content

Commit c80ca84

Browse files
alexandre-janniauxrobUx4
authored andcommitted
test: lua: check that extension are correctly probed
The test included in this commit checks that lua will correctly probe extension scripts, but without ensuring that it correctly follows the data home. It only check that lua creates the correct access to load the files. In particular, the test fails to pass if the condition for loading .vle files is not correct.
1 parent 7bd66a2 commit c80ca84

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed

test/Makefile.am

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ check_PROGRAMS = \
3838
test_src_misc_image \
3939
test_src_video_output \
4040
test_src_video_output_opengl \
41+
test_modules_lua_extension \
4142
test_modules_misc_medialibrary \
4243
test_modules_packetizer_helpers \
4344
test_modules_packetizer_hxxx \
@@ -149,6 +150,10 @@ test_src_interface_dialog_LDADD = $(LIBVLCCORE) $(LIBVLC)
149150
test_src_media_source_LDADD = $(LIBVLCCORE) $(LIBVLC)
150151
test_src_media_source_SOURCES = src/media_source/media_source.c
151152

153+
test_modules_lua_extension_SOURCES = modules/lua/extension.c
154+
test_modules_lua_extension_LDADD = $(LIBVLCCORE) $(LIBVLC)
155+
test_modules_lua_extension_CPPFLAGS = $(AM_CPPFLAGS) \
156+
-DLUA_EXTENSION_DIR=\"$(srcdir)/modules/\"
152157
test_modules_misc_medialibrary_SOURCES = modules/misc/medialibrary.c
153158
test_modules_misc_medialibrary_LDADD = $(LIBVLCCORE) $(LIBVLC)
154159
test_modules_packetizer_helpers_SOURCES = modules/packetizer/helpers.c

test/modules/lua/extension.c

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*****************************************************************************
2+
* extension.c: test for the lua extension module
3+
*****************************************************************************
4+
* Copyright (C) 2023 Videolabs
5+
*
6+
* Authors: Alexandre Janniaux <[email protected]>
7+
*
8+
* This program is free software; you can redistribute it and/or modify it
9+
* under the terms of the GNU Lesser General Public License as published
10+
* by the Free Software Foundation; either version 2.1 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this program; if not, write to the Free Software Foundation,
20+
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21+
*****************************************************************************/
22+
23+
#ifdef HAVE_CONFIG_H
24+
# include <config.h>
25+
#endif
26+
27+
/* Define a builtin module for mocked parts */
28+
#define MODULE_NAME test_lua_extension
29+
#define MODULE_STRING "test_lua_extension"
30+
#undef __PLUGIN__
31+
const char vlc_module_name[] = MODULE_STRING;
32+
33+
#include "../../libvlc/test.h"
34+
35+
#include <vlc/vlc.h>
36+
37+
#include <vlc_common.h>
38+
#include <vlc_plugin.h>
39+
#include <vlc_modules.h>
40+
#include <vlc_extensions.h>
41+
42+
#include <limits.h>
43+
44+
static int exitcode = 0;
45+
46+
static int OpenIntf(vlc_object_t *root)
47+
{
48+
extensions_manager_t *mgr =
49+
vlc_object_create(root, sizeof *mgr);
50+
assert(mgr);
51+
52+
setenv("XDG_DATA_HOME", LUA_EXTENSION_DIR, 1);
53+
setenv("VLC_DATA_PATH", LUA_EXTENSION_DIR, 1);
54+
setenv("VLC_LIB_PATH", LUA_EXTENSION_DIR, 1);
55+
56+
mgr->p_module = module_need(mgr, "extension", "lua", true);
57+
58+
if (mgr->p_module == NULL)
59+
{
60+
exitcode = 77;
61+
goto end;
62+
}
63+
64+
/* Check that the extension from the test is correctly probed. */
65+
assert(mgr->extensions.i_size == 1);
66+
extension_Activate(mgr, mgr->extensions.p_elems[0]);
67+
extension_Deactivate(mgr, mgr->extensions.p_elems[0]);
68+
69+
module_unneed(mgr, mgr->p_module);
70+
end:
71+
vlc_object_delete(mgr);
72+
return VLC_SUCCESS;
73+
}
74+
75+
/** Inject the mocked modules as a static plugin: **/
76+
vlc_module_begin()
77+
set_callback(OpenIntf)
78+
set_capability("interface", 0)
79+
vlc_module_end()
80+
81+
/* Helper typedef for vlc_static_modules */
82+
typedef int (*vlc_plugin_cb)(vlc_set_cb, void*);
83+
84+
VLC_EXPORT const vlc_plugin_cb vlc_static_modules[] = {
85+
VLC_SYMBOL(vlc_entry),
86+
NULL
87+
};
88+
89+
90+
int main()
91+
{
92+
test_init();
93+
94+
const char * const args[] = {
95+
"-vvv", "--vout=dummy", "--aout=dummy", "--text-renderer=dummy",
96+
"--no-auto-preparse",
97+
};
98+
99+
libvlc_instance_t *vlc = libvlc_new(ARRAY_SIZE(args), args);
100+
101+
libvlc_add_intf(vlc, MODULE_STRING);
102+
libvlc_playlist_play(vlc);
103+
104+
libvlc_release(vlc);
105+
return 0;
106+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function descriptor()
2+
return {
3+
title = "test",
4+
version = "0.0.1",
5+
author = "VideoLAN",
6+
shortdesc = "Test example",
7+
description = "Test description",
8+
capabilities = {
9+
"input-listener",
10+
"meta-listener",
11+
"playing-listener",
12+
}
13+
}
14+
end
15+
16+
function activate()
17+
vlc.msg.dbg("Activate")
18+
end
19+
20+
function close()
21+
vlc.msg.dbg("Close")
22+
end
23+
24+
function deactivate()
25+
vlc.msg.dbg("Deactivate")
26+
end
27+
28+
function input_changed()
29+
vlc.msg.dbg("Input changed")
30+
end
31+
32+
function playing_changed()
33+
vlc.msg.dbg("Playing changed")
34+
end
35+
36+
function meta_changed()
37+
vlc.msg.dbg("Meta changed")
38+
end

0 commit comments

Comments
 (0)