"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "googlemock/include/gmock/internal/gmock-internal-utils.h" between
googletest-release-1.11.0.tar.gz and googletest-release-1.12.0.tar.gz

About: GoogleTest is Google's (unit) testing and mocking framework for C++ tests.

gmock-internal-utils.h  (googletest-release-1.11.0):gmock-internal-utils.h  (googletest-release-1.12.0)
skipping to change at line 36 skipping to change at line 36
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file defines some utilities useful for implementing Google // This file defines some utilities useful for implementing Google
// Mock. They are subject to change without notice, so please DO NOT // Mock. They are subject to change without notice, so please DO NOT
// USE THEM IN USER CODE. // USE THEM IN USER CODE.
// GOOGLETEST_CM0002 DO NOT DELETE // IWYU pragma: private, include "gmock/gmock.h"
// IWYU pragma: friend gmock/.*
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
#include <stdio.h> #include <stdio.h>
#include <ostream> // NOLINT #include <ostream> // NOLINT
#include <string> #include <string>
#include <type_traits> #include <type_traits>
#include <vector>
#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace testing { namespace testing {
template <typename> template <typename>
class Matcher; class Matcher;
namespace internal { namespace internal {
// Silence MSVC C4100 (unreferenced formal parameter) and // Silence MSVC C4100 (unreferenced formal parameter) and
// C4805('==': unsafe mix of type 'const int' and type 'const bool') // C4805('==': unsafe mix of type 'const int' and type 'const bool')
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(push) #pragma warning(push)
# pragma warning(disable:4100) #pragma warning(disable : 4100)
# pragma warning(disable:4805) #pragma warning(disable : 4805)
#endif #endif
// Joins a vector of strings as if they are fields of a tuple; returns // Joins a vector of strings as if they are fields of a tuple; returns
// the joined string. // the joined string.
GTEST_API_ std::string JoinAsTuple(const Strings& fields); GTEST_API_ std::string JoinAsKeyValueTuple(
const std::vector<const char*>& names, const Strings& values);
// Converts an identifier name to a space-separated list of lower-case // 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 // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
// treated as one word. For example, both "FooBar123" and // treated as one word. For example, both "FooBar123" and
// "foo_bar_123" are converted to "foo bar 123". // "foo_bar_123" are converted to "foo bar 123".
GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name); GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name);
// GetRawPointer(p) returns the raw pointer underlying p when p is a // 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. // smart pointer, or returns p itself when p is already a raw pointer.
// The following default implementation is for the smart pointer case. // The following default implementation is for the smart pointer case.
template <typename Pointer> template <typename Pointer>
inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) { inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
return p.get(); return p.get();
} }
// This overload version is for std::reference_wrapper, which does not work with
// the overload above, as it does not have an `element_type`.
template <typename Element>
inline const Element* GetRawPointer(const std::reference_wrapper<Element>& r) {
return &r.get();
}
// This overloaded version is for the raw pointer case. // This overloaded version is for the raw pointer case.
template <typename Element> template <typename Element>
inline Element* GetRawPointer(Element* p) { return p; } inline Element* GetRawPointer(Element* p) {
return p;
}
// MSVC treats wchar_t as a native type usually, but treats it as the // 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 // same as unsigned short when the compiler option /Zc:wchar_t- is
// specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t // specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
// is a native type. // is a native type.
#if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED) #if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)
// wchar_t is a typedef. // wchar_t is a typedef.
#else #else
# define GMOCK_WCHAR_T_IS_NATIVE_ 1 #define GMOCK_WCHAR_T_IS_NATIVE_ 1
#endif #endif
// In what follows, we use the term "kind" to indicate whether a type // In what follows, we use the term "kind" to indicate whether a type
// is bool, an integer type (excluding bool), a floating-point type, // is bool, an integer type (excluding bool), a floating-point type,
// or none of them. This categorization is useful for determining // or none of them. This categorization is useful for determining
// when a matcher argument type can be safely converted to another // when a matcher argument type can be safely converted to another
// type in the implementation of SafeMatcherCast. // type in the implementation of SafeMatcherCast.
enum TypeKind { enum TypeKind { kBool, kInteger, kFloatingPoint, kOther };
kBool, kInteger, kFloatingPoint, kOther
};
// KindOf<T>::value is the kind of type T. // KindOf<T>::value is the kind of type T.
template <typename T> struct KindOf { template <typename T>
struct KindOf {
enum { value = kOther }; // The default kind. enum { value = kOther }; // The default kind.
}; };
// This macro declares that the kind of 'type' is 'kind'. // This macro declares that the kind of 'type' is 'kind'.
#define GMOCK_DECLARE_KIND_(type, kind) \ #define GMOCK_DECLARE_KIND_(type, kind) \
template <> struct KindOf<type> { enum { value = kind }; } template <> \
struct KindOf<type> { \
enum { value = kind }; \
}
GMOCK_DECLARE_KIND_(bool, kBool); GMOCK_DECLARE_KIND_(bool, kBool);
// All standard integer types. // All standard integer types.
GMOCK_DECLARE_KIND_(char, kInteger); GMOCK_DECLARE_KIND_(char, kInteger);
GMOCK_DECLARE_KIND_(signed char, kInteger); GMOCK_DECLARE_KIND_(signed char, kInteger);
GMOCK_DECLARE_KIND_(unsigned char, kInteger); GMOCK_DECLARE_KIND_(unsigned char, kInteger);
GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT
GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT
GMOCK_DECLARE_KIND_(int, kInteger); GMOCK_DECLARE_KIND_(int, kInteger);
GMOCK_DECLARE_KIND_(unsigned int, kInteger); GMOCK_DECLARE_KIND_(unsigned int, kInteger);
GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT
GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT
GMOCK_DECLARE_KIND_(long long, kInteger); // NOLINT GMOCK_DECLARE_KIND_(long long, kInteger); // NOLINT
GMOCK_DECLARE_KIND_(unsigned long long, kInteger); // NOLINT GMOCK_DECLARE_KIND_(unsigned long long, kInteger); // NOLINT
#if GMOCK_WCHAR_T_IS_NATIVE_ #if GMOCK_WCHAR_T_IS_NATIVE_
GMOCK_DECLARE_KIND_(wchar_t, kInteger); GMOCK_DECLARE_KIND_(wchar_t, kInteger);
#endif #endif
// All standard floating-point types. // All standard floating-point types.
GMOCK_DECLARE_KIND_(float, kFloatingPoint); GMOCK_DECLARE_KIND_(float, kFloatingPoint);
GMOCK_DECLARE_KIND_(double, kFloatingPoint); GMOCK_DECLARE_KIND_(double, kFloatingPoint);
GMOCK_DECLARE_KIND_(long double, kFloatingPoint); GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
#undef GMOCK_DECLARE_KIND_ #undef GMOCK_DECLARE_KIND_
// Evaluates to the kind of 'type'. // Evaluates to the kind of 'type'.
#define GMOCK_KIND_OF_(type) \ #define GMOCK_KIND_OF_(type) \
static_cast< ::testing::internal::TypeKind>( \ static_cast< ::testing::internal::TypeKind>( \
::testing::internal::KindOf<type>::value) ::testing::internal::KindOf<type>::value)
// LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value // LosslessArithmeticConvertibleImpl<kFromKind, From, kToKind, To>::value
// is true if and only if 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. // arithmetic type To.
// //
// It's the user's responsibility to ensure that both From and To are // 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 // 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 // reference) built-in arithmetic types, kFromKind is the kind of
skipping to change at line 195 skipping to change at line 211
template <typename From, typename To> template <typename From, typename To>
using LosslessArithmeticConvertible = using LosslessArithmeticConvertible =
LosslessArithmeticConvertibleImpl<GMOCK_KIND_OF_(From), From, LosslessArithmeticConvertibleImpl<GMOCK_KIND_OF_(From), From,
GMOCK_KIND_OF_(To), To>; GMOCK_KIND_OF_(To), To>;
// This interface knows how to report a Google Mock failure (either // This interface knows how to report a Google Mock failure (either
// non-fatal or fatal). // non-fatal or fatal).
class FailureReporterInterface { class FailureReporterInterface {
public: public:
// The type of a failure (either non-fatal or fatal). // The type of a failure (either non-fatal or fatal).
enum FailureType { enum FailureType { kNonfatal, kFatal };
kNonfatal, kFatal
};
virtual ~FailureReporterInterface() {} virtual ~FailureReporterInterface() {}
// Reports a failure that occurred at the given source file location. // Reports a failure that occurred at the given source file location.
virtual void ReportFailure(FailureType type, const char* file, int line, virtual void ReportFailure(FailureType type, const char* file, int line,
const std::string& message) = 0; const std::string& message) = 0;
}; };
// Returns the failure reporter used by Google Mock. // Returns the failure reporter used by Google Mock.
GTEST_API_ FailureReporterInterface* GetFailureReporter(); GTEST_API_ FailureReporterInterface* GetFailureReporter();
// Asserts that condition is true; aborts the process with the given // Asserts that condition is true; aborts the process with the given
// message if condition is false. We cannot use LOG(FATAL) or CHECK() // 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 // 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 // inline this function to prevent it from showing up in the stack
// trace. // trace.
inline void Assert(bool condition, const char* file, int line, inline void Assert(bool condition, const char* file, int line,
const std::string& msg) { const std::string& msg) {
if (!condition) { if (!condition) {
GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal, GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal, file,
file, line, msg); line, msg);
} }
} }
inline void Assert(bool condition, const char* file, int line) { inline void Assert(bool condition, const char* file, int line) {
Assert(condition, file, line, "Assertion failed."); Assert(condition, file, line, "Assertion failed.");
} }
// Verifies that condition is true; generates a non-fatal failure if // Verifies that condition is true; generates a non-fatal failure if
// condition is false. // condition is false.
inline void Expect(bool condition, const char* file, int line, inline void Expect(bool condition, const char* file, int line,
const std::string& msg) { const std::string& msg) {
if (!condition) { if (!condition) {
GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal, GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
file, line, msg); file, line, msg);
} }
} }
inline void Expect(bool condition, const char* file, int line) { inline void Expect(bool condition, const char* file, int line) {
Expect(condition, file, line, "Expectation failed."); Expect(condition, file, line, "Expectation failed.");
} }
// Severity level of a log. // Severity level of a log.
enum LogSeverity { enum LogSeverity { kInfo = 0, kWarning = 1 };
kInfo = 0,
kWarning = 1
};
// Valid values for the --gmock_verbose flag. // Valid values for the --gmock_verbose flag.
// All logs (informational and warnings) are printed. // All logs (informational and warnings) are printed.
const char kInfoVerbosity[] = "info"; const char kInfoVerbosity[] = "info";
// Only warnings are printed. // Only warnings are printed.
const char kWarningVerbosity[] = "warning"; const char kWarningVerbosity[] = "warning";
// No logs are printed. // No logs are printed.
const char kErrorVerbosity[] = "error"; const char kErrorVerbosity[] = "error";
skipping to change at line 283 skipping to change at line 294
class WithoutMatchers { class WithoutMatchers {
private: private:
WithoutMatchers() {} WithoutMatchers() {}
friend GTEST_API_ WithoutMatchers GetWithoutMatchers(); friend GTEST_API_ WithoutMatchers GetWithoutMatchers();
}; };
// Internal use only: access the singleton instance of WithoutMatchers. // Internal use only: access the singleton instance of WithoutMatchers.
GTEST_API_ WithoutMatchers GetWithoutMatchers(); GTEST_API_ WithoutMatchers GetWithoutMatchers();
// Disable MSVC warnings for infinite recursion, since in this case the // Disable MSVC warnings for infinite recursion, since in this case the
// the recursion is unreachable. // recursion is unreachable.
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(push) #pragma warning(push)
# pragma warning(disable:4717) #pragma warning(disable : 4717)
#endif #endif
// Invalid<T>() is usable as an expression of type T, but will terminate // 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 // the program with an assertion failure if actually run. This is useful
// when a value of type T is needed for compilation, but the statement // 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 // will not really be executed (or we don't care if the statement
// crashes). // crashes).
template <typename T> template <typename T>
inline T Invalid() { inline T Invalid() {
Assert(false, "", -1, "Internal error: attempt to return invalid value"); Assert(false, "", -1, "Internal error: attempt to return invalid value");
// This statement is unreachable, and would never terminate even if it #if defined(__GNUC__) || defined(__clang__)
// could be reached. It is provided only to placate compiler warnings __builtin_unreachable();
// about missing return statements. #elif defined(_MSC_VER)
__assume(0);
#else
return Invalid<T>(); return Invalid<T>();
#endif
} }
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(pop) #pragma warning(pop)
#endif #endif
// Given a raw type (i.e. having no top-level reference or const // Given a raw type (i.e. having no top-level reference or const
// modifier) RawContainer that's either an STL-style container or a // modifier) RawContainer that's either an STL-style container or a
// native array, class StlContainerView<RawContainer> has the // native array, class StlContainerView<RawContainer> has the
// following members: // following members:
// //
// - type is a type that provides an STL-style container view to // - type is a type that provides an STL-style container view to
// (i.e. implements the STL container concept for) RawContainer; // (i.e. implements the STL container concept for) RawContainer;
// - const_reference is a type that provides a reference to a const // - const_reference is a type that provides a reference to a const
skipping to change at line 383 skipping to change at line 397
return type(std::get<0>(array), std::get<1>(array), return type(std::get<0>(array), std::get<1>(array),
RelationToSourceReference()); RelationToSourceReference());
} }
static type Copy(const ::std::tuple<ElementPointer, Size>& array) { static type Copy(const ::std::tuple<ElementPointer, Size>& array) {
return type(std::get<0>(array), std::get<1>(array), RelationToSourceCopy()); return type(std::get<0>(array), std::get<1>(array), RelationToSourceCopy());
} }
}; };
// The following specialization prevents the user from instantiating // The following specialization prevents the user from instantiating
// StlContainer with a reference type. // StlContainer with a reference type.
template <typename T> class StlContainerView<T&>; template <typename T>
class StlContainerView<T&>;
// A type transform to remove constness from the first part of a pair. // 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, // Pairs like that are used as the value_type of associative containers,
// and this transform produces a similar but assignable pair. // and this transform produces a similar but assignable pair.
template <typename T> template <typename T>
struct RemoveConstFromKey { struct RemoveConstFromKey {
typedef T type; typedef T type;
}; };
// Partially specialized to remove constness from std::pair<const K, V>. // Partially specialized to remove constness from std::pair<const K, V>.
template <typename K, typename V> template <typename K, typename V>
struct RemoveConstFromKey<std::pair<const K, V> > { struct RemoveConstFromKey<std::pair<const K, V> > {
typedef std::pair<K, V> type; typedef std::pair<K, V> type;
}; };
// Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to // Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to
// reduce code size. // reduce code size.
GTEST_API_ void IllegalDoDefault(const char* file, int line); GTEST_API_ void IllegalDoDefault(const char* file, int line);
template <typename F, typename Tuple, size_t... Idx> template <typename F, typename Tuple, size_t... Idx>
auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>) -> decltype( auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>)
std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...)) { -> decltype(std::forward<F>(f)(
std::get<Idx>(std::forward<Tuple>(args))...)) {
return 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. // Apply the function to a tuple of arguments.
template <typename F, typename Tuple> template <typename F, typename Tuple>
auto Apply(F&& f, Tuple&& args) -> decltype( auto Apply(F&& f, Tuple&& args) -> decltype(ApplyImpl(
ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), std::forward<F>(f), std::forward<Tuple>(args),
MakeIndexSequence<std::tuple_size< MakeIndexSequence<std::tuple_size<
typename std::remove_reference<Tuple>::type>::value>())) { typename std::remove_reference<Tuple>::type>::value>())) {
return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args), return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
MakeIndexSequence<std::tuple_size< MakeIndexSequence<std::tuple_size<
typename std::remove_reference<Tuple>::type>::value>()); typename std::remove_reference<Tuple>::type>::value>());
} }
// Template struct Function<F>, where F must be a function type, contains // Template struct Function<F>, where F must be a function type, contains
// the following typedefs: // the following typedefs:
// //
// Result: the function's return type. // Result: the function's return type.
// Arg<N>: the type of the N-th argument, where N starts with 0. // Arg<N>: the type of the N-th argument, where N starts with 0.
skipping to change at line 451 skipping to change at line 467
using Arg = ElemFromList<I, Args...>; using Arg = ElemFromList<I, Args...>;
using ArgumentTuple = std::tuple<Args...>; using ArgumentTuple = std::tuple<Args...>;
using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>; using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
using MakeResultVoid = void(Args...); using MakeResultVoid = void(Args...);
using MakeResultIgnoredValue = IgnoredValue(Args...); using MakeResultIgnoredValue = IgnoredValue(Args...);
}; };
template <typename R, typename... Args> template <typename R, typename... Args>
constexpr size_t Function<R(Args...)>::ArgumentCount; constexpr size_t Function<R(Args...)>::ArgumentCount;
bool Base64Unescape(const std::string& encoded, std::string* decoded);
#ifdef _MSC_VER #ifdef _MSC_VER
# pragma warning(pop) #pragma warning(pop)
#endif #endif
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
 End of changes. 27 change blocks. 
41 lines changed or deleted 59 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)