diff options
Diffstat (limited to 'java/test/TestH5S.java')
-rw-r--r-- | java/test/TestH5S.java | 313 |
1 files changed, 193 insertions, 120 deletions
diff --git a/java/test/TestH5S.java b/java/test/TestH5S.java index 7eeed7a..6e081a6 100644 --- a/java/test/TestH5S.java +++ b/java/test/TestH5S.java @@ -12,10 +12,10 @@ package test; - import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; + import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; import hdf.hdf5lib.exceptions.HDF5Exception; @@ -28,16 +28,17 @@ import org.junit.Test; import org.junit.rules.TestName; public class TestH5S { - @Rule public TestName testname = new TestName(); - long H5sid = HDF5Constants.H5I_INVALID_HID; - int H5rank = 2; - long H5dims[] = {5, 5}; - long H5maxdims[] = {10, 10}; + @Rule + public TestName testname = new TestName(); + long H5sid = HDF5Constants.H5I_INVALID_HID; + int H5rank = 2; + long H5dims[] = {5, 5}; + long H5maxdims[] = {10, 10}; @Before - public void createH5file() - throws NullPointerException, HDF5Exception { - assertTrue("H5 open ids is 0", H5.getOpenIDCount()==0); + public void createH5file() throws NullPointerException, HDF5Exception + { + assertTrue("H5 open ids is 0", H5.getOpenIDCount() == 0); System.out.print(testname.getMethodName()); H5sid = H5.H5Screate_simple(H5rank, H5dims, H5maxdims); @@ -45,15 +46,21 @@ public class TestH5S { } @After - public void deleteH5file() throws HDF5LibraryException { + public void deleteH5file() throws HDF5LibraryException + { if (H5sid > 0) { - try {H5.H5Sclose(H5sid);} catch (Exception ex) {} + try { + H5.H5Sclose(H5sid); + } + catch (Exception ex) { + } } System.out.println(); } @Test - public void testH5Sget_simple_extent_ndims() { + public void testH5Sget_simple_extent_ndims() + { int read_rank = -1; try { read_rank = H5.H5Sget_simple_extent_ndims(H5sid); @@ -66,7 +73,8 @@ public class TestH5S { } @Test - public void testH5Sget_simple_extent_dims_null() { + public void testH5Sget_simple_extent_dims_null() + { int read_rank = -1; try { @@ -80,9 +88,10 @@ public class TestH5S { } @Test - public void testH5Sget_simple_extent_dims() { - int read_rank = -1; - long dims[] = {5, 5}; + public void testH5Sget_simple_extent_dims() + { + int read_rank = -1; + long dims[] = {5, 5}; long maxdims[] = {10, 10}; try { @@ -98,11 +107,12 @@ public class TestH5S { } @Test - public void testH5Sget_simple_extent_npoints() { + public void testH5Sget_simple_extent_npoints() + { long num_elements = -1; try { num_elements = H5.H5Sget_simple_extent_npoints(H5sid); - assertTrue("H5.H5Sget_simple_extent_npoints", (H5dims[0]*H5dims[1]) == num_elements); + assertTrue("H5.H5Sget_simple_extent_npoints", (H5dims[0] * H5dims[1]) == num_elements); } catch (Throwable err) { err.printStackTrace(); @@ -111,7 +121,8 @@ public class TestH5S { } @Test - public void testH5Sget_simple_extent_type() { + public void testH5Sget_simple_extent_type() + { int read_type = -1; try { read_type = H5.H5Sget_simple_extent_type(H5sid); @@ -124,7 +135,8 @@ public class TestH5S { } @Test - public void testH5Sis_simple() { + public void testH5Sis_simple() + { boolean result = false; try { @@ -138,12 +150,13 @@ public class TestH5S { } @Test - public void testH5Sset_extent_simple() { + public void testH5Sset_extent_simple() + { long num_elements = -1; try { H5.H5Sset_extent_simple(H5sid, H5rank, H5maxdims, H5maxdims); num_elements = H5.H5Sget_simple_extent_npoints(H5sid); - assertTrue("H5.H5Sget_simple_extent_npoints", (H5maxdims[0]*H5maxdims[1]) == num_elements); + assertTrue("H5.H5Sget_simple_extent_npoints", (H5maxdims[0] * H5maxdims[1]) == num_elements); } catch (Throwable err) { err.printStackTrace(); @@ -152,7 +165,8 @@ public class TestH5S { } @Test - public void testH5Sget_select_type() { + public void testH5Sget_select_type() + { int read_type = -1; try { read_type = H5.H5Sget_select_type(H5sid); @@ -165,12 +179,13 @@ public class TestH5S { } @Test - public void testH5Sset_extent_none() { + public void testH5Sset_extent_none() + { int read_type = -1; try { H5.H5Sset_extent_none(H5sid); read_type = H5.H5Sget_simple_extent_type(H5sid); - assertTrue("H5.H5Sget_simple_extent_type: "+read_type, HDF5Constants.H5S_NULL == read_type); + assertTrue("H5.H5Sget_simple_extent_type: " + read_type, HDF5Constants.H5S_NULL == read_type); } catch (Throwable err) { err.printStackTrace(); @@ -179,8 +194,9 @@ public class TestH5S { } @Test - public void testH5Scopy() { - long sid = HDF5Constants.H5I_INVALID_HID; + public void testH5Scopy() + { + long sid = HDF5Constants.H5I_INVALID_HID; int read_rank = -1; try { @@ -194,13 +210,18 @@ public class TestH5S { fail("H5.H5Scopy: " + err); } finally { - try {H5.H5Sclose(sid);} catch (Exception ex) {} + try { + H5.H5Sclose(sid); + } + catch (Exception ex) { + } } } @Test - public void testH5Sextent_copy() { - long sid = HDF5Constants.H5I_INVALID_HID; + public void testH5Sextent_copy() + { + long sid = HDF5Constants.H5I_INVALID_HID; int class_type = -1; try { @@ -215,18 +236,23 @@ public class TestH5S { fail("H5.H5Sextent_copy: " + err); } finally { - try {H5.H5Sclose(sid);} catch (Exception ex) {} + try { + H5.H5Sclose(sid); + } + catch (Exception ex) { + } } } @Test - public void testH5Sextent_equal() { - long sid = HDF5Constants.H5I_INVALID_HID; + public void testH5Sextent_equal() + { + long sid = HDF5Constants.H5I_INVALID_HID; boolean result = false; try { sid = H5.H5Screate(HDF5Constants.H5S_NULL); - assertTrue("H5.H5Screate_null",sid > 0); + assertTrue("H5.H5Screate_null", sid > 0); } catch (Throwable err) { err.printStackTrace(); @@ -235,7 +261,7 @@ public class TestH5S { try { result = H5.H5Sextent_equal(sid, H5sid); - assertFalse("H5.testH5Sextent_equal",result); + assertFalse("H5.testH5Sextent_equal", result); H5.H5Sextent_copy(sid, H5sid); result = H5.H5Sextent_equal(sid, H5sid); assertTrue("H5.testH5Sextent_equal", result); @@ -245,16 +271,21 @@ public class TestH5S { fail("H5.H5Sextent_copy " + err); } finally { - try {H5.H5Sclose(sid);} catch (Exception ex) {} + try { + H5.H5Sclose(sid); + } + catch (Exception ex) { + } } } @Test - public void testH5Sencode_decode_null_dataspace() { - long sid = HDF5Constants.H5I_INVALID_HID; + public void testH5Sencode_decode_null_dataspace() + { + long sid = HDF5Constants.H5I_INVALID_HID; long decoded_sid = HDF5Constants.H5I_INVALID_HID; byte[] null_sbuf = null; - boolean result = false; + boolean result = false; try { sid = H5.H5Screate(HDF5Constants.H5S_NULL); @@ -267,21 +298,25 @@ public class TestH5S { try { null_sbuf = H5.H5Sencode(sid); - assertFalse("H5.testH5Sencode", null_sbuf==null); + assertFalse("H5.testH5Sencode", null_sbuf == null); } catch (Throwable err) { err.printStackTrace(); fail("H5.H5Sencode " + err); } finally { - if(null_sbuf == null) { - try {H5.H5Sclose(sid);} catch (Exception ex) {} + if (null_sbuf == null) { + try { + H5.H5Sclose(sid); + } + catch (Exception ex) { + } } } try { decoded_sid = H5.H5Sdecode(null_sbuf); - assertTrue("H5.testH5Sdecode", decoded_sid>0); + assertTrue("H5.testH5Sdecode", decoded_sid > 0); result = H5.H5Sextent_equal(sid, decoded_sid); assertTrue("H5.testH5Sextent_equal", result); @@ -291,19 +326,28 @@ public class TestH5S { fail("H5.H5Sdecode " + err); } finally { - try {H5.H5Sclose(decoded_sid);} catch (Exception ex) {} - try {H5.H5Sclose(sid);} catch (Exception ex) {} + try { + H5.H5Sclose(decoded_sid); + } + catch (Exception ex) { + } + try { + H5.H5Sclose(sid); + } + catch (Exception ex) { + } } } @Test - public void testH5Sencode_decode_scalar_dataspace() { - long sid = HDF5Constants.H5I_INVALID_HID; - long decoded_sid = HDF5Constants.H5I_INVALID_HID; + public void testH5Sencode_decode_scalar_dataspace() + { + long sid = HDF5Constants.H5I_INVALID_HID; + long decoded_sid = HDF5Constants.H5I_INVALID_HID; byte[] scalar_sbuf = null; - boolean result = false; - int iresult = -1; - long lresult = -1; + boolean result = false; + int iresult = -1; + long lresult = -1; try { sid = H5.H5Screate(HDF5Constants.H5S_SCALAR); @@ -316,52 +360,65 @@ public class TestH5S { try { scalar_sbuf = H5.H5Sencode(sid); - assertFalse("H5.testH5Sencode", scalar_sbuf==null); + assertFalse("H5.testH5Sencode", scalar_sbuf == null); } catch (Throwable err) { err.printStackTrace(); fail("H5.H5Sencode " + err); } finally { - if(scalar_sbuf == null) { - try {H5.H5Sclose(sid);} catch (Exception ex) {} + if (scalar_sbuf == null) { + try { + H5.H5Sclose(sid); + } + catch (Exception ex) { + } } } try { decoded_sid = H5.H5Sdecode(scalar_sbuf); - assertTrue("H5.testH5Sdecode", decoded_sid>0); + assertTrue("H5.testH5Sdecode", decoded_sid > 0); result = H5.H5Sextent_equal(sid, decoded_sid); assertTrue("H5.testH5Sextent_equal", result); /* Verify decoded dataspace */ lresult = H5.H5Sget_simple_extent_npoints(decoded_sid); - assertTrue("H5.testH5Sget_simple_extent_npoints", lresult==1); + assertTrue("H5.testH5Sget_simple_extent_npoints", lresult == 1); iresult = H5.H5Sget_simple_extent_ndims(decoded_sid); - assertTrue("H5.testH5Sget_simple_extent_ndims", iresult==0); + assertTrue("H5.testH5Sget_simple_extent_ndims", iresult == 0); } catch (Throwable err) { err.printStackTrace(); fail("H5.H5Sdecode " + err); } finally { - try {H5.H5Sclose(decoded_sid);} catch (Exception ex) {} - try {H5.H5Sclose(sid);} catch (Exception ex) {} + try { + H5.H5Sclose(decoded_sid); + } + catch (Exception ex) { + } + try { + H5.H5Sclose(sid); + } + catch (Exception ex) { + } } } @Test - public void testH5Sselect_none() { + public void testH5Sselect_none() + { int read_type = -1; try { H5.H5Sselect_none(H5sid); read_type = H5.H5Sget_select_type(H5sid); - assertTrue("H5.H5Sget_select_type: "+read_type, HDF5Constants.H5S_SEL_NONE == read_type); + assertTrue("H5.H5Sget_select_type: " + read_type, HDF5Constants.H5S_SEL_NONE == read_type); H5.H5Sselect_all(H5sid); read_type = H5.H5Sget_select_type(H5sid); - assertTrue("H5.H5Sget_select_type: "+read_type, HDF5Constants.H5S_SEL_ALL == read_type); + assertTrue("H5.H5Sget_select_type: " + read_type, HDF5Constants.H5S_SEL_ALL == read_type); } catch (Throwable err) { err.printStackTrace(); @@ -370,13 +427,14 @@ public class TestH5S { } @Test - public void testH5Sget_select_npoints() { - long coord[][] = {{0,1},{2,4},{5,6}}; /* Coordinates for point selection */ + public void testH5Sget_select_npoints() + { + long coord[][] = {{0, 1}, {2, 4}, {5, 6}}; /* Coordinates for point selection */ long num_elements = -1; try { H5.H5Sselect_elements(H5sid, HDF5Constants.H5S_SELECT_SET, 3, coord); num_elements = H5.H5Sget_select_npoints(H5sid); - assertTrue("H5.H5Sget_select_npoints: "+num_elements, 3 == num_elements); + assertTrue("H5.H5Sget_select_npoints: " + num_elements, 3 == num_elements); } catch (Throwable err) { err.printStackTrace(); @@ -385,9 +443,10 @@ public class TestH5S { } @Test(expected = IllegalArgumentException.class) - public void testH5Sget_select_elem_pointlist_invalid() throws Throwable { - long coord[][] = {{0,1},{2,4},{5,6}}; /* Coordinates for point selection */ - long getcoord[] = {-1,-1}; /* Coordinates for get point selection */ + public void testH5Sget_select_elem_pointlist_invalid() throws Throwable + { + long coord[][] = {{0, 1}, {2, 4}, {5, 6}}; /* Coordinates for point selection */ + long getcoord[] = {-1, -1}; /* Coordinates for get point selection */ try { H5.H5Sselect_elements(H5sid, HDF5Constants.H5S_SELECT_SET, 3, coord); } @@ -399,9 +458,10 @@ public class TestH5S { } @Test - public void testH5Sget_select_elem_pointlist() { - long coord[][] = {{0,1},{2,3},{4,5}}; /* Coordinates for point selection */ - long getcoord[] = {-1,-1,-1,-1,-1,-1}; /* Coordinates for get point selection */ + public void testH5Sget_select_elem_pointlist() + { + long coord[][] = {{0, 1}, {2, 3}, {4, 5}}; /* Coordinates for point selection */ + long getcoord[] = {-1, -1, -1, -1, -1, -1}; /* Coordinates for get point selection */ try { H5.H5Sselect_elements(H5sid, HDF5Constants.H5S_SELECT_SET, 3, coord); H5.H5Sget_select_elem_pointlist(H5sid, 0, 3, getcoord); @@ -419,15 +479,16 @@ public class TestH5S { } @Test - public void testH5Sget_select_bounds() { - long lowbounds[] = {-1,-1}; - long hibounds[] = {-1,-1}; + public void testH5Sget_select_bounds() + { + long lowbounds[] = {-1, -1}; + long hibounds[] = {-1, -1}; try { H5.H5Sget_select_bounds(H5sid, lowbounds, hibounds); assertTrue("H5.H5Sget_select_bounds", 0 == lowbounds[0]); assertTrue("H5.H5Sget_select_bounds", 0 == lowbounds[1]); - assertTrue("H5.H5Sget_select_bounds", (H5dims[0]-1) == hibounds[0]); - assertTrue("H5.H5Sget_select_bounds", (H5dims[1]-1) == hibounds[1]); + assertTrue("H5.H5Sget_select_bounds", (H5dims[0] - 1) == hibounds[0]); + assertTrue("H5.H5Sget_select_bounds", (H5dims[1] - 1) == hibounds[1]); } catch (Throwable err) { err.printStackTrace(); @@ -436,30 +497,31 @@ public class TestH5S { } @Test - public void testH5Soffset_simple() { - long coord[][] = {{2,2},{2,4},{4,2},{4,4}}; /* Coordinates for point selection */ - long lowbounds[] = {-1,-1}; - long hibounds[] = {-1,-1}; + public void testH5Soffset_simple() + { + long coord[][] = {{2, 2}, {2, 4}, {4, 2}, {4, 4}}; /* Coordinates for point selection */ + long lowbounds[] = {-1, -1}; + long hibounds[] = {-1, -1}; try { H5.H5Sselect_elements(H5sid, HDF5Constants.H5S_SELECT_SET, 4, coord); H5.H5Sget_select_bounds(H5sid, lowbounds, hibounds); assertTrue("H5.H5Sget_select_bounds", 2 == lowbounds[0]); assertTrue("H5.H5Sget_select_bounds", 2 == lowbounds[1]); - assertTrue("H5.H5Sget_select_bounds", (H5dims[0]-1) == hibounds[0]); - assertTrue("H5.H5Sget_select_bounds", (H5dims[1]-1) == hibounds[1]); + assertTrue("H5.H5Sget_select_bounds", (H5dims[0] - 1) == hibounds[0]); + assertTrue("H5.H5Sget_select_bounds", (H5dims[1] - 1) == hibounds[1]); } catch (Throwable err) { err.printStackTrace(); fail("H5.H5Sget_select_bounds: " + err); } try { - long offset[] = {-1,-1}; + long offset[] = {-1, -1}; H5.H5Soffset_simple(H5sid, offset); H5.H5Sget_select_bounds(H5sid, lowbounds, hibounds); assertTrue("H5.H5Sget_select_bounds", 1 == lowbounds[0]); assertTrue("H5.H5Sget_select_bounds", 1 == lowbounds[1]); - assertTrue("H5.H5Sget_select_bounds", (H5dims[0]-2) == hibounds[0]); - assertTrue("H5.H5Sget_select_bounds", (H5dims[1]-2) == hibounds[1]); + assertTrue("H5.H5Sget_select_bounds", (H5dims[0] - 2) == hibounds[0]); + assertTrue("H5.H5Sget_select_bounds", (H5dims[1] - 2) == hibounds[1]); } catch (Throwable err) { err.printStackTrace(); @@ -468,14 +530,15 @@ public class TestH5S { } @Test - public void testH5Sget_select_hyper() { - long space1 = HDF5Constants.H5I_INVALID_HID; - long start[] = {0,0}; - long stride[] = {1,1}; - long count[] = {1,1}; - long block[] = {4,4}; - long nblocks; // Number of hyperslab blocks - long blocks[] = {-1, -1, -1, -1, -1, -1, -1, -1}; // List of blocks + public void testH5Sget_select_hyper() + { + long space1 = HDF5Constants.H5I_INVALID_HID; + long start[] = {0, 0}; + long stride[] = {1, 1}; + long count[] = {1, 1}; + long block[] = {4, 4}; + long nblocks; // Number of hyperslab blocks + long blocks[] = {-1, -1, -1, -1, -1, -1, -1, -1}; // List of blocks try { // Copy "all" selection & space space1 = H5.H5Scopy(H5sid); @@ -493,26 +556,31 @@ public class TestH5S { // Verify that the correct block is defined assertTrue("H5.H5Sget_select_hyper_blocklist", start[0] == blocks[0]); assertTrue("H5.H5Sget_select_hyper_blocklist", start[1] == blocks[1]); - assertTrue("H5.H5Sget_select_hyper_blocklist", (block[0]-1) == blocks[2]); - assertTrue("H5.H5Sget_select_hyper_blocklist", (block[1]-1) == blocks[3]); + assertTrue("H5.H5Sget_select_hyper_blocklist", (block[0] - 1) == blocks[2]); + assertTrue("H5.H5Sget_select_hyper_blocklist", (block[1] - 1) == blocks[3]); } catch (Throwable err) { err.printStackTrace(); fail("H5.H5Sget_select_bounds: " + err); } finally { - try {H5.H5Sclose(space1);} catch (Exception ex) {} + try { + H5.H5Sclose(space1); + } + catch (Exception ex) { + } } } @Test - public void testH5Sget_select_valid() { - long space1 = HDF5Constants.H5I_INVALID_HID; - long start[] = {1,0}; - long stride[] = {1,1}; - long count[] = {2,3}; - long block[] = {1,1}; - long offset[] = {0,0}; // Offset of selection + public void testH5Sget_select_valid() + { + long space1 = HDF5Constants.H5I_INVALID_HID; + long start[] = {1, 0}; + long stride[] = {1, 1}; + long count[] = {2, 3}; + long block[] = {1, 1}; + long offset[] = {0, 0}; // Offset of selection try { // Copy "all" selection & space @@ -522,20 +590,20 @@ public class TestH5S { H5.H5Sselect_hyperslab(space1, HDF5Constants.H5S_SELECT_SET, start, stride, count, block); // Check a valid offset - offset[0]=-1; - offset[1]=0; + offset[0] = -1; + offset[1] = 0; H5.H5Soffset_simple(space1, offset); assertTrue("H5Sselect_valid", H5.H5Sselect_valid(space1)); // Check an invalid offset - offset[0]=10; - offset[1]=0; + offset[0] = 10; + offset[1] = 0; H5.H5Soffset_simple(space1, offset); assertFalse("H5Sselect_valid", H5.H5Sselect_valid(space1)); /* Reset offset */ - offset[0]=0; - offset[1]=0; + offset[0] = 0; + offset[1] = 0; H5.H5Soffset_simple(space1, offset); assertTrue("H5Sselect_valid", H5.H5Sselect_valid(space1)); } @@ -544,20 +612,25 @@ public class TestH5S { fail("testH5Sget_select_valid: " + err); } finally { - try {H5.H5Sclose(space1);} catch (Exception ex) {} + try { + H5.H5Sclose(space1); + } + catch (Exception ex) { + } } } @Test - public void testH5Shyper_regular() { - long start[] = {1,0}; - long stride[] = {1,1}; - long count[] = {2,3}; - long block[] = {1,1}; - long q_start[] = new long[2]; - long q_stride[] = new long[2]; - long q_count[] = new long[2]; - long q_block[] = new long[2]; + public void testH5Shyper_regular() + { + long start[] = {1, 0}; + long stride[] = {1, 1}; + long count[] = {2, 3}; + long block[] = {1, 1}; + long q_start[] = new long[2]; + long q_stride[] = new long[2]; + long q_count[] = new long[2]; + long q_block[] = new long[2]; boolean is_regular = false; try { @@ -572,7 +645,7 @@ public class TestH5S { H5.H5Sget_regular_hyperslab(H5sid, q_start, q_stride, q_count, q_block); /* Verify the hyperslab parameters */ - for(int u = 0; u < H5rank; u++) { + for (int u = 0; u < H5rank; u++) { assertTrue("H5Sget_regular_hyperslab, start", start[u] == q_start[u]); assertTrue("H5Sget_regular_hyperslab, stride", stride[u] == q_stride[u]); assertTrue("H5Sget_regular_hyperslab, count", count[u] == q_count[u]); |