39 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ 40 #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ 45 #include <type_traits> 46 #include "gmock/internal/gmock-port.h" 47 #include "gtest/gtest.h" 59 # pragma warning(push) 60 # pragma warning(disable:4100) 61 # pragma warning(disable:4805) 66 GTEST_API_ std::string JoinAsTuple(
const Strings& fields);
72 GTEST_API_ std::string ConvertIdentifierNameToWords(
const char* id_name);
77 template <
typename Po
inter>
78 inline const typename Pointer::element_type* GetRawPointer(
const Pointer& p) {
82 template <
typename Element>
83 inline Element* GetRawPointer(Element* p) {
return p; }
89 #if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED) 92 # define GMOCK_WCHAR_T_IS_NATIVE_ 1 101 kBool, kInteger, kFloatingPoint, kOther
105 template <
typename T>
struct KindOf {
106 enum { value = kOther };
110 #define GMOCK_DECLARE_KIND_(type, kind) \ 111 template <> struct KindOf<type> { enum { value = kind }; } 113 GMOCK_DECLARE_KIND_(
bool, kBool);
116 GMOCK_DECLARE_KIND_(
char, kInteger);
117 GMOCK_DECLARE_KIND_(
signed char, kInteger);
118 GMOCK_DECLARE_KIND_(
unsigned char, kInteger);
119 GMOCK_DECLARE_KIND_(
short, kInteger);
120 GMOCK_DECLARE_KIND_(
unsigned short, kInteger);
121 GMOCK_DECLARE_KIND_(
int, kInteger);
122 GMOCK_DECLARE_KIND_(
unsigned int, kInteger);
123 GMOCK_DECLARE_KIND_(
long, kInteger);
124 GMOCK_DECLARE_KIND_(
unsigned long, kInteger);
125 GMOCK_DECLARE_KIND_(
long long, kInteger);
126 GMOCK_DECLARE_KIND_(
unsigned long long, kInteger);
128 #if GMOCK_WCHAR_T_IS_NATIVE_ 129 GMOCK_DECLARE_KIND_(
wchar_t, kInteger);
133 GMOCK_DECLARE_KIND_(
float, kFloatingPoint);
134 GMOCK_DECLARE_KIND_(
double, kFloatingPoint);
135 GMOCK_DECLARE_KIND_(
long double, kFloatingPoint);
137 #undef GMOCK_DECLARE_KIND_ 140 #define GMOCK_KIND_OF_(type) \ 141 static_cast< ::testing::internal::TypeKind>( \ 142 ::testing::internal::KindOf<type>::value) 153 template <TypeKind kFromKind,
typename From, TypeKind kToKind,
typename To>
154 using LosslessArithmeticConvertibleImpl = std::integral_constant<
158 (kFromKind == kBool) ?
true 161 : (kFromKind != kToKind) ? false
162 : (kFromKind == kInteger &&
165 (((
sizeof(From) <
sizeof(To)) &&
166 !(std::is_signed<From>::value && !std::is_signed<To>::value)) ||
169 ((
sizeof(From) ==
sizeof(To)) &&
170 (std::is_signed<From>::value == std::is_signed<To>::value)))
174 : (kFromKind == kFloatingPoint && (
sizeof(From) <=
sizeof(To))) ? true
186 template <
typename From,
typename To>
187 using LosslessArithmeticConvertible =
188 LosslessArithmeticConvertibleImpl<GMOCK_KIND_OF_(From), From,
189 GMOCK_KIND_OF_(To), To>;
193 class FailureReporterInterface {
200 virtual ~FailureReporterInterface() {}
203 virtual void ReportFailure(FailureType type,
const char* file,
int line,
204 const std::string& message) = 0;
208 GTEST_API_ FailureReporterInterface* GetFailureReporter();
215 inline void Assert(
bool condition,
const char* file,
int line,
216 const std::string& msg) {
218 GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal,
222 inline void Assert(
bool condition,
const char* file,
int line) {
223 Assert(condition, file, line,
"Assertion failed.");
228 inline void Expect(
bool condition,
const char* file,
int line,
229 const std::string& msg) {
231 GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
235 inline void Expect(
bool condition,
const char* file,
int line) {
236 Expect(condition, file, line,
"Expectation failed.");
248 const char kInfoVerbosity[] =
"info";
250 const char kWarningVerbosity[] =
"warning";
252 const char kErrorVerbosity[] =
"error";
256 GTEST_API_
bool LogIsVisible(LogSeverity severity);
265 GTEST_API_
void Log(LogSeverity severity,
const std::string& message,
266 int stack_frames_to_skip);
274 class WithoutMatchers {
277 friend GTEST_API_ WithoutMatchers GetWithoutMatchers();
281 GTEST_API_ WithoutMatchers GetWithoutMatchers();
286 # pragma warning(push) 287 # pragma warning(disable:4717) 295 template <
typename T>
297 Assert(
false,
"", -1,
"Internal error: attempt to return invalid value");
305 # pragma warning(pop) 324 template <
class RawContainer>
325 class StlContainerView {
327 typedef RawContainer type;
328 typedef const type& const_reference;
330 static const_reference ConstReference(
const RawContainer& container) {
331 static_assert(!std::is_const<RawContainer>::value,
332 "RawContainer type must not be const");
335 static type Copy(
const RawContainer& container) {
return container; }
339 template <
typename Element,
size_t N>
340 class StlContainerView<Element[N]> {
342 typedef typename std::remove_const<Element>::type RawElement;
343 typedef internal::NativeArray<RawElement> type;
349 typedef const type const_reference;
351 static const_reference ConstReference(
const Element (&array)[N]) {
352 static_assert(std::is_same<Element, RawElement>::value,
353 "Element type must not be const");
354 return type(array, N, RelationToSourceReference());
356 static type Copy(
const Element (&array)[N]) {
357 return type(array, N, RelationToSourceCopy());
363 template <
typename ElementPo
inter,
typename Size>
364 class StlContainerView< ::std::tuple<ElementPointer, Size> > {
366 typedef typename std::remove_const<
367 typename std::pointer_traits<ElementPointer>::element_type>::type
369 typedef internal::NativeArray<RawElement> type;
370 typedef const type const_reference;
372 static const_reference ConstReference(
373 const ::std::tuple<ElementPointer, Size>& array) {
374 return type(std::get<0>(array), std::get<1>(array),
375 RelationToSourceReference());
377 static type Copy(const ::std::tuple<ElementPointer, Size>& array) {
378 return type(std::get<0>(array), std::get<1>(array), RelationToSourceCopy());
384 template <
typename T>
class StlContainerView<T&>;
389 template <
typename T>
390 struct RemoveConstFromKey {
395 template <
typename K,
typename V>
396 struct RemoveConstFromKey<
std::pair<const K, V> > {
397 typedef std::pair<K, V> type;
402 GTEST_API_
void IllegalDoDefault(
const char* file,
int line);
404 template <
typename F,
typename Tuple,
size_t... Idx>
405 auto ApplyImpl(F&& f, Tuple&& args, IndexSequence<Idx...>) -> decltype(
406 std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...)) {
407 return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(args))...);
411 template <
typename F,
typename Tuple>
412 auto Apply(F&& f, Tuple&& args) -> decltype(
413 ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
414 MakeIndexSequence<std::tuple_size<
415 typename std::remove_reference<Tuple>::type>::value>())) {
416 return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
417 MakeIndexSequence<std::tuple_size<
418 typename std::remove_reference<Tuple>::type>::value>());
434 template <
typename T>
437 template <
typename R,
typename... Args>
438 struct Function<R(Args...)> {
440 static constexpr
size_t ArgumentCount =
sizeof...(Args);
442 using Arg = ElemFromList<I, Args...>;
443 using ArgumentTuple = std::tuple<Args...>;
444 using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
445 using MakeResultVoid = void(Args...);
446 using MakeResultIgnoredValue = IgnoredValue(Args...);
449 template <
typename R,
typename... Args>
450 constexpr
size_t Function<R(Args...)>::ArgumentCount;
453 # pragma warning(pop) 459 #endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ Definition: gmock-actions.h:154
Definition: gtest-internal.h:1322