diff options
-rw-r--r-- | src/namestore/Makefile.am | 15 | ||||
-rw-r--r-- | src/namestore/plugin_namestore_sqlite.c | 8 | ||||
-rw-r--r-- | src/namestore/test_plugin_namestore.c | 149 | ||||
-rw-r--r-- | src/namestore/test_plugin_namestore_sqlite.conf | 2 |
4 files changed, 168 insertions, 6 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index 5e7f1cbfd..20c07f707 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -16,8 +16,14 @@ if USE_COVERAGE | |||
16 | XLIBS = -lgcov | 16 | XLIBS = -lgcov |
17 | endif | 17 | endif |
18 | 18 | ||
19 | if HAVE_SQLITE | ||
20 | SQLITE_TESTS = \ | ||
21 | test_plugin_namestore_sqlite | ||
22 | endif | ||
23 | |||
19 | 24 | ||
20 | check_PROGRAMS = \ | 25 | check_PROGRAMS = \ |
26 | $(SQLITE_TESTS) \ | ||
21 | test_namestore_api | 27 | test_namestore_api |
22 | 28 | ||
23 | lib_LTLIBRARIES = \ | 29 | lib_LTLIBRARIES = \ |
@@ -66,6 +72,11 @@ test_namestore_api_LDADD = \ | |||
66 | $(top_builddir)/src/namestore/libgnunetnamestore.la | 72 | $(top_builddir)/src/namestore/libgnunetnamestore.la |
67 | 73 | ||
68 | EXTRADIST = \ | 74 | EXTRADIST = \ |
69 | test_namestore_api.conf | 75 | test_namestore_api.conf \ |
76 | test_plugin_namestore_sqlite.conf | ||
77 | |||
70 | 78 | ||
71 | \ No newline at end of file | 79 | test_plugin_namestore_sqlite_SOURCES = \ |
80 | test_plugin_namestore.c | ||
81 | test_plugin_namestore_sqlite_LDADD = \ | ||
82 | $(top_builddir)/src/util/libgnunetutil.la | ||
diff --git a/src/namestore/plugin_namestore_sqlite.c b/src/namestore/plugin_namestore_sqlite.c index 9a218f4bc..3c20b0d7f 100644 --- a/src/namestore/plugin_namestore_sqlite.c +++ b/src/namestore/plugin_namestore_sqlite.c | |||
@@ -353,7 +353,7 @@ database_setup (struct Plugin *plugin) | |||
353 | (plugin->dbh, | 353 | (plugin->dbh, |
354 | "INSERT INTO ns090signatures (zone_hash, zone_revision, zone_time, zone_root_hash, " | 354 | "INSERT INTO ns090signatures (zone_hash, zone_revision, zone_time, zone_root_hash, " |
355 | "zone_root_depth, zone_public_key, zone_signature) " | 355 | "zone_root_depth, zone_public_key, zone_signature) " |
356 | "VALUES (?, ?, ?, ?, ?, ?)", | 356 | "VALUES (?, ?, ?, ?, ?, ?, ?)", |
357 | &plugin->put_signature) != SQLITE_OK) || | 357 | &plugin->put_signature) != SQLITE_OK) || |
358 | (sq_prepare | 358 | (sq_prepare |
359 | (plugin->dbh, | 359 | (plugin->dbh, |
@@ -372,15 +372,15 @@ database_setup (struct Plugin *plugin) | |||
372 | &plugin->get_signature) != SQLITE_OK) || | 372 | &plugin->get_signature) != SQLITE_OK) || |
373 | (sq_prepare | 373 | (sq_prepare |
374 | (plugin->dbh, | 374 | (plugin->dbh, |
375 | "DELETE FROM gn090records WHERE zone_hash=?", | 375 | "DELETE FROM ns090records WHERE zone_hash=?", |
376 | &plugin->delete_zone_records) != SQLITE_OK) || | 376 | &plugin->delete_zone_records) != SQLITE_OK) || |
377 | (sq_prepare | 377 | (sq_prepare |
378 | (plugin->dbh, | 378 | (plugin->dbh, |
379 | "DELETE FROM gn090nodes WHERE zone_hash=?", | 379 | "DELETE FROM ns090nodes WHERE zone_hash=?", |
380 | &plugin->delete_zone_nodes) != SQLITE_OK) || | 380 | &plugin->delete_zone_nodes) != SQLITE_OK) || |
381 | (sq_prepare | 381 | (sq_prepare |
382 | (plugin->dbh, | 382 | (plugin->dbh, |
383 | "DELETE FROM gn090signatures WHERE zone_hash=?", | 383 | "DELETE FROM ns090signatures WHERE zone_hash=?", |
384 | &plugin->delete_zone_signatures) != SQLITE_OK) ) | 384 | &plugin->delete_zone_signatures) != SQLITE_OK) ) |
385 | { | 385 | { |
386 | LOG_SQLITE (plugin,GNUNET_ERROR_TYPE_ERROR, "precompiling"); | 386 | LOG_SQLITE (plugin,GNUNET_ERROR_TYPE_ERROR, "precompiling"); |
diff --git a/src/namestore/test_plugin_namestore.c b/src/namestore/test_plugin_namestore.c new file mode 100644 index 000000000..01f73df8e --- /dev/null +++ b/src/namestore/test_plugin_namestore.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | 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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /* | ||
21 | * @file namestore/test_plugin_namestore.c | ||
22 | * @brief Test for the namestore plugins | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include "gnunet_namestore_plugin.h" | ||
28 | |||
29 | #define VERBOSE GNUNET_EXTRA_LOGGING | ||
30 | |||
31 | #define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0) | ||
32 | |||
33 | static int ok; | ||
34 | |||
35 | /** | ||
36 | * Name of plugin under test. | ||
37 | */ | ||
38 | static const char *plugin_name; | ||
39 | |||
40 | |||
41 | /** | ||
42 | * Function called when the service shuts down. Unloads our namestore | ||
43 | * plugin. | ||
44 | * | ||
45 | * @param api api to unload | ||
46 | */ | ||
47 | static void | ||
48 | unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api) | ||
49 | { | ||
50 | char *libname; | ||
51 | |||
52 | GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); | ||
53 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); | ||
54 | GNUNET_free (libname); | ||
55 | } | ||
56 | |||
57 | |||
58 | /** | ||
59 | * Load the namestore plugin. | ||
60 | * | ||
61 | * @param cfg configuration to pass | ||
62 | * @return NULL on error | ||
63 | */ | ||
64 | static struct GNUNET_NAMESTORE_PluginFunctions * | ||
65 | load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
66 | { | ||
67 | struct GNUNET_NAMESTORE_PluginFunctions *ret; | ||
68 | char *libname; | ||
69 | |||
70 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' namestore plugin\n"), | ||
71 | plugin_name); | ||
72 | GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); | ||
73 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg))) | ||
74 | { | ||
75 | FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name); | ||
76 | return NULL; | ||
77 | } | ||
78 | GNUNET_free (libname); | ||
79 | return ret; | ||
80 | } | ||
81 | |||
82 | |||
83 | static void | ||
84 | run (void *cls, char *const *args, const char *cfgfile, | ||
85 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
86 | { | ||
87 | struct GNUNET_NAMESTORE_PluginFunctions *nsp; | ||
88 | |||
89 | ok = 0; | ||
90 | nsp = load_plugin (cfg); | ||
91 | if (NULL == nsp) | ||
92 | { | ||
93 | FPRINTF (stderr, | ||
94 | "%s", | ||
95 | "Failed to initialize namestore. Database likely not setup, skipping test.\n"); | ||
96 | return; | ||
97 | } | ||
98 | |||
99 | unload_plugin (nsp); | ||
100 | } | ||
101 | |||
102 | |||
103 | int | ||
104 | main (int argc, char *argv[]) | ||
105 | { | ||
106 | char *pos; | ||
107 | char cfg_name[128]; | ||
108 | |||
109 | char *const xargv[] = { | ||
110 | "test-plugin-namestore", | ||
111 | "-c", | ||
112 | cfg_name, | ||
113 | #if VERBOSE | ||
114 | "-L", "DEBUG", | ||
115 | #endif | ||
116 | NULL | ||
117 | }; | ||
118 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
119 | GNUNET_GETOPT_OPTION_END | ||
120 | }; | ||
121 | |||
122 | GNUNET_log_setup ("test-plugin-namestore", | ||
123 | #if VERBOSE | ||
124 | "DEBUG", | ||
125 | #else | ||
126 | "WARNING", | ||
127 | #endif | ||
128 | NULL); | ||
129 | /* determine name of plugin to use */ | ||
130 | plugin_name = argv[0]; | ||
131 | while (NULL != (pos = strstr (plugin_name, "_"))) | ||
132 | plugin_name = pos + 1; | ||
133 | if (NULL != (pos = strstr (plugin_name, "."))) | ||
134 | pos[0] = 0; | ||
135 | else | ||
136 | pos = (char *) plugin_name; | ||
137 | |||
138 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_namestore_%s.conf", | ||
139 | plugin_name); | ||
140 | if (pos != plugin_name) | ||
141 | pos[0] = '.'; | ||
142 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | ||
143 | "test-plugin-namestore", "nohelp", options, &run, NULL); | ||
144 | if (ok != 0) | ||
145 | FPRINTF (stderr, "Missed some testcases: %d\n", ok); | ||
146 | return ok; | ||
147 | } | ||
148 | |||
149 | /* end of test_plugin_namestore.c */ | ||
diff --git a/src/namestore/test_plugin_namestore_sqlite.conf b/src/namestore/test_plugin_namestore_sqlite.conf new file mode 100644 index 000000000..8f95b65bf --- /dev/null +++ b/src/namestore/test_plugin_namestore_sqlite.conf | |||
@@ -0,0 +1,2 @@ | |||
1 | [namestore-sqlite] | ||
2 | FILENAME = $SERVICEHOME/namestore/sqlite.db | ||