From 4cbcf6be3d53791e2440a794b8b6d11ddbc29d82 Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 3 Apr 2017 22:01:46 -0500 Subject: [PATCH] Test that proves MultiAddress not handling 0s properly --- test_multiaddr.h | 24 +++++++++++++++++++++++- testing.c | 6 ++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/test_multiaddr.h b/test_multiaddr.h index 4356f81..76c1a7b 100644 --- a/test_multiaddr.h +++ b/test_multiaddr.h @@ -69,7 +69,7 @@ int test_int_to_hex() { } int test_multiaddr_utils() { - struct MultiAddress* addr = multiaddress_new_from_string("/ip4/127.0.0.1/tcp/4001"); + struct MultiAddress* addr = multiaddress_new_from_string("/ip4/127.0.0.1/tcp/4001/"); if (!multiaddress_is_ip(addr)) { fprintf(stderr, "The address should be an IP\n"); return 0; @@ -115,3 +115,25 @@ int test_multiaddr_peer_id() { return retVal; } +int test_multiaddr_bytes() { + int retVal = 0; + char* orig_address = "/ip4/127.0.0.1/tcp/4001/"; + struct MultiAddress *orig = NULL, *result = NULL; + + orig = multiaddress_new_from_string(orig_address); + + result = multiaddress_new_from_bytes(orig->bytes, orig->bsize); + + if (strcmp(orig_address, result->string) != 0) + goto exit; + + retVal = 1; + exit: + if (orig != NULL) + multiaddress_free(orig); + if (result != NULL) + multiaddress_free(result); + return retVal; + +} + diff --git a/testing.c b/testing.c index a6da84c..395f9ea 100644 --- a/testing.c +++ b/testing.c @@ -8,7 +8,8 @@ const char* names[] = { "test_hex_to_var", "test_int_to_hex", "test_multiaddr_utils", - "test_multiaddr_peer_id" + "test_multiaddr_peer_id", + "test_multiaddr_bytes" }; int (*funcs[])(void) = { @@ -17,7 +18,8 @@ int (*funcs[])(void) = { test_hex_to_var, test_int_to_hex, test_multiaddr_utils, - test_multiaddr_peer_id + test_multiaddr_peer_id, + test_multiaddr_bytes }; int testit(const char* name, int (*func)(void)) {