source: tests/utils_tests.h @ a6065b9

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretch
Last change on this file since a6065b9 was a6065b9, checked in by Paul Brossier <piem@piem.org>, 13 months ago

[tests] include unistd for unlink, close (linux, darwin)

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include <time.h>
2#include <stdlib.h>
3#include <stdio.h>
4#include <math.h>
5#include <assert.h>
6#include "config.h"
7
8#ifdef HAVE_UNISTD_H
9#include <unistd.h> // unlink, close
10#endif
11
12#ifdef HAVE_LIMITS_H
13#include <limits.h> // PATH_MAX
14#endif /* HAVE_LIMITS_H */
15#ifndef PATH_MAX
16#define PATH_MAX 1024
17#endif
18
19#ifdef HAVE_C99_VARARGS_MACROS
20#define PRINT_ERR(...)   fprintf(stderr, "AUBIO-TESTS ERROR: " __VA_ARGS__)
21#define PRINT_MSG(...)   fprintf(stdout, __VA_ARGS__)
22#define PRINT_DBG(...)   fprintf(stderr, __VA_ARGS__)
23#define PRINT_WRN(...)   fprintf(stderr, "AUBIO-TESTS WARNING: " __VA_ARGS__)
24#else
25#define PRINT_ERR(format, args...)   fprintf(stderr, "AUBIO-TESTS ERROR: " format , ##args)
26#define PRINT_MSG(format, args...)   fprintf(stdout, format , ##args)
27#define PRINT_DBG(format, args...)   fprintf(stderr, format , ##args)
28#define PRINT_WRN(format, args...)   fprintf(stderr, "AUBIO-TESTS WARNING: " format, ##args)
29#endif
30
31#ifndef M_PI
32#define M_PI         (3.14159265358979323846)
33#endif
34
35#ifndef RAND_MAX
36#define RAND_MAX 32767
37#endif
38
39// are we on windows ? or are we using -std=c99 ?
40#if defined(HAVE_WIN_HACKS) || defined(__STRICT_ANSI__)
41// http://en.wikipedia.org/wiki/Linear_congruential_generator
42// no srandom/random on win32
43
44uint_t srandom_seed = 1029;
45
46void srandom(uint_t new_seed) {
47    srandom_seed = new_seed;
48}
49
50uint_t random(void) {
51    srandom_seed = 1664525 * srandom_seed + 1013904223;
52    return srandom_seed;
53}
54#endif
55
56void utils_init_random (void);
57
58void utils_init_random (void) {
59  time_t now = time(0);
60  struct tm *tm_struct = localtime(&now);
61  int seed = tm_struct->tm_sec;
62  //PRINT_WRN("current seed: %d\n", seed);
63  srandom (seed);
64}
65
66int run_on_default_sink( int main(int, char**) )
67{
68  int argc = 2, err;
69  char* argv[argc];
70  char sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
71  int fd = mkstemp(sink_path);
72  argv[0] = __FILE__;
73  if (!fd) return 1;
74  argv[1] = sink_path;
75  err = main(argc, argv);
76  unlink(sink_path);
77  close(fd);
78  return err;
79}
Note: See TracBrowser for help on using the repository browser.