From 6953e9a0101f6fca7183a0be80e0c34c7eedc692 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Mon, 15 Sep 2003 15:06:55 -0500 Subject: [svn-r7474] Purpose: Add more test Description: test fixed-length strings in two ways: array of strings and array of character. Platforms tested: h5committest --- test/tmisc.c | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 180 insertions(+), 1 deletion(-) diff --git a/test/tmisc.c b/test/tmisc.c index 6dcef6f..19150d3 100644 --- a/test/tmisc.c +++ b/test/tmisc.c @@ -194,6 +194,21 @@ unsigned m13_rdata[MISC13_DIM1][MISC13_DIM2]; /* Data read from dataset /* Definitions for misc. test #15 */ #define MISC15_FILE "tmisc15.h5" +/* Definitions for misc. test #16 */ +#define MISC16_FILE "tmisc16.h5" +#define MISC16_SPACE_DIM 4 +#define MISC16_SPACE_RANK 1 +#define MISC16_STR_SIZE 8 +#define MISC16_DSET_NAME "Dataset" + +/* Definitions for misc. test #17 */ +#define MISC17_FILE "tmisc17.h5" +#define MISC17_SPACE_RANK 2 +#define MISC17_SPACE_DIM1 4 +#define MISC17_SPACE_DIM2 8 +#define MISC17_DSET_NAME "Dataset" + + /**************************************************************** ** ** test_misc1(): test unlinking a dataset from a group and immediately @@ -2621,6 +2636,166 @@ test_misc15(void) /**************************************************************** ** +** test_misc16(): Test array of NULL-terminated +** fixed-length string. It creates a dataset of fixed-length +** strings. Each string is MISC16_STR_SIZE long. There are +** totally MISC16_SPACE_DIM by MISC16_SPACE_RANK strings. +** +****************************************************************/ +static void +test_misc16(void) +{ + hid_t file; /* File ID */ + herr_t ret; /* Generic return value */ + const char wdata[MISC16_SPACE_DIM][MISC16_STR_SIZE] = + {"1234567", "1234567\0", "12345678", NULL}; + char rdata[MISC16_SPACE_DIM][MISC16_STR_SIZE]; /* Information read in */ + hid_t dataset; /* Dataset ID */ + hid_t sid; /* Dataspace ID */ + hid_t tid; /* Datatype ID */ + hsize_t dims[] = {MISC16_SPACE_DIM}; + int i; + + /* Create the file */ + file = H5Fcreate(MISC16_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(file, FAIL, "H5Fcreate"); + + /* Create dataspace for datasets */ + sid = H5Screate_simple(MISC16_SPACE_RANK, dims, NULL); + CHECK(sid, FAIL, "H5Screate_simple"); + + /* Create a datatype to refer to */ + tid = H5Tcopy (H5T_C_S1); + CHECK(tid, FAIL, "H5Tcopy"); + + ret = H5Tset_size (tid,MISC16_STR_SIZE); + CHECK(ret, FAIL, "H5Tset_size"); + + /*ret = H5Tset_strpad (tid,H5T_STR_NULLPAD); + CHECK(ret, FAIL, "H5Tset_strpad");*/ + + /* Create a dataset */ + dataset=H5Dcreate(file,MISC16_DSET_NAME,tid,sid,H5P_DEFAULT); + CHECK(dataset, FAIL, "H5Dcreate"); + + /* Write dataset to disk */ + ret=H5Dwrite(dataset,tid,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata); + CHECK(ret, FAIL, "H5Dwrite"); + + /* Read dataset from disk */ + ret=H5Dread(dataset,tid,H5S_ALL,H5S_ALL,H5P_DEFAULT,rdata); + CHECK(ret, FAIL, "H5Dread"); + + /* Compare data read in */ + for(i=0; i