From 43d690d0aa4ceb6702cc179c5f75d10bcfeb8f72 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 4 Oct 2012 00:50:38 +0100 Subject: [PATCH] tests: Fix creation/deletion of E.Sources in EDS test backend MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The E.Sources for testing were being created by calling `cp` in the wrapper script running around the entire test suite. However, each test case was tearing down the E.Sources by deleting them. This meant that no E.Source existed for anything except the first test case in a given test suite. The fix is to move the file copying inside the test suite’s setup method. --- tests/lib/eds/backend.vala | 59 +++++++++++++++++++++++++++++++++++++++------- tests/tools/Makefile.am | 2 -- tests/tools/eds.sh | 2 -- tests/tools/other.source | 6 ----- tests/tools/test.source | 6 ----- 5 files changed, 51 insertions(+), 24 deletions(-) delete mode 100644 tests/tools/other.source delete mode 100644 tests/tools/test.source diff --git a/tests/lib/eds/backend.vala b/tests/lib/eds/backend.vala index 738deea..788e703 100644 --- a/tests/lib/eds/backend.vala +++ b/tests/lib/eds/backend.vala @@ -38,11 +38,12 @@ errordomain EdsTest.BackendSetupError public class EdsTest.Backend { private string _addressbook_name; - private E.BookClient _addressbook; + private E.BookClient? _addressbook = null; private GLib.List _e_contacts; private GLib.List> _contacts; E.SourceRegistry _source_registry; - E.Source _source; + E.Source? _source = null; + File? _source_file = null; public string address_book_uid { @@ -127,25 +128,65 @@ public class EdsTest.Backend { var mainloop = new GLib.MainLoop (null, false); - create_source_registry.begin (null, (obj, async_res) => + this._prepare_source_async.begin (is_default, (obj, async_res) => { try { - this._source_registry = create_source_registry.end (async_res); + this._prepare_source_async.end (async_res); + mainloop.quit (); } catch (GLib.Error e) { GLib.critical (e.message); } - mainloop.quit(); }); - mainloop.run(); + mainloop.run (); + } + + private async void _prepare_source_async (bool is_default) throws GLib.Error + { + /* Create a new source file. */ + var source_file_name = this._addressbook_name + ".source"; + + var config_dir = File.new_for_path (Environment.get_user_config_dir ()); + var source_file = config_dir.get_child ("evolution") + .get_child ("sources").get_child (source_file_name); + + var source_file_content = ("[Data Source]\n" + + "DisplayName=%s\n" + + "Parent=local-stub\n" + + "\n" + + "[Address Book]\n" + + "BackendName=local").printf (this._addressbook_name); + + /* Build a SourceRegistry to manage the sources. */ + this._source_registry = yield create_source_registry (null); + var signal_id = this._source_registry.source_added.connect ((r, s) => + { + this._source = s; + this._prepare_source_async.callback (); + }); + /* Perform the write and then wait for the SourceRegistry to notify. */ + yield source_file.replace_contents_async (source_file_content.data, null, + false, FileCreateFlags.NONE, null, null); this._source = this._source_registry.ref_source (this._addressbook_name); + if (this._source == null) + { + yield; + } + + /* Sanity check then tidy up. */ + assert (this._source != null); + this._source_registry.disconnect (signal_id); + + this._source_file = source_file; if (is_default) - this.set_as_default(); + { + this.set_as_default (); + } } public async void commit_contacts_to_addressbook () @@ -276,7 +317,7 @@ public class EdsTest.Backend try { - this._source.remove_sync (null); + this._source_file.delete (); } catch (GLib.Error e) { @@ -285,6 +326,8 @@ public class EdsTest.Backend } finally { + this._source_file = null; + this._source = null; this._addressbook = null; } } diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am index 04a2373..e98f35b 100644 --- a/tests/tools/Makefile.am +++ b/tests/tools/Makefile.am @@ -7,8 +7,6 @@ EXTRA_DIST = \ with-session-bus-eds.sh \ with-session-bus-tracker.sh \ tracker.sh \ - test.source \ - other.source \ $(NULL) -include $(top_srcdir)/git.mk diff --git a/tests/tools/eds.sh b/tests/tools/eds.sh index db9d3f8..e482144 100644 --- a/tests/tools/eds.sh +++ b/tests/tools/eds.sh @@ -19,8 +19,6 @@ eds_init_settings () { export XDG_CACHE_HOME=$eds_tmpdir/.cache export XDG_CONFIG_HOME=$eds_tmpdir/.config mkdir -p $XDG_CONFIG_HOME/evolution/sources - cp $cur_dir/test.source $XDG_CONFIG_HOME/evolution/sources/ - cp $cur_dir/other.source $XDG_CONFIG_HOME/evolution/sources/ } eds_start () { diff --git a/tests/tools/other.source b/tests/tools/other.source deleted file mode 100644 index f170f40..0000000 --- a/tests/tools/other.source +++ /dev/null @@ -1,6 +0,0 @@ -[Data Source] -DisplayName=Other Test Address Book -Parent=local-stub - -[Address Book] -BackendName=local diff --git a/tests/tools/test.source b/tests/tools/test.source deleted file mode 100644 index 2ad3dfb..0000000 --- a/tests/tools/test.source +++ /dev/null @@ -1,6 +0,0 @@ -[Data Source] -DisplayName=Test Address Book -Parent=local-stub - -[Address Book] -BackendName=local -- 2.7.4