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/database.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/database.cpp (limited to 'tests/database.cpp') diff --git a/tests/database.cpp b/tests/database.cpp new file mode 100644 index 0000000..fd9e873 --- /dev/null +++ b/tests/database.cpp @@ -0,0 +1,30 @@ +#include "catch.hpp" + +#include + +#include +#include + +TEST_CASE("Database") +{ +#ifdef USE_DATABASE + // Remove any potential existing db + ::unlink("./test.db"); + Config::set("db_name", "test.db"); + Database::set_verbose(false); + auto o = Database::get_irc_server_options("zouzou@example.com", "irc.example.com"); + o.update(); + auto a = Database::get_irc_server_options("zouzou@example.com", "irc.example.com"); + auto b = Database::get_irc_server_options("moumou@example.com", "irc.example.com"); + + // b does not yet exist in the db, the object is created but not yet + // inserted + CHECK(1 == Database::count()); + + b.update(); + CHECK(2 == Database::count()); + + CHECK(b.pass == ""); + CHECK(b.pass.value() == ""); +#endif +} -- 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/database.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/database.cpp') 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 } -- cgit v1.2.3 From 4dd01a29caff8a1712478cb20e9137453367da07 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sat, 31 Oct 2015 05:35:59 +0100 Subject: Run the database tests with an in-memory sqlite db --- tests/database.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'tests/database.cpp') diff --git a/tests/database.cpp b/tests/database.cpp index c248568..c0f4e9f 100644 --- a/tests/database.cpp +++ b/tests/database.cpp @@ -2,15 +2,12 @@ #include -#include #include TEST_CASE("Database") { #ifdef USE_DATABASE - // Remove any potential existing db - ::unlink("./test.db"); - Config::set("db_name", "test.db"); + Config::set("db_name", ":memory:"); Database::set_verbose(false); auto o = Database::get_irc_server_options("zouzou@example.com", "irc.example.com"); o.update(); -- cgit v1.2.3 From 421c960df501b40e836a783400ab00dc60c3fdae Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Thu, 24 Dec 2015 21:39:53 +0100 Subject: Add a ChannelOptions table in the DB And a way to retrieve its values, defaulting on the ServerOptions for unset values. --- tests/database.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 11 deletions(-) (limited to 'tests/database.cpp') diff --git a/tests/database.cpp b/tests/database.cpp index c0f4e9f..5d557fd 100644 --- a/tests/database.cpp +++ b/tests/database.cpp @@ -9,20 +9,82 @@ TEST_CASE("Database") #ifdef USE_DATABASE Config::set("db_name", ":memory:"); Database::set_verbose(false); - auto o = Database::get_irc_server_options("zouzou@example.com", "irc.example.com"); - o.update(); - auto a = Database::get_irc_server_options("zouzou@example.com", "irc.example.com"); - auto b = Database::get_irc_server_options("moumou@example.com", "irc.example.com"); - // b does not yet exist in the db, the object is created but not yet - // inserted - CHECK(1 == Database::count()); + SECTION("Basic retrieve and update") + { + auto o = Database::get_irc_server_options("zouzou@example.com", "irc.example.com"); + o.update(); + auto a = Database::get_irc_server_options("zouzou@example.com", "irc.example.com"); + auto b = Database::get_irc_server_options("moumou@example.com", "irc.example.com"); - b.update(); - CHECK(2 == Database::count()); + // b does not yet exist in the db, the object is created but not yet + // inserted + CHECK(1 == Database::count()); - CHECK(b.pass == ""); - CHECK(b.pass.value() == ""); + b.update(); + CHECK(2 == Database::count()); + + CHECK(b.pass == ""); + CHECK(b.pass.value() == ""); + } + + SECTION("channel options") + { + Config::set("db_name", ":memory:"); + auto o = Database::get_irc_channel_options("zouzou@example.com", "irc.example.com", "#foo"); + + CHECK(o.encodingIn == ""); + o.encodingIn = "ISO-8859-1"; + o.update(); + auto b = Database::get_irc_channel_options("zouzou@example.com", "irc.example.com", "#foo"); + CHECK(o.encodingIn == "ISO-8859-1"); + } + + SECTION("Channel options with server default") + { + const std::string owner{"zouzou@example.com"}; + const std::string server{"irc.example.com"}; + const std::string chan1{"#foo"}; + + auto c = Database::get_irc_channel_options(owner, server, chan1); + auto s = Database::get_irc_server_options(owner, server); + + GIVEN("An option defined for the channel but not the server") + { + c.encodingIn = "channelEncoding"; + c.update(); + WHEN("we fetch that option") + { + auto r = Database::get_irc_channel_options_with_server_default(owner, server, chan1); + THEN("we get the channel option") + CHECK(r.encodingIn == "channelEncoding"); + } + } + GIVEN("An option defined for the server but not the channel") + { + s.encodingIn = "serverEncoding"; + s.update(); + WHEN("we fetch that option") + { + auto r = Database::get_irc_channel_options_with_server_default(owner, server, chan1); + THEN("we get the server option") + CHECK(r.encodingIn == "serverEncoding"); + } + } + GIVEN("An option defined for both the server and the channel") + { + s.encodingIn = "serverEncoding"; + s.update(); + c.encodingIn = "channelEncoding"; + c.update(); + WHEN("we fetch that option") + { + auto r = Database::get_irc_channel_options_with_server_default(owner, server, chan1); + THEN("we get the channel option") + CHECK(r.encodingIn == "channelEncoding"); + } + } + } Database::close(); #endif -- cgit v1.2.3 From 79cdf170d2ab6c5378cfbf61d5c8888a4c666190 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Mon, 28 Dec 2015 21:25:48 +0100 Subject: Use the configured encoding value when decoding received messages --- tests/database.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests/database.cpp') diff --git a/tests/database.cpp b/tests/database.cpp index 5d557fd..b059d0d 100644 --- a/tests/database.cpp +++ b/tests/database.cpp @@ -83,6 +83,12 @@ TEST_CASE("Database") THEN("we get the channel option") CHECK(r.encodingIn == "channelEncoding"); } + WHEN("we fetch that option, with no channel specified") + { + auto r = Database::get_irc_channel_options_with_server_default(owner, server, ""); + THEN("we get the server option") + CHECK(r.encodingIn == "serverEncoding"); + } } } -- cgit v1.2.3 From 4c1b9abe7e230a39b119bdc45ebcd5e677fad488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 12 Jul 2016 00:31:57 +0200 Subject: Properly catch and handle database errors Do not use a singleton for the database. fix #3203 --- tests/database.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/database.cpp') diff --git a/tests/database.cpp b/tests/database.cpp index b059d0d..4e2be14 100644 --- a/tests/database.cpp +++ b/tests/database.cpp @@ -7,7 +7,7 @@ TEST_CASE("Database") { #ifdef USE_DATABASE - Config::set("db_name", ":memory:"); + Database::open(":memory:"); Database::set_verbose(false); SECTION("Basic retrieve and update") -- cgit v1.2.3