[vlc-commits] [Git][videolan/vlc][master] 3 commits: qt: provide a stubbed medialib implementation for qt tests
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Dec 20 09:42:57 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
21616e94 by Pierre Lamot at 2024-12-20T09:18:25+00:00
qt: provide a stubbed medialib implementation for qt tests
Only the entry points exists, this is not designed to mock medialibrary
behaviors
- - - - -
2c7e9e16 by Pierre Lamot at 2024-12-20T09:18:25+00:00
qt: add missing qtest.pro for autotools QTest check
- - - - -
ba595bce by Pierre Lamot at 2024-12-20T09:18:25+00:00
qt: add test case for recursive model changes MLBaseModel
- - - - -
5 changed files:
- modules/gui/qt/Makefile.am
- modules/gui/qt/meson.build
- + modules/gui/qt/qtest.pro
- + modules/gui/qt/tests/test_ml_model.cpp
- modules/gui/qt/tests/vlc_stub_modules.cpp
Changes:
=====================================
modules/gui/qt/Makefile.am
=====================================
@@ -1596,6 +1596,43 @@ QT_QTEST_COMMON_cxxflags = $(AM_CXXFLAGS) $(QT_CFLAGS) $(QT_QTEST_CFLAGS) -fPIC
QT_QTEST_COMMON_ldadd = $(QT_LIBS) $(LIBS_qt) $(QT_QTEST_LIBS) $(LIBVLCCORE) $(LIBVLC)
QT_QTEST_COMMON_ldflags = $(AM_LDFLAGS) $(QT_LDFLAGS) $(QT_QTEST_LDFLAGS)
+
+# test_ml_model
+
+test_ml_model_SOURCES = \
+ tests/vlc_stub_modules.cpp \
+ tests/test_ml_model.cpp \
+ util/base_model.hpp util/base_model_p.hpp util/base_model.cpp \
+ util/listcache.hpp \
+ util/locallistcacheloader.hpp \
+ medialibrary/mlqmltypes.hpp \
+ medialibrary/mlbasemodel.hpp medialibrary/mlbasemodel.cpp \
+ medialibrary/medialib.hpp medialibrary/medialib.cpp \
+ medialibrary/mlthreadpool.hpp medialibrary/mlthreadpool.cpp \
+ playlist/playlist_controller.hpp playlist/playlist_controller.cpp \
+ playlist/playlist_item.hpp playlist/playlist_item.cpp
+
+nodist_test_ml_model_SOURCES = \
+ tests/test_ml_model.moc \
+ util/base_model.moc.cpp \
+ util/listcache.moc.cpp \
+ util/locallistcacheloader.moc.cpp \
+ medialibrary/mlqmltypes.moc.cpp \
+ medialibrary/mlbasemodel.moc.cpp \
+ medialibrary/medialib.moc.cpp \
+ medialibrary/mlthreadpool.moc.cpp \
+ playlist/playlist_controller.moc.cpp \
+ playlist/playlist_item.moc.cpp
+
+BUILT_SOURCES += tests/test_ml_model.moc
+CLEANFILES += tests/test_ml_model.moc
+test_ml_model_CPPFLAGS = $(QT_QTEST_COMMON_cppflags)
+test_ml_model_CXXFLAGS = $(QT_QTEST_COMMON_cxxflags)
+test_ml_model_LDADD = $(QT_QTEST_COMMON_ldadd)
+test_ml_model_LDFLAGS = $(QT_QTEST_COMMON_ldflags)
+check_PROGRAMS += test_ml_model
+TESTS += test_ml_model
+
# test_renderer_manager_model
test_renderer_manager_model_SOURCES = \
=====================================
modules/gui/qt/meson.build
=====================================
@@ -1141,6 +1141,39 @@ if qt6_dep.found()
qtest_qt6_dep = dependency('qt6', version: '=' + qt6_dep.version(), modules: ['Test'], required: false)
if qtest_qt6_dep.found()
+ vlc_tests += {
+ 'name': 'test_qt_ml_model',
+ 'sources': files(
+ 'tests/test_ml_model.cpp',
+ 'tests/vlc_stub_modules.cpp',
+ 'util/base_model.cpp',
+ 'medialibrary/mlbasemodel.cpp',
+ 'medialibrary/medialib.cpp',
+ 'medialibrary/mlthreadpool.cpp',
+ 'playlist/playlist_controller.cpp',
+ 'playlist/playlist_item.cpp',
+ ),
+ 'moc_sources': files(
+ 'tests/test_ml_model.cpp'
+ ),
+ 'moc_headers': files(
+ 'tests/vlc_stub_modules.cpp',
+ 'util/base_model.hpp',
+ 'util/listcache.hpp',
+ 'util/locallistcacheloader.hpp',
+ 'medialibrary/mlqmltypes.hpp',
+ 'medialibrary/mlbasemodel.hpp',
+ 'medialibrary/medialib.hpp',
+ 'medialibrary/mlthreadpool.hpp',
+ 'playlist/playlist_controller.hpp',
+ 'playlist/playlist_item.hpp',
+ ),
+ 'suite': ['qt'],
+ 'include_directories' : qt_include_dir,
+ 'link_with': [libvlccore, libvlc],
+ 'dependencies': [qt6_dep, qt_extra_deps, qtest_qt6_dep],
+ }
+
vlc_tests += {
'name': 'test_qt_renderer_manager',
'sources': files(
=====================================
modules/gui/qt/qtest.pro
=====================================
@@ -0,0 +1,3 @@
+QT = testlib
+CONFIG -= debug_and_release
+CONFIG += no_include_pwd
=====================================
modules/gui/qt/tests/test_ml_model.cpp
=====================================
@@ -0,0 +1,174 @@
+/*****************************************************************************
+ * Copyright (C) 2024 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "../medialibrary/mlbasemodel.hpp"
+#include "vlc_stub_modules.hpp"
+
+#include <memory>
+#include <vector>
+
+#include <QCoreApplication>
+#include <QTest>
+
+struct vlc_medialibrary_t;
+
+class MLTestModel : public MLBaseModel
+{
+ Q_OBJECT
+
+public:
+ virtual QVariant itemRoleData(MLItem *item, int role) const override
+ {
+ VLC_UNUSED(role);
+ if (!item)
+ return {};
+
+ return QVariant::fromValue(item->getId());
+ }
+
+ void appendRange(int64_t min, int64_t max)
+ {
+ for (int64_t i = min; i <= max; ++i)
+ m_items.emplace_back(i, VLC_ML_PARENT_UNKNOWN);
+ emit resetRequested();
+ }
+
+ void updateItem(size_t position, int64_t id)
+ {
+ MLItemId itemId{id, VLC_ML_PARENT_UNKNOWN};
+ m_items[position] = itemId;
+ updateItemInCache(itemId);
+ }
+
+
+protected:
+ std::unique_ptr<MLListCacheLoader> createMLLoader() const override
+ {
+ return std::make_unique<MLListCacheLoader>(m_mediaLib, std::make_shared<MLTestModel::Loader>(*this, *this));
+ }
+
+ struct Loader : public MLListCacheLoader::MLOp
+ {
+ Loader(const MLBaseModel& model, const MLTestModel& parent)
+ : MLOp(model)
+ , m_mlTestModel(parent)
+ {}
+
+ size_t count(vlc_medialibrary_t* ml, const vlc_ml_query_params_t* queryParams) const override
+ {
+ VLC_UNUSED(ml);
+ VLC_UNUSED(queryParams);
+ return m_mlTestModel.m_items.size();
+ }
+
+ std::vector<std::unique_ptr<MLItem>> load(vlc_medialibrary_t* ml, const vlc_ml_query_params_t* queryParams) const override
+ {
+ VLC_UNUSED(ml);
+ uint32_t offset = queryParams->i_offset;
+ uint32_t count = queryParams->i_nbResults;
+ size_t maxIndex = std::min(
+ static_cast<size_t>(offset + count),
+ m_mlTestModel.m_items.size() - 1);
+ std::vector<std::unique_ptr<MLItem>> ret;
+ for (size_t i = offset; i <= maxIndex; ++i) {
+ ret.emplace_back(std::make_unique<MLItem>(m_mlTestModel.m_items[i]));
+ }
+ return ret;
+ }
+
+ std::unique_ptr<MLItem> loadItemById(vlc_medialibrary_t* ml, MLItemId itemId) const override
+ {
+ VLC_UNUSED(ml);
+ return std::make_unique<MLItem>(itemId);
+ }
+
+ const MLTestModel& m_mlTestModel;
+ };
+
+
+ std::vector<MLItemId> m_items;
+};
+
+class TestVLCMLModel : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase() {
+ m_env = std::make_unique<VLCTestingEnv>();
+ QVERIFY(m_env->init());
+ }
+
+ void cleanupTestCase() {
+ m_env.reset();
+ }
+
+
+ void init() {
+ m_medialib = std::make_unique<MediaLib>(m_env->intf, nullptr);
+ m_model = std::make_unique<MLTestModel>();
+ m_model->classBegin();
+ m_model->setMl(m_medialib.get());
+ m_model->componentComplete();
+ }
+
+ void cleanup() {
+ m_model.reset();
+ m_medialib.reset();
+ }
+
+ /**
+ * @brief testModelUpdatedFromCallback
+ * test for !6537 scenario
+ *
+ * - Count&Load task issued (task n°1)
+ * - model need reset (thumbnail is updated for instance) => `needReload = true`
+ * - Count&Load task (n°1) is resolved
+ * * diff util insert/remove rows
+ * - Callback from model change ask to refer an item beyond the cache
+ * - refer issue a new 'fetch more' request (n°2) as m_countTask is 0
+ * - as `needReload await true`, cache is moved to oldCache, new count&load request
+ * is issued (n° 3)
+ * - task n°2 resolve, cache is null, assertion fails
+ *
+ */
+ void testModelRecuseUpdateFromSlot()
+ {
+ connect(m_model.get(), &BaseModel::countChanged, this, [this](){
+ m_model->updateItem(13, 37);
+ //model will initially only load 100 elements fetching beyond the loaded range
+ // will trigger "fetch more" request
+ m_model->data(m_model->index(500), Qt::DisplayRole);
+ }, Qt::SingleShotConnection);
+
+ m_model->appendRange(1, 1000);
+ QTRY_COMPARE_WITH_TIMEOUT(m_model->getCount(), 1000u, 100);
+ }
+private:
+ std::unique_ptr<VLCTestingEnv> m_env;
+ std::unique_ptr<MediaLib> m_medialib;
+ std::unique_ptr<MLTestModel> m_model;
+};
+
+
+QTEST_GUILESS_MAIN(TestVLCMLModel)
+#include "test_ml_model.moc"
=====================================
modules/gui/qt/tests/vlc_stub_modules.cpp
=====================================
@@ -33,6 +33,7 @@
#include <vlc_probe.h>
#include <vlc_interface.h>
#include <vlc_player.h>
+#include <vlc_media_library.h>
#include "../../../../lib/libvlc_internal.h"
@@ -111,6 +112,38 @@ static void CloseIntf( vlc_object_t *p_this )
testenv->intf = nullptr;
}
+//Medialib module
+
+static void* MLGet( vlc_medialibrary_module_t* module, int query, va_list args )
+{
+ return nullptr;
+}
+
+static int MLList( vlc_medialibrary_module_t* module, int query,
+ const vlc_ml_query_params_t* params, va_list args )
+{
+ return VLC_EGENERIC;
+}
+
+static int MLControl( vlc_medialibrary_module_t* module, int query, va_list args )
+{
+ return VLC_EGENERIC;
+}
+
+static int MLOpen( vlc_object_t* obj )
+{
+ auto* p_ml = reinterpret_cast<vlc_medialibrary_module_t*>( obj );
+ p_ml->pf_control = MLControl;
+ p_ml->pf_get = MLGet;
+ p_ml->pf_list = MLList;
+ return VLC_SUCCESS;
+}
+
+static void MLClose( vlc_object_t* obj )
+{
+ VLC_UNUSED(obj);
+}
+
//module declaration
vlc_module_begin()
@@ -123,6 +156,9 @@ add_submodule()
add_submodule()
set_capability("renderer probe", 10000)
set_callback(vlc_rd_probe_open)
+add_submodule()
+ set_capability("medialibrary", 10000)
+ set_callbacks(MLOpen, MLClose)
vlc_module_end()
extern "C" {
@@ -148,7 +184,7 @@ VLCTestingEnv::~VLCTestingEnv()
}
static const char * test_defaults_args[] = {
- "-v", "--vout=vdummy", "--aout=adummy", "--text-renderer=tdummy",
+ "-v", "--vout=vdummy", "--aout=adummy", "--text-renderer=tdummy", "--media-library"
};
static const int test_defaults_nargs =
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/346c18b719ae5775e7e41a6084c07c65a89bd79b...ba595bce6ce184ab2680dd185e5a6ccaf309ba2e
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/346c18b719ae5775e7e41a6084c07c65a89bd79b...ba595bce6ce184ab2680dd185e5a6ccaf309ba2e
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list