aboutsummaryrefslogtreecommitdiff
path: root/src/hello/test_hello.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hello/test_hello.c')
-rw-r--r--src/hello/test_hello.c71
1 files changed, 26 insertions, 45 deletions
diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c
index bdabc72ea..ac482efe5 100644
--- a/src/hello/test_hello.c
+++ b/src/hello/test_hello.c
@@ -25,11 +25,6 @@
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_hello_lib.h" 26#include "gnunet_hello_lib.h"
27 27
28#define DEBUG GNUNET_NO
29
30#define VERBOSE GNUNET_NO
31
32
33static size_t 28static size_t
34my_addr_gen (void *cls, size_t max, void *buf) 29my_addr_gen (void *cls, size_t max, void *buf)
35{ 30{
@@ -37,9 +32,8 @@ my_addr_gen (void *cls, size_t max, void *buf)
37 size_t ret; 32 size_t ret;
38 struct GNUNET_HELLO_Address address; 33 struct GNUNET_HELLO_Address address;
39 34
40#if DEBUG 35 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
41 FPRINTF (stderr, "DEBUG: my_addr_gen called with i = %d\n", *i); 36 "DEBUG: my_addr_gen called with i = %d\n", *i);
42#endif
43 if (0 == *i) 37 if (0 == *i)
44 return 0; 38 return 0;
45 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); 39 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity));
@@ -60,10 +54,9 @@ check_addr (void *cls, const struct GNUNET_HELLO_Address *address,
60{ 54{
61 unsigned int *i = cls; 55 unsigned int *i = cls;
62 56
63#if DEBUG 57 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
64 FPRINTF (stderr, "DEBUG: check_addr called with i = %d and addrlen = %u\n", 58 "DEBUG: check_addr called with i = %d and addrlen = %u\n",
65 *i, (unsigned int) address->address_length); 59 *i, (unsigned int) address->address_length);
66#endif
67 GNUNET_assert (address->address_length > 0); 60 GNUNET_assert (address->address_length > 0);
68 GNUNET_assert (*i & (1 << (address->address_length - 1))); 61 GNUNET_assert (*i & (1 << (address->address_length - 1)));
69 *i -= (1 << (address->address_length - 1)); 62 *i -= (1 << (address->address_length - 1));
@@ -81,10 +74,9 @@ remove_some (void *cls, const struct GNUNET_HELLO_Address *address,
81{ 74{
82 unsigned int *i = cls; 75 unsigned int *i = cls;
83 76
84#if DEBUG 77 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
85 FPRINTF (stderr, "DEBUG: remove_some called with i = %d and addrlen = %u\n", 78 "DEBUG: remove_some called with i = %d and addrlen = %u\n",
86 *i, (unsigned int) address->address_length); 79 *i, (unsigned int) address->address_length);
87#endif
88 GNUNET_assert (address->address_length > 0); 80 GNUNET_assert (address->address_length > 0);
89 if (*i & (1 << (address->address_length - 1))) 81 if (*i & (1 << (address->address_length - 1)))
90 { 82 {
@@ -109,65 +101,56 @@ main (int argc, char *argv[])
109 GNUNET_log_setup ("test-hello", "DEBUG", NULL); 101 GNUNET_log_setup ("test-hello", "DEBUG", NULL);
110 startup_time = GNUNET_TIME_absolute_get (); 102 startup_time = GNUNET_TIME_absolute_get ();
111 memset (&publicKey, 42, sizeof (publicKey)); 103 memset (&publicKey, 42, sizeof (publicKey));
112#if VERBOSE 104 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
113 FPRINTF (stderr, "%s", "Testing HELLO creation (without addresses)...\n"); 105 "Testing HELLO creation (without addresses)...\n");
114#endif
115 i = 0; 106 i = 0;
116 msg1 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i); 107 msg1 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i);
117 GNUNET_assert (msg1 != NULL); 108 GNUNET_assert (msg1 != NULL);
118 GNUNET_assert (0 < GNUNET_HELLO_size (msg1)); 109 GNUNET_assert (0 < GNUNET_HELLO_size (msg1));
119 110
120#if VERBOSE 111 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
121 FPRINTF (stderr, "%s", "Testing address iteration (empty set)...\n"); 112 "Testing address iteration (empty set)...\n");
122#endif
123 GNUNET_assert (NULL == 113 GNUNET_assert (NULL ==
124 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr, 114 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
125 &i)); 115 &i));
126 116 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
127#if VERBOSE 117 "Testing HELLO creation (with one address)...\n");
128 FPRINTF (stderr, "%s", "Testing HELLO creation (with one address)...\n");
129#endif
130 i = 1; 118 i = 1;
131 msg2 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i); 119 msg2 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i);
132 GNUNET_assert (msg2 != NULL); 120 GNUNET_assert (msg2 != NULL);
133 GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2)); 121 GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2));
134 122
135#if VERBOSE 123 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
136 FPRINTF (stderr, "%s", "Testing address iteration (one address)...\n"); 124 "Testing address iteration (one address)...\n");
137#endif
138 i = 1; 125 i = 1;
139 GNUNET_assert (NULL == 126 GNUNET_assert (NULL ==
140 GNUNET_HELLO_iterate_addresses (msg2, GNUNET_NO, &check_addr, 127 GNUNET_HELLO_iterate_addresses (msg2, GNUNET_NO, &check_addr,
141 &i)); 128 &i));
142 GNUNET_assert (i == 0); 129 GNUNET_assert (i == 0);
143 130
144#if VERBOSE 131 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
145 FPRINTF (stderr, "%s", "Testing get_key from HELLO...\n"); 132 "Testing get_key from HELLO...\n");
146#endif
147 GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_key (msg2, &pk)); 133 GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_key (msg2, &pk));
148 GNUNET_assert (0 == memcmp (&publicKey, &pk, sizeof (pk))); 134 GNUNET_assert (0 == memcmp (&publicKey, &pk, sizeof (pk)));
149 GNUNET_free (msg1); 135 GNUNET_free (msg1);
150 136
151#if VERBOSE 137 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
152 FPRINTF (stderr, "%s", "Testing HELLO creation (with two addresses)...\n"); 138 "Testing HELLO creation (with two addresses)...\n");
153#endif
154 i = 2; 139 i = 2;
155 msg3 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i); 140 msg3 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i);
156 GNUNET_assert (msg3 != NULL); 141 GNUNET_assert (msg3 != NULL);
157 GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3)); 142 GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3));
158 143
159#if VERBOSE 144 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
160 FPRINTF (stderr, "%s", "Testing address iteration (two addresses)...\n"); 145 "Testing address iteration (two addresses)...\n");
161#endif
162 i = 3; 146 i = 3;
163 GNUNET_assert (NULL == 147 GNUNET_assert (NULL ==
164 GNUNET_HELLO_iterate_addresses (msg3, GNUNET_NO, &check_addr, 148 GNUNET_HELLO_iterate_addresses (msg3, GNUNET_NO, &check_addr,
165 &i)); 149 &i));
166 GNUNET_assert (i == 0); 150 GNUNET_assert (i == 0);
167 151
168#if VERBOSE 152 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
169 FPRINTF (stderr, "%s", "Testing HELLO merge...\n"); 153 "Testing HELLO merge...\n");
170#endif
171 msg1 = GNUNET_HELLO_merge (msg2, msg3); 154 msg1 = GNUNET_HELLO_merge (msg2, msg3);
172 GNUNET_assert (GNUNET_HELLO_size (msg1) == GNUNET_HELLO_size (msg3)); 155 GNUNET_assert (GNUNET_HELLO_size (msg1) == GNUNET_HELLO_size (msg3));
173 156
@@ -178,9 +161,8 @@ main (int argc, char *argv[])
178 GNUNET_assert (i == 0); 161 GNUNET_assert (i == 0);
179 GNUNET_free (msg1); 162 GNUNET_free (msg1);
180 163
181#if VERBOSE 164 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
182 FPRINTF (stderr, "%s", "Testing address iteration to copy HELLO...\n"); 165 "Testing address iteration to copy HELLO...\n");
183#endif
184 i = 2; 166 i = 2;
185 msg1 = GNUNET_HELLO_iterate_addresses (msg3, GNUNET_YES, &remove_some, &i); 167 msg1 = GNUNET_HELLO_iterate_addresses (msg3, GNUNET_YES, &remove_some, &i);
186 GNUNET_assert (msg1 != NULL); 168 GNUNET_assert (msg1 != NULL);
@@ -192,9 +174,8 @@ main (int argc, char *argv[])
192 GNUNET_assert (i == 0); 174 GNUNET_assert (i == 0);
193 GNUNET_free (msg1); 175 GNUNET_free (msg1);
194 176
195#if VERBOSE 177 GNUNTE_log (GNUNET_ERROR_TYPE_DEBUG,
196 FPRINTF (stderr, "%s", "Testing delta address iteration...\n"); 178 "Testing delta address iteration...\n");
197#endif
198 i = 2; 179 i = 2;
199 GNUNET_HELLO_iterate_new_addresses (msg3, msg2, startup_time, &check_addr, 180 GNUNET_HELLO_iterate_new_addresses (msg3, msg2, startup_time, &check_addr,
200 &i); 181 &i);