From 3c1889fbd0d7b96aae16f3479ac8aae70a7e15f7 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 28 Oct 2015 19:13:53 +0100 Subject: Use Catch for our test suite `make check` is also added to compile and run the tests Catch is fetched with cmake automatically into the build directory when needed --- tests/xmpp.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/xmpp.cpp (limited to 'tests/xmpp.cpp') diff --git a/tests/xmpp.cpp b/tests/xmpp.cpp new file mode 100644 index 0000000..46ecd35 --- /dev/null +++ b/tests/xmpp.cpp @@ -0,0 +1,47 @@ +#include "catch.hpp" + +#include + +TEST_CASE("Test basic XML parsing") +{ + XmppParser xml; + + const std::string doc = "innertail"; + + auto check_stanza = [](const Stanza& stanza) + { + CHECK(stanza.get_name() == "stanza"); + CHECK(stanza.get_tag("xmlns") == "stream_ns"); + CHECK(stanza.get_tag("b") == "c"); + CHECK(stanza.get_inner() == "inner"); + CHECK(stanza.get_tail() == ""); + CHECK(stanza.get_child("child1", "stream_ns") != nullptr); + CHECK(stanza.get_child("child2", "stream_ns") == nullptr); + CHECK(stanza.get_child("child2", "child2_ns") != nullptr); + CHECK(stanza.get_child("child2", "child2_ns")->get_tail() == "tail"); + }; + xml.add_stanza_callback([check_stanza](const Stanza& stanza) + { + check_stanza(stanza); + // Do the same checks on a copy of that stanza. + Stanza copy(stanza); + check_stanza(copy); + }); + xml.feed(doc.data(), doc.size(), true); + + const std::string doc2 = "coucou\r\n\a"; + xml.add_stanza_callback([](const Stanza& stanza) + { + CHECK(stanza.get_inner() == "coucou\r\n"); + }); + + xml.feed(doc2.data(), doc.size(), true); +} + +TEST_CASE("XML escape/unescape") +{ + const std::string unescaped = "'coucou'/&\"gaga\""; + CHECK(xml_escape(unescaped) == "'coucou'<cc>/&"gaga""); + CHECK(xml_unescape(xml_escape(unescaped)) == unescaped); +} + -- cgit v1.2.3 From 66887c225b63cecea62d17bcfae40cddef38c9d1 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sat, 31 Oct 2015 05:35:46 +0100 Subject: Add a few tests --- tests/xmpp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/xmpp.cpp') diff --git a/tests/xmpp.cpp b/tests/xmpp.cpp index 46ecd35..b6b50ed 100644 --- a/tests/xmpp.cpp +++ b/tests/xmpp.cpp @@ -26,6 +26,8 @@ TEST_CASE("Test basic XML parsing") // Do the same checks on a copy of that stanza. Stanza copy(stanza); check_stanza(copy); + // And do the same checks on moved-constructed stanza + Stanza moved(std::move(copy)); }); xml.feed(doc.data(), doc.size(), true); @@ -44,4 +46,3 @@ TEST_CASE("XML escape/unescape") CHECK(xml_escape(unescaped) == "'coucou'<cc>/&"gaga""); CHECK(xml_unescape(xml_escape(unescaped)) == unescaped); } - -- cgit v1.2.3 From 218260362f0ccb4fd5b51765d4bd331389f39baa Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Wed, 10 Feb 2016 20:22:51 +0100 Subject: Remove unused xml_unescape() function --- tests/xmpp.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/xmpp.cpp') diff --git a/tests/xmpp.cpp b/tests/xmpp.cpp index b6b50ed..6aab8c4 100644 --- a/tests/xmpp.cpp +++ b/tests/xmpp.cpp @@ -40,9 +40,8 @@ TEST_CASE("Test basic XML parsing") xml.feed(doc2.data(), doc.size(), true); } -TEST_CASE("XML escape/unescape") +TEST_CASE("XML escape") { const std::string unescaped = "'coucou'/&\"gaga\""; CHECK(xml_escape(unescaped) == "'coucou'<cc>/&"gaga""); - CHECK(xml_unescape(xml_escape(unescaped)) == unescaped); } -- cgit v1.2.3