Commit 23142843 authored by Tom Hughes's avatar Tom Hughes Committed by Copybara-Service
Browse files

Use "#ifdef GTEST_OS_..." instead of "#if GTEST_OS_..."

This is compatible with compiling with "-Wundef" (#3267).

PiperOrigin-RevId: 513943378
Change-Id: I47cf5fabbb77be061c4483a0adc54511af6b191c
parent cead3d57
...@@ -39,7 +39,7 @@ using testing::internal::AlwaysTrue; ...@@ -39,7 +39,7 @@ using testing::internal::AlwaysTrue;
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#include <direct.h> // For chdir(). #include <direct.h> // For chdir().
#include <fcntl.h> // For O_BINARY #include <fcntl.h> // For O_BINARY
#include <io.h> #include <io.h>
...@@ -52,7 +52,7 @@ using testing::internal::AlwaysTrue; ...@@ -52,7 +52,7 @@ using testing::internal::AlwaysTrue;
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
#include <sys/time.h> #include <sys/time.h>
#endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
...@@ -200,7 +200,7 @@ int DieInDebugElse12(int* sideeffect) { ...@@ -200,7 +200,7 @@ int DieInDebugElse12(int* sideeffect) {
return 12; return 12;
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Death in dbg due to Windows CRT assertion failure, not opt. // Death in dbg due to Windows CRT assertion failure, not opt.
int DieInCRTDebugElse12(int* sideeffect) { int DieInCRTDebugElse12(int* sideeffect) {
...@@ -220,7 +220,7 @@ int DieInCRTDebugElse12(int* sideeffect) { ...@@ -220,7 +220,7 @@ int DieInCRTDebugElse12(int* sideeffect) {
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA)
// Tests the ExitedWithCode predicate. // Tests the ExitedWithCode predicate.
TEST(ExitStatusPredicateTest, ExitedWithCode) { TEST(ExitStatusPredicateTest, ExitedWithCode) {
...@@ -374,7 +374,7 @@ TEST_F(TestForDeathTest, FastDeathTestInChangedDir) { ...@@ -374,7 +374,7 @@ TEST_F(TestForDeathTest, FastDeathTestInChangedDir) {
ASSERT_DEATH(_exit(1), ""); ASSERT_DEATH(_exit(1), "");
} }
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
void SigprofAction(int, siginfo_t*, void*) { /* no op */ void SigprofAction(int, siginfo_t*, void*) { /* no op */
} }
...@@ -641,7 +641,7 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) { ...@@ -641,7 +641,7 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) {
#endif #endif
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/crtsetreportmode // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/crtsetreportmode
// In debug mode, the calls to _CrtSetReportMode and _CrtSetReportFile enable // In debug mode, the calls to _CrtSetReportMode and _CrtSetReportFile enable
...@@ -693,7 +693,7 @@ void ExpectDebugDeathHelper(bool* aborted) { ...@@ -693,7 +693,7 @@ void ExpectDebugDeathHelper(bool* aborted) {
*aborted = false; *aborted = false;
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) { TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) {
printf( printf(
"This test should be considered failing if it shows " "This test should be considered failing if it shows "
...@@ -805,14 +805,14 @@ static void TestExitMacros() { ...@@ -805,14 +805,14 @@ static void TestExitMacros() {
EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), ""); EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1), "");
ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42), ""); ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42), "");
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Of all signals effects on the process exit code, only those of SIGABRT // Of all signals effects on the process exit code, only those of SIGABRT
// are documented on Windows. // are documented on Windows.
// See https://msdn.microsoft.com/en-us/query-bi/m/dwwzkt4c. // See https://msdn.microsoft.com/en-us/query-bi/m/dwwzkt4c.
EXPECT_EXIT(raise(SIGABRT), testing::ExitedWithCode(3), "") << "b_ar"; EXPECT_EXIT(raise(SIGABRT), testing::ExitedWithCode(3), "") << "b_ar";
#elif !GTEST_OS_FUCHSIA #elif !defined(GTEST_OS_FUCHSIA)
// Fuchsia has no unix signals. // Fuchsia has no unix signals.
EXPECT_EXIT(raise(SIGKILL), testing::KilledBySignal(SIGKILL), "") << "foo"; EXPECT_EXIT(raise(SIGKILL), testing::KilledBySignal(SIGKILL), "") << "foo";
...@@ -1177,7 +1177,7 @@ TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) { ...@@ -1177,7 +1177,7 @@ TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) {
EXPECT_STREQ("", GetLastErrnoDescription().c_str()); EXPECT_STREQ("", GetLastErrnoDescription().c_str());
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
TEST(AutoHandleTest, AutoHandleWorks) { TEST(AutoHandleTest, AutoHandleWorks) {
HANDLE handle = ::CreateEvent(NULL, FALSE, FALSE, NULL); HANDLE handle = ::CreateEvent(NULL, FALSE, FALSE, NULL);
ASSERT_NE(INVALID_HANDLE_VALUE, handle); ASSERT_NE(INVALID_HANDLE_VALUE, handle);
...@@ -1204,7 +1204,7 @@ TEST(AutoHandleTest, AutoHandleWorks) { ...@@ -1204,7 +1204,7 @@ TEST(AutoHandleTest, AutoHandleWorks) {
} }
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
typedef unsigned __int64 BiggestParsable; typedef unsigned __int64 BiggestParsable;
typedef signed __int64 BiggestSignedParsable; typedef signed __int64 BiggestSignedParsable;
#else #else
...@@ -1301,7 +1301,7 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) { ...@@ -1301,7 +1301,7 @@ TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
EXPECT_EQ(123, char_result); EXPECT_EQ(123, char_result);
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
TEST(EnvironmentTest, HandleFitsIntoSizeT) { TEST(EnvironmentTest, HandleFitsIntoSizeT) {
ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t)); ASSERT_TRUE(sizeof(HANDLE) <= sizeof(size_t));
} }
......
...@@ -41,9 +41,9 @@ ...@@ -41,9 +41,9 @@
#include "gtest/internal/gtest-filepath.h" #include "gtest/internal/gtest-filepath.h"
#include "src/gtest-internal-inl.h" #include "src/gtest-internal-inl.h"
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
#include <windows.h> // NOLINT #include <windows.h> // NOLINT
#elif GTEST_OS_WINDOWS #elif defined(GTEST_OS_WINDOWS)
#include <direct.h> // NOLINT #include <direct.h> // NOLINT
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
...@@ -51,7 +51,7 @@ namespace testing { ...@@ -51,7 +51,7 @@ namespace testing {
namespace internal { namespace internal {
namespace { namespace {
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have the remove C function. // Windows CE doesn't have the remove C function.
int remove(const char* path) { int remove(const char* path) {
...@@ -80,7 +80,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) { ...@@ -80,7 +80,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
const FilePath cwd = FilePath::GetCurrentDir(); const FilePath cwd = FilePath::GetCurrentDir();
posix::ChDir(original_dir.c_str()); posix::ChDir(original_dir.c_str());
#if GTEST_OS_WINDOWS || GTEST_OS_OS2 #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_OS2)
// Skips the ":". // Skips the ":".
const char* const cwd_without_drive = strchr(cwd.c_str(), ':'); const char* const cwd_without_drive = strchr(cwd.c_str(), ':');
...@@ -174,7 +174,7 @@ TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) { ...@@ -174,7 +174,7 @@ TEST(RemoveDirectoryNameTest, ShouldAlsoGiveFileNameForAlternateSeparator) {
// RemoveFileName "" -> "./" // RemoveFileName "" -> "./"
TEST(RemoveFileNameTest, EmptyName) { TEST(RemoveFileNameTest, EmptyName) {
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
// On Windows CE, we use the root as the current directory. // On Windows CE, we use the root as the current directory.
EXPECT_EQ(GTEST_PATH_SEP_, FilePath("").RemoveFileName().string()); EXPECT_EQ(GTEST_PATH_SEP_, FilePath("").RemoveFileName().string());
#else #else
...@@ -357,7 +357,7 @@ TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) { ...@@ -357,7 +357,7 @@ TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) {
} }
TEST(DirectoryTest, RootDirectoryExists) { TEST(DirectoryTest, RootDirectoryExists) {
#if GTEST_OS_WINDOWS // We are on Windows. #ifdef GTEST_OS_WINDOWS // We are on Windows.
char current_drive[_MAX_PATH]; // NOLINT char current_drive[_MAX_PATH]; // NOLINT
current_drive[0] = static_cast<char>(_getdrive() + 'A' - 1); current_drive[0] = static_cast<char>(_getdrive() + 'A' - 1);
current_drive[1] = ':'; current_drive[1] = ':';
...@@ -369,7 +369,7 @@ TEST(DirectoryTest, RootDirectoryExists) { ...@@ -369,7 +369,7 @@ TEST(DirectoryTest, RootDirectoryExists) {
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) { TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
const int saved_drive_ = _getdrive(); const int saved_drive_ = _getdrive();
// Find a drive that doesn't exist. Start with 'Z' to avoid common ones. // Find a drive that doesn't exist. Start with 'Z' to avoid common ones.
...@@ -387,7 +387,7 @@ TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) { ...@@ -387,7 +387,7 @@ TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
} }
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
// Windows CE _does_ consider an empty directory to exist. // Windows CE _does_ consider an empty directory to exist.
TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) { TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
EXPECT_FALSE(FilePath("").DirectoryExists()); EXPECT_FALSE(FilePath("").DirectoryExists());
...@@ -395,7 +395,7 @@ TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) { ...@@ -395,7 +395,7 @@ TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
#endif // !GTEST_OS_WINDOWS_MOBILE #endif // !GTEST_OS_WINDOWS_MOBILE
TEST(DirectoryTest, CurrentDirectoryExists) { TEST(DirectoryTest, CurrentDirectoryExists) {
#if GTEST_OS_WINDOWS // We are on Windows. #ifdef GTEST_OS_WINDOWS // We are on Windows.
#ifndef _WIN32_CE // Windows CE doesn't have a current directory. #ifndef _WIN32_CE // Windows CE doesn't have a current directory.
EXPECT_TRUE(FilePath(".").DirectoryExists()); EXPECT_TRUE(FilePath(".").DirectoryExists());
...@@ -423,7 +423,7 @@ TEST(NormalizeTest, MultipleConsecutiveSeparatorsInMidstring) { ...@@ -423,7 +423,7 @@ TEST(NormalizeTest, MultipleConsecutiveSeparatorsInMidstring) {
// "/bar" == //bar" == "///bar" // "/bar" == //bar" == "///bar"
TEST(NormalizeTest, MultipleConsecutiveSeparatorsAtStringStart) { TEST(NormalizeTest, MultipleConsecutiveSeparatorsAtStringStart) {
EXPECT_EQ(GTEST_PATH_SEP_ "bar", FilePath(GTEST_PATH_SEP_ "bar").string()); EXPECT_EQ(GTEST_PATH_SEP_ "bar", FilePath(GTEST_PATH_SEP_ "bar").string());
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
EXPECT_EQ(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar", EXPECT_EQ(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar",
FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string()); FilePath(GTEST_PATH_SEP_ GTEST_PATH_SEP_ "bar").string());
#else #else
...@@ -620,7 +620,7 @@ TEST(FilePathTest, IsDirectory) { ...@@ -620,7 +620,7 @@ TEST(FilePathTest, IsDirectory) {
TEST(FilePathTest, IsAbsolutePath) { TEST(FilePathTest, IsAbsolutePath) {
EXPECT_FALSE(FilePath("is" GTEST_PATH_SEP_ "relative").IsAbsolutePath()); EXPECT_FALSE(FilePath("is" GTEST_PATH_SEP_ "relative").IsAbsolutePath());
EXPECT_FALSE(FilePath("").IsAbsolutePath()); EXPECT_FALSE(FilePath("").IsAbsolutePath());
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
EXPECT_TRUE( EXPECT_TRUE(
FilePath("c:\\" GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative") FilePath("c:\\" GTEST_PATH_SEP_ "is_not" GTEST_PATH_SEP_ "relative")
.IsAbsolutePath()); .IsAbsolutePath());
...@@ -638,7 +638,7 @@ TEST(FilePathTest, IsAbsolutePath) { ...@@ -638,7 +638,7 @@ TEST(FilePathTest, IsAbsolutePath) {
} }
TEST(FilePathTest, IsRootDirectory) { TEST(FilePathTest, IsRootDirectory) {
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
EXPECT_TRUE(FilePath("a:\\").IsRootDirectory()); EXPECT_TRUE(FilePath("a:\\").IsRootDirectory());
EXPECT_TRUE(FilePath("Z:/").IsRootDirectory()); EXPECT_TRUE(FilePath("Z:/").IsRootDirectory());
EXPECT_TRUE(FilePath("e://").IsRootDirectory()); EXPECT_TRUE(FilePath("e://").IsRootDirectory());
......
...@@ -40,11 +40,11 @@ ...@@ -40,11 +40,11 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
#include <windows.h> #include <windows.h>
#elif GTEST_OS_WINDOWS #elif defined(GTEST_OS_WINDOWS)
#include <direct.h> #include <direct.h>
#elif GTEST_OS_OS2 #elif defined(GTEST_OS_OS2)
// For strcasecmp on OS/2 // For strcasecmp on OS/2
#include <strings.h> #include <strings.h>
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
...@@ -92,7 +92,7 @@ TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) { ...@@ -92,7 +92,7 @@ TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
.string(); .string();
const std::string& output_file = const std::string& output_file =
UnitTestOptions::GetAbsolutePathToOutputFile(); UnitTestOptions::GetAbsolutePathToOutputFile();
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str()); EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
#else #else
EXPECT_EQ(expected_output_file, output_file.c_str()); EXPECT_EQ(expected_output_file, output_file.c_str());
...@@ -101,19 +101,19 @@ TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) { ...@@ -101,19 +101,19 @@ TEST(XmlOutputTest, GetOutputFileFromDirectoryPath) {
TEST(OutputFileHelpersTest, GetCurrentExecutableName) { TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
const std::string exe_str = GetCurrentExecutableName().string(); const std::string exe_str = GetCurrentExecutableName().string();
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
const bool success = const bool success =
_strcmpi("googletest-options-test", exe_str.c_str()) == 0 || _strcmpi("googletest-options-test", exe_str.c_str()) == 0 ||
_strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 || _strcmpi("gtest-options-ex_test", exe_str.c_str()) == 0 ||
_strcmpi("gtest_all_test", exe_str.c_str()) == 0 || _strcmpi("gtest_all_test", exe_str.c_str()) == 0 ||
_strcmpi("gtest_dll_test", exe_str.c_str()) == 0; _strcmpi("gtest_dll_test", exe_str.c_str()) == 0;
#elif GTEST_OS_OS2 #elif defined(GTEST_OS_OS2)
const bool success = const bool success =
strcasecmp("googletest-options-test", exe_str.c_str()) == 0 || strcasecmp("googletest-options-test", exe_str.c_str()) == 0 ||
strcasecmp("gtest-options-ex_test", exe_str.c_str()) == 0 || strcasecmp("gtest-options-ex_test", exe_str.c_str()) == 0 ||
strcasecmp("gtest_all_test", exe_str.c_str()) == 0 || strcasecmp("gtest_all_test", exe_str.c_str()) == 0 ||
strcasecmp("gtest_dll_test", exe_str.c_str()) == 0; strcasecmp("gtest_dll_test", exe_str.c_str()) == 0;
#elif GTEST_OS_FUCHSIA #elif defined(GTEST_OS_FUCHSIA)
const bool success = exe_str == "app"; const bool success = exe_str == "app";
#else #else
const bool success = const bool success =
...@@ -123,7 +123,7 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) { ...@@ -123,7 +123,7 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
if (!success) FAIL() << "GetCurrentExecutableName() returns " << exe_str; if (!success) FAIL() << "GetCurrentExecutableName() returns " << exe_str;
} }
#if !GTEST_OS_FUCHSIA #ifndef GTEST_OS_FUCHSIA
class XmlOutputChangeDirTest : public Test { class XmlOutputChangeDirTest : public Test {
protected: protected:
...@@ -176,7 +176,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) { ...@@ -176,7 +176,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
.string(); .string();
const std::string& output_file = const std::string& output_file =
UnitTestOptions::GetAbsolutePathToOutputFile(); UnitTestOptions::GetAbsolutePathToOutputFile();
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str()); EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
#else #else
EXPECT_EQ(expected_output_file, output_file.c_str()); EXPECT_EQ(expected_output_file, output_file.c_str());
...@@ -184,7 +184,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) { ...@@ -184,7 +184,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithRelativePath) {
} }
TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) { TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
GTEST_FLAG_SET(output, "xml:c:\\tmp\\filename.abc"); GTEST_FLAG_SET(output, "xml:c:\\tmp\\filename.abc");
EXPECT_EQ(FilePath("c:\\tmp\\filename.abc").string(), EXPECT_EQ(FilePath("c:\\tmp\\filename.abc").string(),
UnitTestOptions::GetAbsolutePathToOutputFile()); UnitTestOptions::GetAbsolutePathToOutputFile());
...@@ -196,7 +196,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) { ...@@ -196,7 +196,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsoluteFile) {
} }
TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) { TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) {
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
const std::string path = "c:\\tmp\\"; const std::string path = "c:\\tmp\\";
#else #else
const std::string path = "/tmp/"; const std::string path = "/tmp/";
...@@ -208,7 +208,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) { ...@@ -208,7 +208,7 @@ TEST_F(XmlOutputChangeDirTest, PreserveOriginalWorkingDirWithAbsolutePath) {
const std::string& output_file = const std::string& output_file =
UnitTestOptions::GetAbsolutePathToOutputFile(); UnitTestOptions::GetAbsolutePathToOutputFile();
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str()); EXPECT_STRCASEEQ(expected_output_file.c_str(), output_file.c_str());
#else #else
EXPECT_EQ(expected_output_file, output_file.c_str()); EXPECT_EQ(expected_output_file, output_file.c_str());
......
...@@ -1028,7 +1028,7 @@ int main(int argc, char** argv) { ...@@ -1028,7 +1028,7 @@ int main(int argc, char** argv) {
if (GTEST_FLAG_GET(internal_run_death_test) != "") { if (GTEST_FLAG_GET(internal_run_death_test) != "") {
// Skip the usual output capturing if we're running as the child // Skip the usual output capturing if we're running as the child
// process of an threadsafe-style death test. // process of an threadsafe-style death test.
#if GTEST_OS_WINDOWS #if defined(GTEST_OS_WINDOWS)
posix::FReopen("nul:", "w", stdout); posix::FReopen("nul:", "w", stdout);
#else #else
posix::FReopen("/dev/null", "w", stdout); posix::FReopen("/dev/null", "w", stdout);
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#if GTEST_OS_MAC #ifdef GTEST_OS_MAC
#include <time.h> #include <time.h>
#endif // GTEST_OS_MAC #endif // GTEST_OS_MAC
...@@ -281,9 +281,11 @@ TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFileAndLine) { ...@@ -281,9 +281,11 @@ TEST(FormatCompilerIndependentFileLocationTest, FormatsUknownFileAndLine) {
EXPECT_EQ("unknown file", FormatCompilerIndependentFileLocation(nullptr, -1)); EXPECT_EQ("unknown file", FormatCompilerIndependentFileLocation(nullptr, -1));
} }
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_QNX || GTEST_OS_FUCHSIA || \ #if defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || \
GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \ defined(GTEST_OS_QNX) || defined(GTEST_OS_FUCHSIA) || \
GTEST_OS_NETBSD || GTEST_OS_OPENBSD || GTEST_OS_GNU_HURD defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \
defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD) || \
defined(GTEST_OS_OPENBSD) || defined(GTEST_OS_GNU_HURD)
void* ThreadFunc(void* data) { void* ThreadFunc(void* data) {
internal::Mutex* mutex = static_cast<internal::Mutex*>(data); internal::Mutex* mutex = static_cast<internal::Mutex*>(data);
mutex->Lock(); mutex->Lock();
...@@ -916,7 +918,7 @@ TEST(RETest, PartialMatchWorks) { ...@@ -916,7 +918,7 @@ TEST(RETest, PartialMatchWorks) {
#endif // GTEST_USES_POSIX_RE #endif // GTEST_USES_POSIX_RE
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
TEST(CaptureTest, CapturesStdout) { TEST(CaptureTest, CapturesStdout) {
CaptureStdout(); CaptureStdout();
...@@ -1064,7 +1066,7 @@ class AtomicCounterWithMutex { ...@@ -1064,7 +1066,7 @@ class AtomicCounterWithMutex {
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&memory_barrier_mutex)); GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&memory_barrier_mutex));
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&memory_barrier_mutex)); GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&memory_barrier_mutex));
#elif GTEST_OS_WINDOWS #elif defined(GTEST_OS_WINDOWS)
// On Windows, performing an interlocked access puts up a memory barrier. // On Windows, performing an interlocked access puts up a memory barrier.
volatile LONG dummy = 0; volatile LONG dummy = 0;
::InterlockedIncrement(&dummy); ::InterlockedIncrement(&dummy);
...@@ -1146,14 +1148,14 @@ class DestructorCall { ...@@ -1146,14 +1148,14 @@ class DestructorCall {
public: public:
DestructorCall() { DestructorCall() {
invoked_ = false; invoked_ = false;
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
wait_event_.Reset(::CreateEvent(NULL, TRUE, FALSE, NULL)); wait_event_.Reset(::CreateEvent(NULL, TRUE, FALSE, NULL));
GTEST_CHECK_(wait_event_.Get() != NULL); GTEST_CHECK_(wait_event_.Get() != NULL);
#endif #endif
} }
bool CheckDestroyed() const { bool CheckDestroyed() const {
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
if (::WaitForSingleObject(wait_event_.Get(), 1000) != WAIT_OBJECT_0) if (::WaitForSingleObject(wait_event_.Get(), 1000) != WAIT_OBJECT_0)
return false; return false;
#endif #endif
...@@ -1162,7 +1164,7 @@ class DestructorCall { ...@@ -1162,7 +1164,7 @@ class DestructorCall {
void ReportDestroyed() { void ReportDestroyed() {
invoked_ = true; invoked_ = true;
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
::SetEvent(wait_event_.Get()); ::SetEvent(wait_event_.Get());
#endif #endif
} }
...@@ -1178,7 +1180,7 @@ class DestructorCall { ...@@ -1178,7 +1180,7 @@ class DestructorCall {
private: private:
bool invoked_; bool invoked_;
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
AutoHandle wait_event_; AutoHandle wait_event_;
#endif #endif
static std::vector<DestructorCall*>* const list_; static std::vector<DestructorCall*>* const list_;
...@@ -1278,12 +1280,12 @@ TEST(ThreadLocalTest, ThreadLocalMutationsAffectOnlyCurrentThread) { ...@@ -1278,12 +1280,12 @@ TEST(ThreadLocalTest, ThreadLocalMutationsAffectOnlyCurrentThread) {
#endif // GTEST_IS_THREADSAFE #endif // GTEST_IS_THREADSAFE
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
TEST(WindowsTypesTest, HANDLEIsVoidStar) { TEST(WindowsTypesTest, HANDLEIsVoidStar) {
StaticAssertTypeEq<HANDLE, void*>(); StaticAssertTypeEq<HANDLE, void*>();
} }
#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR) #if defined(GTEST_OS_WINDOWS_MINGW) && !defined(__MINGW64_VERSION_MAJOR)
TEST(WindowsTypesTest, _CRITICAL_SECTIONIs_CRITICAL_SECTION) { TEST(WindowsTypesTest, _CRITICAL_SECTIONIs_CRITICAL_SECTION) {
StaticAssertTypeEq<CRITICAL_SECTION, _CRITICAL_SECTION>(); StaticAssertTypeEq<CRITICAL_SECTION, _CRITICAL_SECTION>();
} }
......
...@@ -432,7 +432,7 @@ TEST(PrintBuiltInTypeTest, Integer) { ...@@ -432,7 +432,7 @@ TEST(PrintBuiltInTypeTest, Integer) {
// Size types. // Size types.
TEST(PrintBuiltInTypeTest, Size_t) { TEST(PrintBuiltInTypeTest, Size_t) {
EXPECT_EQ("1", Print(sizeof('a'))); // size_t. EXPECT_EQ("1", Print(sizeof('a'))); // size_t.
#if !GTEST_OS_WINDOWS #ifndef GTEST_OS_WINDOWS
// Windows has no ssize_t type. // Windows has no ssize_t type.
EXPECT_EQ("-2", Print(static_cast<ssize_t>(-2))); // ssize_t. EXPECT_EQ("-2", Print(static_cast<ssize_t>(-2))); // ssize_t.
#endif // !GTEST_OS_WINDOWS #endif // !GTEST_OS_WINDOWS
......
...@@ -448,7 +448,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { ...@@ -448,7 +448,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
// tzset() distinguishes between the TZ variable being present and empty // tzset() distinguishes between the TZ variable being present and empty
// and not being present, so we have to consider the case of time_zone // and not being present, so we have to consider the case of time_zone
// being NULL. // being NULL.
#if defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW #if defined(_MSC_VER) || defined(GTEST_OS_WINDOWS_MINGW)
// ...Unless it's MSVC, whose standard library's _putenv doesn't // ...Unless it's MSVC, whose standard library's _putenv doesn't
// distinguish between an empty and a missing variable. // distinguish between an empty and a missing variable.
const std::string env_var = const std::string env_var =
...@@ -458,7 +458,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test { ...@@ -458,7 +458,7 @@ class FormatEpochTimeInMillisAsIso8601Test : public Test {
tzset(); tzset();
GTEST_DISABLE_MSC_WARNINGS_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()
#else #else
#if GTEST_OS_LINUX_ANDROID && __ANDROID_API__ < 21 #if defined(GTEST_OS_LINUX_ANDROID) && __ANDROID_API__ < 21
// Work around KitKat bug in tzset by setting "UTC" before setting "UTC+00". // Work around KitKat bug in tzset by setting "UTC" before setting "UTC+00".
// See https://github.com/android/ndk/issues/1604. // See https://github.com/android/ndk/issues/1604.
setenv("TZ", "UTC", 1); setenv("TZ", "UTC", 1);
...@@ -1090,7 +1090,7 @@ TEST(StringTest, CaseInsensitiveWideCStringEquals) { ...@@ -1090,7 +1090,7 @@ TEST(StringTest, CaseInsensitiveWideCStringEquals) {
EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"FOOBAR", L"foobar")); EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"FOOBAR", L"foobar"));
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Tests String::ShowWideCString(). // Tests String::ShowWideCString().
TEST(StringTest, ShowWideCString) { TEST(StringTest, ShowWideCString) {
...@@ -1099,7 +1099,7 @@ TEST(StringTest, ShowWideCString) { ...@@ -1099,7 +1099,7 @@ TEST(StringTest, ShowWideCString) {
EXPECT_STREQ("foo", String::ShowWideCString(L"foo").c_str()); EXPECT_STREQ("foo", String::ShowWideCString(L"foo").c_str());
} }
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
TEST(StringTest, AnsiAndUtf16Null) { TEST(StringTest, AnsiAndUtf16Null) {
EXPECT_EQ(NULL, String::AnsiToUtf16(NULL)); EXPECT_EQ(NULL, String::AnsiToUtf16(NULL));
EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL)); EXPECT_EQ(NULL, String::Utf16ToAnsi(NULL));
...@@ -1676,7 +1676,7 @@ TEST_F(GTestFlagSaverTest, VerifyGTestFlags) { VerifyAndModifyFlags(); } ...@@ -1676,7 +1676,7 @@ TEST_F(GTestFlagSaverTest, VerifyGTestFlags) { VerifyAndModifyFlags(); }
// value. If the value argument is "", unsets the environment // value. If the value argument is "", unsets the environment
// variable. The caller must ensure that both arguments are not NULL. // variable. The caller must ensure that both arguments are not NULL.
static void SetEnv(const char* name, const char* value) { static void SetEnv(const char* name, const char* value) {
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
// Environment variables are not supported on Windows CE. // Environment variables are not supported on Windows CE.
return; return;
#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
...@@ -1699,7 +1699,7 @@ static void SetEnv(const char* name, const char* value) { ...@@ -1699,7 +1699,7 @@ static void SetEnv(const char* name, const char* value) {
// We cast away the 'const' since that would work for both variants. // We cast away the 'const' since that would work for both variants.
putenv(const_cast<char*>(added_env[name]->c_str())); putenv(const_cast<char*>(added_env[name]->c_str()));
delete prev_env; delete prev_env;
#elif GTEST_OS_WINDOWS // If we are on Windows proper. #elif defined(GTEST_OS_WINDOWS) // If we are on Windows proper.
_putenv((Message() << name << "=" << value).GetString().c_str()); _putenv((Message() << name << "=" << value).GetString().c_str());
#else #else
if (*value == '\0') { if (*value == '\0') {
...@@ -1710,7 +1710,7 @@ static void SetEnv(const char* name, const char* value) { ...@@ -1710,7 +1710,7 @@ static void SetEnv(const char* name, const char* value) {
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
} }
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
// Environment variables are not supported on Windows CE. // Environment variables are not supported on Windows CE.
using testing::internal::Int32FromGTestEnv; using testing::internal::Int32FromGTestEnv;
...@@ -1819,7 +1819,7 @@ TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) { ...@@ -1819,7 +1819,7 @@ TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) {
// Tests that Int32FromEnvOrDie() parses the value of the var or // Tests that Int32FromEnvOrDie() parses the value of the var or
// returns the correct default. // returns the correct default.
// Environment variables are not supported on Windows CE. // Environment variables are not supported on Windows CE.
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) { TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) {
EXPECT_EQ(333, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333)); EXPECT_EQ(333, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333));
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "123"); SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "123");
...@@ -1892,7 +1892,7 @@ TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) { ...@@ -1892,7 +1892,7 @@ TEST_F(ShouldShardTest, ReturnsFalseWhenTotalShardIsOne) {
// Tests that sharding is enabled if total_shards > 1 and // Tests that sharding is enabled if total_shards > 1 and
// we are not in a death test subprocess. // we are not in a death test subprocess.
// Environment variables are not supported on Windows CE. // Environment variables are not supported on Windows CE.
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) { TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) {
SetEnv(index_var_, "4"); SetEnv(index_var_, "4");
SetEnv(total_var_, "22"); SetEnv(total_var_, "22");
...@@ -3926,7 +3926,7 @@ TEST(AssertionTest, NamedEnum) { ...@@ -3926,7 +3926,7 @@ TEST(AssertionTest, NamedEnum) {
enum { enum {
kCaseA = -1, kCaseA = -1,
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
// We want to test the case where the size of the anonymous enum is // We want to test the case where the size of the anonymous enum is
// larger than sizeof(int), to make sure our implementation of the // larger than sizeof(int), to make sure our implementation of the
...@@ -3949,7 +3949,7 @@ enum { ...@@ -3949,7 +3949,7 @@ enum {
}; };
TEST(AssertionTest, AnonymousEnum) { TEST(AssertionTest, AnonymousEnum) {
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB)); EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB));
...@@ -3983,7 +3983,7 @@ TEST(AssertionTest, AnonymousEnum) { ...@@ -3983,7 +3983,7 @@ TEST(AssertionTest, AnonymousEnum) {
#endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC) #endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC)
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
static HRESULT UnexpectedHRESULTFailure() { return E_UNEXPECTED; } static HRESULT UnexpectedHRESULTFailure() { return E_UNEXPECTED; }
...@@ -4343,7 +4343,7 @@ TEST(AssertionWithMessageTest, ASSERT_TRUE) { ...@@ -4343,7 +4343,7 @@ TEST(AssertionWithMessageTest, ASSERT_TRUE) {
"(null)(null)"); "(null)(null)");
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Tests using wide strings in assertion messages. // Tests using wide strings in assertion messages.
TEST(AssertionWithMessageTest, WideStringMessage) { TEST(AssertionWithMessageTest, WideStringMessage) {
EXPECT_NONFATAL_FAILURE( EXPECT_NONFATAL_FAILURE(
...@@ -6224,7 +6224,7 @@ TEST_F(ParseFlagsTest, AbseilPositionalFlags) { ...@@ -6224,7 +6224,7 @@ TEST_F(ParseFlagsTest, AbseilPositionalFlags) {
} }
#endif #endif
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Tests parsing wide strings. // Tests parsing wide strings.
TEST_F(ParseFlagsTest, WideStrings) { TEST_F(ParseFlagsTest, WideStrings) {
const wchar_t* argv[] = {L"foo.exe", const wchar_t* argv[] = {L"foo.exe",
...@@ -6614,7 +6614,7 @@ TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) { ...@@ -6614,7 +6614,7 @@ TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) {
TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) { TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
GTEST_FLAG_SET(color, "auto"); GTEST_FLAG_SET(color, "auto");
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW #if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW)
// On Windows, we ignore the TERM variable as it's usually not set. // On Windows, we ignore the TERM variable as it's usually not set.
SetEnv("TERM", "dumb"); SetEnv("TERM", "dumb");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment