summaryrefslogtreecommitdiffstats
path: root/c++/test
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2017-03-16 23:19:32 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2017-03-16 23:19:32 (GMT)
commitf7711df680f2ccd07f23223deccb217440ec3788 (patch)
tree4ad4633af3ce182c14aecd4430135298d0a95371 /c++/test
parent368089572a079f0801ab7177aab2719d4cbd4e48 (diff)
parent98090fe3b08a0ff85ae9bc93218a14017a6f37fe (diff)
downloadhdf5-f7711df680f2ccd07f23223deccb217440ec3788.zip
hdf5-f7711df680f2ccd07f23223deccb217440ec3788.tar.gz
hdf5-f7711df680f2ccd07f23223deccb217440ec3788.tar.bz2
Merge pull request #334 in HDFFV/hdf5 from ~BMRIBLER/hdf5_bmr_cpp2:develop to develop
* commit '98090fe3b08a0ff85ae9bc93218a14017a6f37fe': Purpose: Add new C++ wrappers Description: Added wrappers for H5Iis_valid, H5Ps/get_nlinks, H5Tget_create_plist, H5Oopen, H5Oclose and H5Pset_virtual
Diffstat (limited to 'c++/test')
-rw-r--r--c++/test/dsets.cpp82
-rw-r--r--c++/test/tlinks.cpp54
-rw-r--r--c++/test/tobject.cpp121
-rw-r--r--c++/test/ttypes.cpp20
4 files changed, 271 insertions, 6 deletions
diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp
index 48a0c4d..970f210 100644
--- a/c++/test/dsets.cpp
+++ b/c++/test/dsets.cpp
@@ -1148,6 +1148,87 @@ test_types(H5File& file)
/*-------------------------------------------------------------------------
+ * Function: test_virtual
+ *
+ * Purpose: Tests fixed, unlimited, and printf selections in the same
+ * VDS
+ *
+ * Return: Success: 0
+ *
+ * Failure: number of errors
+ *
+ * Programmer: Binh-Minh Ribler
+ * Friday, March 10, 2017
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+const int RANK = 2;
+static herr_t
+test_virtual()
+{
+ SUBTEST("DSetCreatPropList::setVirtual");
+
+ try {
+ // Create DCPLs
+ DSetCreatPropList dcpl;
+ DSetCreatPropList srcdcpl;
+
+ // Set fill value
+ char *fill = NULL;
+ dcpl.setFillValue(PredType::NATIVE_INT, &fill);
+
+ // Set chunk dimensions
+ hsize_t cdims[RANK];
+ cdims[0] = 2;
+ cdims[1] = 2;
+ srcdcpl.setChunk(RANK, cdims);
+
+ // Create memory space
+ hsize_t mdims[RANK];
+ mdims[0] = 10;
+ mdims[1] = 10;
+ DataSpace memspace(RANK, mdims);
+
+ // Get the current layout, should be default, H5D_CONTIGUOUS
+ H5D_layout_t layout = dcpl.getLayout();
+ verify_val(layout, H5D_CONTIGUOUS, "DSetCreatPropList::getLayout", __LINE__, __FILE__);
+
+ // Create fixed mapping
+ hsize_t dims[RANK];
+ dims[0] = 6;
+ dims[1] = 6;
+ DataSpace vspace(RANK, dims, mdims);
+
+ hsize_t start[RANK]; // Hyperslab start
+ hsize_t count[RANK]; // Hyperslab count
+ start[0] = start[1] = 3;
+ count[0] = count[1] = 3;
+ vspace.selectHyperslab(H5S_SELECT_SET, count, start);
+
+ DataSpace srcspace(RANK, count);
+
+ H5std_string src_file = "src_file_map.h5";
+ H5std_string src_dset = "src_dset_fixed";
+ dcpl.setVirtual(vspace, src_file, src_dset, srcspace);
+
+ // Get and verify the new layout
+ layout = dcpl.getLayout();
+ verify_val(layout, H5D_VIRTUAL, "DSetCreatPropList::getLayout", __LINE__, __FILE__);
+
+ PASSED();
+ return 0;
+ } // end top try block
+
+ catch (Exception& E)
+ {
+ return -1;
+ }
+} // test_virtual
+
+
+/*-------------------------------------------------------------------------
* Function: test_dset
*
* Purpose Tests the dataset interface (H5D)
@@ -1195,6 +1276,7 @@ void test_dset()
nerrors += test_nbit_compression(file) < 0 ? 1:0;
nerrors += test_multiopen (file) < 0 ? 1:0;
nerrors += test_types(file) < 0 ? 1:0;
+ nerrors += test_virtual() < 0 ? 1:0;
// Close group "emit diagnostics".
grp.close();
diff --git a/c++/test/tlinks.cpp b/c++/test/tlinks.cpp
index c217718..0bf6ebf 100644
--- a/c++/test/tlinks.cpp
+++ b/c++/test/tlinks.cpp
@@ -142,11 +142,8 @@ const char *FILENAME[] = {
#define H5L_DIM2 100
/* Creation order macros */
-#define CORDER_GROUP_NAME "corder_group"
#define CORDER_SOFT_GROUP_NAME "corder_soft_group"
#define CORDER_NLINKS 18
-#define CORDER_ITER_STOP 3
-#define CORDER_EST_ENTRY_LEN 9
/* Timestamp macros */
#define TIMESTAMP_GROUP_1 "timestamp1"
@@ -341,7 +338,7 @@ static const char *FILENAME[] = {
static void test_basic_links(hid_t fapl_id, hbool_t new_format)
{
hsize_t size[1] = {1};
- char filename[NAME_BUF_SIZE];
+ char filename[NAME_BUF_SIZE];
// Use the file access template id to create a file access prop. list.
FileAccPropList fapl(fapl_id);
@@ -441,6 +438,55 @@ static void test_basic_links(hid_t fapl_id, hbool_t new_format)
/*-------------------------------------------------------------------------
+ * Function: test_num_links
+ *
+ * Purpose Test setting and getting limit of number of links
+ *
+ * Return Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer Binh-Minh Ribler
+ * October 16, 2009
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static void test_num_links(hid_t fapl_id, hbool_t new_format)
+{
+ char filename[NAME_BUF_SIZE];
+
+ if(new_format)
+ SUBTEST("Setting number of links (w/new group format)")
+ else
+ SUBTEST("Setting number of links")
+
+ try
+ {
+ // Use the file access template id to create a file access prop. list.
+ FileAccPropList fapl(fapl_id);
+
+ h5_fixname(FILENAME[0], fapl_id, filename, sizeof filename);
+ H5File file(filename, H5F_ACC_RDWR, FileCreatPropList::DEFAULT, fapl);
+
+ LinkAccPropList lapl;
+ size_t nlinks = 5;
+ lapl.setNumLinks(nlinks);
+
+ // Read it back and verify
+ size_t read_nlinks = lapl.getNumLinks();
+ verify_val(read_nlinks, nlinks, "LinkAccPropList::setNumLinks", __LINE__, __FILE__);
+
+ PASSED();
+ } // end of try block
+ catch (Exception& E)
+ {
+ issue_fail_msg("test_num_links()", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+} // test_num_links
+
+/*-------------------------------------------------------------------------
* Function: test_links
*
* Purpose Test links
diff --git a/c++/test/tobject.cpp b/c++/test/tobject.cpp
index 6003dd6..3c9c1b0 100644
--- a/c++/test/tobject.cpp
+++ b/c++/test/tobject.cpp
@@ -32,6 +32,7 @@ using namespace H5;
#include "h5cpputil.h" // C++ utilility header file
const H5std_string FILE_OBJECTS("tobjects.h5");
+const H5std_string FILE_OBJHDR("tobject_header.h5");
const H5std_string GROUP1("Top Group");
const H5std_string GROUP1_PATH("/Top Group");
const H5std_string GROUP1_1("Sub-Group 1.1");
@@ -395,7 +396,126 @@ static void test_get_objtype()
issue_fail_msg("test_get_objtype", __LINE__, __FILE__);
}
} // test_get_objtype
+
+/*-------------------------------------------------------------------------
+ * Function: test_open_object_header
+ *
+ * Purpose Test Group::getObjId function.
+ *
+ * Return None
+ *
+ * Programmer Binh-Minh Ribler (use C version)
+ * March, 2017
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+const H5std_string GROUPNAME("group");
+const H5std_string DTYPENAME("group/datatype");
+const H5std_string DTYPENAME_INGRP("datatype");
+const H5std_string DSETNAME("dataset");
+#define RANK 2
+#define DIM0 5
+#define DIM1 10
+static void test_open_object_header()
+{
+ hsize_t dims[2];
+ H5G_info_t ginfo; /* Group info struct */
+
+ // Output message about test being performed
+ SUBTEST("Group::getObjId");
+
+ try {
+ // Create file FILE1
+ H5File file1(FILE_OBJHDR, H5F_ACC_TRUNC);
+ /* Create a group, dataset, and committed datatype within the file */
+
+ // Create a group in the root group
+ Group grp(file1.createGroup(GROUPNAME));
+ grp.close();
+ // Commit the type inside the file
+ IntType dtype(PredType::NATIVE_INT);
+ dtype.commit(file1, DTYPENAME);
+ dtype.close();
+
+ // Create a new dataset
+ dims[0] = DIM0;
+ dims[1] = DIM1;
+ DataSpace dspace(RANK, dims);
+ DataSet dset(file1.createDataSet(DSETNAME, PredType::NATIVE_INT, dspace));
+
+ // Close dataset and dataspace
+ dset.close();
+ dspace.close();
+
+ // Now make sure that getObjId can open all three types of objects
+ hid_t obj_grp = file1.getObjId(GROUPNAME);
+ hid_t obj_dtype = file1.getObjId(DTYPENAME);
+ hid_t obj_dset = file1.getObjId(DSETNAME);
+
+ // Make sure that each is the right kind of ID
+ H5I_type_t id_type = IdComponent::getHDFObjType(obj_grp);
+ verify_val(id_type, H5I_GROUP, "H5Iget_type for group ID", __LINE__, __FILE__);
+ id_type = IdComponent::getHDFObjType(obj_dtype);
+ verify_val(id_type, H5I_DATATYPE, "H5Iget_type for datatype ID", __LINE__, __FILE__);
+ id_type = IdComponent::getHDFObjType(obj_dset);
+ verify_val(id_type, H5I_DATASET, "H5Iget_type for dataset ID", __LINE__, __FILE__);
+
+ /* Do something more complex with each of the IDs to make sure */
+
+ Group grp2(obj_grp);
+ hsize_t num_objs = grp2.getNumObjs();
+ verify_val(num_objs, 1, "H5Gget_info", __LINE__, __FILE__);
+ // There should be one object, the datatype
+
+ // Close datatype object opened from the file
+ file1.closeObjId(obj_dtype);
+
+ dset.setId(obj_dset);
+ dspace = dset.getSpace();
+ bool is_simple = dspace.isSimple();
+ dspace.close();
+
+ // Open datatype object from the group
+ obj_dtype = grp2.getObjId(DTYPENAME_INGRP);
+
+ dtype.setId(obj_dtype);
+ H5T_class_t type_class = dtype.getClass();
+ verify_val(type_class, H5T_INTEGER, "H5Tget_class", __LINE__, __FILE__);
+ dtype.close();
+
+ // Close datatype object
+ grp2.closeObjId(obj_dtype);
+
+ // Close the group object
+ file1.closeObjId(obj_grp);
+
+ // Try doing something with group, the ID should still work
+ num_objs = grp2.getNumObjs();
+ verify_val(num_objs, 1, "H5Gget_info", __LINE__, __FILE__);
+
+ // Close the cloned group
+ grp2.close();
+
+ PASSED();
+ } // end of try block
+ // catch invalid action exception
+ catch (InvalidActionException& E)
+ {
+ cerr << " in InvalidActionException" << endl;
+ cerr << " *FAILED*" << endl;
+ cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl;
+ }
+ // catch all other exceptions
+ catch (Exception& E)
+ {
+ cerr << " in Exception" << endl;
+ issue_fail_msg("test_file_name()", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+} /* test_open_object_header() */
+
/*-------------------------------------------------------------------------
* Function: test_objects
*
@@ -421,6 +541,7 @@ void test_object()
test_existance(); // Test check for object existance
test_get_objname_ontypes(); // Test get object name from types
test_get_objtype(); // Test get object type
+ test_open_object_header(); // Test object header functions (H5O)
} // test_objects
diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp
index 0cc8918..22db539 100644
--- a/c++/test/ttypes.cpp
+++ b/c++/test/ttypes.cpp
@@ -248,12 +248,28 @@ static void test_query()
index = tid2.getMemberIndex("ORANGE");
verify_val(index, 3, "EnumType::getMemberIndex()", __LINE__, __FILE__);
- // Commit compound datatype and close it
+ // Commit compound datatype, and test getting the datatype creation
+ // prop list, then close it
tid1.commit(file, CompT_NAME);
+ PropList tcpl = tid1.getCreatePlist();
+ if (!IdComponent::isValid(tcpl.getId()))
+ {
+ // Throw an invalid action exception
+ throw InvalidActionException("H5Object::createAttribute", "Datatype creation property list is not valid");
+ }
+ tcpl.close();
tid1.close();
- // Commit enumeration datatype and close it
+ // Commit enumeration datatype, and test getting the datatype creation
+ // prop list, then close it
tid2.commit(file, EnumT_NAME);
+ tcpl = tid2.getCreatePlist();
+ if (!IdComponent::isValid(tcpl.getId()))
+ {
+ // Throw an invalid action exception
+ throw InvalidActionException("H5Object::createAttribute", "Datatype creation property list is not valid");
+ }
+ tcpl.close();
tid2.close();
// Open the datatypes for query