OpenDNSSEC-enforcer 2.1.10
test_initialization.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014 Jerry Lundström <lundstrom.jerry@gmail.com>
3 * Copyright (c) 2014 .SE (The Internet Infrastructure Foundation).
4 * Copyright (c) 2014 OpenDNSSEC AB (svb)
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30#include "config.h"
31
32#include "../db_configuration.h"
33#include "../db_connection.h"
34
35#include "CUnit/Basic.h"
36
37static db_configuration_list_t* configuration_list = NULL;
38static db_configuration_t* configuration = NULL;
39static db_connection_t* connection = NULL;
40
42 if (configuration_list) {
43 return 1;
44 }
45 if (configuration) {
46 return 1;
47 }
48 if (connection) {
49 return 1;
50 }
51 return 0;
52}
53
55 db_connection_free(connection);
56 connection = NULL;
57 db_configuration_free(configuration);
58 configuration = NULL;
59 db_configuration_list_free(configuration_list);
60 configuration_list = NULL;
61 return 0;
62}
63
65 CU_ASSERT_PTR_NOT_NULL_FATAL((configuration_list = db_configuration_list_new()));
66
67#if defined(ENFORCER_DATABASE_SQLITE3)
68 CU_ASSERT_PTR_NOT_NULL_FATAL((configuration = db_configuration_new()));
69 CU_ASSERT_FATAL(!db_configuration_set_name(configuration, "backend"));
70 CU_ASSERT_FATAL(!db_configuration_set_value(configuration, "sqlite"));
71 CU_ASSERT_FATAL(!db_configuration_list_add(configuration_list, configuration));
72 configuration = NULL;
73
74 CU_ASSERT_PTR_NOT_NULL_FATAL((configuration = db_configuration_new()));
75 CU_ASSERT_FATAL(!db_configuration_set_name(configuration, "file"));
76 CU_ASSERT_FATAL(!db_configuration_set_value(configuration, "test.db"));
77 CU_ASSERT_FATAL(!db_configuration_list_add(configuration_list, configuration));
78 configuration = NULL;
79#endif
80
81#if defined(ENFORCER_DATABASE_MYSQL)
82 CU_ASSERT_PTR_NOT_NULL_FATAL((configuration = db_configuration_new()));
83 CU_ASSERT_FATAL(!db_configuration_set_name(configuration, "backend"));
84 CU_ASSERT_FATAL(!db_configuration_set_value(configuration, "mysql"));
85 CU_ASSERT_FATAL(!db_configuration_list_add(configuration_list, configuration));
86 configuration = NULL;
87
88 CU_ASSERT_PTR_NOT_NULL_FATAL((configuration = db_configuration_new()));
89 CU_ASSERT_FATAL(!db_configuration_set_name(configuration, "host"));
90 CU_ASSERT_FATAL(!db_configuration_set_value(configuration, ENFORCER_DB_HOST));
91 CU_ASSERT_FATAL(!db_configuration_list_add(configuration_list, configuration));
92 configuration = NULL;
93
94 CU_ASSERT_PTR_NOT_NULL_FATAL((configuration = db_configuration_new()));
95 CU_ASSERT_FATAL(!db_configuration_set_name(configuration, "port"));
96 CU_ASSERT_FATAL(!db_configuration_set_value(configuration, ENFORCER_DB_PORT_TEXT));
97 CU_ASSERT_FATAL(!db_configuration_list_add(configuration_list, configuration));
98 configuration = NULL;
99
100 CU_ASSERT_PTR_NOT_NULL_FATAL((configuration = db_configuration_new()));
101 CU_ASSERT_FATAL(!db_configuration_set_name(configuration, "user"));
102 CU_ASSERT_FATAL(!db_configuration_set_value(configuration, ENFORCER_DB_USERNAME));
103 CU_ASSERT_FATAL(!db_configuration_list_add(configuration_list, configuration));
104 configuration = NULL;
105
106 CU_ASSERT_PTR_NOT_NULL_FATAL((configuration = db_configuration_new()));
107 CU_ASSERT_FATAL(!db_configuration_set_name(configuration, "pass"));
108 CU_ASSERT_FATAL(!db_configuration_set_value(configuration, ENFORCER_DB_PASSWORD));
109 CU_ASSERT_FATAL(!db_configuration_list_add(configuration_list, configuration));
110 configuration = NULL;
111
112 CU_ASSERT_PTR_NOT_NULL_FATAL((configuration = db_configuration_new()));
113 CU_ASSERT_FATAL(!db_configuration_set_name(configuration, "db"));
114 CU_ASSERT_FATAL(!db_configuration_set_value(configuration, ENFORCER_DB_DATABASE));
115 CU_ASSERT_FATAL(!db_configuration_list_add(configuration_list, configuration));
116 configuration = NULL;
117#endif
118}
119
121 CU_ASSERT_PTR_NOT_NULL_FATAL((connection = db_connection_new()));
122 CU_ASSERT_FATAL(!db_connection_set_configuration_list(connection, configuration_list));
123 CU_ASSERT_FATAL(!db_connection_setup(connection));
124 CU_ASSERT_FATAL(!db_connection_connect(connection));
125}
db_configuration_t * db_configuration_new(void)
db_configuration_list_t * db_configuration_list_new(void)
void db_configuration_free(db_configuration_t *configuration)
int db_configuration_set_name(db_configuration_t *configuration, const char *name)
int db_configuration_list_add(db_configuration_list_t *configuration_list, db_configuration_t *configuration)
int db_configuration_set_value(db_configuration_t *configuration, const char *value)
void db_configuration_list_free(db_configuration_list_t *configuration_list)
int db_connection_connect(const db_connection_t *connection)
Definition: db_connection.c:88
db_connection_t * db_connection_new(void)
Definition: db_connection.c:38
int db_connection_setup(db_connection_t *connection)
Definition: db_connection.c:66
void db_connection_free(db_connection_t *connection)
Definition: db_connection.c:45
int db_connection_set_configuration_list(db_connection_t *connection, const db_configuration_list_t *configuration_list)
Definition: db_connection.c:54
int clean_suite_initialization(void)
void test_initialization_configuration(void)
void test_initialization_connection(void)
int init_suite_initialization(void)