[vlc-commits] [Git][videolan/vlc][master] test: add lua playlist parser module test

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Tue May 26 12:20:29 UTC 2026



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
ad29b852 by Bipul Lamsal at 2026-05-26T14:04:21+02:00
test: add lua playlist parser module test

Add a test for the lua playlist parser module, similar to the existing
lua extension test. It provides a basic html mock stream with a hardcoded
title "VideoLAN" and verifies the lua parser returns the same title.
To sum up it checks:
- vlc.access and vlc.path returning correct values
- vlc.read(), vlc.readline(), vlc.peek()
- parse() to get invoked after probe() returns true
- parse() returning the expected title back to the test 

- - - - -


4 changed files:

- test/Makefile.am
- + test/modules/lua/playlist/playlist.lua
- + test/modules/lua/playlist_parser.c
- test/modules/meson.build


Changes:

=====================================
test/Makefile.am
=====================================
@@ -69,6 +69,7 @@ check_PROGRAMS = \
 	test_src_video_output \
 	test_src_video_output_opengl \
 	test_modules_lua_extension \
+	test_modules_lua_playlist_parser \
 	test_modules_misc_medialibrary \
 	test_modules_packetizer_helpers \
 	test_modules_packetizer_hxxx \
@@ -129,6 +130,7 @@ EXTRA_PROGRAMS = \
 
 EXTRA_DIST = \
 	modules/lua/extensions/extensions.lua \
+	modules/lua/playlist/playlist.lua \
 	samples/certs/certkey.pem \
 	samples/empty.voc \
 	samples/image.jpg \
@@ -326,6 +328,11 @@ test_src_misc_image_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_lua_extension_SOURCES = modules/lua/extension.c
 test_modules_lua_extension_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_lua_extension_CPPFLAGS = $(AM_CPPFLAGS)
+
+test_modules_lua_playlist_parser_SOURCES = modules/lua/playlist_parser.c
+test_modules_lua_playlist_parser_LDADD = $(LIBVLCCORE) $(LIBVLC)
+test_modules_lua_playlist_parser_CPPFLAGS = $(AM_CPPFLAGS)
+
 test_modules_misc_medialibrary_SOURCES = modules/misc/medialibrary.c
 test_modules_misc_medialibrary_LDADD = $(LIBVLCCORE) $(LIBVLC)
 test_modules_packetizer_helpers_SOURCES = modules/packetizer/helpers.c


=====================================
test/modules/lua/playlist/playlist.lua
=====================================
@@ -0,0 +1,22 @@
+local check_peek_read = "<html>"
+
+function probe()
+	vlc.msg.dbg("Access:" .. vlc.access)
+	vlc.msg.dbg("Path:" .. vlc.path)
+	local peeked = vlc.peek(6)
+	return vlc.access == "mock" and vlc.path == "length=100" and peeked == check_peek_read
+end
+
+function parse()
+	vlc.msg.dbg("parse is triggered ")
+	local read_bytes = vlc.read(6)
+	if read_bytes == check_peek_read then
+		vlc.msg.dbg("read is triggered")
+	end
+	local line = vlc.readline()
+	local title = string.match(line, "<title>(.-)</title>")
+	if title ~= nil then
+		vlc.msg.dbg("readline is triggered")
+	end
+	return { { name = title, path = vlc.access .. "://" .. vlc.path } }
+end


=====================================
test/modules/lua/playlist_parser.c
=====================================
@@ -0,0 +1,119 @@
+/*****************************************************************************
+ * playlist_parser.c: test for the lua playlist parser module
+ *****************************************************************************
+ * Copyright (C) 2026 VideoLAN
+ *
+ * Authors: Bipul Lamsal <bipullamsal _at_ gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* Define a builtin module for mocked parts */
+#define MODULE_NAME test_lua_playlist_parser
+#undef VLC_DYNAMIC_PLUGIN
+
+#include "../../libvlc/test.h"
+
+#include <vlc_common.h>
+#include <vlc_demux.h>
+#include <vlc_input_item.h>
+#include <vlc_interface.h>
+#include <vlc_plugin.h>
+#include <vlc_stream.h>
+
+#include "../lib/libvlc_internal.h"
+
+const char vlc_module_name[] = MODULE_STRING;
+
+static int OpenIntf(vlc_object_t *root) {
+  // setup
+  const char *test_parsed_value = "VideoLAN";
+  const char *sample_test_markup = "<html><title>%s</title></html>\n";
+  char sample_test[100];
+  snprintf(sample_test, sizeof(sample_test), sample_test_markup,
+           test_parsed_value);
+
+  stream_t *p_s = vlc_stream_MemoryNew(root, (uint8_t *)sample_test,
+                                       strlen(sample_test), true);
+  assert(p_s != NULL);
+
+  p_s->psz_url = strdup("mock://length=100");
+
+  // exercise
+  demux_t *p_d = demux_New(root, "luaplaylist", p_s->psz_url, p_s, NULL);
+
+  // verification
+  assert(p_d != NULL);
+
+  // next behavior is parse() execution
+  input_item_t *p_item = input_item_New(INPUT_ITEM_URI_NOP, NULL);
+  input_item_node_t *p_node = input_item_node_Create(p_item);
+
+  int probe_ret = vlc_stream_ReadDir(p_d, p_node);
+
+  assert(probe_ret == 0);
+  assert(p_node->i_children == 1);
+
+  char *test_title = p_node->pp_children[0]->p_item->psz_name;
+  assert(strcmp(test_title, test_parsed_value) == 0);
+
+  input_item_node_Delete(p_node);
+
+  // cleanup
+  // this calls demux_DestroyDemux(p_d) callback unloading the module and
+  // deleting the stream as well
+  demux_Delete(p_d);
+  return VLC_SUCCESS;
+}
+
+/** Inject the mocked modules as a static plugin: **/
+vlc_module_begin()
+    set_callback(OpenIntf)
+    set_capability("interface", 0)
+vlc_module_end()
+
+VLC_EXPORT const vlc_plugin_cb vlc_static_modules[] = {
+    VLC_SYMBOL(vlc_entry),
+    NULL
+};
+
+int main(void) {
+  setenv("VLC_USERDATA_PATH", TOP_SRCDIR "/test/modules/", 1);
+  test_init();
+
+  const char *const args[] = {
+      "-vvv",
+      "--vout=dummy",
+      "--aout=dummy",
+      "--text-renderer=dummy",
+      "--no-auto-preparse",
+  };
+
+  libvlc_instance_t *vlc = libvlc_new(ARRAY_SIZE(args), args);
+
+  libvlc_InternalAddIntf(vlc->p_libvlc_int, MODULE_STRING);
+  libvlc_InternalPlay(vlc->p_libvlc_int);
+
+  libvlc_release(vlc);
+  return 0;
+}


=====================================
test/modules/meson.build
=====================================
@@ -6,6 +6,14 @@ vlc_tests += {
     'module_depends' : vlc_plugins_targets.keys()
 }
 
+vlc_tests += {
+    'name' : 'test_modules_lua_playlist_parser',
+    'sources' : files('lua/playlist_parser.c'),
+    'suite' : ['modules', 'test_modules'],
+    'link_with' : [libvlc, libvlccore],
+    'module_depends' : ['lua'] 
+}
+
 if not (host_system == 'windows') # missing mkdtemp()
 vlc_tests += {
     'name' : 'test_modules_misc_medialibrary',



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/ad29b852744d938f6b1d78d214ce32bcbc355089

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/ad29b852744d938f6b1d78d214ce32bcbc355089
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list