From 9ae602429c694026fce0d7f7656b101c3fc05360 Mon Sep 17 00:00:00 2001 From: JordanTheToaster Date: Mon, 7 Sep 2026 21:04:13 +0100 Subject: [PATCH] 3rdparty: Update googletest to v1.18.0 --- 3rdparty/googletest/CONTRIBUTORS | 1 + 3rdparty/googletest/README.md | 25 +- .../googlemock/include/gmock/gmock-actions.h | 118 ++-- .../include/gmock/gmock-cardinalities.h | 4 +- .../googlemock/include/gmock/gmock-matchers.h | 617 ++++++++++++------ .../include/gmock/gmock-more-matchers.h | 15 +- .../include/gmock/gmock-nice-strict.h | 18 +- .../include/gmock/gmock-spec-builders.h | 27 +- .../gmock/internal/gmock-internal-utils.h | 61 +- .../include/gmock/internal/gmock-port.h | 6 +- .../include/gmock/internal/gmock-pp.h | 142 +++- .../googlemock/src/gmock-internal-utils.cc | 4 +- .../googlemock/src/gmock-spec-builders.cc | 34 +- 3rdparty/googletest/googletest/README.md | 8 +- .../include/gtest/gtest-assertion-result.h | 40 +- .../include/gtest/gtest-death-test.h | 6 +- .../googletest/include/gtest/gtest-matchers.h | 195 ++++-- .../googletest/include/gtest/gtest-message.h | 4 +- .../googletest/include/gtest/gtest-printers.h | 201 +++--- .../googletest/include/gtest/gtest-spi.h | 4 +- .../include/gtest/gtest-test-part.h | 17 +- .../include/gtest/gtest-typed-test.h | 12 +- .../googletest/include/gtest/gtest.h | 78 ++- .../internal/gtest-death-test-internal.h | 30 +- .../include/gtest/internal/gtest-filepath.h | 2 +- .../include/gtest/internal/gtest-internal.h | 64 +- .../include/gtest/internal/gtest-param-util.h | 43 +- .../include/gtest/internal/gtest-port-arch.h | 2 + .../include/gtest/internal/gtest-port.h | 355 +++++----- .../include/gtest/internal/gtest-string.h | 4 +- .../googletest/src/gtest-internal-inl.h | 15 +- .../googletest/src/gtest-matchers.cc | 2 - .../googletest/googletest/src/gtest-port.cc | 49 +- .../googletest/src/gtest-printers.cc | 23 +- .../googletest/src/gtest-test-part.cc | 8 +- 3rdparty/googletest/googletest/src/gtest.cc | 214 +++--- 36 files changed, 1468 insertions(+), 980 deletions(-) diff --git a/3rdparty/googletest/CONTRIBUTORS b/3rdparty/googletest/CONTRIBUTORS index 77397a5b53..ccea41ea81 100644 --- a/3rdparty/googletest/CONTRIBUTORS +++ b/3rdparty/googletest/CONTRIBUTORS @@ -55,6 +55,7 @@ Russ Cox Russ Rufer Sean Mcafee Sigurður Ásgeirsson +Soyeon Kim Sverre Sundsdal Szymon Sobik Takeshi Yoshino diff --git a/3rdparty/googletest/README.md b/3rdparty/googletest/README.md index 598cf31242..b4e9b434fc 100644 --- a/3rdparty/googletest/README.md +++ b/3rdparty/googletest/README.md @@ -8,12 +8,13 @@ Our documentation is now live on GitHub Pages at https://google.github.io/googletest/. We recommend browsing the documentation on GitHub Pages rather than directly in the repository. -#### Release 1.17.0 +#### Release 1.18.0 -[Release 1.17.0](https://github.com/google/googletest/releases/tag/v1.17.0) is +[Release 1.18.0](https://github.com/google/googletest/releases/tag/v1.18.0) is now available. -The 1.17.x branch [requires at least C++17]((https://opensource.google/documentation/policies/cplusplus-support#c_language_standard). +The 1.18.x branch +[requires at least C++17](https://opensource.google/documentation/policies/cplusplus-support#c_language_standard). #### Continuous Integration @@ -43,35 +44,35 @@ More information about building GoogleTest can be found at * xUnit test framework: \ Googletest is based on the [xUnit](https://en.wikipedia.org/wiki/XUnit) - testing framework, a popular architecture for unit testing + testing framework, a popular architecture for unit testing. * Test discovery: \ Googletest automatically discovers and runs your tests, eliminating the need - to manually register your tests + to manually register your tests. * Rich set of assertions: \ Googletest provides a variety of assertions, such as equality, inequality, - exceptions, and more, making it easy to test your code + exceptions, and more, making it easy to test your code. * User-defined assertions: \ You can define your own assertions with Googletest, making it simple to - write tests that are specific to your code + write tests that are specific to your code. * Death tests: \ Googletest supports death tests, which verify that your code exits in a - certain way, making it useful for testing error-handling code + certain way, making it useful for testing error-handling code. * Fatal and non-fatal failures: \ You can specify whether a test failure should be treated as fatal or non-fatal with Googletest, allowing tests to continue running even if a - failure occurs + failure occurs. * Value-parameterized tests: \ Googletest supports value-parameterized tests, which run multiple times with different input values, making it useful for testing functions that take - different inputs + different inputs. * Type-parameterized tests: \ Googletest also supports type-parameterized tests, which run with different data types, making it useful for testing functions that work with different - data types + data types. * Various options for running tests: \ Googletest provides many options for running tests including running individual tests, running tests in a specific order and running tests in - parallel + parallel. ## Supported Platforms diff --git a/3rdparty/googletest/googlemock/include/gmock/gmock-actions.h b/3rdparty/googletest/googlemock/include/gmock/gmock-actions.h index 5fe50e3d8e..b0a6bdefe6 100644 --- a/3rdparty/googletest/googlemock/include/gmock/gmock-actions.h +++ b/3rdparty/googletest/googlemock/include/gmock/gmock-actions.h @@ -196,7 +196,7 @@ struct BuiltInDefaultValueGetter { // other type T, the built-in default T value is undefined, and the // function will abort the process. template -class BuiltInDefaultValue { +class [[nodiscard]] BuiltInDefaultValue { public: // This function returns true if and only if type T has a built-in default // value. @@ -211,7 +211,7 @@ class BuiltInDefaultValue { // This partial specialization says that we use the same built-in // default value for T and const T. template -class BuiltInDefaultValue { +class [[nodiscard]] BuiltInDefaultValue { public: static bool Exists() { return BuiltInDefaultValue::Exists(); } static T Get() { return BuiltInDefaultValue::Get(); } @@ -220,7 +220,7 @@ class BuiltInDefaultValue { // This partial specialization defines the default values for pointer // types. template -class BuiltInDefaultValue { +class [[nodiscard]] BuiltInDefaultValue { public: static bool Exists() { return true; } static T* Get() { return nullptr; } @@ -383,7 +383,7 @@ typename std::add_const::type& as_const(T& t) { // Specialized for function types below. template -class OnceAction; +class [[nodiscard]] OnceAction; // An action that can only be used once. // @@ -421,27 +421,26 @@ class OnceAction; // A less-contrived example would be an action that returns an arbitrary type, // whose &&-qualified call operator is capable of dealing with move-only types. template -class OnceAction final { +class [[nodiscard]] OnceAction final { private: // True iff we can use the given callable type (or lvalue reference) directly // via StdFunctionAdaptor. template using IsDirectlyCompatible = internal::conjunction< - // It must be possible to capture the callable in StdFunctionAdaptor. - std::is_constructible::type, Callable>, // The callable must be compatible with our signature. - internal::is_callable_r::type, - Args...>>; + internal::is_callable_r, Args...>, + // It must be possible to capture the callable in StdFunctionAdaptor. + std::is_constructible, Callable>>; // True iff we can use the given callable type via StdFunctionAdaptor once we // ignore incoming arguments. template using IsCompatibleAfterIgnoringArguments = internal::conjunction< - // It must be possible to capture the callable in a lambda. - std::is_constructible::type, Callable>, // The callable must be invocable with zero arguments, returning something // convertible to Result. - internal::is_callable_r::type>>; + internal::is_callable_r>, + // It must be possible to capture the callable in a lambda. + std::is_constructible, Callable>>; public: // Construct from a callable that is directly compatible with our mocked @@ -574,7 +573,7 @@ class OnceAction final { // // Sets the default value for type T to be foo. // DefaultValue::Set(foo); template -class DefaultValue { +class [[nodiscard]] DefaultValue { public: // Sets the default value for type T; requires T to be // copy-constructable and have a public destructor. @@ -651,7 +650,7 @@ class DefaultValue { // This partial specialization allows a user to set default values for // reference types. template -class DefaultValue { +class [[nodiscard]] DefaultValue { public: // Sets the default value for type T&. static void Set(T& x) { // NOLINT @@ -685,7 +684,7 @@ class DefaultValue { // This specialization allows DefaultValue::Get() to // compile. template <> -class DefaultValue { +class [[nodiscard]] DefaultValue { public: static bool Exists() { return true; } static void Get() {} @@ -701,7 +700,7 @@ T* DefaultValue::address_ = nullptr; // Implement this interface to define an action for function type F. template -class ActionInterface { +class [[nodiscard]] ActionInterface { public: typedef typename internal::Function::Result Result; typedef typename internal::Function::ArgumentTuple ArgumentTuple; @@ -721,7 +720,7 @@ class ActionInterface { }; template -class Action; +class [[nodiscard]] Action; // An Action is a copyable and IMMUTABLE (except by assignment) // object that represents an action to be taken when a mock function of type @@ -730,7 +729,7 @@ class Action; // can view an object implementing ActionInterface as a concrete action // (including its current state), and an Action object as a handle to it. template -class Action { +class [[nodiscard]] Action { private: using F = R(Args...); @@ -869,7 +868,7 @@ class Action { // the definition of Return(void) and SetArgumentPointee(value) for // complete examples. template -class PolymorphicAction { +class [[nodiscard]] PolymorphicAction { public: explicit PolymorphicAction(const Impl& impl) : impl_(impl) {} @@ -929,7 +928,7 @@ struct ByMoveWrapper { // The general implementation of Return(R). Specializations follow below. template -class ReturnAction final { +class [[nodiscard]] ReturnAction final { public: explicit ReturnAction(R value) : value_(std::move(value)) {} @@ -1095,7 +1094,7 @@ class ReturnAction final { // the const call operator, checking at runtime that it isn't called more than // once, since the user has declared their intent to do so by using ByMove. template -class ReturnAction> final { +class [[nodiscard]] ReturnAction> final { public: explicit ReturnAction(ByMoveWrapper wrapper) : state_(new State(std::move(wrapper.payload))) {} @@ -1122,7 +1121,7 @@ class ReturnAction> final { }; // Implements the ReturnNull() action. -class ReturnNullAction { +class [[nodiscard]] ReturnNullAction { public: // Allows ReturnNull() to be used in any pointer-returning function. In C++11 // this is enforced by returning nullptr, and in non-C++11 by asserting a @@ -1134,7 +1133,7 @@ class ReturnNullAction { }; // Implements the Return() action. -class ReturnVoidAction { +class [[nodiscard]] ReturnVoidAction { public: // Allows Return() to be used in any void-returning function. template @@ -1147,7 +1146,7 @@ class ReturnVoidAction { // in any function that returns a reference to the type of x, // regardless of the argument types. template -class ReturnRefAction { +class [[nodiscard]] ReturnRefAction { public: // Constructs a ReturnRefAction object from the reference to be returned. explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT @@ -1188,7 +1187,7 @@ class ReturnRefAction { // used in any function that returns a reference to the type of x, // regardless of the argument types. template -class ReturnRefOfCopyAction { +class [[nodiscard]] ReturnRefOfCopyAction { public: // Constructs a ReturnRefOfCopyAction object from the reference to // be returned. @@ -1229,7 +1228,7 @@ class ReturnRefOfCopyAction { // Implements the polymorphic ReturnRoundRobin(v) action, which can be // used in any function that returns the element_type of v. template -class ReturnRoundRobinAction { +class [[nodiscard]] ReturnRoundRobinAction { public: explicit ReturnRoundRobinAction(std::vector values) { GTEST_CHECK_(!values.empty()) @@ -1257,7 +1256,7 @@ class ReturnRoundRobinAction { }; // Implements the polymorphic DoDefault() action. -class DoDefaultAction { +class [[nodiscard]] DoDefaultAction { public: // This template type conversion operator allows DoDefault() to be // used in any function. @@ -1270,7 +1269,7 @@ class DoDefaultAction { // Implements the Assign action to set a given pointer referent to a // particular value. template -class AssignAction { +class [[nodiscard]] AssignAction { public: AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {} @@ -1289,7 +1288,7 @@ class AssignAction { // Implements the SetErrnoAndReturn action to simulate return from // various system calls and libc functions. template -class SetErrnoAndReturnAction { +class [[nodiscard]] SetErrnoAndReturnAction { public: SetErrnoAndReturnAction(int errno_value, T result) : errno_(errno_value), result_(result) {} @@ -1331,22 +1330,6 @@ struct InvokeMethodAction { } }; -// Implements the InvokeWithoutArgs(f) action. The template argument -// FunctionImpl is the implementation type of f, which can be either a -// function pointer or a functor. InvokeWithoutArgs(f) can be used as an -// Action as long as f's type is compatible with F. -template -struct InvokeWithoutArgsAction { - FunctionImpl function_impl; - - // Allows InvokeWithoutArgs(f) to be used as any action whose type is - // compatible with f. - template - auto operator()(const Args&...) -> decltype(function_impl()) { - return function_impl(); - } -}; - // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action. template struct InvokeMethodWithoutArgsAction { @@ -1397,7 +1380,7 @@ class IgnoreResultAction { void Perform(const ArgumentTuple& args) override { // Performs the action and ignores its result. - action_.Perform(args); + (void)action_.Perform(args); } private: @@ -1503,11 +1486,11 @@ struct WithArgsAction { }; template -class DoAllAction; +class [[nodiscard]] DoAllAction; // Base case: only a single action. template -class DoAllAction { +class [[nodiscard]] DoAllAction { public: struct UserConstructorTag {}; @@ -1561,7 +1544,7 @@ class DoAllAction { // Recursive case: support N actions by calling the initial action and then // calling through to the base class containing N-1 actions. template -class DoAllAction +class [[nodiscard]] DoAllAction : private DoAllAction { private: using Base = DoAllAction; @@ -1796,11 +1779,24 @@ struct SetArrayArgumentAction { }; template -struct DeleteArgAction { +class [[nodiscard]] DeleteArgAction { + public: template void operator()(const Args&... args) const { - delete std::get(std::tie(args...)); + DoDelete(std::get(std::tie(args...))); } + + private: + template + static void DoDelete(T* ptr) { + delete ptr; + } + + template + [[deprecated( + "DeleteArg used for a non-pointer argument, it was likely migrated " + "to a smart pointer type. This action should be removed.")]] + static void DoDelete(T&) {} }; template @@ -1866,6 +1862,13 @@ struct RethrowAction { // EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin)); typedef internal::IgnoredValue Unused; +// Deprecated single-argument DoAll. +template +GTEST_INTERNAL_DEPRECATE_AND_INLINE("Avoid using DoAll() for single actions") +typename std::decay::type DoAll(Action&& action) { + return std::forward(action); +} + // Creates an action that does actions a1, a2, ..., sequentially in // each invocation. All but the last action will have a readonly view of the // arguments. @@ -2031,10 +2034,11 @@ PolymorphicAction> SetErrnoAndReturn( // Various overloads for Invoke(). // Legacy function. -// Actions can now be implicitly constructed from callables. No need to create -// wrapper objects. // This function exists for backwards compatibility. template +GTEST_INTERNAL_DEPRECATE_AND_INLINE( + "Actions can now be implicitly constructed from callables. No need to " + "create wrapper objects using Invoke().") typename std::decay::type Invoke(FunctionImpl&& function_impl) { return std::forward(function_impl); } @@ -2049,9 +2053,11 @@ internal::InvokeMethodAction Invoke(Class* obj_ptr, // Creates an action that invokes 'function_impl' with no argument. template -internal::InvokeWithoutArgsAction::type> -InvokeWithoutArgs(FunctionImpl function_impl) { - return {std::move(function_impl)}; +GTEST_INTERNAL_DEPRECATE_AND_INLINE( + "Actions can now be implicitly constructed from zero-argument callables. " + "No need to create wrapper objects using InvokeWithoutArgs().") +std::decay_t InvokeWithoutArgs(FunctionImpl&& function_impl) { + return std::forward(function_impl); } // Creates an action that invokes the given method on the given object diff --git a/3rdparty/googletest/googlemock/include/gmock/gmock-cardinalities.h b/3rdparty/googletest/googlemock/include/gmock/gmock-cardinalities.h index 533e604f32..c88c00c441 100644 --- a/3rdparty/googletest/googlemock/include/gmock/gmock-cardinalities.h +++ b/3rdparty/googletest/googlemock/include/gmock/gmock-cardinalities.h @@ -63,7 +63,7 @@ namespace testing { // management as Cardinality objects can now be copied like plain values. // The implementation of a cardinality. -class CardinalityInterface { +class [[nodiscard]] CardinalityInterface { public: virtual ~CardinalityInterface() = default; @@ -88,7 +88,7 @@ class CardinalityInterface { // object that specifies how many times a mock function is expected to // be called. The implementation of Cardinality is just a std::shared_ptr // to const CardinalityInterface. Don't inherit from Cardinality! -class GTEST_API_ Cardinality { +class GTEST_API_ [[nodiscard]] Cardinality { public: // Constructs a null cardinality. Needed for storing Cardinality // objects in STL containers. diff --git a/3rdparty/googletest/googlemock/include/gmock/gmock-matchers.h b/3rdparty/googletest/googlemock/include/gmock/gmock-matchers.h index aa3a5eb16f..9caee1d6aa 100644 --- a/3rdparty/googletest/googlemock/include/gmock/gmock-matchers.h +++ b/3rdparty/googletest/googlemock/include/gmock/gmock-matchers.h @@ -258,7 +258,6 @@ #include #include #include -#include #include #include #include @@ -268,14 +267,15 @@ #include // NOLINT #include #include +#include #include #include #include #include "gmock/internal/gmock-internal-utils.h" -#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-pp.h" #include "gtest/gtest.h" +#include "gtest/internal/gtest-internal.h" // MSVC warning C5046 is new as of VS2017 version 15.8. #if defined(_MSC_VER) && _MSC_VER >= 1915 @@ -284,6 +284,44 @@ #define GMOCK_MAYBE_5046_ #endif +#if GTEST_HAS_RTTI +namespace proto2 { +namespace internal { + +// A type trait to essentially determine if `DynamicCastMessage` is available, +// since older versions of protobuf don't have this function. +template +static constexpr bool kHasDynamicCastMessage = false; +template +static constexpr bool kHasDynamicCastMessage< + T, std::void_t( + std::declval()))>> = true; + +// A helper function to call `DynamicCastMessage` if available, otherwise +// falling back to `dynamic_cast`. Note that we must declare this function in +// the `proto2` namespace because we need ADL to find the right +// `DynamicCastMessage`, and ADL only applies to unqualified function calls. +template +const T* DynamicCastMessageForGtest(const proto2::MessageLite* msg) { + if constexpr (kHasDynamicCastMessage) { + return DynamicCastMessage(msg); + } else { + return dynamic_cast(msg); + } +} +template +T* DynamicCastMessageForGtest(proto2::MessageLite* msg) { + if constexpr (kHasDynamicCastMessage) { + return DynamicCastMessage(msg); + } else { + return dynamic_cast(msg); + } +} + +} // namespace internal +} // namespace proto2 +#endif // GTEST_HAS_RTTI + GTEST_DISABLE_MSC_WARNINGS_PUSH_( 4251 GMOCK_MAYBE_5046_ /* class A needs to have dll-interface to be used by clients of class B */ @@ -304,7 +342,7 @@ namespace testing { // plain values. // A match result listener that stores the explanation in a string. -class StringMatchResultListener : public MatchResultListener { +class [[nodiscard]] StringMatchResultListener : public MatchResultListener { public: StringMatchResultListener() : MatchResultListener(&ss_) {} @@ -337,7 +375,7 @@ namespace internal { // Matcher but is not one yet; for example, Eq(value)) or a value (for // example, "hello"). template -class MatcherCastImpl { +class [[nodiscard]] MatcherCastImpl { public: static Matcher Cast(const M& polymorphic_matcher_or_value) { // M can be a polymorphic matcher, in which case we want to use @@ -376,11 +414,16 @@ class MatcherCastImpl { // M can't be implicitly converted to Matcher, so M isn't a polymorphic // matcher. It's a value of a type implicitly convertible to T. Use direct - // initialization to create a matcher. + // initialization or `ImplicitCastEqMatcher` to create a matcher. static Matcher CastImpl(const M& value, std::false_type /* convertible_to_matcher */, std::true_type /* convertible_to_T */) { - return Matcher(ImplicitCast_(value)); + using NoRefT = std::remove_cv_t>; + if constexpr (std::is_same_v) { + return Matcher(value); + } else { + return ImplicitCastEqMatcher>(value); + } } // M can't be implicitly converted to either Matcher or T. Attempt to use @@ -391,18 +434,18 @@ class MatcherCastImpl { // latter calls bool operator==(const Lhs& lhs, const Rhs& rhs) in the end // which might be undefined even when Rhs is implicitly convertible to Lhs // (e.g. std::pair vs. std::pair). - // - // We don't define this method inline as we need the declaration of Eq(). static Matcher CastImpl(const M& value, std::false_type /* convertible_to_matcher */, - std::false_type /* convertible_to_T */); + std::false_type /* convertible_to_T */) { + return Eq(value); + } }; // This more specialized version is used when MatcherCast()'s argument // is already a Matcher. This only compiles when type T can be // statically converted to type U. template -class MatcherCastImpl> { +class [[nodiscard]] MatcherCastImpl> { public: static Matcher Cast(const Matcher& source_matcher) { return Matcher(new Impl(source_matcher)); @@ -464,14 +507,14 @@ class MatcherCastImpl> { // This even more specialized version is used for efficiently casting // a matcher to its own type. template -class MatcherCastImpl> { +class [[nodiscard]] MatcherCastImpl> { public: static Matcher Cast(const Matcher& matcher) { return matcher; } }; // Template specialization for parameterless Matcher. template -class MatcherBaseImpl { +class [[nodiscard]] MatcherBaseImpl { public: MatcherBaseImpl() = default; @@ -484,7 +527,7 @@ class MatcherBaseImpl { // Template specialization for Matcher with parameters. template