summaryrefslogtreecommitdiffstats
path: root/test/API/H5_api_object_test.c
diff options
context:
space:
mode:
authorLarry Knox <lrknox@hdfgroup.org>2024-02-15 22:51:33 (GMT)
committerGitHub <noreply@github.com>2024-02-15 22:51:33 (GMT)
commit413d10f6e3d4db5341413ba7cd4f819eb5156a51 (patch)
tree8741384bb37a09d0e8d31116c64d9065a0b046f3 /test/API/H5_api_object_test.c
parent987a734e759c82c65a661ae6090b2252d63a7aec (diff)
parent424cb6ecd35bc262120e250ee25706c3d3c3c15d (diff)
downloadhdf5-413d10f6e3d4db5341413ba7cd4f819eb5156a51.zip
hdf5-413d10f6e3d4db5341413ba7cd4f819eb5156a51.tar.gz
hdf5-413d10f6e3d4db5341413ba7cd4f819eb5156a51.tar.bz2
Merge pull request #4019 from lrknox/1_14_dev_sync2_lrk
* Update upload- artifact to match download version (#3929) * Reorg and update options for doc and cmake config (#3934) * Add binary build for linux S3 (#3936) * Clean up Doxygen for szip functions and constants (#3943) * Replace off_t with HDoff_t internally (#3944) off_t is a 32-bit signed value on Windows, so we should use HDoff_t (which is __int64 on Windows) internally instead. Also defines HDftell on Windows to be _ftelli64(). * Fix chid_t to hid_t (#3948) * Fortran API work. (#3941) * - Added Fortran APIs: H5FGET_INTENT_F, H5SSELECT_ITER_CREATE_F, H5SSEL_ITER_GET_SEQ_LIST_F, H5SSELECT_ITER_CLOSE_F, H5S_mp_H5SSELECT_ITER_RESET_F - Added Fortran Parameters: H5S_SEL_ITER_GET_SEQ_LIST_SORTED_F, H5S_SEL_ITER_SHARE_WITH_DATASPACE_F - Added tests for new APIs - Removed H5F C wrapper stubs - Documentation misc. cleanup. * Add the user test program in HDFFV-9174 for committed types. (#3937) Add the user test program for committed types in HDFFV-9174 * Remove cached datatype conversion path table entries on file close (#3942) * fixed BIND name (#3957) * update H5Ssel_iter_reset_f test * Change 'extensible' to 'fixed' in H5FA code (#3964) * RF: move codespell configuration into .codespellrc so could be used locally as well (#3958) * Add RELEASE.txt note for the fix for issue #1256 (#3955) * Fix doxygen errors (#3962) * Add API support for Fortran MPI_F08 module definitions. (#3959) * revert to using c-stub for _F08 MPI APIs * use mpi compiler wrappers for cmake and nvhpc * Added a GitHub Codespaces configuration. (#3966) * Fixed XL and gfortran errors (#3968) * h5 compiler wrappers now pass all arguments passed to it to the compile line (#3954) * The issue was that the "allargs" variable was not being used in the final command of the compiler wrapper. Any entries containing an escaped quote (\", \') or other non-matching argument (*) would not be passed to the compile line. I have fixed this problem by ensuring all arguments passed to the compiler wrapper are now included in the compile line. * Add binary testing to CI testing (#3971) * Replace 'T2' with ' ' to avoid failure to match expected output due to (#3975) * Clarify vlen string datatype message (#3950) * append '-WF,' when passing C preprocessor directives to the xlf compiler (#3976) * Create CITATION.cff (#3927) Add citation source based on http://web.archive.org/web/20230610185232/https://portal.hdfgroup.org/display/knowledge/How+do+I+properly+cite+HDF5%The space difference in the Fortran examples must be fixed to match the expected output for compression filter examples. * corrected warning: implicit conversion changes signedness (#3982) * Skip mac bintest until more reliable (#3983) * Make platform specific test presets for windows and macs (#3988) * chore: fix typo (#3989) * Add a missing left parenthesis in RELEASE.txt. (#3990) * Remove ADB signature from RELEASE.txt. (#3986) * Bump the github-actions group with 6 updates (#3981) * Sync API tests with vol-tests (#3940) * Fix for github issue #2414: segfault when copying dataset with attrib… (#3967) * Fix for github issue #2414: segfault when copying dataset with attributes. This also fixes github issue #3241: segfault when copying dataset. Need to set the location via H5T_set_loc() of the src datatype when copying dense attributes. Otherwise the vlen callbacks are not set up therefore causing seg fault when doing H5T_convert() -> H5T__conv_vlen(). * Fix broken links caused by examples relocation. (#3995) * Add abi-complience check and upload to releases (#3996) * Fix h5watch test failures to ignore system warnings on ppc64le. (#3997) * Remove oneapi/clang compiler printf() type warning. (#3994) * Updated information about obtaining the HDF5 source code to use the repos. (#3972) * Fix overwritten preset names (#4000) * Fix incompatible pointer type warnings in object reference examples (#3999) * Fix build issue and some warnings in H5_api_dataset_test.c (#3998) * Modern C++ dtor declarations (#1830) * C++ dtor modernization - Replaced a bunch of empty dtors with `= default` - Removed deprecated `throw()`. In C++11, dtors are `noexcept` by default. * remove incorrect check for environ (#4002) * Add a missing file into Makefile.am for MinGW Autotools build error. (#4004) * Issue #1824: Replaced most remaining sprintf with safer snprint (#4003) * Add hl and cpp ABI reports to daily build (#4006) * Don't add files and directories with names that begin with ., or that match *autom4te* to release tar & zip files. (#4009) * Fix some output issues with ph5diff (#4008) * Update install texts (#4010) * Add C in project line for CMake to fix #4012. (#4014) * separate out individual checks for string removal (#4015) * Add compound subset ops on attributes to API tests (#4005) ---------
Diffstat (limited to 'test/API/H5_api_object_test.c')
-rw-r--r--test/API/H5_api_object_test.c263
1 files changed, 237 insertions, 26 deletions
diff --git a/test/API/H5_api_object_test.c b/test/API/H5_api_object_test.c
index d861661..77af8c9 100644
--- a/test/API/H5_api_object_test.c
+++ b/test/API/H5_api_object_test.c
@@ -51,6 +51,8 @@ static herr_t object_copy_soft_link_expand_callback(hid_t group, const char *nam
void *op_data);
static herr_t object_visit_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info,
void *op_data);
+static herr_t object_visit_simple_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info,
+ void *op_data);
static herr_t object_visit_dset_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info,
void *op_data);
static herr_t object_visit_dtype_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info,
@@ -5048,15 +5050,23 @@ test_object_comments_invalid_params(void)
static int
test_object_visit(void)
{
- size_t i;
- hid_t file_id = H5I_INVALID_HID;
- hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID;
- hid_t group_id2 = H5I_INVALID_HID;
- hid_t gcpl_id = H5I_INVALID_HID;
- hid_t type_id = H5I_INVALID_HID;
- hid_t dset_id = H5I_INVALID_HID;
- hid_t dset_dtype = H5I_INVALID_HID;
- hid_t fspace_id = H5I_INVALID_HID;
+ size_t i;
+ hid_t file_id = H5I_INVALID_HID;
+ hid_t file_id2 = H5I_INVALID_HID;
+ hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID;
+ hid_t group_id2 = H5I_INVALID_HID;
+ hid_t gcpl_id = H5I_INVALID_HID;
+ hid_t type_id = H5I_INVALID_HID;
+ hid_t dset_id = H5I_INVALID_HID;
+ hid_t dset_dtype = H5I_INVALID_HID;
+ hid_t fspace_id = H5I_INVALID_HID;
+ hid_t attr_id = H5I_INVALID_HID;
+ hid_t group_id3 = H5I_INVALID_HID;
+ hid_t group_id4 = H5I_INVALID_HID;
+ hid_t group_id5 = H5I_INVALID_HID;
+ hssize_t num_elems = 0;
+ size_t elem_size = 0;
+ char visit_filename[H5_API_TEST_FILENAME_MAX_LENGTH];
TESTING_MULTIPART("object visiting");
@@ -5079,6 +5089,15 @@ test_object_visit(void)
goto error;
}
+ snprintf(visit_filename, H5_API_TEST_FILENAME_MAX_LENGTH, "%s%s", test_path_prefix,
+ OBJECT_VISIT_TEST_FILE_NAME);
+
+ if ((file_id2 = H5Fcreate(visit_filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't open file '%s'\n", OBJECT_VISIT_TEST_FILE_NAME);
+ goto error;
+ }
+
if ((container_group = H5Gopen2(file_id, OBJECT_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) {
H5_FAILED();
printf(" couldn't open container group '%s'\n", OBJECT_TEST_GROUP_NAME);
@@ -5106,18 +5125,44 @@ test_object_visit(void)
goto error;
}
- if ((fspace_id = generate_random_dataspace(OBJECT_VISIT_TEST_SPACE_RANK, NULL, NULL, false)) < 0)
- TEST_ERROR;
+ /* Make sure not to generate too much data for an attribute to hold */
+ do {
+ if (fspace_id != H5I_INVALID_HID)
+ H5Sclose(fspace_id);
- if ((dset_dtype = generate_random_datatype(H5T_NO_CLASS, false)) < 0)
- TEST_ERROR;
+ if (dset_dtype != H5I_INVALID_HID)
+ H5Tclose(dset_dtype);
+
+ if ((fspace_id = generate_random_dataspace(OBJECT_VISIT_TEST_SPACE_RANK, NULL, NULL, FALSE)) < 0) {
+ TEST_ERROR;
+ }
+
+ if ((dset_dtype = generate_random_datatype(H5T_NO_CLASS, FALSE)) < 0) {
+ TEST_ERROR;
+ }
- if ((type_id = generate_random_datatype(H5T_NO_CLASS, false)) < 0) {
+ if ((num_elems = H5Sget_simple_extent_npoints(fspace_id)) < 0)
+ TEST_ERROR;
+
+ if ((elem_size = H5Tget_size(dset_dtype)) == 0)
+ TEST_ERROR;
+
+ } while (((long unsigned int)num_elems * elem_size) > OBJECT_VISIT_TEST_TOTAL_DATA_SIZE_LIMIT);
+
+ if ((type_id = generate_random_datatype(H5T_NO_CLASS, FALSE)) < 0) {
H5_FAILED();
printf(" couldn't create datatype '%s'\n", OBJECT_VISIT_TEST_TYPE_NAME);
goto error;
}
+ if ((attr_id = H5Acreate2(group_id, OBJECT_VISIT_TEST_ATTR_NAME, dset_dtype, fspace_id, H5P_DEFAULT,
+ H5P_DEFAULT)) == H5I_INVALID_HID) {
+ H5_FAILED();
+ printf(" couldn't create attribute '%s' on group '%s'\n", OBJECT_VISIT_TEST_ATTR_NAME,
+ OBJECT_VISIT_TEST_SUBGROUP_NAME);
+ goto error;
+ }
+
if ((group_id2 = H5Gcreate2(group_id, OBJECT_VISIT_TEST_GROUP_NAME, H5P_DEFAULT, gcpl_id, H5P_DEFAULT)) <
0) {
H5_FAILED();
@@ -5125,6 +5170,27 @@ test_object_visit(void)
goto error;
}
+ if ((group_id3 = H5Gcreate2(file_id2, OBJECT_VISIT_TEST_GROUP_NAME_PARENT, H5P_DEFAULT, gcpl_id,
+ H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't create group '%s'\n", OBJECT_VISIT_TEST_GROUP_NAME_PARENT);
+ goto error;
+ }
+
+ if ((group_id4 = H5Gcreate2(group_id3, OBJECT_VISIT_TEST_GROUP_NAME_CHILD, H5P_DEFAULT, gcpl_id,
+ H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't create group '%s'\n", OBJECT_VISIT_TEST_GROUP_NAME_CHILD);
+ goto error;
+ }
+
+ if ((group_id5 = H5Gcreate2(group_id4, OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD, H5P_DEFAULT, gcpl_id,
+ H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't create group '%s'\n", OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD);
+ goto error;
+ }
+
if ((dset_id = H5Dcreate2(group_id, OBJECT_VISIT_TEST_DSET_NAME, dset_dtype, fspace_id, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();
@@ -5257,16 +5323,49 @@ test_object_visit(void)
}
PART_END(H5Ovisit_create_order_decreasing);
+ PART_BEGIN(H5Ovisit_group)
+ {
+ TESTING_2("H5Ovisit on a group");
+
+ i = 0;
+
+ if (H5Ovisit3(group_id3, H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback, &i,
+ H5O_INFO_ALL) < 0) {
+ H5_FAILED();
+ printf(" H5Ovisit on a group failed!\n");
+ PART_ERROR(H5Ovisit_group);
+ }
+
+ if (i != OBJECT_VISIT_TEST_SUBGROUP_LAYERS) {
+ H5_FAILED();
+ printf(" some objects were not visited!\n");
+ PART_ERROR(H5Ovisit_group);
+ }
+
+ PASSED();
+ }
+ PART_END(H5Ovisit_group);
+
PART_BEGIN(H5Ovisit_file)
{
TESTING_2("H5Ovisit on a file ID");
- /*
- * XXX:
- */
+ i = 0;
+
+ if (H5Ovisit3(file_id2, H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback, &i,
+ H5O_INFO_ALL) < 0) {
+ H5_FAILED();
+ printf(" H5Ovisit on a file ID failed!\n");
+ PART_ERROR(H5Ovisit_file);
+ }
+
+ if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) {
+ H5_FAILED();
+ printf(" some objects were not visited!\n");
+ PART_ERROR(H5Ovisit_file);
+ }
- SKIPPED();
- PART_EMPTY(H5Ovisit_file);
+ PASSED();
}
PART_END(H5Ovisit_file);
@@ -5300,6 +5399,30 @@ test_object_visit(void)
}
PART_END(H5Ovisit_dtype);
+ PART_BEGIN(H5Ovisit_attr)
+ {
+ TESTING_2("H5Ovisit on an attribute");
+
+ i = 0;
+
+ if (H5Ovisit3(attr_id, H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback, &i,
+ H5O_INFO_ALL) < 0) {
+ H5_FAILED();
+ printf(" H5Ovisit on an attribute failed!\n");
+ PART_ERROR(H5Ovisit_attr);
+ }
+
+ /* Should have same effect as calling H5Ovisit on group_id */
+ if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) {
+ H5_FAILED();
+ printf(" some objects were not visited!\n");
+ PART_ERROR(H5Ovisit_attr);
+ }
+
+ PASSED();
+ }
+ PART_END(H5Ovisit_attr);
+
PART_BEGIN(H5Ovisit_by_name_obj_name_increasing)
{
TESTING_2("H5Ovisit_by_name by object name in increasing order");
@@ -5480,12 +5603,22 @@ test_object_visit(void)
{
TESTING_2("H5Ovisit_by_name on a file ID");
- /*
- * XXX:
- */
+ i = 0;
+
+ if (H5Ovisit_by_name3(file_id2, "/", H5_INDEX_CRT_ORDER, H5_ITER_INC,
+ object_visit_simple_callback, &i, H5O_INFO_ALL, H5P_DEFAULT) < 0) {
+ H5_FAILED();
+ printf(" H5Ovisit on a file ID failed!\n");
+ PART_ERROR(H5Ovisit_by_name_file);
+ }
- SKIPPED();
- PART_EMPTY(H5Ovisit_by_name_file);
+ if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) {
+ H5_FAILED();
+ printf(" some objects were not visited!\n");
+ PART_ERROR(H5Ovisit_by_name_file);
+ }
+
+ PASSED();
}
PART_END(H5Ovisit_by_name_file);
@@ -5518,6 +5651,30 @@ test_object_visit(void)
PASSED();
}
PART_END(H5Ovisit_by_name_dtype);
+
+ PART_BEGIN(H5Ovisit_by_name_attr)
+ {
+ TESTING_2("H5Ovisit_by_name on an attribute");
+
+ i = 0;
+
+ if (H5Ovisit_by_name(attr_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, object_visit_simple_callback,
+ &i, H5O_INFO_ALL, H5P_DEFAULT) < 0) {
+ H5_FAILED();
+ printf(" H5Ovisit_by_name on an attribute failed!\n");
+ PART_ERROR(H5Ovisit_by_name_attr);
+ }
+
+ /* Should have same effect as calling H5Ovisit on group_id */
+ if (i != OBJECT_VISIT_TEST_NUM_OBJS_VISITED) {
+ H5_FAILED();
+ printf(" some objects were not visited!\n");
+ PART_ERROR(H5Ovisit_by_name_attr);
+ }
+
+ PASSED();
+ }
+ PART_END(H5Ovisit_by_name_attr);
}
END_MULTIPART;
@@ -5535,12 +5692,22 @@ test_object_visit(void)
TEST_ERROR;
if (H5Gclose(group_id2) < 0)
TEST_ERROR;
+ if (H5Gclose(group_id3) < 0)
+ TEST_ERROR;
+ if (H5Gclose(group_id4) < 0)
+ TEST_ERROR;
+ if (H5Gclose(group_id5) < 0)
+ TEST_ERROR;
+ if (H5Aclose(attr_id) < 0)
+ TEST_ERROR;
if (H5Gclose(group_id) < 0)
TEST_ERROR;
if (H5Gclose(container_group) < 0)
TEST_ERROR;
if (H5Fclose(file_id) < 0)
TEST_ERROR;
+ if (H5Fclose(file_id2) < 0)
+ TEST_ERROR;
PASSED();
@@ -5555,11 +5722,16 @@ error:
H5Dclose(dset_id);
H5Pclose(gcpl_id);
H5Gclose(group_id2);
+ H5Gclose(group_id3);
+ H5Gclose(group_id4);
+ H5Gclose(group_id5);
+ H5Aclose(attr_id);
H5Gclose(group_id);
H5Gclose(container_group);
H5Fclose(file_id);
+ H5Fclose(file_id2);
}
- H5E_END_TRY
+ H5E_END_TRY;
return 1;
}
@@ -7068,6 +7240,29 @@ done:
}
/*
+ * H5Ovisit callback to count the number of visited objects
+ */
+static herr_t
+object_visit_simple_callback(hid_t o_id, const char *name, const H5O_info2_t *object_info, void *op_data)
+{
+ size_t *i = (size_t *)op_data;
+ herr_t ret_val = 0;
+
+ UNUSED(o_id);
+ UNUSED(object_info);
+
+ if (name)
+ goto done;
+
+ ret_val = -1;
+
+done:
+ (*i)++;
+
+ return ret_val;
+}
+
+/*
* H5Ovisit callback for visiting a singular dataset.
*/
static herr_t
@@ -7128,6 +7323,14 @@ object_visit_soft_link_callback(hid_t o_id, const char *name, const H5O_info2_t
UNUSED(o_id);
+ if (!strcmp(name, OBJECT_VISIT_TEST_GROUP_NAME_PARENT) ||
+ !strcmp(name, OBJECT_VISIT_TEST_GROUP_NAME_PARENT "/" OBJECT_VISIT_TEST_GROUP_NAME_CHILD) ||
+ !strcmp(name, OBJECT_VISIT_TEST_GROUP_NAME_PARENT "/" OBJECT_VISIT_TEST_GROUP_NAME_CHILD
+ "/" OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD)) {
+ (*i)--;
+ goto done;
+ }
+
if (!strncmp(name, ".", strlen(".") + 1) && (counter_val <= 5)) {
if (H5O_TYPE_GROUP == object_info->type)
goto done;
@@ -7166,7 +7369,15 @@ object_visit_noop_callback(hid_t o_id, const char *name, const H5O_info2_t *obje
static void
cleanup_files(void)
{
- H5Fdelete(OBJECT_COPY_BETWEEN_FILES_TEST_FILE_NAME, H5P_DEFAULT);
+ char filename[H5_API_TEST_FILENAME_MAX_LENGTH];
+
+ snprintf(filename, H5_API_TEST_FILENAME_MAX_LENGTH, "%s%s", test_path_prefix,
+ OBJECT_COPY_BETWEEN_FILES_TEST_FILE_NAME);
+ H5Fdelete(filename, H5P_DEFAULT);
+
+ snprintf(filename, H5_API_TEST_FILENAME_MAX_LENGTH, "%s%s", test_path_prefix,
+ OBJECT_VISIT_TEST_FILE_NAME);
+ H5Fdelete(filename, H5P_DEFAULT);
}
int