diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/tselect.c | 355 |
1 files changed, 354 insertions, 1 deletions
diff --git a/test/tselect.c b/test/tselect.c index fd577ca..3f18eb9 100644 --- a/test/tselect.c +++ b/test/tselect.c @@ -5672,7 +5672,7 @@ test_scalar_select(void) /**************************************************************** ** ** test_scalar_select2(): Tests selections on scalar dataspace, -** verify H5Shyperslab and H5Sselect_elements fails for +** verify H5Sselect_hyperslab and H5Sselect_elements fails for ** scalar dataspace. ** ****************************************************************/ @@ -5722,6 +5722,146 @@ test_scalar_select2(void) /**************************************************************** ** +** test_scalar_select3(): Test basic H5S (dataspace) selection code. +** Tests selections on scalar dataspaces in memory +** +****************************************************************/ +static void +test_scalar_select3(void) +{ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t sid1,sid2; /* Dataspace ID */ + hsize_t dims2[] = {SPACE7_DIM1, SPACE7_DIM2}; + hsize_t coord1[SPACE7_RANK]; /* Coordinates for point selection */ + hsize_t start[SPACE7_RANK]; /* Hyperslab start */ + hsize_t count[SPACE7_RANK]; /* Hyperslab block count */ + uint8_t wval_uint8, /* Value written out */ + rval_uint8; /* Value read in */ + unsigned short wval_ushort, /* Another value written out */ + rval_ushort; /* Another value read in */ + herr_t ret; /* Generic return value */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing I/O on Selections in Scalar Dataspaces in Memory\n")); + + /* Create file */ + fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid1, FAIL, "H5Fcreate"); + + /* Create dataspace for dataset */ + sid1 = H5Screate_simple(SPACE7_RANK, dims2, NULL); + CHECK(sid1, FAIL, "H5Screate_simple"); + + /* Create dataspace for writing buffer */ + sid2 = H5Screate(H5S_SCALAR); + CHECK(sid2, FAIL, "H5Screate_simple"); + + /* Create a dataset */ + dataset = H5Dcreate2(fid1, "Dataset1", H5T_NATIVE_UCHAR, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + CHECK(dataset, FAIL, "H5Dcreate2"); + + /* Select one element in file with a point selection */ + coord1[0] = 0; coord1[1] = 2; + ret = H5Sselect_elements(sid1, H5S_SELECT_SET, (size_t)1, (const hsize_t **)&coord1); + CHECK(ret, FAIL, "H5Sselect_elements"); + + /* Write single point to disk */ + wval_uint8 = 12; + ret = H5Dwrite(dataset, H5T_NATIVE_UCHAR, sid2, sid1, H5P_DEFAULT, &wval_uint8); + CHECK(ret, FAIL, "H5Dwrite"); + + /* Read scalar element from disk */ + rval_uint8 = 0; + ret = H5Dread(dataset, H5T_NATIVE_UCHAR, sid2, sid1, H5P_DEFAULT, &rval_uint8); + CHECK(ret, FAIL, "H5Dread"); + + /* Check value read back in */ + if(rval_uint8 != wval_uint8) + TestErrPrintf("%u: Error! rval=%u, should be: wval=%u\n", (unsigned)__LINE__, (unsigned)rval_uint8, (unsigned)wval_uint8); + + /* Write single point to disk (with a datatype conversion) */ + wval_ushort = 23; + ret = H5Dwrite(dataset, H5T_NATIVE_USHORT, sid2, sid1, H5P_DEFAULT, &wval_ushort); + CHECK(ret, FAIL, "H5Dwrite"); + + /* Read scalar element from disk */ + rval_ushort = 0; + ret = H5Dread(dataset, H5T_NATIVE_USHORT, sid2, sid1, H5P_DEFAULT, &rval_ushort); + CHECK(ret, FAIL, "H5Dread"); + + /* Check value read back in */ + if(rval_ushort != wval_ushort) + TestErrPrintf("%u: Error! rval=%u, should be: wval=%u\n", (unsigned)__LINE__, (unsigned)rval_ushort, (unsigned)wval_ushort); + + /* Select one element in file with a hyperslab selection */ + start[0] = 4; start[1] = 3; + count[0] = 1; count[1] = 1; + ret = H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL); + CHECK(ret, FAIL, "H5Sselect_hyperslab"); + + /* Write single hyperslab element to disk */ + wval_uint8 = 92; + ret = H5Dwrite(dataset, H5T_NATIVE_UCHAR, sid2, sid1, H5P_DEFAULT, &wval_uint8); + CHECK(ret, FAIL, "H5Dwrite"); + + /* Read scalar element from disk */ + rval_uint8 = 0; + ret = H5Dread(dataset, H5T_NATIVE_UCHAR, sid2, sid1, H5P_DEFAULT, &rval_uint8); + CHECK(ret, FAIL, "H5Dread"); + + /* Check value read back in */ + if(rval_uint8 != wval_uint8) + TestErrPrintf("%u: Error! rval=%u, should be: wval=%u\n", (unsigned)__LINE__, (unsigned)rval_uint8, (unsigned)wval_uint8); + + /* Write single hyperslab element to disk (with a datatype conversion) */ + wval_ushort = 107; + ret = H5Dwrite(dataset, H5T_NATIVE_USHORT, sid2, sid1, H5P_DEFAULT, &wval_ushort); + CHECK(ret, FAIL, "H5Dwrite"); + + /* Read scalar element from disk */ + rval_ushort = 0; + ret = H5Dread(dataset, H5T_NATIVE_USHORT, sid2, sid1, H5P_DEFAULT, &rval_ushort); + CHECK(ret, FAIL, "H5Dread"); + + /* Check value read back in */ + if(rval_ushort != wval_ushort) + TestErrPrintf("%u: Error! rval=%u, should be: wval=%u\n", (unsigned)__LINE__, (unsigned)rval_ushort, (unsigned)wval_ushort); + + /* Select no elements in memory & file with "none" selections */ + ret = H5Sselect_none(sid1); + CHECK(ret, FAIL, "H5Sselect_none"); + + ret = H5Sselect_none(sid2); + CHECK(ret, FAIL, "H5Sselect_none"); + + /* Write no data to disk */ + ret = H5Dwrite(dataset, H5T_NATIVE_UCHAR, sid2, sid1, H5P_DEFAULT, &wval_uint8); + CHECK(ret, FAIL, "H5Dwrite"); + + /* Write no data to disk (with a datatype conversion) */ + ret = H5Dwrite(dataset, H5T_NATIVE_USHORT, sid2, sid1, H5P_DEFAULT, &wval_ushort); + CHECK(ret, FAIL, "H5Dwrite"); + + /* Close memory dataspace */ + ret = H5Sclose(sid2); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close disk dataspace */ + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close Dataset */ + ret = H5Dclose(dataset); + CHECK(ret, FAIL, "H5Dclose"); + + /* Close file */ + ret = H5Fclose(fid1); + CHECK(ret, FAIL, "H5Fclose"); +} /* test_scalar_select3() */ + +/**************************************************************** +** ** test_shape_same(): Tests selections on dataspace, verify that ** "shape same" routine is working correctly. ** @@ -5744,6 +5884,8 @@ test_shape_same(void) hid_t regular_hyper_sid; /* Dataspace ID with regular hyperslab selection */ hid_t irreg_hyper_sid; /* Dataspace ID with irregular hyperslab selection */ hid_t none_hyper_sid; /* Dataspace ID with "no hyperslabs" selection */ + hid_t scalar_all_sid; /* ID for scalar dataspace with "all" selection */ + hid_t scalar_none_sid; /* ID for scalar dataspace with "none" selection */ hid_t tmp_sid; /* Temporary dataspace ID */ hsize_t dims[] = {SPACE9_DIM1, SPACE9_DIM2}; hsize_t coord1[1][SPACE2_RANK]; /* Coordinates for single point selection */ @@ -5885,6 +6027,18 @@ test_shape_same(void) ret = H5Sselect_hyperslab(none_hyper_sid,H5S_SELECT_XOR,start,stride,count,block); CHECK(ret, FAIL, "H5Sselect_hyperslab"); + /* Create scalar dataspace for "all" selection */ + scalar_all_sid = H5Screate(H5S_SCALAR); + CHECK(scalar_all_sid, FAIL, "H5Screate"); + + /* Create scalar dataspace for "none" selection */ + scalar_none_sid = H5Screate(H5S_SCALAR); + CHECK(scalar_none_sid, FAIL, "H5Screate"); + + /* Un-Select entire extent for dataspace */ + ret = H5Sselect_none(scalar_none_sid); + CHECK(ret, FAIL, "H5Sselect_none"); + /* Compare "all" selection to all the selections created */ /* Compare against itself */ check=H5S_select_shape_same_test(all_sid,all_sid); @@ -5936,6 +6090,14 @@ test_shape_same(void) check=H5S_select_shape_same_test(all_sid,none_hyper_sid); VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Compare against scalar "all" hyperslab selection */ + check = H5S_select_shape_same_test(all_sid, scalar_all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against scalar "none" hyperslab selection */ + check = H5S_select_shape_same_test(all_sid, scalar_none_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Compare "none" selection to all the selections created */ /* Compare against itself */ check=H5S_select_shape_same_test(none_sid,none_sid); @@ -5987,6 +6149,14 @@ test_shape_same(void) check=H5S_select_shape_same_test(none_sid,none_hyper_sid); VERIFY(check, TRUE, "H5S_select_shape_same_test"); + /* Compare against scalar "all" hyperslab selection */ + check = H5S_select_shape_same_test(none_sid, scalar_all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against scalar "none" hyperslab selection */ + check = H5S_select_shape_same_test(none_sid, scalar_none_sid); + VERIFY(check, TRUE, "H5S_select_shape_same_test"); + /* Compare single point selection to all the selections created */ /* Compare against itself */ check=H5S_select_shape_same_test(single_pt_sid,single_pt_sid); @@ -6038,6 +6208,14 @@ test_shape_same(void) check=H5S_select_shape_same_test(single_pt_sid,none_hyper_sid); VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Compare against scalar "all" hyperslab selection */ + check = H5S_select_shape_same_test(single_pt_sid, scalar_all_sid); + VERIFY(check, TRUE, "H5S_select_shape_same_test"); + + /* Compare against scalar "none" hyperslab selection */ + check = H5S_select_shape_same_test(single_pt_sid, scalar_none_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Compare multiple point selection to all the selections created */ /* Compare against itself */ check=H5S_select_shape_same_test(mult_pt_sid,mult_pt_sid); @@ -6089,6 +6267,14 @@ test_shape_same(void) check=H5S_select_shape_same_test(mult_pt_sid,none_hyper_sid); VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Compare against scalar "all" hyperslab selection */ + check = H5S_select_shape_same_test(mult_pt_sid, scalar_all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against scalar "none" hyperslab selection */ + check = H5S_select_shape_same_test(mult_pt_sid, scalar_none_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Compare single "normal" hyperslab selection to all the selections created */ /* Compare against itself */ check=H5S_select_shape_same_test(single_hyper_sid,single_hyper_sid); @@ -6195,6 +6381,14 @@ test_shape_same(void) ret = H5Sclose(tmp_sid); CHECK(ret, FAIL, "H5Sclose"); + /* Compare against scalar "all" hyperslab selection */ + check = H5S_select_shape_same_test(single_hyper_sid, scalar_all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against scalar "none" hyperslab selection */ + check = H5S_select_shape_same_test(single_hyper_sid, scalar_none_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Compare single "all" hyperslab selection to all the selections created */ /* Compare against itself */ check=H5S_select_shape_same_test(single_hyper_all_sid,single_hyper_all_sid); @@ -6301,6 +6495,14 @@ test_shape_same(void) ret = H5Sclose(tmp_sid); CHECK(ret, FAIL, "H5Sclose"); + /* Compare against scalar "all" hyperslab selection */ + check = H5S_select_shape_same_test(single_hyper_all_sid, scalar_all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against scalar "none" hyperslab selection */ + check = H5S_select_shape_same_test(single_hyper_all_sid, scalar_none_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Compare single "point" hyperslab selection to all the selections created */ /* Compare against itself */ check=H5S_select_shape_same_test(single_hyper_pt_sid,single_hyper_pt_sid); @@ -6352,6 +6554,14 @@ test_shape_same(void) check=H5S_select_shape_same_test(single_hyper_pt_sid,none_hyper_sid); VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Compare against scalar "all" hyperslab selection */ + check = H5S_select_shape_same_test(single_hyper_pt_sid, scalar_all_sid); + VERIFY(check, TRUE, "H5S_select_shape_same_test"); + + /* Compare against scalar "none" hyperslab selection */ + check = H5S_select_shape_same_test(single_hyper_pt_sid, scalar_none_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Compare regular, strided hyperslab selection to all the selections created */ /* Compare against itself */ check=H5S_select_shape_same_test(regular_hyper_sid,regular_hyper_sid); @@ -6470,6 +6680,14 @@ test_shape_same(void) ret = H5Sclose(tmp_sid); CHECK(ret, FAIL, "H5Sclose"); + /* Compare against scalar "all" hyperslab selection */ + check = H5S_select_shape_same_test(regular_hyper_sid, scalar_all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against scalar "none" hyperslab selection */ + check = H5S_select_shape_same_test(regular_hyper_sid, scalar_none_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Compare irregular hyperslab selection to all the selections created */ /* Compare against itself */ check=H5S_select_shape_same_test(irreg_hyper_sid,irreg_hyper_sid); @@ -6550,6 +6768,136 @@ test_shape_same(void) ret = H5Sclose(tmp_sid); CHECK(ret, FAIL, "H5Sclose"); + /* Compare against scalar "all" hyperslab selection */ + check = H5S_select_shape_same_test(irreg_hyper_sid, scalar_all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against scalar "none" hyperslab selection */ + check = H5S_select_shape_same_test(irreg_hyper_sid, scalar_none_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + + /* Compare scalar "all" dataspace with all selections created */ + + /* Compare against itself */ + check = H5S_select_shape_same_test(scalar_all_sid, scalar_all_sid); + VERIFY(check, TRUE, "H5S_select_shape_same_test"); + + /* Compare against copy of itself */ + tmp_sid = H5Scopy(scalar_all_sid); + CHECK(tmp_sid, FAIL, "H5Scopy"); + + check = H5S_select_shape_same_test(scalar_all_sid, tmp_sid); + VERIFY(check, TRUE, "H5S_select_shape_same_test"); + + ret = H5Sclose(tmp_sid); + CHECK(ret, FAIL, "H5Sclose"); + + /* Compare against "all" selection */ + check = H5S_select_shape_same_test(scalar_all_sid, all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against "none" selection */ + check = H5S_select_shape_same_test(scalar_all_sid, none_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against single point selection */ + check = H5S_select_shape_same_test(scalar_all_sid, single_pt_sid); + VERIFY(check, TRUE, "H5S_select_shape_same_test"); + + /* Compare against multiple point selection */ + check = H5S_select_shape_same_test(scalar_all_sid, mult_pt_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against "plain" single hyperslab selection */ + check = H5S_select_shape_same_test(scalar_all_sid, single_hyper_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against "all" single hyperslab selection */ + check = H5S_select_shape_same_test(scalar_all_sid, single_hyper_all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against "single point" single hyperslab selection */ + check = H5S_select_shape_same_test(scalar_all_sid, single_hyper_pt_sid); + VERIFY(check, TRUE, "H5S_select_shape_same_test"); + + /* Compare against regular, strided hyperslab selection */ + check = H5S_select_shape_same_test(scalar_all_sid, regular_hyper_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against irregular hyperslab selection */ + check = H5S_select_shape_same_test(scalar_all_sid, irreg_hyper_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against "no" hyperslab selection */ + check = H5S_select_shape_same_test(scalar_all_sid, none_hyper_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against scalar "none" hyperslab selection */ + check = H5S_select_shape_same_test(scalar_all_sid, scalar_none_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + + /* Compare scalar "none" dataspace with all selections created */ + + /* Compare against itself */ + check = H5S_select_shape_same_test(scalar_none_sid, scalar_none_sid); + VERIFY(check, TRUE, "H5S_select_shape_same_test"); + + /* Compare against copy of itself */ + tmp_sid = H5Scopy(scalar_none_sid); + CHECK(tmp_sid, FAIL, "H5Scopy"); + + check = H5S_select_shape_same_test(scalar_none_sid, tmp_sid); + VERIFY(check, TRUE, "H5S_select_shape_same_test"); + + ret = H5Sclose(tmp_sid); + CHECK(ret, FAIL, "H5Sclose"); + + /* Compare against "all" selection */ + check = H5S_select_shape_same_test(scalar_none_sid, all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against "none" selection */ + check = H5S_select_shape_same_test(scalar_none_sid, none_sid); + VERIFY(check, TRUE, "H5S_select_shape_same_test"); + + /* Compare against single point selection */ + check = H5S_select_shape_same_test(scalar_none_sid, single_pt_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against multiple point selection */ + check = H5S_select_shape_same_test(scalar_none_sid, mult_pt_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against "plain" single hyperslab selection */ + check = H5S_select_shape_same_test(scalar_none_sid, single_hyper_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against "all" single hyperslab selection */ + check = H5S_select_shape_same_test(scalar_none_sid, single_hyper_all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against "single point" single hyperslab selection */ + check = H5S_select_shape_same_test(scalar_none_sid, single_hyper_pt_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against regular, strided hyperslab selection */ + check = H5S_select_shape_same_test(scalar_none_sid, regular_hyper_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against irregular hyperslab selection */ + check = H5S_select_shape_same_test(scalar_none_sid, irreg_hyper_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + + /* Compare against "no" hyperslab selection */ + check = H5S_select_shape_same_test(scalar_none_sid, none_hyper_sid); + VERIFY(check, TRUE, "H5S_select_shape_same_test"); + + /* Compare against scalar "all" hyperslab selection */ + check = H5S_select_shape_same_test(scalar_none_sid, scalar_all_sid); + VERIFY(check, FALSE, "H5S_select_shape_same_test"); + /* Close dataspaces */ ret = H5Sclose(all_sid); @@ -6572,6 +6920,10 @@ test_shape_same(void) CHECK(ret, FAIL, "H5Sclose"); ret = H5Sclose(none_hyper_sid); CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(scalar_all_sid); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(scalar_none_sid); + CHECK(ret, FAIL, "H5Sclose"); } /* test_shape_same() */ @@ -7886,6 +8238,7 @@ test_select(void) /* Test selections on scalar dataspaces */ test_scalar_select(); test_scalar_select2(); + test_scalar_select3(); /* Test "same shape" routine */ test_shape_same(); |