shithub: aubio

Download patch

ref: 0f5f40bbd31550e8b1b8b3019c94fdf5c2a3dd20
parent: e4e0861cffbc8d3a53dcd18f9ae85797690d67c7
author: Paul Brossier <piem@piem.org>
date: Sat Nov 24 14:00:11 EST 2018

[tests] run some tests in onset if no arguments passed

--- a/tests/src/onset/test-onset.c
+++ b/tests/src/onset/test-onset.c
@@ -1,13 +1,20 @@
 #include <aubio.h>
 #include "utils_tests.h"
 
+int test_wrong_params(void);
+
 int main (int argc, char **argv)
 {
   uint_t err = 0;
   if (argc < 2) {
     err = 2;
-    PRINT_ERR("not enough arguments\n");
-    PRINT_MSG("read a wave file as a mono vector\n");
+    PRINT_WRN("no arguments, running tests\n");
+    if (test_wrong_params() != 0) {
+      PRINT_ERR("tests failed!\n");
+      err = 1;
+    } else {
+      err = 0;
+    }
     PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     return err;
   }
@@ -59,4 +66,38 @@
   aubio_cleanup();
 
   return err;
+}
+
+int test_wrong_params(void)
+{
+  uint_t win_size = 1024;
+  uint_t hop_size = win_size / 2;
+  uint_t samplerate = 44100;
+  // hop_size < 1
+  if (new_aubio_onset("default", 5, 0, samplerate))
+    return 1;
+  // buf_size < 2
+  if (new_aubio_onset("default", 1, 1, samplerate))
+    return 1;
+  // buf_size < hop_size
+  if (new_aubio_onset("default", hop_size, win_size, samplerate))
+    return 1;
+  // samplerate < 1
+  if (new_aubio_onset("default", 1024, 512, 0))
+    return 1;
+
+  // specdesc creation failed
+  if (new_aubio_onset("abcd", win_size, win_size/2, samplerate))
+    return 1;
+  // pv creation failed
+  if (new_aubio_onset("default", 5, 2, samplerate))
+    return 1;
+
+  aubio_onset_t *o;
+  o = new_aubio_onset("default", win_size, hop_size, samplerate);
+  if (!aubio_onset_set_default_parameters(o, "wrong_type"))
+    return 1;
+  del_aubio_onset(o);
+
+  return 0;
 }