diff options
Diffstat (limited to 'test/getname.c')
-rw-r--r-- | test/getname.c | 96 |
1 files changed, 55 insertions, 41 deletions
diff --git a/test/getname.c b/test/getname.c index 18a8c4d..842f6db 100644 --- a/test/getname.c +++ b/test/getname.c @@ -2431,6 +2431,7 @@ test_obj_ref(hid_t fapl) hsize_t dims1[] = {SPACE1_DIM1}; hobj_ref_t wbuf[SPACE1_DIM1]; /* Buffer to write to disk */ int tu32[SPACE1_DIM1]; /* Int data */ + ssize_t namelen; /* Length of the name */ int i; /* counting variables */ char buf[100]; @@ -2573,96 +2574,104 @@ test_obj_ref(hid_t fapl) TESTING("getting path to normal dataset in root group"); if((dataset2 = H5Rdereference(dataset, H5R_OBJECT, &wbuf[0])) < 0) FAIL_STACK_ERROR *buf = '\0'; - i = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); + namelen = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); if(H5Dclose(dataset2) < 0) FAIL_STACK_ERROR - if(!((HDstrcmp(buf, "/Dataset3") == 0) &&(i == 9))) TEST_ERROR + if(!((HDstrcmp(buf, "/Dataset3") == 0) &&(namelen == 9))) TEST_ERROR *buf = '\0'; - i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[0], (char*)buf, sizeof(buf)); - if(!((HDstrcmp(buf, "/Dataset3") == 0) &&(i == 9))) TEST_ERROR + + /* Check H5Rget_name returns the correct length of the name when name is NULL */ + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[0], NULL, 0); + if(namelen != 9) TEST_ERROR + /* Make sure size parameter is ignored */ + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[0], NULL, 200); + if(namelen != 9) TEST_ERROR + + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[0], (char*)buf, sizeof(buf)); + if(!((HDstrcmp(buf, "/Dataset3") == 0) &&(namelen == 9))) TEST_ERROR PASSED() HDmemset(buf, 0, sizeof(buf)); TESTING("getting path to dataset in /Group1"); if((dataset2 = H5Rdereference(dataset, H5R_OBJECT, &wbuf[1])) < 0) FAIL_STACK_ERROR *buf = '\0'; - i = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); + namelen = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); if(H5Dclose(dataset2) < 0) FAIL_STACK_ERROR - if(!((HDstrcmp(buf, "/Group1/Dataset2") == 0) &&(i == 16))) TEST_ERROR + if(!((HDstrcmp(buf, "/Group1/Dataset2") == 0) &&(namelen == 16))) TEST_ERROR *buf = '\0'; - i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[1], (char*)buf, sizeof(buf)); - if(!((HDstrcmp(buf, "/Group1/Dataset2") == 0) &&(i == 16))) TEST_ERROR + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[1], (char*)buf, sizeof(buf)); + if(!((HDstrcmp(buf, "/Group1/Dataset2") == 0) &&(namelen == 16))) TEST_ERROR PASSED() HDmemset(buf, 0, sizeof(buf)); TESTING("getting path to /Group1"); if((group = H5Rdereference(dataset, H5R_OBJECT, &wbuf[2])) < 0) FAIL_STACK_ERROR *buf = '\0'; - i = H5Iget_name(group, (char*)buf, sizeof(buf)); + namelen = H5Iget_name(group, (char*)buf, sizeof(buf)); if(H5Gclose(group) < 0) FAIL_STACK_ERROR - if(!((HDstrcmp(buf, "/Group1") == 0) &&(i == 7))) TEST_ERROR + if(!((HDstrcmp(buf, "/Group1") == 0) &&(namelen == 7))) TEST_ERROR *buf = '\0'; - i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[2], (char*)buf, sizeof(buf)); - if(!((HDstrcmp(buf, "/Group1") == 0) &&(i == 7))) TEST_ERROR + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[2], (char*)buf, sizeof(buf)); + if(!((HDstrcmp(buf, "/Group1") == 0) &&(namelen == 7))) TEST_ERROR PASSED() HDmemset(buf, 0, sizeof(buf)); TESTING("getting path to datatype in /Group1"); if((tid1 = H5Rdereference(dataset, H5R_OBJECT, &wbuf[3])) < 0) FAIL_STACK_ERROR *buf = '\0'; - i = H5Iget_name(tid1, (char*)buf, sizeof(buf)); + namelen = H5Iget_name(tid1, (char*)buf, sizeof(buf)); if(H5Tclose(tid1) < 0) FAIL_STACK_ERROR - if(!((HDstrcmp(buf, "/Group1/Datatype1") == 0) &&(i == 17))) TEST_ERROR + if(!((HDstrcmp(buf, "/Group1/Datatype1") == 0) &&(namelen == 17))) TEST_ERROR *buf = '\0'; - i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[3], (char*)buf, sizeof(buf)); - if(!((HDstrcmp(buf, "/Group1/Datatype1") == 0) &&(i == 17))) TEST_ERROR + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[3], (char*)buf, sizeof(buf)); + if(!((HDstrcmp(buf, "/Group1/Datatype1") == 0) &&(namelen == 17))) TEST_ERROR PASSED() HDmemset(buf, 0, sizeof(buf)); TESTING("getting path to dataset in nested group"); if((dataset2 = H5Rdereference(dataset, H5R_OBJECT, &wbuf[4])) < 0) FAIL_STACK_ERROR *buf = '\0'; - i = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); + namelen = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); if(H5Dclose(dataset2) < 0) FAIL_STACK_ERROR - if(!((HDstrcmp(buf, "/Group1/Group2/Dataset4") == 0) &&(i == 23))) TEST_ERROR + if(!((HDstrcmp(buf, "/Group1/Group2/Dataset4") == 0) &&(namelen == 23))) TEST_ERROR *buf = '\0'; - i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[4], (char*)buf, sizeof(buf)); - if(!((HDstrcmp(buf, "/Group1/Group2/Dataset4") == 0) &&(i == 23))) TEST_ERROR + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[4], (char*)buf, sizeof(buf)); + if(!((HDstrcmp(buf, "/Group1/Group2/Dataset4") == 0) &&(namelen == 23))) TEST_ERROR PASSED() HDmemset(buf, 0, sizeof(buf)); TESTING("getting path to nested group"); if((group = H5Rdereference(dataset, H5R_OBJECT, &wbuf[5])) < 0) FAIL_STACK_ERROR *buf = '\0'; - i = H5Iget_name(group, (char*)buf, sizeof(buf)); + namelen = H5Iget_name(group, (char*)buf, sizeof(buf)); if(H5Gclose(group) < 0) FAIL_STACK_ERROR - if(!((HDstrcmp(buf, "/Group1/Group2") == 0) &&(i == 14))) TEST_ERROR + if(!((HDstrcmp(buf, "/Group1/Group2") == 0) &&(namelen == 14))) TEST_ERROR *buf = '\0'; - i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[5], (char*)buf, sizeof(buf)); - if(!((HDstrcmp(buf, "/Group1/Group2") == 0) &&(i == 14))) TEST_ERROR + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[5], (char*)buf, sizeof(buf)); + if(!((HDstrcmp(buf, "/Group1/Group2") == 0) &&(namelen == 14))) TEST_ERROR PASSED() HDmemset(buf, 0, sizeof(buf)); TESTING("getting path to dataset created via hard link"); if((dataset2 = H5Rdereference(dataset, H5R_OBJECT, &wbuf[6])) < 0) FAIL_STACK_ERROR *buf = '\0'; - i = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); + namelen = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); if(H5Dclose(dataset2) < 0) FAIL_STACK_ERROR - if(!((HDstrcmp(buf, "/Group1/Dataset5") == 0) &&(i == 16))) TEST_ERROR + if(!((HDstrcmp(buf, "/Group1/Dataset5") == 0) &&(namelen == 16))) TEST_ERROR *buf = '\0'; - i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[6], (char*)buf, sizeof(buf)); - if(!((HDstrcmp(buf, "/Group1/Dataset5") == 0) &&(i == 16))) TEST_ERROR + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[6], (char*)buf, sizeof(buf)); + if(!((HDstrcmp(buf, "/Group1/Dataset5") == 0) &&(namelen == 16))) TEST_ERROR PASSED() HDmemset(buf, 0, sizeof(buf)); TESTING("getting path to root group"); if((group = H5Rdereference(dataset, H5R_OBJECT, &wbuf[7])) < 0) FAIL_STACK_ERROR *buf = '\0'; - i = H5Iget_name(group, (char*)buf, sizeof(buf)); + namelen = H5Iget_name(group, (char*)buf, sizeof(buf)); if(H5Gclose(group) < 0) FAIL_STACK_ERROR - if(!((HDstrcmp(buf, "/") == 0) &&(i == 1))) TEST_ERROR + if(!((HDstrcmp(buf, "/") == 0) &&(namelen == 1))) TEST_ERROR *buf = '\0'; - i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[7], (char*)buf, sizeof(buf)); - if(!((HDstrcmp(buf, "/") == 0) &&(i == 1))) TEST_ERROR + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[7], (char*)buf, sizeof(buf)); + if(!((HDstrcmp(buf, "/") == 0) &&(namelen == 1))) TEST_ERROR PASSED() /* Now we mount fid2 at /Group2 and look for dataset4. It shouldn't be found */ @@ -2672,12 +2681,12 @@ test_obj_ref(hid_t fapl) TESTING("getting path to dataset hidden by a mounted file"); if((dataset2 = H5Rdereference(dataset, H5R_OBJECT, &wbuf[4])) < 0) FAIL_STACK_ERROR *buf = '\0'; - i = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); + namelen = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); if(H5Dclose(dataset2) < 0) FAIL_STACK_ERROR - if(i != 0) TEST_ERROR + if(namelen != 0) TEST_ERROR *buf = '\0'; - i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[4], (char*)buf, sizeof(buf)); - if(i != 0) TEST_ERROR + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[4], (char*)buf, sizeof(buf)); + if(namelen != 0) TEST_ERROR PASSED() /* Now we try unlinking dataset2 from the file and searching for it. It shouldn't be found */ @@ -2688,12 +2697,12 @@ test_obj_ref(hid_t fapl) TESTING("getting path to dataset that has been unlinked"); *buf = '\0'; - i = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); + namelen = H5Iget_name(dataset2, (char*)buf, sizeof(buf)); if(H5Dclose(dataset2) < 0) FAIL_STACK_ERROR - if(i != 0) TEST_ERROR + if(namelen != 0) TEST_ERROR *buf = '\0'; - i = H5Rget_name(dataset, H5R_OBJECT, &wbuf[1], (char*)buf, sizeof(buf)); - if(i != 0) TEST_ERROR + namelen = H5Rget_name(dataset, H5R_OBJECT, &wbuf[1], (char*)buf, sizeof(buf)); + if(namelen != 0) TEST_ERROR PASSED() /* Close disk dataspace */ @@ -2814,7 +2823,12 @@ test_reg_ref(hid_t fapl) /* Get name of the dataset the first region reference points to using H5Rget_name */ TESTING("H5Rget_name to get name from region reference(hyperslab)"); *buf1 = '\0'; - name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], (char*)buf1, NAME_BUF_SIZE); + + /* Check H5Rget_name returns the correct length of the name when name is NULL */ + name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], NULL, 0); + if(name_size1 != 7) TEST_ERROR + + name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], (char*)buf1, NAME_BUF_SIZE ); if(!((HDstrcmp(buf1, "/MATRIX") == 0) &&(name_size1 == 7))) TEST_ERROR PASSED() |