Merge pull request #611 from mark-chromium/gmock_cxx11
googlemock: Support C++11 language with pre-C++11 library
This commit is contained in:
commit
5bd7c2b589
@ -46,7 +46,7 @@
|
|||||||
#include "gmock/internal/gmock-internal-utils.h"
|
#include "gmock/internal/gmock-internal-utils.h"
|
||||||
#include "gmock/internal/gmock-port.h"
|
#include "gmock/internal/gmock-port.h"
|
||||||
|
|
||||||
#if GTEST_LANG_CXX11 // Defined by gtest-port.h via gmock-port.h.
|
#if GTEST_HAS_STD_TYPE_TRAITS_ // Defined by gtest-port.h via gmock-port.h.
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ struct BuiltInDefaultValueGetter<T, false> {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
class BuiltInDefaultValue {
|
class BuiltInDefaultValue {
|
||||||
public:
|
public:
|
||||||
#if GTEST_LANG_CXX11
|
#if GTEST_HAS_STD_TYPE_TRAITS_
|
||||||
// This function returns true iff type T has a built-in default value.
|
// This function returns true iff type T has a built-in default value.
|
||||||
static bool Exists() {
|
static bool Exists() {
|
||||||
return ::std::is_default_constructible<T>::value;
|
return ::std::is_default_constructible<T>::value;
|
||||||
@ -107,7 +107,7 @@ class BuiltInDefaultValue {
|
|||||||
T, ::std::is_default_constructible<T>::value>::Get();
|
T, ::std::is_default_constructible<T>::value>::Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // GTEST_LANG_CXX11
|
#else // GTEST_HAS_STD_TYPE_TRAITS_
|
||||||
// This function returns true iff type T has a built-in default value.
|
// This function returns true iff type T has a built-in default value.
|
||||||
static bool Exists() {
|
static bool Exists() {
|
||||||
return false;
|
return false;
|
||||||
@ -117,7 +117,7 @@ class BuiltInDefaultValue {
|
|||||||
return BuiltInDefaultValueGetter<T, false>::Get();
|
return BuiltInDefaultValueGetter<T, false>::Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // GTEST_LANG_CXX11
|
#endif // GTEST_HAS_STD_TYPE_TRAITS_
|
||||||
};
|
};
|
||||||
|
|
||||||
// This partial specialization says that we use the same built-in
|
// This partial specialization says that we use the same built-in
|
||||||
|
@ -214,7 +214,7 @@ class MyNonDefaultConstructible {
|
|||||||
int value_;
|
int value_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if GTEST_LANG_CXX11
|
#if GTEST_HAS_STD_TYPE_TRAITS_
|
||||||
|
|
||||||
TEST(BuiltInDefaultValueTest, ExistsForDefaultConstructibleType) {
|
TEST(BuiltInDefaultValueTest, ExistsForDefaultConstructibleType) {
|
||||||
EXPECT_TRUE(BuiltInDefaultValue<MyDefaultConstructible>::Exists());
|
EXPECT_TRUE(BuiltInDefaultValue<MyDefaultConstructible>::Exists());
|
||||||
@ -224,7 +224,7 @@ TEST(BuiltInDefaultValueTest, IsDefaultConstructedForDefaultConstructibleType) {
|
|||||||
EXPECT_EQ(42, BuiltInDefaultValue<MyDefaultConstructible>::Get().value());
|
EXPECT_EQ(42, BuiltInDefaultValue<MyDefaultConstructible>::Get().value());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // GTEST_LANG_CXX11
|
#endif // GTEST_HAS_STD_TYPE_TRAITS_
|
||||||
|
|
||||||
TEST(BuiltInDefaultValueTest, DoesNotExistForNonDefaultConstructibleType) {
|
TEST(BuiltInDefaultValueTest, DoesNotExistForNonDefaultConstructibleType) {
|
||||||
EXPECT_FALSE(BuiltInDefaultValue<MyNonDefaultConstructible>::Exists());
|
EXPECT_FALSE(BuiltInDefaultValue<MyNonDefaultConstructible>::Exists());
|
||||||
|
@ -1042,14 +1042,14 @@ TEST(IsNullTest, ReferenceToConstLinkedPtr) {
|
|||||||
EXPECT_FALSE(m.Matches(non_null_p));
|
EXPECT_FALSE(m.Matches(non_null_p));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GTEST_LANG_CXX11
|
#if GTEST_HAS_STD_FUNCTION_
|
||||||
TEST(IsNullTest, StdFunction) {
|
TEST(IsNullTest, StdFunction) {
|
||||||
const Matcher<std::function<void()>> m = IsNull();
|
const Matcher<std::function<void()>> m = IsNull();
|
||||||
|
|
||||||
EXPECT_TRUE(m.Matches(std::function<void()>()));
|
EXPECT_TRUE(m.Matches(std::function<void()>()));
|
||||||
EXPECT_FALSE(m.Matches([]{}));
|
EXPECT_FALSE(m.Matches([]{}));
|
||||||
}
|
}
|
||||||
#endif // GTEST_LANG_CXX11
|
#endif // GTEST_HAS_STD_FUNCTION_
|
||||||
|
|
||||||
// Tests that IsNull() describes itself properly.
|
// Tests that IsNull() describes itself properly.
|
||||||
TEST(IsNullTest, CanDescribeSelf) {
|
TEST(IsNullTest, CanDescribeSelf) {
|
||||||
@ -1090,14 +1090,14 @@ TEST(NotNullTest, ReferenceToConstLinkedPtr) {
|
|||||||
EXPECT_TRUE(m.Matches(non_null_p));
|
EXPECT_TRUE(m.Matches(non_null_p));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GTEST_LANG_CXX11
|
#if GTEST_HAS_STD_FUNCTION_
|
||||||
TEST(NotNullTest, StdFunction) {
|
TEST(NotNullTest, StdFunction) {
|
||||||
const Matcher<std::function<void()>> m = NotNull();
|
const Matcher<std::function<void()>> m = NotNull();
|
||||||
|
|
||||||
EXPECT_TRUE(m.Matches([]{}));
|
EXPECT_TRUE(m.Matches([]{}));
|
||||||
EXPECT_FALSE(m.Matches(std::function<void()>()));
|
EXPECT_FALSE(m.Matches(std::function<void()>()));
|
||||||
}
|
}
|
||||||
#endif // GTEST_LANG_CXX11
|
#endif // GTEST_HAS_STD_FUNCTION_
|
||||||
|
|
||||||
// Tests that NotNull() describes itself properly.
|
// Tests that NotNull() describes itself properly.
|
||||||
TEST(NotNullTest, CanDescribeSelf) {
|
TEST(NotNullTest, CanDescribeSelf) {
|
||||||
|
@ -358,8 +358,9 @@
|
|||||||
# define GTEST_HAS_STD_FUNCTION_ 1
|
# define GTEST_HAS_STD_FUNCTION_ 1
|
||||||
# define GTEST_HAS_STD_INITIALIZER_LIST_ 1
|
# define GTEST_HAS_STD_INITIALIZER_LIST_ 1
|
||||||
# define GTEST_HAS_STD_MOVE_ 1
|
# define GTEST_HAS_STD_MOVE_ 1
|
||||||
# define GTEST_HAS_STD_UNIQUE_PTR_ 1
|
|
||||||
# define GTEST_HAS_STD_SHARED_PTR_ 1
|
# define GTEST_HAS_STD_SHARED_PTR_ 1
|
||||||
|
# define GTEST_HAS_STD_TYPE_TRAITS_ 1
|
||||||
|
# define GTEST_HAS_STD_UNIQUE_PTR_ 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// C++11 specifies that <tuple> provides std::tuple.
|
// C++11 specifies that <tuple> provides std::tuple.
|
||||||
|
Loading…
Reference in New Issue
Block a user