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    h5cpputil.h - Header file of the utilities/misc for HDF5 C++ tests.
17 
18    EXTERNAL ROUTINES/VARIABLES:
19 
20  ***************************************************************************/
21 
22 #ifndef _h5cpputil_h
23 #define _h5cpputil_h
24 
25 #include "h5test.h"
26 
27 using namespace H5;
28 using std::cerr;
29 using std::endl;
30 
31 #define MESSAGE(V,A) {if (HDGetTestVerbosity()>(V)) print_func A;}
32 #define SUBTEST(TEST) {printf("   Subtest: %-52s",TEST); fflush(stdout);}
33 
34 int check_values (hsize_t i, hsize_t j, int apoint, int acheck);
35 void check_values(const char *value, const char* msg, int line, const char* file_name);
36 int test_report (int, const H5std_string&);
37 void issue_fail_msg(const char* where, int line, const char* file_name,
38                     const char* message="");
39 void issue_fail_msg(const char* where, int line, const char* file_name,
40                     const char* func_name, const char* message);
41 
42 class InvalidActionException : public Exception {
43    public:
44         InvalidActionException(const H5std_string func_name, const H5std_string message = DEFAULT_MSG);
45         InvalidActionException();
46         virtual ~InvalidActionException() throw();
47 };
48 
49 class TestFailedException : public Exception {
50    public:
51         TestFailedException(const H5std_string func_name, const H5std_string message = DEFAULT_MSG);
52         TestFailedException();
53         virtual ~TestFailedException() throw();
54 };
55 
56 // Overloaded/Template functions to verify values and display proper info
57 
58 // Verifies
59 void verify_val(const char* x, const char* value, const char* where, int line, const char* file_name);
60 
61 template <class Type1, class Type2>
verify_val(Type1 x,Type2 value,const char * where,int line,const char * file_name)62     void verify_val(Type1 x, Type2 value, const char* where, int line, const char* file_name)
63 {
64     if (GetTestVerbosity()>=VERBO_HI)
65     {
66         cerr << endl;
67         cerr << "   Call to routine: " << where << " at line " << line
68              << " in " << file_name <<  " had value " << x << endl;
69     }
70     if (x != value)
71     {
72         cerr << endl;
73         cerr << "*** UNEXPECTED VALUE from " << where << " should be "
74              << value << ", but is " << x << " at line " << line
75              << " in " << file_name << endl;
76         IncTestNumErrs();
77         throw TestFailedException(where, "");
78     }
79 }
80 
81 template <class Type1, class Type2>
verify_val(Type1 x,Type2 value,const char * msg,const char * file_name,int line)82     void verify_val(Type1 x, Type2 value, const char* msg, const char* file_name, int line)
83 {
84     if (x != value)
85     {
86         cerr << endl;
87         cerr << "*** UNEXPECTED VALUE: " << file_name << ":line " << line
88              << ": " << msg << " different: " << x << ", should be " << value
89              << endl;
90         IncTestNumErrs();
91         throw TestFailedException(file_name, msg);
92     }
93 }
94 
95 template <class Type1, class Type2>
verify_val_noteq(Type1 x,Type2 value,const char * where,int line,const char * file_name)96     void verify_val_noteq(Type1 x, Type2 value, const char* where, int line, const char* file_name)
97 {
98     if (GetTestVerbosity()>=VERBO_HI)
99     {
100         cerr << endl;
101         cerr << "   Call to routine: " << where << " at line " << line
102              << " in " << file_name <<  " had value " << x << endl;
103     }
104     if (x == value)
105     {
106         cerr << endl;
107         cerr << "*** UNEXPECTED VALUE from " << where << " should not be "
108              << value << " at line " << line << " in " << file_name << endl;
109         IncTestNumErrs();
110         throw TestFailedException(where, "");
111     }
112 }
113 
114 template <class Type1, class Type2>
CHECK(Type1 x,Type2 value,const char * msg,int line,const char * file_name)115     void CHECK(Type1 x, Type2 value, const char* msg, int line, const char* file_name)
116 {
117     if (x == value)
118     {
119         cerr << endl;
120         cerr << "*** Function " << msg << " FAILED at line " << line << endl;
121         IncTestNumErrs();
122         throw TestFailedException(file_name, msg);
123     }
124 }
125 
126 template <class Type1, class Type2>
verify_val(Type1 x,Type2 value,float epsilon,const char * msg,int line,const char * file_name)127     void verify_val(Type1 x, Type2 value, float epsilon, const char* msg, int line, const char* file_name)
128 {
129     if (x == value)
130     {
131         cerr << endl;
132         cerr << "*** UNEXPECTED FLOAT VALUE: " << file_name << ":line " << line
133              << ": " << msg << " different: " << x << ", should be " << value
134              << " (epsilon=" << epsilon << ")" << endl;
135         IncTestNumErrs();
136         throw TestFailedException(file_name, msg);
137     }
138 }
139 
140 /* Prototypes for the test routines */
141 #ifdef __cplusplus
142 extern "C" {
143 #endif
144 void test_array();
145 void test_attr();
146 void test_compound();
147 void test_dsproplist();
148 void test_file();
149 void test_filters();
150 void test_links();
151 void test_h5s();
152 void test_iterate();
153 void test_object();
154 void test_reference();
155 void test_types();
156 void test_vlstrings();
157 void test_dset();
158 
159 /* Prototypes for the cleanup routines */
160 void cleanup_array();
161 void cleanup_attr();
162 void cleanup_compound();
163 void cleanup_dsproplist();
164 void cleanup_dsets();
165 void cleanup_file();
166 void cleanup_filters();
167 void cleanup_h5s();
168 void cleanup_iterate();
169 void cleanup_links();
170 void cleanup_object();
171 void cleanup_reference();
172 void cleanup_types();
173 void cleanup_vlstrings();
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 /* not yet
180 void cleanup_select(void);
181 void cleanup_time(void);
182 void cleanup_vltypes(void);
183 void cleanup_array(void);
184 void cleanup_genprop(void);
185 void cleanup_misc(void);
186 */
187 
188 #endif
189