From 8f8018ec81d4ea6e6a5e2f3d811daa57a31f6122 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sat, 27 Jun 2020 11:23:22 +0200 Subject: Fix async tests --- xmpp-vala/tests/stanza.vala | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'xmpp-vala/tests/stanza.vala') diff --git a/xmpp-vala/tests/stanza.vala b/xmpp-vala/tests/stanza.vala index 13fc626f..19baef49 100644 --- a/xmpp-vala/tests/stanza.vala +++ b/xmpp-vala/tests/stanza.vala @@ -4,12 +4,12 @@ class StanzaTest : Gee.TestCase { public StanzaTest() { base("Stanza"); - add_test("node_one", () => { test_node_one.begin(); }); - add_test("typical_stream", () => { test_typical_stream.begin(); }); - add_test("ack_stream", () => { test_ack_stream.begin(); }); + add_async_test("node_one", (cb) => { test_node_one.begin(cb); }); + add_async_test("typical_stream", (cb) => { test_typical_stream.begin(cb); }); + add_async_test("ack_stream", (cb) => { test_ack_stream.begin(cb); }); } - private async void test_node_one() { + private async void test_node_one(Gee.TestCase.FinishCallback cb) { var node1 = new StanzaNode.build("test", "ns1_uri") .add_self_xmlns() .put_attribute("ns2", "ns2_uri", XMLNS_URI) @@ -23,9 +23,10 @@ class StanzaTest : Gee.TestCase { var node2 = yield new StanzaReader.for_string(xml1).read_node(); fail_if_not(node1.equals(node2)); fail_if_not_eq_str(node1.to_string(), node2.to_string()); + cb(); } - private async void test_typical_stream() { + private async void test_typical_stream(Gee.TestCase.FinishCallback cb) { var stream = """ reader.read_node(), 3, "end of stream should be reached"); + yield fail_if_not_end_of_stream(reader); + cb(); } - private async void test_ack_stream() { + private async void fail_if_not_end_of_stream(StanzaReader reader) { + try { + yield reader.read_node(); + fail_if_reached("end of stream should be reached"); + } catch (XmlError.EOF e) { + return; + } catch (Error e) { + fail_if_reached("Unexpected error"); + } + } + + private async void test_ack_stream(Gee.TestCase.FinishCallback cb) { var stream = """ reader.read_node(), 3, "end of stream should be reached"); + yield fail_if_not_end_of_stream(reader); + cb(); } } -- cgit v1.2.3-54-g00ecf