shithub: aubio

Download patch

ref: abe67e1b1c8d9dad64be35317f59373924534e3a
parent: c0ce78fc1b46449b7e03a0d77a2a4b453400d87d
author: Paul Brossier <piem@piem.org>
date: Wed Nov 28 17:41:10 EST 2018

[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.

--- a/tests/src/synth/test-wavetable.c
+++ b/tests/src/synth/test-wavetable.c
@@ -6,8 +6,8 @@
   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 <output_path> [freq] [samplerate]\n", argv[0]);
     return err;
   }
--- a/tests/utils_tests.h
+++ b/tests/utils_tests.h
@@ -5,6 +5,13 @@
 #include <assert.h>
 #include "config.h"
 
+#ifdef HAVE_LIMITS_H
+#include <limits.h> // 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__)
@@ -50,4 +57,19 @@
   int seed = tm_struct->tm_sec;
   //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;
 }