#define PATH_MAX 1024
#endif
-#define DEFAULT_TEST_FILE "python/tests/sounds/44100Hz_44100f_sine441.wav"
+#if defined(HAVE_WIN_HACKS) && !defined(__GNUC__)
+#include <io.h> // _access
+#endif
+
+// This macro is used to pass a string to msvc compiler: since msvc's -D flag
+// strips the quotes, we define the string without quotes and re-add them with
+// this macro.
+
+#define REDEFINESTRING(x) #x
+#define DEFINEDSTRING(x) REDEFINESTRING(x)
+
+#ifndef AUBIO_TESTS_SOURCE
+#error "AUBIO_TESTS_SOURCE is not defined"
+#endif
#ifdef HAVE_C99_VARARGS_MACROS
#define PRINT_ERR(...) fprintf(stderr, "AUBIO-TESTS ERROR: " __VA_ARGS__)
// create_temp_sink / close_temp_sink
#if defined(__GNUC__) // mkstemp
+int check_source(char *source_path)
+{
+ return access(source_path, R_OK);
+}
+
int create_temp_sink(char *sink_path)
{
return mkstemp(sink_path);
#elif defined(HAVE_WIN_HACKS) //&& !defined(__GNUC__)
// windows workaround, where mkstemp does not exist...
+
+int check_source(char *source_path)
+{
+ return _access(source_path, 04);
+}
+
int create_temp_sink(char *templ)
{
int i = 0;
// pass progname / default
int run_on_default_source( int main(int, char**) )
{
- int argc = 2;
- char* argv[argc];
- argv[0] = __FILE__;
- // when running from waf build
- argv[1] = "../../" DEFAULT_TEST_FILE;
- // when running from source root directory
- if ( access(argv[1], R_OK) )
- argv[1] = DEFAULT_TEST_FILE;
- // no file found
- if ( access(argv[1], R_OK) != 0 )
- return 1;
- return main(argc, argv);
-}
-
-int run_on_default_source_and_sink( int main(int, char**) )
-{
- int argc = 3, err;
- char* argv[argc];
+ const int argc = 2;
+ int err = 0;
+ char** argv = (char**)calloc(argc, sizeof(char*));
argv[0] = __FILE__;
- // when running from waf build
- argv[1] = "../../" DEFAULT_TEST_FILE;
- // when running from source root directory
- if ( access(argv[1], R_OK) )
- argv[1] = DEFAULT_TEST_FILE;
- // no file found
- if ( access(argv[1], R_OK) != 0 )
- return 1;
- char sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
- int fd = mkstemp(sink_path);
- if (!fd) return 1;
- argv[2] = sink_path;
+ argv[1] = DEFINEDSTRING(AUBIO_TESTS_SOURCE);
+ // check if the file can be read
+ if ( check_source(argv[1]) ) return 1;
err = main(argc, argv);
- unlink(sink_path);
- close(fd);
+ if (argv) free(argv);
return err;
}
{
const int argc = 2;
int err = 0;
- char* argv[argc];
+ char** argv = (char**)calloc(argc, sizeof(char*));
char sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
int fd = create_temp_sink(sink_path);
if (!fd) return 1;
argv[1] = sink_path;
err = main(argc, argv);
close_temp_sink(sink_path, fd);
+ if (argv) free(argv);
return err;
}