summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/librygel-core/rygel-meta-config.vala16
-rw-r--r--tests/meson.build12
-rw-r--r--tests/rygel-meta-config-test.vala99
3 files changed, 127 insertions, 0 deletions
diff --git a/src/librygel-core/rygel-meta-config.vala b/src/librygel-core/rygel-meta-config.vala
index 313f3b40..cd5a36c6 100644
--- a/src/librygel-core/rygel-meta-config.vala
+++ b/src/librygel-core/rygel-meta-config.vala
@@ -62,6 +62,12 @@ public class Rygel.MetaConfig : GLib.Object, Configuration {
return meta_config;
}
+ /**
+ * Register another configuration provider to the meta configuration
+ * First configuration to provide a value wins. If you want to assign
+ * priority to configuration providers, they have to be added with descending
+ * priority
+ */
public static void register_configuration (Configuration config) {
if (MetaConfig.configs == null) {
MetaConfig.configs = new ArrayList<Configuration> ();
@@ -73,6 +79,16 @@ public class Rygel.MetaConfig : GLib.Object, Configuration {
}
}
+ /**
+ * Convenoience method for cleaning up the singleton. This
+ * Should usually not be used; only if you care for your
+ * valgrind report or in tests
+ */
+ public static void cleanup () {
+ MetaConfig.meta_config = null;
+ MetaConfig.configs = null;
+ }
+
public string get_interface () throws GLib.Error {
string val = null;
bool unavailable = true;
diff --git a/tests/meson.build b/tests/meson.build
index bb690457..45579018 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -79,6 +79,18 @@ test('rygel-plugin-loader-test',
workdir : meson.current_source_dir(),
)
+test('rygel-meta-config-test',
+ executable(
+ 'rygel-meta-config-test',
+ files(
+ 'rygel-meta-config-test.vala'
+ ),
+ dependencies : [
+ rygel_core
+ ]
+ )
+)
+
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/rygel-meta-config-test.vala b/tests/rygel-meta-config-test.vala
new file mode 100644
index 00000000..147748bc
--- /dev/null
+++ b/tests/rygel-meta-config-test.vala
@@ -0,0 +1,99 @@
+class TestConfig : Rygel.BaseConfiguration {
+ public HashTable<string, bool> enable = new HashTable<string, bool> (str_hash, str_equal);
+
+ public void toggl_enable (string module) {
+ print("%s ->", enable[module].to_string ());
+ enable[module] = !enable[module];
+ print("%s\n", enable[module].to_string ());
+ 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");
+ }
+}
+
+void
+test_meta_config_single_instance ()
+{
+ Test.summary ("Test whether we actually get only one instance");
+ var instance_a = Rygel.MetaConfig.get_default ();
+ var instance_b = Rygel.MetaConfig.get_default ();
+
+ assert (instance_a == instance_b);
+ Rygel.MetaConfig.cleanup ();
+}
+
+const string SECTION_A = "Tracker";
+const string SECTION_B = "SomePlugin";
+
+void
+test_meta_config_overrides () {
+
+ var first_config = new TestConfig ();
+ first_config.enable[SECTION_A] = true;
+
+ Rygel.MetaConfig.register_configuration (first_config);
+
+ var second_config = new TestConfig ();
+ second_config.enable[SECTION_A] = false;
+ second_config.enable[SECTION_B] = true;
+
+ Rygel.MetaConfig.register_configuration (second_config);
+
+ var instance = Rygel.MetaConfig.get_default ();
+
+ // Check that signalling a change for a value that only exists
+ // on lower priority will trigger a signal on the MetaConfig
+ assert_true (instance.get_enabled (SECTION_A));
+ assert_true (instance.get_enabled (SECTION_B));
+
+ var id = instance.section_changed.connect ((section, entry) => {
+ assert_true (section == SECTION_B);
+ assert_true (entry == Rygel.SectionEntry.ENABLED);
+ assert_false (instance.get_enabled (section));
+ });
+
+ second_config.toggl_enable (SECTION_B);
+ instance.disconnect (id);
+
+ // Check that changing a value on a lower priority will not
+ // propagated up if there is a value with higher priority
+ id = instance.section_changed.connect ((section, entry) => {
+ assert_not_reached ();
+ });
+ second_config.toggl_enable (SECTION_A);
+ instance.disconnect (id);
+
+ // Check that changing a value on a higher priority will be
+ // propagated up
+ id = instance.section_changed.connect ((section, entry) => {
+ assert_true (section == SECTION_A);
+ assert_true (entry == Rygel.SectionEntry.ENABLED);
+ try {
+ assert_false (instance.get_enabled (section));
+ } catch (Error error) {
+ assert_not_reached ();
+ }
+ });
+ first_config.toggl_enable (SECTION_A);
+ instance.disconnect (id);
+
+ Rygel.MetaConfig.cleanup ();
+}
+
+int main(string[] args) {
+ Test.init (ref args);
+
+ Test.add_func ("/librygel-core/meta-config/single-instance",
+ test_meta_config_single_instance);
+
+ Test.add_func ("/librygel-core/meta-config/overrides",
+ test_meta_config_overrides);
+
+ return Test.run ();
+}