gtest-port.h (googletest-release-1.10.0) | : | gtest-port.h (googletest-release-1.11.0) | ||
---|---|---|---|---|
skipping to change at line 43 | skipping to change at line 43 | |||
// outside Google Test MUST NOT USE THEM DIRECTLY. Macros that don't | // outside Google Test MUST NOT USE THEM DIRECTLY. Macros that don't | |||
// end with _ are part of Google Test's public API and can be used by | // end with _ are part of Google Test's public API and can be used by | |||
// code outside Google Test. | // code outside Google Test. | |||
// | // | |||
// This file is fundamental to Google Test. All other Google Test source | // This file is fundamental to Google Test. All other Google Test source | |||
// files are expected to #include this. Therefore, it cannot #include | // files are expected to #include this. Therefore, it cannot #include | |||
// any other Google Test header. | // any other Google Test header. | |||
// GOOGLETEST_CM0001 DO NOT DELETE | // GOOGLETEST_CM0001 DO NOT DELETE | |||
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ | |||
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ | |||
// Environment-describing macros | // Environment-describing macros | |||
// ----------------------------- | // ----------------------------- | |||
// | // | |||
// Google Test can be used in many different environments. Macros in | // Google Test can be used in many different environments. Macros in | |||
// this section tell Google Test what kind of environment it is being | // this section tell Google Test what kind of environment it is being | |||
// used in, such that Google Test can provide environment-specific | // used in, such that Google Test can provide environment-specific | |||
// features and implementations. | // features and implementations. | |||
// | // | |||
// Google Test tries to automatically detect the properties of its | // Google Test tries to automatically detect the properties of its | |||
skipping to change at line 193 | skipping to change at line 193 | |||
// Internal utilities | // Internal utilities | |||
// ------------------ | // ------------------ | |||
// | // | |||
// The following macros and utilities are for Google Test's INTERNAL | // The following macros and utilities are for Google Test's INTERNAL | |||
// use only. Code outside Google Test MUST NOT USE THEM DIRECTLY. | // use only. Code outside Google Test MUST NOT USE THEM DIRECTLY. | |||
// | // | |||
// Macros for basic C++ coding: | // Macros for basic C++ coding: | |||
// GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning. | // GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning. | |||
// GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a | // GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a | |||
// variable don't have to be used. | // variable don't have to be used. | |||
// GTEST_DISALLOW_ASSIGN_ - disables operator=. | // GTEST_DISALLOW_ASSIGN_ - disables copy operator=. | |||
// GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=. | // GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=. | |||
// GTEST_DISALLOW_MOVE_ASSIGN_ - disables move operator=. | ||||
// GTEST_DISALLOW_MOVE_AND_ASSIGN_ - disables move ctor and operator=. | ||||
// GTEST_MUST_USE_RESULT_ - declares that a function's result must be used. | // GTEST_MUST_USE_RESULT_ - declares that a function's result must be used. | |||
// GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is | // GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is | |||
// suppressed (constant conditional). | // suppressed (constant conditional). | |||
// GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127 | // GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127 | |||
// is suppressed. | // is suppressed. | |||
// GTEST_INTERNAL_HAS_ANY - for enabling UniversalPrinter<std::any> or | ||||
// UniversalPrinter<absl::any> specializations. | ||||
// GTEST_INTERNAL_HAS_OPTIONAL - for enabling UniversalPrinter<std::optional> | ||||
// or | ||||
// UniversalPrinter<absl::optional> | ||||
// specializations. | ||||
// GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher<std::string_view> or | ||||
// Matcher<absl::string_view> | ||||
// specializations. | ||||
// GTEST_INTERNAL_HAS_VARIANT - for enabling UniversalPrinter<std::variant> or | ||||
// UniversalPrinter<absl::variant> | ||||
// specializations. | ||||
// | // | |||
// Synchronization: | // Synchronization: | |||
// Mutex, MutexLock, ThreadLocal, GetThreadCount() | // Mutex, MutexLock, ThreadLocal, GetThreadCount() | |||
// - synchronization primitives. | // - synchronization primitives. | |||
// | // | |||
// Regular expressions: | // Regular expressions: | |||
// RE - a simple regular expression class using the POSIX | // RE - a simple regular expression class using the POSIX | |||
// Extended Regular Expression syntax on UNIX-like platforms | // Extended Regular Expression syntax on UNIX-like platforms | |||
// GOOGLETEST_CM0008 DO NOT DELETE | // GOOGLETEST_CM0008 DO NOT DELETE | |||
// or a reduced regular exception syntax on other | // or a reduced regular exception syntax on other | |||
skipping to change at line 226 | skipping to change at line 240 | |||
// Stdout and stderr capturing: | // Stdout and stderr capturing: | |||
// CaptureStdout() - starts capturing stdout. | // CaptureStdout() - starts capturing stdout. | |||
// GetCapturedStdout() - stops capturing stdout and returns the captured | // GetCapturedStdout() - stops capturing stdout and returns the captured | |||
// string. | // string. | |||
// CaptureStderr() - starts capturing stderr. | // CaptureStderr() - starts capturing stderr. | |||
// GetCapturedStderr() - stops capturing stderr and returns the captured | // GetCapturedStderr() - stops capturing stderr and returns the captured | |||
// string. | // string. | |||
// | // | |||
// Integer types: | // Integer types: | |||
// TypeWithSize - maps an integer to a int type. | // TypeWithSize - maps an integer to a int type. | |||
// Int32, UInt32, Int64, UInt64, TimeInMillis | // TimeInMillis - integers of known sizes. | |||
// - integers of known sizes. | ||||
// BiggestInt - the biggest signed integer type. | // BiggestInt - the biggest signed integer type. | |||
// | // | |||
// Command-line utilities: | // Command-line utilities: | |||
// GTEST_DECLARE_*() - declares a flag. | // GTEST_DECLARE_*() - declares a flag. | |||
// GTEST_DEFINE_*() - defines a flag. | // GTEST_DEFINE_*() - defines a flag. | |||
// GetInjectableArgvs() - returns the command line as a vector of strings. | // GetInjectableArgvs() - returns the command line as a vector of strings. | |||
// | // | |||
// Environment variable utilities: | // Environment variable utilities: | |||
// GetEnv() - gets the value of an environment variable. | // GetEnv() - gets the value of an environment variable. | |||
// BoolFromGTestEnv() - parses a bool environment variable. | // BoolFromGTestEnv() - parses a bool environment variable. | |||
// Int32FromGTestEnv() - parses an Int32 environment variable. | // Int32FromGTestEnv() - parses an int32_t environment variable. | |||
// StringFromGTestEnv() - parses a string environment variable. | // StringFromGTestEnv() - parses a string environment variable. | |||
// | // | |||
// Deprecation warnings: | // Deprecation warnings: | |||
// GTEST_INTERNAL_DEPRECATED(message) - attribute marking a function as | // GTEST_INTERNAL_DEPRECATED(message) - attribute marking a function as | |||
// deprecated; calling a marked function | // deprecated; calling a marked function | |||
// should generate a compiler warning | // should generate a compiler warning | |||
#include <ctype.h> // for isspace, etc | #include <ctype.h> // for isspace, etc | |||
#include <stddef.h> // for ptrdiff_t | #include <stddef.h> // for ptrdiff_t | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include <string.h> | #include <string.h> | |||
#include <memory> | ||||
#include <cerrno> | ||||
#include <cstdint> | ||||
#include <limits> | ||||
#include <type_traits> | #include <type_traits> | |||
#ifndef _WIN32_WCE | #ifndef _WIN32_WCE | |||
# include <sys/types.h> | # include <sys/types.h> | |||
# include <sys/stat.h> | # include <sys/stat.h> | |||
#endif // !_WIN32_WCE | #endif // !_WIN32_WCE | |||
#if defined __APPLE__ | #if defined __APPLE__ | |||
# include <AvailabilityMacros.h> | # include <AvailabilityMacros.h> | |||
# include <TargetConditionals.h> | # include <TargetConditionals.h> | |||
#endif | #endif | |||
#include <algorithm> // NOLINT | #include <iostream> // NOLINT | |||
#include <iostream> // NOLINT | #include <locale> | |||
#include <sstream> // NOLINT | #include <memory> | |||
#include <string> // NOLINT | #include <string> // NOLINT | |||
#include <tuple> | #include <tuple> | |||
#include <utility> | ||||
#include <vector> // NOLINT | #include <vector> // NOLINT | |||
#include "gtest/internal/gtest-port-arch.h" | ||||
#include "gtest/internal/custom/gtest-port.h" | #include "gtest/internal/custom/gtest-port.h" | |||
#include "gtest/internal/gtest-port-arch.h" | ||||
#if !defined(GTEST_DEV_EMAIL_) | #if !defined(GTEST_DEV_EMAIL_) | |||
# define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com" | # define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com" | |||
# define GTEST_FLAG_PREFIX_ "gtest_" | # define GTEST_FLAG_PREFIX_ "gtest_" | |||
# define GTEST_FLAG_PREFIX_DASH_ "gtest-" | # define GTEST_FLAG_PREFIX_DASH_ "gtest-" | |||
# define GTEST_FLAG_PREFIX_UPPER_ "GTEST_" | # define GTEST_FLAG_PREFIX_UPPER_ "GTEST_" | |||
# define GTEST_NAME_ "Google Test" | # define GTEST_NAME_ "Google Test" | |||
# define GTEST_PROJECT_URL_ "https://github.com/google/googletest/" | # define GTEST_PROJECT_URL_ "https://github.com/google/googletest/" | |||
#endif // !defined(GTEST_DEV_EMAIL_) | #endif // !defined(GTEST_DEV_EMAIL_) | |||
skipping to change at line 347 | skipping to change at line 362 | |||
#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR) | #if 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; | |||
#else | #else | |||
// Assume CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION. | // Assume CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION. | |||
// This assumption is verified by | // This assumption is verified by | |||
// 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 | ||||
#include <unistd.h> | ||||
// Xtensa toolchains define strcasecmp in the string.h header instead of | ||||
// strings.h. string.h is already included. | ||||
#else | #else | |||
// This assumes that non-Windows OSes provide unistd.h. For OSes where this | // This assumes that non-Windows OSes provide unistd.h. For OSes where this | |||
// is not the case, we need to include headers that provide the functions | // is not the case, we need to include headers that provide the functions | |||
// mentioned above. | // mentioned above. | |||
# include <unistd.h> | # include <unistd.h> | |||
# include <strings.h> | # include <strings.h> | |||
#endif // GTEST_OS_WINDOWS | #endif // GTEST_OS_WINDOWS | |||
#if GTEST_OS_LINUX_ANDROID | #if 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 | |||
// 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 | # if 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 (!GTEST_OS_WINDOWS) | #define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS && !GTEST_OS_XTENSA) | |||
# endif | # endif | |||
#endif | #endif | |||
#if GTEST_USES_PCRE | #if GTEST_USES_PCRE | |||
// The appropriate headers have already been included. | // The appropriate headers have already been included. | |||
#elif GTEST_HAS_POSIX_RE | #elif GTEST_HAS_POSIX_RE | |||
// On some platforms, <regex.h> needs someone to define size_t, and | // On some platforms, <regex.h> needs someone to define size_t, and | |||
// won't compile otherwise. We can #include it here as we already | // won't compile otherwise. We can #include it here as we already | |||
skipping to change at line 444 | skipping to change at line 463 | |||
// Exception handling is in effect by default in HP aCC compiler. It has to | // Exception handling is in effect by default in HP aCC compiler. It has to | |||
// be turned of by +noeh compiler option if desired. | // be turned of by +noeh compiler option if desired. | |||
# define GTEST_HAS_EXCEPTIONS 1 | # define GTEST_HAS_EXCEPTIONS 1 | |||
# else | # else | |||
// For other compilers, we assume exceptions are disabled to be | // For other compilers, we assume exceptions are disabled to be | |||
// conservative. | // conservative. | |||
# define GTEST_HAS_EXCEPTIONS 0 | # define GTEST_HAS_EXCEPTIONS 0 | |||
# endif // defined(_MSC_VER) || defined(__BORLANDC__) | # endif // defined(_MSC_VER) || defined(__BORLANDC__) | |||
#endif // GTEST_HAS_EXCEPTIONS | #endif // GTEST_HAS_EXCEPTIONS | |||
#if !defined(GTEST_HAS_STD_STRING) | ||||
// Even though we don't use this macro any longer, we keep it in case | ||||
// some clients still depend on it. | ||||
# define GTEST_HAS_STD_STRING 1 | ||||
#elif !GTEST_HAS_STD_STRING | ||||
// The user told us that ::std::string isn't available. | ||||
# error "::std::string isn't available." | ||||
#endif // !defined(GTEST_HAS_STD_STRING) | ||||
#ifndef GTEST_HAS_STD_WSTRING | #ifndef GTEST_HAS_STD_WSTRING | |||
// The user didn't tell us whether ::std::wstring is available, so we need | // The user didn't tell us whether ::std::wstring is available, so we need | |||
// to figure it out. | // to figure it out. | |||
// 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 \ | #define GTEST_HAS_STD_WSTRING \ | |||
(!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ | (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ | |||
GTEST_OS_HAIKU)) | GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266 || GTEST_OS_XTENSA)) | |||
#endif // GTEST_HAS_STD_WSTRING | #endif // GTEST_HAS_STD_WSTRING | |||
// Determines whether RTTI is available. | // Determines whether RTTI is available. | |||
#ifndef GTEST_HAS_RTTI | #ifndef GTEST_HAS_RTTI | |||
// The user didn't tell us whether RTTI is enabled, so we need to | // The user didn't tell us whether RTTI is enabled, so we need to | |||
// figure it out. | // figure it out. | |||
# ifdef _MSC_VER | # ifdef _MSC_VER | |||
skipping to change at line 585 | skipping to change at line 595 | |||
# define GTEST_HAS_CLONE 0 | # define GTEST_HAS_CLONE 0 | |||
# endif // GTEST_OS_LINUX && !defined(__ia64__) | # endif // GTEST_OS_LINUX && !defined(__ia64__) | |||
#endif // GTEST_HAS_CLONE | #endif // GTEST_HAS_CLONE | |||
// Determines whether to support stream redirection. This is used to test | // Determines whether to support stream redirection. This is used to test | |||
// output correctness and to implement death tests. | // output correctness and to implement death tests. | |||
#ifndef GTEST_HAS_STREAM_REDIRECTION | #ifndef GTEST_HAS_STREAM_REDIRECTION | |||
// 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 ones. | // platforms except known mobile ones. | |||
# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT | #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ | |||
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA | ||||
# 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 | |||
# endif // !GTEST_OS_WINDOWS_MOBILE | # endif // !GTEST_OS_WINDOWS_MOBILE | |||
#endif // GTEST_HAS_STREAM_REDIRECTION | #endif // GTEST_HAS_STREAM_REDIRECTION | |||
// 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 (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ | |||
(GTEST_OS_MAC && !GTEST_OS_IOS) || \ | (GTEST_OS_MAC && !GTEST_OS_IOS) || \ | |||
skipping to change at line 678 | skipping to change at line 689 | |||
__attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \ | __attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \ | |||
first_to_check))) | first_to_check))) | |||
# else | # else | |||
# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ | # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ | |||
__attribute__((__format__(__printf__, string_index, first_to_check))) | __attribute__((__format__(__printf__, string_index, first_to_check))) | |||
# endif | # endif | |||
#else | #else | |||
# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) | # define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) | |||
#endif | #endif | |||
// A macro to disallow operator= | // A macro to disallow copy operator= | |||
// This should be used in the private: declarations for a class. | // This should be used in the private: declarations for a class. | |||
#define GTEST_DISALLOW_ASSIGN_(type) \ | #define GTEST_DISALLOW_ASSIGN_(type) \ | |||
void operator=(type const &) = delete | type& operator=(type const &) = delete | |||
// A macro to disallow copy constructor and operator= | // A macro to disallow copy constructor and operator= | |||
// This should be used in the private: declarations for a class. | // This should be used in the private: declarations for a class. | |||
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \ | #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \ | |||
type(type const &) = delete; \ | type(type const&) = delete; \ | |||
GTEST_DISALLOW_ASSIGN_(type) | type& operator=(type const&) = delete | |||
// A macro to disallow move operator= | ||||
// This should be used in the private: declarations for a class. | ||||
#define GTEST_DISALLOW_MOVE_ASSIGN_(type) \ | ||||
type& operator=(type &&) noexcept = delete | ||||
// A macro to disallow move constructor and operator= | ||||
// This should be used in the private: declarations for a class. | ||||
#define GTEST_DISALLOW_MOVE_AND_ASSIGN_(type) \ | ||||
type(type&&) noexcept = delete; \ | ||||
type& operator=(type&&) noexcept = delete | ||||
// Tell the compiler to warn about unused return values for functions declared | // Tell the compiler to warn about unused return values for functions declared | |||
// with this macro. The macro should be used on function declarations | // with this macro. The macro should be used on function declarations | |||
// following the argument list: | // following the argument list: | |||
// | // | |||
// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; | // Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; | |||
#if defined(__GNUC__) && !defined(COMPILER_ICC) | #if defined(__GNUC__) && !defined(COMPILER_ICC) | |||
# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) | # define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) | |||
#else | #else | |||
# define GTEST_MUST_USE_RESULT_ | # define GTEST_MUST_USE_RESULT_ | |||
skipping to change at line 858 | skipping to change at line 880 | |||
// time expression is true (in new code, use static_assert instead). For | // time expression is true (in new code, use static_assert instead). For | |||
// example, you could use it to verify the size of a static array: | // example, you could use it to verify the size of a static array: | |||
// | // | |||
// GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES, | // GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES, | |||
// names_incorrect_size); | // names_incorrect_size); | |||
// | // | |||
// The second argument to the macro must be a valid C++ identifier. If the | // The second argument to the macro must be a valid C++ identifier. If the | |||
// expression is false, compiler will issue an error containing this identifier. | // expression is false, compiler will issue an error containing this identifier. | |||
#define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg) | #define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg) | |||
// Evaluates to the number of elements in 'array'. | ||||
#define GTEST_ARRAY_SIZE_(array) (sizeof(array) / sizeof(array[0])) | ||||
// A helper for suppressing warnings on constant condition. It just | // A helper for suppressing warnings on constant condition. It just | |||
// returns 'condition'. | // returns 'condition'. | |||
GTEST_API_ bool IsTrue(bool condition); | GTEST_API_ bool IsTrue(bool condition); | |||
// Defines RE. | // Defines RE. | |||
#if GTEST_USES_PCRE | #if GTEST_USES_PCRE | |||
// if used, PCRE is injected by custom/gtest-port.h | // if used, PCRE is injected by custom/gtest-port.h | |||
#elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE | #elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE | |||
skipping to change at line 917 | skipping to change at line 936 | |||
# if GTEST_USES_POSIX_RE | # if GTEST_USES_POSIX_RE | |||
regex_t full_regex_; // For FullMatch(). | regex_t full_regex_; // For FullMatch(). | |||
regex_t partial_regex_; // For PartialMatch(). | regex_t partial_regex_; // For PartialMatch(). | |||
# else // GTEST_USES_SIMPLE_RE | # else // GTEST_USES_SIMPLE_RE | |||
const char* full_pattern_; // For FullMatch(); | const char* full_pattern_; // For FullMatch(); | |||
# endif | # endif | |||
GTEST_DISALLOW_ASSIGN_(RE); | ||||
}; | }; | |||
#endif // GTEST_USES_PCRE | #endif // GTEST_USES_PCRE | |||
// Formats a source file path and a line number as they would appear | // Formats a source file path and a line number as they would appear | |||
// in an error message from the compiler used to compile this code. | // in an error message from the compiler used to compile this code. | |||
GTEST_API_ ::std::string FormatFileLocation(const char* file, int line); | GTEST_API_ ::std::string FormatFileLocation(const char* file, int line); | |||
// Formats a file location for compiler-independent XML output. | // Formats a file location for compiler-independent XML output. | |||
// Although this function is not platform dependent, we put it next to | // Although this function is not platform dependent, we put it next to | |||
skipping to change at line 1600 | skipping to change at line 1617 | |||
virtual ~ValueHolderFactory() {} | virtual ~ValueHolderFactory() {} | |||
virtual ValueHolder* MakeNewHolder() const = 0; | virtual ValueHolder* MakeNewHolder() const = 0; | |||
private: | private: | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory); | GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory); | |||
}; | }; | |||
class DefaultValueHolderFactory : public ValueHolderFactory { | class DefaultValueHolderFactory : public ValueHolderFactory { | |||
public: | public: | |||
DefaultValueHolderFactory() {} | DefaultValueHolderFactory() {} | |||
virtual ValueHolder* MakeNewHolder() const { return new ValueHolder(); } | ValueHolder* MakeNewHolder() const override { return new ValueHolder(); } | |||
private: | private: | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory); | GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory); | |||
}; | }; | |||
class InstanceValueHolderFactory : public ValueHolderFactory { | class InstanceValueHolderFactory : public ValueHolderFactory { | |||
public: | public: | |||
explicit InstanceValueHolderFactory(const T& value) : value_(value) {} | explicit InstanceValueHolderFactory(const T& value) : value_(value) {} | |||
virtual ValueHolder* MakeNewHolder() const { | ValueHolder* MakeNewHolder() const override { | |||
return new ValueHolder(value_); | return new ValueHolder(value_); | |||
} | } | |||
private: | private: | |||
const T value_; // The value for each thread. | const T value_; // The value for each thread. | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory); | GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory); | |||
}; | }; | |||
std::unique_ptr<ValueHolderFactory> default_factory_; | std::unique_ptr<ValueHolderFactory> default_factory_; | |||
skipping to change at line 1809 | skipping to change at line 1826 | |||
virtual ~ValueHolderFactory() {} | virtual ~ValueHolderFactory() {} | |||
virtual ValueHolder* MakeNewHolder() const = 0; | virtual ValueHolder* MakeNewHolder() const = 0; | |||
private: | private: | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory); | GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory); | |||
}; | }; | |||
class DefaultValueHolderFactory : public ValueHolderFactory { | class DefaultValueHolderFactory : public ValueHolderFactory { | |||
public: | public: | |||
DefaultValueHolderFactory() {} | DefaultValueHolderFactory() {} | |||
virtual ValueHolder* MakeNewHolder() const { return new ValueHolder(); } | ValueHolder* MakeNewHolder() const override { return new ValueHolder(); } | |||
private: | private: | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory); | GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory); | |||
}; | }; | |||
class InstanceValueHolderFactory : public ValueHolderFactory { | class InstanceValueHolderFactory : public ValueHolderFactory { | |||
public: | public: | |||
explicit InstanceValueHolderFactory(const T& value) : value_(value) {} | explicit InstanceValueHolderFactory(const T& value) : value_(value) {} | |||
virtual ValueHolder* MakeNewHolder() const { | ValueHolder* MakeNewHolder() const override { | |||
return new ValueHolder(value_); | return new ValueHolder(value_); | |||
} | } | |||
private: | private: | |||
const T value_; // The value for each thread. | const T value_; // The value for each thread. | |||
GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory); | GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory); | |||
}; | }; | |||
// A key pthreads uses for looking up per-thread values. | // A key pthreads uses for looking up per-thread values. | |||
skipping to change at line 1888 | skipping to change at line 1905 | |||
private: | private: | |||
T value_; | T value_; | |||
}; | }; | |||
#endif // GTEST_IS_THREADSAFE | #endif // GTEST_IS_THREADSAFE | |||
// 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. | |||
GTEST_API_ size_t GetThreadCount(); | GTEST_API_ size_t GetThreadCount(); | |||
template <bool B> | ||||
using bool_constant = std::integral_constant<bool, B>; | ||||
#if GTEST_OS_WINDOWS | #if 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 | |||
// The biggest signed integer type the compiler supports. | ||||
typedef __int64 BiggestInt; | ||||
#else | #else | |||
# define GTEST_PATH_SEP_ "/" | # define GTEST_PATH_SEP_ "/" | |||
# define GTEST_HAS_ALT_PATH_SEP_ 0 | # define GTEST_HAS_ALT_PATH_SEP_ 0 | |||
typedef long long BiggestInt; // NOLINT | ||||
#endif // GTEST_OS_WINDOWS | #endif // GTEST_OS_WINDOWS | |||
// Utilities for char. | // Utilities for char. | |||
// isspace(int ch) and friends accept an unsigned char or EOF. char | // isspace(int ch) and friends accept an unsigned char or EOF. char | |||
// may be signed, depending on the compiler (or compiler flags). | // may be signed, depending on the compiler (or compiler flags). | |||
// Therefore we need to cast a char to unsigned char before calling | // Therefore we need to cast a char to unsigned char before calling | |||
// isspace(), etc. | // isspace(), etc. | |||
inline bool IsAlpha(char ch) { | inline bool IsAlpha(char ch) { | |||
skipping to change at line 1930 | skipping to change at line 1941 | |||
} | } | |||
inline bool IsSpace(char ch) { | inline bool IsSpace(char ch) { | |||
return isspace(static_cast<unsigned char>(ch)) != 0; | return isspace(static_cast<unsigned char>(ch)) != 0; | |||
} | } | |||
inline bool IsUpper(char ch) { | inline bool IsUpper(char ch) { | |||
return isupper(static_cast<unsigned char>(ch)) != 0; | return isupper(static_cast<unsigned char>(ch)) != 0; | |||
} | } | |||
inline bool IsXDigit(char ch) { | inline bool IsXDigit(char ch) { | |||
return isxdigit(static_cast<unsigned char>(ch)) != 0; | return isxdigit(static_cast<unsigned char>(ch)) != 0; | |||
} | } | |||
#ifdef __cpp_char8_t | ||||
inline bool IsXDigit(char8_t ch) { | ||||
return isxdigit(static_cast<unsigned char>(ch)) != 0; | ||||
} | ||||
#endif | ||||
inline bool IsXDigit(char16_t ch) { | ||||
const unsigned char low_byte = static_cast<unsigned char>(ch); | ||||
return ch == low_byte && isxdigit(low_byte) != 0; | ||||
} | ||||
inline bool IsXDigit(char32_t ch) { | ||||
const unsigned char low_byte = static_cast<unsigned char>(ch); | ||||
return ch == low_byte && isxdigit(low_byte) != 0; | ||||
} | ||||
inline bool IsXDigit(wchar_t ch) { | inline bool IsXDigit(wchar_t ch) { | |||
const unsigned char low_byte = static_cast<unsigned char>(ch); | const unsigned char low_byte = static_cast<unsigned char>(ch); | |||
return ch == low_byte && isxdigit(low_byte) != 0; | return ch == low_byte && isxdigit(low_byte) != 0; | |||
} | } | |||
inline char ToLower(char ch) { | inline char ToLower(char ch) { | |||
return static_cast<char>(tolower(static_cast<unsigned char>(ch))); | return static_cast<char>(tolower(static_cast<unsigned char>(ch))); | |||
} | } | |||
inline char ToUpper(char ch) { | inline char ToUpper(char ch) { | |||
return static_cast<char>(toupper(static_cast<unsigned char>(ch))); | return static_cast<char>(toupper(static_cast<unsigned char>(ch))); | |||
skipping to change at line 1964 | skipping to change at line 1988 | |||
namespace posix { | namespace posix { | |||
// Functions with a different name on Windows. | // Functions with a different name on Windows. | |||
#if GTEST_OS_WINDOWS | #if GTEST_OS_WINDOWS | |||
typedef struct _stat StatStruct; | typedef struct _stat StatStruct; | |||
# ifdef __BORLANDC__ | # ifdef __BORLANDC__ | |||
inline int IsATTY(int fd) { return isatty(fd); } | inline int DoIsATTY(int fd) { return isatty(fd); } | |||
inline int StrCaseCmp(const char* s1, const char* s2) { | inline int StrCaseCmp(const char* s1, const char* s2) { | |||
return stricmp(s1, s2); | return stricmp(s1, s2); | |||
} | } | |||
inline char* StrDup(const char* src) { return strdup(src); } | inline char* StrDup(const char* src) { return strdup(src); } | |||
# else // !__BORLANDC__ | # else // !__BORLANDC__ | |||
# if GTEST_OS_WINDOWS_MOBILE | # if GTEST_OS_WINDOWS_MOBILE | |||
inline int IsATTY(int /* fd */) { return 0; } | inline int DoIsATTY(int /* fd */) { return 0; } | |||
# else | # else | |||
inline int IsATTY(int fd) { return _isatty(fd); } | inline int DoIsATTY(int fd) { return _isatty(fd); } | |||
# endif // GTEST_OS_WINDOWS_MOBILE | # endif // GTEST_OS_WINDOWS_MOBILE | |||
inline int StrCaseCmp(const char* s1, const char* s2) { | inline int StrCaseCmp(const char* s1, const char* s2) { | |||
return _stricmp(s1, s2); | return _stricmp(s1, s2); | |||
} | } | |||
inline char* StrDup(const char* src) { return _strdup(src); } | inline char* StrDup(const char* src) { return _strdup(src); } | |||
# endif // __BORLANDC__ | # endif // __BORLANDC__ | |||
# if GTEST_OS_WINDOWS_MOBILE | # if 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. | |||
# else | # else | |||
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); } | |||
inline int RmDir(const char* dir) { return _rmdir(dir); } | inline int RmDir(const char* dir) { return _rmdir(dir); } | |||
inline bool IsDir(const StatStruct& st) { | inline bool IsDir(const StatStruct& st) { | |||
return (_S_IFDIR & st.st_mode) != 0; | return (_S_IFDIR & st.st_mode) != 0; | |||
} | } | |||
# endif // GTEST_OS_WINDOWS_MOBILE | # endif // GTEST_OS_WINDOWS_MOBILE | |||
#elif GTEST_OS_ESP8266 | ||||
typedef struct stat StatStruct; | ||||
inline int FileNo(FILE* file) { return fileno(file); } | ||||
inline int DoIsATTY(int fd) { return isatty(fd); } | ||||
inline int Stat(const char* path, StatStruct* buf) { | ||||
// stat function not implemented on ESP8266 | ||||
return 0; | ||||
} | ||||
inline int StrCaseCmp(const char* s1, const char* s2) { | ||||
return strcasecmp(s1, s2); | ||||
} | ||||
inline char* StrDup(const char* src) { return strdup(src); } | ||||
inline int RmDir(const char* dir) { return rmdir(dir); } | ||||
inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } | ||||
#else | #else | |||
typedef struct stat StatStruct; | typedef struct stat StatStruct; | |||
inline int FileNo(FILE* file) { return fileno(file); } | inline int FileNo(FILE* file) { return fileno(file); } | |||
inline int IsATTY(int fd) { return isatty(fd); } | inline int DoIsATTY(int fd) { return isatty(fd); } | |||
inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } | inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } | |||
inline int StrCaseCmp(const char* s1, const char* s2) { | inline int StrCaseCmp(const char* s1, const char* s2) { | |||
return strcasecmp(s1, s2); | return strcasecmp(s1, s2); | |||
} | } | |||
inline char* StrDup(const char* src) { return strdup(src); } | inline char* StrDup(const char* src) { return strdup(src); } | |||
inline int RmDir(const char* dir) { return rmdir(dir); } | inline int RmDir(const char* dir) { return rmdir(dir); } | |||
inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } | inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } | |||
#endif // GTEST_OS_WINDOWS | #endif // GTEST_OS_WINDOWS | |||
inline int IsATTY(int fd) { | ||||
// DoIsATTY might change errno (for example ENOTTY in case you redirect stdout | ||||
// to a file on Linux), which is unexpected, so save the previous value, and | ||||
// restore it after the call. | ||||
int savedErrno = errno; | ||||
int isAttyValue = DoIsATTY(fd); | ||||
errno = savedErrno; | ||||
return isAttyValue; | ||||
} | ||||
// Functions deprecated by MSVC 8.0. | // Functions deprecated by MSVC 8.0. | |||
GTEST_DISABLE_MSC_DEPRECATED_PUSH_() | GTEST_DISABLE_MSC_DEPRECATED_PUSH_() | |||
inline const char* StrNCpy(char* dest, const char* src, size_t n) { | ||||
return strncpy(dest, src, n); | ||||
} | ||||
// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and | // ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and | |||
// 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_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT | #if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ | |||
!GTEST_OS_WINDOWS_RT && !GTEST_OS_ESP8266 && !GTEST_OS_XTENSA | ||||
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 | ||||
struct wchar_codecvt : public std::codecvt<wchar_t, char, std::mbstate_t> {}; | ||||
std::wstring_convert<wchar_codecvt> converter; | ||||
std::wstring wide_path = converter.from_bytes(path); | ||||
std::wstring wide_mode = converter.from_bytes(mode); | ||||
return _wfopen(wide_path.c_str(), wide_mode.c_str()); | ||||
#else // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW | ||||
return fopen(path, mode); | return fopen(path, mode); | |||
#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW | ||||
} | } | |||
#if !GTEST_OS_WINDOWS_MOBILE | #if !GTEST_OS_WINDOWS_MOBILE | |||
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 | #endif | |||
inline int FClose(FILE* fp) { return fclose(fp); } | inline int FClose(FILE* fp) { return fclose(fp); } | |||
#if !GTEST_OS_WINDOWS_MOBILE | #if !GTEST_OS_WINDOWS_MOBILE | |||
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)); | |||
} | } | |||
inline int Write(int fd, const void* buf, unsigned int count) { | inline int Write(int fd, const void* buf, unsigned int count) { | |||
return static_cast<int>(write(fd, buf, count)); | return static_cast<int>(write(fd, buf, count)); | |||
} | } | |||
inline int Close(int fd) { return close(fd); } | inline int Close(int fd) { return close(fd); } | |||
inline const char* StrError(int errnum) { return strerror(errnum); } | inline const char* StrError(int errnum) { return strerror(errnum); } | |||
#endif | #endif | |||
inline const char* GetEnv(const char* name) { | inline const char* GetEnv(const char* name) { | |||
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT | #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ | |||
// We are on Windows CE, which has no environment variables. | GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA | |||
// 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; | |||
#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) | #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) | |||
// Environment variables which we programmatically clear will be set to the | // Environment variables which we programmatically clear will be set to the | |||
// empty string rather than unset (NULL). Handle that case. | // empty string rather than unset (NULL). Handle that case. | |||
const char* const env = getenv(name); | const char* const env = getenv(name); | |||
return (env != nullptr && env[0] != '\0') ? env : nullptr; | return (env != nullptr && env[0] != '\0') ? env : nullptr; | |||
#else | #else | |||
return getenv(name); | return getenv(name); | |||
#endif | #endif | |||
skipping to change at line 2089 | skipping to change at line 2146 | |||
// 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__) | |||
#elif defined(_MSC_VER) | #elif defined(_MSC_VER) | |||
// Windows CE does not define _snprintf_s | // Windows CE does not define _snprintf_s | |||
# define GTEST_SNPRINTF_ _snprintf | # define GTEST_SNPRINTF_ _snprintf | |||
#else | #else | |||
# define GTEST_SNPRINTF_ snprintf | # define GTEST_SNPRINTF_ snprintf | |||
#endif | #endif | |||
// The maximum number a BiggestInt can represent. This definition | // The biggest signed integer type the compiler supports. | |||
// works no matter BiggestInt is represented in one's complement or | // | |||
// two's complement. | // long long is guaranteed to be at least 64-bits in C++11. | |||
// | using BiggestInt = long long; // NOLINT | |||
// We cannot rely on numeric_limits in STL, as __int64 and long long | ||||
// are not part of standard C++ and numeric_limits doesn't need to be | // The maximum number a BiggestInt can represent. | |||
// defined for them. | constexpr BiggestInt kMaxBiggestInt = (std::numeric_limits<BiggestInt>::max)(); | |||
const BiggestInt kMaxBiggestInt = | ||||
~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1)); | ||||
// This template class serves as a compile-time function from size to | // This template class serves as a compile-time function from size to | |||
// type. It maps a size in bytes to a primitive type with that | // type. It maps a size in bytes to a primitive type with that | |||
// size. e.g. | // size. e.g. | |||
// | // | |||
// TypeWithSize<4>::UInt | // TypeWithSize<4>::UInt | |||
// | // | |||
// is typedef-ed to be unsigned int (unsigned integer made up of 4 | // is typedef-ed to be unsigned int (unsigned integer made up of 4 | |||
// bytes). | // bytes). | |||
// | // | |||
skipping to change at line 2122 | skipping to change at line 2177 | |||
// comparison. | // comparison. | |||
// | // | |||
// For now it only handles UInt (unsigned int) as that's all Google Test | // For now it only handles UInt (unsigned int) as that's all Google Test | |||
// needs. Other types can be easily added in the future if need | // needs. Other types can be easily added in the future if need | |||
// arises. | // arises. | |||
template <size_t size> | template <size_t size> | |||
class TypeWithSize { | class TypeWithSize { | |||
public: | public: | |||
// This prevents the user from using TypeWithSize<N> with incorrect | // This prevents the user from using TypeWithSize<N> with incorrect | |||
// values of N. | // values of N. | |||
typedef void UInt; | using UInt = void; | |||
}; | }; | |||
// The specialization for size 4. | // The specialization for size 4. | |||
template <> | template <> | |||
class TypeWithSize<4> { | class TypeWithSize<4> { | |||
public: | public: | |||
// unsigned int has size 4 in both gcc and MSVC. | using Int = std::int32_t; | |||
// | using UInt = std::uint32_t; | |||
// As base/basictypes.h doesn't compile on Windows, we cannot use | ||||
// uint32, uint64, and etc here. | ||||
typedef int Int; | ||||
typedef unsigned int UInt; | ||||
}; | }; | |||
// The specialization for size 8. | // The specialization for size 8. | |||
template <> | template <> | |||
class TypeWithSize<8> { | class TypeWithSize<8> { | |||
public: | public: | |||
#if GTEST_OS_WINDOWS | using Int = std::int64_t; | |||
typedef __int64 Int; | using UInt = std::uint64_t; | |||
typedef unsigned __int64 UInt; | ||||
#else | ||||
typedef long long Int; // NOLINT | ||||
typedef unsigned long long UInt; // NOLINT | ||||
#endif // GTEST_OS_WINDOWS | ||||
}; | }; | |||
// Integer types of known sizes. | // Integer types of known sizes. | |||
typedef TypeWithSize<4>::Int Int32; | using TimeInMillis = int64_t; // Represents time in milliseconds. | |||
typedef TypeWithSize<4>::UInt UInt32; | ||||
typedef TypeWithSize<8>::Int Int64; | ||||
typedef TypeWithSize<8>::UInt UInt64; | ||||
typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds. | ||||
// Utilities for command line flags and environment variables. | // Utilities for command line flags and environment variables. | |||
// Macro for referencing flags. | // Macro for referencing flags. | |||
#if !defined(GTEST_FLAG) | #if !defined(GTEST_FLAG) | |||
# define GTEST_FLAG(name) FLAGS_gtest_##name | # define GTEST_FLAG(name) FLAGS_gtest_##name | |||
#endif // !defined(GTEST_FLAG) | #endif // !defined(GTEST_FLAG) | |||
#if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) | #if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) | |||
# define GTEST_USE_OWN_FLAGFILE_FLAG_ 1 | # define GTEST_USE_OWN_FLAGFILE_FLAG_ 1 | |||
#endif // !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) | #endif // !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) | |||
#if !defined(GTEST_DECLARE_bool_) | #if !defined(GTEST_DECLARE_bool_) | |||
# define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver | # define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver | |||
// Macros for declaring flags. | // Macros for declaring flags. | |||
# define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name) | # define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name) | |||
# define GTEST_DECLARE_int32_(name) \ | # define GTEST_DECLARE_int32_(name) \ | |||
GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name) | GTEST_API_ extern std::int32_t GTEST_FLAG(name) | |||
# define GTEST_DECLARE_string_(name) \ | # define GTEST_DECLARE_string_(name) \ | |||
GTEST_API_ extern ::std::string GTEST_FLAG(name) | GTEST_API_ extern ::std::string GTEST_FLAG(name) | |||
// Macros for defining flags. | // Macros for defining flags. | |||
# define GTEST_DEFINE_bool_(name, default_val, doc) \ | # define GTEST_DEFINE_bool_(name, default_val, doc) \ | |||
GTEST_API_ bool GTEST_FLAG(name) = (default_val) | GTEST_API_ bool GTEST_FLAG(name) = (default_val) | |||
# define GTEST_DEFINE_int32_(name, default_val, doc) \ | # define GTEST_DEFINE_int32_(name, default_val, doc) \ | |||
GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val) | GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val) | |||
# define GTEST_DEFINE_string_(name, default_val, doc) \ | # define GTEST_DEFINE_string_(name, default_val, doc) \ | |||
GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val) | GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val) | |||
#endif // !defined(GTEST_DECLARE_bool_) | #endif // !defined(GTEST_DECLARE_bool_) | |||
// Thread annotations | // Thread annotations | |||
#if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) | #if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) | |||
# define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) | # define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) | |||
# define GTEST_LOCK_EXCLUDED_(locks) | # define GTEST_LOCK_EXCLUDED_(locks) | |||
#endif // !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) | #endif // !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) | |||
// Parses 'str' for a 32-bit signed integer. If successful, writes the result | // Parses 'str' for a 32-bit signed integer. If successful, writes the result | |||
// to *value and returns true; otherwise leaves *value unchanged and returns | // to *value and returns true; otherwise leaves *value unchanged and returns | |||
// false. | // false. | |||
bool ParseInt32(const Message& src_text, const char* str, Int32* value); | GTEST_API_ bool ParseInt32(const Message& src_text, const char* str, | |||
int32_t* value); | ||||
// Parses a bool/Int32/string from the environment variable | // Parses a bool/int32_t/string from the environment variable | |||
// corresponding to the given Google Test flag. | // corresponding to the given Google Test flag. | |||
bool BoolFromGTestEnv(const char* flag, bool default_val); | bool BoolFromGTestEnv(const char* flag, bool default_val); | |||
GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val); | GTEST_API_ int32_t Int32FromGTestEnv(const char* flag, int32_t default_val); | |||
std::string OutputFlagAlsoCheckEnvVar(); | std::string OutputFlagAlsoCheckEnvVar(); | |||
const char* StringFromGTestEnv(const char* flag, const char* default_val); | const char* StringFromGTestEnv(const char* flag, const char* default_val); | |||
} // namespace internal | } // namespace internal | |||
} // namespace testing | } // namespace testing | |||
#if !defined(GTEST_INTERNAL_DEPRECATED) | #if !defined(GTEST_INTERNAL_DEPRECATED) | |||
// Internal Macro to mark an API deprecated, for googletest usage only | // Internal Macro to mark an API deprecated, for googletest usage only | |||
// Usage: class GTEST_INTERNAL_DEPRECATED(message) MyClass or | // Usage: class GTEST_INTERNAL_DEPRECATED(message) MyClass or | |||
skipping to change at line 2229 | skipping to change at line 2272 | |||
#if defined(_MSC_VER) | #if defined(_MSC_VER) | |||
#define GTEST_INTERNAL_DEPRECATED(message) __declspec(deprecated(message)) | #define GTEST_INTERNAL_DEPRECATED(message) __declspec(deprecated(message)) | |||
#elif defined(__GNUC__) | #elif defined(__GNUC__) | |||
#define GTEST_INTERNAL_DEPRECATED(message) __attribute__((deprecated(message))) | #define GTEST_INTERNAL_DEPRECATED(message) __attribute__((deprecated(message))) | |||
#else | #else | |||
#define GTEST_INTERNAL_DEPRECATED(message) | #define GTEST_INTERNAL_DEPRECATED(message) | |||
#endif | #endif | |||
#endif // !defined(GTEST_INTERNAL_DEPRECATED) | #endif // !defined(GTEST_INTERNAL_DEPRECATED) | |||
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ | #if GTEST_HAS_ABSL | |||
// Always use absl::any for UniversalPrinter<> specializations if googletest | ||||
// is built with absl support. | ||||
#define GTEST_INTERNAL_HAS_ANY 1 | ||||
#include "absl/types/any.h" | ||||
namespace testing { | ||||
namespace internal { | ||||
using Any = ::absl::any; | ||||
} // namespace internal | ||||
} // namespace testing | ||||
#else | ||||
#ifdef __has_include | ||||
#if __has_include(<any>) && __cplusplus >= 201703L | ||||
// Otherwise for C++17 and higher use std::any for UniversalPrinter<> | ||||
// specializations. | ||||
#define GTEST_INTERNAL_HAS_ANY 1 | ||||
#include <any> | ||||
namespace testing { | ||||
namespace internal { | ||||
using Any = ::std::any; | ||||
} // namespace internal | ||||
} // namespace testing | ||||
// The case where absl is configured NOT to alias std::any is not | ||||
// supported. | ||||
#endif // __has_include(<any>) && __cplusplus >= 201703L | ||||
#endif // __has_include | ||||
#endif // GTEST_HAS_ABSL | ||||
#if GTEST_HAS_ABSL | ||||
// Always use absl::optional for UniversalPrinter<> specializations if | ||||
// googletest is built with absl support. | ||||
#define GTEST_INTERNAL_HAS_OPTIONAL 1 | ||||
#include "absl/types/optional.h" | ||||
namespace testing { | ||||
namespace internal { | ||||
template <typename T> | ||||
using Optional = ::absl::optional<T>; | ||||
} // namespace internal | ||||
} // namespace testing | ||||
#else | ||||
#ifdef __has_include | ||||
#if __has_include(<optional>) && __cplusplus >= 201703L | ||||
// Otherwise for C++17 and higher use std::optional for UniversalPrinter<> | ||||
// specializations. | ||||
#define GTEST_INTERNAL_HAS_OPTIONAL 1 | ||||
#include <optional> | ||||
namespace testing { | ||||
namespace internal { | ||||
template <typename T> | ||||
using Optional = ::std::optional<T>; | ||||
} // namespace internal | ||||
} // namespace testing | ||||
// The case where absl is configured NOT to alias std::optional is not | ||||
// supported. | ||||
#endif // __has_include(<optional>) && __cplusplus >= 201703L | ||||
#endif // __has_include | ||||
#endif // GTEST_HAS_ABSL | ||||
#if GTEST_HAS_ABSL | ||||
// Always use absl::string_view for Matcher<> specializations if googletest | ||||
// is built with absl support. | ||||
# define GTEST_INTERNAL_HAS_STRING_VIEW 1 | ||||
#include "absl/strings/string_view.h" | ||||
namespace testing { | ||||
namespace internal { | ||||
using StringView = ::absl::string_view; | ||||
} // namespace internal | ||||
} // namespace testing | ||||
#else | ||||
# ifdef __has_include | ||||
# if __has_include(<string_view>) && __cplusplus >= 201703L | ||||
// Otherwise for C++17 and higher use std::string_view for Matcher<> | ||||
// specializations. | ||||
# define GTEST_INTERNAL_HAS_STRING_VIEW 1 | ||||
#include <string_view> | ||||
namespace testing { | ||||
namespace internal { | ||||
using StringView = ::std::string_view; | ||||
} // namespace internal | ||||
} // namespace testing | ||||
// The case where absl is configured NOT to alias std::string_view is not | ||||
// supported. | ||||
# endif // __has_include(<string_view>) && __cplusplus >= 201703L | ||||
# endif // __has_include | ||||
#endif // GTEST_HAS_ABSL | ||||
#if GTEST_HAS_ABSL | ||||
// Always use absl::variant for UniversalPrinter<> specializations if googletest | ||||
// is built with absl support. | ||||
#define GTEST_INTERNAL_HAS_VARIANT 1 | ||||
#include "absl/types/variant.h" | ||||
namespace testing { | ||||
namespace internal { | ||||
template <typename... T> | ||||
using Variant = ::absl::variant<T...>; | ||||
} // namespace internal | ||||
} // namespace testing | ||||
#else | ||||
#ifdef __has_include | ||||
#if __has_include(<variant>) && __cplusplus >= 201703L | ||||
// Otherwise for C++17 and higher use std::variant for UniversalPrinter<> | ||||
// specializations. | ||||
#define GTEST_INTERNAL_HAS_VARIANT 1 | ||||
#include <variant> | ||||
namespace testing { | ||||
namespace internal { | ||||
template <typename... T> | ||||
using Variant = ::std::variant<T...>; | ||||
} // namespace internal | ||||
} // namespace testing | ||||
// The case where absl is configured NOT to alias std::variant is not supported. | ||||
#endif // __has_include(<variant>) && __cplusplus >= 201703L | ||||
#endif // __has_include | ||||
#endif // GTEST_HAS_ABSL | ||||
#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ | ||||
End of changes. 51 change blocks. | ||||
88 lines changed or deleted | 131 lines changed or added |