diff options
Diffstat (limited to 'java/test')
-rw-r--r-- | java/test/CMakeLists.txt | 4 | ||||
-rw-r--r-- | java/test/TestH5.java | 119 | ||||
-rw-r--r-- | java/test/TestH5D.java | 2 | ||||
-rw-r--r-- | java/test/TestH5Rref.java | 2 | ||||
-rw-r--r-- | java/test/TestH5T.java | 4 | ||||
-rw-r--r-- | java/test/junit.sh.in | 2 | ||||
-rw-r--r-- | java/test/testfiles/JUnit-TestH5.txt | 4 |
7 files changed, 118 insertions, 19 deletions
diff --git a/java/test/CMakeLists.txt b/java/test/CMakeLists.txt index c791c79..10f9d52 100644 --- a/java/test/CMakeLists.txt +++ b/java/test/CMakeLists.txt @@ -96,6 +96,8 @@ HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/h5ex_g_iterate.orig" "${PROJECT_BINARY_ HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/h5ex_g_iterate.orig" "${PROJECT_BINARY_DIR}/h5ex_g_iterateO2.hdf" "${HDF5_JAVA_TEST_LIB_TARGET}_files") HDFTEST_COPY_FILE("${HDF5_TOOLS_DIR}/testfiles/trefer_reg.h5" "${PROJECT_BINARY_DIR}/trefer_reg.h5" "${HDF5_JAVA_TEST_LIB_TARGET}_files") HDFTEST_COPY_FILE("${HDF5_TOOLS_DIR}/testfiles/trefer_attr.h5" "${PROJECT_BINARY_DIR}/trefer_attr.h5" "${HDF5_JAVA_TEST_LIB_TARGET}_files") +HDFTEST_COPY_FILE("${HDF5_TOOLS_DIR}/testfiles/tdatareg.h5" "${PROJECT_BINARY_DIR}/tdatareg.h5" "${HDF5_JAVA_TEST_LIB_TARGET}_files") +HDFTEST_COPY_FILE("${HDF5_TOOLS_DIR}/testfiles/tattrreg.h5" "${PROJECT_BINARY_DIR}/tattrreg.h5" "${HDF5_JAVA_TEST_LIB_TARGET}_files") add_custom_target(${HDF5_JAVA_TEST_LIB_TARGET}_files ALL COMMENT "Copying files needed by ${HDF5_JAVA_TEST_LIB_TARGET} tests" DEPENDS ${${HDF5_JAVA_TEST_LIB_TARGET}_files_list}) @@ -213,6 +215,8 @@ if (HDF5_TEST_JAVA AND HDF5_TEST_SERIAL) HDFTEST_COPY_FILE("${PROJECT_SOURCE_DIR}/h5ex_g_iterate.orig" "${PROJECT_BINARY_DIR}/${voltest}/h5ex_g_iterateO2.hdf" "${HDF5_JAVA_TEST_LIB_TARGET}_${voltest}_files") HDFTEST_COPY_FILE("${HDF5_TOOLS_DIR}/testfiles/trefer_reg.h5" "${PROJECT_BINARY_DIR}/${voltest}/trefer_reg.h5" "${HDF5_JAVA_TEST_LIB_TARGET}_${voltest}_files") HDFTEST_COPY_FILE("${HDF5_TOOLS_DIR}/testfiles/trefer_attr.h5" "${PROJECT_BINARY_DIR}/${voltest}/trefer_attr.h5" "${HDF5_JAVA_TEST_LIB_TARGET}_${voltest}_files") + HDFTEST_COPY_FILE("${HDF5_TOOLS_DIR}/testfiles/tdatareg.h5" "${PROJECT_BINARY_DIR}/${voltest}/tdatareg.h5" "${HDF5_JAVA_TEST_LIB_TARGET}_${voltest}_files") + HDFTEST_COPY_FILE("${HDF5_TOOLS_DIR}/testfiles/tattrreg.h5" "${PROJECT_BINARY_DIR}/${voltest}/tattrreg.h5" "${HDF5_JAVA_TEST_LIB_TARGET}_${voltest}_files") add_custom_target(${HDF5_JAVA_TEST_LIB_TARGET}_${voltest}_files ALL COMMENT "Copying files needed by ${HDF5_JAVA_TEST_LIB_TARGET} tests" DEPENDS ${${HDF5_JAVA_TEST_LIB_TARGET}_${voltest}_files_list}) diff --git a/java/test/TestH5.java b/java/test/TestH5.java index c4f298e..1f298f3 100644 --- a/java/test/TestH5.java +++ b/java/test/TestH5.java @@ -49,9 +49,13 @@ public class TestH5 { @Rule public TestName testname = new TestName(); private static final String H5_FILE = "testData.h5"; private static final String EXPORT_FILE = "testExport.txt"; - private static final String H5_DREG_FILE = "trefer_reg.h5"; - private static final String EXPORT_DREG_FILE = "testExportReg.txt"; - private static final String H5_AREG_FILE = "trefer_attr.h5"; + private static final String H5_REGION_FILE = "trefer_reg.h5"; + private static final String EXPORT_REGION_FILE = "testExportReg.txt"; + private static final String H5_ATTR_FILE = "trefer_attr.h5"; + private static final String EXPORT_ATTR_FILE = "testExportAttr.txt"; + private static final String H5_DREG_FILE = "tdatareg.h5"; + private static final String EXPORT_DREG_FILE = "testExportDReg.txt"; + private static final String H5_AREG_FILE = "tattrreg.h5"; private static final String EXPORT_AREG_FILE = "testExportAReg.txt"; private static final int DIM_X = 4; private static final int DIM_Y = 6; @@ -129,7 +133,7 @@ public class TestH5 { public void _openH5File(String filename, String dsetname) { try { H5fid = H5.H5Fopen(filename, - HDF5Constants.H5F_ACC_RDWR, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT); } catch (Throwable err) { err.printStackTrace(); @@ -162,6 +166,7 @@ public class TestH5 { @After public void closeH5File() throws HDF5LibraryException { _closeH5File(); + assertTrue("H5 open ids is 0", H5.getOpenIDCount()==0); System.out.println(); } @@ -415,8 +420,10 @@ public class TestH5 { _closeH5File(); + _openH5File(H5_FILE, "/dset"); + try { - H5.H5export_dataset(EXPORT_FILE, H5_FILE, "/dset", 99); + H5.H5export_dataset(EXPORT_FILE, H5fid, "/dset", 99); } catch (HDF5LibraryException err) { err.printStackTrace(); @@ -454,6 +461,86 @@ public class TestH5 { } @Test + public void testH5export_region() { + int[] dset_data_expect = {66, 69, 72, 75, 78, 81, 96, 99, 102, 105, 108, + 111, 126, 129, 132, 135, 138, 141, 156, 159, 162, 165, 168, 171, + 186, 189, 192, 195, 198, 201, 216, 219, 222, 225, 228, 231, + 207, 66, 252, 48, 84, 96, 12, 14, 213, 99}; + int[] dset_indata = new int[DIM_BLKS+DIM_PNTS]; + String objName = "/Dataset1"; + + _openH5File(H5_REGION_FILE, objName); + + try { + H5.H5export_dataset(EXPORT_REGION_FILE, H5fid, objName, 99); + } + catch (HDF5LibraryException err) { + err.printStackTrace(); + fail("H5export_dataset failed: " + err); + } + + File file = new File(EXPORT_REGION_FILE); + + try { + Reader reader = new FileReader(EXPORT_REGION_FILE); + StreamTokenizer streamTokenizer = new StreamTokenizer(reader); + int indx = 0; + while(streamTokenizer.nextToken() != StreamTokenizer.TT_EOF){ + if(streamTokenizer.ttype == StreamTokenizer.TT_NUMBER) { + dset_indata[indx] = (int)streamTokenizer.nval; + indx++; + } + } + reader.close(); + } + catch (IOException err) { + err.printStackTrace(); + fail("read file failed: " + err); + } + for(int row = 0; row < DIM_X; row++) + assertTrue("testH5export_region: <"+row+">"+dset_indata[row], dset_indata[row]==dset_data_expect[row]); + } + + @Test + public void testH5export_attribute() { + int[] dset_data_expect = {0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11}; + int[] dset_indata = new int[DIM_ATTR]; + String objName = "/Dataset3"; + + _openH5File(H5_ATTR_FILE, objName); + + try { + H5.H5export_dataset(EXPORT_ATTR_FILE, H5did, objName, 99); + } + catch (HDF5LibraryException err) { + err.printStackTrace(); + fail("H5export_dataset failed: " + err); + } + + File file = new File(EXPORT_ATTR_FILE); + + try { + Reader reader = new FileReader(EXPORT_ATTR_FILE); + StreamTokenizer streamTokenizer = new StreamTokenizer(reader); + int indx = 0; + int jndx = 0; + while(streamTokenizer.nextToken() != StreamTokenizer.TT_EOF){ + if(streamTokenizer.ttype == StreamTokenizer.TT_NUMBER) { + dset_indata[indx] = (int)streamTokenizer.nval; + indx++; + } + } + reader.close(); + } + catch (IOException err) { + err.printStackTrace(); + fail("read file failed: " + err); + } + for(int row = 0; row < DIM_X; row++) + assertTrue("testH5export_attribute: <"+row+">"+dset_indata[row], dset_indata[row]==dset_data_expect[row]); + } + + @Test public void testH5export_regdataset() { int[] dset_data_expect = {66, 69, 72, 75, 78, 81, 96, 99, 102, 105, 108, 111, 126, 129, 132, 135, 138, 141, 156, 159, 162, 165, 168, 171, @@ -465,7 +552,7 @@ public class TestH5 { _openH5File(H5_DREG_FILE, objName); try { - H5.H5export_dataset(EXPORT_DREG_FILE, H5_DREG_FILE, objName, 99); + H5.H5export_dataset(EXPORT_DREG_FILE, H5fid, objName, 99); } catch (HDF5LibraryException err) { err.printStackTrace(); @@ -491,23 +578,27 @@ public class TestH5 { fail("read file failed: " + err); } for(int row = 0; row < DIM_X; row++) - assertTrue("H5export_dataset: <"+row+">"+dset_indata[row], dset_indata[row]==dset_data_expect[row]); + assertTrue("testH5export_regdataset: <"+row+">"+dset_indata[row], dset_indata[row]==dset_data_expect[row]); } @Test public void testH5export_attrdataset() { - int[] dset_data_expect = {0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11}; - int[] dset_indata = new int[DIM_ATTR]; - String objName = "/Dataset3"; + int[] dset_data_expect = {66, 69, 72, 75, 78, 81, 96, 99, 102, 105, 108, + 111, 126, 129, 132, 135, 138, 141, 156, 159, 162, 165, 168, 171, + 186, 189, 192, 195, 198, 201, 216, 219, 222, 225, 228, 231, + 207, 66, 252, 48, 84, 96, 12, 14, 213, 99}; + int[] dset_indata = new int[DIM_BLKS+DIM_PNTS]; + String dsetName = "/Dataset1"; + String objName = "Attribute1"; - _openH5File(H5_AREG_FILE, objName); + _openH5File(H5_AREG_FILE, dsetName); try { - H5.H5export_dataset(EXPORT_AREG_FILE, H5_AREG_FILE, objName, 99); + H5.H5export_attribute(EXPORT_AREG_FILE, H5did, objName, 99); } catch (HDF5LibraryException err) { err.printStackTrace(); - fail("H5export_dataset failed: " + err); + fail("H5export_attribute failed: " + err); } File file = new File(EXPORT_AREG_FILE); @@ -530,6 +621,6 @@ public class TestH5 { fail("read file failed: " + err); } for(int row = 0; row < DIM_X; row++) - assertTrue("H5export_dataset: <"+row+">"+dset_indata[row], dset_indata[row]==dset_data_expect[row]); + assertTrue("testH5export_attrdataset: <"+row+">"+dset_indata[row], dset_indata[row]==dset_data_expect[row]); } } diff --git a/java/test/TestH5D.java b/java/test/TestH5D.java index 863ce79..dac3a9c 100644 --- a/java/test/TestH5D.java +++ b/java/test/TestH5D.java @@ -197,7 +197,7 @@ public class TestH5D { private final void _openH5file(String filename, String dsetname, long dapl) { try { H5fid = H5.H5Fopen(filename, - HDF5Constants.H5F_ACC_RDWR, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT); } catch (Throwable err) { err.printStackTrace(); diff --git a/java/test/TestH5Rref.java b/java/test/TestH5Rref.java index aeec64f..cbdabdd 100644 --- a/java/test/TestH5Rref.java +++ b/java/test/TestH5Rref.java @@ -53,7 +53,7 @@ public class TestH5Rref { public void openH5file(String filename, String dsetname) { try { H5fid = H5.H5Fopen(filename, - HDF5Constants.H5F_ACC_RDWR, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT); } catch (Throwable err) { err.printStackTrace(); diff --git a/java/test/TestH5T.java b/java/test/TestH5T.java index c882f8e..ed4e2a9 100644 --- a/java/test/TestH5T.java +++ b/java/test/TestH5T.java @@ -206,7 +206,7 @@ public class TestH5T { @Test public void testH5Tenum_functions() { - long filetype_id =HDF5Constants.H5I_INVALID_HID; + long filetype_id = HDF5Constants.H5I_INVALID_HID; String enum_type ="Enum_type"; byte[] enum_val = new byte[1]; String enum_name = null; @@ -398,7 +398,7 @@ public class TestH5T { @Test public void testH5Tcompound_functions() { - long filetype_id =HDF5Constants.H5I_INVALID_HID; + long filetype_id = HDF5Constants.H5I_INVALID_HID; // Create a compound datatype try { diff --git a/java/test/junit.sh.in b/java/test/junit.sh.in index 81ce13b..3774cbd 100644 --- a/java/test/junit.sh.in +++ b/java/test/junit.sh.in @@ -252,6 +252,8 @@ COPY_DATAFILES_TO_BLDDIR() $CP -f $HDFTEST_HOME/h5ex_g_iterate.orig $BLDDIR/h5ex_g_iterateO2.hdf $CP -f $TOOLS_TESTFILES/trefer_reg.h5 $BLDDIR/trefer_reg.h5 $CP -f $TOOLS_TESTFILES/trefer_attr.h5 $BLDDIR/trefer_attr.h5 + $CP -f $TOOLS_TESTFILES/tdatareg.h5 $BLDDIR/tdatareg.h5 + $CP -f $TOOLS_TESTFILES/tattrreg.h5 $BLDDIR/tattrreg.h5 } CLEAN_DATAFILES_AND_BLDDIR() diff --git a/java/test/testfiles/JUnit-TestH5.txt b/java/test/testfiles/JUnit-TestH5.txt index 59765d9..fb50a57 100644 --- a/java/test/testfiles/JUnit-TestH5.txt +++ b/java/test/testfiles/JUnit-TestH5.txt @@ -1,4 +1,5 @@ JUnit version 4.11 +.testH5export_region .testH5get_libversion_null_param .testJ2C .testH5export_dataset @@ -7,6 +8,7 @@ JUnit version 4.11 .testH5garbage_collect .testH5error_off .testH5export_regdataset +.testH5export_attribute .serializeToDisk .testH5open .testH5check_version @@ -15,5 +17,5 @@ JUnit version 4.11 Time: XXXX -OK (13 tests) +OK (15 tests) |