123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489 |
- #ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
- #define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
- #include <stdio.h>
- #include <ostream> // NOLINT
- #include <string>
- #include <type_traits>
- #include <utility>
- #include <vector>
- #include "gmock/internal/gmock-port.h"
- #include "gtest/gtest.h"
- namespace testing {
- template <typename>
- class Matcher;
- namespace internal {
- GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100 4805)
- GTEST_API_ std::string JoinAsKeyValueTuple(
- const std::vector<const char*>& names, const Strings& values);
- GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name);
- template <typename Pointer>
- inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
- return p.get();
- }
- template <typename Element>
- inline const Element* GetRawPointer(const std::reference_wrapper<Element>& r) {
- return &r.get();
- }
- template <typename Element>
- inline Element* GetRawPointer(Element* p) {
- return p;
- }
- #define GMOCK_INTERNAL_WARNING_PUSH()
- #define GMOCK_INTERNAL_WARNING_CLANG(Level, Name)
- #define GMOCK_INTERNAL_WARNING_POP()
- #if defined(__clang__)
- #undef GMOCK_INTERNAL_WARNING_PUSH
- #define GMOCK_INTERNAL_WARNING_PUSH() _Pragma("clang diagnostic push")
- #undef GMOCK_INTERNAL_WARNING_CLANG
- #define GMOCK_INTERNAL_WARNING_CLANG(Level, Warning) \
- _Pragma(GMOCK_PP_INTERNAL_STRINGIZE(clang diagnostic Level Warning))
- #undef GMOCK_INTERNAL_WARNING_POP
- #define GMOCK_INTERNAL_WARNING_POP() _Pragma("clang diagnostic pop")
- #endif
- #if defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)
- #else
- #define GMOCK_WCHAR_T_IS_NATIVE_ 1
- #endif
- enum TypeKind { kBool, kInteger, kFloatingPoint, kOther };
- template <typename T>
- struct KindOf {
- enum { value = kOther };
- };
- #define GMOCK_DECLARE_KIND_(type, kind) \
- template <> \
- struct KindOf<type> { \
- enum { value = kind }; \
- }
- GMOCK_DECLARE_KIND_(bool, kBool);
- GMOCK_DECLARE_KIND_(char, kInteger);
- GMOCK_DECLARE_KIND_(signed char, kInteger);
- GMOCK_DECLARE_KIND_(unsigned char, kInteger);
- GMOCK_DECLARE_KIND_(short, kInteger);
- GMOCK_DECLARE_KIND_(unsigned short, kInteger);
- GMOCK_DECLARE_KIND_(int, kInteger);
- GMOCK_DECLARE_KIND_(unsigned int, kInteger);
- GMOCK_DECLARE_KIND_(long, kInteger);
- GMOCK_DECLARE_KIND_(unsigned long, kInteger);
- GMOCK_DECLARE_KIND_(long long, kInteger);
- GMOCK_DECLARE_KIND_(unsigned long long, kInteger);
- #if GMOCK_WCHAR_T_IS_NATIVE_
- GMOCK_DECLARE_KIND_(wchar_t, kInteger);
- #endif
- GMOCK_DECLARE_KIND_(float, kFloatingPoint);
- GMOCK_DECLARE_KIND_(double, kFloatingPoint);
- GMOCK_DECLARE_KIND_(long double, kFloatingPoint);
- #undef GMOCK_DECLARE_KIND_
- #define GMOCK_KIND_OF_(type) \
- static_cast< ::testing::internal::TypeKind>( \
- ::testing::internal::KindOf<type>::value)
- template <TypeKind kFromKind, typename From, TypeKind kToKind, typename To>
- using LosslessArithmeticConvertibleImpl = std::integral_constant<
- bool,
-
-
- (kFromKind == kBool) ? true
-
-
- : (kFromKind != kToKind) ? false
- : (kFromKind == kInteger &&
-
-
- (((sizeof(From) < sizeof(To)) &&
- !(std::is_signed<From>::value && !std::is_signed<To>::value)) ||
-
-
- ((sizeof(From) == sizeof(To)) &&
- (std::is_signed<From>::value == std::is_signed<To>::value)))
- ) ? true
-
-
- : (kFromKind == kFloatingPoint && (sizeof(From) <= sizeof(To))) ? true
- : false
-
- >;
- template <typename From, typename To>
- using LosslessArithmeticConvertible =
- LosslessArithmeticConvertibleImpl<GMOCK_KIND_OF_(From), From,
- GMOCK_KIND_OF_(To), To>;
- class FailureReporterInterface {
- public:
-
- enum FailureType { kNonfatal, kFatal };
- virtual ~FailureReporterInterface() = default;
-
- virtual void ReportFailure(FailureType type, const char* file, int line,
- const std::string& message) = 0;
- };
- GTEST_API_ FailureReporterInterface* GetFailureReporter();
- inline void Assert(bool condition, const char* file, int line,
- const std::string& msg) {
- if (!condition) {
- GetFailureReporter()->ReportFailure(FailureReporterInterface::kFatal, file,
- line, msg);
- }
- }
- inline void Assert(bool condition, const char* file, int line) {
- Assert(condition, file, line, "Assertion failed.");
- }
- inline void Expect(bool condition, const char* file, int line,
- const std::string& msg) {
- if (!condition) {
- GetFailureReporter()->ReportFailure(FailureReporterInterface::kNonfatal,
- file, line, msg);
- }
- }
- inline void Expect(bool condition, const char* file, int line) {
- Expect(condition, file, line, "Expectation failed.");
- }
- enum LogSeverity { kInfo = 0, kWarning = 1 };
- const char kInfoVerbosity[] = "info";
- const char kWarningVerbosity[] = "warning";
- const char kErrorVerbosity[] = "error";
- GTEST_API_ bool LogIsVisible(LogSeverity severity);
- GTEST_API_ void Log(LogSeverity severity, const std::string& message,
- int stack_frames_to_skip);
- class WithoutMatchers {
- private:
- WithoutMatchers() {}
- friend GTEST_API_ WithoutMatchers GetWithoutMatchers();
- };
- GTEST_API_ WithoutMatchers GetWithoutMatchers();
- template <typename T>
- inline T Invalid() {
- Assert(false, "", -1,
- "Internal error: attempt to return invalid value");
- #if defined(__GNUC__) || defined(__clang__)
- __builtin_unreachable();
- #elif defined(_MSC_VER)
- __assume(0);
- #else
- return Invalid<T>();
- #endif
- }
- template <class RawContainer>
- class StlContainerView {
- public:
- typedef RawContainer type;
- typedef const type& const_reference;
- static const_reference ConstReference(const RawContainer& container) {
- static_assert(!std::is_const<RawContainer>::value,
- "RawContainer type must not be const");
- return container;
- }
- static type Copy(const RawContainer& container) { return container; }
- };
- template <typename Element, size_t N>
- class StlContainerView<Element[N]> {
- public:
- typedef typename std::remove_const<Element>::type RawElement;
- typedef internal::NativeArray<RawElement> type;
-
-
-
-
-
- typedef const type const_reference;
- static const_reference ConstReference(const Element (&array)[N]) {
- static_assert(std::is_same<Element, RawElement>::value,
- "Element type must not be const");
- return type(array, N, RelationToSourceReference());
- }
- static type Copy(const Element (&array)[N]) {
- return type(array, N, RelationToSourceCopy());
- }
- };
- template <typename ElementPointer, typename Size>
- class StlContainerView< ::std::tuple<ElementPointer, Size> > {
- public:
- typedef typename std::remove_const<
- typename std::pointer_traits<ElementPointer>::element_type>::type
- RawElement;
- typedef internal::NativeArray<RawElement> type;
- typedef const type const_reference;
- static const_reference ConstReference(
- const ::std::tuple<ElementPointer, Size>& array) {
- return type(std::get<0>(array), std::get<1>(array),
- RelationToSourceReference());
- }
- static type Copy(const ::std::tuple<ElementPointer, Size>& array) {
- return type(std::get<0>(array), std::get<1>(array), RelationToSourceCopy());
- }
- };
- template <typename T>
- class StlContainerView<T&>;
- template <typename T>
- struct RemoveConstFromKey {
- typedef T type;
- };
- template <typename K, typename V>
- struct RemoveConstFromKey<std::pair<const K, V> > {
- typedef std::pair<K, V> type;
- };
- GTEST_API_ void IllegalDoDefault(const char* file, int line);
- template <typename F, typename Tuple, size_t... Idx>
- auto ApplyImpl(F&& f, Tuple&& args, std::index_sequence<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))...);
- }
- template <typename F, typename Tuple>
- auto Apply(F&& f, Tuple&& args)
- -> decltype(ApplyImpl(
- std::forward<F>(f), std::forward<Tuple>(args),
- std::make_index_sequence<std::tuple_size<
- typename std::remove_reference<Tuple>::type>::value>())) {
- return ApplyImpl(std::forward<F>(f), std::forward<Tuple>(args),
- std::make_index_sequence<std::tuple_size<
- typename std::remove_reference<Tuple>::type>::value>());
- }
- 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, Args...>;
- using ArgumentTuple = std::tuple<Args...>;
- using ArgumentMatcherTuple = std::tuple<Matcher<Args>...>;
- using MakeResultVoid = void(Args...);
- using MakeResultIgnoredValue = IgnoredValue(Args...);
- };
- #ifdef GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL
- template <typename R, typename... Args>
- constexpr size_t Function<R(Args...)>::ArgumentCount;
- #endif
- template <size_t I, typename T>
- using TupleElement = typename std::tuple_element<I, T>::type;
- bool Base64Unescape(const std::string& encoded, std::string* decoded);
- GTEST_DISABLE_MSC_WARNINGS_POP_()
- }
- }
- #endif
|