1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
class TestConfig : Rygel.BaseConfiguration {
public HashTable<string, bool> enable = new HashTable<string, bool> (str_hash, str_equal);
public void toggle_enable (string module) {
enable[module] = !enable[module];
this.section_changed (module, Rygel.SectionEntry.ENABLED);
}
public override bool get_enabled(string module) throws Error {
if (module in this.enable) {
return this.enable[module];
}
throw new Rygel.ConfigurationError.NO_VALUE_SET ("Should not happen");
}
}
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 () {
var config = new TestConfig ();
config.enable["Tracker"] = true;
config.enable["Tracker3"] = true;
config.enable["SomePlugin"] = true;
Rygel.MetaConfig.register_configuration (config);
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);
Rygel.MetaConfig.cleanup ();
}
void test_plugin_loader_conflict_dynamic_enable () {
var config = new TestConfig ();
config.enable["Tracker"] = true;
config.enable["Tracker3"] = false;
config.enable["SomePlugin"] = true;
Rygel.MetaConfig.register_configuration (config);
var loader = new TestPluginLoader("conflicts",
{"librygel-tracker.so", "librygel-no-conflict.so"},
{"librygel-tracker3.so"});
loader.load_modules_sync ();
assert (loader.loaded_plugins.length == 2);
assert ("librygel-tracker.so" in loader.loaded_plugins);
assert ("librygel-no-conflict.so" in loader.loaded_plugins);
// Enabling Tracker3 should not change the list of loaded plugins
config.toggle_enable ("Tracker3");
assert (loader.loaded_plugins.length == 2);
assert ("librygel-tracker.so" in loader.loaded_plugins);
assert ("librygel-no-conflict.so" in loader.loaded_plugins);
Rygel.MetaConfig.cleanup ();
}
int main (string[] args) {
Test.init (ref args);
Test.add_func ("/librygel-core/plugins/load-conflict",
test_plugin_loader_conflict);
Test.add_func ("/librygel-core/plugins/load-conflict-enable",
test_plugin_loader_conflict_dynamic_enable);
return Test.run ();
}
|