Test that proves MultiAddress not handling 0s properly

master
John Jones 2017-04-03 22:01:46 -05:00
parent 615adc86ef
commit 4cbcf6be3d
2 changed files with 27 additions and 3 deletions

View File

@ -69,7 +69,7 @@ int test_int_to_hex() {
} }
int test_multiaddr_utils() { 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)) { if (!multiaddress_is_ip(addr)) {
fprintf(stderr, "The address should be an IP\n"); fprintf(stderr, "The address should be an IP\n");
return 0; return 0;
@ -115,3 +115,25 @@ int test_multiaddr_peer_id() {
return retVal; 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;
}

View File

@ -8,7 +8,8 @@ const char* names[] = {
"test_hex_to_var", "test_hex_to_var",
"test_int_to_hex", "test_int_to_hex",
"test_multiaddr_utils", "test_multiaddr_utils",
"test_multiaddr_peer_id" "test_multiaddr_peer_id",
"test_multiaddr_bytes"
}; };
int (*funcs[])(void) = { int (*funcs[])(void) = {
@ -17,7 +18,8 @@ int (*funcs[])(void) = {
test_hex_to_var, test_hex_to_var,
test_int_to_hex, test_int_to_hex,
test_multiaddr_utils, test_multiaddr_utils,
test_multiaddr_peer_id test_multiaddr_peer_id,
test_multiaddr_bytes
}; };
int testit(const char* name, int (*func)(void)) { int testit(const char* name, int (*func)(void)) {