Add API for (de)serialising FolderPath and EmailIdentifier

Supports (de)serialising via GLib.Variant for use as GLib.Action targets
transmission via DBus, etc.
This commit is contained in:
Michael James Gratton 2018-01-03 15:01:21 +11:00
parent f269e552ae
commit dd3a7a1bc8
14 changed files with 251 additions and 13 deletions

View file

@ -120,6 +120,21 @@ public class Geary.MockAccount : Account, MockObject {
}
}
public override EmailIdentifier to_email_identifier(GLib.Variant serialised)
throws EngineError.BAD_PARAMETERS {
try {
return object_or_throw_call(
"to_email_identifier",
{ box_arg(serialised) },
new EngineError.BAD_PARAMETERS("Mock error")
);
} catch (EngineError.BAD_PARAMETERS err) {
throw err;
} catch (GLib.Error err) {
return new MockEmailIdentifer(0);
}
}
public override Gee.Collection<Folder> list_folders() throws Error {
return object_call<Gee.Collection<Folder>>(
"list_folders", {}, Gee.List.empty<Folder>()

View file

@ -21,4 +21,8 @@ public class Geary.MockEmailIdentifer : EmailIdentifier {
return (other_mock == null) ? 1 : this.id - other_mock.id;
}
public override GLib.Variant to_variant() {
return new GLib.Variant.int32(id);
}
}

View file

@ -26,6 +26,7 @@ public class Geary.FolderPathTest : TestCase {
add_test("path_compare", path_compare);
add_test("path_compare_normalised", path_compare_normalised);
add_test("distinct_roots_compare", distinct_roots_compare);
add_test("variant_representation", variant_representation);
}
public override void set_up() {
@ -305,4 +306,12 @@ public class Geary.FolderPathTest : TestCase {
}
public void variant_representation() throws GLib.Error {
FolderPath orig = this.root.get_child("test");
GLib.Variant variant = orig.to_variant();
FolderPath copy = this.root.from_variant(variant);
assert_true(orig.equal_to(copy));
}
}