diff options
Diffstat (limited to 'src/namecache/test_plugin_namecache.c')
-rw-r--r-- | src/namecache/test_plugin_namecache.c | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/src/namecache/test_plugin_namecache.c b/src/namecache/test_plugin_namecache.c new file mode 100644 index 000000000..38b004aa5 --- /dev/null +++ b/src/namecache/test_plugin_namecache.c | |||
@@ -0,0 +1,131 @@ | |||
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 namecache/test_plugin_namecache.c | ||
22 | * @brief Test for the namecache plugins | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include "gnunet_namecache_plugin.h" | ||
28 | #include "gnunet_testing_lib.h" | ||
29 | |||
30 | |||
31 | static int ok; | ||
32 | |||
33 | /** | ||
34 | * Name of plugin under test. | ||
35 | */ | ||
36 | static const char *plugin_name; | ||
37 | |||
38 | |||
39 | /** | ||
40 | * Function called when the service shuts down. Unloads our namecache | ||
41 | * plugin. | ||
42 | * | ||
43 | * @param api api to unload | ||
44 | */ | ||
45 | static void | ||
46 | unload_plugin (struct GNUNET_NAMECACHE_PluginFunctions *api) | ||
47 | { | ||
48 | char *libname; | ||
49 | |||
50 | GNUNET_asprintf (&libname, "libgnunet_plugin_namecache_%s", plugin_name); | ||
51 | GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); | ||
52 | GNUNET_free (libname); | ||
53 | } | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Load the namecache plugin. | ||
58 | * | ||
59 | * @param cfg configuration to pass | ||
60 | * @return NULL on error | ||
61 | */ | ||
62 | static struct GNUNET_NAMECACHE_PluginFunctions * | ||
63 | load_plugin (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
64 | { | ||
65 | struct GNUNET_NAMECACHE_PluginFunctions *ret; | ||
66 | char *libname; | ||
67 | |||
68 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading `%s' namecache plugin\n"), | ||
69 | plugin_name); | ||
70 | GNUNET_asprintf (&libname, "libgnunet_plugin_namecache_%s", plugin_name); | ||
71 | if (NULL == (ret = GNUNET_PLUGIN_load (libname, (void*) cfg))) | ||
72 | { | ||
73 | FPRINTF (stderr, "Failed to load plugin `%s'!\n", plugin_name); | ||
74 | GNUNET_free (libname); | ||
75 | return NULL; | ||
76 | } | ||
77 | GNUNET_free (libname); | ||
78 | return ret; | ||
79 | } | ||
80 | |||
81 | |||
82 | static void | ||
83 | run (void *cls, char *const *args, const char *cfgfile, | ||
84 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
85 | { | ||
86 | struct GNUNET_NAMECACHE_PluginFunctions *nsp; | ||
87 | |||
88 | ok = 0; | ||
89 | nsp = load_plugin (cfg); | ||
90 | if (NULL == nsp) | ||
91 | { | ||
92 | FPRINTF (stderr, | ||
93 | "%s", | ||
94 | "Failed to initialize namecache. Database likely not setup, skipping test.\n"); | ||
95 | return; | ||
96 | } | ||
97 | |||
98 | unload_plugin (nsp); | ||
99 | } | ||
100 | |||
101 | |||
102 | int | ||
103 | main (int argc, char *argv[]) | ||
104 | { | ||
105 | char cfg_name[128]; | ||
106 | char *const xargv[] = { | ||
107 | "test-plugin-namecache", | ||
108 | "-c", | ||
109 | cfg_name, | ||
110 | NULL | ||
111 | }; | ||
112 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
113 | GNUNET_GETOPT_OPTION_END | ||
114 | }; | ||
115 | |||
116 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namecache-sqlite"); | ||
117 | GNUNET_log_setup ("test-plugin-namecache", | ||
118 | "WARNING", | ||
119 | NULL); | ||
120 | plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); | ||
121 | GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_namecache_%s.conf", | ||
122 | plugin_name); | ||
123 | GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, | ||
124 | "test-plugin-namecache", "nohelp", options, &run, NULL); | ||
125 | if (ok != 0) | ||
126 | FPRINTF (stderr, "Missed some testcases: %d\n", ok); | ||
127 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namecache-sqlite"); | ||
128 | return ok; | ||
129 | } | ||
130 | |||
131 | /* end of test_plugin_namecache.c */ | ||