From f1269cc220734a5be8d68b370bf27efe6962bdb2 Mon Sep 17 00:00:00 2001 From: Troels Gram <28827711+to01z@users.noreply.github.com> Date: Sat, 23 Mar 2024 22:53:35 -0700 Subject: [PATCH 1/2] Add support for compiling GoogleTest for Xbox Support for Xbox platforms, requires the code to support compilation with the WINAPI_FAMILY_GAMES subset of the Win32 API. - Add support for WINAPI_FAMILY_GAMES to enable GTEST_OS_WINDOWS_GAMES platform. - Disable stream redirection (GTEST_HAS_STREAM_REDIRECTION = 0) and colored TTY printing for GTEST_OS_WINDOWS_GAMES platform. Both features currently require Win32 functions that don't exist in the WINAPI_FAMILY_GAMES subset. Misc fixes: - gtest-port.cc: Move GTEST_DISABLE_MSC_DEPRECATED_PUSH_ into GTEST_HAS_STREAM_REDIRECTION conditional section where the corresponding GTEST_DISABLE_MSC_DEPRECATED_POP_ is located. - googletest-port-test.cc: Switch stream redirection tests to be conditional on GTEST_HAS_STREAM_REDIRECTION instead of !defined(GTEST_OS_WINDOWS_MOBILE). --- googletest/include/gtest/internal/gtest-port-arch.h | 2 ++ googletest/include/gtest/internal/gtest-port.h | 10 ++++++---- googletest/src/gtest-port.cc | 4 ++-- googletest/src/gtest.cc | 12 +++++++----- googletest/test/googletest-port-test.cc | 4 ++-- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port-arch.h b/googletest/include/gtest/internal/gtest-port-arch.h index 3162f2b1cb..7ec968f312 100644 --- a/googletest/include/gtest/internal/gtest-port-arch.h +++ b/googletest/include/gtest/internal/gtest-port-arch.h @@ -56,6 +56,8 @@ #elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE) #define GTEST_OS_WINDOWS_PHONE 1 #define GTEST_OS_WINDOWS_TV_TITLE 1 +#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_GAMES) +#define GTEST_OS_WINDOWS_GAMES 1 #else // WINAPI_FAMILY defined but no known partition matched. // Default to desktop. diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index fa457b7880..35bcf9bfec 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -658,9 +658,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; // By default, we assume that stream redirection is supported on all // platforms except known mobile / embedded ones. Also, if the port doesn't have // a file system, stream redirection is not supported. -#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ - defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \ - defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) || \ +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ + defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_WINDOWS_GAMES) || \ + defined(GTEST_OS_ESP8266) || \ + defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) || \ !GTEST_HAS_FILE_SYSTEM #define GTEST_HAS_STREAM_REDIRECTION 0 #else @@ -2108,7 +2109,8 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_() // defined there. #if GTEST_HAS_FILE_SYSTEM #if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \ - !defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_ESP8266) && \ + !defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_WINDOWS_GAMES) && \ + !defined(GTEST_OS_ESP8266) && \ !defined(GTEST_OS_XTENSA) && !defined(GTEST_OS_QURT) inline int ChDir(const char* dir) { return chdir(dir); } #endif diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 3bb7dd4508..d4238146e5 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -1033,12 +1033,12 @@ GTestLog::~GTestLog() { } } +#if GTEST_HAS_STREAM_REDIRECTION + // Disable Microsoft deprecation warnings for POSIX functions called from // this class (creat, dup, dup2, and close) GTEST_DISABLE_MSC_DEPRECATED_PUSH_() -#if GTEST_HAS_STREAM_REDIRECTION - namespace { #if defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_IOS) diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 36f4a2da1b..898904f5f1 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -3184,8 +3184,9 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) { } // class PrettyUnitTestResultPrinter -#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \ - !defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \ +#if defined(GTEST_OS_WINDOWS) && \ + !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_GAMES) && \ + !defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \ !defined(GTEST_OS_WINDOWS_MINGW) // Returns the character attribute for the given color. @@ -3313,8 +3314,9 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) { return; } -#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \ - !defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \ +#if defined(GTEST_OS_WINDOWS) && \ + !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_GAMES) && \ + !defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \ !defined(GTEST_OS_WINDOWS_MINGW) const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); @@ -5473,7 +5475,7 @@ int UnitTest::Run() { // about crashes - they are expected. if (impl()->catch_exceptions() || in_death_test_child_process) { #if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \ - !defined(GTEST_OS_WINDOWS_RT) + !defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_WINDOWS_GAMES) // SetErrorMode doesn't exist on CE. SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index 9f05a01993..69d637bdec 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -918,7 +918,7 @@ TEST(RETest, PartialMatchWorks) { #endif // GTEST_USES_POSIX_RE -#ifndef GTEST_OS_WINDOWS_MOBILE +#if GTEST_HAS_STREAM_REDIRECTION TEST(CaptureTest, CapturesStdout) { CaptureStdout(); @@ -960,7 +960,7 @@ TEST(CaptureDeathTest, CannotReenterStdoutCapture) { // themselves. } -#endif // !GTEST_OS_WINDOWS_MOBILE +#endif // GTEST_HAS_STREAM_REDIRECTION TEST(ThreadLocalTest, DefaultConstructorInitializesToDefaultValues) { ThreadLocal t1; From a7678dd0db369dcb0110d83cfa5c9f9ba02f2423 Mon Sep 17 00:00:00 2001 From: Troels Gram <28827711+to01z@users.noreply.github.com> Date: Thu, 28 Mar 2024 22:05:08 -0700 Subject: [PATCH 2/2] Revert changes to googletest-port-test.cc GoogleTest's tests do not currently compile when WINAPI_FAMILY is set to anything else than WINAPI_FAMILY_DESKTOP_APP on Windows (if WINAPI_FAMILY is not set explicitly, it will default to WINAPI_FAMILY_DESKTOP_APP). --- googletest/test/googletest-port-test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index 69d637bdec..9f05a01993 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -918,7 +918,7 @@ TEST(RETest, PartialMatchWorks) { #endif // GTEST_USES_POSIX_RE -#if GTEST_HAS_STREAM_REDIRECTION +#ifndef GTEST_OS_WINDOWS_MOBILE TEST(CaptureTest, CapturesStdout) { CaptureStdout(); @@ -960,7 +960,7 @@ TEST(CaptureDeathTest, CannotReenterStdoutCapture) { // themselves. } -#endif // GTEST_HAS_STREAM_REDIRECTION +#endif // !GTEST_OS_WINDOWS_MOBILE TEST(ThreadLocalTest, DefaultConstructorInitializesToDefaultValues) { ThreadLocal t1;