fix
[oweals/gnunet.git] / src / util / test_plugin.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009 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 util/test_plugin.c
22  * @brief testcase for plugin.c
23  */
24 #include "platform.h"
25 #include "gnunet_plugin_lib.h"
26
27 #define VERBOSE GNUNET_EXTRA_LOGGING
28
29 static void
30 test_cb (void *cls,
31          const char *libname,
32          void *lib_ret)
33 {
34   GNUNET_assert (0 == strcmp (cls, "test"));
35   GNUNET_assert (0 == strcmp (lib_ret, "Hello"));
36   GNUNET_assert (0 == strcmp (GNUNET_PLUGIN_unload (libname, "out"), "World"));
37 }
38          
39
40 static int
41 check ()
42 {
43   void *ret;
44
45   GNUNET_log_skip (1, GNUNET_NO);
46   ret = GNUNET_PLUGIN_load ("libgnunet_plugin_missing", NULL);
47   GNUNET_log_skip (0, GNUNET_NO);
48   if (ret != NULL)
49     return 1;
50   ret = GNUNET_PLUGIN_load ("libgnunet_plugin_test", "in");
51   if (ret == NULL)
52     return 1;
53   if (0 != strcmp (ret, "Hello"))
54     return 2;
55   ret = GNUNET_PLUGIN_unload ("libgnunet_plugin_test", "out");
56   if (ret == NULL)
57     return 3;
58   if (0 != strcmp (ret, "World"))
59     return 4;
60   free (ret);
61
62   GNUNET_PLUGIN_load_all ("libgnunet_plugin_tes", "in", &test_cb, "test");
63   return 0;
64 }
65
66 int
67 main (int argc, char *argv[])
68 {
69   int ret;
70
71   GNUNET_log_setup ("test-plugin", "WARNING", NULL);
72   ret = check ();
73
74   return ret;
75 }
76
77 /* end of test_plugin.c */