diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/examples/datatypes/H5Ex_T_ObjectReference.java | 124 | ||||
-rw-r--r-- | java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java | 149 | ||||
-rw-r--r-- | java/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | java/test/Makefile.am | 1 | ||||
-rw-r--r-- | java/test/TestH5Ocopy.java | 241 | ||||
-rw-r--r-- | java/test/TestH5OcopyOld.java | 398 | ||||
-rw-r--r-- | java/test/junit.sh.in | 22 | ||||
-rw-r--r-- | java/test/testfiles/JUnit-TestH5Ocopy.txt | 3 | ||||
-rw-r--r-- | java/test/testfiles/JUnit-TestH5OcopyOld.txt | 10 |
9 files changed, 698 insertions, 251 deletions
diff --git a/java/examples/datatypes/H5Ex_T_ObjectReference.java b/java/examples/datatypes/H5Ex_T_ObjectReference.java index 38536b8..98a11df 100644 --- a/java/examples/datatypes/H5Ex_T_ObjectReference.java +++ b/java/examples/datatypes/H5Ex_T_ObjectReference.java @@ -70,7 +70,7 @@ public class H5Ex_T_ObjectReference { long group_id = HDF5Constants.H5I_INVALID_HID; long dataset_id = HDF5Constants.H5I_INVALID_HID; long[] dims = { DIM0 }; - byte[][] dset_data = new byte[DIM0][8]; + byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE]; // Create a new file using default properties. try { @@ -111,50 +111,58 @@ public class H5Ex_T_ObjectReference { e.printStackTrace(); } - // Create references to the previously created objects. Passing -1 - // as space_id causes this parameter to be ignored. Other values - // besides valid dataspaces result in an error. try { if (file_id >= 0) { - byte rbuf0[] = H5.H5Rcreate(file_id, GROUPNAME, HDF5Constants.H5R_OBJECT, -1); - byte rbuf1[] = H5.H5Rcreate(file_id, DATASETNAME2, HDF5Constants.H5R_OBJECT, -1); - for (int indx = 0; indx < 8; indx++) { - dset_data[0][indx] = rbuf0[indx]; - dset_data[1][indx] = rbuf1[indx]; + try { + dset_data[0] = H5.H5Rcreate_object(file_id, GROUPNAME, HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); + } + + try { + dset_data[1] = H5.H5Rcreate_object(file_id, DATASETNAME2, HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); } } + + // Create dataspace. Setting maximum size to NULL sets the maximum + // size to be the current size. + try { + filespace_id = H5.H5Screate_simple(RANK, dims, null); + } + catch (Exception e) { + e.printStackTrace(); + } + + // Create the dataset. + try { + if ((file_id >= 0) && (filespace_id >= 0)) + dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_REF, filespace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + } + catch (Exception e) { + e.printStackTrace(); + } + + // Write the object references to it. + try { + if (dataset_id >= 0) + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, dset_data); + } + catch (Exception e) { + e.printStackTrace(); + } } - catch (Exception e) { - e.printStackTrace(); - } - - // Create dataspace. Setting maximum size to NULL sets the maximum - // size to be the current size. - try { - filespace_id = H5.H5Screate_simple(RANK, dims, null); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Create the dataset. - try { - if ((file_id >= 0) && (filespace_id >= 0)) - dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_REF_OBJ, filespace_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Write the object references to it. - try { - if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + catch (Exception ex) { + ex.printStackTrace(); } - catch (Exception e) { - e.printStackTrace(); + finally { + try {H5.H5Rdestroy(dset_data[1]);} catch (Exception ex) {} + try {H5.H5Rdestroy(dset_data[0]);} catch (Exception ex) {} } // End access to the dataset and release resources used by it. @@ -192,7 +200,7 @@ public class H5Ex_T_ObjectReference { int object_type = -1; long object_id = HDF5Constants.H5I_INVALID_HID; long[] dims = { DIM0 }; - byte[][] dset_data; + byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE]; // Open an existing file. try { @@ -228,14 +236,10 @@ public class H5Ex_T_ObjectReference { e.printStackTrace(); } - // Allocate array of pointers to two-dimensional arrays (the - // elements of the dataset. - dset_data = new byte[(int)dims[0]][8]; - - // Read the data using the default properties. + // Read data. try { if (dataset_id >= 0) { - H5.H5Dread(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + H5.H5Dread(dataset_id, HDF5Constants.H5T_STD_REF, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } } @@ -250,45 +254,24 @@ public class H5Ex_T_ObjectReference { // Open the referenced object, get its name and type. try { if (dataset_id >= 0) { - object_id = H5.H5Rdereference(dataset_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, dset_data[indx]); + object_id = H5.H5Ropen_object(dset_data[indx], HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); object_type = H5.H5Rget_obj_type(dataset_id, HDF5Constants.H5R_OBJECT, dset_data[indx]); } String obj_name = null; if (object_type >= 0) { - // Get the length of the name and retrieve the name. + // Get the name. obj_name = H5.H5Iget_name(object_id); } if ((object_id >= 0) && (object_type >= -1)) { switch (H5G_obj.get(object_type)) { case H5G_GROUP: System.out.print("H5G_GROUP"); - try { - if (object_id >= 0) - H5.H5Gclose(object_id); - } - catch (Exception e) { - e.printStackTrace(); - } break; case H5G_DATASET: System.out.print("H5G_DATASET"); - try { - if (object_id >= 0) - H5.H5Dclose(object_id); - } - catch (Exception e) { - e.printStackTrace(); - } break; case H5G_TYPE: System.out.print("H5G_TYPE"); - try { - if (object_id >= 0) - H5.H5Tclose(object_id); - } - catch (Exception e) { - e.printStackTrace(); - } break; default: System.out.print("UNHANDLED"); @@ -300,6 +283,9 @@ public class H5Ex_T_ObjectReference { catch (Exception e) { e.printStackTrace(); } + finally { + try {H5.H5Oclose(object_id);} catch (Exception ex) {} + } } // End access to the dataset and release resources used by it. diff --git a/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java b/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java index b38b0a0..885b1da 100644 --- a/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java +++ b/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java @@ -18,7 +18,6 @@ Next, it reopens the file, dereferences the references, and outputs the names of their targets to the screen. ************************************************************/ - package examples.datatypes; import java.util.EnumSet; @@ -72,7 +71,7 @@ public class H5Ex_T_ObjectReferenceAttribute { long dataset_id = HDF5Constants.H5I_INVALID_HID; long attribute_id = HDF5Constants.H5I_INVALID_HID; long[] dims = { DIM0 }; - byte[][] dset_data = new byte[DIM0][8]; + byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE]; // Create a new file using default properties. try { @@ -113,64 +112,72 @@ public class H5Ex_T_ObjectReferenceAttribute { e.printStackTrace(); } - // Create references to the previously created objects. Passing -1 - // as space_id causes this parameter to be ignored. Other values - // besides valid dataspaces result in an error. try { if (file_id >= 0) { - byte rbuf0[] = H5.H5Rcreate(file_id, GROUPNAME, HDF5Constants.H5R_OBJECT, -1); - byte rbuf1[] = H5.H5Rcreate(file_id, DATASETNAME2, HDF5Constants.H5R_OBJECT, -1); - for (int indx = 0; indx < 8; indx++) { - dset_data[0][indx] = rbuf0[indx]; - dset_data[1][indx] = rbuf1[indx]; + try { + dset_data[0] = H5.H5Rcreate_object(file_id, GROUPNAME, HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); + } + + try { + dset_data[1] = H5.H5Rcreate_object(file_id, DATASETNAME2, HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); } } - } - catch (Exception e) { - e.printStackTrace(); - } - // Create dataset with a scalar dataspace to serve as the parent - // for the attribute. - try { - dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR); - if (dataspace_id >= 0) { - dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); - H5.H5Sclose(dataspace_id); - dataspace_id = HDF5Constants.H5I_INVALID_HID; + // Create dataset with a scalar dataspace to serve as the parent + // for the attribute. + try { + dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR); + if (dataspace_id >= 0) { + dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + H5.H5Sclose(dataspace_id); + dataspace_id = HDF5Constants.H5I_INVALID_HID; + } + } + catch (Exception e) { + e.printStackTrace(); + } + + // Create dataspace. Setting maximum size to NULL sets the maximum + // size to be the current size. + try { + dataspace_id = H5.H5Screate_simple(RANK, dims, null); + } + catch (Exception e) { + e.printStackTrace(); + } + + // Create the attribute and write the array data to it. + try { + if ((dataset_id >= 0) && (dataspace_id >= 0)) + attribute_id = H5.H5Acreate(dataset_id, ATTRIBUTENAME, HDF5Constants.H5T_STD_REF, dataspace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + } + catch (Exception e) { + e.printStackTrace(); + } + + // Write the dataset. + try { + if (attribute_id >= 0) + H5.H5Awrite(attribute_id, HDF5Constants.H5T_STD_REF, dset_data); + } + catch (Exception e) { + e.printStackTrace(); } } - catch (Exception e) { - e.printStackTrace(); - } - - // Create dataspace. Setting maximum size to NULL sets the maximum - // size to be the current size. - try { - dataspace_id = H5.H5Screate_simple(RANK, dims, null); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Create the attribute and write the array data to it. - try { - if ((dataset_id >= 0) && (dataspace_id >= 0)) - attribute_id = H5.H5Acreate(dataset_id, ATTRIBUTENAME, HDF5Constants.H5T_STD_REF_OBJ, dataspace_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Write the dataset. - try { - if (attribute_id >= 0) - H5.H5Awrite(attribute_id, HDF5Constants.H5T_STD_REF_OBJ, dset_data); + catch (Exception ex) { + ex.printStackTrace(); } - catch (Exception e) { - e.printStackTrace(); + finally { + try {H5.H5Rdestroy(dset_data[1]);} catch (Exception ex) {} + try {H5.H5Rdestroy(dset_data[0]);} catch (Exception ex) {} } // End access to the dataset and release resources used by it. @@ -207,7 +214,6 @@ public class H5Ex_T_ObjectReferenceAttribute { catch (Exception e) { e.printStackTrace(); } - } private static void ReadDataset() { @@ -218,7 +224,7 @@ public class H5Ex_T_ObjectReferenceAttribute { int object_type = -1; long object_id = HDF5Constants.H5I_INVALID_HID; long[] dims = { DIM0 }; - byte[][] dset_data; + byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE]; // Open an existing file. try { @@ -263,14 +269,10 @@ public class H5Ex_T_ObjectReferenceAttribute { e.printStackTrace(); } - // Allocate array of pointers to two-dimensional arrays (the - // elements of the dataset. - dset_data = new byte[(int) dims[0]][8]; - // Read data. try { if (attribute_id >= 0) - H5.H5Aread(attribute_id, HDF5Constants.H5T_STD_REF_OBJ, dset_data); + H5.H5Aread(attribute_id, HDF5Constants.H5T_STD_REF, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -283,45 +285,24 @@ public class H5Ex_T_ObjectReferenceAttribute { // Open the referenced object, get its name and type. try { if (dataset_id >= 0) { - object_id = H5.H5Rdereference(dataset_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, dset_data[indx]); + object_id = H5.H5Ropen_object(dset_data[indx], HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); object_type = H5.H5Rget_obj_type(dataset_id, HDF5Constants.H5R_OBJECT, dset_data[indx]); } String obj_name = null; if (object_type >= 0) { - // Get the length of the name and retrieve the name. + // Get the name. obj_name = H5.H5Iget_name(object_id); } if ((object_id >= 0) && (object_type >= -1)) { switch (H5G_obj.get(object_type)) { case H5G_GROUP: System.out.print("H5G_GROUP"); - try { - if (object_id >= 0) - H5.H5Gclose(object_id); - } - catch (Exception e) { - e.printStackTrace(); - } break; case H5G_DATASET: System.out.print("H5G_DATASET"); - try { - if (object_id >= 0) - H5.H5Dclose(object_id); - } - catch (Exception e) { - e.printStackTrace(); - } break; case H5G_TYPE: System.out.print("H5G_TYPE"); - try { - if (object_id >= 0) - H5.H5Tclose(object_id); - } - catch (Exception e) { - e.printStackTrace(); - } break; default: System.out.print("UNHANDLED"); @@ -333,6 +314,9 @@ public class H5Ex_T_ObjectReferenceAttribute { catch (Exception e) { e.printStackTrace(); } + finally { + try {H5.H5Oclose(object_id);} catch (Exception ex) {} + } } // End access to the dataset and release resources used by it. @@ -369,7 +353,6 @@ public class H5Ex_T_ObjectReferenceAttribute { catch (Exception e) { e.printStackTrace(); } - } public static void main(String[] args) { diff --git a/java/test/CMakeLists.txt b/java/test/CMakeLists.txt index c6cf607..b1186a4 100644 --- a/java/test/CMakeLists.txt +++ b/java/test/CMakeLists.txt @@ -39,6 +39,7 @@ set (HDF5_JAVA_TEST_SOURCES TestH5Oparams TestH5Obasic TestH5Ocreate + TestH5OcopyOld TestH5Ocopy TestH5PL TestH5VL diff --git a/java/test/Makefile.am b/java/test/Makefile.am index ac3b619..6dd309c 100644 --- a/java/test/Makefile.am +++ b/java/test/Makefile.am @@ -71,6 +71,7 @@ noinst_JAVA = \ TestH5Oparams.java \ TestH5Obasic.java \ TestH5Ocreate.java \ + TestH5OcopyOld.java \ TestH5Ocopy.java \ TestH5PL.java \ TestH5VL.java \ diff --git a/java/test/TestH5Ocopy.java b/java/test/TestH5Ocopy.java index b3b1acd..8ac73c6 100644 --- a/java/test/TestH5Ocopy.java +++ b/java/test/TestH5Ocopy.java @@ -136,33 +136,48 @@ public class TestH5Ocopy { @Test public void testH5OcopyRefsAttr() { long ocp_plist_id = HDF5Constants.H5I_INVALID_HID; - byte rbuf0[]=null , rbuf1[] = null; - byte[] dset_data = new byte[16]; + byte[][] dset_data = null; + byte[][] read_data = null; long attribute_id = HDF5Constants.H5I_INVALID_HID; - - try { - rbuf0 = H5.H5Rcreate(H5fid, "/G1", HDF5Constants.H5R_OBJECT, -1); - rbuf1 = H5.H5Rcreate(H5fid, "DS2", HDF5Constants.H5R_OBJECT, -1); - //System.arraycopy(rbuf0, 0, dset_data, 0, 8); - System.arraycopy(rbuf1, 0, dset_data, 8, 8); - } - catch (Exception ex) { - fail("testH5OcopyRefsAttr: H5Rcreate failed"); - } - try { - attribute_id = H5.H5Acreate(H5did2, "A1", HDF5Constants.H5T_STD_REF_OBJ, H5dsid, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); - assertTrue("testH5OcopyRefsAttr.H5Acreate: ", attribute_id >= 0); - H5.H5Awrite(attribute_id, HDF5Constants.H5T_STD_REF_OBJ, dset_data); - - H5.H5Aclose(attribute_id); + dset_data = new byte[2][HDF5Constants.H5R_REF_BUF_SIZE]; + try { + dset_data[0] = H5.H5Rcreate_object(H5fid, "/G1", HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5OcopyInvalidRef: H5Rcreate_object " + err); + } + + try { + dset_data[1] = H5.H5Rcreate_object(H5fid, "DS2", HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5OcopyInvalidRef: H5Rcreate_object " + err); + } + + try { + attribute_id = H5.H5Acreate(H5did2, "A1", HDF5Constants.H5T_STD_REF, H5dsid, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5OcopyRefsAttr.H5Acreate: ", attribute_id >= 0); + H5.H5Awrite(attribute_id, HDF5Constants.H5T_STD_REF, dset_data); + + H5.H5Aclose(attribute_id); + } + catch (Exception ex) { + fail("testH5OcopyRefsAttr: H5Awrite failed"); + } + finally { + try {H5.H5Aclose(attribute_id);} catch (Exception exx) {} + } } catch (Exception ex) { - fail("testH5OcopyRefsAttr: H5Awrite failed"); + ex.printStackTrace(); } finally { - try {H5.H5Aclose(attribute_id);} catch (Exception exx) {} + try {H5.H5Rdestroy(dset_data[1]);} catch (Exception ex) {} + try {H5.H5Rdestroy(dset_data[0]);} catch (Exception ex) {} } try { @@ -181,30 +196,44 @@ public class TestH5Ocopy { @Test public void testH5OcopyRefsDatasettodiffFile() { - byte rbuf1[] = null; - byte[] dset_data = new byte[16]; + byte[][] dset_data = null; + byte[][] read_data = null; long ocp_plist_id = HDF5Constants.H5I_INVALID_HID; long dataset_id = HDF5Constants.H5I_INVALID_HID; long H5fid2 = HDF5Constants.H5I_INVALID_HID; try { - rbuf1 = H5.H5Rcreate(H5fid, "DS2", HDF5Constants.H5R_OBJECT, -1); - System.arraycopy(rbuf1, 0, dset_data, 8, 8); - - dataset_id = H5.H5Dcreate(H5fid, "DSREF", - HDF5Constants.H5T_STD_REF_OBJ, H5dsid, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); - assertTrue("testH5OcopyRefsDatasettodiffFile.H5Dcreate: ", dataset_id >= 0); - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, - HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); - H5.H5Dclose(dataset_id); + dset_data = new byte[2][HDF5Constants.H5R_REF_BUF_SIZE]; + try { + dset_data[1] = H5.H5Rcreate_object(H5fid, "DS2", HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5OcopyInvalidRef: H5Rcreate_object " + err); + } + + try { + dataset_id = H5.H5Dcreate(H5fid, "DSREF", + HDF5Constants.H5T_STD_REF_OBJ, H5dsid, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5OcopyRefsDatasettodiffFile.H5Dcreate: ", dataset_id >= 0); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF, + HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dclose(dataset_id); + } + catch (Exception ex) { + fail("testH5OcopyRefsDatasettodiffFile: create dataset failed"); + } + finally { + try {H5.H5Dclose(dataset_id);} catch (Exception exx) {} + } } catch (Exception ex) { - fail("testH5OcopyRefsDatasettodiffFile: create dataset failed"); + ex.printStackTrace(); } finally { - try {H5.H5Dclose(dataset_id);} catch (Exception exx) {} + try {H5.H5Rdestroy(dset_data[1]);} catch (Exception ex) {} } try { @@ -241,34 +270,54 @@ public class TestH5Ocopy { @Test public void testH5OcopyRefsDatasettosameFile() { - byte rbuf0[]=null , rbuf1[] = null; - byte[] dset_data = new byte[16]; + byte[][] dset_data = null; + byte[][] read_data = null; long ocp_plist_id = HDF5Constants.H5I_INVALID_HID; long dataset_id = HDF5Constants.H5I_INVALID_HID; long did = HDF5Constants.H5I_INVALID_HID; int obj_type = -1; - byte[] read_data = new byte[16]; try { - rbuf0 = H5.H5Rcreate(H5fid, "/G1", HDF5Constants.H5R_OBJECT, -1); - rbuf1 = H5.H5Rcreate(H5fid, "DS2", HDF5Constants.H5R_OBJECT, -1); - System.arraycopy(rbuf0, 0, dset_data, 0, 8); - System.arraycopy(rbuf1, 0, dset_data, 8, 8); - - //Create a dataset and write object references to it. - dataset_id = H5.H5Dcreate(H5fid, "DSREF", - HDF5Constants.H5T_STD_REF_OBJ, H5dsid, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); - assertTrue("testH5OcopyRefsDatasettosameFile.H5Dcreate: ", dataset_id >= 0); - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, - HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); - //Close the dataset. - H5.H5Dclose(dataset_id); + dset_data = new byte[2][HDF5Constants.H5R_REF_BUF_SIZE]; + try { + dset_data[0] = H5.H5Rcreate_object(H5fid, "/G1", HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5OcopyInvalidRef: H5Rcreate_object " + err); + } + + try { + dset_data[1] = H5.H5Rcreate_object(H5fid, "DS2", HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5OcopyInvalidRef: H5Rcreate_object " + err); + } + + try { + //Create a dataset and write object references to it. + dataset_id = H5.H5Dcreate(H5fid, "DSREF", + HDF5Constants.H5T_STD_REF, H5dsid, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5OcopyRefsDatasettosameFile.H5Dcreate: ", dataset_id >= 0); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF, + HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, dset_data); + //Close the dataset. + H5.H5Dclose(dataset_id); + } + catch (Exception ex) { + try {H5.H5Dclose(dataset_id);} catch (Exception exx) {} + fail("testH5OcopyRefsDatasettosameFile: create dataset failed"); + } } catch (Exception ex) { - try {H5.H5Dclose(dataset_id);} catch (Exception exx) {} - fail("testH5OcopyRefsDatasettosameFile: create dataset failed"); + ex.printStackTrace(); + } + finally { + try {H5.H5Rdestroy(dset_data[1]);} catch (Exception ex) {} + try {H5.H5Rdestroy(dset_data[0]);} catch (Exception ex) {} } try { @@ -303,15 +352,13 @@ public class TestH5Ocopy { try { //Read the dataset object references in the read_data buffer. - H5.H5Dread(did, HDF5Constants.H5T_STD_REF_OBJ, HDF5Constants.H5S_ALL,HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, read_data); - System.arraycopy(read_data, 0, rbuf0, 0, 8); - System.arraycopy(read_data, 8, rbuf1, 0, 8); + H5.H5Dread(did, HDF5Constants.H5T_STD_REF, HDF5Constants.H5S_ALL,HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, read_data); //Get the type of object the reference points to. - obj_type = H5.H5Rget_obj_type(H5fid, HDF5Constants.H5R_OBJECT, rbuf1); + obj_type = H5.H5Rget_obj_type(H5fid, HDF5Constants.H5R_OBJECT, read_data[1]); assertEquals(obj_type, HDF5Constants.H5O_TYPE_DATASET); - obj_type = H5.H5Rget_obj_type(H5fid, HDF5Constants.H5R_OBJECT, rbuf0); + obj_type = H5.H5Rget_obj_type(H5fid, HDF5Constants.H5R_OBJECT, read_data[0]); assertEquals(obj_type, HDF5Constants.H5O_TYPE_GROUP); } catch (Exception ex) { @@ -321,43 +368,41 @@ public class TestH5Ocopy { try {H5.H5Dclose(did);} catch (Exception ex) {} try {H5.H5Pclose(ocp_plist_id);} catch (Exception ex) {} } - } - -// @Ignore because of JIRA HDF5-9547 -// @Test(expected = HDF5LibraryException.class) -// public void testH5OcopyInvalidRef() throws Throwable { -// final long _pid_ = HDF5Constants.H5P_DEFAULT; -// long sid = HDF5Constants.H5I_INVALID_HID; -// long did = HDF5Constants.H5I_INVALID_HID; -// long aid = HDF5Constants.H5I_INVALID_HID; -// -// try { -// sid = H5.H5Screate_simple(1, new long[] {1}, null); -// assertTrue("testH5OcopyInvalidRef.H5Screate_simple: ", sid >= 0); -// did = H5.H5Dcreate(H5fid, "Dataset_with_invalid_Ref", HDF5Constants.H5T_NATIVE_INT, sid, _pid_, _pid_, _pid_); -// assertTrue("testH5OcopyInvalidRef.H5Dcreate: ", did > 0); -// aid = H5.H5Acreate(did, "Invalid_Ref", HDF5Constants.H5T_STD_REF_OBJ, sid, _pid_, _pid_); -// assertTrue("testH5OcopyInvalidRef.H5Acreate: ", aid > 0); -// H5.H5Awrite(aid, HDF5Constants.H5T_STD_REF_OBJ, new long[]{-1}); -// } -// catch (Exception ex) { -// ex.printStackTrace(); -// } -// finally { -// try {H5.H5Dclose(did);} catch (Exception exx) {} -// try {H5.H5Aclose(aid);} catch (Exception exx) {} -// try {H5.H5Sclose(sid);} catch (Exception exx) {} -// } -// -// long ocp_plist_id = H5.H5Pcreate(HDF5Constants.H5P_OBJECT_COPY); -// assertTrue("testH5OcopyInvalidRef.H5Pcreate: ", ocp_plist_id >= 0); -// H5.H5Pset_copy_object(ocp_plist_id, HDF5Constants.H5O_COPY_EXPAND_REFERENCE_FLAG); -// try { -// H5.H5Ocopy(H5fid, "/Dataset_with_invalid_Ref", H5fid, "/Dataset_with_invalid_Ref_cp", ocp_plist_id, _pid_); -// } -// finally { -// try {H5.H5Pclose(ocp_plist_id);} catch (Exception exx) {} -// } -// } + } + + @Test + public void testH5OcopyNullRef() throws Throwable { + final long _pid_ = HDF5Constants.H5P_DEFAULT; + long sid = HDF5Constants.H5I_INVALID_HID; + long did = HDF5Constants.H5I_INVALID_HID; + long aid = HDF5Constants.H5I_INVALID_HID; + + try { + sid = H5.H5Screate_simple(1, new long[] {1}, null); + assertTrue("testH5OcopyNullRef.H5Screate_simple: ", sid >= 0); + did = H5.H5Dcreate(H5fid, "Dataset_with_null_Ref", HDF5Constants.H5T_NATIVE_INT, sid, _pid_, _pid_, _pid_); + assertTrue("testH5OcopyNullRef.H5Dcreate: ", did > 0); + aid = H5.H5Acreate(did, "Null_Ref", HDF5Constants.H5T_STD_REF, sid, _pid_, _pid_); + assertTrue("testH5OcopyNullRef.H5Acreate: ", aid > 0); + } + catch (Exception ex) { + ex.printStackTrace(); + } + finally { + try {H5.H5Dclose(did);} catch (Exception exx) {} + try {H5.H5Aclose(aid);} catch (Exception exx) {} + try {H5.H5Sclose(sid);} catch (Exception exx) {} + } + + long ocp_plist_id = H5.H5Pcreate(HDF5Constants.H5P_OBJECT_COPY); + assertTrue("testH5OcopyNullRef.H5Pcreate: ", ocp_plist_id >= 0); + H5.H5Pset_copy_object(ocp_plist_id, HDF5Constants.H5O_COPY_EXPAND_REFERENCE_FLAG); + try { + H5.H5Ocopy(H5fid, "/Dataset_with_null_Ref", H5fid, "/Dataset_with_null_Ref_cp", ocp_plist_id, _pid_); + } + finally { + try {H5.H5Pclose(ocp_plist_id);} catch (Exception exx) {} + } + } } diff --git a/java/test/TestH5OcopyOld.java b/java/test/TestH5OcopyOld.java new file mode 100644 index 0000000..b360cd0 --- /dev/null +++ b/java/test/TestH5OcopyOld.java @@ -0,0 +1,398 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the COPYING file, which can be found at the root of the source code * + * distribution tree, or in https://www.hdfgroup.org/licenses. * + * If you do not have access to either file, you may request a copy from * + * help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +package test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; + +import hdf.hdf5lib.H5; +import hdf.hdf5lib.HDF5Constants; +import hdf.hdf5lib.exceptions.HDF5Exception; +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; + +public class TestH5OcopyOld { + @Rule public TestName testname = new TestName(); + private static final String FILENAME = "testRefsattribute.h5"; + private static final int DIM_X = 4; + private static final int DIM_Y = 6; + long H5fid = HDF5Constants.H5I_INVALID_HID; + long H5dsid = HDF5Constants.H5I_INVALID_HID; + long H5did1 = HDF5Constants.H5I_INVALID_HID; + long H5did2 = HDF5Constants.H5I_INVALID_HID; + long H5gcpl = HDF5Constants.H5I_INVALID_HID; + long H5gid = HDF5Constants.H5I_INVALID_HID; + long H5dsid2 = HDF5Constants.H5I_INVALID_HID; + long[] dims = { 2 }; + + private final void _deleteFile(String filename) { + File file = new File(filename); + + if (file.exists()) { + try { + file.delete(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + + private final long _createDataset(long fid, long dsid, String name, long dapl) { + long did = HDF5Constants.H5I_INVALID_HID; + try { + did = H5.H5Dcreate(fid, name, + HDF5Constants.H5T_STD_I32BE, dsid, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, dapl); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Dcreate: " + err); + } + assertTrue("TestH5O._createDataset: ",did >= 0); + + return did; + } + + private final long _createGroup(long fid, String name) { + long gid = HDF5Constants.H5I_INVALID_HID; + try { + H5gcpl = HDF5Constants.H5P_DEFAULT; + gid = H5.H5Gcreate(fid, name, HDF5Constants.H5P_DEFAULT, + H5gcpl, HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Gcreate: " + err); + } + assertTrue("TestH5O._createGroup: ",gid >= 0); + + return gid; + } + + @Before + public void createH5file() + throws NullPointerException, HDF5Exception { + assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0); + System.out.print(testname.getMethodName()); + try { + H5fid = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + H5dsid2 = H5.H5Screate(HDF5Constants.H5S_SCALAR); + H5did1 = _createDataset(H5fid, H5dsid2, "DS2", HDF5Constants.H5P_DEFAULT); + H5dsid = H5.H5Screate_simple(1, dims, null); + H5gid = _createGroup(H5fid, "/G1"); + H5did2 = _createDataset(H5gid, H5dsid, "DS1", HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); + fail("TestH5O.createH5file: " + err); + } + assertTrue("TestH5O.createH5file: H5.H5Fcreate: ",H5fid >= 0); + assertTrue("TestH5O.createH5file: H5.H5Screate_simple: ",H5dsid >= 0); + assertTrue("TestH5O.createH5file: H5.H5Gcreate: ",H5gid >= 0); + + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + } + + @After + public void deleteH5file() throws HDF5LibraryException { + if (H5gid > 0) + try {H5.H5Gclose(H5gid);} catch (Exception ex) {} + if (H5did2 > 0) + try {H5.H5Dclose(H5did2);} catch (Exception ex) {} + if (H5dsid > 0) + try {H5.H5Sclose(H5dsid);} catch (Exception ex) {} + if (H5dsid2 > 0) + try {H5.H5Sclose(H5dsid2);} catch (Exception ex) {} + if (H5did1 > 0) + try {H5.H5Dclose(H5did1);} catch (Exception ex) {} + if (H5fid > 0) + try {H5.H5Fclose(H5fid);} catch (Exception ex) {} + + _deleteFile(FILENAME); + System.out.println(); + } + + @Test + public void testH5OcopyRefsAttr() { + long ocp_plist_id = HDF5Constants.H5I_INVALID_HID; + byte rbuf0[]=null , rbuf1[] = null; + byte[] dset_data = new byte[16]; + long attribute_id = HDF5Constants.H5I_INVALID_HID; + + + try { + rbuf0 = H5.H5Rcreate(H5fid, "/G1", HDF5Constants.H5R_OBJECT, -1); + rbuf1 = H5.H5Rcreate(H5fid, "DS2", HDF5Constants.H5R_OBJECT, -1); + //System.arraycopy(rbuf0, 0, dset_data, 0, 8); + System.arraycopy(rbuf1, 0, dset_data, 8, 8); + } + catch (Exception ex) { + fail("testH5OcopyRefsAttr: H5Rcreate failed"); + } + + try { + attribute_id = H5.H5Acreate(H5did2, "A1", HDF5Constants.H5T_STD_REF_OBJ, H5dsid, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5OcopyRefsAttr.H5Acreate: ", attribute_id >= 0); + H5.H5Awrite(attribute_id, HDF5Constants.H5T_STD_REF_OBJ, dset_data); + + H5.H5Aclose(attribute_id); + } + catch (Exception ex) { + fail("testH5OcopyRefsAttr: H5Awrite failed"); + } + finally { + try {H5.H5Aclose(attribute_id);} catch (Exception exx) {} + } + + try { + ocp_plist_id = H5.H5Pcreate(HDF5Constants.H5P_OBJECT_COPY); + assertTrue("testH5OcopyRefsAttr.H5Pcreate: ", ocp_plist_id >= 0); + H5.H5Pset_copy_object(ocp_plist_id, HDF5Constants.H5O_COPY_EXPAND_REFERENCE_FLAG); + H5.H5Ocopy(H5fid, ".", H5fid, "CPYREF", ocp_plist_id, HDF5Constants.H5P_DEFAULT); + } + catch (Exception ex) { + fail("testH5OcopyRefsAttr: H5Ocopy failed"); + } + finally { + try {H5.H5Pclose(ocp_plist_id);} catch (Exception ex) {} + } + } + + @Test + public void testH5OcopyRefsDatasettodiffFile() { + byte rbuf1[] = null; + byte[] dset_data = new byte[16]; + long ocp_plist_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long H5fid2 = HDF5Constants.H5I_INVALID_HID; + + try { + rbuf1 = H5.H5Rcreate(H5fid, "DS2", HDF5Constants.H5R_OBJECT, -1); + System.arraycopy(rbuf1, 0, dset_data, 8, 8); + + dataset_id = H5.H5Dcreate(H5fid, "DSREF", + HDF5Constants.H5T_STD_REF_OBJ, H5dsid, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5OcopyRefsDatasettodiffFile.H5Dcreate: ", dataset_id >= 0); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, + HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dclose(dataset_id); + } + catch (Exception ex) { + fail("testH5OcopyRefsDatasettodiffFile: create dataset failed"); + } + finally { + try {H5.H5Dclose(dataset_id);} catch (Exception exx) {} + } + + try { + //create new file + H5fid2 = H5.H5Fcreate("copy.h5", HDF5Constants.H5F_ACC_TRUNC, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5OcopyRefsDatasettodiffFile.H5Fcreate: ", H5fid2 >= 0); + H5.H5Fflush(H5fid2, HDF5Constants.H5F_SCOPE_LOCAL); + } + catch (Exception ex) { + try {H5.H5Fclose(H5fid2);} catch (Exception exx) {} + fail("testH5OcopyRefsDatasettodiffFile: H5Fcreate failed"); + } + + try { + //create object copy property list id and set the flags. + ocp_plist_id = H5.H5Pcreate(HDF5Constants.H5P_OBJECT_COPY); + assertTrue("testH5OcopyRefsDatasettodiffFile.H5Pcreate: ", ocp_plist_id >= 0); + H5.H5Pset_copy_object(ocp_plist_id, HDF5Constants.H5O_COPY_EXPAND_REFERENCE_FLAG); + + //Perform copy function. + H5.H5Ocopy(H5fid, ".", H5fid2, "CPYREFD", ocp_plist_id, HDF5Constants.H5P_DEFAULT); + } + catch (Exception ex){ + ex.printStackTrace(); + fail("testH5OcopyRefsDatasettodiffFile: H5Ocopy failed"); + } + finally { + try {H5.H5Pclose(ocp_plist_id);} catch (Exception ex) {} + try {H5.H5Fclose(H5fid2);} catch (Exception ex) {} + } + _deleteFile("copy.h5"); + } + + @Test + public void testH5OcopyRefsDatasettosameFile() { + byte rbuf0[]=null , rbuf1[] = null; + byte[] dset_data = new byte[16]; + long ocp_plist_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long did = HDF5Constants.H5I_INVALID_HID; + int obj_type = -1; + byte[] read_data = new byte[16]; + + try { + rbuf0 = H5.H5Rcreate(H5fid, "/G1", HDF5Constants.H5R_OBJECT, -1); + rbuf1 = H5.H5Rcreate(H5fid, "DS2", HDF5Constants.H5R_OBJECT, -1); + System.arraycopy(rbuf0, 0, dset_data, 0, 8); + System.arraycopy(rbuf1, 0, dset_data, 8, 8); + + //Create a dataset and write object references to it. + dataset_id = H5.H5Dcreate(H5fid, "DSREF", + HDF5Constants.H5T_STD_REF_OBJ, H5dsid, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + assertTrue("testH5OcopyRefsDatasettosameFile.H5Dcreate: ", dataset_id >= 0); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, + HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, dset_data); + //Close the dataset. + H5.H5Dclose(dataset_id); + } + catch (Exception ex) { + try {H5.H5Dclose(dataset_id);} catch (Exception exx) {} + fail("testH5OcopyRefsDatasettosameFile: create dataset failed"); + } + + try { + ocp_plist_id = H5.H5Pcreate(HDF5Constants.H5P_OBJECT_COPY); + assertTrue("testH5OcopyRefsDatasettosameFile.H5Pcreate: ", ocp_plist_id >= 0); + H5.H5Pset_copy_object(ocp_plist_id, HDF5Constants.H5O_COPY_EXPAND_REFERENCE_FLAG); + } + catch (Exception ex) { + try {H5.H5Pclose(ocp_plist_id);} catch (Exception exx) {} + fail("testH5OcopyRefsDatasettosameFile: H5Pset_copy_object failed"); + } + + //Perform copy function. + try { + H5.H5Ocopy(H5fid, "DSREF", H5fid, "CPYREFD", ocp_plist_id, HDF5Constants.H5P_DEFAULT); + } + catch(Exception ex) { + try {H5.H5Pclose(ocp_plist_id);} catch (Exception exx) {} + fail("testH5OcopyRefsDatasettosameFile: H5Ocopy failed"); + } + + //Open the dataset that has been copied + try { + did = H5.H5Dopen(H5fid, "DSREF", HDF5Constants.H5P_DEFAULT); + assertTrue("testH5OcopyRefsDatasettosameFile.H5Dopen: ", did >= 0); + } + catch (Exception e) { + try {H5.H5Dclose(did);} catch (Exception exx) {} + e.printStackTrace(); + fail("testH5OcopyRefsDatasettosameFile: H5Dopen failed"); + } + + try { + //Read the dataset object references in the read_data buffer. + H5.H5Dread(did, HDF5Constants.H5T_STD_REF_OBJ, HDF5Constants.H5S_ALL,HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, read_data); + System.arraycopy(read_data, 0, rbuf0, 0, 8); + System.arraycopy(read_data, 8, rbuf1, 0, 8); + + //Get the type of object the reference points to. + obj_type = H5.H5Rget_obj_type(H5fid, HDF5Constants.H5R_OBJECT, rbuf1); + assertEquals(obj_type, HDF5Constants.H5O_TYPE_DATASET); + + obj_type = H5.H5Rget_obj_type(H5fid, HDF5Constants.H5R_OBJECT, rbuf0); + assertEquals(obj_type, HDF5Constants.H5O_TYPE_GROUP); + } + catch (Exception ex) { + ex.printStackTrace(); + } + finally { + try {H5.H5Dclose(did);} catch (Exception ex) {} + try {H5.H5Pclose(ocp_plist_id);} catch (Exception ex) {} + } + } + + @Test + public void testH5OcopyNullRef() throws Throwable { + final long _pid_ = HDF5Constants.H5P_DEFAULT; + long sid = HDF5Constants.H5I_INVALID_HID; + long did = HDF5Constants.H5I_INVALID_HID; + long aid = HDF5Constants.H5I_INVALID_HID; + + try { + sid = H5.H5Screate_simple(1, new long[] {1}, null); + assertTrue("testH5OcopyNullRef.H5Screate_simple: ", sid >= 0); + did = H5.H5Dcreate(H5fid, "Dataset_with_null_Ref", HDF5Constants.H5T_NATIVE_INT, sid, _pid_, _pid_, _pid_); + assertTrue("testH5OcopyNullRef.H5Dcreate: ", did > 0); + aid = H5.H5Acreate(did, "Null_Ref", HDF5Constants.H5T_STD_REF_OBJ, sid, _pid_, _pid_); + assertTrue("testH5OcopyNullRef.H5Acreate: ", aid > 0); + } + catch (Exception ex) { + ex.printStackTrace(); + } + finally { + try {H5.H5Dclose(did);} catch (Exception exx) {} + try {H5.H5Aclose(aid);} catch (Exception exx) {} + try {H5.H5Sclose(sid);} catch (Exception exx) {} + } + + long ocp_plist_id = H5.H5Pcreate(HDF5Constants.H5P_OBJECT_COPY); + assertTrue("testH5OcopyNullRef.H5Pcreate: ", ocp_plist_id >= 0); + H5.H5Pset_copy_object(ocp_plist_id, HDF5Constants.H5O_COPY_EXPAND_REFERENCE_FLAG); + try { + H5.H5Ocopy(H5fid, "/Dataset_with_null_Ref", H5fid, "/Dataset_with_null_Ref_cp", ocp_plist_id, _pid_); + } + finally { + try {H5.H5Pclose(ocp_plist_id);} catch (Exception exx) {} + } + } + +// @Ignore because of JIRA HDF5-9547 +// @Test(expected = HDF5LibraryException.class) +// public void testH5OcopyInvalidRef() throws Throwable { +// final long _pid_ = HDF5Constants.H5P_DEFAULT; +// long sid = HDF5Constants.H5I_INVALID_HID; +// long did = HDF5Constants.H5I_INVALID_HID; +// long aid = HDF5Constants.H5I_INVALID_HID; +// +// try { +// sid = H5.H5Screate_simple(1, new long[] {1}, null); +// assertTrue("testH5OcopyInvalidRef.H5Screate_simple: ", sid >= 0); +// did = H5.H5Dcreate(H5fid, "Dataset_with_invalid_Ref", HDF5Constants.H5T_NATIVE_INT, sid, _pid_, _pid_, _pid_); +// assertTrue("testH5OcopyInvalidRef.H5Dcreate: ", did > 0); +// aid = H5.H5Acreate(did, "Invalid_Ref", HDF5Constants.H5T_STD_REF_OBJ, sid, _pid_, _pid_); +// assertTrue("testH5OcopyInvalidRef.H5Acreate: ", aid > 0); +// H5.H5Awrite(aid, HDF5Constants.H5T_STD_REF_OBJ, new long[]{-1}); +// } +// catch (Exception ex) { +// ex.printStackTrace(); +// } +// finally { +// try {H5.H5Dclose(did);} catch (Exception exx) {} +// try {H5.H5Aclose(aid);} catch (Exception exx) {} +// try {H5.H5Sclose(sid);} catch (Exception exx) {} +// } +// +// long ocp_plist_id = H5.H5Pcreate(HDF5Constants.H5P_OBJECT_COPY); +// assertTrue("testH5OcopyInvalidRef.H5Pcreate: ", ocp_plist_id >= 0); +// H5.H5Pset_copy_object(ocp_plist_id, HDF5Constants.H5O_COPY_EXPAND_REFERENCE_FLAG); +// try { +// H5.H5Ocopy(H5fid, "/Dataset_with_invalid_Ref", H5fid, "/Dataset_with_invalid_Ref_cp", ocp_plist_id, _pid_); +// } +// finally { +// try {H5.H5Pclose(ocp_plist_id);} catch (Exception exx) {} +// } +// } + +} diff --git a/java/test/junit.sh.in b/java/test/junit.sh.in index 39db296..e096302 100644 --- a/java/test/junit.sh.in +++ b/java/test/junit.sh.in @@ -108,6 +108,7 @@ $HDFTEST_HOME/testfiles/JUnit-TestH5Arw.txt $HDFTEST_HOME/testfiles/JUnit-TestH5Oparams.txt $HDFTEST_HOME/testfiles/JUnit-TestH5Obasic.txt $HDFTEST_HOME/testfiles/JUnit-TestH5Ocreate.txt +$HDFTEST_HOME/testfiles/JUnit-TestH5OcopyOld.txt $HDFTEST_HOME/testfiles/JUnit-TestH5Ocopy.txt $HDFTEST_HOME/testfiles/JUnit-TestH5PL.txt $HDFTEST_HOME/testfiles/JUnit-TestH5VL.txt @@ -1030,6 +1031,27 @@ else test yes = "$verbose" && $DIFF JUnit-TestH5Ocreate.txt JUnit-TestH5Ocreate.out |sed 's/^/ /' fi +echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH -ea org.junit.runner.JUnitCore test.TestH5OcopyOld" +TESTING JUnit-TestH5OcopyOld +($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH -ea org.junit.runner.JUnitCore test.TestH5OcopyOld > JUnit-TestH5OcopyOld.ext) + +# Extract file name, line number, version and thread IDs because they may be different +sed -e 's/thread [0-9]*/thread (IDs)/' -e 's/: .*\.c /: (file name) /' \ + -e 's/line [0-9]*/line (number)/' \ + -e 's/Time: [0-9]*[\.,[0-9]*]*/Time: XXXX/' \ + -e 's/v[1-9]*\.[0-9]*\./version (number)\./' \ + -e 's/[1-9]*\.[0-9]*\.[0-9]*[^)]*/version (number)/' \ + JUnit-TestH5OcopyOld.ext > JUnit-TestH5OcopyOld.out + +if diff JUnit-TestH5OcopyOld.out JUnit-TestH5OcopyOld.txt > /dev/null; then + echo " PASSED JUnit-TestH5OcopyOld" +else + echo "**FAILED** JUnit-TestH5OcopyOld" + echo " Expected result differs from actual result" + nerrors="`expr $nerrors + 1`" + test yes = "$verbose" && $DIFF JUnit-TestH5OcopyOld.txt JUnit-TestH5OcopyOld.out |sed 's/^/ /' +fi + echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH -ea org.junit.runner.JUnitCore test.TestH5Ocopy" TESTING JUnit-TestH5Ocopy ($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH -ea org.junit.runner.JUnitCore test.TestH5Ocopy > JUnit-TestH5Ocopy.ext) diff --git a/java/test/testfiles/JUnit-TestH5Ocopy.txt b/java/test/testfiles/JUnit-TestH5Ocopy.txt index 32dfde7..7f66410 100644 --- a/java/test/testfiles/JUnit-TestH5Ocopy.txt +++ b/java/test/testfiles/JUnit-TestH5Ocopy.txt @@ -1,9 +1,10 @@ JUnit version 4.11 .testH5OcopyRefsDatasettosameFile +.testH5OcopyNullRef .testH5OcopyRefsDatasettodiffFile .testH5OcopyRefsAttr Time: XXXX -OK (3 tests) +OK (4 tests) diff --git a/java/test/testfiles/JUnit-TestH5OcopyOld.txt b/java/test/testfiles/JUnit-TestH5OcopyOld.txt new file mode 100644 index 0000000..7f66410 --- /dev/null +++ b/java/test/testfiles/JUnit-TestH5OcopyOld.txt @@ -0,0 +1,10 @@ +JUnit version 4.11 +.testH5OcopyRefsDatasettosameFile +.testH5OcopyNullRef +.testH5OcopyRefsDatasettodiffFile +.testH5OcopyRefsAttr + +Time: XXXX + +OK (4 tests) + |