Changeset aa15080


Ignore:
Timestamp:
Nov 29, 2018, 12:07:58 AM (13 months ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master
Children:
d22b568
Parents:
a6065b9
Message:

[tests] workaround for windows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/utils_tests.h

    ra6065b9 raa15080  
    6464}
    6565
     66// create_temp_sink / close_temp_sink
     67#if defined(__GNUC__) // mkstemp
     68
     69int create_temp_sink(char *sink_path)
     70{
     71  return mkstemp(sink_path);
     72}
     73
     74int close_temp_sink(char *sink_path, int sink_fildes)
     75{
     76  int err;
     77  if ((err = close(sink_fildes)) != 0) return err;
     78  if ((err = unlink(sink_path)) != 0) return err;
     79  return err;
     80}
     81
     82#elif (defined(HAVE_WIN_HACKS) //&& !defined(__GNUC__))
     83// windows workaround, where mkstemp does not exist...
     84int create_temp_sink(char *templ)
     85{
     86  int i = 0;
     87  static const char letters[] = "abcdefg0123456789";
     88  int letters_len = strlen(letters);
     89  int templ_len = strlen(templ);
     90  if (templ_len == 0) return 0;
     91  utils_init_random();
     92  for (i = 0; i < 6; i++)
     93  {
     94    templ[templ_len - i] = letters[rand() % letters_len];
     95  }
     96  return 1;
     97}
     98
     99int close_temp_sink(char* sink_path, int sink_fildes) {
     100  // the file should be closed when not using mkstemp, no need to open it
     101  if (sink_fildes == 0) return 1;
     102  return _unlink(sink_path);
     103}
     104
     105#else // windows workaround
     106// otherwise, we don't really know what to do yet
     107#error "mkstemp undefined, but not on windows. additional workaround required."
     108#endif
     109
     110
    66111int run_on_default_sink( int main(int, char**) )
    67112{
     
    69114  char* argv[argc];
    70115  char sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
    71   int fd = mkstemp(sink_path);
     116  int fd = create_temp_sink(sink_path);
     117  if (!fd) return 1;
    72118  argv[0] = __FILE__;
    73   if (!fd) return 1;
    74119  argv[1] = sink_path;
    75120  err = main(argc, argv);
    76   unlink(sink_path);
    77   close(fd);
     121  close_temp_sink(sink_path, fd);
    78122  return err;
    79123}
Note: See TracChangeset for help on using the changeset viewer.