|
| 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 | +} |
0 commit comments