gmock-actions.h   gmock-actions.h 
skipping to change at line 120 skipping to change at line 120
class BuiltInDefaultValue<type> { \ class BuiltInDefaultValue<type> { \
public: \ public: \
static bool Exists() { return true; } \ static bool Exists() { return true; } \
static type Get() { return value; } \ static type Get() { return value; } \
} }
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT
#if GTEST_HAS_GLOBAL_STRING #if GTEST_HAS_GLOBAL_STRING
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, ""); GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, "");
#endif // GTEST_HAS_GLOBAL_STRING #endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_STD_STRING
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, ""); GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, "");
#endif // GTEST_HAS_STD_STRING
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false); GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false);
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0'); GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0');
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0'); GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0');
GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0'); GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0');
// There's no need for a default action for signed wchar_t, as that // There's no need for a default action for signed wchar_t, as that
// type is the same as wchar_t for gcc, and invalid for MSVC. // type is the same as wchar_t for gcc, and invalid for MSVC.
// //
// There's also no need for a default action for unsigned wchar_t, as // There's also no need for a default action for unsigned wchar_t, as
// that type is the same as unsigned int for gcc, and invalid for // that type is the same as unsigned int for gcc, and invalid for
skipping to change at line 284 skipping to change at line 283
template <typename Function> template <typename Function>
friend class internal::MonomorphicDoDefaultActionImpl; friend class internal::MonomorphicDoDefaultActionImpl;
// This private constructor is reserved for implementing // This private constructor is reserved for implementing
// DoDefault(), the default action for a given mock function. // DoDefault(), the default action for a given mock function.
explicit ActionInterface(bool is_do_default) explicit ActionInterface(bool is_do_default)
: is_do_default_(is_do_default) {} : is_do_default_(is_do_default) {}
// True iff this action is DoDefault(). // True iff this action is DoDefault().
const bool is_do_default_; const bool is_do_default_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
}; };
// An Action<F> is a copyable and IMMUTABLE (except by assignment) // An Action<F> is a copyable and IMMUTABLE (except by assignment)
// object that represents an action to be taken when a mock function // object that represents an action to be taken when a mock function
// of type F is called. The implementation of Action<T> is just a // of type F is called. The implementation of Action<T> is just a
// linked_ptr to const ActionInterface<T>, so copying is fairly cheap. // linked_ptr to const ActionInterface<T>, so copying is fairly cheap.
// Don't inherit from Action! // Don't inherit from Action!
// //
// You can view an object implementing ActionInterface<F> as a // You can view an object implementing ActionInterface<F> as a
// concrete action (including its current state), and an Action<F> // concrete action (including its current state), and an Action<F>
skipping to change at line 313 skipping to change at line 314
Action() : impl_(NULL) {} Action() : impl_(NULL) {}
// Constructs an Action from its implementation. // Constructs an Action from its implementation.
explicit Action(ActionInterface<F>* impl) : impl_(impl) {} explicit Action(ActionInterface<F>* impl) : impl_(impl) {}
// Copy constructor. // Copy constructor.
Action(const Action& action) : impl_(action.impl_) {} Action(const Action& action) : impl_(action.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
// to Func's and Func's return type cann be implicitly converted to // to Func's and Func's return type can be implicitly converted to
// F's. // F's.
template <typename Func> template <typename Func>
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_->IsDoDefault(); } bool IsDoDefault() const { return impl_->IsDoDefault(); }
// 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
// is that a const Action<F> means that it cannot be re-bound to // is that a const Action<F> means that it cannot be re-bound to
skipping to change at line 382 skipping to change at line 385
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
virtual Result Perform(const ArgumentTuple& args) { virtual Result Perform(const ArgumentTuple& args) {
return impl_.template Perform<Result>(args); return impl_.template Perform<Result>(args);
} }
private: private:
Impl impl_; Impl impl_;
GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
}; };
Impl impl_; Impl impl_;
GTEST_DISALLOW_ASSIGN_(PolymorphicAction);
}; };
// Creates an Action from its implementation and returns it. The // Creates an Action from its implementation and returns it. The
// created Action object owns the implementation. // created Action object owns the implementation.
template <typename F> template <typename F>
Action<F> MakeAction(ActionInterface<F>* impl) { Action<F> MakeAction(ActionInterface<F>* impl) {
return Action<F>(impl); return Action<F>(impl);
} }
// Creates a polymorphic action from its implementation. This is // Creates a polymorphic action from its implementation. This is
skipping to change at line 421 skipping to change at line 428
class ActionAdaptor : public ActionInterface<F1> { class ActionAdaptor : public ActionInterface<F1> {
public: public:
typedef typename internal::Function<F1>::Result Result; typedef typename internal::Function<F1>::Result Result;
typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F1>::ArgumentTuple ArgumentTuple;
explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {} explicit ActionAdaptor(const Action<F2>& from) : impl_(from.impl_) {}
virtual Result Perform(const ArgumentTuple& args) { virtual Result Perform(const ArgumentTuple& args) {
return impl_->Perform(args); return impl_->Perform(args);
} }
private: private:
const internal::linked_ptr<ActionInterface<F2> > impl_; const internal::linked_ptr<ActionInterface<F2> > impl_;
GTEST_DISALLOW_ASSIGN_(ActionAdaptor);
}; };
// Implements the polymorphic Return(x) action, which can be used in // Implements the polymorphic Return(x) action, which can be used in
// any function that returns the type of x, regardless of the argument // any function that returns the type of x, regardless of the argument
// types. // types.
//
// Note: The value passed into Return must be converted into
// Function<F>::Result when this action is cast to Action<F> rather than
// when that action is performed. This is important in scenarios like
//
// MOCK_METHOD1(Method, T(U));
// ...
// {
// Foo foo;
// X x(&foo);
// EXPECT_CALL(mock, Method(_)).WillOnce(Return(x));
// }
//
// In the example above the variable x holds reference to foo which leaves
// scope and gets destroyed. If copying X just copies a reference to foo,
// that copy will be left with a hanging reference. If conversion to T
// makes a copy of foo, the above code is safe. To support that scenario, w
e
// need to make sure that the type conversion happens inside the EXPECT_CAL
L
// statement, and conversion of the result of Return to Action<T(U)> is a
// good place for that.
//
template <typename R> template <typename R>
class ReturnAction { class ReturnAction {
public: public:
// Constructs a ReturnAction object from the value to be returned. // Constructs a ReturnAction object from the value to be returned.
// 'value' is passed by value instead of by const reference in order // 'value' is passed by value instead of by const reference in order
// to allow Return("string literal") to compile. // to allow Return("string literal") to compile.
explicit ReturnAction(R value) : value_(value) {} explicit ReturnAction(R value) : value_(value) {}
// This template type conversion operator allows Return(x) to be // This template type conversion operator allows Return(x) to be
// used in ANY function that returns x's type. // used in ANY function that returns x's type.
skipping to change at line 454 skipping to change at line 485
// because MSVC produces duplicate symbols in different translation uni ts // because MSVC produces duplicate symbols in different translation uni ts
// in this case. Until MS fixes that bug we put Impl into the class sco pe // in this case. Until MS fixes that bug we put Impl into the class sco pe
// and put the typedef both here (for use in assert statement) and // and put the typedef both here (for use in assert statement) and
// in the Impl class. But both definitions must be the same. // in the Impl class. But both definitions must be the same.
typedef typename Function<F>::Result Result; typedef typename Function<F>::Result Result;
GMOCK_COMPILE_ASSERT_( GMOCK_COMPILE_ASSERT_(
!internal::is_reference<Result>::value, !internal::is_reference<Result>::value,
use_ReturnRef_instead_of_Return_to_return_a_reference); use_ReturnRef_instead_of_Return_to_return_a_reference);
return Action<F>(new Impl<F>(value_)); return Action<F>(new Impl<F>(value_));
} }
private: private:
// Implements the Return(x) action for a particular function type F. // Implements the Return(x) action for a particular function type F.
template <typename F> template <typename F>
class Impl : public ActionInterface<F> { class Impl : public ActionInterface<F> {
public: public:
typedef typename Function<F>::Result Result; typedef typename Function<F>::Result Result;
typedef typename Function<F>::ArgumentTuple ArgumentTuple; typedef typename Function<F>::ArgumentTuple ArgumentTuple;
explicit Impl(R value) : value_(value) {} // The implicit cast is necessary when Result has more than one
// single-argument constructor (e.g. Result is std::vector<int>) and R
// has a type conversion operator template. In that case, value_(value
)
// won't compile as the compiler doesn't known which constructor of
// Result to call. implicit_cast forces the compiler to convert R to
// Result without considering explicit constructors, thus resolving the
// ambiguity. value_ is then initialized using its copy constructor.
explicit Impl(R value)
: value_(::testing::internal::implicit_cast<Result>(value)) {}
virtual Result Perform(const ArgumentTuple&) { return value_; } virtual Result Perform(const ArgumentTuple&) { return value_; }
private: private:
R value_; GMOCK_COMPILE_ASSERT_(!internal::is_reference<Result>::value,
Result_cannot_be_a_reference_type);
Result value_;
GTEST_DISALLOW_ASSIGN_(Impl);
}; };
R value_; R value_;
GTEST_DISALLOW_ASSIGN_(ReturnAction);
}; };
// Implements the ReturnNull() action. // Implements the ReturnNull() action.
class ReturnNullAction { class ReturnNullAction {
public: public:
// Allows ReturnNull() to be used in any pointer-returning function. // Allows ReturnNull() to be used in any pointer-returning function.
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
static Result Perform(const ArgumentTuple&) { static Result Perform(const ArgumentTuple&) {
GMOCK_COMPILE_ASSERT_(internal::is_pointer<Result>::value, GMOCK_COMPILE_ASSERT_(internal::is_pointer<Result>::value,
ReturnNull_can_be_used_to_return_a_pointer_only); ReturnNull_can_be_used_to_return_a_pointer_only);
skipping to change at line 529 skipping to change at line 576
class Impl : public ActionInterface<F> { class Impl : public ActionInterface<F> {
public: public:
typedef typename Function<F>::Result Result; typedef typename Function<F>::Result Result;
typedef typename Function<F>::ArgumentTuple ArgumentTuple; typedef typename Function<F>::ArgumentTuple ArgumentTuple;
explicit Impl(T& ref) : ref_(ref) {} // NOLINT explicit Impl(T& ref) : ref_(ref) {} // NOLINT
virtual Result Perform(const ArgumentTuple&) { virtual Result Perform(const ArgumentTuple&) {
return ref_; return ref_;
} }
private: private:
T& ref_; T& ref_;
GTEST_DISALLOW_ASSIGN_(Impl);
}; };
T& ref_; T& ref_;
GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
}; };
// Implements the DoDefault() action for a particular function type F. // Implements the DoDefault() action for a particular function type F.
template <typename F> template <typename F>
class MonomorphicDoDefaultActionImpl : public ActionInterface<F> { class MonomorphicDoDefaultActionImpl : public ActionInterface<F> {
public: public:
typedef typename Function<F>::Result Result; typedef typename Function<F>::Result Result;
typedef typename Function<F>::ArgumentTuple ArgumentTuple; typedef typename Function<F>::ArgumentTuple ArgumentTuple;
MonomorphicDoDefaultActionImpl() : ActionInterface<F>(true) {} MonomorphicDoDefaultActionImpl() : ActionInterface<F>(true) {}
skipping to change at line 585 skipping to change at line 637
// particular value. // particular value.
template <typename T1, typename T2> template <typename T1, typename T2>
class AssignAction { class AssignAction {
public: public:
AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {} AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {}
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
void Perform(const ArgumentTuple& /* args */) const { void Perform(const ArgumentTuple& /* args */) const {
*ptr_ = value_; *ptr_ = value_;
} }
private: private:
T1* const ptr_; T1* const ptr_;
const T2 value_; const T2 value_;
GTEST_DISALLOW_ASSIGN_(AssignAction);
}; };
#if !GTEST_OS_WINDOWS_MOBILE #if !GTEST_OS_WINDOWS_MOBILE
// Implements the SetErrnoAndReturn action to simulate return from // Implements the SetErrnoAndReturn action to simulate return from
// various system calls and libc functions. // various system calls and libc functions.
template <typename T> template <typename T>
class SetErrnoAndReturnAction { class SetErrnoAndReturnAction {
public: public:
SetErrnoAndReturnAction(int errno_value, T result) SetErrnoAndReturnAction(int errno_value, T result)
skipping to change at line 605 skipping to change at line 660
class SetErrnoAndReturnAction { class SetErrnoAndReturnAction {
public: public:
SetErrnoAndReturnAction(int errno_value, T result) SetErrnoAndReturnAction(int errno_value, T result)
: errno_(errno_value), : errno_(errno_value),
result_(result) {} result_(result) {}
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
Result Perform(const ArgumentTuple& /* args */) const { Result Perform(const ArgumentTuple& /* args */) const {
errno = errno_; errno = errno_;
return result_; return result_;
} }
private: private:
const int errno_; const int errno_;
const T result_; const T result_;
GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction);
}; };
#endif // !GTEST_OS_WINDOWS_MOBILE #endif // !GTEST_OS_WINDOWS_MOBILE
// Implements the SetArgumentPointee<N>(x) action for any function // Implements the SetArgumentPointee<N>(x) action for any function
// whose N-th argument (0-based) is a pointer to x's type. The // whose N-th argument (0-based) is a pointer to x's type. The
// template parameter kIsProto is true iff type A is ProtocolMessage, // template parameter kIsProto is true iff type A is ProtocolMessage,
// proto2::Message, or a sub-class of those. // proto2::Message, or a sub-class of those.
template <size_t N, typename A, bool kIsProto> template <size_t N, typename A, bool kIsProto>
class SetArgumentPointeeAction { class SetArgumentPointeeAction {
skipping to change at line 631 skipping to change at line 689
explicit SetArgumentPointeeAction(const A& value) : value_(value) {} explicit SetArgumentPointeeAction(const A& value) : value_(value) {}
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>();
*::std::tr1::get<N>(args) = value_; *::std::tr1::get<N>(args) = value_;
} }
private: private:
const A value_; const A value_;
GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
}; };
template <size_t N, typename Proto> template <size_t N, typename Proto>
class SetArgumentPointeeAction<N, Proto, true> { class SetArgumentPointeeAction<N, Proto, true> {
public: public:
// Constructs an action that sets the variable pointed to by the // Constructs an action that sets the variable pointed to by the
// N-th function argument to 'proto'. Both ProtocolMessage and // N-th function argument to 'proto'. Both ProtocolMessage and
// proto2::Message have the CopyFrom() method, so the same // proto2::Message have the CopyFrom() method, so the same
// implementation works for both. // implementation works for both.
explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) { explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
skipping to change at line 649 skipping to change at line 709
// implementation works for both. // implementation works for both.
explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) { explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) {
proto_->CopyFrom(proto); proto_->CopyFrom(proto);
} }
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>();
::std::tr1::get<N>(args)->CopyFrom(*proto_); ::std::tr1::get<N>(args)->CopyFrom(*proto_);
} }
private: private:
const internal::linked_ptr<Proto> proto_; const internal::linked_ptr<Proto> proto_;
GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction);
}; };
// Implements the InvokeWithoutArgs(f) action. The template argument // Implements the InvokeWithoutArgs(f) action. The template argument
// FunctionImpl is the implementation type of f, which can be either a // FunctionImpl is the implementation type of f, which can be either a
// function pointer or a functor. InvokeWithoutArgs(f) can be used as an // function pointer or a functor. InvokeWithoutArgs(f) can be used as an
// Action<F> as long as f's type is compatible with F (i.e. f can be // Action<F> as long as f's type is compatible with F (i.e. f can be
// assigned to a tr1::function<F>). // assigned to a tr1::function<F>).
template <typename FunctionImpl> template <typename FunctionImpl>
class InvokeWithoutArgsAction { class InvokeWithoutArgsAction {
public: public:
skipping to change at line 670 skipping to change at line 733
public: public:
// The c'tor makes a copy of function_impl (either a function // The c'tor makes a copy of function_impl (either a function
// pointer or a functor). // pointer or a functor).
explicit InvokeWithoutArgsAction(FunctionImpl function_impl) explicit InvokeWithoutArgsAction(FunctionImpl function_impl)
: function_impl_(function_impl) {} : function_impl_(function_impl) {}
// Allows InvokeWithoutArgs(f) to be used as any action whose type is // Allows InvokeWithoutArgs(f) to be used as any action whose type is
// compatible with f. // compatible with f.
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
Result Perform(const ArgumentTuple&) { return function_impl_(); } Result Perform(const ArgumentTuple&) { return function_impl_(); }
private: private:
FunctionImpl function_impl_; FunctionImpl function_impl_;
GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction);
}; };
// Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action. // Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action.
template <class Class, typename MethodPtr> template <class Class, typename MethodPtr>
class InvokeMethodWithoutArgsAction { class InvokeMethodWithoutArgsAction {
public: public:
InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr) InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr)
: obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
skipping to change at line 685 skipping to change at line 751
template <class Class, typename MethodPtr> template <class Class, typename MethodPtr>
class InvokeMethodWithoutArgsAction { class InvokeMethodWithoutArgsAction {
public: public:
InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr) InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr)
: obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
Result Perform(const ArgumentTuple&) const { Result Perform(const ArgumentTuple&) const {
return (obj_ptr_->*method_ptr_)(); return (obj_ptr_->*method_ptr_)();
} }
private: private:
Class* const obj_ptr_; Class* const obj_ptr_;
const MethodPtr method_ptr_; const MethodPtr method_ptr_;
GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction);
}; };
// Implements the IgnoreResult(action) action. // Implements the IgnoreResult(action) action.
template <typename A> template <typename A>
class IgnoreResultAction { class IgnoreResultAction {
public: public:
explicit IgnoreResultAction(const A& action) : action_(action) {} explicit IgnoreResultAction(const A& action) : action_(action) {}
template <typename F> template <typename F>
operator Action<F>() const { operator Action<F>() const {
skipping to change at line 734 skipping to change at line 804
action_.Perform(args); action_.Perform(args);
} }
private: private:
// Type OriginalFunction is the same as F except that its return // Type OriginalFunction is the same as F except that its return
// type is IgnoredValue. // type is IgnoredValue.
typedef typename internal::Function<F>::MakeResultIgnoredValue typedef typename internal::Function<F>::MakeResultIgnoredValue
OriginalFunction; OriginalFunction;
const Action<OriginalFunction> action_; const Action<OriginalFunction> action_;
GTEST_DISALLOW_ASSIGN_(Impl);
}; };
const A action_; const A action_;
GTEST_DISALLOW_ASSIGN_(IgnoreResultAction);
}; };
// 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,
// ReferenceWrapper<T> can be copied and can survive template type // ReferenceWrapper<T> can be copied and can survive template type
// inference. This is used to support by-reference arguments in the // inference. This is used to support by-reference arguments in the
// InvokeArgument<N>(...) action. The idea was from "reference // InvokeArgument<N>(...) action. The idea was from "reference
// wrappers" in tr1, which we don't have in our source tree yet. // wrappers" in tr1, which we don't have in our source tree yet.
template <typename T> template <typename T>
skipping to change at line 801 skipping to change at line 875
: action1_(action1), action2_(action2) {} : action1_(action1), action2_(action2) {}
virtual Result Perform(const ArgumentTuple& args) { virtual Result Perform(const ArgumentTuple& args) {
action1_.Perform(args); action1_.Perform(args);
return action2_.Perform(args); return action2_.Perform(args);
} }
private: private:
const Action<VoidResult> action1_; const Action<VoidResult> action1_;
const Action<F> action2_; const Action<F> action2_;
GTEST_DISALLOW_ASSIGN_(Impl);
}; };
Action1 action1_; Action1 action1_;
Action2 action2_; Action2 action2_;
GTEST_DISALLOW_ASSIGN_(DoBothAction);
}; };
} // namespace internal } // namespace internal
// An Unused object can be implicitly constructed from ANY value. // An Unused object can be implicitly constructed from ANY value.
// This is handy when defining actions that ignore some or all of the // This is handy when defining actions that ignore some or all of the
// mock function arguments. For example, given // mock function arguments. For example, given
// //
// MOCK_METHOD3(Foo, double(const string& label, double x, double y)); // MOCK_METHOD3(Foo, double(const string& label, double x, double y));
// MOCK_METHOD3(Bar, double(int index, double x, double y)); // MOCK_METHOD3(Bar, double(int index, double x, double y));
 End of changes. 31 change blocks. 
5 lines changed or deleted 81 lines changed or added


 gmock-generated-actions.h   gmock-generated-actions.h 
skipping to change at line 618 skipping to change at line 618
} }
private: private:
typedef typename SelectArgs<Result, ArgumentTuple, typedef typename SelectArgs<Result, ArgumentTuple,
k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType; k1, k2, k3, k4, k5, k6, k7, k8, k9, k10>::type InnerFunctionType;
Action<InnerFunctionType> action_; Action<InnerFunctionType> action_;
}; };
const InnerAction action_; const InnerAction action_;
GTEST_DISALLOW_ASSIGN_(WithArgsAction);
}; };
// A macro from the ACTION* family (defined later in this file) // A macro from the ACTION* family (defined later in this file)
// defines an action that can be used in a mock function. Typically, // defines an action that can be used in a mock function. Typically,
// these actions only care about a subset of the arguments of the mock // these actions only care about a subset of the arguments of the mock
// function. For example, if such an action only uses the second // function. For example, if such an action only uses the second
// argument, it can be used in any mock function that takes >= 2 // argument, it can be used in any mock function that takes >= 2
// arguments where the type of the second argument is compatible. // arguments where the type of the second argument is compatible.
// //
// Therefore, the action implementation must be prepared to take more // Therefore, the action implementation must be prepared to take more
skipping to change at line 1409 skipping to change at line 1411
}\ }\
template <typename arg0_type, typename arg1_type, typename arg2_type, \ template <typename arg0_type, typename arg1_type, typename arg2_type, \
typename arg3_type, typename arg4_type, typename arg5_type, \ typename arg3_type, typename arg4_type, typename arg5_type, \
typename arg6_type, typename arg7_type, typename arg8_type, \ typename arg6_type, typename arg7_type, typename arg8_type, \
typename arg9_type>\ typename arg9_type>\
return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
arg9_type arg9) const;\ arg9_type arg9) const;\
GMOCK_INTERNAL_DEFN_##value_params\ GMOCK_INTERNAL_DEFN_##value_params\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(\ return ::testing::Action<F>(\
new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\ new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
}\ }\
GMOCK_INTERNAL_DEFN_##value_params\ GMOCK_INTERNAL_DEFN_##value_params\
private:\
GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\
};\ };\
template <GMOCK_INTERNAL_DECL_##template_params\ template <GMOCK_INTERNAL_DECL_##template_params\
GMOCK_INTERNAL_DECL_TYPE_##value_params>\ GMOCK_INTERNAL_DECL_TYPE_##value_params>\
inline GMOCK_ACTION_CLASS_(name, value_params)<\ inline GMOCK_ACTION_CLASS_(name, value_params)<\
GMOCK_INTERNAL_LIST_##template_params\ GMOCK_INTERNAL_LIST_##template_params\
GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\ GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
GMOCK_INTERNAL_DECL_##value_params) {\ GMOCK_INTERNAL_DECL_##value_params) {\
return GMOCK_ACTION_CLASS_(name, value_params)<\ return GMOCK_ACTION_CLASS_(name, value_params)<\
GMOCK_INTERNAL_LIST_##template_params\ GMOCK_INTERNAL_LIST_##template_params\
GMOCK_INTERNAL_LIST_TYPE_##value_params>(\ GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
skipping to change at line 1465 skipping to change at line 1471
Perform(this, args);\ Perform(this, args);\
}\ }\
template <typename arg0_type, typename arg1_type, typename arg2_type, \ template <typename arg0_type, typename arg1_type, typename arg2_type, \
typename arg3_type, typename arg4_type, typename arg5_type, \ typename arg3_type, typename arg4_type, typename arg5_type, \
typename arg6_type, typename arg7_type, typename arg8_type, \ typename arg6_type, typename arg7_type, typename arg8_type, \
typename arg9_type>\ typename arg9_type>\
return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
arg9_type arg9) const;\ arg9_type arg9) const;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>());\ return ::testing::Action<F>(new gmock_Impl<F>());\
}\ }\
private:\
GTEST_DISALLOW_ASSIGN_(name##Action);\
};\ };\
inline name##Action name() {\ inline name##Action name() {\
return name##Action();\ return name##Action();\
}\ }\
template <typename F>\ template <typename F>\
template <typename arg0_type, typename arg1_type, typename arg2_type, \ template <typename arg0_type, typename arg1_type, typename arg2_type, \
typename arg3_type, typename arg4_type, typename arg5_type, \ typename arg3_type, typename arg4_type, typename arg5_type, \
typename arg6_type, typename arg7_type, typename arg8_type, \ typename arg6_type, typename arg7_type, typename arg8_type, \
typename arg9_type>\ typename arg9_type>\
typename ::testing::internal::Function<F>::Result\ typename ::testing::internal::Function<F>::Result\
skipping to change at line 1508 skipping to change at line 1518
}\ }\
template <typename arg0_type, typename arg1_type, typename arg2_type, \ template <typename arg0_type, typename arg1_type, typename arg2_type, \
typename arg3_type, typename arg4_type, typename arg5_type, \ typename arg3_type, typename arg4_type, typename arg5_type, \
typename arg6_type, typename arg7_type, typename arg8_type, \ typename arg6_type, typename arg7_type, typename arg8_type, \
typename arg9_type>\ typename arg9_type>\
return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
arg9_type arg9) const;\ arg9_type arg9) const;\
p0##_type p0;\ p0##_type p0;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>(p0));\ return ::testing::Action<F>(new gmock_Impl<F>(p0));\
}\ }\
p0##_type p0;\ p0##_type p0;\
private:\
GTEST_DISALLOW_ASSIGN_(name##ActionP);\
};\ };\
template <typename p0##_type>\ template <typename p0##_type>\
inline name##ActionP<p0##_type> name(p0##_type p0) {\ inline name##ActionP<p0##_type> name(p0##_type p0) {\
return name##ActionP<p0##_type>(p0);\ return name##ActionP<p0##_type>(p0);\
}\ }\
template <typename p0##_type>\ template <typename p0##_type>\
template <typename F>\ template <typename F>\
template <typename arg0_type, typename arg1_type, typename arg2_type, \ template <typename arg0_type, typename arg1_type, typename arg2_type, \
typename arg3_type, typename arg4_type, typename arg5_type, \ typename arg3_type, typename arg4_type, typename arg5_type, \
typename arg6_type, typename arg7_type, typename arg8_type, \ typename arg6_type, typename arg7_type, typename arg8_type, \
skipping to change at line 1557 skipping to change at line 1571
template <typename arg0_type, typename arg1_type, typename arg2_type, \ template <typename arg0_type, typename arg1_type, typename arg2_type, \
typename arg3_type, typename arg4_type, typename arg5_type, \ typename arg3_type, typename arg4_type, typename arg5_type, \
typename arg6_type, typename arg7_type, typename arg8_type, \ typename arg6_type, typename arg7_type, typename arg8_type, \
typename arg9_type>\ typename arg9_type>\
return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
arg9_type arg9) const;\ arg9_type arg9) const;\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
private:\
GTEST_DISALLOW_ASSIGN_(name##ActionP2);\
};\ };\
template <typename p0##_type, typename p1##_type>\ template <typename p0##_type, typename p1##_type>\
inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \ inline name##ActionP2<p0##_type, p1##_type> name(p0##_type p0, \
p1##_type p1) {\ p1##_type p1) {\
return name##ActionP2<p0##_type, p1##_type>(p0, p1);\ return name##ActionP2<p0##_type, p1##_type>(p0, p1);\
}\ }\
template <typename p0##_type, typename p1##_type>\ template <typename p0##_type, typename p1##_type>\
template <typename F>\ template <typename F>\
template <typename arg0_type, typename arg1_type, typename arg2_type, \ template <typename arg0_type, typename arg1_type, typename arg2_type, \
typename arg3_type, typename arg4_type, typename arg5_type, \ typename arg3_type, typename arg4_type, typename arg5_type, \
skipping to change at line 1609 skipping to change at line 1627
typename arg3_type, typename arg4_type, typename arg5_type, \ typename arg3_type, typename arg4_type, typename arg5_type, \
typename arg6_type, typename arg7_type, typename arg8_type, \ typename arg6_type, typename arg7_type, typename arg8_type, \
typename arg9_type>\ typename arg9_type>\
return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
arg9_type arg9) const;\ arg9_type arg9) const;\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
private:\
GTEST_DISALLOW_ASSIGN_(name##ActionP3);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type>\ template <typename p0##_type, typename p1##_type, typename p2##_type>\
inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \ inline name##ActionP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
p1##_type p1, p2##_type p2) {\ p1##_type p1, p2##_type p2) {\
return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\ return name##ActionP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type>\ template <typename p0##_type, typename p1##_type, typename p2##_type>\
template <typename F>\ template <typename F>\
template <typename arg0_type, typename arg1_type, typename arg2_type, \ template <typename arg0_type, typename arg1_type, typename arg2_type, \
typename arg3_type, typename arg4_type, typename arg5_type, \ typename arg3_type, typename arg4_type, typename arg5_type, \
skipping to change at line 1667 skipping to change at line 1689
typename arg6_type, typename arg7_type, typename arg8_type, \ typename arg6_type, typename arg7_type, typename arg8_type, \
typename arg9_type>\ typename arg9_type>\
return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
arg9_type arg9) const;\ arg9_type arg9) const;\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
private:\
GTEST_DISALLOW_ASSIGN_(name##ActionP4);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type>\ typename p3##_type>\
inline name##ActionP4<p0##_type, p1##_type, p2##_type, \ inline name##ActionP4<p0##_type, p1##_type, p2##_type, \
p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
p3##_type p3) {\ p3##_type p3) {\
return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p 1, \ return name##ActionP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, p 1, \
p2, p3);\ p2, p3);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
skipping to change at line 1732 skipping to change at line 1758
typename arg9_type>\ typename arg9_type>\
return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
arg9_type arg9) const;\ arg9_type arg9) const;\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
private:\
GTEST_DISALLOW_ASSIGN_(name##ActionP5);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type>\ typename p3##_type, typename p4##_type>\
inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \ p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \
p4##_type p4) {\ p4##_type p4) {\
return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \ return name##ActionP5<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type>(p0, p1, p2, p3, p4);\ p4##_type>(p0, p1, p2, p3, p4);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
skipping to change at line 1800 skipping to change at line 1830
return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \
arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
arg9_type arg9) const;\ arg9_type arg9) const;\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5) );\ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5) );\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
private:\
GTEST_DISALLOW_ASSIGN_(name##ActionP6);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type>\ typename p3##_type, typename p4##_type, typename p5##_type>\
inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
p3##_type p3, p4##_type p4, p5##_type p5) {\ p3##_type p3, p4##_type p4, p5##_type p5) {\
return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \ return name##ActionP6<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\ p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
skipping to change at line 1872 skipping to change at line 1906
arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \
arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
arg9_type arg9) const;\ arg9_type arg9) const;\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
p6));\ p6));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
private:\
GTEST_DISALLOW_ASSIGN_(name##ActionP7);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type>\ typename p6##_type>\
inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \ p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
p6##_type p6) {\ p6##_type p6) {\
return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \ return name##ActionP7<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\ p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
skipping to change at line 1952 skipping to change at line 1990
arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \
arg9_type arg9) const;\ arg9_type arg9) const;\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
p6, p7));\ p6, p7));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
private:\
GTEST_DISALLOW_ASSIGN_(name##ActionP8);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type>\ typename p6##_type, typename p7##_type>\
inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \ p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
p6##_type p6, p7##_type p7) {\ p6##_type p6, p7##_type p7) {\
return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \ return name##ActionP8<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \ p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
skipping to change at line 2037 skipping to change at line 2079
arg9_type arg9) const;\ arg9_type arg9) const;\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
p8##_type p8;\ p8##_type p8;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
p6, p7, p8));\ p6, p7, p8));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
p8##_type p8;\ p8##_type p8;\
private:\
GTEST_DISALLOW_ASSIGN_(name##ActionP9);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type, typename p8##_type>\ typename p6##_type, typename p7##_type, typename p8##_type>\
inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type, p7##_type, \ p4##_type, p5##_type, p6##_type, p7##_type, \
p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \ p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \
p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
p8##_type p8) {\ p8##_type p8) {\
return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \ return name##ActionP9<p0##_type, p1##_type, p2##_type, p3##_type, \
skipping to change at line 2126 skipping to change at line 2172
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
p8##_type p8;\ p8##_type p8;\
p9##_type p9;\ p9##_type p9;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename F> operator ::testing::Action<F>() const {\ template <typename F> operator ::testing::Action<F>() const {\
return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \ return ::testing::Action<F>(new gmock_Impl<F>(p0, p1, p2, p3, p4, p5, \
p6, p7, p8, p9));\ p6, p7, p8, p9));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
p8##_type p8;\ p8##_type p8;\
p9##_type p9;\ p9##_type p9;\
private:\
GTEST_DISALLOW_ASSIGN_(name##ActionP10);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type, typename p8##_type, \ typename p6##_type, typename p7##_type, typename p8##_type, \
typename p9##_type>\ typename p9##_type>\
inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \ p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \
p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
p9##_type p9) {\ p9##_type p9) {\
skipping to change at line 2175 skipping to change at line 2225
name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type , \ name##ActionP10<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type , \
p5##_type, p6##_type, p7##_type, p8##_type, \ p5##_type, p6##_type, p7##_type, p8##_type, \
p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\ p9##_type>::gmock_Impl<F>::gmock_PerformImpl(\
GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
// TODO(wan@google.com): move the following to a different .h file // TODO(wan@google.com): move the following to a different .h file
// such that we don't have to run 'pump' every time the code is // such that we don't have to run 'pump' every time the code is
// updated. // updated.
namespace testing { namespace testing {
// The ACTION*() macros trigger warning C4100 (unreferenced formal
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
// the macro definition, as the warnings are generated when the macro
// is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4100)
#endif
// Various overloads for InvokeArgument<N>(). // Various overloads for InvokeArgument<N>().
// //
// The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
// (0-based) argument, which must be a k-ary callable, of the mock // (0-based) argument, which must be a k-ary callable, of the mock
// function, with arguments a1, a2, ..., a_k. // function, with arguments a1, a2, ..., a_k.
// //
// Notes: // Notes:
// //
// 1. The arguments are passed by value by default. If you need to // 1. The arguments are passed by value by default. If you need to
// pass an argument by reference, wrap it inside ByRef(). For // pass an argument by reference, wrap it inside ByRef(). For
skipping to change at line 2353 skipping to change at line 2413
AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) { AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8); return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8);
} }
ACTION_TEMPLATE(ReturnNew, ACTION_TEMPLATE(ReturnNew,
HAS_1_TEMPLATE_PARAMS(typename, T), HAS_1_TEMPLATE_PARAMS(typename, T),
AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9) ) { AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9) ) {
return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9);
} }
#ifdef _MSC_VER
#pragma warning(pop)
#endif
} // namespace testing } // namespace testing
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
 End of changes. 27 change blocks. 
0 lines changed or deleted 64 lines changed or added


 gmock-generated-function-mockers.h   gmock-generated-function-mockers.h 
skipping to change at line 45 skipping to change at line 45
// //
// This file implements function mockers of various arities. // This file implements function mockers of various arities.
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
#include <gmock/gmock-spec-builders.h> #include <gmock/gmock-spec-builders.h>
#include <gmock/internal/gmock-internal-utils.h> #include <gmock/internal/gmock-internal-utils.h>
namespace testing { namespace testing {
template <typename F>
class MockSpec;
namespace internal { namespace internal {
template <typename F> template <typename F>
class FunctionMockerBase; class FunctionMockerBase;
// Note: class FunctionMocker really belongs to the ::testing // Note: class FunctionMocker really belongs to the ::testing
// namespace. However if we define it in ::testing, MSVC will // namespace. However if we define it in ::testing, MSVC will
// complain when classes in ::testing::internal declare it as a // complain when classes in ::testing::internal declare it as a
// friend class template. To workaround this compiler bug, we define // friend class template. To workaround this compiler bug, we define
// FunctionMocker in ::testing::internal and import it into ::testing. // FunctionMocker in ::testing::internal and import it into ::testing.
skipping to change at line 74 skipping to change at line 70
internal::FunctionMockerBase<R()> { internal::FunctionMockerBase<R()> {
public: public:
typedef R F(); typedef R F();
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With() { MockSpec<F>& With() {
return this->current_spec(); return this->current_spec();
} }
R Invoke() { R Invoke() {
return InvokeWith(ArgumentTuple()); // Even though gcc and MSVC don't enforce it, 'this->' is required
// by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple());
} }
}; };
template <typename R, typename A1> template <typename R, typename A1>
class FunctionMocker<R(A1)> : public class FunctionMocker<R(A1)> : public
internal::FunctionMockerBase<R(A1)> { internal::FunctionMockerBase<R(A1)> {
public: public:
typedef R F(A1); typedef R F(A1);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1) { MockSpec<F>& With(const Matcher<A1>& m1) {
this->current_spec().SetMatchers(::std::tr1::make_tuple(m1)); this->current_spec().SetMatchers(::std::tr1::make_tuple(m1));
return this->current_spec(); return this->current_spec();
} }
R Invoke(A1 a1) { R Invoke(A1 a1) {
return InvokeWith(ArgumentTuple(a1)); // Even though gcc and MSVC don't enforce it, 'this->' is required
// by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1));
} }
}; };
template <typename R, typename A1, typename A2> template <typename R, typename A1, typename A2>
class FunctionMocker<R(A1, A2)> : public class FunctionMocker<R(A1, A2)> : public
internal::FunctionMockerBase<R(A1, A2)> { internal::FunctionMockerBase<R(A1, A2)> {
public: public:
typedef R F(A1, A2); typedef R F(A1, A2);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2) { MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2) {
this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2)); this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2));
return this->current_spec(); return this->current_spec();
} }
R Invoke(A1 a1, A2 a2) { R Invoke(A1 a1, A2 a2) {
return InvokeWith(ArgumentTuple(a1, a2)); // Even though gcc and MSVC don't enforce it, 'this->' is required
// by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2));
} }
}; };
template <typename R, typename A1, typename A2, typename A3> template <typename R, typename A1, typename A2, typename A3>
class FunctionMocker<R(A1, A2, A3)> : public class FunctionMocker<R(A1, A2, A3)> : public
internal::FunctionMockerBase<R(A1, A2, A3)> { internal::FunctionMockerBase<R(A1, A2, A3)> {
public: public:
typedef R F(A1, A2, A3); typedef R F(A1, A2, A3);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3) { const Matcher<A3>& m3) {
this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3)); this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3));
return this->current_spec(); return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3) { R Invoke(A1 a1, A2 a2, A3 a3) {
return InvokeWith(ArgumentTuple(a1, a2, a3)); // Even though gcc and MSVC don't enforce it, 'this->' is required
// by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3));
} }
}; };
template <typename R, typename A1, typename A2, typename A3, typename A4> template <typename R, typename A1, typename A2, typename A3, typename A4>
class FunctionMocker<R(A1, A2, A3, A4)> : public class FunctionMocker<R(A1, A2, A3, A4)> : public
internal::FunctionMockerBase<R(A1, A2, A3, A4)> { internal::FunctionMockerBase<R(A1, A2, A3, A4)> {
public: public:
typedef R F(A1, A2, A3, A4); typedef R F(A1, A2, A3, A4);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4) { const Matcher<A3>& m3, const Matcher<A4>& m4) {
this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4) ); this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4) );
return this->current_spec(); return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) {
return InvokeWith(ArgumentTuple(a1, a2, a3, a4)); // Even though gcc and MSVC don't enforce it, 'this->' is required
// by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4));
} }
}; };
template <typename R, typename A1, typename A2, typename A3, typename A4, template <typename R, typename A1, typename A2, typename A3, typename A4,
typename A5> typename A5>
class FunctionMocker<R(A1, A2, A3, A4, A5)> : public class FunctionMocker<R(A1, A2, A3, A4, A5)> : public
internal::FunctionMockerBase<R(A1, A2, A3, A4, A5)> { internal::FunctionMockerBase<R(A1, A2, A3, A4, A5)> {
public: public:
typedef R F(A1, A2, A3, A4, A5); typedef R F(A1, A2, A3, A4, A5);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) { const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5) {
this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4,
m5)); m5));
return this->current_spec(); return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
return InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5)); // Even though gcc and MSVC don't enforce it, 'this->' is required
// by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5));
} }
}; };
template <typename R, typename A1, typename A2, typename A3, typename A4, template <typename R, typename A1, typename A2, typename A3, typename A4,
typename A5, typename A6> typename A5, typename A6>
class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public class FunctionMocker<R(A1, A2, A3, A4, A5, A6)> : public
internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6)> { internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6)> {
public: public:
typedef R F(A1, A2, A3, A4, A5, A6); typedef R F(A1, A2, A3, A4, A5, A6);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
const Matcher<A6>& m6) { const Matcher<A6>& m6) {
this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
m6)); m6));
return this->current_spec(); return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
return InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6)); // Even though gcc and MSVC don't enforce it, 'this->' is required
// by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6));
} }
}; };
template <typename R, typename A1, typename A2, typename A3, typename A4, template <typename R, typename A1, typename A2, typename A3, typename A4,
typename A5, typename A6, typename A7> typename A5, typename A6, typename A7>
class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7)> : public
internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7)> { internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7)> {
public: public:
typedef R F(A1, A2, A3, A4, A5, A6, A7); typedef R F(A1, A2, A3, A4, A5, A6, A7);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
const Matcher<A6>& m6, const Matcher<A7>& m7) { const Matcher<A6>& m6, const Matcher<A7>& m7) {
this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
m6, m7)); m6, m7));
return this->current_spec(); return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
return InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7)); // Even though gcc and MSVC don't enforce it, 'this->' is required
// by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7));
} }
}; };
template <typename R, typename A1, typename A2, typename A3, typename A4, template <typename R, typename A1, typename A2, typename A3, typename A4,
typename A5, typename A6, typename A7, typename A8> typename A5, typename A6, typename A7, typename A8>
class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8)> : public
internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8)> { internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8)> {
public: public:
typedef R F(A1, A2, A3, A4, A5, A6, A7, A8); typedef R F(A1, A2, A3, A4, A5, A6, A7, A8);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) { const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8) {
this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
m6, m7, m8)); m6, m7, m8));
return this->current_spec(); return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
return InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8)); // Even though gcc and MSVC don't enforce it, 'this->' is required
// by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8));
} }
}; };
template <typename R, typename A1, typename A2, typename A3, typename A4, template <typename R, typename A1, typename A2, typename A3, typename A4,
typename A5, typename A6, typename A7, typename A8, typename A9> typename A5, typename A6, typename A7, typename A8, typename A9>
class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> : public
internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> { internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
public: public:
typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9); typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9);
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
skipping to change at line 249 skipping to change at line 281
MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2, MockSpec<F>& With(const Matcher<A1>& m1, const Matcher<A2>& m2,
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8, const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
const Matcher<A9>& m9) { const Matcher<A9>& m9) {
this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
m6, m7, m8, m9)); m6, m7, m8, m9));
return this->current_spec(); return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
return InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9)); // Even though gcc and MSVC don't enforce it, 'this->' is required
// by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a
9));
} }
}; };
template <typename R, typename A1, typename A2, typename A3, typename A4, template <typename R, typename A1, typename A2, typename A3, typename A4,
typename A5, typename A6, typename A7, typename A8, typename A9, typename A5, typename A6, typename A7, typename A8, typename A9,
typename A10> typename A10>
class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public class FunctionMocker<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> : public
internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) > { internal::FunctionMockerBase<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) > {
public: public:
typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
skipping to change at line 273 skipping to change at line 309
const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5, const Matcher<A3>& m3, const Matcher<A4>& m4, const Matcher<A5>& m5,
const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8, const Matcher<A6>& m6, const Matcher<A7>& m7, const Matcher<A8>& m8,
const Matcher<A9>& m9, const Matcher<A10>& m10) { const Matcher<A9>& m9, const Matcher<A10>& m10) {
this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5,
m6, m7, m8, m9, m10)); m6, m7, m8, m9, m10));
return this->current_spec(); return this->current_spec();
} }
R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
A10 a10) { A10 a10) {
return InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 // Even though gcc and MSVC don't enforce it, 'this->' is required
)); // by the C++ standard [14.6.4] here, as the base class type is
// dependent on the template argument (and thus shouldn't be
// looked into when resolving InvokeWith).
return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a
9,
a10));
} }
}; };
} // namespace internal } // namespace internal
// The style guide prohibits "using" statements in a namespace scope // The style guide prohibits "using" statements in a namespace scope
// inside a header file. However, the FunctionMocker class template // inside a header file. However, the FunctionMocker class template
// is meant to be defined in the ::testing namespace. The following // is meant to be defined in the ::testing namespace. The following
// line is just a trick for working around a bug in MSVC 8.0, which // line is just a trick for working around a bug in MSVC 8.0, which
// cannot handle it if we define FunctionMocker in ::testing. // cannot handle it if we define FunctionMocker in ::testing.
skipping to change at line 756 skipping to change at line 797
// before check point "1", the second Bar("a") must happen after check // before check point "1", the second Bar("a") must happen after check
// point "2", and nothing should happen between the two check // point "2", and nothing should happen between the two check
// points. The explicit check points make it easy to tell which // points. The explicit check points make it easy to tell which
// Bar("a") is called by which call to Foo(). // Bar("a") is called by which call to Foo().
template <typename F> template <typename F>
class MockFunction; class MockFunction;
template <typename R> template <typename R>
class MockFunction<R()> { class MockFunction<R()> {
public: public:
MockFunction() {}
MOCK_METHOD0_T(Call, R()); MOCK_METHOD0_T(Call, R());
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
}; };
template <typename R, typename A0> template <typename R, typename A0>
class MockFunction<R(A0)> { class MockFunction<R(A0)> {
public: public:
MockFunction() {}
MOCK_METHOD1_T(Call, R(A0)); MOCK_METHOD1_T(Call, R(A0));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
}; };
template <typename R, typename A0, typename A1> template <typename R, typename A0, typename A1>
class MockFunction<R(A0, A1)> { class MockFunction<R(A0, A1)> {
public: public:
MockFunction() {}
MOCK_METHOD2_T(Call, R(A0, A1)); MOCK_METHOD2_T(Call, R(A0, A1));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
}; };
template <typename R, typename A0, typename A1, typename A2> template <typename R, typename A0, typename A1, typename A2>
class MockFunction<R(A0, A1, A2)> { class MockFunction<R(A0, A1, A2)> {
public: public:
MockFunction() {}
MOCK_METHOD3_T(Call, R(A0, A1, A2)); MOCK_METHOD3_T(Call, R(A0, A1, A2));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
}; };
template <typename R, typename A0, typename A1, typename A2, typename A3> template <typename R, typename A0, typename A1, typename A2, typename A3>
class MockFunction<R(A0, A1, A2, A3)> { class MockFunction<R(A0, A1, A2, A3)> {
public: public:
MockFunction() {}
MOCK_METHOD4_T(Call, R(A0, A1, A2, A3)); MOCK_METHOD4_T(Call, R(A0, A1, A2, A3));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
}; };
template <typename R, typename A0, typename A1, typename A2, typename A3, template <typename R, typename A0, typename A1, typename A2, typename A3,
typename A4> typename A4>
class MockFunction<R(A0, A1, A2, A3, A4)> { class MockFunction<R(A0, A1, A2, A3, A4)> {
public: public:
MockFunction() {}
MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4)); MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
}; };
template <typename R, typename A0, typename A1, typename A2, typename A3, template <typename R, typename A0, typename A1, typename A2, typename A3,
typename A4, typename A5> typename A4, typename A5>
class MockFunction<R(A0, A1, A2, A3, A4, A5)> { class MockFunction<R(A0, A1, A2, A3, A4, A5)> {
public: public:
MockFunction() {}
MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5)); MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
}; };
template <typename R, typename A0, typename A1, typename A2, typename A3, template <typename R, typename A0, typename A1, typename A2, typename A3,
typename A4, typename A5, typename A6> typename A4, typename A5, typename A6>
class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> { class MockFunction<R(A0, A1, A2, A3, A4, A5, A6)> {
public: public:
MockFunction() {}
MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6)); MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
}; };
template <typename R, typename A0, typename A1, typename A2, typename A3, template <typename R, typename A0, typename A1, typename A2, typename A3,
typename A4, typename A5, typename A6, typename A7> typename A4, typename A5, typename A6, typename A7>
class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> { class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7)> {
public: public:
MockFunction() {}
MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7)); MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
}; };
template <typename R, typename A0, typename A1, typename A2, typename A3, template <typename R, typename A0, typename A1, typename A2, typename A3,
typename A4, typename A5, typename A6, typename A7, typename A8> typename A4, typename A5, typename A6, typename A7, typename A8>
class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> { class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8)> {
public: public:
MockFunction() {}
MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8)); MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
}; };
template <typename R, typename A0, typename A1, typename A2, typename A3, template <typename R, typename A0, typename A1, typename A2, typename A3,
typename A4, typename A5, typename A6, typename A7, typename A8, typename A4, typename A5, typename A6, typename A7, typename A8,
typename A9> typename A9>
class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> { class MockFunction<R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)> {
public: public:
MockFunction() {}
MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)); MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9));
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
}; };
} // namespace testing } // namespace testing
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
 End of changes. 34 change blocks. 
16 lines changed or deleted 113 lines changed or added


 gmock-generated-matchers.h   gmock-generated-matchers.h 
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! // This file was GENERATED by command:
// pump.py gmock-generated-matchers.h.pump
// DO NOT EDIT BY HAND!!!
// Copyright 2008, Google Inc. // Copyright 2008, Google Inc.
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
skipping to change at line 92 skipping to change at line 94
get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t), get<k9>(t)); get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t), get<k9>(t));
} }
}; };
// The following specialization is used for 0 ~ 9 selectors. // The following specialization is used for 0 ~ 9 selectors.
template <class Tuple> template <class Tuple>
class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> { class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
public: public:
typedef ::std::tr1::tuple<> type; typedef ::std::tr1::tuple<> type;
static type GetSelectedFields(const Tuple& t) { static type GetSelectedFields(const Tuple& /* t */) {
using ::std::tr1::get; using ::std::tr1::get;
return type(); return type();
} }
}; };
template <class Tuple, int k0> template <class Tuple, int k0>
class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> { class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
public: public:
typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type; typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type;
static type GetSelectedFields(const Tuple& t) { static type GetSelectedFields(const Tuple& t) {
skipping to change at line 232 skipping to change at line 234
// ArgsTuple may have top-level const or reference modifiers. // ArgsTuple may have top-level const or reference modifiers.
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(ArgsTuple)) RawArgsTu ple; typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(ArgsTuple)) RawArgsTu ple;
typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5,
k6, k7, k8, k9>::type SelectedArgs; k6, k7, k8, k9>::type SelectedArgs;
typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher; typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher;
template <typename InnerMatcher> template <typename InnerMatcher>
explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
: inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {} : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
virtual bool Matches(ArgsTuple args) const { virtual bool MatchAndExplain(ArgsTuple args,
return inner_matcher_.Matches(GetSelectedArgs(args)); MatchResultListener* listener) const {
const SelectedArgs& selected_args = GetSelectedArgs(args);
if (!listener->IsInterested())
return inner_matcher_.Matches(selected_args);
PrintIndices(listener->stream());
*listener << "are " << PrintToString(selected_args);
StringMatchResultListener inner_listener;
const bool match = inner_matcher_.MatchAndExplain(selected_args,
&inner_listener);
PrintIfNotEmpty(inner_listener.str(), listener->stream());
return match;
} }
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
*os << "are a tuple ";
PrintIndices(os); PrintIndices(os);
inner_matcher_.DescribeTo(os); inner_matcher_.DescribeTo(os);
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "are a tuple ";
PrintIndices(os); PrintIndices(os);
inner_matcher_.DescribeNegationTo(os); inner_matcher_.DescribeNegationTo(os);
} }
virtual void ExplainMatchResultTo(ArgsTuple args,
::std::ostream* os) const {
inner_matcher_.ExplainMatchResultTo(GetSelectedArgs(args), os);
}
private: private:
static SelectedArgs GetSelectedArgs(ArgsTuple args) { static SelectedArgs GetSelectedArgs(ArgsTuple args) {
return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8,
k9>::GetSelectedFields(args); k9>::GetSelectedFields(args);
} }
// Prints the indices of the selected fields. // Prints the indices of the selected fields.
static void PrintIndices(::std::ostream* os) { static void PrintIndices(::std::ostream* os) {
*os << "are a tuple whose fields ("; *os << "whose fields (";
const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 }; const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 };
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
if (indices[i] < 0) if (indices[i] < 0)
break; break;
if (i >= 1) if (i >= 1)
*os << ", "; *os << ", ";
*os << "#" << indices[i]; *os << "#" << indices[i];
} }
*os << ") "; *os << ") ";
} }
const MonomorphicInnerMatcher inner_matcher_; const MonomorphicInnerMatcher inner_matcher_;
GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl);
}; };
template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1, template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1,
int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1,
int k8 = -1, int k9 = -1> int k8 = -1, int k9 = -1>
class ArgsMatcher { class ArgsMatcher {
public: public:
explicit ArgsMatcher(const InnerMatcher& inner_matcher) explicit ArgsMatcher(const InnerMatcher& inner_matcher)
: inner_matcher_(inner_matcher) {} : inner_matcher_(inner_matcher) {}
template <typename ArgsTuple> template <typename ArgsTuple>
operator Matcher<ArgsTuple>() const { operator Matcher<ArgsTuple>() const {
return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k 5, return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k 5,
k6, k7, k8, k9>(inner_matcher_)); k6, k7, k8, k9>(inner_matcher_));
} }
private:
const InnerMatcher inner_matcher_; const InnerMatcher inner_matcher_;
GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
}; };
// Implements ElementsAre() of 1-10 arguments. // Implements ElementsAre() of 1-10 arguments.
template <typename T1> template <typename T1>
class ElementsAreMatcher1 { class ElementsAreMatcher1 {
public: public:
explicit ElementsAreMatcher1(const T1& e1) : e1_(e1) {} explicit ElementsAreMatcher1(const T1& e1) : e1_(e1) {}
template <typename Container> template <typename Container>
skipping to change at line 320 skipping to change at line 336
// added the linked_ptr in it to our other linked_ptrs list. // added the linked_ptr in it to our other linked_ptrs list.
// Hence we implement ElementsAreMatcher1 specially to avoid using // Hence we implement ElementsAreMatcher1 specially to avoid using
// a local array. // a local array.
const Matcher<const Element&> matcher = const Matcher<const Element&> matcher =
MatcherCast<const Element&>(e1_); MatcherCast<const Element&>(e1_);
return MakeMatcher(new ElementsAreMatcherImpl<Container>(&matcher, 1)); return MakeMatcher(new ElementsAreMatcherImpl<Container>(&matcher, 1));
} }
private: private:
const T1& e1_; const T1& e1_;
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher1);
}; };
template <typename T1, typename T2> template <typename T1, typename T2>
class ElementsAreMatcher2 { class ElementsAreMatcher2 {
public: public:
ElementsAreMatcher2(const T1& e1, const T2& e2) : e1_(e1), e2_(e2) {} ElementsAreMatcher2(const T1& e1, const T2& e2) : e1_(e1), e2_(e2) {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
skipping to change at line 345 skipping to change at line 363
MatcherCast<const Element&>(e1_), MatcherCast<const Element&>(e1_),
MatcherCast<const Element&>(e2_), MatcherCast<const Element&>(e2_),
}; };
return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 2)); return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 2));
} }
private: private:
const T1& e1_; const T1& e1_;
const T2& e2_; const T2& e2_;
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher2);
}; };
template <typename T1, typename T2, typename T3> template <typename T1, typename T2, typename T3>
class ElementsAreMatcher3 { class ElementsAreMatcher3 {
public: public:
ElementsAreMatcher3(const T1& e1, const T2& e2, const T3& e3) : e1_(e1), ElementsAreMatcher3(const T1& e1, const T2& e2, const T3& e3) : e1_(e1),
e2_(e2), e3_(e3) {} e2_(e2), e3_(e3) {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
skipping to change at line 373 skipping to change at line 393
MatcherCast<const Element&>(e3_), MatcherCast<const Element&>(e3_),
}; };
return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 3)); return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 3));
} }
private: private:
const T1& e1_; const T1& e1_;
const T2& e2_; const T2& e2_;
const T3& e3_; const T3& e3_;
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher3);
}; };
template <typename T1, typename T2, typename T3, typename T4> template <typename T1, typename T2, typename T3, typename T4>
class ElementsAreMatcher4 { class ElementsAreMatcher4 {
public: public:
ElementsAreMatcher4(const T1& e1, const T2& e2, const T3& e3, ElementsAreMatcher4(const T1& e1, const T2& e2, const T3& e3,
const T4& e4) : e1_(e1), e2_(e2), e3_(e3), e4_(e4) {} const T4& e4) : e1_(e1), e2_(e2), e3_(e3), e4_(e4) {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
skipping to change at line 403 skipping to change at line 425
}; };
return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 4)); return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 4));
} }
private: private:
const T1& e1_; const T1& e1_;
const T2& e2_; const T2& e2_;
const T3& e3_; const T3& e3_;
const T4& e4_; const T4& e4_;
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher4);
}; };
template <typename T1, typename T2, typename T3, typename T4, typename T5> template <typename T1, typename T2, typename T3, typename T4, typename T5>
class ElementsAreMatcher5 { class ElementsAreMatcher5 {
public: public:
ElementsAreMatcher5(const T1& e1, const T2& e2, const T3& e3, const T4& e 4, ElementsAreMatcher5(const T1& e1, const T2& e2, const T3& e3, const T4& e 4,
const T5& e5) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5) {} const T5& e5) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5) {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
skipping to change at line 435 skipping to change at line 459
return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 5)); return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 5));
} }
private: private:
const T1& e1_; const T1& e1_;
const T2& e2_; const T2& e2_;
const T3& e3_; const T3& e3_;
const T4& e4_; const T4& e4_;
const T5& e5_; const T5& e5_;
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher5);
}; };
template <typename T1, typename T2, typename T3, typename T4, typename T5, template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6> typename T6>
class ElementsAreMatcher6 { class ElementsAreMatcher6 {
public: public:
ElementsAreMatcher6(const T1& e1, const T2& e2, const T3& e3, const T4& e 4, ElementsAreMatcher6(const T1& e1, const T2& e2, const T3& e3, const T4& e 4,
const T5& e5, const T6& e6) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), const T5& e5, const T6& e6) : e1_(e1), e2_(e2), e3_(e3), e4_(e4),
e5_(e5), e6_(e6) {} e5_(e5), e6_(e6) {}
skipping to change at line 471 skipping to change at line 497
return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 6)); return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 6));
} }
private: private:
const T1& e1_; const T1& e1_;
const T2& e2_; const T2& e2_;
const T3& e3_; const T3& e3_;
const T4& e4_; const T4& e4_;
const T5& e5_; const T5& e5_;
const T6& e6_; const T6& e6_;
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher6);
}; };
template <typename T1, typename T2, typename T3, typename T4, typename T5, template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7> typename T6, typename T7>
class ElementsAreMatcher7 { class ElementsAreMatcher7 {
public: public:
ElementsAreMatcher7(const T1& e1, const T2& e2, const T3& e3, const T4& e 4, ElementsAreMatcher7(const T1& e1, const T2& e2, const T3& e3, const T4& e 4,
const T5& e5, const T6& e6, const T7& e7) : e1_(e1), e2_(e2), e3_(e3) , const T5& e5, const T6& e6, const T7& e7) : e1_(e1), e2_(e2), e3_(e3) ,
e4_(e4), e5_(e5), e6_(e6), e7_(e7) {} e4_(e4), e5_(e5), e6_(e6), e7_(e7) {}
skipping to change at line 509 skipping to change at line 537
} }
private: private:
const T1& e1_; const T1& e1_;
const T2& e2_; const T2& e2_;
const T3& e3_; const T3& e3_;
const T4& e4_; const T4& e4_;
const T5& e5_; const T5& e5_;
const T6& e6_; const T6& e6_;
const T7& e7_; const T7& e7_;
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher7);
}; };
template <typename T1, typename T2, typename T3, typename T4, typename T5, template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8> typename T6, typename T7, typename T8>
class ElementsAreMatcher8 { class ElementsAreMatcher8 {
public: public:
ElementsAreMatcher8(const T1& e1, const T2& e2, const T3& e3, const T4& e 4, ElementsAreMatcher8(const T1& e1, const T2& e2, const T3& e3, const T4& e 4,
const T5& e5, const T6& e6, const T7& e7, const T8& e8) : e1_(e1), const T5& e5, const T6& e6, const T7& e7, const T8& e8) : e1_(e1),
e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6), e7_(e7), e8_(e8) {} e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6), e7_(e7), e8_(e8) {}
skipping to change at line 549 skipping to change at line 579
private: private:
const T1& e1_; const T1& e1_;
const T2& e2_; const T2& e2_;
const T3& e3_; const T3& e3_;
const T4& e4_; const T4& e4_;
const T5& e5_; const T5& e5_;
const T6& e6_; const T6& e6_;
const T7& e7_; const T7& e7_;
const T8& e8_; const T8& e8_;
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher8);
}; };
template <typename T1, typename T2, typename T3, typename T4, typename T5, template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9> typename T6, typename T7, typename T8, typename T9>
class ElementsAreMatcher9 { class ElementsAreMatcher9 {
public: public:
ElementsAreMatcher9(const T1& e1, const T2& e2, const T3& e3, const T4& e 4, ElementsAreMatcher9(const T1& e1, const T2& e2, const T3& e3, const T4& e 4,
const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T5& e5, const T6& e6, const T7& e7, const T8& e8,
const T9& e9) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6), const T9& e9) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6),
e7_(e7), e8_(e8), e9_(e9) {} e7_(e7), e8_(e8), e9_(e9) {}
skipping to change at line 592 skipping to change at line 624
private: private:
const T1& e1_; const T1& e1_;
const T2& e2_; const T2& e2_;
const T3& e3_; const T3& e3_;
const T4& e4_; const T4& e4_;
const T5& e5_; const T5& e5_;
const T6& e6_; const T6& e6_;
const T7& e7_; const T7& e7_;
const T8& e8_; const T8& e8_;
const T9& e9_; const T9& e9_;
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher9);
}; };
template <typename T1, typename T2, typename T3, typename T4, typename T5, template <typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10> typename T6, typename T7, typename T8, typename T9, typename T10>
class ElementsAreMatcher10 { class ElementsAreMatcher10 {
public: public:
ElementsAreMatcher10(const T1& e1, const T2& e2, const T3& e3, const T4& e4, ElementsAreMatcher10(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9, const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
const T10& e10) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6 ), const T10& e10) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6 ),
e7_(e7), e8_(e8), e9_(e9), e10_(e10) {} e7_(e7), e8_(e8), e9_(e9), e10_(e10) {}
skipping to change at line 637 skipping to change at line 671
const T1& e1_; const T1& e1_;
const T2& e2_; const T2& e2_;
const T3& e3_; const T3& e3_;
const T4& e4_; const T4& e4_;
const T5& e5_; const T5& e5_;
const T6& e6_; const T6& e6_;
const T7& e7_; const T7& e7_;
const T8& e8_; const T8& e8_;
const T9& e9_; const T9& e9_;
const T10& e10_; const T10& e10_;
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher10);
}; };
} // namespace internal } // namespace internal
// Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
// fields of it matches a_matcher. C++ doesn't support default // fields of it matches a_matcher. C++ doesn't support default
// arguments for function templates, so we have to overload it. // arguments for function templates, so we have to overload it.
template <typename InnerMatcher> template <typename InnerMatcher>
inline internal::ArgsMatcher<InnerMatcher> inline internal::ArgsMatcher<InnerMatcher>
Args(const InnerMatcher& matcher) { Args(const InnerMatcher& matcher) {
skipping to change at line 830 skipping to change at line 866
template <typename T, size_t N> template <typename T, size_t N>
inline internal::ElementsAreArrayMatcher<T> inline internal::ElementsAreArrayMatcher<T>
ElementsAreArray(const T (&array)[N]) { ElementsAreArray(const T (&array)[N]) {
return internal::ElementsAreArrayMatcher<T>(array, N); return internal::ElementsAreArrayMatcher<T>(array, N);
} }
} // namespace testing } // namespace testing
// The MATCHER* family of macros can be used in a namespace scope to // The MATCHER* family of macros can be used in a namespace scope to
// define custom matchers easily. The syntax: // define custom matchers easily.
//
// Basic Usage
// ===========
//
// The syntax
// //
// MATCHER(name, description_string) { statements; } // MATCHER(name, description_string) { statements; }
// //
// will define a matcher with the given name that executes the // defines a matcher with the given name that executes the statements,
// statements, which must return a bool to indicate if the match // which must return a bool to indicate if the match succeeds. Inside
// succeeds. Inside the statements, you can refer to the value being // the statements, you can refer to the value being matched by 'arg',
// matched by 'arg', and refer to its type by 'arg_type'. // and refer to its type by 'arg_type'.
// //
// The description string documents what the matcher does, and is used // The description string documents what the matcher does, and is used
// to generate the failure message when the match fails. Since a // to generate the failure message when the match fails. Since a
// MATCHER() is usually defined in a header file shared by multiple // MATCHER() is usually defined in a header file shared by multiple
// C++ source files, we require the description to be a C-string // C++ source files, we require the description to be a C-string
// literal to avoid possible side effects. It can be empty, in which // literal to avoid possible side effects. It can be empty, in which
// case we'll use the sequence of words in the matcher name as the // case we'll use the sequence of words in the matcher name as the
// description. // description.
// //
// For example: // For example:
skipping to change at line 870 skipping to change at line 911
// //
// If the above assertion fails, it will print something like: // If the above assertion fails, it will print something like:
// //
// Value of: some_expression // Value of: some_expression
// Expected: is even // Expected: is even
// Actual: 7 // Actual: 7
// //
// where the description "is even" is automatically calculated from the // where the description "is even" is automatically calculated from the
// matcher name IsEven. // matcher name IsEven.
// //
// Argument Type
// =============
//
// Note that the type of the value being matched (arg_type) is // Note that the type of the value being matched (arg_type) is
// determined by the context in which you use the matcher and is // determined by the context in which you use the matcher and is
// supplied to you by the compiler, so you don't need to worry about // supplied to you by the compiler, so you don't need to worry about
// declaring it (nor can you). This allows the matcher to be // declaring it (nor can you). This allows the matcher to be
// polymorphic. For example, IsEven() can be used to match any type // polymorphic. For example, IsEven() can be used to match any type
// where the value of "(arg % 2) == 0" can be implicitly converted to // where the value of "(arg % 2) == 0" can be implicitly converted to
// a bool. In the "Bar(IsEven())" example above, if method Bar() // a bool. In the "Bar(IsEven())" example above, if method Bar()
// takes an int, 'arg_type' will be int; if it takes an unsigned long, // takes an int, 'arg_type' will be int; if it takes an unsigned long,
// 'arg_type' will be unsigned long; and so on. // 'arg_type' will be unsigned long; and so on.
// //
// Parameterizing Matchers
// =======================
//
// Sometimes you'll want to parameterize the matcher. For that you // Sometimes you'll want to parameterize the matcher. For that you
// can use another macro: // can use another macro:
// //
// MATCHER_P(name, param_name, description_string) { statements; } // MATCHER_P(name, param_name, description_string) { statements; }
// //
// For example: // For example:
// //
// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; } // MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
// //
// will allow you to write: // will allow you to write:
skipping to change at line 910 skipping to change at line 957
// printed, making the message human-friendly. // printed, making the message human-friendly.
// //
// In the matcher definition body, you can write 'foo_type' to // In the matcher definition body, you can write 'foo_type' to
// reference the type of a parameter named 'foo'. For example, in the // reference the type of a parameter named 'foo'. For example, in the
// body of MATCHER_P(HasAbsoluteValue, value) above, you can write // body of MATCHER_P(HasAbsoluteValue, value) above, you can write
// 'value_type' to refer to the type of 'value'. // 'value_type' to refer to the type of 'value'.
// //
// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to // We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to
// support multi-parameter matchers. // support multi-parameter matchers.
// //
// Describing Parameterized Matchers
// =================================
//
// When defining a parameterized matcher, you can use Python-style // When defining a parameterized matcher, you can use Python-style
// interpolations in the description string to refer to the parameter // interpolations in the description string to refer to the parameter
// values. We support the following syntax currently: // values. We support the following syntax currently:
// //
// %% a single '%' character // %% a single '%' character
// %(*)s all parameters of the matcher printed as a tuple // %(*)s all parameters of the matcher printed as a tuple
// %(foo)s value of the matcher parameter named 'foo' // %(foo)s value of the matcher parameter named 'foo'
// //
// For example, // For example,
// //
skipping to change at line 942 skipping to change at line 992
// parameter values printed as a tuple. For example, // parameter values printed as a tuple. For example,
// //
// MATCHER_P2(InClosedRange, low, hi, "") { ... } // MATCHER_P2(InClosedRange, low, hi, "") { ... }
// ... // ...
// EXPECT_THAT(3, InClosedRange(4, 6)); // EXPECT_THAT(3, InClosedRange(4, 6));
// //
// would generate a failure that contains the text: // would generate a failure that contains the text:
// //
// Expected: in closed range (4, 6) // Expected: in closed range (4, 6)
// //
// Types of Matcher Parameters
// ===========================
//
// For the purpose of typing, you can view // For the purpose of typing, you can view
// //
// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... } // MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
// //
// as shorthand for // as shorthand for
// //
// template <typename p1_type, ..., typename pk_type> // template <typename p1_type, ..., typename pk_type>
// FooMatcherPk<p1_type, ..., pk_type> // FooMatcherPk<p1_type, ..., pk_type>
// Foo(p1_type p1, ..., pk_type pk) { ... } // Foo(p1_type p1, ..., pk_type pk) { ... }
// //
skipping to change at line 969 skipping to change at line 1022
// to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This // to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
// can be useful when composing matchers. // can be useful when composing matchers.
// //
// While you can instantiate a matcher template with reference types, // While you can instantiate a matcher template with reference types,
// passing the parameters by pointer usually makes your code more // passing the parameters by pointer usually makes your code more
// readable. If, however, you still want to pass a parameter by // readable. If, however, you still want to pass a parameter by
// reference, be aware that in the failure message generated by the // reference, be aware that in the failure message generated by the
// matcher you will see the value of the referenced object but not its // matcher you will see the value of the referenced object but not its
// address. // address.
// //
// Explaining Match Results
// ========================
//
// Sometimes the matcher description alone isn't enough to explain why
// the match has failed or succeeded. For example, when expecting a
// long string, it can be very helpful to also print the diff between
// the expected string and the actual one. To achieve that, you can
// optionally stream additional information to a special variable
// named result_listener, whose type is a pointer to class
// MatchResultListener:
//
// MATCHER_P(EqualsLongString, str, "") {
// if (arg == str) return true;
//
// *result_listener << "the difference: "
/// << DiffStrings(str, arg);
// return false;
// }
//
// Overloading Matchers
// ====================
//
// You can overload matchers with different numbers of parameters: // You can overload matchers with different numbers of parameters:
// //
// MATCHER_P(Blah, a, description_string1) { ... } // MATCHER_P(Blah, a, description_string1) { ... }
// MATCHER_P2(Blah, a, b, description_string2) { ... } // MATCHER_P2(Blah, a, b, description_string2) { ... }
// //
// While it's tempting to always use the MATCHER* macros when defining // Caveats
// a new matcher, you should also consider implementing // =======
// MatcherInterface or using MakePolymorphicMatcher() instead,
// especially if you need to use the matcher a lot. While these
// approaches require more work, they give you more control on the
// types of the value being matched and the matcher parameters, which
// in general leads to better compiler error messages that pay off in
// the long run. They also allow overloading matchers based on
// parameter types (as opposed to just based on the number of
// parameters).
// //
// CAVEAT: // When defining a new matcher, you should also consider implementing
// MatcherInterface or using MakePolymorphicMatcher(). These
// approaches require more work than the MATCHER* macros, but also
// give you more control on the types of the value being matched and
// the matcher parameters, which may leads to better compiler error
// messages when the matcher is used wrong. They also allow
// overloading matchers based on parameter types (as opposed to just
// based on the number of parameters).
// //
// MATCHER*() can only be used in a namespace scope. The reason is // MATCHER*() can only be used in a namespace scope. The reason is
// that C++ doesn't yet allow function-local types to be used to // that C++ doesn't yet allow function-local types to be used to
// instantiate templates. The up-coming C++0x standard will fix this. // instantiate templates. The up-coming C++0x standard will fix this.
// Once that's done, we'll consider supporting using MATCHER*() inside // Once that's done, we'll consider supporting using MATCHER*() inside
// a function. // a function.
// //
// MORE INFORMATION: // More Information
// ================
// //
// To learn more about using these macros, please search for 'MATCHER' // To learn more about using these macros, please search for 'MATCHER'
// on http://code.google.com/p/googlemock/wiki/CookBook. // on http://code.google.com/p/googlemock/wiki/CookBook.
#define MATCHER(name, description)\ #define MATCHER(name, description)\
class name##Matcher {\ class name##Matcher {\
public:\ public:\
template <typename arg_type>\ template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
public:\ public:\
gmock_Impl(const ::testing::internal::Interpolations& gmock_interp)\ gmock_Impl(const ::testing::internal::Interpolations& gmock_interp)\
: gmock_interp_(gmock_interp) {}\ : gmock_interp_(gmock_interp) {}\
virtual bool Matches(arg_type arg) const;\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co
nst;\
virtual void DescribeTo(::std::ostream* gmock_os) const {\ virtual void DescribeTo(::std::ostream* gmock_os) const {\
const ::testing::internal::Strings& gmock_printed_params = \ const ::testing::internal::Strings& gmock_printed_params = \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<>());\ ::std::tr1::tuple<>());\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << ::testing::internal::FormatMatcherDescription(\
#name, description, gmock_interp_, gmock_printed_param s);\ #name, description, gmock_interp_, gmock_printed_param s);\
}\ }\
const ::testing::internal::Interpolations gmock_interp_;\ const ::testing::internal::Interpolations gmock_interp_;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\ operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\ return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>(gmock_interp_));\ new gmock_Impl<arg_type>(gmock_interp_));\
}\ }\
name##Matcher() {\ name##Matcher() {\
const char* gmock_param_names[] = { NULL };\ const char* gmock_param_names[] = { NULL };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\ gmock_param_names, ("" description ""));\
}\ }\
private:\
::testing::internal::Interpolations gmock_interp_;\ ::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##Matcher);\
};\ };\
inline name##Matcher name() {\ inline name##Matcher name() {\
return name##Matcher();\ return name##Matcher();\
}\ }\
template <typename arg_type>\ template <typename arg_type>\
bool name##Matcher::\ bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\
gmock_Impl<arg_type>::Matches(arg_type arg) const arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE
D_)\
const
#define MATCHER_P(name, p0, description)\ #define MATCHER_P(name, p0, description)\
template <typename p0##_type>\ template <typename p0##_type>\
class name##MatcherP {\ class name##MatcherP {\
public:\ public:\
template <typename arg_type>\ template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
public:\ public:\
explicit gmock_Impl(p0##_type gmock_p0, \ explicit gmock_Impl(p0##_type gmock_p0, \
const ::testing::internal::Interpolations& gmock_interp)\ const ::testing::internal::Interpolations& gmock_interp)\
: p0(gmock_p0), gmock_interp_(gmock_interp) {}\ : p0(gmock_p0), gmock_interp_(gmock_interp) {}\
virtual bool Matches(arg_type arg) const;\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co
nst;\
virtual void DescribeTo(::std::ostream* gmock_os) const {\ virtual void DescribeTo(::std::ostream* gmock_os) const {\
const ::testing::internal::Strings& gmock_printed_params = \ const ::testing::internal::Strings& gmock_printed_params = \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type>(p0));\ ::std::tr1::tuple<p0##_type>(p0));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << ::testing::internal::FormatMatcherDescription(\
#name, description, gmock_interp_, gmock_printed_param s);\ #name, description, gmock_interp_, gmock_printed_param s);\
}\ }\
p0##_type p0;\ p0##_type p0;\
const ::testing::internal::Interpolations gmock_interp_;\ const ::testing::internal::Interpolations gmock_interp_;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\ operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\ return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>(p0, gmock_interp_));\ new gmock_Impl<arg_type>(p0, gmock_interp_));\
}\ }\
name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\ name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\
const char* gmock_param_names[] = { #p0, NULL };\ const char* gmock_param_names[] = { #p0, NULL };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\ gmock_param_names, ("" description ""));\
}\ }\
p0##_type p0;\ p0##_type p0;\
private:\
::testing::internal::Interpolations gmock_interp_;\ ::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP);\
};\ };\
template <typename p0##_type>\ template <typename p0##_type>\
inline name##MatcherP<p0##_type> name(p0##_type p0) {\ inline name##MatcherP<p0##_type> name(p0##_type p0) {\
return name##MatcherP<p0##_type>(p0);\ return name##MatcherP<p0##_type>(p0);\
}\ }\
template <typename p0##_type>\ template <typename p0##_type>\
template <typename arg_type>\ template <typename arg_type>\
bool name##MatcherP<p0##_type>::\ bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
gmock_Impl<arg_type>::Matches(arg_type arg) const arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE
D_)\
const
#define MATCHER_P2(name, p0, p1, description)\ #define MATCHER_P2(name, p0, p1, description)\
template <typename p0##_type, typename p1##_type>\ template <typename p0##_type, typename p1##_type>\
class name##MatcherP2 {\ class name##MatcherP2 {\
public:\ public:\
template <typename arg_type>\ template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
public:\ public:\
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \
const ::testing::internal::Interpolations& gmock_interp)\ const ::testing::internal::Interpolations& gmock_interp)\
: p0(gmock_p0), p1(gmock_p1), gmock_interp_(gmock_interp) {}\ : p0(gmock_p0), p1(gmock_p1), gmock_interp_(gmock_interp) {}\
virtual bool Matches(arg_type arg) const;\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co
nst;\
virtual void DescribeTo(::std::ostream* gmock_os) const {\ virtual void DescribeTo(::std::ostream* gmock_os) const {\
const ::testing::internal::Strings& gmock_printed_params = \ const ::testing::internal::Strings& gmock_printed_params = \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type>(p0, p1));\ ::std::tr1::tuple<p0##_type, p1##_type>(p0, p1));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << ::testing::internal::FormatMatcherDescription(\
#name, description, gmock_interp_, gmock_printed_param s);\ #name, description, gmock_interp_, gmock_printed_param s);\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
const ::testing::internal::Interpolations gmock_interp_;\ const ::testing::internal::Interpolations gmock_interp_;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\ operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\ return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>(p0, p1, gmock_interp_));\ new gmock_Impl<arg_type>(p0, p1, gmock_interp_));\
}\ }\
name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
p1(gmock_p1) {\ p1(gmock_p1) {\
const char* gmock_param_names[] = { #p0, #p1, NULL };\ const char* gmock_param_names[] = { #p0, #p1, NULL };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\ gmock_param_names, ("" description ""));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
private:\
::testing::internal::Interpolations gmock_interp_;\ ::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\
};\ };\
template <typename p0##_type, typename p1##_type>\ template <typename p0##_type, typename p1##_type>\
inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \ inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
p1##_type p1) {\ p1##_type p1) {\
return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\ return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\
}\ }\
template <typename p0##_type, typename p1##_type>\ template <typename p0##_type, typename p1##_type>\
template <typename arg_type>\ template <typename arg_type>\
bool name##MatcherP2<p0##_type, p1##_type>::\ bool name##MatcherP2<p0##_type, \
gmock_Impl<arg_type>::Matches(arg_type arg) const p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE
D_)\
const
#define MATCHER_P3(name, p0, p1, p2, description)\ #define MATCHER_P3(name, p0, p1, p2, description)\
template <typename p0##_type, typename p1##_type, typename p2##_type>\ template <typename p0##_type, typename p1##_type, typename p2##_type>\
class name##MatcherP3 {\ class name##MatcherP3 {\
public:\ public:\
template <typename arg_type>\ template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
public:\ public:\
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \
const ::testing::internal::Interpolations& gmock_interp)\ const ::testing::internal::Interpolations& gmock_interp)\
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
gmock_interp_(gmock_interp) {}\ gmock_interp_(gmock_interp) {}\
virtual bool Matches(arg_type arg) const;\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co
nst;\
virtual void DescribeTo(::std::ostream* gmock_os) const {\ virtual void DescribeTo(::std::ostream* gmock_os) const {\
const ::testing::internal::Strings& gmock_printed_params = \ const ::testing::internal::Strings& gmock_printed_params = \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \
p2));\ p2));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << ::testing::internal::FormatMatcherDescription(\
#name, description, gmock_interp_, gmock_printed_param s);\ #name, description, gmock_interp_, gmock_printed_param s);\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
const ::testing::internal::Interpolations gmock_interp_;\ const ::testing::internal::Interpolations gmock_interp_;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\ operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\ return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>(p0, p1, p2, gmock_interp_));\ new gmock_Impl<arg_type>(p0, p1, p2, gmock_interp_));\
}\ }\
name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \ name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\ p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\
const char* gmock_param_names[] = { #p0, #p1, #p2, NULL };\ const char* gmock_param_names[] = { #p0, #p1, #p2, NULL };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\ gmock_param_names, ("" description ""));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
private:\
::testing::internal::Interpolations gmock_interp_;\ ::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type>\ template <typename p0##_type, typename p1##_type, typename p2##_type>\
inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0 , \ inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0 , \
p1##_type p1, p2##_type p2) {\ p1##_type p1, p2##_type p2) {\
return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\ return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type>\ template <typename p0##_type, typename p1##_type, typename p2##_type>\
template <typename arg_type>\ template <typename arg_type>\
bool name##MatcherP3<p0##_type, p1##_type, p2##_type>::\ bool name##MatcherP3<p0##_type, p1##_type, \
gmock_Impl<arg_type>::Matches(arg_type arg) const p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE
D_)\
const
#define MATCHER_P4(name, p0, p1, p2, p3, description)\ #define MATCHER_P4(name, p0, p1, p2, p3, description)\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type>\ typename p3##_type>\
class name##MatcherP4 {\ class name##MatcherP4 {\
public:\ public:\
template <typename arg_type>\ template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
public:\ public:\
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \
p3##_type gmock_p3, \ p3##_type gmock_p3, \
const ::testing::internal::Interpolations& gmock_interp)\ const ::testing::internal::Interpolations& gmock_interp)\
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
gmock_interp_(gmock_interp) {}\ gmock_interp_(gmock_interp) {}\
virtual bool Matches(arg_type arg) const;\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co
nst;\
virtual void DescribeTo(::std::ostream* gmock_os) const {\ virtual void DescribeTo(::std::ostream* gmock_os) const {\
const ::testing::internal::Strings& gmock_printed_params = \ const ::testing::internal::Strings& gmock_printed_params = \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \
p3##_type>(p0, p1, p2, p3));\ p3##_type>(p0, p1, p2, p3));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << ::testing::internal::FormatMatcherDescription(\
#name, description, gmock_interp_, gmock_printed_param s);\ #name, description, gmock_interp_, gmock_printed_param s);\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
const ::testing::internal::Interpolations gmock_interp_;\ const ::testing::internal::Interpolations gmock_interp_;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\ operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\ return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>(p0, p1, p2, p3, gmock_interp_));\ new gmock_Impl<arg_type>(p0, p1, p2, p3, gmock_interp_));\
}\ }\
name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \ name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1 ), \ p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1 ), \
p2(gmock_p2), p3(gmock_p3) {\ p2(gmock_p2), p3(gmock_p3) {\
const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, NULL };\ const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, NULL };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\ gmock_param_names, ("" description ""));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
private:\
::testing::internal::Interpolations gmock_interp_;\ ::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type>\ typename p3##_type>\
inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \ inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \
p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
p3##_type p3) {\ p3##_type p3) {\
return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \ return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
p1, p2, p3);\ p1, p2, p3);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type>\ typename p3##_type>\
template <typename arg_type>\ template <typename arg_type>\
bool name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>::\ bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \
gmock_Impl<arg_type>::Matches(arg_type arg) const p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE
D_)\
const
#define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\ #define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type>\ typename p3##_type, typename p4##_type>\
class name##MatcherP5 {\ class name##MatcherP5 {\
public:\ public:\
template <typename arg_type>\ template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
public:\ public:\
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \
p3##_type gmock_p3, p4##_type gmock_p4, \ p3##_type gmock_p3, p4##_type gmock_p4, \
const ::testing::internal::Interpolations& gmock_interp)\ const ::testing::internal::Interpolations& gmock_interp)\
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
p4(gmock_p4), gmock_interp_(gmock_interp) {}\ p4(gmock_p4), gmock_interp_(gmock_interp) {}\
virtual bool Matches(arg_type arg) const;\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co
nst;\
virtual void DescribeTo(::std::ostream* gmock_os) const {\ virtual void DescribeTo(::std::ostream* gmock_os) const {\
const ::testing::internal::Strings& gmock_printed_params = \ const ::testing::internal::Strings& gmock_printed_params = \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \
p4##_type>(p0, p1, p2, p3, p4));\ p4##_type>(p0, p1, p2, p3, p4));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << ::testing::internal::FormatMatcherDescription(\
#name, description, gmock_interp_, gmock_printed_param s);\ #name, description, gmock_interp_, gmock_printed_param s);\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
const ::testing::internal::Interpolations gmock_interp_;\ const ::testing::internal::Interpolations gmock_interp_;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\ operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\ return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, gmock_interp_));\ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, gmock_interp_));\
}\ }\
name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \ name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
p2##_type gmock_p2, p3##_type gmock_p3, \ p2##_type gmock_p2, p3##_type gmock_p3, \
p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
p3(gmock_p3), p4(gmock_p4) {\ p3(gmock_p3), p4(gmock_p4) {\
const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, NULL };\ const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, NULL };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\ gmock_param_names, ("" description ""));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
private:\
::testing::internal::Interpolations gmock_interp_;\ ::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type>\ typename p3##_type, typename p4##_type>\
inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \ p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \
p4##_type p4) {\ p4##_type p4) {\
return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \ return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type>(p0, p1, p2, p3, p4);\ p4##_type>(p0, p1, p2, p3, p4);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type>\ typename p3##_type, typename p4##_type>\
template <typename arg_type>\ template <typename arg_type>\
bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, p4##_typ bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
e>::\ p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
gmock_Impl<arg_type>::Matches(arg_type arg) const arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE
D_)\
const
#define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\ #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type>\ typename p3##_type, typename p4##_type, typename p5##_type>\
class name##MatcherP6 {\ class name##MatcherP6 {\
public:\ public:\
template <typename arg_type>\ template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
public:\ public:\
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
const ::testing::internal::Interpolations& gmock_interp)\ const ::testing::internal::Interpolations& gmock_interp)\
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
p4(gmock_p4), p5(gmock_p5), gmock_interp_(gmock_interp) {}\ p4(gmock_p4), p5(gmock_p5), gmock_interp_(gmock_interp) {}\
virtual bool Matches(arg_type arg) const;\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co
nst;\
virtual void DescribeTo(::std::ostream* gmock_os) const {\ virtual void DescribeTo(::std::ostream* gmock_os) const {\
const ::testing::internal::Strings& gmock_printed_params = \ const ::testing::internal::Strings& gmock_printed_params = \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \
p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5));\ p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << ::testing::internal::FormatMatcherDescription(\
#name, description, gmock_interp_, gmock_printed_param s);\ #name, description, gmock_interp_, gmock_printed_param s);\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
const ::testing::internal::Interpolations gmock_interp_;\ const ::testing::internal::Interpolations gmock_interp_;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\ operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\ return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, gmock_interp_)); \ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, gmock_interp_)); \
}\ }\
name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \ name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\ p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\
const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, NUL L };\ const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, NUL L };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\ gmock_param_names, ("" description ""));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
private:\
::testing::internal::Interpolations gmock_interp_;\ ::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type>\ typename p3##_type, typename p4##_type, typename p5##_type>\
inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \ p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
p3##_type p3, p4##_type p4, p5##_type p5) {\ p3##_type p3, p4##_type p4, p5##_type p5) {\
return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \ return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\ p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type>\ typename p3##_type, typename p4##_type, typename p5##_type>\
template <typename arg_type>\ template <typename arg_type>\
bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_typ e, \ bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_typ e, \
p5##_type>::\ p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
gmock_Impl<arg_type>::Matches(arg_type arg) const arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE
D_)\
const
#define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\ #define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type>\ typename p6##_type>\
class name##MatcherP7 {\ class name##MatcherP7 {\
public:\ public:\
template <typename arg_type>\ template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
public:\ public:\
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
p6##_type gmock_p6, \ p6##_type gmock_p6, \
const ::testing::internal::Interpolations& gmock_interp)\ const ::testing::internal::Interpolations& gmock_interp)\
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
gmock_interp_(gmock_interp) {}\ gmock_interp_(gmock_interp) {}\
virtual bool Matches(arg_type arg) const;\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co
nst;\
virtual void DescribeTo(::std::ostream* gmock_os) const {\ virtual void DescribeTo(::std::ostream* gmock_os) const {\
const ::testing::internal::Strings& gmock_printed_params = \ const ::testing::internal::Strings& gmock_printed_params = \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \
p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5 , \ p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5 , \
p6));\ p6));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << ::testing::internal::FormatMatcherDescription(\
#name, description, gmock_interp_, gmock_printed_param s);\ #name, description, gmock_interp_, gmock_printed_param s);\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
const ::testing::internal::Interpolations gmock_interp_;\ const ::testing::internal::Interpolations gmock_interp_;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\ operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\ return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, gmock_interp _));\ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, gmock_interp _));\
}\ }\
name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \ name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1 ), \ p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1 ), \
p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
skipping to change at line 1422 skipping to change at line 1553
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\ gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\ gmock_param_names, ("" description ""));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
private:\
::testing::internal::Interpolations gmock_interp_;\ ::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type>\ typename p6##_type>\
inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \ p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
p6##_type p6) {\ p6##_type p6) {\
return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \ return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\ p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type>\ typename p6##_type>\
template <typename arg_type>\ template <typename arg_type>\
bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_typ e, \ bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_typ e, \
p5##_type, p6##_type>::\ p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
gmock_Impl<arg_type>::Matches(arg_type arg) const arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE
D_)\
const
#define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\ #define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type>\ typename p6##_type, typename p7##_type>\
class name##MatcherP8 {\ class name##MatcherP8 {\
public:\ public:\
template <typename arg_type>\ template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
public:\ public:\
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
p6##_type gmock_p6, p7##_type gmock_p7, \ p6##_type gmock_p6, p7##_type gmock_p7, \
const ::testing::internal::Interpolations& gmock_interp)\ const ::testing::internal::Interpolations& gmock_interp)\
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
gmock_interp_(gmock_interp) {}\ gmock_interp_(gmock_interp) {}\
virtual bool Matches(arg_type arg) const;\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co
nst;\
virtual void DescribeTo(::std::ostream* gmock_os) const {\ virtual void DescribeTo(::std::ostream* gmock_os) const {\
const ::testing::internal::Strings& gmock_printed_params = \ const ::testing::internal::Strings& gmock_printed_params = \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \
p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \ p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
p3, p4, p5, p6, p7));\ p3, p4, p5, p6, p7));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << ::testing::internal::FormatMatcherDescription(\
#name, description, gmock_interp_, gmock_printed_param s);\ #name, description, gmock_interp_, gmock_printed_param s);\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
const ::testing::internal::Interpolations gmock_interp_;\ const ::testing::internal::Interpolations gmock_interp_;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\ operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\ return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, \ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, \
gmock_interp_));\ gmock_interp_));\
}\ }\
name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \ name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
p5##_type gmock_p5, p6##_type gmock_p6, \ p5##_type gmock_p5, p6##_type gmock_p6, \
skipping to change at line 1503 skipping to change at line 1641
gmock_param_names, ("" description ""));\ gmock_param_names, ("" description ""));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
private:\
::testing::internal::Interpolations gmock_interp_;\ ::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type>\ typename p6##_type, typename p7##_type>\
inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \ p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
p6##_type p6, p7##_type p7) {\ p6##_type p6, p7##_type p7) {\
return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \ return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \ p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
p6, p7);\ p6, p7);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type>\ typename p6##_type, typename p7##_type>\
template <typename arg_type>\ template <typename arg_type>\
bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_typ e, \ bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_typ e, \
p5##_type, p6##_type, p7##_type>::\ p5##_type, p6##_type, \
gmock_Impl<arg_type>::Matches(arg_type arg) const p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE
D_)\
const
#define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\ #define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type, typename p8##_type>\ typename p6##_type, typename p7##_type, typename p8##_type>\
class name##MatcherP9 {\ class name##MatcherP9 {\
public:\ public:\
template <typename arg_type>\ template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
public:\ public:\
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
const ::testing::internal::Interpolations& gmock_interp)\ const ::testing::internal::Interpolations& gmock_interp)\
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
p8(gmock_p8), gmock_interp_(gmock_interp) {}\ p8(gmock_p8), gmock_interp_(gmock_interp) {}\
virtual bool Matches(arg_type arg) const;\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co
nst;\
virtual void DescribeTo(::std::ostream* gmock_os) const {\ virtual void DescribeTo(::std::ostream* gmock_os) const {\
const ::testing::internal::Strings& gmock_printed_params = \ const ::testing::internal::Strings& gmock_printed_params = \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \
p4##_type, p5##_type, p6##_type, p7##_type, \ p4##_type, p5##_type, p6##_type, p7##_type, \
p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\ p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << ::testing::internal::FormatMatcherDescription(\
#name, description, gmock_interp_, gmock_printed_param s);\ #name, description, gmock_interp_, gmock_printed_param s);\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
p8##_type p8;\ p8##_type p8;\
const ::testing::internal::Interpolations gmock_interp_;\ const ::testing::internal::Interpolations gmock_interp_;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\ operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\ return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, \ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, \
gmock_interp_));\ gmock_interp_));\
}\ }\
name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \ name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
skipping to change at line 1587 skipping to change at line 1733
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
p8##_type p8;\ p8##_type p8;\
private:\
::testing::internal::Interpolations gmock_interp_;\ ::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type, typename p8##_type>\ typename p6##_type, typename p7##_type, typename p8##_type>\
inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type, p7##_type, \ p4##_type, p5##_type, p6##_type, p7##_type, \
p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \ p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \
p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
p8##_type p8) {\ p8##_type p8) {\
return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \ return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
p3, p4, p5, p6, p7, p8);\ p3, p4, p5, p6, p7, p8);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type, typename p8##_type>\ typename p6##_type, typename p7##_type, typename p8##_type>\
template <typename arg_type>\ template <typename arg_type>\
bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_typ e, \ bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_typ e, \
p5##_type, p6##_type, p7##_type, p8##_type>::\ p5##_type, p6##_type, p7##_type, \
gmock_Impl<arg_type>::Matches(arg_type arg) const p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE
D_)\
const
#define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, descripti on)\ #define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, descripti on)\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type, typename p8##_type, \ typename p6##_type, typename p7##_type, typename p8##_type, \
typename p9##_type>\ typename p9##_type>\
class name##MatcherP10 {\ class name##MatcherP10 {\
public:\ public:\
template <typename arg_type>\ template <typename arg_type>\
class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\ class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
public:\ public:\
gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \ gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2 , \
p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \ p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
p9##_type gmock_p9, \ p9##_type gmock_p9, \
const ::testing::internal::Interpolations& gmock_interp)\ const ::testing::internal::Interpolations& gmock_interp)\
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
p8(gmock_p8), p9(gmock_p9), gmock_interp_(gmock_interp) {}\ p8(gmock_p8), p9(gmock_p9), gmock_interp_(gmock_interp) {}\
virtual bool Matches(arg_type arg) const;\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co
nst;\
virtual void DescribeTo(::std::ostream* gmock_os) const {\ virtual void DescribeTo(::std::ostream* gmock_os) const {\
const ::testing::internal::Strings& gmock_printed_params = \ const ::testing::internal::Strings& gmock_printed_params = \
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \ ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ e, \
p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\ p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << ::testing::internal::FormatMatcherDescription(\
#name, description, gmock_interp_, gmock_printed_param s);\ #name, description, gmock_interp_, gmock_printed_param s);\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
p8##_type p8;\ p8##_type p8;\
p9##_type p9;\ p9##_type p9;\
const ::testing::internal::Interpolations gmock_interp_;\ const ::testing::internal::Interpolations gmock_interp_;\
private:\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
};\ };\
template <typename arg_type>\ template <typename arg_type>\
operator ::testing::Matcher<arg_type>() const {\ operator ::testing::Matcher<arg_type>() const {\
return ::testing::Matcher<arg_type>(\ return ::testing::Matcher<arg_type>(\
new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, \ new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, \
gmock_interp_));\ gmock_interp_));\
}\ }\
name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \ name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \ p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
skipping to change at line 1676 skipping to change at line 1830
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
p3##_type p3;\ p3##_type p3;\
p4##_type p4;\ p4##_type p4;\
p5##_type p5;\ p5##_type p5;\
p6##_type p6;\ p6##_type p6;\
p7##_type p7;\ p7##_type p7;\
p8##_type p8;\ p8##_type p8;\
p9##_type p9;\ p9##_type p9;\
private:\
::testing::internal::Interpolations gmock_interp_;\ ::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\
};\ };\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type, typename p8##_type, \ typename p6##_type, typename p7##_type, typename p8##_type, \
typename p9##_type>\ typename p9##_type>\
inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \ inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \ p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p 3, \
p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
p9##_type p9) {\ p9##_type p9) {\
return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \ return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p 0, \ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p 0, \
p1, p2, p3, p4, p5, p6, p7, p8, p9);\ p1, p2, p3, p4, p5, p6, p7, p8, p9);\
}\ }\
template <typename p0##_type, typename p1##_type, typename p2##_type, \ template <typename p0##_type, typename p1##_type, typename p2##_type, \
typename p3##_type, typename p4##_type, typename p5##_type, \ typename p3##_type, typename p4##_type, typename p5##_type, \
typename p6##_type, typename p7##_type, typename p8##_type, \ typename p6##_type, typename p7##_type, typename p8##_type, \
typename p9##_type>\ typename p9##_type>\
template <typename arg_type>\ template <typename arg_type>\
bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \ bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>::\ p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
gmock_Impl<arg_type>::Matches(arg_type arg) const p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE
D_)\
const
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
 End of changes. 85 change blocks. 
61 lines changed or deleted 241 lines changed or added


 gmock-generated-nice-strict.h   gmock-generated-nice-strict.h 
skipping to change at line 158 skipping to change at line 158
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
::testing::Mock::AllowUninterestingCalls( ::testing::Mock::AllowUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::implicit_cast<MockClass*>(this));
} }
virtual ~NiceMock() { virtual ~NiceMock() {
::testing::Mock::UnregisterCallReaction( ::testing::Mock::UnregisterCallReaction(
internal::implicit_cast<MockClass*>(this)); internal::implicit_cast<MockClass*>(this));
} }
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock);
}; };
template <class MockClass> template <class MockClass>
class StrictMock : public MockClass { class StrictMock : public MockClass {
public: public:
// We don't factor out the constructor body to a common method, as // We don't factor out the constructor body to a common method, as
// we have to avoid a possible clash with members of MockClass. // we have to avoid a possible clash with members of MockClass.
StrictMock() { StrictMock() {
::testing::Mock::FailUninterestingCalls( ::testing::Mock::FailUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::implicit_cast<MockClass*>(this));
skipping to change at line 249 skipping to change at line 252
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9,
const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { const A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) {
::testing::Mock::FailUninterestingCalls( ::testing::Mock::FailUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::implicit_cast<MockClass*>(this));
} }
virtual ~StrictMock() { virtual ~StrictMock() {
::testing::Mock::UnregisterCallReaction( ::testing::Mock::UnregisterCallReaction(
internal::implicit_cast<MockClass*>(this)); internal::implicit_cast<MockClass*>(this));
} }
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock);
}; };
// The following specializations catch some (relatively more common) // The following specializations catch some (relatively more common)
// user errors of nesting nice and strict mocks. They do NOT catch // user errors of nesting nice and strict mocks. They do NOT catch
// all possible errors. // all possible errors.
// These specializations are declared but not defined, as NiceMock and // These specializations are declared but not defined, as NiceMock and
// StrictMock cannot be nested. // StrictMock cannot be nested.
template <typename MockClass> template <typename MockClass>
class NiceMock<NiceMock<MockClass> >; class NiceMock<NiceMock<MockClass> >;
 End of changes. 2 change blocks. 
0 lines changed or deleted 6 lines changed or added


 gmock-internal-utils.h   gmock-internal-utils.h 
skipping to change at line 643 skipping to change at line 643
return size() == rhs.size() && return size() == rhs.size() &&
ArrayEq(begin(), size(), rhs.begin()); ArrayEq(begin(), size(), rhs.begin());
} }
private: private:
// Not implemented as we don't want to support assignment. // Not implemented as we don't want to support assignment.
void operator=(const NativeArray& rhs); void operator=(const NativeArray& rhs);
// Initializes this object; makes a copy of the input array if // Initializes this object; makes a copy of the input array if
// 'relation' is kCopy. // 'relation' is kCopy.
void Init(const Element* array, size_t size, RelationToSource relation) { void Init(const Element* array, size_t a_size, RelationToSource relation) {
if (relation == kReference) { if (relation == kReference) {
array_ = array; array_ = array;
} else { } else {
Element* const copy = new Element[size]; Element* const copy = new Element[a_size];
CopyArray(array, size, copy); CopyArray(array, a_size, copy);
array_ = copy; array_ = copy;
} }
size_ = size; size_ = a_size;
relation_to_source_ = relation; relation_to_source_ = relation;
} }
const Element* array_; const Element* array_;
size_t size_; size_t size_;
RelationToSource relation_to_source_; RelationToSource relation_to_source_;
}; };
// Given a raw type (i.e. having no top-level reference or const // Given a raw type (i.e. having no top-level reference or const
// modifier) RawContainer that's either an STL-style container or a // modifier) RawContainer that's either an STL-style container or a
 End of changes. 3 change blocks. 
4 lines changed or deleted 4 lines changed or added


 gmock-matchers.h   gmock-matchers.h 
skipping to change at line 67 skipping to change at line 67
// MatcherInterface<T> interface, and // MatcherInterface<T> interface, and
// 2. a factory function that creates a Matcher<T> object from a // 2. a factory function that creates a Matcher<T> object from a
// FooMatcherImpl*. // FooMatcherImpl*.
// //
// The two-level delegation design makes it possible to allow a user // The two-level delegation design makes it possible to allow a user
// to write "v" instead of "Eq(v)" where a Matcher is expected, which // to write "v" instead of "Eq(v)" where a Matcher is expected, which
// is impossible if we pass matchers by pointers. It also eases // is impossible if we pass matchers by pointers. It also eases
// ownership management as Matcher objects can now be copied like // ownership management as Matcher objects can now be copied like
// plain values. // plain values.
// MatchResultListener is an abstract class. Its << operator can be
// used by a matcher to explain why a value matches or doesn't match.
//
// TODO(wan@google.com): add method
// bool InterestedInWhy(bool result) const;
// to indicate whether the listener is interested in why the match
// result is 'result'.
class MatchResultListener {
public:
// Creates a listener object with the given underlying ostream. The
// listener does not own the ostream.
explicit MatchResultListener(::std::ostream* os) : stream_(os) {}
virtual ~MatchResultListener() = 0; // Makes this class abstract.
// Streams x to the underlying ostream; does nothing if the ostream
// is NULL.
template <typename T>
MatchResultListener& operator<<(const T& x) {
if (stream_ != NULL)
*stream_ << x;
return *this;
}
// Returns the underlying ostream.
::std::ostream* stream() { return stream_; }
// Returns true iff the listener is interested in an explanation of
// the match result. A matcher's MatchAndExplain() method can use
// this information to avoid generating the explanation when no one
// intends to hear it.
bool IsInterested() const { return stream_ != NULL; }
private:
::std::ostream* const stream_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener);
};
inline MatchResultListener::~MatchResultListener() {
}
// The implementation of a matcher. // The implementation of a matcher.
template <typename T> template <typename T>
class MatcherInterface { class MatcherInterface {
public: public:
virtual ~MatcherInterface() {} virtual ~MatcherInterface() {}
// Returns true iff the matcher matches x. // Returns true iff the matcher matches x; also explains the match
virtual bool Matches(T x) const = 0; // result to 'listener', in the form of a non-restrictive relative
// clause ("which ...", "whose ...", etc) that describes x. For
// example, the MatchAndExplain() method of the Pointee(...) matcher
// should generate an explanation like "which points to ...".
//
// You should override this method when defining a new matcher.
//
// It's the responsibility of the caller (Google Mock) to guarantee
// that 'listener' is not NULL. This helps to simplify a matcher's
// implementation when it doesn't care about the performance, as it
// can talk to 'listener' without checking its validity first.
// However, in order to implement dummy listeners efficiently,
// listener->stream() may be NULL.
virtual bool MatchAndExplain(T x, MatchResultListener* listener) const =
0;
// Describes this matcher to an ostream. // Describes this matcher to an ostream. The function should print
// a verb phrase that describes the property a value matching this
// matcher should have. The subject of the verb phrase is the value
// being matched. For example, the DescribeTo() method of the Gt(7)
// matcher prints "is greater than 7".
virtual void DescribeTo(::std::ostream* os) const = 0; virtual void DescribeTo(::std::ostream* os) const = 0;
// Describes the negation of this matcher to an ostream. For // Describes the negation of this matcher to an ostream. For
// example, if the description of this matcher is "is greater than // example, if the description of this matcher is "is greater than
// 7", the negated description could be "is not greater than 7". // 7", the negated description could be "is not greater than 7".
// You are not required to override this when implementing // You are not required to override this when implementing
// MatcherInterface, but it is highly advised so that your matcher // MatcherInterface, but it is highly advised so that your matcher
// can produce good error messages. // can produce good error messages.
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "not ("; *os << "not (";
DescribeTo(os); DescribeTo(os);
*os << ")"; *os << ")";
} }
// Explains why x matches, or doesn't match, the matcher. Override
// this to provide any additional information that helps a user
// understand the match result.
virtual void ExplainMatchResultTo(T /* x */, ::std::ostream* /* os */) co
nst {
// By default, nothing more needs to be explained, as Google Mock
// has already printed the value of x when this function is
// called.
}
}; };
namespace internal { namespace internal {
// A match result listener that ignores the explanation.
class DummyMatchResultListener : public MatchResultListener {
public:
DummyMatchResultListener() : MatchResultListener(NULL) {}
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener);
};
// A match result listener that forwards the explanation to a given
// ostream. The difference between this and MatchResultListener is
// that the former is concrete.
class StreamMatchResultListener : public MatchResultListener {
public:
explicit StreamMatchResultListener(::std::ostream* os)
: MatchResultListener(os) {}
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener);
};
// A match result listener that stores the explanation in a string.
class StringMatchResultListener : public MatchResultListener {
public:
StringMatchResultListener() : MatchResultListener(&ss_) {}
// Returns the explanation heard so far.
internal::string str() const { return ss_.str(); }
private:
::std::stringstream ss_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener);
};
// An internal class for implementing Matcher<T>, which will derive // An internal class for implementing Matcher<T>, which will derive
// from it. We put functionalities common to all Matcher<T> // from it. We put functionalities common to all Matcher<T>
// specializations here to avoid code duplication. // specializations here to avoid code duplication.
template <typename T> template <typename T>
class MatcherBase { class MatcherBase {
public: public:
// Returns true iff the matcher matches x; also explains the match
// result to 'listener'.
bool MatchAndExplain(T x, MatchResultListener* listener) const {
return impl_->MatchAndExplain(x, listener);
}
// Returns true iff this matcher matches x. // Returns true iff this matcher matches x.
bool Matches(T x) const { return impl_->Matches(x); } bool Matches(T x) const {
DummyMatchResultListener dummy;
return MatchAndExplain(x, &dummy);
}
// Describes this matcher to an ostream. // Describes this matcher to an ostream.
void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
// Describes the negation of this matcher to an ostream. // Describes the negation of this matcher to an ostream.
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
impl_->DescribeNegationTo(os); impl_->DescribeNegationTo(os);
} }
// Explains why x matches, or doesn't match, the matcher. // Explains why x matches, or doesn't match, the matcher.
void ExplainMatchResultTo(T x, ::std::ostream* os) const { void ExplainMatchResultTo(T x, ::std::ostream* os) const {
impl_->ExplainMatchResultTo(x, os); StreamMatchResultListener listener(os);
MatchAndExplain(x, &listener);
} }
protected: protected:
MatcherBase() {} MatcherBase() {}
// Constructs a matcher from its implementation. // Constructs a matcher from its implementation.
explicit MatcherBase(const MatcherInterface<T>* impl) explicit MatcherBase(const MatcherInterface<T>* impl)
: impl_(impl) {} : impl_(impl) {}
virtual ~MatcherBase() {} virtual ~MatcherBase() {}
private: private:
// shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar // shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar
// interfaces. The former dynamically allocates a chunk of memory // interfaces. The former dynamically allocates a chunk of memory
// to hold the reference count, while the latter tracks all // to hold the reference count, while the latter tracks all
// references using a circular linked list without allocating // references using a circular linked list without allocating
// memory. It has been observed that linked_ptr performs better in // memory. It has been observed that linked_ptr performs better in
// typical scenarios. However, shared_ptr can out-perform // typical scenarios. However, shared_ptr can out-perform
// linked_ptr when there are many more uses of the copy constructor // linked_ptr when there are many more uses of the copy constructor
// than the default constructor. // than the default constructor.
// //
skipping to change at line 147 skipping to change at line 243
// memory. It has been observed that linked_ptr performs better in // memory. It has been observed that linked_ptr performs better in
// typical scenarios. However, shared_ptr can out-perform // typical scenarios. However, shared_ptr can out-perform
// linked_ptr when there are many more uses of the copy constructor // linked_ptr when there are many more uses of the copy constructor
// than the default constructor. // than the default constructor.
// //
// If performance becomes a problem, we should see if using // If performance becomes a problem, we should see if using
// shared_ptr helps. // shared_ptr helps.
::testing::internal::linked_ptr<const MatcherInterface<T> > impl_; ::testing::internal::linked_ptr<const MatcherInterface<T> > impl_;
}; };
// The default implementation of ExplainMatchResultTo() for
// polymorphic matchers.
template <typename PolymorphicMatcherImpl, typename T>
inline void ExplainMatchResultTo(const PolymorphicMatcherImpl& /* impl */,
const T& /* x */,
::std::ostream* /* os */) {
// By default, nothing more needs to be said, as Google Mock already
// prints the value of x elsewhere.
}
} // namespace internal } // namespace internal
// A Matcher<T> is a copyable and IMMUTABLE (except by assignment) // A Matcher<T> is a copyable and IMMUTABLE (except by assignment)
// object that can check whether a value of type T matches. The // object that can check whether a value of type T matches. The
// implementation of Matcher<T> is just a linked_ptr to const // implementation of Matcher<T> is just a linked_ptr to const
// MatcherInterface<T>, so copying is fairly cheap. Don't inherit // MatcherInterface<T>, so copying is fairly cheap. Don't inherit
// from Matcher! // from Matcher!
template <typename T> template <typename T>
class Matcher : public internal::MatcherBase<T> { class Matcher : public internal::MatcherBase<T> {
public: public:
skipping to change at line 221 skipping to change at line 307
Matcher(const internal::string& s); // NOLINT Matcher(const internal::string& s); // NOLINT
// Allows the user to write "foo" instead of Eq("foo") sometimes. // Allows the user to write "foo" instead of Eq("foo") sometimes.
Matcher(const char* s); // NOLINT Matcher(const char* s); // NOLINT
}; };
// The PolymorphicMatcher class template makes it easy to implement a // The PolymorphicMatcher class template makes it easy to implement a
// polymorphic matcher (i.e. a matcher that can match values of more // polymorphic matcher (i.e. a matcher that can match values of more
// than one type, e.g. Eq(n) and NotNull()). // than one type, e.g. Eq(n) and NotNull()).
// //
// To define a polymorphic matcher, a user first provides a Impl class // To define a polymorphic matcher, a user should provide an Impl
// that has a Matches() method, a DescribeTo() method, and a // class that has a DescribeTo() method and a DescribeNegationTo()
// DescribeNegationTo() method. The Matches() method is usually a // method, and define a member function (or member function template)
// method template (such that it works with multiple types). Then the
// user creates the polymorphic matcher using
// MakePolymorphicMatcher(). To provide additional explanation to the
// match result, define a FREE function (or function template)
// //
// void ExplainMatchResultTo(const Impl& matcher, const Value& value, // bool MatchAndExplain(const Value& value,
// ::std::ostream* os); // MatchResultListener* listener) const;
// //
// in the SAME NAME SPACE where Impl is defined. See the definition // See the definition of NotNull() for a complete example.
// of NotNull() for a complete example.
template <class Impl> template <class Impl>
class PolymorphicMatcher { class PolymorphicMatcher {
public: public:
explicit PolymorphicMatcher(const Impl& impl) : impl_(impl) {} explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {}
// Returns a mutable reference to the underlying matcher // Returns a mutable reference to the underlying matcher
// implementation object. // implementation object.
Impl& mutable_impl() { return impl_; } Impl& mutable_impl() { return impl_; }
// Returns an immutable reference to the underlying matcher // Returns an immutable reference to the underlying matcher
// implementation object. // implementation object.
const Impl& impl() const { return impl_; } const Impl& impl() const { return impl_; }
template <typename T> template <typename T>
skipping to change at line 251 skipping to change at line 332
Impl& mutable_impl() { return impl_; } Impl& mutable_impl() { return impl_; }
// Returns an immutable reference to the underlying matcher // Returns an immutable reference to the underlying matcher
// implementation object. // implementation object.
const Impl& impl() const { return impl_; } const Impl& impl() const { return impl_; }
template <typename T> template <typename T>
operator Matcher<T>() const { operator Matcher<T>() const {
return Matcher<T>(new MonomorphicImpl<T>(impl_)); return Matcher<T>(new MonomorphicImpl<T>(impl_));
} }
private: private:
template <typename T> template <typename T>
class MonomorphicImpl : public MatcherInterface<T> { class MonomorphicImpl : public MatcherInterface<T> {
public: public:
explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {}
virtual bool Matches(T x) const { return impl_.Matches(x); }
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
impl_.DescribeTo(os); impl_.DescribeTo(os);
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
impl_.DescribeNegationTo(os); impl_.DescribeNegationTo(os);
} }
virtual void ExplainMatchResultTo(T x, ::std::ostream* os) const { virtual bool MatchAndExplain(T x, MatchResultListener* listener) const
using ::testing::internal::ExplainMatchResultTo; {
return impl_.MatchAndExplain(x, listener);
// C++ uses Argument-Dependent Look-up (aka Koenig Look-up) to
// resolve the call to ExplainMatchResultTo() here. This
// means that if there's a ExplainMatchResultTo() function
// defined in the name space where class Impl is defined, it
// will be picked by the compiler as the better match.
// Otherwise the default implementation of it in
// ::testing::internal will be picked.
//
// This look-up rule lets a writer of a polymorphic matcher
// customize the behavior of ExplainMatchResultTo() when he
// cares to. Nothing needs to be done by the writer if he
// doesn't need to customize it.
ExplainMatchResultTo(impl_, x, os);
} }
private: private:
const Impl impl_; const Impl impl_;
GTEST_DISALLOW_ASSIGN_(MonomorphicImpl);
}; };
Impl impl_; Impl impl_;
GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher);
}; };
// Creates a matcher from its implementation. This is easier to use // Creates a matcher from its implementation. This is easier to use
// than the Matcher<T> constructor as it doesn't require you to // than the Matcher<T> constructor as it doesn't require you to
// explicitly write the template argument, e.g. // explicitly write the template argument, e.g.
// //
// MakeMatcher(foo); // MakeMatcher(foo);
// vs // vs
// Matcher<const string&>(foo); // Matcher<const string&>(foo);
template <typename T> template <typename T>
skipping to change at line 386 skipping to change at line 456
} }
// A<T>() returns a matcher that matches any value of type T. // A<T>() returns a matcher that matches any value of type T.
template <typename T> template <typename T>
Matcher<T> A(); Matcher<T> A();
// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
// and MUST NOT BE USED IN USER CODE!!! // and MUST NOT BE USED IN USER CODE!!!
namespace internal { namespace internal {
// Appends the explanation on the result of matcher.Matches(value) to // If the explanation is not empty, prints it to the ostream.
// os iff the explanation is not empty. inline void PrintIfNotEmpty(const internal::string& explanation,
template <typename T> std::ostream* os) {
void ExplainMatchResultAsNeededTo(const Matcher<T>& matcher, T value, if (explanation != "" && os != NULL) {
::std::ostream* os) { *os << ", " << explanation;
::std::stringstream reason;
matcher.ExplainMatchResultTo(value, &reason);
const internal::string s = reason.str();
if (s != "") {
*os << " (" << s << ")";
} }
} }
// Matches the value against the given matcher, prints the value and explai
ns
// the match result to the listener. Returns the match result.
// 'listener' must not be NULL.
// Value cannot be passed by const reference, because some matchers take a
// non-const argument.
template <typename Value, typename T>
bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
MatchResultListener* listener) {
if (!listener->IsInterested()) {
// If the listener is not interested, we do not need to construct the
// inner explanation.
return matcher.Matches(value);
}
StringMatchResultListener inner_listener;
const bool match = matcher.MatchAndExplain(value, &inner_listener);
UniversalPrint(value, listener->stream());
PrintIfNotEmpty(inner_listener.str(), listener->stream());
return match;
}
// An internal helper class for doing compile-time loop on a tuple's // An internal helper class for doing compile-time loop on a tuple's
// fields. // fields.
template <size_t N> template <size_t N>
class TuplePrefix { class TuplePrefix {
public: public:
// TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true // TuplePrefix<N>::Matches(matcher_tuple, value_tuple) returns true
// iff the first N fields of matcher_tuple matches the first N // iff the first N fields of matcher_tuple matches the first N
// fields of value_tuple, respectively. // fields of value_tuple, respectively.
template <typename MatcherTuple, typename ValueTuple> template <typename MatcherTuple, typename ValueTuple>
static bool Matches(const MatcherTuple& matcher_tuple, static bool Matches(const MatcherTuple& matcher_tuple,
const ValueTuple& value_tuple) { const ValueTuple& value_tuple) {
using ::std::tr1::get; using ::std::tr1::get;
return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple) return TuplePrefix<N - 1>::Matches(matcher_tuple, value_tuple)
&& get<N - 1>(matcher_tuple).Matches(get<N - 1>(value_tuple)); && get<N - 1>(matcher_tuple).Matches(get<N - 1>(value_tuple));
} }
// TuplePrefix<N>::DescribeMatchFailuresTo(matchers, values, os) // TuplePrefix<N>::ExplainMatchFailuresTo(matchers, values, os)
// describes failures in matching the first N fields of matchers // describes failures in matching the first N fields of matchers
// against the first N fields of values. If there is no failure, // against the first N fields of values. If there is no failure,
// nothing will be streamed to os. // nothing will be streamed to os.
template <typename MatcherTuple, typename ValueTuple> template <typename MatcherTuple, typename ValueTuple>
static void DescribeMatchFailuresTo(const MatcherTuple& matchers, static void ExplainMatchFailuresTo(const MatcherTuple& matchers,
const ValueTuple& values, const ValueTuple& values,
::std::ostream* os) { ::std::ostream* os) {
using ::std::tr1::tuple_element; using ::std::tr1::tuple_element;
using ::std::tr1::get; using ::std::tr1::get;
// First, describes failures in the first N - 1 fields. // First, describes failures in the first N - 1 fields.
TuplePrefix<N - 1>::DescribeMatchFailuresTo(matchers, values, os); TuplePrefix<N - 1>::ExplainMatchFailuresTo(matchers, values, os);
// Then describes the failure (if any) in the (N - 1)-th (0-based) // Then describes the failure (if any) in the (N - 1)-th (0-based)
// field. // field.
typename tuple_element<N - 1, MatcherTuple>::type matcher = typename tuple_element<N - 1, MatcherTuple>::type matcher =
get<N - 1>(matchers); get<N - 1>(matchers);
typedef typename tuple_element<N - 1, ValueTuple>::type Value; typedef typename tuple_element<N - 1, ValueTuple>::type Value;
Value value = get<N - 1>(values); Value value = get<N - 1>(values);
if (!matcher.Matches(value)) { StringMatchResultListener listener;
if (!matcher.MatchAndExplain(value, &listener)) {
// TODO(wan): include in the message the name of the parameter // TODO(wan): include in the message the name of the parameter
// as used in MOCK_METHOD*() when possible. // as used in MOCK_METHOD*() when possible.
*os << " Expected arg #" << N - 1 << ": "; *os << " Expected arg #" << N - 1 << ": ";
get<N - 1>(matchers).DescribeTo(os); get<N - 1>(matchers).DescribeTo(os);
*os << "\n Actual: "; *os << "\n Actual: ";
// We remove the reference in type Value to prevent the // We remove the reference in type Value to prevent the
// universal printer from printing the address of value, which // universal printer from printing the address of value, which
// isn't interesting to the user most of the time. The // isn't interesting to the user most of the time. The
// matcher's ExplainMatchResultTo() method handles the case when // matcher's MatchAndExplain() method handles the case when
// the address is interesting. // the address is interesting.
internal::UniversalPrinter<GMOCK_REMOVE_REFERENCE_(Value)>:: internal::UniversalPrint(value, os);
Print(value, os); PrintIfNotEmpty(listener.str(), os);
ExplainMatchResultAsNeededTo<Value>(matcher, value, os);
*os << "\n"; *os << "\n";
} }
} }
}; };
// The base case. // The base case.
template <> template <>
class TuplePrefix<0> { class TuplePrefix<0> {
public: public:
template <typename MatcherTuple, typename ValueTuple> template <typename MatcherTuple, typename ValueTuple>
static bool Matches(const MatcherTuple& /* matcher_tuple */, static bool Matches(const MatcherTuple& /* matcher_tuple */,
const ValueTuple& /* value_tuple */) { const ValueTuple& /* value_tuple */) {
return true; return true;
} }
template <typename MatcherTuple, typename ValueTuple> template <typename MatcherTuple, typename ValueTuple>
static void DescribeMatchFailuresTo(const MatcherTuple& /* matchers */, static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */,
const ValueTuple& /* values */, const ValueTuple& /* values */,
::std::ostream* /* os */) {} ::std::ostream* /* os */) {}
}; };
// TupleMatches(matcher_tuple, value_tuple) returns true iff all // TupleMatches(matcher_tuple, value_tuple) returns true iff all
// matchers in matcher_tuple match the corresponding fields in // matchers in matcher_tuple match the corresponding fields in
// value_tuple. It is a compiler error if matcher_tuple and // value_tuple. It is a compiler error if matcher_tuple and
// value_tuple have different number of fields or incompatible field // value_tuple have different number of fields or incompatible field
// types. // types.
template <typename MatcherTuple, typename ValueTuple> template <typename MatcherTuple, typename ValueTuple>
bool TupleMatches(const MatcherTuple& matcher_tuple, bool TupleMatches(const MatcherTuple& matcher_tuple,
const ValueTuple& value_tuple) { const ValueTuple& value_tuple) {
skipping to change at line 491 skipping to change at line 579
GMOCK_COMPILE_ASSERT_(tuple_size<MatcherTuple>::value == GMOCK_COMPILE_ASSERT_(tuple_size<MatcherTuple>::value ==
tuple_size<ValueTuple>::value, tuple_size<ValueTuple>::value,
matcher_and_value_have_different_numbers_of_fields) ; matcher_and_value_have_different_numbers_of_fields) ;
return TuplePrefix<tuple_size<ValueTuple>::value>:: return TuplePrefix<tuple_size<ValueTuple>::value>::
Matches(matcher_tuple, value_tuple); Matches(matcher_tuple, value_tuple);
} }
// Describes failures in matching matchers against values. If there // Describes failures in matching matchers against values. If there
// is no failure, nothing will be streamed to os. // is no failure, nothing will be streamed to os.
template <typename MatcherTuple, typename ValueTuple> template <typename MatcherTuple, typename ValueTuple>
void DescribeMatchFailureTupleTo(const MatcherTuple& matchers, void ExplainMatchFailureTupleTo(const MatcherTuple& matchers,
const ValueTuple& values, const ValueTuple& values,
::std::ostream* os) { ::std::ostream* os) {
using ::std::tr1::tuple_size; using ::std::tr1::tuple_size;
TuplePrefix<tuple_size<MatcherTuple>::value>::DescribeMatchFailuresTo( TuplePrefix<tuple_size<MatcherTuple>::value>::ExplainMatchFailuresTo(
matchers, values, os); matchers, values, os);
} }
// The MatcherCastImpl class template is a helper for implementing // The MatcherCastImpl class template is a helper for implementing
// MatcherCast(). We need this helper in order to partially // MatcherCast(). We need this helper in order to partially
// specialize the implementation of MatcherCast() (C++ allows // specialize the implementation of MatcherCast() (C++ allows
// class/struct templates to be partially specialized, but not // class/struct templates to be partially specialized, but not
// function templates.). // function templates.).
// This general version is used when MatcherCast()'s argument is a // This general version is used when MatcherCast()'s argument is a
skipping to change at line 525 skipping to change at line 613
// This more specialized version is used when MatcherCast()'s argument // This more specialized version is used when MatcherCast()'s argument
// is already a Matcher. This only compiles when type T can be // is already a Matcher. This only compiles when type T can be
// statically converted to type U. // statically converted to type U.
template <typename T, typename U> template <typename T, typename U>
class MatcherCastImpl<T, Matcher<U> > { class MatcherCastImpl<T, Matcher<U> > {
public: public:
static Matcher<T> Cast(const Matcher<U>& source_matcher) { static Matcher<T> Cast(const Matcher<U>& source_matcher) {
return Matcher<T>(new Impl(source_matcher)); return Matcher<T>(new Impl(source_matcher));
} }
private: private:
class Impl : public MatcherInterface<T> { class Impl : public MatcherInterface<T> {
public: public:
explicit Impl(const Matcher<U>& source_matcher) explicit Impl(const Matcher<U>& source_matcher)
: source_matcher_(source_matcher) {} : source_matcher_(source_matcher) {}
// We delegate the matching logic to the source matcher. // We delegate the matching logic to the source matcher.
virtual bool Matches(T x) const { virtual bool MatchAndExplain(T x, MatchResultListener* listener) const
return source_matcher_.Matches(static_cast<U>(x)); {
return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
} }
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
source_matcher_.DescribeTo(os); source_matcher_.DescribeTo(os);
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
source_matcher_.DescribeNegationTo(os); source_matcher_.DescribeNegationTo(os);
} }
virtual void ExplainMatchResultTo(T x, ::std::ostream* os) const {
source_matcher_.ExplainMatchResultTo(static_cast<U>(x), os);
}
private: private:
const Matcher<U> source_matcher_; const Matcher<U> source_matcher_;
GTEST_DISALLOW_ASSIGN_(Impl);
}; };
}; };
// This even more specialized version is used for efficiently casting // This even more specialized version is used for efficiently casting
// a matcher to its own type. // a matcher to its own type.
template <typename T> template <typename T>
class MatcherCastImpl<T, Matcher<T> > { class MatcherCastImpl<T, Matcher<T> > {
public: public:
static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; } static Matcher<T> Cast(const Matcher<T>& matcher) { return matcher; }
}; };
// Implements A<T>(). // Implements A<T>().
template <typename T> template <typename T>
class AnyMatcherImpl : public MatcherInterface<T> { class AnyMatcherImpl : public MatcherInterface<T> {
public: public:
virtual bool Matches(T /* x */) const { return true; } virtual bool MatchAndExplain(
T /* x */, MatchResultListener* /* listener */) const { return true;
}
virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; } virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
// This is mostly for completeness' safe, as it's not very useful // This is mostly for completeness' safe, as it's not very useful
// to write Not(A<bool>()). However we cannot completely rule out // to write Not(A<bool>()). However we cannot completely rule out
// such a possibility, and it doesn't hurt to be prepared. // such a possibility, and it doesn't hurt to be prepared.
*os << "never matches"; *os << "never matches";
} }
}; };
// Implements _, a matcher that matches any value of any // Implements _, a matcher that matches any value of any
skipping to change at line 597 skipping to change at line 686
// //
// The matcher defined here is polymorphic (for example, Eq(5) can be // The matcher defined here is polymorphic (for example, Eq(5) can be
// used to match an int, a short, a double, etc). Therefore we use // used to match an int, a short, a double, etc). Therefore we use
// a template type conversion operator in the implementation. // a template type conversion operator in the implementation.
// //
// We define this as a macro in order to eliminate duplicated source // We define this as a macro in order to eliminate duplicated source
// code. // code.
// //
// The following template definition assumes that the Rhs parameter is // The following template definition assumes that the Rhs parameter is
// a "bare" type (i.e. neither 'const T' nor 'T&'). // a "bare" type (i.e. neither 'const T' nor 'T&').
#define GMOCK_IMPLEMENT_COMPARISON_MATCHER_(name, op, relation) \ #define GMOCK_IMPLEMENT_COMPARISON_MATCHER_( \
name, op, relation, negated_relation) \
template <typename Rhs> class name##Matcher { \ template <typename Rhs> class name##Matcher { \
public: \ public: \
explicit name##Matcher(const Rhs& rhs) : rhs_(rhs) {} \ explicit name##Matcher(const Rhs& rhs) : rhs_(rhs) {} \
template <typename Lhs> \ template <typename Lhs> \
operator Matcher<Lhs>() const { \ operator Matcher<Lhs>() const { \
return MakeMatcher(new Impl<Lhs>(rhs_)); \ return MakeMatcher(new Impl<Lhs>(rhs_)); \
} \ } \
private: \ private: \
template <typename Lhs> \ template <typename Lhs> \
class Impl : public MatcherInterface<Lhs> { \ class Impl : public MatcherInterface<Lhs> { \
public: \ public: \
explicit Impl(const Rhs& rhs) : rhs_(rhs) {} \ explicit Impl(const Rhs& rhs) : rhs_(rhs) {} \
virtual bool Matches(Lhs lhs) const { return lhs op rhs_; } \ virtual bool MatchAndExplain(\
Lhs lhs, MatchResultListener* /* listener */) const { \
return lhs op rhs_; \
} \
virtual void DescribeTo(::std::ostream* os) const { \ virtual void DescribeTo(::std::ostream* os) const { \
*os << "is " relation " "; \ *os << relation " "; \
UniversalPrinter<Rhs>::Print(rhs_, os); \ UniversalPrinter<Rhs>::Print(rhs_, os); \
} \ } \
virtual void DescribeNegationTo(::std::ostream* os) const { \ virtual void DescribeNegationTo(::std::ostream* os) const { \
*os << "is not " relation " "; \ *os << negated_relation " "; \
UniversalPrinter<Rhs>::Print(rhs_, os); \ UniversalPrinter<Rhs>::Print(rhs_, os); \
} \ } \
private: \ private: \
Rhs rhs_; \ Rhs rhs_; \
GTEST_DISALLOW_ASSIGN_(Impl); \
}; \ }; \
Rhs rhs_; \ Rhs rhs_; \
GTEST_DISALLOW_ASSIGN_(name##Matcher); \
} }
// Implements Eq(v), Ge(v), Gt(v), Le(v), Lt(v), and Ne(v) // Implements Eq(v), Ge(v), Gt(v), Le(v), Lt(v), and Ne(v)
// respectively. // respectively.
GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "equal to"); GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to"
GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ge, >=, "greater than or equal to"); );
GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Gt, >, "greater than"); GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ge, >=, "is >=", "isn't >=");
GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Le, <=, "less than or equal to"); GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Gt, >, "is >", "isn't >");
GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Lt, <, "less than"); GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Le, <=, "is <=", "isn't <=");
GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ne, !=, "not equal to"); GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Lt, <, "is <", "isn't <");
GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ne, !=, "isn't equal to", "is equal to"
);
#undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_ #undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_
// Implements the polymorphic IsNull() matcher, which matches any // Implements the polymorphic IsNull() matcher, which matches any raw or sm art
// pointer that is NULL. // pointer that is NULL.
class IsNullMatcher { class IsNullMatcher {
public: public:
template <typename T> template <typename Pointer>
bool Matches(T* p) const { return p == NULL; } bool MatchAndExplain(const Pointer& p,
MatchResultListener* /* listener */) const {
return GetRawPointer(p) == NULL;
}
void DescribeTo(::std::ostream* os) const { *os << "is NULL"; } void DescribeTo(::std::ostream* os) const { *os << "is NULL"; }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
*os << "is not NULL"; *os << "isn't NULL";
} }
}; };
// Implements the polymorphic NotNull() matcher, which matches any // Implements the polymorphic NotNull() matcher, which matches any raw or s mart
// pointer that is not NULL. // pointer that is not NULL.
class NotNullMatcher { class NotNullMatcher {
public: public:
template <typename T> template <typename Pointer>
bool Matches(T* p) const { return p != NULL; } bool MatchAndExplain(const Pointer& p,
MatchResultListener* /* listener */) const {
return GetRawPointer(p) != NULL;
}
void DescribeTo(::std::ostream* os) const { *os << "is not NULL"; } void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
*os << "is NULL"; *os << "is NULL";
} }
}; };
// Ref(variable) matches any argument that is a reference to // Ref(variable) matches any argument that is a reference to
// 'variable'. This matcher is polymorphic as it can match any // 'variable'. This matcher is polymorphic as it can match any
// super type of the type of 'variable'. // super type of the type of 'variable'.
// //
// The RefMatcher template class implements Ref(variable). It can // The RefMatcher template class implements Ref(variable). It can
skipping to change at line 700 skipping to change at line 801
template <typename Super> template <typename Super>
operator Matcher<Super&>() const { operator Matcher<Super&>() const {
// By passing object_ (type T&) to Impl(), which expects a Super&, // By passing object_ (type T&) to Impl(), which expects a Super&,
// we make sure that Super is a super type of T. In particular, // we make sure that Super is a super type of T. In particular,
// this catches using Ref(const_value) as a matcher for a // this catches using Ref(const_value) as a matcher for a
// non-const reference, as you cannot implicitly convert a const // non-const reference, as you cannot implicitly convert a const
// reference to a non-const reference. // reference to a non-const reference.
return MakeMatcher(new Impl<Super>(object_)); return MakeMatcher(new Impl<Super>(object_));
} }
private: private:
template <typename Super> template <typename Super>
class Impl : public MatcherInterface<Super&> { class Impl : public MatcherInterface<Super&> {
public: public:
explicit Impl(Super& x) : object_(x) {} // NOLINT explicit Impl(Super& x) : object_(x) {} // NOLINT
// Matches() takes a Super& (as opposed to const Super&) in // MatchAndExplain() takes a Super& (as opposed to const Super&)
// order to match the interface MatcherInterface<Super&>. // in order to match the interface MatcherInterface<Super&>.
virtual bool Matches(Super& x) const { return &x == &object_; } // NOL virtual bool MatchAndExplain(
INT Super& x, MatchResultListener* listener) const {
*listener << "which is located @" << static_cast<const void*>(&x);
return &x == &object_;
}
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
*os << "references the variable "; *os << "references the variable ";
UniversalPrinter<Super&>::Print(object_, os); UniversalPrinter<Super&>::Print(object_, os);
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "does not reference the variable "; *os << "does not reference the variable ";
UniversalPrinter<Super&>::Print(object_, os); UniversalPrinter<Super&>::Print(object_, os);
} }
virtual void ExplainMatchResultTo(Super& x, // NOLINT
::std::ostream* os) const {
*os << "is located @" << static_cast<const void*>(&x);
}
private: private:
const Super& object_; const Super& object_;
GTEST_DISALLOW_ASSIGN_(Impl);
}; };
T& object_; T& object_;
GTEST_DISALLOW_ASSIGN_(RefMatcher);
}; };
// Polymorphic helper functions for narrow and wide string matchers. // Polymorphic helper functions for narrow and wide string matchers.
inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) { inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) {
return String::CaseInsensitiveCStringEquals(lhs, rhs); return String::CaseInsensitiveCStringEquals(lhs, rhs);
} }
inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs, inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs,
const wchar_t* rhs) { const wchar_t* rhs) {
return String::CaseInsensitiveWideCStringEquals(lhs, rhs); return String::CaseInsensitiveWideCStringEquals(lhs, rhs);
skipping to change at line 778 skipping to change at line 884
class StrEqualityMatcher { class StrEqualityMatcher {
public: public:
typedef typename StringType::const_pointer ConstCharPointer; typedef typename StringType::const_pointer ConstCharPointer;
StrEqualityMatcher(const StringType& str, bool expect_eq, StrEqualityMatcher(const StringType& str, bool expect_eq,
bool case_sensitive) bool case_sensitive)
: string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive ) {} : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive ) {}
// When expect_eq_ is true, returns true iff s is equal to string_; // When expect_eq_ is true, returns true iff s is equal to string_;
// otherwise returns true iff s is not equal to string_. // otherwise returns true iff s is not equal to string_.
bool Matches(ConstCharPointer s) const { bool MatchAndExplain(ConstCharPointer s,
MatchResultListener* listener) const {
if (s == NULL) { if (s == NULL) {
return !expect_eq_; return !expect_eq_;
} }
return Matches(StringType(s)); return MatchAndExplain(StringType(s), listener);
} }
bool Matches(const StringType& s) const { bool MatchAndExplain(const StringType& s,
MatchResultListener* /* listener */) const {
const bool eq = case_sensitive_ ? s == string_ : const bool eq = case_sensitive_ ? s == string_ :
CaseInsensitiveStringEquals(s, string_); CaseInsensitiveStringEquals(s, string_);
return expect_eq_ == eq; return expect_eq_ == eq;
} }
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
DescribeToHelper(expect_eq_, os); DescribeToHelper(expect_eq_, os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
skipping to change at line 798 skipping to change at line 906
return expect_eq_ == eq; return expect_eq_ == eq;
} }
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
DescribeToHelper(expect_eq_, os); DescribeToHelper(expect_eq_, os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
DescribeToHelper(!expect_eq_, os); DescribeToHelper(!expect_eq_, os);
} }
private: private:
void DescribeToHelper(bool expect_eq, ::std::ostream* os) const { void DescribeToHelper(bool expect_eq, ::std::ostream* os) const {
*os << "is "; *os << (expect_eq ? "is " : "isn't ");
if (!expect_eq) {
*os << "not ";
}
*os << "equal to "; *os << "equal to ";
if (!case_sensitive_) { if (!case_sensitive_) {
*os << "(ignoring case) "; *os << "(ignoring case) ";
} }
UniversalPrinter<StringType>::Print(string_, os); UniversalPrinter<StringType>::Print(string_, os);
} }
const StringType string_; const StringType string_;
const bool expect_eq_; const bool expect_eq_;
const bool case_sensitive_; const bool case_sensitive_;
GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher);
}; };
// Implements the polymorphic HasSubstr(substring) matcher, which // Implements the polymorphic HasSubstr(substring) matcher, which
// can be used as a Matcher<T> as long as T can be converted to a // can be used as a Matcher<T> as long as T can be converted to a
// string. // string.
template <typename StringType> template <typename StringType>
class HasSubstrMatcher { class HasSubstrMatcher {
public: public:
typedef typename StringType::const_pointer ConstCharPointer; typedef typename StringType::const_pointer ConstCharPointer;
explicit HasSubstrMatcher(const StringType& substring) explicit HasSubstrMatcher(const StringType& substring)
: substring_(substring) {} : substring_(substring) {}
// These overloaded methods allow HasSubstr(substring) to be used as a // These overloaded methods allow HasSubstr(substring) to be used as a
// Matcher<T> as long as T can be converted to string. Returns true // Matcher<T> as long as T can be converted to string. Returns true
// iff s contains substring_ as a substring. // iff s contains substring_ as a substring.
bool Matches(ConstCharPointer s) const { bool MatchAndExplain(ConstCharPointer s,
return s != NULL && Matches(StringType(s)); MatchResultListener* listener) const {
return s != NULL && MatchAndExplain(StringType(s), listener);
} }
bool Matches(const StringType& s) const { bool MatchAndExplain(const StringType& s,
MatchResultListener* /* listener */) const {
return s.find(substring_) != StringType::npos; return s.find(substring_) != StringType::npos;
} }
// Describes what this matcher matches. // Describes what this matcher matches.
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "has substring "; *os << "has substring ";
UniversalPrinter<StringType>::Print(substring_, os); UniversalPrinter<StringType>::Print(substring_, os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
skipping to change at line 848 skipping to change at line 958
// Describes what this matcher matches. // Describes what this matcher matches.
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "has substring "; *os << "has substring ";
UniversalPrinter<StringType>::Print(substring_, os); UniversalPrinter<StringType>::Print(substring_, os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
*os << "has no substring "; *os << "has no substring ";
UniversalPrinter<StringType>::Print(substring_, os); UniversalPrinter<StringType>::Print(substring_, os);
} }
private: private:
const StringType substring_; const StringType substring_;
GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher);
}; };
// Implements the polymorphic StartsWith(substring) matcher, which // Implements the polymorphic StartsWith(substring) matcher, which
// can be used as a Matcher<T> as long as T can be converted to a // can be used as a Matcher<T> as long as T can be converted to a
// string. // string.
template <typename StringType> template <typename StringType>
class StartsWithMatcher { class StartsWithMatcher {
public: public:
typedef typename StringType::const_pointer ConstCharPointer; typedef typename StringType::const_pointer ConstCharPointer;
explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) { explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
} }
// These overloaded methods allow StartsWith(prefix) to be used as a // These overloaded methods allow StartsWith(prefix) to be used as a
// Matcher<T> as long as T can be converted to string. Returns true // Matcher<T> as long as T can be converted to string. Returns true
// iff s starts with prefix_. // iff s starts with prefix_.
bool Matches(ConstCharPointer s) const { bool MatchAndExplain(ConstCharPointer s,
return s != NULL && Matches(StringType(s)); MatchResultListener* listener) const {
return s != NULL && MatchAndExplain(StringType(s), listener);
} }
bool Matches(const StringType& s) const { bool MatchAndExplain(const StringType& s,
MatchResultListener* /* listener */) const {
return s.length() >= prefix_.length() && return s.length() >= prefix_.length() &&
s.substr(0, prefix_.length()) == prefix_; s.substr(0, prefix_.length()) == prefix_;
} }
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "starts with "; *os << "starts with ";
UniversalPrinter<StringType>::Print(prefix_, os); UniversalPrinter<StringType>::Print(prefix_, os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
skipping to change at line 884 skipping to change at line 999
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "starts with "; *os << "starts with ";
UniversalPrinter<StringType>::Print(prefix_, os); UniversalPrinter<StringType>::Print(prefix_, os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
*os << "doesn't start with "; *os << "doesn't start with ";
UniversalPrinter<StringType>::Print(prefix_, os); UniversalPrinter<StringType>::Print(prefix_, os);
} }
private: private:
const StringType prefix_; const StringType prefix_;
GTEST_DISALLOW_ASSIGN_(StartsWithMatcher);
}; };
// Implements the polymorphic EndsWith(substring) matcher, which // Implements the polymorphic EndsWith(substring) matcher, which
// can be used as a Matcher<T> as long as T can be converted to a // can be used as a Matcher<T> as long as T can be converted to a
// string. // string.
template <typename StringType> template <typename StringType>
class EndsWithMatcher { class EndsWithMatcher {
public: public:
typedef typename StringType::const_pointer ConstCharPointer; typedef typename StringType::const_pointer ConstCharPointer;
explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {} explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
// These overloaded methods allow EndsWith(suffix) to be used as a // These overloaded methods allow EndsWith(suffix) to be used as a
// Matcher<T> as long as T can be converted to string. Returns true // Matcher<T> as long as T can be converted to string. Returns true
// iff s ends with suffix_. // iff s ends with suffix_.
bool Matches(ConstCharPointer s) const { bool MatchAndExplain(ConstCharPointer s,
return s != NULL && Matches(StringType(s)); MatchResultListener* listener) const {
return s != NULL && MatchAndExplain(StringType(s), listener);
} }
bool Matches(const StringType& s) const { bool MatchAndExplain(const StringType& s,
MatchResultListener* /* listener */) const {
return s.length() >= suffix_.length() && return s.length() >= suffix_.length() &&
s.substr(s.length() - suffix_.length()) == suffix_; s.substr(s.length() - suffix_.length()) == suffix_;
} }
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "ends with "; *os << "ends with ";
UniversalPrinter<StringType>::Print(suffix_, os); UniversalPrinter<StringType>::Print(suffix_, os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
skipping to change at line 919 skipping to change at line 1039
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "ends with "; *os << "ends with ";
UniversalPrinter<StringType>::Print(suffix_, os); UniversalPrinter<StringType>::Print(suffix_, os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
*os << "doesn't end with "; *os << "doesn't end with ";
UniversalPrinter<StringType>::Print(suffix_, os); UniversalPrinter<StringType>::Print(suffix_, os);
} }
private: private:
const StringType suffix_; const StringType suffix_;
};
#if GMOCK_HAS_REGEX GTEST_DISALLOW_ASSIGN_(EndsWithMatcher);
};
// Implements polymorphic matchers MatchesRegex(regex) and // Implements polymorphic matchers MatchesRegex(regex) and
// ContainsRegex(regex), which can be used as a Matcher<T> as long as // ContainsRegex(regex), which can be used as a Matcher<T> as long as
// T can be converted to a string. // T can be converted to a string.
class MatchesRegexMatcher { class MatchesRegexMatcher {
public: public:
MatchesRegexMatcher(const RE* regex, bool full_match) MatchesRegexMatcher(const RE* regex, bool full_match)
: regex_(regex), full_match_(full_match) {} : regex_(regex), full_match_(full_match) {}
// These overloaded methods allow MatchesRegex(regex) to be used as // These overloaded methods allow MatchesRegex(regex) to be used as
// a Matcher<T> as long as T can be converted to string. Returns // a Matcher<T> as long as T can be converted to string. Returns
// true iff s matches regular expression regex. When full_match_ is // true iff s matches regular expression regex. When full_match_ is
// true, a full match is done; otherwise a partial match is done. // true, a full match is done; otherwise a partial match is done.
bool Matches(const char* s) const { bool MatchAndExplain(const char* s,
return s != NULL && Matches(internal::string(s)); MatchResultListener* listener) const {
return s != NULL && MatchAndExplain(internal::string(s), listener);
} }
bool Matches(const internal::string& s) const { bool MatchAndExplain(const internal::string& s,
MatchResultListener* /* listener */) const {
return full_match_ ? RE::FullMatch(s, *regex_) : return full_match_ ? RE::FullMatch(s, *regex_) :
RE::PartialMatch(s, *regex_); RE::PartialMatch(s, *regex_);
} }
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << (full_match_ ? "matches" : "contains") *os << (full_match_ ? "matches" : "contains")
<< " regular expression "; << " regular expression ";
UniversalPrinter<internal::string>::Print(regex_->pattern(), os); UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
} }
skipping to change at line 957 skipping to change at line 1080
*os << (full_match_ ? "matches" : "contains") *os << (full_match_ ? "matches" : "contains")
<< " regular expression "; << " regular expression ";
UniversalPrinter<internal::string>::Print(regex_->pattern(), os); UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
*os << "doesn't " << (full_match_ ? "match" : "contain") *os << "doesn't " << (full_match_ ? "match" : "contain")
<< " regular expression "; << " regular expression ";
UniversalPrinter<internal::string>::Print(regex_->pattern(), os); UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
} }
private: private:
const internal::linked_ptr<const RE> regex_; const internal::linked_ptr<const RE> regex_;
const bool full_match_; const bool full_match_;
};
#endif // GMOCK_HAS_REGEX GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher);
};
// Implements a matcher that compares the two fields of a 2-tuple // Implements a matcher that compares the two fields of a 2-tuple
// using one of the ==, <=, <, etc, operators. The two fields being // using one of the ==, <=, <, etc, operators. The two fields being
// compared don't have to have the same type. // compared don't have to have the same type.
// //
// The matcher defined here is polymorphic (for example, Eq() can be // The matcher defined here is polymorphic (for example, Eq() can be
// used to match a tuple<int, short>, a tuple<const long&, double>, // used to match a tuple<int, short>, a tuple<const long&, double>,
// etc). Therefore we use a template type conversion operator in the // etc). Therefore we use a template type conversion operator in the
// implementation. // implementation.
// //
skipping to change at line 986 skipping to change at line 1110
class name##2Matcher { \ class name##2Matcher { \
public: \ public: \
template <typename T1, typename T2> \ template <typename T1, typename T2> \
operator Matcher<const ::std::tr1::tuple<T1, T2>&>() const { \ operator Matcher<const ::std::tr1::tuple<T1, T2>&>() const { \
return MakeMatcher(new Impl<T1, T2>); \ return MakeMatcher(new Impl<T1, T2>); \
} \ } \
private: \ private: \
template <typename T1, typename T2> \ template <typename T1, typename T2> \
class Impl : public MatcherInterface<const ::std::tr1::tuple<T1, T2>&> { \ class Impl : public MatcherInterface<const ::std::tr1::tuple<T1, T2>&> { \
public: \ public: \
virtual bool Matches(const ::std::tr1::tuple<T1, T2>& args) const { \ virtual bool MatchAndExplain( \
const ::std::tr1::tuple<T1, T2>& args, \
MatchResultListener* /* listener */) const { \
return ::std::tr1::get<0>(args) op ::std::tr1::get<1>(args); \ return ::std::tr1::get<0>(args) op ::std::tr1::get<1>(args); \
} \ } \
virtual void DescribeTo(::std::ostream* os) const { \ virtual void DescribeTo(::std::ostream* os) const { \
*os << "are a pair (x, y) where x " #op " y"; \ *os << "are a pair (x, y) where x " #op " y"; \
} \ } \
virtual void DescribeNegationTo(::std::ostream* os) const { \ virtual void DescribeNegationTo(::std::ostream* os) const { \
*os << "are a pair (x, y) where x " #op " y is false"; \ *os << "are a pair (x, y) where x " #op " y is false"; \
} \ } \
}; \ }; \
} }
skipping to change at line 1018 skipping to change at line 1144
// Implements the Not(...) matcher for a particular argument type T. // Implements the Not(...) matcher for a particular argument type T.
// We do not nest it inside the NotMatcher class template, as that // We do not nest it inside the NotMatcher class template, as that
// will prevent different instantiations of NotMatcher from sharing // will prevent different instantiations of NotMatcher from sharing
// the same NotMatcherImpl<T> class. // the same NotMatcherImpl<T> class.
template <typename T> template <typename T>
class NotMatcherImpl : public MatcherInterface<T> { class NotMatcherImpl : public MatcherInterface<T> {
public: public:
explicit NotMatcherImpl(const Matcher<T>& matcher) explicit NotMatcherImpl(const Matcher<T>& matcher)
: matcher_(matcher) {} : matcher_(matcher) {}
virtual bool Matches(T x) const { virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
return !matcher_.Matches(x); return !matcher_.MatchAndExplain(x, listener);
} }
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
matcher_.DescribeNegationTo(os); matcher_.DescribeNegationTo(os);
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
matcher_.DescribeTo(os); matcher_.DescribeTo(os);
} }
virtual void ExplainMatchResultTo(T x, ::std::ostream* os) const {
matcher_.ExplainMatchResultTo(x, os);
}
private: private:
const Matcher<T> matcher_; const Matcher<T> matcher_;
GTEST_DISALLOW_ASSIGN_(NotMatcherImpl);
}; };
// Implements the Not(m) matcher, which matches a value that doesn't // Implements the Not(m) matcher, which matches a value that doesn't
// match matcher m. // match matcher m.
template <typename InnerMatcher> template <typename InnerMatcher>
class NotMatcher { class NotMatcher {
public: public:
explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {} explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
// This template type conversion operator allows Not(m) to be used // This template type conversion operator allows Not(m) to be used
skipping to change at line 1050 skipping to change at line 1175
class NotMatcher { class NotMatcher {
public: public:
explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {} explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {}
// This template type conversion operator allows Not(m) to be used // This template type conversion operator allows Not(m) to be used
// to match any type m can match. // to match any type m can match.
template <typename T> template <typename T>
operator Matcher<T>() const { operator Matcher<T>() const {
return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_))); return Matcher<T>(new NotMatcherImpl<T>(SafeMatcherCast<T>(matcher_)));
} }
private: private:
InnerMatcher matcher_; InnerMatcher matcher_;
GTEST_DISALLOW_ASSIGN_(NotMatcher);
}; };
// Implements the AllOf(m1, m2) matcher for a particular argument type // Implements the AllOf(m1, m2) matcher for a particular argument type
// T. We do not nest it inside the BothOfMatcher class template, as // T. We do not nest it inside the BothOfMatcher class template, as
// that will prevent different instantiations of BothOfMatcher from // that will prevent different instantiations of BothOfMatcher from
// sharing the same BothOfMatcherImpl<T> class. // sharing the same BothOfMatcherImpl<T> class.
template <typename T> template <typename T>
class BothOfMatcherImpl : public MatcherInterface<T> { class BothOfMatcherImpl : public MatcherInterface<T> {
public: public:
BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2) BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
: matcher1_(matcher1), matcher2_(matcher2) {} : matcher1_(matcher1), matcher2_(matcher2) {}
virtual bool Matches(T x) const {
return matcher1_.Matches(x) && matcher2_.Matches(x);
}
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
*os << "("; *os << "(";
matcher1_.DescribeTo(os); matcher1_.DescribeTo(os);
*os << ") and ("; *os << ") and (";
matcher2_.DescribeTo(os); matcher2_.DescribeTo(os);
*os << ")"; *os << ")";
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "not "; *os << "(";
DescribeTo(os); matcher1_.DescribeNegationTo(os);
*os << ") or (";
matcher2_.DescribeNegationTo(os);
*os << ")";
} }
virtual void ExplainMatchResultTo(T x, ::std::ostream* os) const { virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
if (Matches(x)) { // If either matcher1_ or matcher2_ doesn't match x, we only need
// When both matcher1_ and matcher2_ match x, we need to // to explain why one of them fails.
// explain why *both* of them match. StringMatchResultListener listener1;
::std::stringstream ss1; if (!matcher1_.MatchAndExplain(x, &listener1)) {
matcher1_.ExplainMatchResultTo(x, &ss1); *listener << listener1.str();
const internal::string s1 = ss1.str(); return false;
}
::std::stringstream ss2; StringMatchResultListener listener2;
matcher2_.ExplainMatchResultTo(x, &ss2); if (!matcher2_.MatchAndExplain(x, &listener2)) {
const internal::string s2 = ss2.str(); *listener << listener2.str();
return false;
}
if (s1 == "") { // Otherwise we need to explain why *both* of them match.
*os << s2; const internal::string s1 = listener1.str();
} else { const internal::string s2 = listener2.str();
*os << s1;
if (s2 != "") { if (s1 == "") {
*os << "; " << s2; *listener << s2;
}
}
} else { } else {
// Otherwise we only need to explain why *one* of them fails *listener << s1;
// to match. if (s2 != "") {
if (!matcher1_.Matches(x)) { *listener << ", and " << s2;
matcher1_.ExplainMatchResultTo(x, os);
} else {
matcher2_.ExplainMatchResultTo(x, os);
} }
} }
return true;
} }
private: private:
const Matcher<T> matcher1_; const Matcher<T> matcher1_;
const Matcher<T> matcher2_; const Matcher<T> matcher2_;
GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl);
}; };
// Used for implementing the AllOf(m_1, ..., m_n) matcher, which // Used for implementing the AllOf(m_1, ..., m_n) matcher, which
// matches a value that matches all of the matchers m_1, ..., and m_n. // matches a value that matches all of the matchers m_1, ..., and m_n.
template <typename Matcher1, typename Matcher2> template <typename Matcher1, typename Matcher2>
class BothOfMatcher { class BothOfMatcher {
public: public:
BothOfMatcher(Matcher1 matcher1, Matcher2 matcher2) BothOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
: matcher1_(matcher1), matcher2_(matcher2) {} : matcher1_(matcher1), matcher2_(matcher2) {}
skipping to change at line 1132 skipping to change at line 1261
: matcher1_(matcher1), matcher2_(matcher2) {} : matcher1_(matcher1), matcher2_(matcher2) {}
// This template type conversion operator allows a // This template type conversion operator allows a
// BothOfMatcher<Matcher1, Matcher2> object to match any type that // BothOfMatcher<Matcher1, Matcher2> object to match any type that
// both Matcher1 and Matcher2 can match. // both Matcher1 and Matcher2 can match.
template <typename T> template <typename T>
operator Matcher<T>() const { operator Matcher<T>() const {
return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_ ), return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_ ),
SafeMatcherCast<T>(matcher2_ ))); SafeMatcherCast<T>(matcher2_ )));
} }
private: private:
Matcher1 matcher1_; Matcher1 matcher1_;
Matcher2 matcher2_; Matcher2 matcher2_;
GTEST_DISALLOW_ASSIGN_(BothOfMatcher);
}; };
// Implements the AnyOf(m1, m2) matcher for a particular argument type // Implements the AnyOf(m1, m2) matcher for a particular argument type
// T. We do not nest it inside the AnyOfMatcher class template, as // T. We do not nest it inside the AnyOfMatcher class template, as
// that will prevent different instantiations of AnyOfMatcher from // that will prevent different instantiations of AnyOfMatcher from
// sharing the same EitherOfMatcherImpl<T> class. // sharing the same EitherOfMatcherImpl<T> class.
template <typename T> template <typename T>
class EitherOfMatcherImpl : public MatcherInterface<T> { class EitherOfMatcherImpl : public MatcherInterface<T> {
public: public:
EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher 2) EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher 2)
: matcher1_(matcher1), matcher2_(matcher2) {} : matcher1_(matcher1), matcher2_(matcher2) {}
virtual bool Matches(T x) const {
return matcher1_.Matches(x) || matcher2_.Matches(x);
}
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
*os << "("; *os << "(";
matcher1_.DescribeTo(os); matcher1_.DescribeTo(os);
*os << ") or ("; *os << ") or (";
matcher2_.DescribeTo(os); matcher2_.DescribeTo(os);
*os << ")"; *os << ")";
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "not "; *os << "(";
DescribeTo(os); matcher1_.DescribeNegationTo(os);
*os << ") and (";
matcher2_.DescribeNegationTo(os);
*os << ")";
} }
virtual void ExplainMatchResultTo(T x, ::std::ostream* os) const { virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
if (Matches(x)) { // If either matcher1_ or matcher2_ matches x, we just need to
// If either matcher1_ or matcher2_ matches x, we just need // explain why *one* of them matches.
// to explain why *one* of them matches. StringMatchResultListener listener1;
if (matcher1_.Matches(x)) { if (matcher1_.MatchAndExplain(x, &listener1)) {
matcher1_.ExplainMatchResultTo(x, os); *listener << listener1.str();
} else { return true;
matcher2_.ExplainMatchResultTo(x, os); }
}
} else {
// Otherwise we need to explain why *neither* matches.
::std::stringstream ss1;
matcher1_.ExplainMatchResultTo(x, &ss1);
const internal::string s1 = ss1.str();
::std::stringstream ss2; StringMatchResultListener listener2;
matcher2_.ExplainMatchResultTo(x, &ss2); if (matcher2_.MatchAndExplain(x, &listener2)) {
const internal::string s2 = ss2.str(); *listener << listener2.str();
return true;
}
if (s1 == "") { // Otherwise we need to explain why *both* of them fail.
*os << s2; const internal::string s1 = listener1.str();
} else { const internal::string s2 = listener2.str();
*os << s1;
if (s2 != "") { if (s1 == "") {
*os << "; " << s2; *listener << s2;
} } else {
*listener << s1;
if (s2 != "") {
*listener << ", and " << s2;
} }
} }
return false;
} }
private: private:
const Matcher<T> matcher1_; const Matcher<T> matcher1_;
const Matcher<T> matcher2_; const Matcher<T> matcher2_;
GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl);
}; };
// Used for implementing the AnyOf(m_1, ..., m_n) matcher, which // Used for implementing the AnyOf(m_1, ..., m_n) matcher, which
// matches a value that matches at least one of the matchers m_1, ..., // matches a value that matches at least one of the matchers m_1, ...,
// and m_n. // and m_n.
template <typename Matcher1, typename Matcher2> template <typename Matcher1, typename Matcher2>
class EitherOfMatcher { class EitherOfMatcher {
public: public:
EitherOfMatcher(Matcher1 matcher1, Matcher2 matcher2) EitherOfMatcher(Matcher1 matcher1, Matcher2 matcher2)
: matcher1_(matcher1), matcher2_(matcher2) {} : matcher1_(matcher1), matcher2_(matcher2) {}
skipping to change at line 1215 skipping to change at line 1349
: matcher1_(matcher1), matcher2_(matcher2) {} : matcher1_(matcher1), matcher2_(matcher2) {}
// This template type conversion operator allows a // This template type conversion operator allows a
// EitherOfMatcher<Matcher1, Matcher2> object to match any type that // EitherOfMatcher<Matcher1, Matcher2> object to match any type that
// both Matcher1 and Matcher2 can match. // both Matcher1 and Matcher2 can match.
template <typename T> template <typename T>
operator Matcher<T>() const { operator Matcher<T>() const {
return Matcher<T>(new EitherOfMatcherImpl<T>( return Matcher<T>(new EitherOfMatcherImpl<T>(
SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_))); SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_)));
} }
private: private:
Matcher1 matcher1_; Matcher1 matcher1_;
Matcher2 matcher2_; Matcher2 matcher2_;
GTEST_DISALLOW_ASSIGN_(EitherOfMatcher);
}; };
// Used for implementing Truly(pred), which turns a predicate into a // Used for implementing Truly(pred), which turns a predicate into a
// matcher. // matcher.
template <typename Predicate> template <typename Predicate>
class TrulyMatcher { class TrulyMatcher {
public: public:
explicit TrulyMatcher(Predicate pred) : predicate_(pred) {} explicit TrulyMatcher(Predicate pred) : predicate_(pred) {}
// This method template allows Truly(pred) to be used as a matcher // This method template allows Truly(pred) to be used as a matcher
// for type T where T is the argument type of predicate 'pred'. The // for type T where T is the argument type of predicate 'pred'. The
// argument is passed by reference as the predicate may be // argument is passed by reference as the predicate may be
// interested in the address of the argument. // interested in the address of the argument.
template <typename T> template <typename T>
bool Matches(T& x) const { // NOLINT bool MatchAndExplain(T& x, // NOLINT
MatchResultListener* /* listener */) const {
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// MSVC warns about converting a value into bool (warning 4800). // MSVC warns about converting a value into bool (warning 4800).
#pragma warning(push) // Saves the current warning state. #pragma warning(push) // Saves the current warning state.
#pragma warning(disable:4800) // Temporarily disables warning 4800. #pragma warning(disable:4800) // Temporarily disables warning 4800.
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
return predicate_(x); return predicate_(x);
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
#pragma warning(pop) // Restores the warning state. #pragma warning(pop) // Restores the warning state.
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
} }
skipping to change at line 1251 skipping to change at line 1389
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
} }
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "satisfies the given predicate"; *os << "satisfies the given predicate";
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
*os << "doesn't satisfy the given predicate"; *os << "doesn't satisfy the given predicate";
} }
private: private:
Predicate predicate_; Predicate predicate_;
GTEST_DISALLOW_ASSIGN_(TrulyMatcher);
}; };
// Used for implementing Matches(matcher), which turns a matcher into // Used for implementing Matches(matcher), which turns a matcher into
// a predicate. // a predicate.
template <typename M> template <typename M>
class MatcherAsPredicate { class MatcherAsPredicate {
public: public:
explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {} explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {}
// This template operator() allows Matches(m) to be used as a // This template operator() allows Matches(m) to be used as a
skipping to change at line 1286 skipping to change at line 1427
// compile when matcher_ has type Matcher<const T&>; if we write // compile when matcher_ has type Matcher<const T&>; if we write
// Matcher<const T&>(matcher_).Matches(x) here, it won't compile // Matcher<const T&>(matcher_).Matches(x) here, it won't compile
// when matcher_ has type Matcher<T>; if we just write // when matcher_ has type Matcher<T>; if we just write
// matcher_.Matches(x), it won't compile when matcher_ is // matcher_.Matches(x), it won't compile when matcher_ is
// polymorphic, e.g. Eq(5). // polymorphic, e.g. Eq(5).
// //
// MatcherCast<const T&>() is necessary for making the code work // MatcherCast<const T&>() is necessary for making the code work
// in all of the above situations. // in all of the above situations.
return MatcherCast<const T&>(matcher_).Matches(x); return MatcherCast<const T&>(matcher_).Matches(x);
} }
private: private:
M matcher_; M matcher_;
GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate);
}; };
// For implementing ASSERT_THAT() and EXPECT_THAT(). The template // For implementing ASSERT_THAT() and EXPECT_THAT(). The template
// argument M must be a type that can be converted to a matcher. // argument M must be a type that can be converted to a matcher.
template <typename M> template <typename M>
class PredicateFormatterFromMatcher { class PredicateFormatterFromMatcher {
public: public:
explicit PredicateFormatterFromMatcher(const M& m) : matcher_(m) {} explicit PredicateFormatterFromMatcher(const M& m) : matcher_(m) {}
// This template () operator allows a PredicateFormatterFromMatcher // This template () operator allows a PredicateFormatterFromMatcher
skipping to change at line 1312 skipping to change at line 1456
// We convert matcher_ to a Matcher<const T&> *now* instead of // We convert matcher_ to a Matcher<const T&> *now* instead of
// when the PredicateFormatterFromMatcher object was constructed, // when the PredicateFormatterFromMatcher object was constructed,
// as matcher_ may be polymorphic (e.g. NotNull()) and we won't // as matcher_ may be polymorphic (e.g. NotNull()) and we won't
// know which type to instantiate it to until we actually see the // know which type to instantiate it to until we actually see the
// type of x here. // type of x here.
// //
// We write MatcherCast<const T&>(matcher_) instead of // We write MatcherCast<const T&>(matcher_) instead of
// Matcher<const T&>(matcher_), as the latter won't compile when // Matcher<const T&>(matcher_), as the latter won't compile when
// matcher_ has type Matcher<T> (e.g. An<int>()). // matcher_ has type Matcher<T> (e.g. An<int>()).
const Matcher<const T&> matcher = MatcherCast<const T&>(matcher_); const Matcher<const T&> matcher = MatcherCast<const T&>(matcher_);
if (matcher.Matches(x)) { StringMatchResultListener listener;
if (MatchPrintAndExplain(x, matcher, &listener))
return AssertionSuccess(); return AssertionSuccess();
} else {
::std::stringstream ss; ::std::stringstream ss;
ss << "Value of: " << value_text << "\n" ss << "Value of: " << value_text << "\n"
<< "Expected: "; << "Expected: ";
matcher.DescribeTo(&ss); matcher.DescribeTo(&ss);
ss << "\n Actual: "; ss << "\n Actual: " << listener.str();
UniversalPrinter<T>::Print(x, &ss); return AssertionFailure() << ss.str();
ExplainMatchResultAsNeededTo<const T&>(matcher, x, &ss);
return AssertionFailure(Message() << ss.str());
}
} }
private: private:
const M matcher_; const M matcher_;
GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher);
}; };
// A helper function for converting a matcher to a predicate-formatter // A helper function for converting a matcher to a predicate-formatter
// without the user needing to explicitly write the type. This is // without the user needing to explicitly write the type. This is
// used for implementing ASSERT_THAT() and EXPECT_THAT(). // used for implementing ASSERT_THAT() and EXPECT_THAT().
template <typename M> template <typename M>
inline PredicateFormatterFromMatcher<M> inline PredicateFormatterFromMatcher<M>
MakePredicateFormatterFromMatcher(const M& matcher) { MakePredicateFormatterFromMatcher(const M& matcher) {
return PredicateFormatterFromMatcher<M>(matcher); return PredicateFormatterFromMatcher<M>(matcher);
} }
skipping to change at line 1359 skipping to change at line 1504
FloatingEqMatcher(FloatType rhs, bool nan_eq_nan) : FloatingEqMatcher(FloatType rhs, bool nan_eq_nan) :
rhs_(rhs), nan_eq_nan_(nan_eq_nan) {} rhs_(rhs), nan_eq_nan_(nan_eq_nan) {}
// Implements floating point equality matcher as a Matcher<T>. // Implements floating point equality matcher as a Matcher<T>.
template <typename T> template <typename T>
class Impl : public MatcherInterface<T> { class Impl : public MatcherInterface<T> {
public: public:
Impl(FloatType rhs, bool nan_eq_nan) : Impl(FloatType rhs, bool nan_eq_nan) :
rhs_(rhs), nan_eq_nan_(nan_eq_nan) {} rhs_(rhs), nan_eq_nan_(nan_eq_nan) {}
virtual bool Matches(T value) const { virtual bool MatchAndExplain(T value,
MatchResultListener* /* listener */) const
{
const FloatingPoint<FloatType> lhs(value), rhs(rhs_); const FloatingPoint<FloatType> lhs(value), rhs(rhs_);
// Compares NaNs first, if nan_eq_nan_ is true. // Compares NaNs first, if nan_eq_nan_ is true.
if (nan_eq_nan_ && lhs.is_nan()) { if (nan_eq_nan_ && lhs.is_nan()) {
return rhs.is_nan(); return rhs.is_nan();
} }
return lhs.AlmostEquals(rhs); return lhs.AlmostEquals(rhs);
} }
skipping to change at line 1394 skipping to change at line 1540
} }
os->precision(old_precision); os->precision(old_precision);
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
// As before, get original precision. // As before, get original precision.
const ::std::streamsize old_precision = os->precision( const ::std::streamsize old_precision = os->precision(
::std::numeric_limits<FloatType>::digits10 + 2); ::std::numeric_limits<FloatType>::digits10 + 2);
if (FloatingPoint<FloatType>(rhs_).is_nan()) { if (FloatingPoint<FloatType>(rhs_).is_nan()) {
if (nan_eq_nan_) { if (nan_eq_nan_) {
*os << "is not NaN"; *os << "isn't NaN";
} else { } else {
*os << "is anything"; *os << "is anything";
} }
} else { } else {
*os << "is not approximately " << rhs_; *os << "isn't approximately " << rhs_;
} }
// Restore original precision. // Restore original precision.
os->precision(old_precision); os->precision(old_precision);
} }
private: private:
const FloatType rhs_; const FloatType rhs_;
const bool nan_eq_nan_; const bool nan_eq_nan_;
GTEST_DISALLOW_ASSIGN_(Impl);
}; };
// The following 3 type conversion operators allow FloatEq(rhs) and // The following 3 type conversion operators allow FloatEq(rhs) and
// NanSensitiveFloatEq(rhs) to be used as a Matcher<float>, a // NanSensitiveFloatEq(rhs) to be used as a Matcher<float>, a
// Matcher<const float&>, or a Matcher<float&>, but nothing else. // Matcher<const float&>, or a Matcher<float&>, but nothing else.
// (While Google's C++ coding style doesn't allow arguments passed // (While Google's C++ coding style doesn't allow arguments passed
// by non-const reference, we may see them in code not conforming to // by non-const reference, we may see them in code not conforming to
// the style. Therefore Google Mock needs to support them.) // the style. Therefore Google Mock needs to support them.)
operator Matcher<FloatType>() const { operator Matcher<FloatType>() const {
return MakeMatcher(new Impl<FloatType>(rhs_, nan_eq_nan_)); return MakeMatcher(new Impl<FloatType>(rhs_, nan_eq_nan_));
skipping to change at line 1430 skipping to change at line 1578
operator Matcher<const FloatType&>() const { operator Matcher<const FloatType&>() const {
return MakeMatcher(new Impl<const FloatType&>(rhs_, nan_eq_nan_)); return MakeMatcher(new Impl<const FloatType&>(rhs_, nan_eq_nan_));
} }
operator Matcher<FloatType&>() const { operator Matcher<FloatType&>() const {
return MakeMatcher(new Impl<FloatType&>(rhs_, nan_eq_nan_)); return MakeMatcher(new Impl<FloatType&>(rhs_, nan_eq_nan_));
} }
private: private:
const FloatType rhs_; const FloatType rhs_;
const bool nan_eq_nan_; const bool nan_eq_nan_;
GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher);
}; };
// Implements the Pointee(m) matcher for matching a pointer whose // Implements the Pointee(m) matcher for matching a pointer whose
// pointee matches matcher m. The pointer can be either raw or smart. // pointee matches matcher m. The pointer can be either raw or smart.
template <typename InnerMatcher> template <typename InnerMatcher>
class PointeeMatcher { class PointeeMatcher {
public: public:
explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {} explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {}
// This type conversion operator template allows Pointee(m) to be // This type conversion operator template allows Pointee(m) to be
skipping to change at line 1462 skipping to change at line 1613
// The monomorphic implementation that works for a particular pointer typ e. // The monomorphic implementation that works for a particular pointer typ e.
template <typename Pointer> template <typename Pointer>
class Impl : public MatcherInterface<Pointer> { class Impl : public MatcherInterface<Pointer> {
public: public:
typedef typename PointeeOf<GMOCK_REMOVE_CONST_( // NOLINT typedef typename PointeeOf<GMOCK_REMOVE_CONST_( // NOLINT
GMOCK_REMOVE_REFERENCE_(Pointer))>::type Pointee; GMOCK_REMOVE_REFERENCE_(Pointer))>::type Pointee;
explicit Impl(const InnerMatcher& matcher) explicit Impl(const InnerMatcher& matcher)
: matcher_(MatcherCast<const Pointee&>(matcher)) {} : matcher_(MatcherCast<const Pointee&>(matcher)) {}
virtual bool Matches(Pointer p) const {
return GetRawPointer(p) != NULL && matcher_.Matches(*p);
}
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
*os << "points to a value that "; *os << "points to a value that ";
matcher_.DescribeTo(os); matcher_.DescribeTo(os);
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "does not point to a value that "; *os << "does not point to a value that ";
matcher_.DescribeTo(os); matcher_.DescribeTo(os);
} }
virtual void ExplainMatchResultTo(Pointer pointer, virtual bool MatchAndExplain(Pointer pointer,
::std::ostream* os) const { MatchResultListener* listener) const {
if (GetRawPointer(pointer) == NULL) if (GetRawPointer(pointer) == NULL)
return; return false;
::std::stringstream ss; *listener << "which points to ";
matcher_.ExplainMatchResultTo(*pointer, &ss); return MatchPrintAndExplain(*pointer, matcher_, listener);
const internal::string s = ss.str();
if (s != "") {
*os << "points to a value that " << s;
}
} }
private: private:
const Matcher<const Pointee&> matcher_; const Matcher<const Pointee&> matcher_;
GTEST_DISALLOW_ASSIGN_(Impl);
}; };
const InnerMatcher matcher_; const InnerMatcher matcher_;
GTEST_DISALLOW_ASSIGN_(PointeeMatcher);
}; };
// Implements the Field() matcher for matching a field (i.e. member // Implements the Field() matcher for matching a field (i.e. member
// variable) of an object. // variable) of an object.
template <typename Class, typename FieldType> template <typename Class, typename FieldType>
class FieldMatcher { class FieldMatcher {
public: public:
FieldMatcher(FieldType Class::*field, FieldMatcher(FieldType Class::*field,
const Matcher<const FieldType&>& matcher) const Matcher<const FieldType&>& matcher)
: field_(field), matcher_(matcher) {} : field_(field), matcher_(matcher) {}
// Returns true iff the inner matcher matches obj.field.
bool Matches(const Class& obj) const {
return matcher_.Matches(obj.*field_);
}
// Returns true iff the inner matcher matches obj->field.
bool Matches(const Class* p) const {
return (p != NULL) && matcher_.Matches(p->*field_);
}
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "the given field "; *os << "is an object whose given field ";
matcher_.DescribeTo(os); matcher_.DescribeTo(os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
*os << "the given field "; *os << "is an object whose given field ";
matcher_.DescribeNegationTo(os); matcher_.DescribeNegationTo(os);
} }
// The first argument of ExplainMatchResultTo() is needed to help template <typename T>
bool MatchAndExplain(const T& value, MatchResultListener* listener) const
{
return MatchAndExplainImpl(
typename ::testing::internal::
is_pointer<GMOCK_REMOVE_CONST_(T)>::type(),
value, listener);
}
private:
// The first argument of MatchAndExplainImpl() is needed to help
// Symbian's C++ compiler choose which overload to use. Its type is // Symbian's C++ compiler choose which overload to use. Its type is
// true_type iff the Field() matcher is used to match a pointer. // true_type iff the Field() matcher is used to match a pointer.
void ExplainMatchResultTo(false_type /* is_not_pointer */, const Class& o bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& ob
bj, j,
::std::ostream* os) const { MatchResultListener* listener) const {
::std::stringstream ss; *listener << "whose given field is ";
matcher_.ExplainMatchResultTo(obj.*field_, &ss); return MatchPrintAndExplain(obj.*field_, matcher_, listener);
const internal::string s = ss.str();
if (s != "") {
*os << "the given field " << s;
}
} }
void ExplainMatchResultTo(true_type /* is_pointer */, const Class* p, bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
::std::ostream* os) const { MatchResultListener* listener) const {
if (p != NULL) { if (p == NULL)
// Since *p has a field, it must be a class/struct/union type return false;
// and thus cannot be a pointer. Therefore we pass false_type()
// as the first argument. *listener << "which points to an object ";
ExplainMatchResultTo(false_type(), *p, os); // Since *p has a field, it must be a class/struct/union type and
} // thus cannot be a pointer. Therefore we pass false_type() as
// the first argument.
return MatchAndExplainImpl(false_type(), *p, listener);
} }
private:
const FieldType Class::*field_; const FieldType Class::*field_;
const Matcher<const FieldType&> matcher_; const Matcher<const FieldType&> matcher_;
};
// Explains the result of matching an object or pointer against a field mat GTEST_DISALLOW_ASSIGN_(FieldMatcher);
cher. };
template <typename Class, typename FieldType, typename T>
void ExplainMatchResultTo(const FieldMatcher<Class, FieldType>& matcher,
const T& value, ::std::ostream* os) {
matcher.ExplainMatchResultTo(
typename ::testing::internal::is_pointer<T>::type(), value, os);
}
// Implements the Property() matcher for matching a property // Implements the Property() matcher for matching a property
// (i.e. return value of a getter method) of an object. // (i.e. return value of a getter method) of an object.
template <typename Class, typename PropertyType> template <typename Class, typename PropertyType>
class PropertyMatcher { class PropertyMatcher {
public: public:
// The property may have a reference type, so 'const PropertyType&' // The property may have a reference type, so 'const PropertyType&'
// may cause double references and fail to compile. That's why we // may cause double references and fail to compile. That's why we
// need GMOCK_REFERENCE_TO_CONST, which works regardless of // need GMOCK_REFERENCE_TO_CONST, which works regardless of
// PropertyType being a reference or not. // PropertyType being a reference or not.
typedef GMOCK_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty; typedef GMOCK_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty;
PropertyMatcher(PropertyType (Class::*property)() const, PropertyMatcher(PropertyType (Class::*property)() const,
const Matcher<RefToConstProperty>& matcher) const Matcher<RefToConstProperty>& matcher)
: property_(property), matcher_(matcher) {} : property_(property), matcher_(matcher) {}
// Returns true iff obj.property() matches the inner matcher.
bool Matches(const Class& obj) const {
return matcher_.Matches((obj.*property_)());
}
// Returns true iff p->property() matches the inner matcher.
bool Matches(const Class* p) const {
return (p != NULL) && matcher_.Matches((p->*property_)());
}
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "the given property "; *os << "is an object whose given property ";
matcher_.DescribeTo(os); matcher_.DescribeTo(os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
*os << "the given property "; *os << "is an object whose given property ";
matcher_.DescribeNegationTo(os); matcher_.DescribeNegationTo(os);
} }
// The first argument of ExplainMatchResultTo() is needed to help template <typename T>
bool MatchAndExplain(const T&value, MatchResultListener* listener) const
{
return MatchAndExplainImpl(
typename ::testing::internal::
is_pointer<GMOCK_REMOVE_CONST_(T)>::type(),
value, listener);
}
private:
// The first argument of MatchAndExplainImpl() is needed to help
// Symbian's C++ compiler choose which overload to use. Its type is // Symbian's C++ compiler choose which overload to use. Its type is
// true_type iff the Property() matcher is used to match a pointer. // true_type iff the Property() matcher is used to match a pointer.
void ExplainMatchResultTo(false_type /* is_not_pointer */, const Class& o bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& ob
bj, j,
::std::ostream* os) const { MatchResultListener* listener) const {
::std::stringstream ss; *listener << "whose given property is ";
matcher_.ExplainMatchResultTo((obj.*property_)(), &ss); // Cannot pass the return value (for example, int) to MatchPrintAndExpl
const internal::string s = ss.str(); ain,
if (s != "") { // which takes a non-const reference as argument.
*os << "the given property " << s; RefToConstProperty result = (obj.*property_)();
} return MatchPrintAndExplain(result, matcher_, listener);
} }
void ExplainMatchResultTo(true_type /* is_pointer */, const Class* p, bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,
::std::ostream* os) const { MatchResultListener* listener) const {
if (p != NULL) { if (p == NULL)
// Since *p has a property method, it must be a return false;
// class/struct/union type and thus cannot be a pointer.
// Therefore we pass false_type() as the first argument. *listener << "which points to an object ";
ExplainMatchResultTo(false_type(), *p, os); // Since *p has a property method, it must be a class/struct/union
} // type and thus cannot be a pointer. Therefore we pass
// false_type() as the first argument.
return MatchAndExplainImpl(false_type(), *p, listener);
} }
private:
PropertyType (Class::*property_)() const; PropertyType (Class::*property_)() const;
const Matcher<RefToConstProperty> matcher_; const Matcher<RefToConstProperty> matcher_;
};
// Explains the result of matching an object or pointer against a GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
// property matcher. };
template <typename Class, typename PropertyType, typename T>
void ExplainMatchResultTo(const PropertyMatcher<Class, PropertyType>& match
er,
const T& value, ::std::ostream* os) {
matcher.ExplainMatchResultTo(
typename ::testing::internal::is_pointer<T>::type(), value, os);
}
// Type traits specifying various features of different functors for Result Of. // Type traits specifying various features of different functors for Result Of.
// The default template specifies features for functor objects. // The default template specifies features for functor objects.
// Functor classes have to typedef argument_type and result_type // Functor classes have to typedef argument_type and result_type
// to be compatible with ResultOf. // to be compatible with ResultOf.
template <typename Functor> template <typename Functor>
struct CallableTraits { struct CallableTraits {
typedef typename Functor::result_type ResultType; typedef typename Functor::result_type ResultType;
typedef Functor StorageType; typedef Functor StorageType;
static void CheckIsValid(Functor functor) {} static void CheckIsValid(Functor /* functor */) {}
template <typename T> template <typename T>
static ResultType Invoke(Functor f, T arg) { return f(arg); } static ResultType Invoke(Functor f, T arg) { return f(arg); }
}; };
// Specialization for function pointers. // Specialization for function pointers.
template <typename ArgType, typename ResType> template <typename ArgType, typename ResType>
struct CallableTraits<ResType(*)(ArgType)> { struct CallableTraits<ResType(*)(ArgType)> {
typedef ResType ResultType; typedef ResType ResultType;
typedef ResType(*StorageType)(ArgType); typedef ResType(*StorageType)(ArgType);
skipping to change at line 1685 skipping to change at line 1817
} }
private: private:
typedef typename CallableTraits<Callable>::StorageType CallableStorageTyp e; typedef typename CallableTraits<Callable>::StorageType CallableStorageTyp e;
template <typename T> template <typename T>
class Impl : public MatcherInterface<T> { class Impl : public MatcherInterface<T> {
public: public:
Impl(CallableStorageType callable, const Matcher<ResultType>& matcher) Impl(CallableStorageType callable, const Matcher<ResultType>& matcher)
: callable_(callable), matcher_(matcher) {} : callable_(callable), matcher_(matcher) {}
// Returns true iff callable_(obj) matches the inner matcher.
// The calling syntax is different for different types of callables
// so we abstract it in CallableTraits<Callable>::Invoke().
virtual bool Matches(T obj) const {
return matcher_.Matches(
CallableTraits<Callable>::template Invoke<T>(callable_, obj));
}
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
*os << "result of the given callable "; *os << "is mapped by the given callable to a value that ";
matcher_.DescribeTo(os); matcher_.DescribeTo(os);
} }
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "result of the given callable "; *os << "is mapped by the given callable to a value that ";
matcher_.DescribeNegationTo(os); matcher_.DescribeNegationTo(os);
} }
virtual void ExplainMatchResultTo(T obj, ::std::ostream* os) const { virtual bool MatchAndExplain(T obj, MatchResultListener* listener) cons
::std::stringstream ss; t {
matcher_.ExplainMatchResultTo( *listener << "which is mapped by the given callable to ";
CallableTraits<Callable>::template Invoke<T>(callable_, obj), // Cannot pass the return value (for example, int) to
&ss); // MatchPrintAndExplain, which takes a non-const reference as argumen
const internal::string s = ss.str(); t.
if (s != "") ResultType result =
*os << "result of the given callable " << s; CallableTraits<Callable>::template Invoke<T>(callable_, obj);
return MatchPrintAndExplain(result, matcher_, listener);
} }
private: private:
// Functors often define operator() as non-const method even though // Functors often define operator() as non-const method even though
// they are actualy stateless. But we need to use them even when // they are actualy stateless. But we need to use them even when
// 'this' is a const pointer. It's the user's responsibility not to // 'this' is a const pointer. It's the user's responsibility not to
// use stateful callables with ResultOf(), which does't guarantee // use stateful callables with ResultOf(), which does't guarantee
// how many times the callable will be invoked. // how many times the callable will be invoked.
mutable CallableStorageType callable_; mutable CallableStorageType callable_;
const Matcher<ResultType> matcher_; const Matcher<ResultType> matcher_;
GTEST_DISALLOW_ASSIGN_(Impl);
}; // class Impl }; // class Impl
const CallableStorageType callable_; const CallableStorageType callable_;
const Matcher<ResultType> matcher_; const Matcher<ResultType> matcher_;
};
// Explains the result of matching a value against a functor matcher. GTEST_DISALLOW_ASSIGN_(ResultOfMatcher);
template <typename T, typename Callable> };
void ExplainMatchResultTo(const ResultOfMatcher<Callable>& matcher,
T obj, ::std::ostream* os) {
matcher.ExplainMatchResultTo(obj, os);
}
// Implements an equality matcher for any STL-style container whose element s // Implements an equality matcher for any STL-style container whose element s
// support ==. This matcher is like Eq(), but its failure explanations prov ide // support ==. This matcher is like Eq(), but its failure explanations prov ide
// more detailed information that is useful when the container is used as a set. // more detailed information that is useful when the container is used as a set.
// The failure message reports elements that are in one of the operands but not // The failure message reports elements that are in one of the operands but not
// the other. The failure messages do not report duplicate or out-of-order // the other. The failure messages do not report duplicate or out-of-order
// elements in the containers (which don't properly matter to sets, but can // elements in the containers (which don't properly matter to sets, but can
// occur if the containers are vectors or lists, for example). // occur if the containers are vectors or lists, for example).
// //
// Uses the container's const_iterator, value_type, operator ==, // Uses the container's const_iterator, value_type, operator ==,
skipping to change at line 1759 skipping to change at line 1881
// We make a copy of rhs in case the elements in it are modified // We make a copy of rhs in case the elements in it are modified
// after this matcher is created. // after this matcher is created.
explicit ContainerEqMatcher(const Container& rhs) : rhs_(View::Copy(rhs)) { explicit ContainerEqMatcher(const Container& rhs) : rhs_(View::Copy(rhs)) {
// Makes sure the user doesn't instantiate this class template // Makes sure the user doesn't instantiate this class template
// with a const or reference type. // with a const or reference type.
testing::StaticAssertTypeEq<Container, testing::StaticAssertTypeEq<Container,
GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))>(); GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))>();
} }
template <typename LhsContainer>
bool Matches(const LhsContainer& lhs) const {
// GMOCK_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug
// that causes LhsContainer to be a const type sometimes.
typedef internal::StlContainerView<GMOCK_REMOVE_CONST_(LhsContainer)>
LhsView;
StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
return lhs_stl_container == rhs_;
}
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "equals "; *os << "equals ";
UniversalPrinter<StlContainer>::Print(rhs_, os); UniversalPrinter<StlContainer>::Print(rhs_, os);
} }
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
*os << "does not equal "; *os << "does not equal ";
UniversalPrinter<StlContainer>::Print(rhs_, os); UniversalPrinter<StlContainer>::Print(rhs_, os);
} }
template <typename LhsContainer> template <typename LhsContainer>
void ExplainMatchResultTo(const LhsContainer& lhs, bool MatchAndExplain(const LhsContainer& lhs,
::std::ostream* os) const { MatchResultListener* listener) const {
// GMOCK_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug // GMOCK_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug
// that causes LhsContainer to be a const type sometimes. // that causes LhsContainer to be a const type sometimes.
typedef internal::StlContainerView<GMOCK_REMOVE_CONST_(LhsContainer)> typedef internal::StlContainerView<GMOCK_REMOVE_CONST_(LhsContainer)>
LhsView; LhsView;
typedef typename LhsView::type LhsStlContainer; typedef typename LhsView::type LhsStlContainer;
StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs);
if (lhs_stl_container == rhs_)
return true;
// Something is different. Check for missing values first. ::std::ostream* const os = listener->stream();
bool printed_header = false; if (os != NULL) {
for (typename LhsStlContainer::const_iterator it = // Something is different. Check for extra values first.
lhs_stl_container.begin(); bool printed_header = false;
it != lhs_stl_container.end(); ++it) { for (typename LhsStlContainer::const_iterator it =
if (internal::ArrayAwareFind(rhs_.begin(), rhs_.end(), *it) == lhs_stl_container.begin();
rhs_.end()) { it != lhs_stl_container.end(); ++it) {
if (printed_header) { if (internal::ArrayAwareFind(rhs_.begin(), rhs_.end(), *it) ==
*os << ", "; rhs_.end()) {
} else { if (printed_header) {
*os << "Only in actual: "; *os << ", ";
printed_header = true; } else {
*os << "which has these unexpected elements: ";
printed_header = true;
}
UniversalPrinter<typename LhsStlContainer::value_type>::
Print(*it, os);
} }
UniversalPrinter<typename LhsStlContainer::value_type>::Print(*it, os);
} }
}
// Now check for extra values. // Now check for missing values.
bool printed_header2 = false; bool printed_header2 = false;
for (typename StlContainer::const_iterator it = rhs_.begin(); for (typename StlContainer::const_iterator it = rhs_.begin();
it != rhs_.end(); ++it) { it != rhs_.end(); ++it) {
if (internal::ArrayAwareFind( if (internal::ArrayAwareFind(
lhs_stl_container.begin(), lhs_stl_container.end(), *it) == lhs_stl_container.begin(), lhs_stl_container.end(), *it) ==
lhs_stl_container.end()) { lhs_stl_container.end()) {
if (printed_header2) { if (printed_header2) {
*os << ", "; *os << ", ";
} else { } else {
*os << (printed_header ? "; not" : "Not") << " in actual: "; *os << (printed_header ? ",\nand" : "which")
printed_header2 = true; << " doesn't have these expected elements: ";
printed_header2 = true;
}
UniversalPrinter<typename StlContainer::value_type>::Print(*it, o
s);
} }
UniversalPrinter<typename StlContainer::value_type>::Print(*it, os) ;
} }
} }
return false;
} }
private: private:
const StlContainer rhs_; const StlContainer rhs_;
};
template <typename LhsContainer, typename Container> GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher);
void ExplainMatchResultTo(const ContainerEqMatcher<Container>& matcher, };
const LhsContainer& lhs,
::std::ostream* os) {
matcher.ExplainMatchResultTo(lhs, os);
}
// Implements Contains(element_matcher) for the given argument type Contain er. // Implements Contains(element_matcher) for the given argument type Contain er.
template <typename Container> template <typename Container>
class ContainsMatcherImpl : public MatcherInterface<Container> { class ContainsMatcherImpl : public MatcherInterface<Container> {
public: public:
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) RawContai ner; typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) RawContai ner;
typedef StlContainerView<RawContainer> View; typedef StlContainerView<RawContainer> View;
typedef typename View::type StlContainer; typedef typename View::type StlContainer;
typedef typename View::const_reference StlContainerReference; typedef typename View::const_reference StlContainerReference;
typedef typename StlContainer::value_type Element; typedef typename StlContainer::value_type Element;
template <typename InnerMatcher> template <typename InnerMatcher>
explicit ContainsMatcherImpl(InnerMatcher inner_matcher) explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
: inner_matcher_( : inner_matcher_(
testing::SafeMatcherCast<const Element&>(inner_matcher)) {} testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
// Returns true iff 'container' matches.
virtual bool Matches(Container container) const {
StlContainerReference stl_container = View::ConstReference(container);
for (typename StlContainer::const_iterator it = stl_container.begin();
it != stl_container.end(); ++it) {
if (inner_matcher_.Matches(*it))
return true;
}
return false;
}
// Describes what this matcher does. // Describes what this matcher does.
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
*os << "contains at least one element that "; *os << "contains at least one element that ";
inner_matcher_.DescribeTo(os); inner_matcher_.DescribeTo(os);
} }
// Describes what the negation of this matcher does. // Describes what the negation of this matcher does.
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "doesn't contain any element that "; *os << "doesn't contain any element that ";
inner_matcher_.DescribeTo(os); inner_matcher_.DescribeTo(os);
} }
// Explains why 'container' matches, or doesn't match, this matcher. virtual bool MatchAndExplain(Container container,
virtual void ExplainMatchResultTo(Container container, MatchResultListener* listener) const {
::std::ostream* os) const {
StlContainerReference stl_container = View::ConstReference(container); StlContainerReference stl_container = View::ConstReference(container);
size_t i = 0;
// We need to explain which (if any) element matches inner_matcher_. for (typename StlContainer::const_iterator it = stl_container.begin();
typename StlContainer::const_iterator it = stl_container.begin(); it != stl_container.end(); ++it, ++i) {
for (size_t i = 0; it != stl_container.end(); ++it, ++i) { StringMatchResultListener inner_listener;
if (inner_matcher_.Matches(*it)) { if (inner_matcher_.MatchAndExplain(*it, &inner_listener)) {
*os << "element " << i << " matches"; *listener << "whose element #" << i << " matches";
return; PrintIfNotEmpty(inner_listener.str(), listener->stream());
return true;
} }
} }
return false;
} }
private: private:
const Matcher<const Element&> inner_matcher_; const Matcher<const Element&> inner_matcher_;
GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl);
}; };
// Implements polymorphic Contains(element_matcher). // Implements polymorphic Contains(element_matcher).
template <typename M> template <typename M>
class ContainsMatcher { class ContainsMatcher {
public: public:
explicit ContainsMatcher(M m) : inner_matcher_(m) {} explicit ContainsMatcher(M m) : inner_matcher_(m) {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
return MakeMatcher(new ContainsMatcherImpl<Container>(inner_matcher_)); return MakeMatcher(new ContainsMatcherImpl<Container>(inner_matcher_));
} }
private: private:
const M inner_matcher_; const M inner_matcher_;
GTEST_DISALLOW_ASSIGN_(ContainsMatcher);
}; };
// Implements Key(inner_matcher) for the given argument pair type. // Implements Key(inner_matcher) for the given argument pair type.
// Key(inner_matcher) matches an std::pair whose 'first' field matches // Key(inner_matcher) matches an std::pair whose 'first' field matches
// inner_matcher. For example, Contains(Key(Ge(5))) can be used to match a n // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match a n
// std::map that contains at least one element whose key is >= 5. // std::map that contains at least one element whose key is >= 5.
template <typename PairType> template <typename PairType>
class KeyMatcherImpl : public MatcherInterface<PairType> { class KeyMatcherImpl : public MatcherInterface<PairType> {
public: public:
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(PairType)) RawPairTyp e; typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(PairType)) RawPairTyp e;
typedef typename RawPairType::first_type KeyType; typedef typename RawPairType::first_type KeyType;
template <typename InnerMatcher> template <typename InnerMatcher>
explicit KeyMatcherImpl(InnerMatcher inner_matcher) explicit KeyMatcherImpl(InnerMatcher inner_matcher)
: inner_matcher_( : inner_matcher_(
testing::SafeMatcherCast<const KeyType&>(inner_matcher)) { testing::SafeMatcherCast<const KeyType&>(inner_matcher)) {
} }
// Returns true iff 'key_value.first' (the key) matches the inner matcher . // Returns true iff 'key_value.first' (the key) matches the inner matcher .
virtual bool Matches(PairType key_value) const { virtual bool MatchAndExplain(PairType key_value,
return inner_matcher_.Matches(key_value.first); MatchResultListener* listener) const {
StringMatchResultListener inner_listener;
const bool match = inner_matcher_.MatchAndExplain(key_value.first,
&inner_listener);
const internal::string explanation = inner_listener.str();
if (explanation != "") {
*listener << "whose first field is a value " << explanation;
}
return match;
} }
// Describes what this matcher does. // Describes what this matcher does.
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
*os << "has a key that "; *os << "has a key that ";
inner_matcher_.DescribeTo(os); inner_matcher_.DescribeTo(os);
} }
// Describes what the negation of this matcher does. // Describes what the negation of this matcher does.
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "doesn't have a key that "; *os << "doesn't have a key that ";
inner_matcher_.DescribeTo(os); inner_matcher_.DescribeTo(os);
} }
// Explains why 'key_value' matches, or doesn't match, this matcher.
virtual void ExplainMatchResultTo(PairType key_value,
::std::ostream* os) const {
inner_matcher_.ExplainMatchResultTo(key_value.first, os);
}
private: private:
const Matcher<const KeyType&> inner_matcher_; const Matcher<const KeyType&> inner_matcher_;
GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl);
}; };
// Implements polymorphic Key(matcher_for_key). // Implements polymorphic Key(matcher_for_key).
template <typename M> template <typename M>
class KeyMatcher { class KeyMatcher {
public: public:
explicit KeyMatcher(M m) : matcher_for_key_(m) {} explicit KeyMatcher(M m) : matcher_for_key_(m) {}
template <typename PairType> template <typename PairType>
operator Matcher<PairType>() const { operator Matcher<PairType>() const {
return MakeMatcher(new KeyMatcherImpl<PairType>(matcher_for_key_)); return MakeMatcher(new KeyMatcherImpl<PairType>(matcher_for_key_));
} }
private: private:
const M matcher_for_key_; const M matcher_for_key_;
GTEST_DISALLOW_ASSIGN_(KeyMatcher);
}; };
// Implements Pair(first_matcher, second_matcher) for the given argument pa ir // Implements Pair(first_matcher, second_matcher) for the given argument pa ir
// type with its two matchers. See Pair() function below. // type with its two matchers. See Pair() function below.
template <typename PairType> template <typename PairType>
class PairMatcherImpl : public MatcherInterface<PairType> { class PairMatcherImpl : public MatcherInterface<PairType> {
public: public:
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(PairType)) RawPairTyp e; typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(PairType)) RawPairTyp e;
typedef typename RawPairType::first_type FirstType; typedef typename RawPairType::first_type FirstType;
typedef typename RawPairType::second_type SecondType; typedef typename RawPairType::second_type SecondType;
template <typename FirstMatcher, typename SecondMatcher> template <typename FirstMatcher, typename SecondMatcher>
PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher) PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher)
: first_matcher_( : first_matcher_(
testing::SafeMatcherCast<const FirstType&>(first_matcher)), testing::SafeMatcherCast<const FirstType&>(first_matcher)),
second_matcher_( second_matcher_(
testing::SafeMatcherCast<const SecondType&>(second_matcher)) { testing::SafeMatcherCast<const SecondType&>(second_matcher)) {
} }
// Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.seco
nd'
// matches second_matcher.
virtual bool Matches(PairType a_pair) const {
return first_matcher_.Matches(a_pair.first) &&
second_matcher_.Matches(a_pair.second);
}
// Describes what this matcher does. // Describes what this matcher does.
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
*os << "has a first field that "; *os << "has a first field that ";
first_matcher_.DescribeTo(os); first_matcher_.DescribeTo(os);
*os << ", and has a second field that "; *os << ", and has a second field that ";
second_matcher_.DescribeTo(os); second_matcher_.DescribeTo(os);
} }
// Describes what the negation of this matcher does. // Describes what the negation of this matcher does.
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "has a first field that "; *os << "has a first field that ";
first_matcher_.DescribeNegationTo(os); first_matcher_.DescribeNegationTo(os);
*os << ", or has a second field that "; *os << ", or has a second field that ";
second_matcher_.DescribeNegationTo(os); second_matcher_.DescribeNegationTo(os);
} }
// Explains why 'a_pair' matches, or doesn't match, this matcher. // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.seco
virtual void ExplainMatchResultTo(PairType a_pair, nd'
::std::ostream* os) const { // matches second_matcher.
::std::stringstream ss1; virtual bool MatchAndExplain(PairType a_pair,
first_matcher_.ExplainMatchResultTo(a_pair.first, &ss1); MatchResultListener* listener) const {
internal::string s1 = ss1.str(); if (!listener->IsInterested()) {
if (s1 != "") { // If the listener is not interested, we don't need to construct the
s1 = "the first field " + s1; // explanation.
return first_matcher_.Matches(a_pair.first) &&
second_matcher_.Matches(a_pair.second);
} }
StringMatchResultListener first_inner_listener;
::std::stringstream ss2; if (!first_matcher_.MatchAndExplain(a_pair.first,
second_matcher_.ExplainMatchResultTo(a_pair.second, &ss2); &first_inner_listener)) {
internal::string s2 = ss2.str(); *listener << "whose first field does not match";
if (s2 != "") { PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
s2 = "the second field " + s2; return false;
} }
StringMatchResultListener second_inner_listener;
*os << s1; if (!second_matcher_.MatchAndExplain(a_pair.second,
if (s1 != "" && s2 != "") { &second_inner_listener)) {
*os << ", and "; *listener << "whose second field does not match";
PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
return false;
} }
*os << s2; ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(),
listener);
return true;
} }
private: private:
void ExplainSuccess(const internal::string& first_explanation,
const internal::string& second_explanation,
MatchResultListener* listener) const {
*listener << "whose both fields match";
if (first_explanation != "") {
*listener << ", where the first field is a value " << first_explanati
on;
}
if (second_explanation != "") {
*listener << ", ";
if (first_explanation != "") {
*listener << "and ";
} else {
*listener << "where ";
}
*listener << "the second field is a value " << second_explanation;
}
}
const Matcher<const FirstType&> first_matcher_; const Matcher<const FirstType&> first_matcher_;
const Matcher<const SecondType&> second_matcher_; const Matcher<const SecondType&> second_matcher_;
GTEST_DISALLOW_ASSIGN_(PairMatcherImpl);
}; };
// Implements polymorphic Pair(first_matcher, second_matcher). // Implements polymorphic Pair(first_matcher, second_matcher).
template <typename FirstMatcher, typename SecondMatcher> template <typename FirstMatcher, typename SecondMatcher>
class PairMatcher { class PairMatcher {
public: public:
PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher) PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher)
: first_matcher_(first_matcher), second_matcher_(second_matcher) {} : first_matcher_(first_matcher), second_matcher_(second_matcher) {}
template <typename PairType> template <typename PairType>
operator Matcher<PairType> () const { operator Matcher<PairType> () const {
return MakeMatcher( return MakeMatcher(
new PairMatcherImpl<PairType>( new PairMatcherImpl<PairType>(
first_matcher_, second_matcher_)); first_matcher_, second_matcher_));
} }
private: private:
const FirstMatcher first_matcher_; const FirstMatcher first_matcher_;
const SecondMatcher second_matcher_; const SecondMatcher second_matcher_;
GTEST_DISALLOW_ASSIGN_(PairMatcher);
}; };
// Implements ElementsAre() and ElementsAreArray(). // Implements ElementsAre() and ElementsAreArray().
template <typename Container> template <typename Container>
class ElementsAreMatcherImpl : public MatcherInterface<Container> { class ElementsAreMatcherImpl : public MatcherInterface<Container> {
public: public:
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) RawContai ner; typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) RawContai ner;
typedef internal::StlContainerView<RawContainer> View; typedef internal::StlContainerView<RawContainer> View;
typedef typename View::type StlContainer; typedef typename View::type StlContainer;
typedef typename View::const_reference StlContainerReference; typedef typename View::const_reference StlContainerReference;
typedef typename StlContainer::value_type Element; typedef typename StlContainer::value_type Element;
// Constructs the matcher from a sequence of element values or // Constructs the matcher from a sequence of element values or
// element matchers. // element matchers.
template <typename InputIter> template <typename InputIter>
ElementsAreMatcherImpl(InputIter first, size_t count) { ElementsAreMatcherImpl(InputIter first, size_t a_count) {
matchers_.reserve(count); matchers_.reserve(a_count);
InputIter it = first; InputIter it = first;
for (size_t i = 0; i != count; ++i, ++it) { for (size_t i = 0; i != a_count; ++i, ++it) {
matchers_.push_back(MatcherCast<const Element&>(*it)); matchers_.push_back(MatcherCast<const Element&>(*it));
} }
} }
// Returns true iff 'container' matches.
virtual bool Matches(Container container) const {
StlContainerReference stl_container = View::ConstReference(container);
if (stl_container.size() != count())
return false;
typename StlContainer::const_iterator it = stl_container.begin();
for (size_t i = 0; i != count(); ++it, ++i) {
if (!matchers_[i].Matches(*it))
return false;
}
return true;
}
// Describes what this matcher does. // Describes what this matcher does.
virtual void DescribeTo(::std::ostream* os) const { virtual void DescribeTo(::std::ostream* os) const {
if (count() == 0) { if (count() == 0) {
*os << "is empty"; *os << "is empty";
} else if (count() == 1) { } else if (count() == 1) {
*os << "has 1 element that "; *os << "has 1 element that ";
matchers_[0].DescribeTo(os); matchers_[0].DescribeTo(os);
} else { } else {
*os << "has " << Elements(count()) << " where\n"; *os << "has " << Elements(count()) << " where\n";
for (size_t i = 0; i != count(); ++i) { for (size_t i = 0; i != count(); ++i) {
*os << "element " << i << " "; *os << "element #" << i << " ";
matchers_[i].DescribeTo(os); matchers_[i].DescribeTo(os);
if (i + 1 < count()) { if (i + 1 < count()) {
*os << ",\n"; *os << ",\n";
} }
} }
} }
} }
// Describes what the negation of this matcher does. // Describes what the negation of this matcher does.
virtual void DescribeNegationTo(::std::ostream* os) const { virtual void DescribeNegationTo(::std::ostream* os) const {
if (count() == 0) { if (count() == 0) {
*os << "is not empty"; *os << "isn't empty";
return; return;
} }
*os << "does not have " << Elements(count()) << ", or\n"; *os << "doesn't have " << Elements(count()) << ", or\n";
for (size_t i = 0; i != count(); ++i) { for (size_t i = 0; i != count(); ++i) {
*os << "element " << i << " "; *os << "element #" << i << " ";
matchers_[i].DescribeNegationTo(os); matchers_[i].DescribeNegationTo(os);
if (i + 1 < count()) { if (i + 1 < count()) {
*os << ", or\n"; *os << ", or\n";
} }
} }
} }
// Explains why 'container' matches, or doesn't match, this matcher. virtual bool MatchAndExplain(Container container,
virtual void ExplainMatchResultTo(Container container, MatchResultListener* listener) const {
::std::ostream* os) const {
StlContainerReference stl_container = View::ConstReference(container); StlContainerReference stl_container = View::ConstReference(container);
if (Matches(container)) { const size_t actual_count = stl_container.size();
// We need to explain why *each* element matches (the obvious if (actual_count != count()) {
// ones can be skipped). // The element count doesn't match. If the container is empty,
// there's no need to explain anything as Google Mock already
bool reason_printed = false; // prints the empty container. Otherwise we just need to show
typename StlContainer::const_iterator it = stl_container.begin(); // how many elements there actually are.
for (size_t i = 0; i != count(); ++it, ++i) { if (actual_count != 0) {
::std::stringstream ss; *listener << "which has " << Elements(actual_count);
matchers_[i].ExplainMatchResultTo(*it, &ss);
const string s = ss.str();
if (!s.empty()) {
if (reason_printed) {
*os << ",\n";
}
*os << "element " << i << " " << s;
reason_printed = true;
}
}
} else {
// We need to explain why the container doesn't match.
const size_t actual_count = stl_container.size();
if (actual_count != count()) {
// The element count doesn't match. If the container is
// empty, there's no need to explain anything as Google Mock
// already prints the empty container. Otherwise we just need
// to show how many elements there actually are.
if (actual_count != 0) {
*os << "has " << Elements(actual_count);
}
return;
} }
return false;
}
// The container has the right size but at least one element typename StlContainer::const_iterator it = stl_container.begin();
// doesn't match expectation. We need to find this element and // explanations[i] is the explanation of the element at index i.
// explain why it doesn't match. std::vector<internal::string> explanations(count());
typename StlContainer::const_iterator it = stl_container.begin(); for (size_t i = 0; i != count(); ++it, ++i) {
for (size_t i = 0; i != count(); ++it, ++i) { StringMatchResultListener s;
if (matchers_[i].Matches(*it)) { if (matchers_[i].MatchAndExplain(*it, &s)) {
continue; explanations[i] = s.str();
} } else {
// The container has the right size but the i-th element
*os << "element " << i << " doesn't match"; // doesn't match its expectation.
*listener << "whose element #" << i << " doesn't match";
PrintIfNotEmpty(s.str(), listener->stream());
return false;
}
}
::std::stringstream ss; // Every element matches its expectation. We need to explain why
matchers_[i].ExplainMatchResultTo(*it, &ss); // (the obvious ones can be skipped).
const string s = ss.str(); bool reason_printed = false;
if (!s.empty()) { for (size_t i = 0; i != count(); ++i) {
*os << " (" << s << ")"; const internal::string& s = explanations[i];
if (!s.empty()) {
if (reason_printed) {
*listener << ",\nand ";
} }
return; *listener << "whose element #" << i << " matches, " << s;
reason_printed = true;
} }
} }
return true;
} }
private: private:
static Message Elements(size_t count) { static Message Elements(size_t count) {
return Message() << count << (count == 1 ? " element" : " elements"); return Message() << count << (count == 1 ? " element" : " elements");
} }
size_t count() const { return matchers_.size(); } size_t count() const { return matchers_.size(); }
std::vector<Matcher<const Element&> > matchers_; std::vector<Matcher<const Element&> > matchers_;
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl);
}; };
// Implements ElementsAre() of 0 arguments. // Implements ElementsAre() of 0 arguments.
class ElementsAreMatcher0 { class ElementsAreMatcher0 {
public: public:
ElementsAreMatcher0() {} ElementsAreMatcher0() {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))
skipping to change at line 2227 skipping to change at line 2341
RawContainer; RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
return MakeMatcher(new ElementsAreMatcherImpl<Container>(first_, count_ )); return MakeMatcher(new ElementsAreMatcherImpl<Container>(first_, count_ ));
} }
private: private:
const T* const first_; const T* const first_;
const size_t count_; const size_t count_;
GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher);
}; };
// Constants denoting interpolations in a matcher description string. // Constants denoting interpolations in a matcher description string.
const int kTupleInterpolation = -1; // "%(*)s" const int kTupleInterpolation = -1; // "%(*)s"
const int kPercentInterpolation = -2; // "%%" const int kPercentInterpolation = -2; // "%%"
const int kInvalidInterpolation = -3; // "%" followed by invalid text const int kInvalidInterpolation = -3; // "%" followed by invalid text
// Records the location and content of an interpolation. // Records the location and content of an interpolation.
struct Interpolation { struct Interpolation {
Interpolation(const char* start, const char* end, int param) Interpolation(const char* start, const char* end, int param)
skipping to change at line 2511 skipping to change at line 2627
prefix)); prefix));
} }
// Matches a string that ends with 'suffix' (case-sensitive). // Matches a string that ends with 'suffix' (case-sensitive).
inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> > inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> >
EndsWith(const internal::string& suffix) { EndsWith(const internal::string& suffix) {
return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string> ( return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string> (
suffix)); suffix));
} }
#ifdef GMOCK_HAS_REGEX
// Matches a string that fully matches regular expression 'regex'. // Matches a string that fully matches regular expression 'regex'.
// The matcher takes ownership of 'regex'. // The matcher takes ownership of 'regex'.
inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
const internal::RE* regex) { const internal::RE* regex) {
return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true)) ; return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true)) ;
} }
inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex( inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
const internal::string& regex) { const internal::string& regex) {
return MatchesRegex(new internal::RE(regex)); return MatchesRegex(new internal::RE(regex));
} }
skipping to change at line 2535 skipping to change at line 2649
// The matcher takes ownership of 'regex'. // The matcher takes ownership of 'regex'.
inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
const internal::RE* regex) { const internal::RE* regex) {
return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false) ); return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false) );
} }
inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex( inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
const internal::string& regex) { const internal::string& regex) {
return ContainsRegex(new internal::RE(regex)); return ContainsRegex(new internal::RE(regex));
} }
#endif // GMOCK_HAS_REGEX
#if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING #if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
// Wide string matchers. // Wide string matchers.
// Matches a string equal to str. // Matches a string equal to str.
inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> > inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
StrEq(const internal::wstring& str) { StrEq(const internal::wstring& str) {
return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstr ing>( return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstr ing>(
str, true, true)); str, true, true));
} }
skipping to change at line 2713 skipping to change at line 2825
inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> > inline PolymorphicMatcher<internal::TrulyMatcher<Predicate> >
Truly(Predicate pred) { Truly(Predicate pred) {
return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred)); return MakePolymorphicMatcher(internal::TrulyMatcher<Predicate>(pred));
} }
// Returns a matcher that matches an equal container. // Returns a matcher that matches an equal container.
// This matcher behaves like Eq(), but in the event of mismatch lists the // This matcher behaves like Eq(), but in the event of mismatch lists the
// values that are included in one container but not the other. (Duplicate // values that are included in one container but not the other. (Duplicate
// values and order differences are not explained.) // values and order differences are not explained.)
template <typename Container> template <typename Container>
inline PolymorphicMatcher<internal::ContainerEqMatcher< inline PolymorphicMatcher<internal::ContainerEqMatcher< // NOLINT
GMOCK_REMOVE_CONST_(Container)> > GMOCK_REMOVE_CONST_(Container)> >
ContainerEq(const Container& rhs) { ContainerEq(const Container& rhs) {
// This following line is for working around a bug in MSVC 8.0, // This following line is for working around a bug in MSVC 8.0,
// which causes Container to be a const type sometimes. // which causes Container to be a const type sometimes.
typedef GMOCK_REMOVE_CONST_(Container) RawContainer; typedef GMOCK_REMOVE_CONST_(Container) RawContainer;
return MakePolymorphicMatcher(internal::ContainerEqMatcher<RawContainer>( return MakePolymorphicMatcher(
rhs)); internal::ContainerEqMatcher<RawContainer>(rhs));
} }
// Matches an STL-style container or a native array that contains at // Matches an STL-style container or a native array that contains at
// least one element matching the given value or matcher. // least one element matching the given value or matcher.
// //
// Examples: // Examples:
// ::std::set<int> page_ids; // ::std::set<int> page_ids;
// page_ids.insert(3); // page_ids.insert(3);
// page_ids.insert(1); // page_ids.insert(1);
// EXPECT_THAT(page_ids, Contains(1)); // EXPECT_THAT(page_ids, Contains(1));
skipping to change at line 2778 skipping to change at line 2891
inline internal::MatcherAsPredicate<M> Matches(M matcher) { inline internal::MatcherAsPredicate<M> Matches(M matcher) {
return internal::MatcherAsPredicate<M>(matcher); return internal::MatcherAsPredicate<M>(matcher);
} }
// Returns true iff the value matches the matcher. // Returns true iff the value matches the matcher.
template <typename T, typename M> template <typename T, typename M>
inline bool Value(const T& value, M matcher) { inline bool Value(const T& value, M matcher) {
return testing::Matches(matcher)(value); return testing::Matches(matcher)(value);
} }
// Matches the value against the given matcher and explains the match
// result to listener.
template <typename T, typename M>
inline bool ExplainMatchResult(
M matcher, const T& value, MatchResultListener* listener) {
return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener
);
}
// AllArgs(m) is a synonym of m. This is useful in // AllArgs(m) is a synonym of m. This is useful in
// //
// EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq())); // EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq()));
// //
// which is easier to read than // which is easier to read than
// //
// EXPECT_CALL(foo, Bar(_, _)).With(Eq()); // EXPECT_CALL(foo, Bar(_, _)).With(Eq());
template <typename InnerMatcher> template <typename InnerMatcher>
inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; } inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
 End of changes. 204 change blocks. 
517 lines changed or deleted 648 lines changed or added


 gmock-more-actions.h   gmock-more-actions.h 
skipping to change at line 61 skipping to change at line 61
public: public:
// The c'tor makes a copy of function_impl (either a function // The c'tor makes a copy of function_impl (either a function
// pointer or a functor). // pointer or a functor).
explicit InvokeAction(FunctionImpl function_impl) explicit InvokeAction(FunctionImpl function_impl)
: function_impl_(function_impl) {} : function_impl_(function_impl) {}
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
Result Perform(const ArgumentTuple& args) { Result Perform(const ArgumentTuple& args) {
return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args ); return InvokeHelper<Result, ArgumentTuple>::Invoke(function_impl_, args );
} }
private: private:
FunctionImpl function_impl_; FunctionImpl function_impl_;
GTEST_DISALLOW_ASSIGN_(InvokeAction);
}; };
// Implements the Invoke(object_ptr, &Class::Method) action. // Implements the Invoke(object_ptr, &Class::Method) action.
template <class Class, typename MethodPtr> template <class Class, typename MethodPtr>
class InvokeMethodAction { class InvokeMethodAction {
public: public:
InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr) InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr)
: obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
skipping to change at line 77 skipping to change at line 80
class InvokeMethodAction { class InvokeMethodAction {
public: public:
InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr) InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr)
: obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {}
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
Result Perform(const ArgumentTuple& args) const { Result Perform(const ArgumentTuple& args) const {
return InvokeHelper<Result, ArgumentTuple>::InvokeMethod( return InvokeHelper<Result, ArgumentTuple>::InvokeMethod(
obj_ptr_, method_ptr_, args); obj_ptr_, method_ptr_, args);
} }
private: private:
Class* const obj_ptr_; Class* const obj_ptr_;
const MethodPtr method_ptr_; const MethodPtr method_ptr_;
GTEST_DISALLOW_ASSIGN_(InvokeMethodAction);
}; };
} // namespace internal } // namespace internal
// Various overloads for Invoke(). // Various overloads for Invoke().
// Creates an action that invokes 'function_impl' with the mock // Creates an action that invokes 'function_impl' with the mock
// function's arguments. // function's arguments.
template <typename FunctionImpl> template <typename FunctionImpl>
PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke( PolymorphicAction<internal::InvokeAction<FunctionImpl> > Invoke(
skipping to change at line 125 skipping to change at line 131
// (0-based) argument of the mock function to an_action and performs // (0-based) argument of the mock function to an_action and performs
// it. It adapts an action accepting one argument to one that accepts // it. It adapts an action accepting one argument to one that accepts
// multiple arguments. For convenience, we also provide // multiple arguments. For convenience, we also provide
// WithArgs<k>(an_action) (defined below) as a synonym. // WithArgs<k>(an_action) (defined below) as a synonym.
template <int k, typename InnerAction> template <int k, typename InnerAction>
inline internal::WithArgsAction<InnerAction, k> inline internal::WithArgsAction<InnerAction, k>
WithArg(const InnerAction& action) { WithArg(const InnerAction& action) {
return internal::WithArgsAction<InnerAction, k>(action); return internal::WithArgsAction<InnerAction, k>(action);
} }
// The ACTION*() macros trigger warning C4100 (unreferenced formal
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
// the macro definition, as the warnings are generated when the macro
// is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4100)
#endif
// Action ReturnArg<k>() returns the k-th argument of the mock function. // Action ReturnArg<k>() returns the k-th argument of the mock function.
ACTION_TEMPLATE(ReturnArg, ACTION_TEMPLATE(ReturnArg,
HAS_1_TEMPLATE_PARAMS(int, k), HAS_1_TEMPLATE_PARAMS(int, k),
AND_0_VALUE_PARAMS()) { AND_0_VALUE_PARAMS()) {
return std::tr1::get<k>(args); return std::tr1::get<k>(args);
} }
// Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the // Action SaveArg<k>(pointer) saves the k-th (0-based) argument of the
// mock function to *pointer. // mock function to *pointer.
ACTION_TEMPLATE(SaveArg, ACTION_TEMPLATE(SaveArg,
skipping to change at line 188 skipping to change at line 204
AND_0_VALUE_PARAMS()) { AND_0_VALUE_PARAMS()) {
delete ::std::tr1::get<k>(args); delete ::std::tr1::get<k>(args);
} }
// Action Throw(exception) can be used in a mock function of any type // Action Throw(exception) can be used in a mock function of any type
// to throw the given exception. Any copyable value can be thrown. // to throw the given exception. Any copyable value can be thrown.
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
ACTION_P(Throw, exception) { throw exception; } ACTION_P(Throw, exception) { throw exception; }
#endif // GTEST_HAS_EXCEPTIONS #endif // GTEST_HAS_EXCEPTIONS
#ifdef _MSC_VER
#pragma warning(pop)
#endif
} // namespace testing } // namespace testing
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
 End of changes. 6 change blocks. 
0 lines changed or deleted 20 lines changed or added


 gmock-port.h   gmock-port.h 
skipping to change at line 55 skipping to change at line 55
#include <gtest/internal/gtest-linked_ptr.h> #include <gtest/internal/gtest-linked_ptr.h>
#include <gtest/internal/gtest-port.h> #include <gtest/internal/gtest-port.h>
// To avoid conditional compilation everywhere, we make it // To avoid conditional compilation everywhere, we make it
// gmock-port.h's responsibility to #include the header implementing // gmock-port.h's responsibility to #include the header implementing
// tr1/tuple. gmock-port.h does this via gtest-port.h, which is // tr1/tuple. gmock-port.h does this via gtest-port.h, which is
// guaranteed to pull in the tuple header. // guaranteed to pull in the tuple header.
#if GTEST_OS_LINUX #if GTEST_OS_LINUX
// On some platforms, <regex.h> needs someone to define size_t, and
// won't compile otherwise. We can #include it here as we already
// included <stdlib.h>, which is guaranteed to define size_t through
// <stddef.h>.
#include <regex.h> // NOLINT
// Defines this iff Google Mock uses the enhanced POSIX regular
// expression syntax. This is public as it affects how a user uses
// regular expression matchers.
#define GMOCK_USES_POSIX_RE 1
#endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
#if defined(GMOCK_USES_PCRE) || defined(GMOCK_USES_POSIX_RE)
// Defines this iff regular expression matchers are supported. This
// is public as it tells a user whether he can use regular expression
// matchers.
#define GMOCK_HAS_REGEX 1
#endif // defined(GMOCK_USES_PCRE) || defined(GMOCK_USES_POSIX_RE)
namespace testing { namespace testing {
namespace internal { namespace internal {
// For MS Visual C++, check the compiler version. At least VS 2003 is // For MS Visual C++, check the compiler version. At least VS 2003 is
// required to compile Google Mock. // required to compile Google Mock.
#if defined(_MSC_VER) && _MSC_VER < 1310 #if defined(_MSC_VER) && _MSC_VER < 1310
#error "At least Visual C++ 2003 (7.1) is required to compile Google Mock." #error "At least Visual C++ 2003 (7.1) is required to compile Google Mock."
#endif #endif
// Use implicit_cast as a safe version of static_cast or const_cast // Use implicit_cast as a safe version of static_cast for upcasting in
// for upcasting in the type hierarchy (i.e. casting a pointer to Foo // the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
// to a pointer to SuperclassOfFoo or casting a pointer to Foo to // const Foo*). When you use implicit_cast, the compiler checks that
// a const pointer to Foo). // the cast is safe. Such explicit implicit_casts are necessary in
// When you use implicit_cast, the compiler checks that the cast is safe. // surprisingly many situations where C++ demands an exact type match
// Such explicit implicit_casts are necessary in surprisingly many // instead of an argument type convertable to a target type.
// situations where C++ demands an exact type match instead of an
// argument type convertable to a target type.
// //
// The From type can be inferred, so the preferred syntax for using // The syntax for using implicit_cast is the same as for static_cast:
// implicit_cast is the same as for static_cast etc.:
// //
// implicit_cast<ToType>(expr) // implicit_cast<ToType>(expr)
// //
// implicit_cast would have been part of the C++ standard library, // implicit_cast would have been part of the C++ standard library,
// but the proposal was submitted too late. It will probably make // but the proposal was submitted too late. It will probably make
// its way into the language in the future. // its way into the language in the future.
template<typename To, typename From> template<typename To>
inline To implicit_cast(From const &f) { inline To implicit_cast(To x) { return x; }
return f;
}
// When you upcast (that is, cast a pointer from type Foo to type // When you upcast (that is, cast a pointer from type Foo to type
// SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts // SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts
// always succeed. When you downcast (that is, cast a pointer from // always succeed. When you downcast (that is, cast a pointer from
// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because // type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
// how do you know the pointer is really of type SubclassOfFoo? It // how do you know the pointer is really of type SubclassOfFoo? It
// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, // could be a bare Foo, or of type DifferentSubclassOfFoo. Thus,
// when you downcast, you should use this macro. In debug mode, we // when you downcast, you should use this macro. In debug mode, we
// use dynamic_cast<> to double-check the downcast is legal (we die // use dynamic_cast<> to double-check the downcast is legal (we die
// if it's not). In normal mode, we do the efficient static_cast<> // if it's not). In normal mode, we do the efficient static_cast<>
skipping to change at line 130 skipping to change at line 107
// if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo); // if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
// if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo); // if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
// You should design the code some other way not to need this. // You should design the code some other way not to need this.
template<typename To, typename From> // use like this: down_cast<T*>(foo); template<typename To, typename From> // use like this: down_cast<T*>(foo);
inline To down_cast(From* f) { // so we only accept pointers inline To down_cast(From* f) { // so we only accept pointers
// Ensures that To is a sub-type of From *. This test is here only // Ensures that To is a sub-type of From *. This test is here only
// for compile-time type checking, and has no overhead in an // for compile-time type checking, and has no overhead in an
// optimized build at run-time, as it will be optimized away // optimized build at run-time, as it will be optimized away
// completely. // completely.
if (false) { if (false) {
implicit_cast<From*, To>(0); const To to = NULL;
::testing::internal::implicit_cast<From*>(to);
} }
#if GTEST_HAS_RTTI #if GTEST_HAS_RTTI
assert(f == NULL || dynamic_cast<To>(f) != NULL); // RTTI: debug mode on ly! assert(f == NULL || dynamic_cast<To>(f) != NULL); // RTTI: debug mode on ly!
#endif #endif
return static_cast<To>(f); return static_cast<To>(f);
} }
// The GMOCK_COMPILE_ASSERT_ macro can be used to verify that a compile tim e // The GMOCK_COMPILE_ASSERT_ macro can be used to verify that a compile tim e
// expression is true. For example, you could use it to verify the // expression is true. For example, you could use it to verify the
skipping to change at line 205 skipping to change at line 183
// //
// - The array size is (bool(expr) ? 1 : -1), instead of simply // - The array size is (bool(expr) ? 1 : -1), instead of simply
// //
// ((expr) ? 1 : -1). // ((expr) ? 1 : -1).
// //
// This is to avoid running into a bug in MS VC 7.1, which // This is to avoid running into a bug in MS VC 7.1, which
// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. // causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
#if GTEST_HAS_GLOBAL_STRING #if GTEST_HAS_GLOBAL_STRING
typedef ::string string; typedef ::string string;
#elif GTEST_HAS_STD_STRING
typedef ::std::string string;
#else #else
#error "Google Mock requires ::std::string to compile." typedef ::std::string string;
#endif // GTEST_HAS_GLOBAL_STRING #endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_GLOBAL_WSTRING #if GTEST_HAS_GLOBAL_WSTRING
typedef ::wstring wstring; typedef ::wstring wstring;
#elif GTEST_HAS_STD_WSTRING #elif GTEST_HAS_STD_WSTRING
typedef ::std::wstring wstring; typedef ::std::wstring wstring;
#endif // GTEST_HAS_GLOBAL_WSTRING #endif // GTEST_HAS_GLOBAL_WSTRING
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
 End of changes. 8 change blocks. 
36 lines changed or deleted 12 lines changed or added


 gmock-printers.h   gmock-printers.h 
skipping to change at line 60 skipping to change at line 60
// the value if it is a protocol buffer, or print the raw bytes in the // the value if it is a protocol buffer, or print the raw bytes in the
// value otherwise. // value otherwise.
// //
// To aid debugging: when T is a reference type, the address of the // To aid debugging: when T is a reference type, the address of the
// value is also printed; when T is a (const) char pointer, both the // value is also printed; when T is a (const) char pointer, both the
// pointer value and the NUL-terminated string it points to are // pointer value and the NUL-terminated string it points to are
// printed. // printed.
// //
// We also provide some convenient wrappers: // We also provide some convenient wrappers:
// //
// // Prints a value as the given type to a string. // // Prints a value to a string. For a (const or not) char
// string ::testing::internal::UniversalPrinter<T>::PrintToString(value); // // pointer, the NUL-terminated string (but not the pointer) is
// // printed.
// std::string ::testing::PrintToString(const T& value);
// //
// // Prints a value tersely: for a reference type, the referenced // // Prints a value tersely: for a reference type, the referenced
// // value (but not the address) is printed; for a (const) char // // value (but not the address) is printed; for a (const or not) char
// // pointer, the NUL-terminated string (but not the pointer) is // // pointer, the NUL-terminated string (but not the pointer) is
// // printed. // // printed.
// void ::testing::internal::UniversalTersePrint(const T& value, ostream* ); // void ::testing::internal::UniversalTersePrint(const T& value, ostream* );
// //
// // Prints value using the type inferred by the compiler. The differen ce // // Prints value using the type inferred by the compiler. The differen ce
// // from UniversalTersePrint() is that this function prints both the // // from UniversalTersePrint() is that this function prints both the
// // pointer and the NUL-terminated string for a (const) char pointer. // // pointer and the NUL-terminated string for a (const or not) char poi nter.
// void ::testing::internal::UniversalPrint(const T& value, ostream*); // void ::testing::internal::UniversalPrint(const T& value, ostream*);
// //
// // Prints the fields of a tuple tersely to a string vector, one // // Prints the fields of a tuple tersely to a string vector, one
// // element for each field. // // element for each field.
// std::vector<string> UniversalTersePrintTupleFieldsToStrings( // std::vector<string> UniversalTersePrintTupleFieldsToStrings(
// const Tuple& value); // const Tuple& value);
// //
// Known limitation: // Known limitation:
// //
// The print primitives print the elements of an STL-style container // The print primitives print the elements of an STL-style container
skipping to change at line 412 skipping to change at line 414
} }
// Overloads for ::string and ::std::string. // Overloads for ::string and ::std::string.
#if GTEST_HAS_GLOBAL_STRING #if GTEST_HAS_GLOBAL_STRING
void PrintStringTo(const ::string&s, ::std::ostream* os); void PrintStringTo(const ::string&s, ::std::ostream* os);
inline void PrintTo(const ::string& s, ::std::ostream* os) { inline void PrintTo(const ::string& s, ::std::ostream* os) {
PrintStringTo(s, os); PrintStringTo(s, os);
} }
#endif // GTEST_HAS_GLOBAL_STRING #endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_STD_STRING
void PrintStringTo(const ::std::string&s, ::std::ostream* os); void PrintStringTo(const ::std::string&s, ::std::ostream* os);
inline void PrintTo(const ::std::string& s, ::std::ostream* os) { inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
PrintStringTo(s, os); PrintStringTo(s, os);
} }
#endif // GTEST_HAS_STD_STRING
// Overloads for ::wstring and ::std::wstring. // Overloads for ::wstring and ::std::wstring.
#if GTEST_HAS_GLOBAL_WSTRING #if GTEST_HAS_GLOBAL_WSTRING
void PrintWideStringTo(const ::wstring&s, ::std::ostream* os); void PrintWideStringTo(const ::wstring&s, ::std::ostream* os);
inline void PrintTo(const ::wstring& s, ::std::ostream* os) { inline void PrintTo(const ::wstring& s, ::std::ostream* os) {
PrintWideStringTo(s, os); PrintWideStringTo(s, os);
} }
#endif // GTEST_HAS_GLOBAL_WSTRING #endif // GTEST_HAS_GLOBAL_WSTRING
#if GTEST_HAS_STD_WSTRING #if GTEST_HAS_STD_WSTRING
void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os); void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os);
inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) { inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
PrintWideStringTo(s, os); PrintWideStringTo(s, os);
} }
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
// Overload for ::std::tr1::tuple. Needed for printing function // Overload for ::std::tr1::tuple. Needed for printing function
// arguments, which are packed as tuples. // arguments, which are packed as tuples.
typedef ::std::vector<string> Strings;
// This helper template allows PrintTo() for tuples and
// UniversalTersePrintTupleFieldsToStrings() to be defined by
// induction on the number of tuple fields. The idea is that
// TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
// fields in tuple t, and can be defined in terms of
// TuplePrefixPrinter<N - 1>.
// The inductive case.
template <size_t N>
struct TuplePrefixPrinter {
// Prints the first N fields of a tuple.
template <typename Tuple>
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
*os << ", ";
UniversalPrinter<typename ::std::tr1::tuple_element<N - 1, Tuple>::type
>
::Print(::std::tr1::get<N - 1>(t), os);
}
// Tersely prints the first N fields of a tuple to a string vector,
// one element for each field.
template <typename Tuple>
static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
::std::stringstream ss;
UniversalTersePrint(::std::tr1::get<N - 1>(t), &ss);
strings->push_back(ss.str());
}
};
// Base cases.
template <>
struct TuplePrefixPrinter<0> {
template <typename Tuple>
static void PrintPrefixTo(const Tuple&, ::std::ostream*) {}
template <typename Tuple>
static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}
};
template <>
template <typename Tuple>
void TuplePrefixPrinter<1>::PrintPrefixTo(const Tuple& t, ::std::ostream* o
s) {
UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>::
Print(::std::tr1::get<0>(t), os);
}
// Helper function for printing a tuple. T must be instantiated with // Helper function for printing a tuple. T must be instantiated with
// a tuple type. // a tuple type.
template <typename T> template <typename T>
void PrintTupleTo(const T& t, ::std::ostream* os) { void PrintTupleTo(const T& t, ::std::ostream* os);
*os << "(";
TuplePrefixPrinter< ::std::tr1::tuple_size<T>::value>::
PrintPrefixTo(t, os);
*os << ")";
}
// Overloaded PrintTo() for tuples of various arities. We support // Overloaded PrintTo() for tuples of various arities. We support
// tuples of up-to 10 fields. The following implementation works // tuples of up-to 10 fields. The following implementation works
// regardless of whether tr1::tuple is implemented using the // regardless of whether tr1::tuple is implemented using the
// non-standard variadic template feature or not. // non-standard variadic template feature or not.
inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) { inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) {
PrintTupleTo(t, os); PrintTupleTo(t, os);
} }
skipping to change at line 603 skipping to change at line 550
// the value. // the value.
// //
// Thanks to Koenig look-up, if T is a class and has its own // Thanks to Koenig look-up, if T is a class and has its own
// PrintTo() function defined in its namespace, that function will // PrintTo() function defined in its namespace, that function will
// be visible here. Since it is more specific than the generic ones // be visible here. Since it is more specific than the generic ones
// in ::testing::internal, it will be picked by the compiler in the // in ::testing::internal, it will be picked by the compiler in the
// following statement - exactly what we want. // following statement - exactly what we want.
PrintTo(value, os); PrintTo(value, os);
} }
// A convenient wrapper for Print() that returns the print-out as a
// string.
static string PrintToString(const T& value) {
::std::stringstream ss;
Print(value, &ss);
return ss.str();
}
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) // Restores the warning state. #pragma warning(pop) // Restores the warning state.
#endif // _MSC_VER #endif // _MSC_VER
}; };
// UniversalPrintArray(begin, len, os) prints an array of 'len' // UniversalPrintArray(begin, len, os) prints an array of 'len'
// elements, starting at address 'begin'. // elements, starting at address 'begin'.
template <typename T> template <typename T>
void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) { void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {
if (len == 0) { if (len == 0) {
skipping to change at line 643 skipping to change at line 582
PrintRawArrayTo(begin, kChunkSize, os); PrintRawArrayTo(begin, kChunkSize, os);
*os << ", ..., "; *os << ", ..., ";
PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os); PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os);
} }
*os << " }"; *os << " }";
} }
} }
// This overload prints a (const) char array compactly. // This overload prints a (const) char array compactly.
void UniversalPrintArray(const char* begin, size_t len, ::std::ostream* os) ; void UniversalPrintArray(const char* begin, size_t len, ::std::ostream* os) ;
// Prints an array of 'len' elements, starting at address 'begin', to a str
ing.
template <typename T>
string UniversalPrintArrayToString(const T* begin, size_t len) {
::std::stringstream ss;
UniversalPrintArray(begin, len, &ss);
return ss.str();
}
// Implements printing an array type T[N]. // Implements printing an array type T[N].
template <typename T, size_t N> template <typename T, size_t N>
class UniversalPrinter<T[N]> { class UniversalPrinter<T[N]> {
public: public:
// Prints the given array, omitting some elements when there are too // Prints the given array, omitting some elements when there are too
// many. // many.
static void Print(const T (&a)[N], ::std::ostream* os) { static void Print(const T (&a)[N], ::std::ostream* os) {
UniversalPrintArray(a, N, os); UniversalPrintArray(a, N, os);
} }
// A convenient wrapper for Print() that returns the print-out as a
// string.
static string PrintToString(const T (&a)[N]) {
return UniversalPrintArrayToString(a, N);
}
}; };
// Implements printing a reference type T&. // Implements printing a reference type T&.
template <typename T> template <typename T>
class UniversalPrinter<T&> { class UniversalPrinter<T&> {
public: public:
// MSVC warns about adding const to a function type, so we want to // MSVC warns about adding const to a function type, so we want to
// disable the warning. // disable the warning.
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) // Saves the current warning state. #pragma warning(push) // Saves the current warning state.
skipping to change at line 688 skipping to change at line 613
static void Print(const T& value, ::std::ostream* os) { static void Print(const T& value, ::std::ostream* os) {
// Prints the address of the value. We use reinterpret_cast here // Prints the address of the value. We use reinterpret_cast here
// as static_cast doesn't compile when T is a function type. // as static_cast doesn't compile when T is a function type.
*os << "@" << reinterpret_cast<const void*>(&value) << " "; *os << "@" << reinterpret_cast<const void*>(&value) << " ";
// Then prints the value itself. // Then prints the value itself.
UniversalPrinter<T>::Print(value, os); UniversalPrinter<T>::Print(value, os);
} }
// A convenient wrapper for Print() that returns the print-out as a
// string.
static string PrintToString(const T& value) {
::std::stringstream ss;
Print(value, &ss);
return ss.str();
}
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) // Restores the warning state. #pragma warning(pop) // Restores the warning state.
#endif // _MSC_VER #endif // _MSC_VER
}; };
// Prints a value tersely: for a reference type, the referenced value // Prints a value tersely: for a reference type, the referenced value
// (but not the address) is printed; for a (const) char pointer, the // (but not the address) is printed; for a (const) char pointer, the
// NUL-terminated string (but not the pointer) is printed. // NUL-terminated string (but not the pointer) is printed.
template <typename T> template <typename T>
void UniversalTersePrint(const T& value, ::std::ostream* os) { void UniversalTersePrint(const T& value, ::std::ostream* os) {
skipping to change at line 728 skipping to change at line 645
// Prints a value using the type inferred by the compiler. The // Prints a value using the type inferred by the compiler. The
// difference between this and UniversalTersePrint() is that for a // difference between this and UniversalTersePrint() is that for a
// (const) char pointer, this prints both the pointer and the // (const) char pointer, this prints both the pointer and the
// NUL-terminated string. // NUL-terminated string.
template <typename T> template <typename T>
void UniversalPrint(const T& value, ::std::ostream* os) { void UniversalPrint(const T& value, ::std::ostream* os) {
UniversalPrinter<T>::Print(value, os); UniversalPrinter<T>::Print(value, os);
} }
typedef ::std::vector<string> Strings;
// This helper template allows PrintTo() for tuples and
// UniversalTersePrintTupleFieldsToStrings() to be defined by
// induction on the number of tuple fields. The idea is that
// TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
// fields in tuple t, and can be defined in terms of
// TuplePrefixPrinter<N - 1>.
// The inductive case.
template <size_t N>
struct TuplePrefixPrinter {
// Prints the first N fields of a tuple.
template <typename Tuple>
static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
*os << ", ";
UniversalPrinter<typename ::std::tr1::tuple_element<N - 1, Tuple>::type
>
::Print(::std::tr1::get<N - 1>(t), os);
}
// Tersely prints the first N fields of a tuple to a string vector,
// one element for each field.
template <typename Tuple>
static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
::std::stringstream ss;
UniversalTersePrint(::std::tr1::get<N - 1>(t), &ss);
strings->push_back(ss.str());
}
};
// Base cases.
template <>
struct TuplePrefixPrinter<0> {
template <typename Tuple>
static void PrintPrefixTo(const Tuple&, ::std::ostream*) {}
template <typename Tuple>
static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}
};
template <>
template <typename Tuple>
void TuplePrefixPrinter<1>::PrintPrefixTo(const Tuple& t, ::std::ostream* o
s) {
UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>::
Print(::std::tr1::get<0>(t), os);
}
// Helper function for printing a tuple. T must be instantiated with
// a tuple type.
template <typename T>
void PrintTupleTo(const T& t, ::std::ostream* os) {
*os << "(";
TuplePrefixPrinter< ::std::tr1::tuple_size<T>::value>::
PrintPrefixTo(t, os);
*os << ")";
}
// Prints the fields of a tuple tersely to a string vector, one // Prints the fields of a tuple tersely to a string vector, one
// element for each field. See the comment before // element for each field. See the comment before
// UniversalTersePrint() for how we define "tersely". // UniversalTersePrint() for how we define "tersely".
template <typename Tuple> template <typename Tuple>
Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) { Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
Strings result; Strings result;
TuplePrefixPrinter< ::std::tr1::tuple_size<Tuple>::value>:: TuplePrefixPrinter< ::std::tr1::tuple_size<Tuple>::value>::
TersePrintPrefixToStrings(value, &result); TersePrintPrefixToStrings(value, &result);
return result; return result;
} }
} // namespace internal } // namespace internal
template <typename T>
::std::string PrintToString(const T& value) {
::std::stringstream ss;
internal::UniversalTersePrint(value, &ss);
return ss.str();
}
} // namespace testing } // namespace testing
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_PRINTERS_H_ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_PRINTERS_H_
 End of changes. 13 change blocks. 
93 lines changed or deleted 75 lines changed or added


 gmock-spec-builders.h   gmock-spec-builders.h 
skipping to change at line 115 skipping to change at line 115
// mockers, and all expectations. // mockers, and all expectations.
// //
// The reason we don't use more fine-grained protection is: when a // The reason we don't use more fine-grained protection is: when a
// mock function Foo() is called, it needs to consult its expectations // mock function Foo() is called, it needs to consult its expectations
// to see which one should be picked. If another thread is allowed to // to see which one should be picked. If another thread is allowed to
// call a mock function (either Foo() or a different one) at the same // call a mock function (either Foo() or a different one) at the same
// time, it could affect the "retired" attributes of Foo()'s // time, it could affect the "retired" attributes of Foo()'s
// expectations when InSequence() is used, and thus affect which // expectations when InSequence() is used, and thus affect which
// expectation gets picked. Therefore, we sequence all mock function // expectation gets picked. Therefore, we sequence all mock function
// calls to ensure the integrity of the mock objects' states. // calls to ensure the integrity of the mock objects' states.
extern Mutex g_gmock_mutex; GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
// Abstract base class of FunctionMockerBase. This is the // Abstract base class of FunctionMockerBase. This is the
// type-agnostic part of the function mocker interface. Its pure // type-agnostic part of the function mocker interface. Its pure
// virtual methods are implemented by FunctionMockerBase. // virtual methods are implemented by FunctionMockerBase.
class UntypedFunctionMockerBase { class UntypedFunctionMockerBase {
public: public:
virtual ~UntypedFunctionMockerBase() {} virtual ~UntypedFunctionMockerBase() {}
// Verifies that all expectations on this mock function have been // Verifies that all expectations on this mock function have been
// satisfied. Reports one or more Google Test non-fatal failures // satisfied. Reports one or more Google Test non-fatal failures
skipping to change at line 145 skipping to change at line 145
// This template class implements a default action spec (i.e. an // This template class implements a default action spec (i.e. an
// ON_CALL() statement). // ON_CALL() statement).
template <typename F> template <typename F>
class DefaultActionSpec { class DefaultActionSpec {
public: public:
typedef typename Function<F>::ArgumentTuple ArgumentTuple; typedef typename Function<F>::ArgumentTuple ArgumentTuple;
typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
// Constructs a DefaultActionSpec object from the information inside // Constructs a DefaultActionSpec object from the information inside
// the parenthesis of an ON_CALL() statement. // the parenthesis of an ON_CALL() statement.
DefaultActionSpec(const char* file, int line, DefaultActionSpec(const char* a_file, int a_line,
const ArgumentMatcherTuple& matchers) const ArgumentMatcherTuple& matchers)
: file_(file), : file_(a_file),
line_(line), line_(a_line),
matchers_(matchers), matchers_(matchers),
// By default, extra_matcher_ should match anything. However, // By default, extra_matcher_ should match anything. However,
// we cannot initialize it with _ as that triggers a compiler // we cannot initialize it with _ as that triggers a compiler
// bug in Symbian's C++ compiler (cannot decide between two // bug in Symbian's C++ compiler (cannot decide between two
// overloaded constructors of Matcher<const ArgumentTuple&>). // overloaded constructors of Matcher<const ArgumentTuple&>).
extra_matcher_(A<const ArgumentTuple&>()), extra_matcher_(A<const ArgumentTuple&>()),
last_clause_(kNone) { last_clause_(kNone) {
} }
// Where in the source file was the default action spec defined? // Where in the source file was the default action spec defined?
skipping to change at line 563 skipping to change at line 564
// types (e.g. all pre-requisites of a particular expectation, all // types (e.g. all pre-requisites of a particular expectation, all
// expectations in a sequence). Therefore these expectation objects // expectations in a sequence). Therefore these expectation objects
// must share a common base class. // must share a common base class.
// //
// 2. We can avoid binary code bloat by moving methods not depending // 2. We can avoid binary code bloat by moving methods not depending
// on the template argument of Expectation to the base class. // on the template argument of Expectation to the base class.
// //
// This class is internal and mustn't be used by user code directly. // This class is internal and mustn't be used by user code directly.
class ExpectationBase { class ExpectationBase {
public: public:
ExpectationBase(const char* file, int line); // source_text is the EXPECT_CALL(...) source that created this Expectati
on.
ExpectationBase(const char* file, int line, const string& source_text);
virtual ~ExpectationBase(); virtual ~ExpectationBase();
// Where in the source file was the expectation spec defined? // Where in the source file was the expectation spec defined?
const char* file() const { return file_; } const char* file() const { return file_; }
int line() const { return line_; } int line() const { return line_; }
const char* source_text() const { return source_text_.c_str(); }
// Returns the cardinality specified in the expectation spec. // Returns the cardinality specified in the expectation spec.
const Cardinality& cardinality() const { return cardinality_; } const Cardinality& cardinality() const { return cardinality_; }
// Describes the source file location of this expectation. // Describes the source file location of this expectation.
void DescribeLocationTo(::std::ostream* os) const { void DescribeLocationTo(::std::ostream* os) const {
*os << file() << ":" << line() << ": "; *os << file() << ":" << line() << ": ";
} }
// Describes how many times a function call matching this // Describes how many times a function call matching this
// expectation has occurred. // expectation has occurred.
skipping to change at line 621 skipping to change at line 624
// Explicitly specifies the cardinality of this expectation. Used // Explicitly specifies the cardinality of this expectation. Used
// by the subclasses to implement the .Times() clause. // by the subclasses to implement the .Times() clause.
void SpecifyCardinality(const Cardinality& cardinality); void SpecifyCardinality(const Cardinality& cardinality);
// Returns true iff the user specified the cardinality explicitly // Returns true iff the user specified the cardinality explicitly
// using a .Times(). // using a .Times().
bool cardinality_specified() const { return cardinality_specified_; } bool cardinality_specified() const { return cardinality_specified_; }
// Sets the cardinality of this expectation spec. // Sets the cardinality of this expectation spec.
void set_cardinality(const Cardinality& cardinality) { void set_cardinality(const Cardinality& a_cardinality) {
cardinality_ = cardinality; cardinality_ = a_cardinality;
} }
// The following group of methods should only be called after the // The following group of methods should only be called after the
// EXPECT_CALL() statement, and only when g_gmock_mutex is held by // EXPECT_CALL() statement, and only when g_gmock_mutex is held by
// the current thread. // the current thread.
// Retires all pre-requisites of this expectation. // Retires all pre-requisites of this expectation.
// L >= g_gmock_mutex // L >= g_gmock_mutex
void RetireAllPreRequisites(); void RetireAllPreRequisites();
skipping to change at line 699 skipping to change at line 702
private: private:
friend class ::testing::Sequence; friend class ::testing::Sequence;
friend class ::testing::internal::ExpectationTester; friend class ::testing::internal::ExpectationTester;
template <typename Function> template <typename Function>
friend class TypedExpectation; friend class TypedExpectation;
// This group of fields are part of the spec and won't change after // This group of fields are part of the spec and won't change after
// an EXPECT_CALL() statement finishes. // an EXPECT_CALL() statement finishes.
const char* file_; // The file that contains the expectation. const char* file_; // The file that contains the expectation.
int line_; // The line number of the expectation. int line_; // The line number of the expectation.
const string source_text_; // The EXPECT_CALL(...) source text.
// True iff the cardinality is specified explicitly. // True iff the cardinality is specified explicitly.
bool cardinality_specified_; bool cardinality_specified_;
Cardinality cardinality_; // The cardinality of the expectatio n. Cardinality cardinality_; // The cardinality of the expectatio n.
// The immediate pre-requisites (i.e. expectations that must be // The immediate pre-requisites (i.e. expectations that must be
// satisfied before this expectation can be matched) of this // satisfied before this expectation can be matched) of this
// expectation. We use linked_ptr in the set because we want an // expectation. We use linked_ptr in the set because we want an
// Expectation object to be co-owned by its FunctionMocker and its // Expectation object to be co-owned by its FunctionMocker and its
// successors. This allows multiple mock objects to be deleted at // successors. This allows multiple mock objects to be deleted at
// different times. // different times.
ExpectationSet immediate_prerequisites_; ExpectationSet immediate_prerequisites_;
// This group of fields are the current state of the expectation, // This group of fields are the current state of the expectation,
// and can change as the mock function is called. // and can change as the mock function is called.
int call_count_; // How many times this expectation has been invoked. int call_count_; // How many times this expectation has been invoked.
bool retired_; // True iff this expectation has retired. bool retired_; // True iff this expectation has retired.
GTEST_DISALLOW_ASSIGN_(ExpectationBase);
}; // class ExpectationBase }; // class ExpectationBase
// Impements an expectation for the given function type. // Impements an expectation for the given function type.
template <typename F> template <typename F>
class TypedExpectation : public ExpectationBase { class TypedExpectation : public ExpectationBase {
public: public:
typedef typename Function<F>::ArgumentTuple ArgumentTuple; typedef typename Function<F>::ArgumentTuple ArgumentTuple;
typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
typedef typename Function<F>::Result Result; typedef typename Function<F>::Result Result;
TypedExpectation(FunctionMockerBase<F>* owner, const char* file, int line TypedExpectation(FunctionMockerBase<F>* owner,
, const char* a_file, int a_line, const string& a_source_t
ext,
const ArgumentMatcherTuple& m) const ArgumentMatcherTuple& m)
: ExpectationBase(file, line), : ExpectationBase(a_file, a_line, a_source_text),
owner_(owner), owner_(owner),
matchers_(m), matchers_(m),
extra_matcher_specified_(false),
// By default, extra_matcher_ should match anything. However, // By default, extra_matcher_ should match anything. However,
// we cannot initialize it with _ as that triggers a compiler // we cannot initialize it with _ as that triggers a compiler
// bug in Symbian's C++ compiler (cannot decide between two // bug in Symbian's C++ compiler (cannot decide between two
// overloaded constructors of Matcher<const ArgumentTuple&>). // overloaded constructors of Matcher<const ArgumentTuple&>).
extra_matcher_(A<const ArgumentTuple&>()), extra_matcher_(A<const ArgumentTuple&>()),
repeated_action_specified_(false), repeated_action_specified_(false),
repeated_action_(DoDefault()), repeated_action_(DoDefault()),
retires_on_saturation_(false), retires_on_saturation_(false),
last_clause_(kNone), last_clause_(kNone),
action_count_checked_(false) {} action_count_checked_(false) {}
skipping to change at line 762 skipping to change at line 770
".With() cannot appear " ".With() cannot appear "
"more than once in an EXPECT_CALL()."); "more than once in an EXPECT_CALL().");
} else { } else {
ExpectSpecProperty(last_clause_ < kWith, ExpectSpecProperty(last_clause_ < kWith,
".With() must be the first " ".With() must be the first "
"clause in an EXPECT_CALL()."); "clause in an EXPECT_CALL().");
} }
last_clause_ = kWith; last_clause_ = kWith;
extra_matcher_ = m; extra_matcher_ = m;
extra_matcher_specified_ = true;
return *this; return *this;
} }
// Implements the .Times() clause. // Implements the .Times() clause.
TypedExpectation& Times(const Cardinality& cardinality) { TypedExpectation& Times(const Cardinality& a_cardinality) {
if (last_clause_ ==kTimes) { if (last_clause_ ==kTimes) {
ExpectSpecProperty(false, ExpectSpecProperty(false,
".Times() cannot appear " ".Times() cannot appear "
"more than once in an EXPECT_CALL()."); "more than once in an EXPECT_CALL().");
} else { } else {
ExpectSpecProperty(last_clause_ < kTimes, ExpectSpecProperty(last_clause_ < kTimes,
".Times() cannot appear after " ".Times() cannot appear after "
".InSequence(), .WillOnce(), .WillRepeatedly(), " ".InSequence(), .WillOnce(), .WillRepeatedly(), "
"or .RetiresOnSaturation()."); "or .RetiresOnSaturation().");
} }
last_clause_ = kTimes; last_clause_ = kTimes;
ExpectationBase::SpecifyCardinality(cardinality); ExpectationBase::SpecifyCardinality(a_cardinality);
return *this; return *this;
} }
// Implements the .Times() clause. // Implements the .Times() clause.
TypedExpectation& Times(int n) { TypedExpectation& Times(int n) {
return Times(Exactly(n)); return Times(Exactly(n));
} }
// Implements the .InSequence() clause. // Implements the .InSequence() clause.
TypedExpectation& InSequence(const Sequence& s) { TypedExpectation& InSequence(const Sequence& s) {
skipping to change at line 940 skipping to change at line 949
Cardinality::DescribeActualCallCountTo(call_count(), os); Cardinality::DescribeActualCallCountTo(call_count(), os);
// Describes the state of the expectation (e.g. is it satisfied? // Describes the state of the expectation (e.g. is it satisfied?
// is it active?). // is it active?).
*os << " - " << (IsOverSaturated() ? "over-saturated" : *os << " - " << (IsOverSaturated() ? "over-saturated" :
IsSaturated() ? "saturated" : IsSaturated() ? "saturated" :
IsSatisfied() ? "satisfied" : "unsatisfied") IsSatisfied() ? "satisfied" : "unsatisfied")
<< " and " << " and "
<< (is_retired() ? "retired" : "active"); << (is_retired() ? "retired" : "active");
} }
void MaybeDescribeExtraMatcherTo(::std::ostream* os) {
if (extra_matcher_specified_) {
*os << " Expected args: ";
extra_matcher_.DescribeTo(os);
*os << "\n";
}
}
private: private:
template <typename Function> template <typename Function>
friend class FunctionMockerBase; friend class FunctionMockerBase;
// Returns an Expectation object that references and co-owns this // Returns an Expectation object that references and co-owns this
// expectation. // expectation.
virtual Expectation GetHandle() { virtual Expectation GetHandle() {
return owner_->GetHandleOf(this); return owner_->GetHandleOf(this);
} }
skipping to change at line 977 skipping to change at line 995
// was defined (e.g. if this expectation has no WillRepeatedly() // was defined (e.g. if this expectation has no WillRepeatedly()
// or RetiresOnSaturation() clause), we check it when the // or RetiresOnSaturation() clause), we check it when the
// expectation is used for the first time. // expectation is used for the first time.
CheckActionCountIfNotDone(); CheckActionCountIfNotDone();
return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args) ; return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args) ;
} }
// Describes the result of matching the arguments against this // Describes the result of matching the arguments against this
// expectation to the given ostream. // expectation to the given ostream.
// L >= g_gmock_mutex // L >= g_gmock_mutex
void DescribeMatchResultTo(const ArgumentTuple& args, void ExplainMatchResultTo(const ArgumentTuple& args,
::std::ostream* os) const { ::std::ostream* os) const {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
if (is_retired()) { if (is_retired()) {
*os << " Expected: the expectation is active\n" *os << " Expected: the expectation is active\n"
<< " Actual: it is retired\n"; << " Actual: it is retired\n";
} else if (!Matches(args)) { } else if (!Matches(args)) {
if (!TupleMatches(matchers_, args)) { if (!TupleMatches(matchers_, args)) {
DescribeMatchFailureTupleTo(matchers_, args, os); ExplainMatchFailureTupleTo(matchers_, args, os);
} }
if (!extra_matcher_.Matches(args)) { StringMatchResultListener listener;
if (!extra_matcher_.MatchAndExplain(args, &listener)) {
*os << " Expected args: "; *os << " Expected args: ";
extra_matcher_.DescribeTo(os); extra_matcher_.DescribeTo(os);
*os << "\n Actual: don't match"; *os << "\n Actual: don't match";
internal::ExplainMatchResultAsNeededTo<const ArgumentTuple&>( internal::PrintIfNotEmpty(listener.str(), os);
extra_matcher_, args, os);
*os << "\n"; *os << "\n";
} }
} else if (!AllPrerequisitesAreSatisfied()) { } else if (!AllPrerequisitesAreSatisfied()) {
*os << " Expected: all pre-requisites are satisfied\n" *os << " Expected: all pre-requisites are satisfied\n"
<< " Actual: the following immediate pre-requisites " << " Actual: the following immediate pre-requisites "
<< "are not satisfied:\n"; << "are not satisfied:\n";
ExpectationSet unsatisfied_prereqs; ExpectationSet unsatisfied_prereqs;
FindUnsatisfiedPrerequisites(&unsatisfied_prereqs); FindUnsatisfiedPrerequisites(&unsatisfied_prereqs);
int i = 0; int i = 0;
for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin(); for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin();
it != unsatisfied_prereqs.end(); ++it) { it != unsatisfied_prereqs.end(); ++it) {
it->expectation_base()->DescribeLocationTo(os); it->expectation_base()->DescribeLocationTo(os);
*os << "pre-requisite #" << i++ << "\n"; *os << "pre-requisite #" << i++ << "\n";
} }
*os << " (end of pre-requisites)\n"; *os << " (end of pre-requisites)\n";
} else { } else {
// This line is here just for completeness' sake. It will never // This line is here just for completeness' sake. It will never
// be executed as currently the DescribeMatchResultTo() function // be executed as currently the ExplainMatchResultTo() function
// is called only when the mock function call does NOT match the // is called only when the mock function call does NOT match the
// expectation. // expectation.
*os << "The call matches the expectation.\n"; *os << "The call matches the expectation.\n";
} }
} }
// Returns the action that should be taken for the current invocation. // Returns the action that should be taken for the current invocation.
// L >= g_gmock_mutex // L >= g_gmock_mutex
const Action<F>& GetCurrentAction(const FunctionMockerBase<F>* mocker, const Action<F>& GetCurrentAction(const FunctionMockerBase<F>* mocker,
const ArgumentTuple& args) const { const ArgumentTuple& args) const {
skipping to change at line 1036 skipping to change at line 1054
"call_count() is <= 0 when GetCurrentAction() is " "call_count() is <= 0 when GetCurrentAction() is "
"called - this should never happen."); "called - this should never happen.");
const int action_count = static_cast<int>(actions().size()); const int action_count = static_cast<int>(actions().size());
if (action_count > 0 && !repeated_action_specified_ && if (action_count > 0 && !repeated_action_specified_ &&
count > action_count) { count > action_count) {
// If there is at least one WillOnce() and no WillRepeatedly(), // If there is at least one WillOnce() and no WillRepeatedly(),
// we warn the user when the WillOnce() clauses ran out. // we warn the user when the WillOnce() clauses ran out.
::std::stringstream ss; ::std::stringstream ss;
DescribeLocationTo(&ss); DescribeLocationTo(&ss);
ss << "Actions ran out.\n" ss << "Actions ran out in " << source_text() << "...\n"
<< "Called " << count << " times, but only " << "Called " << count << " times, but only "
<< action_count << " WillOnce()" << action_count << " WillOnce()"
<< (action_count == 1 ? " is" : "s are") << " specified - "; << (action_count == 1 ? " is" : "s are") << " specified - ";
mocker->DescribeDefaultActionTo(args, &ss); mocker->DescribeDefaultActionTo(args, &ss);
Log(WARNING, ss.str(), 1); Log(WARNING, ss.str(), 1);
} }
return count <= action_count ? actions()[count - 1] : repeated_action() ; return count <= action_count ? actions()[count - 1] : repeated_action() ;
} }
skipping to change at line 1080 skipping to change at line 1098
} }
IncrementCallCount(); IncrementCallCount();
RetireAllPreRequisites(); RetireAllPreRequisites();
if (retires_on_saturation() && IsSaturated()) { if (retires_on_saturation() && IsSaturated()) {
Retire(); Retire();
} }
// Must be done after IncrementCount()! // Must be done after IncrementCount()!
*what << "Expected mock function call.\n"; *what << "Mock function call matches " << source_text() <<"...\n";
return GetCurrentAction(mocker, args); return GetCurrentAction(mocker, args);
} }
// Checks the action count (i.e. the number of WillOnce() and // Checks the action count (i.e. the number of WillOnce() and
// WillRepeatedly() clauses) against the cardinality if this hasn't // WillRepeatedly() clauses) against the cardinality if this hasn't
// been done before. Prints a warning if there are too many or too // been done before. Prints a warning if there are too many or too
// few actions. // few actions.
// L < mutex_ // L < mutex_
void CheckActionCountIfNotDone() const { void CheckActionCountIfNotDone() const {
bool should_check = false; bool should_check = false;
skipping to change at line 1125 skipping to change at line 1143
} else if (0 < action_count && action_count < lower_bound && } else if (0 < action_count && action_count < lower_bound &&
!repeated_action_specified_) { !repeated_action_specified_) {
too_many = false; too_many = false;
} else { } else {
return; return;
} }
::std::stringstream ss; ::std::stringstream ss;
DescribeLocationTo(&ss); DescribeLocationTo(&ss);
ss << "Too " << (too_many ? "many" : "few") ss << "Too " << (too_many ? "many" : "few")
<< " actions specified.\n" << " actions specified in " << source_text() << "...\n"
<< "Expected to be "; << "Expected to be ";
cardinality().DescribeTo(&ss); cardinality().DescribeTo(&ss);
ss << ", but has " << (too_many ? "" : "only ") ss << ", but has " << (too_many ? "" : "only ")
<< action_count << " WillOnce()" << action_count << " WillOnce()"
<< (action_count == 1 ? "" : "s"); << (action_count == 1 ? "" : "s");
if (repeated_action_specified_) { if (repeated_action_specified_) {
ss << " and a WillRepeatedly()"; ss << " and a WillRepeatedly()";
} }
ss << "."; ss << ".";
Log(WARNING, ss.str(), -1); // -1 means "don't print stack trace". Log(WARNING, ss.str(), -1); // -1 means "don't print stack trace".
} }
} }
// All the fields below won't change once the EXPECT_CALL() // All the fields below won't change once the EXPECT_CALL()
// statement finishes. // statement finishes.
FunctionMockerBase<F>* const owner_; FunctionMockerBase<F>* const owner_;
ArgumentMatcherTuple matchers_; ArgumentMatcherTuple matchers_;
bool extra_matcher_specified_;
Matcher<const ArgumentTuple&> extra_matcher_; Matcher<const ArgumentTuple&> extra_matcher_;
std::vector<Action<F> > actions_; std::vector<Action<F> > actions_;
bool repeated_action_specified_; // True if a WillRepeatedly() was speci fied. bool repeated_action_specified_; // True if a WillRepeatedly() was speci fied.
Action<F> repeated_action_; Action<F> repeated_action_;
bool retires_on_saturation_; bool retires_on_saturation_;
Clause last_clause_; Clause last_clause_;
mutable bool action_count_checked_; // Under mutex_. mutable bool action_count_checked_; // Under mutex_.
mutable Mutex mutex_; // Protects action_count_checked_. mutable Mutex mutex_; // Protects action_count_checked_.
GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation);
}; // class TypedExpectation }; // class TypedExpectation
// A MockSpec object is used by ON_CALL() or EXPECT_CALL() for // A MockSpec object is used by ON_CALL() or EXPECT_CALL() for
// specifying the default behavior of, or expectation on, a mock // specifying the default behavior of, or expectation on, a mock
// function. // function.
// Note: class MockSpec really belongs to the ::testing namespace. // Note: class MockSpec really belongs to the ::testing namespace.
// However if we define it in ::testing, MSVC will complain when // However if we define it in ::testing, MSVC will complain when
// classes in ::testing::internal declare it as a friend class // classes in ::testing::internal declare it as a friend class
// template. To workaround this compiler bug, we define MockSpec in // template. To workaround this compiler bug, we define MockSpec in
skipping to change at line 1188 skipping to change at line 1209
const char* file, int line, const char* obj, const char* call) { const char* file, int line, const char* obj, const char* call) {
LogWithLocation(internal::INFO, file, line, LogWithLocation(internal::INFO, file, line,
string("ON_CALL(") + obj + ", " + call + ") invoked"); string("ON_CALL(") + obj + ", " + call + ") invoked");
return function_mocker_->AddNewDefaultActionSpec(file, line, matchers_) ; return function_mocker_->AddNewDefaultActionSpec(file, line, matchers_) ;
} }
// Adds a new expectation spec to the function mocker and returns // Adds a new expectation spec to the function mocker and returns
// the newly created spec. // the newly created spec.
internal::TypedExpectation<F>& InternalExpectedAt( internal::TypedExpectation<F>& InternalExpectedAt(
const char* file, int line, const char* obj, const char* call) { const char* file, int line, const char* obj, const char* call) {
LogWithLocation(internal::INFO, file, line, const string source_text(string("EXPECT_CALL(") + obj + ", " + call + "
string("EXPECT_CALL(") + obj + ", " + call + ") invoked"); )");
return function_mocker_->AddNewExpectation(file, line, matchers_); LogWithLocation(internal::INFO, file, line, source_text + " invoked");
return function_mocker_->AddNewExpectation(
file, line, source_text, matchers_);
} }
private: private:
template <typename Function> template <typename Function>
friend class internal::FunctionMocker; friend class internal::FunctionMocker;
void SetMatchers(const ArgumentMatcherTuple& matchers) { void SetMatchers(const ArgumentMatcherTuple& matchers) {
matchers_ = matchers; matchers_ = matchers;
} }
skipping to change at line 1214 skipping to change at line 1236
const string& message) { const string& message) {
::std::ostringstream s; ::std::ostringstream s;
s << file << ":" << line << ": " << message << ::std::endl; s << file << ":" << line << ": " << message << ::std::endl;
Log(severity, s.str(), 0); Log(severity, s.str(), 0);
} }
// The function mocker that owns this spec. // The function mocker that owns this spec.
internal::FunctionMockerBase<F>* const function_mocker_; internal::FunctionMockerBase<F>* const function_mocker_;
// The argument matchers specified in the spec. // The argument matchers specified in the spec.
ArgumentMatcherTuple matchers_; ArgumentMatcherTuple matchers_;
GTEST_DISALLOW_ASSIGN_(MockSpec);
}; // class MockSpec }; // class MockSpec
// MSVC warns about using 'this' in base member initializer list, so // MSVC warns about using 'this' in base member initializer list, so
// we need to temporarily disable the warning. We have to do it for // we need to temporarily disable the warning. We have to do it for
// the entire class to suppress the warning, even though it's about // the entire class to suppress the warning, even though it's about
// the constructor only. // the constructor only.
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) // Saves the current warning state. #pragma warning(push) // Saves the current warning state.
#pragma warning(disable:4355) // Temporarily disables warning 4355. #pragma warning(disable:4355) // Temporarily disables warning 4355.
skipping to change at line 1237 skipping to change at line 1261
// a void-typed variable or pass a void value to a function. // a void-typed variable or pass a void value to a function.
// ActionResultHolder<T> holds a value of type T, where T must be a // ActionResultHolder<T> holds a value of type T, where T must be a
// copyable type or void (T doesn't need to be default-constructable). // copyable type or void (T doesn't need to be default-constructable).
// It hides the syntactic difference between void and other types, and // It hides the syntactic difference between void and other types, and
// is used to unify the code for invoking both void-returning and // is used to unify the code for invoking both void-returning and
// non-void-returning mock functions. This generic definition is used // non-void-returning mock functions. This generic definition is used
// when T is not void. // when T is not void.
template <typename T> template <typename T>
class ActionResultHolder { class ActionResultHolder {
public: public:
explicit ActionResultHolder(T value) : value_(value) {} explicit ActionResultHolder(T a_value) : value_(a_value) {}
// The compiler-generated copy constructor and assignment operator // The compiler-generated copy constructor and assignment operator
// are exactly what we need, so we don't need to define them. // are exactly what we need, so we don't need to define them.
T value() const { return value_; } T value() const { return value_; }
// Prints the held value as an action's result to os. // Prints the held value as an action's result to os.
void PrintAsActionResult(::std::ostream* os) const { void PrintAsActionResult(::std::ostream* os) const {
*os << "\n Returns: "; *os << "\n Returns: ";
UniversalPrinter<T>::Print(value_, os); UniversalPrinter<T>::Print(value_, os);
skipping to change at line 1271 skipping to change at line 1295
// Performs the given action and returns the result in a // Performs the given action and returns the result in a
// ActionResultHolder. // ActionResultHolder.
template <typename Function, typename Arguments> template <typename Function, typename Arguments>
static ActionResultHolder PerformAction(const Action<Function>& action, static ActionResultHolder PerformAction(const Action<Function>& action,
const Arguments& args) { const Arguments& args) {
return ActionResultHolder(action.Perform(args)); return ActionResultHolder(action.Perform(args));
} }
private: private:
T value_; T value_;
// T could be a reference type, so = isn't supported.
GTEST_DISALLOW_ASSIGN_(ActionResultHolder);
}; };
// Specialization for T = void. // Specialization for T = void.
template <> template <>
class ActionResultHolder<void> { class ActionResultHolder<void> {
public: public:
ActionResultHolder() {} ActionResultHolder() {}
void value() const {} void value() const {}
void PrintAsActionResult(::std::ostream* /* os */) const {} void PrintAsActionResult(::std::ostream* /* os */) const {}
skipping to change at line 1442 skipping to change at line 1470
const char* file, int line, const char* file, int line,
const ArgumentMatcherTuple& m) { const ArgumentMatcherTuple& m) {
Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
default_actions_.push_back(DefaultActionSpec<F>(file, line, m)); default_actions_.push_back(DefaultActionSpec<F>(file, line, m));
return default_actions_.back(); return default_actions_.back();
} }
// Adds and returns an expectation spec for this mock function. // Adds and returns an expectation spec for this mock function.
// L < g_gmock_mutex // L < g_gmock_mutex
TypedExpectation<F>& AddNewExpectation( TypedExpectation<F>& AddNewExpectation(
const char* file, int line, const char* file,
int line,
const string& source_text,
const ArgumentMatcherTuple& m) { const ArgumentMatcherTuple& m) {
Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line);
const linked_ptr<TypedExpectation<F> > expectation( const linked_ptr<TypedExpectation<F> > expectation(
new TypedExpectation<F>(this, file, line, m)); new TypedExpectation<F>(this, file, line, source_text, m));
expectations_.push_back(expectation); expectations_.push_back(expectation);
// Adds this expectation into the implicit sequence if there is one. // Adds this expectation into the implicit sequence if there is one.
Sequence* const implicit_sequence = g_gmock_implicit_sequence.get(); Sequence* const implicit_sequence = g_gmock_implicit_sequence.get();
if (implicit_sequence != NULL) { if (implicit_sequence != NULL) {
implicit_sequence->AddExpectation(Expectation(expectation)); implicit_sequence->AddExpectation(Expectation(expectation));
} }
return *expectation; return *expectation;
} }
skipping to change at line 1586 skipping to change at line 1617
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
const int count = static_cast<int>(expectations_.size()); const int count = static_cast<int>(expectations_.size());
*why << "Google Mock tried the following " << count << " " *why << "Google Mock tried the following " << count << " "
<< (count == 1 ? "expectation, but it didn't match" : << (count == 1 ? "expectation, but it didn't match" :
"expectations, but none matched") "expectations, but none matched")
<< ":\n"; << ":\n";
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
*why << "\n"; *why << "\n";
expectations_[i]->DescribeLocationTo(why); expectations_[i]->DescribeLocationTo(why);
if (count > 1) { if (count > 1) {
*why << "tried expectation #" << i; *why << "tried expectation #" << i << ": ";
} }
*why << "\n"; *why << expectations_[i]->source_text() << "...\n";
expectations_[i]->DescribeMatchResultTo(args, why); expectations_[i]->ExplainMatchResultTo(args, why);
expectations_[i]->DescribeCallCountTo(why); expectations_[i]->DescribeCallCountTo(why);
} }
} }
// Address of the mock object this mock method belongs to. Only // Address of the mock object this mock method belongs to. Only
// valid after this mock method has been called or // valid after this mock method has been called or
// ON_CALL/EXPECT_CALL has been invoked on it. // ON_CALL/EXPECT_CALL has been invoked on it.
const void* mock_obj_; // Protected by g_gmock_mutex. const void* mock_obj_; // Protected by g_gmock_mutex.
// Name of the function being mocked. Only valid after this mock // Name of the function being mocked. Only valid after this mock
skipping to change at line 1653 skipping to change at line 1684
TypedExpectation<F>* const exp = it->get(); TypedExpectation<F>* const exp = it->get();
if (exp->IsOverSaturated()) { if (exp->IsOverSaturated()) {
// There was an upper-bound violation. Since the error was // There was an upper-bound violation. Since the error was
// already reported when it occurred, there is no need to do // already reported when it occurred, there is no need to do
// anything here. // anything here.
expectations_met = false; expectations_met = false;
} else if (!exp->IsSatisfied()) { } else if (!exp->IsSatisfied()) {
expectations_met = false; expectations_met = false;
::std::stringstream ss; ::std::stringstream ss;
ss << "Actual function call count doesn't match this expectation.\n"; ss << "Actual function call count doesn't match "
<< exp->source_text() << "...\n";
// No need to show the source file location of the expectation // No need to show the source file location of the expectation
// in the description, as the Expect() call that follows already // in the description, as the Expect() call that follows already
// takes care of it. // takes care of it.
exp->MaybeDescribeExtraMatcherTo(&ss);
exp->DescribeCallCountTo(&ss); exp->DescribeCallCountTo(&ss);
Expect(false, exp->file(), exp->line(), ss.str()); Expect(false, exp->file(), exp->line(), ss.str());
} }
} }
expectations_.clear(); expectations_.clear();
return expectations_met; return expectations_met;
} }
// Reports an uninteresting call (whose description is in msg) in the // Reports an uninteresting call (whose description is in msg) in the
// manner specified by 'reaction'. // manner specified by 'reaction'.
 End of changes. 35 change blocks. 
35 lines changed or deleted 66 lines changed or added


 gtest-death-test-internal.h   gtest-death-test-internal.h 
skipping to change at line 67 skipping to change at line 67
// style, as defined by the --gtest_death_test_style and/or // style, as defined by the --gtest_death_test_style and/or
// --gtest_internal_run_death_test flags. // --gtest_internal_run_death_test flags.
// In describing the results of death tests, these terms are used with // In describing the results of death tests, these terms are used with
// the corresponding definitions: // the corresponding definitions:
// //
// exit status: The integer exit information in the format specified // exit status: The integer exit information in the format specified
// by wait(2) // by wait(2)
// exit code: The integer code passed to exit(3), _exit(2), or // exit code: The integer code passed to exit(3), _exit(2), or
// returned from main() // returned from main()
class DeathTest { class GTEST_API_ DeathTest {
public: public:
// Create returns false if there was an error determining the // Create returns false if there was an error determining the
// appropriate action to take for the current death test; for example, // appropriate action to take for the current death test; for example,
// if the gtest_death_test_style flag is set to an invalid value. // if the gtest_death_test_style flag is set to an invalid value.
// The LastMessage method will return a more detailed message in that // The LastMessage method will return a more detailed message in that
// case. Otherwise, the DeathTest pointer pointed to by the "test" // case. Otherwise, the DeathTest pointer pointed to by the "test"
// argument is set. If the death test should be skipped, the pointer // argument is set. If the death test should be skipped, the pointer
// is set to NULL; otherwise, it is set to the address of a new concrete // is set to NULL; otherwise, it is set to the address of a new concrete
// DeathTest object that controls the execution of the current test. // DeathTest object that controls the execution of the current test.
static bool Create(const char* statement, const RE* regex, static bool Create(const char* statement, const RE* regex,
skipping to change at line 150 skipping to change at line 150
// A concrete DeathTestFactory implementation for normal use. // A concrete DeathTestFactory implementation for normal use.
class DefaultDeathTestFactory : public DeathTestFactory { class DefaultDeathTestFactory : public DeathTestFactory {
public: public:
virtual bool Create(const char* statement, const RE* regex, virtual bool Create(const char* statement, const RE* regex,
const char* file, int line, DeathTest** test); const char* file, int line, DeathTest** test);
}; };
// Returns true if exit_status describes a process that was terminated // Returns true if exit_status describes a process that was terminated
// by a signal, or exited normally with a nonzero exit code. // by a signal, or exited normally with a nonzero exit code.
bool ExitedUnsuccessfully(int exit_status); GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*, // This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
// ASSERT_EXIT*, and EXPECT_EXIT*. // ASSERT_EXIT*, and EXPECT_EXIT*.
#define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \ #define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::AlwaysTrue()) { \ if (::testing::internal::AlwaysTrue()) { \
const ::testing::internal::RE& gtest_regex = (regex); \ const ::testing::internal::RE& gtest_regex = (regex); \
::testing::internal::DeathTest* gtest_dt; \ ::testing::internal::DeathTest* gtest_dt; \
if (!::testing::internal::DeathTest::Create(#statement, &gtest_regex, \ if (!::testing::internal::DeathTest::Create(#statement, &gtest_regex, \
__FILE__, __LINE__, &gtest_dt)) { \ __FILE__, __LINE__, &gtest_dt)) { \
skipping to change at line 192 skipping to change at line 192
GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \ GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \
fail(::testing::internal::DeathTest::LastMessage()) fail(::testing::internal::DeathTest::LastMessage())
// The symbol "fail" here expands to something into which a message // The symbol "fail" here expands to something into which a message
// can be streamed. // can be streamed.
// A class representing the parsed contents of the // A class representing the parsed contents of the
// --gtest_internal_run_death_test flag, as it existed when // --gtest_internal_run_death_test flag, as it existed when
// RUN_ALL_TESTS was called. // RUN_ALL_TESTS was called.
class InternalRunDeathTestFlag { class InternalRunDeathTestFlag {
public: public:
InternalRunDeathTestFlag(const String& file, InternalRunDeathTestFlag(const String& a_file,
int line, int a_line,
int index, int an_index,
int write_fd) int a_write_fd)
: file_(file), line_(line), index_(index), write_fd_(write_fd) {} : file_(a_file), line_(a_line), index_(an_index),
write_fd_(a_write_fd) {}
~InternalRunDeathTestFlag() { ~InternalRunDeathTestFlag() {
if (write_fd_ >= 0) if (write_fd_ >= 0)
posix::Close(write_fd_); posix::Close(write_fd_);
} }
String file() const { return file_; } String file() const { return file_; }
int line() const { return line_; } int line() const { return line_; }
int index() const { return index_; } int index() const { return index_; }
int write_fd() const { return write_fd_; } int write_fd() const { return write_fd_; }
 End of changes. 3 change blocks. 
7 lines changed or deleted 8 lines changed or added


 gtest-death-test.h   gtest-death-test.h 
skipping to change at line 179 skipping to change at line 179
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
// Like ASSERT_DEATH, but continues on to successive tests in the // Like ASSERT_DEATH, but continues on to successive tests in the
// test case, if any: // test case, if any:
#define EXPECT_DEATH(statement, regex) \ #define EXPECT_DEATH(statement, regex) \
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*: // Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:
// Tests that an exit code describes a normal exit with a given exit code. // Tests that an exit code describes a normal exit with a given exit code.
class ExitedWithCode { class GTEST_API_ ExitedWithCode {
public: public:
explicit ExitedWithCode(int exit_code); explicit ExitedWithCode(int exit_code);
bool operator()(int exit_status) const; bool operator()(int exit_status) const;
private: private:
// No implementation - assignment is unsupported. // No implementation - assignment is unsupported.
void operator=(const ExitedWithCode& other); void operator=(const ExitedWithCode& other);
const int exit_code_; const int exit_code_;
}; };
#if !GTEST_OS_WINDOWS #if !GTEST_OS_WINDOWS
// Tests that an exit code describes an exit due to termination by a // Tests that an exit code describes an exit due to termination by a
// given signal. // given signal.
class KilledBySignal { class GTEST_API_ KilledBySignal {
public: public:
explicit KilledBySignal(int signum); explicit KilledBySignal(int signum);
bool operator()(int exit_status) const; bool operator()(int exit_status) const;
private: private:
const int signum_; const int signum_;
}; };
#endif // !GTEST_OS_WINDOWS #endif // !GTEST_OS_WINDOWS
// EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode. // EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode.
// The death testing framework causes this to have interesting semantics, // The death testing framework causes this to have interesting semantics,
 End of changes. 2 change blocks. 
2 lines changed or deleted 2 lines changed or added


 gtest-filepath.h   gtest-filepath.h 
skipping to change at line 59 skipping to change at line 59
// handles platform-specific conventions (like the pathname separator). // handles platform-specific conventions (like the pathname separator).
// Used for helper functions for naming files in a directory for xml output . // Used for helper functions for naming files in a directory for xml output .
// Except for Set methods, all methods are const or static, which provides an // Except for Set methods, all methods are const or static, which provides an
// "immutable value object" -- useful for peace of mind. // "immutable value object" -- useful for peace of mind.
// A FilePath with a value ending in a path separator ("like/this/") repres ents // A FilePath with a value ending in a path separator ("like/this/") repres ents
// a directory, otherwise it is assumed to represent a file. In either case , // a directory, otherwise it is assumed to represent a file. In either case ,
// it may or may not represent an actual file or directory in the file syst em. // it may or may not represent an actual file or directory in the file syst em.
// Names are NOT checked for syntax correctness -- no checking for illegal // Names are NOT checked for syntax correctness -- no checking for illegal
// characters, malformed paths, etc. // characters, malformed paths, etc.
class FilePath { class GTEST_API_ FilePath {
public: public:
FilePath() : pathname_("") { } FilePath() : pathname_("") { }
FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { } FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
explicit FilePath(const char* pathname) : pathname_(pathname) { explicit FilePath(const char* pathname) : pathname_(pathname) {
Normalize(); Normalize();
} }
explicit FilePath(const String& pathname) : pathname_(pathname) { explicit FilePath(const String& pathname) : pathname_(pathname) {
Normalize(); Normalize();
skipping to change at line 192 skipping to change at line 192
// user error or as a result of some scripts or APIs that generate a path name // user error or as a result of some scripts or APIs that generate a path name
// with a trailing separator. On other platforms the same API or script // with a trailing separator. On other platforms the same API or script
// may NOT generate a pathname with a trailing "/". Then elsewhere that // may NOT generate a pathname with a trailing "/". Then elsewhere that
// pathname may have another "/" and pathname components added to it, // pathname may have another "/" and pathname components added to it,
// without checking for the separator already being there. // without checking for the separator already being there.
// The script language and operating system may allow paths like "foo//ba r" // The script language and operating system may allow paths like "foo//ba r"
// but some of the functions in FilePath will not handle that correctly. In // but some of the functions in FilePath will not handle that correctly. In
// particular, RemoveTrailingPathSeparator() only removes one separator, and // particular, RemoveTrailingPathSeparator() only removes one separator, and
// it is called in CreateDirectoriesRecursively() assuming that it will c hange // it is called in CreateDirectoriesRecursively() assuming that it will c hange
// a pathname from directory syntax (trailing separator) to filename synt ax. // a pathname from directory syntax (trailing separator) to filename synt ax.
//
// On Windows this method also replaces the alternate path separator '/'
with
// the primary path separator '\\', so that for example "bar\\/\\foo" bec
omes
// "bar\\foo".
void Normalize(); void Normalize();
// Returns a pointer to the last occurence of a valid path separator in
// the FilePath. On Windows, for example, both '/' and '\' are valid path
// separators. Returns NULL if no path separator was found.
const char* FindLastPathSeparator() const;
String pathname_; String pathname_;
}; // class FilePath }; // class FilePath
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
 End of changes. 3 change blocks. 
1 lines changed or deleted 12 lines changed or added


 gtest-internal.h   gtest-internal.h 
skipping to change at line 117 skipping to change at line 117
class TestInfo; // Information about a test. class TestInfo; // Information about a test.
class TestPartResult; // Result of a test part. class TestPartResult; // Result of a test part.
class UnitTest; // A collection of test cases. class UnitTest; // A collection of test cases.
namespace internal { namespace internal {
struct TraceInfo; // Information about a trace point. struct TraceInfo; // Information about a trace point.
class ScopedTrace; // Implements scoped trace. class ScopedTrace; // Implements scoped trace.
class TestInfoImpl; // Opaque implementation of TestInfo class TestInfoImpl; // Opaque implementation of TestInfo
class UnitTestImpl; // Opaque implementation of UnitTest class UnitTestImpl; // Opaque implementation of UnitTest
template <typename E> class Vector; // A generic vector.
// How many times InitGoogleTest() has been called. // How many times InitGoogleTest() has been called.
extern int g_init_gtest_count; extern int g_init_gtest_count;
// The text used in failure messages to indicate the start of the // The text used in failure messages to indicate the start of the
// stack trace. // stack trace.
extern const char kStackTraceMarker[]; GTEST_API_ extern const char kStackTraceMarker[];
// A secret type that Google Test users don't know about. It has no // A secret type that Google Test users don't know about. It has no
// definition on purpose. Therefore it's impossible to create a // definition on purpose. Therefore it's impossible to create a
// Secret object, which is what we want. // Secret object, which is what we want.
class Secret; class Secret;
// Two overloaded helpers for checking at compile time whether an // Two overloaded helpers for checking at compile time whether an
// expression is a null pointer literal (i.e. NULL or any 0-valued // expression is a null pointer literal (i.e. NULL or any 0-valued
// compile-time integral constant). Their return values have // compile-time integral constant). Their return values have
// different sizes, so we can use sizeof() to test which version is // different sizes, so we can use sizeof() to test which version is
skipping to change at line 151 skipping to change at line 150
// type, the only expression a user can write that has type Secret* is // type, the only expression a user can write that has type Secret* is
// a null pointer literal. Therefore, we know that x is a null // a null pointer literal. Therefore, we know that x is a null
// pointer literal if and only if the first version is picked by the // pointer literal if and only if the first version is picked by the
// compiler. // compiler.
char IsNullLiteralHelper(Secret* p); char IsNullLiteralHelper(Secret* p);
char (&IsNullLiteralHelper(...))[2]; // NOLINT char (&IsNullLiteralHelper(...))[2]; // NOLINT
// A compile-time bool constant that is true if and only if x is a // A compile-time bool constant that is true if and only if x is a
// null pointer literal (i.e. NULL or any 0-valued compile-time // null pointer literal (i.e. NULL or any 0-valued compile-time
// integral constant). // integral constant).
#ifdef GTEST_ELLIPSIS_NEEDS_COPY_ #ifdef GTEST_ELLIPSIS_NEEDS_POD_
// Passing non-POD classes through ellipsis (...) crashes the ARM // We lose support for NULL detection where the compiler doesn't like
// compiler. The Nokia Symbian and the IBM XL C/C++ compiler try to // passing non-POD classes through ellipsis (...).
// instantiate a copy constructor for objects passed through ellipsis
// (...), failing for uncopyable objects. Hence we define this to
// false (and lose support for NULL detection).
#define GTEST_IS_NULL_LITERAL_(x) false #define GTEST_IS_NULL_LITERAL_(x) false
#else #else
#define GTEST_IS_NULL_LITERAL_(x) \ #define GTEST_IS_NULL_LITERAL_(x) \
(sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1) (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
#endif // GTEST_ELLIPSIS_NEEDS_COPY_ #endif // GTEST_ELLIPSIS_NEEDS_POD_
// Appends the user-supplied message to the Google-Test-generated message. // Appends the user-supplied message to the Google-Test-generated message.
String AppendUserMessage(const String& gtest_msg, GTEST_API_ String AppendUserMessage(const String& gtest_msg,
const Message& user_msg); const Message& user_msg);
// A helper class for creating scoped traces in user programs. // A helper class for creating scoped traces in user programs.
class ScopedTrace { class GTEST_API_ ScopedTrace {
public: public:
// The c'tor pushes the given source file location and message onto // The c'tor pushes the given source file location and message onto
// a trace stack maintained by Google Test. // a trace stack maintained by Google Test.
ScopedTrace(const char* file, int line, const Message& message); ScopedTrace(const char* file, int line, const Message& message);
// The d'tor pops the info pushed by the c'tor. // The d'tor pops the info pushed by the c'tor.
// //
// Note that the d'tor is not virtual in order to be efficient. // Note that the d'tor is not virtual in order to be efficient.
// Don't inherit from ScopedTrace! // Don't inherit from ScopedTrace!
~ScopedTrace(); ~ScopedTrace();
skipping to change at line 247 skipping to change at line 243
// This overload makes sure that all pointers (including // This overload makes sure that all pointers (including
// those to char or wchar_t) are printed as raw pointers. // those to char or wchar_t) are printed as raw pointers.
template <typename T> template <typename T>
inline String FormatForFailureMessage(T* pointer) { inline String FormatForFailureMessage(T* pointer) {
return StreamableToString(static_cast<const void*>(pointer)); return StreamableToString(static_cast<const void*>(pointer));
} }
#endif // GTEST_NEEDS_IS_POINTER_ #endif // GTEST_NEEDS_IS_POINTER_
// These overloaded versions handle narrow and wide characters. // These overloaded versions handle narrow and wide characters.
String FormatForFailureMessage(char ch); GTEST_API_ String FormatForFailureMessage(char ch);
String FormatForFailureMessage(wchar_t wchar); GTEST_API_ String FormatForFailureMessage(wchar_t wchar);
// When this operand is a const char* or char*, and the other operand // When this operand is a const char* or char*, and the other operand
// is a ::std::string or ::string, we print this operand as a C string // is a ::std::string or ::string, we print this operand as a C string
// rather than a pointer. We do the same for wide strings. // rather than a pointer. We do the same for wide strings.
// This internal macro is used to avoid duplicated code. // This internal macro is used to avoid duplicated code.
#define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\ #define GTEST_FORMAT_IMPL_(operand2_type, operand1_printer)\
inline String FormatForComparisonFailureMessage(\ inline String FormatForComparisonFailureMessage(\
operand2_type::value_type* str, const operand2_type& /*operand2*/) {\ operand2_type::value_type* str, const operand2_type& /*operand2*/) {\
return operand1_printer(str);\ return operand1_printer(str);\
}\ }\
inline String FormatForComparisonFailureMessage(\ inline String FormatForComparisonFailureMessage(\
const operand2_type::value_type* str, const operand2_type& /*operand2*/ ) {\ const operand2_type::value_type* str, const operand2_type& /*operand2*/ ) {\
return operand1_printer(str);\ return operand1_printer(str);\
} }
#if GTEST_HAS_STD_STRING
GTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted) GTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted)
#endif // GTEST_HAS_STD_STRING
#if GTEST_HAS_STD_WSTRING #if GTEST_HAS_STD_WSTRING
GTEST_FORMAT_IMPL_(::std::wstring, String::ShowWideCStringQuoted) GTEST_FORMAT_IMPL_(::std::wstring, String::ShowWideCStringQuoted)
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
#if GTEST_HAS_GLOBAL_STRING #if GTEST_HAS_GLOBAL_STRING
GTEST_FORMAT_IMPL_(::string, String::ShowCStringQuoted) GTEST_FORMAT_IMPL_(::string, String::ShowCStringQuoted)
#endif // GTEST_HAS_GLOBAL_STRING #endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_GLOBAL_WSTRING #if GTEST_HAS_GLOBAL_WSTRING
GTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted) GTEST_FORMAT_IMPL_(::wstring, String::ShowWideCStringQuoted)
#endif // GTEST_HAS_GLOBAL_WSTRING #endif // GTEST_HAS_GLOBAL_WSTRING
skipping to change at line 296 skipping to change at line 290
// where foo is 5 and bar is 6, we have: // where foo is 5 and bar is 6, we have:
// //
// expected_expression: "foo" // expected_expression: "foo"
// actual_expression: "bar" // actual_expression: "bar"
// expected_value: "5" // expected_value: "5"
// actual_value: "6" // actual_value: "6"
// //
// The ignoring_case parameter is true iff the assertion is a // The ignoring_case parameter is true iff the assertion is a
// *_STRCASEEQ*. When it's true, the string " (ignoring case)" will // *_STRCASEEQ*. When it's true, the string " (ignoring case)" will
// be inserted into the message. // be inserted into the message.
AssertionResult EqFailure(const char* expected_expression, GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
const char* actual_expression, const char* actual_expression,
const String& expected_value, const String& expected_value,
const String& actual_value, const String& actual_value,
bool ignoring_case); bool ignoring_case);
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
GTEST_API_ String GetBoolAssertionFailureMessage(
const AssertionResult& assertion_result,
const char* expression_text,
const char* actual_predicate_value,
const char* expected_predicate_value);
// This template class represents an IEEE floating-point number // This template class represents an IEEE floating-point number
// (either single-precision or double-precision, depending on the // (either single-precision or double-precision, depending on the
// template parameters). // template parameters).
// //
// The purpose of this class is to do more sophisticated number // The purpose of this class is to do more sophisticated number
// comparison. (Due to round-off error, etc, it's very unlikely that // comparison. (Due to round-off error, etc, it's very unlikely that
// two floating-points will be equal exactly. Hence a naive // two floating-points will be equal exactly. Hence a naive
// comparison by the == operation often doesn't work.) // comparison by the == operation often doesn't work.)
// //
skipping to change at line 520 skipping to change at line 521
// the template. Therefore, the address of dummy_ is guaranteed to // the template. Therefore, the address of dummy_ is guaranteed to
// be unique. // be unique.
return &(TypeIdHelper<T>::dummy_); return &(TypeIdHelper<T>::dummy_);
} }
// Returns the type ID of ::testing::Test. Always call this instead // Returns the type ID of ::testing::Test. Always call this instead
// of GetTypeId< ::testing::Test>() to get the type ID of // of GetTypeId< ::testing::Test>() to get the type ID of
// ::testing::Test, as the latter may give the wrong result due to a // ::testing::Test, as the latter may give the wrong result due to a
// suspected linker bug when compiling Google Test as a Mac OS X // suspected linker bug when compiling Google Test as a Mac OS X
// framework. // framework.
TypeId GetTestTypeId(); GTEST_API_ TypeId GetTestTypeId();
// Defines the abstract factory interface that creates instances // Defines the abstract factory interface that creates instances
// of a Test object. // of a Test object.
class TestFactoryBase { class TestFactoryBase {
public: public:
virtual ~TestFactoryBase() {} virtual ~TestFactoryBase() {}
// Creates a test instance to run. The instance is both created and destr oyed // Creates a test instance to run. The instance is both created and destr oyed
// within TestInfoImpl::Run() // within TestInfoImpl::Run()
virtual Test* CreateTest() = 0; virtual Test* CreateTest() = 0;
skipping to change at line 553 skipping to change at line 554
public: public:
virtual Test* CreateTest() { return new TestClass; } virtual Test* CreateTest() { return new TestClass; }
}; };
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// Predicate-formatters for implementing the HRESULT checking macros // Predicate-formatters for implementing the HRESULT checking macros
// {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED} // {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}
// We pass a long instead of HRESULT to avoid causing an // We pass a long instead of HRESULT to avoid causing an
// include dependency for the HRESULT type. // include dependency for the HRESULT type.
AssertionResult IsHRESULTSuccess(const char* expr, long hr); // NOLINT GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr,
AssertionResult IsHRESULTFailure(const char* expr, long hr); // NOLINT long hr); // NOLINT
GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
long hr); // NOLINT
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
// Formats a source file path and a line number as they would appear // Formats a source file path and a line number as they would appear
// in a compiler error message. // in a compiler error message.
inline String FormatFileLocation(const char* file, int line) { inline String FormatFileLocation(const char* file, int line) {
const char* const file_name = file == NULL ? "unknown file" : file; const char* const file_name = file == NULL ? "unknown file" : file;
if (line < 0) { if (line < 0) {
return String::Format("%s:", file_name); return String::Format("%s:", file_name);
} }
skipping to change at line 593 skipping to change at line 596
// test_case_comment: a comment on the test case that will be included in // test_case_comment: a comment on the test case that will be included in
// the test output // the test output
// comment: a comment on the test that will be included in the // comment: a comment on the test that will be included in the
// test output // test output
// fixture_class_id: ID of the test fixture class // fixture_class_id: ID of the test fixture class
// set_up_tc: pointer to the function that sets up the test case // set_up_tc: pointer to the function that sets up the test case
// tear_down_tc: pointer to the function that tears down the test cas e // tear_down_tc: pointer to the function that tears down the test cas e
// factory: pointer to the factory that creates a test object. // factory: pointer to the factory that creates a test object.
// The newly created TestInfo instance will assume // The newly created TestInfo instance will assume
// ownership of the factory object. // ownership of the factory object.
TestInfo* MakeAndRegisterTestInfo( GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
const char* test_case_name, const char* name, const char* test_case_name, const char* name,
const char* test_case_comment, const char* comment, const char* test_case_comment, const char* comment,
TypeId fixture_class_id, TypeId fixture_class_id,
SetUpTestCaseFunc set_up_tc, SetUpTestCaseFunc set_up_tc,
TearDownTestCaseFunc tear_down_tc, TearDownTestCaseFunc tear_down_tc,
TestFactoryBase* factory); TestFactoryBase* factory);
// If *pstr starts with the given prefix, modifies *pstr to be right
// past the prefix and returns true; otherwise leaves *pstr unchanged
// and returns false. None of pstr, *pstr, and prefix can be NULL.
bool SkipPrefix(const char* prefix, const char** pstr);
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
// State of the definition of a type-parameterized test case. // State of the definition of a type-parameterized test case.
class TypedTestCasePState { class GTEST_API_ TypedTestCasePState {
public: public:
TypedTestCasePState() : registered_(false) {} TypedTestCasePState() : registered_(false) {}
// Adds the given test name to defined_test_names_ and return true // Adds the given test name to defined_test_names_ and return true
// if the test case hasn't been registered; otherwise aborts the // if the test case hasn't been registered; otherwise aborts the
// program. // program.
bool AddTestName(const char* file, int line, const char* case_name, bool AddTestName(const char* file, int line, const char* case_name,
const char* test_name) { const char* test_name) {
if (registered_) { if (registered_) {
fprintf(stderr, "%s Test %s must be defined before " fprintf(stderr, "%s Test %s must be defined before "
skipping to change at line 745 skipping to change at line 753
// Returns the current OS stack trace as a String. // Returns the current OS stack trace as a String.
// //
// The maximum number of stack frames to be included is specified by // The maximum number of stack frames to be included is specified by
// the gtest_stack_trace_depth flag. The skip_count parameter // the gtest_stack_trace_depth flag. The skip_count parameter
// specifies the number of top frames to be skipped, which doesn't // specifies the number of top frames to be skipped, which doesn't
// count against the number of frames to be included. // count against the number of frames to be included.
// //
// For example, if Foo() calls Bar(), which in turn calls // For example, if Foo() calls Bar(), which in turn calls
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count) GTEST_API_ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test,
; int skip_count);
// Helpers for suppressing warnings on unreachable code or constant // Helpers for suppressing warnings on unreachable code or constant
// condition. // condition.
// Always returns true. // Always returns true.
bool AlwaysTrue(); GTEST_API_ bool AlwaysTrue();
// Always returns false. // Always returns false.
inline bool AlwaysFalse() { return !AlwaysTrue(); } inline bool AlwaysFalse() { return !AlwaysTrue(); }
// A simple Linear Congruential Generator for generating random // A simple Linear Congruential Generator for generating random
// numbers with a uniform distribution. Unlike rand() and srand(), it // numbers with a uniform distribution. Unlike rand() and srand(), it
// doesn't use global state (and therefore can't interfere with user // doesn't use global state (and therefore can't interfere with user
// code). Unlike rand_r(), it's portable. An LCG isn't very random, // code). Unlike rand_r(), it's portable. An LCG isn't very random,
// but it's good enough for our purposes. // but it's good enough for our purposes.
class Random { class GTEST_API_ Random {
public: public:
static const UInt32 kMaxRange = 1u << 31; static const UInt32 kMaxRange = 1u << 31;
explicit Random(UInt32 seed) : state_(seed) {} explicit Random(UInt32 seed) : state_(seed) {}
void Reseed(UInt32 seed) { state_ = seed; } void Reseed(UInt32 seed) { state_ = seed; }
// Generates a random number from [0, range). Crashes if 'range' is // Generates a random number from [0, range). Crashes if 'range' is
// 0 or greater than kMaxRange. // 0 or greater than kMaxRange.
UInt32 Generate(UInt32 range); UInt32 Generate(UInt32 range);
skipping to change at line 859 skipping to change at line 868
} \ } \
if (!gtest_caught_any) { \ if (!gtest_caught_any) { \
gtest_msg = "Expected: " #statement " throws an exception.\n" \ gtest_msg = "Expected: " #statement " throws an exception.\n" \
" Actual: it doesn't."; \ " Actual: it doesn't."; \
goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
} \ } \
} else \ } else \
GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \ GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
fail(gtest_msg) fail(gtest_msg)
#define GTEST_TEST_BOOLEAN_(boolexpr, booltext, actual, expected, fail) \ // Implements Boolean test assertions such as EXPECT_TRUE. expression can b
e
// either a boolean expression or an AssertionResult. text is a textual
// represenation of expression as it was passed into the EXPECT_TRUE.
#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::IsTrue(boolexpr)) \ if (const ::testing::AssertionResult gtest_ar_ = \
::testing::AssertionResult(expression)) \
; \ ; \
else \ else \
fail("Value of: " booltext "\n Actual: " #actual "\nExpected: " #expec fail(::testing::internal::GetBoolAssertionFailureMessage(\
ted) gtest_ar_, text, #actual, #expected).c_str())
#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const char* gtest_msg = "") { \ if (const char* gtest_msg = "") { \
::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_check er; \ ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_check er; \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
gtest_msg = "Expected: " #statement " doesn't generate new fatal " \ gtest_msg = "Expected: " #statement " doesn't generate new fatal " \
"failures in the current thread.\n" \ "failures in the current thread.\n" \
" Actual: it does."; \ " Actual: it does."; \
 End of changes. 21 change blocks. 
34 lines changed or deleted 47 lines changed or added


 gtest-linked_ptr.h   gtest-linked_ptr.h 
skipping to change at line 80 skipping to change at line 80
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <gtest/internal/gtest-port.h> #include <gtest/internal/gtest-port.h>
namespace testing { namespace testing {
namespace internal { namespace internal {
// Protects copying of all linked_ptr objects. // Protects copying of all linked_ptr objects.
extern Mutex g_linked_ptr_mutex; GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_linked_ptr_mutex);
// This is used internally by all instances of linked_ptr<>. It needs to b e // This is used internally by all instances of linked_ptr<>. It needs to b e
// a non-template class because different types of linked_ptr<> can refer t o // a non-template class because different types of linked_ptr<> can refer t o
// the same object (linked_ptr<Superclass>(obj) vs linked_ptr<Subclass>(obj )). // the same object (linked_ptr<Superclass>(obj) vs linked_ptr<Subclass>(obj )).
// So, it needs to be possible for different types of linked_ptr to partici pate // So, it needs to be possible for different types of linked_ptr to partici pate
// in the same circular linked list, so we need a single class type here. // in the same circular linked list, so we need a single class type here.
// //
// DO NOT USE THIS CLASS DIRECTLY YOURSELF. Use linked_ptr<T>. // DO NOT USE THIS CLASS DIRECTLY YOURSELF. Use linked_ptr<T>.
class linked_ptr_internal { class linked_ptr_internal {
public: public:
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 gtest-message.h   gtest-message.h 
skipping to change at line 49 skipping to change at line 49
// //
// // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
// //
// Such code is NOT meant to be used by a user directly, and is subject // Such code is NOT meant to be used by a user directly, and is subject
// to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user // to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
// program! // program!
#ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ #ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
#define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_ #define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
#include <limits>
#include <gtest/internal/gtest-string.h> #include <gtest/internal/gtest-string.h>
#include <gtest/internal/gtest-internal.h> #include <gtest/internal/gtest-internal.h>
namespace testing { namespace testing {
// The Message class works like an ostream repeater. // The Message class works like an ostream repeater.
// //
// Typical usage: // Typical usage:
// //
// 1. You stream a bunch of values to a Message object. // 1. You stream a bunch of values to a Message object.
skipping to change at line 80 skipping to change at line 82
// will print "1 != 2". // will print "1 != 2".
// //
// Message is not intended to be inherited from. In particular, its // Message is not intended to be inherited from. In particular, its
// destructor is not virtual. // destructor is not virtual.
// //
// Note that StrStream behaves differently in gcc and in MSVC. You // Note that StrStream behaves differently in gcc and in MSVC. You
// can stream a NULL char pointer to it in the former, but not in the // can stream a NULL char pointer to it in the former, but not in the
// latter (it causes an access violation if you do). The Message // latter (it causes an access violation if you do). The Message
// class hides this difference by treating a NULL char pointer as // class hides this difference by treating a NULL char pointer as
// "(null)". // "(null)".
class Message { class GTEST_API_ Message {
private: private:
// The type of basic IO manipulators (endl, ends, and flush) for // The type of basic IO manipulators (endl, ends, and flush) for
// narrow streams. // narrow streams.
typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&); typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&);
public: public:
// Constructs an empty Message. // Constructs an empty Message.
// We allocate the StrStream separately because it otherwise each use of // We allocate the StrStream separately because it otherwise each use of
// ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's // ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's
// stack frame leading to huge stack frames in some cases; gcc does not r euse // stack frame leading to huge stack frames in some cases; gcc does not r euse
// the stack space. // the stack space.
Message() : ss_(new internal::StrStream) {} Message() : ss_(new internal::StrStream) {
// By default, we want there to be enough precision when printing
// a double to a Message.
*ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
}
// Copy constructor. // Copy constructor.
Message(const Message& msg) : ss_(new internal::StrStream) { // NOLINT Message(const Message& msg) : ss_(new internal::StrStream) { // NOLINT
*ss_ << msg.GetString(); *ss_ << msg.GetString();
} }
// Constructs a Message from a C-string. // Constructs a Message from a C-string.
explicit Message(const char* str) : ss_(new internal::StrStream) { explicit Message(const char* str) : ss_(new internal::StrStream) {
*ss_ << str; *ss_ << str;
} }
 End of changes. 3 change blocks. 
2 lines changed or deleted 8 lines changed or added


 gtest-param-test.h   gtest-param-test.h 
skipping to change at line 135 skipping to change at line 135
// //
// * AnotherInstantiationName/FooTest.DoesBlah/0 for "cat" // * AnotherInstantiationName/FooTest.DoesBlah/0 for "cat"
// * AnotherInstantiationName/FooTest.DoesBlah/1 for "dog" // * AnotherInstantiationName/FooTest.DoesBlah/1 for "dog"
// * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat" // * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
// * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog" // * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
// //
// Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests // Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests
// in the given test case, whether their definitions come before or // in the given test case, whether their definitions come before or
// AFTER the INSTANTIATE_TEST_CASE_P statement. // AFTER the INSTANTIATE_TEST_CASE_P statement.
// //
// Please also note that generator expressions are evaluated in // Please also note that generator expressions (including parameters to the
// RUN_ALL_TESTS(), after main() has started. This allows evaluation of // generators) are evaluated in InitGoogleTest(), after main() has started.
// parameter list based on command line parameters. // This allows the user on one hand, to adjust generator parameters in orde
r
// to dynamically determine a set of tests to run and on the other hand,
// give the user a chance to inspect the generated tests with Google Test
// reflection API before RUN_ALL_TESTS() is executed.
// //
// You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc // You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc
// for more examples. // for more examples.
// //
// In the future, we plan to publish the API for defining new parameter // In the future, we plan to publish the API for defining new parameter
// generators. But for now this interface remains part of the internal // generators. But for now this interface remains part of the internal
// implementation and is subject to change. // implementation and is subject to change.
#endif // 0 #endif // 0
#include <gtest/internal/gtest-port.h> #include <gtest/internal/gtest-port.h>
#if !GTEST_OS_SYMBIAN #if !GTEST_OS_SYMBIAN
#include <utility> #include <utility>
#endif #endif
#if GTEST_HAS_PARAM_TEST // scripts/fuse_gtest.py depends on gtest's own header being #included
// *unconditionally*. Therefore these #includes cannot be moved
// inside #if GTEST_HAS_PARAM_TEST.
#include <gtest/internal/gtest-internal.h> #include <gtest/internal/gtest-internal.h>
#include <gtest/internal/gtest-param-util.h> #include <gtest/internal/gtest-param-util.h>
#include <gtest/internal/gtest-param-util-generated.h> #include <gtest/internal/gtest-param-util-generated.h>
#if GTEST_HAS_PARAM_TEST
namespace testing { namespace testing {
// Functions producing parameter generators. // Functions producing parameter generators.
// //
// Google Test uses these generators to produce parameters for value- // Google Test uses these generators to produce parameters for value-
// parameterized tests. When a parameterized test case is instantiated // parameterized tests. When a parameterized test case is instantiated
// with a particular generator, Google Test creates and runs tests // with a particular generator, Google Test creates and runs tests
// for each element in the sequence produced by the generator. // for each element in the sequence produced by the generator.
// //
// In the following sample, tests from test case FooTest are instantiated // In the following sample, tests from test case FooTest are instantiated
 End of changes. 3 change blocks. 
5 lines changed or deleted 12 lines changed or added


 gtest-param-util-generated.h   gtest-param-util-generated.h 
skipping to change at line 47 skipping to change at line 47
// Currently Google Test supports at most 50 arguments in Values, // Currently Google Test supports at most 50 arguments in Values,
// and at most 10 arguments in Combine. Please contact // and at most 10 arguments in Combine. Please contact
// googletestframework@googlegroups.com if you need more. // googletestframework@googlegroups.com if you need more.
// Please note that the number of arguments to Combine is limited // Please note that the number of arguments to Combine is limited
// by the maximum arity of the implementation of tr1::tuple which is // by the maximum arity of the implementation of tr1::tuple which is
// currently set at 10. // currently set at 10.
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
// scripts/fuse_gtest.py depends on gtest's own header being #included
// *unconditionally*. Therefore these #includes cannot be moved
// inside #if GTEST_HAS_PARAM_TEST.
#include <gtest/internal/gtest-param-util.h>
#include <gtest/internal/gtest-port.h> #include <gtest/internal/gtest-port.h>
#if GTEST_HAS_PARAM_TEST #if GTEST_HAS_PARAM_TEST
#include <gtest/internal/gtest-param-util.h>
namespace testing { namespace testing {
// Forward declarations of ValuesIn(), which is implemented in
// include/gtest/gtest-param-test.h.
template <typename ForwardIterator>
internal::ParamGenerator<
typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn(
ForwardIterator begin, ForwardIterator end);
template <typename T, size_t N>
internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);
template <class Container>
internal::ParamGenerator<typename Container::value_type> ValuesIn(
const Container& container);
namespace internal { namespace internal {
// Used in the Values() function to provide polymorphic capabilities. // Used in the Values() function to provide polymorphic capabilities.
template <typename T1> template <typename T1>
class ValueArray1 { class ValueArray1 {
public: public:
explicit ValueArray1(T1 v1) : v1_(v1) {} explicit ValueArray1(T1 v1) : v1_(v1) {}
template <typename T> template <typename T>
operator ParamGenerator<T>() const { return ValuesIn(&v1_, &v1_ + 1); } operator ParamGenerator<T>() const { return ValuesIn(&v1_, &v1_ + 1); }
 End of changes. 3 change blocks. 
2 lines changed or deleted 19 lines changed or added


 gtest-param-util.h   gtest-param-util.h 
skipping to change at line 41 skipping to change at line 41
// Type and function utilities for implementing parameterized tests. // Type and function utilities for implementing parameterized tests.
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
#include <iterator> #include <iterator>
#include <utility> #include <utility>
#include <vector> #include <vector>
// scripts/fuse_gtest.py depends on gtest's own header being #included
// *unconditionally*. Therefore these #includes cannot be moved
// inside #if GTEST_HAS_PARAM_TEST.
#include <gtest/internal/gtest-internal.h>
#include <gtest/internal/gtest-linked_ptr.h>
#include <gtest/internal/gtest-port.h> #include <gtest/internal/gtest-port.h>
#if GTEST_HAS_PARAM_TEST #if GTEST_HAS_PARAM_TEST
#if GTEST_HAS_RTTI
#include <typeinfo>
#endif // GTEST_HAS_RTTI
#include <gtest/internal/gtest-linked_ptr.h>
#include <gtest/internal/gtest-internal.h>
namespace testing { namespace testing {
namespace internal { namespace internal {
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
// //
// Outputs a message explaining invalid registration of different // Outputs a message explaining invalid registration of different
// fixture class for the same test case. This may happen when // fixture class for the same test case. This may happen when
// TEST_P macro is used to define two tests with the same name // TEST_P macro is used to define two tests with the same name
// but in different namespaces. // but in different namespaces.
void ReportInvalidTestCaseType(const char* test_case_name, GTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name,
const char* file, int line); const char* file, int line);
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
//
// Downcasts the pointer of type Base to Derived.
// Derived must be a subclass of Base. The parameter MUST
// point to a class of type Derived, not any subclass of it.
// When RTTI is available, the function performs a runtime
// check to enforce this.
template <class Derived, class Base>
Derived* CheckedDowncastToActualType(Base* base) {
#if GTEST_HAS_RTTI
GTEST_CHECK_(typeid(*base) == typeid(Derived));
Derived* derived = dynamic_cast<Derived*>(base); // NOLINT
#else
Derived* derived = static_cast<Derived*>(base); // Poor man's downcast.
#endif // GTEST_HAS_RTTI
return derived;
}
template <typename> class ParamGeneratorInterface; template <typename> class ParamGeneratorInterface;
template <typename> class ParamGenerator; template <typename> class ParamGenerator;
// Interface for iterating over elements provided by an implementation // Interface for iterating over elements provided by an implementation
// of ParamGeneratorInterface<T>. // of ParamGeneratorInterface<T>.
template <typename T> template <typename T>
class ParamIteratorInterface { class ParamIteratorInterface {
public: public:
virtual ~ParamIteratorInterface() {} virtual ~ParamIteratorInterface() {}
skipping to change at line 172 skipping to change at line 152
public: public:
typedef T ParamType; typedef T ParamType;
virtual ~ParamGeneratorInterface() {} virtual ~ParamGeneratorInterface() {}
// Generator interface definition // Generator interface definition
virtual ParamIteratorInterface<T>* Begin() const = 0; virtual ParamIteratorInterface<T>* Begin() const = 0;
virtual ParamIteratorInterface<T>* End() const = 0; virtual ParamIteratorInterface<T>* End() const = 0;
}; };
// Wraps ParamGeneratorInetrface<T> and provides general generator syntax // Wraps ParamGeneratorInterface<T> and provides general generator syntax
// compatible with the STL Container concept. // compatible with the STL Container concept.
// This class implements copy initialization semantics and the contained // This class implements copy initialization semantics and the contained
// ParamGeneratorInterface<T> instance is shared among all copies // ParamGeneratorInterface<T> instance is shared among all copies
// of the original object. This is possible because that instance is immuta ble. // of the original object. This is possible because that instance is immuta ble.
template<typename T> template<typename T>
class ParamGenerator { class ParamGenerator {
public: public:
typedef ParamIterator<T> iterator; typedef ParamIterator<T> iterator;
explicit ParamGenerator(ParamGeneratorInterface<T>* impl) : impl_(impl) { } explicit ParamGenerator(ParamGeneratorInterface<T>* impl) : impl_(impl) { }
skipping to change at line 248 skipping to change at line 228
GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
<< "The program attempted to compare iterators " << "The program attempted to compare iterators "
<< "from different generators." << std::endl; << "from different generators." << std::endl;
const int other_index = const int other_index =
CheckedDowncastToActualType<const Iterator>(&other)->index_; CheckedDowncastToActualType<const Iterator>(&other)->index_;
return index_ == other_index; return index_ == other_index;
} }
private: private:
Iterator(const Iterator& other) Iterator(const Iterator& other)
: base_(other.base_), value_(other.value_), index_(other.index_), : ParamIteratorInterface<T>(),
base_(other.base_), value_(other.value_), index_(other.index_),
step_(other.step_) {} step_(other.step_) {}
// No implementation - assignment is unsupported. // No implementation - assignment is unsupported.
void operator=(const Iterator& other); void operator=(const Iterator& other);
const ParamGeneratorInterface<T>* const base_; const ParamGeneratorInterface<T>* const base_;
T value_; T value_;
int index_; int index_;
const IncrementT step_; const IncrementT step_;
}; // class RangeGenerator::Iterator }; // class RangeGenerator::Iterator
skipping to change at line 544 skipping to change at line 525
test_info->test_meta_factory->CreateTestFactory(*param_it)); test_info->test_meta_factory->CreateTestFactory(*param_it));
} // for param_it } // for param_it
} // for gen_it } // for gen_it
} // for test_it } // for test_it
} // RegisterTests } // RegisterTests
private: private:
// LocalTestInfo structure keeps information about a single test register ed // LocalTestInfo structure keeps information about a single test register ed
// with TEST_P macro. // with TEST_P macro.
struct TestInfo { struct TestInfo {
TestInfo(const char* test_case_base_name, TestInfo(const char* a_test_case_base_name,
const char* test_base_name, const char* a_test_base_name,
TestMetaFactoryBase<ParamType>* test_meta_factory) : TestMetaFactoryBase<ParamType>* a_test_meta_factory) :
test_case_base_name(test_case_base_name), test_case_base_name(a_test_case_base_name),
test_base_name(test_base_name), test_base_name(a_test_base_name),
test_meta_factory(test_meta_factory) {} test_meta_factory(a_test_meta_factory) {}
const String test_case_base_name; const String test_case_base_name;
const String test_base_name; const String test_base_name;
const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory; const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
}; };
typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer; typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer;
// Keeps pairs of <Instantiation name, Sequence generator creation functi on> // Keeps pairs of <Instantiation name, Sequence generator creation functi on>
// received from INSTANTIATE_TEST_CASE_P macros. // received from INSTANTIATE_TEST_CASE_P macros.
typedef ::std::vector<std::pair<String, GeneratorCreationFunc*> > typedef ::std::vector<std::pair<String, GeneratorCreationFunc*> >
InstantiationContainer; InstantiationContainer;
 End of changes. 6 change blocks. 
35 lines changed or deleted 16 lines changed or added


 gtest-spi.h   gtest-spi.h 
skipping to change at line 51 skipping to change at line 51
// This helper class can be used to mock out Google Test failure reporting // This helper class can be used to mock out Google Test failure reporting
// so that we can test Google Test or code that builds on Google Test. // so that we can test Google Test or code that builds on Google Test.
// //
// An object of this class appends a TestPartResult object to the // An object of this class appends a TestPartResult object to the
// TestPartResultArray object given in the constructor whenever a Google Te st // TestPartResultArray object given in the constructor whenever a Google Te st
// failure is reported. It can either intercept only failures that are // failure is reported. It can either intercept only failures that are
// generated in the same thread that created this object or it can intercep t // generated in the same thread that created this object or it can intercep t
// all generated failures. The scope of this mock object can be controlled with // all generated failures. The scope of this mock object can be controlled with
// the second argument to the two arguments constructor. // the second argument to the two arguments constructor.
class ScopedFakeTestPartResultReporter class GTEST_API_ ScopedFakeTestPartResultReporter
: public TestPartResultReporterInterface { : public TestPartResultReporterInterface {
public: public:
// The two possible mocking modes of this object. // The two possible mocking modes of this object.
enum InterceptMode { enum InterceptMode {
INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failure s. INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failure s.
INTERCEPT_ALL_THREADS // Intercepts all failures. INTERCEPT_ALL_THREADS // Intercepts all failures.
}; };
// The c'tor sets this object as the test part result reporter used // The c'tor sets this object as the test part result reporter used
// by Google Test. The 'result' parameter specifies where to report the // by Google Test. The 'result' parameter specifies where to report the
skipping to change at line 96 skipping to change at line 96
GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter); GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter);
}; };
namespace internal { namespace internal {
// A helper class for implementing EXPECT_FATAL_FAILURE() and // A helper class for implementing EXPECT_FATAL_FAILURE() and
// EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given // EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given
// TestPartResultArray contains exactly one failure that has the given // TestPartResultArray contains exactly one failure that has the given
// type and contains the given substring. If that's not the case, a // type and contains the given substring. If that's not the case, a
// non-fatal failure will be generated. // non-fatal failure will be generated.
class SingleFailureChecker { class GTEST_API_ SingleFailureChecker {
public: public:
// The constructor remembers the arguments. // The constructor remembers the arguments.
SingleFailureChecker(const TestPartResultArray* results, SingleFailureChecker(const TestPartResultArray* results,
TestPartResult::Type type, TestPartResult::Type type,
const char* substr); const char* substr);
~SingleFailureChecker(); ~SingleFailureChecker();
private: private:
const TestPartResultArray* const results_; const TestPartResultArray* const results_;
const TestPartResult::Type type_; const TestPartResult::Type type_;
const String substr_; const String substr_;
 End of changes. 2 change blocks. 
2 lines changed or deleted 2 lines changed or added


 gtest-string.h   gtest-string.h 
skipping to change at line 44 skipping to change at line 44
// This header file declares the String class and functions used internally by // This header file declares the String class and functions used internally by
// Google Test. They are subject to change without notice. They should not used // Google Test. They are subject to change without notice. They should not used
// by code external to Google Test. // by code external to Google Test.
// //
// This header file is #included by <gtest/internal/gtest-internal.h>. // This header file is #included by <gtest/internal/gtest-internal.h>.
// It should not be #included by other files. // It should not be #included by other files.
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
#ifdef __BORLANDC__
// string.h is not guaranteed to provide strcpy on C++ Builder.
#include <mem.h>
#endif
#include <string.h> #include <string.h>
#include <gtest/internal/gtest-port.h> #include <gtest/internal/gtest-port.h>
#if GTEST_HAS_GLOBAL_STRING || GTEST_HAS_STD_STRING
#include <string> #include <string>
#endif // GTEST_HAS_GLOBAL_STRING || GTEST_HAS_STD_STRING
namespace testing { namespace testing {
namespace internal { namespace internal {
// String - a UTF-8 string class. // String - a UTF-8 string class.
// //
// We cannot use std::string as Microsoft's STL implementation in // For historic reasons, we don't use std::string.
// Visual C++ 7.1 has problems when exception is disabled. There is a
// hack to work around this, but we've seen cases where the hack fails
// to work.
// //
// Also, String is different from std::string in that it can represent // TODO(wan@google.com): replace this class with std::string or
// both NULL and the empty string, while std::string cannot represent // implement it in terms of the latter.
// NULL. //
// Note that String can represent both NULL and the empty string,
// while std::string cannot represent NULL.
// //
// NULL and the empty string are considered different. NULL is less // NULL and the empty string are considered different. NULL is less
// than anything (including the empty string) except itself. // than anything (including the empty string) except itself.
// //
// This class only provides minimum functionality necessary for // This class only provides minimum functionality necessary for
// implementing Google Test. We do not intend to implement a full-fledged // implementing Google Test. We do not intend to implement a full-fledged
// string class here. // string class here.
// //
// Since the purpose of this class is to provide a substitute for // Since the purpose of this class is to provide a substitute for
// std::string on platforms where it cannot be used, we define a copy // std::string on platforms where it cannot be used, we define a copy
// constructor and assignment operators such that we don't need // constructor and assignment operators such that we don't need
// conditional compilation in a lot of places. // conditional compilation in a lot of places.
// //
// In order to make the representation efficient, the d'tor of String // In order to make the representation efficient, the d'tor of String
// is not virtual. Therefore DO NOT INHERIT FROM String. // is not virtual. Therefore DO NOT INHERIT FROM String.
class String { class GTEST_API_ String {
public: public:
// Static utility methods // Static utility methods
// Returns the input enclosed in double quotes if it's not NULL; // Returns the input enclosed in double quotes if it's not NULL;
// otherwise returns "(null)". For example, "\"Hello\"" is returned // otherwise returns "(null)". For example, "\"Hello\"" is returned
// for input "Hello". // for input "Hello".
// //
// This is useful for printing a C string in the syntax of a literal. // This is useful for printing a C string in the syntax of a literal.
// //
// Known issue: escape sequences are not handled yet. // Known issue: escape sequences are not handled yet.
skipping to change at line 193 skipping to change at line 195
// 0). If 4096 characters are not enough to format the input, // 0). If 4096 characters are not enough to format the input,
// "<buffer exceeded>" is returned. // "<buffer exceeded>" is returned.
static String Format(const char* format, ...); static String Format(const char* format, ...);
// C'tors // C'tors
// The default c'tor constructs a NULL string. // The default c'tor constructs a NULL string.
String() : c_str_(NULL), length_(0) {} String() : c_str_(NULL), length_(0) {}
// Constructs a String by cloning a 0-terminated C string. // Constructs a String by cloning a 0-terminated C string.
String(const char* c_str) { // NOLINT String(const char* a_c_str) { // NOLINT
if (c_str == NULL) { if (a_c_str == NULL) {
c_str_ = NULL; c_str_ = NULL;
length_ = 0; length_ = 0;
} else { } else {
ConstructNonNull(c_str, strlen(c_str)); ConstructNonNull(a_c_str, strlen(a_c_str));
} }
} }
// Constructs a String by copying a given number of chars from a // Constructs a String by copying a given number of chars from a
// buffer. E.g. String("hello", 3) creates the string "hel", // buffer. E.g. String("hello", 3) creates the string "hel",
// String("a\0bcd", 4) creates "a\0bc", String(NULL, 0) creates "", // String("a\0bcd", 4) creates "a\0bc", String(NULL, 0) creates "",
// and String(NULL, 1) results in access violation. // and String(NULL, 1) results in access violation.
String(const char* buffer, size_t length) { String(const char* buffer, size_t a_length) {
ConstructNonNull(buffer, length); ConstructNonNull(buffer, a_length);
} }
// The copy c'tor creates a new copy of the string. The two // The copy c'tor creates a new copy of the string. The two
// String objects do not share content. // String objects do not share content.
String(const String& str) : c_str_(NULL), length_(0) { *this = str; } String(const String& str) : c_str_(NULL), length_(0) { *this = str; }
// D'tor. String is intended to be a final class, so the d'tor // D'tor. String is intended to be a final class, so the d'tor
// doesn't need to be virtual. // doesn't need to be virtual.
~String() { delete[] c_str_; } ~String() { delete[] c_str_; }
// Allows a String to be implicitly converted to an ::std::string or // Allows a String to be implicitly converted to an ::std::string or
// ::string, and vice versa. Converting a String containing a NULL // ::string, and vice versa. Converting a String containing a NULL
// pointer to ::std::string or ::string is undefined behavior. // pointer to ::std::string or ::string is undefined behavior.
// Converting a ::std::string or ::string containing an embedded NUL // Converting a ::std::string or ::string containing an embedded NUL
// character to a String will result in the prefix up to the first // character to a String will result in the prefix up to the first
// NUL character. // NUL character.
#if GTEST_HAS_STD_STRING
String(const ::std::string& str) { String(const ::std::string& str) {
ConstructNonNull(str.c_str(), str.length()); ConstructNonNull(str.c_str(), str.length());
} }
operator ::std::string() const { return ::std::string(c_str(), length()); } operator ::std::string() const { return ::std::string(c_str(), length()); }
#endif // GTEST_HAS_STD_STRING
#if GTEST_HAS_GLOBAL_STRING #if GTEST_HAS_GLOBAL_STRING
String(const ::string& str) { String(const ::string& str) {
ConstructNonNull(str.c_str(), str.length()); ConstructNonNull(str.c_str(), str.length());
} }
operator ::string() const { return ::string(c_str(), length()); } operator ::string() const { return ::string(c_str(), length()); }
#endif // GTEST_HAS_GLOBAL_STRING #endif // GTEST_HAS_GLOBAL_STRING
// Returns true iff this is an empty string (i.e. ""). // Returns true iff this is an empty string (i.e. "").
bool empty() const { return (c_str() != NULL) && (length() == 0); } bool empty() const { return (c_str() != NULL) && (length() == 0); }
// Compares this with another String. // Compares this with another String.
// Returns < 0 if this is less than rhs, 0 if this is equal to rhs, or > 0 // Returns < 0 if this is less than rhs, 0 if this is equal to rhs, or > 0
// if this is greater than rhs. // if this is greater than rhs.
int Compare(const String& rhs) const; int Compare(const String& rhs) const;
// Returns true iff this String equals the given C string. A NULL // Returns true iff this String equals the given C string. A NULL
// string and a non-NULL string are considered not equal. // string and a non-NULL string are considered not equal.
bool operator==(const char* c_str) const { return Compare(c_str) == 0; } bool operator==(const char* a_c_str) const { return Compare(a_c_str) == 0 ; }
// Returns true iff this String is less than the given String. A // Returns true iff this String is less than the given String. A
// NULL string is considered less than "". // NULL string is considered less than "".
bool operator<(const String& rhs) const { return Compare(rhs) < 0; } bool operator<(const String& rhs) const { return Compare(rhs) < 0; }
// Returns true iff this String doesn't equal the given C string. A NULL // Returns true iff this String doesn't equal the given C string. A NULL
// string and a non-NULL string are considered not equal. // string and a non-NULL string are considered not equal.
bool operator!=(const char* c_str) const { return !(*this == c_str); } bool operator!=(const char* a_c_str) const { return !(*this == a_c_str); }
// Returns true iff this String ends with the given suffix. *Any* // Returns true iff this String ends with the given suffix. *Any*
// String is considered to end with a NULL or empty suffix. // String is considered to end with a NULL or empty suffix.
bool EndsWith(const char* suffix) const; bool EndsWith(const char* suffix) const;
// Returns true iff this String ends with the given suffix, not consideri ng // Returns true iff this String ends with the given suffix, not consideri ng
// case. Any String is considered to end with a NULL or empty suffix. // case. Any String is considered to end with a NULL or empty suffix.
bool EndsWithCaseInsensitive(const char* suffix) const; bool EndsWithCaseInsensitive(const char* suffix) const;
// Returns the length of the encapsulated string, or 0 if the // Returns the length of the encapsulated string, or 0 if the
// string is NULL. // string is NULL.
size_t length() const { return length_; } size_t length() const { return length_; }
// Gets the 0-terminated C string this String object represents. // Gets the 0-terminated C string this String object represents.
// The String object still owns the string. Therefore the caller // The String object still owns the string. Therefore the caller
// should NOT delete the return value. // should NOT delete the return value.
const char* c_str() const { return c_str_; } const char* c_str() const { return c_str_; }
// Assigns a C string to this object. Self-assignment works. // Assigns a C string to this object. Self-assignment works.
const String& operator=(const char* c_str) { return *this = String(c_str) const String& operator=(const char* a_c_str) {
; } return *this = String(a_c_str);
}
// Assigns a String object to this object. Self-assignment works. // Assigns a String object to this object. Self-assignment works.
const String& operator=(const String& rhs) { const String& operator=(const String& rhs) {
if (this != &rhs) { if (this != &rhs) {
delete[] c_str_; delete[] c_str_;
if (rhs.c_str() == NULL) { if (rhs.c_str() == NULL) {
c_str_ = NULL; c_str_ = NULL;
length_ = 0; length_ = 0;
} else { } else {
ConstructNonNull(rhs.c_str(), rhs.length()); ConstructNonNull(rhs.c_str(), rhs.length());
skipping to change at line 300 skipping to change at line 302
} }
return *this; return *this;
} }
private: private:
// Constructs a non-NULL String from the given content. This // Constructs a non-NULL String from the given content. This
// function can only be called when data_ has not been allocated. // function can only be called when data_ has not been allocated.
// ConstructNonNull(NULL, 0) results in an empty string (""). // ConstructNonNull(NULL, 0) results in an empty string ("").
// ConstructNonNull(NULL, non_zero) is undefined behavior. // ConstructNonNull(NULL, non_zero) is undefined behavior.
void ConstructNonNull(const char* buffer, size_t length) { void ConstructNonNull(const char* buffer, size_t a_length) {
char* const str = new char[length + 1]; char* const str = new char[a_length + 1];
memcpy(str, buffer, length); memcpy(str, buffer, a_length);
str[length] = '\0'; str[a_length] = '\0';
c_str_ = str; c_str_ = str;
length_ = length; length_ = a_length;
} }
const char* c_str_; const char* c_str_;
size_t length_; size_t length_;
}; // class String }; // class String
// Streams a String to an ostream. Each '\0' character in the String // Streams a String to an ostream. Each '\0' character in the String
// is replaced with "\\0". // is replaced with "\\0".
inline ::std::ostream& operator<<(::std::ostream& os, const String& str) { inline ::std::ostream& operator<<(::std::ostream& os, const String& str) {
if (str.c_str() == NULL) { if (str.c_str() == NULL) {
skipping to change at line 332 skipping to change at line 334
} else { } else {
os << c_str[i]; os << c_str[i];
} }
} }
} }
return os; return os;
} }
// Gets the content of the StrStream's buffer as a String. Each '\0' // Gets the content of the StrStream's buffer as a String. Each '\0'
// character in the buffer is replaced with "\\0". // character in the buffer is replaced with "\\0".
String StrStreamToString(StrStream* stream); GTEST_API_ String StrStreamToString(StrStream* stream);
// Converts a streamable value to a String. A NULL pointer is // Converts a streamable value to a String. A NULL pointer is
// converted to "(null)". When the input value is a ::string, // converted to "(null)". When the input value is a ::string,
// ::std::string, ::wstring, or ::std::wstring object, each NUL // ::std::string, ::wstring, or ::std::wstring object, each NUL
// character in it is replaced with "\\0". // character in it is replaced with "\\0".
// Declared here but defined in gtest.h, so that it has access // Declared here but defined in gtest.h, so that it has access
// to the definition of the Message class, required by the ARM // to the definition of the Message class, required by the ARM
// compiler. // compiler.
template <typename T> template <typename T>
 End of changes. 17 change blocks. 
27 lines changed or deleted 28 lines changed or added


 gtest-test-part.h   gtest-test-part.h 
skipping to change at line 37 skipping to change at line 37
// (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: mheule@google.com (Markus Heule) // Author: mheule@google.com (Markus Heule)
// //
#ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ #ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
#define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_ #define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
#include <iosfwd> #include <iosfwd>
#include <vector>
#include <gtest/internal/gtest-internal.h> #include <gtest/internal/gtest-internal.h>
#include <gtest/internal/gtest-string.h> #include <gtest/internal/gtest-string.h>
namespace testing { namespace testing {
// A copyable object representing the result of a test part (i.e. an // A copyable object representing the result of a test part (i.e. an
// assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()). // assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
// //
// Don't inherit from TestPartResult as its destructor is not virtual. // Don't inherit from TestPartResult as its destructor is not virtual.
class TestPartResult { class GTEST_API_ TestPartResult {
public: public:
// The possible outcomes of a test part (i.e. an assertion or an // The possible outcomes of a test part (i.e. an assertion or an
// explicit SUCCEED(), FAIL(), or ADD_FAILURE()). // explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
enum Type { enum Type {
kSuccess, // Succeeded. kSuccess, // Succeeded.
kNonFatalFailure, // Failed but the test can continue. kNonFatalFailure, // Failed but the test can continue.
kFatalFailure // Failed and the test should be terminated. kFatalFailure // Failed and the test should be terminated.
}; };
// C'tor. TestPartResult does NOT have a default constructor. // C'tor. TestPartResult does NOT have a default constructor.
// Always use this constructor (with parameters) to create a // Always use this constructor (with parameters) to create a
// TestPartResult object. // TestPartResult object.
TestPartResult(Type type, TestPartResult(Type a_type,
const char* file_name, const char* a_file_name,
int line_number, int a_line_number,
const char* message) const char* a_message)
: type_(type), : type_(a_type),
file_name_(file_name), file_name_(a_file_name),
line_number_(line_number), line_number_(a_line_number),
summary_(ExtractSummary(message)), summary_(ExtractSummary(a_message)),
message_(message) { message_(a_message) {
} }
// Gets the outcome of the test part. // Gets the outcome of the test part.
Type type() const { return type_; } Type type() const { return type_; }
// Gets the name of the source file where the test part took place, or // Gets the name of the source file where the test part took place, or
// NULL if it's unknown. // NULL if it's unknown.
const char* file_name() const { return file_name_.c_str(); } const char* file_name() const { return file_name_.c_str(); }
// Gets the line in the source file where the test part took place, // Gets the line in the source file where the test part took place,
skipping to change at line 120 skipping to change at line 121
int line_number_; int line_number_;
internal::String summary_; // The test failure summary. internal::String summary_; // The test failure summary.
internal::String message_; // The test failure message. internal::String message_; // The test failure message.
}; };
// Prints a TestPartResult object. // Prints a TestPartResult object.
std::ostream& operator<<(std::ostream& os, const TestPartResult& result); std::ostream& operator<<(std::ostream& os, const TestPartResult& result);
// An array of TestPartResult objects. // An array of TestPartResult objects.
// //
// We define this class as we cannot use STL containers when compiling
// Google Test with MSVC 7.1 and exceptions disabled.
//
// Don't inherit from TestPartResultArray as its destructor is not // Don't inherit from TestPartResultArray as its destructor is not
// virtual. // virtual.
class TestPartResultArray { class GTEST_API_ TestPartResultArray {
public: public:
TestPartResultArray(); TestPartResultArray() {}
~TestPartResultArray();
// Appends the given TestPartResult to the array. // Appends the given TestPartResult to the array.
void Append(const TestPartResult& result); void Append(const TestPartResult& result);
// Returns the TestPartResult at the given index (0-based). // Returns the TestPartResult at the given index (0-based).
const TestPartResult& GetTestPartResult(int index) const; const TestPartResult& GetTestPartResult(int index) const;
// Returns the number of TestPartResult objects in the array. // Returns the number of TestPartResult objects in the array.
int size() const; int size() const;
private: private:
// Internally we use a Vector to implement the array. std::vector<TestPartResult> array_;
internal::Vector<TestPartResult>* const array_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray); GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray);
}; };
// This interface knows how to report a test part result. // This interface knows how to report a test part result.
class TestPartResultReporterInterface { class TestPartResultReporterInterface {
public: public:
virtual ~TestPartResultReporterInterface() {} virtual ~TestPartResultReporterInterface() {}
virtual void ReportTestPartResult(const TestPartResult& result) = 0; virtual void ReportTestPartResult(const TestPartResult& result) = 0;
}; };
namespace internal { namespace internal {
// This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check i f a // This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check i f a
// statement generates new fatal failures. To do so it registers itself as the // statement generates new fatal failures. To do so it registers itself as the
// current test part result reporter. Besides checking if fatal failures we re // current test part result reporter. Besides checking if fatal failures we re
// reported, it only delegates the reporting to the former result reporter. // reported, it only delegates the reporting to the former result reporter.
// The original result reporter is restored in the destructor. // The original result reporter is restored in the destructor.
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
class HasNewFatalFailureHelper : public TestPartResultReporterInterface { class GTEST_API_ HasNewFatalFailureHelper
: public TestPartResultReporterInterface {
public: public:
HasNewFatalFailureHelper(); HasNewFatalFailureHelper();
virtual ~HasNewFatalFailureHelper(); virtual ~HasNewFatalFailureHelper();
virtual void ReportTestPartResult(const TestPartResult& result); virtual void ReportTestPartResult(const TestPartResult& result);
bool has_new_fatal_failure() const { return has_new_fatal_failure_; } bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
private: private:
bool has_new_fatal_failure_; bool has_new_fatal_failure_;
TestPartResultReporterInterface* original_reporter_; TestPartResultReporterInterface* original_reporter_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper); GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper);
 End of changes. 9 change blocks. 
19 lines changed or deleted 17 lines changed or added


 gtest-tuple.h   gtest-tuple.h 
skipping to change at line 45 skipping to change at line 45
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
#include <utility> // For ::std::pair. #include <utility> // For ::std::pair.
// The compiler used in Symbian has a bug that prevents us from declaring t he // The compiler used in Symbian has a bug that prevents us from declaring t he
// tuple template as a friend (it complains that tuple is redefined). This // tuple template as a friend (it complains that tuple is redefined). This
// hack bypasses the bug by declaring the members that should otherwise be // hack bypasses the bug by declaring the members that should otherwise be
// private as public. // private as public.
#if defined(__SYMBIAN32__) // Sun Studio versions < 12 also have the above bug.
#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
#define GTEST_DECLARE_TUPLE_AS_FRIEND_ public: #define GTEST_DECLARE_TUPLE_AS_FRIEND_ public:
#else #else
#define GTEST_DECLARE_TUPLE_AS_FRIEND_ \ #define GTEST_DECLARE_TUPLE_AS_FRIEND_ \
template <GTEST_10_TYPENAMES_(U)> friend class tuple; \ template <GTEST_10_TYPENAMES_(U)> friend class tuple; \
private: private:
#endif #endif
// GTEST_n_TUPLE_(T) is the type of an n-tuple. // GTEST_n_TUPLE_(T) is the type of an n-tuple.
#define GTEST_0_TUPLE_(T) tuple<> #define GTEST_0_TUPLE_(T) tuple<>
#define GTEST_1_TUPLE_(T) tuple<T##0, void, void, void, void, void, void, \ #define GTEST_1_TUPLE_(T) tuple<T##0, void, void, void, void, void, void, \
skipping to change at line 186 skipping to change at line 187
tuple() {} tuple() {}
tuple(const tuple& /* t */) {} tuple(const tuple& /* t */) {}
tuple& operator=(const tuple& /* t */) { return *this; } tuple& operator=(const tuple& /* t */) { return *this; }
}; };
template <GTEST_1_TYPENAMES_(T)> template <GTEST_1_TYPENAMES_(T)>
class GTEST_1_TUPLE_(T) { class GTEST_1_TUPLE_(T) {
public: public:
template <int k> friend class gtest_internal::Get; template <int k> friend class gtest_internal::Get;
tuple() {} tuple() : f0_() {}
explicit tuple(GTEST_BY_REF_(T0) f0) : f0_(f0) {} explicit tuple(GTEST_BY_REF_(T0) f0) : f0_(f0) {}
tuple(const tuple& t) : f0_(t.f0_) {} tuple(const tuple& t) : f0_(t.f0_) {}
template <GTEST_1_TYPENAMES_(U)> template <GTEST_1_TYPENAMES_(U)>
tuple(const GTEST_1_TUPLE_(U)& t) : f0_(t.f0_) {} tuple(const GTEST_1_TUPLE_(U)& t) : f0_(t.f0_) {}
tuple& operator=(const tuple& t) { return CopyFrom(t); } tuple& operator=(const tuple& t) { return CopyFrom(t); }
skipping to change at line 218 skipping to change at line 219
} }
T0 f0_; T0 f0_;
}; };
template <GTEST_2_TYPENAMES_(T)> template <GTEST_2_TYPENAMES_(T)>
class GTEST_2_TUPLE_(T) { class GTEST_2_TUPLE_(T) {
public: public:
template <int k> friend class gtest_internal::Get; template <int k> friend class gtest_internal::Get;
tuple() {} tuple() : f0_(), f1_() {}
explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1) : f0_(f0), explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1) : f0_(f0),
f1_(f1) {} f1_(f1) {}
tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_) {} tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_) {}
template <GTEST_2_TYPENAMES_(U)> template <GTEST_2_TYPENAMES_(U)>
tuple(const GTEST_2_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_) {} tuple(const GTEST_2_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_) {}
template <typename U0, typename U1> template <typename U0, typename U1>
tuple(const ::std::pair<U0, U1>& p) : f0_(p.first), f1_(p.second) {} tuple(const ::std::pair<U0, U1>& p) : f0_(p.first), f1_(p.second) {}
skipping to change at line 261 skipping to change at line 262
T0 f0_; T0 f0_;
T1 f1_; T1 f1_;
}; };
template <GTEST_3_TYPENAMES_(T)> template <GTEST_3_TYPENAMES_(T)>
class GTEST_3_TUPLE_(T) { class GTEST_3_TUPLE_(T) {
public: public:
template <int k> friend class gtest_internal::Get; template <int k> friend class gtest_internal::Get;
tuple() {} tuple() : f0_(), f1_(), f2_() {}
explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
GTEST_BY_REF_(T2) f2) : f0_(f0), f1_(f1), f2_(f2) {} GTEST_BY_REF_(T2) f2) : f0_(f0), f1_(f1), f2_(f2) {}
tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {} tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {}
template <GTEST_3_TYPENAMES_(U)> template <GTEST_3_TYPENAMES_(U)>
tuple(const GTEST_3_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {} tuple(const GTEST_3_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {}
tuple& operator=(const tuple& t) { return CopyFrom(t); } tuple& operator=(const tuple& t) { return CopyFrom(t); }
skipping to change at line 298 skipping to change at line 299
T0 f0_; T0 f0_;
T1 f1_; T1 f1_;
T2 f2_; T2 f2_;
}; };
template <GTEST_4_TYPENAMES_(T)> template <GTEST_4_TYPENAMES_(T)>
class GTEST_4_TUPLE_(T) { class GTEST_4_TUPLE_(T) {
public: public:
template <int k> friend class gtest_internal::Get; template <int k> friend class gtest_internal::Get;
tuple() {} tuple() : f0_(), f1_(), f2_(), f3_() {}
explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3) : f0_(f0), f1_(f1), f2_(f 2), GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3) : f0_(f0), f1_(f1), f2_(f 2),
f3_(f3) {} f3_(f3) {}
tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_) {} tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_) {}
template <GTEST_4_TYPENAMES_(U)> template <GTEST_4_TYPENAMES_(U)>
tuple(const GTEST_4_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), tuple(const GTEST_4_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
f3_(t.f3_) {} f3_(t.f3_) {}
skipping to change at line 339 skipping to change at line 340
T1 f1_; T1 f1_;
T2 f2_; T2 f2_;
T3 f3_; T3 f3_;
}; };
template <GTEST_5_TYPENAMES_(T)> template <GTEST_5_TYPENAMES_(T)>
class GTEST_5_TUPLE_(T) { class GTEST_5_TUPLE_(T) {
public: public:
template <int k> friend class gtest_internal::Get; template <int k> friend class gtest_internal::Get;
tuple() {} tuple() : f0_(), f1_(), f2_(), f3_(), f4_() {}
explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3,
GTEST_BY_REF_(T4) f4) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4) { } GTEST_BY_REF_(T4) f4) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4) { }
tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
f4_(t.f4_) {} f4_(t.f4_) {}
template <GTEST_5_TYPENAMES_(U)> template <GTEST_5_TYPENAMES_(U)>
tuple(const GTEST_5_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), tuple(const GTEST_5_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
skipping to change at line 383 skipping to change at line 384
T2 f2_; T2 f2_;
T3 f3_; T3 f3_;
T4 f4_; T4 f4_;
}; };
template <GTEST_6_TYPENAMES_(T)> template <GTEST_6_TYPENAMES_(T)>
class GTEST_6_TUPLE_(T) { class GTEST_6_TUPLE_(T) {
public: public:
template <int k> friend class gtest_internal::Get; template <int k> friend class gtest_internal::Get;
tuple() {} tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_() {}
explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4, GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
GTEST_BY_REF_(T5) f5) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4), GTEST_BY_REF_(T5) f5) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
f5_(f5) {} f5_(f5) {}
tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
f4_(t.f4_), f5_(t.f5_) {} f4_(t.f4_), f5_(t.f5_) {}
template <GTEST_6_TYPENAMES_(U)> template <GTEST_6_TYPENAMES_(U)>
skipping to change at line 430 skipping to change at line 431
T3 f3_; T3 f3_;
T4 f4_; T4 f4_;
T5 f5_; T5 f5_;
}; };
template <GTEST_7_TYPENAMES_(T)> template <GTEST_7_TYPENAMES_(T)>
class GTEST_7_TUPLE_(T) { class GTEST_7_TUPLE_(T) {
public: public:
template <int k> friend class gtest_internal::Get; template <int k> friend class gtest_internal::Get;
tuple() {} tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_() {}
explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4, GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6) : f0_(f0), f1_(f1), f2_(f 2), GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6) : f0_(f0), f1_(f1), f2_(f 2),
f3_(f3), f4_(f4), f5_(f5), f6_(f6) {} f3_(f3), f4_(f4), f5_(f5), f6_(f6) {}
tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {} f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {}
template <GTEST_7_TYPENAMES_(U)> template <GTEST_7_TYPENAMES_(U)>
skipping to change at line 479 skipping to change at line 480
T4 f4_; T4 f4_;
T5 f5_; T5 f5_;
T6 f6_; T6 f6_;
}; };
template <GTEST_8_TYPENAMES_(T)> template <GTEST_8_TYPENAMES_(T)>
class GTEST_8_TUPLE_(T) { class GTEST_8_TUPLE_(T) {
public: public:
template <int k> friend class gtest_internal::Get; template <int k> friend class gtest_internal::Get;
tuple() {} tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_() {}
explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4, GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6,
GTEST_BY_REF_(T7) f7) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4), GTEST_BY_REF_(T7) f7) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
f5_(f5), f6_(f6), f7_(f7) {} f5_(f5), f6_(f6), f7_(f7) {}
tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {} f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {}
skipping to change at line 531 skipping to change at line 532
T5 f5_; T5 f5_;
T6 f6_; T6 f6_;
T7 f7_; T7 f7_;
}; };
template <GTEST_9_TYPENAMES_(T)> template <GTEST_9_TYPENAMES_(T)>
class GTEST_9_TUPLE_(T) { class GTEST_9_TUPLE_(T) {
public: public:
template <int k> friend class gtest_internal::Get; template <int k> friend class gtest_internal::Get;
tuple() {} tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_() { }
explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4, GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7, GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7,
GTEST_BY_REF_(T8) f8) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4), GTEST_BY_REF_(T8) f8) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
f5_(f5), f6_(f6), f7_(f7), f8_(f8) {} f5_(f5), f6_(f6), f7_(f7), f8_(f8) {}
tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_) {} f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_) {}
skipping to change at line 585 skipping to change at line 586
T6 f6_; T6 f6_;
T7 f7_; T7 f7_;
T8 f8_; T8 f8_;
}; };
template <GTEST_10_TYPENAMES_(T)> template <GTEST_10_TYPENAMES_(T)>
class tuple { class tuple {
public: public:
template <int k> friend class gtest_internal::Get; template <int k> friend class gtest_internal::Get;
tuple() {} tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_(),
f9_() {}
explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1, explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4, GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7, GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7,
GTEST_BY_REF_(T8) f8, GTEST_BY_REF_(T9) f9) : f0_(f0), f1_(f1), f2_(f 2), GTEST_BY_REF_(T8) f8, GTEST_BY_REF_(T9) f9) : f0_(f0), f1_(f1), f2_(f 2),
f3_(f3), f4_(f4), f5_(f5), f6_(f6), f7_(f7), f8_(f8), f9_(f9) {} f3_(f3), f4_(f4), f5_(f5), f6_(f6), f7_(f7), f8_(f8), f9_(f9) {}
tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_), tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_), f9_(t.f9_ ) {} f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_), f9_(t.f9_ ) {}
 End of changes. 11 change blocks. 
11 lines changed or deleted 13 lines changed or added


 gtest-type-util.h   gtest-type-util.h 
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! // This file was GENERATED by command:
// pump.py gtest-type-util.h.pump
// DO NOT EDIT BY HAND!!!
// Copyright 2008 Google Inc. // Copyright 2008 Google Inc.
// All Rights Reserved. // All Rights Reserved.
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
skipping to change at line 56 skipping to change at line 58
#include <gtest/internal/gtest-string.h> #include <gtest/internal/gtest-string.h>
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
// #ifdef __GNUC__ is too general here. It is possible to use gcc without using // #ifdef __GNUC__ is too general here. It is possible to use gcc without using
// libstdc++ (which is where cxxabi.h comes from). // libstdc++ (which is where cxxabi.h comes from).
#ifdef __GLIBCXX__ #ifdef __GLIBCXX__
#include <cxxabi.h> #include <cxxabi.h>
#endif // __GLIBCXX__ #endif // __GLIBCXX__
#include <typeinfo>
namespace testing { namespace testing {
namespace internal { namespace internal {
// AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same // AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
// type. This can be used as a compile-time assertion to ensure that // type. This can be used as a compile-time assertion to ensure that
// two types are equal. // two types are equal.
template <typename T1, typename T2> template <typename T1, typename T2>
struct AssertTypeEq; struct AssertTypeEq;
 End of changes. 2 change blocks. 
3 lines changed or deleted 3 lines changed or added


 gtest-typed-test.h   gtest-typed-test.h 
skipping to change at line 162 skipping to change at line 162
// Implements typed tests. // Implements typed tests.
#if GTEST_HAS_TYPED_TEST #if GTEST_HAS_TYPED_TEST
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
// //
// Expands to the name of the typedef for the type parameters of the // Expands to the name of the typedef for the type parameters of the
// given test case. // given test case.
#define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName## _ #define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName## _
// The 'Types' template argument below must have spaces around it
// since some compilers may choke on '>>' when passing a template
// instance (e.g. Types<int>)
#define TYPED_TEST_CASE(CaseName, Types) \ #define TYPED_TEST_CASE(CaseName, Types) \
typedef ::testing::internal::TypeList<Types>::type \ typedef ::testing::internal::TypeList< Types >::type \
GTEST_TYPE_PARAMS_(CaseName) GTEST_TYPE_PARAMS_(CaseName)
#define TYPED_TEST(CaseName, TestName) \ #define TYPED_TEST(CaseName, TestName) \
template <typename gtest_TypeParam_> \ template <typename gtest_TypeParam_> \
class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \ class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
: public CaseName<gtest_TypeParam_> { \ : public CaseName<gtest_TypeParam_> { \
private: \ private: \
typedef CaseName<gtest_TypeParam_> TestFixture; \ typedef CaseName<gtest_TypeParam_> TestFixture; \
typedef gtest_TypeParam_ TypeParam; \ typedef gtest_TypeParam_ TypeParam; \
virtual void TestBody(); \ virtual void TestBody(); \
skipping to change at line 244 skipping to change at line 247
void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBod y() void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBod y()
#define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \ #define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \
namespace GTEST_CASE_NAMESPACE_(CaseName) { \ namespace GTEST_CASE_NAMESPACE_(CaseName) { \
typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_ ; \ typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_ ; \
} \ } \
static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) = \ static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) = \
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames(\ GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames(\
__FILE__, __LINE__, #__VA_ARGS__) __FILE__, __LINE__, #__VA_ARGS__)
// The 'Types' template argument below must have spaces around it
// since some compilers may choke on '>>' when passing a template
// instance (e.g. Types<int>)
#define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \ #define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \
bool gtest_##Prefix##_##CaseName = \ bool gtest_##Prefix##_##CaseName = \
::testing::internal::TypeParameterizedTestCase<CaseName, \ ::testing::internal::TypeParameterizedTestCase<CaseName, \
GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \ GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \
::testing::internal::TypeList<Types>::type>::Register(\ ::testing::internal::TypeList< Types >::type>::Register(\
#Prefix, #CaseName, GTEST_REGISTERED_TEST_NAMES_(CaseName)) #Prefix, #CaseName, GTEST_REGISTERED_TEST_NAMES_(CaseName))
#endif // GTEST_HAS_TYPED_TEST_P #endif // GTEST_HAS_TYPED_TEST_P
#endif // GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_ #endif // GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
 End of changes. 4 change blocks. 
2 lines changed or deleted 8 lines changed or added


 gtest.h   gtest.h 
skipping to change at line 55 skipping to change at line 55
// program! // program!
// //
// Acknowledgment: Google Test borrowed the idea of automatic test // Acknowledgment: Google Test borrowed the idea of automatic test
// registration from Barthelemy Dagenais' (barthelemy@prologique.com) // registration from Barthelemy Dagenais' (barthelemy@prologique.com)
// easyUnit framework. // easyUnit framework.
#ifndef GTEST_INCLUDE_GTEST_GTEST_H_ #ifndef GTEST_INCLUDE_GTEST_GTEST_H_
#define GTEST_INCLUDE_GTEST_GTEST_H_ #define GTEST_INCLUDE_GTEST_GTEST_H_
#include <limits> #include <limits>
#include <vector>
#include <gtest/internal/gtest-internal.h> #include <gtest/internal/gtest-internal.h>
#include <gtest/internal/gtest-string.h> #include <gtest/internal/gtest-string.h>
#include <gtest/gtest-death-test.h> #include <gtest/gtest-death-test.h>
#include <gtest/gtest-message.h> #include <gtest/gtest-message.h>
#include <gtest/gtest-param-test.h> #include <gtest/gtest-param-test.h>
#include <gtest/gtest_prod.h> #include <gtest/gtest_prod.h>
#include <gtest/gtest-test-part.h> #include <gtest/gtest-test-part.h>
#include <gtest/gtest-typed-test.h> #include <gtest/gtest-typed-test.h>
// Depending on the platform, different string classes are available. // Depending on the platform, different string classes are available.
// On Windows, ::std::string compiles only when exceptions are // On Linux, in addition to ::std::string, Google also makes use of
// enabled. On Linux, in addition to ::std::string, Google also makes // class ::string, which has the same interface as ::std::string, but
// use of class ::string, which has the same interface as // has a different implementation.
// ::std::string, but has a different implementation.
// //
// The user can tell us whether ::std::string is available in his // The user can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
// environment by defining the macro GTEST_HAS_STD_STRING to either 1 // ::string is available AND is a distinct type to ::std::string, or
// or 0 on the compiler command line. He can also define // define it to 0 to indicate otherwise.
// GTEST_HAS_GLOBAL_STRING to 1 to indicate that ::string is available
// AND is a distinct type to ::std::string, or define it to 0 to
// indicate otherwise.
// //
// If the user's ::std::string and ::string are the same class due to // If the user's ::std::string and ::string are the same class due to
// aliasing, he should define GTEST_HAS_STD_STRING to 1 and // aliasing, he should define GTEST_HAS_GLOBAL_STRING to 0.
// GTEST_HAS_GLOBAL_STRING to 0.
// //
// If the user doesn't define GTEST_HAS_STD_STRING and/or // If the user doesn't define GTEST_HAS_GLOBAL_STRING, it is defined
// GTEST_HAS_GLOBAL_STRING, they are defined heuristically. // heuristically.
namespace testing { namespace testing {
// Declares the flags. // Declares the flags.
// This flag temporary enables the disabled tests. // This flag temporary enables the disabled tests.
GTEST_DECLARE_bool_(also_run_disabled_tests); GTEST_DECLARE_bool_(also_run_disabled_tests);
// This flag brings the debugger on an assertion failure. // This flag brings the debugger on an assertion failure.
GTEST_DECLARE_bool_(break_on_failure); GTEST_DECLARE_bool_(break_on_failure);
skipping to change at line 180 skipping to change at line 177
// compiler. // compiler.
template <typename T> template <typename T>
String StreamableToString(const T& streamable) { String StreamableToString(const T& streamable) {
return (Message() << streamable).GetString(); return (Message() << streamable).GetString();
} }
} // namespace internal } // namespace internal
// A class for indicating whether an assertion was successful. When // A class for indicating whether an assertion was successful. When
// the assertion wasn't successful, the AssertionResult object // the assertion wasn't successful, the AssertionResult object
// remembers a non-empty message that described how it failed. // remembers a non-empty message that describes how it failed.
//
// This class is useful for defining predicate-format functions to be
// used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
// //
// The constructor of AssertionResult is private. To create an // To create an instance of this class, use one of the factory functions
// instance of this class, use one of the factory functions
// (AssertionSuccess() and AssertionFailure()). // (AssertionSuccess() and AssertionFailure()).
// //
// For example, in order to be able to write: // This class is useful for two purposes:
// 1. Defining predicate functions to be used with Boolean test assertion
s
// EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
// 2. Defining predicate-format functions to be
// used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
//
// For example, if you define IsEven predicate:
//
// testing::AssertionResult IsEven(int n) {
// if ((n % 2) == 0)
// return testing::AssertionSuccess();
// else
// return testing::AssertionFailure() << n << " is odd";
// }
//
// Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
// will print the message
//
// Value of: IsEven(Fib(5))
// Actual: false (5 is odd)
// Expected: true
//
// instead of a more opaque
//
// Value of: IsEven(Fib(5))
// Actual: false
// Expected: true
//
// in case IsEven is a simple Boolean predicate.
//
// If you expect your predicate to be reused and want to support informativ
e
// messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
// about half as often as positive ones in our tests), supply messages for
// both success and failure cases:
//
// testing::AssertionResult IsEven(int n) {
// if ((n % 2) == 0)
// return testing::AssertionSuccess() << n << " is even";
// else
// return testing::AssertionFailure() << n << " is odd";
// }
//
// Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
//
// Value of: IsEven(Fib(6))
// Actual: true (8 is even)
// Expected: false
//
// NB: Predicates that support negative Boolean assertions have reduced
// performance in positive ones so be careful not to use them in tests
// that have lots (tens of thousands) of positive Boolean assertions.
//
// To use this class with EXPECT_PRED_FORMAT assertions such as:
// //
// // Verifies that Foo() returns an even number. // // Verifies that Foo() returns an even number.
// EXPECT_PRED_FORMAT1(IsEven, Foo()); // EXPECT_PRED_FORMAT1(IsEven, Foo());
// //
// you just need to define: // you need to define:
// //
// testing::AssertionResult IsEven(const char* expr, int n) { // testing::AssertionResult IsEven(const char* expr, int n) {
// if ((n % 2) == 0) return testing::AssertionSuccess(); // if ((n % 2) == 0)
// // return testing::AssertionSuccess();
// Message msg; // else
// msg << "Expected: " << expr << " is even\n" // return testing::AssertionFailure()
// << " Actual: it's " << n; // << "Expected: " << expr << " is even\n Actual: it's " << n;
// return testing::AssertionFailure(msg);
// } // }
// //
// If Foo() returns 5, you will see the following message: // If Foo() returns 5, you will see the following message:
// //
// Expected: Foo() is even // Expected: Foo() is even
// Actual: it's 5 // Actual: it's 5
class AssertionResult { //
class GTEST_API_ AssertionResult {
public: public:
// Declares factory functions for making successful and failed // Copy constructor.
// assertion results as friends. // Used in EXPECT_TRUE/FALSE(assertion_result).
friend AssertionResult AssertionSuccess(); AssertionResult(const AssertionResult& other);
friend AssertionResult AssertionFailure(const Message&); // Used in the EXPECT_TRUE/FALSE(bool_expression).
explicit AssertionResult(bool success) : success_(success) {}
// Returns true iff the assertion succeeded. // Returns true iff the assertion succeeded.
operator bool() const { return failure_message_.c_str() == NULL; } // NO LINT operator bool() const { return success_; } // NOLINT
// Returns the assertion's failure message. // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
const char* failure_message() const { return failure_message_.c_str(); } AssertionResult operator!() const;
// Returns the text streamed into this AssertionResult. Test assertions
// use it when they fail (i.e., the predicate's outcome doesn't match the
// assertion's expectation). When nothing has been streamed into the
// object, returns an empty string.
const char* message() const {
return message_.get() != NULL && message_->c_str() != NULL ?
message_->c_str() : "";
}
// TODO(vladl@google.com): Remove this after making sure no clients use i
t.
// Deprecated; please use message() instead.
const char* failure_message() const { return message(); }
// Streams a custom failure message into this object.
template <typename T> AssertionResult& operator<<(const T& value);
private: private:
// The default constructor. It is used when the assertion succeeded. // No implementation - we want AssertionResult to be
AssertionResult() {} // copy-constructible but not assignable.
void operator=(const AssertionResult& other);
// The constructor used when the assertion failed. // Stores result of the assertion predicate.
explicit AssertionResult(const internal::String& failure_message); bool success_;
// Stores the message describing the condition in case the expectation
// construct is not satisfied with the predicate's outcome.
// Referenced via a pointer to avoid taking too much stack frame space
// with test assertions.
internal::scoped_ptr<internal::String> message_;
}; // class AssertionResult
// Stores the assertion's failure message. // Streams a custom failure message into this object.
internal::String failure_message_; template <typename T>
}; AssertionResult& AssertionResult::operator<<(const T& value) {
Message msg;
if (message_.get() != NULL)
msg << *message_;
msg << value;
message_.reset(new internal::String(msg.GetString()));
return *this;
}
// Makes a successful assertion result. // Makes a successful assertion result.
AssertionResult AssertionSuccess(); GTEST_API_ AssertionResult AssertionSuccess();
// Makes a failed assertion result.
GTEST_API_ AssertionResult AssertionFailure();
// Makes a failed assertion result with the given failure message. // Makes a failed assertion result with the given failure message.
AssertionResult AssertionFailure(const Message& msg); // Deprecated; use AssertionFailure() << msg.
GTEST_API_ AssertionResult AssertionFailure(const Message& msg);
// The abstract class that all tests inherit from. // The abstract class that all tests inherit from.
// //
// In Google Test, a unit test program contains one or many TestCases, and // In Google Test, a unit test program contains one or many TestCases, and
// each TestCase contains one or many Tests. // each TestCase contains one or many Tests.
// //
// When you define a test using the TEST macro, you don't need to // When you define a test using the TEST macro, you don't need to
// explicitly derive from Test - the TEST macro automatically does // explicitly derive from Test - the TEST macro automatically does
// this for you. // this for you.
// //
skipping to change at line 262 skipping to change at line 341
// protected: // protected:
// virtual void SetUp() { ... } // virtual void SetUp() { ... }
// virtual void TearDown() { ... } // virtual void TearDown() { ... }
// ... // ...
// }; // };
// //
// TEST_F(FooTest, Bar) { ... } // TEST_F(FooTest, Bar) { ... }
// TEST_F(FooTest, Baz) { ... } // TEST_F(FooTest, Baz) { ... }
// //
// Test is not copyable. // Test is not copyable.
class Test { class GTEST_API_ Test {
public: public:
friend class internal::TestInfoImpl; friend class internal::TestInfoImpl;
// Defines types for pointers to functions that set up and tear down // Defines types for pointers to functions that set up and tear down
// a test case. // a test case.
typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc; typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc; typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
// The d'tor is virtual as we intend to inherit from Test. // The d'tor is virtual as we intend to inherit from Test.
virtual ~Test(); virtual ~Test();
skipping to change at line 378 skipping to change at line 457
// A copyable object representing a user specified test property which can be // A copyable object representing a user specified test property which can be
// output as a key/value string pair. // output as a key/value string pair.
// //
// Don't inherit from TestProperty as its destructor is not virtual. // Don't inherit from TestProperty as its destructor is not virtual.
class TestProperty { class TestProperty {
public: public:
// C'tor. TestProperty does NOT have a default constructor. // C'tor. TestProperty does NOT have a default constructor.
// Always use this constructor (with parameters) to create a // Always use this constructor (with parameters) to create a
// TestProperty object. // TestProperty object.
TestProperty(const char* key, const char* value) : TestProperty(const char* a_key, const char* a_value) :
key_(key), value_(value) { key_(a_key), value_(a_value) {
} }
// Gets the user supplied key. // Gets the user supplied key.
const char* key() const { const char* key() const {
return key_.c_str(); return key_.c_str();
} }
// Gets the user supplied value. // Gets the user supplied value.
const char* value() const { const char* value() const {
return value_.c_str(); return value_.c_str();
skipping to change at line 410 skipping to change at line 489
// The value supplied by the user. // The value supplied by the user.
internal::String value_; internal::String value_;
}; };
// The result of a single Test. This includes a list of // The result of a single Test. This includes a list of
// TestPartResults, a list of TestProperties, a count of how many // TestPartResults, a list of TestProperties, a count of how many
// death tests there are in the Test, and how much time it took to run // death tests there are in the Test, and how much time it took to run
// the Test. // the Test.
// //
// TestResult is not copyable. // TestResult is not copyable.
class TestResult { class GTEST_API_ TestResult {
public: public:
// Creates an empty TestResult. // Creates an empty TestResult.
TestResult(); TestResult();
// D'tor. Do not inherit from TestResult. // D'tor. Do not inherit from TestResult.
~TestResult(); ~TestResult();
// Gets the number of all test parts. This is the sum of the number // Gets the number of all test parts. This is the sum of the number
// of successful test parts and the number of failed test parts. // of successful test parts and the number of failed test parts.
int total_part_count() const; int total_part_count() const;
skipping to change at line 461 skipping to change at line 540
friend class TestInfo; friend class TestInfo;
friend class UnitTest; friend class UnitTest;
friend class internal::DefaultGlobalTestPartResultReporter; friend class internal::DefaultGlobalTestPartResultReporter;
friend class internal::ExecDeathTest; friend class internal::ExecDeathTest;
friend class internal::TestInfoImpl; friend class internal::TestInfoImpl;
friend class internal::TestResultAccessor; friend class internal::TestResultAccessor;
friend class internal::UnitTestImpl; friend class internal::UnitTestImpl;
friend class internal::WindowsDeathTest; friend class internal::WindowsDeathTest;
// Gets the vector of TestPartResults. // Gets the vector of TestPartResults.
const internal::Vector<TestPartResult>& test_part_results() const { const std::vector<TestPartResult>& test_part_results() const {
return *test_part_results_; return test_part_results_;
} }
// Gets the vector of TestProperties. // Gets the vector of TestProperties.
const internal::Vector<TestProperty>& test_properties() const { const std::vector<TestProperty>& test_properties() const {
return *test_properties_; return test_properties_;
} }
// Sets the elapsed time. // Sets the elapsed time.
void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; } void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
// Adds a test property to the list. The property is validated and may ad d // Adds a test property to the list. The property is validated and may ad d
// a non-fatal failure if invalid (e.g., if it conflicts with reserved // a non-fatal failure if invalid (e.g., if it conflicts with reserved
// key names). If a property is already recorded for the same key, the // key names). If a property is already recorded for the same key, the
// value will be updated, rather than storing multiple values for the sam e // value will be updated, rather than storing multiple values for the sam e
// key. // key.
skipping to change at line 505 skipping to change at line 584
void ClearTestPartResults(); void ClearTestPartResults();
// Clears the object. // Clears the object.
void Clear(); void Clear();
// Protects mutable state of the property vector and of owned // Protects mutable state of the property vector and of owned
// properties, whose values may be updated. // properties, whose values may be updated.
internal::Mutex test_properites_mutex_; internal::Mutex test_properites_mutex_;
// The vector of TestPartResults // The vector of TestPartResults
internal::scoped_ptr<internal::Vector<TestPartResult> > test_part_results _; std::vector<TestPartResult> test_part_results_;
// The vector of TestProperties // The vector of TestProperties
internal::scoped_ptr<internal::Vector<TestProperty> > test_properties_; std::vector<TestProperty> test_properties_;
// Running count of death tests. // Running count of death tests.
int death_test_count_; int death_test_count_;
// The elapsed time, in milliseconds. // The elapsed time, in milliseconds.
TimeInMillis elapsed_time_; TimeInMillis elapsed_time_;
// We disallow copying TestResult. // We disallow copying TestResult.
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult); GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
}; // class TestResult }; // class TestResult
// A TestInfo object stores the following information about a test: // A TestInfo object stores the following information about a test:
// //
// Test case name // Test case name
// Test name // Test name
// Whether the test should be run // Whether the test should be run
// A function pointer that creates the test object when invoked // A function pointer that creates the test object when invoked
// Test result // Test result
// //
// The constructor of TestInfo registers itself with the UnitTest // The constructor of TestInfo registers itself with the UnitTest
// singleton such that the RUN_ALL_TESTS() macro knows which tests to // singleton such that the RUN_ALL_TESTS() macro knows which tests to
// run. // run.
class TestInfo { class GTEST_API_ TestInfo {
public: public:
// Destructs a TestInfo object. This function is not virtual, so // Destructs a TestInfo object. This function is not virtual, so
// don't inherit from TestInfo. // don't inherit from TestInfo.
~TestInfo(); ~TestInfo();
// Returns the test case name. // Returns the test case name.
const char* test_case_name() const; const char* test_case_name() const;
// Returns the test name. // Returns the test name.
const char* name() const; const char* name() const;
skipping to change at line 610 skipping to change at line 689
// An opaque implementation object. // An opaque implementation object.
internal::TestInfoImpl* impl_; internal::TestInfoImpl* impl_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo); GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
}; };
// A test case, which consists of a vector of TestInfos. // A test case, which consists of a vector of TestInfos.
// //
// TestCase is not copyable. // TestCase is not copyable.
class TestCase { class GTEST_API_ TestCase {
public: public:
// Creates a TestCase with the given name. // Creates a TestCase with the given name.
// //
// TestCase does NOT have a default constructor. Always use this // TestCase does NOT have a default constructor. Always use this
// constructor to create a TestCase object. // constructor to create a TestCase object.
// //
// Arguments: // Arguments:
// //
// name: name of the test case // name: name of the test case
// set_up_tc: pointer to the function that sets up the test case // set_up_tc: pointer to the function that sets up the test case
skipping to change at line 671 skipping to change at line 750
// Returns the i-th test among all the tests. i can range from 0 to // Returns the i-th test among all the tests. i can range from 0 to
// total_test_count() - 1. If i is not in that range, returns NULL. // total_test_count() - 1. If i is not in that range, returns NULL.
const TestInfo* GetTestInfo(int i) const; const TestInfo* GetTestInfo(int i) const;
private: private:
friend class Test; friend class Test;
friend class internal::UnitTestImpl; friend class internal::UnitTestImpl;
// Gets the (mutable) vector of TestInfos in this TestCase. // Gets the (mutable) vector of TestInfos in this TestCase.
internal::Vector<TestInfo*>& test_info_list() { return *test_info_list_; } std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
// Gets the (immutable) vector of TestInfos in this TestCase. // Gets the (immutable) vector of TestInfos in this TestCase.
const internal::Vector<TestInfo *> & test_info_list() const { const std::vector<TestInfo*>& test_info_list() const {
return *test_info_list_; return test_info_list_;
} }
// Returns the i-th test among all the tests. i can range from 0 to // Returns the i-th test among all the tests. i can range from 0 to
// total_test_count() - 1. If i is not in that range, returns NULL. // total_test_count() - 1. If i is not in that range, returns NULL.
TestInfo* GetMutableTestInfo(int i); TestInfo* GetMutableTestInfo(int i);
// Sets the should_run member. // Sets the should_run member.
void set_should_run(bool should) { should_run_ = should; } void set_should_run(bool should) { should_run_ = should; }
// Adds a TestInfo to this test case. Will delete the TestInfo upon // Adds a TestInfo to this test case. Will delete the TestInfo upon
skipping to change at line 724 skipping to change at line 803
// Restores the test order to before the first shuffle. // Restores the test order to before the first shuffle.
void UnshuffleTests(); void UnshuffleTests();
// Name of the test case. // Name of the test case.
internal::String name_; internal::String name_;
// Comment on the test case. // Comment on the test case.
internal::String comment_; internal::String comment_;
// The vector of TestInfos in their original order. It owns the // The vector of TestInfos in their original order. It owns the
// elements in the vector. // elements in the vector.
const internal::scoped_ptr<internal::Vector<TestInfo*> > test_info_list_; std::vector<TestInfo*> test_info_list_;
// Provides a level of indirection for the test list to allow easy // Provides a level of indirection for the test list to allow easy
// shuffling and restoring the test order. The i-th element in this // shuffling and restoring the test order. The i-th element in this
// vector is the index of the i-th test in the shuffled test list. // vector is the index of the i-th test in the shuffled test list.
const internal::scoped_ptr<internal::Vector<int> > test_indices_; std::vector<int> test_indices_;
// Pointer to the function that sets up the test case. // Pointer to the function that sets up the test case.
Test::SetUpTestCaseFunc set_up_tc_; Test::SetUpTestCaseFunc set_up_tc_;
// Pointer to the function that tears down the test case. // Pointer to the function that tears down the test case.
Test::TearDownTestCaseFunc tear_down_tc_; Test::TearDownTestCaseFunc tear_down_tc_;
// True iff any test in this test case should run. // True iff any test in this test case should run.
bool should_run_; bool should_run_;
// Elapsed time, in milliseconds. // Elapsed time, in milliseconds.
TimeInMillis elapsed_time_; TimeInMillis elapsed_time_;
// We disallow copying TestCases. // We disallow copying TestCases.
skipping to change at line 848 skipping to change at line 927
virtual void OnTestEnd(const TestInfo& /*test_info*/) {} virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {} virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) { } virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) { }
virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {} virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/, virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
int /*iteration*/) {} int /*iteration*/) {}
virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {} virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
}; };
// TestEventListeners lets users add listeners to track events in Google Te st. // TestEventListeners lets users add listeners to track events in Google Te st.
class TestEventListeners { class GTEST_API_ TestEventListeners {
public: public:
TestEventListeners(); TestEventListeners();
~TestEventListeners(); ~TestEventListeners();
// Appends an event listener to the end of the list. Google Test assumes // Appends an event listener to the end of the list. Google Test assumes
// the ownership of the listener (i.e. it will delete the listener when // the ownership of the listener (i.e. it will delete the listener when
// the test program finishes). // the test program finishes).
void Append(TestEventListener* listener); void Append(TestEventListener* listener);
// Removes the given event listener from the list and returns it. It the n // Removes the given event listener from the list and returns it. It the n
skipping to change at line 935 skipping to change at line 1014
// A UnitTest consists of a vector of TestCases. // A UnitTest consists of a vector of TestCases.
// //
// This is a singleton class. The only instance of UnitTest is // This is a singleton class. The only instance of UnitTest is
// created when UnitTest::GetInstance() is first called. This // created when UnitTest::GetInstance() is first called. This
// instance is never deleted. // instance is never deleted.
// //
// UnitTest is not copyable. // UnitTest is not copyable.
// //
// This class is thread-safe as long as the methods are called // This class is thread-safe as long as the methods are called
// according to their specification. // according to their specification.
class UnitTest { class GTEST_API_ UnitTest {
public: public:
// Gets the singleton UnitTest object. The first time this method // Gets the singleton UnitTest object. The first time this method
// is called, a UnitTest object is constructed and returned. // is called, a UnitTest object is constructed and returned.
// Consecutive calls will return the same object. // Consecutive calls will return the same object.
static UnitTest* GetInstance(); static UnitTest* GetInstance();
// Runs all tests in this UnitTest object and prints the result. // Runs all tests in this UnitTest object and prints the result.
// Returns 0 if successful, or 1 otherwise. // Returns 0 if successful, or 1 otherwise.
// //
// This method can only be called from the main thread. // This method can only be called from the main thread.
skipping to change at line 1122 skipping to change at line 1201
// Initializes Google Test. This must be called before calling // Initializes Google Test. This must be called before calling
// RUN_ALL_TESTS(). In particular, it parses a command line for the // RUN_ALL_TESTS(). In particular, it parses a command line for the
// flags that Google Test recognizes. Whenever a Google Test flag is // flags that Google Test recognizes. Whenever a Google Test flag is
// seen, it is removed from argv, and *argc is decremented. // seen, it is removed from argv, and *argc is decremented.
// //
// No value is returned. Instead, the Google Test flag variables are // No value is returned. Instead, the Google Test flag variables are
// updated. // updated.
// //
// Calling the function for the second time has no user-visible effect. // Calling the function for the second time has no user-visible effect.
void InitGoogleTest(int* argc, char** argv); GTEST_API_ void InitGoogleTest(int* argc, char** argv);
// This overloaded version can be used in Windows programs compiled in // This overloaded version can be used in Windows programs compiled in
// UNICODE mode. // UNICODE mode.
void InitGoogleTest(int* argc, wchar_t** argv); GTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
namespace internal { namespace internal {
// These overloaded versions handle ::std::string and ::std::wstring. // These overloaded versions handle ::std::string and ::std::wstring.
#if GTEST_HAS_STD_STRING GTEST_API_ inline String FormatForFailureMessage(const ::std::string& str)
inline String FormatForFailureMessage(const ::std::string& str) { {
return (Message() << '"' << str << '"').GetString(); return (Message() << '"' << str << '"').GetString();
} }
#endif // GTEST_HAS_STD_STRING
#if GTEST_HAS_STD_WSTRING #if GTEST_HAS_STD_WSTRING
inline String FormatForFailureMessage(const ::std::wstring& wstr) { GTEST_API_ inline String FormatForFailureMessage(const ::std::wstring& wstr ) {
return (Message() << "L\"" << wstr << '"').GetString(); return (Message() << "L\"" << wstr << '"').GetString();
} }
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
// These overloaded versions handle ::string and ::wstring. // These overloaded versions handle ::string and ::wstring.
#if GTEST_HAS_GLOBAL_STRING #if GTEST_HAS_GLOBAL_STRING
inline String FormatForFailureMessage(const ::string& str) { GTEST_API_ inline String FormatForFailureMessage(const ::string& str) {
return (Message() << '"' << str << '"').GetString(); return (Message() << '"' << str << '"').GetString();
} }
#endif // GTEST_HAS_GLOBAL_STRING #endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_GLOBAL_WSTRING #if GTEST_HAS_GLOBAL_WSTRING
inline String FormatForFailureMessage(const ::wstring& wstr) { GTEST_API_ inline String FormatForFailureMessage(const ::wstring& wstr) {
return (Message() << "L\"" << wstr << '"').GetString(); return (Message() << "L\"" << wstr << '"').GetString();
} }
#endif // GTEST_HAS_GLOBAL_WSTRING #endif // GTEST_HAS_GLOBAL_WSTRING
// Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc) // Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
// operand to be used in a failure message. The type (but not value) // operand to be used in a failure message. The type (but not value)
// of the other operand may affect the format. This allows us to // of the other operand may affect the format. This allows us to
// print a char* as a raw pointer when it is compared against another // print a char* as a raw pointer when it is compared against another
// char*, and print it as a C string when it is compared against an // char*, and print it as a C string when it is compared against an
// std::string object, for example. // std::string object, for example.
skipping to change at line 1204 skipping to change at line 1281
return EqFailure(expected_expression, return EqFailure(expected_expression,
actual_expression, actual_expression,
FormatForComparisonFailureMessage(expected, actual), FormatForComparisonFailureMessage(expected, actual),
FormatForComparisonFailureMessage(actual, expected), FormatForComparisonFailureMessage(actual, expected),
false); false);
} }
// With this overloaded version, we allow anonymous enums to be used // With this overloaded version, we allow anonymous enums to be used
// in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
// can be implicitly cast to BiggestInt. // can be implicitly cast to BiggestInt.
AssertionResult CmpHelperEQ(const char* expected_expression, GTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression,
const char* actual_expression, const char* actual_expression,
BiggestInt expected, BiggestInt expected,
BiggestInt actual); BiggestInt actual);
// The helper class for {ASSERT|EXPECT}_EQ. The template argument // The helper class for {ASSERT|EXPECT}_EQ. The template argument
// lhs_is_null_literal is true iff the first argument to ASSERT_EQ() // lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
// is a null pointer literal. The following default implementation is // is a null pointer literal. The following default implementation is
// for lhs_is_null_literal being false. // for lhs_is_null_literal being false.
template <bool lhs_is_null_literal> template <bool lhs_is_null_literal>
class EqHelper { class EqHelper {
public: public:
// This templatized version is for the general case. // This templatized version is for the general case.
template <typename T1, typename T2> template <typename T1, typename T2>
skipping to change at line 1296 skipping to change at line 1373
if (val1 op val2) {\ if (val1 op val2) {\
return AssertionSuccess();\ return AssertionSuccess();\
} else {\ } else {\
Message msg;\ Message msg;\
msg << "Expected: (" << expr1 << ") " #op " (" << expr2\ msg << "Expected: (" << expr1 << ") " #op " (" << expr2\
<< "), actual: " << FormatForComparisonFailureMessage(val1, val2)\ << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
<< " vs " << FormatForComparisonFailureMessage(val2, val1);\ << " vs " << FormatForComparisonFailureMessage(val2, val1);\
return AssertionFailure(msg);\ return AssertionFailure(msg);\
}\ }\
}\ }\
AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ GTEST_API_ AssertionResult CmpHelper##op_name(\
BiggestInt val1, BiggestInt val2); const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
// Implements the helper function for {ASSERT|EXPECT}_NE // Implements the helper function for {ASSERT|EXPECT}_NE
GTEST_IMPL_CMP_HELPER_(NE, !=) GTEST_IMPL_CMP_HELPER_(NE, !=);
// Implements the helper function for {ASSERT|EXPECT}_LE // Implements the helper function for {ASSERT|EXPECT}_LE
GTEST_IMPL_CMP_HELPER_(LE, <=) GTEST_IMPL_CMP_HELPER_(LE, <=);
// Implements the helper function for {ASSERT|EXPECT}_LT // Implements the helper function for {ASSERT|EXPECT}_LT
GTEST_IMPL_CMP_HELPER_(LT, < ) GTEST_IMPL_CMP_HELPER_(LT, < );
// Implements the helper function for {ASSERT|EXPECT}_GE // Implements the helper function for {ASSERT|EXPECT}_GE
GTEST_IMPL_CMP_HELPER_(GE, >=) GTEST_IMPL_CMP_HELPER_(GE, >=);
// Implements the helper function for {ASSERT|EXPECT}_GT // Implements the helper function for {ASSERT|EXPECT}_GT
GTEST_IMPL_CMP_HELPER_(GT, > ) GTEST_IMPL_CMP_HELPER_(GT, > );
#undef GTEST_IMPL_CMP_HELPER_ #undef GTEST_IMPL_CMP_HELPER_
// The helper function for {ASSERT|EXPECT}_STREQ. // The helper function for {ASSERT|EXPECT}_STREQ.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
AssertionResult CmpHelperSTREQ(const char* expected_expression, GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
const char* actual_expression, const char* actual_expression,
const char* expected, const char* expected,
const char* actual); const char* actual);
// The helper function for {ASSERT|EXPECT}_STRCASEEQ. // The helper function for {ASSERT|EXPECT}_STRCASEEQ.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression, GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expressi
const char* actual_expression, on,
const char* expected, const char* actual_expression
const char* actual); ,
const char* expected,
const char* actual);
// The helper function for {ASSERT|EXPECT}_STRNE. // The helper function for {ASSERT|EXPECT}_STRNE.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
AssertionResult CmpHelperSTRNE(const char* s1_expression, GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
const char* s2_expression, const char* s2_expression,
const char* s1, const char* s1,
const char* s2); const char* s2);
// The helper function for {ASSERT|EXPECT}_STRCASENE. // The helper function for {ASSERT|EXPECT}_STRCASENE.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
AssertionResult CmpHelperSTRCASENE(const char* s1_expression, GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
const char* s2_expression, const char* s2_expression,
const char* s1, const char* s1,
const char* s2); const char* s2);
// Helper function for *_STREQ on wide strings. // Helper function for *_STREQ on wide strings.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
AssertionResult CmpHelperSTREQ(const char* expected_expression, GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
const char* actual_expression, const char* actual_expression,
const wchar_t* expected, const wchar_t* expected,
const wchar_t* actual); const wchar_t* actual);
// Helper function for *_STRNE on wide strings. // Helper function for *_STRNE on wide strings.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
AssertionResult CmpHelperSTRNE(const char* s1_expression, GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
const char* s2_expression, const char* s2_expression,
const wchar_t* s1, const wchar_t* s1,
const wchar_t* s2); const wchar_t* s2);
} // namespace internal } // namespace internal
// IsSubstring() and IsNotSubstring() are intended to be used as the // IsSubstring() and IsNotSubstring() are intended to be used as the
// first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by // first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
// themselves. They check whether needle is a substring of haystack // themselves. They check whether needle is a substring of haystack
// (NULL is considered a substring of itself only), and return an // (NULL is considered a substring of itself only), and return an
// appropriate error message when they fail. // appropriate error message when they fail.
// //
// The {needle,haystack}_expr arguments are the stringified // The {needle,haystack}_expr arguments are the stringified
// expressions that generated the two real arguments. // expressions that generated the two real arguments.
AssertionResult IsSubstring( GTEST_API_ AssertionResult IsSubstring(
const char* needle_expr, const char* haystack_expr, const char* needle_expr, const char* haystack_expr,
const char* needle, const char* haystack); const char* needle, const char* haystack);
AssertionResult IsSubstring( GTEST_API_ AssertionResult IsSubstring(
const char* needle_expr, const char* haystack_expr, const char* needle_expr, const char* haystack_expr,
const wchar_t* needle, const wchar_t* haystack); const wchar_t* needle, const wchar_t* haystack);
AssertionResult IsNotSubstring( GTEST_API_ AssertionResult IsNotSubstring(
const char* needle_expr, const char* haystack_expr, const char* needle_expr, const char* haystack_expr,
const char* needle, const char* haystack); const char* needle, const char* haystack);
AssertionResult IsNotSubstring( GTEST_API_ AssertionResult IsNotSubstring(
const char* needle_expr, const char* haystack_expr, const char* needle_expr, const char* haystack_expr,
const wchar_t* needle, const wchar_t* haystack); const wchar_t* needle, const wchar_t* haystack);
#if GTEST_HAS_STD_STRING GTEST_API_ AssertionResult IsSubstring(
AssertionResult IsSubstring(
const char* needle_expr, const char* haystack_expr, const char* needle_expr, const char* haystack_expr,
const ::std::string& needle, const ::std::string& haystack); const ::std::string& needle, const ::std::string& haystack);
AssertionResult IsNotSubstring( GTEST_API_ AssertionResult IsNotSubstring(
const char* needle_expr, const char* haystack_expr, const char* needle_expr, const char* haystack_expr,
const ::std::string& needle, const ::std::string& haystack); const ::std::string& needle, const ::std::string& haystack);
#endif // GTEST_HAS_STD_STRING
#if GTEST_HAS_STD_WSTRING #if GTEST_HAS_STD_WSTRING
AssertionResult IsSubstring( GTEST_API_ AssertionResult IsSubstring(
const char* needle_expr, const char* haystack_expr, const char* needle_expr, const char* haystack_expr,
const ::std::wstring& needle, const ::std::wstring& haystack); const ::std::wstring& needle, const ::std::wstring& haystack);
AssertionResult IsNotSubstring( GTEST_API_ AssertionResult IsNotSubstring(
const char* needle_expr, const char* haystack_expr, const char* needle_expr, const char* haystack_expr,
const ::std::wstring& needle, const ::std::wstring& haystack); const ::std::wstring& needle, const ::std::wstring& haystack);
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
namespace internal { namespace internal {
// Helper template function for comparing floating-points. // Helper template function for comparing floating-points.
// //
// Template parameter: // Template parameter:
// //
skipping to change at line 1440 skipping to change at line 1515
return EqFailure(expected_expression, return EqFailure(expected_expression,
actual_expression, actual_expression,
StrStreamToString(&expected_ss), StrStreamToString(&expected_ss),
StrStreamToString(&actual_ss), StrStreamToString(&actual_ss),
false); false);
} }
// Helper function for implementing ASSERT_NEAR. // Helper function for implementing ASSERT_NEAR.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
AssertionResult DoubleNearPredFormat(const char* expr1, GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
const char* expr2, const char* expr2,
const char* abs_error_expr, const char* abs_error_expr,
double val1, double val1,
double val2, double val2,
double abs_error); double abs_error);
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
// A class that enables one to stream messages to assertion macros // A class that enables one to stream messages to assertion macros
class AssertHelper { class GTEST_API_ AssertHelper {
public: public:
// Constructor. // Constructor.
AssertHelper(TestPartResult::Type type, AssertHelper(TestPartResult::Type type,
const char* file, const char* file,
int line, int line,
const char* message); const char* message);
~AssertHelper(); ~AssertHelper();
// Message assignment is a semantic trick to enable assertion // Message assignment is a semantic trick to enable assertion
// streaming; see the GTEST_MESSAGE_ macro below. // streaming; see the GTEST_MESSAGE_ macro below.
skipping to change at line 1578 skipping to change at line 1653
// Examples: // Examples:
// //
// EXPECT_TRUE(server.StatusIsOK()); // EXPECT_TRUE(server.StatusIsOK());
// ASSERT_FALSE(server.HasPendingRequest(port)) // ASSERT_FALSE(server.HasPendingRequest(port))
// << "There are still pending requests " << "on port " << port; // << "There are still pending requests " << "on port " << port;
// Generates a nonfatal failure with a generic message. // Generates a nonfatal failure with a generic message.
#define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed") #define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
// Generates a fatal failure with a generic message. // Generates a fatal failure with a generic message.
#define FAIL() GTEST_FATAL_FAILURE_("Failed") #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
// Define this macro to 1 to omit the definition of FAIL(), which is a
// generic name and clashes with some other libraries.
#if !GTEST_DONT_DEFINE_FAIL
#define FAIL() GTEST_FAIL()
#endif
// Generates a success with a generic message. // Generates a success with a generic message.
#define SUCCEED() GTEST_SUCCESS_("Succeeded") #define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
// Define this macro to 1 to omit the definition of SUCCEED(), which
// is a generic name and clashes with some other libraries.
#if !GTEST_DONT_DEFINE_SUCCEED
#define SUCCEED() GTEST_SUCCEED()
#endif
// Macros for testing exceptions. // Macros for testing exceptions.
// //
// * {ASSERT|EXPECT}_THROW(statement, expected_exception): // * {ASSERT|EXPECT}_THROW(statement, expected_exception):
// Tests that the statement throws the expected exception. // Tests that the statement throws the expected exception.
// * {ASSERT|EXPECT}_NO_THROW(statement): // * {ASSERT|EXPECT}_NO_THROW(statement):
// Tests that the statement doesn't throw any exception. // Tests that the statement doesn't throw any exception.
// * {ASSERT|EXPECT}_ANY_THROW(statement): // * {ASSERT|EXPECT}_ANY_THROW(statement):
// Tests that the statement throws an exception. // Tests that the statement throws an exception.
skipping to change at line 1605 skipping to change at line 1692
GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_) GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
#define EXPECT_ANY_THROW(statement) \ #define EXPECT_ANY_THROW(statement) \
GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_) GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
#define ASSERT_THROW(statement, expected_exception) \ #define ASSERT_THROW(statement, expected_exception) \
GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_) GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
#define ASSERT_NO_THROW(statement) \ #define ASSERT_NO_THROW(statement) \
GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_) GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
#define ASSERT_ANY_THROW(statement) \ #define ASSERT_ANY_THROW(statement) \
GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_) GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
// Boolean assertions. // Boolean assertions. Condition can be either a Boolean expression or an
// AssertionResult. For more information on how to use AssertionResult with
// these macros see comments on that class.
#define EXPECT_TRUE(condition) \ #define EXPECT_TRUE(condition) \
GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
GTEST_NONFATAL_FAILURE_) GTEST_NONFATAL_FAILURE_)
#define EXPECT_FALSE(condition) \ #define EXPECT_FALSE(condition) \
GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
GTEST_NONFATAL_FAILURE_) GTEST_NONFATAL_FAILURE_)
#define ASSERT_TRUE(condition) \ #define ASSERT_TRUE(condition) \
GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \ GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
GTEST_FATAL_FAILURE_) GTEST_FATAL_FAILURE_)
#define ASSERT_FALSE(condition) \ #define ASSERT_FALSE(condition) \
skipping to change at line 1778 skipping to change at line 1867
ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \ ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
val1, val2, abs_error) val1, val2, abs_error)
// These predicate format functions work on floating-point values, and // These predicate format functions work on floating-point values, and
// can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g. // can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
// //
// EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0); // EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
// Asserts that val1 is less than, or almost equal to, val2. Fails // Asserts that val1 is less than, or almost equal to, val2. Fails
// otherwise. In particular, it fails if either val1 or val2 is NaN. // otherwise. In particular, it fails if either val1 or val2 is NaN.
AssertionResult FloatLE(const char* expr1, const char* expr2, GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
float val1, float val2); float val1, float val2);
AssertionResult DoubleLE(const char* expr1, const char* expr2, GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
double val1, double val2); double val1, double val2);
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// Macros that test for HRESULT failure and success, these are only useful // Macros that test for HRESULT failure and success, these are only useful
// on Windows, and rely on Windows SDK macros and APIs to compile. // on Windows, and rely on Windows SDK macros and APIs to compile.
// //
// * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr) // * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
// //
// When expr unexpectedly fails or succeeds, Google Test prints the // When expr unexpectedly fails or succeeds, Google Test prints the
// expected result and the actual result with both a human-readable // expected result and the actual result with both a human-readable
skipping to change at line 1910 skipping to change at line 1999
// Note that we call GetTestTypeId() instead of GetTypeId< // Note that we call GetTestTypeId() instead of GetTypeId<
// ::testing::Test>() here to get the type ID of testing::Test. This // ::testing::Test>() here to get the type ID of testing::Test. This
// is to work around a suspected linker bug when using Google Test as // is to work around a suspected linker bug when using Google Test as
// a framework on Mac OS X. The bug causes GetTypeId< // a framework on Mac OS X. The bug causes GetTypeId<
// ::testing::Test>() to return different values depending on whether // ::testing::Test>() to return different values depending on whether
// the call is from the Google Test framework itself or from user test // the call is from the Google Test framework itself or from user test
// code. GetTestTypeId() is guaranteed to always return the same // code. GetTestTypeId() is guaranteed to always return the same
// value, as it always calls GetTypeId<>() from the Google Test // value, as it always calls GetTypeId<>() from the Google Test
// framework. // framework.
#define TEST(test_case_name, test_name)\ #define GTEST_TEST(test_case_name, test_name)\
GTEST_TEST_(test_case_name, test_name, \ GTEST_TEST_(test_case_name, test_name, \
::testing::Test, ::testing::internal::GetTestTypeId()) ::testing::Test, ::testing::internal::GetTestTypeId())
// Define this macro to 1 to omit the definition of TEST(), which
// is a generic name and clashes with some other libraries.
#if !GTEST_DONT_DEFINE_TEST
#define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_nam
e)
#endif
// Defines a test that uses a test fixture. // Defines a test that uses a test fixture.
// //
// The first parameter is the name of the test fixture class, which // The first parameter is the name of the test fixture class, which
// also doubles as the test case name. The second parameter is the // also doubles as the test case name. The second parameter is the
// name of the test within the test case. // name of the test within the test case.
// //
// A test fixture class must be declared earlier. The user should put // A test fixture class must be declared earlier. The user should put
// his test code between braces after using this macro. Example: // his test code between braces after using this macro. Example:
// //
// class FooTest : public testing::Test { // class FooTest : public testing::Test {
 End of changes. 71 change blocks. 
132 lines changed or deleted 234 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/