Add simple/demo client unit test using GSettings.

* test/client/application/geary-configuration-test.vala: New unit test
  for Configuration class.

* test/main.vala: Add new unit test to the client suite, ensure the
  memory GSettings backend is used as the default so we get default
  setting values, and never save any changes made.

* test/CMakeLists.txt: Add new unit test source.

* src/client/application/geary-config.vala: Tidy up code a bit to adhere
  to code conventions.
This commit is contained in:
Michael James Gratton 2016-12-26 13:21:58 +10:30
parent 325232bad7
commit 50120c67ff
4 changed files with 66 additions and 13 deletions

View file

@ -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);

View file

@ -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

View file

@ -0,0 +1,35 @@
/*
* Copyright 2016 Michael Gratton <mike@vee.net>
*
* 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);
}
}

View file

@ -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
*/