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

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

PiperOrigin-RevId: 513943378
Change-Id: I47cf5fabbb77be061c4483a0adc54511af6b191c
This commit is contained in:
Tom Hughes 2023-03-03 15:54:32 -08:00 committed by Copybara-Service
parent cead3d57c9
commit 23142843f7
27 changed files with 305 additions and 263 deletions

View File

@ -1273,7 +1273,7 @@ class AssignAction {
const T2 value_; const T2 value_;
}; };
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
// Implements the SetErrnoAndReturn action to simulate return from // Implements the SetErrnoAndReturn action to simulate return from
// various system calls and libc functions. // various system calls and libc functions.
@ -1926,7 +1926,7 @@ PolymorphicAction<internal::AssignAction<T1, T2>> Assign(T1* ptr, T2 val) {
return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val)); return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
} }
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
// Creates an action that sets errno and returns the appropriate error. // Creates an action that sets errno and returns the appropriate error.
template <typename T> template <typename T>

View File

@ -98,7 +98,7 @@ constexpr bool HasStrictnessModifier() {
// deregistration. This guarantees that MockClass's constructor and destructor // deregistration. This guarantees that MockClass's constructor and destructor
// run with the same level of strictness as its instance methods. // run with the same level of strictness as its instance methods.
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW && \ #if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW) && \
(defined(_MSC_VER) || defined(__clang__)) (defined(_MSC_VER) || defined(__clang__))
// We need to mark these classes with this declspec to ensure that // We need to mark these classes with this declspec to ensure that
// the empty base class optimization is performed. // the empty base class optimization is performed.

View File

@ -48,10 +48,10 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC #if defined(GTEST_OS_CYGWIN) || defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC)
#include <unistd.h> // NOLINT #include <unistd.h> // NOLINT
#endif #endif
#if GTEST_OS_QURT #ifdef GTEST_OS_QURT
#include <qurt_event.h> #include <qurt_event.h>
#endif #endif
@ -526,7 +526,7 @@ class MockObjectRegistry {
// RUN_ALL_TESTS() has already returned when this destructor is // RUN_ALL_TESTS() has already returned when this destructor is
// called. Therefore we cannot use the normal Google Test // called. Therefore we cannot use the normal Google Test
// failure reporting mechanism. // failure reporting mechanism.
#if GTEST_OS_QURT #ifdef GTEST_OS_QURT
qurt_exception_raise_fatal(); qurt_exception_raise_fatal();
#else #else
_exit(1); // We cannot call exit() as it is not reentrant and _exit(1); // We cannot call exit() as it is not reentrant and

View File

@ -32,8 +32,8 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#if GTEST_OS_ESP8266 || GTEST_OS_ESP32 #if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32)
#if GTEST_OS_ESP8266 #ifdef GTEST_OS_ESP8266
extern "C" { extern "C" {
#endif #endif
void setup() { void setup() {
@ -43,7 +43,7 @@ void setup() {
testing::InitGoogleMock(); testing::InitGoogleMock();
} }
void loop() { RUN_ALL_TESTS(); } void loop() { RUN_ALL_TESTS(); }
#if GTEST_OS_ESP8266 #ifdef GTEST_OS_ESP8266
} }
#endif #endif
@ -55,7 +55,7 @@ void loop() { RUN_ALL_TESTS(); }
// Windows. See the following link to track the current status of this bug: // Windows. See the following link to track the current status of this bug:
// https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library // https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library
// // NOLINT // // NOLINT
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
#include <tchar.h> // NOLINT #include <tchar.h> // NOLINT
GTEST_API_ int _tmain(int argc, TCHAR** argv) { GTEST_API_ int _tmain(int argc, TCHAR** argv) {

View File

@ -1592,7 +1592,7 @@ TEST(WithArgsTest, RefQualifiedInnerAction) {
EXPECT_EQ(19, mock.AsStdFunction()(0, 17)); EXPECT_EQ(19, mock.AsStdFunction()(0, 17));
} }
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
class SetErrnoAndReturnTest : public testing::Test { class SetErrnoAndReturnTest : public testing::Test {
protected: protected:

View File

@ -35,7 +35,7 @@
// Silence C4503 (decorated name length exceeded) for MSVC. // Silence C4503 (decorated name length exceeded) for MSVC.
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503)
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// MSDN says the header file to be included for STDMETHOD is BaseTyps.h but // MSDN says the header file to be included for STDMETHOD is BaseTyps.h but
// we are getting compiler errors if we use basetyps.h, hence including // we are getting compiler errors if we use basetyps.h, hence including
// objbase.h for definition of STDMETHOD. // objbase.h for definition of STDMETHOD.
@ -120,7 +120,7 @@ class FooInterface {
virtual int RefQualifiedOverloaded() & = 0; virtual int RefQualifiedOverloaded() & = 0;
virtual int RefQualifiedOverloaded() && = 0; virtual int RefQualifiedOverloaded() && = 0;
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
STDMETHOD_(int, CTNullary)() = 0; STDMETHOD_(int, CTNullary)() = 0;
STDMETHOD_(bool, CTUnary)(int x) = 0; STDMETHOD_(bool, CTUnary)(int x) = 0;
STDMETHOD_(int, CTDecimal) STDMETHOD_(int, CTDecimal)
@ -178,7 +178,7 @@ class MockFoo : public FooInterface {
MOCK_METHOD(int (*)(bool), ReturnsFunctionPointer1, (int), ()); MOCK_METHOD(int (*)(bool), ReturnsFunctionPointer1, (int), ());
MOCK_METHOD(fn_ptr, ReturnsFunctionPointer2, (int), ()); MOCK_METHOD(fn_ptr, ReturnsFunctionPointer2, (int), ());
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE))); MOCK_METHOD(int, CTNullary, (), (Calltype(STDMETHODCALLTYPE)));
MOCK_METHOD(bool, CTUnary, (int), (Calltype(STDMETHODCALLTYPE))); MOCK_METHOD(bool, CTUnary, (int), (Calltype(STDMETHODCALLTYPE)));
MOCK_METHOD(int, CTDecimal, MOCK_METHOD(int, CTDecimal,
@ -248,7 +248,7 @@ class LegacyMockFoo : public FooInterface {
MOCK_METHOD1(ReturnsFunctionPointer1, int (*(int))(bool)); MOCK_METHOD1(ReturnsFunctionPointer1, int (*(int))(bool));
MOCK_METHOD1(ReturnsFunctionPointer2, fn_ptr(int)); MOCK_METHOD1(ReturnsFunctionPointer2, fn_ptr(int));
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int()); MOCK_METHOD0_WITH_CALLTYPE(STDMETHODCALLTYPE, CTNullary, int());
MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int)); // NOLINT MOCK_METHOD1_WITH_CALLTYPE(STDMETHODCALLTYPE, CTUnary, bool(int)); // NOLINT
MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal, MOCK_METHOD10_WITH_CALLTYPE(STDMETHODCALLTYPE, CTDecimal,
@ -404,7 +404,7 @@ TYPED_TEST(FunctionMockerTest, MocksTypeWithTemplatedCopyCtor) {
EXPECT_TRUE(this->foo_->TypeWithTemplatedCopyCtor(TemplatedCopyable<int>())); EXPECT_TRUE(this->foo_->TypeWithTemplatedCopyCtor(TemplatedCopyable<int>()));
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Tests mocking a nullary function with calltype. // Tests mocking a nullary function with calltype.
TYPED_TEST(FunctionMockerTest, MocksNullaryFunctionWithCallType) { TYPED_TEST(FunctionMockerTest, MocksNullaryFunctionWithCallType) {
EXPECT_CALL(this->mock_foo_, CTNullary()) EXPECT_CALL(this->mock_foo_, CTNullary())
@ -620,7 +620,7 @@ TYPED_TEST(TemplateMockTest, MethodWithCommaInReturnTypeWorks) {
EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1)); EXPECT_EQ(a_map, mock.ReturnTypeWithComma(1));
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Tests mocking template interfaces with calltype. // Tests mocking template interfaces with calltype.
template <typename T> template <typename T>

View File

@ -56,7 +56,7 @@
#include "src/gtest-internal-inl.h" #include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_ #undef GTEST_IMPLEMENTATION_
#if GTEST_OS_CYGWIN #ifdef GTEST_OS_CYGWIN
#include <sys/types.h> // For ssize_t. NOLINT #include <sys/types.h> // For ssize_t. NOLINT
#endif #endif
@ -167,7 +167,7 @@ TEST(KindOfTest, Integer) {
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long long)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long long)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN #if defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || defined(GTEST_OS_CYGWIN)
// ssize_t is not defined on Windows and possibly some other OSes. // ssize_t is not defined on Windows and possibly some other OSes.
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(ssize_t)); // NOLINT EXPECT_EQ(kInteger, GMOCK_KIND_OF_(ssize_t)); // NOLINT
#endif #endif

View File

@ -116,7 +116,7 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
#include <errno.h> #include <errno.h>
#endif #endif
@ -181,7 +181,7 @@ using testing::WithArg;
using testing::WithArgs; using testing::WithArgs;
using testing::WithoutArgs; using testing::WithoutArgs;
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
using testing::SetErrnoAndReturn; using testing::SetErrnoAndReturn;
#endif #endif
@ -306,7 +306,7 @@ TEST(LinkTest, TestSetArrayArgument) {
mock.VoidFromString(&ch); mock.VoidFromString(&ch);
} }
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
// Tests the linkage of the SetErrnoAndReturn action. // Tests the linkage of the SetErrnoAndReturn action.
TEST(LinkTest, TestSetErrnoAndReturn) { TEST(LinkTest, TestSetErrnoAndReturn) {

View File

@ -203,7 +203,7 @@ class GTEST_API_ ExitedWithCode {
const int exit_code_; const int exit_code_;
}; };
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA #if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA)
// Tests that an exit code describes an exit due to termination by a // Tests that an exit code describes an exit due to termination by a
// given signal. // given signal.
class GTEST_API_ KilledBySignal { class GTEST_API_ KilledBySignal {

View File

@ -1999,7 +1999,7 @@ GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
double val1, double val2); double val1, double val2);
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Macros that test for HRESULT failure and success, these are only useful // Macros that test for HRESULT failure and success, these are only useful
// on Windows, and rely on Windows SDK macros and APIs to compile. // on Windows, and rely on Windows SDK macros and APIs to compile.

View File

@ -41,7 +41,7 @@
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
@ -457,7 +457,7 @@ class TestFactoryImpl : public TestFactoryBase {
Test* CreateTest() override { return new TestClass; } Test* CreateTest() override { return new TestClass; }
}; };
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Predicate-formatters for implementing the HRESULT checking macros // Predicate-formatters for implementing the HRESULT checking macros
// {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED} // {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}

View File

@ -361,13 +361,13 @@
// Brings in definitions for functions used in the testing::internal::posix // Brings in definitions for functions used in the testing::internal::posix
// namespace (read, write, close, chdir, isatty, stat). We do not currently // namespace (read, write, close, chdir, isatty, stat). We do not currently
// use them on Windows Mobile. // use them on Windows Mobile.
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
#include <direct.h> #include <direct.h>
#include <io.h> #include <io.h>
#endif #endif
// In order to avoid having to include <windows.h>, use forward declaration // In order to avoid having to include <windows.h>, use forward declaration
#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR) #if defined(GTEST_OS_WINDOWS_MINGW) && !defined(__MINGW64_VERSION_MAJOR)
// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two // MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
// separate (equivalent) structs, instead of using typedef // separate (equivalent) structs, instead of using typedef
typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION; typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
@ -377,7 +377,7 @@ typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION. // WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#endif #endif
#elif GTEST_OS_XTENSA #elif defined(GTEST_OS_XTENSA)
#include <unistd.h> #include <unistd.h>
// Xtensa toolchains define strcasecmp in the string.h header instead of // Xtensa toolchains define strcasecmp in the string.h header instead of
// strings.h. string.h is already included. // strings.h. string.h is already included.
@ -389,7 +389,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#include <unistd.h> #include <unistd.h>
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_OS_LINUX_ANDROID #ifdef GTEST_OS_LINUX_ANDROID
// Used to define __ANDROID_API__ matching the target NDK API level. // Used to define __ANDROID_API__ matching the target NDK API level.
#include <android/api-level.h> // NOLINT #include <android/api-level.h> // NOLINT
#endif #endif
@ -397,13 +397,17 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Defines this to true if and only if Google Test can use POSIX regular // Defines this to true if and only if Google Test can use POSIX regular
// expressions. // expressions.
#ifndef GTEST_HAS_POSIX_RE #ifndef GTEST_HAS_POSIX_RE
#if GTEST_OS_LINUX_ANDROID #ifdef GTEST_OS_LINUX_ANDROID
// On Android, <regex.h> is only available starting with Gingerbread. // On Android, <regex.h> is only available starting with Gingerbread.
#define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9) #define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
#else #else
#define GTEST_HAS_POSIX_RE \ #if !(defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_XTENSA) || \
!(GTEST_OS_WINDOWS || GTEST_OS_XTENSA || GTEST_OS_QURT) defined(GTEST_OS_QURT))
#define GTEST_HAS_POSIX_RE 1
#else
#define GTEST_HAS_POSIX_RE 0
#endif #endif
#endif // GTEST_OS_LINUX_ANDROID
#endif #endif
// Select the regular expression implementation. // Select the regular expression implementation.
@ -472,11 +476,14 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Cygwin 1.7 and below doesn't support ::std::wstring. // Cygwin 1.7 and below doesn't support ::std::wstring.
// Solaris' libc++ doesn't support it either. Android has // Solaris' libc++ doesn't support it either. Android has
// no support for it at least as recent as Froyo (2.2). // no support for it at least as recent as Froyo (2.2).
#define GTEST_HAS_STD_WSTRING \ #if (!(defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_CYGWIN) || \
(!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ defined(GTEST_OS_SOLARIS) || defined(GTEST_OS_HAIKU) || \
GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266 || \ defined(GTEST_OS_ESP32) || defined(GTEST_OS_ESP8266) || \
GTEST_OS_XTENSA || GTEST_OS_QURT)) defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT)))
#define GTEST_HAS_STD_WSTRING 1
#else
#define GTEST_HAS_STD_WSTRING 0
#endif
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
#ifndef GTEST_HAS_FILE_SYSTEM #ifndef GTEST_HAS_FILE_SYSTEM
@ -506,7 +513,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// -frtti -fno-exceptions, the build fails at link time with undefined // -frtti -fno-exceptions, the build fails at link time with undefined
// references to __cxa_bad_typeid. Note sure if STL or toolchain bug, // references to __cxa_bad_typeid. Note sure if STL or toolchain bug,
// so disable RTTI when detected. // so disable RTTI when detected.
#if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && !defined(__EXCEPTIONS) #if defined(GTEST_OS_LINUX_ANDROID) && defined(_STLPORT_MAJOR) && \
!defined(__EXCEPTIONS)
#define GTEST_HAS_RTTI 0 #define GTEST_HAS_RTTI 0
#else #else
#define GTEST_HAS_RTTI 1 #define GTEST_HAS_RTTI 1
@ -554,11 +562,17 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// //
// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0 // To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
// to your compiler flags. // to your compiler flags.
#define GTEST_HAS_PTHREAD \ #if (defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || \
(GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX || GTEST_OS_QNX || \ defined(GTEST_OS_HPUX) || defined(GTEST_OS_QNX) || \
GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ defined(GTEST_OS_FREEBSD) || defined(GTEST_OS_NACL) || \
GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_OPENBSD || \ defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \
GTEST_OS_HAIKU || GTEST_OS_GNU_HURD) defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \
defined(GTEST_OS_OPENBSD) || defined(GTEST_OS_HAIKU) || \
defined(GTEST_OS_GNU_HURD))
#define GTEST_HAS_PTHREAD 1
#else
#define GTEST_HAS_PTHREAD 0
#endif
#endif // GTEST_HAS_PTHREAD #endif // GTEST_HAS_PTHREAD
#if GTEST_HAS_PTHREAD #if GTEST_HAS_PTHREAD
@ -577,8 +591,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#ifndef GTEST_HAS_CLONE #ifndef GTEST_HAS_CLONE
// The user didn't tell us, so we need to figure it out. // The user didn't tell us, so we need to figure it out.
#if GTEST_OS_LINUX && !defined(__ia64__) #if defined(GTEST_OS_LINUX) && !defined(__ia64__)
#if GTEST_OS_LINUX_ANDROID #if defined(GTEST_OS_LINUX_ANDROID)
// On Android, clone() became available at different API levels for each 32-bit // On Android, clone() became available at different API levels for each 32-bit
// architecture. // architecture.
#if defined(__LP64__) || (defined(__arm__) && __ANDROID_API__ >= 9) || \ #if defined(__LP64__) || (defined(__arm__) && __ANDROID_API__ >= 9) || \
@ -603,9 +617,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// By default, we assume that stream redirection is supported on all // By default, we assume that stream redirection is supported on all
// platforms except known mobile / embedded ones. Also, if the port doesn't have // platforms except known mobile / embedded ones. Also, if the port doesn't have
// a file system, stream redirection is not supported. // a file system, stream redirection is not supported.
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA || \ defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \
GTEST_OS_QURT || !GTEST_HAS_FILE_SYSTEM defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) || \
!GTEST_HAS_FILE_SYSTEM
#define GTEST_HAS_STREAM_REDIRECTION 0 #define GTEST_HAS_STREAM_REDIRECTION 0
#else #else
#define GTEST_HAS_STREAM_REDIRECTION 1 #define GTEST_HAS_STREAM_REDIRECTION 1
@ -614,13 +629,16 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Determines whether to support death tests. // Determines whether to support death tests.
// pops up a dialog window that cannot be suppressed programmatically. // pops up a dialog window that cannot be suppressed programmatically.
#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ #if (defined(GTEST_OS_LINUX) || defined(GTEST_OS_CYGWIN) || \
(GTEST_OS_MAC && !GTEST_OS_IOS) || \ defined(GTEST_OS_SOLARIS) || \
(GTEST_OS_WINDOWS_DESKTOP && _MSC_VER) || GTEST_OS_WINDOWS_MINGW || \ (defined(GTEST_OS_MAC) && !defined(GTEST_OS_IOS)) || \
GTEST_OS_AIX || GTEST_OS_HPUX || GTEST_OS_OPENBSD || GTEST_OS_QNX || \ (defined(GTEST_OS_WINDOWS_DESKTOP) && _MSC_VER) || \
GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ defined(GTEST_OS_WINDOWS_MINGW) || defined(GTEST_OS_AIX) || \
GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_HAIKU || \ defined(GTEST_OS_HPUX) || defined(GTEST_OS_OPENBSD) || \
GTEST_OS_GNU_HURD) defined(GTEST_OS_QNX) || defined(GTEST_OS_FREEBSD) || \
defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \
defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \
defined(GTEST_OS_HAIKU) || defined(GTEST_OS_GNU_HURD))
// Death tests require a file system to work properly. // Death tests require a file system to work properly.
#if GTEST_HAS_FILE_SYSTEM #if GTEST_HAS_FILE_SYSTEM
#define GTEST_HAS_DEATH_TEST 1 #define GTEST_HAS_DEATH_TEST 1
@ -638,14 +656,21 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#endif #endif
// Determines whether the system compiler uses UTF-16 for encoding wide strings. // Determines whether the system compiler uses UTF-16 for encoding wide strings.
#define GTEST_WIDE_STRING_USES_UTF16_ \ #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_CYGWIN) || \
(GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_AIX || GTEST_OS_OS2) defined(GTEST_OS_AIX) || defined(GTEST_OS_OS2)
#define GTEST_WIDE_STRING_USES_UTF16_ 1
#else
#define GTEST_WIDE_STRING_USES_UTF16_ 0
#endif
// Determines whether test results can be streamed to a socket. // Determines whether test results can be streamed to a socket.
#if GTEST_OS_LINUX || GTEST_OS_GNU_KFREEBSD || GTEST_OS_DRAGONFLY || \ #if defined(GTEST_OS_LINUX) || defined(GTEST_OS_GNU_KFREEBSD) || \
GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_OPENBSD || \ defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \
GTEST_OS_GNU_HURD defined(GTEST_OS_NETBSD) || defined(GTEST_OS_OPENBSD) || \
defined(GTEST_OS_GNU_HURD)
#define GTEST_CAN_STREAM_RESULTS_ 1 #define GTEST_CAN_STREAM_RESULTS_ 1
#else
#define GTEST_CAN_STREAM_RESULTS_ 0
#endif #endif
// Defines some utility macros. // Defines some utility macros.
@ -759,10 +784,14 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#ifndef GTEST_IS_THREADSAFE #ifndef GTEST_IS_THREADSAFE
#define GTEST_IS_THREADSAFE \ #if (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \
(GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \ (defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \
(GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) || \ !defined(GTEST_OS_WINDOWS_RT)) || \
GTEST_HAS_PTHREAD) GTEST_HAS_PTHREAD)
#define GTEST_IS_THREADSAFE 1
#else
#define GTEST_IS_THREADSAFE 0
#endif
#endif // GTEST_IS_THREADSAFE #endif // GTEST_IS_THREADSAFE
@ -1185,7 +1214,7 @@ void ClearInjectableArgvs();
// Defines synchronization primitives. // Defines synchronization primitives.
#if GTEST_IS_THREADSAFE #if GTEST_IS_THREADSAFE
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Provides leak-safe Windows kernel handle ownership. // Provides leak-safe Windows kernel handle ownership.
// Used in death tests and in threading support. // Used in death tests and in threading support.
class GTEST_API_ AutoHandle { class GTEST_API_ AutoHandle {
@ -1264,7 +1293,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
// On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD // On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD
// defined, but we don't want to use MinGW's pthreads implementation, which // defined, but we don't want to use MinGW's pthreads implementation, which
// has conformance problems with some versions of the POSIX standard. // has conformance problems with some versions of the POSIX standard.
#if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW #if GTEST_HAS_PTHREAD && !defined(GTEST_OS_WINDOWS_MINGW)
// As a C-function, ThreadFuncWithCLinkage cannot be templated itself. // As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
// Consequently, it cannot select a correct instantiation of ThreadWithParam // Consequently, it cannot select a correct instantiation of ThreadWithParam
@ -1350,7 +1379,8 @@ class ThreadWithParam : public ThreadWithParamBase {
// Mutex and ThreadLocal have already been imported into the namespace. // Mutex and ThreadLocal have already been imported into the namespace.
// Nothing to do here. // Nothing to do here.
#elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT #elif defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \
!defined(GTEST_OS_WINDOWS_RT)
// Mutex implements mutex on Windows platforms. It is used in conjunction // Mutex implements mutex on Windows platforms. It is used in conjunction
// with class MutexLock: // with class MutexLock:
@ -1903,7 +1933,7 @@ class GTEST_API_ ThreadLocal {
// we cannot detect it. // we cannot detect it.
GTEST_API_ size_t GetThreadCount(); GTEST_API_ size_t GetThreadCount();
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#define GTEST_PATH_SEP_ "\\" #define GTEST_PATH_SEP_ "\\"
#define GTEST_HAS_ALT_PATH_SEP_ 1 #define GTEST_HAS_ALT_PATH_SEP_ 1
#else #else
@ -1980,11 +2010,11 @@ namespace posix {
// File system porting. // File system porting.
#if GTEST_HAS_FILE_SYSTEM #if GTEST_HAS_FILE_SYSTEM
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
typedef struct _stat StatStruct; typedef struct _stat StatStruct;
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); } inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
// time and thus not defined there. // time and thus not defined there.
@ -1995,7 +2025,7 @@ inline int RmDir(const char* dir) { return _rmdir(dir); }
inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; } inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; }
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
#elif GTEST_OS_ESP8266 #elif defined(GTEST_OS_ESP8266)
typedef struct stat StatStruct; typedef struct stat StatStruct;
inline int FileNo(FILE* file) { return fileno(file); } inline int FileNo(FILE* file) { return fileno(file); }
@ -2012,7 +2042,7 @@ typedef struct stat StatStruct;
inline int FileNo(FILE* file) { return fileno(file); } inline int FileNo(FILE* file) { return fileno(file); }
inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
#if GTEST_OS_QURT #ifdef GTEST_OS_QURT
// QuRT doesn't support any directory functions, including rmdir // QuRT doesn't support any directory functions, including rmdir
inline int RmDir(const char*) { return 0; } inline int RmDir(const char*) { return 0; }
#else #else
@ -2025,7 +2055,7 @@ inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
// Other functions with a different name on Windows. // Other functions with a different name on Windows.
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#ifdef __BORLANDC__ #ifdef __BORLANDC__
inline int DoIsATTY(int fd) { return isatty(fd); } inline int DoIsATTY(int fd) { return isatty(fd); }
@ -2033,8 +2063,9 @@ inline int StrCaseCmp(const char* s1, const char* s2) {
return stricmp(s1, s2); return stricmp(s1, s2);
} }
#else // !__BORLANDC__ #else // !__BORLANDC__
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \ #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_ZOS) || \
GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || defined(ESP_PLATFORM) defined(GTEST_OS_IOS) || defined(GTEST_OS_WINDOWS_PHONE) || \
defined(GTEST_OS_WINDOWS_RT) || defined(ESP_PLATFORM)
inline int DoIsATTY(int /* fd */) { return 0; } inline int DoIsATTY(int /* fd */) { return 0; }
#else #else
inline int DoIsATTY(int fd) { return _isatty(fd); } inline int DoIsATTY(int fd) { return _isatty(fd); }
@ -2072,13 +2103,13 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
// StrError() aren't needed on Windows CE at this time and thus not // StrError() aren't needed on Windows CE at this time and thus not
// defined there. // defined there.
#if GTEST_HAS_FILE_SYSTEM #if GTEST_HAS_FILE_SYSTEM
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ #if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \
!GTEST_OS_WINDOWS_RT && !GTEST_OS_ESP8266 && !GTEST_OS_XTENSA && \ !defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_ESP8266) && \
!GTEST_OS_QURT !defined(GTEST_OS_XTENSA) && !defined(GTEST_OS_QURT)
inline int ChDir(const char* dir) { return chdir(dir); } inline int ChDir(const char* dir) { return chdir(dir); }
#endif #endif
inline FILE* FOpen(const char* path, const char* mode) { inline FILE* FOpen(const char* path, const char* mode) {
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW #if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW)
struct wchar_codecvt : public std::codecvt<wchar_t, char, std::mbstate_t> {}; struct wchar_codecvt : public std::codecvt<wchar_t, char, std::mbstate_t> {};
std::wstring_convert<wchar_codecvt> converter; std::wstring_convert<wchar_codecvt> converter;
std::wstring wide_path = converter.from_bytes(path); std::wstring wide_path = converter.from_bytes(path);
@ -2088,14 +2119,14 @@ inline FILE* FOpen(const char* path, const char* mode) {
return fopen(path, mode); return fopen(path, mode);
#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
} }
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT)
inline FILE* FReopen(const char* path, const char* mode, FILE* stream) { inline FILE* FReopen(const char* path, const char* mode, FILE* stream) {
return freopen(path, mode, stream); return freopen(path, mode, stream);
} }
inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT
inline int FClose(FILE* fp) { return fclose(fp); } inline int FClose(FILE* fp) { return fclose(fp); }
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT)
inline int Read(int fd, void* buf, unsigned int count) { inline int Read(int fd, void* buf, unsigned int count) {
return static_cast<int>(read(fd, buf, count)); return static_cast<int>(read(fd, buf, count));
} }
@ -2106,14 +2137,14 @@ inline int Close(int fd) { return close(fd); }
#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT
#endif // GTEST_HAS_FILE_SYSTEM #endif // GTEST_HAS_FILE_SYSTEM
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT)
inline const char* StrError(int errnum) { return strerror(errnum); } inline const char* StrError(int errnum) { return strerror(errnum); }
#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT
inline const char* GetEnv(const char* name) { inline const char* GetEnv(const char* name) {
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA || \ defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \
GTEST_OS_QURT defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT)
// We are on an embedded platform, which has no environment variables. // We are on an embedded platform, which has no environment variables.
static_cast<void>(name); // To prevent 'unused argument' warning. static_cast<void>(name); // To prevent 'unused argument' warning.
return nullptr; return nullptr;
@ -2129,7 +2160,7 @@ inline const char* GetEnv(const char* name) {
GTEST_DISABLE_MSC_DEPRECATED_POP_() GTEST_DISABLE_MSC_DEPRECATED_POP_()
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
// Windows CE has no C library. The abort() function is used in // Windows CE has no C library. The abort() function is used in
// several places in Google Test. This implementation provides a reasonable // several places in Google Test. This implementation provides a reasonable
// imitation of standard behaviour. // imitation of standard behaviour.
@ -2145,7 +2176,7 @@ GTEST_DISABLE_MSC_DEPRECATED_POP_()
// MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate // MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate
// function in order to achieve that. We use macro definition here because // function in order to achieve that. We use macro definition here because
// snprintf is a variadic function. // snprintf is a variadic function.
#if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE #if defined(_MSC_VER) && !defined(GTEST_OS_WINDOWS_MOBILE)
// MSVC 2005 and above support variadic macros. // MSVC 2005 and above support variadic macros.
#define GTEST_SNPRINTF_(buffer, size, format, ...) \ #define GTEST_SNPRINTF_(buffer, size, format, ...) \
_snprintf_s(buffer, size, size, format, __VA_ARGS__) _snprintf_s(buffer, size, size, format, __VA_ARGS__)

View File

@ -73,7 +73,7 @@ class GTEST_API_ String {
// memory using malloc(). // memory using malloc().
static const char* CloneCString(const char* c_str); static const char* CloneCString(const char* c_str);
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
// Windows CE does not have the 'ANSI' versions of Win32 APIs. To be // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be
// able to pass strings to Win32 APIs on CE we need to convert them // able to pass strings to Win32 APIs on CE we need to convert them
// to 'Unicode', UTF-16. // to 'Unicode', UTF-16.

View File

@ -42,7 +42,7 @@
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
#if GTEST_OS_MAC #ifdef GTEST_OS_MAC
#include <crt_externs.h> #include <crt_externs.h>
#endif // GTEST_OS_MAC #endif // GTEST_OS_MAC
@ -50,24 +50,24 @@
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
#include <signal.h> #include <signal.h>
#endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
#include <stdarg.h> #include <stdarg.h>
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#include <windows.h> #include <windows.h>
#else #else
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/wait.h> #include <sys/wait.h>
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_OS_QNX #ifdef GTEST_OS_QNX
#include <spawn.h> #include <spawn.h>
#endif // GTEST_OS_QNX #endif // GTEST_OS_QNX
#if GTEST_OS_FUCHSIA #ifdef GTEST_OS_FUCHSIA
#include <lib/fdio/fd.h> #include <lib/fdio/fd.h>
#include <lib/fdio/io.h> #include <lib/fdio/io.h>
#include <lib/fdio/spawn.h> #include <lib/fdio/spawn.h>
@ -139,7 +139,7 @@ namespace internal {
// Valid only for fast death tests. Indicates the code is running in the // Valid only for fast death tests. Indicates the code is running in the
// child process of a fast style death test. // child process of a fast style death test.
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA #if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA)
static bool g_in_fast_death_test_child = false; static bool g_in_fast_death_test_child = false;
#endif #endif
@ -149,7 +149,7 @@ static bool g_in_fast_death_test_child = false;
// tests. IMPORTANT: This is an internal utility. Using it may break the // tests. IMPORTANT: This is an internal utility. Using it may break the
// implementation of death tests. User code MUST NOT use it. // implementation of death tests. User code MUST NOT use it.
bool InDeathTestChild() { bool InDeathTestChild() {
#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA)
// On Windows and Fuchsia, death tests are thread-safe regardless of the value // On Windows and Fuchsia, death tests are thread-safe regardless of the value
// of the death_test_style flag. // of the death_test_style flag.
@ -171,7 +171,7 @@ ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {}
// ExitedWithCode function-call operator. // ExitedWithCode function-call operator.
bool ExitedWithCode::operator()(int exit_status) const { bool ExitedWithCode::operator()(int exit_status) const {
#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA)
return exit_status == exit_code_; return exit_status == exit_code_;
@ -182,7 +182,7 @@ bool ExitedWithCode::operator()(int exit_status) const {
#endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA #endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
} }
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA #if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA)
// KilledBySignal constructor. // KilledBySignal constructor.
KilledBySignal::KilledBySignal(int signum) : signum_(signum) {} KilledBySignal::KilledBySignal(int signum) : signum_(signum) {}
@ -209,7 +209,7 @@ namespace internal {
static std::string ExitSummary(int exit_code) { static std::string ExitSummary(int exit_code) {
Message m; Message m;
#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA)
m << "Exited with exit status " << exit_code; m << "Exited with exit status " << exit_code;
@ -236,7 +236,7 @@ bool ExitedUnsuccessfully(int exit_status) {
return !ExitedWithCode(0)(exit_status); return !ExitedWithCode(0)(exit_status);
} }
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA #if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA)
// Generates a textual failure message when a death test finds more than // Generates a textual failure message when a death test finds more than
// one thread running, or cannot determine the number of threads, prior // one thread running, or cannot determine the number of threads, prior
// to executing the given statement. It is the responsibility of the // to executing the given statement. It is the responsibility of the
@ -265,7 +265,7 @@ static const char kDeathTestReturned = 'R';
static const char kDeathTestThrew = 'T'; static const char kDeathTestThrew = 'T';
static const char kDeathTestInternalError = 'I'; static const char kDeathTestInternalError = 'I';
#if GTEST_OS_FUCHSIA #ifdef GTEST_OS_FUCHSIA
// File descriptor used for the pipe in the child process. // File descriptor used for the pipe in the child process.
static const int kFuchsiaReadPipeFd = 3; static const int kFuchsiaReadPipeFd = 3;
@ -634,7 +634,7 @@ std::unique_ptr<char*[]> CreateArgvFromArgs(std::vector<std::string>& args) {
return result; return result;
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// WindowsDeathTest implements death tests on Windows. Due to the // WindowsDeathTest implements death tests on Windows. Due to the
// specifics of starting new processes on Windows, death tests there are // specifics of starting new processes on Windows, death tests there are
// always threadsafe, and Google Test considers the // always threadsafe, and Google Test considers the
@ -821,7 +821,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
return OVERSEE_TEST; return OVERSEE_TEST;
} }
#elif GTEST_OS_FUCHSIA #elif defined(GTEST_OS_FUCHSIA)
class FuchsiaDeathTest : public DeathTestImpl { class FuchsiaDeathTest : public DeathTestImpl {
public: public:
@ -1164,7 +1164,7 @@ struct ExecDeathTestArgs {
int close_fd; // File descriptor to close; the read end of a pipe int close_fd; // File descriptor to close; the read end of a pipe
}; };
#if GTEST_OS_QNX #ifdef GTEST_OS_QNX
extern "C" char** environ; extern "C" char** environ;
#else // GTEST_OS_QNX #else // GTEST_OS_QNX
// The main function for a threadsafe-style death test child process. // The main function for a threadsafe-style death test child process.
@ -1245,7 +1245,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
ExecDeathTestArgs args = {argv, close_fd}; ExecDeathTestArgs args = {argv, close_fd};
pid_t child_pid = -1; pid_t child_pid = -1;
#if GTEST_OS_QNX #ifdef GTEST_OS_QNX
// Obtains the current directory and sets it to be closed in the child // Obtains the current directory and sets it to be closed in the child
// process. // process.
const int cwd_fd = open(".", O_RDONLY); const int cwd_fd = open(".", O_RDONLY);
@ -1276,7 +1276,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd)); GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd));
#else // GTEST_OS_QNX #else // GTEST_OS_QNX
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
// When a SIGPROF signal is received while fork() or clone() are executing, // When a SIGPROF signal is received while fork() or clone() are executing,
// the process may hang. To avoid this, we ignore SIGPROF here and re-enable // the process may hang. To avoid this, we ignore SIGPROF here and re-enable
// it after the call to fork()/clone() is complete. // it after the call to fork()/clone() is complete.
@ -1327,7 +1327,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
_exit(0); _exit(0);
} }
#endif // GTEST_OS_QNX #endif // GTEST_OS_QNX
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
GTEST_DEATH_TEST_CHECK_SYSCALL_( GTEST_DEATH_TEST_CHECK_SYSCALL_(
sigaction(SIGPROF, &saved_sigprof_action, nullptr)); sigaction(SIGPROF, &saved_sigprof_action, nullptr));
#endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
@ -1419,14 +1419,14 @@ bool DefaultDeathTestFactory::Create(const char* statement,
} }
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
if (GTEST_FLAG_GET(death_test_style) == "threadsafe" || if (GTEST_FLAG_GET(death_test_style) == "threadsafe" ||
GTEST_FLAG_GET(death_test_style) == "fast") { GTEST_FLAG_GET(death_test_style) == "fast") {
*test = new WindowsDeathTest(statement, std::move(matcher), file, line); *test = new WindowsDeathTest(statement, std::move(matcher), file, line);
} }
#elif GTEST_OS_FUCHSIA #elif defined(GTEST_OS_FUCHSIA)
if (GTEST_FLAG_GET(death_test_style) == "threadsafe" || if (GTEST_FLAG_GET(death_test_style) == "threadsafe" ||
GTEST_FLAG_GET(death_test_style) == "fast") { GTEST_FLAG_GET(death_test_style) == "fast") {
@ -1453,7 +1453,7 @@ bool DefaultDeathTestFactory::Create(const char* statement,
return true; return true;
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Recreates the pipe and event handles from the provided parameters, // Recreates the pipe and event handles from the provided parameters,
// signals the event, and returns a file descriptor wrapped around the pipe // signals the event, and returns a file descriptor wrapped around the pipe
// handle. This function is called in the child process only. // handle. This function is called in the child process only.
@ -1530,7 +1530,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
SplitString(GTEST_FLAG_GET(internal_run_death_test), '|', &fields); SplitString(GTEST_FLAG_GET(internal_run_death_test), '|', &fields);
int write_fd = -1; int write_fd = -1;
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
unsigned int parent_process_id = 0; unsigned int parent_process_id = 0;
size_t write_handle_as_size_t = 0; size_t write_handle_as_size_t = 0;
@ -1547,7 +1547,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
write_fd = GetStatusFileDescriptor(parent_process_id, write_handle_as_size_t, write_fd = GetStatusFileDescriptor(parent_process_id, write_handle_as_size_t,
event_handle_as_size_t); event_handle_as_size_t);
#elif GTEST_OS_FUCHSIA #elif defined(GTEST_OS_FUCHSIA)
if (fields.size() != 3 || !ParseNaturalNumber(fields[1], &line) || if (fields.size() != 3 || !ParseNaturalNumber(fields[1], &line) ||
!ParseNaturalNumber(fields[2], &index)) { !ParseNaturalNumber(fields[2], &index)) {

View File

@ -34,9 +34,9 @@
#include "gtest/gtest-message.h" #include "gtest/gtest-message.h"
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.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>
#include <io.h> #include <io.h>
#else #else
@ -47,7 +47,7 @@
#include "gtest/internal/gtest-string.h" #include "gtest/internal/gtest-string.h"
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#define GTEST_PATH_MAX_ _MAX_PATH #define GTEST_PATH_MAX_ _MAX_PATH
#elif defined(PATH_MAX) #elif defined(PATH_MAX)
#define GTEST_PATH_MAX_ PATH_MAX #define GTEST_PATH_MAX_ PATH_MAX
@ -62,7 +62,7 @@
namespace testing { namespace testing {
namespace internal { namespace internal {
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// On Windows, '\\' is the standard path separator, but many tools and the // On Windows, '\\' is the standard path separator, but many tools and the
// Windows API also accept '/' as an alternate path separator. Unless otherwise // Windows API also accept '/' as an alternate path separator. Unless otherwise
// noted, a file path can contain either kind of path separators, or a mixture // noted, a file path can contain either kind of path separators, or a mixture
@ -70,7 +70,7 @@ namespace internal {
const char kPathSeparator = '\\'; const char kPathSeparator = '\\';
const char kAlternatePathSeparator = '/'; const char kAlternatePathSeparator = '/';
const char kAlternatePathSeparatorString[] = "/"; const char kAlternatePathSeparatorString[] = "/";
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have a current directory. You should not use // Windows CE doesn't have a current directory. You should not use
// the current directory in tests on Windows CE, but this at least // the current directory in tests on Windows CE, but this at least
// provides a reasonable fallback. // provides a reasonable fallback.
@ -96,19 +96,20 @@ static bool IsPathSeparator(char c) {
// Returns the current working directory, or "" if unsuccessful. // Returns the current working directory, or "" if unsuccessful.
FilePath FilePath::GetCurrentDir() { FilePath FilePath::GetCurrentDir() {
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 || \ defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \
GTEST_OS_XTENSA || GTEST_OS_QURT defined(GTEST_OS_ESP32) || defined(GTEST_OS_XTENSA) || \
defined(GTEST_OS_QURT)
// These platforms do not have a current directory, so we just return // These platforms do not have a current directory, so we just return
// something reasonable. // something reasonable.
return FilePath(kCurrentDirectoryString); return FilePath(kCurrentDirectoryString);
#elif GTEST_OS_WINDOWS #elif defined(GTEST_OS_WINDOWS)
char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; char cwd[GTEST_PATH_MAX_ + 1] = {'\0'};
return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd); return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd);
#else #else
char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; char cwd[GTEST_PATH_MAX_ + 1] = {'\0'};
char* result = getcwd(cwd, sizeof(cwd)); char* result = getcwd(cwd, sizeof(cwd));
#if GTEST_OS_NACL #ifdef GTEST_OS_NACL
// getcwd will likely fail in NaCl due to the sandbox, so return something // getcwd will likely fail in NaCl due to the sandbox, so return something
// reasonable. The user may have provided a shim implementation for getcwd, // reasonable. The user may have provided a shim implementation for getcwd,
// however, so fallback only when failure is detected. // however, so fallback only when failure is detected.
@ -151,7 +152,7 @@ size_t FilePath::CalculateRootLength() const {
const auto& path = pathname_; const auto& path = pathname_;
auto s = path.begin(); auto s = path.begin();
auto end = path.end(); auto end = path.end();
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
if (end - s >= 2 && s[1] == ':' && (end - s == 2 || IsPathSeparator(s[2])) && if (end - s >= 2 && s[1] == ':' && (end - s == 2 || IsPathSeparator(s[2])) &&
(('A' <= s[0] && s[0] <= 'Z') || ('a' <= s[0] && s[0] <= 'z'))) { (('A' <= s[0] && s[0] <= 'Z') || ('a' <= s[0] && s[0] <= 'z'))) {
// A typical absolute path like "C:\Windows" or "D:" // A typical absolute path like "C:\Windows" or "D:"
@ -244,7 +245,7 @@ FilePath FilePath::ConcatPaths(const FilePath& directory,
// Returns true if pathname describes something findable in the file-system, // Returns true if pathname describes something findable in the file-system,
// either a file, directory, or whatever. // either a file, directory, or whatever.
bool FilePath::FileOrDirectoryExists() const { bool FilePath::FileOrDirectoryExists() const {
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str()); LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
const DWORD attributes = GetFileAttributes(unicode); const DWORD attributes = GetFileAttributes(unicode);
delete[] unicode; delete[] unicode;
@ -259,7 +260,7 @@ bool FilePath::FileOrDirectoryExists() const {
// that exists. // that exists.
bool FilePath::DirectoryExists() const { bool FilePath::DirectoryExists() const {
bool result = false; bool result = false;
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Don't strip off trailing separator if path is a root directory on // Don't strip off trailing separator if path is a root directory on
// Windows (like "C:\\"). // Windows (like "C:\\").
const FilePath& path(IsRootDirectory() ? *this const FilePath& path(IsRootDirectory() ? *this
@ -268,7 +269,7 @@ bool FilePath::DirectoryExists() const {
const FilePath& path(*this); const FilePath& path(*this);
#endif #endif
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
LPCWSTR unicode = String::AnsiToUtf16(path.c_str()); LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
const DWORD attributes = GetFileAttributes(unicode); const DWORD attributes = GetFileAttributes(unicode);
delete[] unicode; delete[] unicode;
@ -344,14 +345,15 @@ bool FilePath::CreateDirectoriesRecursively() const {
// directory for any reason, including if the parent directory does not // directory for any reason, including if the parent directory does not
// exist. Not named "CreateDirectory" because that's a macro on Windows. // exist. Not named "CreateDirectory" because that's a macro on Windows.
bool FilePath::CreateFolder() const { bool FilePath::CreateFolder() const {
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
FilePath removed_sep(this->RemoveTrailingPathSeparator()); FilePath removed_sep(this->RemoveTrailingPathSeparator());
LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str()); LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
int result = CreateDirectory(unicode, nullptr) ? 0 : -1; int result = CreateDirectory(unicode, nullptr) ? 0 : -1;
delete[] unicode; delete[] unicode;
#elif GTEST_OS_WINDOWS #elif defined(GTEST_OS_WINDOWS)
int result = _mkdir(pathname_.c_str()); int result = _mkdir(pathname_.c_str());
#elif GTEST_OS_ESP8266 || GTEST_OS_XTENSA || GTEST_OS_QURT #elif defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \
defined(GTEST_OS_QURT)
// do nothing // do nothing
int result = 0; int result = 0;
#else #else
@ -380,7 +382,7 @@ void FilePath::Normalize() {
auto out = pathname_.begin(); auto out = pathname_.begin();
auto i = pathname_.cbegin(); auto i = pathname_.cbegin();
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// UNC paths are treated specially // UNC paths are treated specially
if (pathname_.end() - i >= 3 && IsPathSeparator(*i) && if (pathname_.end() - i >= 3 && IsPathSeparator(*i) &&
IsPathSeparator(*(i + 1)) && !IsPathSeparator(*(i + 2))) { IsPathSeparator(*(i + 1)) && !IsPathSeparator(*(i + 2))) {

View File

@ -55,7 +55,7 @@
#include <netdb.h> // NOLINT #include <netdb.h> // NOLINT
#endif #endif
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#include <windows.h> // NOLINT #include <windows.h> // NOLINT
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
@ -384,7 +384,7 @@ class GTEST_API_ UnitTestOptions {
static bool FilterMatchesTest(const std::string& test_suite_name, static bool FilterMatchesTest(const std::string& test_suite_name,
const std::string& test_name); const std::string& test_name);
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Function for supporting the gtest_catch_exception flag. // Function for supporting the gtest_catch_exception flag.
// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the

View File

@ -38,7 +38,7 @@
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#include <io.h> #include <io.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <windows.h> #include <windows.h>
@ -51,32 +51,34 @@
#include <unistd.h> #include <unistd.h>
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_OS_MAC #ifdef GTEST_OS_MAC
#include <mach/mach_init.h> #include <mach/mach_init.h>
#include <mach/task.h> #include <mach/task.h>
#include <mach/vm_map.h> #include <mach/vm_map.h>
#endif // GTEST_OS_MAC #endif // GTEST_OS_MAC
#if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \ #if defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \
GTEST_OS_NETBSD || GTEST_OS_OPENBSD defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD) || \
defined(GTEST_OS_OPENBSD)
#include <sys/sysctl.h> #include <sys/sysctl.h>
#if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD #if defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \
defined(GTEST_OS_GNU_KFREEBSD)
#include <sys/user.h> #include <sys/user.h>
#endif #endif
#endif #endif
#if GTEST_OS_QNX #ifdef GTEST_OS_QNX
#include <devctl.h> #include <devctl.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/procfs.h> #include <sys/procfs.h>
#endif // GTEST_OS_QNX #endif // GTEST_OS_QNX
#if GTEST_OS_AIX #ifdef GTEST_OS_AIX
#include <procinfo.h> #include <procinfo.h>
#include <sys/types.h> #include <sys/types.h>
#endif // GTEST_OS_AIX #endif // GTEST_OS_AIX
#if GTEST_OS_FUCHSIA #ifdef GTEST_OS_FUCHSIA
#include <zircon/process.h> #include <zircon/process.h>
#include <zircon/syscalls.h> #include <zircon/syscalls.h>
#endif // GTEST_OS_FUCHSIA #endif // GTEST_OS_FUCHSIA
@ -90,7 +92,7 @@
namespace testing { namespace testing {
namespace internal { namespace internal {
#if GTEST_OS_LINUX || GTEST_OS_GNU_HURD #if defined(GTEST_OS_LINUX) || defined(GTEST_OS_GNU_HURD)
namespace { namespace {
template <typename T> template <typename T>
@ -113,7 +115,7 @@ size_t GetThreadCount() {
return ReadProcFileField<size_t>(filename, 19); return ReadProcFileField<size_t>(filename, 19);
} }
#elif GTEST_OS_MAC #elif defined(GTEST_OS_MAC)
size_t GetThreadCount() { size_t GetThreadCount() {
const task_t task = mach_task_self(); const task_t task = mach_task_self();
@ -131,20 +133,20 @@ size_t GetThreadCount() {
} }
} }
#elif GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \ #elif defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \
GTEST_OS_NETBSD defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD)
#if GTEST_OS_NETBSD #ifdef GTEST_OS_NETBSD
#undef KERN_PROC #undef KERN_PROC
#define KERN_PROC KERN_PROC2 #define KERN_PROC KERN_PROC2
#define kinfo_proc kinfo_proc2 #define kinfo_proc kinfo_proc2
#endif #endif
#if GTEST_OS_DRAGONFLY #ifdef GTEST_OS_DRAGONFLY
#define KP_NLWP(kp) (kp.kp_nthreads) #define KP_NLWP(kp) (kp.kp_nthreads)
#elif GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD #elif defined(GTEST_OS_FREEBSD) || defined(GTEST_OS_GNU_KFREEBSD)
#define KP_NLWP(kp) (kp.ki_numthreads) #define KP_NLWP(kp) (kp.ki_numthreads)
#elif GTEST_OS_NETBSD #elif defined(GTEST_OS_NETBSD)
#define KP_NLWP(kp) (kp.p_nlwps) #define KP_NLWP(kp) (kp.p_nlwps)
#endif #endif
@ -156,7 +158,7 @@ size_t GetThreadCount() {
KERN_PROC, KERN_PROC,
KERN_PROC_PID, KERN_PROC_PID,
getpid(), getpid(),
#if GTEST_OS_NETBSD #ifdef GTEST_OS_NETBSD
sizeof(struct kinfo_proc), sizeof(struct kinfo_proc),
1, 1,
#endif #endif
@ -169,7 +171,7 @@ size_t GetThreadCount() {
} }
return static_cast<size_t>(KP_NLWP(info)); return static_cast<size_t>(KP_NLWP(info));
} }
#elif GTEST_OS_OPENBSD #elif defined(GTEST_OS_OPENBSD)
// Returns the number of threads running in the process, or 0 to indicate that // Returns the number of threads running in the process, or 0 to indicate that
// we cannot detect it. // we cannot detect it.
@ -206,7 +208,7 @@ size_t GetThreadCount() {
return nthreads; return nthreads;
} }
#elif GTEST_OS_QNX #elif defined(GTEST_OS_QNX)
// Returns the number of threads running in the process, or 0 to indicate that // Returns the number of threads running in the process, or 0 to indicate that
// we cannot detect it. // we cannot detect it.
@ -226,7 +228,7 @@ size_t GetThreadCount() {
} }
} }
#elif GTEST_OS_AIX #elif defined(GTEST_OS_AIX)
size_t GetThreadCount() { size_t GetThreadCount() {
struct procentry64 entry; struct procentry64 entry;
@ -239,7 +241,7 @@ size_t GetThreadCount() {
} }
} }
#elif GTEST_OS_FUCHSIA #elif defined(GTEST_OS_FUCHSIA)
size_t GetThreadCount() { size_t GetThreadCount() {
int dummy_buffer; int dummy_buffer;
@ -264,7 +266,7 @@ size_t GetThreadCount() {
#endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS #if defined(GTEST_IS_THREADSAFE) && defined(GTEST_OS_WINDOWS)
AutoHandle::AutoHandle() : handle_(INVALID_HANDLE_VALUE) {} AutoHandle::AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
@ -1027,7 +1029,7 @@ class CapturedStream {
public: public:
// The ctor redirects the stream to a temporary file. // The ctor redirects the stream to a temporary file.
explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
char temp_dir_path[MAX_PATH + 1] = {'\0'}; // NOLINT char temp_dir_path[MAX_PATH + 1] = {'\0'}; // NOLINT
char temp_file_path[MAX_PATH + 1] = {'\0'}; // NOLINT char temp_file_path[MAX_PATH + 1] = {'\0'}; // NOLINT
@ -1046,7 +1048,7 @@ class CapturedStream {
// directory, so we create the temporary file in a temporary directory. // directory, so we create the temporary file in a temporary directory.
std::string name_template; std::string name_template;
#if GTEST_OS_LINUX_ANDROID #ifdef GTEST_OS_LINUX_ANDROID
// Note: Android applications are expected to call the framework's // Note: Android applications are expected to call the framework's
// Context.getExternalStorageDirectory() method through JNI to get // Context.getExternalStorageDirectory() method through JNI to get
// the location of the world-writable SD Card directory. However, // the location of the world-writable SD Card directory. However,
@ -1059,7 +1061,7 @@ class CapturedStream {
// '/sdcard' and other variants cannot be relied on, as they are not // '/sdcard' and other variants cannot be relied on, as they are not
// guaranteed to be mounted, or may have a delay in mounting. // guaranteed to be mounted, or may have a delay in mounting.
name_template = "/data/local/tmp/"; name_template = "/data/local/tmp/";
#elif GTEST_OS_IOS #elif defined(GTEST_OS_IOS)
char user_temp_dir[PATH_MAX + 1]; char user_temp_dir[PATH_MAX + 1];
// Documented alternative to NSTemporaryDirectory() (for obtaining creating // Documented alternative to NSTemporaryDirectory() (for obtaining creating
@ -1246,7 +1248,7 @@ void ClearInjectableArgvs() {
} }
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
namespace posix { namespace posix {
void Abort() { void Abort() {
DebugBreak(); DebugBreak();

View File

@ -61,7 +61,7 @@
#include "gtest/internal/custom/gtest.h" #include "gtest/internal/custom/gtest.h"
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
#include <fcntl.h> // NOLINT #include <fcntl.h> // NOLINT
#include <limits.h> // NOLINT #include <limits.h> // NOLINT
@ -74,18 +74,18 @@
#include <string> #include <string>
#elif GTEST_OS_ZOS #elif defined(GTEST_OS_ZOS)
#include <sys/time.h> // NOLINT #include <sys/time.h> // NOLINT
// On z/OS we additionally need strings.h for strcasecmp. // On z/OS we additionally need strings.h for strcasecmp.
#include <strings.h> // NOLINT #include <strings.h> // NOLINT
#elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE. #elif defined(GTEST_OS_WINDOWS_MOBILE) // We are on Windows CE.
#include <windows.h> // NOLINT #include <windows.h> // NOLINT
#undef min #undef min
#elif GTEST_OS_WINDOWS // We are on Windows proper. #elif defined(GTEST_OS_WINDOWS) // We are on Windows proper.
#include <windows.h> // NOLINT #include <windows.h> // NOLINT
#undef min #undef min
@ -99,7 +99,7 @@
#include <sys/timeb.h> // NOLINT #include <sys/timeb.h> // NOLINT
#include <sys/types.h> // NOLINT #include <sys/types.h> // NOLINT
#if GTEST_OS_WINDOWS_MINGW #ifdef GTEST_OS_WINDOWS_MINGW
#include <sys/time.h> // NOLINT #include <sys/time.h> // NOLINT
#endif // GTEST_OS_WINDOWS_MINGW #endif // GTEST_OS_WINDOWS_MINGW
@ -125,11 +125,11 @@
#include "src/gtest-internal-inl.h" #include "src/gtest-internal-inl.h"
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_OS_MAC #ifdef GTEST_OS_MAC
#ifndef GTEST_OS_IOS #ifndef GTEST_OS_IOS
#include <crt_externs.h> #include <crt_externs.h>
#endif #endif
@ -630,7 +630,7 @@ static ::std::vector<std::string> g_argvs;
FilePath GetCurrentExecutableName() { FilePath GetCurrentExecutableName() {
FilePath result; FilePath result;
#if GTEST_OS_WINDOWS || GTEST_OS_OS2 #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_OS2)
result.Set(FilePath(GetArgvs()[0]).RemoveExtension("exe")); result.Set(FilePath(GetArgvs()[0]).RemoveExtension("exe"));
#else #else
result.Set(FilePath(GetArgvs()[0])); result.Set(FilePath(GetArgvs()[0]));
@ -1165,7 +1165,7 @@ TimeInMillis GetTimeInMillis() {
// class String. // class String.
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
// Creates a UTF-16 wide string from the given ANSI string, allocating // Creates a UTF-16 wide string from the given ANSI string, allocating
// memory using new. The caller is responsible for deleting the return // memory using new. The caller is responsible for deleting the return
// value using delete[]. Returns the wide string, or NULL if the // value using delete[]. Returns the wide string, or NULL if the
@ -1867,14 +1867,14 @@ AssertionResult IsNotSubstring(const char* needle_expr,
namespace internal { namespace internal {
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
namespace { namespace {
// Helper function for IsHRESULT{SuccessFailure} predicates // Helper function for IsHRESULT{SuccessFailure} predicates
AssertionResult HRESULTFailureHelper(const char* expr, const char* expected, AssertionResult HRESULTFailureHelper(const char* expr, const char* expected,
long hr) { // NOLINT long hr) { // NOLINT
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_TV_TITLE #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_TV_TITLE)
// Windows CE doesn't support FormatMessage. // Windows CE doesn't support FormatMessage.
const char error_text[] = ""; const char error_text[] = "";
@ -2135,9 +2135,9 @@ bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
if (rhs == nullptr) return false; if (rhs == nullptr) return false;
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
return _wcsicmp(lhs, rhs) == 0; return _wcsicmp(lhs, rhs) == 0;
#elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID #elif defined(GTEST_OS_LINUX) && !defined(GTEST_OS_LINUX_ANDROID)
return wcscasecmp(lhs, rhs) == 0; return wcscasecmp(lhs, rhs) == 0;
#else #else
// Android, Mac OS X and Cygwin don't define wcscasecmp. // Android, Mac OS X and Cygwin don't define wcscasecmp.
@ -3144,7 +3144,7 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) {
// following statements add the test part result message to the Output // following statements add the test part result message to the Output
// window such that the user can double-click on it to jump to the // window such that the user can double-click on it to jump to the
// corresponding source code location; otherwise they do nothing. // corresponding source code location; otherwise they do nothing.
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE #if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE)
// We don't call OutputDebugString*() on Windows Mobile, as printing // We don't call OutputDebugString*() on Windows Mobile, as printing
// to stdout is done by OutputDebugString() there already - we don't // to stdout is done by OutputDebugString() there already - we don't
// want the same message printed twice. // want the same message printed twice.
@ -3154,8 +3154,9 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) {
} }
// class PrettyUnitTestResultPrinter // class PrettyUnitTestResultPrinter
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ #if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \
!GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW !defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \
!defined(GTEST_OS_WINDOWS_MINGW)
// Returns the character attribute for the given color. // Returns the character attribute for the given color.
static WORD GetColorAttribute(GTestColor color) { static WORD GetColorAttribute(GTestColor color) {
@ -3227,7 +3228,7 @@ bool ShouldUseColor(bool stdout_is_tty) {
const char* const gtest_color = c.c_str(); const char* const gtest_color = c.c_str();
if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) { if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) {
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW #if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW)
// On Windows the TERM variable is usually not set, but the // On Windows the TERM variable is usually not set, but the
// console there does support colors. // console there does support colors.
return stdout_is_tty; return stdout_is_tty;
@ -3282,8 +3283,9 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) {
return; return;
} }
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ #if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \
!GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW !defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \
!defined(GTEST_OS_WINDOWS_MINGW)
const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
// Gets the current text color. // Gets the current text color.
@ -5036,7 +5038,7 @@ class ScopedPrematureExitFile {
} }
~ScopedPrematureExitFile() { ~ScopedPrematureExitFile() {
#if !GTEST_OS_ESP8266 #ifndef GTEST_OS_ESP8266
if (!premature_exit_filepath_.empty()) { if (!premature_exit_filepath_.empty()) {
int retval = remove(premature_exit_filepath_.c_str()); int retval = remove(premature_exit_filepath_.c_str());
if (retval) { if (retval) {
@ -5332,7 +5334,8 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type,
// with another testing framework) and specify the former on the // with another testing framework) and specify the former on the
// command line for debugging. // command line for debugging.
if (GTEST_FLAG_GET(break_on_failure)) { if (GTEST_FLAG_GET(break_on_failure)) {
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT #if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \
!defined(GTEST_OS_WINDOWS_RT)
// Using DebugBreak on Windows allows gtest to still break into a debugger // Using DebugBreak on Windows allows gtest to still break into a debugger
// when a failure happens and both the --gtest_break_on_failure and // when a failure happens and both the --gtest_break_on_failure and
// the --gtest_catch_exceptions flags are specified. // the --gtest_catch_exceptions flags are specified.
@ -5417,26 +5420,28 @@ int UnitTest::Run() {
// used for the duration of the program. // used for the duration of the program.
impl()->set_catch_exceptions(GTEST_FLAG_GET(catch_exceptions)); impl()->set_catch_exceptions(GTEST_FLAG_GET(catch_exceptions));
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Either the user wants Google Test to catch exceptions thrown by the // Either the user wants Google Test to catch exceptions thrown by the
// tests or this is executing in the context of death test child // tests or this is executing in the context of death test child
// process. In either case the user does not want to see pop-up dialogs // process. In either case the user does not want to see pop-up dialogs
// about crashes - they are expected. // about crashes - they are expected.
if (impl()->catch_exceptions() || in_death_test_child_process) { if (impl()->catch_exceptions() || in_death_test_child_process) {
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT #if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \
!defined(GTEST_OS_WINDOWS_RT)
// SetErrorMode doesn't exist on CE. // SetErrorMode doesn't exist on CE.
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
#endif // !GTEST_OS_WINDOWS_MOBILE #endif // !GTEST_OS_WINDOWS_MOBILE
#if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE #if (defined(_MSC_VER) || defined(GTEST_OS_WINDOWS_MINGW)) && \
!defined(GTEST_OS_WINDOWS_MOBILE)
// Death test children can be terminated with _abort(). On Windows, // Death test children can be terminated with _abort(). On Windows,
// _abort() can show a dialog with a warning message. This forces the // _abort() can show a dialog with a warning message. This forces the
// abort message to go to stderr instead. // abort message to go to stderr instead.
_set_error_mode(_OUT_TO_STDERR); _set_error_mode(_OUT_TO_STDERR);
#endif #endif
#if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE #if defined(_MSC_VER) && !defined(GTEST_OS_WINDOWS_MOBILE)
// In the debug version, Visual Studio pops up a separate dialog // In the debug version, Visual Studio pops up a separate dialog
// offering a choice to debug the aborted program. We need to suppress // offering a choice to debug the aborted program. We need to suppress
// this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
@ -6520,7 +6525,7 @@ static const char kColorEncodedHelpMessage[] =
#endif // GTEST_CAN_STREAM_RESULTS_ #endif // GTEST_CAN_STREAM_RESULTS_
"\n" "\n"
"Assertion Behavior:\n" "Assertion Behavior:\n"
#if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS #if defined(GTEST_HAS_DEATH_TEST) && !defined(GTEST_OS_WINDOWS)
" @G--" GTEST_FLAG_PREFIX_ " @G--" GTEST_FLAG_PREFIX_
"death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n" "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n"
" Set the default death test style.\n" " Set the default death test style.\n"
@ -6687,7 +6692,7 @@ void ParseGoogleTestFlagsOnly(int* argc, char** argv) {
// Fix the value of *_NSGetArgc() on macOS, but if and only if // Fix the value of *_NSGetArgc() on macOS, but if and only if
// *_NSGetArgv() == argv // *_NSGetArgv() == argv
// Only applicable to char** version of argv // Only applicable to char** version of argv
#if GTEST_OS_MAC #ifdef GTEST_OS_MAC
#ifndef GTEST_OS_IOS #ifndef GTEST_OS_IOS
if (*_NSGetArgv() == argv) { if (*_NSGetArgv() == argv) {
*_NSGetArgc() = *argc; *_NSGetArgc() = *argc;
@ -6799,9 +6804,9 @@ static std::string GetDirFromEnv(
std::string TempDir() { std::string TempDir() {
#if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_) #if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_)
return GTEST_CUSTOM_TEMPDIR_FUNCTION_(); return GTEST_CUSTOM_TEMPDIR_FUNCTION_();
#elif GTEST_OS_WINDOWS || GTEST_OS_WINDOWS_MOBILE #elif defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_WINDOWS_MOBILE)
return GetDirFromEnv({"TEST_TMPDIR", "TEMP"}, "\\temp\\", '\\'); return GetDirFromEnv({"TEST_TMPDIR", "TEMP"}, "\\temp\\", '\\');
#elif GTEST_OS_LINUX_ANDROID #elif defined(GTEST_OS_LINUX_ANDROID)
return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/data/local/tmp/", '/'); return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/data/local/tmp/", '/');
#else #else
return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/tmp/", '/'); return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/tmp/", '/');
@ -6821,10 +6826,10 @@ static std::string GetCurrentExecutableDirectory() {
std::string SrcDir() { std::string SrcDir() {
#if defined(GTEST_CUSTOM_SRCDIR_FUNCTION_) #if defined(GTEST_CUSTOM_SRCDIR_FUNCTION_)
return GTEST_CUSTOM_SRCDIR_FUNCTION_(); return GTEST_CUSTOM_SRCDIR_FUNCTION_();
#elif GTEST_OS_WINDOWS || GTEST_OS_WINDOWS_MOBILE #elif defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_WINDOWS_MOBILE)
return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(), return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(),
'\\'); '\\');
#elif GTEST_OS_LINUX_ANDROID #elif defined(GTEST_OS_LINUX_ANDROID)
return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(), return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(),
'/'); '/');
#else #else

View File

@ -31,10 +31,10 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#if GTEST_OS_ESP8266 || GTEST_OS_ESP32 #if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32)
// Arduino-like platforms: program entry points are setup/loop instead of main. // Arduino-like platforms: program entry points are setup/loop instead of main.
#if GTEST_OS_ESP8266 #ifdef GTEST_OS_ESP8266
extern "C" { extern "C" {
#endif #endif
@ -42,11 +42,11 @@ void setup() { testing::InitGoogleTest(); }
void loop() { RUN_ALL_TESTS(); } void loop() { RUN_ALL_TESTS(); }
#if GTEST_OS_ESP8266 #ifdef GTEST_OS_ESP8266
} }
#endif #endif
#elif GTEST_OS_QURT #elif defined(GTEST_OS_QURT)
// QuRT: program entry point is main, but argc/argv are unusable. // QuRT: program entry point is main, but argc/argv are unusable.
GTEST_API_ int main() { GTEST_API_ int main() {

View File

@ -39,7 +39,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#include <stdlib.h> #include <stdlib.h>
#include <windows.h> #include <windows.h>
#endif #endif
@ -49,7 +49,7 @@ namespace {
// A test that's expected to fail. // A test that's expected to fail.
TEST(Foo, Bar) { EXPECT_EQ(2, 3); } TEST(Foo, Bar) { EXPECT_EQ(2, 3); }
#if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE #if GTEST_HAS_SEH && !defined(GTEST_OS_WINDOWS_MOBILE)
// On Windows Mobile global exception handlers are not supported. // On Windows Mobile global exception handlers are not supported.
LONG WINAPI LONG WINAPI
ExitWithExceptionCode(struct _EXCEPTION_POINTERS* exception_pointers) { ExitWithExceptionCode(struct _EXCEPTION_POINTERS* exception_pointers) {
@ -60,12 +60,12 @@ ExitWithExceptionCode(struct _EXCEPTION_POINTERS* exception_pointers) {
} // namespace } // namespace
int main(int argc, char** argv) { int main(int argc, char** argv) {
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Suppresses display of the Windows error dialog upon encountering // Suppresses display of the Windows error dialog upon encountering
// a general protection fault (segment violation). // a general protection fault (segment violation).
SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS); SetErrorMode(SEM_NOGPFAULTERRORBOX | SEM_FAILCRITICALERRORS);
#if GTEST_HAS_SEH && !GTEST_OS_WINDOWS_MOBILE #if GTEST_HAS_SEH && !defined(GTEST_OS_WINDOWS_MOBILE)
// The default unhandled exception filter does not always exit // The default unhandled exception filter does not always exit
// with the exception code as exit code - for example it exits with // with the exception code as exit code - for example it exits with

View File

@ -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;
#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) {
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) {
#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) {
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) {
#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) {
*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() {
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) {
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) {
} }
#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) {
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));
} }

View File

@ -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 {
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) {
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) {
// 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) {
} }
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) {
#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) {
} }
#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) {
#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) {
// "/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) {
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) {
} }
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());

View File

@ -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) {
.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) {
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) {
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) {
.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) {
} }
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) {
} }
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) {
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());

View File

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

View File

@ -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) {
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) {
#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 {
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 {
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 {
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 {
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) {
#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>();
} }

View File

@ -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

View File

@ -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 {
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) {
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) {
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(); }
// 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) {
// 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) {
#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) {
// 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) {
// 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) {
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 {
}; };
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) {
#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) {
"(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) {
} }
#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) {
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");