summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2020-04-22 13:56:27 +0200
committerJens Georg <mail@jensge.org>2020-07-05 15:31:52 +0200
commit373abd66fe6a146d74ff400e8be46902bba366f1 (patch)
tree57e257fc167ea8912620101d9a8fecf1446230f3 /tests
parent1c06777690fdf5eba3e9494dc8d450e29d0de539 (diff)
downloadrygel-373abd66fe6a146d74ff400e8be46902bba366f1.tar.gz
test: Add tests for MetaConfig
Diffstat (limited to 'tests')
-rw-r--r--tests/meson.build12
-rw-r--r--tests/rygel-meta-config-test.vala99
2 files changed, 111 insertions, 0 deletions
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 ();
+}