diff options
author | Quincey Koziol <koziol@koziol.gov> | 2019-04-14 03:58:16 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@koziol.gov> | 2019-04-14 03:58:16 (GMT) |
commit | d7e1464058515d07b838741f65a77977224814de (patch) | |
tree | c25d0985895862053d6b9d1eb1fce4fa94d471e3 /java | |
parent | 4918d443bb2f8406c3be9882a7945853c84760f6 (diff) | |
download | hdf5-d7e1464058515d07b838741f65a77977224814de.zip hdf5-d7e1464058515d07b838741f65a77977224814de.tar.gz hdf5-d7e1464058515d07b838741f65a77977224814de.tar.bz2 |
Add C++, Java, and FORTRAN wrappers and tests for H5Fget_fileno
Diffstat (limited to 'java')
-rw-r--r-- | java/src/hdf/hdf5lib/H5.java | 13 | ||||
-rw-r--r-- | java/src/jni/h5fImp.c | 20 | ||||
-rw-r--r-- | java/src/jni/h5fImp.h | 9 | ||||
-rw-r--r-- | java/test/TestH5F.java | 130 | ||||
-rw-r--r-- | java/test/testfiles/JUnit-TestH5F.txt | 4 |
5 files changed, 175 insertions, 1 deletions
diff --git a/java/src/hdf/hdf5lib/H5.java b/java/src/hdf/hdf5lib/H5.java index d107ad8..e874732 100644 --- a/java/src/hdf/hdf5lib/H5.java +++ b/java/src/hdf/hdf5lib/H5.java @@ -2968,6 +2968,19 @@ public class H5 implements java.io.Serializable { public synchronized static native int H5Fget_intent(long file_id) throws HDF5LibraryException; /** + * H5Fget_fileno retrieves the "file number" for an open file. + * + * @param file_id + * IN: File identifier for a currently-open HDF5 file + * + * @return the unique file number for the file. + * + * @exception HDF5LibraryException + * - Error from the HDF-5 Library. + **/ + public synchronized static native long H5Fget_fileno(long file_id) throws HDF5LibraryException; + + /** * H5Fget_mdc_hit_rate queries the metadata cache of the target file to obtain its hit rate (cache hits / (cache * hits + cache misses)) since the last time hit rate statistics were reset. * diff --git a/java/src/jni/h5fImp.c b/java/src/jni/h5fImp.c index d145c6a..26c1d17 100644 --- a/java/src/jni/h5fImp.c +++ b/java/src/jni/h5fImp.c @@ -275,6 +275,26 @@ done: /* * Class: hdf_hdf5lib_H5 + * Method: H5Fget_fileno + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Fget_1fileno + (JNIEnv *env, jclass cls, jlong file_id) +{ + unsigned long fileno = 0; + + UNUSED(cls); + + if (H5Fget_intent((hid_t)file_id, &fileno) < 0) + H5_LIBRARY_ERROR(ENVONLY); + +done: + return (jlong)fileno; +} /* end Java_hdf_hdf5lib_H5_H5Fget_1intent */ + +/* + * Class: hdf_hdf5lib_H5 * Method: H5Fclose * Signature: (J)I */ diff --git a/java/src/jni/h5fImp.h b/java/src/jni/h5fImp.h index 410a249..fc02c76 100644 --- a/java/src/jni/h5fImp.h +++ b/java/src/jni/h5fImp.h @@ -104,6 +104,15 @@ Java_hdf_hdf5lib_H5_H5Fget_1intent /* * Class: hdf_hdf5lib_H5 + * Method: H5Fget_fileno + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL +Java_hdf_hdf5lib_H5_H5Fget_1fileno + (JNIEnv*, jclass, jlong); + +/* + * Class: hdf_hdf5lib_H5 * Method: H5Fclose * Signature: (J)I */ diff --git a/java/test/TestH5F.java b/java/test/TestH5F.java index e4f9a30..a86fddb 100644 --- a/java/test/TestH5F.java +++ b/java/test/TestH5F.java @@ -14,6 +14,7 @@ package test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -32,6 +33,7 @@ import org.junit.rules.TestName; public class TestH5F { @Rule public TestName testname = new TestName(); private static final String H5_FILE = "testF.h5"; + private static final String H5_FILE2 = "testF2.h5"; private static final int COUNT_OBJ_FILE = 1; private static final int COUNT_OBJ_DATASET = 0; @@ -48,6 +50,7 @@ public class TestH5F { HDF5Constants.H5F_OBJ_DATATYPE, HDF5Constants.H5F_OBJ_ATTR, HDF5Constants.H5F_OBJ_ALL }; long H5fid = -1; + long H5fid2 = -1; private final void _deleteFile(String filename) { File file = new File(filename); @@ -66,6 +69,10 @@ public class TestH5F { H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + + H5fid2 = H5.H5Fcreate(H5_FILE2, HDF5Constants.H5F_ACC_TRUNC, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + H5.H5Fflush(H5fid2, HDF5Constants.H5F_SCOPE_LOCAL); } @After @@ -74,7 +81,12 @@ public class TestH5F { try {H5.H5Fclose(H5fid);} catch (Exception ex) {} H5fid = -1; } + if (H5fid2 > 0) { + try {H5.H5Fclose(H5fid2);} catch (Exception ex) {} + H5fid2 = -1; + } _deleteFile(H5_FILE); + _deleteFile(H5_FILE2); System.out.println(); } @@ -223,6 +235,124 @@ public class TestH5F { } @Test + public void testH5Fget_fileno_same() { + long fileno1 = 0; + long fileno2 = 0; + long fid1 = -1; + long fid2 = -1; + + if (H5fid > 0) { + try {H5.H5Fclose(H5fid);} catch (Exception ex) {} + H5fid = -1; + } + + try { + fid1 = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR, + HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + fail("H5.H5Fopen: " + err); + } + + try { + fid2 = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR, + HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + fail("H5.H5Fopen: " + err); + } + + try { + fileno1 = H5.H5Fget_fileno(fid1); + } + catch (Throwable err) { + fail("H5.H5Fget_fileno: " + err); + } + + try { + fileno2 = H5.H5Fget_fileno(fid2); + } + catch (Throwable err) { + fail("H5.H5Fget_fileno: " + err); + } + + assertEquals(fileno1, fileno2); + + try { + H5.H5Fclose(fid1); + } + catch (Exception ex) { + } + + try { + H5.H5Fclose(fid2); + } + catch (Exception ex) { + } + } + + @Test + public void testH5Fget_fileno_diff() { + long fileno1 = 0; + long fileno2 = 0; + long fid1 = -1; + long fid2 = -1; + + if (H5fid > 0) { + try {H5.H5Fclose(H5fid);} catch (Exception ex) {} + H5fid = -1; + } + if (H5fid2 > 0) { + try {H5.H5Fclose(H5fid2);} catch (Exception ex) {} + H5fid2 = -1; + } + + try { + fid1 = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR, + HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + fail("H5.H5Fopen: " + err); + } + + try { + fid2 = H5.H5Fopen(H5_FILE2, HDF5Constants.H5F_ACC_RDWR, + HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + fail("H5.H5Fopen: " + err); + } + + try { + fileno1 = H5.H5Fget_fileno(fid1); + } + catch (Throwable err) { + fail("H5.H5Fget_fileno: " + err); + } + + try { + fileno2 = H5.H5Fget_fileno(fid2); + } + catch (Throwable err) { + fail("H5.H5Fget_fileno: " + err); + } + + assertNotEquals(fileno1, fileno2); + + try { + H5.H5Fclose(fid1); + } + catch (Exception ex) { + } + + try { + H5.H5Fclose(fid2); + } + catch (Exception ex) { + } + } + + @Test public void testH5Fget_obj_count() { long count = -1; diff --git a/java/test/testfiles/JUnit-TestH5F.txt b/java/test/testfiles/JUnit-TestH5F.txt index 16a423e..791e82d 100644 --- a/java/test/testfiles/JUnit-TestH5F.txt +++ b/java/test/testfiles/JUnit-TestH5F.txt @@ -7,8 +7,10 @@ JUnit version 4.11 .testH5Fget_intent_rdonly .testH5Fget_create_plist .testH5Fget_obj_count +.testH5Fget_fileno_same +.testH5Fget_fileno_diff Time: XXXX -OK (8 tests) +OK (10 tests) |