X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fhello%2Ftest_hello.c;h=6d824ef81f517015f086327336fc3345851b7240;hb=f40acfa927bb605c81c99ed250277d51bf951e25;hp=64abec5e4bf7be7628ceb4af0235ce1318bb4d59;hpb=b3883971cd31d198dbd768fffb15960dff0352a6;p=oweals%2Fgnunet.git diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c index 64abec5e4..6d824ef81 100644 --- a/src/hello/test_hello.c +++ b/src/hello/test_hello.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet - (C) 2009 Christian Grothoff (and other contributing authors) + Copyright (C) 2009, 2015 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /** * @file hello/test_hello.c @@ -25,58 +25,93 @@ #include "platform.h" #include "gnunet_hello_lib.h" -static size_t -my_addr_gen (void *cls, size_t max, void *buf) + +/** + * + * + * @param cls + * @param max + * @param buf + * @return + */ +static ssize_t +my_addr_gen (void *cls, + size_t max, + void *buf) { unsigned int *i = cls; size_t ret; struct GNUNET_HELLO_Address address; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "DEBUG: my_addr_gen called with i = %d\n", *i); + "DEBUG: my_addr_gen called with i = %d\n", + *i); if (0 == *i) - return 0; + return GNUNET_SYSERR; memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); address.address = "address_information"; address.transport_name = "test"; address.address_length = *i; - ret = - GNUNET_HELLO_add_address (&address, GNUNET_TIME_absolute_get (), buf, - max); + ret = GNUNET_HELLO_add_address (&address, + GNUNET_TIME_absolute_get (), + buf, + max); (*i)--; return ret; } +/** + * + * + * @param cls + * @param address + * @param expiration + * @return + */ static int -check_addr (void *cls, const struct GNUNET_HELLO_Address *address, +check_addr (void *cls, + const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration) { unsigned int *i = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "DEBUG: check_addr called with i = %d and addrlen = %u\n", - *i, (unsigned int) address->address_length); + "DEBUG: check_addr called with i = %d and addrlen = %u\n", + *i, + (unsigned int) address->address_length); GNUNET_assert (address->address_length > 0); GNUNET_assert (*i & (1 << (address->address_length - 1))); *i -= (1 << (address->address_length - 1)); GNUNET_assert (0 == - strncmp ("address_information", address->address, + strncmp ("address_information", + address->address, address->address_length)); - GNUNET_assert (0 == strcmp ("test", address->transport_name)); + GNUNET_assert (0 == strcmp ("test", + address->transport_name)); return GNUNET_OK; } +/** + * + * + * @param cls + * @param address + * @param expiration + * @return + */ static int -remove_some (void *cls, const struct GNUNET_HELLO_Address *address, +remove_some (void *cls, + const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration) { unsigned int *i = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DEBUG: remove_some called with i = %d and addrlen = %u\n", - *i, (unsigned int) address->address_length); + *i, + (unsigned int) address->address_length); GNUNET_assert (address->address_length > 0); if (*i & (1 << (address->address_length - 1))) { @@ -88,35 +123,46 @@ remove_some (void *cls, const struct GNUNET_HELLO_Address *address, int -main (int argc, char *argv[]) +main (int argc, + char *argv[]) { struct GNUNET_HELLO_Message *msg1; struct GNUNET_HELLO_Message *msg2; struct GNUNET_HELLO_Message *msg3; - struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded publicKey; - struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk; + struct GNUNET_CRYPTO_EddsaPublicKey publicKey; + struct GNUNET_PeerIdentity pid; struct GNUNET_TIME_Absolute startup_time; unsigned int i; - GNUNET_log_setup ("test-hello", "DEBUG", NULL); + GNUNET_log_setup ("test-hello", + "DEBUG", + NULL); startup_time = GNUNET_TIME_absolute_get (); memset (&publicKey, 42, sizeof (publicKey)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing HELLO creation (without addresses)...\n"); i = 0; - msg1 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_NO); + msg1 = GNUNET_HELLO_create (&publicKey, + &my_addr_gen, + &i, + GNUNET_NO); GNUNET_assert (msg1 != NULL); GNUNET_assert (0 < GNUNET_HELLO_size (msg1)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing address iteration (empty set)...\n"); GNUNET_assert (NULL == - GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr, + GNUNET_HELLO_iterate_addresses (msg1, + GNUNET_NO, + &check_addr, &i)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing HELLO creation (with one address)...\n"); i = 1; - msg2 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_NO); + msg2 = GNUNET_HELLO_create (&publicKey, + &my_addr_gen, + &i, + GNUNET_NO); GNUNET_assert (msg2 != NULL); GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2)); @@ -124,20 +170,27 @@ main (int argc, char *argv[]) "Testing address iteration (one address)...\n"); i = 1; GNUNET_assert (NULL == - GNUNET_HELLO_iterate_addresses (msg2, GNUNET_NO, &check_addr, + GNUNET_HELLO_iterate_addresses (msg2, + GNUNET_NO, + &check_addr, &i)); GNUNET_assert (i == 0); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing get_key from HELLO...\n"); - GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_key (msg2, &pk)); - GNUNET_assert (0 == memcmp (&publicKey, &pk, sizeof (pk))); + GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (msg2, &pid)); + GNUNET_assert (0 == memcmp (&publicKey, + &pid.public_key, + sizeof (struct GNUNET_CRYPTO_EddsaPublicKey))); GNUNET_free (msg1); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing HELLO creation (with two addresses)...\n"); i = 2; - msg3 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_NO); + msg3 = GNUNET_HELLO_create (&publicKey, + &my_addr_gen, + &i, + GNUNET_NO); GNUNET_assert (msg3 != NULL); GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3)); @@ -145,7 +198,9 @@ main (int argc, char *argv[]) "Testing address iteration (two addresses)...\n"); i = 3; GNUNET_assert (NULL == - GNUNET_HELLO_iterate_addresses (msg3, GNUNET_NO, &check_addr, + GNUNET_HELLO_iterate_addresses (msg3, + GNUNET_NO, + &check_addr, &i)); GNUNET_assert (i == 0); @@ -156,7 +211,9 @@ main (int argc, char *argv[]) i = 3; GNUNET_assert (NULL == - GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr, + GNUNET_HELLO_iterate_addresses (msg1, + GNUNET_NO, + &check_addr, &i)); GNUNET_assert (i == 0); GNUNET_free (msg1); @@ -164,12 +221,17 @@ main (int argc, char *argv[]) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing address iteration to copy HELLO...\n"); i = 2; - msg1 = GNUNET_HELLO_iterate_addresses (msg3, GNUNET_YES, &remove_some, &i); + msg1 = GNUNET_HELLO_iterate_addresses (msg3, + GNUNET_YES, + &remove_some, + &i); GNUNET_assert (msg1 != NULL); GNUNET_assert (i == 0); i = 1; GNUNET_assert (NULL == - GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr, + GNUNET_HELLO_iterate_addresses (msg1, + GNUNET_NO, + &check_addr, &i)); GNUNET_assert (i == 0); GNUNET_free (msg1); @@ -177,10 +239,15 @@ main (int argc, char *argv[]) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing delta address iteration...\n"); i = 2; - GNUNET_HELLO_iterate_new_addresses (msg3, msg2, startup_time, &check_addr, + GNUNET_HELLO_iterate_new_addresses (msg3, + msg2, + startup_time, + &check_addr, &i); GNUNET_assert (i == 0); GNUNET_free (msg2); GNUNET_free (msg3); return 0; /* testcase passed */ } + +/* end of test_hello.c */