|
|
|
@ -198,21 +198,8 @@
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
// Always defined to 0 or 1.
|
|
|
|
|
|
|
|
// GTEST_INTERNAL_HAS_OPTIONAL - for enabling UniversalPrinter<std::optional>
|
|
|
|
|
|
|
|
// or
|
|
|
|
|
|
|
|
// UniversalPrinter<absl::optional>
|
|
|
|
|
|
|
|
// specializations. Always defined to 0 or 1.
|
|
|
|
|
|
|
|
// GTEST_INTERNAL_HAS_STD_SPAN - for enabling UniversalPrinter<std::span>
|
|
|
|
// GTEST_INTERNAL_HAS_STD_SPAN - for enabling UniversalPrinter<std::span>
|
|
|
|
// specializations. Always defined to 0 or 1
|
|
|
|
// specializations. Always defined to 0 or 1
|
|
|
|
// GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher<std::string_view> or
|
|
|
|
|
|
|
|
// Matcher<absl::string_view>
|
|
|
|
|
|
|
|
// specializations. Always defined to 0 or 1.
|
|
|
|
|
|
|
|
// GTEST_INTERNAL_HAS_VARIANT - for enabling UniversalPrinter<std::variant> or
|
|
|
|
|
|
|
|
// UniversalPrinter<absl::variant>
|
|
|
|
|
|
|
|
// specializations. Always defined to 0 or 1.
|
|
|
|
|
|
|
|
// GTEST_USE_OWN_FLAGFILE_FLAG_ - Always defined to 0 or 1.
|
|
|
|
// GTEST_USE_OWN_FLAGFILE_FLAG_ - Always defined to 0 or 1.
|
|
|
|
// GTEST_HAS_CXXABI_H_ - Always defined to 0 or 1.
|
|
|
|
// GTEST_HAS_CXXABI_H_ - Always defined to 0 or 1.
|
|
|
|
// GTEST_CAN_STREAM_RESULTS_ - Always defined to 0 or 1.
|
|
|
|
// GTEST_CAN_STREAM_RESULTS_ - Always defined to 0 or 1.
|
|
|
|
@ -306,9 +293,10 @@
|
|
|
|
#include <limits>
|
|
|
|
#include <limits>
|
|
|
|
#include <locale>
|
|
|
|
#include <locale>
|
|
|
|
#include <memory>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
// #include <mutex> // Guarded by GTEST_IS_THREADSAFE below
|
|
|
|
#include <ostream>
|
|
|
|
#include <ostream>
|
|
|
|
#include <string>
|
|
|
|
#include <string>
|
|
|
|
// #include <mutex> // Guarded by GTEST_IS_THREADSAFE below
|
|
|
|
#include <string_view>
|
|
|
|
#include <tuple>
|
|
|
|
#include <tuple>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
@ -376,18 +364,24 @@
|
|
|
|
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
|
|
|
|
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Clang on Windows does not understand MSVC's pragma warning.
|
|
|
|
// Pragmas to disable function deprecation warnings.
|
|
|
|
// We need clang-specific way to disable function deprecation warning.
|
|
|
|
#if defined(__clang__)
|
|
|
|
#ifdef __clang__
|
|
|
|
#define GTEST_DISABLE_DEPRECATED_PUSH_() \
|
|
|
|
#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \
|
|
|
|
|
|
|
|
_Pragma("clang diagnostic push") \
|
|
|
|
_Pragma("clang diagnostic push") \
|
|
|
|
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
|
|
|
|
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \
|
|
|
|
_Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"")
|
|
|
|
_Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"")
|
|
|
|
#define GTEST_DISABLE_MSC_DEPRECATED_POP_() _Pragma("clang diagnostic pop")
|
|
|
|
#define GTEST_DISABLE_DEPRECATED_POP_() _Pragma("clang diagnostic pop")
|
|
|
|
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
|
|
|
|
#define GTEST_DISABLE_DEPRECATED_PUSH_() \
|
|
|
|
|
|
|
|
_Pragma("GCC diagnostic push") \
|
|
|
|
|
|
|
|
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
|
|
|
|
|
|
|
|
#define GTEST_DISABLE_DEPRECATED_POP_() _Pragma("GCC diagnostic pop")
|
|
|
|
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
|
|
|
|
#define GTEST_DISABLE_DEPRECATED_PUSH_() GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)
|
|
|
|
|
|
|
|
#define GTEST_DISABLE_DEPRECATED_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \
|
|
|
|
#define GTEST_DISABLE_DEPRECATED_PUSH_()
|
|
|
|
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996)
|
|
|
|
#define GTEST_DISABLE_DEPRECATED_POP_()
|
|
|
|
#define GTEST_DISABLE_MSC_DEPRECATED_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_()
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Brings in definitions for functions used in the testing::internal::posix
|
|
|
|
// Brings in definitions for functions used in the testing::internal::posix
|
|
|
|
@ -606,7 +600,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
|
|
|
defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \
|
|
|
|
defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \
|
|
|
|
defined(GTEST_OS_OPENBSD) || defined(GTEST_OS_HAIKU) || \
|
|
|
|
defined(GTEST_OS_OPENBSD) || defined(GTEST_OS_HAIKU) || \
|
|
|
|
defined(GTEST_OS_GNU_HURD) || defined(GTEST_OS_SOLARIS) || \
|
|
|
|
defined(GTEST_OS_GNU_HURD) || defined(GTEST_OS_SOLARIS) || \
|
|
|
|
defined(GTEST_OS_AIX) || defined(GTEST_OS_ZOS))
|
|
|
|
defined(GTEST_OS_AIX) || defined(GTEST_OS_ZOS) || \
|
|
|
|
|
|
|
|
(defined(GTEST_OS_EMSCRIPTEN) && defined(__EMSCRIPTEN_PTHREADS__)))
|
|
|
|
#define GTEST_HAS_PTHREAD 1
|
|
|
|
#define GTEST_HAS_PTHREAD 1
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#define GTEST_HAS_PTHREAD 0
|
|
|
|
#define GTEST_HAS_PTHREAD 0
|
|
|
|
@ -677,12 +672,22 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
|
|
|
defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \
|
|
|
|
defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \
|
|
|
|
defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \
|
|
|
|
defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \
|
|
|
|
defined(GTEST_OS_HAIKU) || defined(GTEST_OS_GNU_HURD))
|
|
|
|
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
|
|
|
|
#endif // GTEST_HAS_FILE_SYSTEM
|
|
|
|
#endif // GTEST_HAS_FILE_SYSTEM
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Determines whether the Premature Exit file can be created.
|
|
|
|
|
|
|
|
// Created by default when Death tests are supported, but other platforms can
|
|
|
|
|
|
|
|
// use the Premature exit file without Death test support (e.g. for detecting
|
|
|
|
|
|
|
|
// crashes).
|
|
|
|
|
|
|
|
#if GTEST_HAS_DEATH_TEST || \
|
|
|
|
|
|
|
|
(defined(GTEST_OS_EMSCRIPTEN) && GTEST_HAS_FILE_SYSTEM)
|
|
|
|
|
|
|
|
#define GTEST_INTERNAL_HAS_PREMATURE_EXIT_FILE 1
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Determines whether to support type-driven tests.
|
|
|
|
// Determines whether to support type-driven tests.
|
|
|
|
|
|
|
|
|
|
|
|
// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
|
|
|
|
// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
|
|
|
|
@ -835,11 +840,13 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
|
|
|
|
#ifndef GTEST_API_
|
|
|
|
#ifndef GTEST_API_
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#if defined(GTEST_LINKED_AS_SHARED_LIBRARY) && GTEST_LINKED_AS_SHARED_LIBRARY
|
|
|
|
#if defined(GTEST_CREATE_SHARED_LIBRARY) && GTEST_CREATE_SHARED_LIBRARY
|
|
|
|
#define GTEST_API_ __declspec(dllimport)
|
|
|
|
|
|
|
|
#elif defined(GTEST_CREATE_SHARED_LIBRARY) && GTEST_CREATE_SHARED_LIBRARY
|
|
|
|
|
|
|
|
#define GTEST_API_ __declspec(dllexport)
|
|
|
|
#define GTEST_API_ __declspec(dllexport)
|
|
|
|
|
|
|
|
#elif defined(GTEST_LINKED_AS_SHARED_LIBRARY) && GTEST_LINKED_AS_SHARED_LIBRARY
|
|
|
|
|
|
|
|
#define GTEST_API_ __declspec(dllimport)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#elif GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(gnu::visibility)
|
|
|
|
|
|
|
|
#define GTEST_API_ [[gnu::visibility("default")]]
|
|
|
|
#elif GTEST_HAVE_ATTRIBUTE_(visibility)
|
|
|
|
#elif GTEST_HAVE_ATTRIBUTE_(visibility)
|
|
|
|
#define GTEST_API_ __attribute__((visibility("default")))
|
|
|
|
#define GTEST_API_ __attribute__((visibility("default")))
|
|
|
|
#endif // _MSC_VER
|
|
|
|
#endif // _MSC_VER
|
|
|
|
@ -930,7 +937,7 @@ namespace internal {
|
|
|
|
// A secret type that Google Test users don't know about. It has no
|
|
|
|
// A secret type that Google Test users don't know about. It has no
|
|
|
|
// accessible constructors on purpose. Therefore it's impossible to create a
|
|
|
|
// accessible constructors on purpose. Therefore it's impossible to create a
|
|
|
|
// Secret object, which is what we want.
|
|
|
|
// Secret object, which is what we want.
|
|
|
|
class Secret {
|
|
|
|
class [[nodiscard]] Secret {
|
|
|
|
Secret(const Secret&) = delete;
|
|
|
|
Secret(const Secret&) = delete;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@ -943,21 +950,21 @@ GTEST_API_ bool IsTrue(bool condition);
|
|
|
|
#ifdef GTEST_USES_RE2
|
|
|
|
#ifdef GTEST_USES_RE2
|
|
|
|
|
|
|
|
|
|
|
|
// This is almost `using RE = ::RE2`, except it is copy-constructible, and it
|
|
|
|
// This is almost `using RE = ::RE2`, except it is copy-constructible, and it
|
|
|
|
// needs to disambiguate the `std::string`, `absl::string_view`, and `const
|
|
|
|
// needs to disambiguate the `std::string`, `std::string_view`, and `const
|
|
|
|
// char*` constructors.
|
|
|
|
// char*` constructors.
|
|
|
|
class GTEST_API_ RE {
|
|
|
|
class GTEST_API_ [[nodiscard]] RE {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
RE(absl::string_view regex) : regex_(regex) {} // NOLINT
|
|
|
|
RE(std::string_view regex) : regex_(regex) {} // NOLINT
|
|
|
|
RE(const char* regex) : RE(absl::string_view(regex)) {} // NOLINT
|
|
|
|
RE(const char* regex) : RE(std::string_view(regex)) {} // NOLINT
|
|
|
|
RE(const std::string& regex) : RE(absl::string_view(regex)) {} // NOLINT
|
|
|
|
RE(const std::string& regex) : RE(std::string_view(regex)) {} // NOLINT
|
|
|
|
RE(const RE& other) : RE(other.pattern()) {}
|
|
|
|
RE(const RE& other) : RE(other.pattern()) {}
|
|
|
|
|
|
|
|
|
|
|
|
const std::string& pattern() const { return regex_.pattern(); }
|
|
|
|
const std::string& pattern() const { return regex_.pattern(); }
|
|
|
|
|
|
|
|
|
|
|
|
static bool FullMatch(absl::string_view str, const RE& re) {
|
|
|
|
static bool FullMatch(std::string_view str, const RE& re) {
|
|
|
|
return RE2::FullMatch(str, re.regex_);
|
|
|
|
return RE2::FullMatch(str, re.regex_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static bool PartialMatch(absl::string_view str, const RE& re) {
|
|
|
|
static bool PartialMatch(std::string_view str, const RE& re) {
|
|
|
|
return RE2::PartialMatch(str, re.regex_);
|
|
|
|
return RE2::PartialMatch(str, re.regex_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -971,7 +978,7 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
|
|
|
|
|
|
|
|
|
|
|
// A simple C++ wrapper for <regex.h>. It uses the POSIX Extended
|
|
|
|
// A simple C++ wrapper for <regex.h>. It uses the POSIX Extended
|
|
|
|
// Regular Expression syntax.
|
|
|
|
// Regular Expression syntax.
|
|
|
|
class GTEST_API_ RE {
|
|
|
|
class GTEST_API_ [[nodiscard]] RE {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
// A copy constructor is required by the Standard to initialize object
|
|
|
|
// A copy constructor is required by the Standard to initialize object
|
|
|
|
// references from r-values.
|
|
|
|
// references from r-values.
|
|
|
|
@ -1040,7 +1047,7 @@ enum GTestLogSeverity { GTEST_INFO, GTEST_WARNING, GTEST_ERROR, GTEST_FATAL };
|
|
|
|
// Formats log entry severity, provides a stream object for streaming the
|
|
|
|
// Formats log entry severity, provides a stream object for streaming the
|
|
|
|
// log message, and terminates the message with a newline when going out of
|
|
|
|
// log message, and terminates the message with a newline when going out of
|
|
|
|
// scope.
|
|
|
|
// scope.
|
|
|
|
class GTEST_API_ GTestLog {
|
|
|
|
class GTEST_API_ [[nodiscard]] GTestLog {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
GTestLog(GTestLogSeverity severity, const char* file, int line);
|
|
|
|
GTestLog(GTestLogSeverity severity, const char* file, int line);
|
|
|
|
|
|
|
|
|
|
|
|
@ -1203,7 +1210,7 @@ void ClearInjectableArgvs();
|
|
|
|
#ifdef 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_ [[nodiscard]] AutoHandle {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
// Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to
|
|
|
|
// Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to
|
|
|
|
// avoid including <windows.h> in this header file. Including <windows.h> is
|
|
|
|
// avoid including <windows.h> in this header file. Including <windows.h> is
|
|
|
|
@ -1237,9 +1244,6 @@ class GTEST_API_ AutoHandle {
|
|
|
|
// Nothing to do here.
|
|
|
|
// Nothing to do here.
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
|
|
|
|
|
|
|
/* class A needs to have dll-interface to be used by clients of class B */)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Allows a controller thread to pause execution of newly created
|
|
|
|
// Allows a controller thread to pause execution of newly created
|
|
|
|
// threads until notified. Instances of this class must be created
|
|
|
|
// threads until notified. Instances of this class must be created
|
|
|
|
// and destroyed in the controller thread.
|
|
|
|
// and destroyed in the controller thread.
|
|
|
|
@ -1247,7 +1251,40 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
|
|
|
// This class is only for testing Google Test's own constructs. Do not
|
|
|
|
// This class is only for testing Google Test's own constructs. Do not
|
|
|
|
// use it in user tests, either directly or indirectly.
|
|
|
|
// use it in user tests, either directly or indirectly.
|
|
|
|
// TODO(b/203539622): Replace unconditionally with absl::Notification.
|
|
|
|
// TODO(b/203539622): Replace unconditionally with absl::Notification.
|
|
|
|
class GTEST_API_ Notification {
|
|
|
|
#ifdef GTEST_OS_WINDOWS_MINGW
|
|
|
|
|
|
|
|
// GCC version < 13 with the win32 thread model does not provide std::mutex and
|
|
|
|
|
|
|
|
// std::condition_variable in the <mutex> and <condition_variable> headers. So
|
|
|
|
|
|
|
|
// we implement the Notification class using a Windows manual-reset event. See
|
|
|
|
|
|
|
|
// https://gcc.gnu.org/gcc-13/changes.html#windows.
|
|
|
|
|
|
|
|
class GTEST_API_ [[nodiscard]] Notification {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Notification();
|
|
|
|
|
|
|
|
Notification(const Notification&) = delete;
|
|
|
|
|
|
|
|
Notification& operator=(const Notification&) = delete;
|
|
|
|
|
|
|
|
~Notification();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Notifies all threads created with this notification to start. Must
|
|
|
|
|
|
|
|
// be called from the controller thread.
|
|
|
|
|
|
|
|
void Notify();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Blocks until the controller thread notifies. Must be called from a test
|
|
|
|
|
|
|
|
// thread.
|
|
|
|
|
|
|
|
void WaitForNotification();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to
|
|
|
|
|
|
|
|
// avoid including <windows.h> in this header file. Including <windows.h> is
|
|
|
|
|
|
|
|
// undesirable because it defines a lot of symbols and macros that tend to
|
|
|
|
|
|
|
|
// conflict with client code. This assumption is verified by
|
|
|
|
|
|
|
|
// WindowsTypesTest.HANDLEIsVoidStar.
|
|
|
|
|
|
|
|
typedef void* Handle;
|
|
|
|
|
|
|
|
Handle event_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
|
|
|
|
|
|
|
|
/* class A needs to have dll-interface to be used by clients of class B */)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GTEST_API_ [[nodiscard]] Notification {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
Notification() : notified_(false) {}
|
|
|
|
Notification() : notified_(false) {}
|
|
|
|
Notification(const Notification&) = delete;
|
|
|
|
Notification(const Notification&) = delete;
|
|
|
|
@ -1274,6 +1311,7 @@ class GTEST_API_ Notification {
|
|
|
|
bool notified_;
|
|
|
|
bool notified_;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
|
|
|
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
|
|
|
|
|
|
|
#endif // GTEST_OS_WINDOWS_MINGW
|
|
|
|
#endif // GTEST_HAS_NOTIFICATION_
|
|
|
|
#endif // GTEST_HAS_NOTIFICATION_
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
@ -1286,7 +1324,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
|
|
|
|
// in order to call its Run(). Introducing ThreadWithParamBase as a
|
|
|
|
// in order to call its Run(). Introducing ThreadWithParamBase as a
|
|
|
|
// non-templated base class for ThreadWithParam allows us to bypass this
|
|
|
|
// non-templated base class for ThreadWithParam allows us to bypass this
|
|
|
|
// problem.
|
|
|
|
// problem.
|
|
|
|
class ThreadWithParamBase {
|
|
|
|
class [[nodiscard]] ThreadWithParamBase {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
virtual ~ThreadWithParamBase() = default;
|
|
|
|
virtual ~ThreadWithParamBase() = default;
|
|
|
|
virtual void Run() = 0;
|
|
|
|
virtual void Run() = 0;
|
|
|
|
@ -1316,7 +1354,7 @@ extern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
|
|
|
|
// These classes are only for testing Google Test's own constructs. Do
|
|
|
|
// These classes are only for testing Google Test's own constructs. Do
|
|
|
|
// not use them in user tests, either directly or indirectly.
|
|
|
|
// not use them in user tests, either directly or indirectly.
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
class ThreadWithParam : public ThreadWithParamBase {
|
|
|
|
class [[nodiscard]] ThreadWithParam : public ThreadWithParamBase {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
typedef void UserThreadFunc(T);
|
|
|
|
typedef void UserThreadFunc(T);
|
|
|
|
|
|
|
|
|
|
|
|
@ -1382,7 +1420,7 @@ class ThreadWithParam : public ThreadWithParamBase {
|
|
|
|
// GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
|
|
|
|
// GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// (A non-static Mutex is defined/declared in the usual way).
|
|
|
|
// (A non-static Mutex is defined/declared in the usual way).
|
|
|
|
class GTEST_API_ Mutex {
|
|
|
|
class GTEST_API_ [[nodiscard]] Mutex {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
enum MutexType { kStatic = 0, kDynamic = 1 };
|
|
|
|
enum MutexType { kStatic = 0, kDynamic = 1 };
|
|
|
|
// We rely on kStaticMutex being 0 as it is to what the linker initializes
|
|
|
|
// We rely on kStaticMutex being 0 as it is to what the linker initializes
|
|
|
|
@ -1398,9 +1436,9 @@ class GTEST_API_ Mutex {
|
|
|
|
Mutex();
|
|
|
|
Mutex();
|
|
|
|
~Mutex();
|
|
|
|
~Mutex();
|
|
|
|
|
|
|
|
|
|
|
|
void Lock();
|
|
|
|
void lock();
|
|
|
|
|
|
|
|
|
|
|
|
void Unlock();
|
|
|
|
void unlock();
|
|
|
|
|
|
|
|
|
|
|
|
// Does nothing if the current thread holds the mutex. Otherwise, crashes
|
|
|
|
// Does nothing if the current thread holds the mutex. Otherwise, crashes
|
|
|
|
// with high probability.
|
|
|
|
// with high probability.
|
|
|
|
@ -1435,14 +1473,13 @@ class GTEST_API_ Mutex {
|
|
|
|
// platforms. That macro is used as a defensive measure to prevent against
|
|
|
|
// platforms. That macro is used as a defensive measure to prevent against
|
|
|
|
// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
|
|
|
|
// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
|
|
|
|
// "MutexLock l(&mu)". Hence the typedef trick below.
|
|
|
|
// "MutexLock l(&mu)". Hence the typedef trick below.
|
|
|
|
class GTestMutexLock {
|
|
|
|
class [[nodiscard]] GTestMutexLock {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit GTestMutexLock(Mutex* mutex) : mutex_(mutex) { mutex_->Lock(); }
|
|
|
|
explicit GTestMutexLock(Mutex& mutex) : mutex_(mutex) { mutex_.lock(); }
|
|
|
|
|
|
|
|
~GTestMutexLock() { mutex_.unlock(); }
|
|
|
|
~GTestMutexLock() { mutex_->Unlock(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
Mutex* const mutex_;
|
|
|
|
Mutex& mutex_;
|
|
|
|
|
|
|
|
|
|
|
|
GTestMutexLock(const GTestMutexLock&) = delete;
|
|
|
|
GTestMutexLock(const GTestMutexLock&) = delete;
|
|
|
|
GTestMutexLock& operator=(const GTestMutexLock&) = delete;
|
|
|
|
GTestMutexLock& operator=(const GTestMutexLock&) = delete;
|
|
|
|
@ -1452,14 +1489,14 @@ typedef GTestMutexLock MutexLock;
|
|
|
|
|
|
|
|
|
|
|
|
// Base class for ValueHolder<T>. Allows a caller to hold and delete a value
|
|
|
|
// Base class for ValueHolder<T>. Allows a caller to hold and delete a value
|
|
|
|
// without knowing its type.
|
|
|
|
// without knowing its type.
|
|
|
|
class ThreadLocalValueHolderBase {
|
|
|
|
class [[nodiscard]] ThreadLocalValueHolderBase {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
virtual ~ThreadLocalValueHolderBase() {}
|
|
|
|
virtual ~ThreadLocalValueHolderBase() = default;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Provides a way for a thread to send notifications to a ThreadLocal
|
|
|
|
// Provides a way for a thread to send notifications to a ThreadLocal
|
|
|
|
// regardless of its parameter type.
|
|
|
|
// regardless of its parameter type.
|
|
|
|
class ThreadLocalBase {
|
|
|
|
class [[nodiscard]] ThreadLocalBase {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
// Creates a new ValueHolder<T> object holding a default value passed to
|
|
|
|
// Creates a new ValueHolder<T> object holding a default value passed to
|
|
|
|
// this ThreadLocal<T>'s constructor and returns it. It is the caller's
|
|
|
|
// this ThreadLocal<T>'s constructor and returns it. It is the caller's
|
|
|
|
@ -1468,8 +1505,8 @@ class ThreadLocalBase {
|
|
|
|
virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const = 0;
|
|
|
|
virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const = 0;
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
protected:
|
|
|
|
ThreadLocalBase() {}
|
|
|
|
ThreadLocalBase() = default;
|
|
|
|
virtual ~ThreadLocalBase() {}
|
|
|
|
virtual ~ThreadLocalBase() = default;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
ThreadLocalBase(const ThreadLocalBase&) = delete;
|
|
|
|
ThreadLocalBase(const ThreadLocalBase&) = delete;
|
|
|
|
@ -1479,7 +1516,7 @@ class ThreadLocalBase {
|
|
|
|
// Maps a thread to a set of ThreadLocals that have values instantiated on that
|
|
|
|
// Maps a thread to a set of ThreadLocals that have values instantiated on that
|
|
|
|
// thread and notifies them when the thread exits. A ThreadLocal instance is
|
|
|
|
// thread and notifies them when the thread exits. A ThreadLocal instance is
|
|
|
|
// expected to persist until all threads it has values on have terminated.
|
|
|
|
// expected to persist until all threads it has values on have terminated.
|
|
|
|
class GTEST_API_ ThreadLocalRegistry {
|
|
|
|
class GTEST_API_ [[nodiscard]] ThreadLocalRegistry {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
// Registers thread_local_instance as having value on the current thread.
|
|
|
|
// Registers thread_local_instance as having value on the current thread.
|
|
|
|
// Returns a value that can be used to identify the thread from other threads.
|
|
|
|
// Returns a value that can be used to identify the thread from other threads.
|
|
|
|
@ -1491,14 +1528,14 @@ class GTEST_API_ ThreadLocalRegistry {
|
|
|
|
const ThreadLocalBase* thread_local_instance);
|
|
|
|
const ThreadLocalBase* thread_local_instance);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class GTEST_API_ ThreadWithParamBase {
|
|
|
|
class GTEST_API_ [[nodiscard]] ThreadWithParamBase {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
void Join();
|
|
|
|
void Join();
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
protected:
|
|
|
|
class Runnable {
|
|
|
|
class Runnable {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
virtual ~Runnable() {}
|
|
|
|
virtual ~Runnable() = default;
|
|
|
|
virtual void Run() = 0;
|
|
|
|
virtual void Run() = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@ -1511,20 +1548,20 @@ class GTEST_API_ ThreadWithParamBase {
|
|
|
|
|
|
|
|
|
|
|
|
// Helper class for testing Google Test's multi-threading constructs.
|
|
|
|
// Helper class for testing Google Test's multi-threading constructs.
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
class ThreadWithParam : public ThreadWithParamBase {
|
|
|
|
class [[nodiscard]] ThreadWithParam : public ThreadWithParamBase {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
typedef void UserThreadFunc(T);
|
|
|
|
typedef void UserThreadFunc(T);
|
|
|
|
|
|
|
|
|
|
|
|
ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
|
|
|
|
ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start)
|
|
|
|
: ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) {}
|
|
|
|
: ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) {}
|
|
|
|
virtual ~ThreadWithParam() {}
|
|
|
|
~ThreadWithParam() override = default;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
class RunnableImpl : public Runnable {
|
|
|
|
class RunnableImpl : public Runnable {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
RunnableImpl(UserThreadFunc* func, T param) : func_(func), param_(param) {}
|
|
|
|
RunnableImpl(UserThreadFunc* func, T param) : func_(func), param_(param) {}
|
|
|
|
virtual ~RunnableImpl() {}
|
|
|
|
~RunnableImpl() override = default;
|
|
|
|
virtual void Run() { func_(param_); }
|
|
|
|
void Run() override { func_(param_); }
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
UserThreadFunc* const func_;
|
|
|
|
UserThreadFunc* const func_;
|
|
|
|
@ -1566,7 +1603,7 @@ class ThreadWithParam : public ThreadWithParamBase {
|
|
|
|
// object managed by Google Test will be leaked as long as all threads
|
|
|
|
// object managed by Google Test will be leaked as long as all threads
|
|
|
|
// using Google Test have exited when main() returns.
|
|
|
|
// using Google Test have exited when main() returns.
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
class ThreadLocal : public ThreadLocalBase {
|
|
|
|
class [[nodiscard]] ThreadLocal : public ThreadLocalBase {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
ThreadLocal() : default_factory_(new DefaultValueHolderFactory()) {}
|
|
|
|
ThreadLocal() : default_factory_(new DefaultValueHolderFactory()) {}
|
|
|
|
explicit ThreadLocal(const T& value)
|
|
|
|
explicit ThreadLocal(const T& value)
|
|
|
|
@ -1607,8 +1644,8 @@ class ThreadLocal : public ThreadLocalBase {
|
|
|
|
|
|
|
|
|
|
|
|
class ValueHolderFactory {
|
|
|
|
class ValueHolderFactory {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
ValueHolderFactory() {}
|
|
|
|
ValueHolderFactory() = default;
|
|
|
|
virtual ~ValueHolderFactory() {}
|
|
|
|
virtual ~ValueHolderFactory() = default;
|
|
|
|
virtual ValueHolder* MakeNewHolder() const = 0;
|
|
|
|
virtual ValueHolder* MakeNewHolder() const = 0;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
@ -1618,7 +1655,7 @@ class ThreadLocal : public ThreadLocalBase {
|
|
|
|
|
|
|
|
|
|
|
|
class DefaultValueHolderFactory : public ValueHolderFactory {
|
|
|
|
class DefaultValueHolderFactory : public ValueHolderFactory {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
DefaultValueHolderFactory() {}
|
|
|
|
DefaultValueHolderFactory() = default;
|
|
|
|
ValueHolder* MakeNewHolder() const override { return new ValueHolder(); }
|
|
|
|
ValueHolder* MakeNewHolder() const override { return new ValueHolder(); }
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
@ -1651,17 +1688,17 @@ class ThreadLocal : public ThreadLocalBase {
|
|
|
|
#elif GTEST_HAS_PTHREAD
|
|
|
|
#elif GTEST_HAS_PTHREAD
|
|
|
|
|
|
|
|
|
|
|
|
// MutexBase and Mutex implement mutex on pthreads-based platforms.
|
|
|
|
// MutexBase and Mutex implement mutex on pthreads-based platforms.
|
|
|
|
class MutexBase {
|
|
|
|
class [[nodiscard]] MutexBase {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
// Acquires this mutex.
|
|
|
|
// Acquires this mutex.
|
|
|
|
void Lock() {
|
|
|
|
void lock() {
|
|
|
|
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
|
|
|
|
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
|
|
|
|
owner_ = pthread_self();
|
|
|
|
owner_ = pthread_self();
|
|
|
|
has_owner_ = true;
|
|
|
|
has_owner_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Releases this mutex.
|
|
|
|
// Releases this mutex.
|
|
|
|
void Unlock() {
|
|
|
|
void unlock() {
|
|
|
|
// Since the lock is being released the owner_ field should no longer be
|
|
|
|
// Since the lock is being released the owner_ field should no longer be
|
|
|
|
// considered valid. We don't protect writing to has_owner_ here, as it's
|
|
|
|
// considered valid. We don't protect writing to has_owner_ here, as it's
|
|
|
|
// the caller's responsibility to ensure that the current thread holds the
|
|
|
|
// the caller's responsibility to ensure that the current thread holds the
|
|
|
|
@ -1709,7 +1746,7 @@ class MutexBase {
|
|
|
|
|
|
|
|
|
|
|
|
// The Mutex class can only be used for mutexes created at runtime. It
|
|
|
|
// The Mutex class can only be used for mutexes created at runtime. It
|
|
|
|
// shares its API with MutexBase otherwise.
|
|
|
|
// shares its API with MutexBase otherwise.
|
|
|
|
class Mutex : public MutexBase {
|
|
|
|
class [[nodiscard]] Mutex : public MutexBase {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
Mutex() {
|
|
|
|
Mutex() {
|
|
|
|
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr));
|
|
|
|
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr));
|
|
|
|
@ -1727,14 +1764,13 @@ class Mutex : public MutexBase {
|
|
|
|
// platforms. That macro is used as a defensive measure to prevent against
|
|
|
|
// platforms. That macro is used as a defensive measure to prevent against
|
|
|
|
// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
|
|
|
|
// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
|
|
|
|
// "MutexLock l(&mu)". Hence the typedef trick below.
|
|
|
|
// "MutexLock l(&mu)". Hence the typedef trick below.
|
|
|
|
class GTestMutexLock {
|
|
|
|
class [[nodiscard]] GTestMutexLock {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit GTestMutexLock(MutexBase* mutex) : mutex_(mutex) { mutex_->Lock(); }
|
|
|
|
explicit GTestMutexLock(MutexBase& mutex) : mutex_(mutex) { mutex_.lock(); }
|
|
|
|
|
|
|
|
~GTestMutexLock() { mutex_.unlock(); }
|
|
|
|
~GTestMutexLock() { mutex_->Unlock(); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
MutexBase* const mutex_;
|
|
|
|
MutexBase& mutex_;
|
|
|
|
|
|
|
|
|
|
|
|
GTestMutexLock(const GTestMutexLock&) = delete;
|
|
|
|
GTestMutexLock(const GTestMutexLock&) = delete;
|
|
|
|
GTestMutexLock& operator=(const GTestMutexLock&) = delete;
|
|
|
|
GTestMutexLock& operator=(const GTestMutexLock&) = delete;
|
|
|
|
@ -1748,7 +1784,7 @@ typedef GTestMutexLock MutexLock;
|
|
|
|
// C-linkage. Therefore it cannot be templatized to access
|
|
|
|
// C-linkage. Therefore it cannot be templatized to access
|
|
|
|
// ThreadLocal<T>. Hence the need for class
|
|
|
|
// ThreadLocal<T>. Hence the need for class
|
|
|
|
// ThreadLocalValueHolderBase.
|
|
|
|
// ThreadLocalValueHolderBase.
|
|
|
|
class GTEST_API_ ThreadLocalValueHolderBase {
|
|
|
|
class GTEST_API_ [[nodiscard]] ThreadLocalValueHolderBase {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
virtual ~ThreadLocalValueHolderBase() = default;
|
|
|
|
virtual ~ThreadLocalValueHolderBase() = default;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@ -1761,7 +1797,7 @@ extern "C" inline void DeleteThreadLocalValue(void* value_holder) {
|
|
|
|
|
|
|
|
|
|
|
|
// Implements thread-local storage on pthreads-based systems.
|
|
|
|
// Implements thread-local storage on pthreads-based systems.
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
class GTEST_API_ ThreadLocal {
|
|
|
|
class GTEST_API_ [[nodiscard]] ThreadLocal {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
ThreadLocal()
|
|
|
|
ThreadLocal()
|
|
|
|
: key_(CreateKey()), default_factory_(new DefaultValueHolderFactory()) {}
|
|
|
|
: key_(CreateKey()), default_factory_(new DefaultValueHolderFactory()) {}
|
|
|
|
@ -1874,11 +1910,11 @@ class GTEST_API_ ThreadLocal {
|
|
|
|
// mutex is not supported - using Google Test in multiple threads is not
|
|
|
|
// mutex is not supported - using Google Test in multiple threads is not
|
|
|
|
// supported on such platforms.
|
|
|
|
// supported on such platforms.
|
|
|
|
|
|
|
|
|
|
|
|
class Mutex {
|
|
|
|
class [[nodiscard]] Mutex {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
Mutex() {}
|
|
|
|
Mutex() {}
|
|
|
|
void Lock() {}
|
|
|
|
void lock() {}
|
|
|
|
void Unlock() {}
|
|
|
|
void unlock() {}
|
|
|
|
void AssertHeld() const {}
|
|
|
|
void AssertHeld() const {}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
@ -1892,15 +1928,15 @@ class Mutex {
|
|
|
|
// platforms. That macro is used as a defensive measure to prevent against
|
|
|
|
// platforms. That macro is used as a defensive measure to prevent against
|
|
|
|
// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
|
|
|
|
// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than
|
|
|
|
// "MutexLock l(&mu)". Hence the typedef trick below.
|
|
|
|
// "MutexLock l(&mu)". Hence the typedef trick below.
|
|
|
|
class GTestMutexLock {
|
|
|
|
class [[nodiscard]] GTestMutexLock {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
explicit GTestMutexLock(Mutex*) {} // NOLINT
|
|
|
|
explicit GTestMutexLock(Mutex&) {} // NOLINT
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef GTestMutexLock MutexLock;
|
|
|
|
typedef GTestMutexLock MutexLock;
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
class GTEST_API_ ThreadLocal {
|
|
|
|
class GTEST_API_ [[nodiscard]] ThreadLocal {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
ThreadLocal() : value_() {}
|
|
|
|
ThreadLocal() : value_() {}
|
|
|
|
explicit ThreadLocal(const T& value) : value_(value) {}
|
|
|
|
explicit ThreadLocal(const T& value) : value_(value) {}
|
|
|
|
@ -2090,7 +2126,7 @@ inline int IsATTY(int fd) {
|
|
|
|
|
|
|
|
|
|
|
|
// Functions deprecated by MSVC 8.0.
|
|
|
|
// Functions deprecated by MSVC 8.0.
|
|
|
|
|
|
|
|
|
|
|
|
GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
|
|
|
|
GTEST_DISABLE_DEPRECATED_PUSH_()
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
@ -2152,7 +2188,7 @@ inline const char* GetEnv(const char* name) {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GTEST_DISABLE_MSC_DEPRECATED_POP_()
|
|
|
|
GTEST_DISABLE_DEPRECATED_POP_()
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef 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
|
|
|
|
@ -2208,7 +2244,7 @@ constexpr BiggestInt kMaxBiggestInt = (std::numeric_limits<BiggestInt>::max)();
|
|
|
|
// 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 [[nodiscard]] 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.
|
|
|
|
@ -2217,7 +2253,7 @@ class TypeWithSize {
|
|
|
|
|
|
|
|
|
|
|
|
// The specialization for size 4.
|
|
|
|
// The specialization for size 4.
|
|
|
|
template <>
|
|
|
|
template <>
|
|
|
|
class TypeWithSize<4> {
|
|
|
|
class [[nodiscard]] TypeWithSize<4> {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
using Int = std::int32_t;
|
|
|
|
using Int = std::int32_t;
|
|
|
|
using UInt = std::uint32_t;
|
|
|
|
using UInt = std::uint32_t;
|
|
|
|
@ -2225,7 +2261,7 @@ class TypeWithSize<4> {
|
|
|
|
|
|
|
|
|
|
|
|
// The specialization for size 8.
|
|
|
|
// The specialization for size 8.
|
|
|
|
template <>
|
|
|
|
template <>
|
|
|
|
class TypeWithSize<8> {
|
|
|
|
class [[nodiscard]] TypeWithSize<8> {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
using Int = std::int64_t;
|
|
|
|
using Int = std::int64_t;
|
|
|
|
using UInt = std::uint64_t;
|
|
|
|
using UInt = std::uint64_t;
|
|
|
|
@ -2255,11 +2291,11 @@ using TimeInMillis = int64_t; // Represents time in milliseconds.
|
|
|
|
|
|
|
|
|
|
|
|
// Macros for declaring flags.
|
|
|
|
// Macros for declaring flags.
|
|
|
|
#define GTEST_DECLARE_bool_(name) \
|
|
|
|
#define GTEST_DECLARE_bool_(name) \
|
|
|
|
ABSL_DECLARE_FLAG(bool, GTEST_FLAG_NAME_(name))
|
|
|
|
GTEST_API_ ABSL_DECLARE_FLAG(bool, GTEST_FLAG_NAME_(name))
|
|
|
|
#define GTEST_DECLARE_int32_(name) \
|
|
|
|
#define GTEST_DECLARE_int32_(name) \
|
|
|
|
ABSL_DECLARE_FLAG(int32_t, GTEST_FLAG_NAME_(name))
|
|
|
|
GTEST_API_ ABSL_DECLARE_FLAG(int32_t, GTEST_FLAG_NAME_(name))
|
|
|
|
#define GTEST_DECLARE_string_(name) \
|
|
|
|
#define GTEST_DECLARE_string_(name) \
|
|
|
|
ABSL_DECLARE_FLAG(std::string, GTEST_FLAG_NAME_(name))
|
|
|
|
GTEST_API_ ABSL_DECLARE_FLAG(std::string, GTEST_FLAG_NAME_(name))
|
|
|
|
|
|
|
|
|
|
|
|
#define GTEST_FLAG_SAVER_ ::absl::FlagSaver
|
|
|
|
#define GTEST_FLAG_SAVER_ ::absl::FlagSaver
|
|
|
|
|
|
|
|
|
|
|
|
@ -2273,22 +2309,29 @@ using TimeInMillis = int64_t; // Represents time in milliseconds.
|
|
|
|
|
|
|
|
|
|
|
|
// 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_DECLARE_bool_(name); \
|
|
|
|
namespace testing { \
|
|
|
|
namespace testing { \
|
|
|
|
GTEST_API_ bool GTEST_FLAG(name) = (default_val); \
|
|
|
|
GTEST_API_ bool GTEST_FLAG(name) = (default_val); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
static_assert(true, "no-op to require trailing semicolon")
|
|
|
|
static_assert(true, "no-op to require trailing semicolon")
|
|
|
|
#define GTEST_DEFINE_int32_(name, default_val, doc) \
|
|
|
|
#define GTEST_DEFINE_int32_(name, default_val, doc) \
|
|
|
|
|
|
|
|
GTEST_DECLARE_int32_(name); \
|
|
|
|
namespace testing { \
|
|
|
|
namespace testing { \
|
|
|
|
GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val); \
|
|
|
|
GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
static_assert(true, "no-op to require trailing semicolon")
|
|
|
|
static_assert(true, "no-op to require trailing semicolon")
|
|
|
|
#define GTEST_DEFINE_string_(name, default_val, doc) \
|
|
|
|
#define GTEST_DEFINE_string_(name, default_val, doc) \
|
|
|
|
|
|
|
|
GTEST_DECLARE_string_(name); \
|
|
|
|
namespace testing { \
|
|
|
|
namespace testing { \
|
|
|
|
GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val); \
|
|
|
|
GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
static_assert(true, "no-op to require trailing semicolon")
|
|
|
|
static_assert(true, "no-op to require trailing semicolon")
|
|
|
|
|
|
|
|
|
|
|
|
// Macros for declaring flags.
|
|
|
|
// Macros for declaring flags.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// We also need to declare the flag in the public namespace to avoid triggering
|
|
|
|
|
|
|
|
// -Wmissing-variable-declarations warnings, as reported here:
|
|
|
|
|
|
|
|
// https://github.com/google/googletest/issues/4897
|
|
|
|
#define GTEST_DECLARE_bool_(name) \
|
|
|
|
#define GTEST_DECLARE_bool_(name) \
|
|
|
|
namespace testing { \
|
|
|
|
namespace testing { \
|
|
|
|
GTEST_API_ extern bool GTEST_FLAG(name); \
|
|
|
|
GTEST_API_ extern bool GTEST_FLAG(name); \
|
|
|
|
@ -2335,71 +2378,11 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val);
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace testing
|
|
|
|
} // namespace testing
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef GTEST_HAS_ABSL
|
|
|
|
#if GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(clang::annotate)
|
|
|
|
// Always use absl::any for UniversalPrinter<> specializations if googletest
|
|
|
|
#define GTEST_INTERNAL_DEPRECATE_AND_INLINE(msg) \
|
|
|
|
// is built with absl support.
|
|
|
|
[[deprecated(msg), clang::annotate("inline-me")]]
|
|
|
|
#define GTEST_INTERNAL_HAS_ANY 1
|
|
|
|
|
|
|
|
#include "absl/types/any.h"
|
|
|
|
|
|
|
|
namespace testing {
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
using Any = ::absl::any;
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
} // namespace testing
|
|
|
|
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#if defined(__cpp_lib_any) || (GTEST_INTERNAL_HAS_INCLUDE(<any>) && \
|
|
|
|
#define GTEST_INTERNAL_DEPRECATE_AND_INLINE(msg) [[deprecated(msg)]]
|
|
|
|
GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L && \
|
|
|
|
|
|
|
|
(!defined(_MSC_VER) || GTEST_HAS_RTTI))
|
|
|
|
|
|
|
|
// 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 // __cpp_lib_any
|
|
|
|
|
|
|
|
#endif // GTEST_HAS_ABSL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GTEST_INTERNAL_HAS_ANY
|
|
|
|
|
|
|
|
#define GTEST_INTERNAL_HAS_ANY 0
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef 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>;
|
|
|
|
|
|
|
|
inline ::absl::nullopt_t Nullopt() { return ::absl::nullopt; }
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
} // namespace testing
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#if defined(__cpp_lib_optional) || (GTEST_INTERNAL_HAS_INCLUDE(<optional>) && \
|
|
|
|
|
|
|
|
GTEST_INTERNAL_CPLUSPLUS_LANG >= 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>;
|
|
|
|
|
|
|
|
inline ::std::nullopt_t Nullopt() { return ::std::nullopt; }
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
} // namespace testing
|
|
|
|
|
|
|
|
// The case where absl is configured NOT to alias std::optional is not
|
|
|
|
|
|
|
|
// supported.
|
|
|
|
|
|
|
|
#endif // __cpp_lib_optional
|
|
|
|
|
|
|
|
#endif // GTEST_HAS_ABSL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GTEST_INTERNAL_HAS_OPTIONAL
|
|
|
|
|
|
|
|
#define GTEST_INTERNAL_HAS_OPTIONAL 0
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(__cpp_lib_span) || (GTEST_INTERNAL_HAS_INCLUDE(<span>) && \
|
|
|
|
#if defined(__cpp_lib_span) || (GTEST_INTERNAL_HAS_INCLUDE(<span>) && \
|
|
|
|
@ -2414,7 +2397,6 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; }
|
|
|
|
#ifdef GTEST_HAS_ABSL
|
|
|
|
#ifdef GTEST_HAS_ABSL
|
|
|
|
// Always use absl::string_view for Matcher<> specializations if googletest
|
|
|
|
// Always use absl::string_view for Matcher<> specializations if googletest
|
|
|
|
// is built with absl support.
|
|
|
|
// is built with absl support.
|
|
|
|
#define GTEST_INTERNAL_HAS_STRING_VIEW 1
|
|
|
|
|
|
|
|
#include "absl/strings/string_view.h"
|
|
|
|
#include "absl/strings/string_view.h"
|
|
|
|
namespace testing {
|
|
|
|
namespace testing {
|
|
|
|
namespace internal {
|
|
|
|
namespace internal {
|
|
|
|
@ -2422,62 +2404,17 @@ using StringView = ::absl::string_view;
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace testing
|
|
|
|
} // namespace testing
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#if defined(__cpp_lib_string_view) || \
|
|
|
|
|
|
|
|
(GTEST_INTERNAL_HAS_INCLUDE(<string_view>) && \
|
|
|
|
|
|
|
|
GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L)
|
|
|
|
|
|
|
|
// Otherwise for C++17 and higher use std::string_view for Matcher<>
|
|
|
|
// Otherwise for C++17 and higher use std::string_view for Matcher<>
|
|
|
|
// specializations.
|
|
|
|
// specializations.
|
|
|
|
#define GTEST_INTERNAL_HAS_STRING_VIEW 1
|
|
|
|
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
namespace testing {
|
|
|
|
namespace testing {
|
|
|
|
namespace internal {
|
|
|
|
namespace internal {
|
|
|
|
using StringView = ::std::string_view;
|
|
|
|
using StringView = std::string_view;
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace testing
|
|
|
|
} // namespace testing
|
|
|
|
// The case where absl is configured NOT to alias std::string_view is not
|
|
|
|
|
|
|
|
// supported.
|
|
|
|
|
|
|
|
#endif // __cpp_lib_string_view
|
|
|
|
|
|
|
|
#endif // GTEST_HAS_ABSL
|
|
|
|
#endif // GTEST_HAS_ABSL
|
|
|
|
|
|
|
|
#define GTEST_INTERNAL_HAS_STRING_VIEW 1
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GTEST_INTERNAL_HAS_STRING_VIEW
|
|
|
|
#if defined(__cpp_lib_three_way_comparison)
|
|
|
|
#define GTEST_INTERNAL_HAS_STRING_VIEW 0
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef 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
|
|
|
|
|
|
|
|
#if defined(__cpp_lib_variant) || (GTEST_INTERNAL_HAS_INCLUDE(<variant>) && \
|
|
|
|
|
|
|
|
GTEST_INTERNAL_CPLUSPLUS_LANG >= 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 // __cpp_lib_variant
|
|
|
|
|
|
|
|
#endif // GTEST_HAS_ABSL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GTEST_INTERNAL_HAS_VARIANT
|
|
|
|
|
|
|
|
#define GTEST_INTERNAL_HAS_VARIANT 0
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if (defined(__cpp_lib_three_way_comparison) || \
|
|
|
|
|
|
|
|
(GTEST_INTERNAL_HAS_INCLUDE(<compare>) && \
|
|
|
|
|
|
|
|
GTEST_INTERNAL_CPLUSPLUS_LANG >= 201907L))
|
|
|
|
|
|
|
|
#define GTEST_INTERNAL_HAS_COMPARE_LIB 1
|
|
|
|
#define GTEST_INTERNAL_HAS_COMPARE_LIB 1
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
#define GTEST_INTERNAL_HAS_COMPARE_LIB 0
|
|
|
|
#define GTEST_INTERNAL_HAS_COMPARE_LIB 0
|
|
|
|
|