aboutsummaryrefslogtreecommitdiff
path: root/src/hello/test_hello.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/hello/test_hello.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/hello/test_hello.c')
-rw-r--r--src/hello/test_hello.c284
1 files changed, 142 insertions, 142 deletions
diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c
index f3134a7ad..1580dcc55 100644
--- a/src/hello/test_hello.c
+++ b/src/hello/test_hello.c
@@ -35,27 +35,27 @@
35 * @return 35 * @return
36 */ 36 */
37static ssize_t 37static ssize_t
38my_addr_gen(void *cls, 38my_addr_gen (void *cls,
39 size_t max, 39 size_t max,
40 void *buf) 40 void *buf)
41{ 41{
42 unsigned int *i = cls; 42 unsigned int *i = cls;
43 size_t ret; 43 size_t ret;
44 struct GNUNET_HELLO_Address address; 44 struct GNUNET_HELLO_Address address;
45 45
46 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
47 "DEBUG: my_addr_gen called with i = %d\n", 47 "DEBUG: my_addr_gen called with i = %d\n",
48 *i); 48 *i);
49 if (0 == *i) 49 if (0 == *i)
50 return GNUNET_SYSERR; 50 return GNUNET_SYSERR;
51 memset(&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); 51 memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity));
52 address.address = "address_information"; 52 address.address = "address_information";
53 address.transport_name = "test"; 53 address.transport_name = "test";
54 address.address_length = *i; 54 address.address_length = *i;
55 ret = GNUNET_HELLO_add_address(&address, 55 ret = GNUNET_HELLO_add_address (&address,
56 GNUNET_TIME_absolute_get(), 56 GNUNET_TIME_absolute_get (),
57 buf, 57 buf,
58 max); 58 max);
59 (*i)--; 59 (*i)--;
60 return ret; 60 return ret;
61} 61}
@@ -70,25 +70,25 @@ my_addr_gen(void *cls,
70 * @return 70 * @return
71 */ 71 */
72static int 72static int
73check_addr(void *cls, 73check_addr (void *cls,
74 const struct GNUNET_HELLO_Address *address, 74 const struct GNUNET_HELLO_Address *address,
75 struct GNUNET_TIME_Absolute expiration) 75 struct GNUNET_TIME_Absolute expiration)
76{ 76{
77 unsigned int *i = cls; 77 unsigned int *i = cls;
78 78
79 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 79 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
80 "DEBUG: check_addr called with i = %d and addrlen = %u\n", 80 "DEBUG: check_addr called with i = %d and addrlen = %u\n",
81 *i, 81 *i,
82 (unsigned int)address->address_length); 82 (unsigned int) address->address_length);
83 GNUNET_assert(address->address_length > 0); 83 GNUNET_assert (address->address_length > 0);
84 GNUNET_assert(*i & (1 << (address->address_length - 1))); 84 GNUNET_assert (*i & (1 << (address->address_length - 1)));
85 *i -= (1 << (address->address_length - 1)); 85 *i -= (1 << (address->address_length - 1));
86 GNUNET_assert(0 == 86 GNUNET_assert (0 ==
87 strncmp("address_information", 87 strncmp ("address_information",
88 address->address, 88 address->address,
89 address->address_length)); 89 address->address_length));
90 GNUNET_assert(0 == strcmp("test", 90 GNUNET_assert (0 == strcmp ("test",
91 address->transport_name)); 91 address->transport_name));
92 return GNUNET_OK; 92 return GNUNET_OK;
93} 93}
94 94
@@ -102,29 +102,29 @@ check_addr(void *cls,
102 * @return 102 * @return
103 */ 103 */
104static int 104static int
105remove_some(void *cls, 105remove_some (void *cls,
106 const struct GNUNET_HELLO_Address *address, 106 const struct GNUNET_HELLO_Address *address,
107 struct GNUNET_TIME_Absolute expiration) 107 struct GNUNET_TIME_Absolute expiration)
108{ 108{
109 unsigned int *i = cls; 109 unsigned int *i = cls;
110 110
111 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
112 "DEBUG: remove_some called with i = %d and addrlen = %u\n", 112 "DEBUG: remove_some called with i = %d and addrlen = %u\n",
113 *i, 113 *i,
114 (unsigned int)address->address_length); 114 (unsigned int) address->address_length);
115 GNUNET_assert(address->address_length > 0); 115 GNUNET_assert (address->address_length > 0);
116 if (*i & (1 << (address->address_length - 1))) 116 if (*i & (1 << (address->address_length - 1)))
117 { 117 {
118 *i -= (1 << (address->address_length - 1)); 118 *i -= (1 << (address->address_length - 1));
119 return GNUNET_NO; 119 return GNUNET_NO;
120 } 120 }
121 return GNUNET_OK; 121 return GNUNET_OK;
122} 122}
123 123
124 124
125int 125int
126main(int argc, 126main (int argc,
127 char *argv[]) 127 char *argv[])
128{ 128{
129 struct GNUNET_HELLO_Message *msg1; 129 struct GNUNET_HELLO_Message *msg1;
130 struct GNUNET_HELLO_Message *msg2; 130 struct GNUNET_HELLO_Message *msg2;
@@ -134,118 +134,118 @@ main(int argc,
134 struct GNUNET_TIME_Absolute startup_time; 134 struct GNUNET_TIME_Absolute startup_time;
135 unsigned int i; 135 unsigned int i;
136 136
137 GNUNET_log_setup("test-hello", 137 GNUNET_log_setup ("test-hello",
138 "DEBUG", 138 "DEBUG",
139 NULL); 139 NULL);
140 startup_time = GNUNET_TIME_absolute_get(); 140 startup_time = GNUNET_TIME_absolute_get ();
141 memset(&publicKey, 42, sizeof(publicKey)); 141 memset (&publicKey, 42, sizeof(publicKey));
142 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
143 "Testing HELLO creation (without addresses)...\n"); 143 "Testing HELLO creation (without addresses)...\n");
144 i = 0; 144 i = 0;
145 msg1 = GNUNET_HELLO_create(&publicKey, 145 msg1 = GNUNET_HELLO_create (&publicKey,
146 &my_addr_gen, 146 &my_addr_gen,
147 &i, 147 &i,
148 GNUNET_NO); 148 GNUNET_NO);
149 GNUNET_assert(msg1 != NULL); 149 GNUNET_assert (msg1 != NULL);
150 GNUNET_assert(0 < GNUNET_HELLO_size(msg1)); 150 GNUNET_assert (0 < GNUNET_HELLO_size (msg1));
151 151
152 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Testing address iteration (empty set)...\n"); 153 "Testing address iteration (empty set)...\n");
154 GNUNET_assert(NULL == 154 GNUNET_assert (NULL ==
155 GNUNET_HELLO_iterate_addresses(msg1, 155 GNUNET_HELLO_iterate_addresses (msg1,
156 GNUNET_NO, 156 GNUNET_NO,
157 &check_addr, 157 &check_addr,
158 &i)); 158 &i));
159 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
160 "Testing HELLO creation (with one address)...\n"); 160 "Testing HELLO creation (with one address)...\n");
161 i = 1; 161 i = 1;
162 msg2 = GNUNET_HELLO_create(&publicKey, 162 msg2 = GNUNET_HELLO_create (&publicKey,
163 &my_addr_gen, 163 &my_addr_gen,
164 &i, 164 &i,
165 GNUNET_NO); 165 GNUNET_NO);
166 GNUNET_assert(msg2 != NULL); 166 GNUNET_assert (msg2 != NULL);
167 GNUNET_assert(GNUNET_HELLO_size(msg1) < GNUNET_HELLO_size(msg2)); 167 GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2));
168 168
169 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "Testing address iteration (one address)...\n"); 170 "Testing address iteration (one address)...\n");
171 i = 1; 171 i = 1;
172 GNUNET_assert(NULL == 172 GNUNET_assert (NULL ==
173 GNUNET_HELLO_iterate_addresses(msg2, 173 GNUNET_HELLO_iterate_addresses (msg2,
174 GNUNET_NO, 174 GNUNET_NO,
175 &check_addr, 175 &check_addr,
176 &i)); 176 &i));
177 GNUNET_assert(i == 0); 177 GNUNET_assert (i == 0);
178 178
179 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
180 "Testing get_key from HELLO...\n"); 180 "Testing get_key from HELLO...\n");
181 GNUNET_assert(GNUNET_OK == GNUNET_HELLO_get_id(msg2, &pid)); 181 GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (msg2, &pid));
182 GNUNET_assert(0 == GNUNET_memcmp(&publicKey, 182 GNUNET_assert (0 == GNUNET_memcmp (&publicKey,
183 &pid.public_key)); 183 &pid.public_key));
184 GNUNET_free(msg1); 184 GNUNET_free (msg1);
185 185
186 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "Testing HELLO creation (with two addresses)...\n"); 187 "Testing HELLO creation (with two addresses)...\n");
188 i = 2; 188 i = 2;
189 msg3 = GNUNET_HELLO_create(&publicKey, 189 msg3 = GNUNET_HELLO_create (&publicKey,
190 &my_addr_gen, 190 &my_addr_gen,
191 &i, 191 &i,
192 GNUNET_NO); 192 GNUNET_NO);
193 GNUNET_assert(msg3 != NULL); 193 GNUNET_assert (msg3 != NULL);
194 GNUNET_assert(GNUNET_HELLO_size(msg2) < GNUNET_HELLO_size(msg3)); 194 GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3));
195 195
196 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
197 "Testing address iteration (two addresses)...\n"); 197 "Testing address iteration (two addresses)...\n");
198 i = 3; 198 i = 3;
199 GNUNET_assert(NULL == 199 GNUNET_assert (NULL ==
200 GNUNET_HELLO_iterate_addresses(msg3, 200 GNUNET_HELLO_iterate_addresses (msg3,
201 GNUNET_NO, 201 GNUNET_NO,
202 &check_addr, 202 &check_addr,
203 &i)); 203 &i));
204 GNUNET_assert(i == 0); 204 GNUNET_assert (i == 0);
205 205
206 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207 "Testing HELLO merge...\n"); 207 "Testing HELLO merge...\n");
208 msg1 = GNUNET_HELLO_merge(msg2, msg3); 208 msg1 = GNUNET_HELLO_merge (msg2, msg3);
209 GNUNET_assert(GNUNET_HELLO_size(msg1) == GNUNET_HELLO_size(msg3)); 209 GNUNET_assert (GNUNET_HELLO_size (msg1) == GNUNET_HELLO_size (msg3));
210 210
211 i = 3; 211 i = 3;
212 GNUNET_assert(NULL == 212 GNUNET_assert (NULL ==
213 GNUNET_HELLO_iterate_addresses(msg1, 213 GNUNET_HELLO_iterate_addresses (msg1,
214 GNUNET_NO, 214 GNUNET_NO,
215 &check_addr, 215 &check_addr,
216 &i)); 216 &i));
217 GNUNET_assert(i == 0); 217 GNUNET_assert (i == 0);
218 GNUNET_free(msg1); 218 GNUNET_free (msg1);
219 219
220 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
221 "Testing address iteration to copy HELLO...\n"); 221 "Testing address iteration to copy HELLO...\n");
222 i = 2; 222 i = 2;
223 msg1 = GNUNET_HELLO_iterate_addresses(msg3, 223 msg1 = GNUNET_HELLO_iterate_addresses (msg3,
224 GNUNET_YES, 224 GNUNET_YES,
225 &remove_some, 225 &remove_some,
226 &i); 226 &i);
227 GNUNET_assert(msg1 != NULL); 227 GNUNET_assert (msg1 != NULL);
228 GNUNET_assert(i == 0); 228 GNUNET_assert (i == 0);
229 i = 1; 229 i = 1;
230 GNUNET_assert(NULL == 230 GNUNET_assert (NULL ==
231 GNUNET_HELLO_iterate_addresses(msg1, 231 GNUNET_HELLO_iterate_addresses (msg1,
232 GNUNET_NO, 232 GNUNET_NO,
233 &check_addr, 233 &check_addr,
234 &i)); 234 &i));
235 GNUNET_assert(i == 0); 235 GNUNET_assert (i == 0);
236 GNUNET_free(msg1); 236 GNUNET_free (msg1);
237 237
238 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
239 "Testing delta address iteration...\n"); 239 "Testing delta address iteration...\n");
240 i = 2; 240 i = 2;
241 GNUNET_HELLO_iterate_new_addresses(msg3, 241 GNUNET_HELLO_iterate_new_addresses (msg3,
242 msg2, 242 msg2,
243 startup_time, 243 startup_time,
244 &check_addr, 244 &check_addr,
245 &i); 245 &i);
246 GNUNET_assert(i == 0); 246 GNUNET_assert (i == 0);
247 GNUNET_free(msg2); 247 GNUNET_free (msg2);
248 GNUNET_free(msg3); 248 GNUNET_free (msg3);
249 return 0; /* testcase passed */ 249 return 0; /* testcase passed */
250} 250}
251 251