test_peerstore_api_watch.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2013-2016 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 peerstore/test_peerstore_api_watch.c
  18. * @brief testcase for peerstore watch functionality
  19. */
  20. #include "platform.h"
  21. #include "gnunet_util_lib.h"
  22. #include "gnunet_testing_lib.h"
  23. #include "gnunet_peerstore_service.h"
  24. static int ok = 1;
  25. static struct GNUNET_PEERSTORE_Handle *h;
  26. static char *ss = "test_peerstore_api_watch";
  27. static char *k = "test_peerstore_api_watch_key";
  28. static char *val = "test_peerstore_api_watch_val";
  29. static void
  30. watch_cb (void *cls,
  31. const struct GNUNET_PEERSTORE_Record *record,
  32. const char *emsg)
  33. {
  34. GNUNET_assert (NULL == emsg);
  35. GNUNET_assert (0 == strcmp (val,
  36. (char *) record->value));
  37. ok = 0;
  38. GNUNET_PEERSTORE_disconnect (h,
  39. GNUNET_NO);
  40. GNUNET_SCHEDULER_shutdown ();
  41. }
  42. static void
  43. run (void *cls,
  44. const struct GNUNET_CONFIGURATION_Handle *cfg,
  45. struct GNUNET_TESTING_Peer *peer)
  46. {
  47. struct GNUNET_PeerIdentity p;
  48. h = GNUNET_PEERSTORE_connect (cfg);
  49. GNUNET_assert (NULL != h);
  50. memset (&p,
  51. 4,
  52. sizeof (p));
  53. GNUNET_PEERSTORE_watch (h,
  54. ss,
  55. &p,
  56. k,
  57. &watch_cb,
  58. NULL);
  59. GNUNET_PEERSTORE_store (h,
  60. ss,
  61. &p,
  62. k,
  63. val,
  64. strlen (val) + 1,
  65. GNUNET_TIME_UNIT_FOREVER_ABS,
  66. GNUNET_PEERSTORE_STOREOPTION_REPLACE,
  67. NULL,
  68. NULL);
  69. }
  70. int
  71. main (int argc,
  72. char *argv[])
  73. {
  74. if (0 !=
  75. GNUNET_TESTING_service_run ("test-gnunet-peerstore",
  76. "peerstore",
  77. "test_peerstore_api_data.conf",
  78. &run,
  79. NULL))
  80. return 1;
  81. return ok;
  82. }
  83. /* end of test_peerstore_api_watch.c */