From 8aa7b7ca770fd4d243203f6c409a12fd85e48ae5 Mon Sep 17 00:00:00 2001 From: John Jones Date: Wed, 4 Oct 2017 08:42:00 -0500 Subject: [PATCH] Added more tests, fixed bug with binary file xfer --- core/api.c | 3 ++- importer/exporter.c | 2 +- test/scripts/test_1.sh | 11 +++++++++-- test/scripts/test_helpers.sh | 5 ++--- 4 files changed, 14 insertions(+), 7 deletions(-) mode change 100644 => 100755 test/scripts/test_helpers.sh diff --git a/core/api.c b/core/api.c index abf8c8a..31cd69b 100644 --- a/core/api.c +++ b/core/api.c @@ -394,7 +394,8 @@ void *api_connection_thread (void *ptr) } r = read(s, buf, sizeof buf); if (r <= 0) { - libp2p_logger_error("api", "Read from client fail.\n"); + // this is a common occurrence, so moved from error to debug + libp2p_logger_debug("api", "Read from client fail.\n"); goto quit; } buf[r] = '\0'; diff --git a/importer/exporter.c b/importer/exporter.c index 245aa11..4a3b6fe 100644 --- a/importer/exporter.c +++ b/importer/exporter.c @@ -293,7 +293,7 @@ int ipfs_exporter_object_cat(struct CliArguments* args) { size_t response_size = 0; int retVal = ipfs_core_http_request_get(local_node, request, &response, &response_size); if (response != NULL && response_size > 0) { - fprintf(stdout, response); + fwrite(response, 1, response_size, stdout); free(response); } else { retVal = 0; diff --git a/test/scripts/test_1.sh b/test/scripts/test_1.sh index e14faf3..bbe35aa 100755 --- a/test/scripts/test_1.sh +++ b/test/scripts/test_1.sh @@ -18,7 +18,8 @@ function pre { function post { rm -Rf /tmp/ipfs_1; -# rm hello.bin; + rm hello.bin; + rm hello2.bin; } function body { @@ -31,8 +32,14 @@ function body { daemon_id=$! sleep 5 - eval "$IPFS" cat QmSsV5T26CnCk3Yt7gtf6Bgyqwe4UtiaLiPbe9uUyr1nHd > hello2.bin + eval "$IPFS" cat QmX4zpwaE7CSgZZsULgoB3gXYC6hh7RN19bEfWxw7sL8Xx > hello2.bin check_failure "cat" $? + # file size should be 256 + actualsize=$(wc -c < hello2.bin) + if [ $actualsize -ne 256 ]; then + echo '*** Failure *** file size incorrect' + fi + kill -9 $daemon_id } diff --git a/test/scripts/test_helpers.sh b/test/scripts/test_helpers.sh old mode 100644 new mode 100755 index cfd858a..8259958 --- a/test/scripts/test_helpers.sh +++ b/test/scripts/test_helpers.sh @@ -16,9 +16,9 @@ function create_hello_world { ### function create_binary_file { rm hello.bin - for byte in `seq 0 256`; + for byte in `seq 0 255`; do - printf "\\$(printf "%o" 0x$byte)" >> hello.bin + printf "\\$(printf "%o" $byte)" >> hello.bin done } @@ -34,4 +34,3 @@ function check_failure() { echo "***Failure*** in $FUNC. The return value was $RESULT"; fi } -