summaryrefslogtreecommitdiffstats
path: root/java/test
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2016-02-29 02:43:00 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2016-02-29 02:43:00 (GMT)
commit63249be0e10a8726acb5a7cf64491319eaa46227 (patch)
treeebb2b75ece8852e8a58804631c0004f06a9bba9f /java/test
parenta1617b7cdbe14173fcf690b4627059fa4528c19b (diff)
downloadhdf5-63249be0e10a8726acb5a7cf64491319eaa46227.zip
hdf5-63249be0e10a8726acb5a7cf64491319eaa46227.tar.gz
hdf5-63249be0e10a8726acb5a7cf64491319eaa46227.tar.bz2
[svn-r29226] HDFFV-9552: merge in java code.
Diffstat (limited to 'java/test')
-rw-r--r--java/test/CMakeLists.txt114
-rw-r--r--java/test/JUnit-interface.txt652
-rw-r--r--java/test/Makefile.am103
-rw-r--r--java/test/TestAll.java40
-rw-r--r--java/test/TestH5.java257
-rw-r--r--java/test/TestH5A.java1119
-rw-r--r--java/test/TestH5D.java892
-rw-r--r--java/test/TestH5Dparams.java134
-rw-r--r--java/test/TestH5Dplist.java216
-rw-r--r--java/test/TestH5E.java553
-rw-r--r--java/test/TestH5Edefault.java564
-rw-r--r--java/test/TestH5Eregister.java78
-rw-r--r--java/test/TestH5F.java332
-rw-r--r--java/test/TestH5Fbasic.java320
-rw-r--r--java/test/TestH5Fparams.java215
-rw-r--r--java/test/TestH5G.java505
-rw-r--r--java/test/TestH5Gbasic.java371
-rw-r--r--java/test/TestH5Giterate.java136
-rw-r--r--java/test/TestH5Lbasic.java371
-rw-r--r--java/test/TestH5Lcreate.java819
-rw-r--r--java/test/TestH5Lparams.java231
-rw-r--r--java/test/TestH5Obasic.java488
-rw-r--r--java/test/TestH5Ocopy.java365
-rw-r--r--java/test/TestH5Ocreate.java562
-rw-r--r--java/test/TestH5Oparams.java154
-rw-r--r--java/test/TestH5P.java1221
-rw-r--r--java/test/TestH5PData.java170
-rw-r--r--java/test/TestH5Pfapl.java1325
-rw-r--r--java/test/TestH5R.java335
-rw-r--r--java/test/TestH5S.java590
-rw-r--r--java/test/TestH5Sbasic.java247
-rw-r--r--java/test/TestH5T.java459
-rw-r--r--java/test/TestH5Tbasic.java161
-rw-r--r--java/test/TestH5Tparams.java389
-rw-r--r--java/test/TestH5Z.java100
-rw-r--r--java/test/h5ex_g_iterate.hdfbin0 -> 2928 bytes
-rw-r--r--java/test/junit.sh.in234
37 files changed, 14822 insertions, 0 deletions
diff --git a/java/test/CMakeLists.txt b/java/test/CMakeLists.txt
new file mode 100644
index 0000000..2632b18
--- /dev/null
+++ b/java/test/CMakeLists.txt
@@ -0,0 +1,114 @@
+cmake_minimum_required (VERSION 3.1.0)
+PROJECT (HDF5_JAVA_TEST Java)
+
+set (CMAKE_VERBOSE_MAKEFILE 1)
+
+INCLUDE_DIRECTORIES (
+ ${HDF5_JAVA_JNI_BINARY_DIR}
+ ${HDF5_JAVA_HDF5_LIB_DIR}
+)
+
+set (HDF5_JAVA_TEST_SRCS
+ TestH5.java
+ TestH5E.java
+ TestH5Edefault.java
+ TestH5Eregister.java
+ TestH5Fparams.java
+ TestH5Fbasic.java
+ TestH5F.java
+ TestH5Gbasic.java
+ TestH5G.java
+ TestH5Giterate.java
+ TestH5Sbasic.java
+ TestH5S.java
+ TestH5Tparams.java
+ TestH5Tbasic.java
+ TestH5T.java
+ TestH5Dparams.java
+ TestH5D.java
+ TestH5Dplist.java
+ TestH5Lparams.java
+ TestH5Lbasic.java
+ TestH5Lcreate.java
+ TestH5R.java
+ TestH5P.java
+ TestH5PData.java
+ TestH5Pfapl.java
+ TestH5Pvirtual.java
+ TestH5Plist.java
+ TestH5A.java
+ TestH5Oparams.java
+ TestH5Obasic.java
+ TestH5Ocreate.java
+ TestH5Ocopy.java
+ TestH5PL.java
+ TestH5Z.java
+ TestAll.java
+)
+
+file (WRITE ${PROJECT_BINARY_DIR}/Manifest.txt
+"Main-Class: test.TestAll
+"
+)
+
+set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_LIB_DIR}/junit.jar;${HDF5_JAVA_LIB_DIR}/hamcrest-core.jar;${HDF5_JAVA_JARS};${HDF5_JAVA_LOGGING_JAR};${HDF5_JAVA_LOGGING_SIMPLE_JAR}")
+
+add_jar (${HDF5_JAVA_TEST_LIB_TARGET} MANIFEST ${PROJECT_BINARY_DIR}/Manifest.txt ${HDF5_JAVA_TEST_SRCS})
+
+get_target_property (${HDF5_JAVA_TEST_LIB_TARGET}_JAR_FILE ${HDF5_JAVA_TEST_LIB_TARGET} JAR_FILE)
+#install_jar (${HDF5_JAVA_TEST_LIB_TARGET} ${HJAVA_INSTALL_DATA_DIR}/tests tests)
+#get_target_property (${HDF5_JAVA_TEST_LIB_TARGET}_CLASSPATH ${HDF5_JAVA_TEST_LIB_TARGET} CLASSDIR)
+
+add_dependencies (${HDF5_JAVA_TEST_LIB_TARGET} ${HDF5_JAVA_HDF5_LIB_TARGET})
+set_target_properties (${HDF5_JAVA_TEST_LIB_TARGET} PROPERTIES FOLDER test/java)
+
+set (HDF_JAVA_TEST_FILES
+ h5ex_g_iterate.hdf
+ JUnit-interface.txt
+)
+
+foreach (h5_file ${HDF_JAVA_TEST_FILES})
+ set (dest "${PROJECT_BINARY_DIR}/${h5_file}")
+ #message (STATUS " Copying ${h5_file}")
+ add_custom_command (
+ TARGET ${HDF5_JAVA_TEST_LIB_TARGET}
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND}
+ ARGS -E copy_if_different ${PROJECT_SOURCE_DIR}/${h5_file} ${dest}
+ )
+endforeach (h5_file ${HDF_JAVA_TEST_FILES})
+
+if (WIN32)
+ set (CMAKE_JAVA_INCLUDE_FLAG_SEP ";")
+else (WIN32)
+ set (CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
+endif (WIN32)
+
+set (CMAKE_JAVA_CLASSPATH ".")
+foreach (CMAKE_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH})
+ set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${CMAKE_INCLUDE_PATH}")
+endforeach (CMAKE_INCLUDE_PATH)
+set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${HDF5_JAVA_TEST_LIB_TARGET}_JAR_FILE}")
+set (testfilter "OK (598 tests)")
+
+if (CMAKE_BUILD_TYPE MATCHES Debug)
+ set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=hdf5_java_debug;")
+endif(CMAKE_BUILD_TYPE MATCHES Debug)
+
+add_test (
+ NAME JUnit-interface
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}"
+ -D "TEST_CLASSPATH:STRING=${CMAKE_JAVA_CLASSPATH}"
+ -D "TEST_ARGS:STRING=${CMD_ARGS}-ea;org.junit.runner.JUnitCore"
+ -D "TEST_PROGRAM=test.TestAll"
+ -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_OUTPUT_DIRECTORY}"
+ -D "TEST_FOLDER=${HDF5_BINARY_DIR}/java/test"
+ -D "TEST_OUTPUT=JUnit-interface.out"
+# -D "TEST_LOG_LEVEL=trace"
+ -D "TEST_EXPECT=0"
+ -D "TEST_MASK_ERROR=TRUE"
+ -D "TEST_FILTER:STRING=${testfilter}"
+ -D "TEST_REFERENCE=JUnit-interface.txt"
+ -P "${HDF_RESOURCES_DIR}/jrunTest.cmake"
+)
diff --git a/java/test/JUnit-interface.txt b/java/test/JUnit-interface.txt
new file mode 100644
index 0000000..f065dd4
--- /dev/null
+++ b/java/test/JUnit-interface.txt
@@ -0,0 +1,652 @@
+JUnit version 4.11
+.testJ2C
+.testIsSerializable
+.testH5garbage_collect
+.testH5error_off
+.serializeToDisk
+.testH5open
+.testH5check_version
+.testH5get_libversion
+.testH5set_free_list_limits
+.testH5Eregister_class_lib_name_null
+.testH5Eregister_class_version_null
+.testH5Eunregister_class_invalid_classid
+.testH5Eregister_class
+.testH5Eregister_class_cls_name_null
+.testH5EprintInt
+.testH5Eset_current_stack_invalid_stkid
+.testH5Eset_current_stack
+.testH5Eget_num
+.testH5Eclear
+.testH5Eprint
+.testH5Epush_null_name
+.testH5Eget_num_with_msg
+.testH5Eclear2_with_msg
+.testH5Epush_invalid_stkid
+.testH5Eget_current_stack
+.testH5Ecreate_stack
+.testH5Eget_msg_invalid_msgid
+.testH5Eauto_is_v2
+.testH5EclearInt
+.testH5Eauto_is_v2_invalid_stkid
+.testH5Eclose_msg_invalid_errid
+.testH5Eclose_stack_invalid_stackid
+.testH5Eget_class_name_invalid_classname
+.testH5Eget_num_invalid_stkid
+.testH5EprintInt_invalid_classid
+.testH5Epop
+.testH5Epop_invalid_stkid
+.testH5Eget_current_stack_pop
+.testH5Eget_class_name_invalid_classid
+.testH5Ecreate_msg_invalid_errid
+.testH5Eclear2_invalid_stkid
+.testH5Eprint2_invalid_classid
+.testH5EprintInt
+.testH5Eget_msg_major
+.testH5Eget_msg_minor
+.testH5Eget_msg
+.testH5Eget_num
+.testH5Epush
+.testH5Ewalk
+.testH5Eget_class_name
+.testH5Eget_num_with_msg
+.testH5Eclear2
+.testH5Eprint2
+.testH5Ecreate_msg_major
+.testH5Ecreate_msg_minor
+.testH5Ecreate_stack
+.testH5Ecreate_msg_name_null
+.testH5Eauto_is_v2
+.testH5EclearInt
+.testH5Epop
+.testH5Fcreate_null
+.testH5Fflush_local
+.testH5Fget_info
+.testH5Fmount_null
+.testH5Fcreate
+.testH5Fflush_global
+.testH5Funmount_null
+.testH5Fclose_negative
+.testH5Fopen_null
+.testH5Fis_hdf5_null
+.testH5Fis_hdf5_text
+.testH5Fget_mdc_size
+.testH5Fget_mdc_hit_rate
+.testH5Fis_hdf5
+.testH5Fget_freespace
+.testH5Fclose
+.testH5Fget_filesize
+.testH5Fcreate_EXCL
+.testH5Freopen_closed
+.testH5Freset_mdc_hit_rate_stats
+.testH5Fget_name
+.testH5Fcreate
+.testH5Fclear_elink_file_cache
+.testH5Fclose_twice
+.testH5Freopen
+.testH5Fopen_read_only
+.testH5Fget_access_plist
+.testH5Fget_obj_ids
+.testH5Fget_intent_rdwr
+.testH5Fget_access_plist_closed
+.testH5Fget_create_plist_closed
+.testH5Fget_intent_rdonly
+.testH5Fget_create_plist
+.testH5Fget_obj_count
+.testH5Gget_info_by_name_not_exists
+.testH5Gget_info_by_idx_not_exists
+.testH5Gget_info_by_name
+.testH5Gget_create_plist
+.testH5Gopen
+.testH5Gget_info_by_idx_null
+.testH5Gopen_not_exists
+.testH5Gclose
+.testH5Gcreate_anon
+.testH5Gcreate_null
+.testH5Gget_info_by_idx_fileid
+.testH5Gclose_invalid
+.testH5Gopen_invalid
+.testH5Gget_info_invalid
+.testH5Gcreate_invalid
+.testH5Gcreate_exists
+.testH5Gget_info_by_name_null
+.testH5Gget_info_by_name_invalid
+.testH5Gget_create_plist_invalid
+.testH5Gcreate
+.testH5Gget_info_by_name_fileid
+.testH5Gget_info_by_idx_invalid
+.testH5Gopen_null
+.testH5Gget_info_by_idx
+.testH5Gget_info
+.testH5Gget_info_by_name
+.testH5Gget_create_plist
+.testH5Gopen
+.testH5Gget_obj_info_all_gid2
+.testH5Gget_obj_info_all_byIndexType
+.testH5Gget_obj_info_max_limit
+.testH5Gget_obj_info_all
+.testH5Gget_obj_info_max
+.testH5Gget_obj_info_all_gid
+.testH5Gget_info_by_idx
+.testH5Gget_info
+.testH5Gget_obj_info_all
+.testH5Sclose_invalid
+.testH5Screate_simple_max_default
+.testH5Screate_simple_dims_null
+.testH5Sdecode_null
+.testH5Screate_simple_dims_exceed
+.testH5Screate_simple_unlimted_1d
+.testH5Screate_simple_dims_invalid
+.testH5Screate_scalar
+.testH5Screate_simple
+.testH5Screate_simple_rank_invalid
+.testH5Sget_simple_extent_type_invalid
+.testH5Sencode_invalid
+.testH5Screate_null
+.testH5Screate_simple_extent
+.testH5Screate_invalid
+.testH5Screate_simple_unlimted
+.testH5Sget_select_npoints
+.testH5Sget_select_type
+.testH5Sset_extent_simple
+.testH5Sget_select_hyper
+.testH5Sget_select_valid
+.testH5Sget_select_elem_pointlist
+.testH5Sset_extent_none
+.testH5Sencode_decode_scalar_dataspace
+.testH5Soffset_simple
+.testH5Scopy
+.testH5Sget_simple_extent_ndims
+.testH5Sextent_equal
+.testH5Sget_simple_extent_dims
+.testH5Sget_simple_extent_type
+.testH5Shyper_regular
+.testH5Sget_select_bounds
+.testH5Sget_select_elem_pointlist_invalid
+.testH5Sget_simple_extent_npoints
+.testH5Sextent_copy
+.testH5Sencode_decode_null_dataspace
+.testH5Sis_simple
+.testH5Sget_simple_extent_dims_null
+.testH5Sselect_none
+.testH5Tget_member_type_invalid
+.testH5Tenum_insert_null
+.testH5Tget_offset_invalid
+.testH5Tset_precision_invalid
+.testH5Tget_inpad_invalid
+.testH5Tenum_nameof_invalid
+.testH5Tget_member_value_invalid
+.testH5Tenum_nameof_value_null
+.testH5Tcreate_invalid
+.testH5Tget_strpad_invalid
+.testH5Tenum_valueof_invalid
+.testH5Tget_fields_null
+.testH5Topen_null
+.testH5Tpack_invalid
+.testH5Tcommit_null
+.testH5Tinsert_invalid
+.testH5Tenum_valueof_null
+.testH5Tset_norm_invalid
+.testH5Tlock_invalid
+.testH5Tarray_create_invalid
+.testH5Tget_member_value_null
+.testH5Tset_offset_invalid
+.testH5Tget_fields_invalid
+.testH5Tequal_invalid
+.testH5Tget_ebias_long_invalid
+.testH5Tget_cset_invalid
+.testH5Tget_size_invalid
+.testH5Tset_strpad_invalid
+.testH5Tset_ebias_invalid
+.testH5Tget_sign_invalid
+.testH5Tget_member_index_invalid
+.testH5Tget_precision_invalid
+.testH5Tset_fields_invalid
+.testH5Tcopy_invalid
+.testH5Tget_pad_invalid
+.testH5Tset_order_invalid
+.testH5Tget_member_class_invalid
+.testH5Tget_super_invalid
+.testH5Tget_class_invalid
+.testH5Topen_invalid
+.testH5Tget_precision_long_invalid
+.testH5Tget_ebias_invalid
+.testH5Tget_native_type_invalid
+.testH5Tget_fields_length_invalid
+.testH5Tget_norm_invalid
+.testH5Tenum_nameof_invalid_size
+.testH5Tset_pad_invalid
+.testH5Tget_pad_null
+.testH5Tset_tag_null
+.testH5Tget_order_invalid
+.testH5Tcommit_invalid
+.testH5Tget_array_ndims_invalid
+.testH5Tset_tag_invalid
+.testH5Tvlen_create_invalid
+.testH5Tenum_create_invalid
+.testH5Tinsert_null
+.testH5Tset_inpad_invalid
+.testH5Tenum_valueof_name_null
+.testH5Tset_cset_invalid
+.testH5Tclose_invalid
+.testH5Tget_nmembers_invalid
+.testH5Tarray_create_value_null
+.testH5Tset_size_invalid
+.testH5Tenum_insert_invalid
+.testH5Tget_array_dims_null
+.testH5Tget_member_index_null
+.testH5Tset_sign_invalid
+.testH5Tenum_insert_name_null
+.testH5Tequal_not
+.testH5Tcopy
+.testH5Tequal
+.testH5Torder_size
+.testH5Tconvert
+.testH5Tvlen_create
+.testH5Tenum_create_functions
+.testH5Tenum_functions
+.testH5Tget_class
+.testH5Tget_array_ndims
+.testH5Tequal_type_error
+.testH5Tget_array_dims
+.testH5Tset_size
+.testH5Tis_variable_str
+.testH5Tcompound_functions
+.testH5Tget_size
+.testH5Tarray_create
+.testH5Topaque_functions
+.testH5Dget_space_status_invalid
+.testH5Dget_access_plist_invalid
+.testH5Dget_type_invalid
+.testH5Dget_create_plist_invalid
+.testH5Dget_offset_invalid
+.testH5Dvlen_get_buf_size_invalid
+.testH5Dcreate_null
+.testH5Dset_extent_status_null
+.testH5Dvlen_reclaim_null
+.testH5Dcreate_invalid
+.testH5Dcreate_anon_invalid
+.testH5Dset_extent_status_invalid
+.testH5Dvlen_reclaim_invalid
+.testH5Dopen_invalid
+.testH5Dclose_invalid
+.testH5Dget_storage_size_invalid
+.testH5Dget_space_invalid
+.testH5Dopen_null
+.testH5Dget_storage_size
+.testH5Diterate_write
+.testH5Dcreate
+.testH5Dget_offset
+.testH5Dget_type
+.testH5Dfill
+.testH5Dopen
+.testH5Dcreate_anon
+.testH5Dfill_null
+.testH5Dget_storage_size_empty
+.testH5Diterate
+.testH5Dget_access_plist
+.testH5Dvlen_read_invalid_buffer
+.testH5Dvlen_get_buf_size
+.testH5Dget_space_closed
+.testH5Dget_space_status
+.testH5Dvlen_write_read
+.testH5Dget_space
+.testH5Dget_type_closed
+.testH5Dset_extent
+.testH5Lcopy_invalid
+.testH5Lget_value_by_idx_null
+.testH5Lcreate_external_invalid
+.testH5Lexists_null
+.testH5Lget_info_invalid
+.testH5Lget_name_by_idx_invalid
+.testH5Lmove_null_current
+.testH5Literate_by_name_nullname
+.testH5Lvisit_by_name_nullname
+.testH5Lvisit_null
+.testH5Lget_name_by_idx_null
+.testH5Lcreate_hard_null_dest
+.testH5Lget_value_null
+.testH5Lcreate_external_null_dest
+.testH5Lcreate_external_null_file
+.testH5Lcreate_external_null_current
+.testH5Ldelete_null
+.testH5Lexists_invalid
+.testH5Lmove_invalid
+.testH5Lcreate_hard_invalid
+.testH5Lcopy_null_dest
+.testH5Lcreate_soft_null_current
+.testH5Lcopy_null_current
+.testH5Lget_info_by_idx_null
+.testH5Literate_null
+.testH5Ldelete_invalid
+.testH5Lvisit_by_name_null
+.testH5Ldelete_by_idx_invalid
+.testH5Lget_info_by_idx_invalid
+.testH5Ldelete_by_idx_null
+.testH5Lcreate_soft_invalid
+.testH5Lcreate_hard_null_current
+.testH5Lget_value_by_idx_invalid
+.testH5Lmove_null_dest
+.testH5Lget_info_null
+.testH5Literate_by_name_null
+.testH5Lcreate_soft_null_dest
+.testH5Lget_value_invalid
+.testH5Lget_info_by_idx_not_exist_name
+.testH5Lget_name_by_idx_not_exist
+.testH5Lvisit
+.testH5Lget_name_by_idx_n0
+.testH5Lget_name_by_idx_n3
+.testH5Lvisit_by_name
+.testH5Literate_by_name
+.testH5Lget_info_hardlink
+.testH5Literate
+.testH5Lget_info_by_idx_n0
+.testH5Lget_info_by_idx_n3
+.testH5Lget_info_by_idx_name_not_exist_create
+.testH5Lexists
+.testH5Lget_info_by_idx_name_not_exist_name
+.testH5Lget_info_by_idx_not_exist_create
+.testH5Lget_info_not_exist
+.testH5Lget_info_dataset
+.testH5Lget_info_by_idx_n0_create
+.testH5Ldelete_soft_link_dangle
+.testH5Lget_value_by_idx_external_create
+.testH5Ldelete_by_idx_not_exist_create
+.testH5Lvisit_create
+.testH5Lmove_dst_link_exists
+.testH5Lcreate_soft_dangle
+.testH5Literate_create
+.testH5Lcopy_cur_not_exists
+.testH5Lcopy
+.testH5Lmove
+.testH5Lget_value_by_idx_n2_create
+.testH5Lget_value_soft
+.testH5Ldelete_by_idx_n2_name
+.testH5Lget_info_by_idx_n1_create
+.testH5Lcreate_external
+.testH5Lget_value_dangle
+.testH5Lcreate_hard_dst_link_exists
+.testH5Lget_value_by_idx_n2_name
+.testH5Lcreate_soft_dst_link_exists
+.testH5Lcreate_hard
+.testH5Lcreate_soft
+.testH5Lmove_cur_not_exists
+.testH5Lcreate_hard_cur_not_exists
+.testH5Lget_info_softlink_dangle
+.testH5Ldelete_by_idx_n2_create
+.testH5Ldelete_soft_link
+.testH5Lget_info_externallink
+.testH5Lcopy_dst_link_exists
+.testH5Lget_value_by_idx_external_name
+.testH5Ldelete_by_idx_not_exist_name
+.testH5Lget_info_softlink
+.testH5Lget_value_external
+.testH5Lget_value_by_idx_not_exist_create
+.testH5Lget_value_by_idx_not_exist_name
+.testH5Ldelete_hard_link
+.testH5Rgetregion_Nullreference
+.testH5Rget_obj_type2_Invalidreftype
+.testH5Rdereference
+.testH5Rget_name
+.testH5Rcreate_Invalidreftype
+.testH5Rget_name_NULLreference
+.testH5Rget_region
+.testH5Rdereference_Nullreference
+.testH5Rcreate_refobj
+.testH5Rcreate_Invalidspace_id
+.testH5Rdereference_Invalidreference
+.testH5Rgetregion_Badreferencetype
+.testH5Rcreate_regionrefobj
+.testH5Rget_name_Invalidreftype
+.testH5Rgetregion_Invalidreftype
+.testH5Rget_obj_type2
+.testH5Rcreate_InvalidObjectName
+.testH5Pset_nbit
+.testH5Pset_shared_mesg_index_InvalidFlag
+.testH5Pset_shared_mesg_phase_change
+.testH5PH5Pset_shared_mesg_phase_change_HighMaxlistValue
+.testH5P_layout
+.testH5Pget_link_creation_order
+.testH5Pset_shared_mesg_nindexes_InvalidHIGHnindexes
+.testH5Pget_shared_mesg_index_Invalid_indexnum
+.testH5Pset_data_transform_NullExpression
+.testH5Pset_elink_prefix_null
+.testH5Pget_elink_prefix
+.testH5Pget_nlinks
+.testH5Pset_libver_bounds_invalidhigh
+.testH5Pget_char_encoding
+.testH5P_istore_k
+.testH5Pget_link_phase_change
+.testH5Pset_link_phase_change_max_compactLESSTHANmin_dense
+.testH5Pget_shared_mesg_phase_change_EqualsSET
+.testH5Pset_scaleoffset_Invalidscale_type
+.testH5Pget_istore_k_null
+.testH5Pset_libver_bounds_invalidlow
+.testH5Pset_est_link_info
+.testH5Pget_link_phase_change_Null
+.testH5P_fill_time
+.testH5Pget_userblock_null
+.testH5Pset_link_creation_order_tracked
+.testH5Pset_shared_mesg_index
+.testH5Pset_copy_object
+.testH5Pset_link_creation_order_trackedPLUSindexed
+.testH5Pset_copy_object_invalidobject
+.testH5Pset_est_link_info_InvalidValues
+.testH5P_file_space
+.testH5Pset_local_heap_size_hint
+.testH5Pget_est_link_info
+.testH5Pset_scaleoffset
+.testH5Pset_create_intermediate_group_invalidobject
+.testH5PH5Pset_shared_mesg_phase_change_HighMinbtreeValue
+.testH5Pset_create_intermediate_group
+.testH5P_alloc_time
+.testH5Pset_elink_acc_flags
+.testH5Pset_link_phase_change_Highmax_Compact
+.testH5P_chunk
+.testH5P_sizes
+.testH5Pset_link_creation_order_invalidvalue
+.testH5P_sym_k
+.testH5PH5Pset_shared_mesg_phase_change_MinbtreeGreaterThanMaxlist
+.testH5Pget_version_null
+.testH5Pset_scaleoffset_Invalidscale_factor
+.testH5Pget_elink_prefix_null
+.testH5Pget_data_transform_IllegalSize
+.testH5Pget_create_intermediate_group
+.testH5Pset_shared_mesg_nindexes
+.testH5Pset_attr_creation_order_trackedPLUSindexed
+.testH5Pget_sym_k_null
+.testH5Pset_nlinks
+.testH5P_obj_track_times
+.testH5P_userblock
+.testH5Pget_local_heap_size_hint
+.testH5Pset_shared_mesg_index_Invalid_indexnum
+.testH5Pset_data_transform_InvalidExpression1
+.testH5Pset_data_transform_InvalidExpression2
+.testH5Pget_attr_phase_change
+.testH5Pget_data_transform
+.testH5Pget_create_intermediate_group_notcreated
+.testH5Pset_elink_prefix
+.testH5Pget_attr_creation_order
+.testH5Pset_attr_creation_order_invalidvalue
+.testH5Pget_shared_mesg_phase_change
+.testH5Pget_shared_mesg_index
+.testH5Pset_link_phase_change
+.testH5Pget_shared_mesg_nindexes
+.testH5Pget_version
+.testH5Pset_elink_acc_flags_InvalidFlag1
+.testH5Pset_elink_acc_flags_InvalidFlag2
+.testH5Pget_link_phase_change_EqualsSet
+.testH5Pget_elink_acc_flags
+.testH5Pget_data_transform_ExpressionNotSet
+.testH5P_fill_value
+.testH5Pget_sizes_null
+.testH5Pset_data_transform
+.testH5Pset_attr_creation_order_tracked
+.testH5P_buffer
+.testH5Pdata_transform
+.testH5P_elink_fapl
+.testH5P_fapl_direct
+.testH5P_alignment
+.testH5P_fapl_family
+.testH5P_chunk_cache
+.testH5P_meta_block_size
+.testH5Pget_elink_fapl
+.testH5Pset_mdc_config
+.testH5P_small_data_block_size
+.testH5Pset_fapl_log
+.testH5Pset_libver_bounds
+.testH5P_sieve_buf_size
+.testH5P_elink_file_cache_size
+.testH5P_cache
+.testH5Pget_mdc_config
+.testH5P_fapl_muti_defaults
+.testH5Pget_libver_bounds
+.testH5P_btree_ratios
+.testH5P_fapl_muti_nulls
+.testH5Pset_fapl_sec2
+.testH5Pmulti_transform
+.testH5Pset_elink_fapl_NegativeID
+.testH5Pset_fapl_stdio
+.testH5P_edc_check
+.testH5Pset_elink_fapl
+.testH5P_hyper_vector_size
+.testH5P_gc_references
+.testH5P_family_offset
+.testH5P_fapl_core
+.testH5P_fapl_muti
+.testH5P_fapl_split
+.testH5Pset_fapl_windows
+.testH5P_fclose_degree
+.testH5Pget_source_datasetname
+.testH5Pvirtual_storage
+.testH5Pget_selection_source_dataset
+.testH5Pget_source_filename
+.testH5Pget_virtual_count
+.testH5Pset_get_virtual_view
+.testH5Pget_mapping_parameters
+.testH5P_genprop_basic_class
+.testH5P_genprop_class_iter
+.testH5P_genprop_basic_class_prop
+.testH5P_genprop_basic_list_prop
+.testH5Acreate2_nullname
+.testH5Acreate_by_name
+.testH5Aget_name_by_idx
+.testH5Aget_storage_size
+.testH5Aiterate
+.testH5Aopen_by_idx
+.testH5Aopen_invalidname
+.testH5Aopen
+.testH5Aget_info_by_name
+.testH5Aget_create_plist
+.testH5Adelete_by_name
+.testH5Aopen_by_name
+.testH5Aget_info
+.testH5Aget_name
+.testH5Aexists
+.testH5Aget_info_by_idx
+.testH5Arename
+.testH5Adelete_by_idx_name1
+.testH5Adelete_by_idx_name2
+.testH5Adelete_by_idx_order
+.testH5Arename_by_name
+.testH5Acreate2_invalidobject
+.testH5Acreate2
+.testH5Aiterate_by_name
+.testH5Adelete_by_idx_null
+.testH5Adelete_by_idx_invalidobject
+.testH5Awrite_readVL
+.testH5Aget_info1
+.testH5Oget_comment_by_name_null
+.testH5Ovisit_by_name_nullname
+.testH5Oget_info_invalid
+.testH5Ovisit_by_name_null
+.testH5Oget_comment_invalid
+.testH5Oset_comment_by_name_invalid
+.testH5Oopen_null
+.testH5Oclose_invalid
+.testH5Oget_comment_by_name_invalid
+.testH5Ocopy_null_dest
+.testH5Olink_invalid
+.testH5Oget_info_by_idx_invalid
+.testH5Oget_info_by_idx_null
+.testH5Olink_null_dest
+.testH5Oget_info_by_name_invalid
+.testH5Oget_info_by_name_null
+.testH5Ocopy_invalid
+.testH5Oset_comment_by_name_null
+.testH5Ocopy_null_current
+.testH5Oset_comment_invalid
+.testH5Oopen_invalid
+.testH5Ovisit_null
+.testH5Oexists_by_name
+.testH5Oget_info_by_idx_n0
+.testH5Oget_info_by_idx_n3
+.testH5Oget_info_by_name_not_exist_name
+.testH5Ovisit_by_name
+.testH5Oget_info_by_idx_name_not_exist_name
+.testH5Oget_info_datatype
+.testH5Oget_info_by_idx_not_exist_name
+.testH5Oopen_by_idx_n0
+.testH5Oopen_by_idx_n3
+.testH5Oopen_not_exists
+.testH5Ovisit
+.testH5Oget_info_by_idx_not_exist_create
+.testH5Oget_info_by_name_hardlink
+.testH5Oget_info_by_name_group
+.testH5Oopen_by_addr
+.testH5Oget_info_by_name_not_exists
+.testH5Oget_info_by_name_dataset
+.testH5Oget_info_group
+.testH5Oget_info_by_name_datatype
+.testH5Oget_info_hardlink
+.testH5Oget_info_by_idx_name_not_exist_create
+.testH5Oget_info_dataset
+.testH5OcopyRefsDatasettosameFile
+.testH5OcopyRefsDatasettodiffFile
+.testH5OcopyRefsAttr
+.testH5Oget_info_by_idx_n0_create
+.testH5Oget_info_softlink_dangle
+.testH5Oget_info_softlink
+.testH5Oget_info_externallink
+.testH5Ocopy
+.testH5Olink
+.testH5Ocomment_by_name
+.testH5Oget_info_by_idx_n1_create
+.testH5Ocomment
+.testH5Oinc_dec_count
+.testH5Ocomment_by_name_clear
+.testH5Ovisit_create
+.testH5Ocopy_dst_link_exists
+.testH5Ocomment_clear
+.testH5Ocopy_cur_not_exists
+.TestH5PLplugins
+.testH5Zfilter_avail
+.testH5Zunregister_predefined
+.testH5Zget_filter_info
+
+Time: XXXX
+
+OK (624 tests)
+
+HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs):
+ #000: (file name) line (number) in H5Fopen(): can't set access and transfer property lists
+ major: File accessibilty
+ minor: Can't set value
+ #001: (file name) line (number) in H5P_verify_apl_and_dxpl(): not the required access property list
+ major: Property lists
+ minor: Inappropriate type
+ #002: (file name) line (number) in H5P_isa_class(): not a property list
+ major: Invalid arguments to routine
+ minor: Inappropriate type
+HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs):
+ #000: (file name) line (number) in H5Fopen(): can't set access and transfer property lists
+ major: File accessibilty
+ minor: Can't set value
+ #001: (file name) line (number) in H5P_verify_apl_and_dxpl(): not the required access property list
+ major: Property lists
+ minor: Inappropriate type
+ #002: (file name) line (number) in H5P_isa_class(): not a property list
+ major: Invalid arguments to routine
+ minor: Inappropriate type
+[main] INFO hdf.hdf5lib.H5 - HDF5 library: hdf5_java
+[main] INFO hdf.hdf5lib.H5 - successfully loaded from java.library.path
diff --git a/java/test/Makefile.am b/java/test/Makefile.am
new file mode 100644
index 0000000..1cb41df
--- /dev/null
+++ b/java/test/Makefile.am
@@ -0,0 +1,103 @@
+#
+# 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.
+##
+## Makefile.am
+## Run automake to generate a Makefile.in from this file.
+##
+#
+# HDF5 Java native interface (JNI) Library Test Makefile(.in)
+
+include $(top_srcdir)/config/commence.am
+
+# Mark this directory as part of the JNI API
+JAVA_API=yes
+
+JAVAROOT = .classes
+
+classes:
+ $(MKDIR_P) $(@D)/$(JAVAROOT)
+
+pkgpath = test
+hdfjarfile = jar$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).jar
+jarfile = jar$(PACKAGE_TARNAME)test.jar
+
+CLASSPATH_ENV=CLASSPATH=.:$(JAVAROOT):$(top_builddir)/java/src/$(hdfjarfile):$(top_srcdir)/java/lib/junit.jar:$(top_srcdir)/java/lib/hamcrest-core.jar:$(top_srcdir)/java/lib/slf4j-api-1.7.5.jar:$(top_srcdir)/java/lib/ext/slf4j-simple-1.7.5.jar:$$CLASSPATH
+AM_JAVACFLAGS = $(H5_JAVACFLAGS) -deprecation
+
+noinst_JAVA = \
+ TestH5.java \
+ TestH5E.java \
+ TestH5Edefault.java \
+ TestH5Eregister.java \
+ TestH5Fparams.java \
+ TestH5Fbasic.java \
+ TestH5F.java \
+ TestH5Gbasic.java \
+ TestH5G.java \
+ TestH5Giterate.java \
+ TestH5Sbasic.java \
+ TestH5S.java \
+ TestH5Tparams.java \
+ TestH5Tbasic.java \
+ TestH5T.java \
+ TestH5Dparams.java \
+ TestH5D.java \
+ TestH5Dplist.java \
+ TestH5Lparams.java \
+ TestH5Lbasic.java \
+ TestH5Lcreate.java \
+ TestH5R.java \
+ TestH5P.java \
+ TestH5PData.java \
+ TestH5Pfapl.java \
+ TestH5Pvirtual.java \
+ TestH5Plist.java \
+ TestH5A.java \
+ TestH5Oparams.java \
+ TestH5Obasic.java \
+ TestH5Ocreate.java \
+ TestH5Ocopy.java \
+ TestH5PL.java \
+ TestH5Z.java \
+ TestAll.java
+
+$(jarfile): classnoinst.stamp classes
+ $(JAR) cvf $@ -C $(JAVAROOT)/ $(pkgpath)
+
+noinst_DATA = $(jarfile)
+
+.PHONY: classes
+
+check_SCRIPTS = junit.sh
+TEST_SCRIPT = $(check_SCRIPTS)
+
+CLEANFILES = classnoinst.stamp $(jarfile) $(JAVAROOT)/$(pkgpath)/*.class junit.sh
+
+#JAVA_JUNIT = $(JAVA_SRCS)
+#noinst_JAVA = @JAVA_JUNIT@
+#EXTRA_JAVA = $(JAVA_JUNIT)
+TESTS_JUNIT = AllJunitTests
+#EXTRA_TEST = $(TESTS_JUNIT)
+
+AllJunitTests :
+ echo "#! /bin/sh" > $@
+ echo "exec @JUNIT@ test.TestAll" >> $@
+ chmod +x $@
+
+clean:
+ rm -rf $(JAVAROOT)
+ rm -f $(jarfile)
+ rm -f classnoinst.stamp
+
+include $(top_srcdir)/config/conclude.am
diff --git a/java/test/TestAll.java b/java/test/TestAll.java
new file mode 100644
index 0000000..e3abe21
--- /dev/null
+++ b/java/test/TestAll.java
@@ -0,0 +1,40 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( { TestH5.class,
+ TestH5Eregister.class,
+ TestH5Edefault.class,
+ TestH5E.class,
+ TestH5Fparams.class, TestH5Fbasic.class, TestH5F.class,
+ TestH5Gbasic.class, TestH5G.class, TestH5Giterate.class,
+ TestH5Sbasic.class, TestH5S.class,
+ TestH5Tparams.class, TestH5Tbasic.class, TestH5T.class,
+ TestH5Dparams.class, TestH5D.class, TestH5Dplist.class,
+ TestH5Lparams.class, TestH5Lbasic.class, TestH5Lcreate.class,
+ TestH5R.class,
+ TestH5P.class, TestH5PData.class, TestH5Pfapl.class, TestH5Pvirtual.class, TestH5Plist.class,
+ TestH5A.class,
+ TestH5Oparams.class, TestH5Obasic.class, TestH5Ocopy.class, TestH5Ocreate.class,
+ TestH5PL.class, TestH5Z.class
+})
+
+public class TestAll {
+}
diff --git a/java/test/TestH5.java b/java/test/TestH5.java
new file mode 100644
index 0000000..1a78bea
--- /dev/null
+++ b/java/test/TestH5.java
@@ -0,0 +1,257 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+
+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;
+
+/**
+ * @author xcao
+ *
+ */
+public class TestH5 {
+ @Rule public TestName testname = new TestName();
+ @Before
+ public void showTestName() {
+ System.out.print(testname.getMethodName());
+ }
+ @After
+ public void nextTestName() {
+ System.out.println();
+ }
+
+ /**
+ * Test method for {@link hdf.hdf5lib.H5#J2C(int)}.
+ * NOTE:
+ * H5F_ACC_DEBUG no longer prints any special debug info. The symbol is
+ * being retained and will be listed as deprecated in HDF5 1.10.0.
+ */
+ @Test
+ public void testJ2C() {
+ int H5F_ACC_RDONLY = 0x0000;
+ int H5F_ACC_RDWR = 0x0001;
+ int H5F_ACC_TRUNC = 0x0002;
+ int H5F_ACC_EXCL = 0x0004;
+ int H5F_ACC_DEBUG = 0x0000; // HDFFV-1074 was 0x0008;
+ int H5F_ACC_CREAT = 0x0010;
+ int H5F_OBJ_FILE = 0x0001;
+ int H5F_OBJ_DATASET = 0x0002;
+ int H5F_OBJ_GROUP = 0x0004;
+ int H5F_OBJ_DATATYPE = 0x0008;
+ int H5F_OBJ_ATTR = 0x0010;
+ int H5F_OBJ_ALL = H5F_OBJ_FILE | H5F_OBJ_DATASET | H5F_OBJ_GROUP
+ | H5F_OBJ_DATATYPE | H5F_OBJ_ATTR;
+ int H5F_OBJ_LOCAL = 0x0020;
+
+ int definedValues[] = { H5F_ACC_RDONLY, H5F_ACC_RDWR, H5F_ACC_TRUNC,
+ H5F_ACC_EXCL, H5F_ACC_DEBUG, H5F_ACC_CREAT, H5F_OBJ_FILE,
+ H5F_OBJ_DATASET, H5F_OBJ_GROUP, H5F_OBJ_DATATYPE, H5F_OBJ_ATTR,
+ H5F_OBJ_ALL, H5F_OBJ_LOCAL };
+
+ int j2cValues[] = { HDF5Constants.H5F_ACC_RDONLY,
+ HDF5Constants.H5F_ACC_RDWR, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5F_ACC_EXCL, H5F_ACC_DEBUG,
+ HDF5Constants.H5F_ACC_CREAT, HDF5Constants.H5F_OBJ_FILE,
+ HDF5Constants.H5F_OBJ_DATASET, HDF5Constants.H5F_OBJ_GROUP,
+ HDF5Constants.H5F_OBJ_DATATYPE, HDF5Constants.H5F_OBJ_ATTR,
+ HDF5Constants.H5F_OBJ_ALL, HDF5Constants.H5F_OBJ_LOCAL };
+
+ for (int i = 0; i < definedValues.length; i++) {
+ assertEquals(definedValues[i], j2cValues[i]);
+ }
+
+ assertFalse(H5F_ACC_RDONLY == HDF5Constants.H5F_ACC_RDWR);
+ assertFalse(H5F_OBJ_FILE == HDF5Constants.H5F_OBJ_GROUP);
+ }
+
+ /**
+ * Test method for {@link hdf.hdf5lib.H5#H5error_off()}.
+ */
+ @Test
+ public void testH5error_off() {
+ try {
+ H5.H5error_off();
+ }
+ catch (Throwable err) {
+ fail("H5.H5error_off failed: " + err);
+ }
+ }
+
+ /**
+ * Test method for {@link hdf.hdf5lib.H5#H5open()}.
+ */
+ @Test
+ public void testH5open() {
+ try {
+ H5.H5open();
+ }
+ catch (Throwable err) {
+ fail("H5.H5open failed: " + err);
+ }
+ }
+
+ /**
+ * Test method for {@link hdf.hdf5lib.H5#H5garbage_collect()}.
+ */
+ @Test
+ public void testH5garbage_collect() {
+ try {
+ H5.H5garbage_collect();
+ }
+ catch (Throwable err) {
+ fail("H5.H5garbage_collect failed: " + err);
+ }
+ }
+
+ /**
+ * Test method for
+ * {@link hdf.hdf5lib.H5#H5set_free_list_limits(int, int, int, int, int, int)}
+ * .
+ */
+ @Test
+ public void testH5set_free_list_limits() {
+ int reg_global_lim = 1;
+ int reg_list_lim = 1;
+ int arr_global_lim = 1;
+ int arr_list_lim = 1;
+ int blk_global_lim = 1;
+ int blk_list_lim = 1;
+
+ try {
+ H5.H5set_free_list_limits(reg_global_lim, reg_list_lim,
+ arr_global_lim, arr_list_lim, blk_global_lim, blk_list_lim);
+ }
+ catch (Throwable err) {
+ fail("H5.H5set_free_list_limits failed: " + err);
+ }
+ }
+
+ /**
+ * Test method for {@link hdf.hdf5lib.H5#H5get_libversion(int[])}.
+ */
+ @Test
+ public void testH5get_libversion() {
+ int libversion[] = { 1, 9, 0 };
+
+ try {
+ H5.H5get_libversion(libversion);
+ }
+ catch (Throwable err) {
+ fail("H5.H5get_libversion: " + err);
+ }
+
+ for (int i = 0; i < 2; i++)
+ assertEquals(H5.LIB_VERSION[i], libversion[i]);
+
+ for (int i = 0; i < 2; i++)
+ assertFalse(libversion[i] == 0);
+ }
+
+ /**
+ * Test method for
+ * {@link hdf.hdf5lib.H5#H5check_version(int, int, int)}.
+ */
+ @Test
+ public void testH5check_version() {
+ int majnum = 1, minnum = 9, relnum = 0;
+
+ try {
+ H5.H5check_version(majnum, minnum, relnum);
+ }
+ catch (Throwable err) {
+ fail("H5.H5check_version failed: " + err);
+ }
+
+ try {
+ H5.H5check_version(-1, 0, 0);
+ }
+ catch (Throwable err) {
+ fail("H5.H5check_version failed: " + err);
+ }
+ }
+
+ @Test
+ public void testIsSerializable() {
+ H5 test = new H5();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ObjectOutputStream oos;
+ try {
+ oos = new ObjectOutputStream(out);
+ oos.writeObject(test);
+ oos.close();
+ }
+ catch (IOException err) {
+ err.printStackTrace();
+ fail("ObjectOutputStream failed: " + err);
+ }
+ assertTrue(out.toByteArray().length > 0);
+
+ }
+
+ @SuppressWarnings("static-access")
+ @Test
+ public void serializeToDisk()
+ {
+ try {
+ H5 test = new H5();
+
+ FileOutputStream fos = new FileOutputStream("temph5.ser");
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+ oos.writeObject(test);
+ oos.close();
+ }
+ catch (Exception ex) {
+ fail("Exception thrown during test: " + ex.toString());
+ }
+
+ try {
+ FileInputStream fis = new FileInputStream("temph5.ser");
+ ObjectInputStream ois = new ObjectInputStream(fis);
+ H5 test = (hdf.hdf5lib.H5) ois.readObject();
+ ois.close();
+
+ assertTrue("H5.LIB_VERSION[0]", test.LIB_VERSION[0]==H5.LIB_VERSION[0]);
+ assertTrue("H5.LIB_VERSION[1]", test.LIB_VERSION[1]==H5.LIB_VERSION[1]);
+// assertTrue("H5.LIB_VERSION[2]", test.LIB_VERSION[2]==H5.LIB_VERSION[2]);
+
+ // Clean up the file
+ new File("temph5.ser").delete();
+ }
+ catch (Exception ex) {
+ fail("Exception thrown during test: " + ex.toString());
+ }
+ }
+}
diff --git a/java/test/TestH5A.java b/java/test/TestH5A.java
new file mode 100644
index 0000000..fb7b31a
--- /dev/null
+++ b/java/test/TestH5A.java
@@ -0,0 +1,1119 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+
+import java.io.File;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.callbacks.H5A_iterate_cb;
+import hdf.hdf5lib.callbacks.H5A_iterate_t;
+import hdf.hdf5lib.exceptions.HDF5Exception;
+import hdf.hdf5lib.exceptions.HDF5LibraryException;
+import hdf.hdf5lib.structs.H5A_info_t;
+
+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 TestH5A {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "test.h5";
+ private static final int DIM_X = 4;
+ private static final int DIM_Y = 6;
+ long H5fid = -1;
+ long H5dsid = -1;
+ long H5did = -1;
+ long[] H5dims = { DIM_X, DIM_Y };
+ long type_id = -1;
+ long space_id = -1;
+ long lapl_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 dapl) {
+ long did = -1;
+ 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("TestH5A._createDataset: ", did > 0);
+
+ return did;
+ }
+
+ @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(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ assertTrue("TestH5A.createH5file: H5.H5Fcreate: ", H5fid > 0);
+ H5dsid = H5.H5Screate_simple(2, H5dims, null);
+ assertTrue("TestH5A.createH5file: H5.H5Screate_simple: ", H5dsid > 0);
+ H5did = _createDataset(H5fid, H5dsid, "dset",
+ HDF5Constants.H5P_DEFAULT);
+ assertTrue("TestH5A.createH5file: _createDataset: ", H5did > 0);
+ space_id = H5.H5Screate(HDF5Constants.H5S_NULL);
+ assertTrue(space_id > 0);
+ lapl_id = H5.H5Pcreate(HDF5Constants.H5P_ATTRIBUTE_ACCESS);
+ assertTrue(lapl_id > 0);
+ type_id = H5.H5Tenum_create(HDF5Constants.H5T_STD_I32LE);
+ assertTrue(type_id > 0);
+ int status = H5.H5Tenum_insert(type_id, "test", 1);
+ assertTrue(status >= 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5A.createH5file: " + err);
+ }
+
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5dsid > 0)
+ try {H5.H5Sclose(H5dsid);} catch (Exception ex) {}
+ if (H5did > 0)
+ try {H5.H5Dclose(H5did);} catch (Exception ex) {}
+ if (H5fid > 0)
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+
+ _deleteFile(H5_FILE);
+
+ if (type_id > 0)
+ try {H5.H5Tclose(type_id);} catch (Exception ex) {}
+ if (space_id > 0)
+ try {H5.H5Sclose(space_id);} catch (Exception ex) {}
+ if (lapl_id > 0)
+ try {H5.H5Pclose(lapl_id);} catch (Exception ex) {}
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Acreate2() {
+ long attr_id = -1;
+ try {
+ attr_id = H5.H5Acreate(H5did, "dset", type_id, space_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Acreate2", attr_id >= 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Acreate2: " + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Acreate2_invalidobject() throws Throwable {
+ H5.H5Acreate(H5dsid, "dset", type_id, space_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Acreate2_nullname() throws Throwable {
+ H5.H5Acreate(H5did, null, type_id, space_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Aopen() {
+ String attr_name = "dset";
+ long attribute_id = -1;
+ long attr_id = -1;
+
+ try {
+ attr_id = H5.H5Acreate(H5did, attr_name, type_id, space_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+
+ // Opening the existing attribute, attr_name(Created by H5ACreate2)
+ // attached to an object identifier.
+ attribute_id = H5.H5Aopen(H5did, attr_name,
+ HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Aopen: H5Aopen", attribute_id >= 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aopen: " + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ if (attribute_id > 0)
+ try {H5.H5Aclose(attribute_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Aopen_invalidname() throws Throwable {
+ H5.H5Aopen(H5did, "attr_name", HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Aopen_by_idx() {
+ long loc_id = H5did;
+ String obj_name = ".";
+ int idx_type = HDF5Constants.H5_INDEX_CRT_ORDER;
+ int order = HDF5Constants.H5_ITER_INC;
+ long n = 0;
+ long attr_id = -1;
+ long attribute_id = -1;
+ long aapl_id = HDF5Constants.H5P_DEFAULT;
+
+ try {
+ attr_id = H5.H5Acreate(H5did, "file", type_id, space_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+
+ // Opening the existing attribute, obj_name(Created by H5ACreate2)
+ // by index, attached to an object identifier.
+ attribute_id = H5.H5Aopen_by_idx(H5did, ".", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC,
+ 0, HDF5Constants.H5P_DEFAULT, lapl_id);
+
+ assertTrue("testH5Aopen_by_idx: H5Aopen_by_idx", attribute_id >= 0);
+
+ // Negative test- Error should be thrown when H5Aopen_by_idx is
+ // called
+ // with n=5 and we do not have 5 attributes created.
+ try {
+ n = 5;
+ H5.H5Aopen_by_idx(loc_id, obj_name, idx_type, order, n,
+ aapl_id, lapl_id);
+ fail("Negative Test Failed:- Error not Thrown when n is invalid.");
+ }
+ catch (AssertionError err) {
+ fail("H5.H5Aopen_by_idx: " + err);
+ }
+ catch (HDF5LibraryException err) {}
+
+ // Negative test- Error should be thrown when H5Aopen_by_idx is
+ // called
+ // with an invalid object name(which hasn't been created).
+ try {
+ n = 0;
+ obj_name = "file";
+ H5.H5Aopen_by_idx(loc_id, obj_name, idx_type, order, n,
+ aapl_id, lapl_id);
+ fail("Negative Test Failed:- Error not Thrown when attribute name is invalid.");
+ }
+ catch (AssertionError err) {
+ fail("H5.H5Aopen_by_idx: " + err);
+ }
+ catch (HDF5LibraryException err) {}
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aopen_by_idx: " + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ if (attribute_id > 0)
+ try {H5.H5Aclose(attribute_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Acreate_by_name() {
+ String obj_name = ".";
+ String attr_name = "DATASET";
+ long attribute_id = -1;
+ boolean bool_val = false;
+
+ try {
+ attribute_id = H5.H5Acreate_by_name(H5fid, obj_name, attr_name,
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ assertTrue("testH5Acreate_by_name: H5Acreate_by_name",
+ attribute_id >= 0);
+
+ // Check if the name of attribute attached to the object specified
+ // by loc_id and obj_name exists.It should be true.
+ bool_val = H5.H5Aexists_by_name(H5fid, obj_name, attr_name,
+ lapl_id);
+ assertTrue("testH5Acreate_by_name: H5Aexists_by_name",
+ bool_val == true);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Acreate_by_name " + err);
+ }
+ finally {
+ if (attribute_id > 0)
+ try {H5.H5Aclose(attribute_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Arename() throws Throwable, HDF5LibraryException, NullPointerException {
+ long loc_id = H5fid;
+ String old_attr_name = "old";
+ String new_attr_name = "new";
+ long attr_id = -1;
+ int ret_val = -1;
+ boolean bool_val = false;
+
+ try {
+ attr_id = H5.H5Acreate(loc_id, old_attr_name, type_id, space_id, HDF5Constants.H5P_DEFAULT, lapl_id);
+
+ ret_val = H5.H5Arename(loc_id, old_attr_name, new_attr_name);
+
+ // Check the return value.It should be non negative.
+ assertTrue("testH5Arename: H5Arename", ret_val >= 0);
+
+ // Check if the new name of attribute attached to the object
+ // specified by loc_id and obj_name exists.It should be true.
+ bool_val = H5.H5Aexists(loc_id, new_attr_name);
+ assertTrue("testH5Arename: H5Aexists", bool_val == true);
+
+ // Check if the old name of attribute attached to the object
+ // specified by loc_id and obj_name exists. It should equal false.
+ bool_val = H5.H5Aexists(loc_id, old_attr_name);
+ assertEquals(bool_val, false);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Arename " + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Arename_by_name() {
+ long loc_id = H5fid;
+ String obj_name = ".";
+ String old_attr_name = "old";
+ String new_attr_name = "new";
+ long attr_id = -1;
+ int ret_val = -1;
+ boolean bool_val = false;
+
+ try {
+ attr_id = H5.H5Acreate_by_name(loc_id, obj_name, old_attr_name,
+ type_id, space_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, lapl_id);
+
+ ret_val = H5.H5Arename_by_name(loc_id, obj_name, old_attr_name,
+ new_attr_name, lapl_id);
+
+ // Check the return value.It should be non negative.
+ assertTrue("testH5Arename_by_name: H5Arename_by_name", ret_val >= 0);
+
+ // Check if the new name of attribute attached to the object
+ // specified by loc_id and obj_name exists.It should be true.
+ bool_val = H5.H5Aexists_by_name(loc_id, obj_name, new_attr_name,
+ lapl_id);
+ assertTrue("testH5Arename_by_name: H5Aexists_by_name",
+ bool_val == true);
+
+ // Check if the old name of attribute attached to the object
+ // specified by loc_id and obj_name exists. It should equal false.
+ bool_val = H5.H5Aexists_by_name(loc_id, obj_name, old_attr_name,
+ lapl_id);
+ assertEquals(bool_val, false);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Arename_by_name " + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Aget_name() {
+ String obj_name = ".";
+ String attr_name = "DATASET1";
+ String ret_name = null;
+ long attribute_id = -1;
+
+ try {
+ attribute_id = H5.H5Acreate_by_name(H5fid, obj_name, attr_name,
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ assertTrue("testH5Aget_name: H5Acreate_by_name ", attribute_id > 0);
+ ret_name = H5.H5Aget_name(attribute_id);
+ assertEquals(ret_name, attr_name);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Aget_name " + err);
+ }
+ finally {
+ if (attribute_id > 0)
+ try {H5.H5Aclose(attribute_id);} catch (Exception ex) {}
+ }
+ }
+
+
+ @Test
+ public void testH5Aget_name_by_idx() {
+ long loc_id = H5fid;
+ String obj_name = ".";
+ String attr_name = "DATASET1", attr2_name = "DATASET2";
+ String ret_name = null;
+ int idx_type = HDF5Constants.H5_INDEX_NAME;
+ int order = HDF5Constants.H5_ITER_INC;
+ int n = 0;
+ long attr1_id = -1;
+ long attr2_id = -1;
+
+ try {
+ attr1_id = H5.H5Acreate_by_name(loc_id, obj_name, attr_name,
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr2_id = H5.H5Acreate_by_name(loc_id, obj_name, attr2_name,
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+
+ // getting the 1st attribute name(n=0).
+ ret_name = H5.H5Aget_name_by_idx(loc_id, obj_name, idx_type, order,
+ n, lapl_id);
+ assertFalse("H5Aget_name_by_idx ", ret_name == null);
+ assertEquals(ret_name, attr_name);
+
+ // getting the second attribute name(n=1)
+ ret_name = H5.H5Aget_name_by_idx(loc_id, obj_name, idx_type, order,
+ 1, lapl_id);
+ assertFalse("H5Aget_name_by_idx ", ret_name == null);
+ assertEquals(ret_name, attr2_name);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aget_name_by_idx " + err);
+ }
+ finally {
+ if (attr1_id > 0)
+ try {H5.H5Aclose(attr1_id);} catch (Exception ex) {}
+ if (attr2_id > 0)
+ try {H5.H5Aclose(attr2_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Aget_storage_size() {
+ long attr_id = -1;
+ long attr_size = -1;
+
+ try {
+ attr_id = H5.H5Acreate(H5did, "dset", type_id, space_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+
+ attr_size = H5.H5Aget_storage_size(attr_id);
+ assertTrue("The size of attribute is :", attr_size == 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aget_storage_size: " + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Aget_info() {
+ H5A_info_t attr_info = null;
+ long attribute_id = -1;
+ long attr_id = -1;
+
+ try {
+ attr_id = H5.H5Acreate(H5did, "dset", type_id, space_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ attribute_id = H5.H5Aopen(H5did, "dset", HDF5Constants.H5P_DEFAULT);
+ // Calling H5Aget_info with attribute_id returned from H5Aopen.
+ attr_info = H5.H5Aget_info(attribute_id);
+ assertFalse("H5Aget_info ", attr_info == null);
+ assertTrue("Corder_Valid should be false",
+ attr_info.corder_valid == false);
+ assertTrue("Character set used for attribute name",
+ attr_info.cset == HDF5Constants.H5T_CSET_ASCII);
+ assertTrue("Corder ", attr_info.corder == 0);
+ assertEquals(attr_info.data_size, H5.H5Aget_storage_size(attr_id));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aget_info: " + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ if (attribute_id > 0)
+ try {H5.H5Aclose(attribute_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Aget_info1() {
+ H5A_info_t attr_info = null;
+ long attribute_id = -1;
+ long attr_id = -1;
+ int order = HDF5Constants.H5_ITER_INC;
+
+ try {
+ attr_id = H5.H5Acreate(H5did, ".", type_id, space_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ attribute_id = H5.H5Aopen_by_idx(H5did, ".",
+ HDF5Constants.H5_INDEX_CRT_ORDER, order, 0,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ // Calling H5Aget_info with attribute_id returned from
+ // H5Aopen_by_idx.
+ attr_info = H5.H5Aget_info(attribute_id);
+
+ assertFalse("H5Aget_info ", attr_info == null);
+ assertTrue("Corder_Valid should be true",
+ attr_info.corder_valid == true);
+ assertTrue("Character set",
+ attr_info.cset == HDF5Constants.H5T_CSET_ASCII);
+ assertTrue("Corder ", attr_info.corder == 0);
+ assertEquals(attr_info.data_size, H5.H5Aget_storage_size(attr_id));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aget_info1: " + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ if (attribute_id > 0)
+ try {H5.H5Aclose(attribute_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Aget_info_by_idx() {
+ long attr_id = -1;
+ long attr2_id = -1;;
+ H5A_info_t attr_info = null;
+
+ try {
+ attr_id = H5.H5Acreate(H5did, "dset1", type_id, space_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ attr2_id = H5.H5Acreate(H5did, "dataset2", type_id, space_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+
+ //Verify info for 1st attribute, in increasing creation order
+ attr_info = H5.H5Aget_info_by_idx(H5did, ".", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0, lapl_id);
+ assertNotNull(attr_info);
+ assertTrue("Corder ", attr_info.corder == 0);//should equal 0 as this is the order of 1st attribute created.
+ assertEquals(attr_info.data_size, H5.H5Aget_storage_size(attr_id));
+
+ //Verify info for 2nd attribute, in increasing creation order
+ attr_info = H5.H5Aget_info_by_idx(H5did, ".", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 1, lapl_id);
+ assertNotNull(attr_info);
+ assertTrue("Corder", attr_info.corder == 1);
+ assertEquals(attr_info.data_size, H5.H5Aget_storage_size(attr2_id));
+
+ //verify info for 2nd attribute, in decreasing creation order
+ attr_info = H5.H5Aget_info_by_idx(H5did, ".", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_DEC, 0, lapl_id);
+ assertNotNull(attr_info);
+ assertTrue("Corder", attr_info.corder == 1); //should equal 1 as this is the order of 2nd attribute created.
+
+ //verify info for 1st attribute, in decreasing creation order
+ attr_info = H5.H5Aget_info_by_idx(H5did, ".", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_DEC, 1, lapl_id);
+ assertNotNull(attr_info);
+ assertTrue("Corder", attr_info.corder == 0); //should equal 0 as this is the order of 1st attribute created.
+
+ //verify info for 1st attribute, in increasing name order
+ attr_info = H5.H5Aget_info_by_idx(H5did, ".", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 1, lapl_id);
+ assertNotNull(attr_info);
+ assertTrue("Corder", attr_info.corder == 0); //should equal 0 as this is the order of 1st attribute created.
+
+ //verify info for 2nd attribute, in decreasing name order
+ attr_info = H5.H5Aget_info_by_idx(H5did, ".", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_DEC, 1, lapl_id);
+ assertNotNull(attr_info);
+ assertTrue("Corder", attr_info.corder == 1); //should equal 1 as this is the order of 2nd attribute created.
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aget_info_by_idx:" + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ if (attr2_id > 0)
+ try {H5.H5Aclose(attr2_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Aget_info_by_name() {
+ long attr_id = -1;
+ H5A_info_t attr_info = null;
+ String obj_name = ".";
+ String attr_name = "DATASET";
+
+ try {
+ attr_id = H5.H5Acreate_by_name(H5fid, obj_name, attr_name, type_id,
+ space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr_info = H5.H5Aget_info_by_name(H5fid, obj_name, attr_name,
+ lapl_id);
+ assertNotNull(attr_info);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aget_info_by_name:" + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Adelete_by_name() {
+ long attr_id = -1;
+ int ret_val = -1;
+ boolean bool_val = false;
+ boolean exists = false;
+
+ try {
+ attr_id = H5.H5Acreate_by_name(H5fid, ".", "DATASET",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ ret_val = H5.H5Adelete_by_name(H5fid, ".", "DATASET", lapl_id);
+ assertTrue("H5Adelete_by_name", ret_val >= 0);
+
+ // Check if the Attribute still exists.
+ bool_val = H5.H5Aexists_by_name(H5fid, ".", "DATASET",
+ lapl_id);
+ assertFalse("testH5Adelete_by_name: H5Aexists_by_name", bool_val);
+ exists = H5.H5Aexists(H5fid, "DATASET");
+ assertFalse("testH5Adelete_by_name: H5Aexists ",exists);
+
+ // Negative test. Error thrown when we try to delete an attribute
+ // that has already been deleted.
+ try{
+ ret_val = H5.H5Adelete_by_name(H5fid, ".", "DATASET", lapl_id);
+ fail("Negative Test Failed: Error Not thrown.");
+ }
+ catch (AssertionError err) {
+ fail("H5.H5Adelete_by_name: " + err);
+ }
+ catch (HDF5LibraryException err) {}
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Adelete_by_name " + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Aexists() {
+ boolean exists = false;
+ long attr_id = -1;
+ long attribute_id = -1;
+
+ try {
+ exists = H5.H5Aexists(H5fid, "None");
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aexists: " + err);
+ }
+ assertFalse("H5Aexists ", exists);
+
+ try {
+ attr_id = H5.H5Acreate(H5fid, "dset", type_id, space_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ exists = H5.H5Aexists(H5fid, "dset");
+ assertTrue("H5Aexists ", exists);
+
+ attribute_id = H5.H5Acreate_by_name(H5fid, ".", "attribute",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ exists = H5.H5Aexists(H5fid, "attribute");
+ assertTrue("H5Aexists ", exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aexists: " + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ if (attribute_id > 0)
+ try {H5.H5Aclose(attribute_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Adelete_by_idx_order() {
+ boolean exists = false;
+ long attr1_id = -1;
+ long attr2_id = -1;
+ long attr3_id = -1;
+ long attr4_id = -1;
+
+ try {
+ attr1_id = H5.H5Acreate_by_name(H5fid, ".", "attribute1",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr2_id = H5.H5Acreate_by_name(H5fid, ".", "attribute2",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr3_id = H5.H5Acreate_by_name(H5fid, ".", "attribute3",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr4_id = H5.H5Acreate_by_name(H5fid, ".", "attribute4",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+
+ H5.H5Adelete_by_idx(H5fid, ".", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 3, lapl_id);
+ exists = H5.H5Aexists(H5fid, "attribute4");
+ assertFalse("H5Adelete_by_idx: H5Aexists", exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Adelete_by_idx: " + err);
+ }
+ finally {
+ if (attr1_id > 0)
+ try {H5.H5Aclose(attr1_id);} catch (Exception ex) {}
+ if (attr2_id > 0)
+ try {H5.H5Aclose(attr2_id);} catch (Exception ex) {}
+ if (attr3_id > 0)
+ try {H5.H5Aclose(attr3_id);} catch (Exception ex) {}
+ if (attr4_id > 0)
+ try {H5.H5Aclose(attr4_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Adelete_by_idx_name1() {
+ boolean exists = false;
+ long attr1_id = -1;
+ long attr2_id = -1;
+ long attr3_id = -1;
+
+ try {
+ attr1_id = H5.H5Acreate_by_name(H5fid, ".", "attribute1",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr2_id = H5.H5Acreate_by_name(H5fid, ".", "attribute2",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr3_id = H5.H5Acreate_by_name(H5fid, ".", "attribute3",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ H5.H5Adelete_by_idx(H5fid, ".", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 2, lapl_id);
+ exists = H5.H5Aexists(H5fid, "attribute3");
+ assertFalse("H5Adelete_by_idx: H5Aexists", exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Adelete_by_idx: " + err);
+ }
+ finally {
+ if (attr1_id > 0)
+ try {H5.H5Aclose(attr1_id);} catch (Exception ex) {}
+ if (attr2_id > 0)
+ try {H5.H5Aclose(attr2_id);} catch (Exception ex) {}
+ if (attr3_id > 0)
+ try {H5.H5Aclose(attr3_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Adelete_by_idx_name2() {
+ boolean exists = false;
+ long attr1_id = -1;
+ long attr2_id = -1;
+ long attr3_id = -1;
+ long attr4_id = -1;
+
+ try {
+ attr1_id = H5.H5Acreate_by_name(H5fid, ".", "attribute1",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr2_id = H5.H5Acreate_by_name(H5fid, ".", "attribute2",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr3_id = H5.H5Acreate_by_name(H5fid, ".", "attribute3",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr4_id = H5.H5Acreate_by_name(H5fid, ".", "attribute4",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+
+ H5.H5Adelete_by_idx(H5fid, ".", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_DEC, 3, lapl_id);
+ exists = H5.H5Aexists(H5fid, "attribute1");
+ assertFalse("H5Adelete_by_idx: H5Aexists", exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Adelete_by_idx: " + err);
+ }
+ finally {
+ if (attr1_id > 0)
+ try {H5.H5Aclose(attr1_id);} catch (Exception ex) {}
+ if (attr2_id > 0)
+ try {H5.H5Aclose(attr2_id);} catch (Exception ex) {}
+ if (attr3_id > 0)
+ try {H5.H5Aclose(attr3_id);} catch (Exception ex) {}
+ if (attr4_id > 0)
+ try {H5.H5Aclose(attr4_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Adelete_by_idx_null() throws Throwable {
+ H5.H5Adelete_by_idx(H5fid, null, HDF5Constants.H5_INDEX_CRT_ORDER,
+ HDF5Constants.H5_ITER_INC, 0, lapl_id);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Adelete_by_idx_invalidobject() throws Throwable {
+ H5.H5Adelete_by_idx(H5fid, "invalid", HDF5Constants.H5_INDEX_CRT_ORDER,
+ HDF5Constants.H5_ITER_INC, 0, lapl_id);
+ }
+
+ @Test
+ public void testH5Aopen_by_name() {
+ String obj_name = ".";
+ String attr_name = "DATASET";
+ long attribute_id = -1;
+ long aid = -1;
+
+ try {
+ attribute_id = H5.H5Acreate_by_name(H5fid, obj_name, attr_name,
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+
+ //open Attribute by name
+ if(attribute_id >= 0) {
+ try {
+ aid = H5.H5Aopen_by_name(H5fid, obj_name, attr_name, HDF5Constants.H5P_DEFAULT, lapl_id);
+ assertTrue("testH5Aopen_by_name: ", aid>=0);
+ }
+ catch(Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aopen_by_name " + err);
+ }
+ }
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aopen_by_name " + err);
+ }
+ finally {
+ if (aid > 0)
+ try {H5.H5Aclose(aid);} catch (Exception ex) {}
+ if (attribute_id > 0)
+ try {H5.H5Aclose(attribute_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Awrite_readVL() {
+ String attr_name = "VLdata";
+ long attr_id = -1;
+ long atype_id = -1;
+ long aspace_id = -1;
+ String[] str_data = { "Parting", "is such", "sweet", "sorrow." };
+ long[] dims = { str_data.length };
+ long lsize = 1;
+
+ try {
+ atype_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
+ assertTrue("testH5Awrite_readVL.H5Tcopy: ", atype_id >= 0);
+ H5.H5Tset_size(atype_id, HDF5Constants.H5T_VARIABLE);
+ assertTrue("testH5Awrite_readVL.H5Tis_variable_str", H5.H5Tis_variable_str(atype_id));
+ }
+ catch (Exception err) {
+ if (atype_id > 0)
+ try {H5.H5Tclose(atype_id);} catch (Exception ex) {}
+ err.printStackTrace();
+ fail("H5.testH5Awrite_readVL: " + err);
+ }
+
+ try {
+ aspace_id = H5.H5Screate_simple(1, dims, null);
+ assertTrue(aspace_id > 0);
+ attr_id = H5.H5Acreate(H5did, attr_name, atype_id, aspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Awrite_readVL: ", attr_id >= 0);
+
+ H5.H5AwriteVL(attr_id, atype_id, str_data);
+
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+
+ for (int j = 0; j < dims.length; j++) {
+ lsize *= dims[j];
+ }
+ String[] strs = new String[(int) lsize];
+ for (int j = 0; j < lsize; j++) {
+ strs[j] = "";
+ }
+ try {
+ H5.H5AreadVL(attr_id, atype_id, strs);
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ assertTrue("testH5Awrite_readVL:", str_data[0].equals(strs[0]));
+ assertTrue("testH5Awrite_readVL:", str_data[1].equals(strs[1]));
+ assertTrue("testH5Awrite_readVL:", str_data[2].equals(strs[2]));
+ assertTrue("testH5Awrite_readVL:", str_data[3].equals(strs[3]));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.testH5Awrite_readVL: " + err);
+ }
+ finally {
+ if (attr_id > 0)
+ try {H5.H5Aclose(attr_id);} catch (Exception ex) {}
+ if (aspace_id > 0)
+ try {H5.H5Sclose(aspace_id);} catch (Exception ex) {}
+ if (atype_id > 0)
+ try {H5.H5Tclose(atype_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Aget_create_plist() {
+ String attr_name = "DATASET1";
+ int char_encoding = 0;
+ long plist_id = -1;
+ long attribute_id = -1;
+
+ try {
+ plist_id = H5.H5Pcreate(HDF5Constants.H5P_ATTRIBUTE_CREATE);
+ assertTrue(plist_id > 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Aget_create_plist: H5Pcreate " + err);
+ }
+ try {
+ // Get the character encoding and ensure that it is the default (ASCII)
+ try {
+ char_encoding = H5.H5Pget_char_encoding(plist_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_char_encoding: " + err);
+ }
+ assertTrue("testH5Aget_create_plist: get_char_encoding", char_encoding == HDF5Constants.H5T_CSET_ASCII);
+
+ // Create an attribute for the dataset using the property list
+ try {
+ attribute_id = H5.H5Acreate(H5fid, attr_name, type_id, space_id, plist_id, HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Aget_create_plist: H5Acreate", attribute_id >= 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Acreate: " + err);
+ }
+
+ /* Close the property list, and get the attribute's property list */
+ H5.H5Pclose(plist_id);
+ plist_id = H5.H5Aget_create_plist(attribute_id);
+ assertTrue(plist_id > 0);
+
+ /* Get the character encoding and ensure that it is the default (ASCII) */
+ try {
+ char_encoding = H5.H5Pget_char_encoding(plist_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_char_encoding: " + err);
+ }
+ assertTrue("testH5Aget_create_plist: get_char_encoding", char_encoding == HDF5Constants.H5T_CSET_ASCII);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Aget_create_plist " + err);
+ }
+ finally {
+ if (plist_id > 0)
+ try {H5.H5Pclose(plist_id);} catch (Exception ex) {}
+ if (attribute_id > 0)
+ try {H5.H5Aclose(attribute_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Aiterate() {
+ long attr1_id = -1;
+ long attr2_id = -1;
+ long attr3_id = -1;
+ long attr4_id = -1;
+
+ class idata {
+ public String attr_name = null;
+ idata(String name) {
+ this.attr_name = name;
+ }
+ }
+ class H5A_iter_data implements H5A_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+ H5A_iterate_t iter_data = new H5A_iter_data();
+ class H5A_iter_callback implements H5A_iterate_cb {
+ public int callback(long group, String name, H5A_info_t info, H5A_iterate_t op_data) {
+ idata id = new idata(name);
+ ((H5A_iter_data)op_data).iterdata.add(id);
+ return 0;
+ }
+ }
+ try {
+ attr1_id = H5.H5Acreate_by_name(H5fid, ".", "attribute1",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr2_id = H5.H5Acreate_by_name(H5fid, ".", "attribute2",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr3_id = H5.H5Acreate_by_name(H5fid, ".", "attribute3",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr4_id = H5.H5Acreate_by_name(H5fid, ".", "attribute4",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ H5A_iterate_cb iter_cb = new H5A_iter_callback();
+ try {
+ H5.H5Aiterate(H5fid, HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0L, iter_cb, iter_data);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aiterate: " + err);
+ }
+ assertFalse("H5Aiterate ",((H5A_iter_data)iter_data).iterdata.isEmpty());
+ assertTrue("H5Aiterate "+((H5A_iter_data)iter_data).iterdata.size(),((H5A_iter_data)iter_data).iterdata.size()==4);
+ assertTrue("H5Aiterate "+(((H5A_iter_data)iter_data).iterdata.get(0)).attr_name,(((H5A_iter_data)iter_data).iterdata.get(0)).attr_name.compareToIgnoreCase("attribute1")==0);
+ assertTrue("H5Aiterate "+(((H5A_iter_data)iter_data).iterdata.get(1)).attr_name,(((H5A_iter_data)iter_data).iterdata.get(1)).attr_name.compareToIgnoreCase("attribute2")==0);
+ assertTrue("H5Aiterate "+((idata)((H5A_iter_data)iter_data).iterdata.get(2)).attr_name,(((H5A_iter_data)iter_data).iterdata.get(2)).attr_name.compareToIgnoreCase("attribute3")==0);
+ assertTrue("H5Aiterate "+((idata)((H5A_iter_data)iter_data).iterdata.get(3)).attr_name,((idata)((H5A_iter_data)iter_data).iterdata.get(3)).attr_name.compareToIgnoreCase("attribute4")==0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Aiterate: " + err);
+ }
+ finally {
+ if (attr1_id > 0)
+ try {H5.H5Aclose(attr1_id);} catch (Exception ex) {}
+ if (attr2_id > 0)
+ try {H5.H5Aclose(attr2_id);} catch (Exception ex) {}
+ if (attr3_id > 0)
+ try {H5.H5Aclose(attr3_id);} catch (Exception ex) {}
+ if (attr4_id > 0)
+ try {H5.H5Aclose(attr4_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Aiterate_by_name() {
+ long attr1_id = -1;
+ long attr2_id = -1;
+ long attr3_id = -1;
+ long attr4_id = -1;
+
+ class idata {
+ public String attr_name = null;
+ idata(String name) {
+ this.attr_name = name;
+ }
+ }
+ class H5A_iter_data implements H5A_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+ H5A_iterate_t iter_data = new H5A_iter_data();
+ class H5A_iter_callback implements H5A_iterate_cb {
+ public int callback(long group, String name, H5A_info_t info, H5A_iterate_t op_data) {
+ idata id = new idata(name);
+ ((H5A_iter_data)op_data).iterdata.add(id);
+ return 0;
+ }
+ }
+ try {
+ attr1_id = H5.H5Acreate_by_name(H5fid, ".", "attribute4",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr2_id = H5.H5Acreate_by_name(H5fid, ".", "attribute3",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr3_id = H5.H5Acreate_by_name(H5fid, ".", "attribute2",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ attr4_id = H5.H5Acreate_by_name(H5fid, ".", "attribute1",
+ type_id, space_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, lapl_id);
+ H5A_iterate_cb iter_cb = new H5A_iter_callback();
+ try {
+ H5.H5Aiterate_by_name(H5fid, ".", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0L, iter_cb, iter_data, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Aiterate_by_name: " + err);
+ }
+ assertFalse("H5Aiterate_by_name ",((H5A_iter_data)iter_data).iterdata.isEmpty());
+ assertTrue("H5Aiterate_by_name "+((H5A_iter_data)iter_data).iterdata.size(),((H5A_iter_data)iter_data).iterdata.size()==4);
+ assertTrue("H5Aiterate_by_name "+((idata)((H5A_iter_data)iter_data).iterdata.get(1)).attr_name,((idata)((H5A_iter_data)iter_data).iterdata.get(1)).attr_name.compareToIgnoreCase("attribute2")==0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Aiterate: " + err);
+ }
+ finally {
+ if (attr1_id > 0)
+ try {H5.H5Aclose(attr1_id);} catch (Exception ex) {}
+ if (attr2_id > 0)
+ try {H5.H5Aclose(attr2_id);} catch (Exception ex) {}
+ if (attr3_id > 0)
+ try {H5.H5Aclose(attr3_id);} catch (Exception ex) {}
+ if (attr4_id > 0)
+ try {H5.H5Aclose(attr4_id);} catch (Exception ex) {}
+ }
+ }
+
+}
+
+
+
diff --git a/java/test/TestH5D.java b/java/test/TestH5D.java
new file mode 100644
index 0000000..9e359e2
--- /dev/null
+++ b/java/test/TestH5D.java
@@ -0,0 +1,892 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.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.HDFNativeData;
+import hdf.hdf5lib.callbacks.H5D_iterate_cb;
+import hdf.hdf5lib.callbacks.H5D_iterate_t;
+import hdf.hdf5lib.exceptions.HDF5Exception;
+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 TestH5D {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "test.h5";
+ private static final int DIM_X = 4;
+ private static final int DIM_Y = 6;
+ private static final int RANK = 2;
+ long H5fid = -1;
+ long H5dsid = -1;
+ long H5dtid = -1;
+ long H5did = -1;
+ long H5did0 = -1;
+ long H5dcpl_id = -1;
+ long[] H5dims = { DIM_X, DIM_Y };
+
+ // Values for the status of space allocation
+ enum H5D_space_status {
+ H5D_SPACE_STATUS_ERROR(-1), H5D_SPACE_STATUS_NOT_ALLOCATED(0), H5D_SPACE_STATUS_PART_ALLOCATED(
+ 1), H5D_SPACE_STATUS_ALLOCATED(2);
+
+ private int code;
+
+ H5D_space_status(int space_status) {
+ this.code = space_status;
+ }
+
+ public int getCode() {
+ return this.code;
+ }
+ }
+
+ private final void _deleteFile(String filename) {
+ File file = new File(filename);
+
+ if (file.exists()) {
+ try {file.delete();}
+ catch (SecurityException e) {}
+ }
+ }
+
+ private final void _createPDataset(long fid, long dsid, String name, long dcpl_val) {
+
+ try {
+ H5dcpl_id = H5.H5Pcreate(dcpl_val);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("H5.H5Pcreate: " + err);
+ }
+ assertTrue("testH5D._createPDataset: H5.H5Pcreate: ", H5dcpl_id >= 0);
+
+ // Set the allocation time to "early". This way we can be sure
+ // that reading from the dataset immediately after creation will
+ // return the fill value.
+ try {
+ H5.H5Pset_alloc_time(H5dcpl_id, HDF5Constants.H5D_ALLOC_TIME_EARLY);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ H5did0 = H5.H5Dcreate(fid, name,
+ HDF5Constants.H5T_STD_I32BE, dsid,
+ HDF5Constants.H5P_DEFAULT, H5dcpl_id, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Dcreate: " + err);
+ }
+ assertTrue("TestH5D._createPDataset.H5Dcreate: ", H5did0 >= 0);
+ }
+
+ private final void _createDataset(long fid, long dsid, String name, long dapl) {
+ try {
+ H5did = 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("TestH5D._createDataset.H5Dcreate: ", H5did >= 0);
+ }
+
+ private final void _createVLDataset(long fid, long dsid, String name, long dapl) {
+ try {
+ H5dtid = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Tcopy: " + err);
+ }
+ assertTrue("TestH5D._createVLDataset.H5Tcopy: ", H5dtid >= 0);
+ try {
+ H5.H5Tset_size(H5dtid, HDF5Constants.H5T_VARIABLE);
+ assertTrue("TestH5D._createVLDataset.H5Tis_variable_str", H5.H5Tis_variable_str(H5dtid));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Tset_size: " + err);
+ }
+ try {
+ H5did = H5.H5Dcreate(fid, name, H5dtid, dsid,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, dapl);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Dcreate: " + err);
+ }
+ assertTrue("TestH5D._createVLDataset.H5Dcreate: ", H5did >= 0);
+ }
+
+ private final void _closeH5file() throws HDF5LibraryException {
+ if (H5dcpl_id >= 0)
+ try {H5.H5Pclose(H5dcpl_id);} catch (Exception ex) {}
+ if (H5did0 >= 0)
+ try {H5.H5Dclose(H5did0);} catch (Exception ex) {}
+ if (H5did >= 0)
+ try {H5.H5Dclose(H5did);} catch (Exception ex) {}
+ if (H5dtid > 0)
+ try {H5.H5Tclose(H5dtid);} catch (Exception ex) {}
+ if (H5dsid > 0)
+ try {H5.H5Sclose(H5dsid);} catch (Exception ex) {}
+ if (H5fid > 0)
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ }
+
+ private final void _openH5file(String name, long dapl) {
+ try {
+ H5fid = H5.H5Fopen(H5_FILE,
+ HDF5Constants.H5F_ACC_RDWR, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5D._openH5file: " + err);
+ }
+ assertTrue("TestH5D._openH5file: H5.H5Fopen: ",H5fid >= 0);
+ try {
+ H5did = H5.H5Dopen(H5fid, name, dapl);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5D._openH5file: " + err);
+ }
+ assertTrue("TestH5D._openH5file: H5.H5Dopen: ",H5did >= 0);
+ try {
+ H5dsid = H5.H5Dget_space(H5did);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5D._openH5file: " + err);
+ }
+ assertTrue("TestH5D._openH5file: H5.H5Screate_simple: ",H5dsid > 0);
+ }
+
+ @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(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5dsid = H5.H5Screate_simple(RANK, H5dims, null);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5D.createH5file: " + err);
+ }
+ assertTrue("TestH5D.createH5file: H5.H5Fcreate: ",H5fid >= 0);
+ assertTrue("TestH5D.createH5file: H5.H5Screate_simple: ",H5dsid >= 0);
+
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5dcpl_id >= 0)
+ try {H5.H5Pclose(H5dcpl_id);} catch (Exception ex) {}
+ if (H5did0 >= 0)
+ try {H5.H5Dclose(H5did0);} catch (Exception ex) {}
+ if (H5did >= 0)
+ try {H5.H5Dclose(H5did);} catch (Exception ex) {}
+ if (H5dtid > 0)
+ try {H5.H5Tclose(H5dtid);} catch (Exception ex) {}
+ if (H5dsid > 0)
+ try {H5.H5Sclose(H5dsid);} catch (Exception ex) {}
+ if (H5fid > 0)
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+
+ _deleteFile(H5_FILE);
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Dcreate() {
+ long dataset_id = -1;
+ try {
+ dataset_id = H5.H5Dcreate(H5fid, "dset",
+ HDF5Constants.H5T_STD_I32BE, H5dsid,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("testH5Dcreate: " + err);
+ }
+ assertTrue(dataset_id >= 0);
+
+ // End access to the dataset and release resources used by it.
+ try {
+ if (dataset_id >= 0)
+ H5.H5Dclose(dataset_id);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testH5Dcreate_anon() {
+ long dataset_id = -1;
+ try {
+ dataset_id = H5.H5Dcreate_anon(H5fid, HDF5Constants.H5T_STD_I32BE,
+ H5dsid, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("testH5Dcreate_anon: " + err);
+ }
+ assertTrue(dataset_id >= 0);
+
+ // End access to the dataset and release resources used by it.
+ try {
+ if (dataset_id >= 0)
+ H5.H5Dclose(dataset_id);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testH5Dopen() {
+ long dataset_id = -1;
+ _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+
+ try {
+ H5.H5Dclose(H5did);
+ H5did = -1;
+ dataset_id = H5.H5Dopen(H5fid, "dset", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("testH5Dopen: " + err);
+ }
+ assertTrue("testH5Dopen: ", dataset_id >= 0);
+
+ // End access to the dataset and release resources used by it.
+ try {
+ if (dataset_id >= 0)
+ H5.H5Dclose(dataset_id);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testH5Dget_storage_size_empty() {
+ long storage_size = 0;
+ _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+
+ try {
+ storage_size = H5.H5Dget_storage_size(H5did);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("testH5Dget_storage_size: " + err);
+ }
+ assertTrue("testH5Dget_storage_size: ", storage_size == 0);
+ }
+
+ @Test
+ public void testH5Dget_storage_size() {
+ long storage_size = 0;
+ int[][] dset_data = new int[DIM_X][DIM_Y];
+ int FILLVAL = 99;
+ _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+
+ // Initialize the dataset.
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++)
+ dset_data[indx][jndx] = FILLVAL;
+
+ try {
+ if (H5did >= 0)
+ H5.H5Dwrite(H5did, HDF5Constants.H5T_NATIVE_INT,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, dset_data[0]);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ storage_size = H5.H5Dget_storage_size(H5did);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("testH5Dget_storage_size: " + err);
+ }
+ assertTrue("testH5Dget_storage_size: "+storage_size, storage_size == DIM_X*DIM_Y*4);
+ }
+
+ @Test
+ public void testH5Dget_access_plist() {
+ long dapl_id = -1;
+ int pequal = -1;
+ long test_dapl_id = -1;
+
+ try {
+ test_dapl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_ACCESS);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("testH5Dget_access_plist: H5.H5Pcreate: " + err);
+ }
+ assertTrue("testH5Dget_access_plist: test_dapl_id: ", test_dapl_id >= 0);
+
+ _createDataset(H5fid, H5dsid, "dset", test_dapl_id);
+
+ try {
+ dapl_id = H5.H5Dget_access_plist(H5did);
+ assertTrue("testH5Dget_access_plist: dapl_id: ", dapl_id >= 0);
+ pequal = H5.H5Pequal(dapl_id, test_dapl_id);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("testH5Dget_access_plist: H5.H5Dget_access_plist: " + err);
+ }
+
+ // End access to the dataset and release resources used by it.
+ try {
+ if (dapl_id >= 0)
+ H5.H5Pclose(dapl_id);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ }
+ try {
+ if (test_dapl_id >= 0)
+ H5.H5Pclose(test_dapl_id);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ }
+ assertTrue("testH5Dget_access_plist: ", pequal > 0);
+ }
+
+ @Test
+ public void testH5Dget_space_status() {
+ int[][] write_dset_data = new int[DIM_X][DIM_Y];
+ int space_status = -1;
+ int space_status0 = -1;
+
+ // Initialize the dataset.
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++)
+ write_dset_data[indx][jndx] = indx * jndx - jndx;
+
+ _createPDataset(H5fid, H5dsid, "dset0", HDF5Constants.H5P_DATASET_CREATE);
+ _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+
+ // Retrieve and print space status and storage size for dset0.
+ try {
+ space_status0 = H5.H5Dget_space_status(H5did0);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ assertTrue("testH5Dget_space_status0 - H5.H5Dget_space_status: ", space_status0 == H5D_space_status.H5D_SPACE_STATUS_ALLOCATED.getCode());
+
+ // Retrieve and print space status and storage size for dset.
+ try {
+ space_status = H5.H5Dget_space_status(H5did);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ assertFalse("testH5Dget_space_status - H5.H5Dget_space_status: ", space_status == H5D_space_status.H5D_SPACE_STATUS_ALLOCATED.getCode());
+
+ // Write the data to the dataset.
+ try {
+ H5.H5Dwrite(H5did, HDF5Constants.H5T_NATIVE_INT,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, write_dset_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Retrieve and print space status and storage size for dset.
+ try {
+ space_status = H5.H5Dget_space_status(H5did);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ assertTrue("testH5Dget_space_status - H5.H5Dget_space_status: ", space_status == H5D_space_status.H5D_SPACE_STATUS_ALLOCATED.getCode());
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dget_space_closed() throws Throwable {
+ long dataset_id = -1;
+ try {
+ dataset_id = H5.H5Dcreate(H5fid, "dset",
+ HDF5Constants.H5T_STD_I32BE, H5dsid,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Dcreate: " + err);
+ }
+ assertTrue("TestH5D.testH5Dget_space_closed: ", dataset_id >= 0);
+ H5.H5Dclose(dataset_id);
+
+ H5.H5Dget_space(dataset_id);
+ }
+
+ @Test
+ public void testH5Dget_space() {
+ long dataspace_id = -1;
+ _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+
+ try {
+ dataspace_id = H5.H5Dget_space(H5did);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("H5.H5Dget_space: " + err);
+ }
+ assertTrue("TestH5D.testH5Dget_space: ", dataspace_id >= 0);
+
+ // End access to the dataspace and release resources used by it.
+ try {
+ if (dataspace_id >= 0)
+ H5.H5Sclose(dataspace_id);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dget_type_closed() throws Throwable {
+ long dataset_id = -1;
+ try {
+ dataset_id = H5.H5Dcreate(H5fid, "dset",
+ HDF5Constants.H5T_STD_I32BE, H5dsid,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Dcreate: " + err);
+ }
+ assertTrue("TestH5D.testH5Dget_type_closed: ", dataset_id >= 0);
+ H5.H5Dclose(dataset_id);
+
+ H5.H5Dget_type(dataset_id);
+ }
+
+ @Test
+ public void testH5Dget_type() {
+ long datatype_id = -1;
+ _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+
+ try {
+ datatype_id = H5.H5Dget_type(H5did);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("H5.H5Dget_type: " + err);
+ }
+ assertTrue("TestH5D.testH5Dget_type: ", datatype_id >= 0);
+
+ // End access to the datatype and release resources used by it.
+ try {
+ if (datatype_id >= 0)
+ H5.H5Tclose(datatype_id);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testH5Dget_offset() {
+ int[][] write_dset_data = new int[DIM_X][DIM_Y];
+ long dset_address = 0;
+ _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+
+ try {
+ // Test dataset address. Should be undefined.
+ dset_address = H5.H5Dget_offset(H5did);
+ }
+ catch (HDF5LibraryException hdfex) {
+ ;
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("H5.H5Dget_offset: " + err);
+ }
+ // Write the data to the dataset.
+ try {
+ H5.H5Dwrite(H5did, HDF5Constants.H5T_NATIVE_INT,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, write_dset_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ // Test dataset address.
+ dset_address = H5.H5Dget_offset(H5did);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("H5.H5Dget_offset: " + err);
+ }
+
+ assertTrue("TestH5D.testH5Dget_offset: ", dset_address >= 0);
+ }
+
+ @Test
+ public void testH5Dfill_null() {
+ int[] buf_data = new int[DIM_X*DIM_Y];
+
+ // Initialize memory buffer
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++) {
+ buf_data[(indx * DIM_Y) + jndx] = indx * jndx - jndx;
+ }
+ byte[] buf_array = HDFNativeData.intToByte(0, DIM_X*DIM_Y, buf_data);
+
+ // Fill selection in memory
+ try {
+ H5.H5Dfill(null, HDF5Constants.H5T_NATIVE_UINT, buf_array, HDF5Constants.H5T_NATIVE_UINT, H5dsid);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("H5.H5Dfill: " + err);
+ }
+ buf_data = HDFNativeData.byteToInt(buf_array);
+
+ // Verify memory buffer the hard way
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++)
+ assertTrue("H5.H5Dfill: [" + indx+","+jndx + "] ", buf_data[(indx * DIM_Y) + jndx] == 0);
+ }
+
+ @Test
+ public void testH5Dfill() {
+ int[] buf_data = new int[DIM_X*DIM_Y];
+ byte[] fill_value = HDFNativeData.intToByte(254);
+
+ // Initialize memory buffer
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++) {
+ buf_data[(indx * DIM_Y) + jndx] = indx * jndx - jndx;
+ }
+ byte[] buf_array = HDFNativeData.intToByte(0, DIM_X*DIM_Y, buf_data);
+
+ // Fill selection in memory
+ try {
+ H5.H5Dfill(fill_value, HDF5Constants.H5T_NATIVE_UINT, buf_array, HDF5Constants.H5T_NATIVE_UINT, H5dsid);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("H5.H5Dfill: " + err);
+ }
+ buf_data = HDFNativeData.byteToInt(buf_array);
+
+ // Verify memory buffer the hard way
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++)
+ assertTrue("H5.H5Dfill: [" + indx+","+jndx + "] ", buf_data[(indx * DIM_Y) + jndx] == 254);
+ }
+
+ @Test
+ public void testH5Diterate() {
+ final int SPACE_RANK = 2;
+ final int SPACE_FILL = 254;
+
+ class H5D_iter_data implements H5D_iterate_t {
+ public int fill_value; /* The fill value to check */
+ public long fill_curr_coord; /* Current coordinate to examine */
+ public long[] fill_coords; /* Pointer to selection's coordinates */
+ }
+
+ H5D_iterate_t iter_data = new H5D_iter_data();
+
+ class H5D_iter_callback implements H5D_iterate_cb {
+ public int callback(byte[] elem_buf, long elem_id, int ndim, long[] point, H5D_iterate_t op_data) {
+ //Check value in current buffer location
+ int element = HDFNativeData.byteToInt(elem_buf, 0);
+ if(element != ((H5D_iter_data)op_data).fill_value)
+ return -1;
+ //Check number of dimensions
+ if(ndim != SPACE_RANK)
+ return(-1);
+ //Check Coordinates
+ long[] fill_coords = new long[2];
+ fill_coords[0] = ((H5D_iter_data)op_data).fill_coords[(int) (2 * ((H5D_iter_data)op_data).fill_curr_coord)];
+ fill_coords[1] = ((H5D_iter_data)op_data).fill_coords[(int) (2 * ((H5D_iter_data)op_data).fill_curr_coord) + 1];
+ ((H5D_iter_data)op_data).fill_curr_coord++;
+ if(fill_coords[0] != point[0])
+ return(-1);
+ if(fill_coords[1] != point[1])
+ return(-1);
+
+ return(0);
+ }
+ }
+
+ int[] buf_data = new int[DIM_X*DIM_Y];
+ byte[] fill_value = HDFNativeData.intToByte(SPACE_FILL);
+
+ // Initialize memory buffer
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++) {
+ buf_data[(indx * DIM_Y) + jndx] = indx * jndx - jndx;
+ }
+ byte[] buf_array = HDFNativeData.intToByte(0, DIM_X*DIM_Y, buf_data);
+
+ // Fill selection in memory
+ try {
+ H5.H5Dfill(fill_value, HDF5Constants.H5T_NATIVE_UINT, buf_array, HDF5Constants.H5T_NATIVE_UINT, H5dsid);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("H5.H5Diterate: " + err);
+ }
+
+ // Initialize the iterator structure
+ ((H5D_iter_data)iter_data).fill_value = SPACE_FILL;
+ ((H5D_iter_data)iter_data).fill_curr_coord = 0;
+ // Set the coordinates of the selection
+ ((H5D_iter_data)iter_data).fill_coords = new long[DIM_X*DIM_Y*SPACE_RANK]; /* Coordinates of selection */
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++) {
+ ((H5D_iter_data)iter_data).fill_coords[2*(indx * DIM_Y + jndx)] = indx;
+ ((H5D_iter_data)iter_data).fill_coords[2*(indx * DIM_Y + jndx) + 1] = jndx;
+ } /* end for */
+
+ // Iterate through selection, verifying correct data
+ H5D_iterate_cb iter_cb = new H5D_iter_callback();
+ int op_status = -1;
+ try {
+ op_status = H5.H5Diterate(buf_array, HDF5Constants.H5T_NATIVE_UINT, H5dsid, iter_cb, iter_data);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Diterate: " + err);
+ }
+ assertTrue("H5Diterate ", op_status == 0);
+ }
+
+ @Test
+ public void testH5Diterate_write() {
+ final int SPACE_RANK = 2;
+ final int SPACE_FILL = 254;
+
+ class H5D_iter_data implements H5D_iterate_t {
+ public int fill_value; /* The fill value to check */
+ public long fill_curr_coord; /* Current coordinate to examine */
+ public long[] fill_coords; /* Pointer to selection's coordinates */
+ }
+
+ H5D_iterate_t iter_data = new H5D_iter_data();
+
+ class H5D_iter_callback implements H5D_iterate_cb {
+ public int callback(byte[] elem_buf, long elem_id, int ndim, long[] point, H5D_iterate_t op_data) {
+ //Check value in current buffer location
+ int element = HDFNativeData.byteToInt(elem_buf, 0);
+ if(element != ((H5D_iter_data)op_data).fill_value)
+ return -1;
+ //Check number of dimensions
+ if(ndim != SPACE_RANK)
+ return(-1);
+ //Check Coordinates
+ long[] fill_coords = new long[2];
+ fill_coords[0] = ((H5D_iter_data)op_data).fill_coords[(int) (2 * ((H5D_iter_data)op_data).fill_curr_coord)];
+ fill_coords[1] = ((H5D_iter_data)op_data).fill_coords[(int) (2 * ((H5D_iter_data)op_data).fill_curr_coord) + 1];
+ ((H5D_iter_data)op_data).fill_curr_coord++;
+ if(fill_coords[0] != point[0])
+ return(-1);
+ if(fill_coords[1] != point[1])
+ return(-1);
+ element -= 128;
+ byte[] new_elembuf = HDFNativeData.intToByte(element);
+ elem_buf[0] = new_elembuf[0];
+ elem_buf[1] = new_elembuf[1];
+ elem_buf[2] = new_elembuf[2];
+ elem_buf[3] = new_elembuf[3];
+ return(0);
+ }
+ }
+
+ int[] buf_data = new int[DIM_X*DIM_Y];
+ byte[] fill_value = HDFNativeData.intToByte(SPACE_FILL);
+
+ // Initialize memory buffer
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++) {
+ buf_data[(indx * DIM_Y) + jndx] = indx * jndx - jndx;
+ }
+ byte[] buf_array = HDFNativeData.intToByte(0, DIM_X*DIM_Y, buf_data);
+
+ // Fill selection in memory
+ try {
+ H5.H5Dfill(fill_value, HDF5Constants.H5T_NATIVE_UINT, buf_array, HDF5Constants.H5T_NATIVE_UINT, H5dsid);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("H5.H5Diterate: " + err);
+ }
+
+ // Initialize the iterator structure
+ ((H5D_iter_data)iter_data).fill_value = SPACE_FILL;
+ ((H5D_iter_data)iter_data).fill_curr_coord = 0;
+ // Set the coordinates of the selection
+ ((H5D_iter_data)iter_data).fill_coords = new long[DIM_X*DIM_Y*SPACE_RANK]; /* Coordinates of selection */
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++) {
+ ((H5D_iter_data)iter_data).fill_coords[2*(indx * DIM_Y + jndx)] = indx;
+ ((H5D_iter_data)iter_data).fill_coords[2*(indx * DIM_Y + jndx) + 1] = jndx;
+ } /* end for */
+
+ // Iterate through selection, verifying correct data
+ H5D_iterate_cb iter_cb = new H5D_iter_callback();
+ int op_status = -1;
+ try {
+ op_status = H5.H5Diterate(buf_array, HDF5Constants.H5T_NATIVE_UINT, H5dsid, iter_cb, iter_data);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Diterate: " + err);
+ }
+ assertTrue("H5Diterate ", op_status == 0);
+
+ buf_data = HDFNativeData.byteToInt(buf_array);
+
+ // Verify memory buffer the hard way
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++)
+ assertTrue("H5.H5Diterate: [" + indx+","+jndx + "] "+buf_data[(indx * DIM_Y) + jndx], buf_data[(indx * DIM_Y) + jndx] == 126);
+ }
+
+ @Test
+ public void testH5Dvlen_get_buf_size() {
+ String[] str_data = { "Parting", "is such", "sweet", "sorrow.",
+ "Testing", "one", "two", "three.",
+ "Dog,", "man's", "best", "friend.",
+ "Diamonds", "are", "a", "girls!",
+ "S A", "T U R", "D A Y", "night",
+ "That's", "all", "folks", "!!!" };
+ long vl_size = -1; /* Number of bytes used */
+ long str_data_bytes = 0;
+ for (int idx = 0; idx < str_data.length; idx++)
+ str_data_bytes += str_data[idx].length() + 1; //Account for terminating null
+
+ _createVLDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+
+ try {
+ if ((H5did >= 0) && (H5dtid >= 0))
+ H5.H5Dwrite_VLStrings(H5did, H5dtid,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, str_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ try {
+ vl_size = H5.H5Dvlen_get_buf_size(H5did, H5dtid, H5dsid);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ assertTrue("H5Dvlen_get_buf_size " + vl_size + " == " + str_data_bytes, vl_size == str_data_bytes);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Dvlen_read_invalid_buffer() throws Throwable {
+ String[] str_data = { "Parting", "is such", "sweet", "sorrow.",
+ "Testing", "one", "two", "three.",
+ "Dog,", "man's", "best", "friend.",
+ "Diamonds", "are", "a", "girls!",
+ "S A", "T U R", "D A Y", "night",
+ "That's", "all", "folks", "!!!" };
+ byte[] read_data = new byte[512];
+
+ _createVLDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+
+ try {
+ H5.H5Dwrite_VLStrings(H5did, H5dtid,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, str_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ H5.H5Dread(H5did, H5dtid,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, read_data);
+ }
+
+ @Test
+ public void testH5Dvlen_write_read() {
+ String[] str_wdata = { "Parting", "is such", "sweet", "sorrow.",
+ "Testing", "one", "two", "three.",
+ "Dog,", "man's", "best", "friend.",
+ "Diamonds", "are", "a", "girls!",
+ "S A", "T U R", "D A Y", "night",
+ "That's", "all", "folks", "!!!" };
+ String[] str_rdata = new String[DIM_X * DIM_Y];
+
+ _createVLDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+
+ try {
+ if ((H5did >= 0) && (H5dtid >= 0))
+ H5.H5Dwrite_VLStrings(H5did, H5dtid,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, str_wdata);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ try {
+ if ((H5did >= 0) && (H5dtid >= 0))
+ H5.H5Dread_VLStrings(H5did, H5dtid,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, str_rdata);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ for (int v = 0; v < DIM_X * DIM_Y; v++)
+ assertTrue("testH5Dvlen_write_read " + str_wdata[v] + " == " + str_rdata[v], str_wdata[v] == str_wdata[v]);
+ }
+
+}
diff --git a/java/test/TestH5Dparams.java b/java/test/TestH5Dparams.java
new file mode 100644
index 0000000..f056027
--- /dev/null
+++ b/java/test/TestH5Dparams.java
@@ -0,0 +1,134 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 hdf.hdf5lib.H5;
+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 TestH5Dparams {
+ @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//(expected = HDF5LibraryException.class)
+ public void testH5Dclose_invalid() throws Throwable {
+ long did = H5.H5Dclose(-1);
+ assertTrue(did == 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Dcreate_null() throws Throwable {
+ H5.H5Dcreate(-1, null, 0, 0, 0, 0, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dcreate_invalid() throws Throwable {
+ H5.H5Dcreate(-1, "Bogus", -1, -1, -1, -1, -1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dcreate_anon_invalid() throws Throwable {
+ H5.H5Dcreate_anon(-1, -1, -1, -1, -1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dget_access_plist_invalid() throws Throwable {
+ H5.H5Dget_access_plist(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dget_create_plist_invalid() throws Throwable {
+ H5.H5Dget_create_plist(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dget_offset_invalid() throws Throwable {
+ H5.H5Dget_offset(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dget_space_invalid() throws Throwable {
+ H5.H5Dget_space(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dget_type_invalid() throws Throwable {
+ H5.H5Dget_type(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dget_space_status_invalid() throws Throwable {
+ int status = H5.H5Dget_space_status(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dset_extent_status_invalid() throws Throwable {
+ long[] size = new long[2];
+ H5.H5Dset_extent(-1, size);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Dset_extent_status_null() throws Throwable {
+ H5.H5Dset_extent(-1, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Dopen_null() throws Throwable {
+ H5.H5Dopen(-1, null, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dopen_invalid() throws Throwable {
+ H5.H5Dopen(-1, "Bogus", 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dvlen_get_buf_size_invalid() throws Throwable {
+ H5.H5Dvlen_get_buf_size(-1, -1, -1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Dvlen_reclaim_invalid() throws Throwable {
+ byte[] buf = new byte[2];
+ H5.H5Dvlen_reclaim(-1, -1, -1, buf);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Dvlen_reclaim_null() throws Throwable {
+ H5.H5Dvlen_reclaim(-1, -1, -1, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Dget_storage_size_invalid() throws Throwable {
+ H5.H5Dget_storage_size(-1);
+ }
+
+}
diff --git a/java/test/TestH5Dplist.java b/java/test/TestH5Dplist.java
new file mode 100644
index 0000000..eb1669f
--- /dev/null
+++ b/java/test/TestH5Dplist.java
@@ -0,0 +1,216 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 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.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5Dplist {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "test.h5";
+ private static final int DIM_X = 4;
+ private static final int DIM_Y = 7;
+ private static final int EDIM_X = 6;
+ private static final int EDIM_Y = 10;
+ private static final int CHUNK_X = 4;
+ private static final int CHUNK_Y = 4;
+ private static final int NDIMS = 2;
+ private static final int FILLVAL = 99;
+ private static final int RANK = 2;
+ long H5fid = -1;
+ long H5dsid = -1;
+ long H5did = -1;
+ long H5dcpl_id = -1;
+ long[] H5dims = { DIM_X, DIM_Y };
+ long[] H5extdims = { EDIM_X, EDIM_Y };
+ long[] H5chunk_dims = { CHUNK_X, CHUNK_Y };
+ long[] H5maxdims = { HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED };
+
+ private final void _deleteFile(String filename) {
+ File file = new File(filename);
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ }
+
+ private final void _createPDataset(long fid, long dsid, String name, long dcpl_val) {
+ try {
+ H5dcpl_id = H5.H5Pcreate(dcpl_val);
+ }
+ catch (Exception err) {
+ err.printStackTrace();
+ fail("H5.H5Pcreate: " + err);
+ }
+ assertTrue("TestH5Dplist._createPDataset: ", H5dcpl_id > 0);
+
+ // Set the chunk size.
+ try {
+ H5.H5Pset_chunk(H5dcpl_id, NDIMS, H5chunk_dims);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Set the fill value for the dataset
+ try {
+ int[] fill_value = { FILLVAL };
+ H5.H5Pset_fill_value(H5dcpl_id, HDF5Constants.H5T_NATIVE_INT, fill_value);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Set the allocation time to "early". This way we can be sure
+ // that reading from the dataset immediately after creation will
+ // return the fill value.
+ try {
+ H5.H5Pset_alloc_time(H5dcpl_id, HDF5Constants.H5D_ALLOC_TIME_EARLY);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ _createDataset(H5fid, H5dsid, "dset", H5dcpl_id, HDF5Constants.H5P_DEFAULT);
+ }
+
+ private final void _createDataset(long fid, long dsid, String name, long dcpl, long dapl) {
+ try {
+ H5did = H5.H5Dcreate(fid, name,
+ HDF5Constants.H5T_STD_I32BE, dsid,
+ HDF5Constants.H5P_DEFAULT, dcpl, dapl);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Dcreate: " + err);
+ }
+ assertTrue("TestH5Dplist._createDataset: ",H5did > 0);
+ }
+
+ @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(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5dsid = H5.H5Screate_simple(RANK, H5dims, H5maxdims);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5Dplist.createH5file: " + err);
+ }
+ assertTrue("TestH5Dplist.createH5file: H5.H5Fcreate: ",H5fid > 0);
+ assertTrue("TestH5Dplist.createH5file: H5.H5Screate_simple: ",H5dsid > 0);
+
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5dcpl_id >= 0)
+ try {H5.H5Pclose(H5dcpl_id);} catch (Exception ex) {}
+ if (H5did > 0)
+ try {H5.H5Dclose(H5did);} catch (Exception ex) {}
+ if (H5dsid > 0)
+ try {H5.H5Sclose(H5dsid);} catch (Exception ex) {}
+ if (H5fid > 0)
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+
+ _deleteFile(H5_FILE);
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Dset_extent() {
+ int[][] write_dset_data = new int[DIM_X][DIM_Y];
+ int[][] read_dset_data = new int[DIM_X][DIM_Y];
+ int[][] extend_dset_data = new int[EDIM_X][EDIM_Y];
+
+ // Initialize the dataset.
+ for (int indx = 0; indx < DIM_X; indx++)
+ for (int jndx = 0; jndx < DIM_Y; jndx++)
+ write_dset_data[indx][jndx] = indx * jndx - jndx;
+
+ _createPDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DATASET_CREATE);
+
+ // Read values from the dataset, which has not been written to yet.
+ try {
+ H5.H5Dread(H5did, HDF5Constants.H5T_NATIVE_INT,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, read_dset_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ assertTrue("testH5Dset_extent - H5.H5Dread: ", read_dset_data[0][0] == 99);
+
+ // Write the data to the dataset.
+ try {
+ H5.H5Dwrite(H5did, HDF5Constants.H5T_NATIVE_INT,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, write_dset_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Read the data back.
+ try {
+ H5.H5Dread(H5did, HDF5Constants.H5T_NATIVE_INT,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, read_dset_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ assertTrue("testH5Dset_extent - H5.H5Dread: ", read_dset_data[3][6] == 12);
+
+ // Extend the dataset.
+ try {
+ H5.H5Dset_extent(H5did, H5extdims);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Read from the extended dataset.
+ try {
+ H5.H5Dread(H5did, HDF5Constants.H5T_NATIVE_INT,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, extend_dset_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ assertTrue("testH5Dset_extent - H5.H5Dread: ", extend_dset_data[3][6] == 12);
+ assertTrue("testH5Dset_extent - H5.H5Dread: ", extend_dset_data[4][8] == 99);
+ }
+
+}
diff --git a/java/test/TestH5E.java b/java/test/TestH5E.java
new file mode 100644
index 0000000..028369d
--- /dev/null
+++ b/java/test/TestH5E.java
@@ -0,0 +1,553 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.exceptions.HDF5LibraryException;
+import hdf.hdf5lib.callbacks.H5E_walk_cb;
+import hdf.hdf5lib.callbacks.H5E_walk_t;
+import hdf.hdf5lib.structs.H5E_error2_t;
+
+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 TestH5E {
+ @Rule public TestName testname = new TestName();
+ long hdf_java_classid = -1;
+ long current_stackid = -1;
+
+ @Before
+ public void H5Eget_stack_class() {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ hdf_java_classid = -1;
+ try {
+ hdf_java_classid = H5.H5Eregister_class("HDF-Java-Error",
+ "hdf-java", "2.5");
+ current_stackid = H5.H5Eget_current_stack();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_stack_class: " + err);
+ }
+ }
+
+ @After
+ public void H5Erestore_stack_class() {
+ try {
+ H5.H5Eunregister_class(hdf_java_classid);
+ hdf_java_classid = -1;
+ H5.H5Eclose_stack(current_stackid);
+ current_stackid = -1;
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Erestore_stack_class: " + err);
+ }
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Eget_class_name() {
+ try {
+ String class_name = H5.H5Eget_class_name(hdf_java_classid);
+ assertNotNull("H5.H5Eget_class_name: " + class_name, class_name);
+ assertEquals("H5.H5Eget_class_name: ", "HDF-Java-Error", class_name);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_class_name: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Eprint2() {
+ try {
+ assertFalse(current_stackid < 0);
+ H5.H5Eprint2(current_stackid, null);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eprint2: " + err);
+ }
+ }
+
+ @Ignore("Tested with create_msg_major[minor]")
+ public void testH5Eclose_msg() {
+ fail("Not yet implemented");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Ecreate_msg_name_null() throws Throwable {
+ H5.H5Ecreate_msg(hdf_java_classid, HDF5Constants.H5E_MAJOR, null);
+ }
+
+ @Test
+ public void testH5Ecreate_msg_major() {
+ try {
+ long err_id = H5.H5Ecreate_msg(hdf_java_classid,
+ HDF5Constants.H5E_MAJOR, "Error in Test");
+ assertFalse("H5.H5Ecreate_msg_major: " + err_id, err_id < 0);
+ H5.H5Eclose_msg(err_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ecreate_msg_major: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Ecreate_msg_minor() {
+ try {
+ long err_id = H5.H5Ecreate_msg(hdf_java_classid,
+ HDF5Constants.H5E_MINOR, "Error in Test Function");
+ assertFalse("H5.H5Ecreate_msg_minor: " + err_id, err_id < 0);
+ H5.H5Eclose_msg(err_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ecreate_msg_minor: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Eget_msg() {
+ int[] error_msg_type = { HDF5Constants.H5E_MINOR };
+ long err_id = -1;
+ String msg = null;
+ try {
+ err_id = H5.H5Ecreate_msg(hdf_java_classid,
+ HDF5Constants.H5E_MAJOR, "Error in Test");
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_msg: " + err);
+ }
+ assertFalse("H5.H5Eget_msg: H5Ecreate_msg - " + err_id, err_id < 0);
+ try {
+ msg = H5.H5Eget_msg(err_id, error_msg_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_msg: " + err);
+ }
+ assertNotNull("H5.H5Eget_msg: " + msg, msg);
+ assertEquals("H5.H5Eget_msg: ", "Error in Test", msg);
+ assertEquals("H5.H5Eget_msg: ", HDF5Constants.H5E_MAJOR,
+ error_msg_type[0]);
+ try {
+ H5.H5Eclose_msg(err_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_msg: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Eget_msg_major() {
+
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (HDF5LibraryException hdferr) {
+ int[] error_msg_type = { HDF5Constants.H5E_MAJOR };
+ String msg = null;
+ try {
+ msg = H5.H5Eget_msg(hdferr.getMajorErrorNumber(),
+ error_msg_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_msg: " + err);
+ }
+ assertNotNull("H5.H5Eget_msg: " + msg, msg);
+ assertEquals("H5.H5Eget_msg: ", "Invalid arguments to routine",
+ msg);
+ assertEquals("H5.H5Eget_msg: ", HDF5Constants.H5E_MAJOR,
+ error_msg_type[0]);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_msg: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Eget_msg_minor() {
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (HDF5LibraryException hdferr) {
+ int[] error_msg_type = { HDF5Constants.H5E_MINOR };
+ String msg = null;
+ try {
+ msg = H5.H5Eget_msg(hdferr.getMinorErrorNumber(),
+ error_msg_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_msg: " + err);
+ }
+ assertNotNull("H5.H5Eget_msg: " + msg, msg);
+ assertEquals("H5.H5Eget_msg: ", "Inappropriate type", msg);
+ assertEquals("H5.H5Eget_msg: ", HDF5Constants.H5E_MINOR,
+ error_msg_type[0]);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_msg: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Ecreate_stack() {
+ long stk_id = -1;
+ try {
+ stk_id = H5.H5Ecreate_stack();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ecreate_stack: " + err);
+ }
+ assertFalse("H5.H5Ecreate_stack: " + stk_id, stk_id < 0);
+ try {
+ H5.H5Eclose_stack(stk_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ecreate_stack: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Epop() {
+ try {
+ H5.H5Eset_current_stack(current_stackid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ }
+
+ // save current stack contents
+ try {
+ current_stackid = H5.H5Eget_current_stack();
+ }
+ catch (HDF5LibraryException err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+
+ long num_msg = -1;
+ try {
+ num_msg = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+
+ assertTrue("H5.H5Epop #:" + num_msg, num_msg == 0);
+
+ try {
+ num_msg = H5.H5Eget_num(current_stackid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+
+ assertTrue("H5.H5Epop #:" + num_msg, num_msg == 3);
+
+ try {
+ H5.H5Epop(current_stackid, 1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+
+ try {
+ num_msg = H5.H5Eget_num(current_stackid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+
+ assertTrue("H5.H5Epop", num_msg == 2);
+ }
+
+ @Test
+ public void testH5Epush() {
+ String err_func = "testH5Epush";
+ String err_msg = "Error message";
+ long estack_id = -1;
+ long maj_err_id = -1;
+ long min_err_id = -1;
+ long num_msg = -1;
+
+ try {
+ try {
+ maj_err_id = H5.H5Ecreate_msg(hdf_java_classid, HDF5Constants.H5E_MAJOR, "Error in Test");
+ assertFalse("testH5Epush: H5.H5Ecreate_msg_major: " + maj_err_id, maj_err_id < 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Epush: H5.H5Ecreate_msg_major: " + err);
+ }
+ try {
+ min_err_id = H5.H5Ecreate_msg(hdf_java_classid, HDF5Constants.H5E_MINOR, "Error in Test Function");
+ assertFalse("H5.H5Ecreate_msg_minor: " + min_err_id, min_err_id < 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Epush: H5.H5Ecreate_msg_minor: " + err);
+ }
+
+ try {
+ estack_id = H5.H5Ecreate_stack();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Epush: H5.H5Ecreate_stack: " + err);
+ }
+ assertFalse("testH5Epush: H5.H5Ecreate_stack: " + estack_id, estack_id < 0);
+
+ try {
+ num_msg = H5.H5Eget_num(estack_id);
+ assertTrue("testH5Epush #:" + num_msg, num_msg == 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Epush: H5.H5Eget_num: " + err);
+ }
+
+ H5.H5Epush(estack_id, "TestH5E.java", err_func, 354, hdf_java_classid, maj_err_id, min_err_id, err_msg);
+
+ try {
+ num_msg = H5.H5Eget_num(estack_id);
+ assertTrue("testH5Epush #:" + num_msg, num_msg == 1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Epush: H5.H5Eget_num: " + err);
+ }
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Epush: " + err);
+ }
+ finally {
+ if (estack_id >= 0)
+ try {H5.H5Eclose_stack(estack_id);} catch (Exception ex) {}
+ if (maj_err_id >= 0)
+ try {H5.H5Eclose_msg(maj_err_id);} catch (Exception ex) {}
+ if (min_err_id >= 0)
+ try {H5.H5Eclose_msg(min_err_id);} catch (Exception ex) {}
+ }
+ } /* end test_create() */
+
+ @Test
+ public void testH5EprintInt() {
+ assertFalse(current_stackid < 0);
+ try {
+ H5.H5Eprint2(current_stackid, null);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5EprintInt: " + err);
+ }
+ }
+
+ @Test
+ public void testH5EclearInt() {
+ try {
+ H5.H5Eclear(current_stackid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5EclearInt: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Eclear2() {
+ try {
+ H5.H5Eclear2(current_stackid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eclear2: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Eauto_is_v2() {
+ boolean is_v2 = false;
+ try {
+ is_v2 = H5.H5Eauto_is_v2(current_stackid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eauto_is_v2: " + err);
+ }
+ assertTrue("H5.H5Eauto_is_v2: ", is_v2);
+ }
+
+ @Test
+ public void testH5Eget_num() {
+ long num_msg = -1;
+ try {
+ num_msg = H5.H5Eget_num(current_stackid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_num: " + err);
+ }
+ assertTrue("H5.H5Eget_num", num_msg == 0);
+ }
+
+ @Test
+ public void testH5Eget_num_with_msg() {
+ try {
+ H5.H5Eset_current_stack(current_stackid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ }
+
+ // save current stack contents
+ try {
+ current_stackid = H5.H5Eget_current_stack();
+ }
+ catch (HDF5LibraryException err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+
+ long num_msg = -1;
+ try {
+ num_msg = H5.H5Eget_num(current_stackid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+ assertTrue("H5.H5Eget_num_with_msg #:" + num_msg, num_msg > 0);
+ }
+
+ @Test
+ public void testH5Ewalk() {
+ class wdata {
+ public String err_desc = null;
+ public String func_name = null;
+ public int line = -1;
+ wdata(String desc, String func, int lineno) {
+ this.err_desc = new String(desc);
+ this.func_name = new String(func);
+ this.line = lineno;
+ }
+ }
+ class H5E_walk_data implements H5E_walk_t {
+ public ArrayList<wdata> walkdata = new ArrayList<wdata>();
+ }
+ H5E_walk_t walk_data = new H5E_walk_data();
+ class H5E_walk_callback implements H5E_walk_cb {
+ public int callback(int nidx, H5E_error2_t info, H5E_walk_t op_data) {
+ wdata wd = new wdata(info.desc, info.func_name, info.line);
+ ((H5E_walk_data)op_data).walkdata.add(wd);
+ return 0;
+ }
+ }
+ H5E_walk_cb walk_cb = new H5E_walk_callback();
+ long num_msg = -1;
+
+ try {
+ H5.H5Eset_current_stack(current_stackid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Ewalk:H5Eset_current_stack " + err);
+ }
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ }
+
+ // save current stack contents
+ try {
+ current_stackid = H5.H5Eget_current_stack();
+ }
+ catch (HDF5LibraryException err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+
+ try {
+ num_msg = H5.H5Eget_num(current_stackid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Ewalk:H5Eget_num " + err);
+ }
+ assertTrue("testH5Ewalk #:" + num_msg, num_msg == 3);
+
+ try {
+ H5.H5Ewalk2(current_stackid, HDF5Constants.H5E_WALK_UPWARD, walk_cb, walk_data);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Ewalk:H5Ewalk2 " + err);
+ }
+ assertFalse("testH5Ewalk:H5Ewalk2 ",((H5E_walk_data)walk_data).walkdata.isEmpty());
+ assertTrue("testH5Ewalk:H5Ewalk2 "+((H5E_walk_data)walk_data).walkdata.size(),((H5E_walk_data)walk_data).walkdata.size()==3);
+ assertTrue("testH5Ewalk:H5Ewalk2 "+((wdata)((H5E_walk_data)walk_data).walkdata.get(0)).line,((wdata)((H5E_walk_data)walk_data).walkdata.get(0)).line==3767);
+ assertTrue("testH5Ewalk:H5Ewalk2 "+((wdata)((H5E_walk_data)walk_data).walkdata.get(1)).line,((wdata)((H5E_walk_data)walk_data).walkdata.get(1)).line==5506);
+ assertTrue("testH5Ewalk:H5Ewalk2 "+((wdata)((H5E_walk_data)walk_data).walkdata.get(1)).func_name,((wdata)((H5E_walk_data)walk_data).walkdata.get(1)).func_name.compareToIgnoreCase("H5P_verify_apl_and_dxpl")==0);
+ assertTrue("testH5Ewalk:H5Ewalk2 "+((wdata)((H5E_walk_data)walk_data).walkdata.get(0)).err_desc,((wdata)((H5E_walk_data)walk_data).walkdata.get(0)).err_desc.compareToIgnoreCase("not a property list")==0);
+ assertTrue("testH5Ewalk:H5Ewalk2 "+((wdata)((H5E_walk_data)walk_data).walkdata.get(1)).err_desc,((wdata)((H5E_walk_data)walk_data).walkdata.get(1)).err_desc.compareToIgnoreCase("not the required access property list")==0);
+ }
+
+}
diff --git a/java/test/TestH5Edefault.java b/java/test/TestH5Edefault.java
new file mode 100644
index 0000000..510aa2f
--- /dev/null
+++ b/java/test/TestH5Edefault.java
@@ -0,0 +1,564 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.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.HDF5LibraryException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5Edefault {
+ @Rule public TestName testname = new TestName();
+
+ @Before
+ public void H5Eset_default_stack() {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ try {
+ // Clear any active stack messages
+ H5.H5Eclear2(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (HDF5LibraryException err) {
+ err.printStackTrace();
+ fail("H5Eset_default_stack: " + err);
+ }
+ }
+ @After
+ public void nextTestName() {
+ System.out.println();
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Eprint2_invalid_classid() throws Throwable {
+ H5.H5Eprint2(-1, null);
+ }
+
+ @Test
+ public void testH5Eprint() {
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ }
+ try {
+ H5.H5Eprint2(HDF5Constants.H5E_DEFAULT, null);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eprint: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Eget_current_stack() {
+ long num_msg = -1;
+ long num_msg_default = -1;
+ long stack_id = -1;
+ long stack_id_default = HDF5Constants.H5E_DEFAULT;
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ //default stack id will be different after exception
+ stack_id_default = HDF5Constants.H5E_DEFAULT;
+ //err.printStackTrace(); //This will clear the error stack
+ }
+ // Verify we have the correct number of messages
+ try {
+ num_msg_default = H5.H5Eget_num(stack_id_default);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eget_current_stack: get_num #:" + num_msg_default,
+ num_msg_default == 3);
+
+ //Save a copy of the current stack and clears the current stack
+ try {
+ stack_id = H5.H5Eget_current_stack();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertFalse("H5.H5Eget_current_stack: get_current_stack - "
+ + stack_id, stack_id < 0);
+ assertFalse("H5.H5Eget_current_stack: get_current_stack - "
+ + stack_id, stack_id == stack_id_default);
+
+ // Verify we have the correct number of messages
+ try {
+ num_msg_default = H5.H5Eget_num(stack_id_default);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eget_current_stack: get_num #:" + num_msg_default,
+ num_msg_default == 0);
+
+ //Verify the copy has the correct number of messages
+ try {
+ num_msg = H5.H5Eget_num(stack_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eget_current_stack: get_num #:" + num_msg,
+ num_msg == 3);
+
+ try {
+ H5.H5Eclose_stack(stack_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Eget_current_stack_pop() {
+ long num_msg = -1;
+ long num_msg_default = -1;
+ long stack_id = -1;
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ //err.printStackTrace(); //This will clear the error stack
+ }
+
+ // Verify we have the correct number of messages
+ try {
+ num_msg_default = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eget_current_stack: get_num #:" + num_msg_default,
+ num_msg_default == 3);
+
+ //Save a copy of the current stack and clears the current stack
+ try {
+ stack_id = H5.H5Eget_current_stack();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertFalse("H5.H5Eget_current_stack: get_current_stack - "
+ + stack_id, stack_id < 0);
+ assertFalse("H5.H5Eget_current_stack: get_current_stack - "
+ + stack_id, stack_id == HDF5Constants.H5E_DEFAULT);
+
+ // Verify we have the correct number of messages
+ try {
+ num_msg_default = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eget_current_stack: get_num #:" + num_msg_default,
+ num_msg_default == 0);
+
+ //Verify the copy has the correct number of messages
+ try {
+ num_msg = H5.H5Eget_num(stack_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eget_current_stack: get_num #:" + num_msg,
+ num_msg == 3);
+
+ //Generate errors on default stack
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ //err.printStackTrace(); //This will clear the error stack
+ }
+
+ // Verify we have the correct number of messages
+ try {
+ num_msg_default = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eget_current_stack: get_num #:" + num_msg_default,
+ num_msg_default == 3);
+
+ //Remove one message from the current stack
+ try {
+ H5.H5Epop(HDF5Constants.H5E_DEFAULT, 1);
+ num_msg_default = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eget_current_stack: pop #:" + num_msg_default,
+ num_msg_default == 2);
+
+ //Verify the copy still has the correct number of messages
+ try {
+ num_msg = H5.H5Eget_num(stack_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eget_current_stack: get_num #:" + num_msg,
+ num_msg == 3);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Eclose_stack_invalid_stackid() throws Throwable {
+ H5.H5Eclose_stack(-1);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Eget_class_name_invalid_classid() throws Throwable {
+ H5.H5Eget_class_name(-1);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Eget_class_name_invalid_classname() throws Throwable {
+ H5.H5Eget_class_name(HDF5Constants.H5E_DEFAULT);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Eclose_msg_invalid_errid() throws Throwable {
+ H5.H5Eclose_msg(-1);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Ecreate_msg_invalid_errid() throws Throwable {
+ H5.H5Ecreate_msg(-1, HDF5Constants.H5E_MAJOR, "null");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Eget_msg_invalid_msgid() throws Throwable {
+ H5.H5Eget_msg(-1, null);
+ }
+
+ @Test
+ public void testH5Ecreate_stack() {
+ try {
+ long stack_id = H5.H5Ecreate_stack();
+ assertTrue("H5.H5Ecreate_stack", stack_id > 0);
+ H5.H5Eclose_stack(stack_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ecreate_stack: " + err);
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Eset_current_stack_invalid_stkid() throws Throwable {
+ H5.H5Eset_current_stack(-1);
+ }
+
+ @Test
+ public void testH5Eset_current_stack() {
+ long num_msg = -1;
+ long stack_id = -1;
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ //err.printStackTrace(); //This will clear the error stack
+ }
+
+ // Verify we have the correct number of messages
+ try {
+ num_msg = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eset_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eset_current_stack: get_num #:" + num_msg,
+ num_msg == 3);
+
+ //Save a copy of the current stack
+ try {
+ stack_id = H5.H5Eget_current_stack();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eset_current_stack: " + err);
+ }
+ assertFalse("H5.H5Eset_current_stack: get_current_stack - "
+ + stack_id, stack_id < 0);
+ assertFalse("H5.H5Eset_current_stack: get_current_stack - "
+ + stack_id, stack_id == HDF5Constants.H5E_DEFAULT);
+
+ //Verify the copy has the correct number of messages
+ try {
+ num_msg = H5.H5Eget_num(stack_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eset_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eset_current_stack: get_num #:" + num_msg,
+ num_msg == 3);
+
+ //Generate errors on default stack
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ //err.printStackTrace(); //This will clear the error stack
+ }
+
+ // Verify we have the correct number of messages
+ try {
+ num_msg = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eset_current_stack: get_num #:" + num_msg,
+ num_msg == 3);
+
+ //Remove one message from the current stack
+ try {
+ H5.H5Epop(HDF5Constants.H5E_DEFAULT, 1);
+ num_msg = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eset_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eset_current_stack: pop #:" + num_msg,
+ num_msg == 2);
+
+ //Verify the copy still has the correct number of messages
+ try {
+ num_msg = H5.H5Eget_num(stack_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eset_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eset_current_stack: get_num #:" + num_msg,
+ num_msg == 3);
+
+ try {
+ H5.H5Eset_current_stack(stack_id);
+ num_msg = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eset_current_stack: " + err);
+ }
+ assertTrue("H5.H5Eset_current_stack: get_num - " + num_msg,
+ num_msg == 3);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Epop_invalid_stkid() throws Throwable {
+ H5.H5Epop(-1, 0);
+ }
+
+ @Test
+ public void testH5Epop() throws Throwable {
+ long num_msg = -1;
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ }
+ try {
+ num_msg = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+ assertTrue("H5.H5Epop before #:" + num_msg, num_msg == 3);
+ try {
+ H5.H5Epop(HDF5Constants.H5E_DEFAULT, 1);
+ num_msg = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Epop: " + err);
+ }
+ assertTrue("H5.H5Epop after #:" + num_msg, num_msg == 2);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Epush_invalid_stkid() throws Throwable {
+ H5.H5Epush(-1, "Invalid", "Invalid", 0, -1, -1, -1, "Invalid message");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Epush_null_name() throws Throwable {
+ H5.H5Epush(HDF5Constants.H5E_DEFAULT, null, "Invalid", 0, HDF5Constants.H5E_DEFAULT, HDF5Constants.H5E_DEFAULT, HDF5Constants.H5E_DEFAULT, "Invalid message");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5EprintInt_invalid_classid() throws Throwable {
+ H5.H5Eprint2(-1, null);
+ }
+
+ @Test
+ public void testH5EprintInt() {
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ }
+ try {
+ H5.H5Eprint2(HDF5Constants.H5E_DEFAULT, null);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5EprintInt: " + err);
+ }
+ }
+
+ @Test
+ public void testH5EclearInt() {
+ try {
+ H5.H5Eclear(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5EclearInt: " + err);
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Eclear2_invalid_stkid() throws Throwable {
+ H5.H5Eclear2(-1);
+ }
+
+ @Test
+ public void testH5Eclear() {
+ try {
+ H5.H5Eclear2(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eclear2: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Eclear2_with_msg() {
+ long num_msg = -1;
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ }
+ try {
+ num_msg = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eclear2_with_msg: " + err);
+ }
+ assertTrue("H5.H5Eclear2_with_msg before #:" + num_msg,
+ num_msg == 3);
+ try {
+ H5.H5Eclear2(HDF5Constants.H5E_DEFAULT);
+ num_msg = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eclear2_with_msg: " + err);
+ }
+ assertTrue("H5.H5Eclear2_with_msg after #:" + num_msg, num_msg == 0);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Eauto_is_v2_invalid_stkid() throws Throwable {
+ H5.H5Eauto_is_v2(-1);
+ }
+
+ @Test
+ public void testH5Eauto_is_v2() {
+ boolean is_v2 = false;
+ try {
+ is_v2 = H5.H5Eauto_is_v2(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eauto_is_v2: " + err);
+ }
+ assertTrue("H5.H5Eauto_is_v2: ", is_v2);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Eget_num_invalid_stkid() throws Throwable {
+ H5.H5Eget_num(-1);
+ }
+
+ @Test
+ public void testH5Eget_num() {
+ long num_msg = -1;
+ try {
+ num_msg = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_num: " + err);
+ }
+ assertTrue("H5.H5Eget_num #:" + num_msg, num_msg == 0);
+ }
+
+ @Test
+ public void testH5Eget_num_with_msg() {
+ long num_msg = -1;
+ try {
+ H5.H5Fopen("test", 0, 1);
+ }
+ catch (Throwable err) {
+ }
+ try {
+ num_msg = H5.H5Eget_num(HDF5Constants.H5E_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Eget_num_with_msg: " + err);
+ }
+ assertTrue("H5.H5Eget_num_with_msg #:" + num_msg, num_msg > 0);
+ }
+
+}
diff --git a/java/test/TestH5Eregister.java b/java/test/TestH5Eregister.java
new file mode 100644
index 0000000..13e0ca2
--- /dev/null
+++ b/java/test/TestH5Eregister.java
@@ -0,0 +1,78 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5Eregister {
+ @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(expected = NullPointerException.class)
+ public void testH5Eregister_class_cls_name_null() throws Throwable {
+ H5.H5Eregister_class(null, "libname", "version");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Eregister_class_lib_name_null() throws Throwable {
+ H5.H5Eregister_class("clsname", null, "version");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Eregister_class_version_null() throws Throwable {
+ H5.H5Eregister_class("clsname", "libname", null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Eunregister_class_invalid_classid() throws Throwable {
+ H5.H5Eunregister_class(-1);
+ }
+
+ @Test
+ public void testH5Eregister_class() {
+ long hdf_java_classid = -1;
+ try {
+ hdf_java_classid = H5.H5Eregister_class("HDF-Java-Error",
+ "hdf-java", "2.5");
+ }
+ catch (Throwable err) {
+ fail("H5.H5Eregister_class: " + err);
+ }
+ try {
+ H5.H5Eunregister_class(hdf_java_classid);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Eunregister_class: " + err);
+ }
+ }
+}
diff --git a/java/test/TestH5F.java b/java/test/TestH5F.java
new file mode 100644
index 0000000..3451187
--- /dev/null
+++ b/java/test/TestH5F.java
@@ -0,0 +1,332 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+
+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 TestH5F {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "test.h5";
+
+ private static final int COUNT_OBJ_FILE = 1;
+ private static final int COUNT_OBJ_DATASET = 0;
+ private static final int COUNT_OBJ_GROUP = 0;
+ private static final int COUNT_OBJ_DATATYPE = 0;
+ private static final int COUNT_OBJ_ATTR = 0;
+ private static final int COUNT_OBJ_ALL = (COUNT_OBJ_FILE
+ + COUNT_OBJ_DATASET + COUNT_OBJ_GROUP + COUNT_OBJ_DATATYPE + COUNT_OBJ_ATTR);
+ private static final int[] OBJ_COUNTS = { COUNT_OBJ_FILE,
+ COUNT_OBJ_DATASET, COUNT_OBJ_GROUP, COUNT_OBJ_DATATYPE,
+ COUNT_OBJ_ATTR, COUNT_OBJ_ALL };
+ private static final int[] OBJ_TYPES = { HDF5Constants.H5F_OBJ_FILE,
+ HDF5Constants.H5F_OBJ_DATASET, HDF5Constants.H5F_OBJ_GROUP,
+ HDF5Constants.H5F_OBJ_DATATYPE, HDF5Constants.H5F_OBJ_ATTR,
+ HDF5Constants.H5F_OBJ_ALL };
+ long H5fid = -1;
+
+ private final void _deleteFile(String filename) {
+ File file = new File(filename);
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ }
+
+ @Before
+ public void createH5file()
+ throws HDF5LibraryException, NullPointerException {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5fid > 0) {
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ H5fid = -1;
+ }
+ _deleteFile(H5_FILE);
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Fget_create_plist() {
+ long plist = -1;
+
+ try {
+ plist = H5.H5Fget_create_plist(H5fid);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fget_create_plist: " + err);
+ }
+ assertTrue(plist > 0);
+ try {H5.H5Pclose(plist);} catch (HDF5LibraryException e) {e.printStackTrace();}
+ }
+
+ @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);
+ }
+
+ @Test
+ public void testH5Fget_access_plist() {
+ long plist = -1;
+
+ try {
+ plist = H5.H5Fget_access_plist(H5fid);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fget_access_plist: " + err);
+ }
+ assertTrue(plist > 0);
+ try {H5.H5Pclose(plist);} catch (HDF5LibraryException e) {e.printStackTrace();}
+ }
+
+ @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);
+ }
+
+ @Test
+ public void testH5Fget_intent_rdwr() {
+ int intent = 0;
+ 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 {
+ intent = H5.H5Fget_intent(fid);
+ }
+ 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) {}
+ H5fid = -1;
+ }
+
+ try {
+ fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDONLY,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fopen: " + err);
+ }
+ try {
+ intent = H5.H5Fget_intent(fid);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fget_intent: " + err);
+ }
+ assertEquals(HDF5Constants.H5F_ACC_RDONLY, intent);
+
+ try {
+ H5.H5Fclose(fid);
+ }
+ catch (Exception ex) {
+ }
+ }
+
+ @Test
+ public void testH5Fget_obj_count() {
+ long count = -1;
+
+ for (int i = 0; i < OBJ_TYPES.length; i++) {
+ try {
+ count = H5.H5Fget_obj_count(H5fid, OBJ_TYPES[i]);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fget_obj_count: " + err);
+ }
+
+ assertEquals(count, OBJ_COUNTS[i]);
+ }
+ }
+
+ @Test
+ public void testH5Fget_obj_ids() {
+ long count = 0;
+ long max_objs = 100;
+ long[] obj_id_list = new long[(int)max_objs];
+ int[] open_obj_counts = new int[OBJ_TYPES.length];
+
+ for (int i = 0; i < OBJ_TYPES.length; i++)
+ open_obj_counts[i] = 0;
+
+ open_obj_counts[0] = 1;
+ for (int i = 0; i < OBJ_TYPES.length - 1; i++)
+ open_obj_counts[OBJ_TYPES.length - 1] += open_obj_counts[i];
+
+ for (int i = 0; i < OBJ_TYPES.length; i++) {
+ try {
+ count = H5.H5Fget_obj_ids(H5fid, OBJ_TYPES[i], max_objs,
+ obj_id_list);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fget_obj_ids: " + err);
+ }
+ assertEquals(count, open_obj_counts[i]);
+ }
+ }
+ /**
+ * TODO: need to add objects to the file after H5G[D,T]create() functions
+ * are implemented.
+ */
+ //
+ // @Test
+ // public void testH5Fmount_unmount() {
+ // String file1 = "src.h5";
+ // String file2 = "dst.h5";
+ // String group1 = "/G";
+ // String group2 = "/MOUNTED";
+ //
+ // _createH5File(file1);
+ // _createH5File(file2);
+ //
+ // int fid1 = _openFile(file1, HDF5Constants.H5F_ACC_RDWR);
+ // assertTrue(fid1 > 0);
+ //
+ // int fid2 = _openFile(file2, HDF5Constants.H5F_ACC_RDWR);
+ // assertTrue(fid2 > 0);
+ //
+ // // create a group at file1
+ // int gid = _createGroup(fid1, group1);
+ // try { H5.H5Gclose(gid); } catch (Exception ex) {}
+ //
+ // // create a group at file 2
+ // gid = _createGroup(fid2, group2);
+ // try { H5.H5Gclose(gid); } catch (Exception ex) {}
+ //
+ // // before mount, "/G/MOUNTED" does not exists in file1
+ // gid = _openGroup(fid1, group1+group2);
+ // assertTrue(gid < 0);
+ //
+ // // Mount file2 under G in the file1
+ // try {
+ // H5.H5Fmount(fid1, group1, fid2, HDF5Constants.H5P_DEFAULT);
+ // }
+ // catch (Throwable err) {
+ // fail("H5.H5Fmount: "+err);
+ // }
+ //
+ // // now file1 should have group "/G/MOUNTED"
+ // gid = _openGroup(fid1, group1+group2);
+ // assertTrue(gid > 0);
+ // try { H5.H5Gclose(gid); } catch (Exception ex) {}
+ //
+ // // unmount file2 from file1
+ // try {
+ // H5.H5Funmount(fid1, group1);
+ // }
+ // catch (Throwable err) {
+ // fail("H5.H5Funmount: "+err);
+ // }
+ //
+ // // file2 was unmounted from file1, "/G/MOUNTED" does not exists in file1
+ // gid = _openGroup(fid1, group1+group2);
+ // assertTrue(gid < 0);
+ //
+ // try { H5.H5Fclose(fid1); } catch (Exception ex) {}
+ // try { H5.H5Fclose(fid2); } catch (Exception ex) {}
+ //
+ // _deleteFile(file1);
+ // _deleteFile(file2);
+ // }
+}
diff --git a/java/test/TestH5Fbasic.java b/java/test/TestH5Fbasic.java
new file mode 100644
index 0000000..c08daff
--- /dev/null
+++ b/java/test/TestH5Fbasic.java
@@ -0,0 +1,320 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertNotNull;
+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.HDF5LibraryException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5Fbasic {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "test.h5";
+ private static final String TXT_FILE = "test.txt";
+ long H5fid = -1;
+
+ private final void _deleteFile(String filename) {
+ File file = new File(filename);
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ }
+
+ @Before
+ public void createH5file() throws HDF5LibraryException, NullPointerException {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5fid > 0) {
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ }
+ _deleteFile(H5_FILE);
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Fcreate() {
+ assertTrue(H5fid > 0);
+ }
+
+ @Test
+ public void testH5Fis_hdf5() {
+ boolean isH5 = false;
+
+ try {
+ isH5 = H5.H5Fis_hdf5(H5_FILE);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fis_hdf5 failed on " + H5_FILE + ": " + err);
+ }
+ assertTrue(isH5 == true);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Fcreate_EXCL() throws Throwable {
+ H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_EXCL,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Fopen_read_only() throws Throwable {
+ long fid = -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) {
+ }
+
+ // set the file to read-only
+ File file = new File(H5_FILE);
+ if (file.setWritable(false)) {
+ // this should fail.
+ fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR,
+ HDF5Constants.H5P_DEFAULT);
+
+ try {
+ H5.H5Fclose(fid);
+ }
+ catch (Exception ex) {
+ }
+ }
+ else {
+ fail("File.setWritable(true) failed.");
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Freopen_closed() throws Throwable {
+ long fid = -1;
+ long fid2 = -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) {
+ }
+
+ // should fail because the file was closed.
+ fid2 = H5.H5Freopen(fid);
+ }
+
+ @Test
+ public void testH5Freopen() {
+ long fid = -1;
+ long fid2 = -1;
+
+ try {
+ fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDWR,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fopen: " + err);
+ }
+
+ try {
+ fid2 = H5.H5Freopen(fid);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Freopen: " + err);
+ }
+ assertTrue(fid2 > 0);
+
+ try {
+ H5.H5Fclose(fid2);
+ }
+ catch (Exception ex) {
+ }
+
+ try {
+ H5.H5Fclose(fid);
+ }
+ catch (Exception ex) {
+ }
+ }
+
+ @Test
+ public void testH5Fclose() {
+ long fid = -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 (Throwable err) {
+ fail("H5.H5Fclose: " + err);
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Fclose_twice() throws Throwable {
+ long fid = -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 (Throwable err) {
+ fail("H5.H5Fclose: " + err);
+ }
+
+ // it should fail since the file was closed.
+ H5.H5Fclose(fid);
+ }
+
+ @Test
+ public void testH5Fget_freespace() {
+ long freeSpace = 0;
+
+ try {
+ freeSpace = H5.H5Fget_freespace(H5fid);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fget_freespace: " + err);
+ }
+ assertEquals(freeSpace, 0);
+ }
+
+ // TODO add/and delete objects and test freespace
+
+ @Test
+ public void testH5Fget_filesize() {
+ long fileSize = 0;
+
+ try {
+ fileSize = H5.H5Fget_filesize(H5fid);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fget_freespace: " + err);
+ }
+ assertTrue(fileSize > 0);
+ }
+
+ // TODO add/and delete objects and test freespace
+
+ @Test
+ public void testH5Fget_mdc_hit_rate() {
+ double rate;
+
+ try {
+ rate = H5.H5Fget_mdc_hit_rate(H5fid);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fget_mdc_hit_rate: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Fget_mdc_size() {
+ int nentries = -1;
+ long cache_sizes[] = new long[3];
+
+ try {
+ nentries = H5.H5Fget_mdc_size(H5fid, cache_sizes);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fget_mdc_size: " + err);
+ }
+ assertTrue("H5.H5Fget_mdc_size #:" + nentries, nentries == 4);
+ }
+
+ // TODO: test more cases of different cache sizes.
+
+ @Test
+ public void testH5Freset_mdc_hit_rate_stats() {
+
+ try {
+ H5.H5Freset_mdc_hit_rate_stats(H5fid);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Freset_mdc_hit_rate_stats: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Fget_name() {
+ String fname = null;
+
+ try {
+ fname = H5.H5Fget_name(H5fid);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fget_name: " + err);
+ }
+ assertNotNull(fname);
+ assertEquals(fname, H5_FILE);
+ }
+
+ @Test
+ public void testH5Fclear_elink_file_cache() {
+
+ try {
+ H5.H5Fclear_elink_file_cache(H5fid);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Freset_mdc_hit_rate_stats: " + err);
+ }
+ }
+}
diff --git a/java/test/TestH5Fparams.java b/java/test/TestH5Fparams.java
new file mode 100644
index 0000000..2d67f3d
--- /dev/null
+++ b/java/test/TestH5Fparams.java
@@ -0,0 +1,215 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.structs.H5F_info2_t;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5Fparams {
+ @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(expected = NullPointerException.class)
+ public void testH5Fcreate_null() throws Throwable {
+ H5.H5Fcreate(null, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Fopen_null() throws Throwable {
+ H5.H5Fopen(null, HDF5Constants.H5F_ACC_RDWR, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Fis_hdf5_null() throws Throwable {
+ H5.H5Fis_hdf5(null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Fmount_null() throws Throwable {
+ H5.H5Fmount(-1, null, -1, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Funmount_null() throws Throwable {
+ H5.H5Funmount(-1, null);
+ }
+
+ @Test
+ public void testH5Fis_hdf5_text() {
+ File txtFile = null;
+ boolean isH5 = false;
+
+ try {
+ txtFile = new File("test.txt");
+ if (!txtFile.exists())
+ txtFile.createNewFile();
+ isH5 = H5.H5Fis_hdf5("test.txt");
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fis_hdf5 failed on test.txt: " + err);
+ }
+
+ assertFalse(isH5);
+
+ try {
+ txtFile.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+
+ @Test//(expected = HDF5LibraryException.class)
+ public void testH5Fclose_negative() throws Throwable {
+ // cannot close a file with negative id.
+ int fid = H5.H5Fclose(-1);
+ assertTrue(fid == 0);
+ }
+
+ @Test
+ public void testH5Fcreate() {
+ long fid = -1;
+ File file = null;
+
+ try {
+ fid = H5.H5Fcreate("test.h5", HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ if (fid > 0) {
+ H5.H5Fclose(fid);
+ }
+ file = new File("test.h5");
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fopen: " + err);
+ }
+
+ if (file.exists()) {
+ try {
+ file.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+ }
+
+ @Test
+ public void testH5Fflush_global() {
+ long fid = -1;
+
+ try {
+ fid = H5.H5Fcreate("test.h5", HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fopen: " + err);
+ }
+
+ try {
+ H5.H5Fflush(fid, HDF5Constants.H5F_SCOPE_GLOBAL);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fflush: " + err);
+ }
+
+ try {
+ H5.H5Fclose(fid);
+ }
+ catch (Exception ex) {
+ }
+ }
+
+ @Test
+ public void testH5Fflush_local() {
+ long fid = -1;
+
+ try {
+ fid = H5.H5Fcreate("test.h5", HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fopen: " + err);
+ }
+
+ try {
+ H5.H5Fflush(fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fflush: " + err);
+ }
+
+ try {
+ H5.H5Fclose(fid);
+ }
+ catch (Exception ex) {
+ }
+ }
+
+ @Test
+ public void testH5Fget_info() {
+ long fid = -1;
+
+ try {
+ try {
+ fid = H5.H5Fcreate("test.h5", HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fopen: " + err);
+ }
+
+ try {
+ H5F_info2_t finfo = H5.H5Fget_info(fid);
+ assertEquals(finfo.super_version, 0);
+ assertEquals(finfo.free_version, 0);
+ assertEquals(finfo.sohm_version, 0);
+ }
+ catch (Throwable err) {
+ fail("H5.H5Fget_info: " + err);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ finally {
+ try {H5.H5Fclose(fid);} catch (Exception ex) {}
+ }
+ }
+}
diff --git a/java/test/TestH5G.java b/java/test/TestH5G.java
new file mode 100644
index 0000000..32329bb
--- /dev/null
+++ b/java/test/TestH5G.java
@@ -0,0 +1,505 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertNotNull;
+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.HDF5LibraryException;
+import hdf.hdf5lib.structs.H5G_info_t;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5G {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "test.h5";
+ private static final String H5_FILE2 = "test2.h5";
+ private static final String[] GROUPS = { "/G1", "/G1/G11", "/G1/G12",
+ "/G1/G11/G111", "/G1/G11/G112", "/G1/G11/G113", "/G1/G11/G114" };
+ private static final String[] GROUPS2 = { "/G1", "/G1/G14", "/G1/G12", "/G1/G13", "/G1/G11"};
+ long H5fid = -1;
+ long H5fid2 = -1;
+
+ private final long _createGroup(long fid, String name) {
+ long gid = -1;
+ try {
+ gid = H5.H5Gcreate(fid, name, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Gcreate: " + err);
+ }
+ assertTrue("TestH5G._createGroup: ", gid > 0);
+
+ return gid;
+ }
+
+ private final long _createGroup2(long fid, String name) {
+ long gid = -1;
+ long gcpl = -1;
+ try {
+ gcpl = H5.H5Pcreate(HDF5Constants.H5P_GROUP_CREATE); //create gcpl
+ }
+ catch (final Exception ex) {
+ fail("H5.H5Pcreate(): " + ex);
+ }
+ assertTrue("TestH5G._createGroup2: ", gcpl >= 0);
+ try {
+ H5.H5Pset_link_creation_order(gcpl, HDF5Constants.H5P_CRT_ORDER_TRACKED
+ + HDF5Constants.H5P_CRT_ORDER_INDEXED); // Set link creation order
+ }
+ catch (final Exception ex) {
+ try {H5.H5Pclose(gcpl);} catch (final Exception exx) {}
+ fail("H5.H5Pset_link_creation_order: " + ex);
+ }
+ try {
+ gid = H5.H5Gcreate(fid, name, HDF5Constants.H5P_DEFAULT,
+ gcpl, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Gcreate: " + err);
+ }
+ finally {
+ try {H5.H5Pclose(gcpl);} catch (final Exception ex) {}
+ }
+ assertTrue("TestH5G._createGroup2: ", gid > 0);
+
+ return gid;
+ }
+
+ private final long _openGroup(long fid, String name) {
+ long gid = -1;
+ try {
+ gid = H5.H5Gopen(fid, name, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ gid = -1;
+ err.printStackTrace();
+ fail("H5.H5Gopen: " + err);
+ }
+ assertTrue("TestH5G._openGroup: ", gid > 0);
+
+ return gid;
+ }
+
+ private final void _deleteFile(String filename) {
+ File file = new File(filename);
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ }
+
+ @Before
+ public void createH5file()
+ throws HDF5LibraryException, NullPointerException {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ try {
+ H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+
+ H5fid2 = H5.H5Fcreate(H5_FILE2, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.createH5file: " + err);
+ }
+ assertTrue("TestH5G.createH5file: H5.H5Fcreate: ", H5fid > 0);
+ assertTrue("TestH5G.createH5file: H5.H5Fcreate: ", H5fid2 > 0);
+
+ long gid = -1;
+
+ for (int i = 0; i < GROUPS.length; i++) {
+ gid = _createGroup(H5fid, GROUPS[i]);
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ for (int i = 0; i < GROUPS2.length; i++) {
+ gid = _createGroup2(H5fid2, GROUPS2[i]);
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ H5.H5Fflush(H5fid2, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5fid > 0) {
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ }
+ if (H5fid2 > 0) {
+ try {H5.H5Fclose(H5fid2);} catch (Exception ex) {}
+ }
+ _deleteFile(H5_FILE);
+ _deleteFile(H5_FILE2);
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Gopen() {
+ long gid = -1;
+ for (int i = 0; i < GROUPS.length; i++) {
+ try {
+ gid = H5.H5Gopen(H5fid, GROUPS[i], HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gopen: H5.H5Gopen: " + err);
+ }
+ assertTrue("TestH5G.testH5Gopen: ", gid > 0);
+ try {
+ H5.H5Gclose(gid);
+ }
+ catch (Exception ex) {
+ }
+ }
+ }
+
+ @Test
+ public void testH5Gget_create_plist() {
+ long gid = -1;
+ long pid = -1;
+
+ for (int i = 0; i < GROUPS.length; i++) {
+ try {
+ gid = H5.H5Gopen(H5fid, GROUPS[i], HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_create_plist: H5.H5Gopen: " + err);
+ }
+ assertTrue("TestH5G.testH5Gget_create_plist: ", gid > 0);
+
+ try {
+ pid = H5.H5Gget_create_plist(gid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_create_plist: H5.H5Gget_create_plist: " + err);
+ }
+ assertTrue("TestH5G.testH5Gget_create_plist: ", pid > 0);
+
+ try {
+ H5.H5Gclose(gid);
+ }
+ catch (Exception ex) {
+ }
+ }
+ }
+
+ @Test
+ public void testH5Gget_info() {
+ H5G_info_t info = null;
+
+ for (int i = 0; i < GROUPS.length; i++) {
+
+ try {
+ info = H5.H5Gget_info(H5fid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_info: H5.H5Gget_info: " + err);
+ }
+ assertNotNull("TestH5G.testH5Gget_info: ", info);
+ }
+ }
+
+ @Test
+ public void testH5Gget_info_by_name() {
+ H5G_info_t info = null;
+
+ for (int i = 0; i < GROUPS.length; i++) {
+ try {
+ info = H5.H5Gget_info_by_name(H5fid, GROUPS[i],
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_info_by_name: H5.H5Gget_info_by_name: " + err);
+ }
+ assertNotNull("TestH5G.testH5Gget_info_by_name: ", info);
+ }
+ }
+
+ @Test
+ public void testH5Gget_info_by_idx() {
+ H5G_info_t info = null;
+ for (int i = 0; i < 2; i++) {
+ try {
+ info = H5.H5Gget_info_by_idx(H5fid, "/G1",
+ HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC,
+ i, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_info_by_idx: H5.H5Gget_info_by_idx: " + err);
+ }
+ assertNotNull("TestH5G.testH5Gget_info_by_idx: ", info);
+ }
+ }
+
+ @Test
+ public void testH5Gget_obj_info_all() {
+ H5G_info_t info = null;
+
+ long gid = _openGroup(H5fid, GROUPS[0]);
+
+ try {
+ info = H5.H5Gget_info(gid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_obj_info_all: H5.H5Gget_info: " + err);
+ }
+ finally {
+ try {H5.H5Gclose(gid);} catch (Exception ex) { }
+ }
+ assertNotNull("TestH5G.testH5Gget_obj_info_all: ", info);
+ assertTrue("TestH5G.testH5Gget_obj_info_all: number of links is empty", info.nlinks > 0);
+ String objNames[] = new String[(int) info.nlinks];
+ int objTypes[] = new int[(int) info.nlinks];
+ int lnkTypes[] = new int[(int) info.nlinks];
+ long objRefs[] = new long[(int) info.nlinks];
+
+ int names_found = 0;
+ try {
+ names_found = H5.H5Gget_obj_info_all(H5fid, GROUPS[0], objNames,
+ objTypes, lnkTypes, objRefs, HDF5Constants.H5_INDEX_NAME);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_obj_info_all: H5.H5Gget_obj_info_all: " + err);
+ }
+
+ assertTrue("number found[" + names_found + "] different than expected["
+ + objNames.length + "]", names_found == objNames.length);
+ for (int i = 0; i < objNames.length; i++) {
+ assertNotNull("name #" + i + " does not exist", objNames[i]);
+ assertTrue("TestH5G.testH5Gget_obj_info_all: ", objNames[i].length() > 0);
+ }
+ }
+
+ @Test
+ public void testH5Gget_obj_info_all_gid() {
+ H5G_info_t info = null;
+
+ long gid = _openGroup(H5fid, GROUPS[0]);
+
+ try {
+ info = H5.H5Gget_info(gid);
+ assertNotNull("TestH5G.testH5Gget_obj_info_all_gid: ", info);
+ assertTrue("TestH5G.testH5Gget_obj_info_all_gid: number of links is empty", info.nlinks > 0);
+ String objNames[] = new String[(int) info.nlinks];
+ long objRefs[] = new long[(int) info.nlinks];
+ int lnkTypes[] = new int[(int) info.nlinks];
+ int objTypes[] = new int[(int) info.nlinks];
+
+ int names_found = 0;
+ try {
+ names_found = H5.H5Gget_obj_info_all(gid, null, objNames, objTypes, lnkTypes,
+ objRefs, HDF5Constants.H5_INDEX_NAME);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_obj_info_all_gid: H5.H5Gget_obj_info_all: " + err);
+ }
+
+ assertTrue("TestH5G.testH5Gget_obj_info_all_gid: number found[" + names_found + "] different than expected["
+ + objNames.length + "]", names_found == objNames.length);
+ for (int i = 0; i < objNames.length; i++) {
+ assertNotNull("TestH5G.testH5Gget_obj_info_all_gid: name #" + i + " does not exist", objNames[i]);
+ assertTrue("TestH5G.testH5Gget_obj_info_all_gid: ", objNames[i].length() > 0);
+ }
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_obj_info_all_gid: H5.H5Gget_info: " + err);
+ }
+ finally {
+ try {H5.H5Gclose(gid);} catch (Exception ex) { }
+ }
+ }
+
+ @Test
+ public void testH5Gget_obj_info_all_gid2() {
+ H5G_info_t info = null;
+
+ long gid = _openGroup(H5fid, GROUPS[1]);
+
+ try {
+ info = H5.H5Gget_info(gid);
+ assertNotNull("TestH5G.testH5Gget_obj_info_all_gid2: ", info);
+ assertTrue("TestH5G.testH5Gget_obj_info_all_gid2: number of links is empty", info.nlinks > 0);
+ String objNames[] = new String[(int) info.nlinks];
+ long objRefs[] = new long[(int) info.nlinks];
+ int lnkTypes[] = new int[(int) info.nlinks];
+ int objTypes[] = new int[(int) info.nlinks];
+
+ int names_found = 0;
+ try {
+ names_found = H5.H5Gget_obj_info_all(gid, null, objNames, objTypes, lnkTypes,
+ objRefs, HDF5Constants.H5_INDEX_NAME);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_obj_info_all_gid2: H5.H5Gget_obj_info_all: " + err);
+ }
+
+ assertTrue("TestH5G.testH5Gget_obj_info_all_gid2: number found[" + names_found + "] different than expected["
+ + objNames.length + "]", names_found == objNames.length);
+ for (int i = 0; i < objNames.length; i++) {
+ assertNotNull("TestH5G.testH5Gget_obj_info_all_gid2: name #" + i + " does not exist", objNames[i]);
+ assertTrue("TestH5G.testH5Gget_obj_info_all_gid2: ", objNames[i].length() > 0);
+ }
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_obj_info_all_gid2: H5.H5Gget_info: " + err);
+ }
+ finally {
+ try {H5.H5Gclose(gid);} catch (Exception ex) { }
+ }
+ }
+
+ @Test
+ public void testH5Gget_obj_info_max() {
+ long gid = _openGroup(H5fid, GROUPS[0]);
+ long groups_max_size = GROUPS.length + 1;
+ String objNames[] = new String[(int)groups_max_size];
+ int objTypes[] = new int[(int)groups_max_size];
+ int lnkTypes[] = new int[(int)groups_max_size];
+ long objRefs[] = new long[(int)groups_max_size];
+
+ int names_found = 0;
+ try {
+ names_found = H5.H5Gget_obj_info_max(gid, objNames, objTypes, lnkTypes,
+ objRefs, groups_max_size);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_obj_info_max: H5.H5Gget_obj_info_max: " + err);
+ }
+ finally {
+ try {H5.H5Gclose(gid);} catch (Exception ex) { }
+ }
+
+ // expected number does not include root group
+ assertTrue("TestH5G.testH5Gget_obj_info_max: number found[" + names_found + "] different than expected["
+ + (GROUPS.length - 1) + "]", names_found == (GROUPS.length - 1));
+ for (int i = 0; i < GROUPS.length-1; i++) {
+ assertNotNull("TestH5G.testH5Gget_obj_info_max: name #"+i+" does not exist",objNames[i]);
+ assertTrue("TestH5G.testH5Gget_obj_info_max: ", objNames[i].length()>0);
+ }
+ }
+
+ @Test
+ public void testH5Gget_obj_info_max_limit() {
+ long gid = _openGroup(H5fid, GROUPS[0]);
+ long groups_max_size = GROUPS.length - 3;
+ String objNames[] = new String[(int)groups_max_size];
+ int objTypes[] = new int[(int)groups_max_size];
+ int lnkTypes[] = new int[(int)groups_max_size];
+ long objRefs[] = new long[(int)groups_max_size];
+
+ int names_found = 0;
+ try {
+ names_found = H5.H5Gget_obj_info_max(gid, objNames, objTypes, lnkTypes,
+ objRefs, groups_max_size);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_obj_info_max_limit: H5.H5Gget_obj_info_max: " + err);
+ }
+ finally {
+ try {H5.H5Gclose(gid);} catch (Exception ex) { }
+ }
+
+ assertTrue("TestH5G.testH5Gget_obj_info_max_limit: number found[" + names_found + "] different than expected["
+ + groups_max_size + "]", names_found == groups_max_size);
+ for (int i = 0; i < objNames.length; i++) {
+ assertNotNull("TestH5G.testH5Gget_obj_info_max_limit: name #" + i + " does not exist", objNames[i]);
+ assertTrue("TestH5G.testH5Gget_obj_info_max_limit: ", objNames[i].length() > 0);
+ }
+ }
+
+ @Test
+ public void testH5Gget_obj_info_all_byIndexType() {
+ H5G_info_t info = null;
+
+ long gid = _openGroup(H5fid2, GROUPS2[0]);
+
+ try {
+ info = H5.H5Gget_info(gid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_obj_info_all_byIndexType: H5.H5Gget_info: " + err);
+ }
+ finally {
+ try {H5.H5Gclose(gid);} catch (Exception ex) { }
+ }
+
+ assertNotNull("TestH5G.testH5Gget_obj_info_all_byIndexType: ", info);
+ assertTrue("TestH5G.testH5Gget_obj_info_all_byIndexType: number of links is empty", info.nlinks > 0);
+ String objNames[] = new String[(int) info.nlinks];
+ int objTypes[] = new int[(int) info.nlinks];
+ int lnkTypes[] = new int[(int) info.nlinks];
+ long objRefs[] = new long[(int) info.nlinks];
+
+ try {
+ H5.H5Gget_obj_info_all(H5fid2, GROUPS2[0], objNames,
+ objTypes, lnkTypes, objRefs, HDF5Constants.H5_INDEX_CRT_ORDER);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_obj_info_all_byIndexType: H5.H5Gget_obj_info_all: " + err);
+ }
+
+ assertEquals("G12",objNames[1]);
+ assertEquals("G13", objNames[2] );
+ assertEquals("G11", objNames[3] );
+
+ try {
+ H5.H5Gget_obj_info_all(H5fid2, GROUPS2[0], objNames,
+ objTypes, lnkTypes, objRefs, HDF5Constants.H5_INDEX_NAME);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5G.testH5Gget_obj_info_all_byIndexType: H5.H5Gget_obj_info_all: " + err);
+ }
+
+ assertEquals("G12",objNames[1]);
+ assertEquals("G13", objNames[2] );
+ assertEquals("G14", objNames[3] );
+ }
+
+}
diff --git a/java/test/TestH5Gbasic.java b/java/test/TestH5Gbasic.java
new file mode 100644
index 0000000..70acef4
--- /dev/null
+++ b/java/test/TestH5Gbasic.java
@@ -0,0 +1,371 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertNotNull;
+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.HDF5LibraryException;
+import hdf.hdf5lib.structs.H5G_info_t;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5Gbasic {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "test.h5";
+ long H5fid = -1;
+
+ private final long _createGroup(long fid, String name) {
+ long gid = -1;
+ try {
+ gid = H5.H5Gcreate(fid, name, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Gcreate: " + err);
+ }
+
+ return gid;
+ }
+
+ private final void _deleteFile(String filename) {
+ File file = new File(filename);
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ }
+
+ @Before
+ public void createH5file()
+ throws HDF5LibraryException, NullPointerException {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5fid > 0) {
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ }
+ _deleteFile(H5_FILE);
+ System.out.println();
+ }
+
+ @Test//(expected = HDF5LibraryException.class)
+ public void testH5Gclose_invalid() throws Throwable {
+ long gid = H5.H5Gclose(-1);
+ assertTrue(gid == 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Gcreate_null() throws Throwable {
+ long gid = -1;
+
+ // it should fail because the group name is null
+ gid = H5.H5Gcreate(H5fid, null, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Gcreate_invalid() throws Throwable {
+ H5.H5Gcreate(-1, "Invalid ID", HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Gcreate() {
+ long gid = -1;
+ try {
+ gid = H5.H5Gcreate(H5fid, "/testH5Gcreate",
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Gcreate: " + err);
+ }
+ assertTrue(gid > 0);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ @Test
+ public void testH5Gclose() {
+ long gid = _createGroup(H5fid, "/testH5Gcreate");
+ assertTrue(gid > 0);
+
+ try {
+ H5.H5Gclose(gid);
+ }
+ catch (Throwable err) {
+ fail("H5Gclose: " + err);
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Gcreate_exists() throws Throwable {
+ long gid = _createGroup(H5fid, "/testH5Gcreate");
+ assertTrue(gid > 0);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+
+ // it should failed now because the group already exists in file
+ gid = H5.H5Gcreate(H5fid, "/testH5Gcreate",
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Gcreate_anon() {
+ long gid = -1;
+ try {
+ gid = H5.H5Gcreate_anon(H5fid, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Gcreate_anon: " + err);
+ }
+ assertTrue(gid > 0);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Gopen_null() throws Throwable {
+ long gid = -1;
+
+ gid = H5.H5Gopen(H5fid, null, HDF5Constants.H5P_DEFAULT);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Gopen_invalid() throws Throwable {
+ H5.H5Gopen(-1, "Invalid ID", HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Gopen_not_exists() throws Throwable {
+ long gid = -1;
+
+ gid = H5.H5Gopen(H5fid, "Never_created", HDF5Constants.H5P_DEFAULT);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ @Test
+ public void testH5Gopen() {
+ long gid = _createGroup(H5fid, "/testH5Gcreate");
+ assertTrue(gid > 0);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+
+ try {
+ gid = H5.H5Gopen(H5fid, "/testH5Gcreate",
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Gopen: " + err);
+ }
+ assertTrue(gid > 0);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Gget_create_plist_invalid() throws Throwable {
+ H5.H5Gget_create_plist(-1);
+ }
+
+ @Test
+ public void testH5Gget_create_plist() {
+ long pid = -1;
+ long gid = _createGroup(H5fid, "/testH5Gcreate");
+ assertTrue(gid > 0);
+
+ try {
+ pid = H5.H5Gget_create_plist(gid);
+ }
+ catch (Throwable err) {
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ err.printStackTrace();
+ fail("H5.H5Gget_create_plist: " + err);
+ }
+ assertTrue(pid > 0);
+
+ try {H5.H5Pclose(pid);} catch (Exception ex) {}
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Gget_info_invalid() throws Throwable {
+ H5.H5Gget_info(-1);
+ }
+
+ @Test
+ public void testH5Gget_info() {
+ H5G_info_t info = null;
+ long gid = _createGroup(H5fid, "/testH5Gcreate");
+ assertTrue(gid > 0);
+
+ try {
+ info = H5.H5Gget_info(gid);
+ }
+ catch (Throwable err) {
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ err.printStackTrace();
+ fail("H5.H5Gget_info: " + err);
+ }
+ assertNotNull(info);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Gget_info_by_name_null() throws Throwable {
+ H5.H5Gget_info_by_name(-1, null, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Gget_info_by_name_invalid() throws Throwable {
+ H5.H5Gget_info_by_name(-1, "/testH5Gcreate", HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Gget_info_by_name_not_exists() throws Throwable {
+ H5.H5Gget_info_by_name(H5fid, "/testH5Gcreate",
+ HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Gget_info_by_name() {
+ H5G_info_t info = null;
+ long gid = _createGroup(H5fid, "/testH5Gcreate");
+ assertTrue(gid > 0);
+
+ try {
+ info = H5.H5Gget_info_by_name(gid, "/testH5Gcreate",
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ err.printStackTrace();
+ fail("H5.H5Gget_info_by_name: " + err);
+ }
+ assertNotNull(info);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ @Test
+ public void testH5Gget_info_by_name_fileid() {
+ H5G_info_t info = null;
+ long gid = _createGroup(H5fid, "/testH5Gcreate");
+ assertTrue(gid > 0);
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+
+ try {
+ info = H5.H5Gget_info_by_name(H5fid, "/testH5Gcreate",
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ err.printStackTrace();
+ fail("H5.H5Gget_info_by_name: " + err);
+ }
+ assertNotNull(info);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Gget_info_by_idx_null() throws Throwable {
+ H5.H5Gget_info_by_idx(-1, null, HDF5Constants.H5_INDEX_NAME,
+ HDF5Constants.H5_ITER_INC, 1L, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Gget_info_by_idx_invalid() throws Throwable {
+ H5.H5Gget_info_by_idx(-1, "/testH5Gcreate", HDF5Constants.H5_INDEX_NAME,
+ HDF5Constants.H5_ITER_INC, 1L, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Gget_info_by_idx_not_exists() throws Throwable {
+ H5.H5Gget_info_by_idx(H5fid, "/testH5Gcreate",
+ HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 1L,
+ HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Gget_info_by_idx() {
+ H5G_info_t info = null;
+ long gid = _createGroup(H5fid, "/testH5Gcreate");
+ assertTrue(gid > 0);
+
+ try {
+ info = H5.H5Gget_info_by_idx(gid, "/", HDF5Constants.H5_INDEX_NAME,
+ HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Gget_info_by_idx: " + err);
+ }
+ assertNotNull(info);
+
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+ }
+
+ @Test
+ public void testH5Gget_info_by_idx_fileid() {
+ H5G_info_t info = null;
+ long gid = _createGroup(H5fid, "/testH5Gcreate");
+ assertTrue(gid > 0);
+ try {H5.H5Gclose(gid);} catch (Exception ex) {}
+
+ try {
+ info = H5.H5Gget_info_by_idx(H5fid, "/",
+ HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Gget_info_by_idx: " + err);
+ }
+ assertNotNull(info);
+ }
+
+}
diff --git a/java/test/TestH5Giterate.java b/java/test/TestH5Giterate.java
new file mode 100644
index 0000000..17f594e
--- /dev/null
+++ b/java/test/TestH5Giterate.java
@@ -0,0 +1,136 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertNotNull;
+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 hdf.hdf5lib.structs.H5G_info_t;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5Giterate {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "h5ex_g_iterate.hdf";
+ long H5fid = -1;
+
+ private final long _openGroup(long fid, String name) {
+ long gid = -1;
+ try {
+ gid = H5.H5Gopen(fid, name, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ gid = -1;
+ err.printStackTrace();
+ fail("H5.H5Gcreate: " + err);
+ }
+
+ return gid;
+ }
+
+ @Before
+ public void openH5file()
+ throws HDF5LibraryException, NullPointerException {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ try {
+ H5fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDONLY,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Fopen: openH5file: " + err);
+ }
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5fid > 0) {
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ }
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Gget_obj_info_all() {
+ H5G_info_t info = null;
+
+ long gid = _openGroup(H5fid, "/");
+
+ try {
+ info = H5.H5Gget_info(gid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Gget_info: " + err);
+ }
+ try {
+ H5.H5Gclose(gid);
+ }
+ catch (Exception ex) {
+ }
+ assertNotNull(info);
+ assertTrue("number of links is empty", info.nlinks > 0);
+ String objNames[] = new String[(int) info.nlinks];
+ int objTypes[] = new int[(int) info.nlinks];
+ int lnkTypes[] = new int[(int) info.nlinks];
+ long objRefs[] = new long[(int) info.nlinks];
+
+ int names_found = 0;
+ try {
+ names_found = H5.H5Gget_obj_info_all(H5fid, "/", objNames,
+ objTypes, lnkTypes, objRefs, HDF5Constants.H5_INDEX_NAME);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Gget_obj_info_all: " + err);
+ }
+
+ assertTrue("number found[" + names_found + "] different than expected["
+ + objNames.length + "]", names_found == objNames.length);
+ for (int i = 0; i < objNames.length; i++) {
+ assertNotNull("name #" + i + " does not exist", objNames[i]);
+ assertTrue(objNames[i].length() > 0);
+ if (objTypes[i]==HDF5Constants.H5O_TYPE_GROUP) {
+ assertTrue("Group is index: "+i + " ",i==2);
+ assertTrue("Group is : "+objNames[i] + " ",objNames[i].compareToIgnoreCase("G1")==0);
+ }
+ else if (objTypes[i]==HDF5Constants.H5O_TYPE_DATASET) {
+ assertTrue("Dataset is index: "+i + " ",(i==0)||(i==3));
+ if(i==0)
+ assertTrue("Dataset is : "+objNames[i] + " ",objNames[i].compareToIgnoreCase("DS1")==0);
+ else
+ assertTrue("Dataset is : "+objNames[i] + " ",objNames[i].compareToIgnoreCase("L1")==0);
+ }
+ else if (objTypes[i]==HDF5Constants.H5O_TYPE_NAMED_DATATYPE) {
+ assertTrue("Datatype is index: "+i + " ",i==1);
+ assertTrue("Datatype is : "+objNames[i] + " ",objNames[i].compareToIgnoreCase("DT1")==0);
+ }
+ else {
+ fail(" Unknown at index: " + i + " " + objNames[i]);
+ }
+ }
+ }
+
+}
diff --git a/java/test/TestH5Lbasic.java b/java/test/TestH5Lbasic.java
new file mode 100644
index 0000000..c35519e
--- /dev/null
+++ b/java/test/TestH5Lbasic.java
@@ -0,0 +1,371 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.callbacks.H5L_iterate_cb;
+import hdf.hdf5lib.callbacks.H5L_iterate_t;
+import hdf.hdf5lib.exceptions.HDF5LibraryException;
+import hdf.hdf5lib.structs.H5L_info_t;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5Lbasic {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "h5ex_g_iterate.hdf";
+ long H5fid = -1;
+
+ @Before
+ public void openH5file()
+ throws HDF5LibraryException, NullPointerException {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ try {
+ H5fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDONLY,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Fopen: openH5file: " + err);
+ }
+ }
+
+ @After
+ public void closeH5file() throws HDF5LibraryException {
+ if (H5fid > 0) {
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ }
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Lexists() {
+ boolean link_exists = false;
+ try {
+ link_exists = H5.H5Lexists(H5fid, "None", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lexists: " + err);
+ }
+ assertFalse("H5Lexists ",link_exists);
+ try {
+ link_exists = H5.H5Lexists(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lexists: " + err);
+ }
+ assertTrue("H5Lexists ",link_exists);
+ try {
+ link_exists = H5.H5Lexists(H5fid, "G1/DS2", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lexists: " + err);
+ }
+ assertTrue("H5Lexists ",link_exists);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_info_not_exist() throws Throwable {
+ H5.H5Lget_info(H5fid, "None", HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Lget_info_dataset() {
+ H5L_info_t link_info = null;
+ try {
+ link_info = H5.H5Lget_info(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info: " + err);
+ }
+ assertFalse("H5Lget_info ",link_info==null);
+ assertTrue("H5Lget_info link type",link_info.type==HDF5Constants.H5L_TYPE_HARD);
+ }
+
+ @Test
+ public void testH5Lget_info_hardlink() {
+ H5L_info_t link_info = null;
+ try {
+ link_info = H5.H5Lget_info(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info: " + err);
+ }
+ assertFalse("H5Lget_info ",link_info==null);
+ assertTrue("H5Lget_info link type",link_info.type==HDF5Constants.H5L_TYPE_HARD);
+ assertTrue("Link Address ",link_info.address_val_size>0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_info_by_idx_name_not_exist_name() throws Throwable {
+ H5.H5Lget_info_by_idx(H5fid, "None", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_info_by_idx_name_not_exist_create() throws Throwable {
+ H5.H5Lget_info_by_idx(H5fid, "None", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_info_by_idx_not_exist_name() throws Throwable {
+ H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 5, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_info_by_idx_not_exist_create() throws Throwable {
+ H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 5, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Lget_info_by_idx_n0() {
+ H5L_info_t link_info = null;
+ H5L_info_t link_info2 = null;
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx: " + err);
+ }
+ assertFalse("H5Lget_info_by_idx ",link_info==null);
+ assertTrue("H5Lget_info_by_idx link type",link_info.type==HDF5Constants.H5L_TYPE_HARD);
+ try {
+ link_info2 = H5.H5Lget_info(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info: " + err);
+ }
+ assertTrue("Link Address ",link_info.address_val_size==link_info2.address_val_size);
+ }
+
+ @Test
+ public void testH5Lget_info_by_idx_n3() {
+ H5L_info_t link_info = null;
+ H5L_info_t link_info2 = null;
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 3, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx: " + err);
+ }
+ assertFalse("H5Lget_info_by_idx ",link_info==null);
+ assertTrue("H5Lget_info_by_idx link type",link_info.type==HDF5Constants.H5L_TYPE_HARD);
+ try {
+ link_info2 = H5.H5Lget_info(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info: " + err);
+ }
+ assertTrue("Link Address ",link_info.address_val_size==link_info2.address_val_size);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_name_by_idx_not_exist() throws Throwable {
+ H5.H5Lget_name_by_idx(H5fid, "None", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Lget_name_by_idx_n0() {
+ String link_name = null;
+ try {
+ link_name = H5.H5Lget_name_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_name_by_idx: " + err);
+ }
+ assertFalse("H5Lget_name_by_idx ",link_name==null);
+ assertTrue("Link Name ",link_name.compareTo("DS1")==0);
+ }
+
+ @Test
+ public void testH5Lget_name_by_idx_n3() {
+ String link_name = null;
+ try {
+ link_name = H5.H5Lget_name_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 3, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_name_by_idx: " + err);
+ }
+ assertFalse("H5Lget_name_by_idx ",link_name==null);
+ assertTrue("Link Name ",link_name.compareTo("L1")==0);
+ }
+
+ @Test
+ public void testH5Lvisit() {
+ class idata {
+ public String link_name = null;
+ public int link_type = -1;
+ idata(String name, int type) {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+ class H5L_iter_data implements H5L_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+ H5L_iterate_t iter_data = new H5L_iter_data();
+ class H5L_iter_callback implements H5L_iterate_cb {
+ public int callback(long group, String name, H5L_info_t info, H5L_iterate_t op_data) {
+ idata id = new idata(name, info.type);
+ ((H5L_iter_data)op_data).iterdata.add(id);
+ return 0;
+ }
+ }
+ H5L_iterate_cb iter_cb = new H5L_iter_callback();
+ try {
+ H5.H5Lvisit(H5fid, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, iter_cb, iter_data);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lvisit: " + err);
+ }
+ assertFalse("H5Lvisit ",((H5L_iter_data)iter_data).iterdata.isEmpty());
+ assertTrue("H5Lvisit "+((H5L_iter_data)iter_data).iterdata.size(),((H5L_iter_data)iter_data).iterdata.size()==5);
+ assertTrue("H5Lvisit "+(((H5L_iter_data)iter_data).iterdata.get(0)).link_name,(((H5L_iter_data)iter_data).iterdata.get(0)).link_name.compareToIgnoreCase("DS1")==0);
+ assertTrue("H5Lvisit "+(((H5L_iter_data)iter_data).iterdata.get(1)).link_name,(((H5L_iter_data)iter_data).iterdata.get(1)).link_name.compareToIgnoreCase("DT1")==0);
+ assertTrue("H5Lvisit "+(((H5L_iter_data)iter_data).iterdata.get(2)).link_name,(((H5L_iter_data)iter_data).iterdata.get(2)).link_name.compareToIgnoreCase("G1")==0);
+ assertTrue("H5Lvisit "+(((H5L_iter_data)iter_data).iterdata.get(3)).link_name,(((H5L_iter_data)iter_data).iterdata.get(3)).link_name.compareToIgnoreCase("G1/DS2")==0);
+ assertTrue("H5Lvisit "+(((H5L_iter_data)iter_data).iterdata.get(4)).link_name,(((H5L_iter_data)iter_data).iterdata.get(4)).link_name.compareToIgnoreCase("L1")==0);
+ }
+
+ @Test
+ public void testH5Lvisit_by_name() {
+ class idata {
+ public String link_name = null;
+ public int link_type = -1;
+ idata(String name, int type) {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+ class H5L_iter_data implements H5L_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+ H5L_iterate_t iter_data = new H5L_iter_data();
+ class H5L_iter_callback implements H5L_iterate_cb {
+ public int callback(long group, String name, H5L_info_t info, H5L_iterate_t op_data) {
+ idata id = new idata(name, info.type);
+ ((H5L_iter_data)op_data).iterdata.add(id);
+ return 0;
+ }
+ }
+ H5L_iterate_cb iter_cb = new H5L_iter_callback();
+ try {
+ H5.H5Lvisit_by_name(H5fid, "G1", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, iter_cb, iter_data, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lvisit_by_name: " + err);
+ }
+ assertFalse("H5Lvisit_by_name ",((H5L_iter_data)iter_data).iterdata.isEmpty());
+ assertTrue("H5Lvisit_by_name "+((H5L_iter_data)iter_data).iterdata.size(),((H5L_iter_data)iter_data).iterdata.size()==1);
+ assertTrue("H5Lvisit_by_name "+(((H5L_iter_data)iter_data).iterdata.get(0)).link_name,(((H5L_iter_data)iter_data).iterdata.get(0)).link_name.compareToIgnoreCase("DS2")==0);
+ }
+
+ @Test
+ public void testH5Literate() {
+ class idata {
+ public String link_name = null;
+ public int link_type = -1;
+ idata(String name, int type) {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+ class H5L_iter_data implements H5L_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+ H5L_iterate_t iter_data = new H5L_iter_data();
+ class H5L_iter_callback implements H5L_iterate_cb {
+ public int callback(long group, String name, H5L_info_t info, H5L_iterate_t op_data) {
+ idata id = new idata(name, info.type);
+ ((H5L_iter_data)op_data).iterdata.add(id);
+ return 0;
+ }
+ }
+ H5L_iterate_cb iter_cb = new H5L_iter_callback();
+ try {
+ H5.H5Literate(H5fid, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0L, iter_cb, iter_data);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Literate: " + err);
+ }
+ assertFalse("H5Literate ",((H5L_iter_data)iter_data).iterdata.isEmpty());
+ assertTrue("H5Literate "+((H5L_iter_data)iter_data).iterdata.size(),((H5L_iter_data)iter_data).iterdata.size()==4);
+ assertTrue("H5Literate "+(((H5L_iter_data)iter_data).iterdata.get(0)).link_name,(((H5L_iter_data)iter_data).iterdata.get(0)).link_name.compareToIgnoreCase("DS1")==0);
+ assertTrue("H5Literate "+(((H5L_iter_data)iter_data).iterdata.get(1)).link_name,(((H5L_iter_data)iter_data).iterdata.get(1)).link_name.compareToIgnoreCase("DT1")==0);
+ assertTrue("H5Literate "+((idata)((H5L_iter_data)iter_data).iterdata.get(2)).link_name,(((H5L_iter_data)iter_data).iterdata.get(2)).link_name.compareToIgnoreCase("G1")==0);
+ assertTrue("H5Literate "+((idata)((H5L_iter_data)iter_data).iterdata.get(3)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(3)).link_name.compareToIgnoreCase("L1")==0);
+ }
+
+ @Test
+ public void testH5Literate_by_name() {
+ class idata {
+ public String link_name = null;
+ public int link_type = -1;
+ idata(String name, int type) {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+ class H5L_iter_data implements H5L_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+ H5L_iterate_t iter_data = new H5L_iter_data();
+ class H5L_iter_callback implements H5L_iterate_cb {
+ public int callback(long group, String name, H5L_info_t info, H5L_iterate_t op_data) {
+ idata id = new idata(name, info.type);
+ ((H5L_iter_data)op_data).iterdata.add(id);
+ return 0;
+ }
+ }
+ H5L_iterate_cb iter_cb = new H5L_iter_callback();
+ try {
+ H5.H5Literate_by_name(H5fid, "G1", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0L, iter_cb, iter_data, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Literate_by_name: " + err);
+ }
+ assertFalse("H5Literate_by_name ",((H5L_iter_data)iter_data).iterdata.isEmpty());
+ assertTrue("H5Literate_by_name "+((H5L_iter_data)iter_data).iterdata.size(),((H5L_iter_data)iter_data).iterdata.size()==1);
+ assertTrue("H5Literate_by_name "+((idata)((H5L_iter_data)iter_data).iterdata.get(0)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(0)).link_name.compareToIgnoreCase("DS2")==0);
+ }
+
+}
diff --git a/java/test/TestH5Lcreate.java b/java/test/TestH5Lcreate.java
new file mode 100644
index 0000000..2fbd9e3
--- /dev/null
+++ b/java/test/TestH5Lcreate.java
@@ -0,0 +1,819 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.callbacks.H5L_iterate_cb;
+import hdf.hdf5lib.callbacks.H5L_iterate_t;
+import hdf.hdf5lib.exceptions.HDF5Exception;
+import hdf.hdf5lib.exceptions.HDF5LibraryException;
+import hdf.hdf5lib.structs.H5L_info_t;
+
+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 TestH5Lcreate {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_EXTFILE = "h5ex_g_iterate.hdf";
+ private static final String H5_FILE = "test.h5";
+ private static final int DIM_X = 4;
+ private static final int DIM_Y = 6;
+ long H5fcpl = -1;
+ long H5fid = -1;
+ long H5dsid = -1;
+ long H5did1 = -1;
+ long H5did2 = -1;
+ long H5gcpl = -1;
+ long H5gid = -1;
+ long[] H5dims = { DIM_X, DIM_Y };
+
+ 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 = -1;
+ 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("TestH5L._createDataset: ",did > 0);
+
+ return did;
+ }
+
+ private final long _createGroup(long fid, String name) {
+ long gid = -1;
+ 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("TestH5L._createGroup: ",gid > 0);
+
+ return gid;
+ }
+
+ private final void _createHardLink(long fid, long cid, String curname, long did, String dstname, long lcpl, long lapl) {
+ boolean link_exists = false;
+ try {
+ H5.H5Lcreate_hard(cid, curname, did, dstname, lcpl, lapl);
+ H5.H5Fflush(fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ link_exists = H5.H5Lexists(did, dstname, lapl);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lcreate_hard: " + err);
+ }
+ assertTrue("TestH5L._createHardLink ", link_exists);
+ }
+
+ private final void _createSoftLink(long fid, String curname, long did, String dstname, long lcpl, long lapl) {
+ boolean link_exists = false;
+ try {
+ H5.H5Lcreate_soft(curname, did, dstname, lcpl, lapl);
+ H5.H5Fflush(fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ link_exists = H5.H5Lexists(did, dstname, lapl);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lcreate_soft: " + err);
+ }
+ assertTrue("TestH5L._createSoftLink ", link_exists);
+ }
+
+ private final void _createExternalLink(long fid, String ext_filename, String curname, long did, String dstname, long lcpl, long lapl) {
+ boolean link_exists = false;
+ try {
+ H5.H5Lcreate_external(ext_filename, curname, did, dstname, lcpl, lapl);
+ H5.H5Fflush(fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ link_exists = H5.H5Lexists(did, dstname, lapl);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lcreate_external: " + err);
+ }
+ assertTrue("TestH5L._createExternalLink ", link_exists);
+ }
+
+ @Before
+ public void createH5file()
+ throws NullPointerException, HDF5Exception {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+ try {
+ H5fcpl = H5.H5Pcreate(HDF5Constants.H5P_FILE_CREATE);
+ H5.H5Pset_link_creation_order(H5fcpl, HDF5Constants.H5P_CRT_ORDER_TRACKED+HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ H5fcpl, HDF5Constants.H5P_DEFAULT);
+ H5dsid = H5.H5Screate_simple(2, H5dims, null);
+ H5did1 = _createDataset(H5fid, H5dsid, "DS1", HDF5Constants.H5P_DEFAULT);
+ H5gid = _createGroup(H5fid, "/G1");
+ H5did2 = _createDataset(H5gid, H5dsid, "DS2", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5L.createH5file: " + err);
+ }
+ assertTrue("TestH5L.createH5file: H5.H5Fcreate: ",H5fid > 0);
+ assertTrue("TestH5L.createH5file: H5.H5Screate_simple: ",H5dsid > 0);
+ assertTrue("TestH5L.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 (H5gcpl > 0)
+ try {H5.H5Pclose(H5gcpl);} catch (Exception ex) {}
+ if (H5did2 > 0)
+ try {H5.H5Dclose(H5did2);} catch (Exception ex) {}
+ if (H5dsid > 0)
+ try {H5.H5Sclose(H5dsid);} catch (Exception ex) {}
+ if (H5did1 > 0)
+ try {H5.H5Dclose(H5did1);} catch (Exception ex) {}
+ if (H5fid > 0)
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ if (H5fcpl > 0)
+ try {H5.H5Pclose(H5fcpl);} catch (Exception ex) {}
+
+ _deleteFile(H5_FILE);
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Lget_info_by_idx_n0_create() {
+ H5L_info_t link_info = null;
+ try {
+ int order = H5.H5Pget_link_creation_order(H5fcpl);
+ assertTrue("creation order :"+order, order == HDF5Constants.H5P_CRT_ORDER_TRACKED+HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx_n0_create:H5Pget_link_creation_order " + err);
+ }
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx: " + err);
+ }
+ assertFalse("H5Lget_info_by_idx ", link_info==null);
+ assertTrue("H5Lget_info_by_idx link type", link_info.type==HDF5Constants.H5L_TYPE_HARD);
+ }
+
+ @Test
+ public void testH5Lget_info_by_idx_n1_create() {
+ H5L_info_t link_info = null;
+ try {
+ int order = H5.H5Pget_link_creation_order(H5fcpl);
+ assertTrue("creation order :"+order, order == HDF5Constants.H5P_CRT_ORDER_TRACKED+HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx_n1_create:H5Pget_link_creation_order " + err);
+ }
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 1, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx: " + err);
+ }
+ assertFalse("H5Lget_info_by_idx ", link_info==null);
+ assertTrue("H5Lget_info_by_idx link type", link_info.type==HDF5Constants.H5L_TYPE_HARD);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lcreate_hard_cur_not_exists() throws Throwable {
+ H5.H5Lcreate_hard(H5fid, "None", H5fid, "DS1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Lcreate_hard() {
+ try {
+ H5.H5Lcreate_hard(H5fid, "DS1", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ boolean link_exists = H5.H5Lexists(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Lcreate_hard:H5Lexists ", link_exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lexists: " + err);
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lcreate_hard_dst_link_exists() throws Throwable {
+ _createHardLink(H5fid, H5fid, "/G1/DS2", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Lcreate_hard(H5fid, "L1", H5fid, "/G1/DS2", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Ldelete_hard_link() {
+ _createHardLink(H5fid, H5fid, "/G1/DS2", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ H5.H5Ldelete(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ boolean link_exists = H5.H5Lexists(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ assertFalse("testH5Lcreate_hard:H5Lexists ", link_exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lexists: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Lcreate_soft() {
+ try {
+ H5.H5Lcreate_soft("DS1", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ boolean link_exists = H5.H5Lexists(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Lcreate_soft:H5Lexists ", link_exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lexists: " + err);
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lcreate_soft_dst_link_exists() throws Throwable {
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Lcreate_soft("L1", H5fid, "/G1/DS2", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Ldelete_soft_link() {
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ H5.H5Ldelete(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ boolean link_exists = H5.H5Lexists(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ assertFalse("testH5Lcreate_soft:H5Lexists ", link_exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lexists: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Lget_info_softlink() {
+ H5L_info_t link_info = null;
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_info = H5.H5Lget_info(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info: " + err);
+ }
+ assertFalse("H5Lget_info ", link_info==null);
+ assertTrue("H5Lget_info link type", link_info.type==HDF5Constants.H5L_TYPE_SOFT);
+ assertTrue("Link Address ", link_info.address_val_size>0);
+ }
+
+ @Test
+ public void testH5Lget_value_soft() {
+ String[] link_value = {null, null};
+ int link_type = -1;
+
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_type = H5.H5Lget_value(H5fid, "L1", link_value, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_value: " + err);
+ }
+ assertTrue("Link Type", link_type == HDF5Constants.H5L_TYPE_SOFT);
+ assertFalse("H5Lget_value ", link_value[0]==null);
+ assertTrue("Link Value ", link_value[0].compareTo("/G1/DS2")==0);
+ }
+
+ @Test
+ public void testH5Lcreate_soft_dangle() {
+ try {
+ H5.H5Lcreate_soft("DS3", H5fid, "L2", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ boolean link_exists = H5.H5Lexists(H5fid, "L2", HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Lcreate_soft:H5Lexists ", link_exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lexists: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Ldelete_soft_link_dangle() {
+ _createSoftLink(H5fid, "DS3", H5fid, "L2", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ H5.H5Ldelete(H5fid, "L2", HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ boolean link_exists = H5.H5Lexists(H5fid, "L2", HDF5Constants.H5P_DEFAULT);
+ assertFalse("testH5Lcreate_soft:H5Lexists ", link_exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lexists: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Lget_info_softlink_dangle() {
+ H5L_info_t link_info = null;
+ _createSoftLink(H5fid, "DS3", H5fid, "L2", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_info = H5.H5Lget_info(H5fid, "L2", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info: " + err);
+ }
+ assertFalse("H5Lget_info ", link_info==null);
+ assertTrue("H5Lget_info link type", link_info.type==HDF5Constants.H5L_TYPE_SOFT);
+ assertTrue("Link Address ", link_info.address_val_size>0);
+ }
+
+ @Test
+ public void testH5Lget_value_dangle() {
+ String[] link_value = {null,null};
+ int link_type = -1;
+
+ _createSoftLink(H5fid, "DS3", H5fid, "L2", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_type = H5.H5Lget_value(H5fid, "L2", link_value, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_value: " + err);
+ }
+ assertTrue("Link Type", link_type == HDF5Constants.H5L_TYPE_SOFT);
+ assertFalse("H5Lget_value ", link_value[0]==null);
+ assertTrue("Link Value ", link_value[0].compareTo("DS3")==0);
+ }
+
+ @Test
+ public void testH5Lcreate_external() {
+ try {
+ H5.H5Lcreate_external(H5_EXTFILE, "DT1", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ boolean link_exists = H5.H5Lexists(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Lcreate_external:H5Lexists ", link_exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lexists: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Lget_info_externallink() {
+ H5L_info_t link_info = null;
+ _createExternalLink(H5fid, H5_EXTFILE, "DT1", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_info = H5.H5Lget_info(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info: " + err);
+ }
+ assertFalse("H5Lget_info ", link_info==null);
+ assertTrue("H5Lget_info link type", link_info.type==HDF5Constants.H5L_TYPE_EXTERNAL);
+ assertTrue("Link Address ", link_info.address_val_size>0);
+ }
+
+ @Test
+ public void testH5Lget_value_external(){
+ String[] link_value = {null,null};
+ int link_type = -1;
+
+ _createExternalLink(H5fid, H5_EXTFILE, "DT1", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_type = H5.H5Lget_value(H5fid, "L1", link_value, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_value: " + err);
+ }
+ assertTrue("Link Type", link_type == HDF5Constants.H5L_TYPE_EXTERNAL);
+ assertFalse("H5Lget_value ", link_value[0]==null);
+ assertFalse("H5Lget_value ", link_value[1]==null);
+ assertTrue("Link Value ", link_value[0].compareTo("DT1")==0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lcopy_cur_not_exists() throws Throwable {
+ H5.H5Lcopy(H5fid, "None", H5fid, "DS1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Lcopy() {
+ try {
+ H5.H5Lcopy(H5fid, "DS1", H5fid, "CPY1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ boolean link_exists = H5.H5Lexists(H5fid, "CPY1", HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Lcopy:H5Lexists ", link_exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Lcopy:H5Lexists: " + err);
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lcopy_dst_link_exists() throws Throwable {
+ _createHardLink(H5fid, H5fid, "/G1/DS2", H5fid, "CPY1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Lcopy(H5fid, "CPY1", H5fid, "/G1/DS2", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lmove_cur_not_exists() throws Throwable {
+ H5.H5Lmove(H5fid, "None", H5fid, "DS1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Lmove() {
+ try {
+ H5.H5Lmove(H5fid, "DS1", H5fid, "CPY1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ boolean link_exists = H5.H5Lexists(H5fid, "CPY1", HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Lmove:H5Lexists ", link_exists);
+ link_exists = H5.H5Lexists(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ assertFalse("testH5Lmove:H5Lexists ", link_exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Lmove:H5Lexists: " + err);
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lmove_dst_link_exists() throws Throwable {
+ _createHardLink(H5fid, H5fid, "/G1/DS2", H5fid, "CPY1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Lmove(H5fid, "CPY1", H5fid, "/G1/DS2", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_value_by_idx_not_exist_name() throws Throwable {
+ String[] link_value = {null,null};
+ H5.H5Lget_value_by_idx(H5fid, "None", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0, link_value, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_value_by_idx_not_exist_create() throws Throwable {
+ String[] link_value = {null,null};
+ H5.H5Lget_value_by_idx(H5fid, "None", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0, link_value, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Lget_value_by_idx_n2_name() {
+ H5L_info_t link_info = null;
+ String[] link_value = {null,null};
+ int link_type = -1;
+
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "LS", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 2, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx: " + err);
+ }
+ assertFalse("testH5Lget_value_by_idx_n2 ",link_info==null);
+ assertTrue("testH5Lget_value_by_idx_n2 link type", link_info.type==HDF5Constants.H5L_TYPE_SOFT);
+ try {
+ link_type = H5.H5Lget_value_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 2, link_value, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_value_by_idx: " + err);
+ }
+ assertTrue("Link Type", link_type == HDF5Constants.H5L_TYPE_SOFT);
+ assertFalse("testH5Lget_value_by_idx_n2 ", link_value[0]==null);
+ assertTrue("testH5Lget_value_by_idx_n2 Link Value ", link_value[0].compareTo("/G1/DS2")==0);
+ }
+
+ @Test
+ public void testH5Lget_value_by_idx_n2_create() {
+ H5L_info_t link_info = null;
+ String[] link_value = {null,null};
+ int link_type = -1;
+
+ try {
+ int order = H5.H5Pget_link_creation_order(H5fcpl);
+ assertTrue("creation order :"+order, order == HDF5Constants.H5P_CRT_ORDER_TRACKED+HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_value_by_idx_n2_create: H5Pget_link_creation_order " + err);
+ }
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "LS", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 2, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx: " + err);
+ }
+ assertFalse("testH5Lget_value_by_idx_n2 ", link_info==null);
+ assertTrue("testH5Lget_value_by_idx_n2 link type", link_info.type==HDF5Constants.H5L_TYPE_SOFT);
+ try {
+ link_type = H5.H5Lget_value_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 2, link_value, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_value_by_idx: " + err);
+ }
+ assertTrue("Link Type", link_type == HDF5Constants.H5L_TYPE_SOFT);
+ assertFalse("testH5Lget_value_by_idx_n2 ", link_value[0]==null);
+ assertTrue("testH5Lget_value_by_idx_n2 Link Value ", link_value[0].compareTo("/G1/DS2")==0);
+ }
+
+ @Test
+ public void testH5Lget_value_by_idx_external_name() {
+ H5L_info_t link_info = null;
+ String[] link_value = {null,null};
+ int link_type = -1;
+
+ _createExternalLink(H5fid, H5_EXTFILE, "DT1", H5fid, "LE", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 2, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx: " + err);
+ }
+ assertFalse("testH5Lget_value_by_idx_ext ", link_info==null);
+ assertTrue("testH5Lget_value_by_idx_ext link type "+link_info.type, link_info.type==HDF5Constants.H5L_TYPE_EXTERNAL);
+ try {
+ link_type = H5.H5Lget_value_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 2, link_value, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_value_by_idx: " + err);
+ }
+ assertTrue("Link Type", link_type == HDF5Constants.H5L_TYPE_EXTERNAL);
+ assertFalse("testH5Lget_value_by_idx_ext ", link_value[0]==null);
+ assertFalse("testH5Lget_value_by_idx_ext ", link_value[1]==null);
+ assertTrue("testH5Lget_value_by_idx_ext Link Value ", link_value[0].compareTo("DT1")==0);
+ }
+
+ @Test
+ public void testH5Lget_value_by_idx_external_create() {
+ H5L_info_t link_info = null;
+ String[] link_value = {null,null};
+ int link_type = -1;
+
+ _createExternalLink(H5fid, H5_EXTFILE, "DT1", H5fid, "LE", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 2, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx: " + err);
+ }
+ assertFalse("testH5Lget_value_by_idx_ext ", link_info==null);
+ assertTrue("testH5Lget_value_by_idx_ext link type "+link_info.type, link_info.type==HDF5Constants.H5L_TYPE_EXTERNAL);
+ try {
+ link_type = H5.H5Lget_value_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 2, link_value, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_value_by_idx: " + err);
+ }
+ assertTrue("Link Type", link_type == HDF5Constants.H5L_TYPE_EXTERNAL);
+ assertFalse("testH5Lget_value_by_idx_ext ", link_value[0]==null);
+ assertFalse("testH5Lget_value_by_idx_ext ", link_value[1]==null);
+ assertTrue("testH5Lget_value_by_idx_ext Link Value ", link_value[0].compareTo("DT1")==0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Ldelete_by_idx_not_exist_name() throws Throwable {
+ H5.H5Ldelete_by_idx(H5fid, "None", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Ldelete_by_idx_not_exist_create() throws Throwable {
+ H5.H5Ldelete_by_idx(H5fid, "None", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Ldelete_by_idx_n2_name() {
+ H5L_info_t link_info = null;
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "LS", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 2, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx: " + err);
+ }
+ assertFalse("testH5Ldelete_by_idx_n2 ", link_info==null);
+ assertTrue("testH5Ldelete_by_idx_n2 link type", link_info.type==HDF5Constants.H5L_TYPE_SOFT);
+ try {
+ H5.H5Ldelete_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 2, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ldelete_by_idx: " + err);
+ }
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 2, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (HDF5LibraryException err) {
+ link_info = null;
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ldelete_by_idx: " + err);
+ }
+ assertTrue("testH5Ldelete_by_idx_n2 ",link_info==null);
+ }
+
+ @Test
+ public void testH5Ldelete_by_idx_n2_create() {
+ H5L_info_t link_info = null;
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "LS", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 2, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lget_info_by_idx: " + err);
+ }
+ assertFalse("testH5Ldelete_by_idx_n2 ", link_info==null);
+ assertTrue("testH5Ldelete_by_idx_n2 link type", link_info.type==HDF5Constants.H5L_TYPE_SOFT);
+ try {
+ H5.H5Ldelete_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 2, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ldelete_by_idx: " + err);
+ }
+ try {
+ link_info = H5.H5Lget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 2, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (HDF5LibraryException err) {
+ link_info = null;
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ldelete_by_idx: " + err);
+ }
+ assertTrue("testH5Ldelete_by_idx_n2 ",link_info==null);
+ }
+
+ @Test
+ public void testH5Lvisit_create() {
+ try {
+ int order = H5.H5Pget_link_creation_order(H5fcpl);
+ assertTrue("creation order :"+order, order == HDF5Constants.H5P_CRT_ORDER_TRACKED+HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lvisit_create: H5Pget_link_creation_order " + err);
+ }
+
+ _createHardLink(H5fid, H5fid, "/G1/DS2", H5fid, "CPY1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ _createExternalLink(H5fid, H5_EXTFILE, "DT1", H5fid, "LE", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "LS", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+
+ class idata {
+ public String link_name = null;
+ public int link_type = -1;
+ idata(String name, int type) {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+ class H5L_iter_data implements H5L_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+ H5L_iterate_t iter_data = new H5L_iter_data();
+ class H5L_iter_callback implements H5L_iterate_cb {
+ public int callback(long group, String name, H5L_info_t info, H5L_iterate_t op_data) {
+ idata id = new idata(name, info.type);
+ ((H5L_iter_data)op_data).iterdata.add(id);
+ return 0;
+ }
+ }
+ H5L_iterate_cb iter_cb = new H5L_iter_callback();
+ try {
+ H5.H5Lvisit(H5fid, HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, iter_cb, iter_data);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lvisit: " + err);
+ }
+ assertFalse("H5Lvisit ",((H5L_iter_data)iter_data).iterdata.isEmpty());
+ assertTrue("H5Lvisit "+((H5L_iter_data)iter_data).iterdata.size(),((H5L_iter_data)iter_data).iterdata.size()==6);
+ assertTrue("H5Lvisit "+((idata)((H5L_iter_data)iter_data).iterdata.get(0)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(0)).link_name.compareToIgnoreCase("DS1")==0);
+ assertTrue("H5Lvisit "+((idata)((H5L_iter_data)iter_data).iterdata.get(1)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(1)).link_name.compareToIgnoreCase("G1")==0);
+ assertTrue("H5Lvisit "+((idata)((H5L_iter_data)iter_data).iterdata.get(2)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(2)).link_name.compareToIgnoreCase("G1/DS2")==0);
+ assertTrue("H5Lvisit "+((idata)((H5L_iter_data)iter_data).iterdata.get(3)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(3)).link_name.compareToIgnoreCase("CPY1")==0);
+ assertTrue("H5Lvisit "+((idata)((H5L_iter_data)iter_data).iterdata.get(4)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(4)).link_name.compareToIgnoreCase("LE")==0);
+ assertTrue("H5Lvisit "+((idata)((H5L_iter_data)iter_data).iterdata.get(5)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(5)).link_name.compareToIgnoreCase("LS")==0);
+ }
+
+ @Test
+ public void testH5Literate_create() {
+ try {
+ int order = H5.H5Pget_link_creation_order(H5fcpl);
+ assertTrue("creation order :"+order, order == HDF5Constants.H5P_CRT_ORDER_TRACKED+HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Literate_create: H5Pget_link_creation_order " + err);
+ }
+
+ _createHardLink(H5fid, H5fid, "/G1/DS2", H5fid, "CPY1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ _createExternalLink(H5fid, H5_EXTFILE, "DT1", H5fid, "LE", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "LS", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+
+ class idata {
+ public String link_name = null;
+ public int link_type = -1;
+ idata(String name, int type) {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+ class H5L_iter_data implements H5L_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+ H5L_iterate_t iter_data = new H5L_iter_data();
+ class H5L_iter_callback implements H5L_iterate_cb {
+ public int callback(long group, String name, H5L_info_t info, H5L_iterate_t op_data) {
+ idata id = new idata(name, info.type);
+ ((H5L_iter_data)op_data).iterdata.add(id);
+ return 0;
+ }
+ }
+ H5L_iterate_cb iter_cb = new H5L_iter_callback();
+ try {
+ H5.H5Literate(H5fid, HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0, iter_cb, iter_data);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Literate: " + err);
+ }
+ assertFalse("H5Literate ",((H5L_iter_data)iter_data).iterdata.isEmpty());
+ assertTrue("H5Literate "+((H5L_iter_data)iter_data).iterdata.size(),((H5L_iter_data)iter_data).iterdata.size()==5);
+ assertTrue("H5Literate "+((idata)((H5L_iter_data)iter_data).iterdata.get(0)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(0)).link_name.compareToIgnoreCase("DS1")==0);
+ assertTrue("H5Literate "+((idata)((H5L_iter_data)iter_data).iterdata.get(1)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(1)).link_name.compareToIgnoreCase("G1")==0);
+ assertTrue("H5Literate "+((idata)((H5L_iter_data)iter_data).iterdata.get(2)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(2)).link_name.compareToIgnoreCase("CPY1")==0);
+ assertTrue("H5Literate "+((idata)((H5L_iter_data)iter_data).iterdata.get(3)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(3)).link_name.compareToIgnoreCase("LE")==0);
+ assertTrue("H5Literate "+((idata)((H5L_iter_data)iter_data).iterdata.get(4)).link_name,((idata)((H5L_iter_data)iter_data).iterdata.get(4)).link_name.compareToIgnoreCase("LS")==0);
+ }
+
+}
diff --git a/java/test/TestH5Lparams.java b/java/test/TestH5Lparams.java
new file mode 100644
index 0000000..9a2c204
--- /dev/null
+++ b/java/test/TestH5Lparams.java
@@ -0,0 +1,231 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 hdf.hdf5lib.H5;
+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 TestH5Lparams {
+ @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(expected = HDF5LibraryException.class)
+ public void testH5Lget_value_invalid() throws Throwable {
+ H5.H5Lget_value(-1, "Bogus", null, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lget_value_null() throws Throwable {
+ H5.H5Lget_value(-1, null, null, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lexists_invalid() throws Throwable {
+ H5.H5Lexists(-1, "Bogus", -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lexists_null() throws Throwable {
+ H5.H5Lexists(-1, null, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_info_invalid() throws Throwable {
+ H5.H5Lget_info(-1, "Bogus", -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lget_info_null() throws Throwable {
+ H5.H5Lget_info(-1, null, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_info_by_idx_invalid() throws Throwable {
+ H5.H5Lget_info_by_idx(-1, "Bogus", -1, -1, -1L, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lget_info_by_idx_null() throws Throwable {
+ H5.H5Lget_info_by_idx(-1, null, 0, 0, 0L, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_name_by_idx_invalid() throws Throwable {
+ H5.H5Lget_name_by_idx(-1, "Bogus", -1, -1, -1L, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lget_name_by_idx_null() throws Throwable {
+ H5.H5Lget_name_by_idx(-1, null, 0, 0, 0L, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lcreate_hard_invalid() throws Throwable {
+ H5.H5Lcreate_hard(-1, "Bogus", -1, "Bogus", -1, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lcreate_hard_null_current() throws Throwable {
+ H5.H5Lcreate_hard(-1, null, 0, "Bogus", 0, 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lcreate_hard_null_dest() throws Throwable {
+ H5.H5Lcreate_hard(-1, "Bogus", 0, null, 0, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Ldelete_invalid() throws Throwable {
+ H5.H5Ldelete(-1, "Bogus", -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Ldelete_null() throws Throwable {
+ H5.H5Ldelete(-1, null, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lcreate_soft_invalid() throws Throwable {
+ H5.H5Lcreate_soft( "Bogus", -1, "Bogus", -1, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lcreate_soft_null_current() throws Throwable {
+ H5.H5Lcreate_soft(null, 0, "Bogus", 0, 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lcreate_soft_null_dest() throws Throwable {
+ H5.H5Lcreate_soft("Bogus", 0, null, 0, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lcreate_external_invalid() throws Throwable {
+ H5.H5Lcreate_external("PathToFile", "Bogus", -1, "Bogus", -1, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lcreate_external_null_file() throws Throwable {
+ H5.H5Lcreate_external(null, "Bogus", 0, "Bogus", 0, 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lcreate_external_null_current() throws Throwable {
+ H5.H5Lcreate_external("PathToFile", null, 0, "Bogus", 0, 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lcreate_external_null_dest() throws Throwable {
+ H5.H5Lcreate_external("PathToFile", "Bogus", 0, null, 0, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lcopy_invalid() throws Throwable {
+ H5.H5Lcopy(-1, "Bogus", -1, "Bogus", -1, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lcopy_null_current() throws Throwable {
+ H5.H5Lcopy(-1, null, 0, "Bogus", 0, 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lcopy_null_dest() throws Throwable {
+ H5.H5Lcopy(-1, "Bogus", 0, null, 0, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lmove_invalid() throws Throwable {
+ H5.H5Lmove(-1, "Bogus", -1, "Bogus", -1, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lmove_null_current() throws Throwable {
+ H5.H5Lmove(-1, null, 0, "Bogus", 0, 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lmove_null_dest() throws Throwable {
+ H5.H5Lmove(-1, "Bogus", 0, null, 0, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Lget_value_by_idx_invalid() throws Throwable {
+ H5.H5Lget_value_by_idx(-1, "Bogus", -1, -1, -1L, null, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lget_value_by_idx_null() throws Throwable {
+ H5.H5Lget_value_by_idx(-1, null, 0, 0, 0L, null, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Ldelete_by_idx_invalid() throws Throwable {
+ H5.H5Ldelete_by_idx(-1, "Bogus", -1, -1, -1L, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Ldelete_by_idx_null() throws Throwable {
+ H5.H5Ldelete_by_idx(-1, null, 0, 0, 0L, 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lvisit_null() throws Throwable {
+ H5.H5Lvisit(-1, -1, -1, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lvisit_by_name_nullname() throws Throwable {
+ H5.H5Lvisit_by_name(-1, null, -1, -1, null, null, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Lvisit_by_name_null() throws Throwable {
+ H5.H5Lvisit_by_name(-1, "Bogus", -1, -1, null, null, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Literate_null() throws Throwable {
+ H5.H5Literate(-1, -1, -1, -1, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Literate_by_name_nullname() throws Throwable {
+ H5.H5Literate_by_name(-1, null, -1, -1, -1, null, null, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Literate_by_name_null() throws Throwable {
+ H5.H5Literate_by_name(-1, "Bogus", -1, -1, -1, null, null, -1);
+ }
+
+}
diff --git a/java/test/TestH5Obasic.java b/java/test/TestH5Obasic.java
new file mode 100644
index 0000000..b564089
--- /dev/null
+++ b/java/test/TestH5Obasic.java
@@ -0,0 +1,488 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.callbacks.H5O_iterate_cb;
+import hdf.hdf5lib.callbacks.H5O_iterate_t;
+import hdf.hdf5lib.exceptions.HDF5LibraryException;
+import hdf.hdf5lib.structs.H5O_info_t;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5Obasic {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "h5ex_g_iterate.hdf";
+ private static long H5la_ds1 = -1;
+ private static long H5la_l1 = -1;
+ private static long H5la_dt1 = -1;
+ private static long H5la_g1 = -1;
+ long H5fid = -1;
+
+ @Before
+ public void openH5file()
+ throws HDF5LibraryException, NullPointerException {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ try {
+ H5fid = H5.H5Fopen(H5_FILE, HDF5Constants.H5F_ACC_RDONLY,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Fopen: openH5file: " + err);
+ }
+ }
+
+ @After
+ public void closeH5file() throws HDF5LibraryException {
+ if (H5fid > 0) {
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ }
+ System.out.println();
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oopen_not_exists() throws Throwable {
+ long oid = -1;
+
+ oid = H5.H5Oopen(H5fid, "Never_created", HDF5Constants.H5P_DEFAULT);
+
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ }
+
+ @Test
+ public void testH5Oget_info_dataset() {
+ long oid = -1;
+ H5O_info_t obj_info = null;
+
+ try {
+ oid = H5.H5Oopen(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info: " + err);
+ }
+ assertFalse("H5Oget_info ",obj_info==null);
+ assertTrue("H5Oget_info object type",obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ }
+
+ @Test
+ public void testH5Oget_info_hardlink() {
+ long oid = -1;
+ H5O_info_t obj_info = null;
+ try {
+ oid = H5.H5Oopen(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info: " + err);
+ }
+ assertFalse("H5Oget_info ",obj_info==null);
+ assertTrue("H5Oget_info object type",obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ }
+
+ @Test
+ public void testH5Oget_info_group() {
+ long oid = -1;
+ H5O_info_t obj_info = null;
+ try {
+ oid = H5.H5Oopen(H5fid, "G1", HDF5Constants.H5P_DEFAULT);
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info: " + err);
+ }
+ assertFalse("H5Oget_info ",obj_info==null);
+ assertTrue("H5Oget_info object type",obj_info.type==HDF5Constants.H5O_TYPE_GROUP);
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ }
+
+ @Test
+ public void testH5Oget_info_datatype() {
+ long oid = -1;
+ H5O_info_t obj_info = null;
+ try {
+ oid = H5.H5Oopen(H5fid, "DT1", HDF5Constants.H5P_DEFAULT);
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info: " + err);
+ }
+ assertFalse("H5Oget_info ",obj_info==null);
+ assertTrue("H5Oget_info object type",obj_info.type==HDF5Constants.H5O_TYPE_NAMED_DATATYPE);
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oget_info_by_name_not_exist_name() throws Throwable {
+ H5.H5Oget_info_by_name(H5fid, "None", HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oget_info_by_name_not_exists() throws Throwable {
+ H5.H5Oget_info_by_name(H5fid, "Bogus", HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Oget_info_by_name_dataset() {
+ H5O_info_t obj_info = null;
+
+ try {
+ obj_info = H5.H5Oget_info_by_name(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info: " + err);
+ }
+ assertFalse("H5Oget_info ",obj_info==null);
+ assertTrue("H5Oget_info object type",obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ }
+
+ @Test
+ public void testH5Oget_info_by_name_hardlink() {
+ H5O_info_t obj_info = null;
+ try {
+ obj_info = H5.H5Oget_info_by_name(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info: " + err);
+ }
+ assertFalse("H5Oget_info ",obj_info==null);
+ assertTrue("H5Oget_info object type",obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ }
+
+ @Test
+ public void testH5Oget_info_by_name_group() {
+ H5O_info_t obj_info = null;
+ try {
+ obj_info = H5.H5Oget_info_by_name(H5fid, "G1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info: " + err);
+ }
+ assertFalse("H5Oget_info ",obj_info==null);
+ assertTrue("H5Oget_info object type",obj_info.type==HDF5Constants.H5O_TYPE_GROUP);
+ }
+
+ @Test
+ public void testH5Oget_info_by_name_datatype() {
+ H5O_info_t obj_info = null;
+ try {
+ obj_info = H5.H5Oget_info_by_name(H5fid, "DT1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info: " + err);
+ }
+ assertFalse("H5Oget_info ",obj_info==null);
+ assertTrue("H5Oget_info object type",obj_info.type==HDF5Constants.H5O_TYPE_NAMED_DATATYPE);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oget_info_by_idx_name_not_exist_name() throws Throwable {
+ H5.H5Oget_info_by_idx(H5fid, "None", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oget_info_by_idx_name_not_exist_create() throws Throwable {
+ H5.H5Oget_info_by_idx(H5fid, "None", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oget_info_by_idx_not_exist_name() throws Throwable {
+ H5.H5Oget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 5, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oget_info_by_idx_not_exist_create() throws Throwable {
+ H5.H5Oget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 5, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Oget_info_by_idx_n0() {
+ long oid = -1;
+ H5O_info_t obj_info = null;
+ try {
+ oid = H5.H5Oopen(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oget_info_by_idx_n0:H5.H5Oget_info: " + err);
+ }
+ H5la_ds1 = obj_info.addr;
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ try {
+ obj_info = H5.H5Oget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oget_info_by_idx_n0:H5.H5Oget_info_by_idx: " + err);
+ }
+ assertFalse("testH5Oget_info_by_idx_n0:H5Oget_info_by_idx ",obj_info==null);
+ assertTrue("testH5Oget_info_by_idx_n0:H5Oget_info_by_idx link type",obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ assertTrue("testH5Oget_info_by_idx_n0:Link Address ",obj_info.addr==H5la_ds1);
+ }
+
+ @Test
+ public void testH5Oget_info_by_idx_n3() {
+ long oid = -1;
+ H5O_info_t obj_info = null;
+ try {
+ oid = H5.H5Oopen(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oget_info_by_idx_n3:H5.H5Oget_info: " + err);
+ }
+ H5la_l1 = obj_info.addr;
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ try {
+ obj_info = H5.H5Oget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 3, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oget_info_by_idx_n3:H5.H5Oget_info_by_idx: " + err);
+ }
+ assertFalse("testH5Oget_info_by_idx_n3:H5Oget_info_by_idx ",obj_info==null);
+ assertTrue("testH5Oget_info_by_idx_n3:H5Oget_info_by_idx link type",obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ assertTrue("testH5Oget_info_by_idx_n3:Link Address ",obj_info.addr==H5la_l1);
+ }
+
+ @Test
+ public void testH5Ovisit() {
+ class idata {
+ public String link_name = null;
+ public int link_type = -1;
+ idata(String name, int type) {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+ class H5O_iter_data implements H5O_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+ H5O_iterate_t iter_data = new H5O_iter_data();
+ class H5O_iter_callback implements H5O_iterate_cb {
+ public int callback(long group, String name, H5O_info_t info, H5O_iterate_t op_data) {
+ idata id = new idata(name, info.type);
+ ((H5O_iter_data)op_data).iterdata.add(id);
+ return 0;
+ }
+ }
+ H5O_iterate_cb iter_cb = new H5O_iter_callback();
+ try {
+ H5.H5Ovisit(H5fid, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, iter_cb, iter_data);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ovisit: " + err);
+ }
+ assertFalse("H5Ovisit ",((H5O_iter_data)iter_data).iterdata.isEmpty());
+ assertTrue("H5Ovisit "+((H5O_iter_data)iter_data).iterdata.size(),((H5O_iter_data)iter_data).iterdata.size()==5);
+ assertTrue("H5Ovisit "+(((H5O_iter_data)iter_data).iterdata.get(0)).link_name,(((H5O_iter_data)iter_data).iterdata.get(0)).link_name.compareToIgnoreCase(".")==0);
+ assertTrue("H5Ovisit "+(((H5O_iter_data)iter_data).iterdata.get(1)).link_name,(((H5O_iter_data)iter_data).iterdata.get(1)).link_name.compareToIgnoreCase("DS1")==0);
+ assertTrue("H5Ovisit "+(((H5O_iter_data)iter_data).iterdata.get(2)).link_name,(((H5O_iter_data)iter_data).iterdata.get(2)).link_name.compareToIgnoreCase("DT1")==0);
+ assertTrue("H5Ovisit "+(((H5O_iter_data)iter_data).iterdata.get(3)).link_name,(((H5O_iter_data)iter_data).iterdata.get(3)).link_name.compareToIgnoreCase("G1")==0);
+ assertTrue("H5Ovisit "+(((H5O_iter_data)iter_data).iterdata.get(4)).link_name,(((H5O_iter_data)iter_data).iterdata.get(4)).link_name.compareToIgnoreCase("G1/DS2")==0);
+// assertTrue("H5Ovisit "+((idata)((H5O_iter_data)iter_data).iterdata.get(5)).link_name,((idata)((H5O_iter_data)iter_data).iterdata.get(5)).link_name.compareToIgnoreCase("L1")==0);
+ }
+
+ @Test
+ public void testH5Ovisit_by_name() {
+ class idata {
+ public String link_name = null;
+ public int link_type = -1;
+ idata(String name, int type) {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+ class H5O_iter_data implements H5O_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+ H5O_iterate_t iter_data = new H5O_iter_data();
+ class H5O_iter_callback implements H5O_iterate_cb {
+ public int callback(long group, String name, H5O_info_t info, H5O_iterate_t op_data) {
+ idata id = new idata(name, info.type);
+ ((H5O_iter_data)op_data).iterdata.add(id);
+ return 0;
+ }
+ }
+ H5O_iterate_cb iter_cb = new H5O_iter_callback();
+ try {
+ H5.H5Ovisit_by_name(H5fid, "G1", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, iter_cb, iter_data, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ovisit_by_name: " + err);
+ }
+ assertFalse("H5Ovisit_by_name ",((H5O_iter_data)iter_data).iterdata.isEmpty());
+ assertTrue("H5Ovisit_by_name "+((H5O_iter_data)iter_data).iterdata.size(),((H5O_iter_data)iter_data).iterdata.size()==2);
+ assertTrue("H5Ovisit_by_name "+(((H5O_iter_data)iter_data).iterdata.get(0)).link_name,(((H5O_iter_data)iter_data).iterdata.get(0)).link_name.compareToIgnoreCase(".")==0);
+ assertTrue("H5Ovisit_by_name "+(((H5O_iter_data)iter_data).iterdata.get(1)).link_name,(((H5O_iter_data)iter_data).iterdata.get(1)).link_name.compareToIgnoreCase("DS2")==0);
+ }
+
+ @Test
+ public void testH5Oexists_by_name() {
+ boolean name_exists = false;
+ try {
+ name_exists = H5.H5Oexists_by_name(H5fid, "G1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oexists_by_name: " + err);
+ }
+ assertTrue("H5Oexists_by_name ", name_exists);
+ //TODO get dangling link result
+ }
+
+ @Test
+ public void testH5Oopen_by_addr() {
+ long oid = -1;
+ H5O_info_t obj_info = null;
+ try {
+ try {
+ oid = H5.H5Oopen(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oopen_by_addr: H5.H5Oget_info: " + err);
+ }
+ H5la_ds1 = obj_info.addr;
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ try {
+ oid = H5.H5Oopen_by_addr(H5fid, H5la_ds1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oopen_by_addr: H5.H5Oopen_by_addr: " + err);
+ }
+ try {
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oopen_by_addr: H5.H5Oget_info: " + err);
+ }
+ assertFalse("testH5Oopen_by_addr: H5Oget_info ",obj_info==null);
+ assertTrue("testH5Oopen_by_addr: H5Oget_info link type",obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ assertTrue("testH5Oopen_by_addr: Link Address ",obj_info.addr==H5la_ds1);
+ }
+ finally {
+ try{H5.H5Oclose(oid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Oopen_by_idx_n0() {
+ long oid = -1;
+ H5O_info_t obj_info = null;
+ try {
+ try {
+ oid = H5.H5Oopen(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oopen_by_idx_n0: H5.H5Oget_info: " + err);
+ }
+ H5la_ds1 = obj_info.addr;
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ try {
+ oid = H5.H5Oopen_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oopen_by_addr: H5.H5Oopen_by_addr: " + err);
+ }
+ try {
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oopen_by_idx_n0: H5.H5Oget_info_by_idx: " + err);
+ }
+ assertFalse("testH5Oopen_by_idx_n0: H5Oget_info_by_idx ",obj_info==null);
+ assertTrue("testH5Oopen_by_idx_n0: H5Oget_info_by_idx link type",obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ assertTrue("testH5Oopen_by_idx_n0: Link Address ",obj_info.addr==H5la_ds1);
+ }
+ finally {
+ try{H5.H5Oclose(oid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Oopen_by_idx_n3() {
+ long oid = -1;
+ H5O_info_t obj_info = null;
+ try {
+ try {
+ oid = H5.H5Oopen(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oopen_by_idx_n3:H5.H5Oget_info: " + err);
+ }
+ H5la_l1 = obj_info.addr;
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ try {
+ oid = H5.H5Oopen_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, 3, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oopen_by_addr: H5.H5Oopen_by_addr: " + err);
+ }
+ try {
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oopen_by_idx_n3:H5.H5Oget_info_by_idx: " + err);
+ }
+ assertFalse("testH5Oopen_by_idx_n3:H5Oget_info_by_idx ",obj_info==null);
+ assertTrue("testH5Oopen_by_idx_n3:H5Oget_info_by_idx link type",obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ assertTrue("testH5Oopen_by_idx_n3:Link Address ",obj_info.addr==H5la_l1);
+ }
+ finally {
+ try{H5.H5Oclose(oid);} catch (Exception ex) {}
+ }
+ }
+}
diff --git a/java/test/TestH5Ocopy.java b/java/test/TestH5Ocopy.java
new file mode 100644
index 0000000..62dd886
--- /dev/null
+++ b/java/test/TestH5Ocopy.java
@@ -0,0 +1,365 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.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 TestH5Ocopy {
+ @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 = -1;
+ long H5dsid = -1;
+ long H5did1 = -1;
+ long H5did2 = -1;
+ long H5gcpl = -1;
+ long H5gid = -1;
+ long H5dsid2 = -1;
+ 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 = -1;
+ 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 = -1;
+ 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 = -1;
+ byte rbuf0[]=null , rbuf1[] = null;
+ byte[] dset_data = new byte[16];
+ long attribute_id = -1;
+
+
+ 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 = -1;
+ long dataset_id = -1;
+ long H5fid2 = -1;
+
+ 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) {}
+ }
+ }
+
+ @Test
+ public void testH5OcopyRefsDatasettosameFile() {
+ byte rbuf0[]=null , rbuf1[] = null;
+ byte[] dset_data = new byte[16];
+ long ocp_plist_id = -1;
+ long dataset_id = -1;
+ long did = -1;
+ 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) {}
+ }
+ }
+
+// @Ignore because of JIRA HDF5-9547
+// @Test(expected = HDF5LibraryException.class)
+// public void testH5OcopyInvalidRef() throws Throwable {
+// final long _pid_ = HDF5Constants.H5P_DEFAULT;
+// long sid = -1;
+// long did = -1;
+// long aid = -1;
+//
+// 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/TestH5Ocreate.java b/java/test/TestH5Ocreate.java
new file mode 100644
index 0000000..0edecba
--- /dev/null
+++ b/java/test/TestH5Ocreate.java
@@ -0,0 +1,562 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.callbacks.H5O_iterate_cb;
+import hdf.hdf5lib.callbacks.H5O_iterate_t;
+import hdf.hdf5lib.exceptions.HDF5Exception;
+import hdf.hdf5lib.exceptions.HDF5LibraryException;
+import hdf.hdf5lib.structs.H5O_info_t;
+
+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 TestH5Ocreate {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_EXTFILE = "h5ex_g_iterate.hdf";
+ private static final String H5_FILE = "test.h5";
+ private static final int DIM_X = 4;
+ private static final int DIM_Y = 6;
+ long H5fcpl = -1;
+ long H5fid = -1;
+ long H5dsid = -1;
+ long H5did1 = -1;
+ long H5did2 = -1;
+ long H5gcpl = -1;
+ long H5gid = -1;
+ long[] H5dims = { DIM_X, DIM_Y };
+
+ 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 = -1;
+ 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 = -1;
+ 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;
+ }
+
+ private final void _createHardLink(long fid, long cid, String curname, long did, String dstname, long lcpl, long lapl) {
+ boolean link_exists = false;
+ try {
+ H5.H5Lcreate_hard(cid, curname, did, dstname, lcpl, lapl);
+ H5.H5Fflush(fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ link_exists = H5.H5Lexists(did, dstname, lapl);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lcreate_hard: " + err);
+ }
+ assertTrue("TestH5O._createHardLink ", link_exists);
+ }
+
+ private final void _createSoftLink(long fid, String curname, long did, String dstname, long lcpl, long lapl) {
+ boolean link_exists = false;
+ try {
+ H5.H5Lcreate_soft(curname, did, dstname, lcpl, lapl);
+ H5.H5Fflush(fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ link_exists = H5.H5Lexists(did, dstname, lapl);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lcreate_soft: " + err);
+ }
+ assertTrue("TestH5O._createSoftLink ", link_exists);
+ }
+
+ private final void _createExternalLink(long fid, String ext_filename, String curname, long did, String dstname, long lcpl, long lapl) {
+ boolean link_exists = false;
+ try {
+ H5.H5Lcreate_external(ext_filename, curname, did, dstname, lcpl, lapl);
+ H5.H5Fflush(fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ link_exists = H5.H5Lexists(did, dstname, lapl);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Lcreate_external: " + err);
+ }
+ assertTrue("TestH5O._createExternalLink ", link_exists);
+ }
+
+ @Before
+ public void createH5file()
+ throws NullPointerException, HDF5Exception {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+ try {
+ H5fcpl = H5.H5Pcreate(HDF5Constants.H5P_FILE_CREATE);
+ H5.H5Pset_link_creation_order(H5fcpl, HDF5Constants.H5P_CRT_ORDER_TRACKED+HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ H5fcpl, HDF5Constants.H5P_DEFAULT);
+ H5dsid = H5.H5Screate_simple(2, H5dims, null);
+ H5did1 = _createDataset(H5fid, H5dsid, "DS1", HDF5Constants.H5P_DEFAULT);
+ H5gid = _createGroup(H5fid, "/G1");
+ H5did2 = _createDataset(H5gid, H5dsid, "DS2", 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 (H5gcpl > 0)
+ try {H5.H5Pclose(H5gcpl);} catch (Exception ex) {}
+ if (H5did2 > 0)
+ try {H5.H5Dclose(H5did2);} catch (Exception ex) {}
+ if (H5dsid > 0)
+ try {H5.H5Sclose(H5dsid);} catch (Exception ex) {}
+ if (H5did1 > 0)
+ try {H5.H5Dclose(H5did1);} catch (Exception ex) {}
+ if (H5fid > 0)
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ if (H5fcpl > 0)
+ try {H5.H5Pclose(H5fcpl);} catch (Exception ex) {}
+
+ _deleteFile(H5_FILE);
+ System.out.println();
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Ocopy_cur_not_exists() throws Throwable {
+ H5.H5Ocopy(H5fid, "None", H5fid, "DS1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Ocopy() {
+ try {
+ H5.H5Ocopy(H5fid, "DS1", H5fid, "CPY1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ boolean link_exists = H5.H5Lexists(H5fid, "CPY1", HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Ocopy:H5Lexists ",link_exists);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ocopy: " + err);
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Ocopy_dst_link_exists() throws Throwable {
+ _createHardLink(H5fid, H5fid, "/G1/DS2", H5fid, "CPY1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Ocopy(H5fid, "CPY1", H5fid, "/G1/DS2", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Oget_info_by_idx_n0_create() {
+ H5O_info_t obj_info = null;
+ try {
+ int order = H5.H5Pget_link_creation_order(H5fcpl);
+ assertTrue("creation order :"+order, order == HDF5Constants.H5P_CRT_ORDER_TRACKED+HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info_by_idx_n0:H5Pget_link_creation_order " + err);
+ }
+ try {
+ obj_info = H5.H5Oget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 0, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info_by_idx: " + err);
+ }
+ assertFalse("H5Oget_info_by_idx ", obj_info==null);
+ assertTrue("H5Oget_info_by_idx link type", obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ }
+
+ @Test
+ public void testH5Oget_info_by_idx_n1_create() {
+ H5O_info_t obj_info = null;
+ try {
+ int order = H5.H5Pget_link_creation_order(H5fcpl);
+ assertTrue("creation order :"+order, order == HDF5Constants.H5P_CRT_ORDER_TRACKED+HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info_by_idx_n1:H5Pget_link_creation_order " + err);
+ }
+ try {
+ obj_info = H5.H5Oget_info_by_idx(H5fid, "/", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, 1, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info_by_idx: " + err);
+ }
+ assertFalse("H5Oget_info_by_idx ", obj_info==null);
+ assertTrue("H5Oget_info_by_idx link type", obj_info.type==HDF5Constants.H5O_TYPE_GROUP);
+ }
+
+ @Test
+ public void testH5Oget_info_softlink() {
+ H5O_info_t obj_info = null;
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ obj_info = H5.H5Oget_info_by_name(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info: " + err);
+ }
+ assertFalse("H5Oget_info ", obj_info==null);
+ assertTrue("H5Oget_info link type", obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ assertTrue("Link Address ", obj_info.addr>0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oget_info_softlink_dangle() throws Throwable {
+ _createSoftLink(H5fid, "DS3", H5fid, "L2", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Oget_info_by_name(H5fid, "L2", HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test
+ public void testH5Oget_info_externallink() {
+ H5O_info_t obj_info = null;
+ _createExternalLink(H5fid, H5_EXTFILE, "DT1", H5fid, "L1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ try {
+ obj_info = H5.H5Oget_info_by_name(H5fid, "L1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info: " + err);
+ }
+ assertFalse("H5Oget_info ", obj_info==null);
+ assertTrue("H5Oget_info link type", obj_info.type==HDF5Constants.H5O_TYPE_NAMED_DATATYPE);
+ assertTrue("Link Address ", obj_info.addr>0);
+ }
+
+ @Test
+ public void testH5Olink() {
+ long oid = -1;
+ H5O_info_t obj_info = null;
+ H5O_info_t dst_obj_info = null;
+ try {
+ oid = H5.H5Oopen(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ obj_info = H5.H5Oget_info(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info: " + err);
+ }
+ try {
+ H5.H5Olink(oid, H5fid, "CPY1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Olink: " + err);
+ }
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+
+ assertFalse("H5Oget_info ", obj_info==null);
+ assertTrue("H5Oget_info object type", obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+
+ try {
+ dst_obj_info = H5.H5Oget_info_by_name(H5fid, "CPY1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_info_by_name: " + err);
+ }
+ assertFalse("H5Oget_info ", dst_obj_info==null);
+ assertTrue("H5Oget_info object type", dst_obj_info.type==HDF5Constants.H5O_TYPE_DATASET);
+ }
+
+ @Test
+ public void testH5Ovisit_create() {
+ try {
+ int order = H5.H5Pget_link_creation_order(H5fcpl);
+ assertTrue("creation order :"+order, order == HDF5Constants.H5P_CRT_ORDER_TRACKED+HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ovisit_create:H5Pget_link_creation_order " + err);
+ }
+
+ _createHardLink(H5fid, H5fid, "/G1/DS2", H5fid, "CPY1", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ _createExternalLink(H5fid, H5_EXTFILE, "DT1", H5fid, "LE", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ _createSoftLink(H5fid, "/G1/DS2", H5fid, "LS", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+
+ class idata {
+ public String link_name = null;
+ public int link_type = -1;
+ idata(String name, int type) {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+ class H5O_iter_data implements H5O_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+ H5O_iterate_t iter_data = new H5O_iter_data();
+ class H5O_iter_callback implements H5O_iterate_cb {
+ public int callback(long group, String name, H5O_info_t info, H5O_iterate_t op_data) {
+ idata id = new idata(name, info.type);
+ ((H5O_iter_data)op_data).iterdata.add(id);
+ return 0;
+ }
+ }
+ H5O_iterate_cb iter_cb = new H5O_iter_callback();
+ try {
+ H5.H5Ovisit(H5fid, HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, iter_cb, iter_data);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Ovisit: " + err);
+ }
+ assertFalse("H5Ovisit ", ((H5O_iter_data)iter_data).iterdata.isEmpty());
+ assertTrue("H5Ovisit "+((H5O_iter_data)iter_data).iterdata.size(), ((H5O_iter_data)iter_data).iterdata.size()==4);
+ assertTrue("H5Ovisit "+((idata)((H5O_iter_data)iter_data).iterdata.get(0)).link_name, ((idata)((H5O_iter_data)iter_data).iterdata.get(0)).link_name.compareToIgnoreCase(".")==0);
+ assertTrue("H5Ovisit "+((idata)((H5O_iter_data)iter_data).iterdata.get(1)).link_name, ((idata)((H5O_iter_data)iter_data).iterdata.get(1)).link_name.compareToIgnoreCase("DS1")==0);
+ assertTrue("H5Ovisit "+((idata)((H5O_iter_data)iter_data).iterdata.get(2)).link_name, ((idata)((H5O_iter_data)iter_data).iterdata.get(2)).link_name.compareToIgnoreCase("G1")==0);
+ assertTrue("H5Ovisit "+((idata)((H5O_iter_data)iter_data).iterdata.get(3)).link_name, ((idata)((H5O_iter_data)iter_data).iterdata.get(3)).link_name.compareToIgnoreCase("G1/DS2")==0);
+ }
+
+ @Test
+ public void testH5Ocomment() {
+ long oid = -1;
+ String obj_comment = null;
+ try {
+ oid = H5.H5Oopen(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ H5.H5Oset_comment(oid, "Test Comment");
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oset_comment: " + err);
+ }
+ try {
+ obj_comment = H5.H5Oget_comment(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_comment: " + err);
+ }
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ assertFalse("H5Oget_comment: ", obj_comment==null);
+ assertTrue("H5Oget_comment: ", obj_comment.compareTo("Test Comment")==0);
+ }
+
+ @Test
+ public void testH5Ocomment_clear() {
+ long oid = -1;
+ String obj_comment = null;
+ try {
+ oid = H5.H5Oopen(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ H5.H5Oset_comment(oid, "Test Comment");
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oset_comment: " + err);
+ }
+ try {
+ obj_comment = H5.H5Oget_comment(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_comment: " + err);
+ }
+ assertFalse("H5Oget_comment: ", obj_comment==null);
+ assertTrue("H5Oget_comment: ", obj_comment.compareTo("Test Comment")==0);
+ try {
+ H5.H5Oset_comment(oid, null);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oset_comment: " + err);
+ }
+ try {
+ obj_comment = H5.H5Oget_comment(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_comment: " + err);
+ }
+ try {H5.H5Oclose(oid);} catch (Exception ex) {}
+ assertTrue("H5Oget_comment: ", obj_comment==null);
+ }
+
+ @Test
+ public void testH5Ocomment_by_name() {
+ String obj_comment = null;
+ try {
+ H5.H5Oset_comment_by_name(H5fid, "DS1", "Test Comment", HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oset_comment_by_name: " + err);
+ }
+ try {
+ obj_comment = H5.H5Oget_comment_by_name(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_comment_by_name: " + err);
+ }
+ assertFalse("H5Oget_comment_by_name: ", obj_comment==null);
+ assertTrue("H5Oget_comment_by_name: ", obj_comment.compareTo("Test Comment")==0);
+ }
+
+ @Test
+ public void testH5Ocomment_by_name_clear() {
+ String obj_comment = null;
+ try {
+ H5.H5Oset_comment_by_name(H5fid, "DS1", "Test Comment", HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oset_comment_by_name: " + err);
+ }
+ try {
+ obj_comment = H5.H5Oget_comment_by_name(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_comment_by_name: " + err);
+ }
+ assertFalse("H5Oget_comment_by_name: ", obj_comment==null);
+ assertTrue("H5Oget_comment_by_name: ", obj_comment.compareTo("Test Comment")==0);
+ try {
+ H5.H5Oset_comment_by_name(H5fid, "DS1", null, HDF5Constants.H5P_DEFAULT);
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oset_comment_by_name: " + err);
+ }
+ try {
+ obj_comment = H5.H5Oget_comment_by_name(H5fid, "DS1", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Oget_comment_by_name: " + err);
+ }
+ assertTrue("H5Oget_comment_by_name: ", obj_comment==null);
+ }
+
+ @Test
+ public void testH5Oinc_dec_count() {
+ long oid = -1;
+ H5O_info_t obj_info = null;
+ try {
+ try {
+ oid = H5.H5Oopen(H5fid, "G1", HDF5Constants.H5P_DEFAULT);
+ obj_info = H5.H5Oget_info(oid);
+ assertFalse("testH5Oinc_dec_count: H5Oget_info ",obj_info==null);
+ assertTrue("testH5Oinc_dec_count: H5Oget_info reference count",obj_info.rc==1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oinc_dec_count: H5.H5Oget_info: " + err);
+ }
+ try {
+ H5.H5Oincr_refcount(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oinc_dec_count: H5.H5Oincr_refcount: " + err);
+ }
+ try {
+ obj_info = H5.H5Oget_info(oid);
+ assertFalse("testH5Oinc_dec_count: H5Oget_info ",obj_info==null);
+ assertTrue("testH5Oinc_dec_count: H5Oget_info reference count",obj_info.rc==2);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oinc_dec_count: H5.H5Oget_info: " + err);
+ }
+ try {
+ H5.H5Odecr_refcount(oid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oinc_dec_count: H5.H5Odecr_refcount: " + err);
+ }
+ try {
+ obj_info = H5.H5Oget_info(oid);
+ assertFalse("testH5Oinc_dec_count: H5Oget_info ",obj_info==null);
+ assertTrue("testH5Oinc_dec_count: H5Oget_info reference count",obj_info.rc==1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Oinc_dec_count: H5.H5Oget_info: " + err);
+ }
+ }
+ finally {
+ try{H5.H5Oclose(oid);} catch (Exception ex) {}
+ }
+ }
+
+}
diff --git a/java/test/TestH5Oparams.java b/java/test/TestH5Oparams.java
new file mode 100644
index 0000000..ced66f5
--- /dev/null
+++ b/java/test/TestH5Oparams.java
@@ -0,0 +1,154 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+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 TestH5Oparams {
+ @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//(expected = HDF5LibraryException.class)
+ public void testH5Oclose_invalid() throws Throwable {
+ long oid = H5.H5Oclose(-1);
+ assertTrue(oid == 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Oopen_null() throws Throwable {
+ H5.H5Oopen(-1, null, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oopen_invalid() throws Throwable {
+ H5.H5Oopen(-1, "Bogus", 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Ocopy_invalid() throws Throwable {
+ H5.H5Ocopy(-1, "Bogus", -1, "Bogus", -1, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Ocopy_null_current() throws Throwable {
+ H5.H5Ocopy(-1, null, 0, "Bogus", 0, 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Ocopy_null_dest() throws Throwable {
+ H5.H5Ocopy(-1, "Bogus", 0, null, 0, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oget_info_invalid() throws Throwable {
+ H5.H5Oget_info(-1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Oget_info_by_name_null() throws Throwable {
+ H5.H5Oget_info_by_name(-1, null, HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oget_info_by_name_invalid() throws Throwable {
+ H5.H5Oget_info_by_name(-1, "/testH5Gcreate", HDF5Constants.H5P_DEFAULT);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oget_info_by_idx_invalid() throws Throwable {
+ H5.H5Oget_info_by_idx(-1, "Bogus", -1, -1, -1L, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Oget_info_by_idx_null() throws Throwable {
+ H5.H5Oget_info_by_idx(-1, null, 0, 0, 0L, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Olink_invalid() throws Throwable {
+ H5.H5Olink(-1, -1, "Bogus", -1, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Olink_null_dest() throws Throwable {
+ H5.H5Olink(-1, 0, null, 0, 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Ovisit_null() throws Throwable {
+ H5.H5Ovisit(-1, -1, -1, null, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Ovisit_by_name_nullname() throws Throwable {
+ H5.H5Ovisit_by_name(-1, null, -1, -1, null, null, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Ovisit_by_name_null() throws Throwable {
+ H5.H5Ovisit_by_name(-1, "Bogus", -1, -1, null, null, -1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oset_comment_invalid() throws Throwable {
+ H5.H5Oset_comment(-1, "Bogus");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Oget_comment_invalid() throws Throwable {
+ H5.H5Oget_comment(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Oset_comment_by_name_invalid() throws Throwable {
+ H5.H5Oset_comment_by_name(-1, "Bogus", null, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Oset_comment_by_name_null() throws Throwable {
+ H5.H5Oset_comment_by_name(-1, null, null, -1);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Oget_comment_by_name_invalid() throws Throwable {
+ H5.H5Oget_comment_by_name(-1, "Bogus", -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Oget_comment_by_name_null() throws Throwable {
+ H5.H5Oget_comment_by_name(-1, null, -1);
+ }
+
+}
diff --git a/java/test/TestH5P.java b/java/test/TestH5P.java
new file mode 100644
index 0000000..2a0fc34
--- /dev/null
+++ b/java/test/TestH5P.java
@@ -0,0 +1,1221 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5P {
+ @Rule public TestName testname = new TestName();
+
+ private static final String H5_FILE = "test.h5";
+ private static final int DIM_X = 4;
+ private static final int DIM_Y = 6;
+ long[] H5dims = { DIM_X, DIM_Y };
+ long H5fid = -1;
+ long H5dsid = -1;
+ long H5did = -1;
+ long lapl_id = -1;
+ long fapl_id = -1;
+ long fcpl_id = -1;
+ long ocpl_id = -1;
+ long ocp_plist_id = -1;
+ long lcpl_id = -1;
+ long plapl_id = -1;
+ long plist_id = -1;
+ long gapl_id = -1;
+ long gcpl_id = -1;
+ long acpl_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 dapl) {
+ long did = -1;
+ 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("TestH5P._createDataset: ", did > 0);
+
+ return did;
+ }
+
+ private final void _createH5File(long fcpl, long fapl) {
+ try {
+ H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ fcpl, fapl);
+ H5dsid = H5.H5Screate_simple(2, H5dims, null);
+ H5did = _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5P.createH5file: " + err);
+ }
+ assertTrue("TestH5P.createH5file: H5.H5Fcreate: ", H5fid > 0);
+ assertTrue("TestH5P.createH5file: H5.H5Screate_simple: ", H5dsid > 0);
+ assertTrue("TestH5P.createH5file: _createDataset: ", H5did > 0);
+
+ try {
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ }
+ }
+
+ public void deleteH5file() throws HDF5LibraryException {
+ _deleteFile(H5_FILE);
+ }
+
+ @Before
+ public void createH5fileProperties()
+ throws NullPointerException, HDF5Exception {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ try {
+ lapl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_ACCESS);
+ fapl_id = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS);
+ fcpl_id = H5.H5Pcreate(HDF5Constants.H5P_FILE_CREATE);
+ ocpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
+ ocp_plist_id = H5.H5Pcreate(HDF5Constants.H5P_OBJECT_COPY);
+ lcpl_id = H5.H5Pcreate(HDF5Constants.H5P_LINK_CREATE);
+ plapl_id = H5.H5Pcreate(HDF5Constants.H5P_LINK_ACCESS);
+ plist_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER);
+ gapl_id = H5.H5Pcreate(HDF5Constants.H5P_GROUP_ACCESS);
+ gcpl_id = H5.H5Pcreate(HDF5Constants.H5P_GROUP_CREATE);
+ acpl_id = H5.H5Pcreate(HDF5Constants.H5P_ATTRIBUTE_CREATE);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5P.createH5file: " + err);
+ }
+ assertTrue(lapl_id > 0);
+ assertTrue(fapl_id > 0);
+ assertTrue(fcpl_id > 0);
+ assertTrue(ocpl_id > 0);
+ assertTrue(ocp_plist_id > 0);
+ assertTrue(lcpl_id > 0);
+ assertTrue(plapl_id>0);
+ assertTrue(plist_id > 0);
+ assertTrue(gapl_id > 0);
+ assertTrue(gcpl_id >0);
+ assertTrue(acpl_id >0);
+ }
+
+ @After
+ public void deleteH5fileProperties() throws HDF5LibraryException {
+ if (lapl_id >0)
+ try {H5.H5Pclose(lapl_id);} catch (Exception ex) {}
+ if (fapl_id >0)
+ try {H5.H5Pclose(fapl_id);} catch (Exception ex) {}
+ if (fcpl_id >0)
+ try {H5.H5Pclose(fcpl_id);} catch (Exception ex) {}
+ if (ocpl_id >0)
+ try {H5.H5Pclose(ocpl_id);} catch (Exception ex) {}
+ if (ocp_plist_id >0)
+ try {H5.H5Pclose(ocp_plist_id);} catch (Exception ex) {}
+ if (lcpl_id >0)
+ try {H5.H5Pclose(lcpl_id);} catch (Exception ex) {}
+ if (plapl_id >0)
+ try {H5.H5Pclose(plapl_id);} catch (Exception ex) {}
+ if (plist_id >0)
+ try {H5.H5Pclose(plist_id);} catch (Exception ex) {}
+ if (gapl_id >0)
+ try {H5.H5Pclose(gapl_id);} catch (Exception ex) {}
+ if (gcpl_id >0)
+ try {H5.H5Pclose(gcpl_id);} catch (Exception ex) {}
+ if (acpl_id >0)
+ try {H5.H5Pclose(acpl_id);} catch (Exception ex) {}
+ if (H5dsid > 0)
+ try {H5.H5Sclose(H5dsid);} catch (Exception ex) {}
+ if (H5did > 0)
+ try {H5.H5Dclose(H5did);} catch (Exception ex) {}
+ if (H5fid > 0)
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Pget_nlinks() {
+ long nlinks = -1;
+ try {
+ nlinks = (long) H5.H5Pget_nlinks(lapl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Pget_nlinks: " + err);
+ }
+ assertTrue("testH5Pget_nlinks", nlinks > 0);
+ // Check the default value of nlinks.
+ assertEquals(nlinks, 16L);
+ }
+
+ @Test
+ public void testH5Pset_nlinks() {
+ long nlinks = 20;
+ int ret_val = -1;
+ try {
+ ret_val = H5.H5Pset_nlinks(lapl_id, nlinks);
+ nlinks = (long) H5.H5Pget_nlinks(lapl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Pset_nlinks: " + err);
+ }
+ assertTrue("testH5Pset_nlinks", ret_val >= 0);
+ // Check the value of nlinks retrieved from H5Pget_nlinks function.
+ assertEquals(nlinks, 20L);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_libver_bounds_invalidlow() throws Throwable {
+ H5.H5Pset_libver_bounds(fapl_id, 5, HDF5Constants.H5F_LIBVER_LATEST);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_libver_bounds_invalidhigh() throws Throwable {
+ H5.H5Pset_libver_bounds(fapl_id, HDF5Constants.H5F_LIBVER_LATEST, 5);
+ }
+
+ @Test
+ public void testH5Pget_link_creation_order() {
+ int crt_order_flags = 0;
+ try {
+ crt_order_flags = H5.H5Pget_link_creation_order(fcpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_link_creation_order: " + err);
+ }
+ assertTrue("testH5Pget_link_creation_order", crt_order_flags >= 0);
+ }
+
+ @Test
+ public void testH5Pset_link_creation_order_trackedPLUSindexed() {
+ int ret_val = -1;
+ int crt_order_flags = HDF5Constants.H5P_CRT_ORDER_TRACKED + HDF5Constants.H5P_CRT_ORDER_INDEXED;
+ int crtorderflags = 0;
+
+ try {
+ ret_val = H5.H5Pset_link_creation_order(fcpl_id, crt_order_flags);
+ crtorderflags = H5.H5Pget_link_creation_order(fcpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_link_creation_order: " + err);
+ }
+ assertTrue("testH5Pset_link_creation_order_trackedPLUSindexed",ret_val >= 0);
+ assertEquals(crt_order_flags, crtorderflags);
+ }
+
+ @Test
+ public void testH5Pset_link_creation_order_tracked() {
+ int ret_val = -1;
+ int crtorderflags = 0;
+
+ try {
+ ret_val = H5.H5Pset_link_creation_order(fcpl_id, HDF5Constants.H5P_CRT_ORDER_TRACKED);
+ crtorderflags = H5.H5Pget_link_creation_order(fcpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_link_creation_order: " + err);
+ }
+ assertTrue("testH5Pset_link_creation_order_tracked",ret_val >= 0);
+ assertEquals(HDF5Constants.H5P_CRT_ORDER_TRACKED, crtorderflags);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Pset_link_creation_order_invalidvalue() throws Throwable {
+ H5.H5Pset_link_creation_order(fcpl_id, HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ }
+
+ @Test
+ public void testH5Pget_attr_creation_order() {
+ int crt_order_flags = 0;
+
+ try {
+ crt_order_flags = H5.H5Pget_attr_creation_order(ocpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_attr_creation_order: " + err);
+ }
+ assertTrue("testH5Pget_attr_creation_order", crt_order_flags >= 0);
+ }
+
+ @Test
+ public void testH5Pset_attr_creation_order_trackedPLUSindexed() {
+ int ret_val = -1;
+ int crt_order_flags = HDF5Constants.H5P_CRT_ORDER_TRACKED + HDF5Constants.H5P_CRT_ORDER_INDEXED;
+ int crtorderflags = 0;
+
+ try {
+ ret_val = H5.H5Pset_attr_creation_order(ocpl_id, crt_order_flags);
+ crtorderflags = H5.H5Pget_attr_creation_order(ocpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_attr_creation_order: " + err);
+ }
+ assertTrue("testH5Pset_attr_creation_order_trackedPLUSindexed", ret_val >= 0);
+ assertEquals(crt_order_flags, crtorderflags);
+ }
+
+ @Test
+ public void testH5Pset_attr_creation_order_tracked() {
+ int ret_val = -1;
+ int crtorderflags = 0;
+
+ try {
+ ret_val = H5.H5Pset_attr_creation_order(ocpl_id, HDF5Constants.H5P_CRT_ORDER_TRACKED);
+ crtorderflags = H5.H5Pget_attr_creation_order(ocpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_attr_creation_order: " + err);
+ }
+ assertTrue("testH5Pset_attr_creation_order_tracked", ret_val >= 0);
+ assertEquals(HDF5Constants.H5P_CRT_ORDER_TRACKED, crtorderflags);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Pset_attr_creation_order_invalidvalue() throws Throwable {
+ H5.H5Pset_attr_creation_order(ocpl_id, HDF5Constants.H5P_CRT_ORDER_INDEXED);
+ }
+
+ @Test
+ public void testH5Pset_copy_object() {
+
+ int cpy_option = -1;
+
+ try {
+ H5.H5Pset_copy_object(ocp_plist_id, HDF5Constants.H5O_COPY_SHALLOW_HIERARCHY_FLAG);
+ cpy_option = H5.H5Pget_copy_object(ocp_plist_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_copy_object: " + err);
+ }
+ assertEquals(HDF5Constants.H5O_COPY_SHALLOW_HIERARCHY_FLAG, cpy_option);
+
+ try {
+ H5.H5Pset_copy_object(ocp_plist_id, HDF5Constants.H5O_COPY_EXPAND_REFERENCE_FLAG);
+ cpy_option = H5.H5Pget_copy_object(ocp_plist_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_copy_object: " + err);
+ }
+ assertEquals(HDF5Constants.H5O_COPY_EXPAND_REFERENCE_FLAG, cpy_option);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Pset_copy_object_invalidobject() throws Throwable {
+ H5.H5Pset_copy_object(HDF5Constants.H5P_DEFAULT, HDF5Constants.H5O_COPY_SHALLOW_HIERARCHY_FLAG);
+ }
+
+ @Test
+ public void testH5Pset_create_intermediate_group() {
+
+ int ret_val = -1;
+ try {
+ ret_val = H5.H5Pset_create_intermediate_group(lcpl_id, true);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_create_intermediate_group: " + err);
+ }
+ assertTrue(ret_val>=0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Pset_create_intermediate_group_invalidobject() throws Throwable {
+ H5.H5Pset_create_intermediate_group(ocp_plist_id, true);
+ }
+
+ @Test
+ public void testH5Pget_create_intermediate_group() {
+ boolean flag = false;
+ try {
+ H5.H5Pset_create_intermediate_group(lcpl_id, true);
+ flag = H5.H5Pget_create_intermediate_group(lcpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_create_intermediate_group: " + err);
+ }
+ assertEquals(true, flag);
+ }
+
+ @Test
+ public void testH5Pget_create_intermediate_group_notcreated() {
+ boolean flag = true;
+ try {
+ flag = H5.H5Pget_create_intermediate_group(lcpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_create_intermediate_group_notcreated: " + err);
+ }
+ assertEquals(false, flag);
+ }
+
+ @Test
+ public void testH5Pset_data_transform() {
+
+ String expression = "(5/9.0)*(x-32)";
+ int ret_val = -1;
+
+ try {
+ ret_val= H5.H5Pset_data_transform(plist_id, expression);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_data_transform: " + err);
+ }
+ assertTrue(ret_val>=0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Pset_data_transform_NullExpression() throws Throwable {
+ H5.H5Pset_data_transform(plist_id, null);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Pset_data_transform_InvalidExpression1() throws Throwable {
+ H5.H5Pset_data_transform(plist_id, "");
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Pset_data_transform_InvalidExpression2() throws Throwable {
+ H5.H5Pset_data_transform(plist_id, "hello");
+ }
+
+ @Test
+ public void testH5Pget_data_transform() {
+
+ String expression = "(5/9.0)*(x-32)";
+ String [] express = {""};
+ long express_size = 0;
+ long size = 20;
+
+ try {
+ H5.H5Pset_data_transform(plist_id, expression);
+ express_size = H5.H5Pget_data_transform(plist_id, express, size);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_data_transform: " + err);
+ }
+ assertTrue(express_size>=0);
+ assertTrue("The data transform expression: ", expression.equals(express[0]));
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Pget_data_transform_ExpressionNotSet() throws Throwable {
+ String [] express = {""};
+ H5.H5Pget_data_transform(plist_id, express, 20);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pget_data_transform_IllegalSize() throws Throwable {
+ String [] express = {""};
+ H5.H5Pset_data_transform(plist_id, "(5/9.0)*(x-32)");
+ H5.H5Pget_data_transform(plist_id, express, 0);
+ }
+
+ @Test
+ public void testH5Pget_elink_acc_flags() {
+
+ int get_flags = -1;
+ try {
+ get_flags = H5.H5Pget_elink_acc_flags(gapl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_elink_acc_flags: " + err);
+ }
+ assertTrue("H5Pget_elink_acc_flags", get_flags >= 0);
+ assertEquals(HDF5Constants.H5F_ACC_DEFAULT, get_flags);
+ }
+
+ @Test
+ public void testH5Pset_elink_acc_flags() {
+
+ int get_flags = -1;
+ int ret_val = -1;
+ try {
+ ret_val = H5.H5Pset_elink_acc_flags(lapl_id, HDF5Constants.H5F_ACC_RDWR);
+ get_flags = H5.H5Pget_elink_acc_flags(lapl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_elink_acc_flags: " + err);
+ }
+ assertTrue("H5Pset_elink_acc_flags", ret_val >= 0);
+ assertEquals(HDF5Constants.H5F_ACC_RDWR, get_flags);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_elink_acc_flags_InvalidFlag1() throws Throwable {
+ H5.H5Pset_elink_acc_flags(lapl_id, HDF5Constants.H5F_ACC_TRUNC);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_elink_acc_flags_InvalidFlag2() throws Throwable {
+ H5.H5Pset_elink_acc_flags(lapl_id, -1);
+ }
+
+ @Test
+ public void testH5Pset_link_phase_change() {
+
+ int ret_val = -1;
+ try {
+ ret_val = H5.H5Pset_link_phase_change(fcpl_id , 2, 2);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_link_phase_change: " + err);
+ }
+ assertTrue("H5Pset_link_phase_change", ret_val >= 0);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_link_phase_change_Highmax_Compact() throws Throwable {
+ H5.H5Pset_link_phase_change(fcpl_id , 70000000, 3);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_link_phase_change_max_compactLESSTHANmin_dense() throws Throwable {
+ H5.H5Pset_link_phase_change(fcpl_id , 5, 6);
+ }
+
+ @Test
+ public void testH5Pget_link_phase_change() {
+ int ret_val = -1;
+ int[] links = new int[2];
+
+ try {
+ ret_val = H5.H5Pget_link_phase_change(fcpl_id, links);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_link_phase_change: " + err);
+ }
+ assertTrue("testH5Pget_link_phase_change", ret_val >= 0);
+ assertEquals("Default value of maximum compact storage", 8, links[0]);
+ assertEquals("Default value of minimum dense storage", 6, links[1]);
+ }
+
+ @Test
+ public void testH5Pget_link_phase_change_EqualsSet() {
+ int[] links = new int[2];
+ try {
+ H5.H5Pset_link_phase_change(fcpl_id , 10, 7);
+ H5.H5Pget_link_phase_change(fcpl_id, links);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_link_phase_change_EqualsSet: " + err);
+ }
+ assertEquals("Value of maximum compact storage set", 10, links[0]);
+ assertEquals("Value of minimum dense storage set", 7, links[1]);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Pget_link_phase_change_Null() throws Throwable {
+ H5.H5Pget_link_phase_change(fcpl_id, null);
+ }
+
+ @Test
+ public void testH5Pget_attr_phase_change() {
+ int ret_val = -1;
+ int[] attributes = new int[2];
+
+ try {
+ ret_val = H5.H5Pget_attr_phase_change(ocpl_id, attributes);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_attr_phase_change: " + err);
+ }
+ assertTrue("testH5Pget_attr_phase_change", ret_val >= 0);
+ assertEquals("Default value of the max. no. of attributes stored in compact storage", 8, attributes[0]);
+ assertEquals("Default value of the min. no. of attributes stored in dense storage", 6, attributes[1]);
+ try {
+ H5.H5Pset_attr_phase_change(ocpl_id, 9, 5);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_attr_phase_change: " + err);
+ }
+ try {
+ ret_val = H5.H5Pget_attr_phase_change(ocpl_id, attributes);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_attr_phase_change: " + err);
+ }
+ assertTrue("testH5Pget_attr_phase_change", ret_val >= 0);
+ assertEquals("Default value of the max. no. of attributes stored in compact storage", 9, attributes[0]);
+ assertEquals("Default value of the min. no. of attributes stored in dense storage", 5, attributes[1]);
+ }
+
+ @Test
+ public void testH5Pget_shared_mesg_phase_change() {
+ int ret_val = -1;
+ int[] size = new int[2];
+
+ try {
+ ret_val = H5.H5Pget_shared_mesg_phase_change(fcpl_id, size);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_shared_mesg_phase_change: " + err);
+ }
+ assertTrue("testH5Pget_shared_mesg_phase_change", ret_val >= 0);
+ }
+
+ @Test
+ public void testH5Pget_shared_mesg_phase_change_EqualsSET() {
+ int[] size = new int[2];
+
+ try {
+ H5.H5Pset_shared_mesg_phase_change(fcpl_id,50, 40);
+ H5.H5Pget_shared_mesg_phase_change(fcpl_id, size);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_shared_mesg_phase_change_EqualsSET: " + err);
+ }
+ assertEquals("Value of maximum list set", 50, size[0]);
+ assertEquals("Value of minimum btree set", 40, size[1]);
+ }
+
+ @Test
+ public void testH5Pset_shared_mesg_phase_change() {
+
+ int ret_val = -1;
+ try {
+ ret_val = H5.H5Pset_shared_mesg_phase_change(fcpl_id,2, 1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_shared_mesg_phase_change: " + err);
+ }
+ assertTrue("H5Pset_shared_mesg_phase_change", ret_val >= 0);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5PH5Pset_shared_mesg_phase_change_HighMaxlistValue() throws Throwable {
+ H5.H5Pset_shared_mesg_phase_change(fcpl_id, 5001, 4000);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5PH5Pset_shared_mesg_phase_change_HighMinbtreeValue() throws Throwable {
+ H5.H5Pset_shared_mesg_phase_change(fcpl_id, 5000, 5001);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5PH5Pset_shared_mesg_phase_change_MinbtreeGreaterThanMaxlist() throws Throwable {
+ H5.H5Pset_link_phase_change(fcpl_id , 3, 7);
+ }
+
+ @Test
+ public void testH5Pget_shared_mesg_nindexes() {
+
+ int nindexes = -1;
+ try {
+ nindexes = H5.H5Pget_shared_mesg_nindexes(fcpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_shared_mesg_nindexes: " + err);
+ }
+ assertTrue("H5Pget_shared_mesg_nindexes", nindexes >= 0);
+ }
+
+ @Test
+ public void testH5Pset_shared_mesg_nindexes() {
+
+ int nindexes = -1;
+ int ret_val = -1;
+ try {
+ ret_val = H5.H5Pset_shared_mesg_nindexes(fcpl_id, 7);
+ nindexes = H5.H5Pget_shared_mesg_nindexes(fcpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_shared_mesg_nindexes: " + err);
+ }
+ assertTrue("H5Pset_shared_mesg_nindexes", ret_val >= 0);
+ assertEquals("Value of nindexes is equal to value set",7 ,nindexes);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_shared_mesg_nindexes_InvalidHIGHnindexes()throws Throwable {
+ H5.H5Pset_shared_mesg_nindexes(fcpl_id, 9);
+ }
+
+ @Test
+ public void testH5Pset_shared_mesg_index() {
+
+ int ret_val = -1;
+ try {
+ H5.H5Pset_shared_mesg_nindexes(fcpl_id, 2);
+ ret_val = H5.H5Pset_shared_mesg_index(fcpl_id, 0,HDF5Constants.H5O_SHMESG_ATTR_FLAG, 10);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_shared_mesg_index: " + err);
+ }
+ assertTrue("H5Pset_shared_mesg_index", ret_val >= 0);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_shared_mesg_index_Invalid_indexnum() throws Throwable {
+ H5.H5Pset_shared_mesg_index(fcpl_id, 2,HDF5Constants.H5O_SHMESG_ATTR_FLAG, 10);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_shared_mesg_index_InvalidFlag() throws Throwable {
+ H5.H5Pset_shared_mesg_nindexes(fcpl_id, 7);
+ H5.H5Pset_shared_mesg_index(fcpl_id, 2,HDF5Constants.H5O_SHMESG_ALL_FLAG + 1, 10);
+ }
+
+ @Test
+ public void testH5Pget_shared_mesg_index() {
+
+ int ret_val = -1;
+ int[] mesg_info = new int[2];
+ try {
+ H5.H5Pset_shared_mesg_nindexes(fcpl_id, 2);
+ H5.H5Pset_shared_mesg_index(fcpl_id, 0,HDF5Constants.H5O_SHMESG_ATTR_FLAG, 10);
+ ret_val = H5.H5Pget_shared_mesg_index(fcpl_id, 0, mesg_info);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_shared_mesg_index: " + err);
+ }
+ assertTrue("H5Pget_shared_mesg_index", ret_val >= 0);
+ assertEquals("Type of message", HDF5Constants.H5O_SHMESG_ATTR_FLAG, mesg_info[0]);
+ assertEquals("minimum message size", 10, mesg_info[1]);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pget_shared_mesg_index_Invalid_indexnum() throws Throwable {
+ int[] mesg_info = new int[2];
+ H5.H5Pget_shared_mesg_index(fcpl_id, 0, mesg_info);
+ }
+
+ @Test
+ public void testH5Pset_local_heap_size_hint() {
+ int ret_val = -1;
+ try {
+ ret_val = H5.H5Pset_local_heap_size_hint(gcpl_id, 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_local_heap_size_hint: " + err);
+ }
+ assertTrue("H5Pset_local_heap_size_hint", ret_val >= 0);
+ }
+
+ @Test
+ public void testH5Pget_local_heap_size_hint() {
+ long size_hint = -1;
+ try {
+ size_hint = H5.H5Pget_local_heap_size_hint(gcpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_local_heap_size_hint: " + err);
+ }
+ assertTrue("H5Pget_local_heap_size_hint", size_hint >= 0);
+ }
+
+ @Test
+ public void testH5Pset_nbit() {
+ int ret_val = -1;
+ try {
+ ret_val = H5.H5Pset_nbit(ocpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_nbit: " + err);
+ }
+ assertTrue("H5Pset_nbit", ret_val >= 0);
+ }
+
+ @Test
+ public void testH5Pset_scaleoffset() {
+ int ret_val = -1;
+ int scale_type = HDF5Constants.H5Z_SO_FLOAT_DSCALE;
+ int scale_factor = HDF5Constants.H5Z_SO_INT_MINBITS_DEFAULT;
+ try {
+ ret_val = H5.H5Pset_scaleoffset(ocpl_id, scale_type, scale_factor);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_scaleoffset: " + err);
+ }
+ assertTrue("H5Pset_scaleoffset", ret_val >= 0);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_scaleoffset_Invalidscale_type() throws Throwable {
+ H5.H5Pset_scaleoffset(ocpl_id, 3, 1);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_scaleoffset_Invalidscale_factor() throws Throwable {
+ H5.H5Pset_scaleoffset(ocpl_id, HDF5Constants.H5Z_SO_INT, -1);
+ }
+
+ @Test
+ public void testH5Pset_est_link_info() {
+ int ret_val = -1;
+ try {
+ ret_val = H5.H5Pset_est_link_info(gcpl_id, 0,10);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_est_link_info: " + err);
+ }
+ assertTrue("H5Pset_est_link_info", ret_val >= 0);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Pset_est_link_info_InvalidValues() throws Throwable {
+ H5.H5Pset_est_link_info(gcpl_id, 100000,10);
+ }
+
+ @Test
+ public void testH5Pget_est_link_info() {
+ int ret_val = -1;
+ int[] link_info = new int[2];
+ try {
+ ret_val = H5.H5Pget_est_link_info(gcpl_id, link_info);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_est_link_info: " + err);
+ }
+ assertTrue("H5Pget_est_link_info", ret_val >= 0);
+ }
+
+ @Test
+ public void testH5Pset_elink_prefix() {
+ int ret_val = -1;
+ String prefix = "tmp";
+ try {
+ ret_val = H5.H5Pset_elink_prefix(plapl_id, prefix);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_est_link_info: " + err);
+ }
+ assertTrue("H5Pset_elink_prefix", ret_val >= 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Pset_elink_prefix_null() throws Throwable{
+ H5.H5Pset_elink_prefix(plapl_id, null);
+ }
+
+ @Test
+ public void testH5Pget_elink_prefix() {
+ String prefix = "tmp";
+ String[] pre = {""};
+ long prefix_size = 0;
+
+ try {
+ H5.H5Pset_elink_prefix(plapl_id, prefix);
+ prefix_size = H5.H5Pget_elink_prefix(plapl_id, pre);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_elink_prefix: " + err);
+ }
+ assertTrue(prefix_size>=0);
+ assertTrue("The prefix: ", prefix.equals(pre[0]));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Pget_elink_prefix_null() throws Throwable {
+ H5.H5Pget_elink_prefix(plapl_id, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Pget_version_null() throws Throwable {
+ H5.H5Pget_version(fcpl_id, null);
+ }
+
+ @Test
+ public void testH5Pget_version() {
+ int[] version_info = {255,255,255,255};
+
+ try {
+ _createH5File(fcpl_id, fapl_id);
+ H5.H5Pget_version(fcpl_id, version_info);
+ deleteH5file();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_version: " + err);
+ }
+ assertTrue("super block version: "+version_info[0], version_info[0] == 0);
+ assertTrue("global freelist version: "+version_info[1], version_info[1] == 0);
+ assertTrue("symbol table version: "+version_info[2], version_info[2] == 0);
+ assertTrue("shared object header version: "+version_info[3], version_info[3] == 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Pget_userblock_null() throws Throwable {
+ H5.H5Pget_userblock(fcpl_id, null);
+ }
+
+ @Test
+ public void testH5P_userblock() {
+ int[] version_info = {255,255,255,255};
+ long[] size = {0};
+
+ try {
+ H5.H5Pset_userblock(fcpl_id, 1024);
+ _createH5File(fcpl_id, fapl_id);
+
+ /* Close FCPL */
+ H5.H5Pclose(fcpl_id);
+
+ /* Get the file's dataset creation property list */
+ fcpl_id = H5.H5Fget_create_plist(H5fid);
+
+ /* Get the file's version information */
+ H5.H5Pget_version(fcpl_id, version_info);
+ H5.H5Pget_userblock(fcpl_id, size);
+ deleteH5file();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_userblock: " + err);
+ }
+ assertTrue("super block version: "+version_info[0], version_info[0] == 0);
+ assertTrue("global freelist version: "+version_info[1], version_info[1] == 0);
+ assertTrue("symbol table version: "+version_info[2], version_info[2] == 0);
+ assertTrue("shared object header version: "+version_info[3], version_info[3] == 0);
+ assertTrue("user block size: "+size[0], size[0] == 1024);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Pget_sizes_null() throws Throwable {
+ H5.H5Pget_sizes(fcpl_id, null);
+ }
+
+ @Test
+ public void testH5P_sizes() {
+ int[] version_info = {255,255,255,255};
+ long[] size = {0,0};
+
+ try {
+ H5.H5Pset_sizes(fcpl_id, 4, 8);
+ _createH5File(fcpl_id, fapl_id);
+
+ /* Close FCPL */
+ H5.H5Pclose(fcpl_id);
+
+ /* Get the file's dataset creation property list */
+ fcpl_id = H5.H5Fget_create_plist(H5fid);
+
+ /* Get the file's version information */
+ H5.H5Pget_version(fcpl_id, version_info);
+ H5.H5Pget_sizes(fcpl_id, size);
+ deleteH5file();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_sizes: " + err);
+ }
+ assertTrue("super block version: "+version_info[0], version_info[0] == 0);
+ assertTrue("global freelist version: "+version_info[1], version_info[1] == 0);
+ assertTrue("symbol table version: "+version_info[2], version_info[2] == 0);
+ assertTrue("shared object header version: "+version_info[3], version_info[3] == 0);
+ assertTrue("sizeof_addr size: "+size[0], size[0] == 4);
+ assertTrue("sizeof_size size: "+size[1], size[1] == 8);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Pget_sym_k_null() throws Throwable {
+ H5.H5Pget_sym_k(fcpl_id, null);
+ }
+
+ @Test
+ public void testH5P_sym_k() {
+ int[] version_info = {255,255,255,255};
+ int[] size = {0,0};
+
+ try {
+ H5.H5Pset_sym_k(fcpl_id, 32, 8);
+ _createH5File(fcpl_id, fapl_id);
+
+ /* Close FCPL */
+ H5.H5Pclose(fcpl_id);
+
+ /* Get the file's dataset creation property list */
+ fcpl_id = H5.H5Fget_create_plist(H5fid);
+
+ /* Get the file's version information */
+ H5.H5Pget_version(fcpl_id, version_info);
+ H5.H5Pget_sym_k(fcpl_id, size);
+ deleteH5file();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_sym_k: " + err);
+ }
+ assertTrue("super block version: "+version_info[0], version_info[0] == 0);
+ assertTrue("global freelist version: "+version_info[1], version_info[1] == 0);
+ assertTrue("symbol table version: "+version_info[2], version_info[2] == 0);
+ assertTrue("shared object header version: "+version_info[3], version_info[3] == 0);
+ assertTrue("symbol table tree rank: "+size[0], size[0] == 32);
+ assertTrue("symbol table node size: "+size[1], size[1] == 8);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Pget_istore_k_null() throws Throwable {
+ H5.H5Pget_istore_k(fcpl_id, null);
+ }
+
+ @Test
+ public void testH5P_istore_k() {
+ int[] version_info = {255,255,255,255};
+ int[] size = {0};
+
+ try {
+ H5.H5Pset_istore_k(fcpl_id, 64);
+ _createH5File(fcpl_id, fapl_id);
+
+ /* Close FCPL */
+ H5.H5Pclose(fcpl_id);
+
+ /* Get the file's dataset creation property list */
+ fcpl_id = H5.H5Fget_create_plist(H5fid);
+
+ /* Get the file's version information */
+ H5.H5Pget_version(fcpl_id, version_info);
+ H5.H5Pget_istore_k(fcpl_id, size);
+ deleteH5file();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_sym_k: " + err);
+ }
+ assertTrue("super block version: "+version_info[0], version_info[0] == 1);
+ assertTrue("global freelist version: "+version_info[1], version_info[1] == 0);
+ assertTrue("symbol table version: "+version_info[2], version_info[2] == 0);
+ assertTrue("shared object header version: "+version_info[3], version_info[3] == 0);
+ assertTrue("chunked storage b-tree 1/2-rank: "+size[0], size[0] == 64);
+ }
+
+ @Test
+ public void testH5P_obj_track_times() {
+ boolean default_ret_val = false;
+ boolean ret_val = true;
+ try {
+ default_ret_val = H5.H5Pget_obj_track_times(ocpl_id);
+ H5.H5Pset_obj_track_times(ocpl_id, false);
+ ret_val = H5.H5Pget_obj_track_times(ocpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_obj_track_times: " + err);
+ }
+ assertTrue("H5Pget_obj_track_times default", default_ret_val);
+ assertFalse("H5Pget_obj_track_times", ret_val);
+ }
+
+ @Test
+ public void testH5Pget_char_encoding() {
+ int char_encoding = 0;
+
+ try {
+ char_encoding = H5.H5Pget_char_encoding(acpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_char_encoding: " + err);
+ }
+ assertTrue("testH5Pget_char_encoding", char_encoding == HDF5Constants.H5T_CSET_ASCII);
+ try {
+ H5.H5Pset_char_encoding(acpl_id, HDF5Constants.H5T_CSET_UTF8);
+ char_encoding = H5.H5Pget_char_encoding(acpl_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_char_encoding: " + err);
+ }
+ assertTrue("testH5Pget_char_encoding", char_encoding == HDF5Constants.H5T_CSET_UTF8);
+ }
+
+ @Test
+ public void testH5P_fill_time() {
+ int[] fill_time = {0};
+
+ try {
+ H5.H5Pget_fill_time(ocpl_id, fill_time);
+ assertTrue("fill_time: "+fill_time[0], fill_time[0] == HDF5Constants.H5D_FILL_TIME_IFSET);
+ H5.H5Pset_fill_time(ocpl_id, HDF5Constants.H5D_FILL_TIME_ALLOC);
+ H5.H5Pget_fill_time(ocpl_id, fill_time);
+ assertTrue("fill_time: "+fill_time[0], fill_time[0] == HDF5Constants.H5D_FILL_TIME_ALLOC);
+ H5.H5Pset_fill_time(ocpl_id, HDF5Constants.H5D_FILL_TIME_NEVER);
+ H5.H5Pget_fill_time(ocpl_id, fill_time);
+ assertTrue("fill_time: "+fill_time[0], fill_time[0] == HDF5Constants.H5D_FILL_TIME_NEVER);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fill_time: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_alloc_time() {
+ int[] alloc_time = {0};
+
+ try {
+ H5.H5Pget_alloc_time(ocpl_id, alloc_time);
+ assertTrue("alloc_time: "+alloc_time[0], alloc_time[0] == HDF5Constants.H5D_ALLOC_TIME_LATE);
+ H5.H5Pset_alloc_time(ocpl_id, HDF5Constants.H5D_ALLOC_TIME_EARLY);
+ H5.H5Pget_alloc_time(ocpl_id, alloc_time);
+ assertTrue("alloc_time: "+alloc_time[0], alloc_time[0] == HDF5Constants.H5D_ALLOC_TIME_EARLY);
+ H5.H5Pset_alloc_time(ocpl_id, HDF5Constants.H5D_ALLOC_TIME_INCR);
+ H5.H5Pget_alloc_time(ocpl_id, alloc_time);
+ assertTrue("alloc_time: "+alloc_time[0], alloc_time[0] == HDF5Constants.H5D_ALLOC_TIME_INCR);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_alloc_time: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_fill_value() {
+ int[] fill_value = {-1};
+ int[] fill_value_status = {-1};
+
+ try {
+ H5.H5Pfill_value_defined(ocpl_id, fill_value_status);
+ assertTrue("fill_value_status: "+fill_value_status[0], fill_value_status[0] == HDF5Constants.H5D_FILL_VALUE_DEFAULT);
+ H5.H5Pget_fill_value(ocpl_id, HDF5Constants.H5T_NATIVE_INT, fill_value);
+ assertTrue("fill_value: "+fill_value[0], fill_value[0] == 0);
+ fill_value[0] = 255;
+ H5.H5Pset_fill_value(ocpl_id, HDF5Constants.H5T_NATIVE_INT, fill_value);
+ H5.H5Pget_fill_value(ocpl_id, HDF5Constants.H5T_NATIVE_INT, fill_value);
+ assertTrue("fill_value: "+fill_value[0], fill_value[0] == 255);
+ H5.H5Pfill_value_defined(ocpl_id, fill_value_status);
+ assertTrue("fill_value_status: "+fill_value_status[0], fill_value_status[0] == HDF5Constants.H5D_FILL_VALUE_USER_DEFINED);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fill_value: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_layout() {
+ int layout_type = -1;
+
+ try {
+ layout_type = H5.H5Pget_layout(ocpl_id);
+ assertTrue("layout: "+layout_type, layout_type == HDF5Constants.H5D_CONTIGUOUS);
+ H5.H5Pset_layout(ocpl_id, HDF5Constants.H5D_COMPACT);
+ layout_type = H5.H5Pget_layout(ocpl_id);
+ assertTrue("layout: "+layout_type, layout_type == HDF5Constants.H5D_COMPACT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_layout: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_chunk() {
+ long[] chunk_size = {0,0};
+ long[] chunk_new_size = {2,3};
+ int layout_type = -1;
+
+ try {
+ H5.H5Pset_chunk(ocpl_id, 2, chunk_new_size);
+ H5.H5Pget_chunk(ocpl_id, 2, chunk_size);
+ assertTrue("chunk: "+chunk_size[0], chunk_size[0] == chunk_new_size[0]);
+ assertTrue("chunk: "+chunk_size[1], chunk_size[1] == chunk_new_size[1]);
+ layout_type = H5.H5Pget_layout(ocpl_id);
+ assertTrue("layout: "+layout_type, layout_type == HDF5Constants.H5D_CHUNKED);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_chunk: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_file_space() {
+ long[] threshold = {0};
+ int[] strategy = {0};
+ try {
+ H5.H5Pget_file_space(fcpl_id, strategy, threshold);
+ assertTrue("strategy: "+strategy[0], strategy[0] == HDF5Constants.H5F_FILE_SPACE_ALL);
+ assertTrue("theshold: "+threshold[0], threshold[0] == 1);
+ H5.H5Pset_file_space(fcpl_id, HDF5Constants.H5F_FILE_SPACE_ALL_PERSIST, 10);
+ H5.H5Pget_file_space(fcpl_id, strategy, threshold);
+ assertTrue("strategy: "+strategy[0], strategy[0] == HDF5Constants.H5F_FILE_SPACE_ALL_PERSIST);
+ assertTrue("theshold: "+threshold[0], threshold[0] == 10);
+ H5.H5Pset_file_space(fcpl_id, HDF5Constants.H5F_FILE_SPACE_VFD, 0);
+ H5.H5Pget_file_space(fcpl_id, strategy, threshold);
+ assertTrue("strategy: "+strategy[0], strategy[0] == HDF5Constants.H5F_FILE_SPACE_VFD);
+ assertTrue("theshold: "+threshold[0], threshold[0] == 10);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5P_file_space: " + err);
+ }
+ }
+}
diff --git a/java/test/TestH5PData.java b/java/test/TestH5PData.java
new file mode 100644
index 0000000..7fc154d
--- /dev/null
+++ b/java/test/TestH5PData.java
@@ -0,0 +1,170 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 java.io.File;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+
+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.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5PData {
+ @Rule public TestName testname = new TestName();
+
+ private static final String H5_FILE = "test.h5";
+ private static final int DIM_X = 12;
+ private static final int DIM_Y = 18;
+ long H5fid = -1;
+ long H5dsid = -1;
+ long H5did = -1;
+ long plist_id = -1;
+ long[] H5dims = { DIM_X, DIM_Y };
+ double windchillF[][] =
+ {{36.0, 31.0, 25.0, 19.0, 13.0, 7.0, 1.0, -5.0, -11.0, -16.0, -22.0, -28.0, -34.0, -40.0, -46.0, -52.0, -57.0, -63.0},
+ {34.0, 27.0, 21.0, 15.0, 9.0, 3.0, -4.0, -10.0, -16.0, -22.0, -28.0, -35.0, -41.0, -47.0, -53.0, -59.0, -66.0, -72.0},
+ {32.0, 25.0, 19.0, 13.0, 6.0, 0.0, -7.0, -13.0, -19.0, -26.0, -32.0, -39.0, -45.0, -51.0, -58.0, -64.0, -71.0, -77.0},
+ {30.0, 24.0, 17.0, 11.0, 4.0, -2.0, -9.0, -15.0, -22.0, -29.0, -35.0, -42.0, -48.0, -55.0, -61.0, -68.0, -74.0, -81.0},
+ {29.0, 23.0, 16.0, 9.0, 3.0, -4.0, -11.0, -17.0, -24.0, -31.0, -37.0, -44.0, -51.0, -58.0, -64.0, -71.0, -78.0, -84.0},
+ {28.0, 22.0, 15.0, 8.0, 1.0, -5.0, -12.0, -19.0, -26.0, -33.0, -39.0, -46.0, -53.0, -60.0, -67.0, -73.0, -80.0, -87.0},
+ {28.0, 21.0, 14.0, 7.0, 0.0, -7.0, -14.0, -21.0, -27.0, -34.0, -41.0, -48.0, -55.0, -62.0, -69.0, -76.0, -82.0, -89.0},
+ {27.0, 20.0, 13.0, 6.0, -1.0, -8.0, -15.0, -22.0, -29.0, -36.0, -43.0, -50.0, -57.0, -64.0, -71.0, -78.0, -84.0, -91.0},
+ {26.0, 19.0, 12.0, 5.0, -2.0, -9.0, -16.0, -23.0, -30.0, -37.0, -44.0, -51.0, -58.0, -65.0, -72.0, -79.0, -86.0, -93.0},
+ {26.0, 19.0, 12.0, 4.0, -3.0, -10.0, -17.0, -24.0, -31.0, -38.0, -45.0, -52.0, -60.0, -67.0, -74.0, -81.0, -88.0, -95.0},
+ {25.0, 18.0, 11.0, 4.0, -3.0, -11.0, -18.0, -25.0, -32.0, -39.0, -46.0, -54.0, -61.0, -68.0, -75.0, -82.0, -89.0, -97.0},
+ {25.0, 17.0, 10.0, 3.0, -4.0, -11.0, -19.0, -26.0, -33.0, -40.0, -48.0, -55.0, -62.0, -69.0, -76.0, -84.0, -91.0, -98.0}
+ };
+
+ private final void _deleteFile(String filename) {
+ File file = new File(filename);
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ }
+
+ private final long _createFloatDataset(long fid, long dsid, String name, long dapl) {
+ long did = -1;
+ try {
+ did = H5.H5Dcreate(fid, name, HDF5Constants.H5T_NATIVE_FLOAT, dsid,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, dapl);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Dcreate: " + err);
+ }
+ assertTrue("TestH5PData._createFloatDataset: ", did > 0);
+
+ return did;
+ }
+
+ @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(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5dsid = H5.H5Screate_simple(2, H5dims, null);
+ H5did = _createFloatDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+ plist_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5PData.createH5file: " + err);
+ }
+ assertTrue("TestH5PData.createH5file: H5.H5Fcreate: ",H5fid > 0);
+ assertTrue("TestH5PData.createH5file: H5.H5Screate_simple: ",H5dsid > 0);
+ assertTrue("TestH5PData.createH5file: _createFloatDataset: ",H5did > 0);
+ assertTrue(plist_id > 0);
+
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5dsid > 0)
+ try {H5.H5Sclose(H5dsid);} catch (Exception ex) {}
+ if (H5did > 0)
+ try {H5.H5Dclose(H5did);} catch (Exception ex) {}
+ if (H5fid > 0)
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+
+ _deleteFile(H5_FILE);
+
+ if (plist_id > 0)
+ try {H5.H5Pclose(plist_id);} catch (Exception ex) {}
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Pdata_transform() {
+ String f_to_c = "(5/9.0)*(x-32)";
+ double windchillFread[][] = new double[DIM_X][DIM_Y];
+ double windchillC;
+ NumberFormat formatter = new DecimalFormat("#0.000");
+
+ try {
+ H5.H5Pset_data_transform(plist_id, f_to_c);
+ H5.H5Dwrite(H5did, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ plist_id, windchillF);
+ H5.H5Dread(H5did, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, windchillFread);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pdata_transform: " + err);
+ }
+ for(int row = 0; row < DIM_X; row++)
+ for(int col = 0; col < DIM_Y; col++) {
+ windchillC = (5/9.0)*(windchillF[row][col]-32);
+ String Cstr = formatter.format(windchillC);
+ String Fread = formatter.format(windchillFread[row][col]);
+ assertTrue("H5Pdata_transform: <"+row+","+col+">"+Fread+"="+Cstr, Fread.compareTo(Cstr)==0);
+ }
+ }
+
+ @Test
+ public void testH5P_buffer() {
+ long default_size = 0;
+ long size = 0;
+
+ try {
+ default_size = H5.H5Pget_buffer_size(plist_id);
+ H5.H5Pset_buffer_size(plist_id, DIM_X*DIM_Y);
+ size = H5.H5Pget_buffer_size(plist_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_buffer fail: " + err);
+ }
+ assertTrue("H5P_buffer default: "+default_size, default_size==1024*1024);
+ assertTrue("H5P_buffer size: "+size, size==DIM_X*DIM_Y);
+ }
+}
diff --git a/java/test/TestH5Pfapl.java b/java/test/TestH5Pfapl.java
new file mode 100644
index 0000000..555afe0
--- /dev/null
+++ b/java/test/TestH5Pfapl.java
@@ -0,0 +1,1325 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+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 TestH5Pfapl {
+ @Rule public TestName testname = new TestName();
+
+ private static final String H5_FILE = "test.h5";
+ private static final String H5_LOG_FILE = "test.log";
+ private static final String H5_FAMILY_FILE = "test%05d";
+ private static final String H5_MULTI_FILE = "testmulti";
+ private static char MULTI_LETTERS[] = {'X','s','b','r','g','l','o'};
+ private static final int DIM_X = 4;
+ private static final int DIM_Y = 6;
+ private static final int DIMF_X = 12;
+ private static final int DIMF_Y = 18;
+ long H5fid = -1;
+ long H5dsid = -1;
+ long H5did = -1;
+ long H5Fdsid = -1;
+ long H5Fdid = -1;
+ long[] H5dims = { DIM_X, DIM_Y };
+ long fapl_id = -1;
+ long plapl_id = -1;
+ long dapl_id = -1;
+ long plist_id = -1;
+ long btplist_id = -1;
+ long[] H5Fdims = { DIMF_X, DIMF_Y };
+ double windchillF[][] =
+ {{36.0, 31.0, 25.0, 19.0, 13.0, 7.0, 1.0, -5.0, -11.0, -16.0, -22.0, -28.0, -34.0, -40.0, -46.0, -52.0, -57.0, -63.0},
+ {34.0, 27.0, 21.0, 15.0, 9.0, 3.0, -4.0, -10.0, -16.0, -22.0, -28.0, -35.0, -41.0, -47.0, -53.0, -59.0, -66.0, -72.0},
+ {32.0, 25.0, 19.0, 13.0, 6.0, 0.0, -7.0, -13.0, -19.0, -26.0, -32.0, -39.0, -45.0, -51.0, -58.0, -64.0, -71.0, -77.0},
+ {30.0, 24.0, 17.0, 11.0, 4.0, -2.0, -9.0, -15.0, -22.0, -29.0, -35.0, -42.0, -48.0, -55.0, -61.0, -68.0, -74.0, -81.0},
+ {29.0, 23.0, 16.0, 9.0, 3.0, -4.0, -11.0, -17.0, -24.0, -31.0, -37.0, -44.0, -51.0, -58.0, -64.0, -71.0, -78.0, -84.0},
+ {28.0, 22.0, 15.0, 8.0, 1.0, -5.0, -12.0, -19.0, -26.0, -33.0, -39.0, -46.0, -53.0, -60.0, -67.0, -73.0, -80.0, -87.0},
+ {28.0, 21.0, 14.0, 7.0, 0.0, -7.0, -14.0, -21.0, -27.0, -34.0, -41.0, -48.0, -55.0, -62.0, -69.0, -76.0, -82.0, -89.0},
+ {27.0, 20.0, 13.0, 6.0, -1.0, -8.0, -15.0, -22.0, -29.0, -36.0, -43.0, -50.0, -57.0, -64.0, -71.0, -78.0, -84.0, -91.0},
+ {26.0, 19.0, 12.0, 5.0, -2.0, -9.0, -16.0, -23.0, -30.0, -37.0, -44.0, -51.0, -58.0, -65.0, -72.0, -79.0, -86.0, -93.0},
+ {26.0, 19.0, 12.0, 4.0, -3.0, -10.0, -17.0, -24.0, -31.0, -38.0, -45.0, -52.0, -60.0, -67.0, -74.0, -81.0, -88.0, -95.0},
+ {25.0, 18.0, 11.0, 4.0, -3.0, -11.0, -18.0, -25.0, -32.0, -39.0, -46.0, -54.0, -61.0, -68.0, -75.0, -82.0, -89.0, -97.0},
+ {25.0, 17.0, 10.0, 3.0, -4.0, -11.0, -19.0, -26.0, -33.0, -40.0, -48.0, -55.0, -62.0, -69.0, -76.0, -84.0, -91.0, -98.0}
+ };
+
+ private final void _deleteFile(String filename) {
+ File file = null;
+ try {
+ file = new File(filename);
+ }
+ catch (Throwable err) {}
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ }
+
+ private final void _deleteLogFile() {
+ File file = null;
+ try {
+ file = new File(H5_LOG_FILE);
+ }
+ catch (Throwable err) {}
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ }
+
+ private final void _deleteFamilyFile() {
+ File file = null;
+ for(int indx = 0; ;indx++) {
+ java.text.DecimalFormat myFormat = new java.text.DecimalFormat("00000");
+ try {
+ file = new File("test"+myFormat.format(new Integer(indx))+".h5");
+ }
+ catch (Throwable err) {}
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ else
+ return;
+ }
+ }
+
+ private final void _deleteMultiFile() {
+ File file = null;
+ for(int indx = 1;indx<7;indx++) {
+ try {
+ file = new File(H5_MULTI_FILE+"-"+MULTI_LETTERS[indx]+".h5");
+ }
+ catch (Throwable err) {}
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ }
+ }
+
+ private final long _createDataset(long fid, long dsid, String name, long dapl) {
+ long did = -1;
+ 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("TestH5Pfapl._createDataset: ", did > 0);
+
+ return did;
+ }
+
+ private final void _createFloatDataset() {
+ try {
+ H5Fdsid = H5.H5Screate_simple(2, H5Fdims, null);
+ H5Fdid = H5.H5Dcreate(H5fid, "dsfloat", HDF5Constants.H5T_NATIVE_FLOAT, H5Fdsid,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Dcreate: " + err);
+ }
+ assertTrue("TestH5Pfapl._createFloatDataset: ", H5Fdid > 0);
+
+ try {
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ }
+ }
+
+ private final void _createH5multiFileDS() {
+ try {
+ H5did = _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5Pfapl.createH5file: " + err);
+ }
+ assertTrue("TestH5Pfapl.createH5file: _createDataset: ", H5did > 0);
+
+ try {
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ }
+ }
+
+ private final void _createH5File(long fapl) {
+ try {
+ H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, fapl);
+ H5dsid = H5.H5Screate_simple(2, H5dims, null);
+ H5did = _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5Pfapl.createH5file: " + err);
+ }
+ assertTrue("TestH5Pfapl.createH5file: H5.H5Fcreate: ", H5fid > 0);
+ assertTrue("TestH5Pfapl.createH5file: H5.H5Screate_simple: ", H5dsid > 0);
+ assertTrue("TestH5Pfapl.createH5file: _createDataset: ", H5did > 0);
+
+ try {
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ }
+ }
+
+ private final void _createH5familyFile(long fapl) {
+ try {
+ H5fid = H5.H5Fcreate(H5_FAMILY_FILE+".h5", HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, fapl);
+ H5dsid = H5.H5Screate_simple(2, H5dims, null);
+ H5did = _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5Pfapl.createH5file: " + err);
+ }
+ assertTrue("TestH5Pfapl.createH5file: H5.H5Fcreate: ", H5fid > 0);
+ assertTrue("TestH5Pfapl.createH5file: H5.H5Screate_simple: ", H5dsid > 0);
+ assertTrue("TestH5Pfapl.createH5file: _createDataset: ", H5did > 0);
+
+ try {
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ }
+ }
+
+ private final void _createH5multiFile(long fapl) {
+ try {
+ H5fid = H5.H5Fcreate(H5_MULTI_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, fapl);
+ H5dsid = H5.H5Screate_simple(2, H5dims, null);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5Pfapl.createH5file: " + err);
+ }
+ assertTrue("TestH5Pfapl.createH5file: H5.H5Fcreate: ", H5fid > 0);
+ assertTrue("TestH5Pfapl.createH5file: H5.H5Screate_simple: ", H5dsid > 0);
+
+ try {
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ }
+ }
+
+ public void deleteH5file() {
+ _deleteFile(H5_FILE);
+ }
+
+ public void deleteH5familyfile() {
+ _deleteFamilyFile();
+ }
+
+ public void deleteH5multifile() {
+ _deleteMultiFile();
+ }
+
+ @Before
+ public void createFileAccess()
+ throws NullPointerException, HDF5Exception {
+ assertTrue("H5 open ids is 0",H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ try {
+ fapl_id = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5Pfapl.createFileAccess: " + err);
+ }
+ assertTrue(fapl_id > 0);
+ try {
+ plapl_id = H5.H5Pcreate(HDF5Constants.H5P_LINK_ACCESS);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5Pfapl.createFileAccess: " + err);
+ }
+ assertTrue(plapl_id > 0);
+ try {
+ plist_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER);
+ btplist_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER);
+ dapl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_ACCESS);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5Pfapl.createFileAccess: " + err);
+ }
+ assertTrue(plist_id > 0);
+ assertTrue(btplist_id > 0);
+ assertTrue(dapl_id > 0);
+ }
+
+ @After
+ public void deleteFileAccess() throws HDF5LibraryException {
+ if (fapl_id > 0)
+ try {H5.H5Pclose(fapl_id);} catch (Exception ex) {}
+ if (plapl_id > 0)
+ try {H5.H5Pclose(plapl_id);} catch (Exception ex) {}
+ if (dapl_id > 0)
+ try {H5.H5Pclose(dapl_id);} catch (Exception ex) {}
+ if (plist_id > 0)
+ try {H5.H5Pclose(plist_id);} catch (Exception ex) {}
+ if (btplist_id > 0)
+ try {H5.H5Pclose(btplist_id);} catch (Exception ex) {}
+
+ if (H5Fdsid > 0)
+ try {H5.H5Sclose(H5Fdsid);} catch (Exception ex) {}
+ if (H5Fdid > 0)
+ try {H5.H5Dclose(H5Fdid);} catch (Exception ex) {}
+ if (H5dsid > 0)
+ try {H5.H5Sclose(H5dsid);} catch (Exception ex) {}
+ if (H5did > 0)
+ try {H5.H5Dclose(H5did);} catch (Exception ex) {}
+ if (H5fid > 0)
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Pget_libver_bounds() {
+ int ret_val = -1;
+ int[] libver = new int[2];
+
+ try {
+ ret_val = H5.H5Pget_libver_bounds(fapl_id, libver);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_libver_bounds: " + err);
+ }
+ assertTrue("testH5Pget_libver_bounds", ret_val >= 0);
+ // Check the Earliest Version if the library
+ assertEquals(HDF5Constants.H5F_LIBVER_EARLIEST, libver[0]);
+ // Check the Latest Version if the library
+ assertEquals(HDF5Constants.H5F_LIBVER_LATEST, libver[1]);
+ }
+
+ @Test
+ public void testH5Pset_libver_bounds() {
+
+ int ret_val = -1;
+ int low = HDF5Constants.H5F_LIBVER_EARLIEST;
+ int high = HDF5Constants.H5F_LIBVER_LATEST;
+ int[] libver = new int[2];
+
+ try {
+ ret_val = H5.H5Pset_libver_bounds(fapl_id, low, high);
+ H5.H5Pget_libver_bounds(fapl_id, libver);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_libver_bounds: " + err);
+ }
+ assertTrue("testH5Pset_libver_bounds", ret_val >= 0);
+ // Check the Earliest Version if the library
+ assertEquals(HDF5Constants.H5F_LIBVER_EARLIEST, libver[0]);
+ // Check the Latest Version if the library
+ assertEquals(HDF5Constants.H5F_LIBVER_LATEST, libver[1]);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Pset_elink_fapl_NegativeID() throws Throwable {
+ H5.H5Pset_elink_fapl(-1, fapl_id );
+ }
+
+ @Test
+ public void testH5Pset_elink_fapl() {
+ int ret_val = -1;
+ try {
+ ret_val = H5.H5Pset_elink_fapl(plapl_id, fapl_id );
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_elink_fapl: " + err);
+ }
+ assertTrue("H5Pset_elink_fapl", ret_val >= 0);
+ }
+
+ @Test
+ public void testH5Pget_elink_fapl() {
+ long ret_val_id = -1;
+ try {
+ ret_val_id = H5.H5Pget_elink_fapl(plapl_id);
+ assertTrue("H5Pget_elink_fapl", ret_val_id >= 0);
+ assertEquals(HDF5Constants.H5P_DEFAULT, ret_val_id );
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_elink_fapl: " + err);
+ }
+ finally {
+ if (ret_val_id > 0)
+ try {H5.H5Pclose(ret_val_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5P_elink_fapl() {
+ long ret_val_id = -1;
+ try {
+ H5.H5Pset_elink_fapl(plapl_id, fapl_id );
+ ret_val_id = H5.H5Pget_elink_fapl(plapl_id);
+ assertTrue("H5P_elink_fapl", ret_val_id >= 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_elink_fapl: " + err);
+ }
+ finally {
+ if (ret_val_id > 0)
+ try {H5.H5Pclose(ret_val_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5P_elink_file_cache_size() {
+ long elink_fapl_id = -1;
+ int efc_size = 0;
+ try {
+ H5.H5Pset_elink_fapl(plapl_id, fapl_id );
+ elink_fapl_id = H5.H5Pget_elink_fapl(plapl_id);
+ assertTrue("H5P_elink_file_cache_size", elink_fapl_id >= 0);
+ try {
+ efc_size = H5.H5Pget_elink_file_cache_size(elink_fapl_id);
+ assertTrue("H5P_elink_file_cache_size default", efc_size == 0);
+ }
+ catch (UnsupportedOperationException err) {
+ System.out.println(err.getMessage());
+ }
+ try {
+ efc_size = 8;
+ H5.H5Pset_elink_file_cache_size(elink_fapl_id, efc_size);
+ efc_size = H5.H5Pget_elink_file_cache_size(elink_fapl_id);
+ assertTrue("H5P_elink_file_cache_size 8", efc_size == 8);
+ }
+ catch (UnsupportedOperationException err) {
+ System.out.println(err.getMessage());
+ }
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_elink_file_cache_size: " + err);
+ }
+ finally {
+ if (elink_fapl_id > 0)
+ try {H5.H5Pclose(elink_fapl_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5P_btree_ratios() {
+ double[] left = {0.1};
+ double[] middle = {0.5};
+ double[] right = {0.7};
+ try {
+ H5.H5Pset_btree_ratios(plist_id, left[0], middle[0], right[0]);
+ H5.H5Pget_btree_ratios(plist_id, left, middle, right);
+ assertTrue("H5P_btree_ratios", left[0] == 0.1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_btree_ratios: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_edc_check() {
+ int ret_val_id = -1;
+ try {
+ ret_val_id = H5.H5Pget_edc_check(plist_id);
+ assertTrue("H5P_edc_check", ret_val_id == HDF5Constants.H5Z_ENABLE_EDC);
+ H5.H5Pset_edc_check(plist_id, HDF5Constants.H5Z_DISABLE_EDC);
+ ret_val_id = H5.H5Pget_edc_check(plist_id);
+ assertTrue("H5P_edc_check", ret_val_id == HDF5Constants.H5Z_DISABLE_EDC);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_edc_check: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_fclose_degree() {
+ int ret_val_id = -1;
+ try {
+ ret_val_id = H5.H5Pget_fclose_degree(fapl_id);
+ assertTrue("H5Pget_fclose_degree default", ret_val_id == HDF5Constants.H5F_CLOSE_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_fclose_degree: default " + err);
+ }
+ try {
+ H5.H5Pset_fclose_degree(fapl_id, HDF5Constants.H5F_CLOSE_STRONG);
+ ret_val_id = H5.H5Pget_fclose_degree(fapl_id);
+ assertTrue("H5Pget_fclose_degree", ret_val_id == HDF5Constants.H5F_CLOSE_STRONG);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_fclose_degree: H5F_CLOSE_STRONG " + err);
+ }
+ try {
+ H5.H5Pset_fclose_degree(fapl_id, HDF5Constants.H5F_CLOSE_SEMI);
+ ret_val_id = H5.H5Pget_fclose_degree(fapl_id);
+ assertTrue("H5Pget_fclose_degree", ret_val_id == HDF5Constants.H5F_CLOSE_SEMI);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_fclose_degree: H5F_CLOSE_SEMI " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_alignment() {
+ long[] align = {0,0};
+ try {
+ H5.H5Pget_alignment(fapl_id, align);
+ assertTrue("H5P_alignment threshold default", align[0] == 1);
+ assertTrue("H5P_alignment alignment default", align[1] == 1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_alignment: default " + err);
+ }
+ try {
+ align[0] = 1024;
+ align[1] = 2048;
+ H5.H5Pset_alignment(fapl_id, align[0], align[1]);
+ H5.H5Pget_alignment(fapl_id, align);
+ assertTrue("H5P_alignment threshold", align[0] == 1024);
+ assertTrue("H5P_alignment alignment", align[1] == 2048);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_alignment: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_meta_block_size() {
+ long meta_size = 0;
+ try {
+ meta_size = H5.H5Pget_meta_block_size(fapl_id);
+ assertTrue("H5P_meta_block_size default", meta_size == 2048);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_meta_block_size: default " + err);
+ }
+ try {
+ meta_size = 4096;
+ H5.H5Pset_meta_block_size(fapl_id, meta_size);
+ meta_size = H5.H5Pget_meta_block_size(fapl_id);
+ assertTrue("H5P_meta_block_size 4096", meta_size == 4096);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_meta_block_size: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_small_data_block_size() {
+ long align = 0;
+ try {
+ align = H5.H5Pget_small_data_block_size(fapl_id);
+ assertTrue("H5P_small_data_block_size default", align == 2048);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_small_data_block_size: default " + err);
+ }
+ try {
+ align = 4096;
+ H5.H5Pset_small_data_block_size(fapl_id, align);
+ align = H5.H5Pget_small_data_block_size(fapl_id);
+ assertTrue("H5P_small_data_block_size 4096", align == 4096);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_small_data_block_size: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_hyper_vector_size() {
+ long[] align = {0};
+ try {
+ H5.H5Pget_hyper_vector_size(plist_id, align);
+ assertTrue("H5P_hyper_vector_size default", align[0] == 1024);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_hyper_vector_size: default " + err);
+ }
+ try {
+ align[0] = 4096;
+ H5.H5Pset_hyper_vector_size(plist_id, align[0]);
+ H5.H5Pget_hyper_vector_size(plist_id, align);
+ assertTrue("H5P_hyper_vector_size 4096", align[0] == 4096);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_hyper_vector_size: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_cache() {
+ long[] rdcc_nelmts = {0};
+ long[] rdcc_nbytes = {0};
+ double[] rdcc_w0 = {0};
+ try {
+ H5.H5Pget_cache(fapl_id, null, rdcc_nelmts, rdcc_nbytes, rdcc_w0);
+ assertTrue("H5P_cache default", rdcc_nelmts[0] == 521);
+ assertTrue("H5P_cache default", rdcc_nbytes[0] == (1024*1024));
+ assertTrue("H5P_cache default", rdcc_w0[0] == 0.75);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_cache: default " + err);
+ }
+ try {
+ rdcc_nelmts[0] = 4096;
+ H5.H5Pset_cache(fapl_id, 0, rdcc_nelmts[0], rdcc_nbytes[0], rdcc_w0[0]);
+ H5.H5Pget_cache(fapl_id, null, rdcc_nelmts, rdcc_nbytes, rdcc_w0);
+ assertTrue("H5P_cache 4096", rdcc_nelmts[0] == 4096);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_cache: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_chunk_cache() {
+ long[] rdcc_nslots = {0};
+ long[] rdcc_nbytes = {0};
+ double[] rdcc_w0 = {0};
+ try {
+ H5.H5Pget_chunk_cache(dapl_id, rdcc_nslots, rdcc_nbytes, rdcc_w0);
+ assertTrue("H5P_chunk_cache default", rdcc_nslots[0] == 521);
+ assertTrue("H5P_chunk_cache default", rdcc_nbytes[0] == (1024*1024));
+ assertTrue("H5P_chunk_cache default", rdcc_w0[0] == 0.75);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_chunk_cache: default " + err);
+ }
+ try {
+ rdcc_nslots[0] = 4096;
+ H5.H5Pset_chunk_cache(dapl_id, rdcc_nslots[0], rdcc_nbytes[0], rdcc_w0[0]);
+ H5.H5Pget_chunk_cache(dapl_id, rdcc_nslots, rdcc_nbytes, rdcc_w0);
+ assertTrue("H5P_chunk_cache 4096", rdcc_nslots[0] == 4096);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_chunk_cache: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_sieve_buf_size() {
+ long buf_size = 0;
+ try {
+ buf_size = H5.H5Pget_sieve_buf_size(fapl_id);
+ assertTrue("H5P_sieve_buf_size default", buf_size == (64*1024));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_sieve_buf_size: default " + err);
+ }
+ try {
+ buf_size = 4096;
+ H5.H5Pset_sieve_buf_size(fapl_id, buf_size);
+ buf_size = H5.H5Pget_sieve_buf_size(fapl_id);
+ assertTrue("H5P_sieve_buf_size 4096", buf_size == 4096);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_sieve_buf_size: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_gc_references() {
+ boolean ret_val_id = false;
+ try {
+ H5.H5Pset_gc_references(fapl_id, true);
+ ret_val_id = H5.H5Pget_gc_references(fapl_id);
+ assertTrue("H5P_gc_references", ret_val_id);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5P_gc_references: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Pget_mdc_config() {
+ H5AC_cache_config_t cache_config = null;
+ try {
+ cache_config = H5.H5Pget_mdc_config(fapl_id);
+ assertTrue("H5Pget_mdc_config", cache_config.version==HDF5Constants.H5AC_CURR_CACHE_CONFIG_VERSION);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_mdc_config: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Pset_mdc_config() {
+ H5AC_cache_config_t cache_config = null;
+ try {
+ cache_config = H5.H5Pget_mdc_config(fapl_id);
+ assertTrue("H5Pset_mdc_config", cache_config.version==HDF5Constants.H5AC_CURR_CACHE_CONFIG_VERSION);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_mdc_config: " + err);
+ }
+ try {
+ cache_config.decr_mode = HDF5Constants.H5C_decr_off;
+ H5.H5Pset_mdc_config(fapl_id, cache_config);
+ cache_config = H5.H5Pget_mdc_config(fapl_id);
+ assertTrue("H5Pset_mdc_config", cache_config.version==HDF5Constants.H5AC_CURR_CACHE_CONFIG_VERSION);
+ assertTrue("H5Pset_mdc_config", cache_config.decr_mode==HDF5Constants.H5C_decr_off);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_mdc_config: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_fapl_core() {
+ if (HDF5Constants.H5FD_CORE < 0)
+ return;
+ try {
+ H5.H5Pset_fapl_core(fapl_id, 4096, false);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: core = "+ driver_type, HDF5Constants.H5FD_CORE==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_core: " + err);
+ }
+ try {
+ long[] increment = {-1};
+ boolean[] backingstore = {true};
+ H5.H5Pget_fapl_core(fapl_id, increment, backingstore);
+ assertTrue("H5Pget_fapl_core: increment="+increment[0], increment[0]==4096);
+ assertTrue("H5Pget_fapl_core: backingstore="+backingstore[0], !backingstore[0]);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fapl_core: " + err);
+ }
+ }
+
+ @Test
+ public void testH5P_fapl_family() {
+ if (HDF5Constants.H5FD_FAMILY < 0)
+ return;
+ try {
+ H5.H5Pset_fapl_family(fapl_id, 1024, HDF5Constants.H5P_DEFAULT);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: family = "+ driver_type, HDF5Constants.H5FD_FAMILY==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_family: " + err);
+ }
+ try {
+ long[] member_size = {0};
+ long[] member_fapl = {-1};
+ H5.H5Pget_fapl_family(fapl_id, member_size, member_fapl);
+ assertTrue("H5Pget_fapl_family: member_size="+member_size[0], member_size[0]==1024);
+ assertTrue("H5Pget_fapl_family: member_fapl ", H5.H5P_equal(member_fapl[0], HDF5Constants.H5P_FILE_ACCESS_DEFAULT));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fapl_family: " + err);
+ }
+ _createH5familyFile(fapl_id);
+ deleteH5familyfile();
+ }
+
+ @Test
+ public void testH5P_family_offset() {
+ if (HDF5Constants.H5FD_FAMILY < 0)
+ return;
+ try {
+ H5.H5Pset_fapl_family(fapl_id, 1024, HDF5Constants.H5P_DEFAULT);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: family = "+ driver_type, HDF5Constants.H5FD_FAMILY==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_family: " + err);
+ }
+ _createH5familyFile(fapl_id);
+ long family_offset = 512;
+ try {
+ H5.H5Pset_family_offset(fapl_id, family_offset);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fapl_family: " + err);
+ }
+ try {
+ long offset = H5.H5Pget_family_offset(fapl_id);
+ assertTrue("H5Pget_fapl_family: offset="+offset, offset==family_offset);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fapl_family: " + err);
+ }
+ deleteH5familyfile();
+ }
+
+ @Test
+ public void testH5Pset_fapl_sec2() {
+ if (HDF5Constants.H5FD_SEC2 < 0)
+ return;
+ try {
+ H5.H5Pset_fapl_sec2(fapl_id);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: sec2 = "+ driver_type, HDF5Constants.H5FD_SEC2==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_sec2: " + err);
+ }
+ _createH5File(fapl_id);
+ deleteH5file();
+ }
+
+ @Test
+ public void testH5Pset_fapl_stdio() {
+ if (HDF5Constants.H5FD_STDIO < 0)
+ return;
+ try {
+ H5.H5Pset_fapl_stdio(fapl_id);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: stdio = "+ driver_type, HDF5Constants.H5FD_STDIO==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_stdio: " + err);
+ }
+ _createH5File(fapl_id);
+ deleteH5file();
+ }
+
+ @Test
+ public void testH5Pset_fapl_log() {
+ if (HDF5Constants.H5FD_LOG < 0)
+ return;
+ try {
+ long log_flags = HDF5Constants.H5FD_LOG_LOC_IO;
+ H5.H5Pset_fapl_log(fapl_id, H5_LOG_FILE, log_flags, 1024);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: log = "+ driver_type, HDF5Constants.H5FD_LOG==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_log: " + err);
+ }
+ _createH5File(fapl_id);
+ deleteH5file();
+ _deleteLogFile();
+ }
+
+ @Test
+ public void testH5P_fapl_muti_nulls() {
+ if (HDF5Constants.H5FD_MULTI < 0)
+ return;
+
+ int[] member_map = null;
+ long[] member_fapl = null;
+ String[] member_name = null;
+ long[] member_addr = null;
+
+ try {
+ H5.H5Pset_fapl_multi(fapl_id, member_map, member_fapl, member_name, member_addr, true);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: muti = "+ driver_type, HDF5Constants.H5FD_MULTI==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_muti: " + err);
+ }
+ try {
+ boolean relax = H5.H5Pget_fapl_multi(fapl_id, member_map, member_fapl, member_name, member_addr);
+ assertTrue("H5Pget_fapl_muti: relax ", relax);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fapl_muti: " + err);
+ }
+ _createH5multiFile(fapl_id);
+ deleteH5multifile();
+ }
+
+ @Test
+ public void testH5P_fapl_muti_defaults() {
+ if (HDF5Constants.H5FD_MULTI < 0)
+ return;
+ int H5FD_MEM_NTYPES = HDF5Constants.H5FD_MEM_NTYPES; // 7
+
+ long sH5FD_MEM_DEFAULT_HADDR = HDF5Constants.H5FD_DEFAULT_HADDR_SIZE;
+ long sH5FD_MEM_HADDR = HDF5Constants.H5FD_MEM_DEFAULT_SIZE;
+ long sH5FD_MEM_SUPER_HADDR = HDF5Constants.H5FD_MEM_DEFAULT_SUPER_SIZE;
+ long sH5FD_MEM_BTREE_HADDR = HDF5Constants.H5FD_MEM_DEFAULT_BTREE_SIZE;
+ long sH5FD_MEM_DRAW_HADDR = HDF5Constants.H5FD_MEM_DEFAULT_DRAW_SIZE;
+ long sH5FD_MEM_GHEAP_HADDR = HDF5Constants.H5FD_MEM_DEFAULT_GHEAP_SIZE;
+ long sH5FD_MEM_LHEAP_HADDR = HDF5Constants.H5FD_MEM_DEFAULT_LHEAP_SIZE;
+ long sH5FD_MEM_OHDR_HADDR = HDF5Constants.H5FD_MEM_DEFAULT_OHDR_SIZE;
+ int[] member_map = null;
+ long[] member_fapl = null;
+ String[] member_name = null;
+ long[] member_addr = null;
+
+ try {
+ H5.H5Pset_fapl_multi(fapl_id, member_map, member_fapl, member_name, member_addr, true);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: muti = "+ driver_type, HDF5Constants.H5FD_MULTI==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_muti: " + err);
+ }
+ try {
+ member_map = new int[HDF5Constants.H5FD_MEM_NTYPES];
+ member_fapl = new long[HDF5Constants.H5FD_MEM_NTYPES];
+ member_name = new String[HDF5Constants.H5FD_MEM_NTYPES];
+ member_addr = new long[HDF5Constants.H5FD_MEM_NTYPES];
+ boolean relax = H5.H5Pget_fapl_multi(fapl_id, member_map, member_fapl, member_name, member_addr);
+ assertTrue("H5Pget_fapl_muti: relax ", relax);
+ assertTrue("H5Pget_fapl_muti: member_map="+member_map[HDF5Constants.H5FD_MEM_DEFAULT], member_map[HDF5Constants.H5FD_MEM_DEFAULT] == HDF5Constants.H5FD_MEM_DEFAULT);
+ assertTrue("H5Pget_fapl_muti: member_fapl ", H5.H5P_equal(member_fapl[HDF5Constants.H5FD_MEM_DEFAULT], HDF5Constants.H5P_FILE_ACCESS_DEFAULT));
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_DEFAULT], member_name[HDF5Constants.H5FD_MEM_DEFAULT].compareTo("%s-X.h5")==0);
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_SUPER], member_name[HDF5Constants.H5FD_MEM_SUPER].compareTo("%s-s.h5")==0);
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_BTREE], member_name[HDF5Constants.H5FD_MEM_BTREE].compareTo("%s-b.h5")==0);
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_DRAW], member_name[HDF5Constants.H5FD_MEM_DRAW].compareTo("%s-r.h5")==0);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_DEFAULT], member_addr[HDF5Constants.H5FD_MEM_DEFAULT] == sH5FD_MEM_HADDR);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_SUPER], member_addr[HDF5Constants.H5FD_MEM_SUPER] == sH5FD_MEM_SUPER_HADDR);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_BTREE], member_addr[HDF5Constants.H5FD_MEM_BTREE] == sH5FD_MEM_BTREE_HADDR);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_DRAW], member_addr[HDF5Constants.H5FD_MEM_DRAW] == sH5FD_MEM_DRAW_HADDR);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_GHEAP], member_addr[HDF5Constants.H5FD_MEM_GHEAP] == sH5FD_MEM_GHEAP_HADDR);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_LHEAP], member_addr[HDF5Constants.H5FD_MEM_LHEAP] == sH5FD_MEM_LHEAP_HADDR);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_OHDR], member_addr[HDF5Constants.H5FD_MEM_OHDR] == sH5FD_MEM_OHDR_HADDR);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fapl_muti: " + err);
+ }
+ _createH5multiFile(fapl_id);
+ _createH5multiFileDS();
+ deleteH5multifile();
+ }
+
+ @Test
+ public void testH5P_fapl_muti() {
+ if (HDF5Constants.H5FD_MULTI < 0)
+ return;
+ long HADDR_DEFAULT_SIZE = HDF5Constants.H5FD_DEFAULT_HADDR_SIZE;
+ int[] member_map = new int[HDF5Constants.H5FD_MEM_NTYPES];
+ long[] member_fapl = new long[HDF5Constants.H5FD_MEM_NTYPES];
+ String[] member_name = new String[HDF5Constants.H5FD_MEM_NTYPES];
+ long[] member_addr = new long[HDF5Constants.H5FD_MEM_NTYPES];
+
+ for(int mt=HDF5Constants.H5FD_MEM_DEFAULT; mt<HDF5Constants.H5FD_MEM_NTYPES; mt++) {
+ member_fapl[mt] = HDF5Constants.H5P_DEFAULT;
+ member_map[mt] = HDF5Constants.H5FD_MEM_SUPER;
+ }
+ member_map[HDF5Constants.H5FD_MEM_DRAW] = HDF5Constants.H5FD_MEM_DRAW;
+ member_map[HDF5Constants.H5FD_MEM_BTREE] = HDF5Constants.H5FD_MEM_BTREE;
+ member_map[HDF5Constants.H5FD_MEM_GHEAP] = HDF5Constants.H5FD_MEM_GHEAP;
+
+ member_name[HDF5Constants.H5FD_MEM_SUPER] = new String("%s-super.h5");
+ member_addr[HDF5Constants.H5FD_MEM_SUPER] = 0;
+
+ member_name[HDF5Constants.H5FD_MEM_BTREE] = new String("%s-btree.h5");
+ member_addr[HDF5Constants.H5FD_MEM_BTREE] = HADDR_DEFAULT_SIZE/4;
+
+ member_name[HDF5Constants.H5FD_MEM_DRAW] = new String("%s-draw.h5");
+ member_addr[HDF5Constants.H5FD_MEM_DRAW] = HADDR_DEFAULT_SIZE/2;
+
+ member_name[HDF5Constants.H5FD_MEM_GHEAP] = new String("%s-gheap.h5");
+ member_addr[HDF5Constants.H5FD_MEM_GHEAP] = (HADDR_DEFAULT_SIZE/4)*3;
+
+ try {
+ H5.H5Pset_fapl_multi(fapl_id, member_map, member_fapl, member_name, member_addr, true);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: muti = "+ driver_type, HDF5Constants.H5FD_MULTI==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_muti: " + err);
+ }
+ try {
+ boolean relax = H5.H5Pget_fapl_multi(fapl_id, member_map, member_fapl, member_name, member_addr);
+ assertTrue("H5Pget_fapl_muti: relax ", relax);
+ assertTrue("H5Pget_fapl_muti: member_map="+member_map[HDF5Constants.H5FD_MEM_DEFAULT], member_map[HDF5Constants.H5FD_MEM_DEFAULT] == HDF5Constants.H5FD_MEM_SUPER);
+ assertTrue("H5Pget_fapl_muti: member_map="+member_map[HDF5Constants.H5FD_MEM_DRAW], member_map[HDF5Constants.H5FD_MEM_DRAW] == HDF5Constants.H5FD_MEM_DRAW);
+ assertTrue("H5Pget_fapl_muti: member_map="+member_map[HDF5Constants.H5FD_MEM_BTREE], member_map[HDF5Constants.H5FD_MEM_BTREE] == HDF5Constants.H5FD_MEM_BTREE);
+ assertTrue("H5Pget_fapl_muti: member_map="+member_map[HDF5Constants.H5FD_MEM_GHEAP], member_map[HDF5Constants.H5FD_MEM_GHEAP] == HDF5Constants.H5FD_MEM_GHEAP);
+
+ assertTrue("H5Pget_fapl_muti: member_fapl ", H5.H5P_equal(member_fapl[HDF5Constants.H5FD_MEM_DEFAULT], HDF5Constants.H5P_FILE_ACCESS_DEFAULT));
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_DEFAULT], member_addr[HDF5Constants.H5FD_MEM_DEFAULT] == 0);
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_SUPER], member_name[HDF5Constants.H5FD_MEM_SUPER].compareTo("%s-super.h5")==0);
+
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_BTREE], member_name[HDF5Constants.H5FD_MEM_BTREE].compareTo("%s-btree.h5")==0);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_BTREE], member_addr[HDF5Constants.H5FD_MEM_BTREE] == HADDR_DEFAULT_SIZE/4);
+
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_DRAW], member_name[HDF5Constants.H5FD_MEM_DRAW].compareTo("%s-draw.h5")==0);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_DRAW], member_addr[HDF5Constants.H5FD_MEM_DRAW] == HADDR_DEFAULT_SIZE/2);
+
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_GHEAP], member_name[HDF5Constants.H5FD_MEM_GHEAP].compareTo("%s-gheap.h5")==0);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_GHEAP], member_addr[HDF5Constants.H5FD_MEM_GHEAP] == (HADDR_DEFAULT_SIZE/4)*3);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fapl_muti: " + err);
+ }
+ _createH5multiFile(fapl_id);
+ try {
+ long file_size = H5.H5Fget_filesize(H5fid);
+ assertTrue("H5Pget_fapl_muti: file_size ", file_size >= HADDR_DEFAULT_SIZE/4 || file_size <= HADDR_DEFAULT_SIZE/2);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_muti:H5Fget_filesize " + err);
+ }
+ _createH5multiFileDS();
+ deleteH5multifile();
+ File file = new File(H5_MULTI_FILE+"-super.h5");
+ if (file.exists()) {
+ try {
+ file.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+ file = new File(H5_MULTI_FILE+"-btree.h5");
+ if (file.exists()) {
+ try {
+ file.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+ file = new File(H5_MULTI_FILE+"-draw.h5");
+ if (file.exists()) {
+ try {
+ file.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+ file = new File(H5_MULTI_FILE+"-gheap.h5");
+ if (file.exists()) {
+ try {
+ file.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+ }
+
+ @Test
+ public void testH5P_fapl_split() {
+ if (HDF5Constants.H5FD_MULTI < 0)
+ return;
+
+ try {
+ H5.H5Pset_fapl_split(fapl_id, "-meta.h5", HDF5Constants.H5P_DEFAULT, "-raw.h5", HDF5Constants.H5P_DEFAULT);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: split = "+ driver_type, HDF5Constants.H5FD_MULTI==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_split: " + err);
+ }
+ try {
+ int[] member_map = new int[HDF5Constants.H5FD_MEM_NTYPES];
+ long[] member_fapl = new long[HDF5Constants.H5FD_MEM_NTYPES];
+ String[] member_name = new String[HDF5Constants.H5FD_MEM_NTYPES];
+ long[] member_addr = new long[HDF5Constants.H5FD_MEM_NTYPES];
+ boolean relax = H5.H5Pget_fapl_multi(fapl_id, member_map, member_fapl, member_name, member_addr);
+ assertTrue("H5Pget_fapl_multi: relax ", relax);
+ assertTrue("H5Pget_fapl_multi: member_name="+member_name[HDF5Constants.H5FD_MEM_SUPER], member_name[HDF5Constants.H5FD_MEM_SUPER].compareTo("%s-meta.h5")==0);
+ assertTrue("H5Pget_fapl_multi: member_name="+member_name[HDF5Constants.H5FD_MEM_DRAW], member_name[HDF5Constants.H5FD_MEM_DRAW].compareTo("%s-raw.h5")==0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fapl_split: " + err);
+ }
+ _createH5multiFile(fapl_id);
+ deleteH5multifile();
+ File file = new File(H5_MULTI_FILE+"-meta.h5");
+ if (file.exists()) {
+ try {
+ file.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+ file = new File(H5_MULTI_FILE+"-raw.h5");
+ if (file.exists()) {
+ try {
+ file.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+ }
+
+ @Test
+ public void testH5P_fapl_direct() {
+ if (HDF5Constants.H5FD_DIRECT < 0)
+ return;
+ try {
+ H5.H5Pset_fapl_direct(fapl_id, 1024, 4096, 8*4096);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: direct = "+ driver_type, HDF5Constants.H5FD_DIRECT==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_direct: " + err);
+ }
+ try {
+ long[] params = {-1, -1, -1};
+ H5.H5Pget_fapl_direct(fapl_id, params);
+ assertTrue("H5Pget_fapl_direct: alignment="+params[0], params[0]==1024);
+ assertTrue("H5Pget_fapl_direct: block_size="+params[1], params[1]==4096);
+ assertTrue("H5Pget_fapl_direct: cbuf_size="+params[2], params[2]==8*4096);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fapl_direct: " + err);
+ }
+ _createH5File(fapl_id);
+ deleteH5file();
+ }
+
+ @Test
+ public void testH5Pset_fapl_windows() {
+ if (HDF5Constants.H5FD_WINDOWS < 0)
+ return;
+ try {
+ H5.H5Pset_fapl_windows(fapl_id);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: windows = "+ driver_type, HDF5Constants.H5FD_WINDOWS==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_windows: " + err);
+ }
+ _createH5File(fapl_id);
+ deleteH5file();
+ }
+
+ @Test
+ public void testH5Pmulti_transform() {
+ if (HDF5Constants.H5FD_MULTI < 0)
+ return;
+ String f_to_c = "(5/9.0)*(x-32)";
+ double windchillFread[][] = new double[DIMF_X][DIMF_Y];
+ double windchillC;
+ NumberFormat formatter = new DecimalFormat("#0.000");
+ long HADDRMAX = HDF5Constants.H5FD_DEFAULT_HADDR_SIZE;
+
+ int[] member_map = new int[HDF5Constants.H5FD_MEM_NTYPES];
+ long[] member_fapl = new long[HDF5Constants.H5FD_MEM_NTYPES];
+ String[] member_name = new String[HDF5Constants.H5FD_MEM_NTYPES];
+ long[] member_addr = new long[HDF5Constants.H5FD_MEM_NTYPES];
+
+ try {
+ H5.H5Pset_data_transform(plist_id, f_to_c);
+ H5.H5Pset_btree_ratios(btplist_id, 0.1, 0.5, 0.7);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pdata_transform: " + err);
+ }
+
+ for(int mt=HDF5Constants.H5FD_MEM_DEFAULT; mt<HDF5Constants.H5FD_MEM_NTYPES; mt++) {
+ member_fapl[mt] = HDF5Constants.H5P_DEFAULT;
+ member_map[mt] = HDF5Constants.H5FD_MEM_SUPER;
+ }
+ member_map[HDF5Constants.H5FD_MEM_DRAW] = HDF5Constants.H5FD_MEM_DRAW;
+ member_map[HDF5Constants.H5FD_MEM_BTREE] = HDF5Constants.H5FD_MEM_BTREE;
+ member_map[HDF5Constants.H5FD_MEM_GHEAP] = HDF5Constants.H5FD_MEM_GHEAP;
+
+ member_name[HDF5Constants.H5FD_MEM_SUPER] = new String("%s-super.h5");
+ member_addr[HDF5Constants.H5FD_MEM_SUPER] = 0;
+
+ member_name[HDF5Constants.H5FD_MEM_BTREE] = new String("%s-btree.h5");
+ member_addr[HDF5Constants.H5FD_MEM_BTREE] = HADDRMAX/4;
+
+ member_name[HDF5Constants.H5FD_MEM_DRAW] = new String("%s-draw.h5");
+ member_addr[HDF5Constants.H5FD_MEM_DRAW] = HADDRMAX/2;
+
+ member_name[HDF5Constants.H5FD_MEM_GHEAP] = new String("%s-gheap.h5");
+ member_addr[HDF5Constants.H5FD_MEM_GHEAP] = (HADDRMAX/4)*3;
+
+ try {
+ H5.H5Pset_fapl_multi(fapl_id, member_map, member_fapl, member_name, member_addr, true);
+ long driver_type = H5.H5Pget_driver(fapl_id);
+ assertTrue("H5Pget_driver: muti = "+ driver_type, HDF5Constants.H5FD_MULTI==driver_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pset_fapl_muti: " + err);
+ }
+ try {
+ boolean relax = H5.H5Pget_fapl_multi(fapl_id, member_map, member_fapl, member_name, member_addr);
+ assertTrue("H5Pget_fapl_muti: relax ", relax);
+ assertTrue("H5Pget_fapl_muti: member_map="+member_map[HDF5Constants.H5FD_MEM_DEFAULT], member_map[HDF5Constants.H5FD_MEM_DEFAULT] == HDF5Constants.H5FD_MEM_SUPER);
+ assertTrue("H5Pget_fapl_muti: member_map="+member_map[HDF5Constants.H5FD_MEM_DRAW], member_map[HDF5Constants.H5FD_MEM_DRAW] == HDF5Constants.H5FD_MEM_DRAW);
+ assertTrue("H5Pget_fapl_muti: member_map="+member_map[HDF5Constants.H5FD_MEM_BTREE], member_map[HDF5Constants.H5FD_MEM_BTREE] == HDF5Constants.H5FD_MEM_BTREE);
+ assertTrue("H5Pget_fapl_muti: member_map="+member_map[HDF5Constants.H5FD_MEM_GHEAP], member_map[HDF5Constants.H5FD_MEM_GHEAP] == HDF5Constants.H5FD_MEM_GHEAP);
+
+ assertTrue("H5Pget_fapl_muti: member_fapl ", H5.H5P_equal(member_fapl[HDF5Constants.H5FD_MEM_DEFAULT], HDF5Constants.H5P_FILE_ACCESS_DEFAULT));
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_DEFAULT], member_addr[HDF5Constants.H5FD_MEM_DEFAULT] == 0);
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_SUPER], member_name[HDF5Constants.H5FD_MEM_SUPER].compareTo("%s-super.h5")==0);
+
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_BTREE], member_name[HDF5Constants.H5FD_MEM_BTREE].compareTo("%s-btree.h5")==0);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_BTREE], member_addr[HDF5Constants.H5FD_MEM_BTREE] == HADDRMAX/4);
+
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_DRAW], member_name[HDF5Constants.H5FD_MEM_DRAW].compareTo("%s-draw.h5")==0);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_DRAW], member_addr[HDF5Constants.H5FD_MEM_DRAW] == HADDRMAX/2);
+
+ assertTrue("H5Pget_fapl_muti: member_name="+member_name[HDF5Constants.H5FD_MEM_GHEAP], member_name[HDF5Constants.H5FD_MEM_GHEAP].compareTo("%s-gheap.h5")==0);
+ assertTrue("H5Pget_fapl_muti: member_addr="+member_addr[HDF5Constants.H5FD_MEM_GHEAP], member_addr[HDF5Constants.H5FD_MEM_GHEAP] == (HADDRMAX/4)*3);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pget_fapl_muti: " + err);
+ }
+ try {
+ _createH5multiFile(fapl_id);
+ long file_size = H5.H5Fget_filesize(H5fid);
+ assertTrue("H5Pget_fapl_muti: file_size ", file_size >= HADDRMAX/4 || file_size <= HADDRMAX/2);
+ _createH5multiFileDS();
+ _createFloatDataset();
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pdata_transform: " + err);
+ }
+ try {
+ H5.H5Dwrite(H5Fdid, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ plist_id, windchillF);
+ H5.H5Dread(H5Fdid, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5P_DEFAULT, windchillFread);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5Pdata_transform: " + err);
+ }
+ for(int row = 0; row < DIMF_X; row++) {
+ for(int col = 0; col < DIMF_Y; col++) {
+ windchillC = (5/9.0)*(windchillF[row][col]-32);
+ String Cstr = formatter.format(windchillC);
+ String Fread = formatter.format(windchillFread[row][col]);
+ assertTrue("H5Pdata_transform: <"+row+","+col+">"+Fread+"="+Cstr, Fread.compareTo(Cstr)==0);
+ }
+ }
+ deleteH5multifile();
+ File file = new File(H5_MULTI_FILE+"-super.h5");
+ if (file.exists()) {
+ try {
+ file.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+ file = new File(H5_MULTI_FILE+"-btree.h5");
+ if (file.exists()) {
+ try {
+ file.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+ file = new File(H5_MULTI_FILE+"-draw.h5");
+ if (file.exists()) {
+ try {
+ file.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+ file = new File(H5_MULTI_FILE+"-gheap.h5");
+ if (file.exists()) {
+ try {
+ file.delete();
+ }
+ catch (SecurityException e) {
+ ;// e.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/java/test/TestH5R.java b/java/test/TestH5R.java
new file mode 100644
index 0000000..72e0bfb
--- /dev/null
+++ b/java/test/TestH5R.java
@@ -0,0 +1,335 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertNotNull;
+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.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5R {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "testH5R.h5";
+ private static final int DIM_X = 4;
+ private static final int DIM_Y = 6;
+ long H5fid = -1;
+ long H5dsid = -1;
+ long H5did = -1;
+ long H5gid = -1;
+ long H5did2 = -1;
+ long[] H5dims = { DIM_X, DIM_Y };
+
+ private final void _deleteFile(String filename) {
+ File file = null;
+ try {
+ file = new File(filename);
+ }
+ catch (Throwable err) {}
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ }
+
+ private final long _createDataset(long fid, long dsid, String name, long dapl) {
+ long did = -1;
+ 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("TestH5R._createDataset: ",did > 0);
+
+ return did;
+ }
+
+ private final long _createGroup(long fid, String name) {
+ long gid = -1;
+ try {
+ gid = H5.H5Gcreate(fid, name, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Gcreate: " + err);
+ }
+ assertTrue("TestH5R._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(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5dsid = H5.H5Screate_simple(2, H5dims, null);
+ H5gid = _createGroup(H5fid, "Group1");
+ H5did2 = _createDataset(H5gid, H5dsid, "dset2", HDF5Constants.H5P_DEFAULT);
+ H5did = _createDataset(H5fid, H5dsid, "dset", HDF5Constants.H5P_DEFAULT);
+
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5R.createH5file: " + err);
+ }
+ assertTrue("TestH5R.createH5file: H5.H5Fcreate: ",H5fid > 0);
+ assertTrue("TestH5R.createH5file: H5.H5Screate_simple: ",H5dsid > 0);
+ assertTrue("TestH5R.createH5file: _createDataset: ",H5did > 0);
+
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5dsid > 0)
+ try {H5.H5Sclose(H5dsid);} catch (Exception ex) {}
+ if (H5did > 0)
+ try {H5.H5Dclose(H5did);} catch (Exception ex) {}
+ if (H5fid > 0)
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+ if (H5gid > 0)
+ try {H5.H5Gclose(H5gid);} catch (Exception ex) {}
+ if (H5did2 > 0)
+ try {H5.H5Dclose(H5did2);} catch (Exception ex) {}
+
+ _deleteFile(H5_FILE);
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Rget_name() {
+ long loc_id=H5fid;
+ int ref_type=HDF5Constants.H5R_OBJECT;
+ long ret_val=-1;
+ byte[] ref=null;
+ String[] name= {""};
+ String objName = "/dset";
+
+ try {
+ ref = H5.H5Rcreate(H5fid, objName, ref_type, -1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Rget_name:H5Rcreate " + err);
+ }
+
+ try {
+ ret_val = H5.H5Rget_name(loc_id, ref_type, ref, name, 16);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Rget_name: " + err);
+ }
+
+ assertTrue("testH5Rget_name: H5Rget_name", ret_val>0);
+ assertTrue("The name of the object: ", objName.equals(name[0]));
+ }
+
+ @Test
+ public void testH5Rget_obj_type2() {
+ int ref_type=HDF5Constants.H5R_OBJECT;
+ byte[] ref=null;
+
+ String objName = "/dset";
+ int obj_type = -1;;
+
+ try {
+ ref = H5.H5Rcreate(H5fid, objName, ref_type, -1);
+ }
+ catch(Throwable err) {
+ err.printStackTrace();
+ }
+
+ try {
+ obj_type = H5.H5Rget_obj_type(H5fid, HDF5Constants.H5R_OBJECT, ref);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Rget_obj_type2: " + err);
+ }
+ assertEquals(obj_type, HDF5Constants.H5O_TYPE_DATASET);
+ }
+
+ @Test
+ public void testH5Rcreate_refobj() {
+ byte[] ref = null;
+
+ try {
+ ref = H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_OBJECT, -1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Rcreate: " + err);
+ }
+ assertNotNull(ref);
+ }
+
+ @Test
+ public void testH5Rcreate_regionrefobj() {
+ byte[] ref = null;
+ try {
+ ref = H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_DATASET_REGION, H5dsid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Rcreate: " + err);
+ }
+ assertNotNull(ref);
+ }
+
+ @Test
+ public void testH5Rdereference() {
+ byte[] ref1 = null;
+ byte[] ref2 = null;
+ long dataset_id = -1;
+ long group_id = -1;
+ try {
+ //Create reference on dataset
+ ref1 = H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_DATASET_REGION, H5dsid);
+ dataset_id= H5.H5Rdereference(H5fid, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_DATASET_REGION, ref1);
+
+ //Create reference on group
+ ref2 = H5.H5Rcreate(H5gid, "/Group1", HDF5Constants.H5R_OBJECT, -1);
+ group_id= H5.H5Rdereference(H5gid, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, ref2);
+ assertNotNull(ref1);
+ assertNotNull(ref2);
+ assertTrue(dataset_id>=0);
+ assertTrue(group_id>=0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5Rdereference " + err);
+ }
+ finally {
+ try {H5.H5Dclose(dataset_id);} catch (Exception ex) {}
+ try {H5.H5Gclose(group_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Rget_region() {
+ byte[] ref = null;
+ long dsid = -1;
+ try {
+ ref = H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_DATASET_REGION, H5dsid);
+ dsid = H5.H5Rget_region(H5fid, HDF5Constants.H5R_DATASET_REGION, ref);
+ assertNotNull(ref);
+ assertTrue(dsid>=0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("TestH5Rget_region: " + err);
+ }
+ finally {
+ try {H5.H5Sclose(dsid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Rget_name_Invalidreftype() throws Throwable {
+ byte[] ref = null;
+ String[] name= {""};
+ ref = H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_OBJECT, -1);
+ H5.H5Rget_name(H5fid, HDF5Constants.H5R_DATASET_REGION, ref, name, 16);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Rget_name_NULLreference() throws Throwable {
+ byte[] ref = null;
+ String[] name= {""};
+ H5.H5Rget_name(H5fid, HDF5Constants.H5R_OBJECT, ref, name, 16);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Rget_obj_type2_Invalidreftype() throws Throwable {
+ byte[] ref = null;
+ ref = H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_OBJECT, -1);
+ H5.H5Rget_obj_type(H5fid, HDF5Constants.H5R_DATASET_REGION, ref);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Rcreate_InvalidObjectName() throws Throwable {
+ H5.H5Rcreate(H5fid, "/GROUPS", HDF5Constants.H5R_OBJECT, -1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Rcreate_Invalidspace_id() throws Throwable {
+ H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_DATASET_REGION, -1);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Rcreate_Invalidreftype() throws Throwable {
+ H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_BADTYPE, -1);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Rgetregion_Invalidreftype() throws Throwable {
+ byte[] ref = null;
+ ref = H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_OBJECT, H5dsid);
+ H5.H5Rget_region(H5fid, HDF5Constants.H5R_DATASET_REGION, ref);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Rgetregion_Badreferencetype() throws Throwable {
+ byte[] ref = null;
+ ref = H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_OBJECT, H5dsid);
+ H5.H5Rget_region(H5fid, HDF5Constants.H5R_OBJECT, ref);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Rgetregion_Nullreference() throws Throwable {
+ byte[] ref = null;
+ H5.H5Rget_region(H5fid, HDF5Constants.H5R_DATASET_REGION, ref);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Rdereference_Nullreference() throws Throwable {
+ byte[] ref = null;
+ H5.H5Rdereference(H5did2, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, ref);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Rdereference_Invalidreference() throws Throwable {
+ byte[] ref1 = null;
+ byte[] ref2 = null;
+ ref1 = H5.H5Rcreate(H5fid, "/dset", HDF5Constants.H5R_DATASET_REGION, H5dsid);
+ ref2 = H5.H5Rcreate(H5gid, "/Group1", HDF5Constants.H5R_OBJECT, -1);
+ H5.H5Rdereference(H5gid, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, ref1);
+ }
+
+}
diff --git a/java/test/TestH5S.java b/java/test/TestH5S.java
new file mode 100644
index 0000000..909ab02
--- /dev/null
+++ b/java/test/TestH5S.java
@@ -0,0 +1,590 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.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;
+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 TestH5S {
+ @Rule public TestName testname = new TestName();
+ long H5sid = -1;
+ 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);
+ System.out.print(testname.getMethodName());
+
+ H5sid = H5.H5Screate_simple(H5rank, H5dims, H5maxdims);
+ assertTrue("H5.H5Screate_simple_extent", H5sid > 0);
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5sid > 0) {
+ try {H5.H5Sclose(H5sid);} catch (Exception ex) {}
+ }
+ System.out.println();
+ }
+
+ @Test
+ public void testH5Sget_simple_extent_ndims() {
+ int read_rank = -1;
+ try {
+ read_rank = H5.H5Sget_simple_extent_ndims(H5sid);
+ assertTrue("H5.H5Sget_simple_extent_ndims", H5rank == read_rank);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sget_simple_extent_ndims: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Sget_simple_extent_dims_null() {
+ int read_rank = -1;
+
+ try {
+ read_rank = H5.H5Sget_simple_extent_dims(H5sid, null, null);
+ assertTrue("H5.H5Sget_simple_extent_dims", H5rank == read_rank);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sget_simple_extent_dims: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Sget_simple_extent_dims() {
+ int read_rank = -1;
+ long dims[] = {5, 5};
+ long maxdims[] = {10, 10};
+
+ try {
+ read_rank = H5.H5Sget_simple_extent_dims(H5sid, dims, maxdims);
+ assertTrue("H5.H5Sget_simple_extent_dims", H5rank == read_rank);
+ assertTrue("H5.H5Sget_simple_extent_dims:dims", H5dims[0] == dims[0]);
+ assertTrue("H5.H5Sget_simple_extent_dims:maxdims", H5maxdims[0] == maxdims[0]);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sget_simple_extent_dims: " + err);
+ }
+ }
+
+ @Test
+ 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);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sget_simple_extent_npoints: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Sget_simple_extent_type() {
+ int read_type = -1;
+ try {
+ read_type = H5.H5Sget_simple_extent_type(H5sid);
+ assertTrue("H5.H5Sget_simple_extent_type", HDF5Constants.H5S_SIMPLE == read_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sget_simple_extent_type: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Sis_simple() {
+ boolean result = false;
+
+ try {
+ result = H5.H5Sis_simple(H5sid);
+ assertTrue("H5.H5Sis_simple", result);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sis_simple: " + err);
+ }
+ }
+
+ @Test
+ 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);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sset_extent_simple: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Sget_select_type() {
+ int read_type = -1;
+ try {
+ read_type = H5.H5Sget_select_type(H5sid);
+ assertTrue("H5.H5Sget_select_type", HDF5Constants.H5S_SEL_ALL == read_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sset_extent_none: " + err);
+ }
+ }
+
+ @Test
+ 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_NO_CLASS == read_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sset_extent_none: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Scopy() {
+ long sid = -1;
+ int read_rank = -1;
+
+ try {
+ sid = H5.H5Scopy(H5sid);
+ assertTrue("H5.H5Sis_simple", sid > 0);
+ read_rank = H5.H5Sget_simple_extent_ndims(sid);
+ assertTrue("H5.H5Screate_simple_extent_ndims", H5rank == read_rank);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Scopy: " + err);
+ }
+ finally {
+ try {H5.H5Sclose(sid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Sextent_copy() {
+ long sid = -1;
+ int class_type = -1;
+
+ try {
+ sid = H5.H5Screate(HDF5Constants.H5S_NULL);
+ assertTrue("H5.H5Screate_null", sid > 0);
+ H5.H5Sextent_copy(sid, H5sid);
+ class_type = H5.H5Sget_simple_extent_type(sid);
+ assertTrue("H5.H5Screate_null: type", class_type == HDF5Constants.H5S_SIMPLE);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sextent_copy: " + err);
+ }
+ finally {
+ try {H5.H5Sclose(sid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Sextent_equal() {
+ long sid = -1;
+ boolean result = false;
+
+ try {
+ sid = H5.H5Screate(HDF5Constants.H5S_NULL);
+ assertTrue("H5.H5Screate_null",sid > 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Screate: null " + err);
+ }
+
+ try {
+ result = H5.H5Sextent_equal(sid, H5sid);
+ assertFalse("H5.testH5Sextent_equal",result);
+ H5.H5Sextent_copy(sid, H5sid);
+ result = H5.H5Sextent_equal(sid, H5sid);
+ assertTrue("H5.testH5Sextent_equal", result);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sextent_copy " + err);
+ }
+ finally {
+ try {H5.H5Sclose(sid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Sencode_decode_null_dataspace() {
+ long sid = -1;
+ long decoded_sid = -1;
+ byte[] null_sbuf = null;
+ boolean result = false;
+
+ try {
+ sid = H5.H5Screate(HDF5Constants.H5S_NULL);
+ assertTrue("H5.H5Screate_null", sid > 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Screate: null " + err);
+ }
+
+ try {
+ null_sbuf = H5.H5Sencode(sid);
+ 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) {}
+ }
+ }
+
+ try {
+ decoded_sid = H5.H5Sdecode(null_sbuf);
+ assertTrue("H5.testH5Sdecode", decoded_sid>0);
+
+ result = H5.H5Sextent_equal(sid, decoded_sid);
+ assertTrue("H5.testH5Sextent_equal", result);
+ }
+ 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) {}
+ }
+ }
+
+ @Test
+ public void testH5Sencode_decode_scalar_dataspace() {
+ long sid = -1;
+ long decoded_sid = -1;
+ byte[] scalar_sbuf = null;
+ boolean result = false;
+ int iresult = -1;
+ long lresult = -1;
+
+ try {
+ sid = H5.H5Screate(HDF5Constants.H5S_SCALAR);
+ assertTrue("H5.H5Screate_null", sid > 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Screate: null " + err);
+ }
+
+ try {
+ scalar_sbuf = H5.H5Sencode(sid);
+ 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) {}
+ }
+ }
+
+ try {
+ decoded_sid = H5.H5Sdecode(scalar_sbuf);
+ 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);
+
+ iresult = H5.H5Sget_simple_extent_ndims(decoded_sid);
+ 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) {}
+ }
+ }
+
+ @Test
+ 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);
+ H5.H5Sselect_all(H5sid);
+ read_type = H5.H5Sget_select_type(H5sid);
+ assertTrue("H5.H5Sget_select_type: "+read_type, HDF5Constants.H5S_SEL_ALL == read_type);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sset_extent_none: " + err);
+ }
+ }
+
+ @Test
+ 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);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sget_select_npoints: " + err);
+ }
+ }
+
+ @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 */
+ try {
+ H5.H5Sselect_elements(H5sid, HDF5Constants.H5S_SELECT_SET, 3, coord);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sget_select_elem_pointlist: " + err);
+ }
+ H5.H5Sget_select_elem_pointlist(H5sid, 0, 3, getcoord);
+ }
+
+ @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 */
+ try {
+ H5.H5Sselect_elements(H5sid, HDF5Constants.H5S_SELECT_SET, 3, coord);
+ H5.H5Sget_select_elem_pointlist(H5sid, 0, 3, getcoord);
+ assertTrue("H5.H5Sget_select_elem_pointlist", coord[0][0] == getcoord[0]);
+ assertTrue("H5.H5Sget_select_elem_pointlist", coord[0][1] == getcoord[1]);
+ assertTrue("H5.H5Sget_select_elem_pointlist", coord[1][0] == getcoord[2]);
+ assertTrue("H5.H5Sget_select_elem_pointlist", coord[1][1] == getcoord[3]);
+ assertTrue("H5.H5Sget_select_elem_pointlist", coord[2][0] == getcoord[4]);
+ assertTrue("H5.H5Sget_select_elem_pointlist", coord[2][1] == getcoord[5]);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sget_select_elem_pointlist: " + err);
+ }
+ }
+
+ @Test
+ 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]);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sget_select_bounds: " + err);
+ }
+ }
+
+ @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};
+ 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]);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sget_select_bounds: " + err);
+ }
+ try {
+ 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]);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Soffset_simple: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Sget_select_hyper() {
+ long space1 = -1;
+ 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);
+ assertTrue("H5.H5Scopy", H5sid > 0);
+ // 'AND' "all" selection with another hyperslab
+ H5.H5Sselect_hyperslab(space1, HDF5Constants.H5S_SELECT_AND, start, stride, count, block);
+
+ // Verify that there is only one block
+ nblocks = H5.H5Sget_select_hyper_nblocks(space1);
+ assertTrue("H5Sget_select_hyper_nblocks", nblocks == 1);
+
+ // Retrieve the block defined
+ H5.H5Sget_select_hyper_blocklist(space1, 0, nblocks, blocks);
+
+ // 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]);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Sget_select_bounds: " + err);
+ }
+ finally {
+ try {H5.H5Sclose(space1);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Sget_select_valid() {
+ long space1 = -1;
+ 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
+ space1 = H5.H5Scopy(H5sid);
+ assertTrue("H5.H5Scopy", H5sid > 0);
+ // 'AND' "all" selection with another hyperslab
+ H5.H5Sselect_hyperslab(space1, HDF5Constants.H5S_SELECT_SET, start, stride, count, block);
+
+ // Check a valid offset
+ 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;
+ H5.H5Soffset_simple(space1, offset);
+ assertFalse("H5Sselect_valid", H5.H5Sselect_valid(space1));
+
+ /* Reset offset */
+ offset[0]=0;
+ offset[1]=0;
+ H5.H5Soffset_simple(space1, offset);
+ assertTrue("H5Sselect_valid", H5.H5Sselect_valid(space1));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Sget_select_valid: " + err);
+ }
+ finally {
+ 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];
+ boolean is_regular = false;
+
+ try {
+ // Set "regular" hyperslab selection
+ H5.H5Sselect_hyperslab(H5sid, HDF5Constants.H5S_SELECT_SET, start, stride, count, block);
+
+ // Query if 'hyperslab' selection is regular hyperslab (should be TRUE)
+ is_regular = H5.H5Sis_regular_hyperslab(H5sid);
+ assertTrue("H5.H5Sis_regular_hyperslab", is_regular);
+
+ // Retrieve the hyperslab parameters
+ H5.H5Sget_regular_hyperslab(H5sid, q_start, q_stride, q_count, q_block);
+
+ /* Verify the hyperslab parameters */
+ 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]);
+ assertTrue("H5Sget_regular_hyperslab, block", block[u] == q_block[u]);
+ } /* end for */
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Sget_select_valid: " + err);
+ }
+ }
+}
diff --git a/java/test/TestH5Sbasic.java b/java/test/TestH5Sbasic.java
new file mode 100644
index 0000000..2731a06
--- /dev/null
+++ b/java/test/TestH5Sbasic.java
@@ -0,0 +1,247 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 TestH5Sbasic {
+ @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//(expected = HDF5LibraryException.class)
+ public void testH5Sclose_invalid() throws Throwable {
+ long sid = H5.H5Sclose(-1);
+ assertTrue(sid == 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Screate_invalid() throws Throwable {
+ H5.H5Screate(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Sget_simple_extent_type_invalid() throws Throwable {
+ H5.H5Sget_simple_extent_type(-1);
+ }
+
+ @Test
+ public void testH5Screate_scalar() {
+ long sid = -1;
+ int class_type = -1;
+ try {
+ sid = H5.H5Screate(HDF5Constants.H5S_SCALAR);
+ assertTrue("H5.H5Screate_scalar",sid > 0);
+ class_type = H5.H5Sget_simple_extent_type(sid);
+ assertTrue("H5.H5Screate_scalar: type",class_type == HDF5Constants.H5S_SCALAR);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Screate: " + err);
+ }
+ finally {
+ try {H5.H5Sclose(sid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Screate_null() {
+ long sid = -1;
+ int class_type = -1;
+ try {
+ sid = H5.H5Screate(HDF5Constants.H5S_NULL);
+ assertTrue("H5.H5Screate_null", sid > 0);
+ class_type = H5.H5Sget_simple_extent_type(sid);
+ assertTrue("H5.H5Screate_null: type", class_type == HDF5Constants.H5S_NULL);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Screate: " + err);
+ }
+ finally {
+ try {H5.H5Sclose(sid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Screate_simple_dims_null() throws Throwable {
+ H5.H5Screate_simple(2, (long[])null, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Screate_simple_rank_invalid() throws Throwable {
+ long dims[] = {5, 5};
+ H5.H5Screate_simple(-1, dims, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Screate_simple_dims_invalid() throws Throwable {
+ long dims[] = {2, 2};
+ H5.H5Screate_simple(5, dims, null);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Screate_simple_dims_exceed() throws Throwable {
+ long dims[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
+ 21,22,23,24,25,26,27,28,29,30,31,32,33,35};
+ H5.H5Screate_simple(35, dims, null);
+ }
+
+//H5Screate_simple was changed to allow a dim of 0
+// @Ignore(expected = HDF5LibraryException.class)
+// public void testH5Screate_simple_dims_zero() {
+// long dims[] = {0, 0};
+// H5.H5Screate_simple(2, dims, null);
+// }
+
+ @Test
+ public void testH5Screate_simple() {
+ long sid = -1;
+ int class_type = -1;
+ int rank = 2;
+ long dims[] = {5, 5};
+ long maxdims[] = {10, 10};
+
+ try {
+ sid = H5.H5Screate_simple(rank, dims, maxdims);
+ assertTrue("H5.H5Screate_simple", sid > 0);
+ class_type = H5.H5Sget_simple_extent_type(sid);
+ assertTrue("H5.H5Screate_simple: type", class_type == HDF5Constants.H5S_SIMPLE);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Screate_simple: " + err);
+ }
+ finally {
+ try {H5.H5Sclose(sid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Screate_simple_unlimted() {
+ long sid = -1;
+ int class_type = -1;
+ int rank = 2;
+ long dims[] = {5, 5};
+ long maxdims[] = {HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED};
+
+ try {
+ sid = H5.H5Screate_simple(rank, dims, maxdims);
+ assertTrue("H5.H5Screate_simple", sid > 0);
+ class_type = H5.H5Sget_simple_extent_type(sid);
+ assertTrue("H5.H5Screate_simple: type", class_type == HDF5Constants.H5S_SIMPLE);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Screate_simple: " + err);
+ }
+ finally {
+ try {H5.H5Sclose(sid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Screate_simple_unlimted_1d() {
+ long sid = -1;
+ int class_type = -1;
+ int rank = 1;
+ long dims[] = {5};
+ long maxdims[] = {HDF5Constants.H5S_UNLIMITED};
+
+ try {
+ sid = H5.H5Screate_simple(rank, dims, maxdims);
+ assertTrue("H5.H5Screate_simple", sid > 0);
+ class_type = H5.H5Sget_simple_extent_type(sid);
+ assertTrue("H5.H5Screate_simple: type", class_type == HDF5Constants.H5S_SIMPLE);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Screate_simple: " + err);
+ }
+ finally {
+ try {H5.H5Sclose(sid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Screate_simple_max_default() {
+ long sid = -1;
+ int rank = 2;
+ long dims[] = {5, 5};
+
+ try {
+ sid = H5.H5Screate_simple(rank, dims, null);
+ assertTrue("H5.H5Screate_simple_max_default", sid > 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Screate_simple: " + err);
+ }
+ finally {
+ try {H5.H5Sclose(sid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Screate_simple_extent() {
+ long sid = -1;
+ int rank = 2;
+ long dims[] = {5, 5};
+ long maxdims[] = {10, 10};
+
+ try {
+ sid = H5.H5Screate(HDF5Constants.H5S_SIMPLE);
+ assertTrue("H5.H5Screate_simple_extent",sid > 0);
+ H5.H5Sset_extent_simple(sid, rank, dims, maxdims);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Screate: " + err);
+ }
+ finally {
+ try {H5.H5Sclose(sid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Sencode_invalid() throws Throwable {
+ H5.H5Sencode(-1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Sdecode_null() throws Throwable {
+ H5.H5Sdecode(null);
+ }
+
+}
diff --git a/java/test/TestH5T.java b/java/test/TestH5T.java
new file mode 100644
index 0000000..e03b97f
--- /dev/null
+++ b/java/test/TestH5T.java
@@ -0,0 +1,459 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.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.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5T {
+ @Rule public TestName testname = new TestName();
+ private static final String H5_FILE = "test.h5";
+ long H5fid = -1;
+ long H5strdid = -1;
+
+ private final void _deleteFile(String filename) {
+ File file = null;
+ try {
+ file = new File(filename);
+ }
+ catch (Throwable err) {}
+
+ if (file.exists()) {
+ try {file.delete();} catch (SecurityException e) {}
+ }
+ }
+
+ @Before
+ public void createH5file() throws NullPointerException, HDF5Exception {
+ assertTrue("H5 open ids is 0", H5.getOpenIDCount()==0);
+ System.out.print(testname.getMethodName());
+
+ H5fid = H5.H5Fcreate(H5_FILE, HDF5Constants.H5F_ACC_TRUNC,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ assertTrue("H5.H5Fcreate", H5fid > 0);
+ H5strdid = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
+ assertTrue("H5.H5Tcopy", H5strdid > 0);
+
+ H5.H5Fflush(H5fid, HDF5Constants.H5F_SCOPE_LOCAL);
+ }
+
+ @After
+ public void deleteH5file() throws HDF5LibraryException {
+ if (H5strdid >= 0)
+ try {H5.H5Tclose(H5strdid);} catch (Exception ex) {}
+ if (H5fid > 0)
+ try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
+
+ _deleteFile(H5_FILE);
+ System.out.println();
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tequal_type_error() throws Throwable {
+ H5.H5Tequal(HDF5Constants.H5T_INTEGER, H5strdid);
+ }
+
+ @Test
+ public void testH5Tget_class() {
+ try {
+ int result = H5.H5Tget_class(H5strdid);
+ assertTrue("H5.H5Tget_class", result > 0);
+ String class_name = H5.H5Tget_class_name(result);
+ assertTrue("H5.H5Tget_class", class_name.compareTo("H5T_STRING")==0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tget_class: " + err);
+ }
+ }
+
+ @Test
+ public void testH5Tget_size() {
+ long dt_size = -1;
+
+ try {
+ dt_size = H5.H5Tget_size(H5strdid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tget_size:H5.H5Tget_size " + err);
+ }
+ assertTrue("testH5Tget_size", dt_size > 0);
+ }
+
+ @Test
+ public void testH5Tset_size() {
+ long dt_size = 5;
+
+ try {
+ H5.H5Tset_size(H5strdid, dt_size);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tset_size:H5.H5Tset_size " + err);
+ }
+ try {
+ dt_size = H5.H5Tget_size(H5strdid);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tget_size:H5.H5Tget_size " + err);
+ }
+ assertTrue("testH5Tget_size", dt_size == 5);
+ }
+
+ @Test
+ public void testH5Tarray_create() {
+ long filetype_id = -1;
+ long[] adims = { 3, 5 };
+
+ try {
+ filetype_id = H5.H5Tarray_create(HDF5Constants.H5T_STD_I64LE, 2, adims);
+ assertTrue("testH5Tarray_create", filetype_id >= 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tarray_create.H5Tarray_create " + err);
+ }
+ finally {
+ if (filetype_id >= 0)
+ try {H5.H5Tclose(filetype_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Tget_array_ndims() {
+ long filetype_id = -1;
+ int ndims = 0;
+ long[] adims = { 3, 5 };
+
+ try {
+ filetype_id = H5.H5Tarray_create(HDF5Constants.H5T_STD_I64LE, 2, adims);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tarray_create.H5Tarray_create " + err);
+ }
+ assertTrue("testH5Tget_array_ndims:H5Tarray_create", filetype_id >= 0);
+ try {
+ ndims = H5.H5Tget_array_ndims(filetype_id);
+ assertTrue("testH5Tget_array_ndims", ndims == 2);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tget_array_ndims.H5Tget_array_ndims " + err);
+ }
+ finally {
+ if (filetype_id >= 0)
+ try {H5.H5Tclose(filetype_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Tget_array_dims() {
+ long filetype_id = -1;
+ int ndims = 0;
+ long[] adims = { 3, 5 };
+ long[] rdims = new long[2];
+
+ try {
+ filetype_id = H5.H5Tarray_create(HDF5Constants.H5T_STD_I64LE, 2, adims);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tarray_create.H5Tarray_create " + err);
+ }
+ assertTrue("testH5Tget_array_dims:H5Tarray_create", filetype_id >= 0);
+ try {
+ ndims = H5.H5Tget_array_dims(filetype_id, rdims);
+ assertTrue("testH5Tget_array_dims", ndims == 2);
+ assertTrue("testH5Tget_array_dims", adims[0] == rdims[0]);
+ assertTrue("testH5Tget_array_dims", adims[1] == rdims[1]);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tget_array_dims.H5Tget_array_dims " + err);
+ }
+ finally {
+ if (filetype_id >= 0)
+ try {H5.H5Tclose(filetype_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Tenum_functions() {
+ long filetype_id =-1;
+ String enum_type ="Enum_type";
+ byte[] enum_val = new byte[1];
+ String enum_name = null;
+
+ // Create a enumerate datatype
+ try {
+ filetype_id = H5.H5Tcreate(HDF5Constants.H5T_ENUM, (long)1);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tenum_functions:H5Tcreate " + err);
+ }
+ assertTrue("testH5Tenum_functions:H5Tcreate", filetype_id >= 0);
+ try {
+ enum_val[0]=10;
+ H5.H5Tenum_insert(filetype_id, "RED", enum_val);
+ enum_val[0]=11;
+ H5.H5Tenum_insert(filetype_id, "GREEN", enum_val);
+ enum_val[0]=12;
+ H5.H5Tenum_insert(filetype_id, "BLUE", enum_val);
+ enum_val[0]=13;
+ H5.H5Tenum_insert(filetype_id, "ORANGE", enum_val);
+ enum_val[0]=14;
+ H5.H5Tenum_insert(filetype_id, "YELLOW", enum_val);
+
+ // Query member number and member index by member name, for enumeration type.
+ assertTrue("Can't get member number", H5.H5Tget_nmembers(filetype_id) == 5);
+ assertTrue("Can't get correct index number", H5.H5Tget_member_index(filetype_id, "ORANGE") == 3);
+
+ // Commit enumeration datatype and close it */
+ H5.H5Tcommit(H5fid, enum_type, filetype_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+
+ H5.H5Tclose(filetype_id);
+
+ // Open the dataytpe for query
+ filetype_id = H5.H5Topen(H5fid, enum_type, HDF5Constants.H5P_DEFAULT);
+ assertTrue("testH5Tenum_functions:H5Tcreate", filetype_id >= 0);
+
+ // Query member number and member index by member name, for enumeration type
+ assertTrue("Can't get member number", H5.H5Tget_nmembers(filetype_id) == 5);
+ assertTrue("Can't get correct index number", H5.H5Tget_member_index(filetype_id, "ORANGE") == 3);
+
+ // Query member value by member name, for enumeration type
+ H5.H5Tenum_valueof (filetype_id, "ORANGE", enum_val);
+ assertTrue("Incorrect value for enum member", enum_val[0]==13);
+
+ // Query member value by member index, for enumeration type
+ H5.H5Tget_member_value (filetype_id, 2, enum_val);
+ assertTrue("Incorrect value for enum member", enum_val[0]==12);
+
+ // Query member name by member value, for enumeration type
+ enum_val[0] = 14;
+ enum_name = H5.H5Tenum_nameof(filetype_id, enum_val, 16);
+ assertTrue("Incorrect name for enum member", enum_name.compareTo("YELLOW")==0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tenum_functions:query " + err);
+ }
+ finally {
+ if (filetype_id >= 0)
+ try {H5.H5Tclose(filetype_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Tenum_create_functions() {
+ long filetype_id = -1;
+ byte[] enum_val = new byte[1];
+
+ // Create a enumerate datatype
+ try {
+ filetype_id = H5.H5Tenum_create(HDF5Constants.H5T_NATIVE_INT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tenum_create_functions:H5Tcreate " + err);
+ }
+ assertTrue("testH5Tenum_create_functions:H5Tcreate", filetype_id >= 0);
+ try {
+ enum_val[0]=10;
+ H5.H5Tenum_insert(filetype_id, "RED", enum_val);
+ enum_val[0]=11;
+ H5.H5Tenum_insert(filetype_id, "GREEN", enum_val);
+ enum_val[0]=12;
+ H5.H5Tenum_insert(filetype_id, "BLUE", enum_val);
+ enum_val[0]=13;
+ H5.H5Tenum_insert(filetype_id, "ORANGE", enum_val);
+ enum_val[0]=14;
+ H5.H5Tenum_insert(filetype_id, "YELLOW", enum_val);
+
+ // Query member number and member index by member name, for enumeration type.
+ assertTrue("Can't get member number", H5.H5Tget_nmembers(filetype_id) == 5);
+ assertTrue("Can't get correct index number", H5.H5Tget_member_index(filetype_id, "ORANGE") == 3);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tenum_create_functions:H5Tget_nmembers " + err);
+ }
+ finally {
+ if (filetype_id >= 0)
+ try {H5.H5Tclose(filetype_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Topaque_functions() {
+ long filetype_id = -1;
+ String opaque_name = null;
+
+ // Create a opaque datatype
+ try {
+ filetype_id = H5.H5Tcreate(HDF5Constants.H5T_OPAQUE, (long)4);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Topaque_functions:H5Tcreate " + err);
+ }
+ assertTrue("testH5Topaque_functions:H5Tcreate", filetype_id >= 0);
+
+ try {
+ H5.H5Tset_tag(filetype_id, "opaque type");
+ opaque_name = H5.H5Tget_tag(filetype_id);
+ assertTrue("Incorrect tag for opaque type", opaque_name.compareTo("opaque type")==0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Topaque_functions:H5Tset_get_tag " + err);
+ }
+ finally {
+ if (filetype_id >= 0)
+ try {H5.H5Tclose(filetype_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Tvlen_create() {
+ long filetype_id = -1;
+
+ try {
+ filetype_id = H5.H5Tvlen_create(HDF5Constants.H5T_C_S1);
+ assertTrue("testH5Tvlen_create", filetype_id >= 0);
+
+ // Check if datatype is VL type
+ int vlclass = H5.H5Tget_class(filetype_id);
+ assertTrue("testH5Tvlen_create:H5Tget_class", vlclass == HDF5Constants.H5T_VLEN);
+ assertFalse("testH5Tis_variable_str:H5Tget_class", vlclass == HDF5Constants.H5T_STRING);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tvlen_create.H5Tvlen_create " + err);
+ }
+ finally {
+ if (filetype_id >= 0)
+ try {H5.H5Tclose(filetype_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Tis_variable_str() {
+ long filetype_id = -1;
+
+ try {
+ filetype_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
+ assertTrue("testH5Tis_variable_str.H5Tcopy: ", filetype_id >= 0);
+
+ // Convert to variable-length string
+ H5.H5Tset_size(filetype_id, HDF5Constants.H5T_VARIABLE);
+
+ // Check if datatype is VL string
+ int vlclass = H5.H5Tget_class(filetype_id);
+ assertTrue("testH5Tis_variable_str:H5Tget_class", vlclass == HDF5Constants.H5T_STRING);
+ assertFalse("testH5Tvlen_create:H5Tget_class", vlclass == HDF5Constants.H5T_VLEN);
+
+ assertTrue("testH5Tis_variable_str:H5Tis_variable_str", H5.H5Tis_variable_str(filetype_id));
+
+ // Verify that the class detects as a string
+ assertTrue("testH5Tis_variable_str:H5Tdetect_class", H5.H5Tdetect_class(filetype_id, HDF5Constants.H5T_STRING));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tis_variable_str " + err);
+ }
+ finally {
+ if (filetype_id >= 0)
+ try {H5.H5Tclose(filetype_id);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Tcompound_functions() {
+ long filetype_id =-1;
+
+ // Create a compound datatype
+ try {
+ filetype_id = H5.H5Tcreate(HDF5Constants.H5T_COMPOUND, (long)16);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tcompound_functions:H5Tcreate " + err);
+ }
+ assertTrue("testH5Tcompound_functions:H5Tcreate", filetype_id >= 0);
+ try {
+ H5.H5Tinsert(filetype_id, "Lon", 0, HDF5Constants.H5T_NATIVE_DOUBLE);
+ H5.H5Tinsert(filetype_id, "Lat", 8, HDF5Constants.H5T_NATIVE_DOUBLE);
+
+ // Query member number and member index by member name, for enumeration type.
+ assertTrue("Can't get member number", H5.H5Tget_nmembers(filetype_id) == 2);
+ assertTrue("Can't get correct index number", H5.H5Tget_member_index(filetype_id, "Lat") == 1);
+
+ // We started to support this function for compound type in 1.8.6 release.
+ int order = H5.H5Tget_order(filetype_id);
+ assertFalse("Can't get order for compound type.", order == HDF5Constants.H5T_ORDER_ERROR);
+ assertTrue("Wrong order for this type.", (order == HDF5Constants.H5T_ORDER_LE) || (order == HDF5Constants.H5T_ORDER_BE));
+
+ // Make certain that the correct classes can be detected
+ assertTrue("Can't get correct class", H5.H5Tdetect_class(filetype_id, HDF5Constants.H5T_COMPOUND));
+ assertTrue("Can't get correct class", H5.H5Tdetect_class(filetype_id, HDF5Constants.H5T_FLOAT));
+ // Make certain that an incorrect class is not detected
+ assertFalse("Can get incorrect class", H5.H5Tdetect_class(filetype_id, HDF5Constants.H5T_TIME));
+
+ // Query member name by member index
+ String index_name = H5.H5Tget_member_name (filetype_id, 0);
+ assertTrue("Incorrect name for member index", index_name.compareTo("Lon")==0);
+
+ // Query member offset by member no
+ long index_offset = H5.H5Tget_member_offset (filetype_id, 1);
+ assertTrue("Incorrect offset for member no", index_offset == 8);
+
+ // Query member type by member index
+ long index_type = H5.H5Tget_member_type (filetype_id, 0);
+ assertTrue("Incorrect type for member index", H5.H5Tequal(HDF5Constants.H5T_NATIVE_DOUBLE, index_type));
+ if (index_type >= 0)
+ try {H5.H5Tclose(index_type);} catch (Exception ex) {}
+
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tcompound_functions:query " + err);
+ }
+ finally {
+ if (filetype_id >= 0)
+ try {H5.H5Tclose(filetype_id);} catch (Exception ex) {}
+ }
+ }
+
+}
diff --git a/java/test/TestH5Tbasic.java b/java/test/TestH5Tbasic.java
new file mode 100644
index 0000000..950f1c7
--- /dev/null
+++ b/java/test/TestH5Tbasic.java
@@ -0,0 +1,161 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class TestH5Tbasic {
+ @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 testH5Tcopy() {
+ long H5strdid = -1;
+ try {
+ H5strdid = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
+ assertTrue("H5.H5Tcopy",H5strdid > 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tcopy: " + err);
+ }
+ finally {
+ if (H5strdid >= 0)
+ try {H5.H5Tclose(H5strdid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Tequal() {
+ long H5strdid = -1;
+ try {
+ H5strdid = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
+ assertTrue("H5.H5Tcopy",H5strdid > 0);
+ boolean teq = H5.H5Tequal(HDF5Constants.H5T_C_S1, H5strdid);
+ assertTrue("H5.H5Tequal",teq);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tequal: " + err);
+ }
+ finally {
+ if (H5strdid >= 0)
+ try {H5.H5Tclose(H5strdid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Tequal_not() {
+ long H5strdid = -1;
+ try {
+ H5strdid = H5.H5Tcopy(HDF5Constants.H5T_STD_U64LE);
+ assertTrue("H5.H5Tcopy",H5strdid > 0);
+ boolean teq = H5.H5Tequal(HDF5Constants.H5T_IEEE_F32BE, H5strdid);
+ assertFalse("H5.H5Tequal",teq);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tequal_not: " + err);
+ }
+ finally {
+ if (H5strdid >= 0)
+ try {H5.H5Tclose(H5strdid);} catch (Exception ex) {}
+ }
+ }
+
+ @Test
+ public void testH5Tconvert() {
+ String[] strs = {"a1234","b1234"};
+ int srcLen = 5;
+ int dstLen = 10;
+ long srcId = -1;
+ long dstId = -1;
+ int dimSize = strs.length;
+ byte[] buf = new byte[dimSize*dstLen];
+
+ for (int i=0; i<dimSize; i++)
+ System.arraycopy(strs[i].getBytes(), 0, buf, i*srcLen, 5);
+
+ try {
+ srcId = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
+ H5.H5Tset_size(srcId, (long)srcLen);
+
+ dstId = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
+ H5.H5Tset_size(dstId, (long)dstLen);
+
+ H5.H5Tconvert(srcId, dstId, dimSize, buf, null, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Tconvert: " + err);
+ }
+ finally {
+ try {H5.H5Tclose(srcId);} catch (Exception ex) {}
+ try {H5.H5Tclose(dstId);} catch (Exception ex) {}
+ }
+
+ for (int i=0; i<strs.length; i++) {
+ assertTrue((new String(buf, i*dstLen, dstLen)).startsWith(strs[i]));
+ }
+ }
+
+ @Test
+ public void testH5Torder_size() {
+ long H5strdid = -1;
+ try {
+ // Fixed length string
+ H5strdid = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
+ assertTrue("H5.H5Tcopy",H5strdid > 0);
+ H5.H5Tset_size(H5strdid, (long)5);
+ assertTrue(HDF5Constants.H5T_ORDER_NONE == H5.H5Tget_order(H5strdid));
+ H5.H5Tset_order(H5strdid, HDF5Constants.H5T_ORDER_NONE);
+ assertTrue(HDF5Constants.H5T_ORDER_NONE == H5.H5Tget_order(H5strdid));
+ assertTrue(5 == H5.H5Tget_size(H5strdid));
+
+ // Variable length string
+ H5.H5Tset_size(H5strdid, HDF5Constants.H5T_VARIABLE);
+ H5.H5Tset_order(H5strdid, HDF5Constants.H5T_ORDER_BE);
+ assertTrue(HDF5Constants.H5T_ORDER_BE == H5.H5Tget_order(H5strdid));
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("testH5Torder: " + err);
+ }
+ finally {
+ if (H5strdid >= 0)
+ try {H5.H5Tclose(H5strdid);} catch (Exception ex) {}
+ }
+ }
+}
diff --git a/java/test/TestH5Tparams.java b/java/test/TestH5Tparams.java
new file mode 100644
index 0000000..15cc6af
--- /dev/null
+++ b/java/test/TestH5Tparams.java
@@ -0,0 +1,389 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 hdf.hdf5lib.H5;
+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 TestH5Tparams {
+ @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//(expected = HDF5LibraryException.class)
+ public void testH5Tclose_invalid() throws Throwable {
+ long tid = H5.H5Tclose(-1);
+ assertTrue(tid == 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tcopy_invalid() throws Throwable {
+ H5.H5Tcopy(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tequal_invalid() throws Throwable {
+ H5.H5Tequal(-1, -1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tlock_invalid() throws Throwable {
+ H5.H5Tlock(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_class_invalid() throws Throwable {
+ H5.H5Tget_class(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_size_invalid() throws Throwable {
+ H5.H5Tget_size(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_size_invalid() throws Throwable {
+ H5.H5Tset_size(-1, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_order_invalid() throws Throwable {
+ H5.H5Tget_order(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_order_invalid() throws Throwable {
+ H5.H5Tset_order(-1, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_precision_invalid() throws Throwable {
+ H5.H5Tget_precision(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_precision_long_invalid() throws Throwable {
+ H5.H5Tget_precision_long(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_precision_invalid() throws Throwable {
+ H5.H5Tset_precision(-1, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_offset_invalid() throws Throwable {
+ H5.H5Tget_offset(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_offset_invalid() throws Throwable {
+ H5.H5Tset_offset(-1, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tcreate_invalid() throws Throwable {
+ H5.H5Tcreate(-1, (long)0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Topen_null() throws Throwable {
+ H5.H5Topen(-1, null, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Topen_invalid() throws Throwable {
+ H5.H5Topen(-1, "Bogus", 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tcommit_null() throws Throwable {
+ H5.H5Tcommit(-1, null, 0, -1, -1, -1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tcommit_invalid() throws Throwable {
+ H5.H5Tcommit(-1, "Bogus", -1, -1, -1, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tget_pad_null() throws Throwable {
+ H5.H5Tget_pad(-1, null);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_pad_invalid() throws Throwable {
+ int[] pad = new int[2];
+ H5.H5Tget_pad(-1, pad);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_pad_invalid() throws Throwable {
+ H5.H5Tset_pad(-1, -1, -1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_sign_invalid() throws Throwable {
+ H5.H5Tget_sign(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_sign_invalid() throws Throwable {
+ H5.H5Tset_sign(-1, 0);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tget_fields_null() throws Throwable {
+ H5.H5Tget_fields(-1, (long[])null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Tget_fields_length_invalid() throws Throwable {
+ long[] fields = new long[2];
+ H5.H5Tget_fields(-1, fields);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_fields_invalid() throws Throwable {
+ long[] fields = new long[5];
+ H5.H5Tget_fields(-1, fields);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_fields_invalid() throws Throwable {
+ H5.H5Tset_fields(-1, -1, -1, -1, -1, -1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_ebias_invalid() throws Throwable {
+ H5.H5Tget_ebias(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_ebias_long_invalid() throws Throwable {
+ H5.H5Tget_ebias_long(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_ebias_invalid() throws Throwable {
+ H5.H5Tset_ebias(-1, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_norm_invalid() throws Throwable {
+ H5.H5Tget_norm(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_norm_invalid() throws Throwable {
+ H5.H5Tset_norm(-1, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_inpad_invalid() throws Throwable {
+ H5.H5Tget_inpad(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_inpad_invalid() throws Throwable {
+ H5.H5Tset_inpad(-1, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_cset_invalid() throws Throwable {
+ H5.H5Tget_cset(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_cset_invalid() throws Throwable {
+ H5.H5Tset_cset(-1, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_strpad_invalid() throws Throwable {
+ H5.H5Tget_strpad(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_strpad_invalid() throws Throwable {
+ H5.H5Tset_strpad(-1, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_nmembers_invalid() throws Throwable {
+ H5.H5Tget_nmembers(-1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tget_member_index_null() throws Throwable {
+ H5.H5Tget_member_index(-1, null);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_member_index_invalid() throws Throwable {
+ H5.H5Tget_member_index(-1, "Bogus");
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_member_type_invalid() throws Throwable {
+ H5.H5Tget_member_type(-1, -1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_member_class_invalid() throws Throwable {
+ H5.H5Tget_member_class(-1, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tinsert_null() throws Throwable {
+ H5.H5Tinsert(-1, null, 0, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tinsert_invalid() throws Throwable {
+ H5.H5Tinsert(-1, "Bogus", 0, 0);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tpack_invalid() throws Throwable {
+ H5.H5Tpack(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tvlen_create_invalid() throws Throwable {
+ H5.H5Tvlen_create(-1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tset_tag_null() throws Throwable {
+ H5.H5Tset_tag(-1, null);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tset_tag_invalid() throws Throwable {
+ H5.H5Tset_tag(-1, "Bogus");
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_super_invalid() throws Throwable {
+ H5.H5Tget_super(-1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tenum_create_invalid() throws Throwable {
+ H5.H5Tenum_create(-1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tenum_insert_name_null() throws Throwable {
+ H5.H5Tenum_insert(-1, null, (byte[])null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tenum_insert_null() throws Throwable {
+ H5.H5Tenum_insert(-1, "bogus", (byte[])null);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tenum_insert_invalid() throws Throwable {
+ byte[] enumtype = new byte[2];
+ H5.H5Tenum_insert(-1, "bogus", enumtype);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Tenum_nameof_invalid_size() throws Throwable {
+ H5.H5Tenum_nameof(-1, null, -1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tenum_nameof_value_null() throws Throwable {
+ H5.H5Tenum_nameof(-1, null, 1);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tenum_nameof_invalid() throws Throwable {
+ byte[] btype = new byte[2];
+ H5.H5Tenum_nameof(-1, btype, 1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tenum_valueof_name_null() throws Throwable {
+ H5.H5Tenum_valueof(-1, null, (byte[])null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tenum_valueof_null() throws Throwable {
+ H5.H5Tenum_valueof(-1, "bogus", (byte[])null);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tenum_valueof_invalid() throws Throwable {
+ byte[] btype = new byte[2];
+ H5.H5Tenum_valueof(-1, "bogus", btype);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tget_member_value_null() throws Throwable {
+ H5.H5Tget_member_value(-1, -1, (byte[])null);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_member_value_invalid() throws Throwable {
+ byte[] btype = new byte[2];
+ H5.H5Tget_member_value(-1, -1, btype);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testH5Tarray_create_invalid() throws Throwable {
+ H5.H5Tarray_create(-1, -1, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tarray_create_value_null() throws Throwable {
+ H5.H5Tarray_create(-1, 1, null);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_array_ndims_invalid() throws Throwable {
+ H5.H5Tget_array_ndims(-1);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testH5Tget_array_dims_null() throws Throwable {
+ H5.H5Tget_array_dims(-1, null);
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Tget_native_type_invalid() throws Throwable {
+ H5.H5Tget_native_type(-1);
+ }
+
+}
diff --git a/java/test/TestH5Z.java b/java/test/TestH5Z.java
new file mode 100644
index 0000000..bdf3f1d
--- /dev/null
+++ b/java/test/TestH5Z.java
@@ -0,0 +1,100 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 TestH5Z {
+ @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 testH5Zfilter_avail() {
+ try {
+ int filter_found = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_DEFLATE);
+ assertTrue("H5.H5Zfilter_avail_DEFLATE", filter_found > 0);
+ filter_found = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_FLETCHER32);
+ assertTrue("H5.H5Zfilter_avail_FLETCHER32", filter_found > 0);
+ filter_found = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_NBIT);
+ assertTrue("H5.H5Zfilter_avail_NBIT", filter_found > 0);
+ filter_found = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SCALEOFFSET);
+ assertTrue("H5.H5Zfilter_avail_SCALEOFFSET", filter_found > 0);
+ filter_found = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SHUFFLE);
+ assertTrue("H5.H5Zfilter_avail_SHUFFLE", filter_found > 0);
+// filter_found = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SZIP);
+// assertTrue("H5.H5Zfilter_avail_SZIP", filter_found > 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Zfilter_avail " + err);
+ }
+ }
+
+ @Test
+ public void testH5Zget_filter_info() {
+ try {
+ int filter_flag = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_DEFLATE);
+ assertTrue("H5.H5Zget_filter_info_DEFLATE_DECODE_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) > 0);
+ assertTrue("H5.H5Zget_filter_info_DEFLATE_ENCODE_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) > 0);
+ filter_flag = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_FLETCHER32);
+ assertTrue("H5.H5Zget_filter_info_FLETCHER32_DECODE_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) > 0);
+ assertTrue("H5.H5Zget_filter_info_FLETCHER32_ENCODE_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) > 0);
+ filter_flag = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_NBIT);
+ assertTrue("H5.H5Zget_filter_info_NBIT_DECODE_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) > 0);
+ assertTrue("H5.H5Zget_filter_info_NBIT_ENCODE_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) > 0);
+ filter_flag = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_SCALEOFFSET);
+ assertTrue("H5.H5Zget_filter_info_SCALEOFFSET_DECODE_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) > 0);
+ assertTrue("H5.H5Zget_filter_info_SCALEOFFSET_ENCODE_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) > 0);
+ filter_flag = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_SHUFFLE);
+ assertTrue("H5.H5Zget_filter_info_DECODE_SHUFFLE_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) > 0);
+ assertTrue("H5.H5Zget_filter_info_ENCODE_SHUFFLE_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) > 0);
+// filter_flag = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_SZIP);
+// assertTrue("H5.H5Zget_filter_info_DECODE_SZIP_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) > 0);
+// assertTrue("H5.H5Zget_filter_info_ENCODE_SZIP_ENABLED", (filter_flag & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) > 0);
+ }
+ catch (Throwable err) {
+ err.printStackTrace();
+ fail("H5.H5Zget_filter_info " + err);
+ }
+ }
+
+ @Test(expected = HDF5LibraryException.class)
+ public void testH5Zunregister_predefined() throws Throwable {
+ int filter_found = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SHUFFLE);
+ assertTrue("H5.H5Zfilter_avail", filter_found > 0);
+
+ H5.H5Zunregister(HDF5Constants.H5Z_FILTER_SHUFFLE);
+ }
+}
diff --git a/java/test/h5ex_g_iterate.hdf b/java/test/h5ex_g_iterate.hdf
new file mode 100644
index 0000000..e462703
--- /dev/null
+++ b/java/test/h5ex_g_iterate.hdf
Binary files differ
diff --git a/java/test/junit.sh.in b/java/test/junit.sh.in
new file mode 100644
index 0000000..6878b3b
--- /dev/null
+++ b/java/test/junit.sh.in
@@ -0,0 +1,234 @@
+#! /bin/sh
+#
+# 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.
+#
+
+top_builddir=@top_builddir@
+top_srcdir=@top_srcdir@
+srcdir=@srcdir@
+
+TESTNAME=JUnitInterface
+EXIT_SUCCESS=0
+EXIT_FAILURE=1
+
+# Set up default variable values if not supplied by the user.
+RM='rm -rf'
+CMP='cmp'
+DIFF='diff -c'
+CP='cp'
+DIRNAME='dirname'
+LS='ls'
+AWK='awk'
+
+nerrors=0
+
+# where the libs exist
+HDFLIB_HOME="$top_srcdir/java/lib"
+BLDLIBDIR="$top_builddir/java/lib"
+BLDDIR="."
+HDFTEST_HOME="$top_srcdir/java/test"
+JARFILE=jar@PACKAGE_TARNAME@-@PACKAGE_VERSION@.jar
+TESTJARFILE=jar@PACKAGE_TARNAME@test.jar
+test -d $BLDLIBDIR || mkdir -p $BLDLIBDIR
+
+######################################################################
+# library files
+# --------------------------------------------------------------------
+# All the library files copy from source directory to test directory
+# NOTE: Keep this framework to add/remove test files.
+# This list are also used for checking exist.
+# Comment '#' without space can be used.
+# --------------------------------------------------------------------
+LIST_LIBRARY_FILES="
+$HDFLIB_HOME/hamcrest-core.jar
+$HDFLIB_HOME/junit.jar
+$HDFLIB_HOME/slf4j-api-1.7.5.jar
+$HDFLIB_HOME/ext/slf4j-simple-1.7.5.jar
+$top_builddir/src/.libs/libhdf5.*
+$top_builddir/java/src/jni/.libs/libhdf5_java.*
+$top_builddir/java/src/$JARFILE
+"
+LIST_DATA_FILES="
+$HDFTEST_HOME/h5ex_g_iterate.hdf
+"
+
+#
+# copy files from source dirs to test dir
+#
+COPY_LIBFILES="$LIST_LIBRARY_FILES"
+
+COPY_LIBFILES_TO_BLDLIBDIR()
+{
+ # copy test files. Used -f to make sure get a new copy
+ for tstfile in $COPY_LIBFILES
+ do
+ # ignore '#' comment
+ echo $tstfile | tr -d ' ' | grep '^#' > /dev/null
+ RET=$?
+ if [ $RET -eq 1 ]; then
+ # skip cp if srcdir is same as destdir
+ # this occurs when build/test performed in source dir and
+ # make cp fail
+ SDIR=`$DIRNAME $tstfile`
+ INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
+ INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
+ if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
+ $CP -f $tstfile $BLDLIBDIR
+ if [ $? -ne 0 ]; then
+ echo "Error: FAILED to copy $tstfile ."
+
+ # Comment out this to CREATE expected file
+ exit $EXIT_FAILURE
+ fi
+ fi
+ fi
+ done
+}
+
+CLEAN_LIBFILES_AND_BLDLIBDIR()
+{
+ # skip rm if srcdir is same as destdir
+ # this occurs when build/test performed in source dir and
+ # make cp fail
+ SDIR=`$DIRNAME $tstfile`
+ INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
+ INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
+ if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
+ $RM $BLDLIBDIR
+ fi
+}
+
+COPY_DATAFILES="$LIST_DATA_FILES"
+
+COPY_DATAFILES_TO_BLDDIR()
+{
+ # copy test files. Used -f to make sure get a new copy
+ for tstfile in $COPY_DATAFILES
+ do
+ # ignore '#' comment
+ echo $tstfile | tr -d ' ' | grep '^#' > /dev/null
+ RET=$?
+ if [ $RET -eq 1 ]; then
+ # skip cp if srcdir is same as destdir
+ # this occurs when build/test performed in source dir and
+ # make cp fail
+ SDIR=`$DIRNAME $tstfile`
+ INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
+ INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
+ if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
+ $CP -f $tstfile $BLDDIR
+ if [ $? -ne 0 ]; then
+ echo "Error: FAILED to copy $tstfile ."
+
+ # Comment out this to CREATE expected file
+ exit $EXIT_FAILURE
+ fi
+ fi
+ fi
+ done
+}
+
+CLEAN_DATAFILES_AND_BLDDIR()
+{
+ # skip rm if srcdir is same as destdir
+ # this occurs when build/test performed in source dir and
+ # make cp fail
+ SDIR=`$DIRNAME $tstfile`
+ INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
+ INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
+ if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
+ $RM $BLDDIR/*.hdf
+ $RM $BLDDIR/*.out
+ fi
+}
+
+# Print a line-line message left justified in a field of 70 characters
+# beginning with the word "Testing".
+#
+TESTING() {
+ SPACES=" "
+ echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012'
+}
+
+# where Java is installed (requires jdk1.7.x)
+JAVAEXE=@JAVA@
+JAVAEXEFLAGS=@H5_JAVAFLAGS@
+
+###############################################################################
+# DO NOT MODIFY BELOW THIS LINE
+###############################################################################
+
+# prepare for test
+COPY_LIBFILES_TO_BLDLIBDIR
+COPY_DATAFILES_TO_BLDDIR
+
+CPATH=".:"$BLDLIBDIR"/"$JARFILE":"$BLDLIBDIR"/junit.jar:"$BLDLIBDIR"/hamcrest-core.jar:"$BLDLIBDIR"/slf4j-api-1.7.5.jar:"$BLDLIBDIR"/slf4j-simple-1.7.5.jar:"$TESTJARFILE""
+
+TEST=/usr/bin/test
+if [ ! -x /usr/bin/test ]
+then
+TEST=`which test`
+fi
+
+if $TEST -z "$CLASSPATH"; then
+ CLASSPATH=""
+fi
+CLASSPATH=$CPATH":"$CLASSPATH
+export CLASSPATH
+
+if $TEST -n "$JAVAPATH" ; then
+ PATH=$JAVAPATH":"$PATH
+ export PATH
+fi
+
+if $TEST -e /bin/uname; then
+ os_name=`/bin/uname -s`
+elif $TEST -e /usr/bin/uname; then
+ os_name=`/usr/bin/uname -s`
+else
+ os_name=unknown
+fi
+
+if $TEST -z "$LD_LIBRARY_PATH" ; then
+ LD_LIBRARY_PATH=""
+fi
+
+case $os_name in
+ Darwin)
+ DYLD_LIBRARY_PATH=$BLDLIBDIR:$DYLD_LIBRARY_PATH
+ export DYLD_LIBRARY_PATH
+ LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
+ ;;
+ *)
+ LD_LIBRARY_PATH=$BLDLIBDIR:$LD_LIBRARY_PATH
+ ;;
+esac
+
+export LD_LIBRARY_PATH
+
+echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH -ea org.junit.runner.JUnitCore test.TestAll"
+($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH -ea org.junit.runner.JUnitCore test.TestAll)
+
+# Clean up temporary files/directories
+CLEAN_LIBFILES_AND_BLDLIBDIR
+CLEAN_DATAFILES_AND_BLDDIR
+
+# Report test results and exit
+if test $nerrors -eq 0 ; then
+ echo "All $TESTNAME tests passed."
+ exit $EXIT_SUCCESS
+else
+ echo "$TESTNAME tests failed with $nerrors errors."
+ exit $EXIT_FAILURE
+fi