diff options
author | Julian Eisel <julian@blender.org> | 2020-07-01 18:25:04 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-07-01 18:25:04 +0300 |
commit | 889c4ca9c26d770af02cedef972d65eb173bdb5e (patch) | |
tree | 6f46156146db1b3f09d92c6eaa1f44ba8a584ed4 /extern/gmock/include/gmock/internal/gmock-internal-utils.h | |
parent | 87df15190210eb84ef52e5dccc2932918f912da5 (diff) | |
parent | 0829cebeb024095c268f190c34daa8ae9a5a224c (diff) |
Merge branch 'asset-uuid--archived' into asset-engine--archivedasset-engine--archived
Diffstat (limited to 'extern/gmock/include/gmock/internal/gmock-internal-utils.h')
-rw-r--r-- | extern/gmock/include/gmock/internal/gmock-internal-utils.h | 248 |
1 files changed, 125 insertions, 123 deletions
diff --git a/extern/gmock/include/gmock/internal/gmock-internal-utils.h b/extern/gmock/include/gmock/internal/gmock-internal-utils.h index e2ddb05c91d..fdc049c589c 100644 --- a/extern/gmock/include/gmock/internal/gmock-internal-utils.h +++ b/extern/gmock/include/gmock/internal/gmock-internal-utils.h @@ -26,8 +26,7 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) + // Google Mock - a framework for writing C++ mock classes. // @@ -35,25 +34,42 @@ // Mock. They are subject to change without notice, so please DO NOT // USE THEM IN USER CODE. +// GOOGLETEST_CM0002 DO NOT DELETE + #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ #include <stdio.h> #include <ostream> // NOLINT #include <string> - -#include "gmock/internal/gmock-generated-internal-utils.h" +#include <type_traits> #include "gmock/internal/gmock-port.h" #include "gtest/gtest.h" namespace testing { + +template <typename> +class Matcher; + namespace internal { +// Silence MSVC C4100 (unreferenced formal parameter) and +// C4805('==': unsafe mix of type 'const int' and type 'const bool') +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable:4100) +# pragma warning(disable:4805) +#endif + +// Joins a vector of strings as if they are fields of a tuple; returns +// the joined string. +GTEST_API_ std::string JoinAsTuple(const Strings& fields); + // Converts an identifier name to a space-separated list of lower-case // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is // treated as one word. For example, both "FooBar123" and // "foo_bar_123" are converted to "foo bar 123". -GTEST_API_ string ConvertIdentifierNameToWords(const char* id_name); +GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name); // PointeeOf<Pointer>::type is the type of a value pointed to by a // Pointer, which can be either a smart pointer or a raw pointer. The @@ -80,44 +96,16 @@ inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) { template <typename Element> inline Element* GetRawPointer(Element* p) { return p; } -// This comparator allows linked_ptr to be stored in sets. -template <typename T> -struct LinkedPtrLessThan { - bool operator()(const ::testing::internal::linked_ptr<T>& lhs, - const ::testing::internal::linked_ptr<T>& rhs) const { - return lhs.get() < rhs.get(); - } -}; - -// Symbian compilation can be done with wchar_t being either a native -// type or a typedef. Using Google Mock with OpenC without wchar_t -// should require the definition of _STLP_NO_WCHAR_T. -// // MSVC treats wchar_t as a native type usually, but treats it as the // same as unsigned short when the compiler option /Zc:wchar_t- is // specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t // is a native type. -#if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \ - (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)) +#if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED) // wchar_t is a typedef. #else # define GMOCK_WCHAR_T_IS_NATIVE_ 1 #endif -// signed wchar_t and unsigned wchar_t are NOT in the C++ standard. -// Using them is a bad practice and not portable. So DON'T use them. -// -// Still, Google Mock is designed to work even if the user uses signed -// wchar_t or unsigned wchar_t (obviously, assuming the compiler -// supports them). -// -// To gcc, -// wchar_t == signed wchar_t != unsigned wchar_t == unsigned int -#ifdef __GNUC__ -// signed/unsigned wchar_t are valid types. -# define GMOCK_HAS_SIGNED_WCHAR_T_ 1 -#endif - // In what follows, we use the term "kind" to indicate whether a type // is bool, an integer type (excluding bool), a floating-point type, // or none of them. This categorization is useful for determining @@ -169,11 +157,11 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint); static_cast< ::testing::internal::TypeKind>( \ ::testing::internal::KindOf<type>::value) -// Evaluates to true iff integer type T is signed. +// Evaluates to true if and only if integer type T is signed. #define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0) // LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value -// is true iff arithmetic type From can be losslessly converted to +// is true if and only if arithmetic type From can be losslessly converted to // arithmetic type To. // // It's the user's responsibility to ensure that both From and To are @@ -182,30 +170,30 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint); // From, and kToKind is the kind of To; the value is // implementation-defined when the above pre-condition is violated. template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To> -struct LosslessArithmeticConvertibleImpl : public false_type {}; +struct LosslessArithmeticConvertibleImpl : public std::false_type {}; // Converting bool to bool is lossless. template <> struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool> - : public true_type {}; // NOLINT + : public std::true_type {}; // Converting bool to any integer type is lossless. template <typename To> struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To> - : public true_type {}; // NOLINT + : public std::true_type {}; // Converting bool to any floating-point type is lossless. template <typename To> struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To> - : public true_type {}; // NOLINT + : public std::true_type {}; // Converting an integer to bool is lossy. template <typename From> struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool> - : public false_type {}; // NOLINT + : public std::false_type {}; -// Converting an integer to another non-bool integer is lossless iff -// the target type's range encloses the source type's range. +// Converting an integer to another non-bool integer is lossless +// if and only if the target type's range encloses the source type's range. template <typename From, typename To> struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To> : public bool_constant< @@ -223,27 +211,27 @@ struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To> // the format of a floating-point number is implementation-defined. template <typename From, typename To> struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To> - : public false_type {}; // NOLINT + : public std::false_type {}; // Converting a floating-point to bool is lossy. template <typename From> struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool> - : public false_type {}; // NOLINT + : public std::false_type {}; // Converting a floating-point to an integer is lossy. template <typename From, typename To> struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To> - : public false_type {}; // NOLINT + : public std::false_type {}; // Converting a floating-point to another floating-point is lossless -// iff the target type is at least as big as the source type. +// if and only if the target type is at least as big as the source type. template <typename From, typename To> struct LosslessArithmeticConvertibleImpl< kFloatingPoint, From, kFloatingPoint, To> : public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT -// LosslessArithmeticConvertible<From, To>::value is true iff arithmetic -// type From can be losslessly converted to arithmetic type To. +// LosslessArithmeticConvertible<From, To>::value is true if and only if +// arithmetic type From can be losslessly converted to arithmetic type To. // // It's the user's responsibility to ensure that both From and To are // raw (i.e. has no CV modifier, is not a pointer, and is not a @@ -267,7 +255,7 @@ class FailureReporterInterface { // Reports a failure that occurred at the given source file location. virtual void ReportFailure(FailureType type, const char* file, int line, - const string& message) = 0; + const std::string& message) = 0; }; // Returns the failure reporter used by Google Mock. @@ -279,7 +267,7 @@ GTEST_API_ FailureReporterInterface* GetFailureReporter(); // inline this function to prevent it from showing up in the stack // trace. inline void Assert(bool condition, const char* file, int line, - const string& msg) { + const std::string& msg) { if (!condition) { GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal, file, line, msg); @@ -292,7 +280,7 @@ inline void Assert(bool condition, const char* file, int line) { // Verifies that condition is true; generates a non-fatal failure if // condition is false. inline void Expect(bool condition, const char* file, int line, - const string& msg) { + const std::string& msg) { if (!condition) { GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal, file, line, msg); @@ -317,49 +305,36 @@ const char kWarningVerbosity[] = "warning"; // No logs are printed. const char kErrorVerbosity[] = "error"; -// Returns true iff a log with the given severity is visible according -// to the --gmock_verbose flag. +// Returns true if and only if a log with the given severity is visible +// according to the --gmock_verbose flag. GTEST_API_ bool LogIsVisible(LogSeverity severity); -// Prints the given message to stdout iff 'severity' >= the level +// Prints the given message to stdout if and only if 'severity' >= the level // specified by the --gmock_verbose flag. If stack_frames_to_skip >= // 0, also prints the stack trace excluding the top // stack_frames_to_skip frames. In opt mode, any positive // stack_frames_to_skip is treated as 0, since we don't know which // function calls will be inlined by the compiler and need to be // conservative. -GTEST_API_ void Log(LogSeverity severity, - const string& message, +GTEST_API_ void Log(LogSeverity severity, const std::string& message, int stack_frames_to_skip); -// TODO(wan@google.com): group all type utilities together. - -// Type traits. - -// is_reference<T>::value is non-zero iff T is a reference type. -template <typename T> struct is_reference : public false_type {}; -template <typename T> struct is_reference<T&> : public true_type {}; - -// type_equals<T1, T2>::value is non-zero iff T1 and T2 are the same type. -template <typename T1, typename T2> struct type_equals : public false_type {}; -template <typename T> struct type_equals<T, T> : public true_type {}; +// A marker class that is used to resolve parameterless expectations to the +// correct overload. This must not be instantiable, to prevent client code from +// accidentally resolving to the overload; for example: +// +// ON_CALL(mock, Method({}, nullptr))... +// +class WithoutMatchers { + private: + WithoutMatchers() {} + friend GTEST_API_ WithoutMatchers GetWithoutMatchers(); +}; -// remove_reference<T>::type removes the reference from type T, if any. -template <typename T> struct remove_reference { typedef T type; }; // NOLINT -template <typename T> struct remove_reference<T&> { typedef T type; }; // NOLINT +// Internal use only: access the singleton instance of WithoutMatchers. +GTEST_API_ WithoutMatchers GetWithoutMatchers(); -// DecayArray<T>::type turns an array type U[N] to const U* and preserves -// other types. Useful for saving a copy of a function argument. -template <typename T> struct DecayArray { typedef T type; }; // NOLINT -template <typename T, size_t N> struct DecayArray<T[N]> { - typedef const T* type; -}; -// Sometimes people use arrays whose size is not available at the use site -// (e.g. extern const char kNamePrefix[]). This specialization covers that -// case. -template <typename T> struct DecayArray<T[]> { - typedef const T* type; -}; +// Type traits. // Disable MSVC warnings for infinite recursion, since in this case the // the recursion is unreachable. @@ -409,9 +384,8 @@ class StlContainerView { typedef const type& const_reference; static const_reference ConstReference(const RawContainer& container) { - // Ensures that RawContainer is not a const type. - testing::StaticAssertTypeEq<RawContainer, - GTEST_REMOVE_CONST_(RawContainer)>(); + static_assert(!std::is_const<RawContainer>::value, + "RawContainer type must not be const"); return container; } static type Copy(const RawContainer& container) { return container; } @@ -421,7 +395,7 @@ class StlContainerView { template <typename Element, size_t N> class StlContainerView<Element[N]> { public: - typedef GTEST_REMOVE_CONST_(Element) RawElement; + typedef typename std::remove_const<Element>::type RawElement; typedef internal::NativeArray<RawElement> type; // NativeArray<T> can represent a native array either by value or by // reference (selected by a constructor argument), so 'const type' @@ -431,53 +405,32 @@ class StlContainerView<Element[N]> { typedef const type const_reference; static const_reference ConstReference(const Element (&array)[N]) { - // Ensures that Element is not a const type. - testing::StaticAssertTypeEq<Element, RawElement>(); -#if GTEST_OS_SYMBIAN - // The Nokia Symbian compiler confuses itself in template instantiation - // for this call without the cast to Element*: - // function call '[testing::internal::NativeArray<char *>].NativeArray( - // {lval} const char *[4], long, testing::internal::RelationToSource)' - // does not match - // 'testing::internal::NativeArray<char *>::NativeArray( - // char *const *, unsigned int, testing::internal::RelationToSource)' - // (instantiating: 'testing::internal::ContainsMatcherImpl - // <const char * (&)[4]>::Matches(const char * (&)[4]) const') - // (instantiating: 'testing::internal::StlContainerView<char *[4]>:: - // ConstReference(const char * (&)[4])') - // (and though the N parameter type is mismatched in the above explicit - // conversion of it doesn't help - only the conversion of the array). - return type(const_cast<Element*>(&array[0]), N, - RelationToSourceReference()); -#else + static_assert(std::is_same<Element, RawElement>::value, + "Element type must not be const"); return type(array, N, RelationToSourceReference()); -#endif // GTEST_OS_SYMBIAN } static type Copy(const Element (&array)[N]) { -#if GTEST_OS_SYMBIAN - return type(const_cast<Element*>(&array[0]), N, RelationToSourceCopy()); -#else return type(array, N, RelationToSourceCopy()); -#endif // GTEST_OS_SYMBIAN } }; // This specialization is used when RawContainer is a native array // represented as a (pointer, size) tuple. template <typename ElementPointer, typename Size> -class StlContainerView< ::testing::tuple<ElementPointer, Size> > { +class StlContainerView< ::std::tuple<ElementPointer, Size> > { public: - typedef GTEST_REMOVE_CONST_( - typename internal::PointeeOf<ElementPointer>::type) RawElement; + typedef typename std::remove_const< + typename internal::PointeeOf<ElementPointer>::type>::type RawElement; typedef internal::NativeArray<RawElement> type; typedef const type const_reference; static const_reference ConstReference( - const ::testing::tuple<ElementPointer, Size>& array) { - return type(get<0>(array), get<1>(array), RelationToSourceReference()); + const ::std::tuple<ElementPointer, Size>& array) { + return type(std::get<0>(array), std::get<1>(array), + RelationToSourceReference()); } - static type Copy(const ::testing::tuple<ElementPointer, Size>& array) { - return type(get<0>(array), get<1>(array), RelationToSourceCopy()); + static type Copy(const ::std::tuple<ElementPointer, Size>& array) { + return type(std::get<0>(array), std::get<1>(array), RelationToSourceCopy()); } }; @@ -499,13 +452,62 @@ struct RemoveConstFromKey<std::pair<const K, V> > { typedef std::pair<K, V> type; }; -// Mapping from booleans to types. Similar to boost::bool_<kValue> and -// std::integral_constant<bool, kValue>. -template <bool kValue> -struct BooleanConstant {}; +// Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to +// reduce code size. +GTEST_API_ void IllegalDoDefault(const char* file, int line); + +template <typename F, typename Tuple, size_t... Idx> +auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>) -> decltype( + std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...)) { + return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...); +} + +// Apply the function to a tuple of arguments. +template <typename F, typename Tuple> +auto Apply(F&& f, Tuple&& args) + -> decltype(ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), + MakeIndexSequence<std::tuple_size<Tuple>::value>())) { + return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), + MakeIndexSequence<std::tuple_size<Tuple>::value>()); +} + +// Template struct Function<F>, where F must be a function type, contains +// the following typedefs: +// +// Result: the function's return type. +// Arg<N>: the type of the N-th argument, where N starts with 0. +// ArgumentTuple: the tuple type consisting of all parameters of F. +// ArgumentMatcherTuple: the tuple type consisting of Matchers for all +// parameters of F. +// MakeResultVoid: the function type obtained by substituting void +// for the return type of F. +// MakeResultIgnoredValue: +// the function type obtained by substituting Something +// for the return type of F. +template <typename T> +struct Function; + +template <typename R, typename... Args> +struct Function<R(Args...)> { + using Result = R; + static constexpr size_t ArgumentCount = sizeof...(Args); + template <size_t I> + using Arg = ElemFromList<I, typename MakeIndexSequence<sizeof...(Args)>::type, + Args...>; + using ArgumentTuple = std::tuple<Args...>; + using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>; + using MakeResultVoid = void(Args...); + using MakeResultIgnoredValue = IgnoredValue(Args...); +}; + +template <typename R, typename... Args> +constexpr size_t Function<R(Args...)>::ArgumentCount; + +#ifdef _MSC_VER +# pragma warning(pop) +#endif } // namespace internal } // namespace testing #endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ - |