diff options
author | fiaxh <git@lightrise.org> | 2024-11-14 10:19:31 -0600 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2024-11-14 10:20:12 -0600 |
commit | 909f569318835d11703c49fba7dbe49996759f38 (patch) | |
tree | 24616308c4f6d7a8fa34a2c08de29fda317ba726 /xmpp-vala/tests | |
parent | a6554e81c5cd766b0936e4dd3c46cd6131a3cc8b (diff) | |
download | dino-909f569318835d11703c49fba7dbe49996759f38.tar.gz dino-909f569318835d11703c49fba7dbe49996759f38.zip |
xmpp-vala: StanzaNode.get_attribute_int: Return default value if not parsable as int
Diffstat (limited to 'xmpp-vala/tests')
-rw-r--r-- | xmpp-vala/tests/stanza.vala | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/xmpp-vala/tests/stanza.vala b/xmpp-vala/tests/stanza.vala index cd374912..fa1ccb41 100644 --- a/xmpp-vala/tests/stanza.vala +++ b/xmpp-vala/tests/stanza.vala @@ -7,6 +7,7 @@ class StanzaTest : Gee.TestCase { 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); }); + add_test("get_attribute_(u)int", test_get_attribute_int); } private async void test_node_one(Gee.TestFinishedCallback cb) { @@ -112,6 +113,25 @@ class StanzaTest : Gee.TestCase { cb(); } + private void test_get_attribute_int() { + var stanza_node = new StanzaNode.build("test", "ns").add_self_xmlns().put_attribute("bar", "42"); + assert(stanza_node.get_attribute_int("bar", -2) == 42); + assert(stanza_node.get_attribute_uint("bar", 3) == 42); + + stanza_node = new StanzaNode.build("test", "ns").add_self_xmlns().put_attribute("bar", "-42"); + assert(stanza_node.get_attribute_int("bar", -2) == -42); + assert(stanza_node.get_attribute_uint("bar", 3) == 3); + + stanza_node = new StanzaNode.build("test", "ns").add_self_xmlns(); + assert(stanza_node.get_attribute_int("bar", -2) == -2); + assert(stanza_node.get_attribute_uint("bar", 3) == 3); + + stanza_node = new StanzaNode.build("test", "ns").add_self_xmlns().put_attribute("bar", "str"); + assert(stanza_node.get_attribute_int("bar", -2) == -2); + assert(stanza_node.get_attribute_uint("bar", 3) == 3); + + } + } } |