summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2015-12-24 21:39:53 +0100
committerFlorent Le Coz <louiz@louiz.org>2016-01-04 13:47:26 +0100
commit421c960df501b40e836a783400ab00dc60c3fdae (patch)
treefb3b7be54a97f71102142aaa1901284c51c1854a /tests
parent9ac0d3a5766494c9c0c2074c4a21542eea195a29 (diff)
downloadbiboumi-421c960df501b40e836a783400ab00dc60c3fdae.tar.gz
biboumi-421c960df501b40e836a783400ab00dc60c3fdae.tar.bz2
biboumi-421c960df501b40e836a783400ab00dc60c3fdae.tar.xz
biboumi-421c960df501b40e836a783400ab00dc60c3fdae.zip
Add a ChannelOptions table in the DB
And a way to retrieve its values, defaulting on the ServerOptions for unset values.
Diffstat (limited to 'tests')
-rw-r--r--tests/database.cpp84
1 files changed, 73 insertions, 11 deletions
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<db::IrcServerOptions>());
+ 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<db::IrcServerOptions>());
+ // b does not yet exist in the db, the object is created but not yet
+ // inserted
+ CHECK(1 == Database::count<db::IrcServerOptions>());
- CHECK(b.pass == "");
- CHECK(b.pass.value() == "");
+ b.update();
+ CHECK(2 == Database::count<db::IrcServerOptions>());
+
+ 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