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/jid.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/jid.cpp (limited to 'tests/jid.cpp') diff --git a/tests/jid.cpp b/tests/jid.cpp new file mode 100644 index 0000000..9015afd --- /dev/null +++ b/tests/jid.cpp @@ -0,0 +1,39 @@ +#include "catch.hpp" + +#include +#include + +TEST_CASE("Jid") +{ + Jid jid1("♥@ツ.coucou/coucou@coucou/coucou"); + CHECK(jid1.local == "♥"); + CHECK(jid1.domain == "ツ.coucou"); + CHECK(jid1.resource == "coucou@coucou/coucou"); + + // Domain and resource + Jid jid2("ツ.coucou/coucou@coucou/coucou"); + CHECK(jid2.local == ""); + CHECK(jid2.domain == "ツ.coucou"); + CHECK(jid2.resource == "coucou@coucou/coucou"); + + // Jidprep + const std::string badjid("~zigougou™@EpiK-7D9D1FDE.poez.io/Boujour/coucou/slt™"); + const std::string correctjid = jidprep(badjid); +#ifdef LIBIDN_FOUND + CHECK(correctjid == "~zigougoutm@epik-7d9d1fde.poez.io/Boujour/coucou/sltTM"); + // Check that the cache does not break things when we prep the same string + // multiple times + CHECK(jidprep(badjid) == "~zigougoutm@epik-7d9d1fde.poez.io/Boujour/coucou/sltTM"); + CHECK(jidprep(badjid) == "~zigougoutm@epik-7d9d1fde.poez.io/Boujour/coucou/sltTM"); + + const std::string badjid2("Zigougou@poez.io"); + const std::string correctjid2 = jidprep(badjid2); + CHECK(correctjid2 == "zigougou@poez.io"); + + const std::string crappy("~Bisous@7ea8beb1:c5fd2849:da9a048e:ip"); + const std::string fixed_crappy = jidprep(crappy); + CHECK(fixed_crappy == "~bisous@7ea8beb1-c5fd2849-da9a048e-ip"); +#else // Without libidn, jidprep always returns an empty string + CHECK(jidprep(badjid) == ""); +#endif +} -- cgit v1.2.3