summaryrefslogtreecommitdiffstats
path: root/java/test/TestH5F.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/test/TestH5F.java')
-rw-r--r--java/test/TestH5F.java110
1 files changed, 62 insertions, 48 deletions
diff --git a/java/test/TestH5F.java b/java/test/TestH5F.java
index e4f9a30..869b45c 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;
@@ -94,28 +96,12 @@ public class TestH5F {
@Test(expected = HDF5LibraryException.class)
public void testH5Fget_create_plist_closed() throws Throwable {
- long fid = -1;
-
if (H5fid > 0) {
try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
- H5fid = -1;
- }
-
- try {
- fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR,
- HDF5Constants.H5P_DEFAULT);
- }
- catch (Throwable err) {
- fail("H5.H5Fopen: " + err);
- }
- try {
- H5.H5Fclose(fid);
- }
- catch (Exception ex) {
}
// it should fail because the file was closed.
- H5.H5Fget_create_plist(fid);
+ H5.H5Fget_create_plist(H5fid);
}
@Test
@@ -134,34 +120,17 @@ public class TestH5F {
@Test(expected = HDF5LibraryException.class)
public void testH5Fget_access_plist_closed() throws Throwable {
- long fid = -1;
-
if (H5fid > 0) {
try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
- H5fid = -1;
- }
-
- try {
- fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR,
- HDF5Constants.H5P_DEFAULT);
- }
- catch (Throwable err) {
- fail("H5.H5Fopen: " + err);
- }
- try {
- H5.H5Fclose(fid);
- }
- catch (Exception ex) {
}
// it should fail because the file was closed.
- H5.H5Fget_access_plist(fid);
+ H5.H5Fget_access_plist(H5fid);
}
@Test
public void testH5Fget_intent_rdwr() {
int intent = 0;
- long fid = -1;
if (H5fid > 0) {
try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
@@ -169,31 +138,24 @@ public class TestH5F {
}
try {
- fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR,
+ H5fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR,
HDF5Constants.H5P_DEFAULT);
}
catch (Throwable err) {
fail("H5.H5Fopen: " + err);
}
try {
- intent = H5.H5Fget_intent(fid);
+ intent = H5.H5Fget_intent(H5fid);
}
catch (Throwable err) {
fail("H5.H5Fget_intent: " + err);
}
assertEquals(HDF5Constants.H5F_ACC_RDWR, intent);
-
- try {
- H5.H5Fclose(fid);
- }
- catch (Exception ex) {
- }
}
@Test
public void testH5Fget_intent_rdonly() {
int intent = 0;
- long fid = -1;
if (H5fid > 0) {
try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
@@ -201,24 +163,76 @@ public class TestH5F {
}
try {
- fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDONLY,
+ H5fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDONLY,
HDF5Constants.H5P_DEFAULT);
}
catch (Throwable err) {
fail("H5.H5Fopen: " + err);
}
try {
- intent = H5.H5Fget_intent(fid);
+ intent = H5.H5Fget_intent(H5fid);
}
catch (Throwable err) {
fail("H5.H5Fget_intent: " + err);
}
assertEquals(HDF5Constants.H5F_ACC_RDONLY, intent);
+ }
+
+ @Test
+ public void testH5Fget_fileno_same() {
+ long fileno1 = 0;
+ long fileno2 = 0;
+ long fid1 = -1;
+ long fid2 = -1;
try {
- H5.H5Fclose(fid);
+ fid1 = H5.H5Fcreate(H5_FILE2, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(fid1, HDF5Constants.H5F_SCOPE_LOCAL);
+ assertTrue("H5Fcreate failed", fid1 > 0);
+ fid2 = H5.H5Fopen(H5_FILE2, HDF5Constants.H5F_ACC_RDWR,
+ HDF5Constants.H5P_DEFAULT);
+ assertTrue("H5Fopen failed", fid2 > 0);
+ fileno1 = H5.H5Fget_fileno(fid1);
+ assertTrue("H5Fget_fileno1="+fileno1, fileno1 > 0);
+ fileno2 = H5.H5Fget_fileno(fid2);
+ assertTrue("H5Fget_fileno2="+fileno2, fileno2 > 0);
+
+ assertEquals("fileno1["+fileno1+"]!=fileno2["+fileno2+"]", fileno1, fileno2);
+ }
+ catch (Throwable err) {
+ fail("testH5Fget_fileno_same: " + err);
+ }
+ finally {
+ H5.H5Fclose(fid1);
+ H5.H5Fclose(fid2);
+ }
+ }
+
+ @Test
+ public void testH5Fget_fileno_diff() {
+ long fileno1 = 0;
+ long fileno2 = 0;
+ long fid2 = -1;
+
+ try {
+ fid2 = H5.H5Fcreate(H5_FILE2, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(fid2, HDF5Constants.H5F_SCOPE_LOCAL);
+ assertTrue("H5Fcreate failed", fid2 > 0);
+
+ fileno1 = H5.H5Fget_fileno(H5fid);
+ assertTrue("H5Fget_fileno1="+fileno1, fileno1 > 0);
+ fileno2 = H5.H5Fget_fileno(fid2);
+ assertTrue("H5Fget_fileno2="+fileno2, fileno2 > 0);
+
+ assertNotEquals("fileno1["+fileno1+"]==fileno2["+fileno2+"]", fileno1, fileno2);
+ }
+ catch (Throwable err) {
+ fail("testH5Fget_fileno_diff: " + err);
}
- catch (Exception ex) {
+ finally {
+ H5.H5Fclose(fid2);
}
}