diff options
Diffstat (limited to 'src/service/peerstore/test_peerstore_api_watch.c')
-rw-r--r-- | src/service/peerstore/test_peerstore_api_watch.c | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/src/service/peerstore/test_peerstore_api_watch.c b/src/service/peerstore/test_peerstore_api_watch.c index 126b321df..63b0e896b 100644 --- a/src/service/peerstore/test_peerstore_api_watch.c +++ b/src/service/peerstore/test_peerstore_api_watch.c | |||
@@ -21,6 +21,8 @@ | |||
21 | * @file peerstore/test_peerstore_api_watch.c | 21 | * @file peerstore/test_peerstore_api_watch.c |
22 | * @brief testcase for peerstore watch functionality | 22 | * @brief testcase for peerstore watch functionality |
23 | */ | 23 | */ |
24 | #include "gnunet_common.h" | ||
25 | #include "gnunet_time_lib.h" | ||
24 | #include "platform.h" | 26 | #include "platform.h" |
25 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
26 | #include "gnunet_testing_lib.h" | 28 | #include "gnunet_testing_lib.h" |
@@ -31,12 +33,42 @@ static int ok = 1; | |||
31 | 33 | ||
32 | static struct GNUNET_PEERSTORE_Handle *h; | 34 | static struct GNUNET_PEERSTORE_Handle *h; |
33 | 35 | ||
36 | static struct GNUNET_PEERSTORE_WatchContext *wc; | ||
37 | |||
34 | static char *ss = "test_peerstore_api_watch"; | 38 | static char *ss = "test_peerstore_api_watch"; |
35 | 39 | ||
36 | static char *k = "test_peerstore_api_watch_key"; | 40 | static char *k = "test_peerstore_api_watch_key"; |
37 | 41 | ||
38 | static char *val = "test_peerstore_api_watch_val"; | 42 | static char *val = "test_peerstore_api_watch_val"; |
39 | 43 | ||
44 | static struct GNUNET_PeerIdentity p; | ||
45 | |||
46 | static void | ||
47 | finish (void *cls) | ||
48 | { | ||
49 | GNUNET_PEERSTORE_watch_cancel (wc); | ||
50 | GNUNET_PEERSTORE_disconnect (h); | ||
51 | GNUNET_SCHEDULER_shutdown (); | ||
52 | } | ||
53 | |||
54 | |||
55 | static void | ||
56 | cont (void *cls) | ||
57 | { | ||
58 | GNUNET_PEERSTORE_store (h, | ||
59 | ss, | ||
60 | &p, | ||
61 | k, | ||
62 | val, | ||
63 | strlen (val) + 1, | ||
64 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
65 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
66 | NULL, | ||
67 | NULL); | ||
68 | } | ||
69 | |||
70 | |||
71 | static int initial_iteration = GNUNET_YES; | ||
40 | 72 | ||
41 | static void | 73 | static void |
42 | watch_cb (void *cls, | 74 | watch_cb (void *cls, |
@@ -44,12 +76,28 @@ watch_cb (void *cls, | |||
44 | const char *emsg) | 76 | const char *emsg) |
45 | { | 77 | { |
46 | GNUNET_assert (NULL == emsg); | 78 | GNUNET_assert (NULL == emsg); |
79 | if (GNUNET_YES == initial_iteration) | ||
80 | { | ||
81 | if (NULL != record) | ||
82 | { | ||
83 | GNUNET_break (0); | ||
84 | return; // Ignore this record, FIXME: Test unclean | ||
85 | } | ||
86 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &cont, NULL); | ||
87 | initial_iteration = GNUNET_NO; | ||
88 | return; | ||
89 | } | ||
90 | if (NULL == record) | ||
91 | { | ||
92 | GNUNET_break (0); | ||
93 | return; | ||
94 | } | ||
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received record: %s\n", | ||
96 | (char*) record->value); | ||
47 | GNUNET_assert (0 == strcmp (val, | 97 | GNUNET_assert (0 == strcmp (val, |
48 | (char *) record->value)); | 98 | (char *) record->value)); |
49 | ok = 0; | 99 | ok = 0; |
50 | GNUNET_PEERSTORE_disconnect (h, | 100 | GNUNET_SCHEDULER_add_now (&finish, NULL); |
51 | GNUNET_NO); | ||
52 | GNUNET_SCHEDULER_shutdown (); | ||
53 | } | 101 | } |
54 | 102 | ||
55 | 103 | ||
@@ -58,29 +106,18 @@ run (void *cls, | |||
58 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 106 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
59 | struct GNUNET_TESTING_Peer *peer) | 107 | struct GNUNET_TESTING_Peer *peer) |
60 | { | 108 | { |
61 | struct GNUNET_PeerIdentity p; | ||
62 | 109 | ||
63 | h = GNUNET_PEERSTORE_connect (cfg); | 110 | h = GNUNET_PEERSTORE_connect (cfg); |
64 | GNUNET_assert (NULL != h); | 111 | GNUNET_assert (NULL != h); |
65 | memset (&p, | 112 | memset (&p, |
66 | 4, | 113 | 4, |
67 | sizeof(p)); | 114 | sizeof(p)); |
68 | GNUNET_PEERSTORE_watch (h, | 115 | wc = GNUNET_PEERSTORE_watch (h, |
69 | ss, | 116 | ss, |
70 | &p, | 117 | &p, |
71 | k, | 118 | k, |
72 | &watch_cb, | 119 | &watch_cb, |
73 | NULL); | 120 | 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 | } | 121 | } |
85 | 122 | ||
86 | 123 | ||