diff options
author | Tom Hughes <tomhughes@google.com> | 2023-03-03 23:54:32 (GMT) |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-03-06 15:14:21 (GMT) |
commit | 23142843f7c875907a6ed7985174a6e346e82c3d (patch) | |
tree | 27fada6ccf3be641ec3ec564887750cf6df98d70 /googletest/src | |
parent | cead3d57c93ff8c4e5c1bbae57a5c0b0b0f6e168 (diff) | |
download | googletest-23142843f7c875907a6ed7985174a6e346e82c3d.zip googletest-23142843f7c875907a6ed7985174a6e346e82c3d.tar.gz googletest-23142843f7c875907a6ed7985174a6e346e82c3d.tar.bz2 |
Use "#ifdef GTEST_OS_..." instead of "#if GTEST_OS_..."
This is compatible with compiling with "-Wundef" (#3267).
PiperOrigin-RevId: 513943378
Change-Id: I47cf5fabbb77be061c4483a0adc54511af6b191c
Diffstat (limited to 'googletest/src')
-rw-r--r-- | googletest/src/gtest-death-test.cc | 46 | ||||
-rw-r--r-- | googletest/src/gtest-filepath.cc | 38 | ||||
-rw-r--r-- | googletest/src/gtest-internal-inl.h | 4 | ||||
-rw-r--r-- | googletest/src/gtest-port.cc | 54 | ||||
-rw-r--r-- | googletest/src/gtest.cc | 67 | ||||
-rw-r--r-- | googletest/src/gtest_main.cc | 8 |
6 files changed, 113 insertions, 104 deletions
diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc index 7fcf9bf..f91eba2 100644 --- a/googletest/src/gtest-death-test.cc +++ b/googletest/src/gtest-death-test.cc @@ -42,7 +42,7 @@ #if GTEST_HAS_DEATH_TEST -#if GTEST_OS_MAC +#ifdef GTEST_OS_MAC #include <crt_externs.h> #endif // GTEST_OS_MAC @@ -50,24 +50,24 @@ #include <fcntl.h> #include <limits.h> -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX #include <signal.h> #endif // GTEST_OS_LINUX #include <stdarg.h> -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #include <windows.h> #else #include <sys/mman.h> #include <sys/wait.h> #endif // GTEST_OS_WINDOWS -#if GTEST_OS_QNX +#ifdef GTEST_OS_QNX #include <spawn.h> #endif // GTEST_OS_QNX -#if GTEST_OS_FUCHSIA +#ifdef GTEST_OS_FUCHSIA #include <lib/fdio/fd.h> #include <lib/fdio/io.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 // 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; #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 // implementation of death tests. User code MUST NOT use it. 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 // of the death_test_style flag. @@ -171,7 +171,7 @@ ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {} // ExitedWithCode function-call operator. 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_; @@ -182,7 +182,7 @@ bool ExitedWithCode::operator()(int exit_status) const { #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::KilledBySignal(int signum) : signum_(signum) {} @@ -209,7 +209,7 @@ namespace internal { static std::string ExitSummary(int exit_code) { 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; @@ -236,7 +236,7 @@ bool ExitedUnsuccessfully(int 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 // one thread running, or cannot determine the number of threads, prior // 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 kDeathTestInternalError = 'I'; -#if GTEST_OS_FUCHSIA +#ifdef GTEST_OS_FUCHSIA // File descriptor used for the pipe in the child process. static const int kFuchsiaReadPipeFd = 3; @@ -634,7 +634,7 @@ std::unique_ptr<char*[]> CreateArgvFromArgs(std::vector<std::string>& args) { return result; } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // WindowsDeathTest implements death tests on Windows. Due to the // specifics of starting new processes on Windows, death tests there are // always threadsafe, and Google Test considers the @@ -821,7 +821,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { return OVERSEE_TEST; } -#elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) class FuchsiaDeathTest : public DeathTestImpl { public: @@ -1164,7 +1164,7 @@ struct ExecDeathTestArgs { 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; #else // GTEST_OS_QNX // 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}; 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 // process. 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)); #else // GTEST_OS_QNX -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX // 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 // 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); } #endif // GTEST_OS_QNX -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX GTEST_DEATH_TEST_CHECK_SYSCALL_( sigaction(SIGPROF, &saved_sigprof_action, nullptr)); #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" || GTEST_FLAG_GET(death_test_style) == "fast") { *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" || GTEST_FLAG_GET(death_test_style) == "fast") { @@ -1453,7 +1453,7 @@ bool DefaultDeathTestFactory::Create(const char* statement, return true; } -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Recreates the pipe and event handles from the provided parameters, // signals the event, and returns a file descriptor wrapped around the pipe // 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); int write_fd = -1; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS unsigned int parent_process_id = 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, event_handle_as_size_t); -#elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) if (fields.size() != 3 || !ParseNaturalNumber(fields[1], &line) || !ParseNaturalNumber(fields[2], &index)) { diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index 940585d..48dee13 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -34,9 +34,9 @@ #include "gtest/gtest-message.h" #include "gtest/internal/gtest-port.h" -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE #include <windows.h> -#elif GTEST_OS_WINDOWS +#elif defined(GTEST_OS_WINDOWS) #include <direct.h> #include <io.h> #else @@ -47,7 +47,7 @@ #include "gtest/internal/gtest-string.h" -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #define GTEST_PATH_MAX_ _MAX_PATH #elif defined(PATH_MAX) #define GTEST_PATH_MAX_ PATH_MAX @@ -62,7 +62,7 @@ namespace testing { namespace internal { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // On Windows, '\\' is the standard path separator, but many tools and the // 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 @@ -70,7 +70,7 @@ namespace internal { const char kPathSeparator = '\\'; const char kAlternatePathSeparator = '/'; 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 // the current directory in tests on Windows CE, but this at least // provides a reasonable fallback. @@ -96,19 +96,20 @@ static bool IsPathSeparator(char c) { // Returns the current working directory, or "" if unsuccessful. FilePath FilePath::GetCurrentDir() { -#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ - GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 || \ - GTEST_OS_XTENSA || GTEST_OS_QURT +#if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \ + defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \ + defined(GTEST_OS_ESP32) || defined(GTEST_OS_XTENSA) || \ + defined(GTEST_OS_QURT) // These platforms do not have a current directory, so we just return // something reasonable. return FilePath(kCurrentDirectoryString); -#elif GTEST_OS_WINDOWS +#elif defined(GTEST_OS_WINDOWS) char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd); #else char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; 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 // reasonable. The user may have provided a shim implementation for getcwd, // however, so fallback only when failure is detected. @@ -151,7 +152,7 @@ size_t FilePath::CalculateRootLength() const { const auto& path = pathname_; auto s = path.begin(); auto end = path.end(); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS 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 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, // either a file, directory, or whatever. bool FilePath::FileOrDirectoryExists() const { -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str()); const DWORD attributes = GetFileAttributes(unicode); delete[] unicode; @@ -259,7 +260,7 @@ bool FilePath::FileOrDirectoryExists() const { // that exists. bool FilePath::DirectoryExists() const { bool result = false; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Don't strip off trailing separator if path is a root directory on // Windows (like "C:\\"). const FilePath& path(IsRootDirectory() ? *this @@ -268,7 +269,7 @@ bool FilePath::DirectoryExists() const { const FilePath& path(*this); #endif -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE LPCWSTR unicode = String::AnsiToUtf16(path.c_str()); const DWORD attributes = GetFileAttributes(unicode); delete[] unicode; @@ -344,14 +345,15 @@ bool FilePath::CreateDirectoriesRecursively() const { // directory for any reason, including if the parent directory does not // exist. Not named "CreateDirectory" because that's a macro on Windows. bool FilePath::CreateFolder() const { -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE FilePath removed_sep(this->RemoveTrailingPathSeparator()); LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str()); int result = CreateDirectory(unicode, nullptr) ? 0 : -1; delete[] unicode; -#elif GTEST_OS_WINDOWS +#elif defined(GTEST_OS_WINDOWS) 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 int result = 0; #else @@ -380,7 +382,7 @@ void FilePath::Normalize() { auto out = pathname_.begin(); auto i = pathname_.cbegin(); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // UNC paths are treated specially if (pathname_.end() - i >= 3 && IsPathSeparator(*i) && IsPathSeparator(*(i + 1)) && !IsPathSeparator(*(i + 2))) { diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h index 9fbcfd3..036c341 100644 --- a/googletest/src/gtest-internal-inl.h +++ b/googletest/src/gtest-internal-inl.h @@ -55,7 +55,7 @@ #include <netdb.h> // NOLINT #endif -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #include <windows.h> // NOLINT #endif // GTEST_OS_WINDOWS @@ -384,7 +384,7 @@ class GTEST_API_ UnitTestOptions { static bool FilterMatchesTest(const std::string& test_suite_name, const std::string& test_name); -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS // Function for supporting the gtest_catch_exception flag. // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index 105a3ec..da4d12d 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -38,7 +38,7 @@ #include <fstream> #include <memory> -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #include <io.h> #include <sys/stat.h> #include <windows.h> @@ -51,32 +51,34 @@ #include <unistd.h> #endif // GTEST_OS_WINDOWS -#if GTEST_OS_MAC +#ifdef GTEST_OS_MAC #include <mach/mach_init.h> #include <mach/task.h> #include <mach/vm_map.h> #endif // GTEST_OS_MAC -#if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \ - GTEST_OS_NETBSD || GTEST_OS_OPENBSD +#if defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD) || \ + defined(GTEST_OS_OPENBSD) #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> #endif #endif -#if GTEST_OS_QNX +#ifdef GTEST_OS_QNX #include <devctl.h> #include <fcntl.h> #include <sys/procfs.h> #endif // GTEST_OS_QNX -#if GTEST_OS_AIX +#ifdef GTEST_OS_AIX #include <procinfo.h> #include <sys/types.h> #endif // GTEST_OS_AIX -#if GTEST_OS_FUCHSIA +#ifdef GTEST_OS_FUCHSIA #include <zircon/process.h> #include <zircon/syscalls.h> #endif // GTEST_OS_FUCHSIA @@ -90,7 +92,7 @@ namespace testing { namespace internal { -#if GTEST_OS_LINUX || GTEST_OS_GNU_HURD +#if defined(GTEST_OS_LINUX) || defined(GTEST_OS_GNU_HURD) namespace { template <typename T> @@ -113,7 +115,7 @@ size_t GetThreadCount() { return ReadProcFileField<size_t>(filename, 19); } -#elif GTEST_OS_MAC +#elif defined(GTEST_OS_MAC) size_t GetThreadCount() { 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 || \ - GTEST_OS_NETBSD +#elif defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \ + defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD) -#if GTEST_OS_NETBSD +#ifdef GTEST_OS_NETBSD #undef KERN_PROC #define KERN_PROC KERN_PROC2 #define kinfo_proc kinfo_proc2 #endif -#if GTEST_OS_DRAGONFLY +#ifdef GTEST_OS_DRAGONFLY #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) -#elif GTEST_OS_NETBSD +#elif defined(GTEST_OS_NETBSD) #define KP_NLWP(kp) (kp.p_nlwps) #endif @@ -156,7 +158,7 @@ size_t GetThreadCount() { KERN_PROC, KERN_PROC_PID, getpid(), -#if GTEST_OS_NETBSD +#ifdef GTEST_OS_NETBSD sizeof(struct kinfo_proc), 1, #endif @@ -169,7 +171,7 @@ size_t GetThreadCount() { } 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 // we cannot detect it. @@ -206,7 +208,7 @@ size_t GetThreadCount() { 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 // we cannot detect it. @@ -226,7 +228,7 @@ size_t GetThreadCount() { } } -#elif GTEST_OS_AIX +#elif defined(GTEST_OS_AIX) size_t GetThreadCount() { struct procentry64 entry; @@ -239,7 +241,7 @@ size_t GetThreadCount() { } } -#elif GTEST_OS_FUCHSIA +#elif defined(GTEST_OS_FUCHSIA) size_t GetThreadCount() { int dummy_buffer; @@ -264,7 +266,7 @@ size_t GetThreadCount() { #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) {} @@ -1027,7 +1029,7 @@ class CapturedStream { public: // The ctor redirects the stream to a temporary file. 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_file_path[MAX_PATH + 1] = {'\0'}; // NOLINT @@ -1046,7 +1048,7 @@ class CapturedStream { // directory, so we create the temporary file in a temporary directory. std::string name_template; -#if GTEST_OS_LINUX_ANDROID +#ifdef GTEST_OS_LINUX_ANDROID // Note: Android applications are expected to call the framework's // Context.getExternalStorageDirectory() method through JNI to get // 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 // guaranteed to be mounted, or may have a delay in mounting. name_template = "/data/local/tmp/"; -#elif GTEST_OS_IOS +#elif defined(GTEST_OS_IOS) char user_temp_dir[PATH_MAX + 1]; // Documented alternative to NSTemporaryDirectory() (for obtaining creating @@ -1246,7 +1248,7 @@ void ClearInjectableArgvs() { } #endif // GTEST_HAS_DEATH_TEST -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE namespace posix { void Abort() { DebugBreak(); diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index fb578d5..88bbcd2 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -61,7 +61,7 @@ #include "gtest/internal/custom/gtest.h" #include "gtest/internal/gtest-port.h" -#if GTEST_OS_LINUX +#ifdef GTEST_OS_LINUX #include <fcntl.h> // NOLINT #include <limits.h> // NOLINT @@ -74,18 +74,18 @@ #include <string> -#elif GTEST_OS_ZOS +#elif defined(GTEST_OS_ZOS) #include <sys/time.h> // NOLINT // On z/OS we additionally need strings.h for strcasecmp. #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 #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 #undef min @@ -99,7 +99,7 @@ #include <sys/timeb.h> // NOLINT #include <sys/types.h> // NOLINT -#if GTEST_OS_WINDOWS_MINGW +#ifdef GTEST_OS_WINDOWS_MINGW #include <sys/time.h> // NOLINT #endif // GTEST_OS_WINDOWS_MINGW @@ -125,11 +125,11 @@ #include "src/gtest-internal-inl.h" -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS #define vsnprintf _vsnprintf #endif // GTEST_OS_WINDOWS -#if GTEST_OS_MAC +#ifdef GTEST_OS_MAC #ifndef GTEST_OS_IOS #include <crt_externs.h> #endif @@ -630,7 +630,7 @@ static ::std::vector<std::string> g_argvs; FilePath GetCurrentExecutableName() { 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")); #else result.Set(FilePath(GetArgvs()[0])); @@ -1165,7 +1165,7 @@ TimeInMillis GetTimeInMillis() { // class String. -#if GTEST_OS_WINDOWS_MOBILE +#ifdef GTEST_OS_WINDOWS_MOBILE // Creates a UTF-16 wide string from the given ANSI string, allocating // memory using new. The caller is responsible for deleting the return // value using delete[]. Returns the wide string, or NULL if the @@ -1867,14 +1867,14 @@ AssertionResult IsNotSubstring(const char* needle_expr, namespace internal { -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS namespace { // Helper function for IsHRESULT{SuccessFailure} predicates AssertionResult HRESULTFailureHelper(const char* expr, const char* expected, 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. const char error_text[] = ""; @@ -2135,9 +2135,9 @@ bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs, if (rhs == nullptr) return false; -#if GTEST_OS_WINDOWS +#ifdef GTEST_OS_WINDOWS 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; #else // 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 // window such that the user can double-click on it to jump to the // 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 // to stdout is done by OutputDebugString() there already - we don't // want the same message printed twice. @@ -3154,8 +3154,9 @@ static void PrintTestPartResult(const TestPartResult& test_part_result) { } // class PrettyUnitTestResultPrinter -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ - !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \ + !defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \ + !defined(GTEST_OS_WINDOWS_MINGW) // Returns the character attribute for the given color. static WORD GetColorAttribute(GTestColor color) { @@ -3227,7 +3228,7 @@ bool ShouldUseColor(bool stdout_is_tty) { const char* const gtest_color = c.c_str(); 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 // console there does support colors. return stdout_is_tty; @@ -3282,8 +3283,9 @@ static void ColoredPrintf(GTestColor color, const char* fmt, ...) { return; } -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ - !GTEST_OS_WINDOWS_RT && !GTEST_OS_WINDOWS_MINGW +#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) && \ + !defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \ + !defined(GTEST_OS_WINDOWS_MINGW) const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE); // Gets the current text color. @@ -5036,7 +5038,7 @@ class ScopedPrematureExitFile { } ~ScopedPrematureExitFile() { -#if !GTEST_OS_ESP8266 +#ifndef GTEST_OS_ESP8266 if (!premature_exit_filepath_.empty()) { int retval = remove(premature_exit_filepath_.c_str()); if (retval) { @@ -5332,7 +5334,8 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type, // with another testing framework) and specify the former on the // command line for debugging. 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 // when a failure happens and both the --gtest_break_on_failure and // the --gtest_catch_exceptions flags are specified. @@ -5417,26 +5420,28 @@ int UnitTest::Run() { // used for the duration of the program. 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 // 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 // about crashes - they are expected. 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(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); #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, // _abort() can show a dialog with a warning message. This forces the // abort message to go to stderr instead. _set_error_mode(_OUT_TO_STDERR); #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 // 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 @@ -6520,7 +6525,7 @@ static const char kColorEncodedHelpMessage[] = #endif // GTEST_CAN_STREAM_RESULTS_ "\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_ "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\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 // *_NSGetArgv() == argv // Only applicable to char** version of argv -#if GTEST_OS_MAC +#ifdef GTEST_OS_MAC #ifndef GTEST_OS_IOS if (*_NSGetArgv() == argv) { *_NSGetArgc() = *argc; @@ -6799,9 +6804,9 @@ static std::string GetDirFromEnv( std::string TempDir() { #if defined(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\\", '\\'); -#elif GTEST_OS_LINUX_ANDROID +#elif defined(GTEST_OS_LINUX_ANDROID) return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/data/local/tmp/", '/'); #else return GetDirFromEnv({"TEST_TMPDIR", "TMPDIR"}, "/tmp/", '/'); @@ -6821,10 +6826,10 @@ static std::string GetCurrentExecutableDirectory() { std::string SrcDir() { #if defined(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(), '\\'); -#elif GTEST_OS_LINUX_ANDROID +#elif defined(GTEST_OS_LINUX_ANDROID) return GetDirFromEnv({"TEST_SRCDIR"}, GetCurrentExecutableDirectory().c_str(), '/'); #else diff --git a/googletest/src/gtest_main.cc b/googletest/src/gtest_main.cc index 5abaa29..c2e3b3c 100644 --- a/googletest/src/gtest_main.cc +++ b/googletest/src/gtest_main.cc @@ -31,10 +31,10 @@ #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. -#if GTEST_OS_ESP8266 +#ifdef GTEST_OS_ESP8266 extern "C" { #endif @@ -42,11 +42,11 @@ void setup() { testing::InitGoogleTest(); } void loop() { RUN_ALL_TESTS(); } -#if GTEST_OS_ESP8266 +#ifdef GTEST_OS_ESP8266 } #endif -#elif GTEST_OS_QURT +#elif defined(GTEST_OS_QURT) // QuRT: program entry point is main, but argc/argv are unusable. GTEST_API_ int main() { |