diff options
Diffstat (limited to 'java/test')
-rw-r--r-- | java/test/CMakeLists.txt | 57 | ||||
-rw-r--r-- | java/test/Makefile.am | 2 | ||||
-rw-r--r-- | java/test/TestH5A.java | 436 | ||||
-rw-r--r-- | java/test/TestH5D.java | 819 | ||||
-rw-r--r-- | java/test/TestH5R.java | 24 | ||||
-rw-r--r-- | java/test/junit.sh.in | 6 | ||||
-rw-r--r-- | java/test/testfiles/JUnit-TestH5A.txt | 5 | ||||
-rw-r--r-- | java/test/testfiles/JUnit-TestH5D.txt | 8 |
8 files changed, 1264 insertions, 93 deletions
diff --git a/java/test/CMakeLists.txt b/java/test/CMakeLists.txt index 3e18d35..48ea0f5 100644 --- a/java/test/CMakeLists.txt +++ b/java/test/CMakeLists.txt @@ -120,23 +120,39 @@ else () endif () get_property (target_name TARGET ${HDF5_JAVA_JNI_LIB_TARGET} PROPERTY OUTPUT_NAME) -set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=${target_name}$<$<CONFIG:Debug>:${CMAKE_DEBUG_POSTFIX}>;") +set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=${target_name}$<$<OR:$<CONFIG:Debug>,$<CONFIG:Developer>>:${CMAKE_DEBUG_POSTFIX}>;") set (CMAKE_JAVA_CLASSPATH ".") foreach (CMAKE_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH}) set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${CMAKE_INCLUDE_PATH}") endforeach () if (HDF5_TEST_JAVA AND HDF5_TEST_SERIAL) + add_test ( + NAME JUnit-clear-objects + COMMAND ${CMAKE_COMMAND} -E remove + test.h5 + testF2.h5 + testPf00000.h5 + testPf00001.h5 + WORKING_DIRECTORY ${HDF5_BINARY_DIR}/java/test + ) + set_tests_properties (JUnit-clear-objects PROPERTIES FIXTURES_SETUP clear_JUnit) + + add_test ( + NAME JUnit-clean-objects + COMMAND ${CMAKE_COMMAND} -E remove + test.h5 + testF2.h5 + testPf00000.h5 + testPf00001.h5 + WORKING_DIRECTORY ${HDF5_BINARY_DIR}/java/test + ) + set_tests_properties (JUnit-clean-objects PROPERTIES FIXTURES_CLEANUP clear_JUnit) + foreach (test_file ${HDF5_JAVA_TEST_SOURCES}) set (TEST_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${HDF5_JAVA_TEST_LIB_TARGET}_${test_file}_JAR_FILE}") add_test ( - NAME JUnit-${test_file}-clearall-objects - COMMAND ${CMAKE_COMMAND} -E remove - JUnit-${test_file}.out - JUnit-${test_file}.out.err - ) - add_test ( NAME JUnit-${test_file} COMMAND "${CMAKE_COMMAND}" -D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}" @@ -156,7 +172,8 @@ if (HDF5_TEST_JAVA AND HDF5_TEST_SERIAL) ) set_tests_properties (JUnit-${test_file} PROPERTIES ENVIRONMENT "HDF5_PLUGIN_PATH=${CMAKE_BINARY_DIR}/testdir2" - DEPENDS "JUnit-${test_file}-clearall-objects" + FIXTURES_REQUIRED clear_JUnit + WORKING_DIRECTORY ${HDF5_BINARY_DIR}/java/test ) endforeach () @@ -169,13 +186,6 @@ if (HDF5_TEST_JAVA AND HDF5_TEST_SERIAL) macro (DO_VOL_TEST voltest volname volinfo volclasspath) #message(STATUS "${voltest}-${volname} with ${volinfo}") - add_test ( - NAME JUnit-VOL-${volname}-${voltest}-clearall-objects - COMMAND ${CMAKE_COMMAND} -E remove - JUnit-VOL-${volname}-${voltest}.out - JUnit-VOL-${volname}-${voltest}.out.err - WORKING_DIRECTORY ${HDF5_BINARY_DIR}/java/test/${volname} - ) add_test (NAME JUnit-VOL-${volname}-${voltest} COMMAND "${CMAKE_COMMAND}" -D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}" @@ -196,7 +206,20 @@ if (HDF5_TEST_JAVA AND HDF5_TEST_SERIAL) ) set_tests_properties (JUnit-VOL-${volname}-${voltest} PROPERTIES ENVIRONMENT "HDF5_PLUGIN_PATH=${CMAKE_BINARY_DIR}/testdir2" - DEPENDS "JUnit-VOL-${volname}-${voltest}-clearall-objects" + WORKING_DIRECTORY ${HDF5_BINARY_DIR}/java/test/${volname} + ) + add_test ( + NAME JUnit-VOL-${volname}-${voltest}-clean-objects + COMMAND ${CMAKE_COMMAND} -E remove + test.h5 + testF2.h5 + testPf00000.h5 + testPf00001.h5 + WORKING_DIRECTORY ${HDF5_BINARY_DIR}/java/test/${volname} + ) + set_tests_properties (JUnit-VOL-${volname}-${voltest}-clean-objects PROPERTIES + ENVIRONMENT "HDF5_PLUGIN_PATH=${CMAKE_BINARY_DIR}/testdir2" + DEPENDS "JUnit-VOL-${volname}-${voltest}" WORKING_DIRECTORY ${HDF5_BINARY_DIR}/java/test/${volname} ) endmacro () @@ -208,6 +231,8 @@ if (HDF5_TEST_JAVA AND HDF5_TEST_SERIAL) vol_pass_through2 ) + # native VOL = 0 + # pass-through VOL = 1 set (vol_native native) set (vol_pass_through1 "pass_through under_vol=0\;under_info={}") set (vol_pass_through2 "pass_through under_vol=505\;under_info={under_vol=0\;under_info={}}") diff --git a/java/test/Makefile.am b/java/test/Makefile.am index bb6be7f..6a407db 100644 --- a/java/test/Makefile.am +++ b/java/test/Makefile.am @@ -27,7 +27,7 @@ classes: pkgpath = test hdfjarfile = jar$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).jar -CLASSPATH_ENV=CLASSPATH=.:$(JAVAROOT):$(top_builddir)/java/src/$(hdfjarfile):$(top_srcdir)/java/lib/junit.jar:$(top_srcdir)/java/lib/hamcrest-core.jar:$(top_srcdir)/java/lib/slf4j-api-1.7.33.jar:$(top_srcdir)/java/lib/ext/slf4j-simple-1.7.33.jar:$$CLASSPATH +CLASSPATH_ENV=CLASSPATH=.:$(JAVAROOT):$(top_builddir)/java/src/$(hdfjarfile):$(top_srcdir)/java/lib/junit.jar:$(top_srcdir)/java/lib/hamcrest-core.jar:$(top_srcdir)/java/lib/slf4j-api-2.0.6.jar:$(top_srcdir)/java/lib/ext/slf4j-simple-2.0.6.jar:$$CLASSPATH jarfile = jar$(PACKAGE_TARNAME)test.jar diff --git a/java/test/TestH5A.java b/java/test/TestH5A.java index 4437ec7..90fe24c 100644 --- a/java/test/TestH5A.java +++ b/java/test/TestH5A.java @@ -46,6 +46,7 @@ public class TestH5A { private static final int DIM_Y = 6; long H5fid = HDF5Constants.H5I_INVALID_HID; long H5dsid = HDF5Constants.H5I_INVALID_HID; + long H5atid = HDF5Constants.H5I_INVALID_HID; long H5did = HDF5Constants.H5I_INVALID_HID; long[] H5dims = {DIM_X, DIM_Y}; long type_id = HDF5Constants.H5I_INVALID_HID; @@ -136,8 +137,12 @@ public class TestH5A { } catch (Exception ex) { } - - _deleteFile(H5_FILE); + if (H5atid > 0) + try { + H5.H5Tclose(H5atid); + } + catch (Exception ex) { + } if (type_id > 0) try { @@ -163,6 +168,8 @@ public class TestH5A { } catch (Exception ex) { } + + _deleteFile(H5_FILE); System.out.println(); } @@ -1072,7 +1079,7 @@ public class TestH5A { HDF5Constants.H5P_DEFAULT); assertTrue("testH5Awrite_readVL: ", attr_id >= 0); - H5.H5Awrite_VLStrings(attr_id, atype_id, str_data); + H5.H5AwriteVL(attr_id, atype_id, str_data); H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); @@ -1084,7 +1091,7 @@ public class TestH5A { strs[j] = ""; } try { - H5.H5Aread_VLStrings(attr_id, atype_id, strs); + H5.H5AreadVL(attr_id, atype_id, strs); } catch (Exception ex) { ex.printStackTrace(); @@ -1501,9 +1508,8 @@ public class TestH5A { H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - for (int j = 0; j < dims.length; j++) { + for (int j = 0; j < dims.length; j++) lsize *= dims[j]; - } // Read Integer data ArrayList[] vl_readbuf = new ArrayList[4]; @@ -1576,4 +1582,422 @@ public class TestH5A { } } } + + @Test + public void testH5AVLwrVL() + { + String attr_int_name = "VLIntdata"; + long attr_int_id = HDF5Constants.H5I_INVALID_HID; + long atype_int_id = HDF5Constants.H5I_INVALID_HID; + long base_atype_int_id = HDF5Constants.H5I_INVALID_HID; + long aspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {4}; + long lsize = 1; + + ArrayList[] base_vl_int_data = new ArrayList[4]; + ArrayList[] vl_int_data = new ArrayList[4]; + try { + // Write Integer data + vl_int_data[0] = new ArrayList<Integer>(Arrays.asList(1)); + vl_int_data[1] = new ArrayList<Integer>(Arrays.asList(2, 3)); + vl_int_data[2] = new ArrayList<Integer>(Arrays.asList(4, 5, 6)); + vl_int_data[3] = new ArrayList<Integer>(Arrays.asList(7, 8, 9, 10)); + Class dataClass = vl_int_data.getClass(); + assertTrue("testH5AVLwrVL.getClass: " + dataClass, dataClass.isArray()); + + // Write VL data + base_vl_int_data[0] = new ArrayList<ArrayList<Integer>>(); + base_vl_int_data[0].add(vl_int_data[0]); + base_vl_int_data[1] = new ArrayList<ArrayList<Integer>>(); + base_vl_int_data[1].add(vl_int_data[0]); + base_vl_int_data[1].add(vl_int_data[1]); + base_vl_int_data[2] = new ArrayList<ArrayList<Integer>>(); + base_vl_int_data[2].add(vl_int_data[0]); + base_vl_int_data[2].add(vl_int_data[1]); + base_vl_int_data[2].add(vl_int_data[2]); + base_vl_int_data[3] = new ArrayList<ArrayList<Integer>>(); + base_vl_int_data[3].add(vl_int_data[0]); + base_vl_int_data[3].add(vl_int_data[1]); + base_vl_int_data[3].add(vl_int_data[2]); + base_vl_int_data[3].add(vl_int_data[3]); + + try { + atype_int_id = H5.H5Tvlen_create(HDF5Constants.H5T_STD_U32LE); + assertTrue("testH5AVLwr.H5Tvlen_create: ", atype_int_id >= 0); + base_atype_int_id = H5.H5Tvlen_create(atype_int_id); + assertTrue("testH5AVLwrVL.H5Tvlen_create: ", base_atype_int_id >= 0); + } + catch (Exception err) { + if (base_atype_int_id > 0) + try { + H5.H5Tclose(base_atype_int_id); + } + catch (Exception ex) { + } + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5AVLwrVL: " + err); + } + + try { + aspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(aspace_id > 0); + attr_int_id = H5.H5Acreate(H5did, attr_int_name, base_atype_int_id, aspace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5AVLwrVL: ", attr_int_id >= 0); + + H5.H5AwriteVL(attr_int_id, base_atype_int_id, base_vl_int_data); + } + catch (Exception err) { + if (attr_int_id > 0) + try { + H5.H5Aclose(attr_int_id); + } + catch (Exception ex) { + } + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5AVLwrVL: " + err); + } + finally { + if (aspace_id > 0) + try { + H5.H5Sclose(aspace_id); + } + catch (Exception ex) { + } + } + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) + lsize *= dims[j]; + + // Read Integer data + ArrayList[] base_vl_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + base_vl_readbuf[j] = new ArrayList<ArrayList<Integer>>(); + + try { + H5.H5AreadVL(attr_int_id, base_atype_int_id, base_vl_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + ArrayList<ArrayList<Integer>> vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[0]; + assertTrue("vl_readbuf 0 exists", vl_readbuf != null); + ArrayList<Integer> vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(0)); + /* + * System.out.println(); System.out.println("vl_readbuf: " + vl_readbuf); + * System.out.println("vl_readbuf_int: " + vl_readbuf_int); + */ + assertTrue("testHADVLwrVL:" + vl_readbuf_int.get(0), + vl_int_data[0].get(0).equals(vl_readbuf_int.get(0))); + + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[1]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(1)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5AVLwrVL:" + vl_readbuf_int.get(1), + vl_int_data[1].get(1).equals(vl_readbuf_int.get(1))); + + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[2]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(2)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5AVLwrVL:" + vl_readbuf_int.get(2), + vl_int_data[2].get(2).equals(vl_readbuf_int.get(2))); + + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[3]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(3)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5AVLwrVL:" + vl_readbuf_int.get(3), + vl_int_data[3].get(3).equals(vl_readbuf_int.get(3))); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5AVLwrVL: " + err); + } + finally { + if (attr_int_id > 0) + try { + H5.H5Aclose(attr_int_id); + } + catch (Exception ex) { + } + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + if (base_atype_int_id > 0) + try { + H5.H5Tclose(base_atype_int_id); + } + catch (Exception ex) { + } + } + } + + @Test + public void testH5AArraywr() + { + String att_int_name = "ArrayIntdata"; + long att_int_id = HDF5Constants.H5I_INVALID_HID; + long atype_int_id = HDF5Constants.H5I_INVALID_HID; + long aspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {4}; + long lsize = 1; + + ArrayList[] arr_int_data = new ArrayList[4]; + try { + // Write Integer data + arr_int_data[0] = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4)); + arr_int_data[1] = new ArrayList<Integer>(Arrays.asList(2, 3, 4, 5)); + arr_int_data[2] = new ArrayList<Integer>(Arrays.asList(4, 5, 6, 7)); + arr_int_data[3] = new ArrayList<Integer>(Arrays.asList(7, 8, 9, 10)); + Class dataClass = arr_int_data.getClass(); + assertTrue("testH5AArraywr.getClass: " + dataClass, dataClass.isArray()); + + try { + atype_int_id = H5.H5Tarray_create(HDF5Constants.H5T_STD_U32LE, 1, dims); + assertTrue("testH5AArraywr.H5Tarray_create: ", atype_int_id >= 0); + } + catch (Exception err) { + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5AArraywr: " + err); + } + + try { + aspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(aspace_id > 0); + att_int_id = H5.H5Acreate(H5did, att_int_name, atype_int_id, aspace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5AVLwr: ", att_int_id >= 0); + + H5.H5AwriteVL(att_int_id, atype_int_id, arr_int_data); + } + catch (Exception err) { + if (att_int_id > 0) + try { + H5.H5Aclose(att_int_id); + } + catch (Exception ex) { + } + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5AVLwr: " + err); + } + finally { + if (aspace_id > 0) + try { + H5.H5Sclose(aspace_id); + } + catch (Exception ex) { + } + } + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) + lsize *= dims[j]; + + // Read Integer data + ArrayList[] arr_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + arr_readbuf[j] = new ArrayList<Integer>(); + + try { + H5.H5AreadVL(att_int_id, atype_int_id, arr_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5AVLwr:" + arr_readbuf[0].get(0), + arr_int_data[0].get(0).equals(arr_readbuf[0].get(0))); + assertTrue("testH5AVLwr:" + arr_readbuf[1].get(0), + arr_int_data[1].get(0).equals(arr_readbuf[1].get(0))); + assertTrue("testH5AVLwr:" + arr_readbuf[2].get(0), + arr_int_data[2].get(0).equals(arr_readbuf[2].get(0))); + assertTrue("testH5AVLwr:" + arr_readbuf[3].get(0), + arr_int_data[3].get(0).equals(arr_readbuf[3].get(0))); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5AArraywr: " + err); + } + finally { + if (att_int_id > 0) + try { + H5.H5Aclose(att_int_id); + } + catch (Exception ex) { + } + if (atype_int_id > 0) + try { + H5.H5Tclose(atype_int_id); + } + catch (Exception ex) { + } + } + } + + @Test + public void testH5AArray_string_buffer() throws Throwable + { + String att_str_name = "ArrayStringdata"; + long att_str_id = HDF5Constants.H5I_INVALID_HID; + long atype_str_id = HDF5Constants.H5I_INVALID_HID; + long aspace_id = HDF5Constants.H5I_INVALID_HID; + long[] strdims = {4}; + long[] dims = {6}; + long lsize = 1; + + String[] str_data0 = {"Parting", "is such", "sweet", "sorrow."}; + String[] str_data1 = {"Testing", "one", "two", "three."}; + String[] str_data2 = {"Dog,", "man's", "best", "friend."}; + String[] str_data3 = {"Diamonds", "are", "a", "girls!"}; + String[] str_data4 = {"S A", "T U R", "D A Y", "night"}; + String[] str_data5 = {"That's", "all", "folks", "!!!"}; + + ArrayList[] arr_str_data = new ArrayList[6]; + arr_str_data[0] = new ArrayList<String>(Arrays.asList(str_data0)); + arr_str_data[1] = new ArrayList<String>(Arrays.asList(str_data1)); + arr_str_data[2] = new ArrayList<String>(Arrays.asList(str_data2)); + arr_str_data[3] = new ArrayList<String>(Arrays.asList(str_data3)); + arr_str_data[4] = new ArrayList<String>(Arrays.asList(str_data4)); + arr_str_data[5] = new ArrayList<String>(Arrays.asList(str_data5)); + + try { + H5atid = H5.H5Tcopy(HDF5Constants.H5T_C_S1); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5AArray_string_buffer.H5.H5Tcopy: " + err); + } + assertTrue("testH5AArray_string_buffer.H5Tcopy: ", H5atid >= 0); + try { + H5.H5Tset_size(H5atid, HDF5Constants.H5T_VARIABLE); + assertTrue("testH5AArray_string_buffer.H5Tis_variable_str", H5.H5Tis_variable_str(H5atid)); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5DArray_string_buffer.H5Tset_size: " + err); + } + try { + atype_str_id = H5.H5Tarray_create(H5atid, 1, strdims); + assertTrue("testH5AArray_string_buffer.H5Tarray_create: ", atype_str_id >= 0); + } + catch (Exception err) { + if (atype_str_id > 0) + try { + H5.H5Tclose(atype_str_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("testH5AArray_string_buffer: " + err); + } + + try { + aspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(aspace_id > 0); + att_str_id = H5.H5Acreate(H5did, att_str_name, atype_str_id, aspace_id, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT); + assertTrue("testH5AArray_string_buffer: ", att_str_id >= 0); + + H5.H5AwriteVL(att_str_id, atype_str_id, arr_str_data); + } + catch (Exception err) { + if (att_str_id > 0) + try { + H5.H5Dclose(att_str_id); + } + catch (Exception ex) { + } + if (atype_str_id > 0) + try { + H5.H5Tclose(atype_str_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("testH5AArray_string_buffer: " + err); + } + finally { + if (aspace_id > 0) + try { + H5.H5Sclose(aspace_id); + } + catch (Exception ex) { + } + } + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) + lsize *= dims[j]; + + ArrayList[] arr_readbuf = new ArrayList[6]; + for (int j = 0; j < lsize; j++) + arr_readbuf[j] = new ArrayList<String>(); + + try { + H5.H5AreadVL(att_str_id, atype_str_id, arr_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + finally { + if (att_str_id > 0) + try { + H5.H5Aclose(att_str_id); + } + catch (Exception ex) { + } + if (atype_str_id > 0) + try { + H5.H5Tclose(atype_str_id); + } + catch (Exception ex) { + } + } + assertTrue("testH5AArray_string_buffer:" + arr_readbuf[0].get(0), + arr_str_data[0].get(0).equals(arr_readbuf[0].get(0))); + assertTrue("testH5AArray_string_buffer:" + arr_readbuf[1].get(0), + arr_str_data[1].get(0).equals(arr_readbuf[1].get(0))); + assertTrue("testH5AArray_string_buffer:" + arr_readbuf[2].get(0), + arr_str_data[2].get(0).equals(arr_readbuf[2].get(0))); + assertTrue("testH5AArray_string_buffer:" + arr_readbuf[3].get(0), + arr_str_data[3].get(0).equals(arr_readbuf[3].get(0))); + } } diff --git a/java/test/TestH5D.java b/java/test/TestH5D.java index f7e5702..eacaabf 100644 --- a/java/test/TestH5D.java +++ b/java/test/TestH5D.java @@ -31,6 +31,7 @@ import hdf.hdf5lib.exceptions.HDF5LibraryException; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestName; @@ -157,7 +158,7 @@ public class TestH5D { assertTrue("TestH5D._createDataset.H5Dcreate: ", H5did >= 0); } - private final void _createVLDataset(long fid, long dsid, String name, long dapl) + private final void _createVLStrDataset(String name, long dapl) { try { H5dtid = H5.H5Tcopy(HDF5Constants.H5T_C_S1); @@ -166,24 +167,24 @@ public class TestH5D { err.printStackTrace(); fail("H5.H5Tcopy: " + err); } - assertTrue("TestH5D._createVLDataset.H5Tcopy: ", H5dtid >= 0); + assertTrue("TestH5D._createVLStrDataset.H5Tcopy: ", H5dtid >= 0); try { H5.H5Tset_size(H5dtid, HDF5Constants.H5T_VARIABLE); - assertTrue("TestH5D._createVLDataset.H5Tis_variable_str", H5.H5Tis_variable_str(H5dtid)); + assertTrue("TestH5D._createVLStrDataset.H5Tis_variable_str", H5.H5Tis_variable_str(H5dtid)); } catch (Throwable err) { err.printStackTrace(); fail("H5.H5Tset_size: " + err); } try { - H5did = H5.H5Dcreate(fid, name, H5dtid, dsid, HDF5Constants.H5P_DEFAULT, + H5did = H5.H5Dcreate(H5fid, name, H5dtid, H5dsid, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, dapl); } catch (Throwable err) { err.printStackTrace(); fail("H5.H5Dcreate: " + err); } - assertTrue("TestH5D._createVLDataset.H5Dcreate: ", H5did >= 0); + assertTrue("TestH5D._createVLStrDataset.H5Dcreate: ", H5did >= 0); } private final void _closeH5file() throws HDF5LibraryException @@ -934,7 +935,7 @@ public class TestH5D { buf_data[(indx * DIM_Y) + jndx] == 126); } - @Test + @Ignore public void testH5Dvlen_get_buf_size() { String[] str_data = {"Parting", "is such", "sweet", "sorrow.", "Testing", "one", "two", "three.", @@ -945,12 +946,12 @@ public class TestH5D { for (int idx = 0; idx < str_data.length; idx++) str_data_bytes += str_data[idx].length() + 1; // Account for terminating null - _createVLDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT); + _createVLStrDataset("dset", HDF5Constants.H5P_DEFAULT); try { if ((H5did >= 0) && (H5dtid >= 0)) - H5.H5Dwrite_VLStrings(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, str_data); + H5.H5DwriteVL(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, str_data); } catch (Exception e) { e.printStackTrace(); @@ -964,26 +965,122 @@ public class TestH5D { assertTrue("H5Dvlen_get_buf_size " + vl_size + " == " + str_data_bytes, vl_size == str_data_bytes); } - @Test - public void testH5Dvlen_read_default_buffer() throws Throwable + @Ignore + public void testH5Dvlen_string_buffer() throws Throwable { - String[] str_data = {"Parting", "is such", "sweet", "sorrow.", "Testing", "one", "two", "three.", - "Dog,", "man's", "best", "friend.", "Diamonds", "are", "a", "girls!", - "S A", "T U R", "D A Y", "night", "That's", "all", "folks", "!!!"}; - byte[] read_data = new byte[512]; + String dset_str_name = "VLStringdata"; + long dset_str_id = HDF5Constants.H5I_INVALID_HID; + long dtype_str_id = HDF5Constants.H5I_INVALID_HID; + long dspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {64}; + long lsize = 1; - _createVLDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT); + String[] str_data0 = {"Parting", "is such", "sweet", "sorrow."}; + String[] str_data1 = {"Testing", "one", "two", "three."}; + String[] str_data2 = {"Dog,", "man's", "best", "friend."}; + String[] str_data3 = {"Diamonds", "are", "a", "girls!"}; + String[] str_data4 = {"S A", "T U R", "D A Y", "night"}; + String[] str_data5 = {"That's", "all", "folks", "!!!"}; + + ArrayList[] vl_str_data = new ArrayList[6]; + vl_str_data[0] = new ArrayList<String>(Arrays.asList(str_data0)); + vl_str_data[1] = new ArrayList<String>(Arrays.asList(str_data1)); + vl_str_data[2] = new ArrayList<String>(Arrays.asList(str_data2)); + vl_str_data[3] = new ArrayList<String>(Arrays.asList(str_data3)); + vl_str_data[4] = new ArrayList<String>(Arrays.asList(str_data4)); + vl_str_data[5] = new ArrayList<String>(Arrays.asList(str_data5)); try { - H5.H5Dwrite_VLStrings(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, str_data); + H5dtid = H5.H5Tcopy(HDF5Constants.H5T_C_S1); } - catch (Exception e) { - e.printStackTrace(); + catch (Throwable err) { + err.printStackTrace(); + fail("testH5Dvlen_string_buffer.H5.H5Tcopy: " + err); + } + assertTrue("testH5Dvlen_string_buffer.H5Tcopy: ", H5dtid >= 0); + try { + H5.H5Tset_size(H5dtid, HDF5Constants.H5T_VARIABLE); + assertTrue("testH5Dvlen_string_buffer.H5Tis_variable_str", H5.H5Tis_variable_str(H5dtid)); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5Dvlen_string_buffer.H5Tset_size: " + err); + } + try { + dtype_str_id = H5.H5Tvlen_create(H5dtid); + assertTrue("testH5Dvlen_string_buffer.H5Tvlen_create: ", dtype_str_id >= 0); + } + catch (Exception err) { + if (dtype_str_id > 0) + try { + H5.H5Tclose(dtype_str_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("testH5Dvlen_string_buffer: " + err); + } + + try { + dspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(dspace_id > 0); + dset_str_id = + H5.H5Dcreate(H5fid, dset_str_name, dtype_str_id, dspace_id, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5Dvlen_string_buffer: ", dset_str_id >= 0); + + H5.H5DwriteVL(dset_str_id, dtype_str_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_str_data); + } + catch (Exception err) { + if (dset_str_id > 0) + try { + H5.H5Dclose(dset_str_id); + } + catch (Exception ex) { + } + if (dtype_str_id > 0) + try { + H5.H5Tclose(dtype_str_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("testH5Dvlen_string_buffer: " + err); + } + finally { + if (dspace_id > 0) + try { + H5.H5Sclose(dspace_id); + } + catch (Exception ex) { + } } - H5.H5Dread(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, - read_data); + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) + lsize *= dims[j]; + + ArrayList[] vl_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + vl_readbuf[j] = new ArrayList<String>(); + + try { + H5.H5DreadVL(dset_str_id, dtype_str_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5Dvlen_string_buffer:" + vl_readbuf[0].get(0), + vl_str_data[0].get(0).equals(vl_readbuf[0].get(0))); + assertTrue("testH5Dvlen_string_buffer:" + vl_readbuf[1].get(0), + vl_str_data[1].get(0).equals(vl_readbuf[1].get(0))); + assertTrue("testH5Dvlen_string_buffer:" + vl_readbuf[2].get(0), + vl_str_data[2].get(0).equals(vl_readbuf[2].get(0))); + assertTrue("testH5Dvlen_string_buffer:" + vl_readbuf[3].get(0), + vl_str_data[3].get(0).equals(vl_readbuf[3].get(0))); } @Test @@ -994,20 +1091,21 @@ public class TestH5D { "S A", "T U R", "D A Y", "night", "That's", "all", "folks", "!!!"}; String[] str_rdata = new String[DIM_X * DIM_Y]; - _createVLDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT); + _createVLStrDataset("dset", HDF5Constants.H5P_DEFAULT); try { if ((H5did >= 0) && (H5dtid >= 0)) - H5.H5Dwrite_VLStrings(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, str_wdata); + H5.H5DwriteVL(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, str_wdata); } catch (Exception e) { e.printStackTrace(); } + try { if ((H5did >= 0) && (H5dtid >= 0)) - H5.H5Dread_VLStrings(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, str_rdata); + H5.H5DreadVL(H5did, H5dtid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, str_rdata); } catch (Exception e) { e.printStackTrace(); @@ -1153,51 +1251,50 @@ public class TestH5D { H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); - for (int j = 0; j < dims.length; j++) { + for (int j = 0; j < dims.length; j++) lsize *= dims[j]; - } // Read Integer data - ArrayList[] vl_readbuf = new ArrayList[4]; + ArrayList[] vl_int_readbuf = new ArrayList[4]; for (int j = 0; j < lsize; j++) - vl_readbuf[j] = new ArrayList<Integer>(); + vl_int_readbuf[j] = new ArrayList<Integer>(); try { H5.H5DreadVL(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, vl_readbuf); + HDF5Constants.H5P_DEFAULT, vl_int_readbuf); } catch (Exception ex) { ex.printStackTrace(); } - assertTrue("testH5DVLwr:" + vl_readbuf[0].get(0), - vl_int_data[0].get(0).equals(vl_readbuf[0].get(0))); - assertTrue("testH5DVLwr:" + vl_readbuf[1].get(0), - vl_int_data[1].get(0).equals(vl_readbuf[1].get(0))); - assertTrue("testH5DVLwr:" + vl_readbuf[2].get(0), - vl_int_data[2].get(0).equals(vl_readbuf[2].get(0))); - assertTrue("testH5DVLwr:" + vl_readbuf[3].get(0), - vl_int_data[3].get(0).equals(vl_readbuf[3].get(0))); + assertTrue("testH5DVLwr:" + vl_int_readbuf[0].get(0), + vl_int_data[0].get(0).equals(vl_int_readbuf[0].get(0))); + assertTrue("testH5DVLwr:" + vl_int_readbuf[1].get(0), + vl_int_data[1].get(0).equals(vl_int_readbuf[1].get(0))); + assertTrue("testH5DVLwr:" + vl_int_readbuf[2].get(0), + vl_int_data[2].get(0).equals(vl_int_readbuf[2].get(0))); + assertTrue("testH5DVLwr:" + vl_int_readbuf[3].get(0), + vl_int_data[3].get(0).equals(vl_int_readbuf[3].get(0))); // Read Double data - vl_readbuf = new ArrayList[4]; + ArrayList[] vl_dbl_readbuf = new ArrayList[4]; for (int j = 0; j < lsize; j++) - vl_readbuf[j] = new ArrayList<Double>(); + vl_dbl_readbuf[j] = new ArrayList<Double>(); try { H5.H5DreadVL(dset_dbl_id, dtype_dbl_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, vl_readbuf); + HDF5Constants.H5P_DEFAULT, vl_dbl_readbuf); } catch (Exception ex) { ex.printStackTrace(); } - assertTrue("testH5DVLwr:" + vl_readbuf[0].get(0), - vl_dbl_data[0].get(0).equals(vl_readbuf[0].get(0))); - assertTrue("testH5DVLwr:" + vl_readbuf[1].get(0), - vl_dbl_data[1].get(0).equals(vl_readbuf[1].get(0))); - assertTrue("testH5DVLwr:" + vl_readbuf[2].get(0), - vl_dbl_data[2].get(0).equals(vl_readbuf[2].get(0))); - assertTrue("testH5DVLwr:" + vl_readbuf[3].get(0), - vl_dbl_data[3].get(0).equals(vl_readbuf[3].get(0))); + assertTrue("testH5DVLwr:" + vl_dbl_readbuf[0].get(0), + vl_dbl_data[0].get(0).equals(vl_dbl_readbuf[0].get(0))); + assertTrue("testH5DVLwr:" + vl_dbl_readbuf[1].get(0), + vl_dbl_data[1].get(0).equals(vl_dbl_readbuf[1].get(0))); + assertTrue("testH5DVLwr:" + vl_dbl_readbuf[2].get(0), + vl_dbl_data[2].get(0).equals(vl_dbl_readbuf[2].get(0))); + assertTrue("testH5DVLwr:" + vl_dbl_readbuf[3].get(0), + vl_dbl_data[3].get(0).equals(vl_dbl_readbuf[3].get(0))); } catch (Throwable err) { err.printStackTrace(); @@ -1230,4 +1327,624 @@ public class TestH5D { } } } + + @Test + public void testH5DVLwrVL() + { + String dset_int_name = "VLIntdata"; + long dset_int_id = HDF5Constants.H5I_INVALID_HID; + long dtype_int_id = HDF5Constants.H5I_INVALID_HID; + long base_dtype_int_id = HDF5Constants.H5I_INVALID_HID; + long dspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {4}; + long lsize = 1; + + ArrayList[] base_vl_int_data = new ArrayList[4]; + ArrayList[] vl_int_data = new ArrayList[4]; + try { + // Write Integer data + vl_int_data[0] = new ArrayList<Integer>(Arrays.asList(1)); + vl_int_data[1] = new ArrayList<Integer>(Arrays.asList(2, 3)); + vl_int_data[2] = new ArrayList<Integer>(Arrays.asList(4, 5, 6)); + vl_int_data[3] = new ArrayList<Integer>(Arrays.asList(7, 8, 9, 10)); + Class dataClass = vl_int_data.getClass(); + assertTrue("testH5DVLwrVL.getClass: " + dataClass, dataClass.isArray()); + + // Write VL data + base_vl_int_data[0] = new ArrayList<ArrayList<Integer>>(); + base_vl_int_data[0].add(vl_int_data[0]); + base_vl_int_data[1] = new ArrayList<ArrayList<Integer>>(); + base_vl_int_data[1].add(vl_int_data[0]); + base_vl_int_data[1].add(vl_int_data[1]); + base_vl_int_data[2] = new ArrayList<ArrayList<Integer>>(); + base_vl_int_data[2].add(vl_int_data[0]); + base_vl_int_data[2].add(vl_int_data[1]); + base_vl_int_data[2].add(vl_int_data[2]); + base_vl_int_data[3] = new ArrayList<ArrayList<Integer>>(); + base_vl_int_data[3].add(vl_int_data[0]); + base_vl_int_data[3].add(vl_int_data[1]); + base_vl_int_data[3].add(vl_int_data[2]); + base_vl_int_data[3].add(vl_int_data[3]); + + try { + dtype_int_id = H5.H5Tvlen_create(HDF5Constants.H5T_STD_U32LE); + assertTrue("testH5DVLwrVL.H5Tvlen_create: ", dtype_int_id >= 0); + base_dtype_int_id = H5.H5Tvlen_create(dtype_int_id); + assertTrue("testH5DVLwrVL.H5Tvlen_create: ", base_dtype_int_id >= 0); + } + catch (Exception err) { + if (base_dtype_int_id > 0) + try { + H5.H5Tclose(base_dtype_int_id); + } + catch (Exception ex) { + } + if (dtype_int_id > 0) + try { + H5.H5Tclose(dtype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5DVLwrVL: " + err); + } + + try { + dspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(dspace_id > 0); + dset_int_id = H5.H5Dcreate(H5fid, dset_int_name, base_dtype_int_id, dspace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT); + assertTrue("testH5DVLwrVL: ", dset_int_id >= 0); + + H5.H5DwriteVL(dset_int_id, base_dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, base_vl_int_data); + } + catch (Exception err) { + if (dset_int_id > 0) + try { + H5.H5Dclose(dset_int_id); + } + catch (Exception ex) { + } + if (dtype_int_id > 0) + try { + H5.H5Tclose(dtype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5DVLwrVL: " + err); + } + finally { + if (dspace_id > 0) + try { + H5.H5Sclose(dspace_id); + } + catch (Exception ex) { + } + } + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) + lsize *= dims[j]; + + // Read Integer data + ArrayList[] base_vl_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + base_vl_readbuf[j] = new ArrayList<ArrayList<Integer>>(); + + try { + H5.H5DreadVL(dset_int_id, base_dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, base_vl_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + ArrayList<ArrayList<Integer>> vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[0]; + assertTrue("vl_readbuf 0 exists", vl_readbuf != null); + ArrayList<Integer> vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(0)); + /* + * System.out.println(); System.out.println("vl_readbuf: " + vl_readbuf); + * System.out.println("vl_readbuf_int: " + vl_readbuf_int); + */ + assertTrue("testH5DVLwrVL:" + vl_readbuf_int.get(0), + vl_int_data[0].get(0).equals(vl_readbuf_int.get(0))); + + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[1]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(1)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5DVLwrVL:" + vl_readbuf_int.get(1), + vl_int_data[1].get(1).equals(vl_readbuf_int.get(1))); + + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[2]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(2)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5DVLwrVL:" + vl_readbuf_int.get(2), + vl_int_data[2].get(2).equals(vl_readbuf_int.get(2))); + + vl_readbuf = (ArrayList<ArrayList<Integer>>)base_vl_readbuf[3]; + vl_readbuf_int = (ArrayList<Integer>)(vl_readbuf.get(3)); + /* + * System.out.println("vl_readbuf: " + vl_readbuf); System.out.println("vl_readbuf_int: " + + * vl_readbuf_int); + */ + assertTrue("testH5DVLwrVL:" + vl_readbuf_int.get(3), + vl_int_data[3].get(3).equals(vl_readbuf_int.get(3))); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5DVLwrVL: " + err); + } + finally { + if (dset_int_id > 0) + try { + H5.H5Dclose(dset_int_id); + } + catch (Exception ex) { + } + if (dtype_int_id > 0) + try { + H5.H5Tclose(dtype_int_id); + } + catch (Exception ex) { + } + if (base_dtype_int_id > 0) + try { + H5.H5Tclose(base_dtype_int_id); + } + catch (Exception ex) { + } + } + } + + @Test + public void testH5DArraywr() + { + String dset_int_name = "ArrayIntdata"; + long dset_int_id = HDF5Constants.H5I_INVALID_HID; + long dtype_int_id = HDF5Constants.H5I_INVALID_HID; + long dspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {4}; + long lsize = 1; + + ArrayList[] arr_int_data = new ArrayList[4]; + try { + // Write Integer data + arr_int_data[0] = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4)); + arr_int_data[1] = new ArrayList<Integer>(Arrays.asList(2, 3, 4, 5)); + arr_int_data[2] = new ArrayList<Integer>(Arrays.asList(4, 5, 6, 7)); + arr_int_data[3] = new ArrayList<Integer>(Arrays.asList(7, 8, 9, 10)); + Class dataClass = arr_int_data.getClass(); + assertTrue("testH5DArraywr.getClass: " + dataClass, dataClass.isArray()); + + try { + dtype_int_id = H5.H5Tarray_create(HDF5Constants.H5T_STD_U32LE, 1, dims); + assertTrue("testH5DArraywr.H5Tarray_create: ", dtype_int_id >= 0); + } + catch (Exception err) { + if (dtype_int_id > 0) + try { + H5.H5Tclose(dtype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5DArraywr: " + err); + } + + try { + dspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(dspace_id > 0); + dset_int_id = + H5.H5Dcreate(H5fid, dset_int_name, dtype_int_id, dspace_id, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5DVLwr: ", dset_int_id >= 0); + + H5.H5DwriteVL(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, arr_int_data); + } + catch (Exception err) { + if (dset_int_id > 0) + try { + H5.H5Dclose(dset_int_id); + } + catch (Exception ex) { + } + if (dtype_int_id > 0) + try { + H5.H5Tclose(dtype_int_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5DVLwr: " + err); + } + finally { + if (dspace_id > 0) + try { + H5.H5Sclose(dspace_id); + } + catch (Exception ex) { + } + } + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) + lsize *= dims[j]; + + // Read Integer data + ArrayList[] arr_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + arr_readbuf[j] = new ArrayList<Integer>(); + + try { + H5.H5DreadVL(dset_int_id, dtype_int_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, arr_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5DVLwr:" + arr_readbuf[0].get(0), + arr_int_data[0].get(0).equals(arr_readbuf[0].get(0))); + assertTrue("testH5DVLwr:" + arr_readbuf[1].get(0), + arr_int_data[1].get(0).equals(arr_readbuf[1].get(0))); + assertTrue("testH5DVLwr:" + arr_readbuf[2].get(0), + arr_int_data[2].get(0).equals(arr_readbuf[2].get(0))); + assertTrue("testH5DVLwr:" + arr_readbuf[3].get(0), + arr_int_data[3].get(0).equals(arr_readbuf[3].get(0))); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5DArraywr: " + err); + } + finally { + if (dset_int_id > 0) + try { + H5.H5Dclose(dset_int_id); + } + catch (Exception ex) { + } + if (dtype_int_id > 0) + try { + H5.H5Tclose(dtype_int_id); + } + catch (Exception ex) { + } + } + } + + @Test + public void testH5DArray_string_buffer() throws Throwable + { + String dset_str_name = "ArrayStringdata"; + long dset_str_id = HDF5Constants.H5I_INVALID_HID; + long dtype_str_id = HDF5Constants.H5I_INVALID_HID; + long dspace_id = HDF5Constants.H5I_INVALID_HID; + long[] strdims = {4}; + long[] dims = {6}; + long lsize = 1; + + String[] str_data0 = {"Parting", "is such", "sweet", "sorrow."}; + String[] str_data1 = {"Testing", "one", "two", "three."}; + String[] str_data2 = {"Dog,", "man's", "best", "friend."}; + String[] str_data3 = {"Diamonds", "are", "a", "girls!"}; + String[] str_data4 = {"S A", "T U R", "D A Y", "night"}; + String[] str_data5 = {"That's", "all", "folks", "!!!"}; + + ArrayList[] arr_str_data = new ArrayList[6]; + arr_str_data[0] = new ArrayList<String>(Arrays.asList(str_data0)); + arr_str_data[1] = new ArrayList<String>(Arrays.asList(str_data1)); + arr_str_data[2] = new ArrayList<String>(Arrays.asList(str_data2)); + arr_str_data[3] = new ArrayList<String>(Arrays.asList(str_data3)); + arr_str_data[4] = new ArrayList<String>(Arrays.asList(str_data4)); + arr_str_data[5] = new ArrayList<String>(Arrays.asList(str_data5)); + + try { + H5dtid = H5.H5Tcopy(HDF5Constants.H5T_C_S1); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5DArray_string_buffer.H5.H5Tcopy: " + err); + } + assertTrue("testH5DArray_string_buffer.H5Tcopy: ", H5dtid >= 0); + try { + H5.H5Tset_size(H5dtid, HDF5Constants.H5T_VARIABLE); + assertTrue("testH5DArray_string_buffer.H5Tis_variable_str", H5.H5Tis_variable_str(H5dtid)); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5DArray_string_buffer.H5Tset_size: " + err); + } + try { + dtype_str_id = H5.H5Tarray_create(H5dtid, 1, strdims); + assertTrue("testH5DArray_string_buffer.H5Tarray_create: ", dtype_str_id >= 0); + } + catch (Exception err) { + if (dtype_str_id > 0) + try { + H5.H5Tclose(dtype_str_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("testH5DArray_string_buffer: " + err); + } + + try { + dspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(dspace_id > 0); + dset_str_id = + H5.H5Dcreate(H5fid, dset_str_name, dtype_str_id, dspace_id, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5DArray_string_buffer: ", dset_str_id >= 0); + + H5.H5DwriteVL(dset_str_id, dtype_str_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, arr_str_data); + } + catch (Exception err) { + if (dset_str_id > 0) + try { + H5.H5Dclose(dset_str_id); + } + catch (Exception ex) { + } + if (dtype_str_id > 0) + try { + H5.H5Tclose(dtype_str_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("testH5DArray_string_buffer: " + err); + } + finally { + if (dspace_id > 0) + try { + H5.H5Sclose(dspace_id); + } + catch (Exception ex) { + } + } + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) + lsize *= dims[j]; + + ArrayList[] arr_readbuf = new ArrayList[6]; + for (int j = 0; j < lsize; j++) + arr_readbuf[j] = new ArrayList<String>(); + + try { + H5.H5DreadVL(dset_str_id, dtype_str_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, arr_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + finally { + if (dset_str_id > 0) + try { + H5.H5Dclose(dset_str_id); + } + catch (Exception ex) { + } + if (dtype_str_id > 0) + try { + H5.H5Tclose(dtype_str_id); + } + catch (Exception ex) { + } + } + assertTrue("testH5DArray_string_buffer:" + arr_readbuf[0].get(0), + arr_str_data[0].get(0).equals(arr_readbuf[0].get(0))); + assertTrue("testH5DArray_string_buffer:" + arr_readbuf[1].get(0), + arr_str_data[1].get(0).equals(arr_readbuf[1].get(0))); + assertTrue("testH5DArray_string_buffer:" + arr_readbuf[2].get(0), + arr_str_data[2].get(0).equals(arr_readbuf[2].get(0))); + assertTrue("testH5DArray_string_buffer:" + arr_readbuf[3].get(0), + arr_str_data[3].get(0).equals(arr_readbuf[3].get(0))); + } + + @Test + public void testH5DArrayenum_rw() + { + String dset_enum_name = "ArrayEnumdata"; + long dset_enum_id = HDF5Constants.H5I_INVALID_HID; + long dtype_enum_id = HDF5Constants.H5I_INVALID_HID; + long dtype_arr_enum_id = HDF5Constants.H5I_INVALID_HID; + long dspace_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {4}; + long lsize = 1; + String enum_type = "Enum_type"; + byte[] enum_val = new byte[1]; + String enum_name = null; + + // Create a enumerate datatype + try { + dtype_enum_id = H5.H5Tcreate(HDF5Constants.H5T_ENUM, (long)1); + assertTrue("testH5DArrayenum_wr.H5Tarray_create: ", dtype_enum_id >= 0); + } + catch (Throwable err) { + if (dtype_enum_id > 0) + try { + H5.H5Tclose(dtype_enum_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("testH5DArrayenum_rw:H5Tcreate " + err); + } + + try { + enum_val[0] = 10; + H5.H5Tenum_insert(dtype_enum_id, "RED", enum_val); + enum_val[0] = 11; + H5.H5Tenum_insert(dtype_enum_id, "GREEN", enum_val); + enum_val[0] = 12; + H5.H5Tenum_insert(dtype_enum_id, "BLUE", enum_val); + enum_val[0] = 13; + H5.H5Tenum_insert(dtype_enum_id, "ORANGE", enum_val); + enum_val[0] = 14; + H5.H5Tenum_insert(dtype_enum_id, "YELLOW", enum_val); + + // Query member number and member index by member name, for enumeration type. + assertTrue("Can't get member number", H5.H5Tget_nmembers(dtype_enum_id) == 5); + assertTrue("Can't get correct index number", + H5.H5Tget_member_index(dtype_enum_id, "ORANGE") == 3); + + // Commit enumeration datatype and close it */ + H5.H5Tcommit(H5fid, enum_type, dtype_enum_id, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + + H5.H5Tclose(dtype_enum_id); + + // Open the dataytpe for query + dtype_enum_id = H5.H5Topen(H5fid, enum_type, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5DArrayenum_rw:H5Tcreate", dtype_enum_id >= 0); + + // Query member number and member index by member name, for enumeration type + assertTrue("Can't get member number", H5.H5Tget_nmembers(dtype_enum_id) == 5); + assertTrue("Can't get correct index number", + H5.H5Tget_member_index(dtype_enum_id, "ORANGE") == 3); + + // Query member value by member name, for enumeration type + H5.H5Tenum_valueof(dtype_enum_id, "ORANGE", enum_val); + assertTrue("Incorrect value for enum member", enum_val[0] == 13); + + // Query member value by member index, for enumeration type + H5.H5Tget_member_value(dtype_enum_id, 2, enum_val); + assertTrue("Incorrect value for enum member", enum_val[0] == 12); + + // Query member name by member value, for enumeration type + enum_val[0] = 14; + enum_name = H5.H5Tenum_nameof(dtype_enum_id, enum_val, 16); + assertTrue("Incorrect name for enum member", enum_name.compareTo("YELLOW") == 0); + + ArrayList[] arr_enum_data = new ArrayList[4]; + try { + // Write Integer data + arr_enum_data[0] = new ArrayList<Integer>(Arrays.asList(10, 11, 12, 13)); + arr_enum_data[1] = new ArrayList<Integer>(Arrays.asList(11, 12, 13, 14)); + arr_enum_data[2] = new ArrayList<Integer>(Arrays.asList(12, 13, 14, 10)); + arr_enum_data[3] = new ArrayList<Integer>(Arrays.asList(13, 14, 10, 11)); + Class dataClass = arr_enum_data.getClass(); + assertTrue("testH5DArrayenum_wr.getClass: " + dataClass, dataClass.isArray()); + + try { + dtype_arr_enum_id = H5.H5Tarray_create(HDF5Constants.H5T_STD_U32LE, 1, dims); + assertTrue("testH5DArrayenum_wr.H5Tarray_create: ", dtype_arr_enum_id >= 0); + } + catch (Exception err) { + if (dtype_arr_enum_id > 0) + try { + H5.H5Tclose(dtype_arr_enum_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("H5.testH5DArrayenum_wr: " + err); + } + + dspace_id = H5.H5Screate_simple(1, dims, null); + assertTrue(dspace_id > 0); + dset_enum_id = H5.H5Dcreate(H5fid, dset_enum_name, dtype_arr_enum_id, dspace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT); + assertTrue("testH5DVLwr: ", dset_enum_id >= 0); + + H5.H5DwriteVL(dset_enum_id, dtype_arr_enum_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, arr_enum_data); + } + catch (Throwable err) { + if (dset_enum_id > 0) + try { + H5.H5Dclose(dset_enum_id); + } + catch (Exception ex) { + } + if (dtype_enum_id > 0) + try { + H5.H5Tclose(dtype_enum_id); + } + catch (Exception ex) { + } + if (dtype_arr_enum_id > 0) + try { + H5.H5Tclose(dtype_arr_enum_id); + } + catch (Exception ex) { + } + err.printStackTrace(); + fail("testH5DArrayenum_rw:query " + err); + } + finally { + if (dspace_id > 0) + try { + H5.H5Sclose(dspace_id); + } + catch (Exception ex) { + } + } + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + for (int j = 0; j < dims.length; j++) + lsize *= dims[j]; + + // Read Integer data + ArrayList[] arr_readbuf = new ArrayList[4]; + for (int j = 0; j < lsize; j++) + arr_readbuf[j] = new ArrayList<Integer>(); + + try { + H5.H5DreadVL(dset_enum_id, dtype_arr_enum_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, arr_readbuf); + } + catch (Exception ex) { + ex.printStackTrace(); + } + assertTrue("testH5DVLArrayenum_wr:" + arr_readbuf[0].get(0), + arr_enum_data[0].get(0).equals(arr_readbuf[0].get(0))); + assertTrue("testH5DVLArrayenum_wr:" + arr_readbuf[1].get(0), + arr_enum_data[1].get(0).equals(arr_readbuf[1].get(0))); + assertTrue("testH5DVLArrayenum_wr:" + arr_readbuf[2].get(0), + arr_enum_data[2].get(0).equals(arr_readbuf[2].get(0))); + assertTrue("testH5DVLArrayenum_wr:" + arr_readbuf[3].get(0), + arr_enum_data[3].get(0).equals(arr_readbuf[3].get(0))); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5DArrayenum_wr: " + err); + } + finally { + if (dset_enum_id > 0) + try { + H5.H5Dclose(dset_enum_id); + } + catch (Exception ex) { + } + if (dtype_enum_id > 0) + try { + H5.H5Tclose(dtype_enum_id); + } + catch (Exception ex) { + } + if (dtype_arr_enum_id > 0) + try { + H5.H5Tclose(dtype_arr_enum_id); + } + catch (Exception ex) { + } + } + } } diff --git a/java/test/TestH5R.java b/java/test/TestH5R.java index 221a71e..1dcf992 100644 --- a/java/test/TestH5R.java +++ b/java/test/TestH5R.java @@ -600,7 +600,7 @@ public class TestH5R { HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); assertTrue("testH5RVLattr_ref: ", attr_obj_id >= 0); - H5.H5AwriteVL(attr_obj_id, atype_obj_id, vl_obj_data); + H5.H5Awrite(attr_obj_id, atype_obj_id, vl_obj_data); } catch (Exception err) { if (attr_obj_id > 0) @@ -657,7 +657,7 @@ public class TestH5R { HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); assertTrue("testH5RVLattr_ref: ", attr_reg_id >= 0); - H5.H5AwriteVL(attr_reg_id, atype_reg_id, vl_reg_data); + H5.H5Awrite(attr_reg_id, atype_reg_id, vl_reg_data); } catch (Exception err) { if (attr_reg_id > 0) @@ -696,7 +696,7 @@ public class TestH5R { vl_readbuf[j] = new ArrayList<byte[]>(); try { - H5.H5AreadVL(attr_obj_id, atype_obj_id, vl_readbuf); + H5.H5Aread(attr_obj_id, atype_obj_id, vl_readbuf); } catch (Exception ex) { ex.printStackTrace(); @@ -716,7 +716,7 @@ public class TestH5R { vl_readbuf[j] = new ArrayList<byte[]>(); try { - H5.H5AreadVL(attr_reg_id, atype_reg_id, vl_readbuf); + H5.H5Aread(attr_reg_id, atype_reg_id, vl_readbuf); } catch (Exception ex) { ex.printStackTrace(); @@ -831,8 +831,8 @@ public class TestH5R { HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); assertTrue("testH5RVLdset_ref: ", dset_obj_id >= 0); - H5.H5DwriteVL(dset_obj_id, dtype_obj_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, vl_obj_data); + H5.H5Dwrite(dset_obj_id, dtype_obj_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_obj_data); } catch (Exception err) { if (dset_obj_id > 0) @@ -890,8 +890,8 @@ public class TestH5R { HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); assertTrue("testH5RVLdset_ref: ", dset_reg_id >= 0); - H5.H5DwriteVL(dset_reg_id, dtype_reg_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, vl_reg_data); + H5.H5Dwrite(dset_reg_id, dtype_reg_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_reg_data); } catch (Exception err) { if (dset_reg_id > 0) @@ -930,8 +930,8 @@ public class TestH5R { vl_readbuf[j] = new ArrayList<byte[]>(); try { - H5.H5DreadVL(dset_obj_id, dtype_obj_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, vl_readbuf); + H5.H5Dread(dset_obj_id, dtype_obj_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_readbuf); } catch (Exception ex) { ex.printStackTrace(); @@ -951,8 +951,8 @@ public class TestH5R { vl_readbuf[j] = new ArrayList<byte[]>(); try { - H5.H5DreadVL(dset_reg_id, dtype_reg_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, vl_readbuf); + H5.H5Dread(dset_reg_id, dtype_reg_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, vl_readbuf); } catch (Exception ex) { ex.printStackTrace(); diff --git a/java/test/junit.sh.in b/java/test/junit.sh.in index 4e5152b..0690081 100644 --- a/java/test/junit.sh.in +++ b/java/test/junit.sh.in @@ -67,8 +67,8 @@ $top_builddir/java/src/jni/.libs/libhdf5_java.* LIST_JAR_TESTFILES=" $HDFLIB_HOME/hamcrest-core.jar $HDFLIB_HOME/junit.jar -$HDFLIB_HOME/slf4j-api-1.7.33.jar -$HDFLIB_HOME/ext/slf4j-simple-1.7.33.jar +$HDFLIB_HOME/slf4j-api-2.0.6.jar +$HDFLIB_HOME/ext/slf4j-simple-2.0.6.jar " LIST_JAR_FILES=" $top_builddir/java/src/$JARFILE @@ -304,7 +304,7 @@ JAVAEXEFLAGS=@H5_JAVAFLAGS@ COPY_LIBFILES_TO_BLDLIBDIR COPY_DATAFILES_TO_BLDDIR -CPATH=".:"$BLDLIBDIR"/"$JARFILE":"$BLDLIBDIR"/junit.jar:"$BLDLIBDIR"/hamcrest-core.jar:"$BLDLIBDIR"/slf4j-api-1.7.33.jar:"$BLDLIBDIR"/slf4j-simple-1.7.33.jar:"$TESTJARFILE"" +CPATH=".:"$BLDLIBDIR"/"$JARFILE":"$BLDLIBDIR"/junit.jar:"$BLDLIBDIR"/hamcrest-core.jar:"$BLDLIBDIR"/slf4j-api-2.0.6.jar:"$BLDLIBDIR"/slf4j-simple-2.0.6.jar:"$TESTJARFILE"" TEST=/usr/bin/test if [ ! -x /usr/bin/test ] diff --git a/java/test/testfiles/JUnit-TestH5A.txt b/java/test/testfiles/JUnit-TestH5A.txt index efdd4a2..f31c86c 100644 --- a/java/test/testfiles/JUnit-TestH5A.txt +++ b/java/test/testfiles/JUnit-TestH5A.txt @@ -11,6 +11,7 @@ JUnit version 4.11 .testH5Aget_info_by_name .testH5Aget_create_plist .testH5Adelete_by_name +.testH5AVLwrVL .testH5Aopen_by_name .testH5Aget_info .testH5Aget_name @@ -22,14 +23,16 @@ JUnit version 4.11 .testH5Adelete_by_idx_order .testH5Arename_by_name .testH5Acreate2_invalidobject +.testH5AArraywr .testH5Acreate2 .testH5Aiterate_by_name .testH5Adelete_by_idx_null .testH5Adelete_by_idx_invalidobject .testH5Awrite_readVL +.testH5AArray_string_buffer .testH5Aget_info1 Time: XXXX -OK (29 tests) +OK (32 tests) diff --git a/java/test/testfiles/JUnit-TestH5D.txt b/java/test/testfiles/JUnit-TestH5D.txt index 288e6d0..4c30621 100644 --- a/java/test/testfiles/JUnit-TestH5D.txt +++ b/java/test/testfiles/JUnit-TestH5D.txt @@ -1,5 +1,8 @@ JUnit version 4.11 +.testH5DArrayenum_rw +.testH5DVLwrVL .testH5Dget_storage_size +.testH5DArraywr .testH5Diterate_write .testH5Dcreate .testH5Dget_offset @@ -12,15 +15,14 @@ JUnit version 4.11 .testH5Dget_storage_size_empty .testH5Diterate .testH5Dget_access_plist -.testH5Dvlen_get_buf_size .testH5Dget_space_closed +.testH5DArray_string_buffer .testH5Dget_space_status .testH5Dvlen_write_read .testH5Dget_space .testH5Dget_type_closed -.testH5Dvlen_read_default_buffer Time: XXXX -OK (20 tests) +OK (22 tests) |