diff options
Diffstat (limited to 'hl/tools')
-rw-r--r-- | hl/tools/CMakeLists.txt | 8 | ||||
-rw-r--r-- | hl/tools/CMakeTests.cmake | 20 | ||||
-rw-r--r-- | hl/tools/gif2h5/decompress.c | 2 | ||||
-rw-r--r-- | hl/tools/gif2h5/gif2mem.c | 10 | ||||
-rw-r--r-- | hl/tools/gif2h5/h52gifgentst.c | 8 | ||||
-rw-r--r-- | hl/tools/gif2h5/h52giftest.sh.in | 75 | ||||
-rw-r--r-- | hl/tools/gif2h5/hdf2gif.c | 21 | ||||
-rw-r--r-- | hl/tools/gif2h5/hdfgifwr.c | 8 | ||||
-rw-r--r-- | hl/tools/gif2h5/testfiles/REAMDE | 6 | ||||
-rw-r--r-- | hl/tools/gif2h5/testfiles/ex_image2.h5 | bin | 0 -> 224533 bytes |
10 files changed, 110 insertions, 48 deletions
diff --git a/hl/tools/CMakeLists.txt b/hl/tools/CMakeLists.txt index 567b3da..f58a513 100644 --- a/hl/tools/CMakeLists.txt +++ b/hl/tools/CMakeLists.txt @@ -19,7 +19,7 @@ INCLUDE_DIRECTORIES (${HDF5_HL_TOOLS_SOURCE_DIR}/gif2h5) add_executable (gif2h5 ${GIF2H5_SRCS}) TARGET_NAMING (gif2h5 ${LIB_TYPE}) -TARGET_C_PROPERTIES (gif2h5 " " " ") +TARGET_C_PROPERTIES (gif2h5 ${LIB_TYPE} " " " ") target_link_libraries (gif2h5 ${HDF5_HL_LIB_TARGET} ${HDF5_LIB_TARGET} ${HDF5_TOOLS_LIB_TARGET}) set_target_properties (gif2h5 PROPERTIES FOLDER tools/hl) @@ -30,7 +30,7 @@ set (hdf2gif_SRCS ) add_executable (h52gif ${hdf2gif_SRCS}) TARGET_NAMING (h52gif ${LIB_TYPE}) -TARGET_C_PROPERTIES (h52gif " " " ") +TARGET_C_PROPERTIES (h52gif ${LIB_TYPE} " " " ") target_link_libraries (h52gif ${HDF5_HL_LIB_TARGET} ${HDF5_LIB_TARGET} ${HDF5_TOOLS_LIB_TARGET}) set_target_properties (h52gif PROPERTIES FOLDER tools/hl) @@ -42,8 +42,8 @@ if (BUILD_TESTING) # -------------------------------------------------------------------- if (HDF5_BUILD_GENERATORS AND NOT BUILD_SHARED_LIBS) add_executable (hl_h52gifgentest ${HDF5_HL_TOOLS_SOURCE_DIR}/gif2h5/h52gifgentst.c) - TARGET_NAMING (hl_h52gifgentest ${LIB_TYPE}) - TARGET_C_PROPERTIES (hl_h52gifgentest " " " ") + TARGET_NAMING (hl_h52gifgentest STATIC) + TARGET_C_PROPERTIES (hl_h52gifgentest STATIC " " " ") target_link_libraries (hl_h52gifgentest ${HDF5_HL_LIB_TARGET} ${HDF5_LIB_TARGET}) set_target_properties (hl_h52gifgentest PROPERTIES FOLDER generator/tools/hl) diff --git a/hl/tools/CMakeTests.cmake b/hl/tools/CMakeTests.cmake index a340c2d..4ebd7a2 100644 --- a/hl/tools/CMakeTests.cmake +++ b/hl/tools/CMakeTests.cmake @@ -26,6 +26,13 @@ add_custom_command ( ARGS -E copy_if_different ${HDF5_HL_TOOLS_SOURCE_DIR}/gif2h5/testfiles/h52giftst.h5 ${PROJECT_BINARY_DIR}/testfiles/h52giftst.h5 ) +add_custom_command ( + TARGET h52gif + POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different ${HDF5_HL_TOOLS_SOURCE_DIR}/gif2h5/testfiles/ex_image2.h5 ${PROJECT_BINARY_DIR}/testfiles/ex_image2.h5 +) + # Remove any output file left over from previous test run add_test ( NAME HL_TOOLS-clear-objects @@ -33,8 +40,19 @@ add_test ( -E remove image1.gif image1.h5 + image.gif + image24.gif ) +add_test (NAME HL_TOOLS_gif2h5 COMMAND $<TARGET_FILE:gif2h5> testfiles/image1.gif image1.h5) + add_test (NAME HL_TOOLS_h52gif COMMAND $<TARGET_FILE:h52gif> testfiles/h52giftst.h5 image1.gif -i image) -add_test (NAME HL_TOOLS_gif2h5 COMMAND $<TARGET_FILE:gif2h5> testfiles/image1.gif image1.h5) +add_test (NAME HL_TOOLS_h52gif_none COMMAND $<TARGET_FILE:h52gif> testfiles/h52giftst.h5 image.gif -i nosuch_image) +set_tests_properties (HL_TOOLS_h52gif_none PROPERTIES WILL_FAIL "true") + +#add_test (NAME HL_TOOLS_h52gifpal COMMAND $<TARGET_FILE:h52gif> testfiles/h52giftst.h5 image.gif -i palette) +#set_tests_properties (HL_TOOLS_h52gifpal PROPERTIES WILL_FAIL "true") + +add_test (NAME HL_TOOLS_h52gif24bits COMMAND $<TARGET_FILE:h52gif> testfiles/ex_image2.h5 image24.gif -i image24bitpixel) +set_tests_properties (HL_TOOLS_h52gif24bits PROPERTIES WILL_FAIL "true") diff --git a/hl/tools/gif2h5/decompress.c b/hl/tools/gif2h5/decompress.c index d4e4cdc..ef2d78a 100644 --- a/hl/tools/gif2h5/decompress.c +++ b/hl/tools/gif2h5/decompress.c @@ -90,7 +90,7 @@ ReadCode(void) RawCode += (0x10000 * Raster[ByteOffset + 2]); RawCode >>= (BitOffset % 8); - BitOffset += CodeSize; + BitOffset += (int)CodeSize; return (RawCode & ReadMask); } diff --git a/hl/tools/gif2h5/gif2mem.c b/hl/tools/gif2h5/gif2mem.c index a2e4893..456a32d 100644 --- a/hl/tools/gif2h5/gif2mem.c +++ b/hl/tools/gif2h5/gif2mem.c @@ -153,7 +153,7 @@ Gif2Mem(BYTE *MemGif, GIFTOMEM *GifMemoryStruct) if (ImageCount > ImageArray) { aTemp = ImageArray; - ImageArray = (ImageArray << 1) + 1; + ImageArray = (BYTE)((ImageArray << 1) + 1); if (!(gifImageDesc = (GIFIMAGEDESC **)realloc(gifImageDesc, sizeof(GIFIMAGEDESC *) * ImageArray))) { printf("Out of memory!"); @@ -220,7 +220,7 @@ Gif2Mem(BYTE *MemGif, GIFTOMEM *GifMemoryStruct) PlainTextCount++; if (PlainTextCount > PlainTextArray) - PlainTextArray = (PlainTextArray << 1) + 1; + PlainTextArray = (BYTE)((PlainTextArray << 1) + 1); if (!(gifPlainText = (GIFPLAINTEXT **)realloc(gifPlainText , sizeof(GIFPLAINTEXT *) * PlainTextArray))) { printf("Out of memory!"); @@ -242,7 +242,7 @@ Gif2Mem(BYTE *MemGif, GIFTOMEM *GifMemoryStruct) CommentCount++; if (CommentCount > CommentArray) - CommentArray = (CommentArray << 1) + 1; + CommentArray = (BYTE)((CommentArray << 1) + 1); if (!(gifComment = (GIFCOMMENT **)realloc(gifComment , sizeof(GIFCOMMENT *) * CommentArray))) { printf("Out of memory!"); @@ -269,7 +269,7 @@ Gif2Mem(BYTE *MemGif, GIFTOMEM *GifMemoryStruct) if (ImageCount > ImageArray) { aTemp = ImageArray; - ImageArray = (ImageArray << 1) + 1; + ImageArray = (BYTE)((ImageArray << 1) + 1); if (!(gifGraphicControl = (GIFGRAPHICCONTROL **)realloc(gifGraphicControl , sizeof(GIFGRAPHICCONTROL *) * ImageArray))) { printf("Out of memory!"); @@ -307,7 +307,7 @@ Gif2Mem(BYTE *MemGif, GIFTOMEM *GifMemoryStruct) ApplicationCount++; if (ApplicationCount > ApplicationArray) - ApplicationArray = (ApplicationArray << 1) + 1; + ApplicationArray = (BYTE)((ApplicationArray << 1) + 1); if (!(gifApplication = (GIFAPPLICATION **)realloc(gifApplication , sizeof(GIFAPPLICATION *) * ApplicationArray))) { printf("Out of memory!"); diff --git a/hl/tools/gif2h5/h52gifgentst.c b/hl/tools/gif2h5/h52gifgentst.c index ef38c3b..3433d0a 100644 --- a/hl/tools/gif2h5/h52gifgentst.c +++ b/hl/tools/gif2h5/h52gifgentst.c @@ -64,7 +64,7 @@ int main(void) space = WIDTH*HEIGHT / PAL_ENTRIES; for (i=0, j=0, n=0; i < WIDTH*HEIGHT; i++, j++ ) { - buf[i] = n; + buf[i] = (unsigned char)n; if ( j > space ) { n++; @@ -83,9 +83,9 @@ int main(void) */ for ( i=0, n=0; i<PAL_ENTRIES*3; i+=3, n++) { - pal[i] =n; /* red */ - pal[i+1]=0; /* green */ - pal[i+2]=255-n; /* blue */ + pal[i] = (unsigned char)n; /* red */ + pal[i+1] = (unsigned char)0; /* green */ + pal[i+2] = (unsigned char)(255-n); /* blue */ } /* make a palette */ diff --git a/hl/tools/gif2h5/h52giftest.sh.in b/hl/tools/gif2h5/h52giftest.sh.in index 186b369..7aec219 100644 --- a/hl/tools/gif2h5/h52giftest.sh.in +++ b/hl/tools/gif2h5/h52giftest.sh.in @@ -18,6 +18,7 @@ TESTFILE1="$srcdir/testfiles/h52giftst.h5" TESTFILE2="$srcdir/testfiles/image1.gif" +TESTFILE3="$srcdir/testfiles/ex_image2.h5" # initialize errors variable errors=0 @@ -29,45 +30,69 @@ TESTING() { -TOOLTEST1() +# Verify the test runs with success (return code is 0) +TOOLTEST() { - $RUNSERIAL ./h52gif $* - - RET=$? - if [ $RET != 0 ] ; then - echo "*FAILED*" - errors="` expr $errors + 1 `"; - else - echo " PASSED" - fi + # for now, discard any error messages generated. + $RUNSERIAL $* > /dev/null 2>&1 + + RET=$? + if [ $RET = 0 ] ; then + echo " PASSED" + else + echo "*FAILED*" + errors="` expr $errors + 1 `"; + fi } -TOOLTEST2() +# Verify the test runs with failure (return code is not 0) +# Use for testing if tool can handle error conditions like +# illegal input, bad arguments, exeeding limits, ... +TOOLTESTFAIL() { - $RUNSERIAL ./gif2h5 $* - - RET=$? - if [ $RET != 0 ] ; then - echo "*FAILED*" - errors="` expr $errors + 1 `"; - else - echo " PASSED" - fi + # for now, discard any error messages generated. + $RUNSERIAL $* > /dev/null 2>&1 + + RET=$? + if [ $RET != 0 ] ; then + echo " PASSED" + else + echo "*FAILED*" + errors="` expr $errors + 1 `"; + fi } +# Positive tests for gif2h5 +echo "**validate the gif2h5 tool processes input correctly..." +TESTING "./gif2h5 image1.gif image1.h5" +TOOLTEST ./gif2h5 $TESTFILE2 image1.h5 +echo "" +# Positive tests for h52gif +echo "**validate the h52gif tool processes input correctly..." TESTING "./h52gif h52giftst.h5 image1.gif -i image" -TOOLTEST1 $TESTFILE1 image1.gif -i image -TESTING "./gif2h5 image1.gif image1.h5" -TOOLTEST2 $TESTFILE2 image1.h5 +TOOLTEST ./h52gif $TESTFILE1 image1.gif -i image +echo "" +# Negative tests. +echo "**verify the the h52gif tool handle error conditions correctly..." +# nonexisting dataset name +TESTING "./h52gif h52giftst.h5 image.gif -i nosuch_image" +TOOLTESTFAIL "./h52gif $TESTFILE1 image.gif -i nosuch_image" +# this test should have failed but it did not. Comment it out for now. +#TESTING "./h52gif h52giftst.h5 image.gif -i palette" +#TOOLTESTFAIL "./h52gif $TESTFILE1 image.gif -i palette" +TESTING "./h52gif h52giftst.h5 image24.gif -i image24bitpixel" +TOOLTESTFAIL "./h52gif $TESTFILE3 image24.gif -i image24bitpixel" +echo "" +# all done. summarize results. if test $errors -eq 0 ; then - echo "All h52gif tests passed." + echo "All gif2h5 and h52gif tests passed." exit 0 else - echo "h52gif tests failed with $errors errors." + echo "Some gif2h5 or h52gif tests failed with $errors errors." exit 1 fi diff --git a/hl/tools/gif2h5/hdf2gif.c b/hl/tools/gif2h5/hdf2gif.c index 090d657..5c342ba 100644 --- a/hl/tools/gif2h5/hdf2gif.c +++ b/hl/tools/gif2h5/hdf2gif.c @@ -20,6 +20,8 @@ #include "h5tools.h" #include "h5tools_utils.h" +#define IMAGE_WIDTH_MAX 65535 /* unsigned 16bits integer */ +#define IMAGE_HEIGHT_MAX 65535 /* unsigned 16bits integer */ int EndianOrder; @@ -147,6 +149,17 @@ int main(int argc , char **argv) if ( H5IMget_image_info( fid, image_name, &width, &height, &planes, interlace, &npals ) < 0 ) goto out; + if (width > IMAGE_WIDTH_MAX || height > IMAGE_HEIGHT_MAX){ + fprintf(stderr, "HDF5 image is too large. Limit is %d by %d.\n", IMAGE_WIDTH_MAX, IMAGE_HEIGHT_MAX); + goto out; + } + + /* tool can handle single plane images only. */ + if (planes > 1){ + fprintf(stderr, "Cannot handle multiple planes image\n"); + goto out; + } + Image = (BYTE*) malloc( (size_t) width * (size_t) height ); if ( H5IMread_image( fid, image_name, Image ) < 0 ) @@ -194,9 +207,9 @@ int main(int argc , char **argv) numcols = 256; for (i = 0 ; i < numcols ; i++) { - Red[i] = 255 - i; - Green[i] = 255 - i; - Blue[i] = 255 - i; + Red[i] = (BYTE)(255 - i); + Green[i] = (BYTE)(255 - i); + Blue[i] = (BYTE)(255 - i); } } else @@ -229,7 +242,7 @@ int main(int argc , char **argv) if (j==i) { /* wasn't found */ - pc2nc[i] = nc; + pc2nc[i] = (BYTE)nc; r1[nc] = Red[i]; g1[nc] = Green[i]; b1[nc] = Blue[i]; diff --git a/hl/tools/gif2h5/hdfgifwr.c b/hl/tools/gif2h5/hdfgifwr.c index d828226..4c52f4c 100644 --- a/hl/tools/gif2h5/hdfgifwr.c +++ b/hl/tools/gif2h5/hdfgifwr.c @@ -270,7 +270,7 @@ nomatch: ent = c; if (free_ent < maxmaxcode) { - CodeTabOf (i) = free_ent++; /* code -> hashtable */ + CodeTabOf (i) = (unsigned short)free_ent++; /* code -> hashtable */ HashTabOf (i) = fcode; } else { cl_block(); @@ -313,9 +313,9 @@ output(int code) cur_accum &= masks[cur_bits]; if (cur_bits > 0) - cur_accum |= ((long)code << cur_bits); + cur_accum |= (unsigned long)((long)code << cur_bits); else - cur_accum = code; + cur_accum = (unsigned long)code; cur_bits += n_bits; @@ -437,7 +437,7 @@ static char accum[ 256 ]; static void char_out(int c) { - accum[ a_count++ ] = c; + accum[ a_count++ ] = (char)c; if (a_count >= 254) flush_char(); diff --git a/hl/tools/gif2h5/testfiles/REAMDE b/hl/tools/gif2h5/testfiles/REAMDE new file mode 100644 index 0000000..a428d47 --- /dev/null +++ b/hl/tools/gif2h5/testfiles/REAMDE @@ -0,0 +1,6 @@ +ex_image2.h5 + Generated by hl/examples/ex_image2.c +5giftst.h5: + Generated by ../h52gifgentst.c +image1.gif: + To be determined. diff --git a/hl/tools/gif2h5/testfiles/ex_image2.h5 b/hl/tools/gif2h5/testfiles/ex_image2.h5 Binary files differnew file mode 100644 index 0000000..a36df1b --- /dev/null +++ b/hl/tools/gif2h5/testfiles/ex_image2.h5 |