cannam@125: /* cannam@125: ** Copyright (C) 2002-2016 Erik de Castro Lopo cannam@125: ** cannam@125: ** This program is free software; you can redistribute it and/or modify cannam@125: ** it under the terms of the GNU General Public License as published by cannam@125: ** the Free Software Foundation; either version 2 of the License, or cannam@125: ** (at your option) any later version. cannam@125: ** cannam@125: ** This program is distributed in the hope that it will be useful, cannam@125: ** but WITHOUT ANY WARRANTY; without even the implied warranty of cannam@125: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the cannam@125: ** GNU General Public License for more details. cannam@125: ** cannam@125: ** You should have received a copy of the GNU General Public License cannam@125: ** along with this program; if not, write to the Free Software cannam@125: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. cannam@125: */ cannam@125: cannam@125: /* cannam@125: ** Utility functions to make writing the test suite easier. cannam@125: ** cannam@125: ** The .c and .h files were generated automagically with Autogen from cannam@125: ** the files utils.def and utils.tpl. cannam@125: */ cannam@125: cannam@125: cannam@125: cannam@125: #ifdef __cplusplus cannam@125: extern "C" { cannam@125: #endif /* __cplusplus */ cannam@125: cannam@125: #include cannam@125: #include cannam@125: cannam@125: #define ARRAY_LEN(x) ((int) (sizeof (x)) / (sizeof ((x) [0]))) cannam@125: #define SIGNED_SIZEOF(x) ((int64_t) (sizeof (x))) cannam@125: #define NOT(x) (! (x)) cannam@125: #define ABS(x) ((x) >= 0 ? (x) : -(x)) cannam@125: cannam@125: #define PIPE_INDEX(x) ((x) + 500) cannam@125: #define PIPE_TEST_LEN 12345 cannam@125: cannam@125: cannam@125: void gen_windowed_sine_float (float *data, int len, double maximum) ; cannam@125: void gen_windowed_sine_double (double *data, int len, double maximum) ; cannam@125: cannam@125: cannam@125: void create_short_sndfile (const char *filename, int format, int channels) ; cannam@125: cannam@125: void check_file_hash_or_die (const char *filename, uint64_t target_hash, int line_num) ; cannam@125: cannam@125: void print_test_name (const char *test, const char *filename) ; cannam@125: cannam@125: void dump_data_to_file (const char *filename, const void *data, unsigned int datalen) ; cannam@125: cannam@125: void write_mono_file (const char * filename, int format, int srate, float * output, int len) ; cannam@125: cannam@125: #ifdef __GNUC__ cannam@125: static inline void cannam@125: exit_if_true (int test, const char *format, ...) cannam@125: #if (defined (__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO) cannam@125: __attribute__ ((format (gnu_printf, 2, 3))) ; cannam@125: #else cannam@125: __attribute__ ((format (printf, 2, 3))) ; cannam@125: #endif cannam@125: #endif cannam@125: cannam@125: static inline void cannam@125: exit_if_true (int test, const char *format, ...) cannam@125: { if (test) cannam@125: { va_list argptr ; cannam@125: va_start (argptr, format) ; cannam@125: vprintf (format, argptr) ; cannam@125: va_end (argptr) ; cannam@125: exit (1) ; cannam@125: } ; cannam@125: } /* exit_if_true */ cannam@125: cannam@125: static inline int32_t cannam@125: arith_shift_left (int32_t x, int shift) cannam@125: { return (int32_t) (((uint32_t) x) << shift) ; cannam@125: } /* arith_shift_left */ cannam@125: cannam@125: /* cannam@125: ** Functions for saving two vectors of data in an ascii text file which cannam@125: ** can then be loaded into GNU octave for comparison. cannam@125: */ cannam@125: cannam@125: int oct_save_short (const short *a, const short *b, int len) ; cannam@125: int oct_save_int (const int *a, const int *b, int len) ; cannam@125: int oct_save_float (const float *a, const float *b, int len) ; cannam@125: int oct_save_double (const double *a, const double *b, int len) ; cannam@125: cannam@125: cannam@125: void delete_file (int format, const char *filename) ; cannam@125: cannam@125: void count_open_files (void) ; cannam@125: void increment_open_file_count (void) ; cannam@125: void check_open_file_count_or_die (int lineno) ; cannam@125: cannam@125: #ifdef SNDFILE_H cannam@125: cannam@125: static inline void cannam@125: sf_info_clear (SF_INFO * info) cannam@125: { memset (info, 0, sizeof (SF_INFO)) ; cannam@125: } /* sf_info_clear */ cannam@125: cannam@125: static inline void cannam@125: sf_info_setup (SF_INFO * info, int format, int samplerate, int channels) cannam@125: { sf_info_clear (info) ; cannam@125: cannam@125: info->format = format ; cannam@125: info->samplerate = samplerate ; cannam@125: info->channels = channels ; cannam@125: } /* sf_info_setup */ cannam@125: cannam@125: cannam@125: void dump_log_buffer (SNDFILE *file) ; cannam@125: void check_log_buffer_or_die (SNDFILE *file, int line_num) ; cannam@125: int string_in_log_buffer (SNDFILE *file, const char *s) ; cannam@125: void hexdump_file (const char * filename, sf_count_t offset, sf_count_t length) ; cannam@125: cannam@125: void test_sf_format_or_die (const SF_INFO *info, int line_num) ; cannam@125: cannam@125: SNDFILE *test_open_file_or_die cannam@125: (const char *filename, int mode, SF_INFO *sfinfo, int allow_fd, int line_num) ; cannam@125: cannam@125: void test_read_write_position_or_die cannam@125: (SNDFILE *file, int line_num, int pass, sf_count_t read_pos, sf_count_t write_pos) ; cannam@125: cannam@125: void test_seek_or_die cannam@125: (SNDFILE *file, sf_count_t offset, int whence, sf_count_t new_pos, int channels, int line_num) ; cannam@125: cannam@125: cannam@125: void test_read_short_or_die cannam@125: (SNDFILE *file, int pass, short *test, sf_count_t items, int line_num) ; cannam@125: void test_read_int_or_die cannam@125: (SNDFILE *file, int pass, int *test, sf_count_t items, int line_num) ; cannam@125: void test_read_float_or_die cannam@125: (SNDFILE *file, int pass, float *test, sf_count_t items, int line_num) ; cannam@125: void test_read_double_or_die cannam@125: (SNDFILE *file, int pass, double *test, sf_count_t items, int line_num) ; cannam@125: cannam@125: void test_readf_short_or_die cannam@125: (SNDFILE *file, int pass, short *test, sf_count_t frames, int line_num) ; cannam@125: void test_readf_int_or_die cannam@125: (SNDFILE *file, int pass, int *test, sf_count_t frames, int line_num) ; cannam@125: void test_readf_float_or_die cannam@125: (SNDFILE *file, int pass, float *test, sf_count_t frames, int line_num) ; cannam@125: void test_readf_double_or_die cannam@125: (SNDFILE *file, int pass, double *test, sf_count_t frames, int line_num) ; cannam@125: cannam@125: cannam@125: void cannam@125: test_read_raw_or_die (SNDFILE *file, int pass, void *test, sf_count_t items, int line_num) ; cannam@125: cannam@125: cannam@125: void test_write_short_or_die cannam@125: (SNDFILE *file, int pass, const short *test, sf_count_t items, int line_num) ; cannam@125: void test_write_int_or_die cannam@125: (SNDFILE *file, int pass, const int *test, sf_count_t items, int line_num) ; cannam@125: void test_write_float_or_die cannam@125: (SNDFILE *file, int pass, const float *test, sf_count_t items, int line_num) ; cannam@125: void test_write_double_or_die cannam@125: (SNDFILE *file, int pass, const double *test, sf_count_t items, int line_num) ; cannam@125: cannam@125: void test_writef_short_or_die cannam@125: (SNDFILE *file, int pass, const short *test, sf_count_t frames, int line_num) ; cannam@125: void test_writef_int_or_die cannam@125: (SNDFILE *file, int pass, const int *test, sf_count_t frames, int line_num) ; cannam@125: void test_writef_float_or_die cannam@125: (SNDFILE *file, int pass, const float *test, sf_count_t frames, int line_num) ; cannam@125: void test_writef_double_or_die cannam@125: (SNDFILE *file, int pass, const double *test, sf_count_t frames, int line_num) ; cannam@125: cannam@125: cannam@125: void cannam@125: test_write_raw_or_die (SNDFILE *file, int pass, const void *test, sf_count_t items, int line_num) ; cannam@125: cannam@125: void compare_short_or_die (const short *expected, const short *actual, unsigned count, int line_num) ; cannam@125: void compare_int_or_die (const int *expected, const int *actual, unsigned count, int line_num) ; cannam@125: void compare_float_or_die (const float *expected, const float *actual, unsigned count, int line_num) ; cannam@125: void compare_double_or_die (const double *expected, const double *actual, unsigned count, int line_num) ; cannam@125: cannam@125: cannam@125: cannam@125: void gen_lowpass_signal_float (float *data, int len) ; cannam@125: cannam@125: sf_count_t file_length (const char * fname) ; cannam@125: sf_count_t file_length_fd (int fd) ; cannam@125: cannam@125: #endif cannam@125: cannam@125: #ifdef __cplusplus cannam@125: } /* extern "C" */ cannam@125: #endif /* __cplusplus */ cannam@125: cannam@125: cannam@125: