paragraph for gnunet devs that don't know how to use the web
[oweals/gnunet.git] / src / peerstore / test_peerstore_api_watch.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2013-2016 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 /**
19  * @file peerstore/test_peerstore_api_watch.c
20  * @brief testcase for peerstore watch functionality
21  */
22 #include "platform.h"
23 #include "gnunet_util_lib.h"
24 #include "gnunet_testing_lib.h"
25 #include "gnunet_peerstore_service.h"
26
27
28 static int ok = 1;
29
30 static struct GNUNET_PEERSTORE_Handle *h;
31
32 static char *ss = "test_peerstore_api_watch";
33
34 static char *k = "test_peerstore_api_watch_key";
35
36 static char *val = "test_peerstore_api_watch_val";
37
38
39 static void
40 watch_cb (void *cls,
41           const struct GNUNET_PEERSTORE_Record *record,
42           const char *emsg)
43 {
44   GNUNET_assert (NULL == emsg);
45   GNUNET_assert (0 == strcmp (val,
46                               (char *) record->value));
47   ok = 0;
48   GNUNET_PEERSTORE_disconnect (h,
49                                GNUNET_NO);
50   GNUNET_SCHEDULER_shutdown ();
51 }
52
53
54 static void
55 run (void *cls,
56      const struct GNUNET_CONFIGURATION_Handle *cfg,
57      struct GNUNET_TESTING_Peer *peer)
58 {
59   struct GNUNET_PeerIdentity p;
60
61   h = GNUNET_PEERSTORE_connect (cfg);
62   GNUNET_assert (NULL != h);
63   memset (&p,
64           4,
65           sizeof (p));
66   GNUNET_PEERSTORE_watch (h,
67                           ss,
68                           &p,
69                           k,
70                           &watch_cb,
71                           NULL);
72   GNUNET_PEERSTORE_store (h,
73                           ss,
74                           &p,
75                           k,
76                           val,
77                           strlen (val) + 1,
78                           GNUNET_TIME_UNIT_FOREVER_ABS,
79                           GNUNET_PEERSTORE_STOREOPTION_REPLACE,
80                           NULL,
81                           NULL);
82 }
83
84
85 int
86 main (int argc,
87       char *argv[])
88 {
89   if (0 !=
90       GNUNET_TESTING_service_run ("test-gnunet-peerstore",
91                                   "peerstore",
92                                   "test_peerstore_api_data.conf",
93                                   &run,
94                                   NULL))
95     return 1;
96   return ok;
97 }
98
99 /* end of test_peerstore_api_watch.c */