Unverified Commit 76bce79a authored by Andy Soffer's avatar Andy Soffer Committed by GitHub
Browse files

Merge branch 'main' into fixes_std_pair_diff

parents 6f1c4b3d f345b2ca
...@@ -51,7 +51,7 @@ GTEST_DECLARE_string_(death_test_style); ...@@ -51,7 +51,7 @@ GTEST_DECLARE_string_(death_test_style);
namespace testing { namespace testing {
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
namespace internal { namespace internal {
...@@ -203,7 +203,7 @@ class GTEST_API_ ExitedWithCode { ...@@ -203,7 +203,7 @@ class GTEST_API_ ExitedWithCode {
const int exit_code_; const int exit_code_;
}; };
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA #if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA)
// Tests that an exit code describes an exit due to termination by a // Tests that an exit code describes an exit due to termination by a
// given signal. // given signal.
class GTEST_API_ KilledBySignal { class GTEST_API_ KilledBySignal {
...@@ -328,7 +328,7 @@ class GTEST_API_ KilledBySignal { ...@@ -328,7 +328,7 @@ class GTEST_API_ KilledBySignal {
// death tests are supported; otherwise they just issue a warning. This is // death tests are supported; otherwise they just issue a warning. This is
// useful when you are combining death test assertions with normal test // useful when you are combining death test assertions with normal test
// assertions in one test. // assertions in one test.
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ #define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
EXPECT_DEATH(statement, regex) EXPECT_DEATH(statement, regex)
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ #define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#define GOOGLETEST_INCLUDE_GTEST_GTEST_MATCHERS_H_ #define GOOGLETEST_INCLUDE_GTEST_GTEST_MATCHERS_H_
#include <atomic> #include <atomic>
#include <functional>
#include <memory> #include <memory>
#include <ostream> #include <ostream>
#include <string> #include <string>
...@@ -106,13 +107,13 @@ class MatchResultListener { ...@@ -106,13 +107,13 @@ class MatchResultListener {
MatchResultListener& operator=(const MatchResultListener&) = delete; MatchResultListener& operator=(const MatchResultListener&) = delete;
}; };
inline MatchResultListener::~MatchResultListener() {} inline MatchResultListener::~MatchResultListener() = default;
// An instance of a subclass of this knows how to describe itself as a // An instance of a subclass of this knows how to describe itself as a
// matcher. // matcher.
class GTEST_API_ MatcherDescriberInterface { class GTEST_API_ MatcherDescriberInterface {
public: public:
virtual ~MatcherDescriberInterface() {} virtual ~MatcherDescriberInterface() = default;
// Describes this matcher to an ostream. The function should print // Describes this matcher to an ostream. The function should print
// a verb phrase that describes the property a value matching this // a verb phrase that describes the property a value matching this
...@@ -178,43 +179,6 @@ class MatcherInterface : public MatcherDescriberInterface { ...@@ -178,43 +179,6 @@ class MatcherInterface : public MatcherDescriberInterface {
namespace internal { namespace internal {
struct AnyEq {
template <typename A, typename B>
bool operator()(const A& a, const B& b) const {
return a == b;
}
};
struct AnyNe {
template <typename A, typename B>
bool operator()(const A& a, const B& b) const {
return a != b;
}
};
struct AnyLt {
template <typename A, typename B>
bool operator()(const A& a, const B& b) const {
return a < b;
}
};
struct AnyGt {
template <typename A, typename B>
bool operator()(const A& a, const B& b) const {
return a > b;
}
};
struct AnyLe {
template <typename A, typename B>
bool operator()(const A& a, const B& b) const {
return a <= b;
}
};
struct AnyGe {
template <typename A, typename B>
bool operator()(const A& a, const B& b) const {
return a >= b;
}
};
// A match result listener that ignores the explanation. // A match result listener that ignores the explanation.
class DummyMatchResultListener : public MatchResultListener { class DummyMatchResultListener : public MatchResultListener {
public: public:
...@@ -530,7 +494,7 @@ template <> ...@@ -530,7 +494,7 @@ template <>
class GTEST_API_ Matcher<const std::string&> class GTEST_API_ Matcher<const std::string&>
: public internal::MatcherBase<const std::string&> { : public internal::MatcherBase<const std::string&> {
public: public:
Matcher() {} Matcher() = default;
explicit Matcher(const MatcherInterface<const std::string&>* impl) explicit Matcher(const MatcherInterface<const std::string&>* impl)
: internal::MatcherBase<const std::string&>(impl) {} : internal::MatcherBase<const std::string&>(impl) {}
...@@ -552,7 +516,7 @@ template <> ...@@ -552,7 +516,7 @@ template <>
class GTEST_API_ Matcher<std::string> class GTEST_API_ Matcher<std::string>
: public internal::MatcherBase<std::string> { : public internal::MatcherBase<std::string> {
public: public:
Matcher() {} Matcher() = default;
explicit Matcher(const MatcherInterface<const std::string&>* impl) explicit Matcher(const MatcherInterface<const std::string&>* impl)
: internal::MatcherBase<std::string>(impl) {} : internal::MatcherBase<std::string>(impl) {}
...@@ -580,7 +544,7 @@ template <> ...@@ -580,7 +544,7 @@ template <>
class GTEST_API_ Matcher<const internal::StringView&> class GTEST_API_ Matcher<const internal::StringView&>
: public internal::MatcherBase<const internal::StringView&> { : public internal::MatcherBase<const internal::StringView&> {
public: public:
Matcher() {} Matcher() = default;
explicit Matcher(const MatcherInterface<const internal::StringView&>* impl) explicit Matcher(const MatcherInterface<const internal::StringView&>* impl)
: internal::MatcherBase<const internal::StringView&>(impl) {} : internal::MatcherBase<const internal::StringView&>(impl) {}
...@@ -606,7 +570,7 @@ template <> ...@@ -606,7 +570,7 @@ template <>
class GTEST_API_ Matcher<internal::StringView> class GTEST_API_ Matcher<internal::StringView>
: public internal::MatcherBase<internal::StringView> { : public internal::MatcherBase<internal::StringView> {
public: public:
Matcher() {} Matcher() = default;
explicit Matcher(const MatcherInterface<const internal::StringView&>* impl) explicit Matcher(const MatcherInterface<const internal::StringView&>* impl)
: internal::MatcherBase<internal::StringView>(impl) {} : internal::MatcherBase<internal::StringView>(impl) {}
...@@ -758,50 +722,53 @@ class ComparisonBase { ...@@ -758,50 +722,53 @@ class ComparisonBase {
}; };
template <typename Rhs> template <typename Rhs>
class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq> { class EqMatcher : public ComparisonBase<EqMatcher<Rhs>, Rhs, std::equal_to<>> {
public: public:
explicit EqMatcher(const Rhs& rhs) explicit EqMatcher(const Rhs& rhs)
: ComparisonBase<EqMatcher<Rhs>, Rhs, AnyEq>(rhs) {} : ComparisonBase<EqMatcher<Rhs>, Rhs, std::equal_to<>>(rhs) {}
static const char* Desc() { return "is equal to"; } static const char* Desc() { return "is equal to"; }
static const char* NegatedDesc() { return "isn't equal to"; } static const char* NegatedDesc() { return "isn't equal to"; }
}; };
template <typename Rhs> template <typename Rhs>
class NeMatcher : public ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe> { class NeMatcher
: public ComparisonBase<NeMatcher<Rhs>, Rhs, std::not_equal_to<>> {
public: public:
explicit NeMatcher(const Rhs& rhs) explicit NeMatcher(const Rhs& rhs)
: ComparisonBase<NeMatcher<Rhs>, Rhs, AnyNe>(rhs) {} : ComparisonBase<NeMatcher<Rhs>, Rhs, std::not_equal_to<>>(rhs) {}
static const char* Desc() { return "isn't equal to"; } static const char* Desc() { return "isn't equal to"; }
static const char* NegatedDesc() { return "is equal to"; } static const char* NegatedDesc() { return "is equal to"; }
}; };
template <typename Rhs> template <typename Rhs>
class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt> { class LtMatcher : public ComparisonBase<LtMatcher<Rhs>, Rhs, std::less<>> {
public: public:
explicit LtMatcher(const Rhs& rhs) explicit LtMatcher(const Rhs& rhs)
: ComparisonBase<LtMatcher<Rhs>, Rhs, AnyLt>(rhs) {} : ComparisonBase<LtMatcher<Rhs>, Rhs, std::less<>>(rhs) {}
static const char* Desc() { return "is <"; } static const char* Desc() { return "is <"; }
static const char* NegatedDesc() { return "isn't <"; } static const char* NegatedDesc() { return "isn't <"; }
}; };
template <typename Rhs> template <typename Rhs>
class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt> { class GtMatcher : public ComparisonBase<GtMatcher<Rhs>, Rhs, std::greater<>> {
public: public:
explicit GtMatcher(const Rhs& rhs) explicit GtMatcher(const Rhs& rhs)
: ComparisonBase<GtMatcher<Rhs>, Rhs, AnyGt>(rhs) {} : ComparisonBase<GtMatcher<Rhs>, Rhs, std::greater<>>(rhs) {}
static const char* Desc() { return "is >"; } static const char* Desc() { return "is >"; }
static const char* NegatedDesc() { return "isn't >"; } static const char* NegatedDesc() { return "isn't >"; }
}; };
template <typename Rhs> template <typename Rhs>
class LeMatcher : public ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe> { class LeMatcher
: public ComparisonBase<LeMatcher<Rhs>, Rhs, std::less_equal<>> {
public: public:
explicit LeMatcher(const Rhs& rhs) explicit LeMatcher(const Rhs& rhs)
: ComparisonBase<LeMatcher<Rhs>, Rhs, AnyLe>(rhs) {} : ComparisonBase<LeMatcher<Rhs>, Rhs, std::less_equal<>>(rhs) {}
static const char* Desc() { return "is <="; } static const char* Desc() { return "is <="; }
static const char* NegatedDesc() { return "isn't <="; } static const char* NegatedDesc() { return "isn't <="; }
}; };
template <typename Rhs> template <typename Rhs>
class GeMatcher : public ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe> { class GeMatcher
: public ComparisonBase<GeMatcher<Rhs>, Rhs, std::greater_equal<>> {
public: public:
explicit GeMatcher(const Rhs& rhs) explicit GeMatcher(const Rhs& rhs)
: ComparisonBase<GeMatcher<Rhs>, Rhs, AnyGe>(rhs) {} : ComparisonBase<GeMatcher<Rhs>, Rhs, std::greater_equal<>>(rhs) {}
static const char* Desc() { return "is >="; } static const char* Desc() { return "is >="; }
static const char* NegatedDesc() { return "isn't >="; } static const char* NegatedDesc() { return "isn't >="; }
}; };
......
...@@ -206,12 +206,13 @@ struct StreamPrinter { ...@@ -206,12 +206,13 @@ struct StreamPrinter {
// Don't accept member pointers here. We'd print them via implicit // Don't accept member pointers here. We'd print them via implicit
// conversion to bool, which isn't useful. // conversion to bool, which isn't useful.
typename = typename std::enable_if< typename = typename std::enable_if<
!std::is_member_pointer<T>::value>::type, !std::is_member_pointer<T>::value>::type>
// Only accept types for which we can find a streaming operator via // Only accept types for which we can find a streaming operator via
// ADL (possibly involving implicit conversions). // ADL (possibly involving implicit conversions).
typename = decltype(std::declval<std::ostream&>() // (Use SFINAE via return type, because it seems GCC < 12 doesn't handle name
<< std::declval<const T&>())> // lookup properly when we do it in the template parameter list.)
static void PrintValue(const T& value, ::std::ostream* os) { static auto PrintValue(const T& value, ::std::ostream* os)
-> decltype((void)(*os << value)) {
// Call streaming operator found by ADL, possibly with implicit conversions // Call streaming operator found by ADL, possibly with implicit conversions
// of the arguments. // of the arguments.
*os << value; *os << value;
...@@ -306,9 +307,10 @@ template <typename T> ...@@ -306,9 +307,10 @@ template <typename T>
void PrintWithFallback(const T& value, ::std::ostream* os) { void PrintWithFallback(const T& value, ::std::ostream* os) {
using Printer = typename FindFirstPrinter< using Printer = typename FindFirstPrinter<
T, void, ContainerPrinter, FunctionPointerPrinter, PointerPrinter, T, void, ContainerPrinter, FunctionPointerPrinter, PointerPrinter,
ProtobufPrinter,
internal_stream_operator_without_lexical_name_lookup::StreamPrinter, internal_stream_operator_without_lexical_name_lookup::StreamPrinter,
ProtobufPrinter, ConvertibleToIntegerPrinter, ConvertibleToIntegerPrinter, ConvertibleToStringViewPrinter,
ConvertibleToStringViewPrinter, RawBytesPrinter, FallbackPrinter>::type; RawBytesPrinter, FallbackPrinter>::type;
Printer::PrintValue(value, os); Printer::PrintValue(value, os);
} }
...@@ -856,7 +858,7 @@ class UniversalPrinter<Variant<T...>> { ...@@ -856,7 +858,7 @@ class UniversalPrinter<Variant<T...>> {
public: public:
static void Print(const Variant<T...>& value, ::std::ostream* os) { static void Print(const Variant<T...>& value, ::std::ostream* os) {
*os << '('; *os << '(';
#if GTEST_HAS_ABSL #ifdef GTEST_HAS_ABSL
absl::visit(Visitor{os, value.index()}, value); absl::visit(Visitor{os, value.index()}, value);
#else #else
std::visit(Visitor{os, value.index()}, value); std::visit(Visitor{os, value.index()}, value);
...@@ -1002,7 +1004,7 @@ template <> ...@@ -1002,7 +1004,7 @@ template <>
class UniversalTersePrinter<char*> : public UniversalTersePrinter<const char*> { class UniversalTersePrinter<char*> : public UniversalTersePrinter<const char*> {
}; };
#ifdef __cpp_char8_t #ifdef __cpp_lib_char8_t
template <> template <>
class UniversalTersePrinter<const char8_t*> { class UniversalTersePrinter<const char8_t*> {
public: public:
......
...@@ -133,7 +133,7 @@ std::ostream& operator<<(std::ostream& os, const TestPartResult& result); ...@@ -133,7 +133,7 @@ std::ostream& operator<<(std::ostream& os, const TestPartResult& result);
// virtual. // virtual.
class GTEST_API_ TestPartResultArray { class GTEST_API_ TestPartResultArray {
public: public:
TestPartResultArray() {} TestPartResultArray() = default;
// Appends the given TestPartResult to the array. // Appends the given TestPartResult to the array.
void Append(const TestPartResult& result); void Append(const TestPartResult& result);
...@@ -154,7 +154,7 @@ class GTEST_API_ TestPartResultArray { ...@@ -154,7 +154,7 @@ class GTEST_API_ TestPartResultArray {
// This interface knows how to report a test part result. // This interface knows how to report a test part result.
class GTEST_API_ TestPartResultReporterInterface { class GTEST_API_ TestPartResultReporterInterface {
public: public:
virtual ~TestPartResultReporterInterface() {} virtual ~TestPartResultReporterInterface() = default;
virtual void ReportTestPartResult(const TestPartResult& result) = 0; virtual void ReportTestPartResult(const TestPartResult& result) = 0;
}; };
......
...@@ -302,7 +302,7 @@ class GTEST_API_ Test { ...@@ -302,7 +302,7 @@ class GTEST_API_ Test {
template <typename T, std::enable_if_t<std::is_convertible<T, int64_t>::value, template <typename T, std::enable_if_t<std::is_convertible<T, int64_t>::value,
bool> = true> bool> = true>
static void RecordProperty(const std::string& key, const T& value) { static void RecordProperty(const std::string& key, const T& value) {
RecordProperty(key, (Message() << static_cast<int64_t>(value)).GetString()); RecordProperty(key, (Message() << value).GetString());
} }
protected: protected:
...@@ -551,14 +551,14 @@ class GTEST_API_ TestInfo { ...@@ -551,14 +551,14 @@ class GTEST_API_ TestInfo {
// Returns the name of the parameter type, or NULL if this is not a typed // Returns the name of the parameter type, or NULL if this is not a typed
// or a type-parameterized test. // or a type-parameterized test.
const char* type_param() const { const char* type_param() const {
if (type_param_.get() != nullptr) return type_param_->c_str(); if (type_param_ != nullptr) return type_param_->c_str();
return nullptr; return nullptr;
} }
// Returns the text representation of the value parameter, or NULL if this // Returns the text representation of the value parameter, or NULL if this
// is not a value-parameterized test. // is not a value-parameterized test.
const char* value_param() const { const char* value_param() const {
if (value_param_.get() != nullptr) return value_param_->c_str(); if (value_param_ != nullptr) return value_param_->c_str();
return nullptr; return nullptr;
} }
...@@ -600,7 +600,7 @@ class GTEST_API_ TestInfo { ...@@ -600,7 +600,7 @@ class GTEST_API_ TestInfo {
const TestResult* result() const { return &result_; } const TestResult* result() const { return &result_; }
private: private:
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
friend class internal::DefaultDeathTestFactory; friend class internal::DefaultDeathTestFactory;
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
friend class Test; friend class Test;
...@@ -697,7 +697,7 @@ class GTEST_API_ TestSuite { ...@@ -697,7 +697,7 @@ class GTEST_API_ TestSuite {
// Returns the name of the parameter type, or NULL if this is not a // Returns the name of the parameter type, or NULL if this is not a
// type-parameterized test suite. // type-parameterized test suite.
const char* type_param() const { const char* type_param() const {
if (type_param_.get() != nullptr) return type_param_->c_str(); if (type_param_ != nullptr) return type_param_->c_str();
return nullptr; return nullptr;
} }
...@@ -894,7 +894,7 @@ class GTEST_API_ TestSuite { ...@@ -894,7 +894,7 @@ class GTEST_API_ TestSuite {
class Environment { class Environment {
public: public:
// The d'tor is virtual as we need to subclass Environment. // The d'tor is virtual as we need to subclass Environment.
virtual ~Environment() {} virtual ~Environment() = default;
// Override this to define how to set up the environment. // Override this to define how to set up the environment.
virtual void SetUp() {} virtual void SetUp() {}
...@@ -925,7 +925,7 @@ class GTEST_API_ AssertionException ...@@ -925,7 +925,7 @@ class GTEST_API_ AssertionException
// the order the corresponding events are fired. // the order the corresponding events are fired.
class TestEventListener { class TestEventListener {
public: public:
virtual ~TestEventListener() {} virtual ~TestEventListener() = default;
// Fired before any test activity starts. // Fired before any test activity starts.
virtual void OnTestProgramStart(const UnitTest& unit_test) = 0; virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
...@@ -1671,7 +1671,7 @@ template <typename T> ...@@ -1671,7 +1671,7 @@ template <typename T>
class WithParamInterface { class WithParamInterface {
public: public:
typedef T ParamType; typedef T ParamType;
virtual ~WithParamInterface() {} virtual ~WithParamInterface() = default;
// The current parameter value. Is also available in the test fixture's // The current parameter value. Is also available in the test fixture's
// constructor. // constructor.
...@@ -1747,7 +1747,7 @@ class TestWithParam : public Test, public WithParamInterface<T> {}; ...@@ -1747,7 +1747,7 @@ class TestWithParam : public Test, public WithParamInterface<T> {};
// Define this macro to 1 to omit the definition of FAIL(), which is a // Define this macro to 1 to omit the definition of FAIL(), which is a
// generic name and clashes with some other libraries. // generic name and clashes with some other libraries.
#if !GTEST_DONT_DEFINE_FAIL #if !(defined(GTEST_DONT_DEFINE_FAIL) && GTEST_DONT_DEFINE_FAIL)
#define FAIL() GTEST_FAIL() #define FAIL() GTEST_FAIL()
#endif #endif
...@@ -1756,7 +1756,7 @@ class TestWithParam : public Test, public WithParamInterface<T> {}; ...@@ -1756,7 +1756,7 @@ class TestWithParam : public Test, public WithParamInterface<T> {};
// Define this macro to 1 to omit the definition of SUCCEED(), which // Define this macro to 1 to omit the definition of SUCCEED(), which
// is a generic name and clashes with some other libraries. // is a generic name and clashes with some other libraries.
#if !GTEST_DONT_DEFINE_SUCCEED #if !(defined(GTEST_DONT_DEFINE_SUCCEED) && GTEST_DONT_DEFINE_SUCCEED)
#define SUCCEED() GTEST_SUCCEED() #define SUCCEED() GTEST_SUCCEED()
#endif #endif
...@@ -1800,19 +1800,19 @@ class TestWithParam : public Test, public WithParamInterface<T> {}; ...@@ -1800,19 +1800,19 @@ class TestWithParam : public Test, public WithParamInterface<T> {};
// Define these macros to 1 to omit the definition of the corresponding // Define these macros to 1 to omit the definition of the corresponding
// EXPECT or ASSERT, which clashes with some users' own code. // EXPECT or ASSERT, which clashes with some users' own code.
#if !GTEST_DONT_DEFINE_EXPECT_TRUE #if !(defined(GTEST_DONT_DEFINE_EXPECT_TRUE) && GTEST_DONT_DEFINE_EXPECT_TRUE)
#define EXPECT_TRUE(condition) GTEST_EXPECT_TRUE(condition) #define EXPECT_TRUE(condition) GTEST_EXPECT_TRUE(condition)
#endif #endif
#if !GTEST_DONT_DEFINE_EXPECT_FALSE #if !(defined(GTEST_DONT_DEFINE_EXPECT_FALSE) && GTEST_DONT_DEFINE_EXPECT_FALSE)
#define EXPECT_FALSE(condition) GTEST_EXPECT_FALSE(condition) #define EXPECT_FALSE(condition) GTEST_EXPECT_FALSE(condition)
#endif #endif
#if !GTEST_DONT_DEFINE_ASSERT_TRUE #if !(defined(GTEST_DONT_DEFINE_ASSERT_TRUE) && GTEST_DONT_DEFINE_ASSERT_TRUE)
#define ASSERT_TRUE(condition) GTEST_ASSERT_TRUE(condition) #define ASSERT_TRUE(condition) GTEST_ASSERT_TRUE(condition)
#endif #endif
#if !GTEST_DONT_DEFINE_ASSERT_FALSE #if !(defined(GTEST_DONT_DEFINE_ASSERT_FALSE) && GTEST_DONT_DEFINE_ASSERT_FALSE)
#define ASSERT_FALSE(condition) GTEST_ASSERT_FALSE(condition) #define ASSERT_FALSE(condition) GTEST_ASSERT_FALSE(condition)
#endif #endif
...@@ -1891,27 +1891,27 @@ class TestWithParam : public Test, public WithParamInterface<T> {}; ...@@ -1891,27 +1891,27 @@ class TestWithParam : public Test, public WithParamInterface<T> {};
// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of // Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
// ASSERT_XY(), which clashes with some users' own code. // ASSERT_XY(), which clashes with some users' own code.
#if !GTEST_DONT_DEFINE_ASSERT_EQ #if !(defined(GTEST_DONT_DEFINE_ASSERT_EQ) && GTEST_DONT_DEFINE_ASSERT_EQ)
#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2) #define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
#endif #endif
#if !GTEST_DONT_DEFINE_ASSERT_NE #if !(defined(GTEST_DONT_DEFINE_ASSERT_NE) && GTEST_DONT_DEFINE_ASSERT_NE)
#define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2) #define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
#endif #endif
#if !GTEST_DONT_DEFINE_ASSERT_LE #if !(defined(GTEST_DONT_DEFINE_ASSERT_LE) && GTEST_DONT_DEFINE_ASSERT_LE)
#define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2) #define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
#endif #endif
#if !GTEST_DONT_DEFINE_ASSERT_LT #if !(defined(GTEST_DONT_DEFINE_ASSERT_LT) && GTEST_DONT_DEFINE_ASSERT_LT)
#define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2) #define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
#endif #endif
#if !GTEST_DONT_DEFINE_ASSERT_GE #if !(defined(GTEST_DONT_DEFINE_ASSERT_GE) && GTEST_DONT_DEFINE_ASSERT_GE)
#define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2) #define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
#endif #endif
#if !GTEST_DONT_DEFINE_ASSERT_GT #if !(defined(GTEST_DONT_DEFINE_ASSERT_GT) && GTEST_DONT_DEFINE_ASSERT_GT)
#define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2) #define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
#endif #endif
...@@ -1999,7 +1999,7 @@ GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2, ...@@ -1999,7 +1999,7 @@ GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2, GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
double val1, double val2); double val1, double val2);
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Macros that test for HRESULT failure and success, these are only useful // Macros that test for HRESULT failure and success, these are only useful
// on Windows, and rely on Windows SDK macros and APIs to compile. // on Windows, and rely on Windows SDK macros and APIs to compile.
...@@ -2169,7 +2169,7 @@ constexpr bool StaticAssertTypeEq() noexcept { ...@@ -2169,7 +2169,7 @@ constexpr bool StaticAssertTypeEq() noexcept {
// Define this macro to 1 to omit the definition of TEST(), which // Define this macro to 1 to omit the definition of TEST(), which
// is a generic name and clashes with some other libraries. // is a generic name and clashes with some other libraries.
#if !GTEST_DONT_DEFINE_TEST #if !(defined(GTEST_DONT_DEFINE_TEST) && GTEST_DONT_DEFINE_TEST)
#define TEST(test_suite_name, test_name) GTEST_TEST(test_suite_name, test_name) #define TEST(test_suite_name, test_name) GTEST_TEST(test_suite_name, test_name)
#endif #endif
...@@ -2201,7 +2201,7 @@ constexpr bool StaticAssertTypeEq() noexcept { ...@@ -2201,7 +2201,7 @@ constexpr bool StaticAssertTypeEq() noexcept {
#define GTEST_TEST_F(test_fixture, test_name) \ #define GTEST_TEST_F(test_fixture, test_name) \
GTEST_TEST_(test_fixture, test_name, test_fixture, \ GTEST_TEST_(test_fixture, test_name, test_fixture, \
::testing::internal::GetTypeId<test_fixture>()) ::testing::internal::GetTypeId<test_fixture>())
#if !GTEST_DONT_DEFINE_TEST_F #if !(defined(GTEST_DONT_DEFINE_TEST_F) && GTEST_DONT_DEFINE_TEST_F)
#define TEST_F(test_fixture, test_name) GTEST_TEST_F(test_fixture, test_name) #define TEST_F(test_fixture, test_name) GTEST_TEST_F(test_fixture, test_name)
#endif #endif
......
...@@ -57,7 +57,7 @@ const char kDeathTestStyleFlag[] = "death_test_style"; ...@@ -57,7 +57,7 @@ const char kDeathTestStyleFlag[] = "death_test_style";
const char kDeathTestUseFork[] = "death_test_use_fork"; const char kDeathTestUseFork[] = "death_test_use_fork";
const char kInternalRunDeathTestFlag[] = "internal_run_death_test"; const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */) /* class A needs to have dll-interface to be used by clients of class B */)
...@@ -88,7 +88,7 @@ class GTEST_API_ DeathTest { ...@@ -88,7 +88,7 @@ class GTEST_API_ DeathTest {
static bool Create(const char* statement, Matcher<const std::string&> matcher, static bool Create(const char* statement, Matcher<const std::string&> matcher,
const char* file, int line, DeathTest** test); const char* file, int line, DeathTest** test);
DeathTest(); DeathTest();
virtual ~DeathTest() {} virtual ~DeathTest() = default;
// A helper class that aborts a death test when it's deleted. // A helper class that aborts a death test when it's deleted.
class ReturnSentinel { class ReturnSentinel {
...@@ -153,7 +153,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 ...@@ -153,7 +153,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
// Factory interface for death tests. May be mocked out for testing. // Factory interface for death tests. May be mocked out for testing.
class DeathTestFactory { class DeathTestFactory {
public: public:
virtual ~DeathTestFactory() {} virtual ~DeathTestFactory() = default;
virtual bool Create(const char* statement, virtual bool Create(const char* statement,
Matcher<const std::string&> matcher, const char* file, Matcher<const std::string&> matcher, const char* file,
int line, DeathTest** test) = 0; int line, DeathTest** test) = 0;
...@@ -238,7 +238,7 @@ inline Matcher<const ::std::string&> MakeDeathTestMatcher( ...@@ -238,7 +238,7 @@ inline Matcher<const ::std::string&> MakeDeathTestMatcher(
} \ } \
break; \ break; \
case ::testing::internal::DeathTest::EXECUTE_TEST: { \ case ::testing::internal::DeathTest::EXECUTE_TEST: { \
::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \ const ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \
gtest_dt); \ gtest_dt); \
GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \ GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
#include <stdlib.h> #include <stdlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
...@@ -435,7 +435,7 @@ GTEST_API_ TypeId GetTestTypeId(); ...@@ -435,7 +435,7 @@ GTEST_API_ TypeId GetTestTypeId();
// of a Test object. // of a Test object.
class TestFactoryBase { class TestFactoryBase {
public: public:
virtual ~TestFactoryBase() {} virtual ~TestFactoryBase() = default;
// Creates a test instance to run. The instance is both created and destroyed // Creates a test instance to run. The instance is both created and destroyed
// within TestInfoImpl::Run() // within TestInfoImpl::Run()
...@@ -457,7 +457,7 @@ class TestFactoryImpl : public TestFactoryBase { ...@@ -457,7 +457,7 @@ class TestFactoryImpl : public TestFactoryBase {
Test* CreateTest() override { return new TestClass; } Test* CreateTest() override { return new TestClass; }
}; };
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Predicate-formatters for implementing the HRESULT checking macros // Predicate-formatters for implementing the HRESULT checking macros
// {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED} // {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}
...@@ -900,8 +900,10 @@ class HasDebugStringAndShortDebugString { ...@@ -900,8 +900,10 @@ class HasDebugStringAndShortDebugString {
HasDebugStringType::value && HasShortDebugStringType::value; HasDebugStringType::value && HasShortDebugStringType::value;
}; };
#ifdef GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
template <typename T> template <typename T>
constexpr bool HasDebugStringAndShortDebugString<T>::value; constexpr bool HasDebugStringAndShortDebugString<T>::value;
#endif
// When the compiler sees expression IsContainerTest<C>(0), if C is an // When the compiler sees expression IsContainerTest<C>(0), if C is an
// STL-style container class, the first overload of IsContainerTest // STL-style container class, the first overload of IsContainerTest
......
...@@ -97,7 +97,7 @@ class ParamGenerator; ...@@ -97,7 +97,7 @@ class ParamGenerator;
template <typename T> template <typename T>
class ParamIteratorInterface { class ParamIteratorInterface {
public: public:
virtual ~ParamIteratorInterface() {} virtual ~ParamIteratorInterface() = default;
// A pointer to the base generator instance. // A pointer to the base generator instance.
// Used only for the purposes of iterator comparison // Used only for the purposes of iterator comparison
// to make sure that two iterators belong to the same generator. // to make sure that two iterators belong to the same generator.
...@@ -171,7 +171,7 @@ class ParamGeneratorInterface { ...@@ -171,7 +171,7 @@ class ParamGeneratorInterface {
public: public:
typedef T ParamType; typedef T ParamType;
virtual ~ParamGeneratorInterface() {} virtual ~ParamGeneratorInterface() = default;
// Generator interface definition // Generator interface definition
virtual ParamIteratorInterface<T>* Begin() const = 0; virtual ParamIteratorInterface<T>* Begin() const = 0;
...@@ -215,7 +215,7 @@ class RangeGenerator : public ParamGeneratorInterface<T> { ...@@ -215,7 +215,7 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
end_(end), end_(end),
step_(step), step_(step),
end_index_(CalculateEndIndex(begin, end, step)) {} end_index_(CalculateEndIndex(begin, end, step)) {}
~RangeGenerator() override {} ~RangeGenerator() override = default;
ParamIteratorInterface<T>* Begin() const override { ParamIteratorInterface<T>* Begin() const override {
return new Iterator(this, begin_, 0, step_); return new Iterator(this, begin_, 0, step_);
...@@ -230,7 +230,7 @@ class RangeGenerator : public ParamGeneratorInterface<T> { ...@@ -230,7 +230,7 @@ class RangeGenerator : public ParamGeneratorInterface<T> {
Iterator(const ParamGeneratorInterface<T>* base, T value, int index, Iterator(const ParamGeneratorInterface<T>* base, T value, int index,
IncrementT step) IncrementT step)
: base_(base), value_(value), index_(index), step_(step) {} : base_(base), value_(value), index_(index), step_(step) {}
~Iterator() override {} ~Iterator() override = default;
const ParamGeneratorInterface<T>* BaseGenerator() const override { const ParamGeneratorInterface<T>* BaseGenerator() const override {
return base_; return base_;
...@@ -299,7 +299,7 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> { ...@@ -299,7 +299,7 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
template <typename ForwardIterator> template <typename ForwardIterator>
ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end) ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
: container_(begin, end) {} : container_(begin, end) {}
~ValuesInIteratorRangeGenerator() override {} ~ValuesInIteratorRangeGenerator() override = default;
ParamIteratorInterface<T>* Begin() const override { ParamIteratorInterface<T>* Begin() const override {
return new Iterator(this, container_.begin()); return new Iterator(this, container_.begin());
...@@ -316,7 +316,7 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> { ...@@ -316,7 +316,7 @@ class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
Iterator(const ParamGeneratorInterface<T>* base, Iterator(const ParamGeneratorInterface<T>* base,
typename ContainerType::const_iterator iterator) typename ContainerType::const_iterator iterator)
: base_(base), iterator_(iterator) {} : base_(base), iterator_(iterator) {}
~Iterator() override {} ~Iterator() override = default;
const ParamGeneratorInterface<T>* BaseGenerator() const override { const ParamGeneratorInterface<T>* BaseGenerator() const override {
return base_; return base_;
...@@ -420,7 +420,7 @@ class ParameterizedTestFactory : public TestFactoryBase { ...@@ -420,7 +420,7 @@ class ParameterizedTestFactory : public TestFactoryBase {
template <class ParamType> template <class ParamType>
class TestMetaFactoryBase { class TestMetaFactoryBase {
public: public:
virtual ~TestMetaFactoryBase() {} virtual ~TestMetaFactoryBase() = default;
virtual TestFactoryBase* CreateTestFactory(ParamType parameter) = 0; virtual TestFactoryBase* CreateTestFactory(ParamType parameter) = 0;
}; };
...@@ -439,7 +439,7 @@ class TestMetaFactory ...@@ -439,7 +439,7 @@ class TestMetaFactory
public: public:
using ParamType = typename TestSuite::ParamType; using ParamType = typename TestSuite::ParamType;
TestMetaFactory() {} TestMetaFactory() = default;
TestFactoryBase* CreateTestFactory(ParamType parameter) override { TestFactoryBase* CreateTestFactory(ParamType parameter) override {
return new ParameterizedTestFactory<TestSuite>(parameter); return new ParameterizedTestFactory<TestSuite>(parameter);
...@@ -462,7 +462,7 @@ class TestMetaFactory ...@@ -462,7 +462,7 @@ class TestMetaFactory
// and calls RegisterTests() on each of them when asked. // and calls RegisterTests() on each of them when asked.
class ParameterizedTestSuiteInfoBase { class ParameterizedTestSuiteInfoBase {
public: public:
virtual ~ParameterizedTestSuiteInfoBase() {} virtual ~ParameterizedTestSuiteInfoBase() = default;
// Base part of test suite name for display purposes. // Base part of test suite name for display purposes.
virtual const std::string& GetTestSuiteName() const = 0; virtual const std::string& GetTestSuiteName() const = 0;
...@@ -691,7 +691,7 @@ using ParameterizedTestCaseInfo = ParameterizedTestSuiteInfo<TestCase>; ...@@ -691,7 +691,7 @@ using ParameterizedTestCaseInfo = ParameterizedTestSuiteInfo<TestCase>;
// ParameterizedTestSuiteInfo descriptors. // ParameterizedTestSuiteInfo descriptors.
class ParameterizedTestSuiteRegistry { class ParameterizedTestSuiteRegistry {
public: public:
ParameterizedTestSuiteRegistry() {} ParameterizedTestSuiteRegistry() = default;
~ParameterizedTestSuiteRegistry() { ~ParameterizedTestSuiteRegistry() {
for (auto& test_suite_info : test_suite_infos_) { for (auto& test_suite_info : test_suite_infos_) {
delete test_suite_info; delete test_suite_info;
...@@ -825,7 +825,7 @@ class CartesianProductGenerator ...@@ -825,7 +825,7 @@ class CartesianProductGenerator
CartesianProductGenerator(const std::tuple<ParamGenerator<T>...>& g) CartesianProductGenerator(const std::tuple<ParamGenerator<T>...>& g)
: generators_(g) {} : generators_(g) {}
~CartesianProductGenerator() override {} ~CartesianProductGenerator() override = default;
ParamIteratorInterface<ParamType>* Begin() const override { ParamIteratorInterface<ParamType>* Begin() const override {
return new Iterator(this, generators_, false); return new Iterator(this, generators_, false);
...@@ -850,7 +850,7 @@ class CartesianProductGenerator ...@@ -850,7 +850,7 @@ class CartesianProductGenerator
current_(is_end ? end_ : begin_) { current_(is_end ? end_ : begin_) {
ComputeCurrentValue(); ComputeCurrentValue();
} }
~IteratorImpl() override {} ~IteratorImpl() override = default;
const ParamGeneratorInterface<ParamType>* BaseGenerator() const override { const ParamGeneratorInterface<ParamType>* BaseGenerator() const override {
return base_; return base_;
...@@ -969,7 +969,7 @@ class ParamGeneratorConverter : public ParamGeneratorInterface<To> { ...@@ -969,7 +969,7 @@ class ParamGeneratorConverter : public ParamGeneratorInterface<To> {
: base_(base), it_(it), end_(end) { : base_(base), it_(it), end_(end) {
if (it_ != end_) value_ = std::make_shared<To>(static_cast<To>(*it_)); if (it_ != end_) value_ = std::make_shared<To>(static_cast<To>(*it_));
} }
~Iterator() override {} ~Iterator() override = default;
const ParamGeneratorInterface<To>* BaseGenerator() const override { const ParamGeneratorInterface<To>* BaseGenerator() const override {
return base_; return base_;
......
...@@ -161,10 +161,10 @@ ...@@ -161,10 +161,10 @@
// NOT define them. // NOT define them.
// //
// These macros are public so that portable tests can be written. // These macros are public so that portable tests can be written.
// Such tests typically surround code using a feature with an #if // Such tests typically surround code using a feature with an #ifdef
// which controls that code. For example: // which controls that code. For example:
// //
// #if GTEST_HAS_DEATH_TEST // #ifdef GTEST_HAS_DEATH_TEST
// EXPECT_DEATH(DoSomethingDeadly()); // EXPECT_DEATH(DoSomethingDeadly());
// #endif // #endif
// //
...@@ -178,6 +178,7 @@ ...@@ -178,6 +178,7 @@
// define themselves. // define themselves.
// GTEST_USES_SIMPLE_RE - our own simple regex is used; // GTEST_USES_SIMPLE_RE - our own simple regex is used;
// the above RE\b(s) are mutually exclusive. // the above RE\b(s) are mutually exclusive.
// GTEST_HAS_ABSL - Google Test is compiled with Abseil.
// Misc public macros // Misc public macros
// ------------------ // ------------------
...@@ -202,16 +203,25 @@ ...@@ -202,16 +203,25 @@
// is suppressed. // is suppressed.
// GTEST_INTERNAL_HAS_ANY - for enabling UniversalPrinter<std::any> or // GTEST_INTERNAL_HAS_ANY - for enabling UniversalPrinter<std::any> or
// UniversalPrinter<absl::any> specializations. // UniversalPrinter<absl::any> specializations.
// Always defined to 0 or 1.
// GTEST_INTERNAL_HAS_OPTIONAL - for enabling UniversalPrinter<std::optional> // GTEST_INTERNAL_HAS_OPTIONAL - for enabling UniversalPrinter<std::optional>
// or // or
// UniversalPrinter<absl::optional> // UniversalPrinter<absl::optional>
// specializations. // specializations. Always defined to 0 or 1.
// GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher<std::string_view> or // GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher<std::string_view> or
// Matcher<absl::string_view> // Matcher<absl::string_view>
// specializations. // specializations. Always defined to 0 or 1.
// GTEST_INTERNAL_HAS_VARIANT - for enabling UniversalPrinter<std::variant> or // GTEST_INTERNAL_HAS_VARIANT - for enabling UniversalPrinter<std::variant> or
// UniversalPrinter<absl::variant> // UniversalPrinter<absl::variant>
// specializations. // specializations. 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_CAN_STREAM_RESULTS_ - Always defined to 0 or 1.
// GTEST_HAS_ALT_PATH_SEP_ - Always defined to 0 or 1.
// GTEST_WIDE_STRING_USES_UTF16_ - Always defined to 0 or 1.
// GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ - Always defined to 0 or 1.
// GTEST_HAS_DOWNCAST_ - Always defined to 0 or 1.
// GTEST_HAS_NOTIFICATION_- Always defined to 0 or 1.
// //
// Synchronization: // Synchronization:
// Mutex, MutexLock, ThreadLocal, GetThreadCount() // Mutex, MutexLock, ThreadLocal, GetThreadCount()
...@@ -303,7 +313,19 @@ ...@@ -303,7 +313,19 @@
#include "gtest/internal/custom/gtest-port.h" #include "gtest/internal/custom/gtest-port.h"
#include "gtest/internal/gtest-port-arch.h" #include "gtest/internal/gtest-port-arch.h"
#if GTEST_HAS_ABSL #ifndef GTEST_HAS_DOWNCAST_
#define GTEST_HAS_DOWNCAST_ 0
#endif
#ifndef GTEST_HAS_MUTEX_AND_THREAD_LOCAL_
#define GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ 0
#endif
#ifndef GTEST_HAS_NOTIFICATION_
#define GTEST_HAS_NOTIFICATION_ 0
#endif
#ifdef GTEST_HAS_ABSL
#include "absl/flags/declare.h" #include "absl/flags/declare.h"
#include "absl/flags/flag.h" #include "absl/flags/flag.h"
#include "absl/flags/reflection.h" #include "absl/flags/reflection.h"
...@@ -361,13 +383,13 @@ ...@@ -361,13 +383,13 @@
// Brings in definitions for functions used in the testing::internal::posix // Brings in definitions for functions used in the testing::internal::posix
// namespace (read, write, close, chdir, isatty, stat). We do not currently // namespace (read, write, close, chdir, isatty, stat). We do not currently
// use them on Windows Mobile. // use them on Windows Mobile.
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#if !GTEST_OS_WINDOWS_MOBILE #ifndef GTEST_OS_WINDOWS_MOBILE
#include <direct.h> #include <direct.h>
#include <io.h> #include <io.h>
#endif #endif
// In order to avoid having to include <windows.h>, use forward declaration // In order to avoid having to include <windows.h>, use forward declaration
#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR) #if defined(GTEST_OS_WINDOWS_MINGW) && !defined(__MINGW64_VERSION_MAJOR)
// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two // MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
// separate (equivalent) structs, instead of using typedef // separate (equivalent) structs, instead of using typedef
typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION; typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
...@@ -377,7 +399,7 @@ typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -377,7 +399,7 @@ typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION. // WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#endif #endif
#elif GTEST_OS_XTENSA #elif defined(GTEST_OS_XTENSA)
#include <unistd.h> #include <unistd.h>
// Xtensa toolchains define strcasecmp in the string.h header instead of // Xtensa toolchains define strcasecmp in the string.h header instead of
// strings.h. string.h is already included. // strings.h. string.h is already included.
...@@ -389,7 +411,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -389,7 +411,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#include <unistd.h> #include <unistd.h>
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_OS_LINUX_ANDROID #ifdef GTEST_OS_LINUX_ANDROID
// Used to define __ANDROID_API__ matching the target NDK API level. // Used to define __ANDROID_API__ matching the target NDK API level.
#include <android/api-level.h> // NOLINT #include <android/api-level.h> // NOLINT
#endif #endif
...@@ -397,17 +419,21 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -397,17 +419,21 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Defines this to true if and only if Google Test can use POSIX regular // Defines this to true if and only if Google Test can use POSIX regular
// expressions. // expressions.
#ifndef GTEST_HAS_POSIX_RE #ifndef GTEST_HAS_POSIX_RE
#if GTEST_OS_LINUX_ANDROID #ifdef GTEST_OS_LINUX_ANDROID
// On Android, <regex.h> is only available starting with Gingerbread. // On Android, <regex.h> is only available starting with Gingerbread.
#define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9) #define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
#else #else
#define GTEST_HAS_POSIX_RE \ #if !(defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_XTENSA) || \
!(GTEST_OS_WINDOWS || GTEST_OS_XTENSA || GTEST_OS_QURT) defined(GTEST_OS_QURT))
#define GTEST_HAS_POSIX_RE 1
#else
#define GTEST_HAS_POSIX_RE 0
#endif #endif
#endif // GTEST_OS_LINUX_ANDROID
#endif #endif
// Select the regular expression implementation. // Select the regular expression implementation.
#if GTEST_HAS_ABSL #ifdef GTEST_HAS_ABSL
// When using Abseil, RE2 is required. // When using Abseil, RE2 is required.
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "re2/re2.h" #include "re2/re2.h"
...@@ -443,8 +469,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -443,8 +469,12 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// cleanups prior to that. To reliably check for C++ exception availability with // cleanups prior to that. To reliably check for C++ exception availability with
// clang, check for // clang, check for
// __EXCEPTIONS && __has_feature(cxx_exceptions). // __EXCEPTIONS && __has_feature(cxx_exceptions).
#define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions)) #if defined(__EXCEPTIONS) && __EXCEPTIONS && __has_feature(cxx_exceptions)
#elif defined(__GNUC__) && __EXCEPTIONS #define GTEST_HAS_EXCEPTIONS 1
#else
#define GTEST_HAS_EXCEPTIONS 0
#endif
#elif defined(__GNUC__) && defined(__EXCEPTIONS) && __EXCEPTIONS
// gcc defines __EXCEPTIONS to 1 if and only if exceptions are enabled. // gcc defines __EXCEPTIONS to 1 if and only if exceptions are enabled.
#define GTEST_HAS_EXCEPTIONS 1 #define GTEST_HAS_EXCEPTIONS 1
#elif defined(__SUNPRO_CC) #elif defined(__SUNPRO_CC)
...@@ -452,7 +482,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -452,7 +482,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// detecting whether they are enabled or not. Therefore, we assume that // detecting whether they are enabled or not. Therefore, we assume that
// they are enabled unless the user tells us otherwise. // they are enabled unless the user tells us otherwise.
#define GTEST_HAS_EXCEPTIONS 1 #define GTEST_HAS_EXCEPTIONS 1
#elif defined(__IBMCPP__) && __EXCEPTIONS #elif defined(__IBMCPP__) && defined(__EXCEPTIONS) && __EXCEPTIONS
// xlC defines __EXCEPTIONS to 1 if and only if exceptions are enabled. // xlC defines __EXCEPTIONS to 1 if and only if exceptions are enabled.
#define GTEST_HAS_EXCEPTIONS 1 #define GTEST_HAS_EXCEPTIONS 1
#elif defined(__HP_aCC) #elif defined(__HP_aCC)
...@@ -472,11 +502,14 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -472,11 +502,14 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Cygwin 1.7 and below doesn't support ::std::wstring. // Cygwin 1.7 and below doesn't support ::std::wstring.
// Solaris' libc++ doesn't support it either. Android has // Solaris' libc++ doesn't support it either. Android has
// no support for it at least as recent as Froyo (2.2). // no support for it at least as recent as Froyo (2.2).
#define GTEST_HAS_STD_WSTRING \ #if (!(defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_CYGWIN) || \
(!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ defined(GTEST_OS_SOLARIS) || defined(GTEST_OS_HAIKU) || \
GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266 || \ defined(GTEST_OS_ESP32) || defined(GTEST_OS_ESP8266) || \
GTEST_OS_XTENSA || GTEST_OS_QURT)) defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT)))
#define GTEST_HAS_STD_WSTRING 1
#else
#define GTEST_HAS_STD_WSTRING 0
#endif
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
#ifndef GTEST_HAS_FILE_SYSTEM #ifndef GTEST_HAS_FILE_SYSTEM
...@@ -506,7 +539,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -506,7 +539,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// -frtti -fno-exceptions, the build fails at link time with undefined // -frtti -fno-exceptions, the build fails at link time with undefined
// references to __cxa_bad_typeid. Note sure if STL or toolchain bug, // references to __cxa_bad_typeid. Note sure if STL or toolchain bug,
// so disable RTTI when detected. // so disable RTTI when detected.
#if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && !defined(__EXCEPTIONS) #if defined(GTEST_OS_LINUX_ANDROID) && defined(_STLPORT_MAJOR) && \
!defined(__EXCEPTIONS)
#define GTEST_HAS_RTTI 0 #define GTEST_HAS_RTTI 0
#else #else
#define GTEST_HAS_RTTI 1 #define GTEST_HAS_RTTI 1
...@@ -554,11 +588,17 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -554,11 +588,17 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// //
// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0 // To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
// to your compiler flags. // to your compiler flags.
#define GTEST_HAS_PTHREAD \ #if (defined(GTEST_OS_LINUX) || defined(GTEST_OS_MAC) || \
(GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX || GTEST_OS_QNX || \ defined(GTEST_OS_HPUX) || defined(GTEST_OS_QNX) || \
GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ defined(GTEST_OS_FREEBSD) || defined(GTEST_OS_NACL) || \
GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_OPENBSD || \ defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \
GTEST_OS_HAIKU || GTEST_OS_GNU_HURD) defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \
defined(GTEST_OS_OPENBSD) || defined(GTEST_OS_HAIKU) || \
defined(GTEST_OS_GNU_HURD))
#define GTEST_HAS_PTHREAD 1
#else
#define GTEST_HAS_PTHREAD 0
#endif
#endif // GTEST_HAS_PTHREAD #endif // GTEST_HAS_PTHREAD
#if GTEST_HAS_PTHREAD #if GTEST_HAS_PTHREAD
...@@ -577,8 +617,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -577,8 +617,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#ifndef GTEST_HAS_CLONE #ifndef GTEST_HAS_CLONE
// The user didn't tell us, so we need to figure it out. // The user didn't tell us, so we need to figure it out.
#if GTEST_OS_LINUX && !defined(__ia64__) #if defined(GTEST_OS_LINUX) && !defined(__ia64__)
#if GTEST_OS_LINUX_ANDROID #if defined(GTEST_OS_LINUX_ANDROID)
// On Android, clone() became available at different API levels for each 32-bit // On Android, clone() became available at different API levels for each 32-bit
// architecture. // architecture.
#if defined(__LP64__) || (defined(__arm__) && __ANDROID_API__ >= 9) || \ #if defined(__LP64__) || (defined(__arm__) && __ANDROID_API__ >= 9) || \
...@@ -603,9 +643,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -603,9 +643,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// By default, we assume that stream redirection is supported on all // By default, we assume that stream redirection is supported on all
// platforms except known mobile / embedded ones. Also, if the port doesn't have // platforms except known mobile / embedded ones. Also, if the port doesn't have
// a file system, stream redirection is not supported. // a file system, stream redirection is not supported.
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA || \ defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \
GTEST_OS_QURT || !GTEST_HAS_FILE_SYSTEM defined(GTEST_OS_XTENSA) || defined(GTEST_OS_QURT) || \
!GTEST_HAS_FILE_SYSTEM
#define GTEST_HAS_STREAM_REDIRECTION 0 #define GTEST_HAS_STREAM_REDIRECTION 0
#else #else
#define GTEST_HAS_STREAM_REDIRECTION 1 #define GTEST_HAS_STREAM_REDIRECTION 1
...@@ -614,13 +655,16 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -614,13 +655,16 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Determines whether to support death tests. // Determines whether to support death tests.
// pops up a dialog window that cannot be suppressed programmatically. // pops up a dialog window that cannot be suppressed programmatically.
#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ #if (defined(GTEST_OS_LINUX) || defined(GTEST_OS_CYGWIN) || \
(GTEST_OS_MAC && !GTEST_OS_IOS) || \ defined(GTEST_OS_SOLARIS) || \
(GTEST_OS_WINDOWS_DESKTOP && _MSC_VER) || GTEST_OS_WINDOWS_MINGW || \ (defined(GTEST_OS_MAC) && !defined(GTEST_OS_IOS)) || \
GTEST_OS_AIX || GTEST_OS_HPUX || GTEST_OS_OPENBSD || GTEST_OS_QNX || \ (defined(GTEST_OS_WINDOWS_DESKTOP) && _MSC_VER) || \
GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ defined(GTEST_OS_WINDOWS_MINGW) || defined(GTEST_OS_AIX) || \
GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_HAIKU || \ defined(GTEST_OS_HPUX) || defined(GTEST_OS_OPENBSD) || \
GTEST_OS_GNU_HURD) defined(GTEST_OS_QNX) || defined(GTEST_OS_FREEBSD) || \
defined(GTEST_OS_NETBSD) || defined(GTEST_OS_FUCHSIA) || \
defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \
defined(GTEST_OS_HAIKU) || defined(GTEST_OS_GNU_HURD))
// Death tests require a file system to work properly. // Death tests require a file system to work properly.
#if GTEST_HAS_FILE_SYSTEM #if GTEST_HAS_FILE_SYSTEM
#define GTEST_HAS_DEATH_TEST 1 #define GTEST_HAS_DEATH_TEST 1
...@@ -638,14 +682,21 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -638,14 +682,21 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#endif #endif
// Determines whether the system compiler uses UTF-16 for encoding wide strings. // Determines whether the system compiler uses UTF-16 for encoding wide strings.
#define GTEST_WIDE_STRING_USES_UTF16_ \ #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_CYGWIN) || \
(GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_AIX || GTEST_OS_OS2) defined(GTEST_OS_AIX) || defined(GTEST_OS_OS2)
#define GTEST_WIDE_STRING_USES_UTF16_ 1
#else
#define GTEST_WIDE_STRING_USES_UTF16_ 0
#endif
// Determines whether test results can be streamed to a socket. // Determines whether test results can be streamed to a socket.
#if GTEST_OS_LINUX || GTEST_OS_GNU_KFREEBSD || GTEST_OS_DRAGONFLY || \ #if defined(GTEST_OS_LINUX) || defined(GTEST_OS_GNU_KFREEBSD) || \
GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_OPENBSD || \ defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \
GTEST_OS_GNU_HURD defined(GTEST_OS_NETBSD) || defined(GTEST_OS_OPENBSD) || \
defined(GTEST_OS_GNU_HURD) || defined(GTEST_OS_MAC)
#define GTEST_CAN_STREAM_RESULTS_ 1 #define GTEST_CAN_STREAM_RESULTS_ 1
#else
#define GTEST_CAN_STREAM_RESULTS_ 0
#endif #endif
// Defines some utility macros. // Defines some utility macros.
...@@ -759,14 +810,16 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -759,14 +810,16 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#ifndef GTEST_IS_THREADSAFE #ifndef GTEST_IS_THREADSAFE
#define GTEST_IS_THREADSAFE \ #if (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \
(GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \ (defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \
(GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) || \ !defined(GTEST_OS_WINDOWS_RT)) || \
GTEST_HAS_PTHREAD) GTEST_HAS_PTHREAD)
#define GTEST_IS_THREADSAFE 1
#endif
#endif // GTEST_IS_THREADSAFE #endif // GTEST_IS_THREADSAFE
#if GTEST_IS_THREADSAFE #ifdef GTEST_IS_THREADSAFE
// Some platforms don't support including these threading related headers. // Some platforms don't support including these threading related headers.
#include <condition_variable> // NOLINT #include <condition_variable> // NOLINT
#include <mutex> // NOLINT #include <mutex> // NOLINT
...@@ -808,7 +861,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; ...@@ -808,7 +861,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Ask the compiler not to perform tail call optimization inside // Ask the compiler not to perform tail call optimization inside
// the marked function. // the marked function.
#define GTEST_NO_TAIL_CALL_ __attribute__((disable_tail_calls)) #define GTEST_NO_TAIL_CALL_ __attribute__((disable_tail_calls))
#elif __GNUC__ #elif defined(__GNUC__) && !defined(__NVCOMPILER)
#define GTEST_NO_TAIL_CALL_ \ #define GTEST_NO_TAIL_CALL_ \
__attribute__((optimize("no-optimize-sibling-calls"))) __attribute__((optimize("no-optimize-sibling-calls")))
#else #else
...@@ -881,7 +934,7 @@ GTEST_API_ bool IsTrue(bool condition); ...@@ -881,7 +934,7 @@ GTEST_API_ bool IsTrue(bool condition);
// Defines RE. // Defines RE.
#if 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`, `absl::string_view`, and `const
...@@ -906,7 +959,9 @@ class GTEST_API_ RE { ...@@ -906,7 +959,9 @@ class GTEST_API_ RE {
RE2 regex_; RE2 regex_;
}; };
#elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE #elif defined(GTEST_USES_POSIX_RE) || defined(GTEST_USES_SIMPLE_RE)
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */)
// 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.
...@@ -923,7 +978,7 @@ class GTEST_API_ RE { ...@@ -923,7 +978,7 @@ class GTEST_API_ RE {
~RE(); ~RE();
// Returns the string representation of the regex. // Returns the string representation of the regex.
const char* pattern() const { return pattern_; } const char* pattern() const { return pattern_.c_str(); }
// FullMatch(str, re) returns true if and only if regular expression re // FullMatch(str, re) returns true if and only if regular expression re
// matches the entire str. // matches the entire str.
...@@ -941,21 +996,21 @@ class GTEST_API_ RE { ...@@ -941,21 +996,21 @@ class GTEST_API_ RE {
private: private:
void Init(const char* regex); void Init(const char* regex);
const char* pattern_; std::string pattern_;
bool is_valid_; bool is_valid_;
#if GTEST_USES_POSIX_RE #ifdef 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(); std::string full_pattern_; // For FullMatch();
#endif #endif
}; };
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
#endif // ::testing::internal::RE implementation #endif // ::testing::internal::RE implementation
// 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
...@@ -1172,7 +1227,7 @@ GTEST_API_ std::string ReadEntireFile(FILE* file); ...@@ -1172,7 +1227,7 @@ GTEST_API_ std::string ReadEntireFile(FILE* file);
// All command line arguments. // All command line arguments.
GTEST_API_ std::vector<std::string> GetArgvs(); GTEST_API_ std::vector<std::string> GetArgvs();
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
std::vector<std::string> GetInjectableArgvs(); std::vector<std::string> GetInjectableArgvs();
// Deprecated: pass the args vector by value instead. // Deprecated: pass the args vector by value instead.
...@@ -1183,9 +1238,9 @@ void ClearInjectableArgvs(); ...@@ -1183,9 +1238,9 @@ void ClearInjectableArgvs();
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
// Defines synchronization primitives. // Defines synchronization primitives.
#if GTEST_IS_THREADSAFE #ifdef GTEST_IS_THREADSAFE
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Provides leak-safe Windows kernel handle ownership. // Provides leak-safe Windows kernel handle ownership.
// Used in death tests and in threading support. // Used in death tests and in threading support.
class GTEST_API_ AutoHandle { class GTEST_API_ AutoHandle {
...@@ -1264,7 +1319,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 ...@@ -1264,7 +1319,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
// On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD // On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD
// defined, but we don't want to use MinGW's pthreads implementation, which // defined, but we don't want to use MinGW's pthreads implementation, which
// has conformance problems with some versions of the POSIX standard. // has conformance problems with some versions of the POSIX standard.
#if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW #if GTEST_HAS_PTHREAD && !defined(GTEST_OS_WINDOWS_MINGW)
// As a C-function, ThreadFuncWithCLinkage cannot be templated itself. // As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
// Consequently, it cannot select a correct instantiation of ThreadWithParam // Consequently, it cannot select a correct instantiation of ThreadWithParam
...@@ -1273,7 +1328,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 ...@@ -1273,7 +1328,7 @@ GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
// problem. // problem.
class ThreadWithParamBase { class ThreadWithParamBase {
public: public:
virtual ~ThreadWithParamBase() {} virtual ~ThreadWithParamBase() = default;
virtual void Run() = 0; virtual void Run() = 0;
}; };
...@@ -1350,7 +1405,8 @@ class ThreadWithParam : public ThreadWithParamBase { ...@@ -1350,7 +1405,8 @@ class ThreadWithParam : public ThreadWithParamBase {
// Mutex and ThreadLocal have already been imported into the namespace. // Mutex and ThreadLocal have already been imported into the namespace.
// Nothing to do here. // Nothing to do here.
#elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT #elif defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_PHONE) && \
!defined(GTEST_OS_WINDOWS_RT)
// Mutex implements mutex on Windows platforms. It is used in conjunction // Mutex implements mutex on Windows platforms. It is used in conjunction
// with class MutexLock: // with class MutexLock:
...@@ -1734,7 +1790,7 @@ typedef GTestMutexLock MutexLock; ...@@ -1734,7 +1790,7 @@ typedef GTestMutexLock MutexLock;
// ThreadLocalValueHolderBase. // ThreadLocalValueHolderBase.
class GTEST_API_ ThreadLocalValueHolderBase { class GTEST_API_ ThreadLocalValueHolderBase {
public: public:
virtual ~ThreadLocalValueHolderBase() {} virtual ~ThreadLocalValueHolderBase() = default;
}; };
// Called by pthread to delete thread-local data stored by // Called by pthread to delete thread-local data stored by
...@@ -1806,8 +1862,8 @@ class GTEST_API_ ThreadLocal { ...@@ -1806,8 +1862,8 @@ class GTEST_API_ ThreadLocal {
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:
...@@ -1817,7 +1873,7 @@ class GTEST_API_ ThreadLocal { ...@@ -1817,7 +1873,7 @@ class GTEST_API_ ThreadLocal {
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:
...@@ -1903,7 +1959,7 @@ class GTEST_API_ ThreadLocal { ...@@ -1903,7 +1959,7 @@ class GTEST_API_ ThreadLocal {
// we cannot detect it. // we cannot detect it.
GTEST_API_ size_t GetThreadCount(); GTEST_API_ size_t GetThreadCount();
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#define GTEST_PATH_SEP_ "\\" #define GTEST_PATH_SEP_ "\\"
#define GTEST_HAS_ALT_PATH_SEP_ 1 #define GTEST_HAS_ALT_PATH_SEP_ 1
#else #else
...@@ -1980,11 +2036,11 @@ namespace posix { ...@@ -1980,11 +2036,11 @@ namespace posix {
// File system porting. // File system porting.
#if GTEST_HAS_FILE_SYSTEM #if GTEST_HAS_FILE_SYSTEM
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
typedef struct _stat StatStruct; typedef struct _stat StatStruct;
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); } inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
// time and thus not defined there. // time and thus not defined there.
...@@ -1995,7 +2051,7 @@ inline int RmDir(const char* dir) { return _rmdir(dir); } ...@@ -1995,7 +2051,7 @@ inline int RmDir(const char* dir) { return _rmdir(dir); }
inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; } inline bool IsDir(const StatStruct& st) { return (_S_IFDIR & st.st_mode) != 0; }
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
#elif GTEST_OS_ESP8266 #elif defined(GTEST_OS_ESP8266)
typedef struct stat StatStruct; typedef struct stat StatStruct;
inline int FileNo(FILE* file) { return fileno(file); } inline int FileNo(FILE* file) { return fileno(file); }
...@@ -2012,7 +2068,7 @@ typedef struct stat StatStruct; ...@@ -2012,7 +2068,7 @@ typedef struct stat StatStruct;
inline int FileNo(FILE* file) { return fileno(file); } inline int FileNo(FILE* file) { return fileno(file); }
inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
#if GTEST_OS_QURT #ifdef GTEST_OS_QURT
// QuRT doesn't support any directory functions, including rmdir // QuRT doesn't support any directory functions, including rmdir
inline int RmDir(const char*) { return 0; } inline int RmDir(const char*) { return 0; }
#else #else
...@@ -2025,17 +2081,17 @@ inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } ...@@ -2025,17 +2081,17 @@ inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
// Other functions with a different name on Windows. // Other functions with a different name on Windows.
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#ifdef __BORLANDC__ #ifdef __BORLANDC__
inline int DoIsATTY(int fd) { return isatty(fd); } inline int DoIsATTY(int fd) { return isatty(fd); }
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); }
#else // !__BORLANDC__ #else // !__BORLANDC__
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_ZOS || GTEST_OS_IOS || \ #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_ZOS) || \
GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || defined(ESP_PLATFORM) defined(GTEST_OS_IOS) || defined(GTEST_OS_WINDOWS_PHONE) || \
defined(GTEST_OS_WINDOWS_RT) || defined(ESP_PLATFORM)
inline int DoIsATTY(int /* fd */) { return 0; } inline int DoIsATTY(int /* fd */) { return 0; }
#else #else
inline int DoIsATTY(int fd) { return _isatty(fd); } inline int DoIsATTY(int fd) { return _isatty(fd); }
...@@ -2043,24 +2099,14 @@ inline int DoIsATTY(int fd) { return _isatty(fd); } ...@@ -2043,24 +2099,14 @@ 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); }
#endif // __BORLANDC__ #endif // __BORLANDC__
#elif GTEST_OS_ESP8266
inline int DoIsATTY(int fd) { return isatty(fd); }
inline int StrCaseCmp(const char* s1, const char* s2) {
return strcasecmp(s1, s2);
}
inline char* StrDup(const char* src) { return strdup(src); }
#else #else
inline int DoIsATTY(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 strcasecmp(s1, s2); return strcasecmp(s1, s2);
} }
inline char* StrDup(const char* src) { return strdup(src); }
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
...@@ -2083,13 +2129,13 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_() ...@@ -2083,13 +2129,13 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
// StrError() aren't needed on Windows CE at this time and thus not // StrError() aren't needed on Windows CE at this time and thus not
// defined there. // defined there.
#if GTEST_HAS_FILE_SYSTEM #if GTEST_HAS_FILE_SYSTEM
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ #if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_WINDOWS_PHONE) && \
!GTEST_OS_WINDOWS_RT && !GTEST_OS_ESP8266 && !GTEST_OS_XTENSA && \ !defined(GTEST_OS_WINDOWS_RT) && !defined(GTEST_OS_ESP8266) && \
!GTEST_OS_QURT !defined(GTEST_OS_XTENSA) && !defined(GTEST_OS_QURT)
inline int ChDir(const char* dir) { return chdir(dir); } inline int ChDir(const char* dir) { return chdir(dir); }
#endif #endif
inline FILE* FOpen(const char* path, const char* mode) { inline FILE* FOpen(const char* path, const char* mode) {
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW #if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MINGW)
struct wchar_codecvt : public std::codecvt<wchar_t, char, std::mbstate_t> {}; struct wchar_codecvt : public std::codecvt<wchar_t, char, std::mbstate_t> {};
std::wstring_convert<wchar_codecvt> converter; std::wstring_convert<wchar_codecvt> converter;
std::wstring wide_path = converter.from_bytes(path); std::wstring wide_path = converter.from_bytes(path);
...@@ -2099,14 +2145,14 @@ inline FILE* FOpen(const char* path, const char* mode) { ...@@ -2099,14 +2145,14 @@ inline FILE* FOpen(const char* path, const char* mode) {
return fopen(path, mode); return fopen(path, mode);
#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW
} }
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT)
inline FILE* FReopen(const char* path, const char* mode, FILE* stream) { inline FILE* FReopen(const char* path, const char* mode, FILE* stream) {
return freopen(path, mode, stream); return freopen(path, mode, stream);
} }
inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT
inline int FClose(FILE* fp) { return fclose(fp); } inline int FClose(FILE* fp) { return fclose(fp); }
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT)
inline int Read(int fd, void* buf, unsigned int count) { inline int Read(int fd, void* buf, unsigned int count) {
return static_cast<int>(read(fd, buf, count)); return static_cast<int>(read(fd, buf, count));
} }
...@@ -2117,14 +2163,14 @@ inline int Close(int fd) { return close(fd); } ...@@ -2117,14 +2163,14 @@ inline int Close(int fd) { return close(fd); }
#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT
#endif // GTEST_HAS_FILE_SYSTEM #endif // GTEST_HAS_FILE_SYSTEM
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #if !defined(GTEST_OS_WINDOWS_MOBILE) && !defined(GTEST_OS_QURT)
inline const char* StrError(int errnum) { return strerror(errnum); } inline const char* StrError(int errnum) { return strerror(errnum); }
#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT #endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_QURT
inline const char* GetEnv(const char* name) { inline const char* GetEnv(const char* name) {
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA || \ defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \
GTEST_OS_QURT defined(GTEST_OS_QURT)
// We are on an embedded platform, which has no environment variables. // We are on an embedded platform, which has no environment variables.
static_cast<void>(name); // To prevent 'unused argument' warning. static_cast<void>(name); // To prevent 'unused argument' warning.
return nullptr; return nullptr;
...@@ -2140,7 +2186,7 @@ inline const char* GetEnv(const char* name) { ...@@ -2140,7 +2186,7 @@ inline const char* GetEnv(const char* name) {
GTEST_DISABLE_MSC_DEPRECATED_POP_() GTEST_DISABLE_MSC_DEPRECATED_POP_()
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
// Windows CE has no C library. The abort() function is used in // Windows CE has no C library. The abort() function is used in
// several places in Google Test. This implementation provides a reasonable // several places in Google Test. This implementation provides a reasonable
// imitation of standard behaviour. // imitation of standard behaviour.
...@@ -2156,7 +2202,7 @@ GTEST_DISABLE_MSC_DEPRECATED_POP_() ...@@ -2156,7 +2202,7 @@ GTEST_DISABLE_MSC_DEPRECATED_POP_()
// MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate // MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate
// function in order to achieve that. We use macro definition here because // function in order to achieve that. We use macro definition here because
// snprintf is a variadic function. // snprintf is a variadic function.
#if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE #if defined(_MSC_VER) && !defined(GTEST_OS_WINDOWS_MOBILE)
// MSVC 2005 and above support variadic macros. // MSVC 2005 and above support variadic macros.
#define GTEST_SNPRINTF_(buffer, size, format, ...) \ #define GTEST_SNPRINTF_(buffer, size, format, ...) \
_snprintf_s(buffer, size, size, format, __VA_ARGS__) _snprintf_s(buffer, size, size, format, __VA_ARGS__)
...@@ -2229,7 +2275,7 @@ using TimeInMillis = int64_t; // Represents time in milliseconds. ...@@ -2229,7 +2275,7 @@ using TimeInMillis = int64_t; // Represents time in milliseconds.
#endif // !defined(GTEST_FLAG) #endif // !defined(GTEST_FLAG)
// Pick a command line flags implementation. // Pick a command line flags implementation.
#if GTEST_HAS_ABSL #ifdef GTEST_HAS_ABSL
// Macros for defining flags. // Macros for defining flags.
#define GTEST_DEFINE_bool_(name, default_val, doc) \ #define GTEST_DEFINE_bool_(name, default_val, doc) \
...@@ -2340,7 +2386,7 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val); ...@@ -2340,7 +2386,7 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val);
#endif // !defined(GTEST_INTERNAL_DEPRECATED) #endif // !defined(GTEST_INTERNAL_DEPRECATED)
#if GTEST_HAS_ABSL #ifdef GTEST_HAS_ABSL
// Always use absl::any for UniversalPrinter<> specializations if googletest // Always use absl::any for UniversalPrinter<> specializations if googletest
// is built with absl support. // is built with absl support.
#define GTEST_INTERNAL_HAS_ANY 1 #define GTEST_INTERNAL_HAS_ANY 1
...@@ -2352,7 +2398,8 @@ using Any = ::absl::any; ...@@ -2352,7 +2398,8 @@ using Any = ::absl::any;
} // namespace testing } // namespace testing
#else #else
#ifdef __has_include #ifdef __has_include
#if __has_include(<any>) && __cplusplus >= 201703L #if __has_include(<any>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L && \
(!defined(_MSC_VER) || GTEST_HAS_RTTI)
// Otherwise for C++17 and higher use std::any for UniversalPrinter<> // Otherwise for C++17 and higher use std::any for UniversalPrinter<>
// specializations. // specializations.
#define GTEST_INTERNAL_HAS_ANY 1 #define GTEST_INTERNAL_HAS_ANY 1
...@@ -2364,11 +2411,15 @@ using Any = ::std::any; ...@@ -2364,11 +2411,15 @@ using Any = ::std::any;
} // namespace testing } // namespace testing
// The case where absl is configured NOT to alias std::any is not // The case where absl is configured NOT to alias std::any is not
// supported. // supported.
#endif // __has_include(<any>) && __cplusplus >= 201703L #endif // __has_include(<any>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
#endif // __has_include #endif // __has_include
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL
#if 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 // Always use absl::optional for UniversalPrinter<> specializations if
// googletest is built with absl support. // googletest is built with absl support.
#define GTEST_INTERNAL_HAS_OPTIONAL 1 #define GTEST_INTERNAL_HAS_OPTIONAL 1
...@@ -2382,7 +2433,7 @@ inline ::absl::nullopt_t Nullopt() { return ::absl::nullopt; } ...@@ -2382,7 +2433,7 @@ inline ::absl::nullopt_t Nullopt() { return ::absl::nullopt; }
} // namespace testing } // namespace testing
#else #else
#ifdef __has_include #ifdef __has_include
#if __has_include(<optional>) && __cplusplus >= 201703L #if __has_include(<optional>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
// Otherwise for C++17 and higher use std::optional for UniversalPrinter<> // Otherwise for C++17 and higher use std::optional for UniversalPrinter<>
// specializations. // specializations.
#define GTEST_INTERNAL_HAS_OPTIONAL 1 #define GTEST_INTERNAL_HAS_OPTIONAL 1
...@@ -2396,11 +2447,15 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; } ...@@ -2396,11 +2447,15 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; }
} // namespace testing } // namespace testing
// The case where absl is configured NOT to alias std::optional is not // The case where absl is configured NOT to alias std::optional is not
// supported. // supported.
#endif // __has_include(<optional>) && __cplusplus >= 201703L #endif // __has_include(<optional>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
#endif // __has_include #endif // __has_include
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL
#if GTEST_HAS_ABSL #ifndef GTEST_INTERNAL_HAS_OPTIONAL
#define GTEST_INTERNAL_HAS_OPTIONAL 0
#endif
#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 #define GTEST_INTERNAL_HAS_STRING_VIEW 1
...@@ -2412,7 +2467,7 @@ using StringView = ::absl::string_view; ...@@ -2412,7 +2467,7 @@ using StringView = ::absl::string_view;
} // namespace testing } // namespace testing
#else #else
#ifdef __has_include #ifdef __has_include
#if __has_include(<string_view>) && __cplusplus >= 201703L #if __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 #define GTEST_INTERNAL_HAS_STRING_VIEW 1
...@@ -2424,11 +2479,16 @@ using StringView = ::std::string_view; ...@@ -2424,11 +2479,16 @@ using StringView = ::std::string_view;
} // namespace testing } // namespace testing
// The case where absl is configured NOT to alias std::string_view is not // The case where absl is configured NOT to alias std::string_view is not
// supported. // supported.
#endif // __has_include(<string_view>) && __cplusplus >= 201703L #endif // __has_include(<string_view>) && GTEST_INTERNAL_CPLUSPLUS_LANG >=
// 201703L
#endif // __has_include #endif // __has_include
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL
#if GTEST_HAS_ABSL #ifndef GTEST_INTERNAL_HAS_STRING_VIEW
#define GTEST_INTERNAL_HAS_STRING_VIEW 0
#endif
#ifdef GTEST_HAS_ABSL
// Always use absl::variant for UniversalPrinter<> specializations if googletest // Always use absl::variant for UniversalPrinter<> specializations if googletest
// is built with absl support. // is built with absl support.
#define GTEST_INTERNAL_HAS_VARIANT 1 #define GTEST_INTERNAL_HAS_VARIANT 1
...@@ -2441,7 +2501,7 @@ using Variant = ::absl::variant<T...>; ...@@ -2441,7 +2501,7 @@ using Variant = ::absl::variant<T...>;
} // namespace testing } // namespace testing
#else #else
#ifdef __has_include #ifdef __has_include
#if __has_include(<variant>) && __cplusplus >= 201703L #if __has_include(<variant>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
// Otherwise for C++17 and higher use std::variant for UniversalPrinter<> // Otherwise for C++17 and higher use std::variant for UniversalPrinter<>
// specializations. // specializations.
#define GTEST_INTERNAL_HAS_VARIANT 1 #define GTEST_INTERNAL_HAS_VARIANT 1
...@@ -2453,8 +2513,17 @@ using Variant = ::std::variant<T...>; ...@@ -2453,8 +2513,17 @@ using Variant = ::std::variant<T...>;
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
// The case where absl is configured NOT to alias std::variant is not supported. // The case where absl is configured NOT to alias std::variant is not supported.
#endif // __has_include(<variant>) && __cplusplus >= 201703L #endif // __has_include(<variant>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
#endif // __has_include #endif // __has_include
#endif // GTEST_HAS_ABSL #endif // GTEST_HAS_ABSL
#ifndef GTEST_INTERNAL_HAS_VARIANT
#define GTEST_INTERNAL_HAS_VARIANT 0
#endif
#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L
#define GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL 1
#endif
#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
...@@ -73,7 +73,7 @@ class GTEST_API_ String { ...@@ -73,7 +73,7 @@ class GTEST_API_ String {
// memory using malloc(). // memory using malloc().
static const char* CloneCString(const char* c_str); static const char* CloneCString(const char* c_str);
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
// Windows CE does not have the 'ANSI' versions of Win32 APIs. To be // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be
// able to pass strings to Win32 APIs on CE we need to convert them // able to pass strings to Win32 APIs on CE we need to convert them
// to 'Unicode', UTF-16. // to 'Unicode', UTF-16.
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
// The prime table interface. // The prime table interface.
class PrimeTable { class PrimeTable {
public: public:
virtual ~PrimeTable() {} virtual ~PrimeTable() = default;
// Returns true if and only if n is a prime number. // Returns true if and only if n is a prime number.
virtual bool IsPrime(int n) const = 0; virtual bool IsPrime(int n) const = 0;
......
...@@ -38,7 +38,6 @@ using ::testing::InitGoogleTest; ...@@ -38,7 +38,6 @@ using ::testing::InitGoogleTest;
using ::testing::Test; using ::testing::Test;
using ::testing::TestEventListeners; using ::testing::TestEventListeners;
using ::testing::TestInfo; using ::testing::TestInfo;
using ::testing::TestPartResult;
using ::testing::UnitTest; using ::testing::UnitTest;
namespace { namespace {
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
// and each test is given one combination as a parameter. // and each test is given one combination as a parameter.
// Use class definitions to test from this header. // Use class definitions to test from this header.
#include <tuple>
#include "prime_tables.h" #include "prime_tables.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace { namespace {
......
...@@ -40,7 +40,6 @@ using ::testing::Test; ...@@ -40,7 +40,6 @@ using ::testing::Test;
using ::testing::TestEventListeners; using ::testing::TestEventListeners;
using ::testing::TestInfo; using ::testing::TestInfo;
using ::testing::TestPartResult; using ::testing::TestPartResult;
using ::testing::TestSuite;
using ::testing::UnitTest; using ::testing::UnitTest;
namespace { namespace {
// Provides alternative output mode which produces minimal amount of // Provides alternative output mode which produces minimal amount of
......
...@@ -44,7 +44,7 @@ namespace testing { ...@@ -44,7 +44,7 @@ namespace testing {
// Used in EXPECT_TRUE/FALSE(assertion_result). // Used in EXPECT_TRUE/FALSE(assertion_result).
AssertionResult::AssertionResult(const AssertionResult& other) AssertionResult::AssertionResult(const AssertionResult& other)
: success_(other.success_), : success_(other.success_),
message_(other.message_.get() != nullptr message_(other.message_ != nullptr
? new ::std::string(*other.message_) ? new ::std::string(*other.message_)
: static_cast< ::std::string*>(nullptr)) {} : static_cast< ::std::string*>(nullptr)) {}
...@@ -58,7 +58,7 @@ void AssertionResult::swap(AssertionResult& other) { ...@@ -58,7 +58,7 @@ void AssertionResult::swap(AssertionResult& other) {
// Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
AssertionResult AssertionResult::operator!() const { AssertionResult AssertionResult::operator!() const {
AssertionResult negation(!success_); AssertionResult negation(!success_);
if (message_.get() != nullptr) negation << *message_; if (message_ != nullptr) negation << *message_;
return negation; return negation;
} }
......
...@@ -33,14 +33,18 @@ ...@@ -33,14 +33,18 @@
#include "gtest/gtest-death-test.h" #include "gtest/gtest-death-test.h"
#include <functional> #include <functional>
#include <memory>
#include <sstream>
#include <string>
#include <utility> #include <utility>
#include <vector>
#include "gtest/internal/custom/gtest.h" #include "gtest/internal/custom/gtest.h"
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
#if GTEST_OS_MAC #ifdef GTEST_OS_MAC
#include <crt_externs.h> #include <crt_externs.h>
#endif // GTEST_OS_MAC #endif // GTEST_OS_MAC
...@@ -48,24 +52,24 @@ ...@@ -48,24 +52,24 @@
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
#include <signal.h> #include <signal.h>
#endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
#include <stdarg.h> #include <stdarg.h>
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#include <windows.h> #include <windows.h>
#else #else
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/wait.h> #include <sys/wait.h>
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_OS_QNX #ifdef GTEST_OS_QNX
#include <spawn.h> #include <spawn.h>
#endif // GTEST_OS_QNX #endif // GTEST_OS_QNX
#if GTEST_OS_FUCHSIA #ifdef GTEST_OS_FUCHSIA
#include <lib/fdio/fd.h> #include <lib/fdio/fd.h>
#include <lib/fdio/io.h> #include <lib/fdio/io.h>
#include <lib/fdio/spawn.h> #include <lib/fdio/spawn.h>
...@@ -131,13 +135,13 @@ GTEST_DEFINE_string_( ...@@ -131,13 +135,13 @@ GTEST_DEFINE_string_(
namespace testing { namespace testing {
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
namespace internal { namespace internal {
// Valid only for fast death tests. Indicates the code is running in the // Valid only for fast death tests. Indicates the code is running in the
// child process of a fast style death test. // child process of a fast style death test.
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA #if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA)
static bool g_in_fast_death_test_child = false; static bool g_in_fast_death_test_child = false;
#endif #endif
...@@ -147,7 +151,7 @@ static bool g_in_fast_death_test_child = false; ...@@ -147,7 +151,7 @@ static bool g_in_fast_death_test_child = false;
// tests. IMPORTANT: This is an internal utility. Using it may break the // tests. IMPORTANT: This is an internal utility. Using it may break the
// implementation of death tests. User code MUST NOT use it. // implementation of death tests. User code MUST NOT use it.
bool InDeathTestChild() { bool InDeathTestChild() {
#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA)
// On Windows and Fuchsia, death tests are thread-safe regardless of the value // On Windows and Fuchsia, death tests are thread-safe regardless of the value
// of the death_test_style flag. // of the death_test_style flag.
...@@ -169,7 +173,7 @@ ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {} ...@@ -169,7 +173,7 @@ ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {}
// ExitedWithCode function-call operator. // ExitedWithCode function-call operator.
bool ExitedWithCode::operator()(int exit_status) const { bool ExitedWithCode::operator()(int exit_status) const {
#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA)
return exit_status == exit_code_; return exit_status == exit_code_;
...@@ -180,7 +184,7 @@ bool ExitedWithCode::operator()(int exit_status) const { ...@@ -180,7 +184,7 @@ bool ExitedWithCode::operator()(int exit_status) const {
#endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA #endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
} }
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA #if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA)
// KilledBySignal constructor. // KilledBySignal constructor.
KilledBySignal::KilledBySignal(int signum) : signum_(signum) {} KilledBySignal::KilledBySignal(int signum) : signum_(signum) {}
...@@ -207,7 +211,7 @@ namespace internal { ...@@ -207,7 +211,7 @@ namespace internal {
static std::string ExitSummary(int exit_code) { static std::string ExitSummary(int exit_code) {
Message m; Message m;
#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA #if defined(GTEST_OS_WINDOWS) || defined(GTEST_OS_FUCHSIA)
m << "Exited with exit status " << exit_code; m << "Exited with exit status " << exit_code;
...@@ -234,7 +238,7 @@ bool ExitedUnsuccessfully(int exit_status) { ...@@ -234,7 +238,7 @@ bool ExitedUnsuccessfully(int exit_status) {
return !ExitedWithCode(0)(exit_status); return !ExitedWithCode(0)(exit_status);
} }
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA #if !defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_FUCHSIA)
// Generates a textual failure message when a death test finds more than // Generates a textual failure message when a death test finds more than
// one thread running, or cannot determine the number of threads, prior // one thread running, or cannot determine the number of threads, prior
// to executing the given statement. It is the responsibility of the // to executing the given statement. It is the responsibility of the
...@@ -263,7 +267,7 @@ static const char kDeathTestReturned = 'R'; ...@@ -263,7 +267,7 @@ static const char kDeathTestReturned = 'R';
static const char kDeathTestThrew = 'T'; static const char kDeathTestThrew = 'T';
static const char kDeathTestInternalError = 'I'; static const char kDeathTestInternalError = 'I';
#if GTEST_OS_FUCHSIA #ifdef GTEST_OS_FUCHSIA
// File descriptor used for the pipe in the child process. // File descriptor used for the pipe in the child process.
static const int kFuchsiaReadPipeFd = 3; static const int kFuchsiaReadPipeFd = 3;
...@@ -621,7 +625,18 @@ bool DeathTestImpl::Passed(bool status_ok) { ...@@ -621,7 +625,18 @@ bool DeathTestImpl::Passed(bool status_ok) {
return success; return success;
} }
#if GTEST_OS_WINDOWS // Note: The return value points into args, so the return value's lifetime is
// bound to that of args.
std::unique_ptr<char*[]> CreateArgvFromArgs(std::vector<std::string>& args) {
auto result = std::make_unique<char*[]>(args.size() + 1);
for (size_t i = 0; i < args.size(); ++i) {
result[i] = &args[i][0];
}
result[args.size()] = nullptr; // extra null terminator
return result;
}
#ifdef GTEST_OS_WINDOWS
// WindowsDeathTest implements death tests on Windows. Due to the // WindowsDeathTest implements death tests on Windows. Due to the
// specifics of starting new processes on Windows, death tests there are // specifics of starting new processes on Windows, death tests there are
// always threadsafe, and Google Test considers the // always threadsafe, and Google Test considers the
...@@ -808,7 +823,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() { ...@@ -808,7 +823,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
return OVERSEE_TEST; return OVERSEE_TEST;
} }
#elif GTEST_OS_FUCHSIA #elif defined(GTEST_OS_FUCHSIA)
class FuchsiaDeathTest : public DeathTestImpl { class FuchsiaDeathTest : public DeathTestImpl {
public: public:
...@@ -836,36 +851,6 @@ class FuchsiaDeathTest : public DeathTestImpl { ...@@ -836,36 +851,6 @@ class FuchsiaDeathTest : public DeathTestImpl {
zx::socket stderr_socket_; zx::socket stderr_socket_;
}; };
// Utility class for accumulating command-line arguments.
class Arguments {
public:
Arguments() { args_.push_back(nullptr); }
~Arguments() {
for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
++i) {
free(*i);
}
}
void AddArgument(const char* argument) {
args_.insert(args_.end() - 1, posix::StrDup(argument));
}
template <typename Str>
void AddArguments(const ::std::vector<Str>& arguments) {
for (typename ::std::vector<Str>::const_iterator i = arguments.begin();
i != arguments.end(); ++i) {
args_.insert(args_.end() - 1, posix::StrDup(i->c_str()));
}
}
char* const* Argv() { return &args_[0]; }
int size() { return static_cast<int>(args_.size()) - 1; }
private:
std::vector<char*> args_;
};
// Waits for the child in a death test to exit, returning its exit // Waits for the child in a death test to exit, returning its exit
// status, or 0 if no child process exists. As a side effect, sets the // status, or 0 if no child process exists. As a side effect, sets the
// outcome data member. // outcome data member.
...@@ -986,10 +971,10 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { ...@@ -986,10 +971,10 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
kInternalRunDeathTestFlag + "=" + file_ + kInternalRunDeathTestFlag + "=" + file_ +
"|" + StreamableToString(line_) + "|" + "|" + StreamableToString(line_) + "|" +
StreamableToString(death_test_index); StreamableToString(death_test_index);
Arguments args;
args.AddArguments(GetInjectableArgvs()); std::vector<std::string> args = GetInjectableArgvs();
args.AddArgument(filter_flag.c_str()); args.push_back(filter_flag);
args.AddArgument(internal_flag.c_str()); args.push_back(internal_flag);
// Build the pipe for communication with the child. // Build the pipe for communication with the child.
zx_status_t status; zx_status_t status;
...@@ -1041,8 +1026,14 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() { ...@@ -1041,8 +1026,14 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
GTEST_DEATH_TEST_CHECK_(status == ZX_OK); GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
// Spawn the child process. // Spawn the child process.
status = fdio_spawn_etc(child_job, FDIO_SPAWN_CLONE_ALL, args.Argv()[0], // Note: The test component must have `fuchsia.process.Launcher` declared
args.Argv(), nullptr, 2, spawn_actions, // in its manifest. (Fuchsia integration tests require creating a
// "Fuchsia Test Component" which contains a "Fuchsia Component Manifest")
// Launching processes is a privileged operation in Fuchsia, and the
// declaration indicates that the ability is required for the component.
std::unique_ptr<char*[]> argv = CreateArgvFromArgs(args);
status = fdio_spawn_etc(child_job, FDIO_SPAWN_CLONE_ALL, argv[0], argv.get(),
nullptr, 2, spawn_actions,
child_process_.reset_and_get_address(), nullptr); child_process_.reset_and_get_address(), nullptr);
GTEST_DEATH_TEST_CHECK_(status == ZX_OK); GTEST_DEATH_TEST_CHECK_(status == ZX_OK);
...@@ -1173,34 +1164,6 @@ class ExecDeathTest : public ForkingDeathTest { ...@@ -1173,34 +1164,6 @@ class ExecDeathTest : public ForkingDeathTest {
const int line_; const int line_;
}; };
// Utility class for accumulating command-line arguments.
class Arguments {
public:
Arguments() { args_.push_back(nullptr); }
~Arguments() {
for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
++i) {
free(*i);
}
}
void AddArgument(const char* argument) {
args_.insert(args_.end() - 1, posix::StrDup(argument));
}
template <typename Str>
void AddArguments(const ::std::vector<Str>& arguments) {
for (typename ::std::vector<Str>::const_iterator i = arguments.begin();
i != arguments.end(); ++i) {
args_.insert(args_.end() - 1, posix::StrDup(i->c_str()));
}
}
char* const* Argv() { return &args_[0]; }
private:
std::vector<char*> args_;
};
// A struct that encompasses the arguments to the child process of a // A struct that encompasses the arguments to the child process of a
// threadsafe-style death test process. // threadsafe-style death test process.
struct ExecDeathTestArgs { struct ExecDeathTestArgs {
...@@ -1208,7 +1171,7 @@ struct ExecDeathTestArgs { ...@@ -1208,7 +1171,7 @@ struct ExecDeathTestArgs {
int close_fd; // File descriptor to close; the read end of a pipe int close_fd; // File descriptor to close; the read end of a pipe
}; };
#if GTEST_OS_QNX #ifdef GTEST_OS_QNX
extern "C" char** environ; extern "C" char** environ;
#else // GTEST_OS_QNX #else // GTEST_OS_QNX
// The main function for a threadsafe-style death test child process. // The main function for a threadsafe-style death test child process.
...@@ -1289,7 +1252,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { ...@@ -1289,7 +1252,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
ExecDeathTestArgs args = {argv, close_fd}; ExecDeathTestArgs args = {argv, close_fd};
pid_t child_pid = -1; pid_t child_pid = -1;
#if GTEST_OS_QNX #ifdef GTEST_OS_QNX
// Obtains the current directory and sets it to be closed in the child // Obtains the current directory and sets it to be closed in the child
// process. // process.
const int cwd_fd = open(".", O_RDONLY); const int cwd_fd = open(".", O_RDONLY);
...@@ -1320,7 +1283,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { ...@@ -1320,7 +1283,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd)); GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd));
#else // GTEST_OS_QNX #else // GTEST_OS_QNX
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
// When a SIGPROF signal is received while fork() or clone() are executing, // When a SIGPROF signal is received while fork() or clone() are executing,
// the process may hang. To avoid this, we ignore SIGPROF here and re-enable // the process may hang. To avoid this, we ignore SIGPROF here and re-enable
// it after the call to fork()/clone() is complete. // it after the call to fork()/clone() is complete.
...@@ -1367,11 +1330,10 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) { ...@@ -1367,11 +1330,10 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
#endif // GTEST_HAS_CLONE #endif // GTEST_HAS_CLONE
if (use_fork && (child_pid = fork()) == 0) { if (use_fork && (child_pid = fork()) == 0) {
ExecDeathTestChildMain(&args); _exit(ExecDeathTestChildMain(&args));
_exit(0);
} }
#endif // GTEST_OS_QNX #endif // GTEST_OS_QNX
#if GTEST_OS_LINUX #ifdef GTEST_OS_LINUX
GTEST_DEATH_TEST_CHECK_SYSCALL_( GTEST_DEATH_TEST_CHECK_SYSCALL_(
sigaction(SIGPROF, &saved_sigprof_action, nullptr)); sigaction(SIGPROF, &saved_sigprof_action, nullptr));
#endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
...@@ -1410,10 +1372,9 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { ...@@ -1410,10 +1372,9 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
StreamableToString(line_) + "|" + StreamableToString(line_) + "|" +
StreamableToString(death_test_index) + "|" + StreamableToString(death_test_index) + "|" +
StreamableToString(pipe_fd[1]); StreamableToString(pipe_fd[1]);
Arguments args; std::vector<std::string> args = GetArgvsForDeathTestChildProcess();
args.AddArguments(GetArgvsForDeathTestChildProcess()); args.push_back(filter_flag);
args.AddArgument(filter_flag.c_str()); args.push_back(internal_flag);
args.AddArgument(internal_flag.c_str());
DeathTest::set_last_death_test_message(""); DeathTest::set_last_death_test_message("");
...@@ -1422,7 +1383,8 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() { ...@@ -1422,7 +1383,8 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
// is necessary. // is necessary.
FlushInfoLog(); FlushInfoLog();
const pid_t child_pid = ExecDeathTestSpawnChild(args.Argv(), pipe_fd[0]); std::unique_ptr<char*[]> argv = CreateArgvFromArgs(args);
const pid_t child_pid = ExecDeathTestSpawnChild(argv.get(), pipe_fd[0]);
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1])); GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
set_child_pid(child_pid); set_child_pid(child_pid);
set_read_fd(pipe_fd[0]); set_read_fd(pipe_fd[0]);
...@@ -1463,14 +1425,14 @@ bool DefaultDeathTestFactory::Create(const char* statement, ...@@ -1463,14 +1425,14 @@ bool DefaultDeathTestFactory::Create(const char* statement,
} }
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
if (GTEST_FLAG_GET(death_test_style) == "threadsafe" || if (GTEST_FLAG_GET(death_test_style) == "threadsafe" ||
GTEST_FLAG_GET(death_test_style) == "fast") { GTEST_FLAG_GET(death_test_style) == "fast") {
*test = new WindowsDeathTest(statement, std::move(matcher), file, line); *test = new WindowsDeathTest(statement, std::move(matcher), file, line);
} }
#elif GTEST_OS_FUCHSIA #elif defined(GTEST_OS_FUCHSIA)
if (GTEST_FLAG_GET(death_test_style) == "threadsafe" || if (GTEST_FLAG_GET(death_test_style) == "threadsafe" ||
GTEST_FLAG_GET(death_test_style) == "fast") { GTEST_FLAG_GET(death_test_style) == "fast") {
...@@ -1497,7 +1459,7 @@ bool DefaultDeathTestFactory::Create(const char* statement, ...@@ -1497,7 +1459,7 @@ bool DefaultDeathTestFactory::Create(const char* statement,
return true; return true;
} }
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Recreates the pipe and event handles from the provided parameters, // Recreates the pipe and event handles from the provided parameters,
// signals the event, and returns a file descriptor wrapped around the pipe // signals the event, and returns a file descriptor wrapped around the pipe
// handle. This function is called in the child process only. // handle. This function is called in the child process only.
...@@ -1564,7 +1526,7 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id, ...@@ -1564,7 +1526,7 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id,
// initialized from the GTEST_FLAG(internal_run_death_test) flag if // initialized from the GTEST_FLAG(internal_run_death_test) flag if
// the flag is specified; otherwise returns NULL. // the flag is specified; otherwise returns NULL.
InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
if (GTEST_FLAG_GET(internal_run_death_test) == "") return nullptr; if (GTEST_FLAG_GET(internal_run_death_test).empty()) return nullptr;
// GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we
// can use it here. // can use it here.
...@@ -1574,7 +1536,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { ...@@ -1574,7 +1536,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
SplitString(GTEST_FLAG_GET(internal_run_death_test), '|', &fields); SplitString(GTEST_FLAG_GET(internal_run_death_test), '|', &fields);
int write_fd = -1; int write_fd = -1;
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
unsigned int parent_process_id = 0; unsigned int parent_process_id = 0;
size_t write_handle_as_size_t = 0; size_t write_handle_as_size_t = 0;
...@@ -1591,7 +1553,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() { ...@@ -1591,7 +1553,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
write_fd = GetStatusFileDescriptor(parent_process_id, write_handle_as_size_t, write_fd = GetStatusFileDescriptor(parent_process_id, write_handle_as_size_t,
event_handle_as_size_t); event_handle_as_size_t);
#elif GTEST_OS_FUCHSIA #elif defined(GTEST_OS_FUCHSIA)
if (fields.size() != 3 || !ParseNaturalNumber(fields[1], &line) || if (fields.size() != 3 || !ParseNaturalNumber(fields[1], &line) ||
!ParseNaturalNumber(fields[2], &index)) { !ParseNaturalNumber(fields[2], &index)) {
......
...@@ -31,12 +31,15 @@ ...@@ -31,12 +31,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <iterator>
#include <string>
#include "gtest/gtest-message.h" #include "gtest/gtest-message.h"
#include "gtest/internal/gtest-port.h" #include "gtest/internal/gtest-port.h"
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
#include <windows.h> #include <windows.h>
#elif GTEST_OS_WINDOWS #elif defined(GTEST_OS_WINDOWS)
#include <direct.h> #include <direct.h>
#include <io.h> #include <io.h>
#else #else
...@@ -47,7 +50,7 @@ ...@@ -47,7 +50,7 @@
#include "gtest/internal/gtest-string.h" #include "gtest/internal/gtest-string.h"
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#define GTEST_PATH_MAX_ _MAX_PATH #define GTEST_PATH_MAX_ _MAX_PATH
#elif defined(PATH_MAX) #elif defined(PATH_MAX)
#define GTEST_PATH_MAX_ PATH_MAX #define GTEST_PATH_MAX_ PATH_MAX
...@@ -62,7 +65,7 @@ ...@@ -62,7 +65,7 @@
namespace testing { namespace testing {
namespace internal { namespace internal {
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// On Windows, '\\' is the standard path separator, but many tools and the // On Windows, '\\' is the standard path separator, but many tools and the
// Windows API also accept '/' as an alternate path separator. Unless otherwise // Windows API also accept '/' as an alternate path separator. Unless otherwise
// noted, a file path can contain either kind of path separators, or a mixture // noted, a file path can contain either kind of path separators, or a mixture
...@@ -70,7 +73,7 @@ namespace internal { ...@@ -70,7 +73,7 @@ namespace internal {
const char kPathSeparator = '\\'; const char kPathSeparator = '\\';
const char kAlternatePathSeparator = '/'; const char kAlternatePathSeparator = '/';
const char kAlternatePathSeparatorString[] = "/"; const char kAlternatePathSeparatorString[] = "/";
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have a current directory. You should not use // Windows CE doesn't have a current directory. You should not use
// the current directory in tests on Windows CE, but this at least // the current directory in tests on Windows CE, but this at least
// provides a reasonable fallback. // provides a reasonable fallback.
...@@ -96,19 +99,20 @@ static bool IsPathSeparator(char c) { ...@@ -96,19 +99,20 @@ static bool IsPathSeparator(char c) {
// Returns the current working directory, or "" if unsuccessful. // Returns the current working directory, or "" if unsuccessful.
FilePath FilePath::GetCurrentDir() { FilePath FilePath::GetCurrentDir() {
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ #if defined(GTEST_OS_WINDOWS_MOBILE) || defined(GTEST_OS_WINDOWS_PHONE) || \
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32 || \ defined(GTEST_OS_WINDOWS_RT) || defined(GTEST_OS_ESP8266) || \
GTEST_OS_XTENSA || GTEST_OS_QURT defined(GTEST_OS_ESP32) || defined(GTEST_OS_XTENSA) || \
defined(GTEST_OS_QURT)
// These platforms do not have a current directory, so we just return // These platforms do not have a current directory, so we just return
// something reasonable. // something reasonable.
return FilePath(kCurrentDirectoryString); return FilePath(kCurrentDirectoryString);
#elif GTEST_OS_WINDOWS #elif defined(GTEST_OS_WINDOWS)
char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; char cwd[GTEST_PATH_MAX_ + 1] = {'\0'};
return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd); return FilePath(_getcwd(cwd, sizeof(cwd)) == nullptr ? "" : cwd);
#else #else
char cwd[GTEST_PATH_MAX_ + 1] = {'\0'}; char cwd[GTEST_PATH_MAX_ + 1] = {'\0'};
char* result = getcwd(cwd, sizeof(cwd)); char* result = getcwd(cwd, sizeof(cwd));
#if GTEST_OS_NACL #ifdef GTEST_OS_NACL
// getcwd will likely fail in NaCl due to the sandbox, so return something // getcwd will likely fail in NaCl due to the sandbox, so return something
// reasonable. The user may have provided a shim implementation for getcwd, // reasonable. The user may have provided a shim implementation for getcwd,
// however, so fallback only when failure is detected. // however, so fallback only when failure is detected.
...@@ -151,7 +155,7 @@ size_t FilePath::CalculateRootLength() const { ...@@ -151,7 +155,7 @@ size_t FilePath::CalculateRootLength() const {
const auto& path = pathname_; const auto& path = pathname_;
auto s = path.begin(); auto s = path.begin();
auto end = path.end(); auto end = path.end();
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
if (end - s >= 2 && s[1] == ':' && (end - s == 2 || IsPathSeparator(s[2])) && if (end - s >= 2 && s[1] == ':' && (end - s == 2 || IsPathSeparator(s[2])) &&
(('A' <= s[0] && s[0] <= 'Z') || ('a' <= s[0] && s[0] <= 'z'))) { (('A' <= s[0] && s[0] <= 'Z') || ('a' <= s[0] && s[0] <= 'z'))) {
// A typical absolute path like "C:\Windows" or "D:" // A typical absolute path like "C:\Windows" or "D:"
...@@ -244,7 +248,7 @@ FilePath FilePath::ConcatPaths(const FilePath& directory, ...@@ -244,7 +248,7 @@ FilePath FilePath::ConcatPaths(const FilePath& directory,
// Returns true if pathname describes something findable in the file-system, // Returns true if pathname describes something findable in the file-system,
// either a file, directory, or whatever. // either a file, directory, or whatever.
bool FilePath::FileOrDirectoryExists() const { bool FilePath::FileOrDirectoryExists() const {
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str()); LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
const DWORD attributes = GetFileAttributes(unicode); const DWORD attributes = GetFileAttributes(unicode);
delete[] unicode; delete[] unicode;
...@@ -259,7 +263,7 @@ bool FilePath::FileOrDirectoryExists() const { ...@@ -259,7 +263,7 @@ bool FilePath::FileOrDirectoryExists() const {
// that exists. // that exists.
bool FilePath::DirectoryExists() const { bool FilePath::DirectoryExists() const {
bool result = false; bool result = false;
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Don't strip off trailing separator if path is a root directory on // Don't strip off trailing separator if path is a root directory on
// Windows (like "C:\\"). // Windows (like "C:\\").
const FilePath& path(IsRootDirectory() ? *this const FilePath& path(IsRootDirectory() ? *this
...@@ -268,7 +272,7 @@ bool FilePath::DirectoryExists() const { ...@@ -268,7 +272,7 @@ bool FilePath::DirectoryExists() const {
const FilePath& path(*this); const FilePath& path(*this);
#endif #endif
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
LPCWSTR unicode = String::AnsiToUtf16(path.c_str()); LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
const DWORD attributes = GetFileAttributes(unicode); const DWORD attributes = GetFileAttributes(unicode);
delete[] unicode; delete[] unicode;
...@@ -344,14 +348,15 @@ bool FilePath::CreateDirectoriesRecursively() const { ...@@ -344,14 +348,15 @@ bool FilePath::CreateDirectoriesRecursively() const {
// directory for any reason, including if the parent directory does not // directory for any reason, including if the parent directory does not
// exist. Not named "CreateDirectory" because that's a macro on Windows. // exist. Not named "CreateDirectory" because that's a macro on Windows.
bool FilePath::CreateFolder() const { bool FilePath::CreateFolder() const {
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
FilePath removed_sep(this->RemoveTrailingPathSeparator()); FilePath removed_sep(this->RemoveTrailingPathSeparator());
LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str()); LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
int result = CreateDirectory(unicode, nullptr) ? 0 : -1; int result = CreateDirectory(unicode, nullptr) ? 0 : -1;
delete[] unicode; delete[] unicode;
#elif GTEST_OS_WINDOWS #elif defined(GTEST_OS_WINDOWS)
int result = _mkdir(pathname_.c_str()); int result = _mkdir(pathname_.c_str());
#elif GTEST_OS_ESP8266 || GTEST_OS_XTENSA || GTEST_OS_QURT #elif defined(GTEST_OS_ESP8266) || defined(GTEST_OS_XTENSA) || \
defined(GTEST_OS_QURT)
// do nothing // do nothing
int result = 0; int result = 0;
#else #else
...@@ -380,7 +385,7 @@ void FilePath::Normalize() { ...@@ -380,7 +385,7 @@ void FilePath::Normalize() {
auto out = pathname_.begin(); auto out = pathname_.begin();
auto i = pathname_.cbegin(); auto i = pathname_.cbegin();
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// UNC paths are treated specially // UNC paths are treated specially
if (pathname_.end() - i >= 3 && IsPathSeparator(*i) && if (pathname_.end() - i >= 3 && IsPathSeparator(*i) &&
IsPathSeparator(*(i + 1)) && !IsPathSeparator(*(i + 2))) { IsPathSeparator(*(i + 1)) && !IsPathSeparator(*(i + 2))) {
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
#include <netdb.h> // NOLINT #include <netdb.h> // NOLINT
#endif #endif
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#include <windows.h> // NOLINT #include <windows.h> // NOLINT
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
...@@ -93,7 +93,7 @@ GTEST_API_ TimeInMillis GetTimeInMillis(); ...@@ -93,7 +93,7 @@ GTEST_API_ TimeInMillis GetTimeInMillis();
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty); GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
// Formats the given time in milliseconds as seconds. If the input is an exact N // Formats the given time in milliseconds as seconds. If the input is an exact N
// seconds, the output has a trailing decimal point (e.g., "N." intead of "N"). // seconds, the output has a trailing decimal point (e.g., "N." instead of "N").
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms); GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
// Converts the given time in milliseconds to a date string in the ISO 8601 // Converts the given time in milliseconds to a date string in the ISO 8601
...@@ -384,7 +384,7 @@ class GTEST_API_ UnitTestOptions { ...@@ -384,7 +384,7 @@ class GTEST_API_ UnitTestOptions {
static bool FilterMatchesTest(const std::string& test_suite_name, static bool FilterMatchesTest(const std::string& test_suite_name,
const std::string& test_name); const std::string& test_name);
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
// Function for supporting the gtest_catch_exception flag. // Function for supporting the gtest_catch_exception flag.
// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
...@@ -407,8 +407,8 @@ GTEST_API_ FilePath GetCurrentExecutableName(); ...@@ -407,8 +407,8 @@ GTEST_API_ FilePath GetCurrentExecutableName();
// The role interface for getting the OS stack trace as a string. // The role interface for getting the OS stack trace as a string.
class OsStackTraceGetterInterface { class OsStackTraceGetterInterface {
public: public:
OsStackTraceGetterInterface() {} OsStackTraceGetterInterface() = default;
virtual ~OsStackTraceGetterInterface() {} virtual ~OsStackTraceGetterInterface() = default;
// Returns the current OS stack trace as an std::string. Parameters: // Returns the current OS stack trace as an std::string. Parameters:
// //
...@@ -436,13 +436,13 @@ class OsStackTraceGetterInterface { ...@@ -436,13 +436,13 @@ class OsStackTraceGetterInterface {
// A working implementation of the OsStackTraceGetterInterface interface. // A working implementation of the OsStackTraceGetterInterface interface.
class OsStackTraceGetter : public OsStackTraceGetterInterface { class OsStackTraceGetter : public OsStackTraceGetterInterface {
public: public:
OsStackTraceGetter() {} OsStackTraceGetter() = default;
std::string CurrentStackTrace(int max_depth, int skip_count) override; std::string CurrentStackTrace(int max_depth, int skip_count) override;
void UponLeavingGTest() override; void UponLeavingGTest() override;
private: private:
#if GTEST_HAS_ABSL #ifdef GTEST_HAS_ABSL
Mutex mutex_; // Protects all internal state. Mutex mutex_; // Protects all internal state.
// We save the stack frame below the frame that calls user code. // We save the stack frame below the frame that calls user code.
...@@ -672,7 +672,7 @@ class GTEST_API_ UnitTestImpl { ...@@ -672,7 +672,7 @@ class GTEST_API_ UnitTestImpl {
void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc, void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc,
internal::TearDownTestSuiteFunc tear_down_tc, internal::TearDownTestSuiteFunc tear_down_tc,
TestInfo* test_info) { TestInfo* test_info) {
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
// In order to support thread-safe death tests, we need to // In order to support thread-safe death tests, we need to
// remember the original working directory when the test program // remember the original working directory when the test program
// was first invoked. We cannot do this in RUN_ALL_TESTS(), as // was first invoked. We cannot do this in RUN_ALL_TESTS(), as
...@@ -778,7 +778,7 @@ class GTEST_API_ UnitTestImpl { ...@@ -778,7 +778,7 @@ class GTEST_API_ UnitTestImpl {
return gtest_trace_stack_.get(); return gtest_trace_stack_.get();
} }
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
void InitDeathTestSubprocessControlInfo() { void InitDeathTestSubprocessControlInfo() {
internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag()); internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
} }
...@@ -943,7 +943,7 @@ class GTEST_API_ UnitTestImpl { ...@@ -943,7 +943,7 @@ class GTEST_API_ UnitTestImpl {
// How long the test took to run, in milliseconds. // How long the test took to run, in milliseconds.
TimeInMillis elapsed_time_; TimeInMillis elapsed_time_;
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
// The decomposed components of the gtest_internal_run_death_test flag, // The decomposed components of the gtest_internal_run_death_test flag,
// parsed when RUN_ALL_TESTS is called. // parsed when RUN_ALL_TESTS is called.
std::unique_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_; std::unique_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
...@@ -967,7 +967,7 @@ inline UnitTestImpl* GetUnitTestImpl() { ...@@ -967,7 +967,7 @@ inline UnitTestImpl* GetUnitTestImpl() {
return UnitTest::GetInstance()->impl(); return UnitTest::GetInstance()->impl();
} }
#if GTEST_USES_SIMPLE_RE #ifdef GTEST_USES_SIMPLE_RE
// Internal helper functions for implementing the simple regular // Internal helper functions for implementing the simple regular
// expression matcher. // expression matcher.
...@@ -993,7 +993,7 @@ GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str); ...@@ -993,7 +993,7 @@ GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv); GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv); GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
// Returns the message describing the last system error, regardless of the // Returns the message describing the last system error, regardless of the
// platform. // platform.
...@@ -1064,7 +1064,7 @@ class StreamingListener : public EmptyTestEventListener { ...@@ -1064,7 +1064,7 @@ class StreamingListener : public EmptyTestEventListener {
// Abstract base class for writing strings to a socket. // Abstract base class for writing strings to a socket.
class AbstractSocketWriter { class AbstractSocketWriter {
public: public:
virtual ~AbstractSocketWriter() {} virtual ~AbstractSocketWriter() = default;
// Sends a string to the socket. // Sends a string to the socket.
virtual void Send(const std::string& message) = 0; virtual void Send(const std::string& message) = 0;
......
...@@ -37,8 +37,12 @@ ...@@ -37,8 +37,12 @@
#include <cstdint> #include <cstdint>
#include <fstream> #include <fstream>
#include <memory> #include <memory>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
#include <io.h> #include <io.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <windows.h> #include <windows.h>
...@@ -51,32 +55,34 @@ ...@@ -51,32 +55,34 @@
#include <unistd.h> #include <unistd.h>
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
#if GTEST_OS_MAC #ifdef GTEST_OS_MAC
#include <mach/mach_init.h> #include <mach/mach_init.h>
#include <mach/task.h> #include <mach/task.h>
#include <mach/vm_map.h> #include <mach/vm_map.h>
#endif // GTEST_OS_MAC #endif // GTEST_OS_MAC
#if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \ #if defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \
GTEST_OS_NETBSD || GTEST_OS_OPENBSD defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD) || \
defined(GTEST_OS_OPENBSD)
#include <sys/sysctl.h> #include <sys/sysctl.h>
#if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD #if defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \
defined(GTEST_OS_GNU_KFREEBSD)
#include <sys/user.h> #include <sys/user.h>
#endif #endif
#endif #endif
#if GTEST_OS_QNX #ifdef GTEST_OS_QNX
#include <devctl.h> #include <devctl.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/procfs.h> #include <sys/procfs.h>
#endif // GTEST_OS_QNX #endif // GTEST_OS_QNX
#if GTEST_OS_AIX #ifdef GTEST_OS_AIX
#include <procinfo.h> #include <procinfo.h>
#include <sys/types.h> #include <sys/types.h>
#endif // GTEST_OS_AIX #endif // GTEST_OS_AIX
#if GTEST_OS_FUCHSIA #ifdef GTEST_OS_FUCHSIA
#include <zircon/process.h> #include <zircon/process.h>
#include <zircon/syscalls.h> #include <zircon/syscalls.h>
#endif // GTEST_OS_FUCHSIA #endif // GTEST_OS_FUCHSIA
...@@ -90,7 +96,7 @@ ...@@ -90,7 +96,7 @@
namespace testing { namespace testing {
namespace internal { namespace internal {
#if GTEST_OS_LINUX || GTEST_OS_GNU_HURD #if defined(GTEST_OS_LINUX) || defined(GTEST_OS_GNU_HURD)
namespace { namespace {
template <typename T> template <typename T>
...@@ -113,7 +119,7 @@ size_t GetThreadCount() { ...@@ -113,7 +119,7 @@ size_t GetThreadCount() {
return ReadProcFileField<size_t>(filename, 19); return ReadProcFileField<size_t>(filename, 19);
} }
#elif GTEST_OS_MAC #elif defined(GTEST_OS_MAC)
size_t GetThreadCount() { size_t GetThreadCount() {
const task_t task = mach_task_self(); const task_t task = mach_task_self();
...@@ -131,20 +137,20 @@ size_t GetThreadCount() { ...@@ -131,20 +137,20 @@ size_t GetThreadCount() {
} }
} }
#elif GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \ #elif defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_FREEBSD) || \
GTEST_OS_NETBSD defined(GTEST_OS_GNU_KFREEBSD) || defined(GTEST_OS_NETBSD)
#if GTEST_OS_NETBSD #ifdef GTEST_OS_NETBSD
#undef KERN_PROC #undef KERN_PROC
#define KERN_PROC KERN_PROC2 #define KERN_PROC KERN_PROC2
#define kinfo_proc kinfo_proc2 #define kinfo_proc kinfo_proc2
#endif #endif
#if GTEST_OS_DRAGONFLY #ifdef GTEST_OS_DRAGONFLY
#define KP_NLWP(kp) (kp.kp_nthreads) #define KP_NLWP(kp) (kp.kp_nthreads)
#elif GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD #elif defined(GTEST_OS_FREEBSD) || defined(GTEST_OS_GNU_KFREEBSD)
#define KP_NLWP(kp) (kp.ki_numthreads) #define KP_NLWP(kp) (kp.ki_numthreads)
#elif GTEST_OS_NETBSD #elif defined(GTEST_OS_NETBSD)
#define KP_NLWP(kp) (kp.p_nlwps) #define KP_NLWP(kp) (kp.p_nlwps)
#endif #endif
...@@ -156,7 +162,7 @@ size_t GetThreadCount() { ...@@ -156,7 +162,7 @@ size_t GetThreadCount() {
KERN_PROC, KERN_PROC,
KERN_PROC_PID, KERN_PROC_PID,
getpid(), getpid(),
#if GTEST_OS_NETBSD #ifdef GTEST_OS_NETBSD
sizeof(struct kinfo_proc), sizeof(struct kinfo_proc),
1, 1,
#endif #endif
...@@ -169,7 +175,7 @@ size_t GetThreadCount() { ...@@ -169,7 +175,7 @@ size_t GetThreadCount() {
} }
return static_cast<size_t>(KP_NLWP(info)); return static_cast<size_t>(KP_NLWP(info));
} }
#elif GTEST_OS_OPENBSD #elif defined(GTEST_OS_OPENBSD)
// Returns the number of threads running in the process, or 0 to indicate that // Returns the number of threads running in the process, or 0 to indicate that
// we cannot detect it. // we cannot detect it.
...@@ -206,7 +212,7 @@ size_t GetThreadCount() { ...@@ -206,7 +212,7 @@ size_t GetThreadCount() {
return nthreads; return nthreads;
} }
#elif GTEST_OS_QNX #elif defined(GTEST_OS_QNX)
// Returns the number of threads running in the process, or 0 to indicate that // Returns the number of threads running in the process, or 0 to indicate that
// we cannot detect it. // we cannot detect it.
...@@ -226,7 +232,7 @@ size_t GetThreadCount() { ...@@ -226,7 +232,7 @@ size_t GetThreadCount() {
} }
} }
#elif GTEST_OS_AIX #elif defined(GTEST_OS_AIX)
size_t GetThreadCount() { size_t GetThreadCount() {
struct procentry64 entry; struct procentry64 entry;
...@@ -239,7 +245,7 @@ size_t GetThreadCount() { ...@@ -239,7 +245,7 @@ size_t GetThreadCount() {
} }
} }
#elif GTEST_OS_FUCHSIA #elif defined(GTEST_OS_FUCHSIA)
size_t GetThreadCount() { size_t GetThreadCount() {
int dummy_buffer; int dummy_buffer;
...@@ -264,7 +270,7 @@ size_t GetThreadCount() { ...@@ -264,7 +270,7 @@ size_t GetThreadCount() {
#endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS #if defined(GTEST_IS_THREADSAFE) && defined(GTEST_OS_WINDOWS)
AutoHandle::AutoHandle() : handle_(INVALID_HANDLE_VALUE) {} AutoHandle::AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
...@@ -655,7 +661,7 @@ void ThreadLocalRegistry::OnThreadLocalDestroyed( ...@@ -655,7 +661,7 @@ void ThreadLocalRegistry::OnThreadLocalDestroyed(
#endif // GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS #endif // GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
#if GTEST_USES_POSIX_RE #ifdef GTEST_USES_POSIX_RE
// Implements RE. Currently only needed for death tests. // Implements RE. Currently only needed for death tests.
...@@ -668,7 +674,6 @@ RE::~RE() { ...@@ -668,7 +674,6 @@ RE::~RE() {
regfree(&partial_regex_); regfree(&partial_regex_);
regfree(&full_regex_); regfree(&full_regex_);
} }
free(const_cast<char*>(pattern_));
} }
// Returns true if and only if regular expression re matches the entire str. // Returns true if and only if regular expression re matches the entire str.
...@@ -690,7 +695,7 @@ bool RE::PartialMatch(const char* str, const RE& re) { ...@@ -690,7 +695,7 @@ bool RE::PartialMatch(const char* str, const RE& re) {
// Initializes an RE from its string representation. // Initializes an RE from its string representation.
void RE::Init(const char* regex) { void RE::Init(const char* regex) {
pattern_ = posix::StrDup(regex); pattern_ = regex;
// Reserves enough bytes to hold the regular expression used for a // Reserves enough bytes to hold the regular expression used for a
// full match. // full match.
...@@ -718,7 +723,7 @@ void RE::Init(const char* regex) { ...@@ -718,7 +723,7 @@ void RE::Init(const char* regex) {
delete[] full_pattern; delete[] full_pattern;
} }
#elif GTEST_USES_SIMPLE_RE #elif defined(GTEST_USES_SIMPLE_RE)
// Returns true if and only if ch appears anywhere in str (excluding the // Returns true if and only if ch appears anywhere in str (excluding the
// terminating '\0' character). // terminating '\0' character).
...@@ -920,27 +925,26 @@ bool MatchRegexAnywhere(const char* regex, const char* str) { ...@@ -920,27 +925,26 @@ bool MatchRegexAnywhere(const char* regex, const char* str) {
// Implements the RE class. // Implements the RE class.
RE::~RE() { RE::~RE() = default;
free(const_cast<char*>(pattern_));
free(const_cast<char*>(full_pattern_));
}
// Returns true if and only if regular expression re matches the entire str. // Returns true if and only if regular expression re matches the entire str.
bool RE::FullMatch(const char* str, const RE& re) { bool RE::FullMatch(const char* str, const RE& re) {
return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_, str); return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_.c_str(), str);
} }
// Returns true if and only if regular expression re matches a substring of // Returns true if and only if regular expression re matches a substring of
// str (including str itself). // str (including str itself).
bool RE::PartialMatch(const char* str, const RE& re) { bool RE::PartialMatch(const char* str, const RE& re) {
return re.is_valid_ && MatchRegexAnywhere(re.pattern_, str); return re.is_valid_ && MatchRegexAnywhere(re.pattern_.c_str(), str);
} }
// Initializes an RE from its string representation. // Initializes an RE from its string representation.
void RE::Init(const char* regex) { void RE::Init(const char* regex) {
pattern_ = full_pattern_ = nullptr; full_pattern_.clear();
pattern_.clear();
if (regex != nullptr) { if (regex != nullptr) {
pattern_ = posix::StrDup(regex); pattern_ = regex;
} }
is_valid_ = ValidateRegex(regex); is_valid_ = ValidateRegex(regex);
...@@ -949,25 +953,19 @@ void RE::Init(const char* regex) { ...@@ -949,25 +953,19 @@ void RE::Init(const char* regex) {
return; return;
} }
const size_t len = strlen(regex);
// Reserves enough bytes to hold the regular expression used for a // Reserves enough bytes to hold the regular expression used for a
// full match: we need space to prepend a '^', append a '$', and // full match: we need space to prepend a '^' and append a '$'.
// terminate the string with '\0'. full_pattern_.reserve(pattern_.size() + 2);
char* buffer = static_cast<char*>(malloc(len + 3));
full_pattern_ = buffer;
if (*regex != '^') if (pattern_.empty() || pattern_.front() != '^') {
*buffer++ = '^'; // Makes sure full_pattern_ starts with '^'. full_pattern_.push_back('^'); // Makes sure full_pattern_ starts with '^'.
}
// We don't use snprintf or strncpy, as they trigger a warning when
// compiled with VC++ 8.0.
memcpy(buffer, regex, len);
buffer += len;
if (len == 0 || regex[len - 1] != '$') full_pattern_.append(pattern_);
*buffer++ = '$'; // Makes sure full_pattern_ ends with '$'.
*buffer = '\0'; if (pattern_.empty() || pattern_.back() != '$') {
full_pattern_.push_back('$'); // Makes sure full_pattern_ ends with '$'.
}
} }
#endif // GTEST_USES_POSIX_RE #endif // GTEST_USES_POSIX_RE
...@@ -1035,7 +1033,7 @@ class CapturedStream { ...@@ -1035,7 +1033,7 @@ class CapturedStream {
public: public:
// The ctor redirects the stream to a temporary file. // The ctor redirects the stream to a temporary file.
explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
#if GTEST_OS_WINDOWS #ifdef GTEST_OS_WINDOWS
char temp_dir_path[MAX_PATH + 1] = {'\0'}; // NOLINT char temp_dir_path[MAX_PATH + 1] = {'\0'}; // NOLINT
char temp_file_path[MAX_PATH + 1] = {'\0'}; // NOLINT char temp_file_path[MAX_PATH + 1] = {'\0'}; // NOLINT
...@@ -1054,7 +1052,7 @@ class CapturedStream { ...@@ -1054,7 +1052,7 @@ class CapturedStream {
// directory, so we create the temporary file in a temporary directory. // directory, so we create the temporary file in a temporary directory.
std::string name_template; std::string name_template;
#if GTEST_OS_LINUX_ANDROID #ifdef GTEST_OS_LINUX_ANDROID
// Note: Android applications are expected to call the framework's // Note: Android applications are expected to call the framework's
// Context.getExternalStorageDirectory() method through JNI to get // Context.getExternalStorageDirectory() method through JNI to get
// the location of the world-writable SD Card directory. However, // the location of the world-writable SD Card directory. However,
...@@ -1067,7 +1065,7 @@ class CapturedStream { ...@@ -1067,7 +1065,7 @@ class CapturedStream {
// '/sdcard' and other variants cannot be relied on, as they are not // '/sdcard' and other variants cannot be relied on, as they are not
// guaranteed to be mounted, or may have a delay in mounting. // guaranteed to be mounted, or may have a delay in mounting.
name_template = "/data/local/tmp/"; name_template = "/data/local/tmp/";
#elif GTEST_OS_IOS #elif defined(GTEST_OS_IOS)
char user_temp_dir[PATH_MAX + 1]; char user_temp_dir[PATH_MAX + 1];
// Documented alternative to NSTemporaryDirectory() (for obtaining creating // Documented alternative to NSTemporaryDirectory() (for obtaining creating
...@@ -1227,7 +1225,7 @@ std::string ReadEntireFile(FILE* file) { ...@@ -1227,7 +1225,7 @@ std::string ReadEntireFile(FILE* file) {
return content; return content;
} }
#if GTEST_HAS_DEATH_TEST #ifdef GTEST_HAS_DEATH_TEST
static const std::vector<std::string>* g_injected_test_argvs = static const std::vector<std::string>* g_injected_test_argvs =
nullptr; // Owned. nullptr; // Owned.
...@@ -1254,7 +1252,7 @@ void ClearInjectableArgvs() { ...@@ -1254,7 +1252,7 @@ void ClearInjectableArgvs() {
} }
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
#if GTEST_OS_WINDOWS_MOBILE #ifdef GTEST_OS_WINDOWS_MOBILE
namespace posix { namespace posix {
void Abort() { void Abort() {
DebugBreak(); DebugBreak();
......
...@@ -47,6 +47,8 @@ ...@@ -47,6 +47,8 @@
#include <cctype> #include <cctype>
#include <cstdint> #include <cstdint>
#include <cwchar> #include <cwchar>
#include <iomanip>
#include <ios>
#include <ostream> // NOLINT #include <ostream> // NOLINT
#include <string> #include <string>
#include <type_traits> #include <type_traits>
...@@ -528,7 +530,7 @@ void PrintStringTo(const ::std::string& s, ostream* os) { ...@@ -528,7 +530,7 @@ void PrintStringTo(const ::std::string& s, ostream* os) {
} }
} }
#ifdef __cpp_char8_t #ifdef __cpp_lib_char8_t
void PrintU8StringTo(const ::std::u8string& s, ostream* os) { void PrintU8StringTo(const ::std::u8string& s, ostream* os) {
PrintCharsAsStringTo(s.data(), s.size(), os); PrintCharsAsStringTo(s.data(), s.size(), os);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment