diff --git a/hl/src/H5LT.c b/hl/src/H5LT.c index 7d44792fbc0..7b55cedeb3b 100644 --- a/hl/src/H5LT.c +++ b/hl/src/H5LT.c @@ -1228,7 +1228,7 @@ find_dataset(H5_ATTR_UNUSED hid_t loc_id, const char *name, H5_ATTR_UNUSED const * cause the iterator to immediately return that positive value, * indicating short-circuit success */ - if (strncmp(name, (char *)op_data, strlen((char *)op_data)) == 0) + if (strcmp(name, (char *)op_data) == 0) ret = 1; return ret; diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c index f85ed81b7fb..0172cb45a22 100644 --- a/hl/test/test_ds.c +++ b/hl/test/test_ds.c @@ -1341,10 +1341,11 @@ test_detachscales(void) static int test_char_attachscales(const char *fileext) { - hid_t fid = -1; - hid_t did = -1; - char dsname[32]; - char scalename[32]; + hid_t fid = -1; + hid_t did = -1; + char dsname[32]; + char scalename[32]; + herr_t ds_existed = 0; snprintf(dsname, sizeof(dsname), "%s%s", DATASET_NAME, "ac"); @@ -1357,6 +1358,14 @@ test_char_attachscales(const char *fileext) if (create_char_dataset(fid, "ac", 0) < 0) goto out; + /* test finding dataset dsname */ + if ((ds_existed = H5LTfind_dataset(fid, dsname)) < 0) + goto out; + if (ds_existed == 0) { + printf("Unexpected result: Dataset \"%s\" does exist\n", dsname); + goto out; + } + if ((did = H5Dopen2(fid, dsname, H5P_DEFAULT)) >= 0) { snprintf(scalename, sizeof(scalename), "%s%s", DS_1_NAME, "ac"); if (test_attach_scale(fid, did, scalename, DIM0) < 0) diff --git a/hl/test/test_lite.c b/hl/test/test_lite.c index 9bbad45d609..bae90b13e22 100644 --- a/hl/test/test_lite.c +++ b/hl/test/test_lite.c @@ -29,6 +29,9 @@ #define DSET6_NAME "dataset double" #define DSET7_NAME "dataset string" +/* Name of a non-existing dataset, do not create a dataset with this name */ +#define NODS_NAME "dataset" + #define DIM 6 #define ATTR_NAME_SUB "att" @@ -60,6 +63,7 @@ test_dsets(void) hsize_t dims[2] = {2, 3}; hid_t file_id; hid_t dataset_id; + herr_t ds_existed = 0; /* whether searched ds exists */ char data_char_in[DIM] = {1, 2, 3, 4, 5, 6}; char data_char_out[DIM]; short data_short_in[DIM] = {1, 2, 3, 4, 5, 6}; @@ -348,6 +352,23 @@ test_dsets(void) if (strcmp(data_string_in, data_string_out) != 0) goto out; + PASSED(); + + /*------------------------------------------------------------------------- + * H5LTfind_dataset test + *------------------------------------------------------------------------- + */ + + HL_TESTING2("H5LTfind_dataset"); + + /* Try to find a non-existing ds whose name matches existing datasets partially */ + if ((ds_existed = H5LTfind_dataset(file_id, NODS_NAME)) < 0) + goto out; + if (ds_existed > 0) { + printf("Dataset \"%s\" does not exist.\n", NODS_NAME); + goto out; + } + /*------------------------------------------------------------------------- * end tests *------------------------------------------------------------------------- @@ -1075,7 +1096,7 @@ test_integers(void) char *dt_str; size_t str_len; - HL_TESTING3("\n text for integer types"); + HL_TESTING3(" text for integer types"); if ((dtype = H5LTtext_to_dtype("H5T_NATIVE_INT\n", H5LT_DDL)) < 0) goto out; @@ -1881,6 +1902,7 @@ test_text_dtype(void) { HL_TESTING2("H5LTtext_to_dtype"); + printf("\n"); if (test_integers() < 0) goto out;