Makes gmock's Pointee() work for optional<T> (by Jeffrey Yasskin).
This commit is contained in:
parent
2fd619edd3
commit
ada23475e2
|
@ -73,7 +73,7 @@ struct PointeeOf<T*> { typedef T type; }; // NOLINT
|
||||||
// smart pointer, or returns p itself when p is already a raw pointer.
|
// smart pointer, or returns p itself when p is already a raw pointer.
|
||||||
// The following default implementation is for the smart pointer case.
|
// The following default implementation is for the smart pointer case.
|
||||||
template <typename Pointer>
|
template <typename Pointer>
|
||||||
inline typename Pointer::element_type* GetRawPointer(const Pointer& p) {
|
inline const typename Pointer::element_type* GetRawPointer(const Pointer& p) {
|
||||||
return p.get();
|
return p.get();
|
||||||
}
|
}
|
||||||
// This overloaded version is for the raw pointer case.
|
// This overloaded version is for the raw pointer case.
|
||||||
|
|
|
@ -2824,6 +2824,38 @@ TEST(PointeeTest, ReferenceToNonConstRawPointer) {
|
||||||
EXPECT_FALSE(m.Matches(p));
|
EXPECT_FALSE(m.Matches(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Minimal const-propagating pointer.
|
||||||
|
template <typename T>
|
||||||
|
class ConstPropagatingPtr {
|
||||||
|
public:
|
||||||
|
typedef T element_type;
|
||||||
|
|
||||||
|
ConstPropagatingPtr() : val_() {}
|
||||||
|
explicit ConstPropagatingPtr(T* t) : val_(t) {}
|
||||||
|
ConstPropagatingPtr(const ConstPropagatingPtr& other) : val_(other.val_) {}
|
||||||
|
|
||||||
|
T* get() { return val_; }
|
||||||
|
T& operator*() { return *val_; }
|
||||||
|
// Most smart pointers return non-const T* and T& from the next methods.
|
||||||
|
const T* get() const { return val_; }
|
||||||
|
const T& operator*() const { return *val_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
T* val_;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(PointeeTest, WorksWithConstPropagatingPointers) {
|
||||||
|
const Matcher< ConstPropagatingPtr<int> > m = Pointee(Lt(5));
|
||||||
|
int three = 3;
|
||||||
|
const ConstPropagatingPtr<int> co(&three);
|
||||||
|
ConstPropagatingPtr<int> o(&three);
|
||||||
|
EXPECT_TRUE(m.Matches(o));
|
||||||
|
EXPECT_TRUE(m.Matches(co));
|
||||||
|
*o = 6;
|
||||||
|
EXPECT_FALSE(m.Matches(o));
|
||||||
|
EXPECT_FALSE(m.Matches(ConstPropagatingPtr<int>()));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(PointeeTest, NeverMatchesNull) {
|
TEST(PointeeTest, NeverMatchesNull) {
|
||||||
const Matcher<const char*> m = Pointee(_);
|
const Matcher<const char*> m = Pointee(_);
|
||||||
EXPECT_FALSE(m.Matches(NULL));
|
EXPECT_FALSE(m.Matches(NULL));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user