[folks] tests: Enable required BlueZ devices during unit tests
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] tests: Enable required BlueZ devices during unit tests
- Date: Sun, 2 Jul 2017 19:57:45 +0000 (UTC)
commit f000f335174aed3d128b0b79909085474d475ec8
Author: Philip Withnall <withnall endlessm com>
Date: Sun Jul 2 20:52:04 2017 +0100
tests: Enable required BlueZ devices during unit tests
Since the BlueZ backend has gained the ability to enable and disable
devices based on their Bluetooth address, and to load that state from a
file, the unit tests were broken because all devices are disabled by
default. Fix the tests by writing out a mock configuration file which
enables the mock devices we want to use.
Signed-off-by: Philip Withnall <withnall endlessm com>
tests/lib/bluez/test-case.vala | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/tests/lib/bluez/test-case.vala b/tests/lib/bluez/test-case.vala
index 390147e..d11f7b0 100644
--- a/tests/lib/bluez/test-case.vala
+++ b/tests/lib/bluez/test-case.vala
@@ -47,6 +47,20 @@ public class BluezTest.TestCase : Folks.TestCase
Environment.set_variable ("FOLKS_BLUEZ_TIMEOUT_DIVISOR", "100", true);
}
+ public override string create_transient_dir ()
+ {
+ var transient = base.create_transient_dir ();
+
+ /* Evolution configuration directory. */
+ var config_dir = Path.build_filename (transient, ".local", "share", "folks");
+
+ if (GLib.DirUtils.create_with_parents (config_dir, 0700) != 0)
+ error ("Unable to create ‘%s’: %s",
+ config_dir, GLib.strerror (GLib.errno));
+
+ return transient;
+ }
+
/**
* {@inheritDoc}
*
@@ -87,6 +101,25 @@ public class BluezTest.TestCase : Folks.TestCase
public virtual void create_backend ()
{
this.bluez_backend = new BluezTest.Backend ();
+
+ /* Whitelist any mock BlueZ devices we will create. */
+ var devices_file_name =
+ Path.build_filename (this.transient_dir, ".local", "share", "folks",
+ "bluez-persona-stores.ini");
+ var devices_file = ("[%s]\n" +
+ "enabled=true\n").printf (((!) this.bluez_backend).primary_device_address);
+
+ GLib.debug ("Creating device enabled file for ‘%s’ at %s", ((!)
this.bluez_backend).primary_device_address, devices_file_name);
+ try
+ {
+ FileUtils.set_contents (devices_file_name, devices_file);
+ }
+ catch (FileError e1)
+ {
+ error ("Error creating BlueZ backend configuration file ‘%s’: %s",
+ devices_file_name, e1.message);
+ }
+
((!) this.bluez_backend).set_up ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]