comparison src/libsndfile-1.0.27/tests/utils.h @ 40:1df64224f5ac

Current libsndfile source
author Chris Cannam
date Tue, 18 Oct 2016 13:22:47 +0100
parents
children
comparison
equal deleted inserted replaced
39:7ddb4fc30dac 40:1df64224f5ac
1 /*
2 ** Copyright (C) 2002-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
13 **
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 /*
20 ** Utility functions to make writing the test suite easier.
21 **
22 ** The .c and .h files were generated automagically with Autogen from
23 ** the files utils.def and utils.tpl.
24 */
25
26
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32 #include <stdint.h>
33 #include <stdarg.h>
34
35 #define ARRAY_LEN(x) ((int) (sizeof (x)) / (sizeof ((x) [0])))
36 #define SIGNED_SIZEOF(x) ((int64_t) (sizeof (x)))
37 #define NOT(x) (! (x))
38 #define ABS(x) ((x) >= 0 ? (x) : -(x))
39
40 #define PIPE_INDEX(x) ((x) + 500)
41 #define PIPE_TEST_LEN 12345
42
43
44 void gen_windowed_sine_float (float *data, int len, double maximum) ;
45 void gen_windowed_sine_double (double *data, int len, double maximum) ;
46
47
48 void create_short_sndfile (const char *filename, int format, int channels) ;
49
50 void check_file_hash_or_die (const char *filename, uint64_t target_hash, int line_num) ;
51
52 void print_test_name (const char *test, const char *filename) ;
53
54 void dump_data_to_file (const char *filename, const void *data, unsigned int datalen) ;
55
56 void write_mono_file (const char * filename, int format, int srate, float * output, int len) ;
57
58 #ifdef __GNUC__
59 static inline void
60 exit_if_true (int test, const char *format, ...)
61 #if (defined (__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO)
62 __attribute__ ((format (gnu_printf, 2, 3))) ;
63 #else
64 __attribute__ ((format (printf, 2, 3))) ;
65 #endif
66 #endif
67
68 static inline void
69 exit_if_true (int test, const char *format, ...)
70 { if (test)
71 { va_list argptr ;
72 va_start (argptr, format) ;
73 vprintf (format, argptr) ;
74 va_end (argptr) ;
75 exit (1) ;
76 } ;
77 } /* exit_if_true */
78
79 static inline int32_t
80 arith_shift_left (int32_t x, int shift)
81 { return (int32_t) (((uint32_t) x) << shift) ;
82 } /* arith_shift_left */
83
84 /*
85 ** Functions for saving two vectors of data in an ascii text file which
86 ** can then be loaded into GNU octave for comparison.
87 */
88
89 int oct_save_short (const short *a, const short *b, int len) ;
90 int oct_save_int (const int *a, const int *b, int len) ;
91 int oct_save_float (const float *a, const float *b, int len) ;
92 int oct_save_double (const double *a, const double *b, int len) ;
93
94
95 void delete_file (int format, const char *filename) ;
96
97 void count_open_files (void) ;
98 void increment_open_file_count (void) ;
99 void check_open_file_count_or_die (int lineno) ;
100
101 #ifdef SNDFILE_H
102
103 static inline void
104 sf_info_clear (SF_INFO * info)
105 { memset (info, 0, sizeof (SF_INFO)) ;
106 } /* sf_info_clear */
107
108 static inline void
109 sf_info_setup (SF_INFO * info, int format, int samplerate, int channels)
110 { sf_info_clear (info) ;
111
112 info->format = format ;
113 info->samplerate = samplerate ;
114 info->channels = channels ;
115 } /* sf_info_setup */
116
117
118 void dump_log_buffer (SNDFILE *file) ;
119 void check_log_buffer_or_die (SNDFILE *file, int line_num) ;
120 int string_in_log_buffer (SNDFILE *file, const char *s) ;
121 void hexdump_file (const char * filename, sf_count_t offset, sf_count_t length) ;
122
123 void test_sf_format_or_die (const SF_INFO *info, int line_num) ;
124
125 SNDFILE *test_open_file_or_die
126 (const char *filename, int mode, SF_INFO *sfinfo, int allow_fd, int line_num) ;
127
128 void test_read_write_position_or_die
129 (SNDFILE *file, int line_num, int pass, sf_count_t read_pos, sf_count_t write_pos) ;
130
131 void test_seek_or_die
132 (SNDFILE *file, sf_count_t offset, int whence, sf_count_t new_pos, int channels, int line_num) ;
133
134
135 void test_read_short_or_die
136 (SNDFILE *file, int pass, short *test, sf_count_t items, int line_num) ;
137 void test_read_int_or_die
138 (SNDFILE *file, int pass, int *test, sf_count_t items, int line_num) ;
139 void test_read_float_or_die
140 (SNDFILE *file, int pass, float *test, sf_count_t items, int line_num) ;
141 void test_read_double_or_die
142 (SNDFILE *file, int pass, double *test, sf_count_t items, int line_num) ;
143
144 void test_readf_short_or_die
145 (SNDFILE *file, int pass, short *test, sf_count_t frames, int line_num) ;
146 void test_readf_int_or_die
147 (SNDFILE *file, int pass, int *test, sf_count_t frames, int line_num) ;
148 void test_readf_float_or_die
149 (SNDFILE *file, int pass, float *test, sf_count_t frames, int line_num) ;
150 void test_readf_double_or_die
151 (SNDFILE *file, int pass, double *test, sf_count_t frames, int line_num) ;
152
153
154 void
155 test_read_raw_or_die (SNDFILE *file, int pass, void *test, sf_count_t items, int line_num) ;
156
157
158 void test_write_short_or_die
159 (SNDFILE *file, int pass, const short *test, sf_count_t items, int line_num) ;
160 void test_write_int_or_die
161 (SNDFILE *file, int pass, const int *test, sf_count_t items, int line_num) ;
162 void test_write_float_or_die
163 (SNDFILE *file, int pass, const float *test, sf_count_t items, int line_num) ;
164 void test_write_double_or_die
165 (SNDFILE *file, int pass, const double *test, sf_count_t items, int line_num) ;
166
167 void test_writef_short_or_die
168 (SNDFILE *file, int pass, const short *test, sf_count_t frames, int line_num) ;
169 void test_writef_int_or_die
170 (SNDFILE *file, int pass, const int *test, sf_count_t frames, int line_num) ;
171 void test_writef_float_or_die
172 (SNDFILE *file, int pass, const float *test, sf_count_t frames, int line_num) ;
173 void test_writef_double_or_die
174 (SNDFILE *file, int pass, const double *test, sf_count_t frames, int line_num) ;
175
176
177 void
178 test_write_raw_or_die (SNDFILE *file, int pass, const void *test, sf_count_t items, int line_num) ;
179
180 void compare_short_or_die (const short *expected, const short *actual, unsigned count, int line_num) ;
181 void compare_int_or_die (const int *expected, const int *actual, unsigned count, int line_num) ;
182 void compare_float_or_die (const float *expected, const float *actual, unsigned count, int line_num) ;
183 void compare_double_or_die (const double *expected, const double *actual, unsigned count, int line_num) ;
184
185
186
187 void gen_lowpass_signal_float (float *data, int len) ;
188
189 sf_count_t file_length (const char * fname) ;
190 sf_count_t file_length_fd (int fd) ;
191
192 #endif
193
194 #ifdef __cplusplus
195 } /* extern "C" */
196 #endif /* __cplusplus */
197
198
199