39#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
40#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
49#include "gmock/internal/gmock-port.h"
50#include "gtest/gtest.h"
63#pragma warning(disable : 4100)
64#pragma warning(disable : 4805)
69GTEST_API_ std::string JoinAsKeyValueTuple(
70 const std::vector<const char*>& names,
const Strings& values);
76GTEST_API_ std::string ConvertIdentifierNameToWords(
const char* id_name);
81template <
typename Po
inter>
82inline const typename Pointer::element_type* GetRawPointer(
const Pointer& p) {
87template <
typename Element>
88inline const Element* GetRawPointer(
const std::reference_wrapper<Element>& r) {
93template <
typename Element>
94inline Element* GetRawPointer(Element* p) {
102#if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)
105#define GMOCK_WCHAR_T_IS_NATIVE_ 1
113enum TypeKind { kBool, kInteger, kFloatingPoint, kOther };
118 enum { value = kOther };
122#define GMOCK_DECLARE_KIND_(type, kind) \
124 struct KindOf<type> { \
125 enum { value = kind }; \
128GMOCK_DECLARE_KIND_(
bool, kBool);
131GMOCK_DECLARE_KIND_(
char, kInteger);
132GMOCK_DECLARE_KIND_(
signed char, kInteger);
133GMOCK_DECLARE_KIND_(
unsigned char, kInteger);
134GMOCK_DECLARE_KIND_(
short, kInteger);
135GMOCK_DECLARE_KIND_(
unsigned short, kInteger);
136GMOCK_DECLARE_KIND_(
int, kInteger);
137GMOCK_DECLARE_KIND_(
unsigned int, kInteger);
138GMOCK_DECLARE_KIND_(
long, kInteger);
139GMOCK_DECLARE_KIND_(
unsigned long, kInteger);
140GMOCK_DECLARE_KIND_(
long long, kInteger);
141GMOCK_DECLARE_KIND_(
unsigned long long, kInteger);
143#if GMOCK_WCHAR_T_IS_NATIVE_
144GMOCK_DECLARE_KIND_(
wchar_t, kInteger);
148GMOCK_DECLARE_KIND_(
float, kFloatingPoint);
149GMOCK_DECLARE_KIND_(
double, kFloatingPoint);
150GMOCK_DECLARE_KIND_(
long double, kFloatingPoint);
152#undef GMOCK_DECLARE_KIND_
155#define GMOCK_KIND_OF_(type) \
156 static_cast< ::testing::internal::TypeKind>( \
157 ::testing::internal::KindOf<type>::value)
168template <TypeKind kFromKind,
typename From, TypeKind kToKind,
typename To>
169using LosslessArithmeticConvertibleImpl = std::integral_constant<
173 (kFromKind == kBool) ?
true
176 : (kFromKind != kToKind) ? false
177 : (kFromKind == kInteger &&
180 (((sizeof(From) < sizeof(
To)) &&
181 !(std::is_signed<From>::value && !std::is_signed<
To>::value)) ||
184 ((sizeof(From) == sizeof(
To)) &&
185 (std::is_signed<From>::value == std::is_signed<
To>::value)))
189 : (kFromKind == kFloatingPoint && (sizeof(From) <= sizeof(
To))) ? true
201template <
typename From,
typename To>
202using LosslessArithmeticConvertible =
203 LosslessArithmeticConvertibleImpl<GMOCK_KIND_OF_(From), From,
204 GMOCK_KIND_OF_(
To),
To>;
211 enum FailureType { kNonfatal, kFatal };
216 virtual void ReportFailure(FailureType type,
const char* file,
int line,
217 const std::string& message) = 0;
228inline void Assert(
bool condition,
const char* file,
int line,
229 const std::string& msg) {
231 GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal, file,
235inline void Assert(
bool condition,
const char* file,
int line) {
236 Assert(condition, file, line,
"Assertion failed.");
241inline void Expect(
bool condition,
const char* file,
int line,
242 const std::string& msg) {
244 GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
248inline void Expect(
bool condition,
const char* file,
int line) {
249 Expect(condition, file, line,
"Expectation failed.");
253enum LogSeverity { kInfo = 0, kWarning = 1 };
258const char kInfoVerbosity[] =
"info";
260const char kWarningVerbosity[] =
"warning";
262const char kErrorVerbosity[] =
"error";
266GTEST_API_
bool LogIsVisible(LogSeverity severity);
275GTEST_API_
void Log(LogSeverity severity,
const std::string& message,
276 int stack_frames_to_skip);
300 Assert(
false,
"", -1,
"Internal error: attempt to return invalid value");
301#if defined(__GNUC__) || defined(__clang__)
302 __builtin_unreachable();
303#elif defined(_MSC_VER)
326template <
class RawContainer>
329 typedef RawContainer type;
330 typedef const type& const_reference;
332 static const_reference ConstReference(
const RawContainer& container) {
333 static_assert(!std::is_const<RawContainer>::value,
334 "RawContainer type must not be const");
337 static type Copy(
const RawContainer& container) {
return container; }
341template <
typename Element,
size_t N>
344 typedef typename std::remove_const<Element>::type RawElement;
354 static_assert(std::is_same<Element, RawElement>::value,
355 "Element type must not be const");
358 static type Copy(
const Element (&array)[N]) {
365template <
typename ElementPo
inter,
typename Size>
368 typedef typename std::remove_const<
369 typename std::pointer_traits<ElementPointer>::element_type>::type
375 const ::std::tuple<ElementPointer, Size>& array) {
376 return type(std::get<0>(array), std::get<1>(array),
379 static type Copy(const ::std::tuple<ElementPointer, Size>& array) {
398template <
typename K,
typename V>
400 typedef std::pair<K, V> type;
405GTEST_API_
void IllegalDoDefault(
const char* file,
int line);
407template <
typename F,
typename Tuple,
size_t... Idx>
409 ->
decltype(std::forward<F>(f)(
410 std::get<Idx>(std::forward<Tuple>(args))...)) {
411 return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...);
415template <
typename F,
typename Tuple>
416auto Apply(F&& f, Tuple&& args) ->
decltype(ApplyImpl(
417 std::forward<F>(f), std::forward<Tuple>(args),
418 MakeIndexSequence<std::tuple_size<
419 typename std::remove_reference<Tuple>::type>::value>())) {
420 return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
421 MakeIndexSequence<std::tuple_size<
422 typename std::remove_reference<Tuple>::type>::value>());
441template <
typename R,
typename... Args>
444 static constexpr size_t ArgumentCount =
sizeof...(Args);
447 using ArgumentTuple = std::tuple<Args...>;
448 using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
449 using MakeResultVoid = void(Args...);
453template <
typename R,
typename... Args>
454constexpr size_t Function<R(Args...)>::ArgumentCount;
460template <
size_t I,
typename T>
461using TupleElement =
typename std::tuple_element<I, T>::type;
463bool Base64Unescape(
const std::string& encoded, std::string* decoded);
Definition gmock-internal-utils.h:55
Definition gmock-internal-utils.h:208
Definition gtest-internal.h:126
Definition gtest-internal.h:1097
Definition gmock-internal-utils.h:327
Definition googletest-port-test.cc:194
Definition gmock-internal-utils.h:284
Definition gtest-internal.h:1209
Definition gmock-internal-utils.h:439
Definition gtest-internal.h:1159
Definition gmock-internal-utils.h:117
Definition gtest-internal.h:1086
Definition gtest-internal.h:1085
Definition gmock-internal-utils.h:393