aboutsummaryrefslogtreecommitdiff
path: root/src/peerstore/test_peerstore_api_watch.c
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-06-05 09:08:28 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-06-05 09:08:28 +0000
commitf8a8dad6b6ff2d1dd28098372f203264b2caa060 (patch)
tree51760410f7176970b68f386d8665a51968e6e6ab /src/peerstore/test_peerstore_api_watch.c
parentecc4ae9b8bbd5e5433b83a1527cd9b83487e9bec (diff)
downloadgnunet-f8a8dad6b6ff2d1dd28098372f203264b2caa060.tar.gz
gnunet-f8a8dad6b6ff2d1dd28098372f203264b2caa060.zip
peerstore: additional test cases
Diffstat (limited to 'src/peerstore/test_peerstore_api_watch.c')
-rw-r--r--src/peerstore/test_peerstore_api_watch.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/peerstore/test_peerstore_api_watch.c b/src/peerstore/test_peerstore_api_watch.c
new file mode 100644
index 000000000..b8d0a0cce
--- /dev/null
+++ b/src/peerstore/test_peerstore_api_watch.c
@@ -0,0 +1,88 @@
1/*
2 This file is part of GNUnet.
3 (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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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
29static int ok = 1;
30
31struct GNUNET_PEERSTORE_Handle *h;
32
33char *ss = "test_peerstore_api_watch";
34struct GNUNET_PeerIdentity p;
35char *k = "test_peerstore_api_watch_key";
36char *val = "test_peerstore_api_watch_val";
37
38static int
39watch_cb(void *cls,
40 struct GNUNET_PEERSTORE_Record *record,
41 char *emsg)
42{
43 GNUNET_assert(NULL == emsg);
44 GNUNET_assert(0 == strcmp(val, (char *)record->value));
45 ok = 0;
46 GNUNET_PEERSTORE_disconnect(h);
47 GNUNET_SCHEDULER_shutdown();
48 return GNUNET_YES;
49}
50
51static void
52run (void *cls,
53 const struct GNUNET_CONFIGURATION_Handle *cfg,
54 struct GNUNET_TESTING_Peer *peer)
55{
56 h = GNUNET_PEERSTORE_connect(cfg);
57 GNUNET_assert(NULL != h);
58 memset (&p, 4, sizeof (p));
59 GNUNET_PEERSTORE_watch(h,
60 ss,
61 &p,
62 k,
63 &watch_cb,
64 NULL);
65 GNUNET_PEERSTORE_store(h,
66 ss,
67 &p,
68 k,
69 val,
70 strlen(val) + 1,
71 GNUNET_TIME_UNIT_FOREVER_ABS,
72 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
73 NULL,
74 NULL);
75}
76
77int
78main (int argc, char *argv[])
79{
80 if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore",
81 "peerstore",
82 "test_peerstore_api_data.conf",
83 &run, NULL))
84 return 1;
85 return ok;
86}
87
88/* end of test_peerstore_api_watch.c */