summaryrefslogtreecommitdiffstats
path: root/c++/test
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2017-09-04 05:41:47 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2017-09-04 05:41:47 (GMT)
commit9b6f4d4937bd0e196e472e71120d6ed4b17e24f7 (patch)
tree433214c61b8cac549ce12f3073d479b697113d05 /c++/test
parent883a235d5ca81770228c5cb5f9d162afda0b411f (diff)
downloadhdf5-9b6f4d4937bd0e196e472e71120d6ed4b17e24f7.zip
hdf5-9b6f4d4937bd0e196e472e71120d6ed4b17e24f7.tar.gz
hdf5-9b6f4d4937bd0e196e472e71120d6ed4b17e24f7.tar.bz2
Adding new C++ wrappers
Description: Added wrappers for H5Tencode to class DataType and H5Tdecode to classes DataType and its subclasses. // Creates a binary object description of this datatype. void DataType::encode() // Returns the decoded type from the binary object description. virtual DataType* DataType::decode() const; virtual DataType* ArrayType::decode() const; virtual DataType* CompType::decode() const; virtual DataType* DataType::decode() const; virtual DataType* EnumType::decode() const; virtual DataType* FloatType::decode() const; virtual DataType* IntType::decode() const; virtual DataType* StrType::decode() const; virtual DataType* VarLenType::decode() const; Platforms tested: Linux/32 2.6 (jam) Linux/64 (platypus) Darwin (osx1010test)
Diffstat (limited to 'c++/test')
-rw-r--r--c++/test/ttypes.cpp252
1 files changed, 234 insertions, 18 deletions
diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp
index f76f780..ec644a8 100644
--- a/c++/test/ttypes.cpp
+++ b/c++/test/ttypes.cpp
@@ -80,6 +80,12 @@ typedef enum int_t {
INT_LONG, INT_ULONG, INT_LLONG, INT_ULLONG, INT_OTHER
} int_t;
+typedef struct {
+ int a;
+ float b;
+ long c;
+ double d;
+} src_typ_t;
/*-------------------------------------------------------------------------
* Function: test_classes
@@ -125,9 +131,7 @@ static void test_classes()
*
* Purpose Test datatype copy functionality
*
- * Return Success: 0
- *
- * Failure: number of errors
+ * Return None
*
* Programmer Binh-Minh Ribler (using C version)
* January, 2007
@@ -183,9 +187,7 @@ static void test_copy()
*
* Purpose Tests query functions of compound and enumeration types.
*
- * Return Success: 0
- *
- * Failure: number of errors
+ * Return None
*
* Programmer Binh-Minh Ribler (use C version)
* January, 2007
@@ -200,12 +202,6 @@ const H5std_string EnumT_NAME("Enum_type");
static void test_query()
{
- typedef struct {
- int a;
- float b;
- long c;
- double d;
- } src_typ_t;
short enum_val;
// Output message about test being performed
@@ -317,9 +313,7 @@ static void test_query()
*
* Purpose Tests transient datatypes.
*
- * Return Success: 0
- *
- * Failure: number of errors
+ * Return None
*
* Programmer Binh-Minh Ribler (use C version)
* January, 2007
@@ -396,9 +390,7 @@ static void test_transient ()
*
* Purpose Tests named datatypes.
*
- * Return Success: 0
- *
- * Failure: number of errors
+ * Return None
*
* Programmer Binh-Minh Ribler (use C version)
* January, 2007
@@ -556,6 +548,229 @@ static void test_named ()
} // test_named
+/*-------------------------------------------------------------------------
+ * Function: test_encode_decode
+ *
+ * Purpose Test datatype encode/decode functionality.
+ *
+ * Return None
+ *
+ * Programmer Binh-Minh Ribler (using C version)
+ * August, 2017
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+const H5std_string filename3("encode_decode.h5");
+const int ARRAY1_RANK = 1;
+const int ARRAY1_DIM = 10;
+static void test_encode_decode()
+{
+ short enum_val;
+
+ SUBTEST("DataType::encode() and DataType::decode()");
+ try {
+ // Create the file.
+ H5File file(filename3, H5F_ACC_TRUNC);
+
+ //
+ // Test with CompType
+ //
+
+ // Create a compound datatype
+ CompType cmptyp(sizeof(src_typ_t));
+
+ cmptyp.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT);
+ cmptyp.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_FLOAT);
+ cmptyp.insertMember("c", HOFFSET(src_typ_t, c), PredType::NATIVE_LONG);
+ cmptyp.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_DOUBLE);
+
+ // Encode compound type in its buffer
+ cmptyp.encode();
+
+ // Verify that encoding had been done
+ verify_val(cmptyp.hasBinaryDesc(), true, "DataType::encode", __LINE__, __FILE__);
+
+ // Decode compound type's buffer to a new CompType
+ CompType* decoded_cmp_ptr(static_cast<CompType *>(cmptyp.decode()));
+
+ // Verify that the datatype was copied exactly via encoding/decoding
+ verify_val(cmptyp == *decoded_cmp_ptr, true, "DataType::decode", __LINE__, __FILE__);
+
+ // Verify again via querying member number and member index by name.
+ verify_val(decoded_cmp_ptr->getNmembers(), 4, "DataType::decode", __LINE__, __FILE__);
+ verify_val(decoded_cmp_ptr->getMemberIndex("c"), 2, "DataType::decode", __LINE__, __FILE__);
+
+ // Create a CompType instance from the pointer and verify it
+ CompType cmptyp_clone(*decoded_cmp_ptr);
+ verify_val(cmptyp == cmptyp_clone, true, "DataType::decode", __LINE__, __FILE__);
+ verify_val(cmptyp_clone.getNmembers(), 4, "DataType::decode", __LINE__, __FILE__);
+ verify_val(cmptyp_clone.getMemberIndex("c"), 2, "DataType::decode", __LINE__, __FILE__);
+
+ delete decoded_cmp_ptr;
+
+ //
+ // Test with EnumType
+ //
+
+ // Create a enumerate datatype
+ EnumType enumtyp(sizeof(short));
+
+ enumtyp.insert("RED", (enum_val=0,&enum_val));
+ enumtyp.insert("GREEN", (enum_val=1,&enum_val));
+ enumtyp.insert("BLUE", (enum_val=2,&enum_val));
+ enumtyp.insert("ORANGE", (enum_val=3,&enum_val));
+ enumtyp.insert("YELLOW", (enum_val=4,&enum_val));
+
+ // Encode compound type in a buffer
+ enumtyp.encode();
+
+ // Verify that encoding had been done
+ verify_val(enumtyp.hasBinaryDesc(), true, "DataType::encode", __LINE__, __FILE__);
+
+ // Decode enumeration type's buffer to a new EnumType
+ EnumType* decoded_enum_ptr(static_cast<EnumType *>(enumtyp.decode()));
+
+ // Verify that the datatype was copied exactly via encoding/decoding
+ verify_val(enumtyp == *decoded_enum_ptr, true, "DataType::decode", __LINE__, __FILE__);
+
+ // Verify again via querying member number and member index by name.
+ verify_val(decoded_enum_ptr->getNmembers(), 5, "DataType::decode", __LINE__, __FILE__);
+ verify_val(decoded_enum_ptr->getMemberIndex("GREEN"), 1, "DataType::decode", __LINE__, __FILE__);
+
+ // Create a EnumType instance from the pointer and verify it
+ EnumType enumtyp_clone(*decoded_enum_ptr);
+ verify_val(enumtyp == enumtyp_clone, true, "DataType::decode", __LINE__, __FILE__);
+ verify_val(enumtyp_clone.getNmembers(), 5, "DataType::decode", __LINE__, __FILE__);
+ verify_val(enumtyp_clone.getMemberIndex("GREEN"), 1, "DataType::decode", __LINE__, __FILE__);
+
+ delete decoded_enum_ptr;
+
+ //
+ // Test with variable-length string
+ //
+
+ // Create a variable-length string type
+ StrType vlsttyp(PredType::C_S1);
+ vlsttyp.setSize(H5T_VARIABLE);
+
+ // Encode the variable-length type in its buffer
+ vlsttyp.encode();
+
+ // Verify that encoding had been done
+ verify_val(vlsttyp.hasBinaryDesc(), true, "DataType::encode", __LINE__, __FILE__);
+
+ // Decode the variable-length type's buffer to a new StrType
+ StrType* decoded_str_ptr(static_cast<StrType *>(vlsttyp.decode()));
+
+ verify_val(vlsttyp == *decoded_str_ptr, true, "DataType::decode", __LINE__, __FILE__);
+ verify_val(decoded_str_ptr->isVariableStr(), true, "DataType::decode", __LINE__, __FILE__);
+
+ delete decoded_str_ptr;
+
+ // Test decoding the type by way of DataType*
+
+ // Decode variable-length string type to a new DataType
+ DataType* decoded_vlstr_ptr(vlsttyp.decode());
+
+ // Create a StrType instance from the DataType object and verify it
+ StrType decoded_vlsttyp(decoded_vlstr_ptr->getId());
+ verify_val(vlsttyp == decoded_vlsttyp, true, "DataType::decode", __LINE__, __FILE__);
+ verify_val(decoded_vlsttyp.isVariableStr(), true, "DataType::decode", __LINE__, __FILE__);
+
+ delete decoded_vlstr_ptr;
+
+ //
+ // Test with ArrayType
+ //
+
+ hsize_t tdims1[] = {ARRAY1_DIM};
+
+ // Create an array datatype of the compound datatype
+ ArrayType arrtyp(cmptyp, ARRAY1_RANK, tdims1);
+
+ // Encode the array type in its buffer
+ arrtyp.encode();
+
+ // Verify that encoding had been done
+ verify_val(arrtyp.hasBinaryDesc(), true, "DataType::encode", __LINE__, __FILE__);
+
+ // Create an ArrayType instance from the decoded pointer and verify it
+ ArrayType* decoded_arr_ptr(static_cast<ArrayType *>(arrtyp.decode()));
+
+ verify_val(arrtyp == *decoded_arr_ptr, true, "DataType::decode", __LINE__, __FILE__);
+
+ delete decoded_arr_ptr;
+
+ // Test decoding the type by way of DataType*
+
+ // Decode the array type's buffer
+ DataType *decoded_dt_ptr = arrtyp.decode();
+
+ // Create a ArrayType instance from the decoded pointer and verify it
+ ArrayType decoded_arrtyp(decoded_dt_ptr->getId());
+ verify_val(arrtyp == decoded_arrtyp, true, "DataType::decode", __LINE__, __FILE__);
+ verify_val(decoded_arrtyp.getArrayNDims(), ARRAY1_RANK, "DataType::decode", __LINE__, __FILE__);
+
+ delete decoded_dt_ptr;
+
+ //
+ // Test with IntType
+ //
+
+ // Create an int datatype
+ IntType inttyp(PredType::NATIVE_UINT);
+
+ // Encode the array type in its buffer
+ inttyp.encode();
+
+ // Verify that encoding had been done
+ verify_val(inttyp.hasBinaryDesc(), true, "DataType::encode", __LINE__, __FILE__);
+
+ // Create an IntType instance from the decoded pointer and verify it
+ IntType* decoded_int_ptr(static_cast<IntType *>(inttyp.decode()));
+ H5T_sign_t int_sign = decoded_int_ptr->getSign();
+ verify_val(int_sign, H5T_SGN_NONE, "DataType::decode", __LINE__, __FILE__);
+ verify_val(inttyp == *decoded_int_ptr, true, "DataType::decode", __LINE__, __FILE__);
+
+ delete decoded_int_ptr;
+
+ //
+ // Test decoding FloatType by way of DataType*
+ //
+
+ // Create a float datatype
+ FloatType flttyp(PredType::NATIVE_FLOAT);
+
+ // Encode the float type in its buffer
+ flttyp.encode();
+
+ // Verify that encoding had been done
+ verify_val(flttyp.hasBinaryDesc(), true, "DataType::encode", __LINE__, __FILE__);
+
+ // Decode the array type's buffer
+ DataType* decoded_flt_ptr(flttyp.decode());
+
+ // Create a IntType instance from the decoded pointer and verify it
+ FloatType decoded_flttyp(decoded_flt_ptr->getId());
+ verify_val(flttyp == decoded_flttyp, true, "DataType::decode", __LINE__, __FILE__);
+
+ H5std_string norm_string;
+ H5T_norm_t mant_norm = decoded_flttyp.getNorm(norm_string);
+ //verify_val(decoded_flttyp.isVariableStr(), true, "DataType::decode", __LINE__, __FILE__);
+
+ delete decoded_flt_ptr;
+
+ PASSED();
+ }
+ catch (Exception& E)
+ {
+ issue_fail_msg("test_encode_decode", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+}
+
+
/****************************************************************
**
** test_types(): Main datatypes testing routine.
@@ -573,6 +788,7 @@ void test_types()
test_query();
test_transient();
test_named();
+ test_encode_decode();
} // test_types()