From c64f2e8ea19aa15bec877d8a25af514b7473c0f9 Mon Sep 17 00:00:00 2001 From: Robin Mills Date: Sat, 16 May 2020 10:11:40 +0100 Subject: [PATCH] iotest.cpp polishing. --- samples/iotest.cpp | 31 ++++++++++++++----------------- test/iotest.sh | 8 ++++---- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/samples/iotest.cpp b/samples/iotest.cpp index 405e4d78..ee593530 100644 --- a/samples/iotest.cpp +++ b/samples/iotest.cpp @@ -70,36 +70,33 @@ int main(int argc, char* const argv[]) if ( argc >= 5 ) { int blocksize = argc==6 ? atoi(ba) : 10000; // ensure blocksize is sane - if (blocksize<1) blocksize=1 ; if (blocksize>1024*1024) blocksize=10000; - Exiv2::byte* bytes = new Exiv2::byte[blocksize]; + Exiv2::byte* bytes = blocksize>0 ? new Exiv2::byte[blocksize]: NULL; // copy fileIn from a remote location. - FILE* f = fopen(f0,"wb"); - if ( !f ) { - Error(Exiv2::kerFileOpenFailed, f0, "w+b", strError()); - } BasicIo::AutoPtr io = Exiv2::ImageFactory::createIo(fr); - io->open(); + if ( io->open() != 0 ) { + Error(Exiv2::kerFileOpenFailed, io->path(), "rb", strError()); + } + FileIo output(f0); + if ( !output.open("wb") ) { + Error(Exiv2::kerFileOpenFailed, output.path() , "w+b", strError()); + } size_t l = 0; - if ( blocksize > 1 ) { + if ( bytes ) { int r ; while ( (r=io->read(bytes,blocksize)) > 0 ) { l += r; - fwrite(bytes,r,1,f) ; + output.write(bytes,r) ; } } else { - // blocksize == 1, read/write byte-wise (#1029) + // read/write byte-wise (#1029) while ( l++ < io->size() ) { - bytes[0] = io->getb(); - fwrite(bytes,1,1,f) ; + output.putb(io->getb()) ; } } - delete [] bytes; - fclose(f); - if ( !l ) { - Error(Exiv2::kerFileOpenFailed, fr, "rb", strError()); - } + if ( bytes ) delete [] bytes; + output.close(); } FileIo fileIn(f0); diff --git a/test/iotest.sh b/test/iotest.sh index 3f8e3bc8..310e8a47 100755 --- a/test/iotest.sh +++ b/test/iotest.sh @@ -35,7 +35,7 @@ if [ "$EXIV2_PORT" != "None" -a "$EXIV2_HTTP" != "None" ]; then if [ ! -z $exiv2_httpServer ]; then ( cd "${testdir}" >&2 printf "*** HTTP tests begin\n" - + cd "$testdir" test_files="table.jpg Reagan.tiff exiv2-bug922a.jpg" for i in $test_files; do @@ -44,11 +44,11 @@ if [ "$EXIV2_PORT" != "None" -a "$EXIV2_HTTP" != "None" ]; then runTest exiv2 -g City -g DateTime $t done done - - runTest iotest s0 s1 s2 $exiv2_url/data/table.jpg 1 ; sniff + + runTest iotest s0 s1 s2 $exiv2_url/data/table.jpg 0 ; sniff runTest iotest s0 s1 s2 $exiv2_url/data/table.jpg 10 ; sniff runTest iotest s0 s1 s2 $exiv2_url/data/table.jpg 1000 ; sniff - + >&2 printf "*** HTTP tests end\n" ) | tr -d '\r' | sed 's/[ \t]+$//' > $results reportTest