mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-03-01 16:28:09 +08:00
Sync API tests with vol-tests (#3940)
This commit is contained in:
parent
2fab2fc9d0
commit
824bbf5cbe
@ -51,6 +51,7 @@ static int test_attribute_iterate_datatype(void);
|
||||
static int test_attribute_iterate_index_saving(void);
|
||||
static int test_attribute_iterate_invalid_params(void);
|
||||
static int test_attribute_iterate_0_attributes(void);
|
||||
static int test_attribute_string_encodings(void);
|
||||
static int test_delete_attribute(void);
|
||||
static int test_delete_attribute_invalid_params(void);
|
||||
static int test_attribute_exists(void);
|
||||
@ -99,6 +100,7 @@ static int (*attribute_tests[])(void) = {test_create_attribute_on_root,
|
||||
test_attribute_iterate_index_saving,
|
||||
test_attribute_iterate_invalid_params,
|
||||
test_attribute_iterate_0_attributes,
|
||||
test_attribute_string_encodings,
|
||||
test_delete_attribute,
|
||||
test_delete_attribute_invalid_params,
|
||||
test_attribute_exists,
|
||||
@ -8333,6 +8335,272 @@ error:
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* A test to check that attributes preserve data
|
||||
* correctness for strings with ASCII or UTF-8 char sets
|
||||
*/
|
||||
static int
|
||||
test_attribute_string_encodings(void)
|
||||
{
|
||||
hid_t file_id = H5I_INVALID_HID;
|
||||
hid_t container_group = H5I_INVALID_HID;
|
||||
hid_t dset_id1 = H5I_INVALID_HID;
|
||||
hid_t dset_id2 = H5I_INVALID_HID;
|
||||
hid_t type_id1 = H5I_INVALID_HID;
|
||||
hid_t type_id2 = H5I_INVALID_HID;
|
||||
hid_t space_id = H5I_INVALID_HID;
|
||||
hid_t attr_id1 = H5I_INVALID_HID;
|
||||
hid_t attr_id2 = H5I_INVALID_HID;
|
||||
hsize_t dims[ATTRIBUTE_STRING_ENCODINGS_RANK] = {ATTRIBUTE_STRING_ENCODINGS_EXTENT};
|
||||
size_t ascii_str_size = 0;
|
||||
size_t utf8_str_size = 0;
|
||||
char *write_buf = NULL;
|
||||
char *read_buf = NULL;
|
||||
|
||||
TESTING_MULTIPART("string encoding read/write correctness on attributes");
|
||||
|
||||
/* Make sure the connector supports the API functions being tested */
|
||||
if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) ||
|
||||
!(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_ATTR_BASIC)) {
|
||||
SKIPPED();
|
||||
printf(" API functions for basic file, group, basic or more dataset aren't supported with this "
|
||||
"connector\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
TESTING_2("test setup");
|
||||
|
||||
ascii_str_size = strlen(ATTRIBUTE_STRING_ENCODINGS_ASCII_STRING);
|
||||
utf8_str_size = strlen(ATTRIBUTE_STRING_ENCODINGS_UTF8_STRING);
|
||||
|
||||
if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't open file '%s'\n", H5_api_test_filename);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((container_group = H5Gopen2(file_id, ATTRIBUTE_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't open container group '%s'\n", ATTRIBUTE_TEST_GROUP_NAME);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((space_id = H5Screate_simple(ATTRIBUTE_STRING_ENCODINGS_RANK, dims, NULL)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't create dataspace\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((type_id1 = H5Tcopy(H5T_C_S1)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't copy builtin string datatype\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((H5Tset_size(type_id1, ascii_str_size)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't set size of string datatype\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((H5Tset_cset(type_id1, H5T_CSET_ASCII)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't set character set of string to ASCII\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((dset_id1 = H5Dcreate(container_group, ATTRIBUTE_STRING_ENCODINGS_DSET_NAME1, type_id1, space_id,
|
||||
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't create dataset with ascii string\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((attr_id1 = H5Acreate(dset_id1, ATTRIBUTE_STRING_ENCODINGS_ATTR_NAME1, type_id1, space_id,
|
||||
H5P_DEFAULT, H5P_DEFAULT)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't create attribute with ascii string\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((type_id2 = H5Tcopy(H5T_C_S1)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't copy builtin string datatype\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((H5Tset_size(type_id2, utf8_str_size)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't set size of string datatype\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((H5Tset_cset(type_id2, H5T_CSET_UTF8)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't set character set of string to UTF-8\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((dset_id2 = H5Dcreate(container_group, ATTRIBUTE_STRING_ENCODINGS_DSET_NAME2, type_id2, space_id,
|
||||
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't create dataset with UTF-8 string\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if ((attr_id2 = H5Acreate(dset_id2, ATTRIBUTE_STRING_ENCODINGS_ATTR_NAME2, type_id2, space_id,
|
||||
H5P_DEFAULT, H5P_DEFAULT)) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't create attribute with ascii string\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
PASSED();
|
||||
|
||||
BEGIN_MULTIPART
|
||||
{
|
||||
PART_BEGIN(ASCII_cset)
|
||||
{
|
||||
TESTING_2("ASCII character set");
|
||||
if ((write_buf = calloc(1, ascii_str_size + 1)) == NULL) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't allocate memory for write buffer\n");
|
||||
PART_ERROR(ASCII_cset);
|
||||
}
|
||||
|
||||
memcpy(write_buf, ATTRIBUTE_STRING_ENCODINGS_ASCII_STRING, ascii_str_size);
|
||||
|
||||
if ((read_buf = calloc(1, ascii_str_size + 1)) == NULL) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't allocate memory for read buffer\n");
|
||||
PART_ERROR(ASCII_cset);
|
||||
}
|
||||
|
||||
if (H5Awrite(attr_id1, type_id1, write_buf) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't write to attribute with ASCII string\n");
|
||||
PART_ERROR(ASCII_cset);
|
||||
}
|
||||
|
||||
if (H5Aread(attr_id1, type_id1, read_buf) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't read from attribute with ASCII string\n");
|
||||
PART_ERROR(ASCII_cset);
|
||||
}
|
||||
|
||||
if (strncmp(write_buf, read_buf, ascii_str_size)) {
|
||||
H5_FAILED();
|
||||
printf(" incorrect data read from attribute with ASCII string\n");
|
||||
PART_ERROR(ASCII_cset);
|
||||
}
|
||||
|
||||
free(write_buf);
|
||||
write_buf = NULL;
|
||||
|
||||
free(read_buf);
|
||||
read_buf = NULL;
|
||||
|
||||
PASSED();
|
||||
}
|
||||
PART_END(ASCII_cset);
|
||||
|
||||
PART_BEGIN(UTF8_cset)
|
||||
{
|
||||
TESTING_2("UTF-8 character set");
|
||||
|
||||
if ((write_buf = calloc(1, utf8_str_size + 1)) == NULL) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't allocate memory for write buffer\n");
|
||||
PART_ERROR(UTF8_cset);
|
||||
}
|
||||
|
||||
memcpy(write_buf, ATTRIBUTE_STRING_ENCODINGS_UTF8_STRING, utf8_str_size);
|
||||
|
||||
if ((read_buf = calloc(1, utf8_str_size + 1)) == NULL) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't allocate memory for read buffer\n");
|
||||
PART_ERROR(UTF8_cset);
|
||||
}
|
||||
|
||||
if (H5Awrite(attr_id2, type_id2, write_buf) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't write to attribute with UTF-8 string\n");
|
||||
PART_ERROR(UTF8_cset);
|
||||
}
|
||||
|
||||
if (H5Aread(attr_id2, type_id2, read_buf) < 0) {
|
||||
H5_FAILED();
|
||||
printf(" couldn't read from attribute with UTF-8 string\n");
|
||||
PART_ERROR(UTF8_cset);
|
||||
}
|
||||
|
||||
if (strncmp(write_buf, read_buf, utf8_str_size)) {
|
||||
H5_FAILED();
|
||||
printf(" incorrect data read from attribute with UTF-8 string\n");
|
||||
PART_ERROR(UTF8_cset);
|
||||
}
|
||||
|
||||
free(write_buf);
|
||||
write_buf = NULL;
|
||||
|
||||
free(read_buf);
|
||||
read_buf = NULL;
|
||||
|
||||
PASSED();
|
||||
}
|
||||
PART_END(UTF8_cset);
|
||||
|
||||
PASSED();
|
||||
}
|
||||
END_MULTIPART;
|
||||
|
||||
TESTING_2("test cleanup");
|
||||
|
||||
if (H5Fclose(file_id) < 0)
|
||||
TEST_ERROR;
|
||||
if (H5Gclose(container_group) < 0)
|
||||
TEST_ERROR;
|
||||
if (H5Dclose(dset_id1) < 0)
|
||||
TEST_ERROR;
|
||||
if (H5Dclose(dset_id2) < 0)
|
||||
TEST_ERROR;
|
||||
if (H5Tclose(type_id1) < 0)
|
||||
TEST_ERROR;
|
||||
if (H5Tclose(type_id2) < 0)
|
||||
TEST_ERROR;
|
||||
if (H5Aclose(attr_id1) < 0)
|
||||
TEST_ERROR;
|
||||
if (H5Aclose(attr_id2) < 0)
|
||||
TEST_ERROR;
|
||||
if (write_buf)
|
||||
free(write_buf);
|
||||
if (read_buf)
|
||||
free(read_buf);
|
||||
PASSED();
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
H5E_BEGIN_TRY
|
||||
{
|
||||
H5Fclose(file_id);
|
||||
H5Gclose(container_group);
|
||||
H5Dclose(dset_id1);
|
||||
H5Dclose(dset_id2);
|
||||
H5Tclose(type_id1);
|
||||
H5Tclose(type_id2);
|
||||
H5Aclose(attr_id1);
|
||||
H5Aclose(attr_id2);
|
||||
if (write_buf)
|
||||
free(write_buf);
|
||||
if (read_buf)
|
||||
free(read_buf);
|
||||
}
|
||||
H5E_END_TRY;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* A test to check that an attribute can be deleted
|
||||
* using H5Adelete(_by_idx).
|
||||
|
@ -156,6 +156,15 @@ int H5_api_attribute_test(void);
|
||||
#define ATTRIBUTE_ITERATE_TEST_0_ATTRIBUTES_SUBGROUP_NAME "attribute_iterate_test_0_attributes"
|
||||
#define ATTRIBUTE_ITERATE_TEST_0_ATTRIBUTES_DSET_NAME "attribute_iterate_dset"
|
||||
|
||||
#define ATTRIBUTE_STRING_ENCODINGS_RANK 1
|
||||
#define ATTRIBUTE_STRING_ENCODINGS_EXTENT 1
|
||||
#define ATTRIBUTE_STRING_ENCODINGS_DSET_NAME1 "encoding_dset1"
|
||||
#define ATTRIBUTE_STRING_ENCODINGS_DSET_NAME2 "encoding_dset2"
|
||||
#define ATTRIBUTE_STRING_ENCODINGS_ASCII_STRING "asciistr"
|
||||
#define ATTRIBUTE_STRING_ENCODINGS_UTF8_STRING "αaααaaaα"
|
||||
#define ATTRIBUTE_STRING_ENCODINGS_ATTR_NAME1 "encoding_attr1"
|
||||
#define ATTRIBUTE_STRING_ENCODINGS_ATTR_NAME2 "encoding_attr2"
|
||||
|
||||
#define ATTRIBUTE_ITERATE_INVALID_PARAMS_TEST_ATTR_SPACE_RANK 1
|
||||
#define ATTRIBUTE_ITERATE_INVALID_PARAMS_TEST_SUBGROUP_NAME "attribute_iterate_invalid_params_test"
|
||||
#define ATTRIBUTE_ITERATE_INVALID_PARAMS_TEST_ATTR_NAME "invalid_params_iter_attr1"
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -42,6 +42,13 @@ int H5_api_dataset_test(void);
|
||||
#define DATASET_CREATE_ANONYMOUS_INVALID_PARAMS_GROUP_NAME "anon_dset_creation_invalid_params_test"
|
||||
#define DATASET_CREATE_ANONYMOUS_INVALID_PARAMS_SPACE_RANK 2
|
||||
|
||||
#define DATASET_STRING_ENCODINGS_RANK 1
|
||||
#define DATASET_STRING_ENCODINGS_EXTENT 1
|
||||
#define DATASET_STRING_ENCODINGS_DSET_NAME1 "encoding_dset1"
|
||||
#define DATASET_STRING_ENCODINGS_DSET_NAME2 "encoding_dset2"
|
||||
#define DATASET_STRING_ENCODINGS_ASCII_STRING "asciistr"
|
||||
#define DATASET_STRING_ENCODINGS_UTF8_STRING "αaααaaaα"
|
||||
|
||||
#define DATASET_CREATE_NULL_DATASPACE_TEST_SUBGROUP_NAME "dataset_with_null_space_test"
|
||||
#define DATASET_CREATE_NULL_DATASPACE_TEST_DSET_NAME "dataset_with_null_space"
|
||||
|
||||
@ -53,7 +60,7 @@ int H5_api_dataset_test(void);
|
||||
#define ZERO_DIM_DSET_TEST_DSET_NAME "zero_dim_dset"
|
||||
|
||||
#define DATASET_MANY_CREATE_GROUP_NAME "group_for_many_datasets"
|
||||
#define DSET_NAME_BUF_SIZE 64u
|
||||
#define DSET_NAME_BUF_SIZE 64
|
||||
#define DATASET_NUMB 100u
|
||||
|
||||
#define DATASET_SHAPE_TEST_DSET_BASE_NAME "dataset_shape_test"
|
||||
@ -106,6 +113,10 @@ int H5_api_dataset_test(void);
|
||||
#define DATASET_CREATION_PROPERTIES_TEST_MAX_COMPACT 12
|
||||
#define DATASET_CREATION_PROPERTIES_TEST_MIN_DENSE 8
|
||||
#define DATASET_CREATION_PROPERTIES_TEST_SHAPE_RANK 3
|
||||
#define DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_ID 32004
|
||||
#define DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NAME "lz4"
|
||||
#define DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_DSET_NAME "ud_filter_test"
|
||||
#define DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS 3
|
||||
|
||||
#define DATASET_OPEN_INVALID_PARAMS_SPACE_RANK 2
|
||||
#define DATASET_OPEN_INVALID_PARAMS_GROUP_NAME "dataset_open_test"
|
||||
@ -126,6 +137,24 @@ int H5_api_dataset_test(void);
|
||||
#define DATASET_PROPERTY_LIST_TEST_DSET_NAME3 "property_list_test_dataset3"
|
||||
#define DATASET_PROPERTY_LIST_TEST_DSET_NAME4 "property_list_test_dataset4"
|
||||
|
||||
#define DATASET_STORAGE_SIZE_TEST_ALL_DSET_SPACE_RANK 2
|
||||
#define DATASET_STORAGE_SIZE_TEST_ALL_DSET_EXTENT 10
|
||||
#define DATASET_STORAGE_SIZE_TEST_GROUP_NAME "dataset_get_storage_size_test"
|
||||
#define DATASET_STORAGE_SIZE_TEST_DSET_CONTIGUOUS_NAME "dataset_contiguous"
|
||||
#define DATASET_STORAGE_SIZE_TEST_DSET_CHUNKED_NAME "dataset_chunked"
|
||||
#define DATASET_STORAGE_SIZE_TEST_DSET_FILTERED_NAME "dataset_filtered"
|
||||
#define DATASET_STORAGE_SIZE_TEST_TYPE H5T_NATIVE_INT
|
||||
|
||||
#define DATASET_FILL_VALUE_TEST_DSET_NAME1 "dataset_fill_value_test_dataset1"
|
||||
#define DATASET_FILL_VALUE_TEST_DSET_NAME2 "dataset_fill_value_test_dataset2"
|
||||
#define DATASET_FILL_VALUE_TEST_DSET_NAME3 "dataset_fill_value_test_dataset3"
|
||||
#define DATASET_FILL_VALUE_TEST_INT_TYPE H5T_NATIVE_INT
|
||||
#define DATASET_FILL_VALUE_TEST_INT_FILL_VALUE 1
|
||||
#define DATASET_FILL_VALUE_TEST_DOUBLE_TYPE H5T_NATIVE_DOUBLE
|
||||
#define DATASET_FILL_VALUE_TEST_DOUBLE_FILL_VALUE 2.002
|
||||
#define DATASET_FILL_VALUE_TEST_STRING_FILL_VALUE "abcdefgh"
|
||||
#define DATASET_FILL_VALUE_TEST_STRING_SIZE 8 /* No null terminator for fixed length string*/
|
||||
|
||||
#define DATASET_SMALL_READ_TEST_ALL_DSET_SPACE_RANK 3
|
||||
#define DATASET_SMALL_READ_TEST_ALL_DSET_DTYPESIZE sizeof(int)
|
||||
#define DATASET_SMALL_READ_TEST_ALL_DSET_DTYPE H5T_NATIVE_INT
|
||||
@ -214,6 +243,15 @@ int H5_api_dataset_test(void);
|
||||
#define DATASET_DATA_BUILTIN_CONVERSION_TEST_GROUP_NAME "dataset_builtin_conversion_verification_test"
|
||||
#define DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME "dataset_builtin_conversion_verification_dset"
|
||||
|
||||
#define DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK 3
|
||||
#define DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS 10
|
||||
#define DATASET_DATA_REAL_CONVERSION_TEST_GROUP_NAME "dataset_real_conversion_verification_test"
|
||||
#define DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME "dataset_real_conversion_verification_dset"
|
||||
#define DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE sizeof(int)
|
||||
#define DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE H5T_NATIVE_INT
|
||||
#define DATASET_DATA_REAL_CONVERSION_TEST_REAL_DTYPESIZE sizeof(double)
|
||||
#define DATASET_DATA_REAL_CONVERSION_TEST_REAL_TYPE H5T_NATIVE_DOUBLE
|
||||
|
||||
#define DATASET_COMPOUND_PARTIAL_IO_DSET_DIMS 10
|
||||
#define DATASET_DATA_COMPOUND_PARTIAL_IO_TEST_GROUP_NAME "dataset_compound_partial_io_test"
|
||||
#define DATASET_DATA_COMPOUND_PARTIAL_IO_TEST_DSET_NAME "dataset_compound_partial_io_test"
|
||||
|
@ -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 ((type_id = generate_random_datatype(H5T_NO_CLASS, false)) < 0) {
|
||||
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 ((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;
|
||||
|
||||
SKIPPED();
|
||||
PART_EMPTY(H5Ovisit_file);
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
SKIPPED();
|
||||
PART_EMPTY(H5Ovisit_by_name_file);
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@ -7067,6 +7239,29 @@ done:
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
@ -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
|
||||
|
@ -121,12 +121,19 @@ int H5_api_object_test(void);
|
||||
#define OBJECT_COPY_INVALID_PARAMS_TEST_GROUP_NAME "object_copy_invalid_params_group"
|
||||
#define OBJECT_COPY_INVALID_PARAMS_TEST_GROUP_NAME2 "object_copy_invalid_params_group_copy"
|
||||
|
||||
#define OBJECT_VISIT_TEST_NUM_OBJS_VISITED 4
|
||||
#define OBJECT_VISIT_TEST_SUBGROUP_NAME "object_visit_test"
|
||||
#define OBJECT_VISIT_TEST_SPACE_RANK 2
|
||||
#define OBJECT_VISIT_TEST_GROUP_NAME "object_visit_test_group"
|
||||
#define OBJECT_VISIT_TEST_DSET_NAME "object_visit_test_dset"
|
||||
#define OBJECT_VISIT_TEST_TYPE_NAME "object_visit_test_type"
|
||||
#define OBJECT_VISIT_TEST_NUM_OBJS_VISITED 4
|
||||
#define OBJECT_VISIT_TEST_SUBGROUP_NAME "object_visit_test"
|
||||
#define OBJECT_VISIT_TEST_SPACE_RANK 2
|
||||
#define OBJECT_VISIT_TEST_GROUP_NAME "object_visit_test_group"
|
||||
#define OBJECT_VISIT_TEST_DSET_NAME "object_visit_test_dset"
|
||||
#define OBJECT_VISIT_TEST_TYPE_NAME "object_visit_test_type"
|
||||
#define OBJECT_VISIT_TEST_ATTR_NAME "object_visit_test_attr"
|
||||
#define OBJECT_VISIT_TEST_FILE_NAME "object_visit_test_file"
|
||||
#define OBJECT_VISIT_TEST_SUBGROUP_LAYERS 3
|
||||
#define OBJECT_VISIT_TEST_GROUP_NAME_PARENT "object_visit_test_group_parent"
|
||||
#define OBJECT_VISIT_TEST_GROUP_NAME_CHILD "object_visit_test_group_child"
|
||||
#define OBJECT_VISIT_TEST_GROUP_NAME_GRANDCHILD "object_visit_test_group_grandchild"
|
||||
#define OBJECT_VISIT_TEST_TOTAL_DATA_SIZE_LIMIT 32000
|
||||
|
||||
#define OBJECT_VISIT_SOFT_LINK_TEST_NUM_OBJS_VISITED 1
|
||||
#define OBJECT_VISIT_SOFT_LINK_TEST_SUBGROUP_NAME "object_visit_soft_link"
|
||||
|
Loading…
Reference in New Issue
Block a user