From: Paul Brossier Date: Wed, 28 Nov 2018 21:41:10 +0000 (+0100) Subject: [tests] create a temporary sink, use in wavetable test X-Git-Tag: 0.4.9~139^2~34 X-Git-Url: https://git.aubio.org/?p=aubio.git;a=commitdiff_plain;h=abe67e1b1c8d9dad64be35317f59373924534e3a [tests] create a temporary sink, use in wavetable test When called without argument, test-wavetable will invoke the function run_on_default_sink to create a temporary file and runs the main function on it. --- diff --git a/tests/src/synth/test-wavetable.c b/tests/src/synth/test-wavetable.c index f569277c..c0f4cf73 100644 --- a/tests/src/synth/test-wavetable.c +++ b/tests/src/synth/test-wavetable.c @@ -6,8 +6,8 @@ int main (int argc, char **argv) sint_t err = 0; if (argc < 2) { - err = 2; - PRINT_ERR("not enough arguments\n"); + PRINT_ERR("not enough arguments, running tests\n"); + err = run_on_default_sink(main); PRINT_MSG("usage: %s [freq] [samplerate]\n", argv[0]); return err; } diff --git a/tests/utils_tests.h b/tests/utils_tests.h index 97d5297a..de157a67 100644 --- a/tests/utils_tests.h +++ b/tests/utils_tests.h @@ -5,6 +5,13 @@ #include #include "config.h" +#ifdef HAVE_LIMITS_H +#include // PATH_MAX +#endif /* HAVE_LIMITS_H */ +#ifndef PATH_MAX +#define PATH_MAX 1024 +#endif + #ifdef HAVE_C99_VARARGS_MACROS #define PRINT_ERR(...) fprintf(stderr, "AUBIO-TESTS ERROR: " __VA_ARGS__) #define PRINT_MSG(...) fprintf(stdout, __VA_ARGS__) @@ -51,3 +58,18 @@ void utils_init_random (void) { //PRINT_WRN("current seed: %d\n", seed); srandom (seed); } + +int run_on_default_sink( int main(int, char**) ) +{ + int argc = 2, err; + char* argv[argc]; + char sink_path[PATH_MAX] = "tmp_aubio_XXXXXX"; + int fd = mkstemp(sink_path); + argv[0] = __FILE__; + if (!fd) return 1; + argv[1] = sink_path; + err = main(argc, argv); + unlink(sink_path); + close(fd); + return err; +}