Mercurial > malikania
view tests/libserver/dao-account/test.hpp @ 77:61ea80e925ab
CMake: import pugixml 1.8, closes #613
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 20 Jan 2017 11:00:14 +0100 |
parents | a47a4477f347 |
children |
line wrap: on
line source
class @TEST_CLASS_NAME@ : public testing::Test { protected: mlk::database m_database; mlk::account_dao m_dao; std::string kind() { static const std::string name = "@TEST_CLASS_NAME@"; return name; } std::unordered_map<std::string, std::string> parameters() { assert(kind() == "TestAccountSqlite"); if (kind() == "TestAccountSqlite") { return {{ "path", "@test-dao-account_BINARY_DIR@/test-account-dao.db" }}; } return {}; } std::string file() { assert(kind() == "TestAccountSqlite"); if (kind() == "TestAccountSqlite") { return DRIVERDIR "sqlite.so"; } return ""; } public: @TEST_CLASS_NAME@() : m_database(file(), parameters()) , m_dao(m_database) { m_dao.clear(); assert(m_dao.count() == 0U); } }; TEST_F(@TEST_CLASS_NAME@, create) { try { mlk::account ac; ac.name = "jean"; ac.email = "jean@christophe.fr"; ac.first_name = "Jean"; ac.last_name = "Christophe"; ac.password = "raw"; m_dao.create(ac); ASSERT_EQ(1U, m_dao.count()); ASSERT_EQ(ac, m_dao.list()[0]); } catch (const std::exception &ex) { FAIL() << ex.what(); } } TEST_F(@TEST_CLASS_NAME@, update) { try { mlk::account ac; ac.name = "jean"; ac.email = "jean@christophe.fr"; ac.first_name = "Jean"; ac.last_name = "Christophe"; ac.password = "raw"; m_dao.create(ac); ac.email = "benoit@christophe.fr"; ac.first_name = "Benoit"; m_dao.update(ac); mlk::account ac2 = m_dao.get(ac.id); ASSERT_EQ("jean", ac2.name); ASSERT_EQ("benoit@christophe.fr", ac2.email); ASSERT_EQ("Benoit", ac2.first_name); } catch (const std::exception &ex) { FAIL() << ex.what(); } }