2008-12-10 05:08:54 +00:00
|
|
|
// Copyright 2007, Google Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following disclaimer
|
|
|
|
// in the documentation and/or other materials provided with the
|
|
|
|
// distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived from
|
|
|
|
// this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// 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.
|
2018-08-14 18:04:07 +00:00
|
|
|
|
2008-12-10 05:08:54 +00:00
|
|
|
|
|
|
|
// Google Mock - a framework for writing C++ mock classes.
|
|
|
|
//
|
|
|
|
// This file defines some utilities useful for implementing Google
|
|
|
|
// Mock. They are subject to change without notice, so please DO NOT
|
|
|
|
// USE THEM IN USER CODE.
|
|
|
|
|
2018-07-27 15:15:08 +00:00
|
|
|
// GOOGLETEST_CM0002 DO NOT DELETE
|
|
|
|
|
2008-12-10 05:08:54 +00:00
|
|
|
#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>
|
2019-01-16 20:23:44 +00:00
|
|
|
#include <type_traits>
|
2010-09-14 05:38:21 +00:00
|
|
|
#include "gmock/internal/gmock-port.h"
|
|
|
|
#include "gtest/gtest.h"
|
2008-12-10 05:08:54 +00:00
|
|
|
|
|
|
|
namespace testing {
|
2019-01-07 22:06:16 +00:00
|
|
|
|
|
|
|
template <typename>
|
|
|
|
class Matcher;
|
|
|
|
|
2008-12-10 05:08:54 +00:00
|
|
|
namespace internal {
|
|
|
|
|
2018-04-11 14:10:24 +00:00
|
|
|
// 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
|
|
|
|
|
2018-01-26 16:57:58 +00:00
|
|
|
// 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);
|
|
|
|
|
2009-02-12 01:34:27 +00:00
|
|
|
// 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".
|
2018-01-26 16:57:58 +00:00
|
|
|
GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name);
|
2009-02-12 01:34:27 +00:00
|
|
|
|
2008-12-10 05:08:54 +00:00
|
|
|
// 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
|
|
|
|
// following default implementation is for the case where Pointer is a
|
|
|
|
// smart pointer.
|
|
|
|
template <typename Pointer>
|
|
|
|
struct PointeeOf {
|
|
|
|
// Smart pointer classes define type element_type as the type of
|
|
|
|
// their pointees.
|
|
|
|
typedef typename Pointer::element_type type;
|
|
|
|
};
|
|
|
|
// This specialization is for the raw pointer case.
|
|
|
|
template <typename T>
|
|
|
|
struct PointeeOf<T*> { typedef T type; }; // NOLINT
|
|
|
|
|
|
|
|
// GetRawPointer(p) returns the raw pointer underlying p when p is a
|
|
|
|
// smart pointer, or returns p itself when p is already a raw pointer.
|
|
|
|
// The following default implementation is for the smart pointer case.
|
|
|
|
template <typename Pointer>
|
2012-08-14 15:38:49 +00:00
|
|
|
inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
|
2008-12-10 05:08:54 +00:00
|
|
|
return p.get();
|
|
|
|
}
|
|
|
|
// This overloaded version is for the raw pointer case.
|
|
|
|
template <typename Element>
|
|
|
|
inline Element* GetRawPointer(Element* p) { return p; }
|
|
|
|
|
2009-09-25 18:55:50 +00:00
|
|
|
// 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.
|
2018-12-28 11:03:51 +00:00
|
|
|
#if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)
|
2009-09-25 18:55:50 +00:00
|
|
|
// wchar_t is a typedef.
|
|
|
|
#else
|
2011-02-24 07:29:13 +00:00
|
|
|
# define GMOCK_WCHAR_T_IS_NATIVE_ 1
|
2009-09-25 18:55:50 +00:00
|
|
|
#endif
|
|
|
|
|
2009-05-14 20:55:30 +00:00
|
|
|
// 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
|
|
|
|
// when a matcher argument type can be safely converted to another
|
|
|
|
// type in the implementation of SafeMatcherCast.
|
|
|
|
enum TypeKind {
|
|
|
|
kBool, kInteger, kFloatingPoint, kOther
|
|
|
|
};
|
|
|
|
|
|
|
|
// KindOf<T>::value is the kind of type T.
|
|
|
|
template <typename T> struct KindOf {
|
|
|
|
enum { value = kOther }; // The default kind.
|
|
|
|
};
|
|
|
|
|
|
|
|
// This macro declares that the kind of 'type' is 'kind'.
|
|
|
|
#define GMOCK_DECLARE_KIND_(type, kind) \
|
|
|
|
template <> struct KindOf<type> { enum { value = kind }; }
|
|
|
|
|
|
|
|
GMOCK_DECLARE_KIND_(bool, kBool);
|
|
|
|
|
|
|
|
// All standard integer types.
|
|
|
|
GMOCK_DECLARE_KIND_(char, kInteger);
|
|
|
|
GMOCK_DECLARE_KIND_(signed char, kInteger);
|
|
|
|
GMOCK_DECLARE_KIND_(unsigned char, kInteger);
|
|
|
|
GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT
|
|
|
|
GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT
|
|
|
|
GMOCK_DECLARE_KIND_(int, kInteger);
|
|
|
|
GMOCK_DECLARE_KIND_(unsigned int, kInteger);
|
|
|
|
GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT
|
|
|
|
GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT
|
|
|
|
|
2009-09-25 18:55:50 +00:00
|
|
|
#if GMOCK_WCHAR_T_IS_NATIVE_
|
2009-05-14 20:55:30 +00:00
|
|
|
GMOCK_DECLARE_KIND_(wchar_t, kInteger);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Non-standard integer types.
|
|
|
|
GMOCK_DECLARE_KIND_(Int64, kInteger);
|
|
|
|
GMOCK_DECLARE_KIND_(UInt64, kInteger);
|
|
|
|
|
|
|
|
// All standard floating-point types.
|
|
|
|
GMOCK_DECLARE_KIND_(float, kFloatingPoint);
|
|
|
|
GMOCK_DECLARE_KIND_(double, kFloatingPoint);
|
|
|
|
GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
|
|
|
|
|
|
|
|
#undef GMOCK_DECLARE_KIND_
|
|
|
|
|
|
|
|
// Evaluates to the kind of 'type'.
|
|
|
|
#define GMOCK_KIND_OF_(type) \
|
|
|
|
static_cast< ::testing::internal::TypeKind>( \
|
|
|
|
::testing::internal::KindOf<type>::value)
|
|
|
|
|
2019-08-12 05:09:50 +00:00
|
|
|
// Evaluates to true if and only if integer type T is signed.
|
2009-05-14 20:55:30 +00:00
|
|
|
#define GMOCK_IS_SIGNED_(T) (static_cast<T>(-1) < 0)
|
|
|
|
|
|
|
|
// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
|
2019-08-12 05:09:50 +00:00
|
|
|
// is true if and only if arithmetic type From can be losslessly converted to
|
2009-05-14 20:55:30 +00:00
|
|
|
// 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
|
|
|
|
// reference) built-in arithmetic types, kFromKind is the kind of
|
|
|
|
// 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>
|
2019-08-23 15:57:56 +00:00
|
|
|
struct LosslessArithmeticConvertibleImpl : public std::false_type {};
|
2009-05-14 20:55:30 +00:00
|
|
|
|
|
|
|
// Converting bool to bool is lossless.
|
|
|
|
template <>
|
|
|
|
struct LosslessArithmeticConvertibleImpl<kBool, bool, kBool, bool>
|
2019-08-23 15:57:56 +00:00
|
|
|
: public std::true_type {};
|
2009-05-14 20:55:30 +00:00
|
|
|
|
|
|
|
// Converting bool to any integer type is lossless.
|
|
|
|
template <typename To>
|
|
|
|
struct LosslessArithmeticConvertibleImpl<kBool, bool, kInteger, To>
|
2019-08-23 15:57:56 +00:00
|
|
|
: public std::true_type {};
|
2009-05-14 20:55:30 +00:00
|
|
|
|
|
|
|
// Converting bool to any floating-point type is lossless.
|
|
|
|
template <typename To>
|
|
|
|
struct LosslessArithmeticConvertibleImpl<kBool, bool, kFloatingPoint, To>
|
2019-08-23 15:57:56 +00:00
|
|
|
: public std::true_type {};
|
2009-05-14 20:55:30 +00:00
|
|
|
|
|
|
|
// Converting an integer to bool is lossy.
|
|
|
|
template <typename From>
|
|
|
|
struct LosslessArithmeticConvertibleImpl<kInteger, From, kBool, bool>
|
2019-08-23 15:57:56 +00:00
|
|
|
: public std::false_type {};
|
2009-05-14 20:55:30 +00:00
|
|
|
|
2019-08-12 05:09:50 +00:00
|
|
|
// 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.
|
2009-05-14 20:55:30 +00:00
|
|
|
template <typename From, typename To>
|
|
|
|
struct LosslessArithmeticConvertibleImpl<kInteger, From, kInteger, To>
|
|
|
|
: public bool_constant<
|
|
|
|
// When converting from a smaller size to a larger size, we are
|
|
|
|
// fine as long as we are not converting from signed to unsigned.
|
|
|
|
((sizeof(From) < sizeof(To)) &&
|
|
|
|
(!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) ||
|
|
|
|
// When converting between the same size, the signedness must match.
|
|
|
|
((sizeof(From) == sizeof(To)) &&
|
|
|
|
(GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT
|
|
|
|
|
|
|
|
#undef GMOCK_IS_SIGNED_
|
|
|
|
|
|
|
|
// Converting an integer to a floating-point type may be lossy, since
|
|
|
|
// the format of a floating-point number is implementation-defined.
|
|
|
|
template <typename From, typename To>
|
|
|
|
struct LosslessArithmeticConvertibleImpl<kInteger, From, kFloatingPoint, To>
|
2019-08-23 15:57:56 +00:00
|
|
|
: public std::false_type {};
|
2009-05-14 20:55:30 +00:00
|
|
|
|
|
|
|
// Converting a floating-point to bool is lossy.
|
|
|
|
template <typename From>
|
|
|
|
struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kBool, bool>
|
2019-08-23 15:57:56 +00:00
|
|
|
: public std::false_type {};
|
2009-05-14 20:55:30 +00:00
|
|
|
|
|
|
|
// Converting a floating-point to an integer is lossy.
|
|
|
|
template <typename From, typename To>
|
|
|
|
struct LosslessArithmeticConvertibleImpl<kFloatingPoint, From, kInteger, To>
|
2019-08-23 15:57:56 +00:00
|
|
|
: public std::false_type {};
|
2009-05-14 20:55:30 +00:00
|
|
|
|
|
|
|
// Converting a floating-point to another floating-point is lossless
|
2019-08-12 05:09:50 +00:00
|
|
|
// if and only if the target type is at least as big as the source type.
|
2009-05-14 20:55:30 +00:00
|
|
|
template <typename From, typename To>
|
|
|
|
struct LosslessArithmeticConvertibleImpl<
|
|
|
|
kFloatingPoint, From, kFloatingPoint, To>
|
|
|
|
: public bool_constant<sizeof(From) <= sizeof(To)> {}; // NOLINT
|
|
|
|
|
2019-08-12 05:09:50 +00:00
|
|
|
// LosslessArithmeticConvertible<From, To>::value is true if and only if
|
|
|
|
// arithmetic type From can be losslessly converted to arithmetic type To.
|
2009-05-14 20:55:30 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// reference) built-in arithmetic types; the value is
|
|
|
|
// implementation-defined when the above pre-condition is violated.
|
|
|
|
template <typename From, typename To>
|
|
|
|
struct LosslessArithmeticConvertible
|
|
|
|
: public LosslessArithmeticConvertibleImpl<
|
|
|
|
GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT
|
|
|
|
|
2008-12-10 05:08:54 +00:00
|
|
|
// This interface knows how to report a Google Mock failure (either
|
|
|
|
// non-fatal or fatal).
|
|
|
|
class FailureReporterInterface {
|
|
|
|
public:
|
|
|
|
// The type of a failure (either non-fatal or fatal).
|
|
|
|
enum FailureType {
|
2012-05-31 20:40:56 +00:00
|
|
|
kNonfatal, kFatal
|
2008-12-10 05:08:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual ~FailureReporterInterface() {}
|
|
|
|
|
|
|
|
// Reports a failure that occurred at the given source file location.
|
|
|
|
virtual void ReportFailure(FailureType type, const char* file, int line,
|
2017-05-15 21:07:03 +00:00
|
|
|
const std::string& message) = 0;
|
2008-12-10 05:08:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Returns the failure reporter used by Google Mock.
|
2011-05-20 00:42:22 +00:00
|
|
|
GTEST_API_ FailureReporterInterface* GetFailureReporter();
|
2008-12-10 05:08:54 +00:00
|
|
|
|
|
|
|
// Asserts that condition is true; aborts the process with the given
|
|
|
|
// message if condition is false. We cannot use LOG(FATAL) or CHECK()
|
|
|
|
// as Google Mock might be used to mock the log sink itself. We
|
|
|
|
// inline this function to prevent it from showing up in the stack
|
|
|
|
// trace.
|
|
|
|
inline void Assert(bool condition, const char* file, int line,
|
2017-05-15 21:07:03 +00:00
|
|
|
const std::string& msg) {
|
2008-12-10 05:08:54 +00:00
|
|
|
if (!condition) {
|
2012-05-31 20:40:56 +00:00
|
|
|
GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
|
2008-12-10 05:08:54 +00:00
|
|
|
file, line, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inline void Assert(bool condition, const char* file, int line) {
|
|
|
|
Assert(condition, file, line, "Assertion failed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verifies that condition is true; generates a non-fatal failure if
|
|
|
|
// condition is false.
|
|
|
|
inline void Expect(bool condition, const char* file, int line,
|
2017-05-15 21:07:03 +00:00
|
|
|
const std::string& msg) {
|
2008-12-10 05:08:54 +00:00
|
|
|
if (!condition) {
|
2012-05-31 20:40:56 +00:00
|
|
|
GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
|
2008-12-10 05:08:54 +00:00
|
|
|
file, line, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inline void Expect(bool condition, const char* file, int line) {
|
|
|
|
Expect(condition, file, line, "Expectation failed.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Severity level of a log.
|
|
|
|
enum LogSeverity {
|
2012-05-31 20:40:56 +00:00
|
|
|
kInfo = 0,
|
|
|
|
kWarning = 1
|
2008-12-10 05:08:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Valid values for the --gmock_verbose flag.
|
|
|
|
|
|
|
|
// All logs (informational and warnings) are printed.
|
|
|
|
const char kInfoVerbosity[] = "info";
|
|
|
|
// Only warnings are printed.
|
|
|
|
const char kWarningVerbosity[] = "warning";
|
|
|
|
// No logs are printed.
|
|
|
|
const char kErrorVerbosity[] = "error";
|
|
|
|
|
2019-08-12 05:09:50 +00:00
|
|
|
// Returns true if and only if a log with the given severity is visible
|
|
|
|
// according to the --gmock_verbose flag.
|
2011-05-20 00:42:22 +00:00
|
|
|
GTEST_API_ bool LogIsVisible(LogSeverity severity);
|
2009-05-29 19:50:06 +00:00
|
|
|
|
2019-08-12 05:09:50 +00:00
|
|
|
// Prints the given message to stdout if and only if 'severity' >= the level
|
2008-12-10 05:08:54 +00:00
|
|
|
// 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.
|
2017-05-15 21:07:03 +00:00
|
|
|
GTEST_API_ void Log(LogSeverity severity, const std::string& message,
|
2011-05-20 00:42:22 +00:00
|
|
|
int stack_frames_to_skip);
|
2008-12-10 05:08:54 +00:00
|
|
|
|
2018-04-18 23:28:56 +00:00
|
|
|
// 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:
|
|
|
|
//
|
2018-07-17 07:46:47 +00:00
|
|
|
// ON_CALL(mock, Method({}, nullptr))...
|
2018-04-18 23:28:56 +00:00
|
|
|
//
|
2018-04-19 05:10:22 +00:00
|
|
|
class WithoutMatchers {
|
2018-04-18 23:28:56 +00:00
|
|
|
private:
|
|
|
|
WithoutMatchers() {}
|
2018-04-19 05:11:50 +00:00
|
|
|
friend GTEST_API_ WithoutMatchers GetWithoutMatchers();
|
2018-04-18 23:28:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Internal use only: access the singleton instance of WithoutMatchers.
|
2018-04-19 00:25:31 +00:00
|
|
|
GTEST_API_ WithoutMatchers GetWithoutMatchers();
|
2018-04-18 23:28:56 +00:00
|
|
|
|
2008-12-10 05:08:54 +00:00
|
|
|
// Type traits.
|
|
|
|
|
2014-01-29 06:41:44 +00:00
|
|
|
// Disable MSVC warnings for infinite recursion, since in this case the
|
|
|
|
// the recursion is unreachable.
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning(push)
|
|
|
|
# pragma warning(disable:4717)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Invalid<T>() is usable as an expression of type T, but will terminate
|
|
|
|
// the program with an assertion failure if actually run. This is useful
|
2008-12-10 05:08:54 +00:00
|
|
|
// when a value of type T is needed for compilation, but the statement
|
|
|
|
// will not really be executed (or we don't care if the statement
|
|
|
|
// crashes).
|
|
|
|
template <typename T>
|
|
|
|
inline T Invalid() {
|
2014-01-29 06:41:44 +00:00
|
|
|
Assert(false, "", -1, "Internal error: attempt to return invalid value");
|
|
|
|
// This statement is unreachable, and would never terminate even if it
|
|
|
|
// could be reached. It is provided only to placate compiler warnings
|
|
|
|
// about missing return statements.
|
|
|
|
return Invalid<T>();
|
2008-12-10 05:08:54 +00:00
|
|
|
}
|
2014-01-29 06:41:44 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning(pop)
|
|
|
|
#endif
|
2008-12-10 05:08:54 +00:00
|
|
|
|
2009-06-04 05:48:20 +00:00
|
|
|
// Given a raw type (i.e. having no top-level reference or const
|
|
|
|
// modifier) RawContainer that's either an STL-style container or a
|
|
|
|
// native array, class StlContainerView<RawContainer> has the
|
|
|
|
// following members:
|
|
|
|
//
|
|
|
|
// - type is a type that provides an STL-style container view to
|
|
|
|
// (i.e. implements the STL container concept for) RawContainer;
|
|
|
|
// - const_reference is a type that provides a reference to a const
|
|
|
|
// RawContainer;
|
|
|
|
// - ConstReference(raw_container) returns a const reference to an STL-style
|
|
|
|
// container view to raw_container, which is a RawContainer.
|
|
|
|
// - Copy(raw_container) returns an STL-style container view of a
|
|
|
|
// copy of raw_container, which is a RawContainer.
|
|
|
|
//
|
|
|
|
// This generic version is used when RawContainer itself is already an
|
|
|
|
// STL-style container.
|
|
|
|
template <class RawContainer>
|
|
|
|
class StlContainerView {
|
|
|
|
public:
|
|
|
|
typedef RawContainer type;
|
|
|
|
typedef const type& const_reference;
|
|
|
|
|
|
|
|
static const_reference ConstReference(const RawContainer& container) {
|
|
|
|
// Ensures that RawContainer is not a const type.
|
2019-08-13 21:59:59 +00:00
|
|
|
testing::StaticAssertTypeEq<
|
|
|
|
RawContainer, typename std::remove_const<RawContainer>::type>();
|
2009-06-04 05:48:20 +00:00
|
|
|
return container;
|
|
|
|
}
|
|
|
|
static type Copy(const RawContainer& container) { return container; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// This specialization is used when RawContainer is a native array type.
|
|
|
|
template <typename Element, size_t N>
|
|
|
|
class StlContainerView<Element[N]> {
|
|
|
|
public:
|
2019-08-13 21:59:59 +00:00
|
|
|
typedef typename std::remove_const<Element>::type RawElement;
|
2009-06-04 05:48:20 +00:00
|
|
|
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'
|
|
|
|
// can be used to reference a const native array. We cannot
|
|
|
|
// 'typedef const type& const_reference' here, as that would mean
|
|
|
|
// ConstReference() has to return a reference to a local variable.
|
|
|
|
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>();
|
2014-05-19 17:54:51 +00:00
|
|
|
return type(array, N, RelationToSourceReference());
|
2009-06-04 05:48:20 +00:00
|
|
|
}
|
|
|
|
static type Copy(const Element (&array)[N]) {
|
2014-05-19 17:54:51 +00:00
|
|
|
return type(array, N, RelationToSourceCopy());
|
2009-06-04 05:48:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// This specialization is used when RawContainer is a native array
|
|
|
|
// represented as a (pointer, size) tuple.
|
|
|
|
template <typename ElementPointer, typename Size>
|
2018-10-09 18:50:26 +00:00
|
|
|
class StlContainerView< ::std::tuple<ElementPointer, Size> > {
|
2009-06-04 05:48:20 +00:00
|
|
|
public:
|
2019-08-13 21:59:59 +00:00
|
|
|
typedef typename std::remove_const<
|
|
|
|
typename internal::PointeeOf<ElementPointer>::type>::type RawElement;
|
2009-06-04 05:48:20 +00:00
|
|
|
typedef internal::NativeArray<RawElement> type;
|
|
|
|
typedef const type const_reference;
|
|
|
|
|
|
|
|
static const_reference ConstReference(
|
2018-10-09 18:50:26 +00:00
|
|
|
const ::std::tuple<ElementPointer, Size>& array) {
|
|
|
|
return type(std::get<0>(array), std::get<1>(array),
|
|
|
|
RelationToSourceReference());
|
2009-06-04 05:48:20 +00:00
|
|
|
}
|
2018-10-09 18:50:26 +00:00
|
|
|
static type Copy(const ::std::tuple<ElementPointer, Size>& array) {
|
|
|
|
return type(std::get<0>(array), std::get<1>(array), RelationToSourceCopy());
|
2009-06-04 05:48:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The following specialization prevents the user from instantiating
|
|
|
|
// StlContainer with a reference type.
|
|
|
|
template <typename T> class StlContainerView<T&>;
|
|
|
|
|
2013-03-27 16:14:55 +00:00
|
|
|
// A type transform to remove constness from the first part of a pair.
|
|
|
|
// Pairs like that are used as the value_type of associative containers,
|
|
|
|
// and this transform produces a similar but assignable pair.
|
|
|
|
template <typename T>
|
|
|
|
struct RemoveConstFromKey {
|
|
|
|
typedef T type;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Partially specialized to remove constness from std::pair<const K, V>.
|
|
|
|
template <typename K, typename V>
|
|
|
|
struct RemoveConstFromKey<std::pair<const K, V> > {
|
|
|
|
typedef std::pair<K, V> type;
|
|
|
|
};
|
|
|
|
|
2018-01-26 16:57:58 +00:00
|
|
|
// Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to
|
|
|
|
// reduce code size.
|
2018-04-11 14:10:24 +00:00
|
|
|
GTEST_API_ void IllegalDoDefault(const char* file, int line);
|
2018-01-26 16:57:58 +00:00
|
|
|
|
|
|
|
template <typename F, typename Tuple, size_t... Idx>
|
2019-08-14 12:21:32 +00:00
|
|
|
auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>) -> decltype(
|
2018-01-26 16:57:58 +00:00
|
|
|
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),
|
2019-08-14 12:21:32 +00:00
|
|
|
MakeIndexSequence<std::tuple_size<Tuple>::value>())) {
|
2018-01-26 16:57:58 +00:00
|
|
|
return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
|
2019-08-14 12:21:32 +00:00
|
|
|
MakeIndexSequence<std::tuple_size<Tuple>::value>());
|
2018-01-26 16:57:58 +00:00
|
|
|
}
|
2018-04-11 14:10:24 +00:00
|
|
|
|
2019-01-07 22:06:16 +00:00
|
|
|
// 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;
|
2018-04-11 14:10:24 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
|
2008-12-10 05:08:54 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace testing
|
|
|
|
|
|
|
|
#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
|