[rygel] core: Add testable UserConfig constructor
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core: Add testable UserConfig constructor
- Date: Wed, 26 Sep 2012 18:00:40 +0000 (UTC)
commit ca32e5415ee3a6eb6074a9dc3619170119a94f5c
Author: Krzesimir Nowak <krnowak openismus com>
Date: Tue Sep 18 13:54:07 2012 +0200
core: Add testable UserConfig constructor
We want to be able to set both custom local config and custom system
config for testing purposes. I guess we could do it by some
environment variable wizardry or compile flags voodoo, but this
solution is just cleaner.
src/rygel/rygel-user-config.vala | 32 +++++++++++++++++++++-----------
1 files changed, 21 insertions(+), 11 deletions(-)
---
diff --git a/src/rygel/rygel-user-config.vala b/src/rygel/rygel-user-config.vala
index 672afe9..bf02538 100644
--- a/src/rygel/rygel-user-config.vala
+++ b/src/rygel/rygel-user-config.vala
@@ -231,19 +231,17 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
return config;
}
- public UserConfig (string file) throws Error {
+ private void initialize (string local_path,
+ string system_path) throws Error {
this.key_file = new KeyFile ();
this.sys_key_file = new KeyFile ();
- var path = Path.build_filename (BuildConfig.SYS_CONFIG_DIR,
- CONFIG_FILE);
-
- this.sys_key_file.load_from_file (path,
+ this.sys_key_file.load_from_file (system_path,
KeyFileFlags.KEEP_COMMENTS |
KeyFileFlags.KEEP_TRANSLATIONS);
- debug ("Loaded system configuration from file '%s'", path);
+ debug ("Loaded system configuration from file '%s'", system_path);
- var sys_key_g_file = File.new_for_path (path);
+ var sys_key_g_file = File.new_for_path (system_path);
this.sys_key_file_monitor = sys_key_g_file.monitor_file
(FileMonitorFlags.NONE,
null);
@@ -252,25 +250,37 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
(this.on_system_config_changed);
try {
- this.key_file.load_from_file (file,
+ this.key_file.load_from_file (local_path,
KeyFileFlags.KEEP_COMMENTS |
KeyFileFlags.KEEP_TRANSLATIONS);
- debug ("Loaded user configuration from file '%s'", file);
+ debug ("Loaded user configuration from file '%s'", local_path);
} catch (Error error) {
debug ("Failed to load user configuration from file '%s': %s",
- file,
+ local_path,
error.message);
this.key_file = new KeyFile ();
}
- var key_g_file = File.new_for_path (file);
+ var key_g_file = File.new_for_path (local_path);
this.key_file_monitor = key_g_file.monitor_file (FileMonitorFlags.NONE,
null);
this.key_file_monitor.changed.connect (this.on_local_config_changed);
}
+ public UserConfig (string local_path) throws Error {
+ var system_path = Path.build_filename (BuildConfig.SYS_CONFIG_DIR,
+ CONFIG_FILE);
+
+ this.initialize (local_path, system_path);
+ }
+
+ public UserConfig.with_paths (string local_path,
+ string system_path) throws Error {
+ this.initialize (local_path, system_path);
+ }
+
public bool get_enabled (string section) throws GLib.Error {
return this.get_bool (section, ENABLED_KEY);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]