comparison tests/libserver/dao-account/main.cpp @ 39:56ab2f0c90dc

Server: add sqlite basic backend, closes #558
author David Demelier <markand@malikania.fr>
date Sun, 27 Nov 2016 18:00:49 +0100
parents d4f5f7231b84
children a47a4477f347
comparison
equal deleted inserted replaced
38:ecf316d52f5d 39:56ab2f0c90dc
26 #include <malikania/dao-account.hpp> 26 #include <malikania/dao-account.hpp>
27 #include <malikania/database.hpp> 27 #include <malikania/database.hpp>
28 28
29 using namespace malikania; 29 using namespace malikania;
30 30
31 class TestAccountDao : public testing::Test { 31 #include "test-sqlite.hpp"
32 protected:
33 Database m_database;
34 AccountDao m_dao;
35
36 public:
37 TestAccountDao()
38 : m_database(DRIVERDIR "pgsql.so", {
39 { "host", WITH_TEST_PGSQL_HOST },
40 { "port", WITH_TEST_PGSQL_PORT },
41 { "user", WITH_TEST_PGSQL_USER },
42 { "database", WITH_TEST_PGSQL_DATABASE }
43 })
44 , m_dao(m_database)
45 {
46 m_dao.clear();
47
48 assert(m_dao.count() == 0U);
49 }
50 };
51
52 TEST_F(TestAccountDao, create)
53 {
54 try {
55 Account ac;
56
57 ac.setName("jean");
58 ac.setEmail("jean@christophe.fr");
59 ac.setFirstName("Jean");
60 ac.setLastName("Christophe");
61 ac.setPassword("raw");
62
63 m_dao.create(ac);
64
65 ASSERT_EQ(1U, m_dao.count());
66 ASSERT_EQ(ac, m_dao.list()[0]);
67 } catch (const std::exception &ex) {
68 FAIL() << ex.what();
69 }
70 }
71
72 TEST_F(TestAccountDao, update)
73 {
74 try {
75 Account ac;
76
77 ac.setName("jean");
78 ac.setEmail("jean@christophe.fr");
79 ac.setFirstName("Jean");
80 ac.setLastName("Christophe");
81 ac.setPassword("raw");
82
83 m_dao.create(ac);
84
85 ac.setEmail("benoit@christophe.fr");
86 ac.setFirstName("Benoit");
87
88 m_dao.update(ac);
89
90 Account ac2 = m_dao.get(ac.id());
91
92 ASSERT_EQ("jean", ac2.name());
93 ASSERT_EQ("benoit@christophe.fr", ac2.email());
94 ASSERT_EQ("Benoit", ac2.firstName());
95 } catch (const std::exception &ex) {
96 FAIL() << ex.what();
97 }
98 }
99 32
100 int main(int argc, char **argv) 33 int main(int argc, char **argv)
101 { 34 {
102 testing::InitGoogleTest(&argc, argv); 35 testing::InitGoogleTest(&argc, argv);
103 36