diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/config.cpp | 29 | ||||
-rw-r--r-- | tests/database.cpp | 2 | ||||
-rw-r--r-- | tests/logger.cpp | 50 | ||||
-rw-r--r-- | tests/utils.cpp | 18 | ||||
-rw-r--r-- | tests/xmpp.cpp | 3 |
5 files changed, 101 insertions, 1 deletions
diff --git a/tests/config.cpp b/tests/config.cpp index 1419f0b..346dea1 100644 --- a/tests/config.cpp +++ b/tests/config.cpp @@ -23,3 +23,32 @@ TEST_CASE("Config basic") } CHECK_FALSE(error); } + +TEST_CASE("Config callbacks") +{ + bool switched = false; + Config::connect([&switched]() + { + switched = !switched; + }); + CHECK_FALSE(switched); + Config::set("un", "deux", true); + CHECK(switched); + Config::set("un", "trois", true); + CHECK_FALSE(switched); + + Config::set("un", "trois", false); + CHECK_FALSE(switched); +} + +TEST_CASE("Config get_int") +{ + auto res = Config::get_int("number", 0); + CHECK(res == 0); + Config::set("number", "88"); + res = Config::get_int("number", 0); + CHECK(res == 88); + Config::set("number", "pouet"); + res = Config::get_int("number", -1); + CHECK(res == 0); +} diff --git a/tests/database.cpp b/tests/database.cpp index fd9e873..c248568 100644 --- a/tests/database.cpp +++ b/tests/database.cpp @@ -26,5 +26,7 @@ TEST_CASE("Database") CHECK(b.pass == ""); CHECK(b.pass.value() == ""); + + Database::close(); #endif } diff --git a/tests/logger.cpp b/tests/logger.cpp new file mode 100644 index 0000000..d4fb055 --- /dev/null +++ b/tests/logger.cpp @@ -0,0 +1,50 @@ +#include "catch.hpp" + +#include <logger/logger.hpp> +#include <config/config.hpp> + +#include "io_tester.hpp" +#include <iostream> + +using namespace std::string_literals; + +TEST_CASE("Basic logging") +{ + Logger::instance().reset(); + GIVEN("A logger with log_level 0") + { + Config::set("log_level", "0"); + WHEN("we log some debug text") + { + IoTester<std::ostream> out(std::cout); + log_debug("debug"); + THEN("debug logs are written") + CHECK(out.str() == "<7>tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\tdebug\n"); + } + WHEN("we log some errors") + { + IoTester<std::ostream> out(std::cout); + log_error("error"); + THEN("error logs are written") + CHECK(out.str() == "<3>tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\terror\n"); + } + } + GIVEN("A logger with log_level 3") + { + Config::set("log_level", "3"); + WHEN("we log some debug text") + { + IoTester<std::ostream> out(std::cout); + log_debug("debug"); + THEN("nothing is written") + CHECK(out.str().empty()); + } + WHEN("we log some errors") + { + IoTester<std::ostream> out(std::cout); + log_error("error"); + THEN("error logs are still written") + CHECK(out.str() == "<3>tests/logger.cpp:" + std::to_string(__LINE__ - 2) + ":\terror\n"); + } + } +} diff --git a/tests/utils.cpp b/tests/utils.cpp index 6e3c32a..8691910 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -5,6 +5,7 @@ #include <utils/string.hpp> #include <utils/split.hpp> #include <utils/xdg.hpp> +#include <utils/empty_if_fixed_server.hpp> TEST_CASE("String split") { @@ -70,3 +71,20 @@ TEST_CASE("xdg_*_path") CHECK(res == "/datadir/biboumi/bonjour.txt"); } } + +TEST_CASE("empty if fixed irc server") +{ + GIVEN("A config with fixed_irc_server") + { + Config::set("fixed_irc_server", "irc.localhost"); + THEN("our string is made empty") + CHECK(utils::empty_if_fixed_server("coucou coucou") == ""); + } + GIVEN("A config with NO fixed_irc_server") + { + Config::set("fixed_irc_server", ""); + THEN("our string is returned untouched") + CHECK(utils::empty_if_fixed_server("coucou coucou") == "coucou coucou"); + } + +} 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); } - |