summaryrefslogtreecommitdiffstats
path: root/examples/multimedia/spectrum/3rdparty/fftreal/test.cpp
blob: 7b6ed2cab9ef88fd91b746a3bc4af4620115485f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*****************************************************************************

        test.cpp
        Copyright (c) 2005 Laurent de Soras

--- Legal stuff ---

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*Tab=3***********************************************************************/



#if defined (_MSC_VER)
	#pragma warning (4 : 4786) // "identifier was truncated to '255' characters in the debug information"
	#pragma warning (4 : 4800) // "forcing value to bool 'true' or 'false' (performance warning)"
#endif



/*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

#include	"test_settings.h"
#include	"TestHelperFixLen.h"
#include	"TestHelperNormal.h"

#if defined (_MSC_VER)
#include	<crtdbg.h>
#include	<new.h>
#endif	// _MSC_VER

#include	<new>

#include	<cassert>
#include	<cstdio>



#define	TEST_


/*\\\ FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/



static int	TEST_perform_test_accuracy_all ();
static int	TEST_perform_test_speed_all ();

static void	TEST_prog_init ();
static void	TEST_prog_end ();



int main (int argc, char *argv [])
{
	using namespace std;

	int				ret_val = 0;

	TEST_prog_init ();

	try
	{
		if (ret_val == 0)
		{
			ret_val = TEST_perform_test_accuracy_all ();
		}

		if (ret_val == 0)
		{
			ret_val = TEST_perform_test_speed_all ();
		}
	}

	catch (std::exception &e)
	{
		printf ("\n*** main(): Exception (std::exception) : %s\n", e.what ());
		ret_val = -1;
	}

	catch (...)
	{
		printf ("\n*** main(): Undefined exception\n");
		ret_val = -1;
	}

	TEST_prog_end ();

	return (ret_val);
}



int	TEST_perform_test_accuracy_all ()
{
   int            ret_val = 0;

	TestHelperNormal <float >::perform_test_accuracy (ret_val);
	TestHelperNormal <double>::perform_test_accuracy (ret_val);

   TestHelperFixLen < 1>::perform_test_accuracy (ret_val);
   TestHelperFixLen < 2>::perform_test_accuracy (ret_val);
   TestHelperFixLen < 3>::perform_test_accuracy (ret_val);
   TestHelperFixLen < 4>::perform_test_accuracy (ret_val);
   TestHelperFixLen < 7>::perform_test_accuracy (ret_val);
   TestHelperFixLen < 8>::perform_test_accuracy (ret_val);
   TestHelperFixLen <10>::perform_test_accuracy (ret_val);
   TestHelperFixLen <12>::perform_test_accuracy (ret_val);
   TestHelperFixLen <13>::perform_test_accuracy (ret_val);

	return (ret_val);
}



int	TEST_perform_test_speed_all ()
{
   int            ret_val = 0;

#if defined (test_settings_SPEED_TEST_ENABLED)

	TestHelperNormal <float >::perform_test_speed (ret_val);
	TestHelperNormal <double>::perform_test_speed (ret_val);

   TestHelperFixLen < 1>::perform_test_speed (ret_val);
   TestHelperFixLen < 2>::perform_test_speed (ret_val);
   TestHelperFixLen < 3>::perform_test_speed (ret_val);
   TestHelperFixLen < 4>::perform_test_speed (ret_val);
   TestHelperFixLen < 7>::perform_test_speed (ret_val);
   TestHelperFixLen < 8>::perform_test_speed (ret_val);
   TestHelperFixLen <10>::perform_test_speed (ret_val);
   TestHelperFixLen <12>::perform_test_speed (ret_val);
   TestHelperFixLen <14>::perform_test_speed (ret_val);
   TestHelperFixLen <16>::perform_test_speed (ret_val);
   TestHelperFixLen <20>::perform_test_speed (ret_val);

#endif

   return (ret_val);
}



#if defined (_MSC_VER)
static int __cdecl	TEST_new_handler_cb (size_t dummy)
{
	throw std::bad_alloc ();
	return (0);
}
#endif	// _MSC_VER



#if defined (_MSC_VER) && ! defined (NDEBUG)
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)
{
	if (block_type != _CRT_BLOCK)	// Ignore CRT blocks to prevent infinite recursion
	{
		switch (alloc_type)
		{
		case	_HOOK_ALLOC:
		case	_HOOK_REALLOC:
		case	_HOOK_FREE:

			// Put some debug code here

			break;

		default:
			assert (false);	// Undefined allocation type
			break;
		}
	}

	return (1);
}
#endif



#if defined (_MSC_VER) && ! defined (NDEBUG)
static int	__cdecl	TEST_debug_report_hook_cb (int report_type, char *user_msg_0, int *ret_val_ptr)
{
	*ret_val_ptr = 0;	// 1 to override the CRT default reporting mode

	switch (report_type)
	{
	case	_CRT_WARN:
	case	_CRT_ERROR:
	case	_CRT_ASSERT:

// Put some debug code here

		break;
	}

	return (*ret_val_ptr);
}
#endif



static void	TEST_prog_init ()
{
#if defined (_MSC_VER)
	::_set_new_handler (::TEST_new_handler_cb);
#endif	// _MSC_VER

#if defined (_MSC_VER) && ! defined (NDEBUG)
	{
		const int	mode =   (1 * _CRTDBG_MODE_DEBUG)
						       | (1 * _CRTDBG_MODE_WNDW);
		::_CrtSetReportMode (_CRT_WARN, mode);
		::_CrtSetReportMode (_CRT_ERROR, mode);
		::_CrtSetReportMode (_CRT_ASSERT, mode);

		const int	old_flags = ::_CrtSetDbgFlag (_CRTDBG_REPORT_FLAG);
		::_CrtSetDbgFlag (  old_flags
		                  | (1 * _CRTDBG_LEAK_CHECK_DF)
		                  | (1 * _CRTDBG_CHECK_ALWAYS_DF));
		::_CrtSetBreakAlloc (-1);	// Specify here a memory bloc number
		::_CrtSetAllocHook (TEST_debug_alloc_hook_cb);
		::_CrtSetReportHook (TEST_debug_report_hook_cb);

		// Speed up I/O but breaks C stdio compatibility
//		std::cout.sync_with_stdio (false);
//		std::cin.sync_with_stdio (false);
//		std::cerr.sync_with_stdio (false);
//		std::clog.sync_with_stdio (false);
	}
#endif	// _MSC_VER, NDEBUG
}



static void	TEST_prog_end ()
{
#if defined (_MSC_VER) && ! defined (NDEBUG)
	{
		const int	mode =   (1 * _CRTDBG_MODE_DEBUG)
						       | (0 * _CRTDBG_MODE_WNDW);
		::_CrtSetReportMode (_CRT_WARN, mode);
		::_CrtSetReportMode (_CRT_ERROR, mode);
		::_CrtSetReportMode (_CRT_ASSERT, mode);

		::_CrtMemState	mem_state;
		::_CrtMemCheckpoint (&mem_state);
		::_CrtMemDumpStatistics (&mem_state);
	}
#endif	// _MSC_VER, NDEBUG
}



/*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/