diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-06-05 09:08:28 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-06-05 09:08:28 +0000 |
commit | f8a8dad6b6ff2d1dd28098372f203264b2caa060 (patch) | |
tree | 51760410f7176970b68f386d8665a51968e6e6ab | |
parent | ecc4ae9b8bbd5e5433b83a1527cd9b83487e9bec (diff) | |
download | gnunet-f8a8dad6b6ff2d1dd28098372f203264b2caa060.tar.gz gnunet-f8a8dad6b6ff2d1dd28098372f203264b2caa060.zip |
peerstore: additional test cases
-rw-r--r-- | src/peerstore/Makefile.am | 19 | ||||
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 6 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_iterate.c | 168 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_store.c | 6 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_watch.c | 88 |
5 files changed, 281 insertions, 6 deletions
diff --git a/src/peerstore/Makefile.am b/src/peerstore/Makefile.am index e65817569..5b3c918db 100644 --- a/src/peerstore/Makefile.am +++ b/src/peerstore/Makefile.am | |||
@@ -65,7 +65,9 @@ libgnunet_plugin_peerstore_sqlite_la_DEPENDENCIES = \ | |||
65 | libgnunetpeerstore.la | 65 | libgnunetpeerstore.la |
66 | 66 | ||
67 | check_PROGRAMS = \ | 67 | check_PROGRAMS = \ |
68 | test_peerstore_api_store | 68 | test_peerstore_api_store \ |
69 | test_peerstore_api_iterate \ | ||
70 | test_peerstore_api_watch | ||
69 | 71 | ||
70 | if ENABLE_TEST_RUN | 72 | if ENABLE_TEST_RUN |
71 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; | 73 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; |
@@ -77,5 +79,18 @@ test_peerstore_api_store_SOURCES = \ | |||
77 | test_peerstore_api_store_LDADD = \ | 79 | test_peerstore_api_store_LDADD = \ |
78 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ | 80 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ |
79 | $(top_builddir)/src/testing/libgnunettesting.la \ | 81 | $(top_builddir)/src/testing/libgnunettesting.la \ |
80 | $(top_builddir)/src/util/libgnunetutil.la | 82 | $(top_builddir)/src/util/libgnunetutil.la |
83 | |||
84 | test_peerstore_api_iterate_SOURCES = \ | ||
85 | test_peerstore_api_iterate.c | ||
86 | test_peerstore_api_iterate_LDADD = \ | ||
87 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ | ||
88 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
89 | $(top_builddir)/src/util/libgnunetutil.la | ||
81 | 90 | ||
91 | test_peerstore_api_watch_SOURCES = \ | ||
92 | test_peerstore_api_watch.c | ||
93 | test_peerstore_api_watch_LDADD = \ | ||
94 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ | ||
95 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
96 | $(top_builddir)/src/util/libgnunetutil.la | ||
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index 418204850..082ab38ac 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -202,7 +202,7 @@ void watch_notifier (struct GNUNET_PEERSTORE_Record *record) | |||
202 | { | 202 | { |
203 | struct GNUNET_HashCode keyhash; | 203 | struct GNUNET_HashCode keyhash; |
204 | 204 | ||
205 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Sending update to any watchers.\n"); | 205 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending update to any watchers.\n"); |
206 | PEERSTORE_hash_key(record->sub_system, | 206 | PEERSTORE_hash_key(record->sub_system, |
207 | record->peer, | 207 | record->peer, |
208 | record->key, | 208 | record->key, |
@@ -279,6 +279,10 @@ void handle_iterate (void *cls, | |||
279 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 279 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
280 | return; | 280 | return; |
281 | } | 281 | } |
282 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Iterate request: ss `%s', peer `%s', key `%s'\n", | ||
283 | record->sub_system, | ||
284 | (NULL == record->peer) ? "NULL" : GNUNET_i2s(record->peer), | ||
285 | (NULL == record->key) ? "NULL" : record->key); | ||
282 | GNUNET_SERVER_notification_context_add(nc, client); | 286 | GNUNET_SERVER_notification_context_add(nc, client); |
283 | if(GNUNET_OK == db->iterate_records(db->cls, | 287 | if(GNUNET_OK == db->iterate_records(db->cls, |
284 | record->sub_system, | 288 | record->sub_system, |
diff --git a/src/peerstore/test_peerstore_api_iterate.c b/src/peerstore/test_peerstore_api_iterate.c new file mode 100644 index 000000000..0655be25f --- /dev/null +++ b/src/peerstore/test_peerstore_api_iterate.c | |||
@@ -0,0 +1,168 @@ | |||
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_iterate.c | ||
22 | * @brief testcase for peerstore iteration operation | ||
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 | struct GNUNET_PEERSTORE_Handle *h; | ||
32 | |||
33 | char *ss = "test_peerstore_api_iterate"; | ||
34 | struct GNUNET_PeerIdentity p1; | ||
35 | struct GNUNET_PeerIdentity p2; | ||
36 | char *k1 = "test_peerstore_api_iterate_key1"; | ||
37 | char *k2 = "test_peerstore_api_iterate_key2"; | ||
38 | char *k3 = "test_peerstore_api_iterate_key3"; | ||
39 | char *val = "test_peerstore_api_iterate_val"; | ||
40 | int count = 0; | ||
41 | |||
42 | static int | ||
43 | iter3_cb(void *cls, | ||
44 | struct GNUNET_PEERSTORE_Record *record, | ||
45 | char *emsg) | ||
46 | { | ||
47 | if(NULL != emsg) | ||
48 | return GNUNET_NO; | ||
49 | if(NULL != record) | ||
50 | { | ||
51 | count++; | ||
52 | return GNUNET_YES; | ||
53 | } | ||
54 | GNUNET_assert(count == 3); | ||
55 | ok = 0; | ||
56 | GNUNET_PEERSTORE_disconnect(h); | ||
57 | GNUNET_SCHEDULER_shutdown(); | ||
58 | return GNUNET_YES; | ||
59 | } | ||
60 | |||
61 | static int | ||
62 | iter2_cb(void *cls, | ||
63 | struct GNUNET_PEERSTORE_Record *record, | ||
64 | char *emsg) | ||
65 | { | ||
66 | if(NULL != emsg) | ||
67 | return GNUNET_NO; | ||
68 | if(NULL != record) | ||
69 | { | ||
70 | count++; | ||
71 | return GNUNET_YES; | ||
72 | } | ||
73 | GNUNET_assert(count == 2); | ||
74 | count = 0; | ||
75 | GNUNET_PEERSTORE_iterate(h, | ||
76 | ss, | ||
77 | NULL, | ||
78 | NULL, | ||
79 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
80 | iter3_cb, | ||
81 | NULL); | ||
82 | return GNUNET_YES; | ||
83 | } | ||
84 | |||
85 | static int | ||
86 | iter1_cb(void *cls, | ||
87 | struct GNUNET_PEERSTORE_Record *record, | ||
88 | char *emsg) | ||
89 | { | ||
90 | if(NULL != emsg) | ||
91 | return GNUNET_NO; | ||
92 | if(NULL != record) | ||
93 | { | ||
94 | count++; | ||
95 | return GNUNET_YES; | ||
96 | } | ||
97 | GNUNET_assert(count == 1); | ||
98 | count = 0; | ||
99 | GNUNET_PEERSTORE_iterate(h, | ||
100 | ss, | ||
101 | &p1, | ||
102 | NULL, | ||
103 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
104 | iter2_cb, | ||
105 | NULL); | ||
106 | return GNUNET_YES; | ||
107 | } | ||
108 | |||
109 | static void | ||
110 | run (void *cls, | ||
111 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
112 | struct GNUNET_TESTING_Peer *peer) | ||
113 | { | ||
114 | h = GNUNET_PEERSTORE_connect(cfg); | ||
115 | GNUNET_assert(NULL != h); | ||
116 | memset (&p1, 1, sizeof (p1)); | ||
117 | memset (&p2, 2, sizeof (p2)); | ||
118 | GNUNET_PEERSTORE_store(h, | ||
119 | ss, | ||
120 | &p1, | ||
121 | k1, | ||
122 | val, | ||
123 | strlen(val) + 1, | ||
124 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
125 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
126 | NULL, | ||
127 | NULL); | ||
128 | GNUNET_PEERSTORE_store(h, | ||
129 | ss, | ||
130 | &p1, | ||
131 | k2, | ||
132 | val, | ||
133 | strlen(val) + 1, | ||
134 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
135 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
136 | NULL, | ||
137 | NULL); | ||
138 | GNUNET_PEERSTORE_store(h, | ||
139 | ss, | ||
140 | &p2, | ||
141 | k3, | ||
142 | val, | ||
143 | strlen(val) + 1, | ||
144 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
145 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, | ||
146 | NULL, | ||
147 | NULL); | ||
148 | GNUNET_PEERSTORE_iterate(h, | ||
149 | ss, | ||
150 | &p1, | ||
151 | k1, | ||
152 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
153 | iter1_cb, | ||
154 | NULL); | ||
155 | } | ||
156 | |||
157 | int | ||
158 | main (int argc, char *argv[]) | ||
159 | { | ||
160 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore", | ||
161 | "peerstore", | ||
162 | "test_peerstore_api_data.conf", | ||
163 | &run, NULL)) | ||
164 | return 1; | ||
165 | return ok; | ||
166 | } | ||
167 | |||
168 | /* end of test_peerstore_api_iterate.c */ | ||
diff --git a/src/peerstore/test_peerstore_api_store.c b/src/peerstore/test_peerstore_api_store.c index d3579947b..8b3391d83 100644 --- a/src/peerstore/test_peerstore_api_store.c +++ b/src/peerstore/test_peerstore_api_store.c | |||
@@ -18,8 +18,8 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file peerstore/test_peerstore_api.c | 21 | * @file peerstore/test_peerstore_api_store.c |
22 | * @brief testcase for peerstore_api.c | 22 | * @brief testcase for peerstore store operation |
23 | */ | 23 | */ |
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_util_lib.h" | 25 | #include "gnunet_util_lib.h" |
@@ -219,4 +219,4 @@ main (int argc, char *argv[]) | |||
219 | return ok; | 219 | return ok; |
220 | } | 220 | } |
221 | 221 | ||
222 | /* end of test_peerstore_api.c */ | 222 | /* end of test_peerstore_api_store.c */ |
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 | |||
29 | static int ok = 1; | ||
30 | |||
31 | struct GNUNET_PEERSTORE_Handle *h; | ||
32 | |||
33 | char *ss = "test_peerstore_api_watch"; | ||
34 | struct GNUNET_PeerIdentity p; | ||
35 | char *k = "test_peerstore_api_watch_key"; | ||
36 | char *val = "test_peerstore_api_watch_val"; | ||
37 | |||
38 | static int | ||
39 | watch_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 | |||
51 | static void | ||
52 | run (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 | |||
77 | int | ||
78 | main (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 */ | ||