[tests] sync test-source with base-source_custom
[aubio.git] / tests / src / io / test-source_seek.c
index 5b7a7f7..8defe22 100644 (file)
@@ -5,8 +5,8 @@ int main (int argc, char **argv)
 {
   uint_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_source(main);
     PRINT_MSG("read a wave file as a mono vector\n");
     PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     PRINT_MSG("examples:\n");
@@ -22,9 +22,9 @@ int main (int argc, char **argv)
   uint_t samplerate = 0;
   uint_t hop_size = 256;
   uint_t n_frames = 0, read = 0;
-  uint_t old_n_frames_1, old_n_frames_2, old_n_frames_3;
-  if ( argc == 3 ) samplerate = atoi(argv[2]);
-  if ( argc == 4 ) hop_size = atoi(argv[3]);
+  uint_t old_n_frames_1 = 0, old_n_frames_2 = 0, old_n_frames_3 = 0;
+  if ( argc >= 3 ) samplerate = atoi(argv[2]);
+  if ( argc >= 4 ) hop_size = atoi(argv[3]);
 
   char_t *source_path = argv[1];
 
@@ -64,7 +64,7 @@ int main (int argc, char **argv)
 
   old_n_frames_2 = n_frames;
 
-  aubio_source_seek (s, n_frames / 2);
+  aubio_source_seek (s, old_n_frames_1 / 2);
 
   n_frames = 0;
   do {
@@ -84,7 +84,9 @@ int main (int argc, char **argv)
 beach:
   del_fvec (vec);
 
+  // check that we got exactly the same number of frames
   assert ( old_n_frames_2 == old_n_frames_1 );
-  assert ( old_n_frames_3 == (uint_t)floor(old_n_frames_1 / 2. + .5) );
+  // check that we got about half the frames, with 3 decimals
+  assert ( roundf(1.e3 * old_n_frames_1 / old_n_frames_3) / 1.e3 == 2.);
   return err;
 }