summaryrefslogtreecommitdiffstats
path: root/test/dsets.c
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2002-12-02 19:47:57 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2002-12-02 19:47:57 (GMT)
commit437dd9be23c86f8228bcb8b7090189a911cc00ef (patch)
tree759809852985607289214f74b7f827fccad4e746 /test/dsets.c
parent4c546d9e6ee7bae685476df6cd4e627eaab5de12 (diff)
downloadhdf5-437dd9be23c86f8228bcb8b7090189a911cc00ef.zip
hdf5-437dd9be23c86f8228bcb8b7090189a911cc00ef.tar.gz
hdf5-437dd9be23c86f8228bcb8b7090189a911cc00ef.tar.bz2
[svn-r6145]
Purpose: New feature to H5Dget_offset Description: If user block is set, H5Dget_offset should be able to return the absolute offset from the beginning of file. Platforms tested: eirene, arabica
Diffstat (limited to 'test/dsets.c')
-rw-r--r--test/dsets.c129
1 files changed, 123 insertions, 6 deletions
diff --git a/test/dsets.c b/test/dsets.c
index b9d900c..a4f4a76 100644
--- a/test/dsets.c
+++ b/test/dsets.c
@@ -14,6 +14,7 @@
const char *FILENAME[] = {
"dataset",
"compact_dataset",
+ "dset_offset",
NULL
};
@@ -32,6 +33,7 @@ const char *FILENAME[] = {
#define DSET_MISSING_NAME "missing"
#define DSET_ONEBYTE_SHUF_NAME "onebyte_shuffle"
+#define USER_BLOCK 512
#define H5Z_BOGUS 305
/* Shared global arrays */
@@ -213,13 +215,16 @@ test_create(hid_t file)
*-------------------------------------------------------------------------
*/
static herr_t
-test_simple_io(hid_t file)
+test_simple_io(hid_t file, char *fname)
{
hid_t dataset, space, xfer;
int i, j, n;
hsize_t dims[2];
void *tconv_buf = NULL;
-
+ FILE *f;
+ haddr_t offset;
+ int rdata[100][200];
+
TESTING("simple I/O");
/* Initialize the dataset */
@@ -251,9 +256,29 @@ test_simple_io(hid_t file)
if (H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, xfer, points)<0)
goto error;
- /* Test dataset address. Should be valid. */
- if(H5Dget_offset(dataset)==HADDR_UNDEF) goto error;
+ /* Test dataset address in file. Open the same file as a C file, seek
+ * the data position as H5Dget_offset points to, read the dataset, and
+ * compare it with the data written in.*/
+ if((offset=H5Dget_offset(dataset))==HADDR_UNDEF) goto error;
+
+ f = fopen(fname, "r");
+ fseek(f, (long int)offset, SEEK_SET);
+ fread(rdata, sizeof(int), 100*200, f);
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ if (points[i][j] != rdata[i][j]) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
+ goto error;
+ }
+ }
+ }
+
+ fclose(f);
+
/* Read the dataset back */
if (H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, xfer, check)<0)
goto error;
@@ -282,6 +307,97 @@ test_simple_io(hid_t file)
/*-------------------------------------------------------------------------
+ * Function: test_userblock_offset
+ *
+ * Purpose: Tests H5Dget_offset when user block exists.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Raymond Lu
+ * Wednesday, November 27, 2002
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_userblock_offset(hid_t fapl)
+{
+ char filename[32];
+ hid_t file, fcpl, dataset, space;
+ int i, j, n;
+ hsize_t dims[2];
+ FILE *f;
+ haddr_t offset;
+ int rdata[100][200];
+
+ TESTING("dataset offset with user block");
+
+ h5_fixname(FILENAME[2], fapl, filename, sizeof filename);
+
+ if((fcpl=H5Pcreate(H5P_FILE_CREATE))<0) goto error;
+ if(H5Pset_userblock(fcpl, USER_BLOCK)<0) goto error;
+
+ if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl))<0) {
+ goto error;
+ }
+
+ /* Initialize the dataset */
+ /*for (i = n = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ points[i][j] = n++;
+ }
+ }*/
+
+ /* Create the data space */
+ dims[0] = 100;
+ dims[1] = 200;
+ if ((space = H5Screate_simple(2, dims, NULL))<0) goto error;
+
+ /* Create the dataset */
+ if ((dataset = H5Dcreate(file, DSET_SIMPLE_IO_NAME, H5T_NATIVE_INT, space,
+ H5P_DEFAULT))<0) goto error;
+
+ /* Write the data to the dataset */
+ if (H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points)<0)
+ goto error;
+
+ /* Test dataset address in file. Open the same file as a C file, seek
+ * the data position as H5Dget_offset points to, read the dataset, and
+ * compare it with the data written in.*/
+ if((offset=H5Dget_offset(dataset))==HADDR_UNDEF) goto error;
+
+ f = fopen(filename, "r");
+ fseek(f, (long int)offset, SEEK_SET);
+ fread(rdata, sizeof(int), 100*200, f);
+
+ /* Check that the values read are the same as the values written */
+ for (i = 0; i < 100; i++) {
+ for (j = 0; j < 200; j++) {
+ if (points[i][j] != rdata[i][j]) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d,%d\n", i, j);
+ goto error;
+ }
+ }
+ }
+
+ fclose(f);
+
+ H5Dclose(dataset);
+ H5Fclose(file);
+ PASSED();
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
* Function: test_compact_io
*
* Purpose: Tests compact dataset I/O. That is, reading and writing a
@@ -1421,7 +1537,7 @@ main(void)
if (H5Gclose (grp)<0) goto error;
nerrors += test_create(file)<0 ?1:0;
- nerrors += test_simple_io(file)<0 ?1:0;
+ nerrors += test_simple_io(file, filename)<0 ?1:0;
nerrors += test_compact_io(fapl)<0 ?1:0;
nerrors += test_tconv(file)<0 ?1:0;
nerrors += test_compression(file)<0 ?1:0;
@@ -1429,7 +1545,8 @@ main(void)
nerrors += test_onebyte_shuffle(file)<0 ?1:0;
nerrors += test_multiopen (file)<0 ?1:0;
nerrors += test_types(file)<0 ?1:0;
-
+ nerrors += test_userblock_offset(fapl)<0 ?1:0;
+
if (H5Fclose(file)<0) goto error;
if (nerrors) goto error;
printf("All dataset tests passed.\n");