From c83fff7eceb6ab54d00ed9aec27de63abe7ca486 Mon Sep 17 00:00:00 2001 From: Jens Georg Date: Sun, 19 Apr 2020 18:13:38 +0200 Subject: core: Add mutually exclusive plugin support Add new, optional "Conflicts" keyword to the plugin meta-data which takes a list of names of other plugings that cannot be loaded together with this plugin. First plugin loaded wins Implements #155 --- .../conflicts/librygel-no-conflict.so | 0 .../plugin-loader/conflicts/librygel-tracker.so | 0 .../plugin-loader/conflicts/librygel-tracker3.so | 0 tests/data/plugin-loader/conflicts/test.conf | 11 +++++ tests/meson.build | 13 ++++++ tests/plugin-loader/rygel-plugin-loader-test.vala | 52 ++++++++++++++++++++++ 6 files changed, 76 insertions(+) create mode 100644 tests/data/plugin-loader/conflicts/librygel-no-conflict.so create mode 100644 tests/data/plugin-loader/conflicts/librygel-tracker.so create mode 100644 tests/data/plugin-loader/conflicts/librygel-tracker3.so create mode 100644 tests/data/plugin-loader/conflicts/test.conf create mode 100644 tests/plugin-loader/rygel-plugin-loader-test.vala (limited to 'tests') diff --git a/tests/data/plugin-loader/conflicts/librygel-no-conflict.so b/tests/data/plugin-loader/conflicts/librygel-no-conflict.so new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/plugin-loader/conflicts/librygel-tracker.so b/tests/data/plugin-loader/conflicts/librygel-tracker.so new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/plugin-loader/conflicts/librygel-tracker3.so b/tests/data/plugin-loader/conflicts/librygel-tracker3.so new file mode 100644 index 00000000..e69de29b diff --git a/tests/data/plugin-loader/conflicts/test.conf b/tests/data/plugin-loader/conflicts/test.conf new file mode 100644 index 00000000..85c6c8a4 --- /dev/null +++ b/tests/data/plugin-loader/conflicts/test.conf @@ -0,0 +1,11 @@ +[general] +log-level = *:5 + +[Tracker3] +enabled = true + +[SomePlugin] +enabled = true + +[Tracker] +enabled = true diff --git a/tests/meson.build b/tests/meson.build index 9cc00e38..bb690457 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -66,6 +66,19 @@ http_time_seek_test = executable( dependencies : [glib, soup] ) +test('rygel-plugin-loader-test', + executable( + 'rygel-plugin-loader-test', + files( + 'plugin-loader/rygel-plugin-loader-test.vala' + ), + dependencies : [ + rygel_core + ] + ), + workdir : meson.current_source_dir(), +) + test('rygel-searchable-container-test', searchable_container_test) test('rygel-object-creator-test', object_creator_test) test('rygel-regression-test', regression_test) diff --git a/tests/plugin-loader/rygel-plugin-loader-test.vala b/tests/plugin-loader/rygel-plugin-loader-test.vala new file mode 100644 index 00000000..3f8db60d --- /dev/null +++ b/tests/plugin-loader/rygel-plugin-loader-test.vala @@ -0,0 +1,52 @@ +class TestPluginLoader : Rygel.PluginLoader { + private string[] expected_plugins; + private string[] forbidden_plugins; + public string[] loaded_plugins; + + public TestPluginLoader(string testset_location, + string[] expected_plugins, + string[] forbidden_plugins) { + Object(base_path : "data/plugin-loader/" + testset_location); + this.forbidden_plugins = forbidden_plugins; + this.expected_plugins = expected_plugins; + this.loaded_plugins = new string[0]; + } + + protected override bool load_module_from_file (File module) { + assert (module.get_basename () in expected_plugins); + assert (!(module.get_basename () in forbidden_plugins)); + + loaded_plugins += module.get_basename (); + + // Just do nothing + return true; + } +} + +void test_plugin_loader_conflict () { + try { + var config = new Rygel.UserConfig.with_paths ( + "data/plugin-loader/conflicts/test.conf", + "data/plugin-loader/conflicts/test.conf"); + Rygel.MetaConfig.register_configuration (config); + } catch (Error error) { + critical("%s", error.message); + assert_not_reached (); + } + + var loader = new TestPluginLoader("conflicts", + {"librygel-tracker.so", "librygel-no-conflict.so"}, + {"librygel-tracker3.so"}); + loader.load_modules_sync (null); + assert (loader.loaded_plugins.length == 2); + assert ("librygel-tracker.so" in loader.loaded_plugins); + assert ("librygel-no-conflict.so" in loader.loaded_plugins); +} + +int main (string[] args) { + Test.init (ref args); + + Test.add_func ("/librygel-core/plugins/load-conflict", + test_plugin_loader_conflict); + return Test.run (); +} \ No newline at end of file -- cgit v1.2.1