diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2002-01-04 02:45:42 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2002-01-04 02:45:42 (GMT) |
commit | ee82d833318c4a6a850fded0cd05f0a3098fbd09 (patch) | |
tree | d7d26a478527cfca968f5fcd610767b63f27fc53 /test/tvlstr.c | |
parent | a5b4db88f40efd056a1bba8d8d85a0d34a9b496a (diff) | |
download | hdf5-ee82d833318c4a6a850fded0cd05f0a3098fbd09.zip hdf5-ee82d833318c4a6a850fded0cd05f0a3098fbd09.tar.gz hdf5-ee82d833318c4a6a850fded0cd05f0a3098fbd09.tar.bz2 |
[svn-r4775] Purpose:
Regression test
Description:
Added regression test which stores variable length strings as an attribute.
Platforms tested:
FreeBSD 4.5 (sleipnir)
Diffstat (limited to 'test/tvlstr.c')
-rw-r--r-- | test/tvlstr.c | 130 |
1 files changed, 127 insertions, 3 deletions
diff --git a/test/tvlstr.c b/test/tvlstr.c index 815a692..3a2fbe5 100644 --- a/test/tvlstr.c +++ b/test/tvlstr.c @@ -28,7 +28,7 @@ #include "hdf5.h" -#define FILE "tvlstr.h5" +#define DATAFILE "tvlstr.h5" /* 1-D dataset with fixed dimensions */ #define SPACE1_NAME "Space1" @@ -41,6 +41,9 @@ #define SPACE2_DIM1 10 #define SPACE2_DIM2 10 +/* String for testing attributes */ +static const char *string_att = "This is the string for the attribute"; + void *test_vlstr_alloc_custom(size_t size, void *info); void test_vlstr_free_custom(void *mem, void *info); @@ -131,7 +134,7 @@ test_vlstrings_basic(void) MESSAGE(5, ("Testing Basic VL String Functionality\n")); /* Create file */ - fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + fid1 = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); CHECK(fid1, FAIL, "H5Fcreate"); /* Create dataspace for datasets */ @@ -223,6 +226,123 @@ test_vlstrings_basic(void) /**************************************************************** ** +** test_write_vl_string_attribute(): Test basic VL string code. +** Tests writing VL strings as attributes +** +****************************************************************/ +static void test_write_vl_string_attribute(void) +{ + hid_t file, root, dataspace, att; + hid_t type; + herr_t ret; + char *string_att_check; + + file = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(file, FAIL, "H5Fcreate"); + + /* Create a datatype to refer to. */ + type = H5Tcopy (H5T_C_S1); + CHECK(type, FAIL, "H5Tcopy"); + + ret = H5Tset_size (type, H5T_VARIABLE); + CHECK(ret, FAIL, "H5Tset_size"); + + root = H5Gopen(file, "/"); + CHECK(root, FAIL, "H5Gopen"); + + dataspace = H5Screate(H5S_SCALAR); + CHECK(dataspace, FAIL, "H5Screate"); + + att = H5Acreate(root, "test_scalar", type, dataspace, H5P_DEFAULT); + CHECK(att, FAIL, "H5Acreate"); + + ret = H5Awrite(att, type, &string_att); + CHECK(ret, FAIL, "H5Awrite"); + + ret = H5Aread(att, type, &string_att_check); + CHECK(ret, FAIL, "H5Aread"); + + if(HDstrcmp(string_att_check,string_att)!=0) { + num_errs++; + printf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",string_att,string_att_check); + } /* end if */ + + free(string_att_check); + + ret = H5Aclose(att); + CHECK(ret, FAIL, "HAclose"); + + ret = H5Gclose(root); + CHECK(ret, FAIL, "H5Gclose"); + + ret = H5Tclose(type); + CHECK(ret, FAIL, "H5Tclose"); + + ret = H5Sclose(dataspace); + CHECK(ret, FAIL, "H5Sclose"); + + ret = H5Fclose(file); + CHECK(ret, FAIL, "H5Fclose"); + + return; +} + +/**************************************************************** +** +** test_read_vl_string_attribute(): Test basic VL string code. +** Tests reading VL strings from attributes +** +****************************************************************/ +static void test_read_vl_string_attribute(void) +{ + hid_t file, root, att; + hid_t type; + herr_t ret; + char *string_att_check; + + file = H5Fopen(DATAFILE, H5F_ACC_RDONLY, H5P_DEFAULT); + CHECK(file, FAIL, "H5Fopen"); + + /* Create a datatype to refer to. */ + type = H5Tcopy (H5T_C_S1); + CHECK(type, FAIL, "H5Tcopy"); + + ret = H5Tset_size (type, H5T_VARIABLE); + CHECK(ret, FAIL, "H5Tset_size"); + + root = H5Gopen(file, "/"); + CHECK(root, FAIL, "H5Gopen"); + + att = H5Aopen_name(root, "test_scalar"); + CHECK(att, FAIL, "H5Aopen_name"); + + ret = H5Aread(att, type, &string_att_check); + CHECK(ret, FAIL, "H5Aread"); + + if(HDstrcmp(string_att_check,string_att)!=0) { + num_errs++; + printf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",string_att,string_att_check); + } /* end if */ + + free(string_att_check); + + ret = H5Aclose(att); + CHECK(ret, FAIL, "HAclose"); + + ret = H5Tclose(type); + CHECK(ret, FAIL, "H5Tclose"); + + ret = H5Gclose(root); + CHECK(ret, FAIL, "H5Gclose"); + + ret = H5Fclose(file); + CHECK(ret, FAIL, "H5Fclose"); + + return; +} + +/**************************************************************** +** ** test_vlstrings(): Main VL string testing routine. ** ****************************************************************/ @@ -234,6 +354,10 @@ test_vlstrings(void) /* These next tests use the same file */ test_vlstrings_basic(); /* Test basic VL string datatype */ + + /* Test using VL strings in attributes */ + test_write_vl_string_attribute(); + test_read_vl_string_attribute(); } /* test_vlstrings() */ @@ -254,6 +378,6 @@ test_vlstrings(void) void cleanup_vlstrings(void) { - remove(FILE); + remove(DATAFILE); } |