From 5d3d452005302479a6ae034db2b384be26c8a542 Mon Sep 17 00:00:00 2001 From: Quincey Koziol Date: Thu, 23 Apr 1998 17:24:52 -0500 Subject: [svn-r362] Added Attribute (H5A) test --- test/.distdep | 72 +++- test/Makefile.in | 8 +- test/dtypes.c | 4 +- test/tattr.c | 1101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/testhdf5.c | 1 + test/testhdf5.h | 1 + 6 files changed, 1162 insertions(+), 25 deletions(-) create mode 100644 test/tattr.c diff --git a/test/.distdep b/test/.distdep index e7c7b05..4e012b1 100644 --- a/test/.distdep +++ b/test/.distdep @@ -4,8 +4,8 @@ testhdf5.o: \ ../src/H5private.h \ ../src/H5public.h \ ../src/H5config.h -tfile.o: \ - tfile.c \ +tattr.o: \ + tattr.c \ testhdf5.h \ ../src/H5private.h \ ../src/H5public.h \ @@ -13,12 +13,21 @@ tfile.o: \ ../src/H5Eprivate.h \ ../src/H5Epublic.h \ ../src/H5Ipublic.h \ - ../src/H5Bprivate.h \ + ../src/hdf5.h \ + ../src/H5Apublic.h \ + ../src/H5ACpublic.h \ ../src/H5Bpublic.h \ - ../src/H5Fprivate.h \ + ../src/H5Dpublic.h \ ../src/H5Fpublic.h \ - ../src/H5Pprivate.h \ - ../src/H5Ppublic.h + ../src/H5Gpublic.h \ + ../src/H5HGpublic.h \ + ../src/H5HLpublic.h \ + ../src/H5MFpublic.h \ + ../src/H5MMpublic.h \ + ../src/H5Opublic.h \ + ../src/H5Ppublic.h \ + ../src/H5Zpublic.h \ + ../src/H5Spublic.h theap.o: \ theap.c \ testhdf5.h \ @@ -138,10 +147,11 @@ dtypes.o: \ ../src/hdf5.h \ ../src/H5public.h \ ../src/H5config.h \ + ../src/H5Ipublic.h \ + ../src/H5Apublic.h \ ../src/H5ACpublic.h \ ../src/H5Bpublic.h \ ../src/H5Dpublic.h \ - ../src/H5Ipublic.h \ ../src/H5Epublic.h \ ../src/H5Fpublic.h \ ../src/H5Gpublic.h \ @@ -195,10 +205,11 @@ dsets.o: \ ../src/hdf5.h \ ../src/H5public.h \ ../src/H5config.h \ + ../src/H5Ipublic.h \ + ../src/H5Apublic.h \ ../src/H5ACpublic.h \ ../src/H5Bpublic.h \ ../src/H5Dpublic.h \ - ../src/H5Ipublic.h \ ../src/H5Epublic.h \ ../src/H5Fpublic.h \ ../src/H5Gpublic.h \ @@ -216,10 +227,11 @@ cmpd_dset.o: \ ../src/hdf5.h \ ../src/H5public.h \ ../src/H5config.h \ + ../src/H5Ipublic.h \ + ../src/H5Apublic.h \ ../src/H5ACpublic.h \ ../src/H5Bpublic.h \ ../src/H5Dpublic.h \ - ../src/H5Ipublic.h \ ../src/H5Epublic.h \ ../src/H5Fpublic.h \ ../src/H5Gpublic.h \ @@ -230,17 +242,17 @@ cmpd_dset.o: \ ../src/H5Opublic.h \ ../src/H5Ppublic.h \ ../src/H5Zpublic.h \ - ../src/H5Spublic.h \ - ../src/H5Tpublic.h + ../src/H5Spublic.h extend.o: \ extend.c \ ../src/hdf5.h \ ../src/H5public.h \ ../src/H5config.h \ + ../src/H5Ipublic.h \ + ../src/H5Apublic.h \ ../src/H5ACpublic.h \ ../src/H5Bpublic.h \ ../src/H5Dpublic.h \ - ../src/H5Ipublic.h \ ../src/H5Epublic.h \ ../src/H5Fpublic.h \ ../src/H5Gpublic.h \ @@ -250,16 +262,18 @@ extend.o: \ ../src/H5MMpublic.h \ ../src/H5Opublic.h \ ../src/H5Ppublic.h \ - ../src/H5Zpublic.h + ../src/H5Zpublic.h \ + ../src/H5Spublic.h external.o: \ external.c \ ../src/hdf5.h \ ../src/H5public.h \ ../src/H5config.h \ + ../src/H5Ipublic.h \ + ../src/H5Apublic.h \ ../src/H5ACpublic.h \ ../src/H5Bpublic.h \ ../src/H5Dpublic.h \ - ../src/H5Ipublic.h \ ../src/H5Epublic.h \ ../src/H5Fpublic.h \ ../src/H5Gpublic.h \ @@ -277,10 +291,11 @@ iopipe.o: \ ../src/hdf5.h \ ../src/H5public.h \ ../src/H5config.h \ + ../src/H5Ipublic.h \ + ../src/H5Apublic.h \ ../src/H5ACpublic.h \ ../src/H5Bpublic.h \ ../src/H5Dpublic.h \ - ../src/H5Ipublic.h \ ../src/H5Epublic.h \ ../src/H5Fpublic.h \ ../src/H5Gpublic.h \ @@ -315,10 +330,11 @@ shtype.o: \ ../src/hdf5.h \ ../src/H5public.h \ ../src/H5config.h \ + ../src/H5Ipublic.h \ + ../src/H5Apublic.h \ ../src/H5ACpublic.h \ ../src/H5Bpublic.h \ ../src/H5Dpublic.h \ - ../src/H5Ipublic.h \ ../src/H5Epublic.h \ ../src/H5Fpublic.h \ ../src/H5Gpublic.h \ @@ -328,16 +344,18 @@ shtype.o: \ ../src/H5MMpublic.h \ ../src/H5Opublic.h \ ../src/H5Ppublic.h \ - ../src/H5Zpublic.h + ../src/H5Zpublic.h \ + ../src/H5Spublic.h big.o: \ big.c \ ../src/hdf5.h \ ../src/H5public.h \ ../src/H5config.h \ + ../src/H5Ipublic.h \ + ../src/H5Apublic.h \ ../src/H5ACpublic.h \ ../src/H5Bpublic.h \ ../src/H5Dpublic.h \ - ../src/H5Ipublic.h \ ../src/H5Epublic.h \ ../src/H5Fpublic.h \ ../src/H5Gpublic.h \ @@ -356,10 +374,11 @@ links.o: \ ../src/hdf5.h \ ../src/H5public.h \ ../src/H5config.h \ + ../src/H5Ipublic.h \ + ../src/H5Apublic.h \ ../src/H5ACpublic.h \ ../src/H5Bpublic.h \ ../src/H5Dpublic.h \ - ../src/H5Ipublic.h \ ../src/H5Epublic.h \ ../src/H5Fpublic.h \ ../src/H5Gpublic.h \ @@ -369,3 +388,18 @@ links.o: \ ../src/H5MMpublic.h \ ../src/H5Opublic.h \ ../src/H5Ppublic.h +tfile.o: \ + tfile.c \ + testhdf5.h \ + ../src/H5private.h \ + ../src/H5public.h \ + ../src/H5config.h \ + ../src/H5Eprivate.h \ + ../src/H5Epublic.h \ + ../src/H5Ipublic.h \ + ../src/H5Bprivate.h \ + ../src/H5Bpublic.h \ + ../src/H5Fprivate.h \ + ../src/H5Fpublic.h \ + ../src/H5Pprivate.h \ + ../src/H5Ppublic.h diff --git a/test/Makefile.in b/test/Makefile.in index 55da8cd..aab4e6c 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -30,12 +30,12 @@ MOSTLYCLEAN=cmpd_dset.h5 dataset.h5 extend.h5 istore.h5 tfile1.h5 tfile2.h5 \ # source files and is used for things like dependencies, archiving, etc. The # other source lists are for the individual tests, the files of which may # overlap with other tests. -PROG_SRC=testhdf5.c tfile.c theap.c tmeta.c tohdr.c tstab.c th5s.c dtypes.c \ - hyperslab.c istore.c dsets.c cmpd_dset.c extend.c external.c \ - iopipe.c gheap.c shtype.c big.c links.c +PROG_SRC=testhdf5.c tattr.c tfile.c theap.c tmeta.c tohdr.c tstab.c th5s.c \ + dtypes.c hyperslab.c istore.c dsets.c cmpd_dset.c extend.c external.c \ + iopipe.c gheap.c shtype.c big.c links.c PROG_OBJ=$(PROG_SRC:.c=.o) -TESTHDF5_SRC=testhdf5.c tfile.c theap.c tmeta.c tohdr.c tstab.c th5s.c +TESTHDF5_SRC=testhdf5.c tattr.c tfile.c theap.c tmeta.c tohdr.c tstab.c th5s.c TESTHDF5_OBJ=$(TESTHDF5_SRC:.c=.o) GHEAP_SRC=gheap.c diff --git a/test/dtypes.c b/test/dtypes.c index f8d3d0a..445e51f 100644 --- a/test/dtypes.c +++ b/test/dtypes.c @@ -170,7 +170,7 @@ test_compound(void) goto error; } /* Add a couple fields */ - status = H5Tinsert(complex_id, "real", HOFFSET(tmp, re), + status = H5Tinsert(complex_id, "real", HOFFSET(complex_t, re), H5T_NATIVE_DOUBLE); if (status < 0) { puts("*FAILED*"); @@ -180,7 +180,7 @@ test_compound(void) } goto error; } - status = H5Tinsert(complex_id, "imaginary", HOFFSET(tmp, im), + status = H5Tinsert(complex_id, "imaginary", HOFFSET(complex_t, im), H5T_NATIVE_DOUBLE); if (status < 0) { puts("*FAILED*"); diff --git a/test/tattr.c b/test/tattr.c new file mode 100644 index 0000000..822472f --- /dev/null +++ b/test/tattr.c @@ -0,0 +1,1101 @@ +/**************************************************************************** + * NCSA HDF * + * Software Development Group * + * National Center for Supercomputing Applications * + * University of Illinois at Urbana-Champaign * + * 605 E. Springfield, Champaign IL 61820 * + * * + * For conditions of distribution and use, see the accompanying * + * hdf/COPYING file. * + * * + ****************************************************************************/ + +#ifdef RCSID +static char RcsId[] = "$Revision$"; +#endif + +/* $Id$ */ + +/*********************************************************** +* +* Test program: tattr +* +* Test the attribute functionality +* +*************************************************************/ + +#include + +#include + +#define FILE "tattr.h5" +#define ATTR_NAME_LEN 16 +#define ATTR_MAX_DIMS 7 + +/* 3-D dataset with fixed dimensions */ +#define SPACE1_NAME "Space1" +#define SPACE1_RANK 3 +#define SPACE1_DIM1 3 +#define SPACE1_DIM2 15 +#define SPACE1_DIM3 13 + +/* Group Information */ +#define GROUP1_NAME "/Group1" + +/* Attribute Rank & Dimensions */ +#define ATTR1_NAME "Attr1" +#define ATTR1_RANK 1 +#define ATTR1_DIM1 3 +int32 attr_data1[ATTR1_DIM1]={512,-234,98123}; /* Test data for 1st attribute */ + +#define ATTR2_NAME "Attr2" +#define ATTR2_RANK 2 +#define ATTR2_DIM1 2 +#define ATTR2_DIM2 2 +int32 attr_data2[ATTR2_DIM1][ATTR2_DIM2]={{7614,-416},{197814,-3}}; /* Test data for 2nd attribute */ + +#define ATTR3_NAME "Attr3" +#define ATTR3_RANK 3 +#define ATTR3_DIM1 2 +#define ATTR3_DIM2 2 +#define ATTR3_DIM3 2 +double attr_data3[ATTR3_DIM1][ATTR3_DIM2][ATTR3_DIM3]={{{2.3,-26.1},{0.123,-10.0}},{{981724.2,-0.91827},{2.0,23.0}}}; /* Test data for 3rd attribute */ + +#define ATTR4_NAME "Attr4" +#define ATTR4_RANK 2 +#define ATTR4_DIM1 2 +#define ATTR4_DIM2 2 +#define ATTR4_FIELDNAME1 "i" +#define ATTR4_FIELDNAME2 "d" +#define ATTR4_FIELDNAME3 "c" +struct attr4_struct { + int32 i; + double d; + char c; + } attr_data4[ATTR4_DIM1][ATTR4_DIM2]={{{3,-26.1,'d'},{-100000, 0.123,'3'}}, + {{-23,981724.2,'Q'},{0,2.0,'\n'}}}; /* Test data for 4th attribute */ + +int attr_op1(hid_t loc_id, const char *name, void *op_data); + +/**************************************************************** +** +** test_attr_basic_write(): Test basic H5A (attribute) code. +** Tests integer attributes on both datasets and groups +** +****************************************************************/ +static void +test_attr_basic_write(void) +{ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t group; /* Group ID */ + hid_t sid1,sid2; /* Dataspace ID */ + hid_t attr; /* Attribute ID */ + hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; + hsize_t dims2[] = {ATTR1_DIM1}; + hsize_t dims3[] = {ATTR2_DIM1,ATTR2_DIM2}; + herr_t ret; /* Generic return value */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Basic Attribute Functions\n")); + + /* Create file */ + fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + CHECK(fid1, FAIL, "H5Fcreate"); + + /* Create dataspace for dataset */ + sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL); + CHECK(sid1, FAIL, "H5Screate_simple"); + + /* Create a dataset */ + dataset=H5Dcreate(fid1,"Dataset1",H5T_NATIVE_UINT8,sid1,H5P_DEFAULT); + + /* Create dataspace for attribute */ + sid2 = H5Screate_simple(ATTR1_RANK, dims2, NULL); + CHECK(sid2, FAIL, "H5Screate_simple"); + + /* Create an attribute for the dataset */ + attr=H5Acreate(dataset,ATTR1_NAME,H5T_NATIVE_INT32,sid2,H5P_DEFAULT); + CHECK(attr, FAIL, "H5Acreate"); + + /* Try to create the same attribute again (should fail) */ + ret=H5Acreate(dataset,ATTR1_NAME,H5T_NATIVE_INT32,sid2,H5P_DEFAULT); + VERIFY(ret, FAIL, "H5Acreate"); + + /* Write attribute information */ + ret=H5Awrite(attr,H5T_NATIVE_INT32,&attr_data1); + CHECK(ret, FAIL, "H5Awrite"); + + /* Close attribute */ + ret=H5Aclose(attr); + CHECK(ret, FAIL, "H5Aclose"); + + ret = H5Sclose(sid1); + CHECK(ret, FAIL, "H5Sclose"); + ret = H5Sclose(sid2); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close Dataset */ + ret = H5Dclose(dataset); + CHECK(ret, FAIL, "H5Dclose"); + + /* Create group */ + group = H5Gcreate(fid1, GROUP1_NAME, 0); + CHECK(group, FAIL, "H5Gcreate"); + + /* Create dataspace for attribute */ + sid2 = H5Screate_simple(ATTR2_RANK, dims3, NULL); + CHECK(sid2, FAIL, "H5Screate_simple"); + + /* Create an attribute for the group */ + attr=H5Acreate(group,ATTR2_NAME,H5T_NATIVE_INT32,sid2,H5P_DEFAULT); + CHECK(attr, FAIL, "H5Acreate"); + + /* Try to create the same attribute again (should fail) */ + ret=H5Acreate(group,ATTR2_NAME,H5T_NATIVE_INT32,sid2,H5P_DEFAULT); + VERIFY(ret, FAIL, "H5Acreate"); + + /* Write attribute information */ + ret=H5Awrite(attr,H5T_NATIVE_INT32,&attr_data2); + CHECK(ret, FAIL, "H5Awrite"); + + /* Close attribute */ + ret=H5Aclose(attr); + CHECK(ret, FAIL, "H5Aclose"); + + /* Close Attribute dataspace */ + ret = H5Sclose(sid2); + CHECK(ret, FAIL, "H5Sclose"); + + /* Close Group */ + ret = H5Gclose(group); + CHECK(ret, FAIL, "H5Gclose"); + + /* Close file */ + ret = H5Fclose(fid1); + CHECK(ret, FAIL, "H5Fclose"); +} /* test_attr_basic_write() */ + +/**************************************************************** +** +** test_attr_basic_read(): Test basic H5A (attribute) code. +** +****************************************************************/ +static void +test_attr_basic_read(void) +{ + hid_t fid1; /* HDF5 File IDs */ + hid_t dataset; /* Dataset ID */ + hid_t group; /* Group ID */ + hid_t attr; /* Attribute ID */ + int32 read_data1[ATTR1_DIM1]={0}; /* Buffer for reading 1st attribute */ + int32 read_data2[ATTR2_DIM1][ATTR2_DIM2]={{0}}; /* Buffer for reading 2nd attribute */ + int i,j; + herr_t ret; /* Generic return value */ + + /* Output message about test being performed */ + MESSAGE(5, ("Testing Basic Attribute Functions\n")); + + /* Create file */ + fid1 = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT); + CHECK(fid1, FAIL, "H5Fopen"); + + /* Open the dataset */ + dataset=H5Dopen(fid1,"Dataset1"); + + /* Verify the correct number of attributes */ + ret=H5Anum_attrs(dataset); + VERIFY(ret, 1, "H5Anum_attrs"); + + /* Open an attribute for the dataset */ + attr=H5Aopen_name(dataset,ATTR1_NAME); + CHECK(attr, FAIL, "H5Aopen_name"); + + /* Read attribute information */ + ret=H5Aread(attr,H5T_NATIVE_INT32,&read_data1); + CHECK(ret, FAIL, "H5Aread"); + + /* Verify values read in */ + for(i=0; i