1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /*****************************************************************************
15    FILE
16    tdspl.cpp - HDF5 C++ testing the dataset memory and transfer property
17                list functionality
18 
19  ***************************************************************************/
20 
21 #ifdef OLD_HEADER_FILENAME
22 #include <iostream.h>
23 #else
24 #include <iostream>
25 #endif
26 using std::cerr;
27 using std::endl;
28 
29 #include <string>
30 #include "H5Cpp.h"      // C++ API header file
31 using namespace H5;
32 
33 #include "h5cpputil.h"  // C++ utilility header file
34 
35 const H5std_string FILENAME("tdatatransform.h5");
36 
test_transfplist()37 static void test_transfplist()
38 {
39     const char* c_to_f = "(9/5.0)*x + 32";
40     const char* simple = "(4/2) * ( (2 + 4)/(5 - 2.5))"; /* this equals 4.8 */
41     /* inverses the utrans transform in init_test to get back original array */
42     const char* utrans_inv = "(x/3)*4 - 100";
43 
44     SUBTEST("DSetMemXferPropList::set/getDataTransform()");
45     try {
46         // Create various data set prop lists and set data transform expression.
47         DSetMemXferPropList dxpl_c_to_f(c_to_f);
48 
49         DSetMemXferPropList dxpl_simple;
50         dxpl_simple.setDataTransform(simple);
51 
52         DSetMemXferPropList dxpl_utrans_inv;
53         dxpl_utrans_inv.setDataTransform(utrans_inv);
54 
55         //
56         // Make a copy of one of those prop lists then read the data transform
57         // expression and verify that it's the same as the original.
58         //
59 
60         // Copy the prop list.
61         DSetMemXferPropList dxpl_c_to_f_copy;
62         dxpl_c_to_f_copy.copy(dxpl_c_to_f);
63 
64         // Find out the length of the transform expression, allocate the buffer
65         // for it, then read and verify the expression from the copied plist
66         ssize_t tran_len = dxpl_c_to_f_copy.getDataTransform(NULL);
67         char *c_to_f_read = (char *)HDmalloc(tran_len+1);
68         HDmemset(c_to_f_read, 0, tran_len+1);
69         dxpl_c_to_f_copy.getDataTransform(c_to_f_read, tran_len+1);
70         verify_val((const char*)c_to_f_read, (const char*)c_to_f,
71                 "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__);
72         HDfree(c_to_f_read);
73 
74         //
75         // Read the expression of each of the prop lists and verify the read
76         // expression
77         //
78 
79         // Get and verify the expression with:
80         // ssize_t getDataTransform(char* exp, const size_t buf_size [default=0])
81         tran_len =  dxpl_c_to_f.getDataTransform(NULL);
82         c_to_f_read = (char *)HDmalloc(tran_len+1);
83         HDmemset(c_to_f_read, 0, tran_len+1);
84         dxpl_c_to_f.getDataTransform(c_to_f_read, tran_len+1);
85         verify_val((const char*)c_to_f_read, (const char*)c_to_f,
86                 "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__);
87         HDfree(c_to_f_read);
88 
89         // Get and verify the expression with:
90         // H5std_string DSetMemXferPropList::getDataTransform()
91         H5std_string simple_read = dxpl_simple.getDataTransform();
92         verify_val((const char*)simple_read.c_str(), (const char*)simple,
93                 "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__);
94 
95         // Get and verify the expression with:
96         // ssize_t getDataTransform(char* exp, const size_t buf_size)
97         tran_len = dxpl_utrans_inv.getDataTransform(NULL, 0);
98         char *utrans_inv_read = (char *)HDmalloc(tran_len+1);
99         HDmemset(utrans_inv_read, 0, tran_len+1);
100         dxpl_utrans_inv.getDataTransform(utrans_inv_read, tran_len+1);
101         verify_val((const char*)utrans_inv_read, (const char*)utrans_inv,
102                 "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__);
103         HDfree(utrans_inv_read);
104 
105         PASSED();
106     }
107     catch (Exception& E)
108     {
109         issue_fail_msg("test_transfplist", __LINE__, __FILE__, E.getCDetailMsg());
110     }
111 }
112 
113 
114 /****************************************************************
115 **
116 **  test_dsproplist(): Main dataset property list testing routine.
117 **
118 ****************************************************************/
119 extern "C"
test_dsproplist()120 void test_dsproplist()
121 {
122     // Output message about test being performed
123     MESSAGE(5, ("Testing Generic Dataset Property Lists\n"));
124 
125     test_transfplist(); // test set/getDataTransform()
126 
127 }   // test_dsproplist()
128 
129 
130 extern "C"
cleanup_dsproplist()131 void cleanup_dsproplist()
132 {
133     HDremove(FILENAME.c_str());
134 }
135