comparison tests/libserver/dao-account/main.cpp @ 29:99792c6c8b06

Server: add initial postgresql account management, #475
author David Demelier <markand@malikania.fr>
date Thu, 26 May 2016 07:32:05 +0200
parents
children a1e80d991968
comparison
equal deleted inserted replaced
28:80736513d699 29:99792c6c8b06
1 /*
2 * main.cpp -- test AccountDao
3 *
4 * Copyright (c) 2013-2016 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <cassert>
20
21 #include <gtest/gtest.h>
22
23 #include <sysconfig-tests.h>
24
25 #include <malikania/account.h>
26 #include <malikania/dao-account.h>
27 #include <malikania/database.h>
28
29 using namespace malikania;
30
31 class TestAccountDao : public testing::Test {
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
100 int main(int argc, char **argv)
101 {
102 testing::InitGoogleTest(&argc, argv);
103
104 return RUN_ALL_TESTS();
105 }