aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/test_common.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-02-24 10:28:16 +0100
committerChristian Grothoff <christian@grothoff.org>2019-02-24 10:28:16 +0100
commit0b5dc8a620fca8dbca9c122594b70267e404859f (patch)
tree71166165545fcd77ee36bba8eaec45f7bac62da9 /src/namestore/test_common.c
parent4577873dccd43d132062ae3c07e316c86be6af2f (diff)
downloadgnunet-0b5dc8a620fca8dbca9c122594b70267e404859f.tar.gz
gnunet-0b5dc8a620fca8dbca9c122594b70267e404859f.zip
avoid failing hard if 'gnunetcheck' db does not exist
(or plugins cannot be loaded for other reasons)
Diffstat (limited to 'src/namestore/test_common.c')
-rw-r--r--src/namestore/test_common.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/namestore/test_common.c b/src/namestore/test_common.c
new file mode 100644
index 000000000..0dc6f9277
--- /dev/null
+++ b/src/namestore/test_common.c
@@ -0,0 +1,89 @@
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
25/**
26 * test if we can load the plugin @a name.
27 */
28static int
29TNC_test_plugin (const char *cfg_name)
30{
31 char *database;
32 char *db_lib_name;
33 struct GNUNET_NAMESTORE_PluginFunctions *db;
34 struct GNUNET_CONFIGURATION_Handle *cfg;
35
36 cfg = GNUNET_CONFIGURATION_create ();
37 if (GNUNET_OK !=
38 GNUNET_CONFIGURATION_load (cfg,
39 cfg_name))
40 {
41 GNUNET_break (0);
42 GNUNET_CONFIGURATION_destroy (cfg);
43 return GNUNET_SYSERR;
44 }
45 if (GNUNET_OK !=
46 GNUNET_CONFIGURATION_get_value_string (cfg,
47 "namestore",
48 "database",
49 &database))
50 {
51 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
52 "No database backend configured\n");
53 GNUNET_CONFIGURATION_destroy (cfg);
54 return GNUNET_SYSERR;
55 }
56 GNUNET_asprintf (&db_lib_name,
57 "libgnunet_plugin_namestore_%s",
58 database);
59 db = GNUNET_PLUGIN_load (db_lib_name,
60 (void *) cfg);
61 if (NULL != db)
62 GNUNET_break (NULL ==
63 GNUNET_PLUGIN_unload (db_lib_name,
64 db));
65 GNUNET_free (db_lib_name);
66 GNUNET_CONFIGURATION_destroy (cfg);
67 if (NULL == db)
68 return GNUNET_NO;
69 return GNUNET_YES;
70}
71
72
73/**
74 * General setup logic for starting the tests. Obtains the @a
75 * plugin_name and initializes the @a cfg_name.
76 */
77#define SETUP_CFG(plugin_name,cfg_name) do { \
78 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); \
79 GNUNET_asprintf (&cfg_name, \
80 "test_namestore_api_%s.conf", \
81 plugin_name); \
82 if (! TNC_test_plugin (cfg_name)) \
83 { \
84 GNUNET_free (cfg_name); \
85 return 77; \
86 } \
87 GNUNET_DISK_purge_cfg_dir (cfg_name, \
88 "GNUNET_TEST_HOME"); \
89 } while (0)