diff options
author | Allen Byrne <byrn@hdfgroup.org> | 2016-02-29 02:45:23 (GMT) |
---|---|---|
committer | Allen Byrne <byrn@hdfgroup.org> | 2016-02-29 02:45:23 (GMT) |
commit | 198ceb5fcc2bc9fd9893bf5905e6fc352c3d6d0a (patch) | |
tree | 406280cf92e68977c39b56747df9a80e96c617c7 /java/test | |
parent | 63249be0e10a8726acb5a7cf64491319eaa46227 (diff) | |
download | hdf5-198ceb5fcc2bc9fd9893bf5905e6fc352c3d6d0a.zip hdf5-198ceb5fcc2bc9fd9893bf5905e6fc352c3d6d0a.tar.gz hdf5-198ceb5fcc2bc9fd9893bf5905e6fc352c3d6d0a.tar.bz2 |
[svn-r29227] HDFFV-9552: merge in java code.
new files added.
Diffstat (limited to 'java/test')
-rw-r--r-- | java/test/TestH5PL.java | 61 | ||||
-rw-r--r-- | java/test/TestH5Plist.java | 1013 | ||||
-rw-r--r-- | java/test/TestH5Pvirtual.java | 433 |
3 files changed, 1507 insertions, 0 deletions
diff --git a/java/test/TestH5PL.java b/java/test/TestH5PL.java new file mode 100644 index 0000000..afcb88a --- /dev/null +++ b/java/test/TestH5PL.java @@ -0,0 +1,61 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * 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 files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. 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.assertTrue; +import static org.junit.Assert.fail; +import hdf.hdf5lib.H5; +import hdf.hdf5lib.HDF5Constants; +import hdf.hdf5lib.exceptions.HDF5LibraryException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +public class TestH5PL { + @Rule public TestName testname = new TestName(); + + @Before + public void checkOpenIDs() { + assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0); + System.out.print(testname.getMethodName()); + } + @After + public void nextTestName() { + System.out.println(); + } + + @Test + public void TestH5PLplugins() { + try { + int plugin_flags = H5.H5PLget_loading_state(); + assertTrue("H5.H5PLget_loading_state: "+plugin_flags, plugin_flags == HDF5Constants.H5PL_ALL_PLUGIN); + int new_setting = plugin_flags & ~HDF5Constants.H5PL_FILTER_PLUGIN; + H5.H5PLset_loading_state (new_setting); + int changed_flags = H5.H5PLget_loading_state(); + assertTrue("H5.H5PLget_loading_state: "+changed_flags, changed_flags == new_setting); + H5.H5PLset_loading_state (plugin_flags); + changed_flags = H5.H5PLget_loading_state(); + assertTrue("H5.H5PLget_loading_state: "+changed_flags, changed_flags == HDF5Constants.H5PL_ALL_PLUGIN); + } + catch (Throwable err) { + err.printStackTrace(); + fail("TestH5PLplugins " + err); + } + } +} diff --git a/java/test/TestH5Plist.java b/java/test/TestH5Plist.java new file mode 100644 index 0000000..c4dee01 --- /dev/null +++ b/java/test/TestH5Plist.java @@ -0,0 +1,1013 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * 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 files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. 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.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.io.File; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.nio.charset.StandardCharsets; + +import hdf.hdf5lib.H5; +import hdf.hdf5lib.HDF5Constants; +import hdf.hdf5lib.HDFNativeData; +import hdf.hdf5lib.callbacks.H5P_cls_close_func_cb; +import hdf.hdf5lib.callbacks.H5P_cls_close_func_t; +import hdf.hdf5lib.callbacks.H5P_cls_copy_func_cb; +import hdf.hdf5lib.callbacks.H5P_cls_copy_func_t; +import hdf.hdf5lib.callbacks.H5P_cls_create_func_cb; +import hdf.hdf5lib.callbacks.H5P_cls_create_func_t; +import hdf.hdf5lib.callbacks.H5P_prp_set_func_cb; +import hdf.hdf5lib.callbacks.H5P_prp_get_func_cb; +import hdf.hdf5lib.callbacks.H5P_prp_delete_func_cb; +import hdf.hdf5lib.callbacks.H5P_prp_copy_func_cb; +import hdf.hdf5lib.callbacks.H5P_prp_compare_func_cb; +import hdf.hdf5lib.callbacks.H5P_prp_close_func_cb; +import hdf.hdf5lib.callbacks.H5P_prp_create_func_cb; +import hdf.hdf5lib.callbacks.H5P_iterate_cb; +import hdf.hdf5lib.callbacks.H5P_iterate_t; +import hdf.hdf5lib.exceptions.HDF5Exception; +import hdf.hdf5lib.exceptions.HDF5LibraryException; +import hdf.hdf5lib.structs.H5AC_cache_config_t; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +public class TestH5Plist { + @Rule public TestName testname = new TestName(); + + // Property definitions + private static final String CLASS1_NAME = "Class 1"; + private static final String CLASS1_PATH = "root/Class 1"; + + private static final String CLASS2_NAME = "Class 2"; + private static final String CLASS2_PATH = "root/Class 1/Class 2"; + + // Property definitions + private static final String PROP1_NAME = "Property 1"; + private static final int prop1_def = 10; // Property 1 default value + private static final int PROP1_SIZE = 2; + + private static final String PROP2_NAME = "Property 2"; + private static final float prop2_def = 3.14F; // Property 2 default value + private static final int PROP2_SIZE = 8; + + private static final String PROP3_NAME = "Property 3"; + private static final char[] prop3_def = {'T','e','n',' ','c','h','a','r','s',' '}; // Property 3 default value + private static final int PROP3_SIZE = 10; + + private static final String PROP4_NAME = "Property 4"; + private static final double prop4_def = 1.41F; // Property 4 default value + private static final int PROP4_SIZE = 8; + + private static final String [] pnames = { // Names of properties for iterator + PROP1_NAME, + PROP2_NAME, + PROP3_NAME, + PROP4_NAME}; + + long plist_class_id = -1; + + @Before + public void createPropClass()throws NullPointerException, HDF5Exception + { + assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0); + System.out.print(testname.getMethodName()); + // Create a new generic class, derived from the root of the class hierarchy + try { + plist_class_id = H5.H5Pcreate_class_nocb(HDF5Constants.H5P_ROOT, CLASS1_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("TestH5Plist.H5Pcreate_class: " + err); + } + assertTrue(plist_class_id > 0); + } + + @After + public void deleteFileAccess() throws HDF5LibraryException { + if (plist_class_id > 0) + try {H5.H5Pclose(plist_class_id);} catch (Exception ex) {} + System.out.println(); + } + + // Test basic generic property list code. Tests creating new generic classes. + @Test + public void testH5P_genprop_basic_class() { + int status = -1; + long cid1 = -1; // Generic Property class ID + long cid2 = -1; // Generic Property class ID + long cid3 = -1; // Generic Property class ID + String name = null; // Name of class + + try { + // Check class name + try { + name = H5.H5Pget_class_name(plist_class_id); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_class_name plist_class_id: " + err); + } + assertTrue("Class names don't match!, "+name+"="+CLASS1_NAME+"\n", name.compareTo(CLASS1_NAME)==0); + + // Check class parent + try { + cid2 = H5.H5Pget_class_parent(plist_class_id); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_class_parent cid2: " + err); + } + + // Verify class parent correct + try { + status = H5.H5Pequal(cid2, HDF5Constants.H5P_ROOT); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pequal cid2: " + err); + } + assertTrue("H5Pequal cid2", status >= 0); + + // Make certain false postives aren't being returned + try { + status = H5.H5Pequal(cid2, HDF5Constants.H5P_FILE_CREATE); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pequal cid2: " + err); + } + assertTrue("H5Pequal cid2", status >= 0); + + // Close parent class + try { + H5.H5Pclose_class(cid2); + cid2 = -1; + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pclose_class cid2: " + err); + } + + // Close class + try { + H5.H5Pclose_class(plist_class_id); + plist_class_id = -1; + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pclose_class plist_class_id: " + err); + } + + // Create another new generic class, derived from file creation class + try { + cid1 = H5.H5Pcreate_class_nocb(HDF5Constants.H5P_FILE_CREATE, CLASS2_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pcreate_class cid1: " + err); + } + assertTrue("H5Pcreate_class cid1", cid1 >= 0); + + // Check class name + try { + name = H5.H5Pget_class_name(cid1); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_class_name cid1: " + err); + } + assertTrue("Class names don't match!, "+name+"="+CLASS2_NAME+"\n", name.compareTo(CLASS2_NAME)==0); + + // Check class parent + try { + cid2 = H5.H5Pget_class_parent(cid1); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_class_parent cid2: " + err); + } + assertTrue("H5Pget_class_parent cid2 ", cid2 >= 0); + + // Verify class parent correct + try { + status = H5.H5Pequal(cid2, HDF5Constants.H5P_FILE_CREATE); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pequal cid2: " + err); + } + assertTrue("H5Pequal cid2 ", status >= 0); + + // Check class parent's parent + try { + cid3 = H5.H5Pget_class_parent(cid2); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_class_parent cid3: " + err); + } + assertTrue("H5Pget_class_parent cid3", cid3 >= 0); + + // Verify class parent's parent correct + try { + status = H5.H5Pequal(cid3, HDF5Constants.H5P_GROUP_CREATE); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pequal cid3: " + err); + } + assertTrue("H5Pequal cid3 ", status >= 0); + + // Close parent class's parent + try { + H5.H5Pclose_class(cid3); + cid3 = -1; + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pclose_class cid3: " + err); + } + + // Close parent class's parent + try { + H5.H5Pclose_class(cid2); + cid2 = -1; + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pclose_class cid2: " + err); + } + + // Close parent class's parent + try { + H5.H5Pclose_class(cid1); + cid1 = -1; + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pclose_class cid1: " + err); + } + } + finally { + if (cid3 > 0) + try {H5.H5Pclose_class(cid3);} catch (Throwable err) {} + if (cid2 > 0) + try {H5.H5Pclose_class(cid2);} catch (Throwable err) {} + if (cid1 > 0) + try {H5.H5Pclose_class(cid1);} catch (Throwable err) {} + } + } + + // Test basic generic property list code. Tests adding properties to generic classes. + @Test + public void testH5P_genprop_basic_class_prop() { + int status = -1; + long size = -1; // Generic Property size + long nprops = -1; // Generic Property class number + + // Check the number of properties in class + try { + nprops = H5.H5Pget_nprops(plist_class_id); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_nprops plist_class_id: " + err); + } + assertTrue("H5Pget_nprops: "+nprops, nprops==0); + + // Check the existance of the first property (should fail) + try { + status = H5.H5Pexist(plist_class_id, PROP1_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pexist plist_class_id: " + err); + } + assertTrue("H5Pexist plist_class_id "+PROP1_NAME, status == 0); + + // Insert first property into class (with no callbacks) + try { + byte[] prop_value = HDFNativeData.intToByte(prop1_def); + + H5.H5Pregister2_nocb(plist_class_id, PROP1_NAME, PROP1_SIZE, prop_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pregister2 plist_class_id: "+PROP1_NAME + err); + } + + // Try to insert the first property again (should fail) + try { + byte[] prop_value = HDFNativeData.intToByte(prop1_def); + + H5.H5Pregister2_nocb(plist_class_id, PROP1_NAME, PROP1_SIZE, prop_value); + fail("H5Pregister2 plist_class_id: "+PROP1_NAME); + } + catch (Throwable err) { + } + + // Check the existance of the first property + try { + status = H5.H5Pexist(plist_class_id, PROP1_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pexist plist_class_id: " + err); + } + assertTrue("H5Pexist plist_class_id "+PROP1_NAME, status == 1); + + // Check the size of the first property + try { + size = H5.H5Pget_size(plist_class_id, PROP1_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_size PROP1_NAME: " + err); + } + assertTrue("H5Pget_size "+PROP1_NAME +" size: "+size, size == PROP1_SIZE); + + // Check the number of properties in class + try { + nprops = H5.H5Pget_nprops(plist_class_id); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_nprops plist_class_id: " + err); + } + assertTrue("H5Pget_nprops: "+nprops, nprops==1); + + // Insert second property into class (with no callbacks) + try { + byte[] prop_value = HDFNativeData.floatToByte(prop2_def); + + H5.H5Pregister2_nocb(plist_class_id, PROP2_NAME, PROP2_SIZE, prop_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pregister2 plist_class_id: "+PROP2_NAME + err); + } + + // Try to insert the second property again (should fail) + try { + byte[] prop_value = HDFNativeData.floatToByte(prop2_def); + + H5.H5Pregister2_nocb(plist_class_id, PROP2_NAME, PROP2_SIZE, prop_value); + fail("H5Pregister2 plist_class_id: "+PROP2_NAME); + } + catch (Throwable err) { + } + + // Check the existance of the second property + try { + status = H5.H5Pexist(plist_class_id, PROP2_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pexist plist_class_id: " + err); + } + assertTrue("H5Pexist plist_class_id "+PROP2_NAME, status == 1); + + // Check the size of the second property + try { + size = H5.H5Pget_size(plist_class_id, PROP2_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_size PROP2_NAME: " + err); + } + assertTrue("H5Pget_size "+PROP2_NAME +" size: "+size, size == PROP2_SIZE); + + // Check the number of properties in class + try { + nprops = H5.H5Pget_nprops(plist_class_id); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_nprops plist_class_id: " + err); + } + assertTrue("H5Pget_nprops: "+nprops, nprops==2); + + // Insert third property into class (with no callbacks) + try { + byte[] prop_value = new String(prop3_def).getBytes(StandardCharsets.UTF_8); + + H5.H5Pregister2_nocb(plist_class_id, PROP3_NAME, PROP3_SIZE, prop_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pregister2 plist_class_id: "+PROP3_NAME + err); + } + + // Check the existance of the third property + try { + status = H5.H5Pexist(plist_class_id, PROP3_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pexist plist_class_id: " + err); + } + assertTrue("H5Pexist plist_class_id "+PROP3_NAME, status == 1); + + // Check the size of the third property + try { + size = H5.H5Pget_size(plist_class_id, PROP3_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_size PROP3_NAME: " + err); + } + assertTrue("H5Pget_size "+PROP3_NAME +" size: "+size, size == PROP3_SIZE); + + // Check the number of properties in class + try { + nprops = H5.H5Pget_nprops(plist_class_id); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_nprops plist_class_id: " + err); + } + assertTrue("H5Pget_nprops: "+nprops, nprops==3); + + // Unregister first property + try { + H5.H5Punregister(plist_class_id, PROP1_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Punregister plist_class_id: "+PROP1_NAME + err); + } + + // Try to check the size of the first property (should fail) + try { + size = H5.H5Pget_size(plist_class_id, PROP1_NAME); + fail("H5Pget_size PROP1_NAME"); + } + catch (Throwable err) { + } + + // Check the number of properties in class + try { + nprops = H5.H5Pget_nprops(plist_class_id); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_nprops plist_class_id: " + err); + } + assertTrue("H5Pget_nprops: "+nprops, nprops==2); + + // Unregister second property + try { + H5.H5Punregister(plist_class_id, PROP2_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Punregister plist_class_id: "+PROP2_NAME + err); + } + + // Check the number of properties in class + try { + nprops = H5.H5Pget_nprops(plist_class_id); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_nprops plist_class_id: " + err); + } + assertTrue("H5Pget_nprops: "+nprops, nprops==1); + + // Unregister third property + try { + H5.H5Punregister(plist_class_id, PROP3_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Punregister plist_class_id: "+PROP3_NAME + err); + } + + // Check the number of properties in class + try { + nprops = H5.H5Pget_nprops(plist_class_id); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_nprops plist_class_id: " + err); + } + assertTrue("H5Pget_nprops: "+nprops, nprops==0); + } + + // Test basic generic property list code. Tests iterating over properties in a generic class. + @Test + public void testH5P_genprop_class_iter() { + class idata { + public String[] iter_names= null; + public int iter_count = -1; + idata(String[] names, int count) { + this.iter_names = names; + this.iter_count = count; + } + } + class H5P_iter_data implements H5P_iterate_t { + public ArrayList<idata> iterdata = new ArrayList<idata>(); + } + H5P_iterate_t iter_data = new H5P_iter_data(); + + class H5P_iter_callback implements H5P_iterate_cb { + public int callback(long list_id, String name, H5P_iterate_t op_data) { + idata id = ((H5P_iter_data)op_data).iterdata.get(0); + return name.compareTo(id.iter_names[id.iter_count++]); + } + } + H5P_iterate_cb iter_cb = new H5P_iter_callback(); + + long size = -1; // Generic Property size + long nprops = -1; // Generic Property class number + int[] idx = {0}; // Index to start iteration at + + // Insert first property into class (with no callbacks) */ + try { + byte[] prop_value = HDFNativeData.intToByte(prop1_def); + + H5.H5Pregister2_nocb(plist_class_id, PROP1_NAME, PROP1_SIZE, prop_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pregister2 plist_class_id: "+PROP1_NAME + err); + } + + // Insert second property into class (with no callbacks) */ + try { + byte[] prop_value = HDFNativeData.floatToByte(prop2_def); + + H5.H5Pregister2_nocb(plist_class_id, PROP2_NAME, PROP2_SIZE, prop_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pregister2 plist_class_id: "+PROP2_NAME + err); + } + + // Insert third property into class (with no callbacks) */ + try { + byte[] prop_value = new String(prop3_def).getBytes(StandardCharsets.UTF_8); + + H5.H5Pregister2_nocb(plist_class_id, PROP3_NAME, PROP3_SIZE, prop_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pregister2 plist_class_id: "+PROP3_NAME + err); + } + + // Insert fourth property into class (with no callbacks) */ + try { + byte[] prop_value = HDFNativeData.doubleToByte(prop4_def); + + H5.H5Pregister2_nocb(plist_class_id, PROP4_NAME, PROP4_SIZE, prop_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pregister2 plist_class_id: "+PROP4_NAME + err); + } + + // Check the number of properties in class */ + try { + nprops = H5.H5Pget_nprops(plist_class_id); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_nprops plist_class_id: " + err); + } + assertTrue("H5Pget_nprops: "+nprops, nprops==4); + + // Iterate over all properties in class */ + idata id = new idata(pnames, 0); + ((H5P_iter_data)iter_data).iterdata.add(id); + try { + H5.H5Piterate(plist_class_id, null, iter_cb, iter_data); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Piterate: " + err); + } + assertFalse("H5Piterate ",((H5P_iter_data)iter_data).iterdata.isEmpty()); + assertTrue("H5Piterate "+((H5P_iter_data)iter_data).iterdata.size(),((H5P_iter_data)iter_data).iterdata.size()==1); + assertTrue("H5Piterate "+(((H5P_iter_data)iter_data).iterdata.get(0)).iter_count,((idata)((H5P_iter_data)iter_data).iterdata.get(0)).iter_count==4); + + // Iterate over last three properties in class */ + idx[0] = 1; + ((H5P_iter_data)iter_data).iterdata.get(0).iter_count = 1; + try { + H5.H5Piterate(plist_class_id, idx, iter_cb, iter_data); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Piterate: " + err); + } + assertFalse("H5Piterate ",((H5P_iter_data)iter_data).iterdata.isEmpty()); + assertTrue("H5Piterate "+((H5P_iter_data)iter_data).iterdata.size(),((H5P_iter_data)iter_data).iterdata.size()==1); + assertTrue("H5Piterate "+(((H5P_iter_data)iter_data).iterdata.get(0)).iter_count,((idata)((H5P_iter_data)iter_data).iterdata.get(0)).iter_count==4); + + assertTrue("H5Piterate: "+nprops+"="+idx[0], nprops == idx[0]); + } + + // Test basic generic property list code. + // Tests creating new generic property lists and adding and + // removing properties from them. + @Test + public void testH5P_genprop_basic_list_prop() { + int status = -1; + long lid1 = -1; // Generic Property list ID + long nprops = -1; // Number of properties in class + + try { + // Add several properties (several w/default values) + + // Insert first property into class (with no callbacks) + try { + byte[] prop_value = HDFNativeData.intToByte(prop1_def); + + H5.H5Pregister2_nocb(plist_class_id, PROP1_NAME, PROP1_SIZE, prop_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pregister2 plist_class_id: "+PROP1_NAME + err); + } + + // Insert second property into class (with no callbacks) + try { + byte[] prop_value = HDFNativeData.floatToByte(prop2_def); + + H5.H5Pregister2_nocb(plist_class_id, PROP2_NAME, PROP2_SIZE, prop_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pregister2 plist_class_id: "+PROP2_NAME + err); + } + + // Create a property list from the class + try { + lid1 = H5.H5Pcreate(plist_class_id); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pcreate lid1: " + err); + } + + // Check the number of properties in class + try { + nprops = H5.H5Pget_nprops(lid1); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_nprops lid1: " + err); + } + assertTrue("H5Pget_nprops: "+nprops, nprops==2); + + // Add temporary properties + + // Insert first temporary property into list (with no callbacks) + try { + byte[] prop_value = new String(prop3_def).getBytes(StandardCharsets.UTF_8); + + H5.H5Pinsert2_nocb(lid1, PROP3_NAME, PROP3_SIZE, prop_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pinsertr2 lid1: "+PROP3_NAME + err); + } + + // Insert second temporary property into list (with no callbacks) + try { + byte[] prop_value = HDFNativeData.doubleToByte(prop4_def); + + H5.H5Pinsert2_nocb(lid1, PROP4_NAME, PROP4_SIZE, prop_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pinsert2 lid1: "+PROP4_NAME + err); + } + + // Check the number of properties in class + try { + nprops = H5.H5Pget_nprops(lid1); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pget_nprops lid1: " + err); + } + assertTrue("H5Pget_nprops: "+nprops, nprops==4); + + // Check existence of all properties + try { + status = H5.H5Pexist(lid1, PROP1_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pexist plist_class_id: " + err); + } + assertTrue("H5Pexist lid1 "+PROP1_NAME, status == 1); + try { + status = H5.H5Pexist(lid1, PROP2_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pexist plist_class_id: " + err); + } + assertTrue("H5Pexist lid1 "+PROP2_NAME, status == 1); + try { + status = H5.H5Pexist(lid1, PROP3_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pexist plist_class_id: " + err); + } + assertTrue("H5Pexist lid1 "+PROP3_NAME, status == 1); + try { + status = H5.H5Pexist(lid1, PROP4_NAME); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pexist plist_class_id: " + err); + } + assertTrue("H5Pexist lid1 "+PROP4_NAME, status == 1); + + } + finally { + if (lid1 > 0) + try {H5.H5Pclose(lid1);} catch (Throwable err) {} + } + } + +// // Test basic generic property list code. Tests callbacks for property lists in a generic class. +// @Test +// public void testH5P_genprop_class_callback() { +// class cdata { +// public long cls_id = -1; +// public int cls_count = -1; +// cdata(long id, int count) { +// this.cls_id = id; +// this.cls_count = count; +// } +// } +// class H5P_cls_create_data implements H5P_cls_create_func_t { +// public ArrayList<cdata> clsdata = new ArrayList<cdata>(); +// } +// H5P_cls_create_func_t cls_create_data = new H5P_cls_create_data(); +// +// class H5P_cls_create_callback implements H5P_cls_create_func_cb { +// public int callback(long list_id, H5P_cls_create_func_t cls_data) { +// System.err.println("H5P_cls_create_callback enter"); +// cdata cd = ((H5P_cls_create_data)cls_create_data).clsdata.get(0); +// cd.cls_count++; +// cd.cls_id = list_id; +// return 0; +// } +// } +// H5P_cls_create_func_cb cls_create_cb = new H5P_cls_create_callback(); +// +// class H5P_cls_copy_data implements H5P_cls_copy_func_t { +// public ArrayList<cdata> clsdata = new ArrayList<cdata>(); +// } +// H5P_cls_copy_func_t cls_copy_data = new H5P_cls_copy_data(); +// +// class H5P_cls_copy_callback implements H5P_cls_copy_func_cb { +// public int callback(long list_id1, long list_id2, H5P_cls_copy_func_t cls_data) { +// cdata cd = ((H5P_cls_copy_data)cls_copy_data).clsdata.get(0); +// cd.cls_count++; +// cd.cls_id = list_id1; +// return 0; +// } +// } +// H5P_cls_copy_func_cb cls_copy_cb = new H5P_cls_copy_callback(); +// +// class H5P_cls_close_data implements H5P_cls_close_func_t { +// public ArrayList<cdata> clsdata = new ArrayList<cdata>(); +// } +// H5P_cls_close_func_t cls_close_data = new H5P_cls_close_data(); +// +// class H5P_cls_close_callback implements H5P_cls_close_func_cb { +// public int callback(long list_id, H5P_cls_close_func_t cls_data) { +// cdata cd = ((H5P_cls_close_data)cls_close_data).clsdata.get(0); +// cd.cls_count++; +// cd.cls_id = list_id; +// return 0; +// } +// } +// H5P_cls_close_func_cb cls_close_cb = new H5P_cls_close_callback(); +// +// long cid1 = -1; // Generic Property class ID +// long cid2 = -1; // Generic Property class ID +// long lid1 = -1; // Generic Property list ID +// long lid2 = -1; // Generic Property list ID +// long lid3 = -1; // Generic Property list ID +// long nprops = -1; // Number of properties in class +// +// try { +// // Create a new generic class, derived from the root of the class hierarchy +// try { +// cid1 = H5.H5Pcreate_class(HDF5Constants.H5P_ROOT, CLASS1_NAME, cls_create_cb, cls_create_data, cls_copy_cb, cls_copy_data, cls_close_cb, cls_close_data); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pcreate_class cid1: " + err); +// } +// assertTrue("H5Pcreate_class cid1", cid1 >= 0); +// +// // Insert first property into class (with no callbacks) +// try { +// byte[] prop_value = HDFNativeData.intToByte(prop1_def); +// +// H5.H5Pregister2(cid1, PROP1_NAME, PROP1_SIZE, prop_value, null, null, null, null, null, null, null); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pregister2 cid1: "+PROP1_NAME + err); +// } +// +// // Insert second property into class (with no callbacks) +// try { +// byte[] prop_value = HDFNativeData.floatToByte(prop2_def); +// +// H5.H5Pregister2(cid1, PROP2_NAME, PROP2_SIZE, prop_value, null, null, null, null, null, null, null); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pregister2 cid1: "+PROP2_NAME + err); +// } +// +// // Insert third property into class (with no callbacks) +// try { +// byte[] prop_value = new String(prop3_def).getBytes(StandardCharsets.UTF_8); +// +// H5.H5Pregister2(cid1, PROP3_NAME, PROP3_SIZE, prop_value, null, null, null, null, null, null, null); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pregister2 cid1: "+PROP3_NAME + err); +// } +// +// // Check the number of properties in class +// try { +// nprops = H5.H5Pget_nprops(cid1); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pget_nprops cid1: " + err); +// } +// assertTrue("H5Pget_nprops: "+nprops, nprops==3); +// +// // Initialize class callback structs +// cdata create_id = new cdata(-1, 0); +// cdata copy_id = new cdata(-1, 0); +// cdata close_id = new cdata(-1, 0); +// ((H5P_cls_create_data)cls_create_data).clsdata.add(create_id); +// ((H5P_cls_copy_data)cls_copy_data).clsdata.add(copy_id); +// ((H5P_cls_close_data)cls_close_data).clsdata.add(close_id); +// +// // Create a property list from the class +// try { +// lid1 = H5.H5Pcreate(cid1); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pcreate lid1: " + err); +// } +// +// // Verify that the creation callback occurred +// assertFalse("H5Pcreate ",((H5P_cls_create_data)cls_create_data).clsdata.isEmpty()); +// assertTrue("H5Pcreate "+((H5P_cls_create_data)cls_create_data).clsdata.get(0).cls_id ,((H5P_cls_create_data)cls_create_data).clsdata.get(0).cls_id == lid1); +// assertTrue("H5Pcreate "+(((H5P_cls_create_data)cls_create_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_create_data)cls_create_data).clsdata.get(0)).cls_count==1); +// +// // Check the number of properties in list +// try { +// nprops = H5.H5Pget_nprops(lid1); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pget_nprops lid1: " + err); +// } +// assertTrue("H5Pget_nprops: "+nprops, nprops==3); +// +// // Create another property list from the class +// try { +// lid2 = H5.H5Pcreate(cid1); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pcreate lid2: " + err); +// } +// +// /* Verify that the creation callback occurred */ +// assertFalse("H5Pcreate ",((H5P_cls_create_data)cls_create_data).clsdata.isEmpty()); +// assertTrue("H5Pcreate "+((H5P_cls_create_data)cls_create_data).clsdata.get(0).cls_id ,((H5P_cls_create_data)cls_create_data).clsdata.get(0).cls_id == lid2); +// assertTrue("H5Pcreate "+(((H5P_cls_create_data)cls_create_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_create_data)cls_create_data).clsdata.get(0)).cls_count==2); +// +// // Check the number of properties in list +// try { +// nprops = H5.H5Pget_nprops(lid2); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pget_nprops lid2: " + err); +// } +// assertTrue("H5Pget_nprops: "+nprops, nprops==3); +// +// // Create another property list by copying an existing list +// try { +// lid3= H5.H5Pcopy(lid1); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pcopy lid3: " + err); +// } +// +// // Verify that the copy callback occurred +// assertFalse("H5Pcopy ",((H5P_cls_copy_data)cls_copy_data).clsdata.isEmpty()); +// assertTrue("H5Pcopy "+((H5P_cls_copy_data)cls_copy_data).clsdata.get(0).cls_id ,((H5P_cls_copy_data)cls_copy_data).clsdata.get(0).cls_id == lid3); +// assertTrue("H5Pcopy "+(((H5P_cls_copy_data)cls_copy_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_copy_data)cls_copy_data).clsdata.get(0)).cls_count==1); +// +// // Check the number of properties in list +// try { +// nprops = H5.H5Pget_nprops(lid3); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pget_nprops lid3: " + err); +// } +// assertTrue("H5Pget_nprops: "+nprops, nprops==3); +// +// // Close first list +// try { +// H5.H5Pclose(lid1); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pclose lid1: " + err); +// } +// +// /* Verify that the close callback occurred */ +// assertFalse("H5Pclose ",((H5P_cls_close_data)cls_close_data).clsdata.isEmpty()); +// assertTrue("H5Pclose "+((H5P_cls_close_data)cls_close_data).clsdata.get(0).cls_id ,((H5P_cls_close_data)cls_copy_data).clsdata.get(0).cls_id == lid1); +// assertTrue("H5Pclose "+(((H5P_cls_close_data)cls_close_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_close_data)cls_copy_data).clsdata.get(0)).cls_count==1); +// +// // Close second list +// try { +// H5.H5Pclose(lid2); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pclose lid2: " + err); +// } +// +// // Verify that the close callback occurred +// assertTrue("H5Pclose "+((H5P_cls_close_data)cls_close_data).clsdata.get(0).cls_id ,((H5P_cls_close_data)cls_close_data).clsdata.get(0).cls_id == lid2); +// assertTrue("H5Pclose "+(((H5P_cls_close_data)cls_close_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_close_data)cls_close_data).clsdata.get(0)).cls_count==2); +// +// // Close third list +// try { +// H5.H5Pclose(lid3); +// } +// catch (Throwable err) { +// err.printStackTrace(); +// fail("H5Pclose lid3: " + err); +// } +// +// // Verify that the close callback occurred +// assertTrue("H5Pclose "+((H5P_cls_close_data)cls_close_data).clsdata.get(0).cls_id ,((H5P_cls_close_data)cls_close_data).clsdata.get(0).cls_id == lid3); +// assertTrue("H5Pclose "+(((H5P_cls_close_data)cls_close_data).clsdata.get(0)).cls_count,((cdata)((H5P_cls_close_data)cls_close_data).clsdata.get(0)).cls_count==3); +// } +// finally { +// if (lid3 > 0) +// try {H5.H5Pclose(lid3);} catch (Throwable err) {} +// if (lid2 > 0) +// try {H5.H5Pclose(lid2);} catch (Throwable err) {} +// if (lid1 > 0) +// try {H5.H5Pclose(lid1);} catch (Throwable err) {} +// if (cid2 > 0) +// try {H5.H5Pclose_class(cid2);} catch (Throwable err) {} +// if (cid1 > 0) +// try {H5.H5Pclose_class(cid1);} catch (Throwable err) {} +// } +// } + +} diff --git a/java/test/TestH5Pvirtual.java b/java/test/TestH5Pvirtual.java new file mode 100644 index 0000000..9372ae1 --- /dev/null +++ b/java/test/TestH5Pvirtual.java @@ -0,0 +1,433 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * 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 files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. 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.assertFalse; +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 TestH5Pvirtual { + @Rule public TestName testname = new TestName(); + + private static final String H5_FILE = "vds.h5"; + private static final String SRC_FILE[] = { + "v-0.h5", + "v-1.h5", + "v-2.h5" + }; + private static final String SRC_DATASET[] = { + "A", + "B", + "C" + }; + private static final int DIM_Y = 6; + private static final int VDSDIM_X = 4; + private static final int VDSDIM_Y = 6; + private static final int fill_value = -1; + long[] H5dims = { DIM_Y }; + long[] VDSH5dims = { VDSDIM_X, VDSDIM_Y }; + long H5fid = -1; + long H5dsid = -1; + long H5dssid = -1; + long H5dvsid = -1; + long H5did = -1; + long H5dcplid = -1; + long H5dapl_id = -1; + + private final void _deleteFile(String filename) { + File file = new File(filename); + + if (file.exists()) { + try {file.delete();} catch (SecurityException e) {} + } + } + + private final long _createDataset(long fid, long dsid, String name, long dcpl, long dapl) { + long did = -1; + long space_id = -1; + long[] start = {0, 0}; + long[] stride = null; + long[] count = {1, 1}; + long[] block = {1, VDSDIM_Y}; + + try { + H5dssid = H5.H5Screate_simple(1, H5dims, null); + for (int i = 0; i < 3; i++) { + start[0] = i; + /* Select i-th row in the virtual dataset; selection in the source datasets is the same. */ + H5.H5Sselect_hyperslab(dsid, HDF5Constants.H5S_SELECT_SET, start, stride, count, block); + H5.H5Pset_virtual(dcpl, dsid, SRC_FILE[i], SRC_DATASET[i], H5dssid); + } + did = H5.H5Dcreate(fid, name, HDF5Constants.H5T_NATIVE_INT, dsid, + HDF5Constants.H5P_DEFAULT, dcpl, dapl); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Dcreate: " + err); + } + assertTrue("TestH5Pvirtual._createDataset: ", did > 0); + + return did; + } + + private final void _createH5File(long fcpl, long fapl) { + int[] dset_data = new int[DIM_Y]; + // Create source files and datasets + for (int i=0; i < 3; i++) { + long space_id = -1; + long dset_id = -1; + long file_id = -1; + for (int j = 0; j < DIM_Y; j++) dset_data[j] = i+1; + + try { + file_id = H5.H5Fcreate(SRC_FILE[i], HDF5Constants.H5F_ACC_TRUNC, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + space_id = H5.H5Screate_simple(1, H5dims, null); + dset_id = H5.H5Dcreate(file_id, SRC_DATASET[i], HDF5Constants.H5T_NATIVE_INT, space_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + H5.H5Dwrite (dset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, + dset_data); + } + catch (Throwable err) { + err.printStackTrace(); + fail("TestH5Pvirtual.createH5file: " + err); + } + finally { + if (dset_id > 0) + try {H5.H5Dclose(dset_id);} catch (Exception ex) {} + if (space_id > 0) + try {H5.H5Sclose(space_id);} catch (Exception ex) {} + if (file_id > 0) + try {H5.H5Fclose(file_id);} catch (Exception ex) {} + } + } + + try { + int[] fill_value = {-1}; + H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + H5dsid = H5.H5Screate_simple(2, VDSH5dims, null); + H5dcplid = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE); + H5.H5Pset_fill_value(H5dcplid, HDF5Constants.H5T_NATIVE_INT, fill_value); + } + catch (Throwable err) { + err.printStackTrace(); + fail("TestH5Pvirtual.createH5file: " + err); + } + assertTrue("TestH5Pvirtual.createH5file: H5.H5Fcreate: ", H5fid > 0); + assertTrue("TestH5Pvirtual.createH5file: H5.H5Screate_simple: ", H5dsid > 0); + assertTrue("TestH5Pvirtual.createH5file: H5.H5Pcreate: ", H5dcplid > 0); + + try { + H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL); + } + catch (Throwable err) { + err.printStackTrace(); + } + } + + @Before + public void createH5file() + throws NullPointerException, HDF5Exception { + assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0); + System.out.print(testname.getMethodName()); + _createH5File(HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + H5dapl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_ACCESS); + assertTrue("TestH5Pvirtual.createH5file: H5.H5Pcreate: ", H5dapl_id > 0); + } + + @After + public void deleteH5file() throws HDF5LibraryException { + if (H5dapl_id > 0) + try {H5.H5Pclose(H5dapl_id);} catch (Exception ex) {} + if (H5dcplid > 0) + try {H5.H5Pclose(H5dcplid);} catch (Exception ex) {} + if (H5dsid > 0) + try {H5.H5Sclose(H5dsid);} catch (Exception ex) {} + if (H5fid > 0) + try {H5.H5Fclose(H5fid);} catch (Exception ex) {} + for (int i = 0; i < 3; i++) { + _deleteFile(SRC_FILE[i]); + } + _deleteFile(H5_FILE); + System.out.println(); + } + + @Test + public void testH5Pvirtual_storage() { + int layout = -1; + + H5did = _createDataset(H5fid, H5dsid, "VDS", H5dcplid, H5dapl_id); + try { + layout = H5.H5Pget_layout (H5dcplid); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Pget_layout: " + err); + } + finally { + if (H5dssid > 0) + try {H5.H5Sclose(H5dssid);} catch (Exception ex) {} + if (H5did > 0) + try {H5.H5Dclose(H5did);} catch (Exception ex) {} + } + assertTrue("testH5Pvirtual_storage", HDF5Constants.H5D_VIRTUAL == layout); + } + + @Test + public void testH5Pget_virtual_count() { + long num_map = -1; + + H5did = _createDataset(H5fid, H5dsid, "VDS", H5dcplid, H5dapl_id); + try { + num_map = H5.H5Pget_virtual_count(H5dcplid); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Pget_virtual_count: " + err); + } + finally { + if (H5dssid > 0) + try {H5.H5Sclose(H5dssid);} catch (Exception ex) {} + if (H5did > 0) + try {H5.H5Dclose(H5did);} catch (Exception ex) {} + } + assertTrue("testH5Pget_virtual_count: "+num_map, num_map >= 0); + } + + @Test + public void testH5Pget_source_filename() throws Throwable { + String filename = null; + + H5did = _createDataset(H5fid, H5dsid, "VDS", H5dcplid, H5dapl_id); + try { + filename = (H5.H5Pget_virtual_filename (H5dcplid, 2)); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Pget_virtual_filename: " + err); + } + finally { + if (H5dssid > 0) + try {H5.H5Sclose(H5dssid);} catch (Exception ex) {} + if (H5did > 0) + try {H5.H5Dclose(H5did);} catch (Exception ex) {} + } + assertTrue("testH5Pget_source_filename: "+filename, filename.compareTo("v-2.h5") == 0); + } + + @Test + public void testH5Pget_source_datasetname() throws Throwable { + String datasetname = null; + + H5did = _createDataset(H5fid, H5dsid, "VDS", H5dcplid, H5dapl_id); + try { + datasetname = H5.H5Pget_virtual_dsetname (H5dcplid, 1); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Pget_virtual_dsetname: " + err); + } + finally { + if (H5dssid > 0) + try {H5.H5Sclose(H5dssid);} catch (Exception ex) {} + if (H5did > 0) + try {H5.H5Dclose(H5did);} catch (Exception ex) {} + } + assertTrue("testH5Pget_source_datasetname: "+datasetname, datasetname.compareTo("B") == 0); + } + + @Test + public void testH5Pget_selection_source_dataset() throws Throwable { + long src_space = -1; + long src_selection = -1; + + H5did = _createDataset(H5fid, H5dsid, "VDS", H5dcplid, H5dapl_id); + try { + src_space = H5.H5Pget_virtual_srcspace (H5dcplid, 0); + src_selection = H5.H5Sget_select_type(src_space); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5Pget_selection_source_dataset: " + err); + } + finally { + if (src_space > 0) + try {H5.H5Sclose(src_space);} catch (Exception ex) {} + if (H5dssid > 0) + try {H5.H5Sclose(H5dssid);} catch (Exception ex) {} + if (H5did > 0) + try {H5.H5Dclose(H5did);} catch (Exception ex) {} + } + assertTrue("testH5Pget_selection_source_dataset", src_selection == HDF5Constants.H5S_SEL_ALL); + } + + @Test + public void testH5Pget_mapping_parameters() { + long num_map = -1; + + H5did = _createDataset(H5fid, H5dsid, "VDS", H5dcplid, H5dapl_id); + try { + try { + num_map = H5.H5Pget_virtual_count(H5dcplid); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Pget_virtual_count: " + err); + } + for (int i = 0; i < num_map; i++) { + int vselection = -1; + long vspace = -1; + long nblocks; // Number of hyperslab blocks + long blocks[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; // List of blocks + long[] start = {i, 0}; + long[] stride = {1, 1}; + long[] count = {1, 1}; + long[] block = {1, VDSDIM_Y}; + 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 { + try { + vspace = H5.H5Pget_virtual_vspace (H5dcplid, i); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Pget_virtual_vspace: " + err); + } + try { + vselection = H5.H5Sget_select_type(vspace); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.H5Sget_select_type: " + err); + } + assertTrue("testH5Pget_mapping_parameters["+i+"]", vselection == HDF5Constants.H5S_SEL_HYPERSLABS); + + // Verify that there is only one block + nblocks = H5.H5Sget_select_hyper_nblocks(vspace); + assertTrue("H5Sget_select_hyper_nblocks", nblocks == 1); + + // Retrieve the block defined + H5.H5Sget_select_hyper_blocklist(vspace, 0, nblocks, blocks); + + // Verify that the correct block is defined + assertTrue("H5.H5Sget_select_hyper_blocklist["+i+"] [0]: "+blocks[0], start[0] == blocks[0]); + assertTrue("H5.H5Sget_select_hyper_blocklist["+i+"] [1]: "+blocks[1], start[1] == blocks[1]); + assertTrue("H5.H5Sget_select_hyper_blocklist["+i+"] [2]: "+blocks[2], (block[0]-1+i) == blocks[2]); + assertTrue("H5.H5Sget_select_hyper_blocklist["+i+"] [3]: "+blocks[3], (block[1]-1) == blocks[3]); + // We also can use new APIs to get start, stride, count and block + is_regular = H5.H5Sis_regular_hyperslab(vspace); + assertTrue("H5.H5Sis_regular_hyperslab", is_regular); + H5.H5Sget_regular_hyperslab (vspace, q_start, q_stride, q_count, q_block); + + // Verify the hyperslab parameters + for(int u = 0; u < 2; 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]); + assertTrue("H5Sget_regular_hyperslab, block", block[u] == q_block[u]); + } + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5.testH5Pget_mapping_parameters: " + err); + } + finally { + if (vspace > 0) + try {H5.H5Sclose(vspace);} catch (Exception ex) {} + } + } + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5Pget_mapping_parameters: " + err); + } + finally { + if (H5dssid > 0) + try {H5.H5Sclose(H5dssid);} catch (Exception ex) {} + if (H5did > 0) + try {H5.H5Dclose(H5did);} catch (Exception ex) {} + } + } + + @Test + public void testH5Pset_get_virtual_view() { + int ret_val = -1; + H5did = _createDataset(H5fid, H5dsid, "VDS", H5dcplid, H5dapl_id); + try { + ret_val = H5.H5Pget_virtual_view(H5dapl_id); + assertTrue("H5Pget_virtual_view", ret_val >= 0); + assertEquals(HDF5Constants.H5D_VDS_LAST_AVAILABLE, ret_val); + H5.H5Pset_virtual_view(H5dapl_id, HDF5Constants.H5D_VDS_FIRST_MISSING); + ret_val = H5.H5Pget_virtual_view(H5dapl_id); + assertTrue("H5Pget_virtual_view", ret_val >= 0); + assertEquals(HDF5Constants.H5D_VDS_FIRST_MISSING, ret_val); + } + catch (Throwable err) { + err.printStackTrace(); + fail("testH5Pset_get_virtual_view: " + err); + } + finally { + if (H5dssid > 0) + try {H5.H5Sclose(H5dssid);} catch (Exception ex) {} + if (H5did > 0) + try {H5.H5Dclose(H5did);} catch (Exception ex) {} + } + } + + @Ignore + public void testH5Pset_get_virtual_printf_gap() { + long ret_val = -1; + H5did = _createDataset(H5fid, H5dsid, "VDS", H5dcplid, H5dapl_id); + try { + ret_val = H5.H5Pget_virtual_printf_gap(H5dapl_id); + assertTrue("H5Pget_virtual_printf_gap", ret_val >= 0); + assertEquals(0, ret_val); + H5.H5Pset_virtual_printf_gap(H5dapl_id, 2); + ret_val = H5.H5Pget_virtual_view(H5dapl_id); + assertTrue("H5Pget_virtual_printf_gap", ret_val >= 0); + assertEquals(2, ret_val); + } + catch (Throwable err) { + err.printStackTrace(); + fail("H5Pset_get_virtual_printf_gap: " + err); + } + finally { + if (H5dssid > 0) + try {H5.H5Sclose(H5dssid);} catch (Exception ex) {} + if (H5did > 0) + try {H5.H5Dclose(H5did);} catch (Exception ex) {} + } + } +} |