From d7a5743e4a7f1963463ea4eab1be5948d22be448 Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:57:50 -0600 Subject: [PATCH] Sync API tests with vol-tests (#3940) --- test/API/H5_api_attribute_test.c | 270 +++++ test/API/H5_api_attribute_test.h | 9 + test/API/H5_api_dataset_test.c | 1747 +++++++++++++++++++++++++----- test/API/H5_api_dataset_test.h | 38 + test/API/H5_api_object_test.c | 256 ++++- test/API/H5_api_object_test.h | 7 + 6 files changed, 2037 insertions(+), 290 deletions(-) diff --git a/test/API/H5_api_attribute_test.c b/test/API/H5_api_attribute_test.c index 8c53d1fefd8..47b74f999d1 100644 --- a/test/API/H5_api_attribute_test.c +++ b/test/API/H5_api_attribute_test.c @@ -52,6 +52,7 @@ static void test_attribute_iterate_datatype(void); static void test_attribute_iterate_index_saving(void); static void test_attribute_iterate_invalid_params(void); static void test_attribute_iterate_0_attributes(void); +static void test_attribute_string_encodings(void); static void test_delete_attribute(void); static void test_delete_attribute_invalid_params(void); static void test_attribute_exists(void); @@ -8303,6 +8304,273 @@ test_attribute_iterate_0_attributes(void) } +/* + * A test to check that attributes preserve data + * correctness for strings with ASCII or UTF-8 char sets + */ +static void +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; + } + + 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; + +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; +} + /* * A test to check that an attribute can be deleted * using H5Adelete(_by_idx). @@ -11089,6 +11357,8 @@ H5_api_attribute_test_add(void) "attribute iteration with invalid parameters", NULL, testframe_flags); AddTest("test_attribute_iterate_0_attributes", test_attribute_iterate_0_attributes, NULL, "attribute iteration on object with 0 attributes", NULL, testframe_flags); + AddTest("test_attribute_string_encodings", test_attribute_string_encodings, NULL, + "attribute string encoding correctness", NULL, testframe_flags); AddTest("test_delete_attribute", test_delete_attribute, NULL, "attribute deletion", NULL, testframe_flags); AddTest("test_delete_attribute_invalid_params", test_delete_attribute_invalid_params, NULL, "attribute deletion with invalid parameters", NULL, testframe_flags); diff --git a/test/API/H5_api_attribute_test.h b/test/API/H5_api_attribute_test.h index 67cef76d1fb..c24eec8d484 100644 --- a/test/API/H5_api_attribute_test.h +++ b/test/API/H5_api_attribute_test.h @@ -156,6 +156,15 @@ void H5_api_attribute_test_add(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" diff --git a/test/API/H5_api_dataset_test.c b/test/API/H5_api_dataset_test.c index 0a6e78c8b6a..2258acc10f7 100644 --- a/test/API/H5_api_dataset_test.c +++ b/test/API/H5_api_dataset_test.c @@ -64,7 +64,9 @@ static void test_write_multi_dataset_small_hyperslab(void); static void test_write_multi_dataset_small_point_selection(void); static void test_write_multi_dataset_data_verification(void); static void test_write_dataset_invalid_params(void); +static void test_dataset_string_encodings(void); static void test_dataset_builtin_type_conversion(void); +static void test_dataset_real_to_int_conversion(void); static void test_dataset_compound_partial_io(void); static void test_dataset_set_extent_chunked_unlimited(void); static void test_dataset_set_extent_chunked_fixed(void); @@ -103,6 +105,9 @@ print_dataset_test_header(void) printf("**********************************************\n\n"); } +size_t filter(unsigned int flags, size_t H5_ATTR_UNUSED cd_nelmts, + const unsigned int H5_ATTR_UNUSED cd_values[], size_t nbytes, size_t H5_ATTR_UNUSED *buf_size, + void H5_ATTR_UNUSED **buf); /* * A test to check that a dataset can be * created under the root group. @@ -1978,6 +1983,22 @@ test_create_dataset_array_types(void) return; } +size_t +filter(unsigned int flags, size_t H5_ATTR_UNUSED cd_nelmts, const unsigned int H5_ATTR_UNUSED cd_values[], + size_t nbytes, size_t H5_ATTR_UNUSED *buf_size, void H5_ATTR_UNUSED **buf) +{ + buf_size = 0; + + if (flags & H5Z_FLAG_REVERSE) { + /* No-op */ + } + else { + /* No-op */ + } + + return nbytes; +} + /* * A test to check the functionality of the different * dataset creation properties. @@ -1993,6 +2014,13 @@ test_create_dataset_creation_properties(void) hid_t dset_id = H5I_INVALID_HID, dcpl_id = H5I_INVALID_HID; hid_t dset_dtype = H5I_INVALID_HID, compact_dtype = H5I_INVALID_HID; hid_t fspace_id = H5I_INVALID_HID, compact_fspace_id = H5I_INVALID_HID; + void *read_buf = NULL; + unsigned int filter_params[DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS] = {1, 2, 3}; + unsigned int filter_params_out[DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS]; + char ud_filter_name[strlen(DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NAME)]; + int nfilters = 0; + H5Z_filter_t retrieved_filter_id = H5I_INVALID_HID; + size_t num_filter_params = DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS; TESTING_MULTIPART("dataset creation properties"); @@ -2326,6 +2354,276 @@ test_create_dataset_creation_properties(void) } PART_END(DCPL_fill_time_property_test); + PART_BEGIN(DCPL_fill_value_test) + { + TESTING_2("fill values"); + + int int_fill_value = DATASET_FILL_VALUE_TEST_INT_FILL_VALUE; + double double_fill_value = DATASET_FILL_VALUE_TEST_DOUBLE_FILL_VALUE; + + void *val = NULL; + size_t num_elems = 1; + hid_t type_id = H5I_INVALID_HID; + + if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILL_VALUES)) { + SKIPPED(); + printf(" dataset fill values are not supported by this VOL connector\n"); + PART_EMPTY(DCPL_fill_value_test); + } + + /* Integer Fill Value */ + if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + H5_FAILED(); + printf(" couldn't create DCPL\n"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Pset_fill_value(dcpl_id, DATASET_FILL_VALUE_TEST_INT_TYPE, (const void *)&int_fill_value) < + 0) { + H5_FAILED(); + printf(" couldn't set integer fill value in property list"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((dset_id = + H5Dcreate(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME1, DATASET_FILL_VALUE_TEST_INT_TYPE, + fspace_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with integer fill value"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((H5Sget_simple_extent_dims(fspace_id, dims, NULL)) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace dimensions"); + PART_ERROR(DCPL_fill_value_test); + } + + for (i = 0; i < DATASET_CREATION_PROPERTIES_TEST_SHAPE_RANK; i++) + num_elems *= (size_t)dims[i]; + + if ((read_buf = calloc(num_elems, sizeof(DATASET_FILL_VALUE_TEST_INT_TYPE))) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for read buffer"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dread(dset_id, DATASET_FILL_VALUE_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf) < + 0) { + H5_FAILED(); + printf(" couldn't read from dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + for (i = 0; i < num_elems; i++) { + val = (int *)(read_buf) + i; + + if (*(int *)val != DATASET_FILL_VALUE_TEST_INT_FILL_VALUE) { + H5_FAILED(); + printf(" incorrect value read from dataset"); + PART_ERROR(DCPL_fill_value_test); + } + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close integer fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Pclose(dcpl_id) < 0) { + H5_FAILED(); + printf(" couldn't close dcpl"); + PART_ERROR(DCPL_fill_value_test); + } + + /* Re-open integer dataset */ + if ((dset_id = H5Dopen2(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME1, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open integer fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close opened integer fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + free(read_buf); + read_buf = NULL; + + /* Double fill value */ + if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) == H5I_INVALID_HID) { + H5_FAILED(); + printf(" couldn't create dcpl"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((H5Pset_fill_value(dcpl_id, DATASET_FILL_VALUE_TEST_DOUBLE_TYPE, + (const void *)&double_fill_value)) < 0) { + H5_FAILED(); + printf(" couldn't set double fill value in property list"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((dset_id = H5Dcreate2(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME2, + DATASET_FILL_VALUE_TEST_DOUBLE_TYPE, fspace_id, H5P_DEFAULT, dcpl_id, + H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with double fill value"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((read_buf = calloc(num_elems, sizeof(DATASET_FILL_VALUE_TEST_DOUBLE_TYPE))) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for read buffer"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dread(dset_id, DATASET_FILL_VALUE_TEST_DOUBLE_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + read_buf) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + for (i = 0; i < num_elems; i++) { + val = (double *)(read_buf) + i; + + if (!(H5_DBL_REL_EQUAL(*(double *)val, DATASET_FILL_VALUE_TEST_DOUBLE_FILL_VALUE, + 0.0000001))) { + H5_FAILED(); + printf(" incorrect value read from dataset"); + PART_ERROR(DCPL_fill_value_test); + } + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close double fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Pclose(dcpl_id) < 0) { + H5_FAILED(); + printf(" couldn't close dcpl"); + PART_ERROR(DCPL_fill_value_test); + } + + /* Re-open double dataset */ + if ((dset_id = H5Dopen2(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME2, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open double fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close opened double fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + free(read_buf); + read_buf = NULL; + + /* Fixed-length string fill value */ + if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) == H5I_INVALID_HID) { + H5_FAILED(); + printf(" couldn't create dcpl"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((type_id = H5Tcopy(H5T_C_S1)) < 0) { + H5_FAILED(); + printf(" couldn't copy string datatype"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((H5Tset_size(type_id, DATASET_FILL_VALUE_TEST_STRING_SIZE)) < 0) { + H5_FAILED(); + printf(" couldn't set size of string datatype"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((H5Pset_fill_value(dcpl_id, type_id, + (const void *)DATASET_FILL_VALUE_TEST_STRING_FILL_VALUE)) < 0) { + H5_FAILED(); + printf(" couldn't set string fill value in property list"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((dset_id = H5Dcreate2(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME3, type_id, fspace_id, + H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset with string fill value"); + PART_ERROR(DCPL_fill_value_test); + } + + if ((read_buf = calloc(num_elems, DATASET_FILL_VALUE_TEST_STRING_SIZE)) == NULL) { + H5_FAILED(); + printf(" couldn't allocate memory for read buffer"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dread(dset_id, type_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + for (i = 0; i < num_elems; i++) { + char val_str[DATASET_FILL_VALUE_TEST_STRING_SIZE + 1]; + + memcpy(val_str, ((char *)read_buf) + i * DATASET_FILL_VALUE_TEST_STRING_SIZE, + DATASET_FILL_VALUE_TEST_STRING_SIZE); + val_str[DATASET_FILL_VALUE_TEST_STRING_SIZE] = '\0'; + + if (strcmp(val_str, DATASET_FILL_VALUE_TEST_STRING_FILL_VALUE)) { + H5_FAILED(); + printf(" incorrect value read from string dataset"); + PART_ERROR(DCPL_fill_value_test); + } + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close string fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Pclose(dcpl_id) < 0) { + H5_FAILED(); + printf(" couldn't close dcpl"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Tclose(type_id) < 0) { + H5_FAILED(); + printf(" couldn't close string type"); + PART_ERROR(DCPL_fill_value_test); + } + + free(read_buf); + read_buf = NULL; + + /* Re-open string dataset */ + if ((dset_id = H5Dopen2(group_id, DATASET_FILL_VALUE_TEST_DSET_NAME3, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open string fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + if (H5Dclose(dset_id) < 0) { + H5_FAILED(); + printf(" couldn't close opened string fill value dataset"); + PART_ERROR(DCPL_fill_value_test); + } + + PASSED(); + } + PART_END(DCPL_fill_value_test); + /* Test filters */ PART_BEGIN(DCPL_filters_test) { @@ -2426,6 +2724,120 @@ test_create_dataset_creation_properties(void) } PART_END(DCPL_filters_test); + /* Test a user-defined filter */ + PART_BEGIN(DCPL_user_defined_filter_test) + { + TESTING_2("user-defined dataset filters"); + /* Create user-defined filter and register with library */ + const H5Z_class2_t filter_cls[1] = { + {H5Z_CLASS_T_VERS, DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_ID, 1, 1, + DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NAME, NULL, NULL, &filter}}; + + if (H5Zregister((const void *)&filter_cls) < 0) { + H5_FAILED(); + printf(" couldn't register filter\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) { + H5_FAILED(); + printf(" couldn't create DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if (H5Pset_chunk(dcpl_id, DATASET_CREATION_PROPERTIES_TEST_SHAPE_RANK, chunk_dims) < 0) { + H5_FAILED(); + printf(" couldn't set chunking on DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + /* Set user-defined filter on the DCPL */ + if (H5Pset_filter(dcpl_id, (H5Z_filter_t)DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_ID, + H5Z_FLAG_MANDATORY, 3, filter_params) < 0) { + H5_FAILED(); + printf(" couldn't set user-defined filter on DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + /* Use a simple datatype, as not all filters support all datatypes. */ + if ((dset_id = H5Dcreate2(group_id, DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_DSET_NAME, + H5T_NATIVE_INT, fspace_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", + DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_DSET_NAME); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if (dset_id >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id); + } + H5E_END_TRY; + dset_id = H5I_INVALID_HID; + } + + if ((dset_id = H5Dopen2(group_id, DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_DSET_NAME, + H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", + DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_DSET_NAME); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if (dcpl_id >= 0) { + H5E_BEGIN_TRY + { + H5Pclose(dcpl_id); + } + H5E_END_TRY; + dcpl_id = H5I_INVALID_HID; + } + + /* Test that parameters are preserved in the DCPL */ + memset(filter_params_out, 0, + sizeof(unsigned int) * DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS); + + if ((dcpl_id = H5Dget_create_plist(dset_id)) < 0) { + H5_FAILED(); + printf(" couldn't retrieve DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if ((nfilters = H5Pget_nfilters(dcpl_id)) != 1) { + H5_FAILED(); + printf(" retrieved incorrect number of filters from DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if ((retrieved_filter_id = H5Pget_filter2( + dcpl_id, 0, H5Z_FLAG_MANDATORY, &num_filter_params, filter_params_out, + strlen(DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NAME), ud_filter_name, NULL)) < 0) { + H5_FAILED(); + printf(" retrieved incorrect user-defined filter ID\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + for (i = 0; i < DATASET_CREATION_PROPERTIES_TEST_UD_FILTER_NUM_PARAMS; i++) + if (filter_params[i] != filter_params_out[i]) { + H5_FAILED(); + printf(" retrieved incorrect parameter value from DCPL\n"); + PART_ERROR(DCPL_user_defined_filter_test); + } + + if (dset_id >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id); + } + H5E_END_TRY; + dset_id = H5I_INVALID_HID; + } + + PASSED(); + } + PART_END(DCPL_user_defined_filter_test) + /* Test the dataset storage layout property */ PART_BEGIN(DCPL_storage_layout_test) { @@ -2625,6 +3037,11 @@ test_create_dataset_creation_properties(void) TESTING_2("test cleanup"); + if (read_buf) { + free(read_buf); + read_buf = NULL; + } + if (H5Sclose(compact_fspace_id) < 0) TEST_ERROR; if (H5Sclose(fspace_id) < 0) @@ -2647,6 +3064,10 @@ test_create_dataset_creation_properties(void) error: H5E_BEGIN_TRY { + if (read_buf) { + free(read_buf); + } + H5Sclose(compact_fspace_id); H5Sclose(fspace_id); H5Tclose(compact_dtype); @@ -4620,7 +5041,7 @@ test_read_multi_dataset_small_point_selection(void) hid_t dset_id_arr[DATASET_MULTI_COUNT]; hid_t mspace_id_arr[DATASET_MULTI_COUNT], fspace_id_arr[DATASET_MULTI_COUNT]; hid_t dtype_arr[DATASET_MULTI_COUNT]; - void *data[DATASET_MULTI_COUNT]; + void *read_buf[DATASET_MULTI_COUNT]; TESTING("small multi read from datasets with point selections"); @@ -4634,7 +5055,7 @@ test_read_multi_dataset_small_point_selection(void) /* Prevent uninitialized memory usage on test failure */ for (i = 0; i < DATASET_MULTI_COUNT; i++) { - data[i] = NULL; + read_buf[i] = NULL; dset_id_arr[i] = H5I_INVALID_HID; } @@ -4696,7 +5117,7 @@ test_read_multi_dataset_small_point_selection(void) goto error; } - if (NULL == (data[i] = malloc(data_size))) + if (NULL == (read_buf[i] = malloc(data_size))) TEST_ERROR; dtype_arr[i] = DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_DTYPE; @@ -4705,16 +5126,16 @@ test_read_multi_dataset_small_point_selection(void) } if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_arr, mspace_id_arr, fspace_id_arr, H5P_DEFAULT, - data) < 0) { + read_buf) < 0) { H5_FAILED(); printf(" couldn't read from dataset '%s'\n", DATASET_SMALL_READ_TEST_POINT_SELECTION_DSET_NAME); goto error; } for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; + if (read_buf[i]) { + free(read_buf[i]); + read_buf[i] = NULL; } if (H5Dclose(dset_id_arr[i]) < 0) TEST_ERROR; @@ -4739,9 +5160,9 @@ test_read_multi_dataset_small_point_selection(void) H5E_BEGIN_TRY { for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; + if (read_buf[i]) { + free(read_buf[i]); + read_buf[i] = NULL; } H5Dclose(dset_id_arr[i]); } @@ -6408,15 +6829,16 @@ test_write_multi_dataset_small_all(void) hid_t dset_id_arr[DATASET_MULTI_COUNT]; hid_t fspace_id = H5I_INVALID_HID, fspace_id_arr[DATASET_MULTI_COUNT]; hid_t dtype_id_arr[DATASET_MULTI_COUNT]; - void *data[DATASET_MULTI_COUNT]; - const void *data_c[DATASET_MULTI_COUNT]; + const void *write_buf[DATASET_MULTI_COUNT]; + void *wbuf_temp[DATASET_MULTI_COUNT]; TESTING("small multi write to datasets with H5S_ALL"); /* Prevent uninitialized memory usage on test failure */ for (i = 0; i < DATASET_MULTI_COUNT; i++) { dset_id_arr[i] = H5I_INVALID_HID; - data[i] = NULL; + write_buf[i] = NULL; + wbuf_temp[i] = NULL; } /* Make sure the connector supports the API functions being tested */ @@ -6500,24 +6922,26 @@ test_write_multi_dataset_small_all(void) dtype_id_arr[i] = DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPE; fspace_id_arr[i] = H5S_ALL; - if (NULL == (data[i] = malloc((hsize_t)space_npoints * DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPESIZE))) + if (NULL == + (wbuf_temp[i] = malloc((hsize_t)space_npoints * DATASET_SMALL_WRITE_TEST_ALL_DSET_DTYPESIZE))) TEST_ERROR; - data_c[i] = data[i]; for (size_t j = 0; j < (size_t)space_npoints; j++) - ((int **)data)[i][j] = (int)i; + ((int **)wbuf_temp)[i][j] = (int)i; + + write_buf[i] = wbuf_temp[i]; } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, fspace_id_arr, fspace_id_arr, - H5P_DEFAULT, data_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_MULTI_TEST_ALL_DSET_NAME); goto error; } for (i = 0; i < DATASET_MULTI_COUNT; i++) { - free(data[i]); - data[i] = NULL; + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; if (H5Dclose(dset_id_arr[i]) < 0) TEST_ERROR; } @@ -6538,8 +6962,8 @@ test_write_multi_dataset_small_all(void) H5E_BEGIN_TRY { for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) - free(data[i]); + if (wbuf_temp[i]) + free(wbuf_temp[i]); H5Dclose(dset_id_arr[i]); } @@ -6572,8 +6996,8 @@ test_write_multi_dataset_small_hyperslab(void) hid_t mspace_id = H5I_INVALID_HID, fspace_id = H5I_INVALID_HID; hid_t mspace_id_arr[DATASET_MULTI_COUNT], fspace_id_arr[DATASET_MULTI_COUNT]; hid_t dtype_id_arr[DATASET_MULTI_COUNT]; - void *data[DATASET_MULTI_COUNT]; - const void *data_c[DATASET_MULTI_COUNT]; + const void *write_buf[DATASET_MULTI_COUNT]; + void *wbuf_temp[DATASET_MULTI_COUNT]; TESTING("small multi write to datasets with hyperslab selections"); @@ -6587,7 +7011,8 @@ test_write_multi_dataset_small_hyperslab(void) for (i = 0; i < DATASET_MULTI_COUNT; i++) { dset_id_arr[i] = H5I_INVALID_HID; - data[i] = NULL; + write_buf[i] = NULL; + wbuf_temp[i] = NULL; } if ((file_id = H5Fopen(H5_API_TEST_FILENAME, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) { @@ -6634,12 +7059,13 @@ test_write_multi_dataset_small_hyperslab(void) goto error; } - if (NULL == (data[i] = malloc(data_size))) + if (NULL == (wbuf_temp[i] = malloc(data_size))) TEST_ERROR; - data_c[i] = data[i]; for (size_t j = 0; j < data_size / DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_DTYPESIZE; j++) - ((int **)data)[i][j] = (int)i; + ((int **)wbuf_temp)[i][j] = (int)i; + + write_buf[i] = (const void *)wbuf_temp[i]; } for (i = 0; i < DATASET_SMALL_WRITE_TEST_HYPERSLAB_DSET_SPACE_RANK; i++) { @@ -6661,16 +7087,16 @@ test_write_multi_dataset_small_hyperslab(void) } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, - H5P_DEFAULT, data_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to dataset '%s'\n", DATASET_SMALL_WRITE_MULTI_TEST_HYPERSLAB_DSET_NAME); goto error; } for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } if (H5Dclose(dset_id_arr[i]) < 0) TEST_ERROR; @@ -6695,9 +7121,9 @@ test_write_multi_dataset_small_hyperslab(void) H5E_BEGIN_TRY { for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } H5Dclose(dset_id_arr[i]); } @@ -6720,7 +7146,7 @@ static void test_write_multi_dataset_small_point_selection(void) { hsize_t points[DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS * - DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_SPACE_RANK]; + DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_SPACE_RANK]; hsize_t dims[DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_SPACE_RANK] = {10, 10, 10}; hsize_t mdims[] = {DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS}; size_t i, data_size; @@ -6730,8 +7156,8 @@ test_write_multi_dataset_small_point_selection(void) hid_t fspace_id = H5I_INVALID_HID, fspace_id_arr[DATASET_MULTI_COUNT]; hid_t mspace_id = H5I_INVALID_HID, mspace_id_arr[DATASET_MULTI_COUNT]; hid_t dtype_id_arr[DATASET_MULTI_COUNT]; - void *data[DATASET_MULTI_COUNT]; - const void *data_c[DATASET_MULTI_COUNT]; + const void *write_buf[DATASET_MULTI_COUNT]; + void *wbuf_temp[DATASET_MULTI_COUNT]; TESTING("small multi write to datasets with point selections"); @@ -6744,7 +7170,8 @@ test_write_multi_dataset_small_point_selection(void) } for (i = 0; i < DATASET_MULTI_COUNT; i++) { - data[i] = NULL; + write_buf[i] = NULL; + wbuf_temp[i] = NULL; dset_id_arr[i] = H5I_INVALID_HID; } @@ -6792,12 +7219,13 @@ test_write_multi_dataset_small_point_selection(void) goto error; } - if (NULL == (data[i] = malloc(data_size))) + if (NULL == (wbuf_temp[i] = malloc(data_size))) TEST_ERROR; - data_c[i] = data[i]; for (size_t j = 0; j < data_size / DATASET_SMALL_WRITE_TEST_POINT_SELECTION_DSET_DTYPESIZE; j++) - ((int **)data)[i][j] = (int)i; + ((int **)wbuf_temp)[i][j] = (int)i; + + write_buf[i] = (const void *)wbuf_temp[i]; } for (i = 0; i < DATASET_SMALL_WRITE_TEST_POINT_SELECTION_NUM_POINTS; i++) { @@ -6821,16 +7249,16 @@ test_write_multi_dataset_small_point_selection(void) } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, - H5P_DEFAULT, data_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to multiple datasets\n"); goto error; } for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } if (H5Dclose(dset_id_arr[i]) < 0) @@ -6856,8 +7284,8 @@ test_write_multi_dataset_small_point_selection(void) H5E_BEGIN_TRY { for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) - free(data[i]); + if (wbuf_temp[i]) + free(wbuf_temp[i]); H5Dclose(dset_id_arr[i]); } @@ -6880,26 +7308,25 @@ test_write_multi_dataset_small_point_selection(void) static void test_write_multi_dataset_data_verification(void) { - hssize_t space_npoints[DATASET_MULTI_COUNT]; - hsize_t dims[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK] = {10, 10, 10}; - hsize_t start[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; - hsize_t stride[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; - hsize_t count[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; - hsize_t block[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; - hsize_t points[DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS * - DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; - size_t i, data_size; - hid_t file_id = H5I_INVALID_HID; - hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; - hid_t dset_id_arr[DATASET_MULTI_COUNT]; - hid_t dtype_id_arr[DATASET_MULTI_COUNT]; - hid_t fspace_id = H5I_INVALID_HID, fspace_id_arr[DATASET_MULTI_COUNT]; - hid_t mspace_id = H5I_INVALID_HID, mspace_id_arr[DATASET_MULTI_COUNT]; - hid_t select_all_arr[DATASET_MULTI_COUNT]; - void *data[DATASET_MULTI_COUNT]; - const void *data_c[DATASET_MULTI_COUNT]; - void *write_buf[DATASET_MULTI_COUNT]; - const void *write_buf_c[DATASET_MULTI_COUNT]; + hssize_t space_npoints[DATASET_MULTI_COUNT]; + hsize_t dims[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK] = {10, 10, 10}; + hsize_t start[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; + hsize_t stride[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; + hsize_t count[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; + hsize_t block[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; + hsize_t + points[DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS * DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK]; + size_t i, data_size; + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t dset_id_arr[DATASET_MULTI_COUNT]; + hid_t dtype_id_arr[DATASET_MULTI_COUNT]; + hid_t fspace_id = H5I_INVALID_HID, fspace_id_arr[DATASET_MULTI_COUNT]; + hid_t mspace_id = H5I_INVALID_HID, mspace_id_arr[DATASET_MULTI_COUNT]; + hid_t select_all_arr[DATASET_MULTI_COUNT]; + void *data[DATASET_MULTI_COUNT]; + const void *write_buf[DATASET_MULTI_COUNT]; + void *wbuf_temp[DATASET_MULTI_COUNT]; void *read_buf[DATASET_MULTI_COUNT]; char dset_names[DATASET_MULTI_COUNT][DSET_NAME_BUF_SIZE]; @@ -6920,6 +7347,7 @@ test_write_multi_dataset_data_verification(void) select_all_arr[i] = H5S_ALL; read_buf[i] = NULL; write_buf[i] = NULL; + wbuf_temp[i] = NULL; data[i] = NULL; } @@ -6964,12 +7392,13 @@ test_write_multi_dataset_data_verification(void) if (NULL == (data[i] = malloc(data_size))) TEST_ERROR; - data_c[i] = data[i]; dtype_id_arr[i] = DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE; for (size_t j = 0; j < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; j++) ((int **)data)[i][j] = (int)j; + + write_buf[i] = (const void *)data[i]; } PASSED(); @@ -6981,7 +7410,7 @@ test_write_multi_dataset_data_verification(void) TESTING_2("H5Dwrite_multi using H5S_ALL then H5Dread_multi"); if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, select_all_arr, select_all_arr, - H5P_DEFAULT, data_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to datasets"); PART_ERROR(H5Dwrite_multi_all_read); @@ -7078,16 +7507,14 @@ test_write_multi_dataset_data_verification(void) for (i = 0; i < DATASET_MULTI_COUNT; i++) { data_size = dims[1] * 2 * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; - if (NULL == (write_buf[i] = malloc(data_size))) { + if (NULL == (wbuf_temp[i] = malloc(data_size))) { H5_FAILED(); printf(" couldn't allocate buffer for dataset write\n"); PART_ERROR(H5Dwrite_multi_hyperslab_read); } - write_buf_c[i] = write_buf[i]; - for (size_t j = 0; j < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; j++) { - ((int *)write_buf[i])[j] = 56; + ((int *)wbuf_temp[i])[j] = 56; } data_size = 1; @@ -7100,6 +7527,8 @@ test_write_multi_dataset_data_verification(void) printf(" couldn't allocate buffer for datasets' data verification\n"); PART_ERROR(H5Dwrite_multi_hyperslab_read); } + + write_buf[i] = (const void *)wbuf_temp[i]; } if (H5Dread_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, select_all_arr, select_all_arr, @@ -7148,7 +7577,7 @@ test_write_multi_dataset_data_verification(void) } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, - H5P_DEFAULT, write_buf_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to datasets\n"); PART_ERROR(H5Dwrite_multi_hyperslab_read); @@ -7226,9 +7655,9 @@ test_write_multi_dataset_data_verification(void) data[i] = NULL; } - if (write_buf[i]) { - free(write_buf[i]); - write_buf[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } if (read_buf[i]) { @@ -7242,14 +7671,9 @@ test_write_multi_dataset_data_verification(void) PART_END(H5Dwrite_multi_hyperslab_read); for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (data[i]) { - free(data[i]); - data[i] = NULL; - } - - if (write_buf[i]) { - free(write_buf[i]); - write_buf[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } if (read_buf[i]) { @@ -7266,16 +7690,16 @@ test_write_multi_dataset_data_verification(void) DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS * DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; for (i = 0; i < DATASET_MULTI_COUNT; i++) { - if (NULL == (write_buf[i] = malloc(data_size))) { + if (NULL == (wbuf_temp[i] = malloc(data_size))) { H5_FAILED(); printf(" couldn't allocate buffer for dataset write\n"); PART_ERROR(H5Dwrite_multi_point_sel_read); } - write_buf_c[i] = write_buf[i]; - for (size_t j = 0; j < data_size / DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPESIZE; j++) - ((int **)write_buf)[i][j] = 13; + ((int **)wbuf_temp)[i][j] = 13; + + write_buf[i] = (const void *)wbuf_temp[i]; data_size = 1; @@ -7326,7 +7750,7 @@ test_write_multi_dataset_data_verification(void) } if (H5Dwrite_multi(DATASET_MULTI_COUNT, dset_id_arr, dtype_id_arr, mspace_id_arr, fspace_id_arr, - H5P_DEFAULT, write_buf_c) < 0) { + H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); printf(" couldn't write to datasets\n"); PART_ERROR(H5Dwrite_multi_point_sel_read); @@ -7428,9 +7852,9 @@ test_write_multi_dataset_data_verification(void) data[i] = NULL; } - if (write_buf[i]) { - free(write_buf[i]); - write_buf[i] = NULL; + if (wbuf_temp[i]) { + free(wbuf_temp[i]); + wbuf_temp[i] = NULL; } if (read_buf[i]) { @@ -7461,8 +7885,8 @@ test_write_multi_dataset_data_verification(void) for (i = 0; i < DATASET_MULTI_COUNT; i++) { if (data[i]) free(data[i]); - if (write_buf[i]) - free(write_buf[i]); + if (wbuf_temp[i]) + free(wbuf_temp[i]); if (read_buf[i]) free(read_buf[i]); @@ -7606,80 +8030,849 @@ test_write_dataset_invalid_params(void) err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5I_INVALID_HID, H5S_ALL, H5P_DEFAULT, data); } - H5E_END_TRY + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" wrote to dataset using H5Dwrite with an invalid memory dataspace!\n"); + PART_ERROR(H5Dwrite_invalid_mem_dataspace); + } + + PASSED(); + } + PART_END(H5Dwrite_invalid_mem_dataspace); + + PART_BEGIN(H5Dwrite_invalid_file_dataspace) + { + TESTING_2("H5Dwrite with an invalid file dataspace"); + + H5E_BEGIN_TRY + { + err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, + H5I_INVALID_HID, H5P_DEFAULT, data); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" wrote to dataset using H5Dwrite with an invalid file dataspace!\n"); + PART_ERROR(H5Dwrite_invalid_file_dataspace); + } + + PASSED(); + } + PART_END(H5Dwrite_invalid_file_dataspace); + + PART_BEGIN(H5Dwrite_invalid_dxpl) + { + TESTING_2("H5Dwrite with an invalid DXPL"); + + H5E_BEGIN_TRY + { + err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, + H5I_INVALID_HID, data); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" wrote to dataset using H5Dwrite with an invalid DXPL!\n"); + PART_ERROR(H5Dwrite_invalid_dxpl); + } + + PASSED(); + } + PART_END(H5Dwrite_invalid_dxpl); + + PART_BEGIN(H5Dwrite_invalid_data_buf) + { + TESTING_2("H5Dwrite with an invalid data buffer"); + + H5E_BEGIN_TRY + { + err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, NULL); + } + H5E_END_TRY + + if (err_ret >= 0) { + H5_FAILED(); + printf(" wrote to dataset using H5Dwrite with an invalid data buffer!\n"); + PART_ERROR(H5Dwrite_invalid_data_buf); + } + + PASSED(); + } + PART_END(H5Dwrite_invalid_data_buf); + } + END_MULTIPART; + + TESTING_2("test cleanup"); + + if (data) { + free(data); + data = NULL; + } + + if (H5Sclose(fspace_id) < 0) + TEST_ERROR; + if (H5Dclose(dset_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; + + PASSED(); + + return; + +error: + H5E_BEGIN_TRY + { + if (data) + free(data); + H5Sclose(fspace_id); + H5Dclose(dset_id); + H5Gclose(group_id); + H5Gclose(container_group); + H5Fclose(file_id); + } + H5E_END_TRY + + return; +} + +/* + * A test to ensure that strings of any encoding + * can be written to and read from a dataset + */ +static void +test_dataset_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; + hsize_t dims[DATASET_STRING_ENCODINGS_RANK] = {DATASET_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 datasets"); + + /* 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; + } + + TESTING_2("test setup"); + + ascii_str_size = strlen(DATASET_STRING_ENCODINGS_ASCII_STRING); + utf8_str_size = strlen(DATASET_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, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open container group '%s'\n", DATASET_TEST_GROUP_NAME); + goto error; + } + + if ((space_id = H5Screate_simple(DATASET_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, DATASET_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 ((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, DATASET_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; + } + + PASSED(); + + BEGIN_MULTIPART + { + PART_BEGIN(ASCII_cset) + { + TESTING_2("ASCII character set"); + /* Dataset with ASCII string datatype */ + 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, DATASET_STRING_ENCODINGS_ASCII_STRING, ascii_str_size); + + if ((H5Dwrite(dset_id1, type_id1, H5S_ALL, H5S_ALL, H5P_DEFAULT, write_buf)) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset with ASCII string\n"); + PART_ERROR(ASCII_cset); + } + + 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 ((H5Dread(dset_id1, type_id1, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf)) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset with ASCII string\n"); + PART_ERROR(ASCII_cset); + } + + if (strncmp(write_buf, read_buf, ascii_str_size)) { + H5_FAILED(); + printf(" incorrect data read from dataset 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"); + /* Dataset with UTF-8 string datatype */ + 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, DATASET_STRING_ENCODINGS_UTF8_STRING, utf8_str_size); + + if ((H5Dwrite(dset_id2, type_id2, H5S_ALL, H5S_ALL, H5P_DEFAULT, write_buf)) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset with ASCII string\n"); + PART_ERROR(UTF8_cset); + } + + 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 ((H5Dread(dset_id2, type_id2, H5S_ALL, H5S_ALL, H5P_DEFAULT, read_buf)) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset with ASCII string\n"); + PART_ERROR(UTF8_cset); + } + + if (strncmp(write_buf, read_buf, utf8_str_size)) { + H5_FAILED(); + printf(" incorrect data read from dataset with ASCII 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 (write_buf) + free(write_buf); + if (read_buf) + free(read_buf); + + PASSED(); + + return; + +error: + H5E_BEGIN_TRY + { + H5Fclose(file_id); + H5Gclose(container_group); + H5Dclose(dset_id1); + H5Dclose(dset_id2); + H5Tclose(type_id1); + H5Tclose(type_id2); + if (write_buf) + free(write_buf); + if (read_buf) + free(read_buf); + } + H5E_END_TRY; + + return; +} + +/* + * A test to ensure that data is read back correctly from a dataset after it has + * been written, using type conversion with builtin types. + */ +static void +test_dataset_builtin_type_conversion(void) +{ + hssize_t space_npoints; + hsize_t dims[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK] = {10, 10, 10}; + hsize_t start[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t stride[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t count[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t block[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t points[DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS * + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; + size_t i, data_size; + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t dset_id = H5I_INVALID_HID; + hid_t fspace_id = H5I_INVALID_HID; + hid_t mspace_id = H5I_INVALID_HID; + hid_t file_type_id = H5I_INVALID_HID; + H5T_order_t native_order; + void *data = NULL; + void *write_buf = NULL; + void *read_buf = NULL; + + TESTING_MULTIPART( + "verification of dataset data using H5Dwrite then H5Dread with type conversion of builtin types"); + + /* 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_DATASET_MORE)) { + SKIPPED(); + printf(" API functions for basic file, group, basic or more dataset aren't supported with this " + "connector\n"); + return; + } + + TESTING_2("test setup"); + + if ((native_order = H5Tget_order(DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE)) < 0) { + H5_FAILED(); + printf(" couldn't get native byte order\n"); + goto error; + } + if (native_order == H5T_ORDER_LE) + file_type_id = H5T_STD_I32BE; + else + file_type_id = H5T_STD_I32LE; + + 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, DATASET_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't open container group '%s'\n", DATASET_TEST_GROUP_NAME); + goto error; + } + + if ((group_id = H5Gcreate2(container_group, DATASET_DATA_BUILTIN_CONVERSION_TEST_GROUP_NAME, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create container sub-group '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_GROUP_NAME); + goto error; + } + + if ((fspace_id = H5Screate_simple(DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK, dims, NULL)) < 0) + TEST_ERROR; + + if ((dset_id = H5Dcreate2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, file_type_id, + fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + H5_FAILED(); + printf(" couldn't create dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + goto error; + } + + for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + data_size *= dims[i]; + data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + + if (NULL == (data = malloc(data_size))) + TEST_ERROR; + + for (i = 0; i < data_size / DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + ((int *)data)[i] = (int)i; + + PASSED(); + + BEGIN_MULTIPART + { + PART_BEGIN(H5Dwrite_all_read) + { + TESTING_2("H5Dwrite then H5Dread with H5S_ALL selection"); + + if (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, data) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_all_read); + } + + if (data) { + free(data); + data = NULL; + } + + if (fspace_id >= 0) { + H5E_BEGIN_TRY + { + H5Sclose(fspace_id); + } + H5E_END_TRY + fspace_id = H5I_INVALID_HID; + } + if (dset_id >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id); + } + H5E_END_TRY + dset_id = H5I_INVALID_HID; + } + + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_all_read); + } + + if ((fspace_id = H5Dget_space(dset_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataset dataspace\n"); + PART_ERROR(H5Dwrite_all_read); + } + + if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace num points\n"); + PART_ERROR(H5Dwrite_all_read); + } + + if (NULL == (data = malloc((hsize_t)space_npoints * + DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_all_read); + } + + if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, data) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_all_read); + } + + for (i = 0; i < (hsize_t)space_npoints; i++) + if (((int *)data)[i] != (int)i) { + H5_FAILED(); + printf(" H5S_ALL selection data verification failed\n"); + PART_ERROR(H5Dwrite_all_read); + } + + if (data) { + free(data); + data = NULL; + } + + PASSED(); + } + PART_END(H5Dwrite_all_read); + + PART_BEGIN(H5Dwrite_hyperslab_read) + { + TESTING_2("H5Dwrite using hyperslab selection then H5Dread"); + + data_size = dims[1] * 2 * DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + + if (NULL == (write_buf = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset write\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + for (i = 0; i < data_size / DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + ((int *)write_buf)[i] = 56; + + for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + data_size *= dims[i]; + data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + + if (NULL == (data = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset data verification\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, data) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + for (i = 0; i < 2; i++) { + size_t j; + + for (j = 0; j < dims[1]; j++) + ((int *)data)[(i * dims[1] * dims[2]) + (j * dims[2])] = 56; + } + + /* Write to first two rows of dataset */ + start[0] = start[1] = start[2] = 0; + stride[0] = stride[1] = stride[2] = 1; + count[0] = 2; + count[1] = dims[1]; + count[2] = 1; + block[0] = block[1] = block[2] = 1; + + if (H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, stride, count, block) < 0) { + H5_FAILED(); + printf(" couldn't select hyperslab for dataset write\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + { + hsize_t mdims[] = {(hsize_t)2 * dims[1]}; + + if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0) { + H5_FAILED(); + printf(" couldn't create memory dataspace\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + } + + if (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, mspace_id, fspace_id, + H5P_DEFAULT, write_buf) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (mspace_id >= 0) { + H5E_BEGIN_TRY + { + H5Sclose(mspace_id); + } + H5E_END_TRY + mspace_id = H5I_INVALID_HID; + } + if (fspace_id >= 0) { + H5E_BEGIN_TRY + { + H5Sclose(fspace_id); + } + H5E_END_TRY + fspace_id = H5I_INVALID_HID; + } + if (dset_id >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id); + } + H5E_END_TRY + dset_id = H5I_INVALID_HID; + } + + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + 0) { + H5_FAILED(); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if ((fspace_id = H5Dget_space(dset_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataset dataspace\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace num points\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (NULL == (read_buf = malloc((hsize_t)space_npoints * + DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, read_buf) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (memcmp(data, read_buf, data_size)) { + H5_FAILED(); + printf(" hyperslab selection data verification failed\n"); + PART_ERROR(H5Dwrite_hyperslab_read); + } + + if (data) { + free(data); + data = NULL; + } + + if (write_buf) { + free(write_buf); + write_buf = NULL; + } + + if (read_buf) { + free(read_buf); + read_buf = NULL; + } + + PASSED(); + } + PART_END(H5Dwrite_hyperslab_read); + + PART_BEGIN(H5Dwrite_point_sel_read) + { + TESTING_2("H5Dwrite using point selection then H5Dread"); + + data_size = DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS * + DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + + if (NULL == (write_buf = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset write\n"); + PART_ERROR(H5Dwrite_point_sel_read); + } + + for (i = 0; i < data_size / DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + ((int *)write_buf)[i] = 13; + + for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + data_size *= dims[i]; + data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + + if (NULL == (data = malloc(data_size))) { + H5_FAILED(); + printf(" couldn't allocate buffer for dataset data verification\n"); + PART_ERROR(H5Dwrite_point_sel_read); + } + + if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, data) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_point_sel_read); + } + + for (i = 0; i < dims[0]; i++) { + size_t j; + + for (j = 0; j < dims[1]; j++) { + size_t k; + + for (k = 0; k < dims[2]; k++) { + if (i == j && j == k) + ((int *)data)[(i * dims[1] * dims[2]) + (j * dims[2]) + k] = 13; + } + } + } + + /* Select a series of 10 points in the dataset */ + for (i = 0; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS; i++) { + size_t j; + + for (j = 0; j < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; j++) + points[(i * DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK) + j] = i; + } + + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS, + points) < 0) { + H5_FAILED(); + printf(" couldn't select elements in dataspace\n"); + PART_ERROR(H5Dwrite_point_sel_read); + } + + { + hsize_t mdims[] = {(hsize_t)DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS}; + + if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0) { + H5_FAILED(); + printf(" couldn't create memory dataspace\n"); + PART_ERROR(H5Dwrite_point_sel_read); + } + } + + if (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, mspace_id, fspace_id, + H5P_DEFAULT, write_buf) < 0) { + H5_FAILED(); + printf(" couldn't write to dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_point_sel_read); + } + + if (mspace_id >= 0) { + H5E_BEGIN_TRY + { + H5Sclose(mspace_id); + } + H5E_END_TRY + mspace_id = H5I_INVALID_HID; + } + if (fspace_id >= 0) { + H5E_BEGIN_TRY + { + H5Sclose(fspace_id); + } + H5E_END_TRY + fspace_id = H5I_INVALID_HID; + } + if (dset_id >= 0) { + H5E_BEGIN_TRY + { + H5Dclose(dset_id); + } + H5E_END_TRY + dset_id = H5I_INVALID_HID; + } - if (err_ret >= 0) { + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + 0) { H5_FAILED(); - printf(" wrote to dataset using H5Dwrite with an invalid memory dataspace!\n"); - PART_ERROR(H5Dwrite_invalid_mem_dataspace); - } - - PASSED(); - } - PART_END(H5Dwrite_invalid_mem_dataspace); - - PART_BEGIN(H5Dwrite_invalid_file_dataspace) - { - TESTING_2("H5Dwrite with an invalid file dataspace"); - - H5E_BEGIN_TRY - { - err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, - H5I_INVALID_HID, H5P_DEFAULT, data); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_point_sel_read); } - H5E_END_TRY - if (err_ret >= 0) { + if ((fspace_id = H5Dget_space(dset_id)) < 0) { H5_FAILED(); - printf(" wrote to dataset using H5Dwrite with an invalid file dataspace!\n"); - PART_ERROR(H5Dwrite_invalid_file_dataspace); + printf(" couldn't get dataset dataspace\n"); + PART_ERROR(H5Dwrite_point_sel_read); } - PASSED(); - } - PART_END(H5Dwrite_invalid_file_dataspace); - - PART_BEGIN(H5Dwrite_invalid_dxpl) - { - TESTING_2("H5Dwrite with an invalid DXPL"); - - H5E_BEGIN_TRY - { - err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, - H5I_INVALID_HID, data); + if ((space_npoints = H5Sget_simple_extent_npoints(fspace_id)) < 0) { + H5_FAILED(); + printf(" couldn't get dataspace num points\n"); + PART_ERROR(H5Dwrite_point_sel_read); } - H5E_END_TRY - if (err_ret >= 0) { + if (NULL == (read_buf = malloc((hsize_t)space_npoints * + DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { H5_FAILED(); - printf(" wrote to dataset using H5Dwrite with an invalid DXPL!\n"); - PART_ERROR(H5Dwrite_invalid_dxpl); + printf(" couldn't allocate buffer for dataset read\n"); + PART_ERROR(H5Dwrite_point_sel_read); } - PASSED(); - } - PART_END(H5Dwrite_invalid_dxpl); - - PART_BEGIN(H5Dwrite_invalid_data_buf) - { - TESTING_2("H5Dwrite with an invalid data buffer"); - - H5E_BEGIN_TRY - { - err_ret = H5Dwrite(dset_id, DATASET_WRITE_INVALID_PARAMS_TEST_DSET_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, NULL); + if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, read_buf) < 0) { + H5_FAILED(); + printf(" couldn't read from dataset '%s'\n", + DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + PART_ERROR(H5Dwrite_point_sel_read); } - H5E_END_TRY - if (err_ret >= 0) { + if (memcmp(data, read_buf, data_size)) { H5_FAILED(); - printf(" wrote to dataset using H5Dwrite with an invalid data buffer!\n"); - PART_ERROR(H5Dwrite_invalid_data_buf); + printf(" point selection data verification failed\n"); + PART_ERROR(H5Dwrite_point_sel_read); } PASSED(); } - PART_END(H5Dwrite_invalid_data_buf); + PART_END(H5Dwrite_point_sel_read); } END_MULTIPART; @@ -7690,6 +8883,16 @@ test_write_dataset_invalid_params(void) data = NULL; } + if (write_buf) { + free(write_buf); + write_buf = NULL; + } + + if (read_buf) { + free(read_buf); + read_buf = NULL; + } + if (H5Sclose(fspace_id) < 0) TEST_ERROR; if (H5Dclose(dset_id) < 0) @@ -7710,6 +8913,11 @@ test_write_dataset_invalid_params(void) { if (data) free(data); + if (write_buf) + free(write_buf); + if (read_buf) + free(read_buf); + H5Sclose(mspace_id); H5Sclose(fspace_id); H5Dclose(dset_id); H5Gclose(group_id); @@ -7721,39 +8929,34 @@ test_write_dataset_invalid_params(void) return; } -/* - * A test to ensure that data is read back correctly from a dataset after it has - * been written, using type conversion with builtin types. - */ static void -test_dataset_builtin_type_conversion(void) +test_dataset_real_to_int_conversion(void) { - hssize_t space_npoints; - hsize_t dims[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK] = {10, 10, 10}; - hsize_t start[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; - hsize_t stride[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; - hsize_t count[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; - hsize_t block[DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; - hsize_t points[DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS * - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK]; - size_t i, data_size; - hid_t file_id = H5I_INVALID_HID; - hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; - hid_t dset_id = H5I_INVALID_HID; - hid_t fspace_id = H5I_INVALID_HID; - hid_t mspace_id = H5I_INVALID_HID; - hid_t file_type_id = H5I_INVALID_HID; - H5T_order_t native_order; - void *data = NULL; - void *write_buf = NULL; - void *read_buf = NULL; + hssize_t space_npoints; + hsize_t dims[DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK] = {10, 10, 10}; + hsize_t start[DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t stride[DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t count[DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t block[DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK]; + hsize_t points[DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS * + DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK]; + size_t i, data_size; + hid_t file_id = H5I_INVALID_HID; + hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID; + hid_t dset_id = H5I_INVALID_HID; + hid_t fspace_id = H5I_INVALID_HID; + hid_t mspace_id = H5I_INVALID_HID; + hid_t real_type_id = DATASET_DATA_REAL_CONVERSION_TEST_REAL_TYPE; + void *data = NULL; + void *write_buf = NULL; + void *read_buf = NULL; TESTING_MULTIPART( - "verification of dataset data using H5Dwrite then H5Dread with type conversion of builtin types"); + "verification of dataset data using H5Dwrite then H5Dread with real <-> integer type conversion"); /* 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_DATASET_MORE)) { + !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC)) { SKIPPED(); printf(" API functions for basic file, group, basic or more dataset aren't supported with this " "connector\n"); @@ -7762,16 +8965,6 @@ test_dataset_builtin_type_conversion(void) TESTING_2("test setup"); - if ((native_order = H5Tget_order(DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE)) < 0) { - H5_FAILED(); - printf(" couldn't get native byte order\n"); - goto error; - } - if (native_order == H5T_ORDER_LE) - file_type_id = H5T_STD_I32BE; - else - file_type_id = H5T_STD_I32LE; - 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); @@ -7784,31 +8977,32 @@ test_dataset_builtin_type_conversion(void) goto error; } - if ((group_id = H5Gcreate2(container_group, DATASET_DATA_BUILTIN_CONVERSION_TEST_GROUP_NAME, H5P_DEFAULT, + if ((group_id = H5Gcreate2(container_group, DATASET_DATA_REAL_CONVERSION_TEST_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't create container sub-group '%s'\n", DATASET_DATA_VERIFY_WRITE_TEST_GROUP_NAME); + printf(" couldn't create container sub-group '%s'\n", + DATASET_DATA_REAL_CONVERSION_TEST_GROUP_NAME); goto error; } - if ((fspace_id = H5Screate_simple(DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK, dims, NULL)) < 0) + if ((fspace_id = H5Screate_simple(DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK, dims, NULL)) < 0) TEST_ERROR; - if ((dset_id = H5Dcreate2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, file_type_id, - fspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { + if ((dset_id = H5Dcreate2(group_id, DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME, real_type_id, fspace_id, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't create dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't create dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); goto error; } - for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + for (i = 0, data_size = 1; i < DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK; i++) data_size *= dims[i]; - data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + data_size *= DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; if (NULL == (data = malloc(data_size))) TEST_ERROR; - for (i = 0; i < data_size / DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + for (i = 0; i < data_size / DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; i++) ((int *)data)[i] = (int)i; PASSED(); @@ -7817,13 +9011,12 @@ test_dataset_builtin_type_conversion(void) { PART_BEGIN(H5Dwrite_all_read) { - TESTING_2("H5Dwrite then H5Dread with H5S_ALL selection"); + TESTING_2("write then read int from real dataset with H5S_ALL selection"); - if (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, data) < 0) { + if (H5Dwrite(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + data) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't write to dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_all_read); } @@ -7837,7 +9030,7 @@ test_dataset_builtin_type_conversion(void) { H5Sclose(fspace_id); } - H5E_END_TRY + H5E_END_TRY; fspace_id = H5I_INVALID_HID; } if (dset_id >= 0) { @@ -7845,14 +9038,14 @@ test_dataset_builtin_type_conversion(void) { H5Dclose(dset_id); } - H5E_END_TRY + H5E_END_TRY; dset_id = H5I_INVALID_HID; } - if ((dset_id = H5Dopen2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_all_read); } @@ -7868,18 +9061,17 @@ test_dataset_builtin_type_conversion(void) PART_ERROR(H5Dwrite_all_read); } - if (NULL == (data = malloc((hsize_t)space_npoints * - DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { + if (NULL == + (data = malloc((hsize_t)space_npoints * DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE))) { H5_FAILED(); printf(" couldn't allocate buffer for dataset read\n"); PART_ERROR(H5Dwrite_all_read); } - if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, data) < 0) { + if (H5Dread(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + data) < 0) { H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_all_read); } @@ -7899,11 +9091,26 @@ test_dataset_builtin_type_conversion(void) } PART_END(H5Dwrite_all_read); + if (data) { + free(data); + data = NULL; + } + + if (write_buf) { + free(write_buf); + write_buf = NULL; + } + + if (read_buf) { + free(read_buf); + read_buf = NULL; + } + PART_BEGIN(H5Dwrite_hyperslab_read) { - TESTING_2("H5Dwrite using hyperslab selection then H5Dread"); + TESTING_2("write then read int from real dataset with hyperslab selection"); - data_size = dims[1] * 2 * DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + data_size = dims[1] * 2 * DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; if (NULL == (write_buf = malloc(data_size))) { H5_FAILED(); @@ -7911,26 +9118,21 @@ test_dataset_builtin_type_conversion(void) PART_ERROR(H5Dwrite_hyperslab_read); } - for (i = 0; i < data_size / DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + for (i = 0; i < data_size / DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; i++) ((int *)write_buf)[i] = 56; - for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + for (i = 0, data_size = 1; i < DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK; i++) data_size *= dims[i]; - data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + data_size *= DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; - if (NULL == (data = malloc(data_size))) { + if (NULL == (data = calloc(1, data_size))) { H5_FAILED(); printf(" couldn't allocate buffer for dataset data verification\n"); PART_ERROR(H5Dwrite_hyperslab_read); } - if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, data) < 0) { - H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); - PART_ERROR(H5Dwrite_hyperslab_read); - } + for (i = 0; i < dims[0] * dims[1] * dims[2]; i++) + ((int *)data)[i] = (int)i; for (i = 0; i < 2; i++) { size_t j; @@ -7963,11 +9165,10 @@ test_dataset_builtin_type_conversion(void) } } - if (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, mspace_id, fspace_id, + if (H5Dwrite(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, mspace_id, fspace_id, H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't write to dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_hyperslab_read); } @@ -7976,7 +9177,7 @@ test_dataset_builtin_type_conversion(void) { H5Sclose(mspace_id); } - H5E_END_TRY + H5E_END_TRY; mspace_id = H5I_INVALID_HID; } if (fspace_id >= 0) { @@ -7984,7 +9185,7 @@ test_dataset_builtin_type_conversion(void) { H5Sclose(fspace_id); } - H5E_END_TRY + H5E_END_TRY; fspace_id = H5I_INVALID_HID; } if (dset_id >= 0) { @@ -7992,14 +9193,14 @@ test_dataset_builtin_type_conversion(void) { H5Dclose(dset_id); } - H5E_END_TRY + H5E_END_TRY; dset_id = H5I_INVALID_HID; } - if ((dset_id = H5Dopen2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_hyperslab_read); } @@ -8016,17 +9217,16 @@ test_dataset_builtin_type_conversion(void) } if (NULL == (read_buf = malloc((hsize_t)space_npoints * - DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { + DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE))) { H5_FAILED(); printf(" couldn't allocate buffer for dataset read\n"); PART_ERROR(H5Dwrite_hyperslab_read); } - if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, read_buf) < 0) { + if (H5Dread(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + read_buf) < 0) { H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_hyperslab_read); } @@ -8055,12 +9255,27 @@ test_dataset_builtin_type_conversion(void) } PART_END(H5Dwrite_hyperslab_read); + if (data) { + free(data); + data = NULL; + } + + if (write_buf) { + free(write_buf); + write_buf = NULL; + } + + if (read_buf) { + free(read_buf); + read_buf = NULL; + } + PART_BEGIN(H5Dwrite_point_sel_read) { - TESTING_2("H5Dwrite using point selection then H5Dread"); + TESTING_2("write then read int from real dataset with point selection"); - data_size = DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS * - DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + data_size = DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS * + DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; if (NULL == (write_buf = malloc(data_size))) { H5_FAILED(); @@ -8068,12 +9283,12 @@ test_dataset_builtin_type_conversion(void) PART_ERROR(H5Dwrite_point_sel_read); } - for (i = 0; i < data_size / DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; i++) + for (i = 0; i < data_size / DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; i++) ((int *)write_buf)[i] = 13; - for (i = 0, data_size = 1; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; i++) + for (i = 0, data_size = 1; i < DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK; i++) data_size *= dims[i]; - data_size *= DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE; + data_size *= DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE; if (NULL == (data = malloc(data_size))) { H5_FAILED(); @@ -8081,11 +9296,10 @@ test_dataset_builtin_type_conversion(void) PART_ERROR(H5Dwrite_point_sel_read); } - if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, data) < 0) { + if (H5Dread(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + data) < 0) { H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_point_sel_read); } @@ -8103,14 +9317,14 @@ test_dataset_builtin_type_conversion(void) } /* Select a series of 10 points in the dataset */ - for (i = 0; i < DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS; i++) { + for (i = 0; i < DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS; i++) { size_t j; - for (j = 0; j < DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK; j++) - points[(i * DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_SPACE_RANK) + j] = i; + for (j = 0; j < DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK; j++) + points[(i * DATASET_DATA_REAL_CONVERSION_TEST_DSET_SPACE_RANK) + j] = i; } - if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS, + if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS, points) < 0) { H5_FAILED(); printf(" couldn't select elements in dataspace\n"); @@ -8118,7 +9332,7 @@ test_dataset_builtin_type_conversion(void) } { - hsize_t mdims[] = {(hsize_t)DATASET_DATA_BUILTIN_CONVERSION_TEST_NUM_POINTS}; + hsize_t mdims[] = {(hsize_t)DATASET_DATA_REAL_CONVERSION_TEST_NUM_POINTS}; if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0) { H5_FAILED(); @@ -8127,11 +9341,10 @@ test_dataset_builtin_type_conversion(void) } } - if (H5Dwrite(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, mspace_id, fspace_id, + if (H5Dwrite(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, mspace_id, fspace_id, H5P_DEFAULT, write_buf) < 0) { H5_FAILED(); - printf(" couldn't write to dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't write to dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_point_sel_read); } @@ -8140,7 +9353,7 @@ test_dataset_builtin_type_conversion(void) { H5Sclose(mspace_id); } - H5E_END_TRY + H5E_END_TRY; mspace_id = H5I_INVALID_HID; } if (fspace_id >= 0) { @@ -8148,7 +9361,7 @@ test_dataset_builtin_type_conversion(void) { H5Sclose(fspace_id); } - H5E_END_TRY + H5E_END_TRY; fspace_id = H5I_INVALID_HID; } if (dset_id >= 0) { @@ -8156,14 +9369,14 @@ test_dataset_builtin_type_conversion(void) { H5Dclose(dset_id); } - H5E_END_TRY + H5E_END_TRY; dset_id = H5I_INVALID_HID; } - if ((dset_id = H5Dopen2(group_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < + if ((dset_id = H5Dopen2(group_id, DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME, H5P_DEFAULT)) < 0) { H5_FAILED(); - printf(" couldn't open dataset '%s'\n", DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't open dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_point_sel_read); } @@ -8180,17 +9393,16 @@ test_dataset_builtin_type_conversion(void) } if (NULL == (read_buf = malloc((hsize_t)space_npoints * - DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPESIZE))) { + DATASET_DATA_REAL_CONVERSION_TEST_INT_DTYPESIZE))) { H5_FAILED(); printf(" couldn't allocate buffer for dataset read\n"); PART_ERROR(H5Dwrite_point_sel_read); } - if (H5Dread(dset_id, DATASET_DATA_BUILTIN_CONVERSION_TEST_MEM_DTYPE, H5S_ALL, H5S_ALL, - H5P_DEFAULT, read_buf) < 0) { + if (H5Dread(dset_id, DATASET_DATA_REAL_CONVERSION_TEST_INT_TYPE, H5S_ALL, H5S_ALL, H5P_DEFAULT, + read_buf) < 0) { H5_FAILED(); - printf(" couldn't read from dataset '%s'\n", - DATASET_DATA_BUILTIN_CONVERSION_TEST_DSET_NAME); + printf(" couldn't read from dataset '%s'\n", DATASET_DATA_REAL_CONVERSION_TEST_DSET_NAME); PART_ERROR(H5Dwrite_point_sel_read); } @@ -8254,7 +9466,7 @@ test_dataset_builtin_type_conversion(void) H5Gclose(container_group); H5Fclose(file_id); } - H5E_END_TRY + H5E_END_TRY; return; } @@ -12469,6 +13681,8 @@ H5_api_dataset_test_add(void) "point selection I/O with all selection in memory and points in file", NULL, testframe_flags); AddTest("test_read_dataset_invalid_params", test_read_dataset_invalid_params, NULL, "H5Dread with invalid parameters", NULL, testframe_flags); + AddTest("test_dataset_string_encodings", test_dataset_string_encodings, NULL, + "dataset string encoding correctness", NULL, testframe_flags); AddTest("test_write_dataset_small_all", test_write_dataset_small_all, NULL, "small write to dataset with H5S_ALL", NULL, testframe_flags); AddTest("test_write_dataset_small_hyperslab", test_write_dataset_small_hyperslab, NULL, @@ -12490,6 +13704,9 @@ H5_api_dataset_test_add(void) AddTest("test_dataset_builtin_type_conversion", test_dataset_builtin_type_conversion, NULL, "verification of dataset data using H5Dwrite then H5Dread with type conversion of builtin types", NULL, testframe_flags); + AddTest("test_dataset_real_to_int_conversion", test_dataset_real_to_int_conversion, NULL, + "verification of dataset data using H5Dwrite then H5Dread with real <-> integer type conversion", + NULL, testframe_flags); AddTest("test_dataset_compound_partial_io", test_dataset_compound_partial_io, NULL, "verification of dataset data using H5Dwrite then H5Dread with partial element compound type I/O", NULL, testframe_flags); diff --git a/test/API/H5_api_dataset_test.h b/test/API/H5_api_dataset_test.h index 4c2901f646a..61f7c977de5 100644 --- a/test/API/H5_api_dataset_test.h +++ b/test/API/H5_api_dataset_test.h @@ -42,6 +42,13 @@ void H5_api_dataset_test_add(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" @@ -106,6 +113,10 @@ void H5_api_dataset_test_add(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 @@ void H5_api_dataset_test_add(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 @@ void H5_api_dataset_test_add(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" diff --git a/test/API/H5_api_object_test.c b/test/API/H5_api_object_test.c index a0d65363164..e1d6ca8b6e2 100644 --- a/test/API/H5_api_object_test.c +++ b/test/API/H5_api_object_test.c @@ -52,6 +52,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, @@ -5032,15 +5034,23 @@ test_object_comments_invalid_params(void) static void 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"); @@ -5063,6 +5073,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); @@ -5090,11 +5109,29 @@ 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 ((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(); @@ -5102,6 +5139,14 @@ test_object_visit(void) 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(); @@ -5109,6 +5154,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(); @@ -5241,16 +5307,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); + } - SKIPPED(); - PART_EMPTY(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); @@ -5284,6 +5383,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"); @@ -5464,12 +5587,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); @@ -5503,6 +5636,29 @@ test_object_visit(void) } 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; @@ -5520,12 +5676,25 @@ 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; + if (remove_test_file(NULL, visit_filename) < 0) + TEST_ERROR; + PASSED(); return; @@ -5539,11 +5708,17 @@ test_object_visit(void) 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); + remove_test_file(NULL, visit_filename); } - H5E_END_TRY + H5E_END_TRY; return; } @@ -7051,6 +7226,29 @@ object_visit_callback(hid_t o_id, const char *name, const H5O_info2_t *object_in 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. */ @@ -7112,7 +7310,15 @@ object_visit_soft_link_callback(hid_t o_id, const char *name, const H5O_info2_t UNUSED(o_id); - if (!HDstrncmp(name, ".", strlen(".") + 1) && (counter_val <= 5)) { + 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; else diff --git a/test/API/H5_api_object_test.h b/test/API/H5_api_object_test.h index ab238914058..60832db7537 100644 --- a/test/API/H5_api_object_test.h +++ b/test/API/H5_api_object_test.h @@ -127,6 +127,13 @@ void H5_api_object_test_add(void); #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"