aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/tests/stanza.vala
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2020-06-27 11:23:22 +0200
committerMarvin W <git@larma.de>2020-06-28 11:53:43 +0200
commit8f8018ec81d4ea6e6a5e2f3d811daa57a31f6122 (patch)
tree9bfcf2e8812293a80bdfefd6872ccb7e93a79536 /xmpp-vala/tests/stanza.vala
parent717d0b7fcaede5688a236af847d518be4a8f0c6b (diff)
downloaddino-8f8018ec81d4ea6e6a5e2f3d811daa57a31f6122.tar.gz
dino-8f8018ec81d4ea6e6a5e2f3d811daa57a31f6122.zip
Fix async tests
Diffstat (limited to 'xmpp-vala/tests/stanza.vala')
-rw-r--r--xmpp-vala/tests/stanza.vala32
1 files changed, 23 insertions, 9 deletions
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 = """
<?xml version='1.0' encoding='UTF-8'?>
<stream:stream
@@ -50,16 +51,28 @@ class StanzaTest : Gee.TestCase {
.put_attribute("to", "juliet@example.com")
.put_attribute("lang", "en", XML_URI)
.put_node(new StanzaNode.build("body")
- .put_node(new StanzaNode.text("I'll send a friar with speed, to Mantua, with my letters to thy lord.")));
+ .put_node(new StanzaNode.text(" I'll send a friar with speed, to Mantua, with my letters to thy lord.")));
var reader = new StanzaReader.for_string(stream);
fail_if_not_eq_node(root_node_cmp, yield reader.read_root_node());
fail_if_not_eq_node(node_cmp, yield reader.read_node());
yield reader.read_node();
- fail_if_not_error_code(() => 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 = """
<?xml version='1.0' encoding='UTF-8'?>
<stream:stream
@@ -95,7 +108,8 @@ class StanzaTest : Gee.TestCase {
fail_if_not_eq_node(node_cmp, yield reader.read_node());
fail_if_not_eq_node(node2_cmp, yield reader.read_node());
yield reader.read_node();
- fail_if_not_error_code(() => reader.read_node(), 3, "end of stream should be reached");
+ yield fail_if_not_end_of_stream(reader);
+ cb();
}
}