aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock
diff options
context:
space:
mode:
Diffstat (limited to 'googlemock')
-rw-r--r--googlemock/docs/cheat_sheet.md2
-rw-r--r--googlemock/include/gmock/gmock-actions.h4
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h2
-rw-r--r--googlemock/include/gmock/gmock-generated-actions.h.pump2
-rw-r--r--googlemock/include/gmock/gmock-matchers.h85
-rw-r--r--googlemock/include/gmock/internal/gmock-internal-utils.h6
-rw-r--r--googlemock/include/gmock/internal/gmock-port.h6
-rw-r--r--googlemock/src/gmock_main.cc13
-rw-r--r--googlemock/test/gmock-actions_test.cc12
-rw-r--r--googlemock/test/gmock-internal-utils_test.cc18
-rw-r--r--googlemock/test/gmock-matchers_test.cc18
11 files changed, 72 insertions, 96 deletions
diff --git a/googlemock/docs/cheat_sheet.md b/googlemock/docs/cheat_sheet.md
index 975362bf..f6e7349f 100644
--- a/googlemock/docs/cheat_sheet.md
+++ b/googlemock/docs/cheat_sheet.md
@@ -266,7 +266,7 @@ Matcher | Description
| `IsTrue()` | `argument` evaluates to `true` in a Boolean context. |
| `IsNull()` | `argument` is a `NULL` pointer (raw or smart). |
| `NotNull()` | `argument` is a non-null pointer (raw or smart). |
-| `Optional(m)` | `argument` is `optional<>` that contains a value matching `m`. |
+| `Optional(m)` | `argument` is `optional<>` that contains a value matching `m`. (For testing whether an `optional<>` is set, check for equality with `nullopt`. You may need to use `Eq(nullopt)` if the inner type doesn't have `==`.)|
| `VariantWith<T>(m)` | `argument` is `variant<>` that holds the alternative of type T with a value matching `m`. |
| `Ref(variable)` | `argument` is a reference to `variable`. |
| `TypedEq<type>(value)` | `argument` has type `type` and is equal to `value`. You may need to use this instead of `Eq(value)` when the mock function is overloaded. |
diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h
index 21469070..c08d97b9 100644
--- a/googlemock/include/gmock/gmock-actions.h
+++ b/googlemock/include/gmock/gmock-actions.h
@@ -162,8 +162,8 @@ GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U);
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0);
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0);
-GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0);
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long long, 0); // NOLINT
+GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long long, 0); // NOLINT
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0);
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0);
diff --git a/googlemock/include/gmock/gmock-generated-actions.h b/googlemock/include/gmock/gmock-generated-actions.h
index cee96dae..5bb62667 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h
+++ b/googlemock/include/gmock/gmock-generated-actions.h
@@ -1638,7 +1638,7 @@ struct AdlTag {};
// InvokeArgumentAdl - a helper for InvokeArgument.
// The basic overloads are provided here for generic functors.
// Overloads for other custom-callables are provided in the
-// internal/custom/callback-actions.h header.
+// internal/custom/gmock-generated-actions.h header.
template <typename R, typename F>
R InvokeArgumentAdl(AdlTag, F f) {
diff --git a/googlemock/include/gmock/gmock-generated-actions.h.pump b/googlemock/include/gmock/gmock-generated-actions.h.pump
index 283abcdc..1fa5e776 100644
--- a/googlemock/include/gmock/gmock-generated-actions.h.pump
+++ b/googlemock/include/gmock/gmock-generated-actions.h.pump
@@ -564,7 +564,7 @@ struct AdlTag {};
// InvokeArgumentAdl - a helper for InvokeArgument.
// The basic overloads are provided here for generic functors.
// Overloads for other custom-callables are provided in the
-// internal/custom/callback-actions.h header.
+// internal/custom/gmock-generated-actions.h header.
$range i 0..n
$for i
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index e71570bc..99f1774a 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -247,56 +247,43 @@ inline Matcher<T> MatcherCast(const M& matcher) {
return internal::MatcherCastImpl<T, M>::Cast(matcher);
}
-// Implements SafeMatcherCast().
-//
-// FIXME: The intermediate SafeMatcherCastImpl class was introduced as a
-// workaround for a compiler bug, and can now be removed.
-template <typename T>
-class SafeMatcherCastImpl {
- public:
- // This overload handles polymorphic matchers and values only since
- // monomorphic matchers are handled by the next one.
- template <typename M>
- static inline Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
- return internal::MatcherCastImpl<T, M>::Cast(polymorphic_matcher_or_value);
- }
-
- // This overload handles monomorphic matchers.
- //
- // In general, if type T can be implicitly converted to type U, we can
- // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
- // contravariant): just keep a copy of the original Matcher<U>, convert the
- // argument from type T to U, and then pass it to the underlying Matcher<U>.
- // The only exception is when U is a reference and T is not, as the
- // underlying Matcher<U> may be interested in the argument's address, which
- // is not preserved in the conversion from T to U.
- template <typename U>
- static inline Matcher<T> Cast(const Matcher<U>& matcher) {
- // Enforce that T can be implicitly converted to U.
- GTEST_COMPILE_ASSERT_((std::is_convertible<T, U>::value),
- "T must be implicitly convertible to U");
- // Enforce that we are not converting a non-reference type T to a reference
- // type U.
- GTEST_COMPILE_ASSERT_(
- std::is_reference<T>::value || !std::is_reference<U>::value,
- cannot_convert_non_reference_arg_to_reference);
- // In case both T and U are arithmetic types, enforce that the
- // conversion is not lossy.
- typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
- typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
- const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
- const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
- GTEST_COMPILE_ASSERT_(
- kTIsOther || kUIsOther ||
- (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
- conversion_of_arithmetic_types_must_be_lossless);
- return MatcherCast<T>(matcher);
- }
-};
-
+// This overload handles polymorphic matchers and values only since
+// monomorphic matchers are handled by the next one.
template <typename T, typename M>
-inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) {
- return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
+inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher_or_value) {
+ return MatcherCast<T>(polymorphic_matcher_or_value);
+}
+
+// This overload handles monomorphic matchers.
+//
+// In general, if type T can be implicitly converted to type U, we can
+// safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
+// contravariant): just keep a copy of the original Matcher<U>, convert the
+// argument from type T to U, and then pass it to the underlying Matcher<U>.
+// The only exception is when U is a reference and T is not, as the
+// underlying Matcher<U> may be interested in the argument's address, which
+// is not preserved in the conversion from T to U.
+template <typename T, typename U>
+inline Matcher<T> SafeMatcherCast(const Matcher<U>& matcher) {
+ // Enforce that T can be implicitly converted to U.
+ GTEST_COMPILE_ASSERT_((std::is_convertible<T, U>::value),
+ "T must be implicitly convertible to U");
+ // Enforce that we are not converting a non-reference type T to a reference
+ // type U.
+ GTEST_COMPILE_ASSERT_(
+ std::is_reference<T>::value || !std::is_reference<U>::value,
+ cannot_convert_non_reference_arg_to_reference);
+ // In case both T and U are arithmetic types, enforce that the
+ // conversion is not lossy.
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
+ constexpr bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
+ constexpr bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
+ GTEST_COMPILE_ASSERT_(
+ kTIsOther || kUIsOther ||
+ (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
+ conversion_of_arithmetic_types_must_be_lossless);
+ return MatcherCast<T>(matcher);
}
// A<T>() returns a matcher that matches any value of type T.
diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h
index 5fd169e9..66cf857b 100644
--- a/googlemock/include/gmock/internal/gmock-internal-utils.h
+++ b/googlemock/include/gmock/internal/gmock-internal-utils.h
@@ -136,15 +136,13 @@ GMOCK_DECLARE_KIND_(int, kInteger);
GMOCK_DECLARE_KIND_(unsigned int, kInteger);
GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT
GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT
+GMOCK_DECLARE_KIND_(long long, kInteger); // NOLINT
+GMOCK_DECLARE_KIND_(unsigned long long, kInteger); // NOLINT
#if GMOCK_WCHAR_T_IS_NATIVE_
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);
diff --git a/googlemock/include/gmock/internal/gmock-port.h b/googlemock/include/gmock/internal/gmock-port.h
index 063e2929..70872ef3 100644
--- a/googlemock/include/gmock/internal/gmock-port.h
+++ b/googlemock/include/gmock/internal/gmock-port.h
@@ -42,6 +42,7 @@
#include <assert.h>
#include <stdlib.h>
+#include <cstdint>
#include <iostream>
// Most of the utilities needed for porting Google Mock are also
@@ -69,8 +70,7 @@
// Macros for declaring flags.
# define GMOCK_DECLARE_bool_(name) extern GTEST_API_ bool GMOCK_FLAG(name)
-# define GMOCK_DECLARE_int32_(name) \
- extern GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name)
+# define GMOCK_DECLARE_int32_(name) extern GTEST_API_ int32_t GMOCK_FLAG(name)
# define GMOCK_DECLARE_string_(name) \
extern GTEST_API_ ::std::string GMOCK_FLAG(name)
@@ -78,7 +78,7 @@
# define GMOCK_DEFINE_bool_(name, default_val, doc) \
GTEST_API_ bool GMOCK_FLAG(name) = (default_val)
# define GMOCK_DEFINE_int32_(name, default_val, doc) \
- GTEST_API_ ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val)
+ GTEST_API_ int32_t GMOCK_FLAG(name) = (default_val)
# define GMOCK_DEFINE_string_(name, default_val, doc) \
GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val)
diff --git a/googlemock/src/gmock_main.cc b/googlemock/src/gmock_main.cc
index 18c500f6..d9e71700 100644
--- a/googlemock/src/gmock_main.cc
+++ b/googlemock/src/gmock_main.cc
@@ -48,21 +48,14 @@ void loop() { RUN_ALL_TESTS(); }
#endif
#else
-
-// MS C++ compiler/linker has a bug on Windows (not on Windows CE), which
-// causes a link error when _tmain is defined in a static library and UNICODE
-// is enabled. For this reason instead of _tmain, main function is used on
-// Windows. See the following link to track the current status of this bug:
-// https://web.archive.org/web/20170912203238/connect.microsoft.com/VisualStudio/feedback/details/394464/wmain-link-error-in-the-static-library
-// // NOLINT
-#if GTEST_OS_WINDOWS_MOBILE
+#if __MSC_VER
# include <tchar.h> // NOLINT
GTEST_API_ int _tmain(int argc, TCHAR** argv) {
#else
GTEST_API_ int main(int argc, char** argv) {
-#endif // GTEST_OS_WINDOWS_MOBILE
- std::cout << "Running main() from gmock_main.cc\n";
+#endif // __MSC_VER
+ std::cout << "Running main() from " << __FILE__ << '\n';
// Since Google Mock depends on Google Test, InitGoogleMock() is
// also responsible for initializing Google Test. Therefore there's
// no need for calling testing::InitGoogleTest() separately.
diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc
index ae4fa20e..58a2d35a 100644
--- a/googlemock/test/gmock-actions_test.cc
+++ b/googlemock/test/gmock-actions_test.cc
@@ -80,8 +80,6 @@ using testing::SetArgumentPointee;
using testing::Unused;
using testing::WithArgs;
using testing::internal::BuiltInDefaultValue;
-using testing::internal::Int64;
-using testing::internal::UInt64;
#if !GTEST_OS_WINDOWS_MOBILE
using testing::SetErrnoAndReturn;
@@ -123,8 +121,9 @@ TEST(BuiltInDefaultValueTest, IsZeroForNumericTypes) {
EXPECT_EQ(0U, BuiltInDefaultValue<unsigned long>::Get()); // NOLINT
EXPECT_EQ(0, BuiltInDefaultValue<signed long>::Get()); // NOLINT
EXPECT_EQ(0, BuiltInDefaultValue<long>::Get()); // NOLINT
- EXPECT_EQ(0U, BuiltInDefaultValue<UInt64>::Get());
- EXPECT_EQ(0, BuiltInDefaultValue<Int64>::Get());
+ EXPECT_EQ(0U, BuiltInDefaultValue<unsigned long long>::Get()); // NOLINT
+ EXPECT_EQ(0, BuiltInDefaultValue<signed long long>::Get()); // NOLINT
+ EXPECT_EQ(0, BuiltInDefaultValue<long long>::Get()); // NOLINT
EXPECT_EQ(0, BuiltInDefaultValue<float>::Get());
EXPECT_EQ(0, BuiltInDefaultValue<double>::Get());
}
@@ -147,8 +146,9 @@ TEST(BuiltInDefaultValueTest, ExistsForNumericTypes) {
EXPECT_TRUE(BuiltInDefaultValue<unsigned long>::Exists()); // NOLINT
EXPECT_TRUE(BuiltInDefaultValue<signed long>::Exists()); // NOLINT
EXPECT_TRUE(BuiltInDefaultValue<long>::Exists()); // NOLINT
- EXPECT_TRUE(BuiltInDefaultValue<UInt64>::Exists());
- EXPECT_TRUE(BuiltInDefaultValue<Int64>::Exists());
+ EXPECT_TRUE(BuiltInDefaultValue<unsigned long long>::Exists()); // NOLINT
+ EXPECT_TRUE(BuiltInDefaultValue<signed long long>::Exists()); // NOLINT
+ EXPECT_TRUE(BuiltInDefaultValue<long long>::Exists()); // NOLINT
EXPECT_TRUE(BuiltInDefaultValue<float>::Exists());
EXPECT_TRUE(BuiltInDefaultValue<double>::Exists());
}
diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc
index 19ba6fe5..8019f4a3 100644
--- a/googlemock/test/gmock-internal-utils_test.cc
+++ b/googlemock/test/gmock-internal-utils_test.cc
@@ -36,6 +36,7 @@
#include <stdlib.h>
+#include <cstdint>
#include <map>
#include <memory>
#include <sstream>
@@ -172,9 +173,9 @@ TEST(KindOfTest, Integer) {
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned int)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long)); // NOLINT
+ EXPECT_EQ(kInteger, GMOCK_KIND_OF_(long long)); // NOLINT
+ EXPECT_EQ(kInteger, GMOCK_KIND_OF_(unsigned long long)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(wchar_t)); // NOLINT
- EXPECT_EQ(kInteger, GMOCK_KIND_OF_(Int64)); // NOLINT
- EXPECT_EQ(kInteger, GMOCK_KIND_OF_(UInt64)); // NOLINT
EXPECT_EQ(kInteger, GMOCK_KIND_OF_(size_t)); // NOLINT
#if GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN
// ssize_t is not defined on Windows and possibly some other OSes.
@@ -222,11 +223,12 @@ TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
EXPECT_TRUE((LosslessArithmeticConvertible<unsigned char, int>::value));
// Unsigned => larger unsigned is fine.
- EXPECT_TRUE(
- (LosslessArithmeticConvertible<unsigned short, UInt64>::value)); // NOLINT
+ EXPECT_TRUE((LosslessArithmeticConvertible<
+ unsigned short, uint64_t>::value)); // NOLINT
// Signed => unsigned is not fine.
- EXPECT_FALSE((LosslessArithmeticConvertible<short, UInt64>::value)); // NOLINT
+ EXPECT_FALSE((LosslessArithmeticConvertible<
+ short, uint64_t>::value)); // NOLINT
EXPECT_FALSE((LosslessArithmeticConvertible<
signed char, unsigned int>::value)); // NOLINT
@@ -242,12 +244,12 @@ TEST(LosslessArithmeticConvertibleTest, IntegerToInteger) {
EXPECT_FALSE((LosslessArithmeticConvertible<
unsigned char, signed char>::value));
EXPECT_FALSE((LosslessArithmeticConvertible<int, unsigned int>::value));
- EXPECT_FALSE((LosslessArithmeticConvertible<UInt64, Int64>::value));
+ EXPECT_FALSE((LosslessArithmeticConvertible<uint64_t, int64_t>::value));
// Larger size => smaller size is not fine.
EXPECT_FALSE((LosslessArithmeticConvertible<long, char>::value)); // NOLINT
EXPECT_FALSE((LosslessArithmeticConvertible<int, signed char>::value));
- EXPECT_FALSE((LosslessArithmeticConvertible<Int64, unsigned int>::value));
+ EXPECT_FALSE((LosslessArithmeticConvertible<int64_t, unsigned int>::value));
}
TEST(LosslessArithmeticConvertibleTest, IntegerToFloatingPoint) {
@@ -266,7 +268,7 @@ TEST(LosslessArithmeticConvertibleTest, FloatingPointToBool) {
TEST(LosslessArithmeticConvertibleTest, FloatingPointToInteger) {
EXPECT_FALSE((LosslessArithmeticConvertible<float, long>::value)); // NOLINT
- EXPECT_FALSE((LosslessArithmeticConvertible<double, Int64>::value));
+ EXPECT_FALSE((LosslessArithmeticConvertible<double, int64_t>::value));
EXPECT_FALSE((LosslessArithmeticConvertible<long double, int>::value));
}
diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc
index bc49cb62..e6e8c8f4 100644
--- a/googlemock/test/gmock-matchers_test.cc
+++ b/googlemock/test/gmock-matchers_test.cc
@@ -46,6 +46,7 @@
#include <time.h>
#include <array>
+#include <cstdint>
#include <deque>
#include <forward_list>
#include <functional>
@@ -2987,18 +2988,13 @@ TEST(MatcherAssertionTest, WorksWhenMatcherIsNotSatisfied) {
static unsigned short n; // NOLINT
n = 5;
- // VC++ prior to version 8.0 SP1 has a bug where it will not see any
- // functions declared in the namespace scope from within nested classes.
- // EXPECT/ASSERT_(NON)FATAL_FAILURE macros use nested classes so that all
- // namespace-level functions invoked inside them need to be explicitly
- // resolved.
- EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Gt(10)),
+ EXPECT_FATAL_FAILURE(ASSERT_THAT(n, Gt(10)),
"Value of: n\n"
"Expected: is > 10\n"
" Actual: 5" + OfType("unsigned short"));
n = 0;
EXPECT_NONFATAL_FAILURE(
- EXPECT_THAT(n, ::testing::AllOf(::testing::Le(7), ::testing::Ge(5))),
+ EXPECT_THAT(n, AllOf(Le(7), Ge(5))),
"Value of: n\n"
"Expected: (is <= 7) and (is >= 5)\n"
" Actual: 0" + OfType("unsigned short"));
@@ -3012,11 +3008,11 @@ TEST(MatcherAssertionTest, WorksForByRefArguments) {
static int n;
n = 0;
EXPECT_THAT(n, AllOf(Le(7), Ref(n)));
- EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Not(::testing::Ref(n))),
+ EXPECT_FATAL_FAILURE(ASSERT_THAT(n, Not(Ref(n))),
"Value of: n\n"
"Expected: does not reference the variable @");
// Tests the "Actual" part.
- EXPECT_FATAL_FAILURE(ASSERT_THAT(n, ::testing::Not(::testing::Ref(n))),
+ EXPECT_FATAL_FAILURE(ASSERT_THAT(n, Not(Ref(n))),
"Actual: 0" + OfType("int") + ", which is located @");
}
@@ -6028,9 +6024,9 @@ TEST_P(BipartiteRandomTest, LargerNets) {
int iters = GetParam().second;
MatchMatrix graph(static_cast<size_t>(nodes), static_cast<size_t>(nodes));
- auto seed = static_cast<testing::internal::UInt32>(GTEST_FLAG(random_seed));
+ auto seed = static_cast<uint32_t>(GTEST_FLAG(random_seed));
if (seed == 0) {
- seed = static_cast<testing::internal::UInt32>(time(nullptr));
+ seed = static_cast<uint32_t>(time(nullptr));
}
for (; iters > 0; --iters, ++seed) {