Makes ByRef(x) printable as a reference to x.
This commit is contained in:
parent
b5937dab69
commit
387bdd551d
@ -39,6 +39,7 @@
|
|||||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||||
|
|
||||||
#include <gmock/gmock-actions.h>
|
#include <gmock/gmock-actions.h>
|
||||||
|
#include <gmock/gmock-printers.h>
|
||||||
#include <gmock/internal/gmock-port.h>
|
#include <gmock/internal/gmock-port.h>
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
@ -321,6 +322,9 @@ class InvokeMethodAction {
|
|||||||
const MethodPtr method_ptr_;
|
const MethodPtr method_ptr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO(wan@google.com): ReferenceWrapper and ByRef() are neither
|
||||||
|
// action-specific nor variadic. Move them to a better place.
|
||||||
|
|
||||||
// A ReferenceWrapper<T> object represents a reference to type T,
|
// A ReferenceWrapper<T> object represents a reference to type T,
|
||||||
// which can be either const or not. It can be explicitly converted
|
// which can be either const or not. It can be explicitly converted
|
||||||
// from, and implicitly converted to, a T&. Unlike a reference,
|
// from, and implicitly converted to, a T&. Unlike a reference,
|
||||||
@ -341,6 +345,13 @@ class ReferenceWrapper {
|
|||||||
T* pointer_;
|
T* pointer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Allows the expression ByRef(x) to be printed as a reference to x.
|
||||||
|
template <typename T>
|
||||||
|
void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) {
|
||||||
|
T& value = ref;
|
||||||
|
UniversalPrinter<T&>::Print(value, os);
|
||||||
|
}
|
||||||
|
|
||||||
// CallableHelper has static methods for invoking "callables",
|
// CallableHelper has static methods for invoking "callables",
|
||||||
// i.e. function pointers and functors. It uses overloading to
|
// i.e. function pointers and functors. It uses overloading to
|
||||||
// provide a uniform interface for invoking different kinds of
|
// provide a uniform interface for invoking different kinds of
|
||||||
|
@ -43,6 +43,7 @@ $$}} This meta comment fixes auto-indentation in editors.
|
|||||||
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
|
||||||
|
|
||||||
#include <gmock/gmock-actions.h>
|
#include <gmock/gmock-actions.h>
|
||||||
|
#include <gmock/gmock-printers.h>
|
||||||
#include <gmock/internal/gmock-port.h>
|
#include <gmock/internal/gmock-port.h>
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
@ -123,6 +124,9 @@ class InvokeMethodAction {
|
|||||||
const MethodPtr method_ptr_;
|
const MethodPtr method_ptr_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO(wan@google.com): ReferenceWrapper and ByRef() are neither
|
||||||
|
// action-specific nor variadic. Move them to a better place.
|
||||||
|
|
||||||
// A ReferenceWrapper<T> object represents a reference to type T,
|
// A ReferenceWrapper<T> object represents a reference to type T,
|
||||||
// which can be either const or not. It can be explicitly converted
|
// which can be either const or not. It can be explicitly converted
|
||||||
// from, and implicitly converted to, a T&. Unlike a reference,
|
// from, and implicitly converted to, a T&. Unlike a reference,
|
||||||
@ -143,6 +147,13 @@ class ReferenceWrapper {
|
|||||||
T* pointer_;
|
T* pointer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Allows the expression ByRef(x) to be printed as a reference to x.
|
||||||
|
template <typename T>
|
||||||
|
void PrintTo(const ReferenceWrapper<T>& ref, ::std::ostream* os) {
|
||||||
|
T& value = ref;
|
||||||
|
UniversalPrinter<T&>::Print(value, os);
|
||||||
|
}
|
||||||
|
|
||||||
// CallableHelper has static methods for invoking "callables",
|
// CallableHelper has static methods for invoking "callables",
|
||||||
// i.e. function pointers and functors. It uses overloading to
|
// i.e. function pointers and functors. It uses overloading to
|
||||||
// provide a uniform interface for invoking different kinds of
|
// provide a uniform interface for invoking different kinds of
|
||||||
|
@ -71,7 +71,6 @@ _COMMON_GMOCK_SYMBOLS = [
|
|||||||
'Not',
|
'Not',
|
||||||
'NotNull',
|
'NotNull',
|
||||||
'Pointee',
|
'Pointee',
|
||||||
'PointeeIsInitializedProto',
|
|
||||||
'Property',
|
'Property',
|
||||||
'Ref',
|
'Ref',
|
||||||
'ResultOf',
|
'ResultOf',
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <gmock/gmock-generated-actions.h>
|
#include <gmock/gmock-generated-actions.h>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
@ -546,6 +547,15 @@ TEST(ByRefTest, ExplicitType) {
|
|||||||
// ByRef<Derived>(b);
|
// ByRef<Derived>(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests that Google Mock prints expression ByRef(x) as a reference to x.
|
||||||
|
TEST(ByRefTest, PrintsCorrectly) {
|
||||||
|
int n = 42;
|
||||||
|
::std::stringstream expected, actual;
|
||||||
|
testing::internal::UniversalPrinter<const int&>::Print(n, &expected);
|
||||||
|
testing::internal::UniversalPrint(ByRef(n), &actual);
|
||||||
|
EXPECT_EQ(expected.str(), actual.str());
|
||||||
|
}
|
||||||
|
|
||||||
// Tests InvokeArgument<N>(...).
|
// Tests InvokeArgument<N>(...).
|
||||||
|
|
||||||
// Tests using InvokeArgument with a nullary function.
|
// Tests using InvokeArgument with a nullary function.
|
||||||
|
Loading…
Reference in New Issue
Block a user