test_plugin.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2009 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file util/test_plugin.c
  18. * @brief testcase for plugin.c
  19. */
  20. #include "platform.h"
  21. #include "gnunet_util_lib.h"
  22. static void
  23. test_cb (void *cls, const char *libname, void *lib_ret)
  24. {
  25. void *ret;
  26. GNUNET_assert (0 == strcmp (cls, "test"));
  27. GNUNET_assert (0 == strcmp (lib_ret, "Hello"));
  28. ret = GNUNET_PLUGIN_unload (libname, "out");
  29. GNUNET_assert (NULL != ret);
  30. GNUNET_assert (0 == strcmp (ret, "World"));
  31. free (ret);
  32. }
  33. int
  34. main (int argc, char *argv[])
  35. {
  36. void *ret;
  37. GNUNET_log_setup ("test-plugin", "WARNING", NULL);
  38. GNUNET_log_skip (1, GNUNET_NO);
  39. ret = GNUNET_PLUGIN_load ("libgnunet_plugin_missing", NULL);
  40. GNUNET_log_skip (0, GNUNET_NO);
  41. if (ret != NULL)
  42. return 1;
  43. ret = GNUNET_PLUGIN_load ("libgnunet_plugin_test", "in");
  44. if (ret == NULL)
  45. return 1;
  46. if (0 != strcmp (ret, "Hello"))
  47. return 2;
  48. ret = GNUNET_PLUGIN_unload ("libgnunet_plugin_test", "out");
  49. if (ret == NULL)
  50. return 3;
  51. if (0 != strcmp (ret, "World"))
  52. return 4;
  53. free (ret);
  54. GNUNET_PLUGIN_load_all ("libgnunet_plugin_tes", "in", &test_cb, "test");
  55. return 0;
  56. }
  57. /* end of test_plugin.c */