From 50cadf3dac0d56ef8181d1800cc30f8dcb749141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 13 Jun 2017 10:38:39 +0200 Subject: Implement our own database ORM, and update the whole code to use it Entirely replace LiteSQL fix #3271 --- tests/database.cpp | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'tests') diff --git a/tests/database.cpp b/tests/database.cpp index 4e2be14..47dfd7c 100644 --- a/tests/database.cpp +++ b/tests/database.cpp @@ -8,24 +8,22 @@ TEST_CASE("Database") { #ifdef USE_DATABASE Database::open(":memory:"); - Database::set_verbose(false); SECTION("Basic retrieve and update") { auto o = Database::get_irc_server_options("zouzou@example.com", "irc.example.com"); - o.update(); + o.save(Database::db); 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()); + CHECK(1 == Database::count(Database::irc_server_options)); - b.update(); - CHECK(2 == Database::count()); + b.save(Database::db); + CHECK(2 == Database::count(Database::irc_server_options)); - CHECK(b.pass == ""); - CHECK(b.pass.value() == ""); + CHECK(b.col() == ""); } SECTION("channel options") @@ -33,16 +31,16 @@ TEST_CASE("Database") 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(); + CHECK(o.col() == ""); + o.col() = "ISO-8859-1"; + o.save(Database::db); auto b = Database::get_irc_channel_options("zouzou@example.com", "irc.example.com", "#foo"); - CHECK(o.encodingIn == "ISO-8859-1"); + CHECK(o.col() == "ISO-8859-1"); } SECTION("Channel options with server default") { - const std::string owner{"zouzou@example.com"}; + const std::string owner{"CACA@example.com"}; const std::string server{"irc.example.com"}; const std::string chan1{"#foo"}; @@ -51,43 +49,43 @@ TEST_CASE("Database") GIVEN("An option defined for the channel but not the server") { - c.encodingIn = "channelEncoding"; - c.update(); + c.col() = "channelEncoding"; + c.save(Database::db); 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"); + CHECK(r.col() == "channelEncoding"); } } GIVEN("An option defined for the server but not the channel") { - s.encodingIn = "serverEncoding"; - s.update(); + s.col() = "serverEncoding"; + s.save(Database::db); 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"); + CHECK(r.col() == "serverEncoding"); } } GIVEN("An option defined for both the server and the channel") { - s.encodingIn = "serverEncoding"; - s.update(); - c.encodingIn = "channelEncoding"; - c.update(); + s.col() = "serverEncoding"; + s.save(Database::db); + c.col() = "channelEncoding"; + c.save(Database::db); 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"); + CHECK(r.col() == "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"); + CHECK(r.col() == "serverEncoding"); } } } -- cgit v1.2.3 From 369ccb037619871403b14c959bbb359332133810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 13 Jun 2017 11:18:05 +0200 Subject: Add default values for the database columns --- tests/end_to_end/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py index f9e04a8..8f108ee 100644 --- a/tests/end_to_end/__main__.py +++ b/tests/end_to_end/__main__.py @@ -2417,7 +2417,7 @@ if __name__ == '__main__': "/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='username']", "/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='realname']", "/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='encoding_in']", - "/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='encoding_out']/dataform:value[text()='ISO-8859-1']", + "/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-single'][@var='encoding_out']", "/iq/commands:command/commands:actions/commands:next", ), after = partial(save_value, "sessionid", partial(extract_attribute, "/iq[@type='result']/commands:command[@node='configure']", "sessionid")) -- cgit v1.2.3