aboutsummaryrefslogtreecommitdiff
path: root/src/set/test_set_intersection_result_full.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-11-07 18:13:30 +0000
committerChristian Grothoff <christian@grothoff.org>2014-11-07 18:13:30 +0000
commitaa6bebab28149dc9440749afadc279f134ea3f5c (patch)
treeaeac2470ed066a45c1f808933d0a93af4b279b39 /src/set/test_set_intersection_result_full.c
parent91b9ba2fc36c1919e11d515d790bae68860653db (diff)
downloadgnunet-aa6bebab28149dc9440749afadc279f134ea3f5c.tar.gz
gnunet-aa6bebab28149dc9440749afadc279f134ea3f5c.zip
make set testcase fail to highlight issue #3490
Diffstat (limited to 'src/set/test_set_intersection_result_full.c')
-rw-r--r--src/set/test_set_intersection_result_full.c119
1 files changed, 58 insertions, 61 deletions
diff --git a/src/set/test_set_intersection_result_full.c b/src/set/test_set_intersection_result_full.c
index b5140b101..c59624459 100644
--- a/src/set/test_set_intersection_result_full.c
+++ b/src/set/test_set_intersection_result_full.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors) 3 (C) 2012-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -21,6 +21,8 @@
21/** 21/**
22 * @file set/test_set_intersection_result_full.c 22 * @file set/test_set_intersection_result_full.c
23 * @brief testcase for full result mode of the intersection set operation 23 * @brief testcase for full result mode of the intersection set operation
24 * @author Christian Fuchs
25 * @author Christian Grothoff
24 */ 26 */
25#include "platform.h" 27#include "platform.h"
26#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
@@ -33,56 +35,63 @@ static int ret;
33static struct GNUNET_PeerIdentity local_id; 35static struct GNUNET_PeerIdentity local_id;
34 36
35static struct GNUNET_HashCode app_id; 37static struct GNUNET_HashCode app_id;
38
36static struct GNUNET_SET_Handle *set1; 39static struct GNUNET_SET_Handle *set1;
40
37static struct GNUNET_SET_Handle *set2; 41static struct GNUNET_SET_Handle *set2;
42
38static struct GNUNET_SET_ListenHandle *listen_handle; 43static struct GNUNET_SET_ListenHandle *listen_handle;
39const static struct GNUNET_CONFIGURATION_Handle *config; 44
45static const struct GNUNET_CONFIGURATION_Handle *config;
40 46
41static int iter_count; 47static int iter_count;
42 48
43 49
44static void 50static void
45result_cb_set1 (void *cls, const struct GNUNET_SET_Element *element, 51result_cb_set1 (void *cls,
52 const struct GNUNET_SET_Element *element,
46 enum GNUNET_SET_Status status) 53 enum GNUNET_SET_Status status)
47{ 54{
55 static int count;
48 switch (status) 56 switch (status)
49 { 57 {
50 case GNUNET_SET_STATUS_OK: 58 case GNUNET_SET_STATUS_OK:
51 printf ("set 1: got element\n"); 59 count++;
52 break; 60 break;
53 case GNUNET_SET_STATUS_FAILURE: 61 case GNUNET_SET_STATUS_FAILURE:
54 printf ("set 1: failure\n"); 62 ret = 1;
55 ret = 1; 63 break;
56 break; 64 case GNUNET_SET_STATUS_DONE:
57 case GNUNET_SET_STATUS_DONE: 65 GNUNET_assert (1 == count);
58 printf ("set 1: done\n"); 66 GNUNET_SET_destroy (set1);
59 GNUNET_SET_destroy (set1); 67 break;
60 break; 68 default:
61 default: 69 GNUNET_assert (0);
62 GNUNET_assert (0);
63 } 70 }
64} 71}
65 72
66 73
67static void 74static void
68result_cb_set2 (void *cls, const struct GNUNET_SET_Element *element, 75result_cb_set2 (void *cls,
69 enum GNUNET_SET_Status status) 76 const struct GNUNET_SET_Element *element,
77 enum GNUNET_SET_Status status)
70{ 78{
79 static int count;
80
71 switch (status) 81 switch (status)
72 { 82 {
73 case GNUNET_SET_STATUS_OK: 83 case GNUNET_SET_STATUS_OK:
74 printf ("set 2: got element\n"); 84 count++;
75 break; 85 break;
76 case GNUNET_SET_STATUS_FAILURE: 86 case GNUNET_SET_STATUS_FAILURE:
77 printf ("set 2: failure\n"); 87 ret = 1;
78 ret = 1; 88 break;
79 break; 89 case GNUNET_SET_STATUS_DONE:
80 case GNUNET_SET_STATUS_DONE: 90 GNUNET_assert (1 == count);
81 printf ("set 2: done\n"); 91 GNUNET_SET_destroy (set2);
82 GNUNET_SET_destroy (set2); 92 break;
83 break; 93 default:
84 default: 94 GNUNET_assert (0);
85 GNUNET_assert (0);
86 } 95 }
87} 96}
88 97
@@ -96,13 +105,11 @@ listen_cb (void *cls,
96 struct GNUNET_SET_OperationHandle *oh; 105 struct GNUNET_SET_OperationHandle *oh;
97 106
98 GNUNET_assert (NULL != context_msg); 107 GNUNET_assert (NULL != context_msg);
99
100 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST); 108 GNUNET_assert (ntohs (context_msg->type) == GNUNET_MESSAGE_TYPE_TEST);
101
102 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "listen cb called\n");
103 GNUNET_SET_listen_cancel (listen_handle); 109 GNUNET_SET_listen_cancel (listen_handle);
104 110 oh = GNUNET_SET_accept (request,
105 oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_FULL, result_cb_set2, NULL); 111 GNUNET_SET_RESULT_FULL,
112 &result_cb_set2, NULL);
106 GNUNET_SET_commit (oh, set2); 113 GNUNET_SET_commit (oh, set2);
107} 114}
108 115
@@ -120,12 +127,15 @@ start (void *cls)
120 127
121 context_msg.size = htons (sizeof context_msg); 128 context_msg.size = htons (sizeof context_msg);
122 context_msg.type = htons (GNUNET_MESSAGE_TYPE_TEST); 129 context_msg.type = htons (GNUNET_MESSAGE_TYPE_TEST);
123 130 listen_handle = GNUNET_SET_listen (config,
124 listen_handle = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_INTERSECTION, 131 GNUNET_SET_OPERATION_INTERSECTION,
125 &app_id, listen_cb, NULL); 132 &app_id,
126 oh = GNUNET_SET_prepare (&local_id, &app_id, &context_msg, 42, 133 &listen_cb, NULL);
134 oh = GNUNET_SET_prepare (&local_id,
135 &app_id,
136 &context_msg, 42,
127 GNUNET_SET_RESULT_FULL, 137 GNUNET_SET_RESULT_FULL,
128 result_cb_set1, NULL); 138 &result_cb_set1, NULL);
129 GNUNET_SET_commit (oh, set1); 139 GNUNET_SET_commit (oh, set1);
130} 140}
131 141
@@ -140,10 +150,9 @@ init_set2 (void *cls)
140{ 150{
141 struct GNUNET_SET_Element element; 151 struct GNUNET_SET_Element element;
142 152
143 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n"); 153 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
144 154 "initializing set 2\n");
145 element.type = 0; 155 element.type = 0;
146
147 element.data = "hello"; 156 element.data = "hello";
148 element.size = strlen(element.data); 157 element.size = strlen(element.data);
149 GNUNET_SET_add_element (set2, &element, NULL, NULL); 158 GNUNET_SET_add_element (set2, &element, NULL, NULL);
@@ -152,7 +161,7 @@ init_set2 (void *cls)
152 GNUNET_SET_add_element (set2, &element, NULL, NULL); 161 GNUNET_SET_add_element (set2, &element, NULL, NULL);
153 element.data = "baz"; 162 element.data = "baz";
154 element.size = strlen(element.data); 163 element.size = strlen(element.data);
155 GNUNET_SET_add_element (set2, &element, start, NULL); 164 GNUNET_SET_add_element (set2, &element, &start, NULL);
156} 165}
157 166
158 167
@@ -165,15 +174,12 @@ init_set1 (void)
165 struct GNUNET_SET_Element element; 174 struct GNUNET_SET_Element element;
166 175
167 element.type = 0; 176 element.type = 0;
168
169 element.data = "hello"; 177 element.data = "hello";
170 element.size = strlen(element.data); 178 element.size = strlen(element.data);
171 GNUNET_SET_add_element (set1, &element, NULL, NULL); 179 GNUNET_SET_add_element (set1, &element, NULL, NULL);
172 element.data = "bar"; 180 element.data = "bar";
173 element.size = strlen(element.data); 181 element.size = strlen(element.data);
174 GNUNET_SET_add_element (set1, &element, init_set2, NULL); 182 GNUNET_SET_add_element (set1, &element, &init_set2, NULL);
175
176 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized set 1\n");
177} 183}
178 184
179 185
@@ -187,7 +193,6 @@ iter_cb (void *cls,
187 GNUNET_SET_destroy (cls); 193 GNUNET_SET_destroy (cls);
188 return GNUNET_YES; 194 return GNUNET_YES;
189 } 195 }
190 printf ("iter: got element\n");
191 iter_count++; 196 iter_count++;
192 return GNUNET_YES; 197 return GNUNET_YES;
193} 198}
@@ -200,9 +205,7 @@ test_iter ()
200 struct GNUNET_SET_Handle *iter_set; 205 struct GNUNET_SET_Handle *iter_set;
201 206
202 iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_INTERSECTION); 207 iter_set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_INTERSECTION);
203
204 element.type = 0; 208 element.type = 0;
205
206 element.data = "hello"; 209 element.data = "hello";
207 element.size = strlen(element.data); 210 element.size = strlen(element.data);
208 GNUNET_SET_add_element (iter_set, &element, NULL, NULL); 211 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
@@ -212,8 +215,7 @@ test_iter ()
212 element.data = "quux"; 215 element.data = "quux";
213 element.size = strlen(element.data); 216 element.size = strlen(element.data);
214 GNUNET_SET_add_element (iter_set, &element, NULL, NULL); 217 GNUNET_SET_add_element (iter_set, &element, NULL, NULL);
215 218 GNUNET_SET_iterate (iter_set, &iter_cb, iter_set);
216 GNUNET_SET_iterate (iter_set, iter_cb, iter_set);
217} 219}
218 220
219 221
@@ -231,11 +233,7 @@ run (void *cls,
231 struct GNUNET_TESTING_Peer *peer) 233 struct GNUNET_TESTING_Peer *peer)
232{ 234{
233 config = cfg; 235 config = cfg;
234 GNUNET_CRYPTO_get_peer_identity (cfg, &local_id);
235 printf ("my id (from CRYPTO): %s\n", GNUNET_i2s (&local_id));
236 GNUNET_TESTING_peer_get_identity (peer, &local_id); 236 GNUNET_TESTING_peer_get_identity (peer, &local_id);
237 printf ("my id (from TESTING): %s\n", GNUNET_i2s (&local_id));
238
239 test_iter (); 237 test_iter ();
240 238
241 set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); 239 set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
@@ -246,15 +244,14 @@ run (void *cls,
246 init_set1 (); 244 init_set1 ();
247} 245}
248 246
247
249int 248int
250main (int argc, char **argv) 249main (int argc, char **argv)
251{ 250{
252 if (0 != GNUNET_TESTING_peer_run ("test_set_api", 251 if (0 != GNUNET_TESTING_peer_run ("test_set_api",
253 "test_set.conf", 252 "test_set.conf",
254 &run, NULL)) 253 &run, NULL))
255 { 254 return 1;
256 return 0;
257 }
258 return ret; 255 return ret;
259} 256}
260 257