Unverified Commit 8c82ba48 authored by BrukerJWD's avatar BrukerJWD Committed by GitHub
Browse files

Merge branch 'master' into isnice

parents 6bbf911a a651a4d4
This diff is collapsed.
This page lists all documentation wiki pages for Google Mock **1.6**
- **if you use a released version of Google Mock, please read the documentation for that specific version instead.**
* [ForDummies](V1_6_ForDummies.md) -- start here if you are new to Google Mock.
* [CheatSheet](V1_6_CheatSheet.md) -- a quick reference.
* [CookBook](V1_6_CookBook.md) -- recipes for doing various tasks using Google Mock.
* [FrequentlyAskedQuestions](V1_6_FrequentlyAskedQuestions.md) -- check here before asking a question on the mailing list.
To contribute code to Google Mock, read:
* [DevGuide](DevGuide.md) -- read this _before_ writing your first patch.
* [Pump Manual](http://code.google.com/p/googletest/wiki/V1_6_PumpManual) -- how we generate some of Google Mock's source files.
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This page lists all documentation wiki pages for Google Mock **(the SVN trunk version)**
- **if you use a released version of Google Mock, please read the documentation for that specific version instead.**
* [ForDummies](V1_7_ForDummies.md) -- start here if you are new to Google Mock.
* [CheatSheet](V1_7_CheatSheet.md) -- a quick reference.
* [CookBook](V1_7_CookBook.md) -- recipes for doing various tasks using Google Mock.
* [FrequentlyAskedQuestions](V1_7_FrequentlyAskedQuestions.md) -- check here before asking a question on the mailing list.
To contribute code to Google Mock, read:
* [DevGuide](DevGuide.md) -- read this _before_ writing your first patch.
* [Pump Manual](http://code.google.com/p/googletest/wiki/PumpManual) -- how we generate some of Google Mock's source files.
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
...@@ -26,13 +26,14 @@ ...@@ -26,13 +26,14 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file implements some commonly used actions. // This file implements some commonly used actions.
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
...@@ -46,9 +47,10 @@ ...@@ -46,9 +47,10 @@
#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_HAS_STD_TYPE_TRAITS_ // Defined by gtest-port.h via gmock-port.h. #if GTEST_LANG_CXX11 // Defined by gtest-port.h via gmock-port.h.
#include <functional>
#include <type_traits> #include <type_traits>
#endif #endif // GTEST_LANG_CXX11
namespace testing { namespace testing {
...@@ -96,7 +98,7 @@ struct BuiltInDefaultValueGetter<T, false> { ...@@ -96,7 +98,7 @@ struct BuiltInDefaultValueGetter<T, false> {
template <typename T> template <typename T>
class BuiltInDefaultValue { class BuiltInDefaultValue {
public: public:
#if GTEST_HAS_STD_TYPE_TRAITS_ #if GTEST_LANG_CXX11
// 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 +109,7 @@ class BuiltInDefaultValue { ...@@ -107,7 +109,7 @@ class BuiltInDefaultValue {
T, ::std::is_default_constructible<T>::value>::Get(); T, ::std::is_default_constructible<T>::value>::Get();
} }
#else // GTEST_HAS_STD_TYPE_TRAITS_ #else // GTEST_LANG_CXX11
// 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 +119,7 @@ class BuiltInDefaultValue { ...@@ -117,7 +119,7 @@ class BuiltInDefaultValue {
return BuiltInDefaultValueGetter<T, false>::Get(); return BuiltInDefaultValueGetter<T, false>::Get();
} }
#endif // GTEST_HAS_STD_TYPE_TRAITS_ #endif // GTEST_LANG_CXX11
}; };
// This partial specialization says that we use the same built-in // This partial specialization says that we use the same built-in
...@@ -135,7 +137,7 @@ template <typename T> ...@@ -135,7 +137,7 @@ template <typename T>
class BuiltInDefaultValue<T*> { class BuiltInDefaultValue<T*> {
public: public:
static bool Exists() { return true; } static bool Exists() { return true; }
static T* Get() { return NULL; } static T* Get() { return nullptr; }
}; };
// The following specializations define the default values for // The following specializations define the default values for
...@@ -218,11 +220,11 @@ class DefaultValue { ...@@ -218,11 +220,11 @@ class DefaultValue {
// Unsets the default value for type T. // Unsets the default value for type T.
static void Clear() { static void Clear() {
delete producer_; delete producer_;
producer_ = NULL; producer_ = nullptr;
} }
// Returns true iff the user has set the default value for type T. // Returns true iff the user has set the default value for type T.
static bool IsSet() { return producer_ != NULL; } static bool IsSet() { return producer_ != nullptr; }
// Returns true if T has a default return value set by the user or there // Returns true if T has a default return value set by the user or there
// exists a built-in default value. // exists a built-in default value.
...@@ -234,8 +236,8 @@ class DefaultValue { ...@@ -234,8 +236,8 @@ class DefaultValue {
// otherwise returns the built-in default value. Requires that Exists() // otherwise returns the built-in default value. Requires that Exists()
// is true, which ensures that the return value is well-defined. // is true, which ensures that the return value is well-defined.
static T Get() { static T Get() {
return producer_ == NULL ? return producer_ == nullptr ? internal::BuiltInDefaultValue<T>::Get()
internal::BuiltInDefaultValue<T>::Get() : producer_->Produce(); : producer_->Produce();
} }
private: private:
...@@ -280,12 +282,10 @@ class DefaultValue<T&> { ...@@ -280,12 +282,10 @@ class DefaultValue<T&> {
} }
// Unsets the default value for type T&. // Unsets the default value for type T&.
static void Clear() { static void Clear() { address_ = nullptr; }
address_ = NULL;
}
// Returns true iff the user has set the default value for type T&. // Returns true iff the user has set the default value for type T&.
static bool IsSet() { return address_ != NULL; } static bool IsSet() { return address_ != nullptr; }
// Returns true if T has a default return value set by the user or there // Returns true if T has a default return value set by the user or there
// exists a built-in default value. // exists a built-in default value.
...@@ -297,8 +297,8 @@ class DefaultValue<T&> { ...@@ -297,8 +297,8 @@ class DefaultValue<T&> {
// otherwise returns the built-in default value if there is one; // otherwise returns the built-in default value if there is one;
// otherwise aborts the process. // otherwise aborts the process.
static T& Get() { static T& Get() {
return address_ == NULL ? return address_ == nullptr ? internal::BuiltInDefaultValue<T&>::Get()
internal::BuiltInDefaultValue<T&>::Get() : *address_; : *address_;
} }
private: private:
...@@ -316,11 +316,11 @@ class DefaultValue<void> { ...@@ -316,11 +316,11 @@ class DefaultValue<void> {
// Points to the user-set default value for type T. // Points to the user-set default value for type T.
template <typename T> template <typename T>
typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = NULL; typename DefaultValue<T>::ValueProducer* DefaultValue<T>::producer_ = nullptr;
// Points to the user-set default value for type T&. // Points to the user-set default value for type T&.
template <typename T> template <typename T>
T* DefaultValue<T&>::address_ = NULL; T* DefaultValue<T&>::address_ = nullptr;
// Implement this interface to define an action for function type F. // Implement this interface to define an action for function type F.
template <typename F> template <typename F>
...@@ -359,14 +359,20 @@ class Action { ...@@ -359,14 +359,20 @@ class Action {
// Constructs a null Action. Needed for storing Action objects in // Constructs a null Action. Needed for storing Action objects in
// STL containers. // STL containers.
Action() : impl_(NULL) {} Action() {}
// Constructs an Action from its implementation. A NULL impl is #if GTEST_LANG_CXX11
// used to represent the "do-default" action. // Construct an Action from a specified callable.
explicit Action(ActionInterface<F>* impl) : impl_(impl) {} // This cannot take std::function directly, because then Action would not be
// directly constructible from lambda (it would require two conversions).
template <typename G,
typename = typename ::std::enable_if<
::std::is_constructible<::std::function<F>, G>::value>::type>
Action(G&& fun) : fun_(::std::forward<G>(fun)) {} // NOLINT
#endif
// Copy constructor. // Constructs an Action from its implementation.
Action(const Action& action) : impl_(action.impl_) {} explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
// This constructor allows us to turn an Action<Func> object into an // This constructor allows us to turn an Action<Func> object into an
// Action<F>, as long as F's arguments can be implicitly converted // Action<F>, as long as F's arguments can be implicitly converted
...@@ -376,7 +382,13 @@ class Action { ...@@ -376,7 +382,13 @@ class Action {
explicit Action(const Action<Func>& action); explicit Action(const Action<Func>& action);
// Returns true iff this is the DoDefault() action. // Returns true iff this is the DoDefault() action.
bool IsDoDefault() const { return impl_.get() == NULL; } bool IsDoDefault() const {
#if GTEST_LANG_CXX11
return impl_ == nullptr && fun_ == nullptr;
#else
return impl_ == NULL;
#endif
}
// Performs the action. Note that this method is const even though // Performs the action. Note that this method is const even though
// the corresponding method in ActionInterface is not. The reason // the corresponding method in ActionInterface is not. The reason
...@@ -384,14 +396,15 @@ class Action { ...@@ -384,14 +396,15 @@ class Action {
// another concrete action, not that the concrete action it binds to // another concrete action, not that the concrete action it binds to
// cannot change state. (Think of the difference between a const // cannot change state. (Think of the difference between a const
// pointer and a pointer to const.) // pointer and a pointer to const.)
Result Perform(const ArgumentTuple& args) const { Result Perform(ArgumentTuple args) const {
internal::Assert( if (IsDoDefault()) {
!IsDoDefault(), __FILE__, __LINE__, internal::IllegalDoDefault(__FILE__, __LINE__);
"You are using DoDefault() inside a composite action like " }
"DoAll() or WithArgs(). This is not supported for technical " #if GTEST_LANG_CXX11
"reasons. Please instead spell out the default action, or " if (fun_ != nullptr) {
"assign the default action to an Action variable and use " return internal::Apply(fun_, ::std::move(args));
"the variable in various places."); }
#endif
return impl_->Perform(args); return impl_->Perform(args);
} }
...@@ -399,6 +412,18 @@ class Action { ...@@ -399,6 +412,18 @@ class Action {
template <typename F1, typename F2> template <typename F1, typename F2>
friend class internal::ActionAdaptor; friend class internal::ActionAdaptor;
template <typename G>
friend class Action;
// In C++11, Action can be implemented either as a generic functor (through
// std::function), or legacy ActionInterface. In C++98, only ActionInterface
// is available. The invariants are as follows:
// * in C++98, impl_ is null iff this is the default action
// * in C++11, at most one of fun_ & impl_ may be nonnull; both are null iff
// this is the default action
#if GTEST_LANG_CXX11
::std::function<F> fun_;
#endif
internal::linked_ptr<ActionInterface<F> > impl_; internal::linked_ptr<ActionInterface<F> > impl_;
}; };
...@@ -414,7 +439,7 @@ class Action { ...@@ -414,7 +439,7 @@ class Action {
// template <typename Result, typename ArgumentTuple> // template <typename Result, typename ArgumentTuple>
// Result Perform(const ArgumentTuple& args) const { // Result Perform(const ArgumentTuple& args) const {
// // Processes the arguments and returns a result, using // // Processes the arguments and returns a result, using
// // tr1::get<N>(args) to get the N-th (0-based) argument in the tuple. // // std::get<N>(args) to get the N-th (0-based) argument in the tuple.
// } // }
// ... // ...
// }; // };
...@@ -530,6 +555,9 @@ struct ByMoveWrapper { ...@@ -530,6 +555,9 @@ struct ByMoveWrapper {
// statement, and conversion of the result of Return to Action<T(U)> is a // statement, and conversion of the result of Return to Action<T(U)> is a
// good place for that. // good place for that.
// //
// The real life example of the above scenario happens when an invocation
// of gtl::Container() is passed into Return.
//
template <typename R> template <typename R>
class ReturnAction { class ReturnAction {
public: public:
...@@ -749,7 +777,7 @@ class DoDefaultAction { ...@@ -749,7 +777,7 @@ class DoDefaultAction {
// This template type conversion operator allows DoDefault() to be // This template type conversion operator allows DoDefault() to be
// used in any function. // used in any function.
template <typename F> template <typename F>
operator Action<F>() const { return Action<F>(NULL); } operator Action<F>() const { return Action<F>(); } // NOLINT
}; };
// Implements the Assign action to set a given pointer referent to a // Implements the Assign action to set a given pointer referent to a
...@@ -810,7 +838,7 @@ class SetArgumentPointeeAction { ...@@ -810,7 +838,7 @@ class SetArgumentPointeeAction {
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
void Perform(const ArgumentTuple& args) const { void Perform(const ArgumentTuple& args) const {
CompileAssertTypesEqual<void, Result>(); CompileAssertTypesEqual<void, Result>();
*::testing::get<N>(args) = value_; *::std::get<N>(args) = value_;
} }
private: private:
...@@ -833,7 +861,7 @@ class SetArgumentPointeeAction<N, Proto, true> { ...@@ -833,7 +861,7 @@ class SetArgumentPointeeAction<N, Proto, true> {
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
void Perform(const ArgumentTuple& args) const { void Perform(const ArgumentTuple& args) const {
CompileAssertTypesEqual<void, Result>(); CompileAssertTypesEqual<void, Result>();
::testing::get<N>(args)->CopyFrom(*proto_); ::std::get<N>(args)->CopyFrom(*proto_);
} }
private: private:
...@@ -885,6 +913,28 @@ class InvokeMethodWithoutArgsAction { ...@@ -885,6 +913,28 @@ class InvokeMethodWithoutArgsAction {
GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction); GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
}; };
// Implements the InvokeWithoutArgs(callback) action.
template <typename CallbackType>
class InvokeCallbackWithoutArgsAction {
public:
// The c'tor takes ownership of the callback.
explicit InvokeCallbackWithoutArgsAction(CallbackType* callback)
: callback_(callback) {
callback->CheckIsRepeatable(); // Makes sure the callback is permanent.
}
// This type conversion operator template allows Invoke(callback) to
// be used wherever the callback's return type can be implicitly
// converted to that of the mock function.
template <typename Result, typename ArgumentTuple>
Result Perform(const ArgumentTuple&) const { return callback_->Run(); }
private:
const internal::linked_ptr<CallbackType> callback_;
GTEST_DISALLOW_ASSIGN_(InvokeCallbackWithoutArgsAction);
};
// Implements the IgnoreResult(action) action. // Implements the IgnoreResult(action) action.
template <typename A> template <typename A>
class IgnoreResultAction { class IgnoreResultAction {
...@@ -1029,9 +1079,9 @@ class DoBothAction { ...@@ -1029,9 +1079,9 @@ class DoBothAction {
// return sqrt(x*x + y*y); // return sqrt(x*x + y*y);
// } // }
// ... // ...
// EXEPCT_CALL(mock, Foo("abc", _, _)) // EXPECT_CALL(mock, Foo("abc", _, _))
// .WillOnce(Invoke(DistanceToOriginWithLabel)); // .WillOnce(Invoke(DistanceToOriginWithLabel));
// EXEPCT_CALL(mock, Bar(5, _, _)) // EXPECT_CALL(mock, Bar(5, _, _))
// .WillOnce(Invoke(DistanceToOriginWithIndex)); // .WillOnce(Invoke(DistanceToOriginWithIndex));
// //
// you could write // you could write
...@@ -1041,8 +1091,8 @@ class DoBothAction { ...@@ -1041,8 +1091,8 @@ class DoBothAction {
// return sqrt(x*x + y*y); // return sqrt(x*x + y*y);
// } // }
// ... // ...
// EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin)); // EXPECT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin));
// EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin)); // EXPECT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin));
typedef internal::IgnoredValue Unused; typedef internal::IgnoredValue Unused;
// This constructor allows us to turn an Action<From> object into an // This constructor allows us to turn an Action<From> object into an
...@@ -1052,7 +1102,14 @@ typedef internal::IgnoredValue Unused; ...@@ -1052,7 +1102,14 @@ typedef internal::IgnoredValue Unused;
template <typename To> template <typename To>
template <typename From> template <typename From>
Action<To>::Action(const Action<From>& from) Action<To>::Action(const Action<From>& from)
: impl_(new internal::ActionAdaptor<To, From>(from)) {} :
#if GTEST_LANG_CXX11
fun_(from.fun_),
#endif
impl_(from.impl_ == nullptr
? nullptr
: new internal::ActionAdaptor<To, From>(from)) {
}
// Creates an action that returns 'value'. 'value' is passed by value // Creates an action that returns 'value'. 'value' is passed by value
// instead of const reference - otherwise Return("string literal") // instead of const reference - otherwise Return("string literal")
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
...@@ -35,6 +34,8 @@ ...@@ -35,6 +34,8 @@
// cardinalities can be defined by the user implementing the // cardinalities can be defined by the user implementing the
// CardinalityInterface interface if necessary. // CardinalityInterface interface if necessary.
// GOOGLETEST_CM0002 DO NOT DELETE
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
...@@ -43,6 +44,9 @@ ...@@ -43,6 +44,9 @@
#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-port.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */)
namespace testing { namespace testing {
// To implement a cardinality Foo, define: // To implement a cardinality Foo, define:
...@@ -144,4 +148,6 @@ inline Cardinality MakeCardinality(const CardinalityInterface* c) { ...@@ -144,4 +148,6 @@ inline Cardinality MakeCardinality(const CardinalityInterface* c) {
} // namespace testing } // namespace testing
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment