diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/hello/test_friend_hello.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/hello/test_friend_hello.c')
-rw-r--r-- | src/hello/test_friend_hello.c | 196 |
1 files changed, 98 insertions, 98 deletions
diff --git a/src/hello/test_friend_hello.c b/src/hello/test_friend_hello.c index 7cbb019c6..1b092c0b8 100644 --- a/src/hello/test_friend_hello.c +++ b/src/hello/test_friend_hello.c | |||
@@ -27,73 +27,73 @@ | |||
27 | 27 | ||
28 | 28 | ||
29 | static ssize_t | 29 | static ssize_t |
30 | my_addr_gen(void *cls, | 30 | my_addr_gen (void *cls, |
31 | size_t max, | 31 | size_t max, |
32 | void *buf) | 32 | void *buf) |
33 | { | 33 | { |
34 | unsigned int *i = cls; | 34 | unsigned int *i = cls; |
35 | size_t ret; | 35 | size_t ret; |
36 | struct GNUNET_HELLO_Address address; | 36 | struct GNUNET_HELLO_Address address; |
37 | 37 | ||
38 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 38 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
39 | "DEBUG: my_addr_gen called with i = %d\n", *i); | 39 | "DEBUG: my_addr_gen called with i = %d\n", *i); |
40 | if (0 == *i) | 40 | if (0 == *i) |
41 | return GNUNET_SYSERR; /* Stop iteration */ | 41 | return GNUNET_SYSERR; /* Stop iteration */ |
42 | memset(&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); | 42 | memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); |
43 | address.address = "address_information"; | 43 | address.address = "address_information"; |
44 | address.transport_name = "test"; | 44 | address.transport_name = "test"; |
45 | address.address_length = *i; | 45 | address.address_length = *i; |
46 | ret = | 46 | ret = |
47 | GNUNET_HELLO_add_address(&address, GNUNET_TIME_absolute_get(), buf, | 47 | GNUNET_HELLO_add_address (&address, GNUNET_TIME_absolute_get (), buf, |
48 | max); | 48 | max); |
49 | (*i)--; | 49 | (*i)--; |
50 | return ret; | 50 | return ret; |
51 | } | 51 | } |
52 | 52 | ||
53 | 53 | ||
54 | static int | 54 | static int |
55 | check_addr(void *cls, | 55 | check_addr (void *cls, |
56 | const struct GNUNET_HELLO_Address *address, | 56 | const struct GNUNET_HELLO_Address *address, |
57 | struct GNUNET_TIME_Absolute expiration) | 57 | struct GNUNET_TIME_Absolute expiration) |
58 | { | 58 | { |
59 | unsigned int *i = cls; | 59 | unsigned int *i = cls; |
60 | 60 | ||
61 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 61 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
62 | "DEBUG: check_addr called with i = %d and addrlen = %u\n", | 62 | "DEBUG: check_addr called with i = %d and addrlen = %u\n", |
63 | *i, (unsigned int)address->address_length); | 63 | *i, (unsigned int) address->address_length); |
64 | GNUNET_assert(address->address_length > 0); | 64 | GNUNET_assert (address->address_length > 0); |
65 | GNUNET_assert(*i & (1 << (address->address_length - 1))); | 65 | GNUNET_assert (*i & (1 << (address->address_length - 1))); |
66 | *i -= (1 << (address->address_length - 1)); | 66 | *i -= (1 << (address->address_length - 1)); |
67 | GNUNET_assert(0 == | 67 | GNUNET_assert (0 == |
68 | strncmp("address_information", address->address, | 68 | strncmp ("address_information", address->address, |
69 | address->address_length)); | 69 | address->address_length)); |
70 | GNUNET_assert(0 == strcmp("test", address->transport_name)); | 70 | GNUNET_assert (0 == strcmp ("test", address->transport_name)); |
71 | return GNUNET_OK; | 71 | return GNUNET_OK; |
72 | } | 72 | } |
73 | 73 | ||
74 | 74 | ||
75 | static int | 75 | static int |
76 | remove_some(void *cls, | 76 | remove_some (void *cls, |
77 | const struct GNUNET_HELLO_Address *address, | 77 | const struct GNUNET_HELLO_Address *address, |
78 | struct GNUNET_TIME_Absolute expiration) | 78 | struct GNUNET_TIME_Absolute expiration) |
79 | { | 79 | { |
80 | unsigned int *i = cls; | 80 | unsigned int *i = cls; |
81 | 81 | ||
82 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
83 | "DEBUG: remove_some called with i = %d and addrlen = %u\n", | 83 | "DEBUG: remove_some called with i = %d and addrlen = %u\n", |
84 | *i, (unsigned int)address->address_length); | 84 | *i, (unsigned int) address->address_length); |
85 | GNUNET_assert(address->address_length > 0); | 85 | GNUNET_assert (address->address_length > 0); |
86 | if (*i & (1 << (address->address_length - 1))) | 86 | if (*i & (1 << (address->address_length - 1))) |
87 | { | 87 | { |
88 | *i -= (1 << (address->address_length - 1)); | 88 | *i -= (1 << (address->address_length - 1)); |
89 | return GNUNET_NO; | 89 | return GNUNET_NO; |
90 | } | 90 | } |
91 | return GNUNET_OK; | 91 | return GNUNET_OK; |
92 | } | 92 | } |
93 | 93 | ||
94 | 94 | ||
95 | int | 95 | int |
96 | main(int argc, char *argv[]) | 96 | main (int argc, char *argv[]) |
97 | { | 97 | { |
98 | struct GNUNET_HELLO_Message *msg1; | 98 | struct GNUNET_HELLO_Message *msg1; |
99 | struct GNUNET_HELLO_Message *msg2; | 99 | struct GNUNET_HELLO_Message *msg2; |
@@ -102,84 +102,84 @@ main(int argc, char *argv[]) | |||
102 | struct GNUNET_TIME_Absolute startup_time; | 102 | struct GNUNET_TIME_Absolute startup_time; |
103 | unsigned int i; | 103 | unsigned int i; |
104 | 104 | ||
105 | GNUNET_log_setup("test-hello", "DEBUG", NULL); | 105 | GNUNET_log_setup ("test-hello", "DEBUG", NULL); |
106 | startup_time = GNUNET_TIME_absolute_get(); | 106 | startup_time = GNUNET_TIME_absolute_get (); |
107 | memset(&publicKey, 42, sizeof(publicKey)); | 107 | memset (&publicKey, 42, sizeof(publicKey)); |
108 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
109 | "Testing HELLO creation (without addresses)...\n"); | 109 | "Testing HELLO creation (without addresses)...\n"); |
110 | i = 0; | 110 | i = 0; |
111 | msg1 = GNUNET_HELLO_create(&publicKey, &my_addr_gen, &i, GNUNET_YES); | 111 | msg1 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES); |
112 | GNUNET_assert(msg1 != NULL); | 112 | GNUNET_assert (msg1 != NULL); |
113 | GNUNET_assert(0 < GNUNET_HELLO_size(msg1)); | 113 | GNUNET_assert (0 < GNUNET_HELLO_size (msg1)); |
114 | 114 | ||
115 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
116 | "Testing address iteration (empty set)...\n"); | 116 | "Testing address iteration (empty set)...\n"); |
117 | GNUNET_assert(NULL == | 117 | GNUNET_assert (NULL == |
118 | GNUNET_HELLO_iterate_addresses(msg1, GNUNET_NO, &check_addr, | 118 | GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr, |
119 | &i)); | 119 | &i)); |
120 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
121 | "Testing HELLO creation (with one address)...\n"); | 121 | "Testing HELLO creation (with one address)...\n"); |
122 | i = 1; | 122 | i = 1; |
123 | msg2 = GNUNET_HELLO_create(&publicKey, &my_addr_gen, &i, GNUNET_YES); | 123 | msg2 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES); |
124 | GNUNET_assert(msg2 != NULL); | 124 | GNUNET_assert (msg2 != NULL); |
125 | GNUNET_assert(GNUNET_HELLO_size(msg1) < GNUNET_HELLO_size(msg2)); | 125 | GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2)); |
126 | 126 | ||
127 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
128 | "Testing address iteration (one address)...\n"); | 128 | "Testing address iteration (one address)...\n"); |
129 | i = 1; | 129 | i = 1; |
130 | GNUNET_assert(NULL == | 130 | GNUNET_assert (NULL == |
131 | GNUNET_HELLO_iterate_addresses(msg2, GNUNET_NO, &check_addr, | 131 | GNUNET_HELLO_iterate_addresses (msg2, GNUNET_NO, &check_addr, |
132 | &i)); | 132 | &i)); |
133 | GNUNET_assert(i == 0); | 133 | GNUNET_assert (i == 0); |
134 | GNUNET_free(msg1); | 134 | GNUNET_free (msg1); |
135 | 135 | ||
136 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
137 | "Testing HELLO creation (with two addresses)...\n"); | 137 | "Testing HELLO creation (with two addresses)...\n"); |
138 | i = 2; | 138 | i = 2; |
139 | msg3 = GNUNET_HELLO_create(&publicKey, &my_addr_gen, &i, GNUNET_YES); | 139 | msg3 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES); |
140 | GNUNET_assert(msg3 != NULL); | 140 | GNUNET_assert (msg3 != NULL); |
141 | GNUNET_assert(GNUNET_HELLO_size(msg2) < GNUNET_HELLO_size(msg3)); | 141 | GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3)); |
142 | 142 | ||
143 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
144 | "Testing address iteration (two addresses)...\n"); | 144 | "Testing address iteration (two addresses)...\n"); |
145 | i = 3; | 145 | i = 3; |
146 | GNUNET_assert(NULL == | 146 | GNUNET_assert (NULL == |
147 | GNUNET_HELLO_iterate_addresses(msg3, GNUNET_NO, &check_addr, | 147 | GNUNET_HELLO_iterate_addresses (msg3, GNUNET_NO, &check_addr, |
148 | &i)); | 148 | &i)); |
149 | GNUNET_assert(i == 0); | 149 | GNUNET_assert (i == 0); |
150 | 150 | ||
151 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
152 | "Testing HELLO merge...\n"); | 152 | "Testing HELLO merge...\n"); |
153 | msg1 = GNUNET_HELLO_merge(msg2, msg3); | 153 | msg1 = GNUNET_HELLO_merge (msg2, msg3); |
154 | GNUNET_assert(GNUNET_HELLO_size(msg1) == GNUNET_HELLO_size(msg3)); | 154 | GNUNET_assert (GNUNET_HELLO_size (msg1) == GNUNET_HELLO_size (msg3)); |
155 | 155 | ||
156 | i = 3; | 156 | i = 3; |
157 | GNUNET_assert(NULL == | 157 | GNUNET_assert (NULL == |
158 | GNUNET_HELLO_iterate_addresses(msg1, GNUNET_NO, &check_addr, | 158 | GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr, |
159 | &i)); | 159 | &i)); |
160 | GNUNET_assert(i == 0); | 160 | GNUNET_assert (i == 0); |
161 | GNUNET_free(msg1); | 161 | GNUNET_free (msg1); |
162 | 162 | ||
163 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
164 | "Testing address iteration to copy HELLO...\n"); | 164 | "Testing address iteration to copy HELLO...\n"); |
165 | i = 2; | 165 | i = 2; |
166 | msg1 = GNUNET_HELLO_iterate_addresses(msg3, GNUNET_YES, &remove_some, &i); | 166 | msg1 = GNUNET_HELLO_iterate_addresses (msg3, GNUNET_YES, &remove_some, &i); |
167 | GNUNET_assert(msg1 != NULL); | 167 | GNUNET_assert (msg1 != NULL); |
168 | GNUNET_assert(i == 0); | 168 | GNUNET_assert (i == 0); |
169 | i = 1; | 169 | i = 1; |
170 | GNUNET_assert(NULL == | 170 | GNUNET_assert (NULL == |
171 | GNUNET_HELLO_iterate_addresses(msg1, GNUNET_NO, &check_addr, | 171 | GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr, |
172 | &i)); | 172 | &i)); |
173 | GNUNET_assert(i == 0); | 173 | GNUNET_assert (i == 0); |
174 | GNUNET_free(msg1); | 174 | GNUNET_free (msg1); |
175 | 175 | ||
176 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 176 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
177 | "Testing delta address iteration...\n"); | 177 | "Testing delta address iteration...\n"); |
178 | i = 2; | 178 | i = 2; |
179 | GNUNET_HELLO_iterate_new_addresses(msg3, msg2, startup_time, &check_addr, | 179 | GNUNET_HELLO_iterate_new_addresses (msg3, msg2, startup_time, &check_addr, |
180 | &i); | 180 | &i); |
181 | GNUNET_assert(i == 0); | 181 | GNUNET_assert (i == 0); |
182 | GNUNET_free(msg2); | 182 | GNUNET_free (msg2); |
183 | GNUNET_free(msg3); | 183 | GNUNET_free (msg3); |
184 | return 0; /* testcase passed */ | 184 | return 0; /* testcase passed */ |
185 | } | 185 | } |