summaryrefslogtreecommitdiffstats
path: root/c++/test/ttypes.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2018-07-17 17:21:07 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2018-07-17 17:21:07 (GMT)
commita31cd3623ff9493b7d6209efe23afcab84b05320 (patch)
tree215649251105b0a8be708f8fb746908ee93cf449 /c++/test/ttypes.cpp
parent3aa24435180d10aeca6493f7c1b277cfd5c73fad (diff)
downloadhdf5-a31cd3623ff9493b7d6209efe23afcab84b05320.zip
hdf5-a31cd3623ff9493b7d6209efe23afcab84b05320.tar.gz
hdf5-a31cd3623ff9493b7d6209efe23afcab84b05320.tar.bz2
Fixed HDFFV-10472
Description: Added operator!= to DataType bool operator!=(const DataType& compared_type) Platforms tested: Linux/64 (jelly) Linux/32 (jam) Darwin (osx1010test)
Diffstat (limited to 'c++/test/ttypes.cpp')
-rw-r--r--c++/test/ttypes.cpp81
1 files changed, 81 insertions, 0 deletions
diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp
index a2bd561..b30d9e7 100644
--- a/c++/test/ttypes.cpp
+++ b/c++/test/ttypes.cpp
@@ -1026,6 +1026,86 @@ static void test_encode_decode()
/*-------------------------------------------------------------------------
+ * Function: test_operators
+ *
+ * Purpose Test datatype encode/decode functionality.
+ *
+ * Return None
+ *
+ * Programmer Binh-Minh Ribler (using C version)
+ * August, 2017
+ *-------------------------------------------------------------------------
+ */
+const H5std_string filename4("h5_type_operators.h5");
+
+static void test_operators()
+{
+ short enum_val;
+
+ SUBTEST("DataType::operator== and DataType::operator!=");
+ try {
+ // Create the file.
+ H5File file(filename4, 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);
+
+ // Copy this compound datatype
+ CompType clone_cmptyp(cmptyp);
+
+ // Verify that operator== and operator!= work properly
+ verify_val(cmptyp == clone_cmptyp, true, "DataType::operator==", __LINE__, __FILE__);
+ verify_val(cmptyp != clone_cmptyp, false, "DataType::operator!=", __LINE__, __FILE__);
+
+ //
+ // 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));
+
+ // Verify that operator== and operator!= work properly
+ verify_val(cmptyp == enumtyp, false, "DataType::operator==", __LINE__, __FILE__);
+ verify_val(cmptyp != enumtyp, true, "DataType::operator!=", __LINE__, __FILE__);
+
+ //
+ // Test with compound datatype's member
+ //
+
+ // Create a variable-length string type
+ IntType inttyp(PredType::NATIVE_INT);
+ FloatType flttyp(PredType::NATIVE_FLOAT);
+
+ // Get NATIVE_INT member from the compound datatype above
+ IntType member_inttyp = cmptyp.getMemberIntType(0);
+
+ verify_val(inttyp == member_inttyp, true, "DataType::operator==", __LINE__, __FILE__);
+ verify_val(flttyp == member_inttyp, false, "DataType::operator==", __LINE__, __FILE__);
+ verify_val(flttyp != member_inttyp, true, "DataType::operator==", __LINE__, __FILE__);
+
+ PASSED();
+ }
+ catch (Exception& E)
+ {
+ issue_fail_msg("test_operators", __LINE__, __FILE__, E.getCDetailMsg());
+ }
+} // test_operators
+
+
+/*-------------------------------------------------------------------------
* Function: test_types
*
* Purpose Main datatypes testing routine
@@ -1048,6 +1128,7 @@ void test_types()
test_transient();
test_named();
test_encode_decode();
+ test_operators();
} // test_types()