Commit 66887c22 authored by louiz’'s avatar louiz’

Add a few tests

parent 73fd710c
......@@ -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);
}
......@@ -26,5 +26,7 @@ TEST_CASE("Database")
CHECK(b.pass == "");
CHECK(b.pass.value() == "");
Database::close();
#endif
}
#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");
}
}
}
......@@ -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");
}
}
......@@ -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) == "&apos;coucou&apos;&lt;cc&gt;/&amp;&quot;gaga&quot;");
CHECK(xml_unescape(xml_escape(unescaped)) == unescaped);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment