diff options
Diffstat (limited to 'src/service/peerstore/test_peerstore_api_watch.c')
-rw-r--r-- | src/service/peerstore/test_peerstore_api_watch.c | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/service/peerstore/test_peerstore_api_watch.c b/src/service/peerstore/test_peerstore_api_watch.c new file mode 100644 index 000000000..126b321df --- /dev/null +++ b/src/service/peerstore/test_peerstore_api_watch.c | |||
@@ -0,0 +1,102 @@ | |||
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 | SPDX-License-Identifier: AGPL3.0-or-later | ||
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 | |||
30 | static int ok = 1; | ||
31 | |||
32 | static struct GNUNET_PEERSTORE_Handle *h; | ||
33 | |||
34 | static char *ss = "test_peerstore_api_watch"; | ||
35 | |||
36 | static char *k = "test_peerstore_api_watch_key"; | ||
37 | |||
38 | static char *val = "test_peerstore_api_watch_val"; | ||
39 | |||
40 | |||
41 | static void | ||
42 | watch_cb (void *cls, | ||
43 | const struct GNUNET_PEERSTORE_Record *record, | ||
44 | const char *emsg) | ||
45 | { | ||
46 | GNUNET_assert (NULL == emsg); | ||
47 | GNUNET_assert (0 == strcmp (val, | ||
48 | (char *) record->value)); | ||
49 | ok = 0; | ||
50 | GNUNET_PEERSTORE_disconnect (h, | ||
51 | GNUNET_NO); | ||
52 | GNUNET_SCHEDULER_shutdown (); | ||
53 | } | ||
54 | |||
55 | |||
56 | static void | ||
57 | run (void *cls, | ||
58 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
59 | struct GNUNET_TESTING_Peer *peer) | ||
60 | { | ||
61 | struct GNUNET_PeerIdentity p; | ||
62 | |||
63 | h = GNUNET_PEERSTORE_connect (cfg); | ||
64 | GNUNET_assert (NULL != h); | ||
65 | memset (&p, | ||
66 | 4, | ||
67 | sizeof(p)); | ||
68 | GNUNET_PEERSTORE_watch (h, | ||
69 | ss, | ||
70 | &p, | ||
71 | k, | ||
72 | &watch_cb, | ||
73 | NULL); | ||
74 | GNUNET_PEERSTORE_store (h, | ||
75 | ss, | ||
76 | &p, | ||
77 | k, | ||
78 | val, | ||
79 | strlen (val) + 1, | ||
80 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
81 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
82 | NULL, | ||
83 | NULL); | ||
84 | } | ||
85 | |||
86 | |||
87 | int | ||
88 | main (int argc, | ||
89 | char *argv[]) | ||
90 | { | ||
91 | if (0 != | ||
92 | GNUNET_TESTING_service_run ("test-gnunet-peerstore", | ||
93 | "peerstore", | ||
94 | "test_peerstore_api_data.conf", | ||
95 | &run, | ||
96 | NULL)) | ||
97 | return 1; | ||
98 | return ok; | ||
99 | } | ||
100 | |||
101 | |||
102 | /* end of test_peerstore_api_watch.c */ | ||