summaryrefslogtreecommitdiffstats
path: root/test/API/H5_api_attribute_test.c
diff options
context:
space:
mode:
authorLarry Knox <lrknox@hdfgroup.org>2024-02-15 22:51:33 (GMT)
committerGitHub <noreply@github.com>2024-02-15 22:51:33 (GMT)
commit413d10f6e3d4db5341413ba7cd4f819eb5156a51 (patch)
tree8741384bb37a09d0e8d31116c64d9065a0b046f3 /test/API/H5_api_attribute_test.c
parent987a734e759c82c65a661ae6090b2252d63a7aec (diff)
parent424cb6ecd35bc262120e250ee25706c3d3c3c15d (diff)
downloadhdf5-413d10f6e3d4db5341413ba7cd4f819eb5156a51.zip
hdf5-413d10f6e3d4db5341413ba7cd4f819eb5156a51.tar.gz
hdf5-413d10f6e3d4db5341413ba7cd4f819eb5156a51.tar.bz2
Merge pull request #4019 from lrknox/1_14_dev_sync2_lrk
* Update upload- artifact to match download version (#3929) * Reorg and update options for doc and cmake config (#3934) * Add binary build for linux S3 (#3936) * Clean up Doxygen for szip functions and constants (#3943) * Replace off_t with HDoff_t internally (#3944) off_t is a 32-bit signed value on Windows, so we should use HDoff_t (which is __int64 on Windows) internally instead. Also defines HDftell on Windows to be _ftelli64(). * Fix chid_t to hid_t (#3948) * Fortran API work. (#3941) * - Added Fortran APIs: H5FGET_INTENT_F, H5SSELECT_ITER_CREATE_F, H5SSEL_ITER_GET_SEQ_LIST_F, H5SSELECT_ITER_CLOSE_F, H5S_mp_H5SSELECT_ITER_RESET_F - Added Fortran Parameters: H5S_SEL_ITER_GET_SEQ_LIST_SORTED_F, H5S_SEL_ITER_SHARE_WITH_DATASPACE_F - Added tests for new APIs - Removed H5F C wrapper stubs - Documentation misc. cleanup. * Add the user test program in HDFFV-9174 for committed types. (#3937) Add the user test program for committed types in HDFFV-9174 * Remove cached datatype conversion path table entries on file close (#3942) * fixed BIND name (#3957) * update H5Ssel_iter_reset_f test * Change 'extensible' to 'fixed' in H5FA code (#3964) * RF: move codespell configuration into .codespellrc so could be used locally as well (#3958) * Add RELEASE.txt note for the fix for issue #1256 (#3955) * Fix doxygen errors (#3962) * Add API support for Fortran MPI_F08 module definitions. (#3959) * revert to using c-stub for _F08 MPI APIs * use mpi compiler wrappers for cmake and nvhpc * Added a GitHub Codespaces configuration. (#3966) * Fixed XL and gfortran errors (#3968) * h5 compiler wrappers now pass all arguments passed to it to the compile line (#3954) * The issue was that the "allargs" variable was not being used in the final command of the compiler wrapper. Any entries containing an escaped quote (\", \') or other non-matching argument (*) would not be passed to the compile line. I have fixed this problem by ensuring all arguments passed to the compiler wrapper are now included in the compile line. * Add binary testing to CI testing (#3971) * Replace 'T2' with ' ' to avoid failure to match expected output due to (#3975) * Clarify vlen string datatype message (#3950) * append '-WF,' when passing C preprocessor directives to the xlf compiler (#3976) * Create CITATION.cff (#3927) Add citation source based on http://web.archive.org/web/20230610185232/https://portal.hdfgroup.org/display/knowledge/How+do+I+properly+cite+HDF5%The space difference in the Fortran examples must be fixed to match the expected output for compression filter examples. * corrected warning: implicit conversion changes signedness (#3982) * Skip mac bintest until more reliable (#3983) * Make platform specific test presets for windows and macs (#3988) * chore: fix typo (#3989) * Add a missing left parenthesis in RELEASE.txt. (#3990) * Remove ADB signature from RELEASE.txt. (#3986) * Bump the github-actions group with 6 updates (#3981) * Sync API tests with vol-tests (#3940) * Fix for github issue #2414: segfault when copying dataset with attrib… (#3967) * Fix for github issue #2414: segfault when copying dataset with attributes. This also fixes github issue #3241: segfault when copying dataset. Need to set the location via H5T_set_loc() of the src datatype when copying dense attributes. Otherwise the vlen callbacks are not set up therefore causing seg fault when doing H5T_convert() -> H5T__conv_vlen(). * Fix broken links caused by examples relocation. (#3995) * Add abi-complience check and upload to releases (#3996) * Fix h5watch test failures to ignore system warnings on ppc64le. (#3997) * Remove oneapi/clang compiler printf() type warning. (#3994) * Updated information about obtaining the HDF5 source code to use the repos. (#3972) * Fix overwritten preset names (#4000) * Fix incompatible pointer type warnings in object reference examples (#3999) * Fix build issue and some warnings in H5_api_dataset_test.c (#3998) * Modern C++ dtor declarations (#1830) * C++ dtor modernization - Replaced a bunch of empty dtors with `= default` - Removed deprecated `throw()`. In C++11, dtors are `noexcept` by default. * remove incorrect check for environ (#4002) * Add a missing file into Makefile.am for MinGW Autotools build error. (#4004) * Issue #1824: Replaced most remaining sprintf with safer snprint (#4003) * Add hl and cpp ABI reports to daily build (#4006) * Don't add files and directories with names that begin with ., or that match *autom4te* to release tar & zip files. (#4009) * Fix some output issues with ph5diff (#4008) * Update install texts (#4010) * Add C in project line for CMake to fix #4012. (#4014) * separate out individual checks for string removal (#4015) * Add compound subset ops on attributes to API tests (#4005) ---------
Diffstat (limited to 'test/API/H5_api_attribute_test.c')
-rw-r--r--test/API/H5_api_attribute_test.c535
1 files changed, 534 insertions, 1 deletions
diff --git a/test/API/H5_api_attribute_test.c b/test/API/H5_api_attribute_test.c
index 680ee43..fd56be8 100644
--- a/test/API/H5_api_attribute_test.c
+++ b/test/API/H5_api_attribute_test.c
@@ -51,6 +51,8 @@ static int test_attribute_iterate_datatype(void);
static int test_attribute_iterate_index_saving(void);
static int test_attribute_iterate_invalid_params(void);
static int test_attribute_iterate_0_attributes(void);
+static int test_attribute_compound_subset(void);
+static int test_attribute_string_encodings(void);
static int test_delete_attribute(void);
static int test_delete_attribute_invalid_params(void);
static int test_attribute_exists(void);
@@ -99,6 +101,8 @@ static int (*attribute_tests[])(void) = {test_create_attribute_on_root,
test_attribute_iterate_index_saving,
test_attribute_iterate_invalid_params,
test_attribute_iterate_0_attributes,
+ test_attribute_compound_subset,
+ test_attribute_string_encodings,
test_delete_attribute,
test_delete_attribute_invalid_params,
test_attribute_exists,
@@ -8333,6 +8337,535 @@ error:
return 1;
}
+/* A compound type for test_attribute_compound_subset */
+typedef struct attribute_compound_io_t {
+ int a;
+ int b;
+} attribute_compound_io_t;
+
+/*
+ * A test to ensure that data is read back correctly from a attribute after it has
+ * been written, using subsets of compound datatypes
+ */
+static int
+test_attribute_compound_subset(void)
+{
+ hsize_t dims[1] = {ATTRIBUTE_COMPOUND_IO_ATTR_DIMS};
+ size_t i;
+ hid_t file_id = H5I_INVALID_HID;
+ hid_t container_group = H5I_INVALID_HID, group_id = H5I_INVALID_HID;
+ hid_t attr_id = H5I_INVALID_HID;
+ hid_t space_id = H5I_INVALID_HID;
+ hid_t full_type_id = H5I_INVALID_HID;
+ hid_t a_type_id = H5I_INVALID_HID;
+ hid_t b_type_id = H5I_INVALID_HID;
+ attribute_compound_io_t wbuf[ATTRIBUTE_COMPOUND_IO_ATTR_DIMS];
+ attribute_compound_io_t rbuf[ATTRIBUTE_COMPOUND_IO_ATTR_DIMS];
+ attribute_compound_io_t fbuf[ATTRIBUTE_COMPOUND_IO_ATTR_DIMS];
+ attribute_compound_io_t erbuf[ATTRIBUTE_COMPOUND_IO_ATTR_DIMS];
+
+ TESTING_MULTIPART(
+ "verification of attribute data using H5Awrite then H5Aread with compound type subsets");
+
+ /* 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_ATTR_BASIC)) {
+ SKIPPED();
+ printf(
+ " API functions for basic file, group, or attribute aren't supported with this connector\n");
+ return 0;
+ }
+
+ TESTING_2("test setup");
+
+ 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 ((group_id = H5Gcreate2(container_group, ATTRIBUTE_COMPOUND_IO_TEST_GROUP_NAME, H5P_DEFAULT,
+ H5P_DEFAULT, H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't create container sub-group '%s'\n", ATTRIBUTE_COMPOUND_IO_TEST_GROUP_NAME);
+ goto error;
+ }
+
+ if ((space_id = H5Screate_simple(1, dims, NULL)) < 0)
+ TEST_ERROR;
+
+ if ((full_type_id = H5Tcreate(H5T_COMPOUND, sizeof(attribute_compound_io_t))) < 0)
+ TEST_ERROR;
+ if (H5Tinsert(full_type_id, "a", HOFFSET(attribute_compound_io_t, a), H5T_NATIVE_INT) < 0)
+ TEST_ERROR;
+ if (H5Tinsert(full_type_id, "b", HOFFSET(attribute_compound_io_t, b), H5T_NATIVE_INT) < 0)
+ TEST_ERROR;
+
+ if ((a_type_id = H5Tcreate(H5T_COMPOUND, sizeof(attribute_compound_io_t))) < 0)
+ TEST_ERROR;
+ if (H5Tinsert(a_type_id, "a", HOFFSET(attribute_compound_io_t, a), H5T_NATIVE_INT) < 0)
+ TEST_ERROR;
+
+ if ((b_type_id = H5Tcreate(H5T_COMPOUND, sizeof(attribute_compound_io_t))) < 0)
+ TEST_ERROR;
+ if (H5Tinsert(b_type_id, "b", HOFFSET(attribute_compound_io_t, b), H5T_NATIVE_INT) < 0)
+ TEST_ERROR;
+
+ if ((attr_id = H5Acreate2(group_id, ATTRIBUTE_COMPOUND_IO_TEST_ATTR_NAME, full_type_id, space_id,
+ H5P_DEFAULT, H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't create attribute '%s'\n", ATTRIBUTE_COMPOUND_IO_TEST_ATTR_NAME);
+ goto error;
+ }
+
+ PASSED();
+
+ BEGIN_MULTIPART
+ {
+ PART_BEGIN(write_full_read_full)
+ {
+ TESTING_2("H5Awrite then H5Aread with all compound members");
+
+ /* Initialize wbuf */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ wbuf[i].a = (int)(2 * i);
+ wbuf[i].b = (int)(2 * i + 1);
+ }
+
+ /* Write data */
+ if (H5Awrite(attr_id, full_type_id, wbuf) < 0)
+ PART_TEST_ERROR(write_full_read_full);
+
+ /* Update fbuf to match file state */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ fbuf[i].a = wbuf[i].a;
+ fbuf[i].b = wbuf[i].b;
+ }
+
+ /* Initialize rbuf to -1 */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ rbuf[i].a = -1;
+ rbuf[i].b = -1;
+ }
+
+ /* Set erbuf (simply match file state since we're reading the whole
+ * thing) */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ erbuf[i].a = fbuf[i].a;
+ erbuf[i].b = fbuf[i].b;
+ }
+
+ /* Read data */
+ if (H5Aread(attr_id, full_type_id, rbuf) < 0)
+ PART_TEST_ERROR(write_full_read_full);
+
+ /* Verify data */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ if (rbuf[i].a != erbuf[i].a)
+ PART_TEST_ERROR(write_full_read_full);
+ if (rbuf[i].b != erbuf[i].b)
+ PART_TEST_ERROR(write_full_read_full);
+ }
+
+ PASSED();
+ }
+ PART_END(write_full_read_full);
+
+ PART_BEGIN(read_a)
+ {
+ TESTING_2("H5Aread with compound member a");
+
+ /* Initialize rbuf to -1 */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ rbuf[i].a = -1;
+ rbuf[i].b = -1;
+ }
+
+ /* Set erbuf (element a comes from the file, element b in untouched)
+ */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ erbuf[i].a = fbuf[i].a;
+ erbuf[i].b = rbuf[i].b;
+ }
+
+ /* Read data */
+ if (H5Aread(attr_id, a_type_id, rbuf) < 0)
+ PART_TEST_ERROR(read_a);
+
+ /* Verify data */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ if (rbuf[i].a != erbuf[i].a)
+ PART_TEST_ERROR(read_a);
+ if (rbuf[i].b != erbuf[i].b)
+ PART_TEST_ERROR(read_a);
+ }
+
+ PASSED();
+ }
+ PART_END(read_a);
+
+ PART_BEGIN(write_b_read_full)
+ {
+ TESTING_2("H5Awrite with compound member b then H5Aread with all compound members");
+
+ /* Initialize wbuf */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ wbuf[i].a = (int)(2 * ATTRIBUTE_COMPOUND_IO_ATTR_DIMS + 2 * i);
+ wbuf[i].b = (int)(2 * ATTRIBUTE_COMPOUND_IO_ATTR_DIMS + 2 * i + 1);
+ }
+
+ /* Write data */
+ if (H5Awrite(attr_id, b_type_id, wbuf) < 0)
+ PART_TEST_ERROR(write_b_read_full);
+
+ /* Update fbuf to match file state - only element b was updated */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ fbuf[i].b = wbuf[i].b;
+ }
+
+ /* Initialize rbuf to -1 */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ rbuf[i].a = -1;
+ rbuf[i].b = -1;
+ }
+
+ /* Set erbuf (simply match file state since we're reading the whole
+ * thing) */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ erbuf[i].a = fbuf[i].a;
+ erbuf[i].b = fbuf[i].b;
+ }
+
+ /* Read data */
+ if (H5Aread(attr_id, full_type_id, rbuf) < 0)
+ PART_TEST_ERROR(write_b_read_full);
+
+ /* Verify data */
+ for (i = 0; i < ATTRIBUTE_COMPOUND_IO_ATTR_DIMS; i++) {
+ if (rbuf[i].a != erbuf[i].a)
+ PART_TEST_ERROR(write_b_read_full);
+ if (rbuf[i].b != erbuf[i].b)
+ PART_TEST_ERROR(write_b_read_full);
+ }
+
+ PASSED();
+ }
+ PART_END(write_b_read_full);
+ }
+ END_MULTIPART;
+
+ TESTING_2("test cleanup");
+
+ if (H5Sclose(space_id) < 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 (H5Tclose(full_type_id) < 0)
+ TEST_ERROR;
+ if (H5Tclose(a_type_id) < 0)
+ TEST_ERROR;
+ if (H5Tclose(b_type_id) < 0)
+ TEST_ERROR;
+
+ PASSED();
+
+ return 0;
+
+error:
+ H5E_BEGIN_TRY
+ {
+ H5Sclose(space_id);
+ H5Aclose(attr_id);
+ H5Gclose(group_id);
+ H5Gclose(container_group);
+ H5Fclose(file_id);
+ H5Tclose(full_type_id);
+ H5Tclose(a_type_id);
+ H5Tclose(b_type_id);
+ }
+ H5E_END_TRY;
+
+ return 1;
+}
+
+/*
+ * A test to check that attributes preserve data
+ * correctness for strings with ASCII or UTF-8 char sets
+ */
+static int
+test_attribute_string_encodings(void)
+{
+ hid_t file_id = H5I_INVALID_HID;
+ hid_t container_group = H5I_INVALID_HID;
+ hid_t dset_id1 = H5I_INVALID_HID;
+ hid_t dset_id2 = H5I_INVALID_HID;
+ hid_t type_id1 = H5I_INVALID_HID;
+ hid_t type_id2 = H5I_INVALID_HID;
+ hid_t space_id = H5I_INVALID_HID;
+ hid_t attr_id1 = H5I_INVALID_HID;
+ hid_t attr_id2 = H5I_INVALID_HID;
+ hsize_t dims[ATTRIBUTE_STRING_ENCODINGS_RANK] = {ATTRIBUTE_STRING_ENCODINGS_EXTENT};
+ size_t ascii_str_size = 0;
+ size_t utf8_str_size = 0;
+ char *write_buf = NULL;
+ char *read_buf = NULL;
+
+ TESTING_MULTIPART("string encoding read/write correctness on attributes");
+
+ /* Make sure the connector supports the API functions being tested */
+ if (!(vol_cap_flags_g & H5VL_CAP_FLAG_FILE_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_GROUP_BASIC) ||
+ !(vol_cap_flags_g & H5VL_CAP_FLAG_DATASET_BASIC) || !(vol_cap_flags_g & H5VL_CAP_FLAG_ATTR_BASIC)) {
+ SKIPPED();
+ printf(" API functions for basic file, group, basic or more dataset aren't supported with this "
+ "connector\n");
+ return 0;
+ }
+
+ TESTING_2("test setup");
+
+ ascii_str_size = strlen(ATTRIBUTE_STRING_ENCODINGS_ASCII_STRING);
+ utf8_str_size = strlen(ATTRIBUTE_STRING_ENCODINGS_UTF8_STRING);
+
+ if ((file_id = H5Fopen(H5_api_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't open file '%s'\n", H5_api_test_filename);
+ goto error;
+ }
+
+ if ((container_group = H5Gopen2(file_id, ATTRIBUTE_TEST_GROUP_NAME, H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't open container group '%s'\n", ATTRIBUTE_TEST_GROUP_NAME);
+ goto error;
+ }
+
+ if ((space_id = H5Screate_simple(ATTRIBUTE_STRING_ENCODINGS_RANK, dims, NULL)) < 0) {
+ H5_FAILED();
+ printf(" couldn't create dataspace\n");
+ goto error;
+ }
+
+ if ((type_id1 = H5Tcopy(H5T_C_S1)) < 0) {
+ H5_FAILED();
+ printf(" couldn't copy builtin string datatype\n");
+ goto error;
+ }
+
+ if ((H5Tset_size(type_id1, ascii_str_size)) < 0) {
+ H5_FAILED();
+ printf(" couldn't set size of string datatype\n");
+ goto error;
+ }
+
+ if ((H5Tset_cset(type_id1, H5T_CSET_ASCII)) < 0) {
+ H5_FAILED();
+ printf(" couldn't set character set of string to ASCII\n");
+ goto error;
+ }
+
+ if ((dset_id1 = H5Dcreate(container_group, ATTRIBUTE_STRING_ENCODINGS_DSET_NAME1, type_id1, space_id,
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't create dataset with ascii string\n");
+ goto error;
+ }
+
+ if ((attr_id1 = H5Acreate(dset_id1, ATTRIBUTE_STRING_ENCODINGS_ATTR_NAME1, type_id1, space_id,
+ H5P_DEFAULT, H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't create attribute with ascii string\n");
+ goto error;
+ }
+
+ if ((type_id2 = H5Tcopy(H5T_C_S1)) < 0) {
+ H5_FAILED();
+ printf(" couldn't copy builtin string datatype\n");
+ goto error;
+ }
+
+ if ((H5Tset_size(type_id2, utf8_str_size)) < 0) {
+ H5_FAILED();
+ printf(" couldn't set size of string datatype\n");
+ goto error;
+ }
+
+ if ((H5Tset_cset(type_id2, H5T_CSET_UTF8)) < 0) {
+ H5_FAILED();
+ printf(" couldn't set character set of string to UTF-8\n");
+ goto error;
+ }
+
+ if ((dset_id2 = H5Dcreate(container_group, ATTRIBUTE_STRING_ENCODINGS_DSET_NAME2, type_id2, space_id,
+ H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't create dataset with UTF-8 string\n");
+ goto error;
+ }
+
+ if ((attr_id2 = H5Acreate(dset_id2, ATTRIBUTE_STRING_ENCODINGS_ATTR_NAME2, type_id2, space_id,
+ H5P_DEFAULT, H5P_DEFAULT)) < 0) {
+ H5_FAILED();
+ printf(" couldn't create attribute with ascii string\n");
+ goto error;
+ }
+
+ PASSED();
+
+ BEGIN_MULTIPART
+ {
+ PART_BEGIN(ASCII_cset)
+ {
+ TESTING_2("ASCII character set");
+ if ((write_buf = calloc(1, ascii_str_size + 1)) == NULL) {
+ H5_FAILED();
+ printf(" couldn't allocate memory for write buffer\n");
+ PART_ERROR(ASCII_cset);
+ }
+
+ memcpy(write_buf, ATTRIBUTE_STRING_ENCODINGS_ASCII_STRING, ascii_str_size);
+
+ if ((read_buf = calloc(1, ascii_str_size + 1)) == NULL) {
+ H5_FAILED();
+ printf(" couldn't allocate memory for read buffer\n");
+ PART_ERROR(ASCII_cset);
+ }
+
+ if (H5Awrite(attr_id1, type_id1, write_buf) < 0) {
+ H5_FAILED();
+ printf(" couldn't write to attribute with ASCII string\n");
+ PART_ERROR(ASCII_cset);
+ }
+
+ if (H5Aread(attr_id1, type_id1, read_buf) < 0) {
+ H5_FAILED();
+ printf(" couldn't read from attribute with ASCII string\n");
+ PART_ERROR(ASCII_cset);
+ }
+
+ if (strncmp(write_buf, read_buf, ascii_str_size)) {
+ H5_FAILED();
+ printf(" incorrect data read from attribute with ASCII string\n");
+ PART_ERROR(ASCII_cset);
+ }
+
+ free(write_buf);
+ write_buf = NULL;
+
+ free(read_buf);
+ read_buf = NULL;
+
+ PASSED();
+ }
+ PART_END(ASCII_cset);
+
+ PART_BEGIN(UTF8_cset)
+ {
+ TESTING_2("UTF-8 character set");
+
+ if ((write_buf = calloc(1, utf8_str_size + 1)) == NULL) {
+ H5_FAILED();
+ printf(" couldn't allocate memory for write buffer\n");
+ PART_ERROR(UTF8_cset);
+ }
+
+ memcpy(write_buf, ATTRIBUTE_STRING_ENCODINGS_UTF8_STRING, utf8_str_size);
+
+ if ((read_buf = calloc(1, utf8_str_size + 1)) == NULL) {
+ H5_FAILED();
+ printf(" couldn't allocate memory for read buffer\n");
+ PART_ERROR(UTF8_cset);
+ }
+
+ if (H5Awrite(attr_id2, type_id2, write_buf) < 0) {
+ H5_FAILED();
+ printf(" couldn't write to attribute with UTF-8 string\n");
+ PART_ERROR(UTF8_cset);
+ }
+
+ if (H5Aread(attr_id2, type_id2, read_buf) < 0) {
+ H5_FAILED();
+ printf(" couldn't read from attribute with UTF-8 string\n");
+ PART_ERROR(UTF8_cset);
+ }
+
+ if (strncmp(write_buf, read_buf, utf8_str_size)) {
+ H5_FAILED();
+ printf(" incorrect data read from attribute with UTF-8 string\n");
+ PART_ERROR(UTF8_cset);
+ }
+
+ free(write_buf);
+ write_buf = NULL;
+
+ free(read_buf);
+ read_buf = NULL;
+
+ PASSED();
+ }
+ PART_END(UTF8_cset);
+
+ PASSED();
+ }
+ END_MULTIPART;
+
+ TESTING_2("test cleanup");
+
+ if (H5Fclose(file_id) < 0)
+ TEST_ERROR;
+ if (H5Gclose(container_group) < 0)
+ TEST_ERROR;
+ if (H5Dclose(dset_id1) < 0)
+ TEST_ERROR;
+ if (H5Dclose(dset_id2) < 0)
+ TEST_ERROR;
+ if (H5Tclose(type_id1) < 0)
+ TEST_ERROR;
+ if (H5Tclose(type_id2) < 0)
+ TEST_ERROR;
+ if (H5Aclose(attr_id1) < 0)
+ TEST_ERROR;
+ if (H5Aclose(attr_id2) < 0)
+ TEST_ERROR;
+ if (write_buf)
+ free(write_buf);
+ if (read_buf)
+ free(read_buf);
+ PASSED();
+
+ return 0;
+
+error:
+ H5E_BEGIN_TRY
+ {
+ H5Fclose(file_id);
+ H5Gclose(container_group);
+ H5Dclose(dset_id1);
+ H5Dclose(dset_id2);
+ H5Tclose(type_id1);
+ H5Tclose(type_id2);
+ H5Aclose(attr_id1);
+ H5Aclose(attr_id2);
+ if (write_buf)
+ free(write_buf);
+ if (read_buf)
+ free(read_buf);
+ }
+ H5E_END_TRY;
+
+ return 1;
+}
+
/*
* A test to check that an attribute can be deleted
* using H5Adelete(_by_idx).
@@ -10457,7 +10990,7 @@ test_attribute_many(void)
/* Create many attributes */
for (u = 0; u < ATTRIBUTE_MANY_NUMB; u++) {
- sprintf(attrname, "many-%06u", u);
+ snprintf(attrname, sizeof(attrname), "many-%06u", u);
if ((attr_id = H5Acreate2(group_id, attrname, attr_dtype, space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();