summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2006-10-22 08:24:24 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2006-10-22 08:24:24 (GMT)
commitfdd56729be8ce04f15dd573557a53c1719eb7ea8 (patch)
treec81d20f7fc7cc0b6648533c9ee8064cc0730746f /c++
parentdaa61b598616713bd39d360aeb9dbbd7ec5803cb (diff)
downloadhdf5-fdd56729be8ce04f15dd573557a53c1719eb7ea8.zip
hdf5-fdd56729be8ce04f15dd573557a53c1719eb7ea8.tar.gz
hdf5-fdd56729be8ce04f15dd573557a53c1719eb7ea8.tar.bz2
[svn-r12796] Purpose: Adding test
Description: Wrappers of H5Rcreate had incorrect prototypes. Fixed and added object reference tests. Platform tested: Linux 2.4 (heping) AIX 5.1 (copper) SunOS 5.8 64-bit (sol)
Diffstat (limited to 'c++')
-rw-r--r--c++/test/Makefile.am3
-rw-r--r--c++/test/Makefile.in8
-rw-r--r--c++/test/testhdf5.cpp21
-rw-r--r--c++/test/trefer.cpp302
4 files changed, 328 insertions, 6 deletions
diff --git a/c++/test/Makefile.am b/c++/test/Makefile.am
index 814c7eb..bd04acf 100644
--- a/c++/test/Makefile.am
+++ b/c++/test/Makefile.am
@@ -37,7 +37,8 @@ check_PROGRAMS=$(TEST_PROG)
LDADD=$(LIBH5CPP) $(LIBH5TEST) $(LIBHDF5)
dsets_SOURCES=dsets.cpp h5cpputil.cpp
-testhdf5_SOURCES=testhdf5.cpp tattr.cpp tfile.cpp th5s.cpp h5cpputil.cpp
+testhdf5_SOURCES=testhdf5.cpp tattr.cpp tfile.cpp th5s.cpp trefer.cpp \
+ h5cpputil.cpp
# Tell conclude.am that these are C++ tests.
HDF_CXX=yes
diff --git a/c++/test/Makefile.in b/c++/test/Makefile.in
index 19623b4..f7b1c93 100644
--- a/c++/test/Makefile.in
+++ b/c++/test/Makefile.in
@@ -75,7 +75,8 @@ am__DEPENDENCIES_3 = $(top_builddir)/src/libhdf5.la
dsets_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
$(am__DEPENDENCIES_3)
am_testhdf5_OBJECTS = testhdf5.$(OBJEXT) tattr.$(OBJEXT) \
- tfile.$(OBJEXT) th5s.$(OBJEXT) h5cpputil.$(OBJEXT)
+ tfile.$(OBJEXT) th5s.$(OBJEXT) trefer.$(OBJEXT) \
+ h5cpputil.$(OBJEXT)
testhdf5_OBJECTS = $(am_testhdf5_OBJECTS)
testhdf5_LDADD = $(LDADD)
testhdf5_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
@@ -341,7 +342,9 @@ TEST_PROG = dsets testhdf5
# The tests depend on the hdf5 library, test library, and the c++ library
LDADD = $(LIBH5CPP) $(LIBH5TEST) $(LIBHDF5)
dsets_SOURCES = dsets.cpp h5cpputil.cpp
-testhdf5_SOURCES = testhdf5.cpp tattr.cpp tfile.cpp th5s.cpp h5cpputil.cpp
+testhdf5_SOURCES = testhdf5.cpp tattr.cpp tfile.cpp th5s.cpp trefer.cpp \
+ h5cpputil.cpp
+
# Tell conclude.am that these are C++ tests.
HDF_CXX = yes
@@ -421,6 +424,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testhdf5.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tfile.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/th5s.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/trefer.Po@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ if $(CXXCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
diff --git a/c++/test/testhdf5.cpp b/c++/test/testhdf5.cpp
index 1951a99..04f00a8 100644
--- a/c++/test/testhdf5.cpp
+++ b/c++/test/testhdf5.cpp
@@ -42,8 +42,22 @@
***************************************************************************/
-#include "testhdf5.h" // C test header file
-#include "H5Cpp.h" // C++ API header file
+#ifdef OLD_HEADER_FILENAME
+#include <iostream.h>
+#else
+#include <iostream>
+#endif
+#include <string>
+
+#ifndef H5_NO_NAMESPACE
+#ifndef H5_NO_STD
+ using std::cerr;
+ using std::endl;
+#endif // H5_NO_STD
+#endif
+
+#include "testhdf5.h" // C test header file
+#include "H5Cpp.h" // C++ API header file
#ifndef H5_NO_NAMESPACE
using namespace H5;
@@ -61,10 +75,11 @@ main(int argc, char *argv[])
AddTest("h5s", test_h5s, cleanup_h5s, "Dataspaces", NULL);
// testing attribute functionalities in tattr.cpp
AddTest("attr", test_attr, cleanup_attr, "Attributes", NULL);
+ // testing reference functionalities in trefer.cpp
+ AddTest("reference", test_reference, cleanup_reference, "References", NULL);
/* Comment out tests that are not done yet. - BMR, Feb 2001
AddTest("select", test_select, cleanup_select, "Selections", NULL);
AddTest("time", test_time, cleanup_time, "Time Datatypes", NULL);
- AddTest("reference", test_reference, cleanup_reference, "References", NULL);
AddTest("vltypes", test_vltypes, cleanup_vltypes, "Variable-Length Datatypes", NULL);
AddTest("vlstrings", test_vlstrings, cleanup_vlstrings, "Variable-Length Strings", NULL);
AddTest("iterate", test_iterate, cleanup_iterate, "Group & Attribute Iteration", NULL);
diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp
new file mode 100644
index 0000000..f997ffd
--- /dev/null
+++ b/c++/test/trefer.cpp
@@ -0,0 +1,302 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group (THG). *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://www.hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/***********************************************************
+*
+* Test program: trefer
+*
+* Test the Reference functionality
+*
+*************************************************************/
+
+#ifdef OLD_HEADER_FILENAME
+#include <iostream.h>
+#else
+#include <iostream>
+#endif
+#include <string>
+
+#ifndef H5_NO_NAMESPACE
+#ifndef H5_NO_STD
+ using std::cerr;
+ using std::endl;
+#endif // H5_NO_STD
+#endif
+
+#include "testhdf5.h" // C test header file
+#include "H5Cpp.h" // C++ API header file
+
+#ifndef H5_NO_NAMESPACE
+using namespace H5;
+#endif
+
+#include "h5cpputil.h" // C++ utilility header file
+
+const H5std_string FILE1("trefer1.h5");
+const H5std_string FILE2("trefer2.h5");
+const H5std_string FILE3("trefer3.h5");
+const H5std_string DSET_DEFAULT_NAME("default");
+
+const H5std_string MEMBER1( "a_name" );
+const H5std_string MEMBER2( "b_name" );
+const H5std_string MEMBER3( "c_name" );
+
+// 1-D dataset with fixed dimensions
+const H5std_string SPACE1_NAME("Space1");
+const int SPACE1_RANK = 1;
+const int SPACE1_DIM1 = 4;
+
+// 2-D dataset with fixed dimensions
+const H5std_string SPACE2_NAME("Space2");
+const int SPACE2_RANK = 2;
+const int SPACE2_DIM1 = 10;
+const int SPACE2_DIM2 = 10;
+
+// Larger 1-D dataset with fixed dimensions
+const H5std_string SPACE3_NAME("Space3");
+const int SPACE3_RANK = 1;
+const int SPACE3_DIM1 = 100;
+
+// Element selection information
+const int POINT1_NPOINTS = 10;
+
+// Compound datatype
+typedef struct s1_t {
+ unsigned int a;
+ unsigned int b;
+ float c;
+} s1_t;
+
+/****************************************************************
+**
+** test_reference_obj(): Test basic object reference functionality.
+** Tests references to various kinds of objects
+**
+****************************************************************/
+static void
+test_reference_obj(void)
+{
+ int i; // counting variables
+ const H5std_string write_comment="Foo!"; // Comments for group
+ char read_comment[10];
+
+ // Output message about test being performed
+ MESSAGE(5, ("Testing Object Reference Functions\n"));
+
+ H5File* file1 = NULL;
+ try {
+ hobj_ref_t *wbuf, // buffer to write to disk
+ *rbuf, // buffer read from disk
+ *tbuf; // temp. buffer read from disk
+
+ // Allocate write & read buffers
+ int temp_size = MAX(sizeof(unsigned),sizeof(hobj_ref_t));
+ wbuf=(hobj_ref_t*)malloc(temp_size*SPACE1_DIM1);
+ rbuf=(hobj_ref_t*)malloc(temp_size*SPACE1_DIM1);
+ tbuf=(hobj_ref_t*)malloc(temp_size*SPACE1_DIM1);
+
+ // Create file FILE1
+ file1 = new H5File (FILE1, H5F_ACC_TRUNC);
+
+ // Create dataspace for datasets
+ hsize_t dims1[] = {SPACE1_DIM1};
+ DataSpace sid1(SPACE1_RANK, dims1);
+
+ // Create a group
+ Group group = file1->createGroup("Group1", (size_t)-1);
+
+ // Set group's comment
+ group.setComment(".", write_comment);
+
+ // Create a dataset (inside /Group1)
+ DataSet dataset = group.createDataSet("Dataset1", PredType::NATIVE_UINT, sid1);
+
+ unsigned *tu32; // Temporary pointer to uint32 data
+ for (tu32=(unsigned *)wbuf, i=0; i<SPACE1_DIM1; i++)
+ *tu32++=i*3; // from C test
+
+ // Write selection to disk
+ dataset.write(wbuf, PredType::NATIVE_UINT);
+
+ // Close Dataset
+ dataset.close();
+
+ // Create another dataset (inside /Group1)
+ dataset = group.createDataSet("Dataset2", PredType::NATIVE_UCHAR, sid1);
+
+ // Close Dataset
+ dataset.close();
+
+ // Create a datatype to refer to
+ CompType dtype1(sizeof(s1_t));
+
+ // Insert fields
+ dtype1.insertMember(MEMBER1, HOFFSET(s1_t, a), PredType::NATIVE_INT);
+ dtype1.insertMember(MEMBER2, HOFFSET(s1_t, b), PredType::NATIVE_INT);
+ dtype1.insertMember(MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_FLOAT);
+
+ // Save datatype for later
+ dtype1.commit(group, "Datatype1");
+
+ // Close datatype and group
+ dtype1.close();
+ group.close();
+
+ // Create a dataset
+ dataset = file1->createDataSet("Dataset3", PredType::STD_REF_OBJ, sid1);
+
+ // Create reference to dataset
+ file1->reference(&wbuf[0], "/Group1/Dataset1");
+
+ H5G_obj_t obj_type = dataset.getObjType(&wbuf[0], H5R_OBJECT);
+ verify_val(obj_type, H5G_DATASET, "DataSet::getObjType", __LINE__, __FILE__);
+
+ // Create reference to dataset
+ file1->reference(&wbuf[1], "/Group1/Dataset2");
+ obj_type = dataset.getObjType(&wbuf[1], H5R_OBJECT);
+ verify_val(obj_type, H5G_DATASET, "DataSet::getObjType", __LINE__, __FILE__);
+
+ // Create reference to group
+ file1->reference(&wbuf[2], "/Group1");
+ obj_type = dataset.getObjType(&wbuf[2], H5R_OBJECT);
+ verify_val(obj_type, H5G_GROUP, "DataSet::getObjType", __LINE__, __FILE__);
+
+ // Create reference to named datatype
+ file1->reference(&wbuf[3], "/Group1/Datatype1");
+ obj_type = dataset.getObjType(&wbuf[3], H5R_OBJECT);
+ verify_val(obj_type, H5G_TYPE, "DataSet::getObjType", __LINE__, __FILE__);
+
+ // Write selection to disk
+ dataset.write(wbuf, PredType::STD_REF_OBJ);
+
+ // Close disk dataspace, dataset, and file
+ sid1.close();
+ dataset.close();
+ delete file1;
+
+ // Re-open the file
+ file1 = new H5File(FILE1, H5F_ACC_RDWR);
+
+ // Open the dataset
+ dataset = file1->openDataSet("/Dataset3");
+
+ // Read selection from disk
+ dataset.read(rbuf, PredType::STD_REF_OBJ);
+
+ // Dereference dataset object by ctor, from the location where
+ // 'dataset' is located
+ DataSet dset2(dataset, &rbuf[0]);
+
+ // Check information in the referenced dataset
+ sid1 = dset2.getSpace();
+ hssize_t n_elements = sid1.getSimpleExtentNpoints();
+ verify_val(n_elements, 4, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
+
+ // Read from disk
+ dset2.read(tbuf, PredType::NATIVE_UINT);
+
+ for(tu32=(unsigned *)tbuf,i=0; i<SPACE1_DIM1; i++,tu32++)
+ VERIFY(*tu32, (uint32_t)(i*3), "Data");
+
+ // Close dereferenced dataset
+ dset2.close();
+
+ // Dereference group object from the location where 'dataset' is located
+ group.dereference(dataset, &rbuf[2]);
+
+ // Get group's comment
+ H5std_string read_comment1 = group.getComment(".", 10);
+ verify_val(read_comment1, write_comment, "Group::getComment", __LINE__, __FILE__);
+
+ // Close group
+ group.close();
+
+ // Dereference group object using file to specify location
+ group.dereference(*file1, &rbuf[2]);
+ H5std_string read_comment2 = group.getComment(".", 10);
+ verify_val(read_comment2, write_comment, "Group::getComment", __LINE__, __FILE__);
+ group.close();
+
+ // Dereference group object by ctor and using dataset to specify
+ // location
+ Group new_group(dataset, &rbuf[2]);
+ H5std_string read_comment3 = group.getComment(".", 10);
+ verify_val(read_comment3, write_comment, "Group::getComment", __LINE__, __FILE__);
+ group.close();
+
+ // Dereference datatype object from the location where 'dataset'
+ // is located
+ dtype1.dereference(dataset, &rbuf[3]);
+
+ // Verify correct datatype
+ H5T_class_t tclass = dtype1.getClass();
+ verify_val(tclass, H5T_COMPOUND, "DataType::getClass", __LINE__, __FILE__);
+
+ int n_members = dtype1.getNmembers();
+ verify_val(n_members, 3, "DataType::getNmembers", __LINE__, __FILE__);
+
+ // Close datatype
+ dtype1.close();
+
+ // Dereference datatype object by ctor, using file to specify location
+ DataType dtype2(*file1, &rbuf[3]);
+
+ // Verify correct datatype
+ H5T_class_t tclass2 = dtype2.getClass();
+ verify_val(tclass2, H5T_COMPOUND, "DataType::getClass", __LINE__, __FILE__);
+
+ // Close datatype
+ dtype2.close();
+
+ // Close dataset and file
+ dataset.close();
+ file1->close();
+
+ // Free memory buffers
+ free(wbuf);
+ free(rbuf);
+ free(tbuf);
+ } // end try
+ catch (Exception E) {
+ issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg());
+ }
+} // test_reference_obj()
+
+/****************************************************************
+**
+** test_reference(): Main reference testing routine.
+**
+****************************************************************/
+void
+test_reference(void)
+{
+ // Output message about test being performed
+ MESSAGE(5, ("Testing References\n"));
+
+ test_reference_obj(); // Test basic object reference functionality
+
+} // test_reference()
+
+
+/****************************************************************
+** Function: cleanup_reference
+** Purpose: Cleanup temporary test files
+** Return: none
+****************************************************************/
+void
+cleanup_reference(void)
+{
+ remove(FILE1.c_str());
+}
+