aboutsummaryrefslogtreecommitdiff
path: root/src/service/namestore/test_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/namestore/test_common.c')
-rw-r--r--src/service/namestore/test_common.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/service/namestore/test_common.c b/src/service/namestore/test_common.c
new file mode 100644
index 000000000..4df24a7f7
--- /dev/null
+++ b/src/service/namestore/test_common.c
@@ -0,0 +1,128 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2019 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/**
21 * @file namestore/test_common.c
22 * @brief common functions for testcase setup
23 */
24#include "platform.h"
25#include <gnunet_namestore_plugin.h>
26
27/**
28 * test if we can load the plugin @a name.
29 */
30static int
31TNC_test_plugin (const char *cfg_name)
32{
33 char *database;
34 char *db_lib_name;
35 struct GNUNET_NAMESTORE_PluginFunctions *db;
36 struct GNUNET_CONFIGURATION_Handle *cfg;
37
38 cfg = GNUNET_CONFIGURATION_create ();
39 if (GNUNET_OK !=
40 GNUNET_CONFIGURATION_load (cfg,
41 cfg_name))
42 {
43 GNUNET_break (0);
44 GNUNET_CONFIGURATION_destroy (cfg);
45 return GNUNET_SYSERR;
46 }
47 if (GNUNET_OK !=
48 GNUNET_CONFIGURATION_get_value_string (cfg,
49 "namestore",
50 "database",
51 &database))
52 {
53 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
54 "No database backend configured\n");
55 GNUNET_CONFIGURATION_destroy (cfg);
56 return GNUNET_SYSERR;
57 }
58 GNUNET_asprintf (&db_lib_name,
59 "libgnunet_plugin_namestore_%s",
60 database);
61 GNUNET_free (database);
62 db = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
63 if (NULL == db)
64 {
65 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
66 "Failed to load plugin `%s'\n",
67 db_lib_name);
68 }
69 else
70 {
71 if (GNUNET_OK != db->create_tables (db->cls))
72 {
73 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
74 "Error creating tables\n");
75 return GNUNET_SYSERR;
76 }
77 if (GNUNET_OK != db->drop_tables (db->cls))
78 {
79 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
80 "Error dropping tables\n");
81 return GNUNET_SYSERR;
82 }
83 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, db));
84 }
85 GNUNET_free (db_lib_name);
86 GNUNET_CONFIGURATION_destroy (cfg);
87 if (NULL == db)
88 return GNUNET_NO;
89 return GNUNET_YES;
90}
91
92
93/**
94 * General setup logic for starting the tests. Obtains the @a
95 * plugin_name and initializes the @a cfg_name.
96 */
97#define SETUP_CFG2(file_template, plugin_name, cfg_name) \
98 do \
99 { \
100 GNUNET_log_setup (__FILE__, "WARNING", NULL); \
101 plugin_name = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]); \
102 GNUNET_asprintf (&cfg_name, file_template, plugin_name); \
103 if (! TNC_test_plugin (cfg_name)) \
104 { \
105 GNUNET_free (plugin_name); \
106 GNUNET_free (cfg_name); \
107 return 77; \
108 } \
109 GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TEST_HOME"); \
110 } while (0)
111/**
112 * General setup logic for starting the tests. Obtains the @a
113 * plugin_name and initializes the @a cfg_name.
114 */
115#define SETUP_CFG(plugin_name, cfg_name) \
116 do \
117 { \
118 GNUNET_log_setup (__FILE__, "WARNING", NULL); \
119 plugin_name = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]); \
120 GNUNET_asprintf (&cfg_name, "test_namestore_api_%s.conf", plugin_name); \
121 if (! TNC_test_plugin (cfg_name)) \
122 { \
123 GNUNET_free (plugin_name); \
124 GNUNET_free (cfg_name); \
125 return 77; \
126 } \
127 GNUNET_DISK_purge_cfg_dir (cfg_name, "GNUNET_TEST_HOME"); \
128 } while (0)