|
1 /***************************************************************************** |
|
2 |
|
3 test.cpp |
|
4 Copyright (c) 2005 Laurent de Soras |
|
5 |
|
6 --- Legal stuff --- |
|
7 |
|
8 This library is free software; you can redistribute it and/or |
|
9 modify it under the terms of the GNU Lesser General Public |
|
10 License as published by the Free Software Foundation; either |
|
11 version 2.1 of the License, or (at your option) any later version. |
|
12 |
|
13 This library is distributed in the hope that it will be useful, |
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 Lesser General Public License for more details. |
|
17 |
|
18 You should have received a copy of the GNU Lesser General Public |
|
19 License along with this library; if not, write to the Free Software |
|
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 |
|
22 *Tab=3***********************************************************************/ |
|
23 |
|
24 |
|
25 |
|
26 #if defined (_MSC_VER) |
|
27 #pragma warning (4 : 4786) // "identifier was truncated to '255' characters in the debug information" |
|
28 #pragma warning (4 : 4800) // "forcing value to bool 'true' or 'false' (performance warning)" |
|
29 #endif |
|
30 |
|
31 |
|
32 |
|
33 /*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ |
|
34 |
|
35 #include "test_settings.h" |
|
36 #include "TestHelperFixLen.h" |
|
37 #include "TestHelperNormal.h" |
|
38 |
|
39 #if defined (_MSC_VER) |
|
40 #include <crtdbg.h> |
|
41 #include <new.h> |
|
42 #endif // _MSC_VER |
|
43 |
|
44 #include <new> |
|
45 |
|
46 #include <cassert> |
|
47 #include <cstdio> |
|
48 |
|
49 |
|
50 |
|
51 #define TEST_ |
|
52 |
|
53 |
|
54 /*\\\ FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ |
|
55 |
|
56 |
|
57 |
|
58 static int TEST_perform_test_accuracy_all (); |
|
59 static int TEST_perform_test_speed_all (); |
|
60 |
|
61 static void TEST_prog_init (); |
|
62 static void TEST_prog_end (); |
|
63 |
|
64 |
|
65 |
|
66 int main (int argc, char *argv []) |
|
67 { |
|
68 using namespace std; |
|
69 |
|
70 int ret_val = 0; |
|
71 |
|
72 TEST_prog_init (); |
|
73 |
|
74 try |
|
75 { |
|
76 if (ret_val == 0) |
|
77 { |
|
78 ret_val = TEST_perform_test_accuracy_all (); |
|
79 } |
|
80 |
|
81 if (ret_val == 0) |
|
82 { |
|
83 ret_val = TEST_perform_test_speed_all (); |
|
84 } |
|
85 } |
|
86 |
|
87 catch (std::exception &e) |
|
88 { |
|
89 printf ("\n*** main(): Exception (std::exception) : %s\n", e.what ()); |
|
90 ret_val = -1; |
|
91 } |
|
92 |
|
93 catch (...) |
|
94 { |
|
95 printf ("\n*** main(): Undefined exception\n"); |
|
96 ret_val = -1; |
|
97 } |
|
98 |
|
99 TEST_prog_end (); |
|
100 |
|
101 return (ret_val); |
|
102 } |
|
103 |
|
104 |
|
105 |
|
106 int TEST_perform_test_accuracy_all () |
|
107 { |
|
108 int ret_val = 0; |
|
109 |
|
110 TestHelperNormal <float >::perform_test_accuracy (ret_val); |
|
111 TestHelperNormal <double>::perform_test_accuracy (ret_val); |
|
112 |
|
113 TestHelperFixLen < 1>::perform_test_accuracy (ret_val); |
|
114 TestHelperFixLen < 2>::perform_test_accuracy (ret_val); |
|
115 TestHelperFixLen < 3>::perform_test_accuracy (ret_val); |
|
116 TestHelperFixLen < 4>::perform_test_accuracy (ret_val); |
|
117 TestHelperFixLen < 7>::perform_test_accuracy (ret_val); |
|
118 TestHelperFixLen < 8>::perform_test_accuracy (ret_val); |
|
119 TestHelperFixLen <10>::perform_test_accuracy (ret_val); |
|
120 TestHelperFixLen <12>::perform_test_accuracy (ret_val); |
|
121 TestHelperFixLen <13>::perform_test_accuracy (ret_val); |
|
122 |
|
123 return (ret_val); |
|
124 } |
|
125 |
|
126 |
|
127 |
|
128 int TEST_perform_test_speed_all () |
|
129 { |
|
130 int ret_val = 0; |
|
131 |
|
132 #if defined (test_settings_SPEED_TEST_ENABLED) |
|
133 |
|
134 TestHelperNormal <float >::perform_test_speed (ret_val); |
|
135 TestHelperNormal <double>::perform_test_speed (ret_val); |
|
136 |
|
137 TestHelperFixLen < 1>::perform_test_speed (ret_val); |
|
138 TestHelperFixLen < 2>::perform_test_speed (ret_val); |
|
139 TestHelperFixLen < 3>::perform_test_speed (ret_val); |
|
140 TestHelperFixLen < 4>::perform_test_speed (ret_val); |
|
141 TestHelperFixLen < 7>::perform_test_speed (ret_val); |
|
142 TestHelperFixLen < 8>::perform_test_speed (ret_val); |
|
143 TestHelperFixLen <10>::perform_test_speed (ret_val); |
|
144 TestHelperFixLen <12>::perform_test_speed (ret_val); |
|
145 TestHelperFixLen <14>::perform_test_speed (ret_val); |
|
146 TestHelperFixLen <16>::perform_test_speed (ret_val); |
|
147 TestHelperFixLen <20>::perform_test_speed (ret_val); |
|
148 |
|
149 #endif |
|
150 |
|
151 return (ret_val); |
|
152 } |
|
153 |
|
154 |
|
155 |
|
156 #if defined (_MSC_VER) |
|
157 static int __cdecl TEST_new_handler_cb (size_t dummy) |
|
158 { |
|
159 throw std::bad_alloc (); |
|
160 return (0); |
|
161 } |
|
162 #endif // _MSC_VER |
|
163 |
|
164 |
|
165 |
|
166 #if defined (_MSC_VER) && ! defined (NDEBUG) |
|
167 static int __cdecl TEST_debug_alloc_hook_cb (int alloc_type, void *user_data_ptr, size_t size, int block_type, long request_nbr, const unsigned char *filename_0, int line_nbr) |
|
168 { |
|
169 if (block_type != _CRT_BLOCK) // Ignore CRT blocks to prevent infinite recursion |
|
170 { |
|
171 switch (alloc_type) |
|
172 { |
|
173 case _HOOK_ALLOC: |
|
174 case _HOOK_REALLOC: |
|
175 case _HOOK_FREE: |
|
176 |
|
177 // Put some debug code here |
|
178 |
|
179 break; |
|
180 |
|
181 default: |
|
182 assert (false); // Undefined allocation type |
|
183 break; |
|
184 } |
|
185 } |
|
186 |
|
187 return (1); |
|
188 } |
|
189 #endif |
|
190 |
|
191 |
|
192 |
|
193 #if defined (_MSC_VER) && ! defined (NDEBUG) |
|
194 static int __cdecl TEST_debug_report_hook_cb (int report_type, char *user_msg_0, int *ret_val_ptr) |
|
195 { |
|
196 *ret_val_ptr = 0; // 1 to override the CRT default reporting mode |
|
197 |
|
198 switch (report_type) |
|
199 { |
|
200 case _CRT_WARN: |
|
201 case _CRT_ERROR: |
|
202 case _CRT_ASSERT: |
|
203 |
|
204 // Put some debug code here |
|
205 |
|
206 break; |
|
207 } |
|
208 |
|
209 return (*ret_val_ptr); |
|
210 } |
|
211 #endif |
|
212 |
|
213 |
|
214 |
|
215 static void TEST_prog_init () |
|
216 { |
|
217 #if defined (_MSC_VER) |
|
218 ::_set_new_handler (::TEST_new_handler_cb); |
|
219 #endif // _MSC_VER |
|
220 |
|
221 #if defined (_MSC_VER) && ! defined (NDEBUG) |
|
222 { |
|
223 const int mode = (1 * _CRTDBG_MODE_DEBUG) |
|
224 | (1 * _CRTDBG_MODE_WNDW); |
|
225 ::_CrtSetReportMode (_CRT_WARN, mode); |
|
226 ::_CrtSetReportMode (_CRT_ERROR, mode); |
|
227 ::_CrtSetReportMode (_CRT_ASSERT, mode); |
|
228 |
|
229 const int old_flags = ::_CrtSetDbgFlag (_CRTDBG_REPORT_FLAG); |
|
230 ::_CrtSetDbgFlag ( old_flags |
|
231 | (1 * _CRTDBG_LEAK_CHECK_DF) |
|
232 | (1 * _CRTDBG_CHECK_ALWAYS_DF)); |
|
233 ::_CrtSetBreakAlloc (-1); // Specify here a memory bloc number |
|
234 ::_CrtSetAllocHook (TEST_debug_alloc_hook_cb); |
|
235 ::_CrtSetReportHook (TEST_debug_report_hook_cb); |
|
236 |
|
237 // Speed up I/O but breaks C stdio compatibility |
|
238 // std::cout.sync_with_stdio (false); |
|
239 // std::cin.sync_with_stdio (false); |
|
240 // std::cerr.sync_with_stdio (false); |
|
241 // std::clog.sync_with_stdio (false); |
|
242 } |
|
243 #endif // _MSC_VER, NDEBUG |
|
244 } |
|
245 |
|
246 |
|
247 |
|
248 static void TEST_prog_end () |
|
249 { |
|
250 #if defined (_MSC_VER) && ! defined (NDEBUG) |
|
251 { |
|
252 const int mode = (1 * _CRTDBG_MODE_DEBUG) |
|
253 | (0 * _CRTDBG_MODE_WNDW); |
|
254 ::_CrtSetReportMode (_CRT_WARN, mode); |
|
255 ::_CrtSetReportMode (_CRT_ERROR, mode); |
|
256 ::_CrtSetReportMode (_CRT_ASSERT, mode); |
|
257 |
|
258 ::_CrtMemState mem_state; |
|
259 ::_CrtMemCheckpoint (&mem_state); |
|
260 ::_CrtMemDumpStatistics (&mem_state); |
|
261 } |
|
262 #endif // _MSC_VER, NDEBUG |
|
263 } |
|
264 |
|
265 |
|
266 |
|
267 /*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/ |