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