Fix some of the tests for MinGW and fix the use of Sleep/usleep for MinGW & MSVC platforms

* Sleep takes ms, not s
* Use sleep/Sleep rather than usleep in the cdchange sample, as usleep
  is not available on recent MinGW platforms

From pbatard branch.
This commit is contained in:
R. Bernstein
2012-02-24 22:03:19 -05:00
parent 871eca6415
commit 734c6473b3
4 changed files with 45 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
/* /*
Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
Rocky Bernstein <rocky@gnu.org> Rocky Bernstein <rocky@gnu.org>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
@@ -26,7 +26,9 @@
#include <cdio/cdio.h> #include <cdio/cdio.h>
/* Test media changed */ /* Test media changed */
#ifdef HAVE_STDIO_H
# include <stdio.h> # include <stdio.h>
#endif
#ifdef HAVE_LIMITS_H #ifdef HAVE_LIMITS_H
# include <limits.h> # include <limits.h>
@@ -51,22 +53,22 @@
#ifdef HAVE_WINDOWS_H #ifdef HAVE_WINDOWS_H
# include <windows.h> # include <windows.h>
#endif #endif
#if !defined(HAVE_SLEEP) && defined(_WIN32)
#ifndef HAVE_USLEEP #include <windows.h>
#error usleep() unimplemented #define sleep(s) Sleep(1000*s)
#endif #endif
int int
main(int argc, const char *argv[]) main(int argc, const char *argv[])
{ {
CdIo_t *p_cdio; CdIo_t *p_cdio;
unsigned long i_sleep_ms = (30 * 1000000); unsigned int i_sleep = 30;
if (argc > 1) { if (argc > 1) {
p_cdio = cdio_open (argv[1], DRIVER_DEVICE); p_cdio = cdio_open (argv[1], DRIVER_DEVICE);
if (argc > 2) { if (argc > 2) {
errno = 0; errno = 0;
i_sleep_ms = strtol(argv[2], (char **)NULL, 10) * 1000000; i_sleep = strtol(argv[2], (char **)NULL, 10);
if ( (LONG_MIN == i_sleep_ms || LONG_MAX == i_sleep_ms) && errno != 0 ) { if ( (LONG_MIN == i_sleep || LONG_MAX == i_sleep) && errno != 0 ) {
printf("Invalid sleep parameter %s\n", argv[2]); printf("Invalid sleep parameter %s\n", argv[2]);
printf("Error reported back from strtol: %s\n", strerror(errno)); printf("Error reported back from strtol: %s\n", strerror(errno));
return 2; return 2;
@@ -86,13 +88,9 @@ main(int argc, const char *argv[])
else else
printf("Initial media status: not changed\n"); printf("Initial media status: not changed\n");
printf("Giving you %g seconds to change CD if you want to do so.\n", printf("Giving you %d seconds to change CD if you want to do so.\n",
i_sleep_ms / 1000000.0); i_sleep);
{ sleep(i_sleep);
int i_ret = usleep(i_sleep_ms);
if (0 != i_ret)
fprintf(stderr, "Something went wrong with usleep\n");
}
if (cdio_get_media_changed(p_cdio)) if (cdio_get_media_changed(p_cdio))
printf("Media status: changed\n"); printf("Media status: changed\n");
else else

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /* -*- C -*-
Copyright (C) 2009 Thomas Schmitt <scdbackup@gmx.net> Copyright (C) 2009 Thomas Schmitt <scdbackup@gmx.net>
Copyright (C) 2010, 2011 Rocky Bernstein <rocky@gnu.org> Copyright (C) 2010, 2011, 2012 Rocky Bernstein <rocky@gnu.org>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -36,7 +36,16 @@
#ifdef HAVE_STDLIB_H #ifdef HAVE_STDLIB_H
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#ifdef HAVE_STRING_H
#include <string.h> #include <string.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#if !defined(HAVE_SLEEP) && defined(_WIN32)
#include <windows.h>
#define sleep(s) Sleep(1000*s)
#endif
#define SKIP_TEST 77 #define SKIP_TEST 77

View File

@@ -1,6 +1,6 @@
/* -*- C -*- /* -*- C -*-
Copyright (C) 2009 Thomas Schmitt <scdbackup@gmx.net> Copyright (C) 2009 Thomas Schmitt <scdbackup@gmx.net>
Copyright (C) 2010 Rocky Bernstein <rocky@gnu.org> Copyright (C) 2010, 2012 Rocky Bernstein <rocky@gnu.org>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -36,7 +36,13 @@
#ifdef HAVE_STDLIB_H #ifdef HAVE_STDLIB_H
# include <stdlib.h> # include <stdlib.h>
#endif #endif
#ifdef HAVE_STRING_H
# include <string.h> # include <string.h>
#endif
#if !defined(HAVE_SLEEP) && defined(_WIN32)
# include <windows.h>
# define sleep(s) Sleep(1000*s)
#endif
#define SKIP_TEST 77 #define SKIP_TEST 77
@@ -518,7 +524,7 @@ test_rwr_mode_page(CdIo_t *p_cdio, unsigned int i_flag)
} else if (memcmp(buf, old_buf, i_size) != 0) { } else if (memcmp(buf, old_buf, i_size) != 0) {
fprintf(stderr, fprintf(stderr,
"test_rwr_mode_page: Mode page was not restored to old state.\n"); "test_rwr_mode_page: Mode page was not restored to old state.\n");
final_return = -1; final_return = final_return > 0 ? -1 : final_return;
} }
if (i_flag & 1) if (i_flag & 1)
printf("test_rwr_mode_page: Mode page 2Ah restored to previous state\n"); printf("test_rwr_mode_page: Mode page 2Ah restored to previous state\n");

View File

@@ -47,6 +47,14 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>
#include <direct.h> /* _mkdir */
/* MinGW, MSVC do not have symlink */
#define symlink(oldpath, newpath) CopyFileA(oldpath, newpath, FALSE)
#else
#define _mkdir(a) mkdir(a, S_IRWXU)
#endif
#ifdef HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
# include <errno.h> # include <errno.h>
@@ -102,7 +110,7 @@ main(int argc, const char *argv[])
exit(77); exit(77);
} }
if (-1 == check_rc(mkdir(psz_tmp_subdir, 0700), if (-1 == check_rc(_mkdir(psz_tmp_subdir),
"mkdir", psz_tmp_subdir)) "mkdir", psz_tmp_subdir))
exit(77); exit(77);