From 2034c41957ce544b223845e72e4535306adff97f Mon Sep 17 00:00:00 2001 From: Robin Mills Date: Mon, 20 Apr 2020 12:57:31 +0100 Subject: [PATCH] Fix #1164 (unit test failures on various platforms) --- unitTests/test_futils.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/unitTests/test_futils.cpp b/unitTests/test_futils.cpp index 950b2d73..9f81c407 100644 --- a/unitTests/test_futils.cpp +++ b/unitTests/test_futils.cpp @@ -17,19 +17,25 @@ TEST(strError, returnSuccessAfterClosingFile) // by a successful system call // -> reset errno so that a real failure is only detected here errno = 0; + std::string tmpFile("tmp.dat"); std::ofstream auxFile(tmpFile.c_str()); auxFile.close(); -#ifdef _WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW__) || defined(__MSYS__) const char * expectedString = "No error (errno = 0)"; -#elif __APPLE__ +#elif defined(__APPLE__) + const char * expectedString = "Undefined error: 0 (errno = 0)"; +#elif defined(__sun__) + const char * expectedString = "Error 0 (errno = 0)"; +#elif defined(__FreeBSD__) + const char * expectedString = "No error: 0 (errno = 0)"; +#elif defined(__NetBSD__) const char * expectedString = "Undefined error: 0 (errno = 0)"; #else const char * expectedString = "Success (errno = 0)"; #endif - - ASSERT_STREQ(expectedString, strError().c_str()); std::remove(tmpFile.c_str()); + ASSERT_STREQ(expectedString, strError().c_str()); } TEST(strError, returnNoSuchFileOrDirectoryWhenTryingToOpenNonExistingFile) @@ -41,9 +47,17 @@ TEST(strError, returnNoSuchFileOrDirectoryWhenTryingToOpenNonExistingFile) TEST(strError, doNotRecognizeUnknownError) { errno = 9999; -#ifdef _WIN32 +#if defined(__MINGW__) || defined(__MSYS__) || defined(__CYGWIN__) + const char * expectedString = "Unknown error 9999 (errno = 9999)"; +#elif defined(_WIN32) const char * expectedString = "Unknown error (errno = 9999)"; -#elif __APPLE__ +#elif defined(__APPLE__) + const char * expectedString = "Unknown error: 9999 (errno = 9999)"; +#elif defined(__sun__) + const char * expectedString = "Unknown error (errno = 9999)"; +#elif defined(__FreeBSD__) + const char * expectedString = "Unknown error: 9999 (errno = 9999)"; +#elif defined(__NetBSD__) const char * expectedString = "Unknown error: 9999 (errno = 9999)"; #else const char * expectedString = "Unknown error 9999 (errno = 9999)";