From 909f569318835d11703c49fba7dbe49996759f38 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 14 Nov 2024 10:19:31 -0600 Subject: xmpp-vala: StanzaNode.get_attribute_int: Return default value if not parsable as int --- xmpp-vala/tests/stanza.vala | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'xmpp-vala/tests') 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); + + } + } } -- cgit v1.2.3-70-g09d2