diff --git a/src/client/application/geary-config.vala b/src/client/application/geary-config.vala index 718c72a4..8df13d85 100644 --- a/src/client/application/geary-config.vala +++ b/src/client/application/geary-config.vala @@ -4,8 +4,11 @@ * (version 2.1 or later). See the COPYING file in this distribution. */ -// Wrapper class for GSettings. +/** + * Provides convenience properties to current Geary GSettings values. + */ public class Configuration { + public const string WINDOW_WIDTH_KEY = "window-width"; public const string WINDOW_HEIGHT_KEY = "window-height"; public const string WINDOW_MAXIMIZE_KEY = "window-maximize"; @@ -27,13 +30,27 @@ public class Configuration { public const string SEARCH_STRATEGY_KEY = "search-strategy"; public const string CONVERSATION_VIEWER_ZOOM_KEY = "conversation-viewer-zoom"; + public enum DesktopEnvironment { UNKNOWN = 0, UNITY; } + + // is_installed: set to true if installed, else false. + // schema_dir: MUST be set if not installed. Directory where GSettings schema is located. + public static void init(bool is_installed, string? schema_dir = null) { + if (!is_installed) { + assert(schema_dir != null); + // If not installed, set an environment variable pointing to where the GSettings schema + // is to be found. + GLib.Environment.set_variable("GSETTINGS_SCHEMA_DIR", schema_dir, true); + } + } + + public Settings settings { get; private set; } - public Settings gnome_interface; + public Settings gnome_interface { get; private set; } public DesktopEnvironment desktop_environment { get { @@ -158,17 +175,6 @@ public class Configuration { Migrate.old_app_config(settings); } - // is_installed: set to true if installed, else false. - // schema_dir: MUST be set if not installed. Directory where GSettings schema is located. - public static void init(bool is_installed, string? schema_dir = null) { - if (!is_installed) { - assert(schema_dir != null); - // If not installed, set an environment variable pointing to where the GSettings schema - // is to be found. - GLib.Environment.set_variable("GSETTINGS_SCHEMA_DIR", schema_dir, true); - } - } - public void bind(string key, Object object, string property, SettingsBindFlags flags = GLib.SettingsBindFlags.DEFAULT) { settings.bind(key, object, property, flags); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 41222123..a90dc6a5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,6 +11,8 @@ set(TEST_SRC engine/rfc822-message-data-test.vala engine/rfc822-utils-test.vala engine/util-html-test.vala + + client/application/geary-configuration-test.vala ) # Vala diff --git a/test/client/application/geary-configuration-test.vala b/test/client/application/geary-configuration-test.vala new file mode 100644 index 00000000..4ce33a2d --- /dev/null +++ b/test/client/application/geary-configuration-test.vala @@ -0,0 +1,35 @@ +/* + * Copyright 2016 Michael Gratton + * + * This software is licensed under the GNU Lesser General Public License + * (version 2.1 or later). See the COPYING file in this distribution. + */ + +class ConfigurationTest : Gee.TestCase { + + private Configuration test_config = null; + + public ConfigurationTest() { + base("ConfigurationTest"); + add_test("desktop_environment", desktop_environment); + } + + public override void set_up() { + Environment.unset_variable("XDG_CURRENT_DESKTOP"); + this.test_config = new Configuration(GearyApplication.APP_ID); + } + + public void desktop_environment() { + assert(this.test_config.desktop_environment == + Configuration.DesktopEnvironment.UNKNOWN); + + Environment.set_variable("XDG_CURRENT_DESKTOP", "BLARG", true); + assert(this.test_config.desktop_environment == + Configuration.DesktopEnvironment.UNKNOWN); + + Environment.set_variable("XDG_CURRENT_DESKTOP", "Unity", true); + assert(this.test_config.desktop_environment == + Configuration.DesktopEnvironment.UNITY); + } + +} diff --git a/test/main.vala b/test/main.vala index 34e9b185..ff99b023 100644 --- a/test/main.vala +++ b/test/main.vala @@ -6,6 +6,14 @@ */ int main(string[] args) { + /* + * Set env vars right up front to avoid weird bugs + */ + + // Use the memory GSettings DB so we a) always start with default + // values, and b) don't persist any changes made during a test + Environment.set_variable("GSETTINGS_BACKEND", "memory", true); + /* * Initialise all the things. */ @@ -29,6 +37,8 @@ int main(string[] args) { TestSuite client = new TestSuite("client"); + client.add_suite(new ConfigurationTest().get_suite()); + /* * Run the tests */