Fix #1164 (unit test failures on various platforms)

This commit is contained in:
Robin Mills 2020-04-20 12:57:31 +01:00
parent 6a8bbcd21e
commit 2034c41957

View File

@ -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)";