gmock-actions.h   gmock-actions.h 
skipping to change at line 43 skipping to change at line 43
// //
// This file implements some commonly used actions. // This file implements some commonly used actions.
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
#include <algorithm> #include <algorithm>
#include <string> #include <string>
#ifndef _WIN32_WCE #ifndef _WIN32_WCE
#include <errno.h> # include <errno.h>
#endif #endif
#include <gmock/gmock-printers.h> #include "gmock/internal/gmock-internal-utils.h"
#include <gmock/internal/gmock-internal-utils.h> #include "gmock/internal/gmock-port.h"
#include <gmock/internal/gmock-port.h>
namespace testing { namespace testing {
// To implement an action Foo, define: // To implement an action Foo, define:
// 1. a class FooAction that implements the ActionInterface interface, an d // 1. a class FooAction that implements the ActionInterface interface, an d
// 2. a factory function that creates an Action object from a // 2. a factory function that creates an Action object from a
// const FooAction*. // const FooAction*.
// //
// The two-level delegation design follows that of Matcher, providing // The two-level delegation design follows that of Matcher, providing
// consistency for extension developers. It also eases ownership // consistency for extension developers. It also eases ownership
// management as Action objects can now be copied like plain values. // management as Action objects can now be copied like plain values.
namespace internal { namespace internal {
template <typename F>
class MonomorphicDoDefaultActionImpl;
template <typename F1, typename F2> template <typename F1, typename F2>
class ActionAdaptor; class ActionAdaptor;
// BuiltInDefaultValue<T>::Get() returns the "built-in" default // BuiltInDefaultValue<T>::Get() returns the "built-in" default
// value for type T, which is NULL when T is a pointer type, 0 when T // value for type T, which is NULL when T is a pointer type, 0 when T
// is a numeric type, false when T is bool, or "" when T is string or // is a numeric type, false when T is bool, or "" when T is string or
// std::string. For any other type T, this value is undefined and the // std::string. For any other type T, this value is undefined and the
// function will abort the process. // function will abort the process.
template <typename T> template <typename T>
class BuiltInDefaultValue { class BuiltInDefaultValue {
skipping to change at line 259 skipping to change at line 255
template <typename T> template <typename T>
T* DefaultValue<T&>::address_ = NULL; T* DefaultValue<T&>::address_ = NULL;
// Implement this interface to define an action for function type F. // Implement this interface to define an action for function type F.
template <typename F> template <typename F>
class ActionInterface { class ActionInterface {
public: public:
typedef typename internal::Function<F>::Result Result; typedef typename internal::Function<F>::Result Result;
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
ActionInterface() : is_do_default_(false) {} ActionInterface() {}
virtual ~ActionInterface() {} virtual ~ActionInterface() {}
// Performs the action. This method is not const, as in general an // Performs the action. This method is not const, as in general an
// action can have side effects and be stateful. For example, a // action can have side effects and be stateful. For example, a
// get-the-next-element-from-the-collection action will need to // get-the-next-element-from-the-collection action will need to
// remember the current element. // remember the current element.
virtual Result Perform(const ArgumentTuple& args) = 0; virtual Result Perform(const ArgumentTuple& args) = 0;
// Returns true iff this is the DoDefault() action.
bool IsDoDefault() const { return is_do_default_; }
private: private:
template <typename Function>
friend class internal::MonomorphicDoDefaultActionImpl;
// This private constructor is reserved for implementing
// DoDefault(), the default action for a given mock function.
explicit ActionInterface(bool is_do_default)
: is_do_default_(is_do_default) {}
// True iff this action is DoDefault().
const bool is_do_default_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface); 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
skipping to change at line 306 skipping to change at line 287
template <typename F> template <typename F>
class Action { class Action {
public: public:
typedef typename internal::Function<F>::Result Result; typedef typename internal::Function<F>::Result Result;
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
// Constructs a null Action. Needed for storing Action objects in // Constructs a null Action. Needed for storing Action objects in
// STL containers. // STL containers.
Action() : impl_(NULL) {} Action() : impl_(NULL) {}
// Constructs an Action from its implementation. // Constructs an Action from its implementation. A NULL impl is
// used to represent the "do-default" action.
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 can 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_.get() == NULL; }
// 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
// another concrete action, not that the concrete action it binds to // another concrete action, not that the concrete action it binds to
// cannot change state. (Think of the difference between a const // cannot change state. (Think of the difference between a const
// pointer and a pointer to const.) // pointer and a pointer to const.)
Result Perform(const ArgumentTuple& args) const { Result Perform(const ArgumentTuple& args) const {
internal::Assert(
!IsDoDefault(), __FILE__, __LINE__,
"You are using DoDefault() inside a composite action like "
"DoAll() or WithArgs(). This is not supported for technical "
"reasons. Please instead spell out the default action, or "
"assign the default action to an Action variable and use "
"the variable in various places.");
return impl_->Perform(args); return impl_->Perform(args);
} }
private: private:
template <typename F1, typename F2> template <typename F1, typename F2>
friend class internal::ActionAdaptor; friend class internal::ActionAdaptor;
internal::linked_ptr<ActionInterface<F> > impl_; internal::linked_ptr<ActionInterface<F> > impl_;
}; };
skipping to change at line 480 skipping to change at line 469
operator Action<F>() const { operator Action<F>() const {
// Assert statement belongs here because this is the best place to veri fy // Assert statement belongs here because this is the best place to veri fy
// conditions on F. It produces the clearest error messages // conditions on F. It produces the clearest error messages
// in most compilers. // in most compilers.
// Impl really belongs in this scope as a local class but can't // Impl really belongs in this scope as a local class but can't
// 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_( GTEST_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;
// The implicit cast is necessary when Result has more than one // The implicit cast is necessary when Result has more than one
// single-argument constructor (e.g. Result is std::vector<int>) and R // single-argument constructor (e.g. Result is std::vector<int>) and R
// has a type conversion operator template. In that case, value_(value ) // has a type conversion operator template. In that case, value_(value )
// won't compile as the compiler doesn't known which constructor of // 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 to call. ImplicitCast_ forces the compiler to convert R to
// Result without considering explicit constructors, thus resolving the // Result without considering explicit constructors, thus resolving the
// ambiguity. value_ is then initialized using its copy constructor. // ambiguity. value_ is then initialized using its copy constructor.
explicit Impl(R value) explicit Impl(R value)
: value_(::testing::internal::implicit_cast<Result>(value)) {} : value_(::testing::internal::ImplicitCast_<Result>(value)) {}
virtual Result Perform(const ArgumentTuple&) { return value_; } virtual Result Perform(const ArgumentTuple&) { return value_; }
private: private:
GMOCK_COMPILE_ASSERT_(!internal::is_reference<Result>::value, GTEST_COMPILE_ASSERT_(!internal::is_reference<Result>::value,
Result_cannot_be_a_reference_type); Result_cannot_be_a_reference_type);
Result value_; Result value_;
GTEST_DISALLOW_ASSIGN_(Impl); GTEST_DISALLOW_ASSIGN_(Impl);
}; };
R value_; R value_;
GTEST_DISALLOW_ASSIGN_(ReturnAction); 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, GTEST_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);
return NULL; return NULL;
} }
}; };
// Implements the Return() action. // Implements the Return() action.
class ReturnVoidAction { class ReturnVoidAction {
public: public:
// Allows Return() to be used in any void-returning function. // Allows Return() to be used in any void-returning function.
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
skipping to change at line 558 skipping to change at line 547
explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT
// This template type conversion operator allows ReturnRef(x) to be // This template type conversion operator allows ReturnRef(x) to be
// used in ANY function that returns a reference to x's type. // used in ANY function that returns a reference to x's type.
template <typename F> template <typename F>
operator Action<F>() const { operator Action<F>() const {
typedef typename Function<F>::Result Result; typedef typename Function<F>::Result Result;
// Asserts that the function return type is a reference. This // Asserts that the function return type is a reference. This
// catches the user error of using ReturnRef(x) when Return(x) // catches the user error of using ReturnRef(x) when Return(x)
// should be used, and generates some helpful error message. // should be used, and generates some helpful error message.
GMOCK_COMPILE_ASSERT_(internal::is_reference<Result>::value, GTEST_COMPILE_ASSERT_(internal::is_reference<Result>::value,
use_Return_instead_of_ReturnRef_to_return_a_value ); use_Return_instead_of_ReturnRef_to_return_a_value );
return Action<F>(new Impl<F>(ref_)); return Action<F>(new Impl<F>(ref_));
} }
private: private:
// Implements the ReturnRef(x) action for a particular function type F. // Implements the ReturnRef(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;
skipping to change at line 588 skipping to change at line 577
T& ref_; T& ref_;
GTEST_DISALLOW_ASSIGN_(Impl); GTEST_DISALLOW_ASSIGN_(Impl);
}; };
T& ref_; T& ref_;
GTEST_DISALLOW_ASSIGN_(ReturnRefAction); GTEST_DISALLOW_ASSIGN_(ReturnRefAction);
}; };
// Implements the DoDefault() action for a particular function type F. // Implements the polymorphic ReturnRefOfCopy(x) action, which can be
template <typename F> // used in any function that returns a reference to the type of x,
class MonomorphicDoDefaultActionImpl : public ActionInterface<F> { // regardless of the argument types.
template <typename T>
class ReturnRefOfCopyAction {
public: public:
typedef typename Function<F>::Result Result; // Constructs a ReturnRefOfCopyAction object from the reference to
typedef typename Function<F>::ArgumentTuple ArgumentTuple; // be returned.
explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOL
MonomorphicDoDefaultActionImpl() : ActionInterface<F>(true) {} INT
// For technical reasons, DoDefault() cannot be used inside a // This template type conversion operator allows ReturnRefOfCopy(x) to be
// composite action (e.g. DoAll(...)). It can only be used at the // used in ANY function that returns a reference to x's type.
// top level in an EXPECT_CALL(). If this function is called, the template <typename F>
// user must be using DoDefault() inside a composite action, and we operator Action<F>() const {
// have to generate a run-time error. typedef typename Function<F>::Result Result;
virtual Result Perform(const ArgumentTuple&) { // Asserts that the function return type is a reference. This
Assert(false, __FILE__, __LINE__, // catches the user error of using ReturnRefOfCopy(x) when Return(x)
"You are using DoDefault() inside a composite action like " // should be used, and generates some helpful error message.
"DoAll() or WithArgs(). This is not supported for technical " GTEST_COMPILE_ASSERT_(
"reasons. Please instead spell out the default action, or " internal::is_reference<Result>::value,
"assign the default action to an Action variable and use " use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
"the variable in various places."); return Action<F>(new Impl<F>(value_));
return internal::Invalid<Result>();
// The above statement will never be reached, but is required in
// order for this function to compile.
} }
private:
// Implements the ReturnRefOfCopy(x) action for a particular function typ
e F.
template <typename F>
class Impl : public ActionInterface<F> {
public:
typedef typename Function<F>::Result Result;
typedef typename Function<F>::ArgumentTuple ArgumentTuple;
explicit Impl(const T& value) : value_(value) {} // NOLINT
virtual Result Perform(const ArgumentTuple&) {
return value_;
}
private:
T value_;
GTEST_DISALLOW_ASSIGN_(Impl);
};
const T value_;
GTEST_DISALLOW_ASSIGN_(ReturnRefOfCopyAction);
}; };
// Implements the polymorphic DoDefault() action. // Implements the polymorphic DoDefault() action.
class DoDefaultAction { class DoDefaultAction {
public: public:
// This template type conversion operator allows DoDefault() to be // This template type conversion operator allows DoDefault() to be
// used in any function. // used in any function.
template <typename F> template <typename F>
operator Action<F>() const { operator Action<F>() const { return Action<F>(NULL); }
return Action<F>(new MonomorphicDoDefaultActionImpl<F>);
}
}; };
// Implements the Assign action to set a given pointer referent to a // Implements the Assign action to set a given pointer referent to a
// 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>
skipping to change at line 952 skipping to change at line 961
inline PolymorphicAction<internal::ReturnVoidAction> Return() { inline PolymorphicAction<internal::ReturnVoidAction> Return() {
return MakePolymorphicAction(internal::ReturnVoidAction()); return MakePolymorphicAction(internal::ReturnVoidAction());
} }
// Creates an action that returns the reference to a variable. // Creates an action that returns the reference to a variable.
template <typename R> template <typename R>
inline internal::ReturnRefAction<R> ReturnRef(R& x) { // NOLINT inline internal::ReturnRefAction<R> ReturnRef(R& x) { // NOLINT
return internal::ReturnRefAction<R>(x); return internal::ReturnRefAction<R>(x);
} }
// Creates an action that returns the reference to a copy of the
// argument. The copy is created when the action is constructed and
// lives as long as the action.
template <typename R>
inline internal::ReturnRefOfCopyAction<R> ReturnRefOfCopy(const R& x) {
return internal::ReturnRefOfCopyAction<R>(x);
}
// Creates an action that does the default action for the give mock functio n. // Creates an action that does the default action for the give mock functio n.
inline internal::DoDefaultAction DoDefault() { inline internal::DoDefaultAction DoDefault() {
return internal::DoDefaultAction(); return internal::DoDefaultAction();
} }
// Creates an action that sets the variable pointed by the N-th // Creates an action that sets the variable pointed by the N-th
// (0-based) function argument to 'value'. // (0-based) function argument to 'value'.
template <size_t N, typename T> template <size_t N, typename T>
PolymorphicAction< PolymorphicAction<
internal::SetArgumentPointeeAction< internal::SetArgumentPointeeAction<
N, T, internal::IsAProtocolMessage<T>::value> > N, T, internal::IsAProtocolMessage<T>::value> >
SetArgPointee(const T& x) {
return MakePolymorphicAction(internal::SetArgumentPointeeAction<
N, T, internal::IsAProtocolMessage<T>::value>(x));
}
#if !((GTEST_GCC_VER_ && GTEST_GCC_VER_ < 40000) || GTEST_OS_SYMBIAN)
// This overload allows SetArgPointee() to accept a string literal.
// GCC prior to the version 4.0 and Symbian C++ compiler cannot distinguish
// this overload from the templated version and emit a compile error.
template <size_t N>
PolymorphicAction<
internal::SetArgumentPointeeAction<N, const char*, false> >
SetArgPointee(const char* p) {
return MakePolymorphicAction(internal::SetArgumentPointeeAction<
N, const char*, false>(p));
}
template <size_t N>
PolymorphicAction<
internal::SetArgumentPointeeAction<N, const wchar_t*, false> >
SetArgPointee(const wchar_t* p) {
return MakePolymorphicAction(internal::SetArgumentPointeeAction<
N, const wchar_t*, false>(p));
}
#endif
// The following version is DEPRECATED.
template <size_t N, typename T>
PolymorphicAction<
internal::SetArgumentPointeeAction<
N, T, internal::IsAProtocolMessage<T>::value> >
SetArgumentPointee(const T& x) { SetArgumentPointee(const T& x) {
return MakePolymorphicAction(internal::SetArgumentPointeeAction< return MakePolymorphicAction(internal::SetArgumentPointeeAction<
N, T, internal::IsAProtocolMessage<T>::value>(x)); N, T, internal::IsAProtocolMessage<T>::value>(x));
} }
// Creates an action that sets a pointer referent to a given value. // Creates an action that sets a pointer referent to a given value.
template <typename T1, typename T2> template <typename T1, typename T2>
PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) { PolymorphicAction<internal::AssignAction<T1, T2> > Assign(T1* ptr, T2 val) {
return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val)); return MakePolymorphicAction(internal::AssignAction<T1, T2>(ptr, val));
} }
 End of changes. 22 change blocks. 
56 lines changed or deleted 106 lines changed or added


 gmock-cardinalities.h   gmock-cardinalities.h 
skipping to change at line 43 skipping to change at line 43
// //
// This file implements some commonly used cardinalities. More // This file implements some commonly used cardinalities. More
// cardinalities can be defined by the user implementing the // cardinalities can be defined by the user implementing the
// CardinalityInterface interface if necessary. // CardinalityInterface interface if necessary.
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_
#include <limits.h> #include <limits.h>
#include <ostream> // NOLINT #include <ostream> // NOLINT
#include <gmock/internal/gmock-port.h> #include "gmock/internal/gmock-port.h"
#include <gtest/gtest.h> #include "gtest/gtest.h"
namespace testing { namespace testing {
// To implement a cardinality Foo, define: // To implement a cardinality Foo, define:
// 1. a class FooCardinality that implements the // 1. a class FooCardinality that implements the
// CardinalityInterface interface, and // CardinalityInterface interface, and
// 2. a factory function that creates a Cardinality object from a // 2. a factory function that creates a Cardinality object from a
// const FooCardinality*. // const FooCardinality*.
// //
// The two-level delegation design follows that of Matcher, providing // The two-level delegation design follows that of Matcher, providing
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 gmock-generated-actions.h   gmock-generated-actions.h 
skipping to change at line 41 skipping to change at line 41
// //
// Author: wan@google.com (Zhanyong Wan) // Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file implements some commonly used variadic actions. // This file implements some commonly used variadic actions.
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
#include <gmock/gmock-actions.h> #include "gmock/gmock-actions.h"
#include <gmock/internal/gmock-port.h> #include "gmock/internal/gmock-port.h"
namespace testing { namespace testing {
namespace internal { namespace internal {
// InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary // InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
// function or method with the unpacked values, where F is a function // function or method with the unpacked values, where F is a function
// type that takes N arguments. // type that takes N arguments.
template <typename Result, typename ArgumentTuple> template <typename Result, typename ArgumentTuple>
class InvokeHelper; class InvokeHelper;
skipping to change at line 1381 skipping to change at line 1381
#define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7 #define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
#define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ #define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
p7) P8 p7) P8
#define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ #define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
p7, p8) P9 p7, p8) P9
#define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6 , \ #define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6 , \
p7, p8, p9) P10 p7, p8, p9) P10
// The name of the class template implementing the action template. // The name of the class template implementing the action template.
#define GMOCK_ACTION_CLASS_(name, value_params)\ #define GMOCK_ACTION_CLASS_(name, value_params)\
GMOCK_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params) GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
#define ACTION_TEMPLATE(name, template_params, value_params)\ #define ACTION_TEMPLATE(name, template_params, 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>\
class GMOCK_ACTION_CLASS_(name, value_params) {\ class GMOCK_ACTION_CLASS_(name, value_params) {\
public:\ public:\
GMOCK_ACTION_CLASS_(name, value_params)\ GMOCK_ACTION_CLASS_(name, value_params)\
GMOCK_INTERNAL_INIT_##value_params {}\ GMOCK_INTERNAL_INIT_##value_params {}\
template <typename F>\ template <typename F>\
class gmock_Impl : public ::testing::ActionInterface<F> {\ class gmock_Impl : public ::testing::ActionInterface<F> {\
skipping to change at line 2231 skipping to change at line 2231
// 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 // The ACTION*() macros trigger warning C4100 (unreferenced formal
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
// the macro definition, as the warnings are generated when the macro // the macro definition, as the warnings are generated when the macro
// is expanded and macro expansion cannot contain #pragma. Therefore // is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here. // we suppress them here.
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) # pragma warning(push)
#pragma warning(disable:4100) # pragma warning(disable:4100)
#endif #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:
// //
skipping to change at line 2414 skipping to change at line 2414
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 #ifdef _MSC_VER
#pragma warning(pop) # pragma warning(pop)
#endif #endif
} // namespace testing } // namespace testing
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
 End of changes. 4 change blocks. 
6 lines changed or deleted 6 lines changed or added


 gmock-generated-function-mockers.h   gmock-generated-function-mockers.h 
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! // This file was GENERATED by command:
// pump.py gmock-generated-function-mockers.h.pump
// DO NOT EDIT BY HAND!!!
// Copyright 2007, Google Inc. // Copyright 2007, 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 41 skipping to change at line 43
// //
// Author: wan@google.com (Zhanyong Wan) // Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file implements 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 {
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
skipping to change at line 342 skipping to change at line 344
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_ARG_(tn, F, N) tn ::testing::internal::Function<F>::Argument# #N #define GMOCK_ARG_(tn, F, N) tn ::testing::internal::Function<F>::Argument# #N
// The matcher type for argument N of function type F. // The matcher type for argument N of function type F.
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_MATCHER_(tn, F, N) const ::testing::Matcher<GMOCK_ARG_(tn, F, N)>& #define GMOCK_MATCHER_(tn, F, N) const ::testing::Matcher<GMOCK_ARG_(tn, F, N)>&
// The variable for mocking the given method. // The variable for mocking the given method.
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_MOCKER_(arity, constness, Method) \ #define GMOCK_MOCKER_(arity, constness, Method) \
GMOCK_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD0_(tn, constness, ct, Method, F) \ #define GMOCK_METHOD0_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method() constness { \ GMOCK_RESULT_(tn, F) ct Method() constness { \
GMOCK_COMPILE_ASSERT_(::std::tr1::tuple_size< \ GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 0, \ tn ::testing::internal::Function<F>::ArgumentTuple>::value == 0, \
this_method_does_not_take_0_arguments); \ this_method_does_not_take_0_arguments); \
GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ return GMOCK_MOCKER_(0, constness, Method).Invoke(); \
} \ } \
::testing::MockSpec<F>& \ ::testing::MockSpec<F>& \
gmock_##Method() constness { \ gmock_##Method() constness { \
return GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this).With(); GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \
\ return GMOCK_MOCKER_(0, constness, Method).With(); \
} \ } \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(0, constness, Method) mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(0, constness, Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD1_(tn, constness, ct, Method, F) \ #define GMOCK_METHOD1_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1) constness { \ GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1) constness { \
GMOCK_COMPILE_ASSERT_(::std::tr1::tuple_size< \ GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 1, \ tn ::testing::internal::Function<F>::ArgumentTuple>::value == 1, \
this_method_does_not_take_1_argument); \ this_method_does_not_take_1_argument); \
GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \ return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \
} \ } \
::testing::MockSpec<F>& \ ::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1) constness { \ gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1) constness { \
return GMOCK_MOCKER_(1, constness, \ GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \
Method).RegisterOwner(this).With(gmock_a1); \ return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \
} \ } \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(1, constness, Method) mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(1, constness, Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD2_(tn, constness, ct, Method, F) \ #define GMOCK_METHOD2_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \
GMOCK_ARG_(tn, F, 2) gmock_a2) constness { \ GMOCK_ARG_(tn, F, 2) gmock_a2) constness { \
GMOCK_COMPILE_ASSERT_(::std::tr1::tuple_size< \ GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 2, \ tn ::testing::internal::Function<F>::ArgumentTuple>::value == 2, \
this_method_does_not_take_2_arguments); \ this_method_does_not_take_2_arguments); \
GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \ return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \
} \ } \
::testing::MockSpec<F>& \ ::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \
GMOCK_MATCHER_(tn, F, 2) gmock_a2) constness { \ GMOCK_MATCHER_(tn, F, 2) gmock_a2) constness { \
return GMOCK_MOCKER_(2, constness, \ GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2); \ return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \
} \ } \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(2, constness, Method) mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(2, constness, Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD3_(tn, constness, ct, Method, F) \ #define GMOCK_METHOD3_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \
GMOCK_ARG_(tn, F, 2) gmock_a2, \ GMOCK_ARG_(tn, F, 2) gmock_a2, \
GMOCK_ARG_(tn, F, 3) gmock_a3) constness { \ GMOCK_ARG_(tn, F, 3) gmock_a3) constness { \
GMOCK_COMPILE_ASSERT_(::std::tr1::tuple_size< \ GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 3, \ tn ::testing::internal::Function<F>::ArgumentTuple>::value == 3, \
this_method_does_not_take_3_arguments); \ this_method_does_not_take_3_arguments); \
GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \
gmock_a3); \ gmock_a3); \
} \ } \
::testing::MockSpec<F>& \ ::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \
GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ GMOCK_MATCHER_(tn, F, 2) gmock_a2, \
GMOCK_MATCHER_(tn, F, 3) gmock_a3) constness { \ GMOCK_MATCHER_(tn, F, 3) gmock_a3) constness { \
return GMOCK_MOCKER_(3, constness, \ GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3); \ return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a3); \
} \ } \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(3, constness, Method) mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(3, constness, Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD4_(tn, constness, ct, Method, F) \ #define GMOCK_METHOD4_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \
GMOCK_ARG_(tn, F, 2) gmock_a2, \ GMOCK_ARG_(tn, F, 2) gmock_a2, \
GMOCK_ARG_(tn, F, 3) gmock_a3, \ GMOCK_ARG_(tn, F, 3) gmock_a3, \
GMOCK_ARG_(tn, F, 4) gmock_a4) constness { \ GMOCK_ARG_(tn, F, 4) gmock_a4) constness { \
GMOCK_COMPILE_ASSERT_(::std::tr1::tuple_size< \ GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 4, \ tn ::testing::internal::Function<F>::ArgumentTuple>::value == 4, \
this_method_does_not_take_4_arguments); \ this_method_does_not_take_4_arguments); \
GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4); \ gmock_a3, gmock_a4); \
} \ } \
::testing::MockSpec<F>& \ ::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \
GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ GMOCK_MATCHER_(tn, F, 2) gmock_a2, \
GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ GMOCK_MATCHER_(tn, F, 3) gmock_a3, \
GMOCK_MATCHER_(tn, F, 4) gmock_a4) constness { \ GMOCK_MATCHER_(tn, F, 4) gmock_a4) constness { \
return GMOCK_MOCKER_(4, constness, \ GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \ return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a4); \ gmock_a3, gmock_a4); \
} \ } \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(4, constness, Method) mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(4, constness, Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD5_(tn, constness, ct, Method, F) \ #define GMOCK_METHOD5_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \
GMOCK_ARG_(tn, F, 2) gmock_a2, \ GMOCK_ARG_(tn, F, 2) gmock_a2, \
GMOCK_ARG_(tn, F, 3) gmock_a3, \ GMOCK_ARG_(tn, F, 3) gmock_a3, \
GMOCK_ARG_(tn, F, 4) gmock_a4, \ GMOCK_ARG_(tn, F, 4) gmock_a4, \
GMOCK_ARG_(tn, F, 5) gmock_a5) constness { \ GMOCK_ARG_(tn, F, 5) gmock_a5) constness { \
GMOCK_COMPILE_ASSERT_(::std::tr1::tuple_size< \ GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 5, \ tn ::testing::internal::Function<F>::ArgumentTuple>::value == 5, \
this_method_does_not_take_5_arguments); \ this_method_does_not_take_5_arguments); \
GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5); \ gmock_a3, gmock_a4, gmock_a5); \
} \ } \
::testing::MockSpec<F>& \ ::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \
GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ GMOCK_MATCHER_(tn, F, 2) gmock_a2, \
GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ GMOCK_MATCHER_(tn, F, 3) gmock_a3, \
GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ GMOCK_MATCHER_(tn, F, 4) gmock_a4, \
GMOCK_MATCHER_(tn, F, 5) gmock_a5) constness { \ GMOCK_MATCHER_(tn, F, 5) gmock_a5) constness { \
return GMOCK_MOCKER_(5, constness, \ GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \ return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a4, gmock_a5); \ gmock_a3, gmock_a4, gmock_a5); \
} \ } \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(5, constness, Method) mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(5, constness, Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD6_(tn, constness, ct, Method, F) \ #define GMOCK_METHOD6_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \
GMOCK_ARG_(tn, F, 2) gmock_a2, \ GMOCK_ARG_(tn, F, 2) gmock_a2, \
GMOCK_ARG_(tn, F, 3) gmock_a3, \ GMOCK_ARG_(tn, F, 3) gmock_a3, \
GMOCK_ARG_(tn, F, 4) gmock_a4, \ GMOCK_ARG_(tn, F, 4) gmock_a4, \
GMOCK_ARG_(tn, F, 5) gmock_a5, \ GMOCK_ARG_(tn, F, 5) gmock_a5, \
GMOCK_ARG_(tn, F, 6) gmock_a6) constness { \ GMOCK_ARG_(tn, F, 6) gmock_a6) constness { \
GMOCK_COMPILE_ASSERT_(::std::tr1::tuple_size< \ GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 6, \ tn ::testing::internal::Function<F>::ArgumentTuple>::value == 6, \
this_method_does_not_take_6_arguments); \ this_method_does_not_take_6_arguments); \
GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
} \ } \
::testing::MockSpec<F>& \ ::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \
GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ GMOCK_MATCHER_(tn, F, 2) gmock_a2, \
GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ GMOCK_MATCHER_(tn, F, 3) gmock_a3, \
GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ GMOCK_MATCHER_(tn, F, 4) gmock_a4, \
GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ GMOCK_MATCHER_(tn, F, 5) gmock_a5, \
GMOCK_MATCHER_(tn, F, 6) gmock_a6) constness { \ GMOCK_MATCHER_(tn, F, 6) gmock_a6) constness { \
return GMOCK_MOCKER_(6, constness, \ GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \ return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a4, gmock_a5, gmock_a6); \ gmock_a3, gmock_a4, gmock_a5, gmock_a6); \
} \ } \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(6, constness, Method) mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(6, constness, Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD7_(tn, constness, ct, Method, F) \ #define GMOCK_METHOD7_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \
GMOCK_ARG_(tn, F, 2) gmock_a2, \ GMOCK_ARG_(tn, F, 2) gmock_a2, \
GMOCK_ARG_(tn, F, 3) gmock_a3, \ GMOCK_ARG_(tn, F, 3) gmock_a3, \
GMOCK_ARG_(tn, F, 4) gmock_a4, \ GMOCK_ARG_(tn, F, 4) gmock_a4, \
GMOCK_ARG_(tn, F, 5) gmock_a5, \ GMOCK_ARG_(tn, F, 5) gmock_a5, \
GMOCK_ARG_(tn, F, 6) gmock_a6, \ GMOCK_ARG_(tn, F, 6) gmock_a6, \
GMOCK_ARG_(tn, F, 7) gmock_a7) constness { \ GMOCK_ARG_(tn, F, 7) gmock_a7) constness { \
GMOCK_COMPILE_ASSERT_(::std::tr1::tuple_size< \ GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 7, \ tn ::testing::internal::Function<F>::ArgumentTuple>::value == 7, \
this_method_does_not_take_7_arguments); \ this_method_does_not_take_7_arguments); \
GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
} \ } \
::testing::MockSpec<F>& \ ::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \
GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ GMOCK_MATCHER_(tn, F, 2) gmock_a2, \
GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ GMOCK_MATCHER_(tn, F, 3) gmock_a3, \
GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ GMOCK_MATCHER_(tn, F, 4) gmock_a4, \
GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ GMOCK_MATCHER_(tn, F, 5) gmock_a5, \
GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ GMOCK_MATCHER_(tn, F, 6) gmock_a6, \
GMOCK_MATCHER_(tn, F, 7) gmock_a7) constness { \ GMOCK_MATCHER_(tn, F, 7) gmock_a7) constness { \
return GMOCK_MOCKER_(7, constness, \ GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \ return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \
} \ } \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(7, constness, Method) mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(7, constness, Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD8_(tn, constness, ct, Method, F) \ #define GMOCK_METHOD8_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \
GMOCK_ARG_(tn, F, 2) gmock_a2, \ GMOCK_ARG_(tn, F, 2) gmock_a2, \
GMOCK_ARG_(tn, F, 3) gmock_a3, \ GMOCK_ARG_(tn, F, 3) gmock_a3, \
GMOCK_ARG_(tn, F, 4) gmock_a4, \ GMOCK_ARG_(tn, F, 4) gmock_a4, \
GMOCK_ARG_(tn, F, 5) gmock_a5, \ GMOCK_ARG_(tn, F, 5) gmock_a5, \
GMOCK_ARG_(tn, F, 6) gmock_a6, \ GMOCK_ARG_(tn, F, 6) gmock_a6, \
GMOCK_ARG_(tn, F, 7) gmock_a7, \ GMOCK_ARG_(tn, F, 7) gmock_a7, \
GMOCK_ARG_(tn, F, 8) gmock_a8) constness { \ GMOCK_ARG_(tn, F, 8) gmock_a8) constness { \
GMOCK_COMPILE_ASSERT_(::std::tr1::tuple_size< \ GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 8, \ tn ::testing::internal::Function<F>::ArgumentTuple>::value == 8, \
this_method_does_not_take_8_arguments); \ this_method_does_not_take_8_arguments); \
GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
} \ } \
::testing::MockSpec<F>& \ ::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \
GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ GMOCK_MATCHER_(tn, F, 2) gmock_a2, \
GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ GMOCK_MATCHER_(tn, F, 3) gmock_a3, \
GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ GMOCK_MATCHER_(tn, F, 4) gmock_a4, \
GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ GMOCK_MATCHER_(tn, F, 5) gmock_a5, \
GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ GMOCK_MATCHER_(tn, F, 6) gmock_a6, \
GMOCK_MATCHER_(tn, F, 7) gmock_a7, \ GMOCK_MATCHER_(tn, F, 7) gmock_a7, \
GMOCK_MATCHER_(tn, F, 8) gmock_a8) constness { \ GMOCK_MATCHER_(tn, F, 8) gmock_a8) constness { \
return GMOCK_MOCKER_(8, constness, \ GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \ return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \
} \ } \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(8, constness, Method) mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(8, constness, Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD9_(tn, constness, ct, Method, F) \ #define GMOCK_METHOD9_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \
GMOCK_ARG_(tn, F, 2) gmock_a2, \ GMOCK_ARG_(tn, F, 2) gmock_a2, \
GMOCK_ARG_(tn, F, 3) gmock_a3, \ GMOCK_ARG_(tn, F, 3) gmock_a3, \
GMOCK_ARG_(tn, F, 4) gmock_a4, \ GMOCK_ARG_(tn, F, 4) gmock_a4, \
GMOCK_ARG_(tn, F, 5) gmock_a5, \ GMOCK_ARG_(tn, F, 5) gmock_a5, \
GMOCK_ARG_(tn, F, 6) gmock_a6, \ GMOCK_ARG_(tn, F, 6) gmock_a6, \
GMOCK_ARG_(tn, F, 7) gmock_a7, \ GMOCK_ARG_(tn, F, 7) gmock_a7, \
GMOCK_ARG_(tn, F, 8) gmock_a8, \ GMOCK_ARG_(tn, F, 8) gmock_a8, \
GMOCK_ARG_(tn, F, 9) gmock_a9) constness { \ GMOCK_ARG_(tn, F, 9) gmock_a9) constness { \
GMOCK_COMPILE_ASSERT_(::std::tr1::tuple_size< \ GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 9, \ tn ::testing::internal::Function<F>::ArgumentTuple>::value == 9, \
this_method_does_not_take_9_arguments); \ this_method_does_not_take_9_arguments); \
GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
gmock_a9); \ gmock_a9); \
} \ } \
::testing::MockSpec<F>& \ ::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \
GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ GMOCK_MATCHER_(tn, F, 2) gmock_a2, \
GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ GMOCK_MATCHER_(tn, F, 3) gmock_a3, \
GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ GMOCK_MATCHER_(tn, F, 4) gmock_a4, \
GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ GMOCK_MATCHER_(tn, F, 5) gmock_a5, \
GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ GMOCK_MATCHER_(tn, F, 6) gmock_a6, \
GMOCK_MATCHER_(tn, F, 7) gmock_a7, \ GMOCK_MATCHER_(tn, F, 7) gmock_a7, \
GMOCK_MATCHER_(tn, F, 8) gmock_a8, \ GMOCK_MATCHER_(tn, F, 8) gmock_a8, \
GMOCK_MATCHER_(tn, F, 9) gmock_a9) constness { \ GMOCK_MATCHER_(tn, F, 9) gmock_a9) constness { \
return GMOCK_MOCKER_(9, constness, \ GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \ return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9); \ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \
gmock_a9); \
} \ } \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(9, constness, Method) mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(9, constness, Method)
// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! // INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!!
#define GMOCK_METHOD10_(tn, constness, ct, Method, F) \ #define GMOCK_METHOD10_(tn, constness, ct, Method, F) \
GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \
GMOCK_ARG_(tn, F, 2) gmock_a2, \ GMOCK_ARG_(tn, F, 2) gmock_a2, \
GMOCK_ARG_(tn, F, 3) gmock_a3, \ GMOCK_ARG_(tn, F, 3) gmock_a3, \
GMOCK_ARG_(tn, F, 4) gmock_a4, \ GMOCK_ARG_(tn, F, 4) gmock_a4, \
GMOCK_ARG_(tn, F, 5) gmock_a5, \ GMOCK_ARG_(tn, F, 5) gmock_a5, \
GMOCK_ARG_(tn, F, 6) gmock_a6, \ GMOCK_ARG_(tn, F, 6) gmock_a6, \
GMOCK_ARG_(tn, F, 7) gmock_a7, \ GMOCK_ARG_(tn, F, 7) gmock_a7, \
GMOCK_ARG_(tn, F, 8) gmock_a8, \ GMOCK_ARG_(tn, F, 8) gmock_a8, \
GMOCK_ARG_(tn, F, 9) gmock_a9, \ GMOCK_ARG_(tn, F, 9) gmock_a9, \
GMOCK_ARG_(tn, F, 10) gmock_a10) constness { \ GMOCK_ARG_(tn, F, 10) gmock_a10) constness { \
GMOCK_COMPILE_ASSERT_(::std::tr1::tuple_size< \ GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \
tn ::testing::internal::Function<F>::ArgumentTuple>::value == 10, \ tn ::testing::internal::Function<F>::ArgumentTuple>::value == 10, \
this_method_does_not_take_10_arguments); \ this_method_does_not_take_10_arguments); \
GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \
return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \ return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \
gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a 9, \ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a 9, \
gmock_a10); \ gmock_a10); \
} \ } \
::testing::MockSpec<F>& \ ::testing::MockSpec<F>& \
gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \
GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ GMOCK_MATCHER_(tn, F, 2) gmock_a2, \
GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ GMOCK_MATCHER_(tn, F, 3) gmock_a3, \
GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ GMOCK_MATCHER_(tn, F, 4) gmock_a4, \
GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ GMOCK_MATCHER_(tn, F, 5) gmock_a5, \
GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ GMOCK_MATCHER_(tn, F, 6) gmock_a6, \
GMOCK_MATCHER_(tn, F, 7) gmock_a7, \ GMOCK_MATCHER_(tn, F, 7) gmock_a7, \
GMOCK_MATCHER_(tn, F, 8) gmock_a8, \ GMOCK_MATCHER_(tn, F, 8) gmock_a8, \
GMOCK_MATCHER_(tn, F, 9) gmock_a9, \ GMOCK_MATCHER_(tn, F, 9) gmock_a9, \
GMOCK_MATCHER_(tn, F, 10) gmock_a10) constness { \ GMOCK_MATCHER_(tn, F, 10) gmock_a10) constness { \
return GMOCK_MOCKER_(10, constness, \ GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \
Method).RegisterOwner(this).With(gmock_a1, gmock_a2, gmock_a3, \ return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \
gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a
9, \
gmock_a10); \ gmock_a10); \
} \ } \
mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(10, constness, Method) mutable ::testing::FunctionMocker<F> GMOCK_MOCKER_(10, constness, Method)
#define MOCK_METHOD0(m, F) GMOCK_METHOD0_(, , , m, F) #define MOCK_METHOD0(m, F) GMOCK_METHOD0_(, , , m, F)
#define MOCK_METHOD1(m, F) GMOCK_METHOD1_(, , , m, F) #define MOCK_METHOD1(m, F) GMOCK_METHOD1_(, , , m, F)
#define MOCK_METHOD2(m, F) GMOCK_METHOD2_(, , , m, F) #define MOCK_METHOD2(m, F) GMOCK_METHOD2_(, , , m, F)
#define MOCK_METHOD3(m, F) GMOCK_METHOD3_(, , , m, F) #define MOCK_METHOD3(m, F) GMOCK_METHOD3_(, , , m, F)
#define MOCK_METHOD4(m, F) GMOCK_METHOD4_(, , , m, F) #define MOCK_METHOD4(m, F) GMOCK_METHOD4_(, , , m, F)
#define MOCK_METHOD5(m, F) GMOCK_METHOD5_(, , , m, F) #define MOCK_METHOD5(m, F) GMOCK_METHOD5_(, , , m, F)
 End of changes. 25 change blocks. 
44 lines changed or deleted 49 lines changed or added


 gmock-generated-internal-utils.h   gmock-generated-internal-utils.h 
skipping to change at line 42 skipping to change at line 42
// Author: wan@google.com (Zhanyong Wan) // Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file contains template meta-programming utility classes needed // This file contains template meta-programming utility classes needed
// for implementing Google Mock. // for implementing Google Mock.
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
#include <gmock/internal/gmock-port.h> #include "gmock/internal/gmock-port.h"
namespace testing { namespace testing {
template <typename T> template <typename T>
class Matcher; class Matcher;
namespace internal { namespace internal {
// An IgnoredValue object can be implicitly constructed from ANY value. // An IgnoredValue object can be implicitly constructed from ANY value.
// This is used in implementing the IgnoreResult(a) action. // This is used in implementing the IgnoreResult(a) action.
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 gmock-generated-matchers.h   gmock-generated-matchers.h 
skipping to change at line 44 skipping to change at line 44
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file implements some commonly used variadic matchers. // This file implements some commonly used variadic matchers.
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <gmock/gmock-matchers.h> #include "gmock/gmock-matchers.h"
#include <gmock/gmock-printers.h>
namespace testing { namespace testing {
namespace internal { namespace internal {
// The type of the i-th (0-based) field of Tuple. // The type of the i-th (0-based) field of Tuple.
#define GMOCK_FIELD_TYPE_(Tuple, i) \ #define GMOCK_FIELD_TYPE_(Tuple, i) \
typename ::std::tr1::tuple_element<i, Tuple>::type typename ::std::tr1::tuple_element<i, Tuple>::type
// TupleFields<Tuple, k0, ..., kn> is for selecting fields from a // TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
// tuple of type Tuple. It has two members: // tuple of type Tuple. It has two members:
skipping to change at line 225 skipping to change at line 224
#undef GMOCK_FIELD_TYPE_ #undef GMOCK_FIELD_TYPE_
// Implements the Args() matcher. // Implements the Args() matcher.
template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1, template <class ArgsTuple, 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 k8 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
int k9 = -1> int k9 = -1>
class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> { class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
public: public:
// 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 GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple;
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 MatchAndExplain(ArgsTuple args, virtual bool MatchAndExplain(ArgsTuple args,
MatchResultListener* listener) const { MatchResultListener* listener) const {
skipping to change at line 318 skipping to change at line 317
// 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>
operator Matcher<Container>() const { operator Matcher<Container>() const {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
// Nokia's Symbian Compiler has a nasty bug where the object put // Nokia's Symbian Compiler has a nasty bug where the object put
// in a one-element local array is not destructed when the array // in a one-element local array is not destructed when the array
// goes out of scope. This leads to obvious badness as we've // goes out of scope. This leads to obvious badness as we've
// 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 =
skipping to change at line 347 skipping to change at line 345
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher1); 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 GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
const Matcher<const Element&> matchers[] = { const Matcher<const Element&> matchers[] = {
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));
} }
skipping to change at line 375 skipping to change at line 372
}; };
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 {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
const Matcher<const Element&> matchers[] = { const Matcher<const Element&> matchers[] = {
MatcherCast<const Element&>(e1_), MatcherCast<const Element&>(e1_),
MatcherCast<const Element&>(e2_), MatcherCast<const Element&>(e2_),
MatcherCast<const Element&>(e3_), MatcherCast<const Element&>(e3_),
}; };
return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 3)); return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 3));
skipping to change at line 405 skipping to change at line 401
}; };
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 {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
const Matcher<const Element&> matchers[] = { const Matcher<const Element&> matchers[] = {
MatcherCast<const Element&>(e1_), MatcherCast<const Element&>(e1_),
MatcherCast<const Element&>(e2_), MatcherCast<const Element&>(e2_),
MatcherCast<const Element&>(e3_), MatcherCast<const Element&>(e3_),
MatcherCast<const Element&>(e4_), MatcherCast<const Element&>(e4_),
}; };
skipping to change at line 437 skipping to change at line 432
}; };
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 {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
const Matcher<const Element&> matchers[] = { const Matcher<const Element&> matchers[] = {
MatcherCast<const Element&>(e1_), MatcherCast<const Element&>(e1_),
MatcherCast<const Element&>(e2_), MatcherCast<const Element&>(e2_),
MatcherCast<const Element&>(e3_), MatcherCast<const Element&>(e3_),
MatcherCast<const Element&>(e4_), MatcherCast<const Element&>(e4_),
MatcherCast<const Element&>(e5_), MatcherCast<const Element&>(e5_),
}; };
skipping to change at line 473 skipping to change at line 467
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) {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
const Matcher<const Element&> matchers[] = { const Matcher<const Element&> matchers[] = {
MatcherCast<const Element&>(e1_), MatcherCast<const Element&>(e1_),
MatcherCast<const Element&>(e2_), MatcherCast<const Element&>(e2_),
MatcherCast<const Element&>(e3_), MatcherCast<const Element&>(e3_),
MatcherCast<const Element&>(e4_), MatcherCast<const Element&>(e4_),
MatcherCast<const Element&>(e5_), MatcherCast<const Element&>(e5_),
MatcherCast<const Element&>(e6_), MatcherCast<const Element&>(e6_),
skipping to change at line 511 skipping to change at line 504
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) {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
const Matcher<const Element&> matchers[] = { const Matcher<const Element&> matchers[] = {
MatcherCast<const Element&>(e1_), MatcherCast<const Element&>(e1_),
MatcherCast<const Element&>(e2_), MatcherCast<const Element&>(e2_),
MatcherCast<const Element&>(e3_), MatcherCast<const Element&>(e3_),
MatcherCast<const Element&>(e4_), MatcherCast<const Element&>(e4_),
MatcherCast<const Element&>(e5_), MatcherCast<const Element&>(e5_),
MatcherCast<const Element&>(e6_), MatcherCast<const Element&>(e6_),
skipping to change at line 551 skipping to change at line 543
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) {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
const Matcher<const Element&> matchers[] = { const Matcher<const Element&> matchers[] = {
MatcherCast<const Element&>(e1_), MatcherCast<const Element&>(e1_),
MatcherCast<const Element&>(e2_), MatcherCast<const Element&>(e2_),
MatcherCast<const Element&>(e3_), MatcherCast<const Element&>(e3_),
MatcherCast<const Element&>(e4_), MatcherCast<const Element&>(e4_),
MatcherCast<const Element&>(e5_), MatcherCast<const Element&>(e5_),
MatcherCast<const Element&>(e6_), MatcherCast<const Element&>(e6_),
skipping to change at line 594 skipping to change at line 585
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) {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
const Matcher<const Element&> matchers[] = { const Matcher<const Element&> matchers[] = {
MatcherCast<const Element&>(e1_), MatcherCast<const Element&>(e1_),
MatcherCast<const Element&>(e2_), MatcherCast<const Element&>(e2_),
MatcherCast<const Element&>(e3_), MatcherCast<const Element&>(e3_),
MatcherCast<const Element&>(e4_), MatcherCast<const Element&>(e4_),
MatcherCast<const Element&>(e5_), MatcherCast<const Element&>(e5_),
MatcherCast<const Element&>(e6_), MatcherCast<const Element&>(e6_),
skipping to change at line 639 skipping to change at line 629
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) {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
const Matcher<const Element&> matchers[] = { const Matcher<const Element&> matchers[] = {
MatcherCast<const Element&>(e1_), MatcherCast<const Element&>(e1_),
MatcherCast<const Element&>(e2_), MatcherCast<const Element&>(e2_),
MatcherCast<const Element&>(e3_), MatcherCast<const Element&>(e3_),
MatcherCast<const Element&>(e4_), MatcherCast<const Element&>(e4_),
MatcherCast<const Element&>(e5_), MatcherCast<const Element&>(e5_),
MatcherCast<const Element&>(e6_), MatcherCast<const Element&>(e6_),
skipping to change at line 863 skipping to change at line 852
const T* first, size_t count) { const T* first, size_t count) {
return internal::ElementsAreArrayMatcher<T>(first, count); return internal::ElementsAreArrayMatcher<T>(first, count);
} }
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);
} }
// AllOf(m1, m2, ..., mk) matches any value that matches all of the given
// sub-matchers. AllOf is called fully qualified to prevent ADL from firin
g.
template <typename Matcher1, typename Matcher2>
inline internal::BothOfMatcher<Matcher1, Matcher2>
AllOf(Matcher1 m1, Matcher2 m2) {
return internal::BothOfMatcher<Matcher1, Matcher2>(m1, m2);
}
template <typename Matcher1, typename Matcher2, typename Matcher3>
inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2,
Matcher3> >
AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) {
return ::testing::AllOf(m1, ::testing::AllOf(m2, m3));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4>
inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2,
internal::BothOfMatcher<Matcher3, Matcher4> > >
AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) {
return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5>
inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2,
internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4,
Matcher5> > > >
AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) {
return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5, typename Matcher6>
inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2,
internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4,
internal::BothOfMatcher<Matcher5, Matcher6> > > > >
AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5,
Matcher6 m6) {
return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5, typename Matcher6, typename Match
er7>
inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2,
internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4,
internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6,
Matcher7> > > > > >
AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5,
Matcher6 m6, Matcher7 m7) {
return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5, typename Matcher6, typename Match
er7,
typename Matcher8>
inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2,
internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4,
internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6,
internal::BothOfMatcher<Matcher7, Matcher8> > > > > > >
AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5,
Matcher6 m6, Matcher7 m7, Matcher8 m8) {
return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8))
;
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5, typename Matcher6, typename Match
er7,
typename Matcher8, typename Matcher9>
inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2,
internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4,
internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6,
internal::BothOfMatcher<Matcher7, internal::BothOfMatcher<Matcher8,
Matcher9> > > > > > > >
AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5,
Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9) {
return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8,
m9));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5, typename Matcher6, typename Match
er7,
typename Matcher8, typename Matcher9, typename Matcher10>
inline internal::BothOfMatcher<Matcher1, internal::BothOfMatcher<Matcher2,
internal::BothOfMatcher<Matcher3, internal::BothOfMatcher<Matcher4,
internal::BothOfMatcher<Matcher5, internal::BothOfMatcher<Matcher6,
internal::BothOfMatcher<Matcher7, internal::BothOfMatcher<Matcher8,
internal::BothOfMatcher<Matcher9, Matcher10> > > > > > > > >
AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5,
Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9, Matcher10 m10) {
return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5, m6, m7, m8,
m9,
m10));
}
// AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
// sub-matchers. AnyOf is called fully qualified to prevent ADL from firin
g.
template <typename Matcher1, typename Matcher2>
inline internal::EitherOfMatcher<Matcher1, Matcher2>
AnyOf(Matcher1 m1, Matcher2 m2) {
return internal::EitherOfMatcher<Matcher1, Matcher2>(m1, m2);
}
template <typename Matcher1, typename Matcher2, typename Matcher3>
inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matche
r2,
Matcher3> >
AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) {
return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4>
inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matche
r2,
internal::EitherOfMatcher<Matcher3, Matcher4> > >
AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) {
return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5>
inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matche
r2,
internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4,
Matcher5> > > >
AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) {
return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5, typename Matcher6>
inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matche
r2,
internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4,
internal::EitherOfMatcher<Matcher5, Matcher6> > > > >
AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5,
Matcher6 m6) {
return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5, typename Matcher6, typename Match
er7>
inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matche
r2,
internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4,
internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6,
Matcher7> > > > > >
AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5,
Matcher6 m6, Matcher7 m7) {
return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5, typename Matcher6, typename Match
er7,
typename Matcher8>
inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matche
r2,
internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4,
internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6,
internal::EitherOfMatcher<Matcher7, Matcher8> > > > > > >
AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5,
Matcher6 m6, Matcher7 m7, Matcher8 m8) {
return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8))
;
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5, typename Matcher6, typename Match
er7,
typename Matcher8, typename Matcher9>
inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matche
r2,
internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4,
internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6,
internal::EitherOfMatcher<Matcher7, internal::EitherOfMatcher<Matcher8,
Matcher9> > > > > > > >
AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5,
Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9) {
return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8,
m9));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5, typename Matcher6, typename Match
er7,
typename Matcher8, typename Matcher9, typename Matcher10>
inline internal::EitherOfMatcher<Matcher1, internal::EitherOfMatcher<Matche
r2,
internal::EitherOfMatcher<Matcher3, internal::EitherOfMatcher<Matcher4,
internal::EitherOfMatcher<Matcher5, internal::EitherOfMatcher<Matcher6,
internal::EitherOfMatcher<Matcher7, internal::EitherOfMatcher<Matcher8,
internal::EitherOfMatcher<Matcher9, Matcher10> > > > > > > > >
AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5,
Matcher6 m6, Matcher7 m7, Matcher8 m8, Matcher9 m9, Matcher10 m10) {
return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5, m6, m7, m8,
m9,
m10));
}
} // 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. // define custom matchers easily.
// //
// Basic Usage // Basic Usage
// =========== // ===========
// //
// The syntax // The syntax
// //
skipping to change at line 960 skipping to change at line 1135
// 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 // Describing Parameterized Matchers
// ================================= // =================================
// //
// When defining a parameterized matcher, you can use Python-style // The last argument to MATCHER*() is a string-typed expression. The
// interpolations in the description string to refer to the parameter // expression can reference all of the matcher's parameters and a
// values. We support the following syntax currently: // special bool-typed variable named 'negation'. When 'negation' is
// // false, the expression should evaluate to the matcher's description;
// %% a single '%' character // otherwise it should evaluate to the description of the negation of
// %(*)s all parameters of the matcher printed as a tuple // the matcher. For example,
// %(foo)s value of the matcher parameter named 'foo'
// //
// For example, // using testing::PrintToString;
// //
// MATCHER_P2(InClosedRange, low, hi, "is in range [%(low)s, %(hi)s]") { // MATCHER_P2(InClosedRange, low, hi,
// string(negation ? "is not" : "is") + " in range [" +
// PrintToString(low) + ", " + PrintToString(hi) + "]") {
// return low <= arg && arg <= hi; // return low <= arg && arg <= hi;
// } // }
// ... // ...
// EXPECT_THAT(3, InClosedRange(4, 6)); // EXPECT_THAT(3, InClosedRange(4, 6));
// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
// //
// would generate a failure that contains the message: // would generate two failures that contain the text:
// //
// Expected: is in range [4, 6] // Expected: is in range [4, 6]
// ...
// Expected: is not in range [2, 4]
// //
// If you specify "" as the description, the failure message will // If you specify "" as the description, the failure message will
// contain the sequence of words in the matcher name followed by the // contain the sequence of words in the matcher name followed by the
// 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));
// EXPECT_THAT(3, Not(InClosedRange(2, 4)));
// //
// would generate a failure that contains the text: // would generate two failures that contain the text:
// //
// Expected: in closed range (4, 6) // Expected: in closed range (4, 6)
// ...
// Expected: not (in closed range (2, 4))
// //
// Types of Matcher Parameters // 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
// //
skipping to change at line 1079 skipping to change at line 1261
// //
// 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()\
: gmock_interp_(gmock_interp) {}\ {}\
virtual bool MatchAndExplain(\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co nst;\ 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 = \ *gmock_os << FormatDescription(false);\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ }\
::std::tr1::tuple<>());\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << FormatDescription(true);\
#name, description, gmock_interp_, gmock_printed_param
s);\
}\ }\
const ::testing::internal::Interpolations gmock_interp_;\
private:\ private:\
::testing::internal::string FormatDescription(bool negation) const {\
const ::testing::internal::string gmock_description = (description)
;\
if (!gmock_description.empty())\
return gmock_description;\
return ::testing::internal::FormatMatcherDescription(\
negation, #name,\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<>()));\
}\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 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>());\
}\ }\
name##Matcher() {\ name##Matcher() {\
const char* gmock_param_names[] = { NULL };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\
}\ }\
private:\ private:\
::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##Matcher);\ 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::gmock_Impl<arg_type>::MatchAndExplain(\ bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\
arg_type arg,\ arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE D_)\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE D_)\
const 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)\ : p0(gmock_p0) {}\
: p0(gmock_p0), gmock_interp_(gmock_interp) {}\
virtual bool MatchAndExplain(\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co nst;\ 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 = \ *gmock_os << FormatDescription(false);\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ }\
::std::tr1::tuple<p0##_type>(p0));\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << FormatDescription(true);\
#name, description, gmock_interp_, gmock_printed_param
s);\
}\ }\
p0##_type p0;\ p0##_type p0;\
const ::testing::internal::Interpolations gmock_interp_;\
private:\ private:\
::testing::internal::string FormatDescription(bool negation) const {\
const ::testing::internal::string gmock_description = (description)
;\
if (!gmock_description.empty())\
return gmock_description;\
return ::testing::internal::FormatMatcherDescription(\
negation, #name,\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type>(p0)));\
}\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 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));\
}\ }\
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 };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\
}\ }\
p0##_type p0;\ p0##_type p0;\
private:\ private:\
::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP);\ 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>::gmock_Impl<arg_type>::MatchAndExplain(\ bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
arg_type arg,\ arg_type arg,\
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE D_)\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE D_)\
const 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)\ : p0(gmock_p0), p1(gmock_p1) {}\
: p0(gmock_p0), p1(gmock_p1), gmock_interp_(gmock_interp) {}\
virtual bool MatchAndExplain(\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co nst;\ 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 = \ *gmock_os << FormatDescription(false);\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ }\
::std::tr1::tuple<p0##_type, p1##_type>(p0, p1));\ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
*gmock_os << ::testing::internal::FormatMatcherDescription(\ *gmock_os << FormatDescription(true);\
#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_;\
private:\ private:\
::testing::internal::string FormatDescription(bool negation) const {\
const ::testing::internal::string gmock_description = (description)
;\
if (!gmock_description.empty())\
return gmock_description;\
return ::testing::internal::FormatMatcherDescription(\
negation, #name,\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type>(p0, p1)));\
}\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 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));\
}\ }\
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 };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
private:\ private:\
::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\ 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, \ bool name##MatcherP2<p0##_type, \
skipping to change at line 1229 skipping to change at line 1418
::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE D_)\ ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSE D_)\
const 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)\ : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
: p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
gmock_interp_(gmock_interp) {}\
virtual bool MatchAndExplain(\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co nst;\ 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 = \ *gmock_os << FormatDescription(false);\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ }\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
\ *gmock_os << FormatDescription(true);\
p2));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\
#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_;\
private:\ private:\
::testing::internal::string FormatDescription(bool negation) const {\
const ::testing::internal::string gmock_description = (description)
;\
if (!gmock_description.empty())\
return gmock_description;\
return ::testing::internal::FormatMatcherDescription(\
negation, #name,\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1,
\
p2)));\
}\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 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));\
}\ }\
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 };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
gmock_param_names, ("" description ""));\
}\ }\
p0##_type p0;\ p0##_type p0;\
p1##_type p1;\ p1##_type p1;\
p2##_type p2;\ p2##_type p2;\
private:\ private:\
::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\ 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, \ bool name##MatcherP3<p0##_type, p1##_type, \
skipping to change at line 1290 skipping to change at line 1480
#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)\ : 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) {}\
virtual bool MatchAndExplain(\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co nst;\ 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 = \ *gmock_os << FormatDescription(false);\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ }\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
p3##_type>(p0, p1, p2, p3));\ *gmock_os << FormatDescription(true);\
*gmock_os << ::testing::internal::FormatMatcherDescription(\
#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_;\
private:\ private:\
::testing::internal::string FormatDescription(bool negation) const {\
const ::testing::internal::string gmock_description = (description)
;\
if (!gmock_description.empty())\
return gmock_description;\
return ::testing::internal::FormatMatcherDescription(\
negation, #name,\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \
p3##_type>(p0, p1, p2, p3)));\
}\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 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));\
}\ }\
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 };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
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:\ private:\
::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\ 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);\
}\ }\
skipping to change at line 1358 skipping to change at line 1549
#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)\
: 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) {}\
virtual bool MatchAndExplain(\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co nst;\ 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 = \ *gmock_os << FormatDescription(false);\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ }\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
e, \ *gmock_os << FormatDescription(true);\
p4##_type>(p0, p1, p2, p3, p4));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\
#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_;\
private:\ private:\
::testing::internal::string FormatDescription(bool negation) const {\
const ::testing::internal::string gmock_description = (description)
;\
if (!gmock_description.empty())\
return gmock_description;\
return ::testing::internal::FormatMatcherDescription(\
negation, #name,\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ
e, \
p4##_type>(p0, p1, p2, p3, p4)));\
}\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 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));\
}\ }\
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 };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
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:\ private:\
::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\ 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);\
}\ }\
skipping to change at line 1429 skipping to change at line 1622
#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)\
: 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) {}\
virtual bool MatchAndExplain(\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co nst;\ 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 = \ *gmock_os << FormatDescription(false);\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ }\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
e, \ *gmock_os << FormatDescription(true);\
p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\
#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_;\
private:\ private:\
::testing::internal::string FormatDescription(bool negation) const {\
const ::testing::internal::string gmock_description = (description)
;\
if (!gmock_description.empty())\
return gmock_description;\
return ::testing::internal::FormatMatcherDescription(\
negation, #name,\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ
e, \
p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\
}\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 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));\
}\ }\
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 };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
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:\ private:\
::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\ 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);\
}\ }\
skipping to change at line 1504 skipping to change at line 1699
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)\
: 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) {}\
virtual bool MatchAndExplain(\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co nst;\ 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 = \ *gmock_os << FormatDescription(false);\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ }\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
e, \ *gmock_os << FormatDescription(true);\
p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5
, \
p6));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\
#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_;\
private:\ private:\
::testing::internal::string FormatDescription(bool negation) const {\
const ::testing::internal::string gmock_description = (description)
;\
if (!gmock_description.empty())\
return gmock_description;\
return ::testing::internal::FormatMatcherDescription(\
negation, #name,\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ
e, \
p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5
, \
p6)));\
}\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 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));\
}\ }\
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), \
p6(gmock_p6) {\ p6(gmock_p6) {\
const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6
, \
NULL };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
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:\ private:\
::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\ 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, \
skipping to change at line 1588 skipping to change at line 1783
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)\
: 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) {}\
virtual bool MatchAndExplain(\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co nst;\ 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 = \ *gmock_os << FormatDescription(false);\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ }\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
e, \ *gmock_os << FormatDescription(true);\
p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2,
\
p3, p4, p5, p6, p7));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\
#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_;\
private:\ private:\
::testing::internal::string FormatDescription(bool negation) const {\
const ::testing::internal::string gmock_description = (description)
;\
if (!gmock_description.empty())\
return gmock_description;\
return ::testing::internal::FormatMatcherDescription(\
negation, #name,\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ
e, \
p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2,
\
p3, p4, p5, p6, p7)));\
}\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 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_));\
}\ }\
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, \
p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
p7(gmock_p7) {\ p7(gmock_p7) {\
const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6
, \
#p7, NULL };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
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:\ private:\
::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\ 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, \
skipping to change at line 1678 skipping to change at line 1872
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)\
: 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) {}\
virtual bool MatchAndExplain(\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co nst;\ 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 = \ *gmock_os << FormatDescription(false);\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ }\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
e, \ *gmock_os << FormatDescription(true);\
p4##_type, p5##_type, p6##_type, p7##_type, \
p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\
#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_;\
private:\ private:\
::testing::internal::string FormatDescription(bool negation) const {\
const ::testing::internal::string gmock_description = (description)
;\
if (!gmock_description.empty())\
return gmock_description;\
return ::testing::internal::FormatMatcherDescription(\
negation, #name,\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ
e, \
p4##_type, p5##_type, p6##_type, p7##_type, \
p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\
}\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 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_));\
}\ }\
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, \
p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7 ), \ p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7 ), \
p8(gmock_p8) {\ p8(gmock_p8) {\
const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6
, \
#p7, #p8, NULL };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
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;\
p8##_type p8;\ p8##_type p8;\
private:\ private:\
::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\ 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) {\
skipping to change at line 1773 skipping to change at line 1967
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)\
: 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) {}\
virtual bool MatchAndExplain(\ virtual bool MatchAndExplain(\
arg_type arg, ::testing::MatchResultListener* result_listener) co nst;\ 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 = \ *gmock_os << FormatDescription(false);\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\ }\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
e, \ *gmock_os << FormatDescription(true);\
p4##_type, p5##_type, p6##_type, p7##_type, p8##_type,
\
p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\
*gmock_os << ::testing::internal::FormatMatcherDescription(\
#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_;\
private:\ private:\
::testing::internal::string FormatDescription(bool negation) const {\
const ::testing::internal::string gmock_description = (description)
;\
if (!gmock_description.empty())\
return gmock_description;\
return ::testing::internal::FormatMatcherDescription(\
negation, #name,\
::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_typ
e, \
p4##_type, p5##_type, p6##_type, p7##_type, p8##_type,
\
p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\
}\
GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ 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_));\
}\ }\
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, \
p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1 ), \ p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1 ), \
p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6 ), \ p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6 ), \
p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\ p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\
const char* gmock_param_names[] = { #p0, #p1, #p2, #p3, #p4, #p5, #p6
, \
#p7, #p8, #p9, NULL };\
gmock_interp_ = ::testing::internal::ValidateMatcherDescription(\
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;\
p8##_type p8;\ p8##_type p8;\
p9##_type p9;\ p9##_type p9;\
private:\ private:\
::testing::internal::Interpolations gmock_interp_;\
GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\ 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, \
 End of changes. 105 change blocks. 
238 lines changed or deleted 451 lines changed or added


 gmock-generated-nice-strict.h   gmock-generated-nice-strict.h 
skipping to change at line 62 skipping to change at line 62
// "strict" modifier may not affect it, depending on the compiler. In // "strict" modifier may not affect it, depending on the compiler. In
// particular, nesting NiceMock and StrictMock is NOT supported. // particular, nesting NiceMock and StrictMock is NOT supported.
// //
// Another known limitation is that the constructors of the base mock // Another known limitation is that the constructors of the base mock
// cannot have arguments passed by non-const reference, which are // cannot have arguments passed by non-const reference, which are
// banned by the Google C++ style guide anyway. // banned by the Google C++ style guide anyway.
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
#include <gmock/gmock-spec-builders.h> #include "gmock/gmock-spec-builders.h"
#include <gmock/internal/gmock-port.h> #include "gmock/internal/gmock-port.h"
namespace testing { namespace testing {
template <class MockClass> template <class MockClass>
class NiceMock : public MockClass { class NiceMock : 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.
NiceMock() { NiceMock() {
::testing::Mock::AllowUninterestingCalls( ::testing::Mock::AllowUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
// C++ doesn't (yet) allow inheritance of constructors, so we have // C++ doesn't (yet) allow inheritance of constructors, so we have
// to define it for each arity. // to define it for each arity.
template <typename A1> template <typename A1>
explicit NiceMock(const A1& a1) : MockClass(a1) { explicit NiceMock(const A1& a1) : MockClass(a1) {
::testing::Mock::AllowUninterestingCalls( ::testing::Mock::AllowUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2> template <typename A1, typename A2>
NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
::testing::Mock::AllowUninterestingCalls( ::testing::Mock::AllowUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3> template <typename A1, typename A2, typename A3>
NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3 ) { NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3 ) {
::testing::Mock::AllowUninterestingCalls( ::testing::Mock::AllowUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4> template <typename A1, typename A2, typename A3, typename A4>
NiceMock(const A1& a1, const A2& a2, const A3& a3, NiceMock(const A1& a1, const A2& a2, const A3& a3,
const A4& a4) : MockClass(a1, a2, a3, a4) { const A4& a4) : MockClass(a1, a2, a3, a4) {
::testing::Mock::AllowUninterestingCalls( ::testing::Mock::AllowUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 > template <typename A1, typename A2, typename A3, typename A4, typename A5 >
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5) : MockClass(a1, a2, a3, a4, a5) { const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
::testing::Mock::AllowUninterestingCalls( ::testing::Mock::AllowUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 , template <typename A1, typename A2, typename A3, typename A4, typename A5 ,
typename A6> typename A6>
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
::testing::Mock::AllowUninterestingCalls( ::testing::Mock::AllowUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 , template <typename A1, typename A2, typename A3, typename A4, typename A5 ,
typename A6, typename A7> typename A6, typename A7>
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
a6, a7) { a6, a7) {
::testing::Mock::AllowUninterestingCalls( ::testing::Mock::AllowUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 , template <typename A1, typename A2, typename A3, typename A4, typename A5 ,
typename A6, typename A7, typename A8> typename A6, typename A7, typename A8>
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a 1, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a 1,
a2, a3, a4, a5, a6, a7, a8) { a2, a3, a4, a5, a6, a7, a8) {
::testing::Mock::AllowUninterestingCalls( ::testing::Mock::AllowUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 , template <typename A1, typename A2, typename A3, typename A4, typename A5 ,
typename A6, typename A7, typename A8, typename A9> typename A6, typename A7, typename A8, typename A9>
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A5& a5, const A6& a6, const A7& a7, const A8& a8,
const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
::testing::Mock::AllowUninterestingCalls( ::testing::Mock::AllowUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 , template <typename A1, typename A2, typename A3, typename A4, typename A5 ,
typename A6, typename A7, typename A8, typename A9, typename A10> typename A6, typename A7, typename A8, typename A9, typename A10>
NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
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::ImplicitCast_<MockClass*>(this));
} }
virtual ~NiceMock() { virtual ~NiceMock() {
::testing::Mock::UnregisterCallReaction( ::testing::Mock::UnregisterCallReaction(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); 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::ImplicitCast_<MockClass*>(this));
} }
template <typename A1> template <typename A1>
explicit StrictMock(const A1& a1) : MockClass(a1) { explicit StrictMock(const A1& a1) : MockClass(a1) {
::testing::Mock::FailUninterestingCalls( ::testing::Mock::FailUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2> template <typename A1, typename A2>
StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) {
::testing::Mock::FailUninterestingCalls( ::testing::Mock::FailUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3> template <typename A1, typename A2, typename A3>
StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) {
::testing::Mock::FailUninterestingCalls( ::testing::Mock::FailUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4> template <typename A1, typename A2, typename A3, typename A4>
StrictMock(const A1& a1, const A2& a2, const A3& a3, StrictMock(const A1& a1, const A2& a2, const A3& a3,
const A4& a4) : MockClass(a1, a2, a3, a4) { const A4& a4) : MockClass(a1, a2, a3, a4) {
::testing::Mock::FailUninterestingCalls( ::testing::Mock::FailUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 > template <typename A1, typename A2, typename A3, typename A4, typename A5 >
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5) : MockClass(a1, a2, a3, a4, a5) { const A5& a5) : MockClass(a1, a2, a3, a4, a5) {
::testing::Mock::FailUninterestingCalls( ::testing::Mock::FailUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 , template <typename A1, typename A2, typename A3, typename A4, typename A5 ,
typename A6> typename A6>
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) { const A5& a5, const A6& a6) : MockClass(a1, a2, a3, a4, a5, a6) {
::testing::Mock::FailUninterestingCalls( ::testing::Mock::FailUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 , template <typename A1, typename A2, typename A3, typename A4, typename A5 ,
typename A6, typename A7> typename A6, typename A7>
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5, const A5& a5, const A6& a6, const A7& a7) : MockClass(a1, a2, a3, a4, a5,
a6, a7) { a6, a7) {
::testing::Mock::FailUninterestingCalls( ::testing::Mock::FailUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 , template <typename A1, typename A2, typename A3, typename A4, typename A5 ,
typename A6, typename A7, typename A8> typename A6, typename A7, typename A8>
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a 1, const A5& a5, const A6& a6, const A7& a7, const A8& a8) : MockClass(a 1,
a2, a3, a4, a5, a6, a7, a8) { a2, a3, a4, a5, a6, a7, a8) {
::testing::Mock::FailUninterestingCalls( ::testing::Mock::FailUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 , template <typename A1, typename A2, typename A3, typename A4, typename A5 ,
typename A6, typename A7, typename A8, typename A9> typename A6, typename A7, typename A8, typename A9>
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A5& a5, const A6& a6, const A7& a7, const A8& a8,
const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { const A9& a9) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
::testing::Mock::FailUninterestingCalls( ::testing::Mock::FailUninterestingCalls(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
template <typename A1, typename A2, typename A3, typename A4, typename A5 , template <typename A1, typename A2, typename A3, typename A4, typename A5 ,
typename A6, typename A7, typename A8, typename A9, typename A10> typename A6, typename A7, typename A8, typename A9, typename A10>
StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4,
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::ImplicitCast_<MockClass*>(this));
} }
virtual ~StrictMock() { virtual ~StrictMock() {
::testing::Mock::UnregisterCallReaction( ::testing::Mock::UnregisterCallReaction(
internal::implicit_cast<MockClass*>(this)); internal::ImplicitCast_<MockClass*>(this));
} }
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); 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.
 End of changes. 25 change blocks. 
26 lines changed or deleted 26 lines changed or added


 gmock-internal-utils.h   gmock-internal-utils.h 
skipping to change at line 45 skipping to change at line 45
// Mock. They are subject to change without notice, so please DO NOT // Mock. They are subject to change without notice, so please DO NOT
// USE THEM IN USER CODE. // USE THEM IN USER CODE.
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
#include <stdio.h> #include <stdio.h>
#include <ostream> // NOLINT #include <ostream> // NOLINT
#include <string> #include <string>
#include <gmock/internal/gmock-generated-internal-utils.h> #include "gmock/internal/gmock-generated-internal-utils.h"
#include <gmock/internal/gmock-port.h> #include "gmock/internal/gmock-port.h"
#include <gtest/gtest.h> #include "gtest/gtest.h"
// Concatenates two pre-processor symbols; works for concatenating
// built-in macros like __FILE__ and __LINE__.
#define GMOCK_CONCAT_TOKEN_IMPL_(foo, bar) foo##bar
#define GMOCK_CONCAT_TOKEN_(foo, bar) GMOCK_CONCAT_TOKEN_IMPL_(foo, bar)
#ifdef __GNUC__
#define GMOCK_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
#else
#define GMOCK_ATTRIBUTE_UNUSED_
#endif // __GNUC__
class ProtocolMessage;
namespace proto2 { class Message; }
namespace testing { namespace testing {
namespace internal { namespace internal {
// Converts an identifier name to a space-separated list of lower-case // Converts an identifier name to a space-separated list of lower-case
// words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is // words. Each maximum substring of the form [A-Za-z][a-z]*|\d+ is
// treated as one word. For example, both "FooBar123" and // treated as one word. For example, both "FooBar123" and
// "foo_bar_123" are converted to "foo bar 123". // "foo_bar_123" are converted to "foo bar 123".
string ConvertIdentifierNameToWords(const char* id_name); string ConvertIdentifierNameToWords(const char* id_name);
// Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
// compiler error iff T1 and T2 are different types.
template <typename T1, typename T2>
struct CompileAssertTypesEqual;
template <typename T>
struct CompileAssertTypesEqual<T, T> {
};
// Removes the reference from a type if it is a reference type,
// otherwise leaves it unchanged. This is the same as
// tr1::remove_reference, which is not widely available yet.
template <typename T>
struct RemoveReference { typedef T type; }; // NOLINT
template <typename T>
struct RemoveReference<T&> { typedef T type; }; // NOLINT
// A handy wrapper around RemoveReference that works when the argument
// T depends on template parameters.
#define GMOCK_REMOVE_REFERENCE_(T) \
typename ::testing::internal::RemoveReference<T>::type
// Removes const from a type if it is a const type, otherwise leaves
// it unchanged. This is the same as tr1::remove_const, which is not
// widely available yet.
template <typename T>
struct RemoveConst { typedef T type; }; // NOLINT
template <typename T>
struct RemoveConst<const T> { typedef T type; }; // NOLINT
// MSVC 8.0 has a bug which causes the above definition to fail to
// remove the const in 'const int[3]'. The following specialization
// works around the bug. However, it causes trouble with gcc and thus
// needs to be conditionally compiled.
#ifdef _MSC_VER
template <typename T, size_t N>
struct RemoveConst<T[N]> {
typedef typename RemoveConst<T>::type type[N];
};
#endif // _MSC_VER
// A handy wrapper around RemoveConst that works when the argument
// T depends on template parameters.
#define GMOCK_REMOVE_CONST_(T) \
typename ::testing::internal::RemoveConst<T>::type
// Adds reference to a type if it is not a reference type,
// otherwise leaves it unchanged. This is the same as
// tr1::add_reference, which is not widely available yet.
template <typename T>
struct AddReference { typedef T& type; }; // NOLINT
template <typename T>
struct AddReference<T&> { typedef T& type; }; // NOLINT
// A handy wrapper around AddReference that works when the argument T
// depends on template parameters.
#define GMOCK_ADD_REFERENCE_(T) \
typename ::testing::internal::AddReference<T>::type
// Adds a reference to const on top of T as necessary. For example,
// it transforms
//
// char ==> const char&
// const char ==> const char&
// char& ==> const char&
// const char& ==> const char&
//
// The argument T must depend on some template parameters.
#define GMOCK_REFERENCE_TO_CONST_(T) \
GMOCK_ADD_REFERENCE_(const GMOCK_REMOVE_REFERENCE_(T))
// PointeeOf<Pointer>::type is the type of a value pointed to by a // PointeeOf<Pointer>::type is the type of a value pointed to by a
// Pointer, which can be either a smart pointer or a raw pointer. The // Pointer, which can be either a smart pointer or a raw pointer. The
// following default implementation is for the case where Pointer is a // following default implementation is for the case where Pointer is a
// smart pointer. // smart pointer.
template <typename Pointer> template <typename Pointer>
struct PointeeOf { struct PointeeOf {
// Smart pointer classes define type element_type as the type of // Smart pointer classes define type element_type as the type of
// their pointees. // their pointees.
typedef typename Pointer::element_type type; typedef typename Pointer::element_type type;
}; };
skipping to change at line 177 skipping to change at line 92
// This comparator allows linked_ptr to be stored in sets. // This comparator allows linked_ptr to be stored in sets.
template <typename T> template <typename T>
struct LinkedPtrLessThan { struct LinkedPtrLessThan {
bool operator()(const ::testing::internal::linked_ptr<T>& lhs, bool operator()(const ::testing::internal::linked_ptr<T>& lhs,
const ::testing::internal::linked_ptr<T>& rhs) const { const ::testing::internal::linked_ptr<T>& rhs) const {
return lhs.get() < rhs.get(); return lhs.get() < rhs.get();
} }
}; };
// ImplicitlyConvertible<From, To>::value is a compile-time bool
// constant that's true iff type From can be implicitly converted to
// type To.
template <typename From, typename To>
class ImplicitlyConvertible {
private:
// We need the following helper functions only for their types.
// They have no implementations.
// MakeFrom() is an expression whose type is From. We cannot simply
// use From(), as the type From may not have a public default
// constructor.
static From MakeFrom();
// These two functions are overloaded. Given an expression
// Helper(x), the compiler will pick the first version if x can be
// implicitly converted to type To; otherwise it will pick the
// second version.
//
// The first version returns a value of size 1, and the second
// version returns a value of size 2. Therefore, by checking the
// size of Helper(x), which can be done at compile time, we can tell
// which version of Helper() is used, and hence whether x can be
// implicitly converted to type To.
static char Helper(To);
static char (&Helper(...))[2]; // NOLINT
// We have to put the 'public' section after the 'private' section,
// or MSVC refuses to compile the code.
public:
// MSVC warns about implicitly converting from double to int for
// possible loss of data, so we need to temporarily disable the
// warning.
#ifdef _MSC_VER
#pragma warning(push) // Saves the current warning state.
#pragma warning(disable:4244) // Temporarily disables warning 4244.
static const bool value =
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
#pragma warning(pop) // Restores the warning state.
#else
static const bool value =
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
#endif // _MSV_VER
};
template <typename From, typename To>
const bool ImplicitlyConvertible<From, To>::value;
// Symbian compilation can be done with wchar_t being either a native // Symbian compilation can be done with wchar_t being either a native
// type or a typedef. Using Google Mock with OpenC without wchar_t // type or a typedef. Using Google Mock with OpenC without wchar_t
// should require the definition of _STLP_NO_WCHAR_T. // should require the definition of _STLP_NO_WCHAR_T.
// //
// MSVC treats wchar_t as a native type usually, but treats it as the // MSVC treats wchar_t as a native type usually, but treats it as the
// same as unsigned short when the compiler option /Zc:wchar_t- is // same as unsigned short when the compiler option /Zc:wchar_t- is
// specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t // specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t
// is a native type. // is a native type.
#if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \ #if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \
(defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)) (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED))
// wchar_t is a typedef. // wchar_t is a typedef.
#else #else
#define GMOCK_WCHAR_T_IS_NATIVE_ 1 # define GMOCK_WCHAR_T_IS_NATIVE_ 1
#endif #endif
// signed wchar_t and unsigned wchar_t are NOT in the C++ standard. // signed wchar_t and unsigned wchar_t are NOT in the C++ standard.
// Using them is a bad practice and not portable. So DON'T use them. // Using them is a bad practice and not portable. So DON'T use them.
// //
// Still, Google Mock is designed to work even if the user uses signed // Still, Google Mock is designed to work even if the user uses signed
// wchar_t or unsigned wchar_t (obviously, assuming the compiler // wchar_t or unsigned wchar_t (obviously, assuming the compiler
// supports them). // supports them).
// //
// To gcc, // To gcc,
// wchar_t == signed wchar_t != unsigned wchar_t == unsigned int // wchar_t == signed wchar_t != unsigned wchar_t == unsigned int
#ifdef __GNUC__ #ifdef __GNUC__
#define GMOCK_HAS_SIGNED_WCHAR_T_ 1 // signed/unsigned wchar_t are valid t // signed/unsigned wchar_t are valid types.
ypes. # define GMOCK_HAS_SIGNED_WCHAR_T_ 1
#endif #endif
// In what follows, we use the term "kind" to indicate whether a type // In what follows, we use the term "kind" to indicate whether a type
// is bool, an integer type (excluding bool), a floating-point type, // is bool, an integer type (excluding bool), a floating-point type,
// or none of them. This categorization is useful for determining // or none of them. This categorization is useful for determining
// when a matcher argument type can be safely converted to another // when a matcher argument type can be safely converted to another
// type in the implementation of SafeMatcherCast. // type in the implementation of SafeMatcherCast.
enum TypeKind { enum TypeKind {
kBool, kInteger, kFloatingPoint, kOther kBool, kInteger, kFloatingPoint, kOther
}; };
skipping to change at line 388 skipping to change at line 257
// //
// It's the user's responsibility to ensure that both From and To are // It's the user's responsibility to ensure that both From and To are
// raw (i.e. has no CV modifier, is not a pointer, and is not a // raw (i.e. has no CV modifier, is not a pointer, and is not a
// reference) built-in arithmetic types; the value is // reference) built-in arithmetic types; the value is
// implementation-defined when the above pre-condition is violated. // implementation-defined when the above pre-condition is violated.
template <typename From, typename To> template <typename From, typename To>
struct LosslessArithmeticConvertible struct LosslessArithmeticConvertible
: public LosslessArithmeticConvertibleImpl< : public LosslessArithmeticConvertibleImpl<
GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT
// IsAProtocolMessage<T>::value is a compile-time bool constant that's
// true iff T is type ProtocolMessage, proto2::Message, or a subclass
// of those.
template <typename T>
struct IsAProtocolMessage
: public bool_constant<
ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||
ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {
};
// When the compiler sees expression IsContainerTest<C>(0), the first
// overload of IsContainerTest will be picked if C is an STL-style
// container class (since C::const_iterator* is a valid type and 0 can
// be converted to it), while the second overload will be picked
// otherwise (since C::const_iterator will be an invalid type in this
// case). Therefore, we can determine whether C is a container class
// by checking the type of IsContainerTest<C>(0). The value of the
// expression is insignificant.
typedef int IsContainer;
template <class C>
IsContainer IsContainerTest(typename C::const_iterator*) { return 0; }
typedef char IsNotContainer;
template <class C>
IsNotContainer IsContainerTest(...) { return '\0'; }
// This interface knows how to report a Google Mock failure (either // This interface knows how to report a Google Mock failure (either
// non-fatal or fatal). // non-fatal or fatal).
class FailureReporterInterface { class FailureReporterInterface {
public: public:
// The type of a failure (either non-fatal or fatal). // The type of a failure (either non-fatal or fatal).
enum FailureType { enum FailureType {
NONFATAL, FATAL NONFATAL, FATAL
}; };
virtual ~FailureReporterInterface() {} virtual ~FailureReporterInterface() {}
skipping to change at line 465 skipping to change at line 308
file, line, msg); file, line, msg);
} }
} }
inline void Expect(bool condition, const char* file, int line) { inline void Expect(bool condition, const char* file, int line) {
Expect(condition, file, line, "Expectation failed."); Expect(condition, file, line, "Expectation failed.");
} }
// Severity level of a log. // Severity level of a log.
enum LogSeverity { enum LogSeverity {
INFO = 0, INFO = 0,
WARNING = 1, WARNING = 1
}; };
// Valid values for the --gmock_verbose flag. // Valid values for the --gmock_verbose flag.
// All logs (informational and warnings) are printed. // All logs (informational and warnings) are printed.
const char kInfoVerbosity[] = "info"; const char kInfoVerbosity[] = "info";
// Only warnings are printed. // Only warnings are printed.
const char kWarningVerbosity[] = "warning"; const char kWarningVerbosity[] = "warning";
// No logs are printed. // No logs are printed.
const char kErrorVerbosity[] = "error"; const char kErrorVerbosity[] = "error";
skipping to change at line 517 skipping to change at line 360
// when a value of type T is needed for compilation, but the statement // when a value of type T is needed for compilation, but the statement
// will not really be executed (or we don't care if the statement // will not really be executed (or we don't care if the statement
// crashes). // crashes).
template <typename T> template <typename T>
inline T Invalid() { inline T Invalid() {
return *static_cast<typename remove_reference<T>::type*>(NULL); return *static_cast<typename remove_reference<T>::type*>(NULL);
} }
template <> template <>
inline void Invalid<void>() {} inline void Invalid<void>() {}
// Utilities for native arrays.
// ArrayEq() compares two k-dimensional native arrays using the
// elements' operator==, where k can be any integer >= 0. When k is
// 0, ArrayEq() degenerates into comparing a single pair of values.
template <typename T, typename U>
bool ArrayEq(const T* lhs, size_t size, const U* rhs);
// This generic version is used when k is 0.
template <typename T, typename U>
inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; }
// This overload is used when k >= 1.
template <typename T, typename U, size_t N>
inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) {
return internal::ArrayEq(lhs, N, rhs);
}
// This helper reduces code bloat. If we instead put its logic inside
// the previous ArrayEq() function, arrays with different sizes would
// lead to different copies of the template code.
template <typename T, typename U>
bool ArrayEq(const T* lhs, size_t size, const U* rhs) {
for (size_t i = 0; i != size; i++) {
if (!internal::ArrayEq(lhs[i], rhs[i]))
return false;
}
return true;
}
// Finds the first element in the iterator range [begin, end) that
// equals elem. Element may be a native array type itself.
template <typename Iter, typename Element>
Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) {
for (Iter it = begin; it != end; ++it) {
if (internal::ArrayEq(*it, elem))
return it;
}
return end;
}
// CopyArray() copies a k-dimensional native array using the elements'
// operator=, where k can be any integer >= 0. When k is 0,
// CopyArray() degenerates into copying a single value.
template <typename T, typename U>
void CopyArray(const T* from, size_t size, U* to);
// This generic version is used when k is 0.
template <typename T, typename U>
inline void CopyArray(const T& from, U* to) { *to = from; }
// This overload is used when k >= 1.
template <typename T, typename U, size_t N>
inline void CopyArray(const T(&from)[N], U(*to)[N]) {
internal::CopyArray(from, N, *to);
}
// This helper reduces code bloat. If we instead put its logic inside
// the previous CopyArray() function, arrays with different sizes
// would lead to different copies of the template code.
template <typename T, typename U>
void CopyArray(const T* from, size_t size, U* to) {
for (size_t i = 0; i != size; i++) {
internal::CopyArray(from[i], to + i);
}
}
// The relation between an NativeArray object (see below) and the
// native array it represents.
enum RelationToSource {
kReference, // The NativeArray references the native array.
kCopy // The NativeArray makes a copy of the native array and
// owns the copy.
};
// Adapts a native array to a read-only STL-style container. Instead
// of the complete STL container concept, this adaptor only implements
// members useful for Google Mock's container matchers. New members
// should be added as needed. To simplify the implementation, we only
// support Element being a raw type (i.e. having no top-level const or
// reference modifier). It's the client's responsibility to satisfy
// this requirement. Element can be an array type itself (hence
// multi-dimensional arrays are supported).
template <typename Element>
class NativeArray {
public:
// STL-style container typedefs.
typedef Element value_type;
typedef const Element* const_iterator;
// Constructs from a native array.
NativeArray(const Element* array, size_t count, RelationToSource relation
) {
Init(array, count, relation);
}
// Copy constructor.
NativeArray(const NativeArray& rhs) {
Init(rhs.array_, rhs.size_, rhs.relation_to_source_);
}
~NativeArray() {
// Ensures that the user doesn't instantiate NativeArray with a
// const or reference type.
testing::StaticAssertTypeEq<Element,
GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Element))>();
if (relation_to_source_ == kCopy)
delete[] array_;
}
// STL-style container methods.
size_t size() const { return size_; }
const_iterator begin() const { return array_; }
const_iterator end() const { return array_ + size_; }
bool operator==(const NativeArray& rhs) const {
return size() == rhs.size() &&
ArrayEq(begin(), size(), rhs.begin());
}
private:
// Not implemented as we don't want to support assignment.
void operator=(const NativeArray& rhs);
// Initializes this object; makes a copy of the input array if
// 'relation' is kCopy.
void Init(const Element* array, size_t a_size, RelationToSource relation)
{
if (relation == kReference) {
array_ = array;
} else {
Element* const copy = new Element[a_size];
CopyArray(array, a_size, copy);
array_ = copy;
}
size_ = a_size;
relation_to_source_ = relation;
}
const Element* array_;
size_t size_;
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
// native array, class StlContainerView<RawContainer> has the // native array, class StlContainerView<RawContainer> has the
// following members: // following members:
// //
// - type is a type that provides an STL-style container view to // - type is a type that provides an STL-style container view to
// (i.e. implements the STL container concept for) RawContainer; // (i.e. implements the STL container concept for) RawContainer;
// - const_reference is a type that provides a reference to a const // - const_reference is a type that provides a reference to a const
// RawContainer; // RawContainer;
// - ConstReference(raw_container) returns a const reference to an STL-st yle // - ConstReference(raw_container) returns a const reference to an STL-st yle
skipping to change at line 685 skipping to change at line 385
// STL-style container. // STL-style container.
template <class RawContainer> template <class RawContainer>
class StlContainerView { class StlContainerView {
public: public:
typedef RawContainer type; typedef RawContainer type;
typedef const type& const_reference; typedef const type& const_reference;
static const_reference ConstReference(const RawContainer& container) { static const_reference ConstReference(const RawContainer& container) {
// Ensures that RawContainer is not a const type. // Ensures that RawContainer is not a const type.
testing::StaticAssertTypeEq<RawContainer, testing::StaticAssertTypeEq<RawContainer,
GMOCK_REMOVE_CONST_(RawContainer)>(); GTEST_REMOVE_CONST_(RawContainer)>();
return container; return container;
} }
static type Copy(const RawContainer& container) { return container; } static type Copy(const RawContainer& container) { return container; }
}; };
// This specialization is used when RawContainer is a native array type. // This specialization is used when RawContainer is a native array type.
template <typename Element, size_t N> template <typename Element, size_t N>
class StlContainerView<Element[N]> { class StlContainerView<Element[N]> {
public: public:
typedef GMOCK_REMOVE_CONST_(Element) RawElement; typedef GTEST_REMOVE_CONST_(Element) RawElement;
typedef internal::NativeArray<RawElement> type; typedef internal::NativeArray<RawElement> type;
// NativeArray<T> can represent a native array either by value or by // NativeArray<T> can represent a native array either by value or by
// reference (selected by a constructor argument), so 'const type' // reference (selected by a constructor argument), so 'const type'
// can be used to reference a const native array. We cannot // can be used to reference a const native array. We cannot
// 'typedef const type& const_reference' here, as that would mean // 'typedef const type& const_reference' here, as that would mean
// ConstReference() has to return a reference to a local variable. // ConstReference() has to return a reference to a local variable.
typedef const type const_reference; typedef const type const_reference;
static const_reference ConstReference(const Element (&array)[N]) { static const_reference ConstReference(const Element (&array)[N]) {
// Ensures that Element is not a const type. // Ensures that Element is not a const type.
skipping to change at line 740 skipping to change at line 440
return type(array, N, kCopy); return type(array, N, kCopy);
#endif // GTEST_OS_SYMBIAN #endif // GTEST_OS_SYMBIAN
} }
}; };
// This specialization is used when RawContainer is a native array // This specialization is used when RawContainer is a native array
// represented as a (pointer, size) tuple. // represented as a (pointer, size) tuple.
template <typename ElementPointer, typename Size> template <typename ElementPointer, typename Size>
class StlContainerView< ::std::tr1::tuple<ElementPointer, Size> > { class StlContainerView< ::std::tr1::tuple<ElementPointer, Size> > {
public: public:
typedef GMOCK_REMOVE_CONST_( typedef GTEST_REMOVE_CONST_(
typename internal::PointeeOf<ElementPointer>::type) RawElement; typename internal::PointeeOf<ElementPointer>::type) RawElement;
typedef internal::NativeArray<RawElement> type; typedef internal::NativeArray<RawElement> type;
typedef const type const_reference; typedef const type const_reference;
static const_reference ConstReference( static const_reference ConstReference(
const ::std::tr1::tuple<ElementPointer, Size>& array) { const ::std::tr1::tuple<ElementPointer, Size>& array) {
using ::std::tr1::get; using ::std::tr1::get;
return type(get<0>(array), get<1>(array), kReference); return type(get<0>(array), get<1>(array), kReference);
} }
static type Copy(const ::std::tr1::tuple<ElementPointer, Size>& array) { static type Copy(const ::std::tr1::tuple<ElementPointer, Size>& array) {
 End of changes. 11 change blocks. 
313 lines changed or deleted 10 lines changed or added


 gmock-matchers.h   gmock-matchers.h 
skipping to change at line 46 skipping to change at line 46
// MatcherInterface<T> interface if necessary. // MatcherInterface<T> interface if necessary.
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_
#include <algorithm> #include <algorithm>
#include <limits> #include <limits>
#include <ostream> // NOLINT #include <ostream> // NOLINT
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include <gmock/gmock-printers.h> #include "gmock/internal/gmock-internal-utils.h"
#include <gmock/internal/gmock-internal-utils.h> #include "gmock/internal/gmock-port.h"
#include <gmock/internal/gmock-port.h> #include "gtest/gtest.h"
#include <gtest/gtest.h>
namespace testing { namespace testing {
// To implement a matcher Foo for type T, define: // To implement a matcher Foo for type T, define:
// 1. a class FooMatcherImpl that implements the // 1. a class FooMatcherImpl that implements the
// 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
skipping to change at line 253 skipping to change at line 253
} // 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:
// Constructs a null matcher. Needed for storing Matcher objects in // Constructs a null matcher. Needed for storing Matcher objects in STL
// STL containers. // containers. A default-constructed matcher is not yet initialized. Yo
u
// cannot use it until a valid value has been assigned to it.
Matcher() {} Matcher() {}
// Constructs a matcher from its implementation. // Constructs a matcher from its implementation.
explicit Matcher(const MatcherInterface<T>* impl) explicit Matcher(const MatcherInterface<T>* impl)
: internal::MatcherBase<T>(impl) {} : internal::MatcherBase<T>(impl) {}
// Implicit constructor here allows people to write // Implicit constructor here allows people to write
// EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) somet imes // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) somet imes
Matcher(T value); // NOLINT Matcher(T value); // NOLINT
}; };
skipping to change at line 422 skipping to change at line 423
// In general, if type T can be implicitly converted to type U, we can // In general, if type T can be implicitly converted to type U, we can
// safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is // safely convert a Matcher<U> to a Matcher<T> (i.e. Matcher is
// contravariant): just keep a copy of the original Matcher<U>, convert t he // contravariant): just keep a copy of the original Matcher<U>, convert t he
// argument from type T to U, and then pass it to the underlying Matcher< U>. // argument from type T to U, and then pass it to the underlying Matcher< U>.
// The only exception is when U is a reference and T is not, as the // The only exception is when U is a reference and T is not, as the
// underlying Matcher<U> may be interested in the argument's address, whi ch // underlying Matcher<U> may be interested in the argument's address, whi ch
// is not preserved in the conversion from T to U. // is not preserved in the conversion from T to U.
template <typename U> template <typename U>
static inline Matcher<T> Cast(const Matcher<U>& matcher) { static inline Matcher<T> Cast(const Matcher<U>& matcher) {
// Enforce that T can be implicitly converted to U. // Enforce that T can be implicitly converted to U.
GMOCK_COMPILE_ASSERT_((internal::ImplicitlyConvertible<T, U>::value), GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible<T, U>::value),
T_must_be_implicitly_convertible_to_U); T_must_be_implicitly_convertible_to_U);
// Enforce that we are not converting a non-reference type T to a refer ence // Enforce that we are not converting a non-reference type T to a refer ence
// type U. // type U.
GMOCK_COMPILE_ASSERT_( GTEST_COMPILE_ASSERT_(
internal::is_reference<T>::value || !internal::is_reference<U>::val ue, internal::is_reference<T>::value || !internal::is_reference<U>::val ue,
cannot_convert_non_referentce_arg_to_reference); cannot_convert_non_referentce_arg_to_reference);
// In case both T and U are arithmetic types, enforce that the // In case both T and U are arithmetic types, enforce that the
// conversion is not lossy. // conversion is not lossy.
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(T)) RawT; typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(U)) RawU; typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU;
const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther; const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther;
const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther; const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther;
GMOCK_COMPILE_ASSERT_( GTEST_COMPILE_ASSERT_(
kTIsOther || kUIsOther || kTIsOther || kUIsOther ||
(internal::LosslessArithmeticConvertible<RawT, RawU>::value), (internal::LosslessArithmeticConvertible<RawT, RawU>::value),
conversion_of_arithmetic_types_must_be_lossless); conversion_of_arithmetic_types_must_be_lossless);
return MatcherCast<T>(matcher); return MatcherCast<T>(matcher);
} }
}; };
template <typename T, typename M> template <typename T, typename M>
inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) { inline Matcher<T> SafeMatcherCast(const M& polymorphic_matcher) {
return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher); return SafeMatcherCastImpl<T>::Cast(polymorphic_matcher);
skipping to change at line 464 skipping to change at line 465
namespace internal { namespace internal {
// If the explanation is not empty, prints it to the ostream. // If the explanation is not empty, prints it to the ostream.
inline void PrintIfNotEmpty(const internal::string& explanation, inline void PrintIfNotEmpty(const internal::string& explanation,
std::ostream* os) { std::ostream* os) {
if (explanation != "" && os != NULL) { if (explanation != "" && os != NULL) {
*os << ", " << explanation; *os << ", " << explanation;
} }
} }
// Returns true if the given type name is easy to read by a human.
// This is used to decide whether printing the type of a value might
// be helpful.
inline bool IsReadableTypeName(const string& type_name) {
// We consider a type name readable if it's short or doesn't contain
// a template or function type.
return (type_name.length() <= 20 ||
type_name.find_first_of("<(") == string::npos);
}
// Matches the value against the given matcher, prints the value and explai ns // Matches the value against the given matcher, prints the value and explai ns
// the match result to the listener. Returns the match result. // the match result to the listener. Returns the match result.
// 'listener' must not be NULL. // 'listener' must not be NULL.
// Value cannot be passed by const reference, because some matchers take a // Value cannot be passed by const reference, because some matchers take a
// non-const argument. // non-const argument.
template <typename Value, typename T> template <typename Value, typename T>
bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher, bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
MatchResultListener* listener) { MatchResultListener* listener) {
if (!listener->IsInterested()) { if (!listener->IsInterested()) {
// If the listener is not interested, we do not need to construct the // If the listener is not interested, we do not need to construct the
// inner explanation. // inner explanation.
return matcher.Matches(value); return matcher.Matches(value);
} }
StringMatchResultListener inner_listener; StringMatchResultListener inner_listener;
const bool match = matcher.MatchAndExplain(value, &inner_listener); const bool match = matcher.MatchAndExplain(value, &inner_listener);
UniversalPrint(value, listener->stream()); UniversalPrint(value, listener->stream());
#if GTEST_HAS_RTTI
const string& type_name = GetTypeName<Value>();
if (IsReadableTypeName(type_name))
*listener->stream() << " (of type " << type_name << ")";
#endif
PrintIfNotEmpty(inner_listener.str(), listener->stream()); PrintIfNotEmpty(inner_listener.str(), listener->stream());
return match; 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:
skipping to change at line 569 skipping to change at line 585
// 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) {
using ::std::tr1::tuple_size; using ::std::tr1::tuple_size;
// Makes sure that matcher_tuple and value_tuple have the same // Makes sure that matcher_tuple and value_tuple have the same
// number of fields. // number of fields.
GMOCK_COMPILE_ASSERT_(tuple_size<MatcherTuple>::value == GTEST_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 ExplainMatchFailureTupleTo(const MatcherTuple& matchers, void ExplainMatchFailureTupleTo(const MatcherTuple& matchers,
skipping to change at line 706 skipping to change at line 722
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 MatchAndExplain(\ virtual bool MatchAndExplain(\
Lhs lhs, MatchResultListener* /* listener */) const { \ Lhs lhs, MatchResultListener* /* listener */) const { \
return lhs op rhs_; \ return lhs op rhs_; \
} \ } \
virtual void DescribeTo(::std::ostream* os) const { \ virtual void DescribeTo(::std::ostream* os) const { \
*os << relation " "; \ *os << relation " "; \
UniversalPrinter<Rhs>::Print(rhs_, os); \ UniversalPrint(rhs_, os); \
} \ } \
virtual void DescribeNegationTo(::std::ostream* os) const { \ virtual void DescribeNegationTo(::std::ostream* os) const { \
*os << negated_relation " "; \ *os << negated_relation " "; \
UniversalPrinter<Rhs>::Print(rhs_, os); \ UniversalPrint(rhs_, os); \
} \ } \
private: \ private: \
Rhs rhs_; \ Rhs rhs_; \
GTEST_DISALLOW_ASSIGN_(Impl); \ GTEST_DISALLOW_ASSIGN_(Impl); \
}; \ }; \
Rhs rhs_; \ Rhs rhs_; \
GTEST_DISALLOW_ASSIGN_(name##Matcher); \ 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)
skipping to change at line 914 skipping to change at line 930
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 << (expect_eq ? "is " : "isn't "); *os << (expect_eq ? "is " : "isn't ");
*os << "equal to "; *os << "equal to ";
if (!case_sensitive_) { if (!case_sensitive_) {
*os << "(ignoring case) "; *os << "(ignoring case) ";
} }
UniversalPrinter<StringType>::Print(string_, os); UniversalPrint(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); GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher);
}; };
// Implements the polymorphic HasSubstr(substring) matcher, which // Implements the polymorphic HasSubstr(substring) matcher, which
skipping to change at line 951 skipping to change at line 967
} }
bool MatchAndExplain(const StringType& s, bool MatchAndExplain(const StringType& s,
MatchResultListener* /* listener */) const { 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); UniversalPrint(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); UniversalPrint(substring_, os);
} }
private: private:
const StringType substring_; const StringType substring_;
GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher); 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
skipping to change at line 992 skipping to change at line 1008
} }
bool MatchAndExplain(const StringType& s, bool MatchAndExplain(const StringType& s,
MatchResultListener* /* listener */) const { 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); UniversalPrint(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); UniversalPrint(prefix_, os);
} }
private: private:
const StringType prefix_; const StringType prefix_;
GTEST_DISALLOW_ASSIGN_(StartsWithMatcher); 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
skipping to change at line 1032 skipping to change at line 1048
} }
bool MatchAndExplain(const StringType& s, bool MatchAndExplain(const StringType& s,
MatchResultListener* /* listener */) const { 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); UniversalPrint(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); UniversalPrint(suffix_, os);
} }
private: private:
const StringType suffix_; const StringType suffix_;
GTEST_DISALLOW_ASSIGN_(EndsWithMatcher); 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
skipping to change at line 1099 skipping to change at line 1115
// 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.
// //
// 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.
#define GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(name, op) \ #define GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(name, op, relation) \
class name##2Matcher { \ class name##2Matcher { \
public: \ public: \
template <typename T1, typename T2> \ template <typename T1, typename T2> \
operator Matcher< ::std::tr1::tuple<T1, T2> >() const { \
return MakeMatcher(new Impl< ::std::tr1::tuple<T1, 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<const ::std::tr1::tuple<T1, T2>&>); \
} \ } \
private: \ private: \
template <typename T1, typename T2> \ template <typename Tuple> \
class Impl : public MatcherInterface<const ::std::tr1::tuple<T1, T2>&> class Impl : public MatcherInterface<Tuple> { \
{ \
public: \ public: \
virtual bool MatchAndExplain( \ virtual bool MatchAndExplain( \
const ::std::tr1::tuple<T1, T2>& args, \ Tuple args, \
MatchResultListener* /* listener */) const { \ 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 " relation; \
} \ } \
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 << "aren't " relation; \
} \ } \
}; \ }; \
} }
// Implements Eq(), Ge(), Gt(), Le(), Lt(), and Ne() respectively. // Implements Eq(), Ge(), Gt(), Le(), Lt(), and Ne() respectively.
GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Eq, ==); GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Eq, ==, "an equal pair");
GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ge, >=); GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Gt, >); Ge, >=, "a pair where the first >= the second");
GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Le, <=); GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Lt, <); Gt, >, "a pair where the first > the second");
GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ne, !=); GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
Le, <=, "a pair where the first <= the second");
GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(
Lt, <, "a pair where the first < the second");
GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Ne, !=, "an unequal pair");
#undef GMOCK_IMPLEMENT_COMPARISON2_MATCHER_ #undef GMOCK_IMPLEMENT_COMPARISON2_MATCHER_
// 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:
skipping to change at line 1371 skipping to change at line 1395
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 MatchAndExplain(T& x, // NOLINT bool MatchAndExplain(T& x, // NOLINT
MatchResultListener* /* listener */) const { MatchResultListener* /* listener */) const {
#if GTEST_OS_WINDOWS // Without the if-statement, MSVC sometimes warns about converting
// MSVC warns about converting a value into bool (warning 4800). // a value to bool (warning 4800).
#pragma warning(push) // Saves the current warning state. //
#pragma warning(disable:4800) // Temporarily disables warning 4800. // We cannot write 'return !!predicate_(x);' as that doesn't work
#endif // GTEST_OS_WINDOWS // when predicate_(x) returns a class convertible to bool but
return predicate_(x); // having no operator!().
#if GTEST_OS_WINDOWS if (predicate_(x))
#pragma warning(pop) // Restores the warning state. return true;
#endif // GTEST_OS_WINDOWS return false;
} }
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";
} }
skipping to change at line 1607 skipping to change at line 1631
template <typename Pointer> template <typename Pointer>
operator Matcher<Pointer>() const { operator Matcher<Pointer>() const {
return MakeMatcher(new Impl<Pointer>(matcher_)); return MakeMatcher(new Impl<Pointer>(matcher_));
} }
private: private:
// 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<GTEST_REMOVE_CONST_( // NOLINT
GMOCK_REMOVE_REFERENCE_(Pointer))>::type Pointee; GTEST_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 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 {
skipping to change at line 1666 skipping to change at line 1690
void DescribeNegationTo(::std::ostream* os) const { void DescribeNegationTo(::std::ostream* os) const {
*os << "is an object whose given field "; *os << "is an object whose given field ";
matcher_.DescribeNegationTo(os); matcher_.DescribeNegationTo(os);
} }
template <typename T> template <typename T>
bool MatchAndExplain(const T& value, MatchResultListener* listener) const { bool MatchAndExplain(const T& value, MatchResultListener* listener) const {
return MatchAndExplainImpl( return MatchAndExplainImpl(
typename ::testing::internal:: typename ::testing::internal::
is_pointer<GMOCK_REMOVE_CONST_(T)>::type(), is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
value, listener); value, listener);
} }
private: private:
// The first argument of MatchAndExplainImpl() is needed to help // 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.
bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& ob j, bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& ob j,
MatchResultListener* listener) const { MatchResultListener* listener) const {
*listener << "whose given field is "; *listener << "whose given field is ";
skipping to change at line 1705 skipping to change at line 1729
GTEST_DISALLOW_ASSIGN_(FieldMatcher); GTEST_DISALLOW_ASSIGN_(FieldMatcher);
}; };
// 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 GTEST_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 GTEST_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) {}
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "is an object whose 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 << "is an object whose given property "; *os << "is an object whose given property ";
matcher_.DescribeNegationTo(os); matcher_.DescribeNegationTo(os);
} }
template <typename T> template <typename T>
bool MatchAndExplain(const T&value, MatchResultListener* listener) const { bool MatchAndExplain(const T&value, MatchResultListener* listener) const {
return MatchAndExplainImpl( return MatchAndExplainImpl(
typename ::testing::internal:: typename ::testing::internal::
is_pointer<GMOCK_REMOVE_CONST_(T)>::type(), is_pointer<GTEST_REMOVE_CONST_(T)>::type(),
value, listener); value, listener);
} }
private: private:
// The first argument of MatchAndExplainImpl() is needed to help // 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.
bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& ob j, bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& ob j,
MatchResultListener* listener) const { MatchResultListener* listener) const {
*listener << "whose given property is "; *listener << "whose given property is ";
skipping to change at line 1877 skipping to change at line 1901
public: public:
typedef internal::StlContainerView<Container> View; typedef internal::StlContainerView<Container> View;
typedef typename View::type StlContainer; typedef typename View::type StlContainer;
typedef typename View::const_reference StlContainerReference; typedef typename View::const_reference StlContainerReference;
// 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, (void)testing::StaticAssertTypeEq<Container,
GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container))>(); GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>();
} }
void DescribeTo(::std::ostream* os) const { void DescribeTo(::std::ostream* os) const {
*os << "equals "; *os << "equals ";
UniversalPrinter<StlContainer>::Print(rhs_, os); UniversalPrint(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); UniversalPrint(rhs_, os);
} }
template <typename LhsContainer> template <typename LhsContainer>
bool MatchAndExplain(const LhsContainer& lhs, bool MatchAndExplain(const LhsContainer& lhs,
MatchResultListener* listener) const { MatchResultListener* listener) const {
// GMOCK_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug // GTEST_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<GTEST_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_) if (lhs_stl_container == rhs_)
return true; return true;
::std::ostream* const os = listener->stream(); ::std::ostream* const os = listener->stream();
if (os != NULL) { if (os != NULL) {
// Something is different. Check for extra values first. // Something is different. Check for extra values first.
bool printed_header = false; bool printed_header = false;
skipping to change at line 1917 skipping to change at line 1941
lhs_stl_container.begin(); lhs_stl_container.begin();
it != lhs_stl_container.end(); ++it) { it != lhs_stl_container.end(); ++it) {
if (internal::ArrayAwareFind(rhs_.begin(), rhs_.end(), *it) == if (internal::ArrayAwareFind(rhs_.begin(), rhs_.end(), *it) ==
rhs_.end()) { rhs_.end()) {
if (printed_header) { if (printed_header) {
*os << ", "; *os << ", ";
} else { } else {
*os << "which has these unexpected elements: "; *os << "which has these unexpected elements: ";
printed_header = true; printed_header = true;
} }
UniversalPrinter<typename LhsStlContainer::value_type>:: UniversalPrint(*it, os);
Print(*it, os);
} }
} }
// Now check for missing 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 ? ",\nand" : "which") *os << (printed_header ? ",\nand" : "which")
<< " doesn't have these expected elements: "; << " doesn't have these expected elements: ";
printed_header2 = true; printed_header2 = true;
} }
UniversalPrinter<typename StlContainer::value_type>::Print(*it, o s); UniversalPrint(*it, os);
} }
} }
} }
return false; return false;
} }
private: private:
const StlContainer rhs_; const StlContainer rhs_;
GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher); GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher);
}; };
// Implements Contains(element_matcher) for the given argument type Contain // Implements Pointwise(tuple_matcher, rhs_container). tuple_matcher
er. // must be able to be safely cast to Matcher<tuple<const T1&, const
// T2&> >, where T1 and T2 are the types of elements in the LHS
// container and the RHS container respectively.
template <typename TupleMatcher, typename RhsContainer>
class PointwiseMatcher {
public:
typedef internal::StlContainerView<RhsContainer> RhsView;
typedef typename RhsView::type RhsStlContainer;
typedef typename RhsStlContainer::value_type RhsValue;
// Like ContainerEq, we make a copy of rhs in case the elements in
// it are modified after this matcher is created.
PointwiseMatcher(const TupleMatcher& tuple_matcher, const RhsContainer& r
hs)
: tuple_matcher_(tuple_matcher), rhs_(RhsView::Copy(rhs)) {
// Makes sure the user doesn't instantiate this class template
// with a const or reference type.
(void)testing::StaticAssertTypeEq<RhsContainer,
GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>();
}
template <typename LhsContainer>
operator Matcher<LhsContainer>() const {
return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_));
}
template <typename LhsContainer>
class Impl : public MatcherInterface<LhsContainer> {
public:
typedef internal::StlContainerView<
GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)> LhsView;
typedef typename LhsView::type LhsStlContainer;
typedef typename LhsView::const_reference LhsStlContainerReference;
typedef typename LhsStlContainer::value_type LhsValue;
// We pass the LHS value and the RHS value to the inner matcher by
// reference, as they may be expensive to copy. We must use tuple
// instead of pair here, as a pair cannot hold references (C++ 98,
// 20.2.2 [lib.pairs]).
typedef std::tr1::tuple<const LhsValue&, const RhsValue&> InnerMatcherA
rg;
Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs)
// mono_tuple_matcher_ holds a monomorphic version of the tuple mat
cher.
: mono_tuple_matcher_(SafeMatcherCast<InnerMatcherArg>(tuple_matche
r)),
rhs_(rhs) {}
virtual void DescribeTo(::std::ostream* os) const {
*os << "contains " << rhs_.size()
<< " values, where each value and its corresponding value in ";
UniversalPrinter<RhsStlContainer>::Print(rhs_, os);
*os << " ";
mono_tuple_matcher_.DescribeTo(os);
}
virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "doesn't contain exactly " << rhs_.size()
<< " values, or contains a value x at some index i"
<< " where x and the i-th value of ";
UniversalPrint(rhs_, os);
*os << " ";
mono_tuple_matcher_.DescribeNegationTo(os);
}
virtual bool MatchAndExplain(LhsContainer lhs,
MatchResultListener* listener) const {
LhsStlContainerReference lhs_stl_container = LhsView::ConstReference(
lhs);
const size_t actual_size = lhs_stl_container.size();
if (actual_size != rhs_.size()) {
*listener << "which contains " << actual_size << " values";
return false;
}
typename LhsStlContainer::const_iterator left = lhs_stl_container.beg
in();
typename RhsStlContainer::const_iterator right = rhs_.begin();
for (size_t i = 0; i != actual_size; ++i, ++left, ++right) {
const InnerMatcherArg value_pair(*left, *right);
if (listener->IsInterested()) {
StringMatchResultListener inner_listener;
if (!mono_tuple_matcher_.MatchAndExplain(
value_pair, &inner_listener)) {
*listener << "where the value pair (";
UniversalPrint(*left, listener->stream());
*listener << ", ";
UniversalPrint(*right, listener->stream());
*listener << ") at index #" << i << " don't match";
PrintIfNotEmpty(inner_listener.str(), listener->stream());
return false;
}
} else {
if (!mono_tuple_matcher_.Matches(value_pair))
return false;
}
}
return true;
}
private:
const Matcher<InnerMatcherArg> mono_tuple_matcher_;
const RhsStlContainer rhs_;
GTEST_DISALLOW_ASSIGN_(Impl);
};
private:
const TupleMatcher tuple_matcher_;
const RhsStlContainer rhs_;
GTEST_DISALLOW_ASSIGN_(PointwiseMatcher);
};
// Holds the logic common to ContainsMatcherImpl and EachMatcherImpl.
template <typename Container> template <typename Container>
class ContainsMatcherImpl : public MatcherInterface<Container> { class QuantifierMatcherImpl : public MatcherInterface<Container> {
public: public:
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) RawContai ner; typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
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 QuantifierMatcherImpl(InnerMatcher inner_matcher)
: inner_matcher_( : inner_matcher_(
testing::SafeMatcherCast<const Element&>(inner_matcher)) {} testing::SafeMatcherCast<const Element&>(inner_matcher)) {}
// Checks whether:
// * All elements in the container match, if all_elements_should_match.
// * Any element in the container matches, if !all_elements_should_match.
bool MatchAndExplainImpl(bool all_elements_should_match,
Container container,
MatchResultListener* listener) const {
StlContainerReference stl_container = View::ConstReference(container);
size_t i = 0;
for (typename StlContainer::const_iterator it = stl_container.begin();
it != stl_container.end(); ++it, ++i) {
StringMatchResultListener inner_listener;
const bool matches = inner_matcher_.MatchAndExplain(*it, &inner_liste
ner);
if (matches != all_elements_should_match) {
*listener << "whose element #" << i
<< (matches ? " matches" : " doesn't match");
PrintIfNotEmpty(inner_listener.str(), listener->stream());
return !all_elements_should_match;
}
}
return all_elements_should_match;
}
protected:
const Matcher<const Element&> inner_matcher_;
GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl);
};
// Implements Contains(element_matcher) for the given argument type Contain
er.
// Symmetric to EachMatcherImpl.
template <typename Container>
class ContainsMatcherImpl : public QuantifierMatcherImpl<Container> {
public:
template <typename InnerMatcher>
explicit ContainsMatcherImpl(InnerMatcher inner_matcher)
: QuantifierMatcherImpl<Container>(inner_matcher) {}
// 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); this->inner_matcher_.DescribeTo(os);
} }
// 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); this->inner_matcher_.DescribeTo(os);
} }
virtual bool MatchAndExplain(Container container, virtual bool MatchAndExplain(Container container,
MatchResultListener* listener) const { MatchResultListener* listener) const {
StlContainerReference stl_container = View::ConstReference(container); return this->MatchAndExplainImpl(false, container, listener);
size_t i = 0;
for (typename StlContainer::const_iterator it = stl_container.begin();
it != stl_container.end(); ++it, ++i) {
StringMatchResultListener inner_listener;
if (inner_matcher_.MatchAndExplain(*it, &inner_listener)) {
*listener << "whose element #" << i << " matches";
PrintIfNotEmpty(inner_listener.str(), listener->stream());
return true;
}
}
return false;
} }
private: private:
const Matcher<const Element&> inner_matcher_;
GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl); GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl);
}; };
// Implements Each(element_matcher) for the given argument type Container.
// Symmetric to ContainsMatcherImpl.
template <typename Container>
class EachMatcherImpl : public QuantifierMatcherImpl<Container> {
public:
template <typename InnerMatcher>
explicit EachMatcherImpl(InnerMatcher inner_matcher)
: QuantifierMatcherImpl<Container>(inner_matcher) {}
// Describes what this matcher does.
virtual void DescribeTo(::std::ostream* os) const {
*os << "only contains elements that ";
this->inner_matcher_.DescribeTo(os);
}
virtual void DescribeNegationTo(::std::ostream* os) const {
*os << "contains some element that ";
this->inner_matcher_.DescribeNegationTo(os);
}
virtual bool MatchAndExplain(Container container,
MatchResultListener* listener) const {
return this->MatchAndExplainImpl(true, container, listener);
}
private:
GTEST_DISALLOW_ASSIGN_(EachMatcherImpl);
};
// 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); GTEST_DISALLOW_ASSIGN_(ContainsMatcher);
}; };
// Implements polymorphic Each(element_matcher).
template <typename M>
class EachMatcher {
public:
explicit EachMatcher(M m) : inner_matcher_(m) {}
template <typename Container>
operator Matcher<Container>() const {
return MakeMatcher(new EachMatcherImpl<Container>(inner_matcher_));
}
private:
const M inner_matcher_;
GTEST_DISALLOW_ASSIGN_(EachMatcher);
};
// 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 GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
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 MatchAndExplain(PairType key_value, virtual bool MatchAndExplain(PairType key_value,
skipping to change at line 2085 skipping to change at line 2288
const M matcher_for_key_; const M matcher_for_key_;
GTEST_DISALLOW_ASSIGN_(KeyMatcher); 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 GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType;
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)) {
} }
skipping to change at line 2192 skipping to change at line 2395
const FirstMatcher first_matcher_; const FirstMatcher first_matcher_;
const SecondMatcher second_matcher_; const SecondMatcher second_matcher_;
GTEST_DISALLOW_ASSIGN_(PairMatcher); 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 GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
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 a_count) { ElementsAreMatcherImpl(InputIter first, size_t a_count) {
matchers_.reserve(a_count); matchers_.reserve(a_count);
skipping to change at line 2311 skipping to change at line 2514
GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl); 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 GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
RawContainer;
typedef typename internal::StlContainerView<RawContainer>::type::value_ type typedef typename internal::StlContainerView<RawContainer>::type::value_ type
Element; Element;
const Matcher<const Element&>* const matchers = NULL; const Matcher<const Element&>* const matchers = NULL;
return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 0)); return MakeMatcher(new ElementsAreMatcherImpl<Container>(matchers, 0));
} }
}; };
// Implements ElementsAreArray(). // Implements ElementsAreArray().
template <typename T> template <typename T>
class ElementsAreArrayMatcher { class ElementsAreArrayMatcher {
public: public:
ElementsAreArrayMatcher(const T* first, size_t count) : ElementsAreArrayMatcher(const T* first, size_t count) :
first_(first), count_(count) {} first_(first), count_(count) {}
template <typename Container> template <typename Container>
operator Matcher<Container>() const { operator Matcher<Container>() const {
typedef GMOCK_REMOVE_CONST_(GMOCK_REMOVE_REFERENCE_(Container)) typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) 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); GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher);
}; };
// Constants denoting interpolations in a matcher description string. // Returns the description for a matcher defined using the MATCHER*()
const int kTupleInterpolation = -1; // "%(*)s" // macro where the user-supplied description string is "", if
const int kPercentInterpolation = -2; // "%%" // 'negation' is false; otherwise returns the description of the
const int kInvalidInterpolation = -3; // "%" followed by invalid text // negation of the matcher. 'param_values' contains a list of strings
// that are the print-out of the matcher's parameters.
// Records the location and content of an interpolation. string FormatMatcherDescription(bool negation, const char* matcher_name,
struct Interpolation { const Strings& param_values);
Interpolation(const char* start, const char* end, int param)
: start_pos(start), end_pos(end), param_index(param) {}
// Points to the start of the interpolation (the '%' character).
const char* start_pos;
// Points to the first character after the interpolation.
const char* end_pos;
// 0-based index of the interpolated matcher parameter;
// kTupleInterpolation for "%(*)s"; kPercentInterpolation for "%%".
int param_index;
};
typedef ::std::vector<Interpolation> Interpolations;
// Parses a matcher description string and returns a vector of
// interpolations that appear in the string; generates non-fatal
// failures iff 'description' is an invalid matcher description.
// 'param_names' is a NULL-terminated array of parameter names in the
// order they appear in the MATCHER_P*() parameter list.
Interpolations ValidateMatcherDescription(
const char* param_names[], const char* description);
// Returns the actual matcher description, given the matcher name,
// user-supplied description template string, interpolations in the
// string, and the printed values of the matcher parameters.
string FormatMatcherDescription(
const char* matcher_name, const char* description,
const Interpolations& interp, const Strings& param_values);
} // namespace internal } // namespace internal
// Implements MatcherCast(). // Implements MatcherCast().
template <typename T, typename M> template <typename T, typename M>
inline Matcher<T> MatcherCast(M matcher) { inline Matcher<T> MatcherCast(M matcher) {
return internal::MatcherCastImpl<T, M>::Cast(matcher); return internal::MatcherCastImpl<T, M>::Cast(matcher);
} }
// _ is a matcher that matches anything of any type. // _ is a matcher that matches anything of any type.
skipping to change at line 2542 skipping to change at line 2715
// matches 'matcher'. For example, // matches 'matcher'. For example,
// Property(&Foo::str, StartsWith("hi")) // Property(&Foo::str, StartsWith("hi"))
// matches a Foo object x iff x.str() starts with "hi". // matches a Foo object x iff x.str() starts with "hi".
template <typename Class, typename PropertyType, typename PropertyMatcher> template <typename Class, typename PropertyType, typename PropertyMatcher>
inline PolymorphicMatcher< inline PolymorphicMatcher<
internal::PropertyMatcher<Class, PropertyType> > Property( internal::PropertyMatcher<Class, PropertyType> > Property(
PropertyType (Class::*property)() const, const PropertyMatcher& matcher ) { PropertyType (Class::*property)() const, const PropertyMatcher& matcher ) {
return MakePolymorphicMatcher( return MakePolymorphicMatcher(
internal::PropertyMatcher<Class, PropertyType>( internal::PropertyMatcher<Class, PropertyType>(
property, property,
MatcherCast<GMOCK_REFERENCE_TO_CONST_(PropertyType)>(matcher))); MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
// The call to MatcherCast() is required for supporting inner // The call to MatcherCast() is required for supporting inner
// matchers of compatible types. For example, it allows // matchers of compatible types. For example, it allows
// Property(&Foo::bar, m) // Property(&Foo::bar, m)
// to compile where bar() returns an int32 and m is a matcher for int64. // to compile where bar() returns an int32 and m is a matcher for int64.
} }
// Creates a matcher that matches an object iff the result of applying // Creates a matcher that matches an object iff the result of applying
// a callable to x matches 'matcher'. // a callable to x matches 'matcher'.
// For example, // For example,
// ResultOf(f, StartsWith("hi")) // ResultOf(f, StartsWith("hi"))
skipping to change at line 2735 skipping to change at line 2908
// first field != the second field. // first field != the second field.
inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); } inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); }
// Creates a matcher that matches any value of type T that m doesn't // Creates a matcher that matches any value of type T that m doesn't
// match. // match.
template <typename InnerMatcher> template <typename InnerMatcher>
inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) { inline internal::NotMatcher<InnerMatcher> Not(InnerMatcher m) {
return internal::NotMatcher<InnerMatcher>(m); return internal::NotMatcher<InnerMatcher>(m);
} }
// Creates a matcher that matches any value that matches all of the
// given matchers.
//
// For now we only support up to 5 matchers. Support for more
// matchers can be added as needed, or the user can use nested
// AllOf()s.
template <typename Matcher1, typename Matcher2>
inline internal::BothOfMatcher<Matcher1, Matcher2>
AllOf(Matcher1 m1, Matcher2 m2) {
return internal::BothOfMatcher<Matcher1, Matcher2>(m1, m2);
}
template <typename Matcher1, typename Matcher2, typename Matcher3>
inline internal::BothOfMatcher<Matcher1,
internal::BothOfMatcher<Matcher2, Matcher3> >
AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) {
return AllOf(m1, AllOf(m2, m3));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4>
inline internal::BothOfMatcher<Matcher1,
internal::BothOfMatcher<Matcher2,
internal::BothOfMatcher<Matcher3, Matcher4> > >
AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) {
return AllOf(m1, AllOf(m2, m3, m4));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5>
inline internal::BothOfMatcher<Matcher1,
internal::BothOfMatcher<Matcher2,
internal::BothOfMatcher<Matcher3,
internal::BothOfMatcher<Matcher4, Matcher5> > > >
AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) {
return AllOf(m1, AllOf(m2, m3, m4, m5));
}
// Creates a matcher that matches any value that matches at least one
// of the given matchers.
//
// For now we only support up to 5 matchers. Support for more
// matchers can be added as needed, or the user can use nested
// AnyOf()s.
template <typename Matcher1, typename Matcher2>
inline internal::EitherOfMatcher<Matcher1, Matcher2>
AnyOf(Matcher1 m1, Matcher2 m2) {
return internal::EitherOfMatcher<Matcher1, Matcher2>(m1, m2);
}
template <typename Matcher1, typename Matcher2, typename Matcher3>
inline internal::EitherOfMatcher<Matcher1,
internal::EitherOfMatcher<Matcher2, Matcher3> >
AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) {
return AnyOf(m1, AnyOf(m2, m3));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4>
inline internal::EitherOfMatcher<Matcher1,
internal::EitherOfMatcher<Matcher2,
internal::EitherOfMatcher<Matcher3, Matcher4> > >
AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) {
return AnyOf(m1, AnyOf(m2, m3, m4));
}
template <typename Matcher1, typename Matcher2, typename Matcher3,
typename Matcher4, typename Matcher5>
inline internal::EitherOfMatcher<Matcher1,
internal::EitherOfMatcher<Matcher2,
internal::EitherOfMatcher<Matcher3,
internal::EitherOfMatcher<Matcher4, Matcher5> > > >
AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) {
return AnyOf(m1, AnyOf(m2, m3, m4, m5));
}
// Returns a matcher that matches anything that satisfies the given // Returns a matcher that matches anything that satisfies the given
// predicate. The predicate can be any unary function or functor // predicate. The predicate can be any unary function or functor
// whose return type can be implicitly converted to bool. // whose return type can be implicitly converted to bool.
template <typename Predicate> template <typename Predicate>
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< // NOLINT inline PolymorphicMatcher<internal::ContainerEqMatcher< // NOLINT
GMOCK_REMOVE_CONST_(Container)> > GTEST_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 GTEST_REMOVE_CONST_(Container) RawContainer;
return MakePolymorphicMatcher( return MakePolymorphicMatcher(
internal::ContainerEqMatcher<RawContainer>(rhs)); internal::ContainerEqMatcher<RawContainer>(rhs));
} }
// Matches an STL-style container or a native array that contains the
// same number of elements as in rhs, where its i-th element and rhs's
// i-th element (as a pair) satisfy the given pair matcher, for all i.
// TupleMatcher must be able to be safely cast to Matcher<tuple<const
// T1&, const T2&> >, where T1 and T2 are the types of elements in the
// LHS container and the RHS container respectively.
template <typename TupleMatcher, typename Container>
inline internal::PointwiseMatcher<TupleMatcher,
GTEST_REMOVE_CONST_(Container)>
Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) {
// This following line is for working around a bug in MSVC 8.0,
// which causes Container to be a const type sometimes.
typedef GTEST_REMOVE_CONST_(Container) RawContainer;
return internal::PointwiseMatcher<TupleMatcher, RawContainer>(
tuple_matcher, 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));
// EXPECT_THAT(page_ids, Contains(Gt(2))); // EXPECT_THAT(page_ids, Contains(Gt(2)));
// EXPECT_THAT(page_ids, Not(Contains(4))); // EXPECT_THAT(page_ids, Not(Contains(4)));
skipping to change at line 2858 skipping to change at line 2972
// EXPECT_THAT(page_lengths, // EXPECT_THAT(page_lengths,
// Contains(::std::pair<const int, size_t>(1, 100))); // Contains(::std::pair<const int, size_t>(1, 100)));
// //
// const char* user_ids[] = { "joe", "mike", "tom" }; // const char* user_ids[] = { "joe", "mike", "tom" };
// EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom")))); // EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom"))));
template <typename M> template <typename M>
inline internal::ContainsMatcher<M> Contains(M matcher) { inline internal::ContainsMatcher<M> Contains(M matcher) {
return internal::ContainsMatcher<M>(matcher); return internal::ContainsMatcher<M>(matcher);
} }
// Matches an STL-style container or a native array that contains only
// elements matching the given value or matcher.
//
// Each(m) is semantically equivalent to Not(Contains(Not(m))). Only
// the messages are different.
//
// Examples:
// ::std::set<int> page_ids;
// // Each(m) matches an empty container, regardless of what m is.
// EXPECT_THAT(page_ids, Each(Eq(1)));
// EXPECT_THAT(page_ids, Each(Eq(77)));
//
// page_ids.insert(3);
// EXPECT_THAT(page_ids, Each(Gt(0)));
// EXPECT_THAT(page_ids, Not(Each(Gt(4))));
// page_ids.insert(1);
// EXPECT_THAT(page_ids, Not(Each(Lt(2))));
//
// ::std::map<int, size_t> page_lengths;
// page_lengths[1] = 100;
// page_lengths[2] = 200;
// page_lengths[3] = 300;
// EXPECT_THAT(page_lengths, Not(Each(Pair(1, 100))));
// EXPECT_THAT(page_lengths, Each(Key(Le(3))));
//
// const char* user_ids[] = { "joe", "mike", "tom" };
// EXPECT_THAT(user_ids, Not(Each(Eq(::std::string("tom")))));
template <typename M>
inline internal::EachMatcher<M> Each(M matcher) {
return internal::EachMatcher<M>(matcher);
}
// 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 M> template <typename M>
inline internal::KeyMatcher<M> Key(M inner_matcher) { inline internal::KeyMatcher<M> Key(M inner_matcher) {
return internal::KeyMatcher<M>(inner_matcher); return internal::KeyMatcher<M>(inner_matcher);
} }
// Pair(first_matcher, second_matcher) matches a std::pair whose 'first' fi eld // Pair(first_matcher, second_matcher) matches a std::pair whose 'first' fi eld
// matches first_matcher and whose 'second' field matches second_matcher. For // matches first_matcher and whose 'second' field matches second_matcher. For
 End of changes. 64 change blocks. 
203 lines changed or deleted 356 lines changed or added


 gmock-more-actions.h   gmock-more-actions.h 
skipping to change at line 39 skipping to change at line 39
// //
// Author: wan@google.com (Zhanyong Wan) // Author: wan@google.com (Zhanyong Wan)
// Google Mock - a framework for writing C++ mock classes. // Google Mock - a framework for writing C++ mock classes.
// //
// This file implements some actions that depend on gmock-generated-actions .h. // This file implements some actions that depend on gmock-generated-actions .h.
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
#include <gmock/gmock-generated-actions.h> #include <algorithm>
#include "gmock/gmock-generated-actions.h"
namespace testing { namespace testing {
namespace internal { namespace internal {
// Implements the Invoke(f) action. The template argument // Implements the Invoke(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. Invoke(f) can be used as an // function pointer or a functor. Invoke(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>
skipping to change at line 137 skipping to change at line 139
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 // The ACTION*() macros trigger warning C4100 (unreferenced formal
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
// the macro definition, as the warnings are generated when the macro // the macro definition, as the warnings are generated when the macro
// is expanded and macro expansion cannot contain #pragma. Therefore // is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here. // we suppress them here.
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(push) # pragma warning(push)
#pragma warning(disable:4100) # pragma warning(disable:4100)
#endif #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,
HAS_1_TEMPLATE_PARAMS(int, k), HAS_1_TEMPLATE_PARAMS(int, k),
AND_1_VALUE_PARAMS(pointer)) { AND_1_VALUE_PARAMS(pointer)) {
*pointer = ::std::tr1::get<k>(args); *pointer = ::std::tr1::get<k>(args);
} }
// Action SaveArgPointee<k>(pointer) saves the value pointed to
// by the k-th (0-based) argument of the mock function to *pointer.
ACTION_TEMPLATE(SaveArgPointee,
HAS_1_TEMPLATE_PARAMS(int, k),
AND_1_VALUE_PARAMS(pointer)) {
*pointer = *::std::tr1::get<k>(args);
}
// Action SetArgReferee<k>(value) assigns 'value' to the variable // Action SetArgReferee<k>(value) assigns 'value' to the variable
// referenced by the k-th (0-based) argument of the mock function. // referenced by the k-th (0-based) argument of the mock function.
ACTION_TEMPLATE(SetArgReferee, ACTION_TEMPLATE(SetArgReferee,
HAS_1_TEMPLATE_PARAMS(int, k), HAS_1_TEMPLATE_PARAMS(int, k),
AND_1_VALUE_PARAMS(value)) { AND_1_VALUE_PARAMS(value)) {
typedef typename ::std::tr1::tuple_element<k, args_type>::type argk_type; typedef typename ::std::tr1::tuple_element<k, args_type>::type argk_type;
// Ensures that argument #k is a reference. If you get a compiler // Ensures that argument #k is a reference. If you get a compiler
// error on the next line, you are using SetArgReferee<k>(value) in // error on the next line, you are using SetArgReferee<k>(value) in
// a mock function whose k-th (0-based) argument is not a reference. // a mock function whose k-th (0-based) argument is not a reference.
GMOCK_COMPILE_ASSERT_(internal::is_reference<argk_type>::value, GTEST_COMPILE_ASSERT_(internal::is_reference<argk_type>::value,
SetArgReferee_must_be_used_with_a_reference_argumen t); SetArgReferee_must_be_used_with_a_reference_argumen t);
::std::tr1::get<k>(args) = value; ::std::tr1::get<k>(args) = value;
} }
// Action SetArrayArgument<k>(first, last) copies the elements in // Action SetArrayArgument<k>(first, last) copies the elements in
// source range [first, last) to the array pointed to by the k-th // source range [first, last) to the array pointed to by the k-th
// (0-based) argument, which can be either a pointer or an // (0-based) argument, which can be either a pointer or an
// iterator. The action does not take ownership of the elements in the // iterator. The action does not take ownership of the elements in the
// source range. // source range.
ACTION_TEMPLATE(SetArrayArgument, ACTION_TEMPLATE(SetArrayArgument,
HAS_1_TEMPLATE_PARAMS(int, k), HAS_1_TEMPLATE_PARAMS(int, k),
AND_2_VALUE_PARAMS(first, last)) { AND_2_VALUE_PARAMS(first, last)) {
// Microsoft compiler deprecates ::std::copy, so we want to suppress warn ing // Microsoft compiler deprecates ::std::copy, so we want to suppress warn ing
// 4996 (Function call with parameters that may be unsafe) there. // 4996 (Function call with parameters that may be unsafe) there.
#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:4996) // Temporarily disables warning 4996. # pragma warning(disable:4996) // Temporarily disables warning 4996.
#endif #endif
::std::copy(first, last, ::std::tr1::get<k>(args)); ::std::copy(first, last, ::std::tr1::get<k>(args));
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) // Restores the warning state. # pragma warning(pop) // Restores the warning state.
#endif #endif
} }
// Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock // Action DeleteArg<k>() deletes the k-th (0-based) argument of the mock
// function. // function.
ACTION_TEMPLATE(DeleteArg, ACTION_TEMPLATE(DeleteArg,
HAS_1_TEMPLATE_PARAMS(int, k), HAS_1_TEMPLATE_PARAMS(int, k),
AND_0_VALUE_PARAMS()) { AND_0_VALUE_PARAMS()) {
delete ::std::tr1::get<k>(args); delete ::std::tr1::get<k>(args);
} }
// This action returns the value pointed to by 'pointer'.
ACTION_P(ReturnPointee, pointer) { return *pointer; }
// 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
// Suppresses the 'unreachable code' warning that VC generates in opt modes
.
# ifdef _MSC_VER
# pragma warning(push) // Saves the current warning state.
# pragma warning(disable:4702) // Temporarily disables warning 4702.
# endif
ACTION_P(Throw, exception) { throw exception; } ACTION_P(Throw, exception) { throw exception; }
# ifdef _MSC_VER
# pragma warning(pop) // Restores the warning state.
# endif
#endif // GTEST_HAS_EXCEPTIONS #endif // GTEST_HAS_EXCEPTIONS
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) # pragma warning(pop)
#endif #endif
} // namespace testing } // namespace testing
#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
 End of changes. 10 change blocks. 
8 lines changed or deleted 32 lines changed or added


 gmock-port.h   gmock-port.h 
skipping to change at line 45 skipping to change at line 45
#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <iostream> #include <iostream>
// Most of the types needed for porting Google Mock are also required // Most of the types needed for porting Google Mock are also required
// for Google Test and are defined in gtest-port.h. // for Google Test and are defined in gtest-port.h.
#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
#endif // GTEST_OS_LINUX
namespace testing {
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 "
// Use implicit_cast as a safe version of static_cast for upcasting in
// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
// const Foo*). When you use implicit_cast, the compiler checks that
// the cast is safe. Such explicit implicit_casts are necessary in
// surprisingly many situations where C++ demands an exact type match
// instead of an argument type convertable to a target type.
//
// The syntax for using implicit_cast is the same as for static_cast:
//
// implicit_cast<ToType>(expr)
//
// implicit_cast would have been part of the C++ standard library,
// but the proposal was submitted too late. It will probably make
// its way into the language in the future.
template<typename To>
inline To implicit_cast(To x) { return x; }
// When you upcast (that is, cast a pointer from type Foo to type
// SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts
// always succeed. When you downcast (that is, cast a pointer from
// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
// how do you know the pointer is really of type SubclassOfFoo? It
// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus,
// when you downcast, you should use this macro. In debug mode, we
// 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<>
// instead. Thus, it's important to test in debug mode to make sure
// the cast is legal!
// This is the only place in the code we should use dynamic_cast<>.
// In particular, you SHOULDN'T be using dynamic_cast<> in order to
// do RTTI (eg code like this:
// if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
// if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
// You should design the code some other way not to need this.
template<typename To, typename From> // use like this: down_cast<T*>(foo);
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
// for compile-time type checking, and has no overhead in an
// optimized build at run-time, as it will be optimized away
// completely.
if (false) {
const To to = NULL;
::testing::internal::implicit_cast<From*>(to);
}
#if GTEST_HAS_RTTI
assert(f == NULL || dynamic_cast<To>(f) != NULL); // RTTI: debug mode on
ly!
#endif #endif
return static_cast<To>(f);
}
// 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
// size of a static array:
//
// GMOCK_COMPILE_ASSERT_(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYP
ES,
// content_type_names_incorrect_size);
//
// or to make sure a struct is smaller than a certain size:
//
// GMOCK_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
//
// The second argument to the macro is the name of the variable. If
// the expression is false, most compilers will issue a warning/error
// containing the name of the variable.
template <bool>
struct CompileAssert {
};
#define GMOCK_COMPILE_ASSERT_(expr, msg) \
typedef ::testing::internal::CompileAssert<(bool(expr))> \
msg[bool(expr) ? 1 : -1]
// Implementation details of GMOCK_COMPILE_ASSERT_:
//
// - GMOCK_COMPILE_ASSERT_ works by defining an array type that has -1
// elements (and thus is invalid) when the expression is false.
//
// - The simpler definition
//
// #define GMOCK_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1
: -1]
//
// does not work, as gcc supports variable-length arrays whose sizes
// are determined at run-time (this is gcc's extension and not part
// of the C++ standard). As a result, gcc fails to reject the
// following code with the simple definition:
//
// int foo;
// GMOCK_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo i
s
// // not a compile-time constant.
//
// - By using the type CompileAssert<(bool(expr))>, we ensures that
// expr is a compile-time constant. (Template arguments must be
// determined at compile-time.)
//
// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
//
// CompileAssert<bool(expr)>
//
// instead, these compilers will refuse to compile
//
// GMOCK_COMPILE_ASSERT_(5 > 0, some_message);
//
// (They seem to think the ">" in "5 > 0" marks the end of the
// template argument list.)
//
// - The array size is (bool(expr) ? 1 : -1), instead of simply
//
// ((expr) ? 1 : -1).
//
// This is to avoid running into a bug in MS VC 7.1, which
// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
#if GTEST_HAS_GLOBAL_STRING
typedef ::string string;
#else
typedef ::std::string string;
#endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_GLOBAL_WSTRING
typedef ::wstring wstring;
#elif GTEST_HAS_STD_WSTRING
typedef ::std::wstring wstring;
#endif // GTEST_HAS_GLOBAL_WSTRING
} // namespace internal
} // namespace testing
// Macro for referencing flags. This is public as we want the user to // Macro for referencing flags. This is public as we want the user to
// use this syntax to reference Google Mock flags. // use this syntax to reference Google Mock flags.
#define GMOCK_FLAG(name) FLAGS_gmock_##name #define GMOCK_FLAG(name) FLAGS_gmock_##name
// Macros for declaring flags. // Macros for declaring flags.
#define GMOCK_DECLARE_bool_(name) extern bool GMOCK_FLAG(name) #define GMOCK_DECLARE_bool_(name) extern bool GMOCK_FLAG(name)
#define GMOCK_DECLARE_int32_(name) \ #define GMOCK_DECLARE_int32_(name) \
extern ::testing::internal::Int32 GMOCK_FLAG(name) extern ::testing::internal::Int32 GMOCK_FLAG(name)
#define GMOCK_DECLARE_string_(name) \ #define GMOCK_DECLARE_string_(name) \
 End of changes. 4 change blocks. 
145 lines changed or deleted 4 lines changed or added


 gmock-spec-builders.h   gmock-spec-builders.h 
skipping to change at line 69 skipping to change at line 69
#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
#define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ #define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
#include <map> #include <map>
#include <set> #include <set>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
#include <gmock/gmock-actions.h> #include "gmock/gmock-actions.h"
#include <gmock/gmock-cardinalities.h> #include "gmock/gmock-cardinalities.h"
#include <gmock/gmock-matchers.h> #include "gmock/gmock-matchers.h"
#include <gmock/gmock-printers.h> #include "gmock/internal/gmock-internal-utils.h"
#include <gmock/internal/gmock-internal-utils.h> #include "gmock/internal/gmock-port.h"
#include <gmock/internal/gmock-port.h> #include "gtest/gtest.h"
#include <gtest/gtest.h>
namespace testing { namespace testing {
// An abstract handle of an expectation. // An abstract handle of an expectation.
class Expectation; class Expectation;
// A set of expectation handles. // A set of expectation handles.
class ExpectationSet; class ExpectationSet;
// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION // Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION
skipping to change at line 117 skipping to change at line 116
// 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.
GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex); GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex);
// Untyped base class for ActionResultHolder<R>.
class UntypedActionResultHolderBase;
// 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() {} 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
// and returns false if not. // and returns false if not.
// L >= g_gmock_mutex // L >= g_gmock_mutex
virtual bool VerifyAndClearExpectationsLocked() = 0; bool VerifyAndClearExpectationsLocked();
// Clears the ON_CALL()s set on this mock function. // Clears the ON_CALL()s set on this mock function.
// L >= g_gmock_mutex // L >= g_gmock_mutex
virtual void ClearDefaultActionsLocked() = 0; virtual void ClearDefaultActionsLocked() = 0;
// In all of the following Untyped* functions, it's the caller's
// responsibility to guarantee the correctness of the arguments'
// types.
// Performs the default action with the given arguments and returns
// the action's result. The call description string will be used in
// the error message to describe the call in the case the default
// action fails.
// L = *
virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
const void* untyped_args,
const string& call_description) const = 0;
// Performs the given action with the given arguments and returns
// the action's result.
// L = *
virtual UntypedActionResultHolderBase* UntypedPerformAction(
const void* untyped_action,
const void* untyped_args) const = 0;
// Writes a message that the call is uninteresting (i.e. neither
// explicitly expected nor explicitly unexpected) to the given
// ostream.
// L < g_gmock_mutex
virtual void UntypedDescribeUninterestingCall(const void* untyped_args,
::std::ostream* os) const =
0;
// Returns the expectation that matches the given function arguments
// (or NULL is there's no match); when a match is found,
// untyped_action is set to point to the action that should be
// performed (or NULL if the action is "do default"), and
// is_excessive is modified to indicate whether the call exceeds the
// expected number.
// L < g_gmock_mutex
virtual const ExpectationBase* UntypedFindMatchingExpectation(
const void* untyped_args,
const void** untyped_action, bool* is_excessive,
::std::ostream* what, ::std::ostream* why) = 0;
// Prints the given function arguments to the ostream.
virtual void UntypedPrintArgs(const void* untyped_args,
::std::ostream* os) const = 0;
// Sets the mock object this mock method belongs to, and registers
// this information in the global mock registry. Will be called
// whenever an EXPECT_CALL() or ON_CALL() is executed on this mock
// method.
// TODO(wan@google.com): rename to SetAndRegisterOwner().
// L < g_gmock_mutex
void RegisterOwner(const void* mock_obj);
// Sets the mock object this mock method belongs to, and sets the
// name of the mock function. Will be called upon each invocation
// of this mock function.
// L < g_gmock_mutex
void SetOwnerAndName(const void* mock_obj, const char* name);
// Returns the mock object this mock method belongs to. Must be
// called after RegisterOwner() or SetOwnerAndName() has been
// called.
// L < g_gmock_mutex
const void* MockObject() const;
// Returns the name of this mock method. Must be called after
// SetOwnerAndName() has been called.
// L < g_gmock_mutex
const char* Name() const;
// Returns the result of invoking this mock function with the given
// arguments. This function can be safely called from multiple
// threads concurrently. The caller is responsible for deleting the
// result.
// L < g_gmock_mutex
const UntypedActionResultHolderBase* UntypedInvokeWith(
const void* untyped_args);
protected:
typedef std::vector<const void*> UntypedOnCallSpecs;
typedef std::vector<internal::linked_ptr<ExpectationBase> >
UntypedExpectations;
// Returns an Expectation object that references and co-owns exp,
// which must be an expectation on this mock function.
Expectation GetHandleOf(ExpectationBase* exp);
// Address of the mock object this mock method belongs to. Only
// valid after this mock method has been called or
// ON_CALL/EXPECT_CALL has been invoked on it.
const void* mock_obj_; // Protected by g_gmock_mutex.
// Name of the function being mocked. Only valid after this mock
// method has been called.
const char* name_; // Protected by g_gmock_mutex.
// All default action specs for this function mocker.
UntypedOnCallSpecs untyped_on_call_specs_;
// All expectations for this function mocker.
UntypedExpectations untyped_expectations_;
}; // class UntypedFunctionMockerBase }; // class UntypedFunctionMockerBase
// This template class implements a default action spec (i.e. an // Untyped base class for OnCallSpec<F>.
// ON_CALL() statement). class UntypedOnCallSpecBase {
public:
// The arguments are the location of the ON_CALL() statement.
UntypedOnCallSpecBase(const char* a_file, int a_line)
: file_(a_file), line_(a_line), last_clause_(kNone) {}
// Where in the source file was the default action spec defined?
const char* file() const { return file_; }
int line() const { return line_; }
protected:
// Gives each clause in the ON_CALL() statement a name.
enum Clause {
// Do not change the order of the enum members! The run-time
// syntax checking relies on it.
kNone,
kWith,
kWillByDefault
};
// Asserts that the ON_CALL() statement has a certain property.
void AssertSpecProperty(bool property, const string& failure_message) con
st {
Assert(property, file_, line_, failure_message);
}
// Expects that the ON_CALL() statement has a certain property.
void ExpectSpecProperty(bool property, const string& failure_message) con
st {
Expect(property, file_, line_, failure_message);
}
const char* file_;
int line_;
// The last clause in the ON_CALL() statement as seen so far.
// Initially kNone and changes as the statement is parsed.
Clause last_clause_;
}; // class UntypedOnCallSpecBase
// This template class implements an ON_CALL spec.
template <typename F> template <typename F>
class DefaultActionSpec { class OnCallSpec : public UntypedOnCallSpecBase {
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 an OnCallSpec object from the information inside
// the parenthesis of an ON_CALL() statement. // the parenthesis of an ON_CALL() statement.
DefaultActionSpec(const char* a_file, int a_line, OnCallSpec(const char* a_file, int a_line,
const ArgumentMatcherTuple& matchers) const ArgumentMatcherTuple& matchers)
: file_(a_file), : UntypedOnCallSpecBase(a_file, a_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) {
} }
// Where in the source file was the default action spec defined?
const char* file() const { return file_; }
int line() const { return line_; }
// Implements the .With() clause. // Implements the .With() clause.
DefaultActionSpec& With(const Matcher<const ArgumentTuple&>& m) { OnCallSpec& With(const Matcher<const ArgumentTuple&>& m) {
// Makes sure this is called at most once. // Makes sure this is called at most once.
ExpectSpecProperty(last_clause_ < kWith, ExpectSpecProperty(last_clause_ < kWith,
".With() cannot appear " ".With() cannot appear "
"more than once in an ON_CALL()."); "more than once in an ON_CALL().");
last_clause_ = kWith; last_clause_ = kWith;
extra_matcher_ = m; extra_matcher_ = m;
return *this; return *this;
} }
// Implements the .WillByDefault() clause. // Implements the .WillByDefault() clause.
DefaultActionSpec& WillByDefault(const Action<F>& action) { OnCallSpec& WillByDefault(const Action<F>& action) {
ExpectSpecProperty(last_clause_ < kWillByDefault, ExpectSpecProperty(last_clause_ < kWillByDefault,
".WillByDefault() must appear " ".WillByDefault() must appear "
"exactly once in an ON_CALL()."); "exactly once in an ON_CALL().");
last_clause_ = kWillByDefault; last_clause_ = kWillByDefault;
ExpectSpecProperty(!action.IsDoDefault(), ExpectSpecProperty(!action.IsDoDefault(),
"DoDefault() cannot be used in ON_CALL()."); "DoDefault() cannot be used in ON_CALL().");
action_ = action; action_ = action;
return *this; return *this;
} }
skipping to change at line 201 skipping to change at line 337
// Returns the action specified by the user. // Returns the action specified by the user.
const Action<F>& GetAction() const { const Action<F>& GetAction() const {
AssertSpecProperty(last_clause_ == kWillByDefault, AssertSpecProperty(last_clause_ == kWillByDefault,
".WillByDefault() must appear exactly " ".WillByDefault() must appear exactly "
"once in an ON_CALL()."); "once in an ON_CALL().");
return action_; return action_;
} }
private: private:
// Gives each clause in the ON_CALL() statement a name.
enum Clause {
// Do not change the order of the enum members! The run-time
// syntax checking relies on it.
kNone,
kWith,
kWillByDefault,
};
// Asserts that the ON_CALL() statement has a certain property.
void AssertSpecProperty(bool property, const string& failure_message) con
st {
Assert(property, file_, line_, failure_message);
}
// Expects that the ON_CALL() statement has a certain property.
void ExpectSpecProperty(bool property, const string& failure_message) con
st {
Expect(property, file_, line_, failure_message);
}
// The information in statement // The information in statement
// //
// ON_CALL(mock_object, Method(matchers)) // ON_CALL(mock_object, Method(matchers))
// .With(multi-argument-matcher) // .With(multi-argument-matcher)
// .WillByDefault(action); // .WillByDefault(action);
// //
// is recorded in the data members like this: // is recorded in the data members like this:
// //
// source file that contains the statement => file_ // source file that contains the statement => file_
// line number of the statement => line_ // line number of the statement => line_
// matchers => matchers_ // matchers => matchers_
// multi-argument-matcher => extra_matcher_ // multi-argument-matcher => extra_matcher_
// action => action_ // action => action_
const char* file_;
int line_;
ArgumentMatcherTuple matchers_; ArgumentMatcherTuple matchers_;
Matcher<const ArgumentTuple&> extra_matcher_; Matcher<const ArgumentTuple&> extra_matcher_;
Action<F> action_; Action<F> action_;
}; // class OnCallSpec
// The last clause in the ON_CALL() statement as seen so far.
// Initially kNone and changes as the statement is parsed.
Clause last_clause_;
}; // class DefaultActionSpec
// Possible reactions on uninteresting calls. TODO(wan@google.com): // Possible reactions on uninteresting calls. TODO(wan@google.com):
// rename the enum values to the kFoo style. // rename the enum values to the kFoo style.
enum CallReaction { enum CallReaction {
ALLOW, ALLOW,
WARN, WARN,
FAIL, FAIL
}; };
} // namespace internal } // namespace internal
// Utilities for manipulating mock objects. // Utilities for manipulating mock objects.
class Mock { class Mock {
public: public:
// The following public methods can be called concurrently. // The following public methods can be called concurrently.
// Tells Google Mock to ignore mock_obj when checking for leaked // Tells Google Mock to ignore mock_obj when checking for leaked
skipping to change at line 273 skipping to change at line 384
// Verifies and clears all expectations on the given mock object. // Verifies and clears all expectations on the given mock object.
// If the expectations aren't satisfied, generates one or more // If the expectations aren't satisfied, generates one or more
// Google Test non-fatal failures and returns false. // Google Test non-fatal failures and returns false.
static bool VerifyAndClearExpectations(void* mock_obj); static bool VerifyAndClearExpectations(void* mock_obj);
// Verifies all expectations on the given mock object and clears its // Verifies all expectations on the given mock object and clears its
// default actions and expectations. Returns true iff the // default actions and expectations. Returns true iff the
// verification was successful. // verification was successful.
static bool VerifyAndClear(void* mock_obj); static bool VerifyAndClear(void* mock_obj);
private: private:
friend class internal::UntypedFunctionMockerBase;
// Needed for a function mocker to register itself (so that we know // Needed for a function mocker to register itself (so that we know
// how to clear a mock object). // how to clear a mock object).
template <typename F> template <typename F>
friend class internal::FunctionMockerBase; friend class internal::FunctionMockerBase;
template <typename M> template <typename M>
friend class NiceMock; friend class NiceMock;
template <typename M> template <typename M>
friend class StrictMock; friend class StrictMock;
skipping to change at line 393 skipping to change at line 506
bool operator==(const Expectation& rhs) const { bool operator==(const Expectation& rhs) const {
return expectation_base_ == rhs.expectation_base_; return expectation_base_ == rhs.expectation_base_;
} }
bool operator!=(const Expectation& rhs) const { return !(*this == rhs); } bool operator!=(const Expectation& rhs) const { return !(*this == rhs); }
private: private:
friend class ExpectationSet; friend class ExpectationSet;
friend class Sequence; friend class Sequence;
friend class ::testing::internal::ExpectationBase; friend class ::testing::internal::ExpectationBase;
friend class ::testing::internal::UntypedFunctionMockerBase;
template <typename F> template <typename F>
friend class ::testing::internal::FunctionMockerBase; friend class ::testing::internal::FunctionMockerBase;
template <typename F> template <typename F>
friend class ::testing::internal::TypedExpectation; friend class ::testing::internal::TypedExpectation;
// This comparator is needed for putting Expectation objects into a set. // This comparator is needed for putting Expectation objects into a set.
class Less { class Less {
public: public:
skipping to change at line 540 skipping to change at line 654
// up mocks in the main thread unless you have a good reason not to do // up mocks in the main thread unless you have a good reason not to do
// so. // so.
class InSequence { class InSequence {
public: public:
InSequence(); InSequence();
~InSequence(); ~InSequence();
private: private:
bool sequence_created_; bool sequence_created_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT
} GMOCK_ATTRIBUTE_UNUSED_; } GTEST_ATTRIBUTE_UNUSED_;
namespace internal { namespace internal {
// Points to the implicit sequence introduced by a living InSequence // Points to the implicit sequence introduced by a living InSequence
// object (if any) in the current thread or NULL. // object (if any) in the current thread or NULL.
extern ThreadLocal<Sequence*> g_gmock_implicit_sequence; extern ThreadLocal<Sequence*> g_gmock_implicit_sequence;
// Base class for implementing expectations. // Base class for implementing expectations.
// //
// There are two reasons for having a type-agnostic base class for // There are two reasons for having a type-agnostic base class for
skipping to change at line 578 skipping to change at line 692
// 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(); } 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 << FormatFileLocation(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.
// L >= g_gmock_mutex // L >= g_gmock_mutex
virtual void DescribeCallCountTo(::std::ostream* os) const = 0; void DescribeCallCountTo(::std::ostream* os) const;
// If this mock method has an extra matcher (i.e. .With(matcher)),
// describes it to the ostream.
virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) = 0;
protected: protected:
friend class ::testing::Expectation; friend class ::testing::Expectation;
friend class UntypedFunctionMockerBase;
enum Clause { enum Clause {
// Don't change the order of the enum members! // Don't change the order of the enum members!
kNone, kNone,
kWith, kWith,
kTimes, kTimes,
kInSequence, kInSequence,
kAfter, kAfter,
kWillOnce, kWillOnce,
kWillRepeatedly, kWillRepeatedly,
kRetiresOnSaturation, kRetiresOnSaturation
}; };
typedef std::vector<const void*> UntypedActions;
// 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() = 0; virtual Expectation GetHandle() = 0;
// Asserts that the EXPECT_CALL() statement has the given property. // Asserts that the EXPECT_CALL() statement has the given property.
void AssertSpecProperty(bool property, const string& failure_message) con st { void AssertSpecProperty(bool property, const string& failure_message) con st {
Assert(property, file_, line_, failure_message); Assert(property, file_, line_, failure_message);
} }
// Expects that the EXPECT_CALL() statement has the given property. // Expects that the EXPECT_CALL() statement has the given property.
skipping to change at line 693 skipping to change at line 814
return call_count_; return call_count_;
} }
// Increments the number this expectation has been invoked. // Increments the number this expectation has been invoked.
// L >= g_gmock_mutex // L >= g_gmock_mutex
void IncrementCallCount() { void IncrementCallCount() {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
call_count_++; call_count_++;
} }
private: // Checks the action count (i.e. the number of WillOnce() and
// WillRepeatedly() clauses) against the cardinality if this hasn't
// been done before. Prints a warning if there are too many or too
// few actions.
// L < mutex_
void CheckActionCountIfNotDone() const;
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;
// Implements the .Times() clause.
void UntypedTimes(const Cardinality& a_cardinality);
// 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. 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.
UntypedActions untyped_actions_;
bool extra_matcher_specified_;
bool repeated_action_specified_; // True if a WillRepeatedly() was speci
fied.
bool retires_on_saturation_;
Clause last_clause_;
mutable bool action_count_checked_; // Under mutex_.
mutable Mutex mutex_; // Protects action_count_checked_.
GTEST_DISALLOW_ASSIGN_(ExpectationBase); 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, TypedExpectation(FunctionMockerBase<F>* owner,
const char* a_file, int a_line, const string& a_source_t ext, const char* a_file, int a_line, const string& a_source_t ext,
const ArgumentMatcherTuple& m) const ArgumentMatcherTuple& m)
: ExpectationBase(a_file, a_line, a_source_text), : 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_(DoDefault()) {}
repeated_action_(DoDefault()),
retires_on_saturation_(false),
last_clause_(kNone),
action_count_checked_(false) {}
virtual ~TypedExpectation() { virtual ~TypedExpectation() {
// Check the validity of the action count if it hasn't been done // Check the validity of the action count if it hasn't been done
// yet (for example, if the expectation was never used). // yet (for example, if the expectation was never used).
CheckActionCountIfNotDone(); CheckActionCountIfNotDone();
for (UntypedActions::const_iterator it = untyped_actions_.begin();
it != untyped_actions_.end(); ++it) {
delete static_cast<const Action<F>*>(*it);
}
} }
// Implements the .With() clause. // Implements the .With() clause.
TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) { TypedExpectation& With(const Matcher<const ArgumentTuple&>& m) {
if (last_clause_ == kWith) { if (last_clause_ == kWith) {
ExpectSpecProperty(false, ExpectSpecProperty(false,
".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,
skipping to change at line 776 skipping to change at line 912
} }
last_clause_ = kWith; last_clause_ = kWith;
extra_matcher_ = m; extra_matcher_ = m;
extra_matcher_specified_ = true; extra_matcher_specified_ = true;
return *this; return *this;
} }
// Implements the .Times() clause. // Implements the .Times() clause.
TypedExpectation& Times(const Cardinality& a_cardinality) { TypedExpectation& Times(const Cardinality& a_cardinality) {
if (last_clause_ ==kTimes) { ExpectationBase::UntypedTimes(a_cardinality);
ExpectSpecProperty(false,
".Times() cannot appear "
"more than once in an EXPECT_CALL().");
} else {
ExpectSpecProperty(last_clause_ < kTimes,
".Times() cannot appear after "
".InSequence(), .WillOnce(), .WillRepeatedly(), "
"or .RetiresOnSaturation().");
}
last_clause_ = kTimes;
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 862 skipping to change at line 986
return After(s1, s2, s3, s4).After(s5); return After(s1, s2, s3, s4).After(s5);
} }
// Implements the .WillOnce() clause. // Implements the .WillOnce() clause.
TypedExpectation& WillOnce(const Action<F>& action) { TypedExpectation& WillOnce(const Action<F>& action) {
ExpectSpecProperty(last_clause_ <= kWillOnce, ExpectSpecProperty(last_clause_ <= kWillOnce,
".WillOnce() cannot appear after " ".WillOnce() cannot appear after "
".WillRepeatedly() or .RetiresOnSaturation()."); ".WillRepeatedly() or .RetiresOnSaturation().");
last_clause_ = kWillOnce; last_clause_ = kWillOnce;
actions_.push_back(action); untyped_actions_.push_back(new Action<F>(action));
if (!cardinality_specified()) { if (!cardinality_specified()) {
set_cardinality(Exactly(static_cast<int>(actions_.size()))); set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
} }
return *this; return *this;
} }
// Implements the .WillRepeatedly() clause. // Implements the .WillRepeatedly() clause.
TypedExpectation& WillRepeatedly(const Action<F>& action) { TypedExpectation& WillRepeatedly(const Action<F>& action) {
if (last_clause_ == kWillRepeatedly) { if (last_clause_ == kWillRepeatedly) {
ExpectSpecProperty(false, ExpectSpecProperty(false,
".WillRepeatedly() cannot appear " ".WillRepeatedly() cannot appear "
"more than once in an EXPECT_CALL()."); "more than once in an EXPECT_CALL().");
} else { } else {
ExpectSpecProperty(last_clause_ < kWillRepeatedly, ExpectSpecProperty(last_clause_ < kWillRepeatedly,
".WillRepeatedly() cannot appear " ".WillRepeatedly() cannot appear "
"after .RetiresOnSaturation()."); "after .RetiresOnSaturation().");
} }
last_clause_ = kWillRepeatedly; last_clause_ = kWillRepeatedly;
repeated_action_specified_ = true; repeated_action_specified_ = true;
repeated_action_ = action; repeated_action_ = action;
if (!cardinality_specified()) { if (!cardinality_specified()) {
set_cardinality(AtLeast(static_cast<int>(actions_.size()))); set_cardinality(AtLeast(static_cast<int>(untyped_actions_.size())));
} }
// Now that no more action clauses can be specified, we check // Now that no more action clauses can be specified, we check
// whether their count makes sense. // whether their count makes sense.
CheckActionCountIfNotDone(); CheckActionCountIfNotDone();
return *this; return *this;
} }
// Implements the .RetiresOnSaturation() clause. // Implements the .RetiresOnSaturation() clause.
TypedExpectation& RetiresOnSaturation() { TypedExpectation& RetiresOnSaturation() {
skipping to change at line 919 skipping to change at line 1043
// EXPECT_CALL() macro. // EXPECT_CALL() macro.
const ArgumentMatcherTuple& matchers() const { const ArgumentMatcherTuple& matchers() const {
return matchers_; return matchers_;
} }
// Returns the matcher specified by the .With() clause. // Returns the matcher specified by the .With() clause.
const Matcher<const ArgumentTuple&>& extra_matcher() const { const Matcher<const ArgumentTuple&>& extra_matcher() const {
return extra_matcher_; return extra_matcher_;
} }
// Returns the sequence of actions specified by the .WillOnce() clause.
const std::vector<Action<F> >& actions() const { return actions_; }
// Returns the action specified by the .WillRepeatedly() clause. // Returns the action specified by the .WillRepeatedly() clause.
const Action<F>& repeated_action() const { return repeated_action_; } const Action<F>& repeated_action() const { return repeated_action_; }
// Returns true iff the .RetiresOnSaturation() clause was specified. // If this mock method has an extra matcher (i.e. .With(matcher)),
bool retires_on_saturation() const { return retires_on_saturation_; } // describes it to the ostream.
virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) {
// Describes how many times a function call matching this
// expectation has occurred (implements
// ExpectationBase::DescribeCallCountTo()).
// L >= g_gmock_mutex
virtual void DescribeCallCountTo(::std::ostream* os) const {
g_gmock_mutex.AssertHeld();
// Describes how many times the function is expected to be called.
*os << " Expected: to be ";
cardinality().DescribeTo(os);
*os << "\n Actual: ";
Cardinality::DescribeActualCallCountTo(call_count(), os);
// Describes the state of the expectation (e.g. is it satisfied?
// is it active?).
*os << " - " << (IsOverSaturated() ? "over-saturated" :
IsSaturated() ? "saturated" :
IsSatisfied() ? "satisfied" : "unsatisfied")
<< " and "
<< (is_retired() ? "retired" : "active");
}
void MaybeDescribeExtraMatcherTo(::std::ostream* os) {
if (extra_matcher_specified_) { if (extra_matcher_specified_) {
*os << " Expected args: "; *os << " Expected args: ";
extra_matcher_.DescribeTo(os); extra_matcher_.DescribeTo(os);
*os << "\n"; *os << "\n";
} }
} }
private: private:
template <typename Function> template <typename Function>
friend class FunctionMockerBase; friend class FunctionMockerBase;
skipping to change at line 1047 skipping to change at line 1145
// 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 {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
const int count = call_count(); const int count = call_count();
Assert(count >= 1, __FILE__, __LINE__, Assert(count >= 1, __FILE__, __LINE__,
"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>(untyped_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 in " << source_text() << "...\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 ?
; *static_cast<const Action<F>*>(untyped_actions_[count - 1]) :
repeated_action();
} }
// Given the arguments of a mock function call, if the call will // Given the arguments of a mock function call, if the call will
// over-saturate this expectation, returns the default action; // over-saturate this expectation, returns the default action;
// otherwise, returns the next action in this expectation. Also // otherwise, returns the next action in this expectation. Also
// describes *what* happened to 'what', and explains *why* Google // describes *what* happened to 'what', and explains *why* Google
// Mock does it to 'why'. This method is not const as it calls // Mock does it to 'why'. This method is not const as it calls
// IncrementCallCount(). // IncrementCallCount(). A return value of NULL means the default
// action.
// L >= g_gmock_mutex // L >= g_gmock_mutex
Action<F> GetActionForArguments(const FunctionMockerBase<F>* mocker, const Action<F>* GetActionForArguments(const FunctionMockerBase<F>* mocke
const ArgumentTuple& args, r,
::std::ostream* what, const ArgumentTuple& args,
::std::ostream* why) { ::std::ostream* what,
::std::ostream* why) {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
if (IsSaturated()) { if (IsSaturated()) {
// We have an excessive call. // We have an excessive call.
IncrementCallCount(); IncrementCallCount();
*what << "Mock function called more times than expected - "; *what << "Mock function called more times than expected - ";
mocker->DescribeDefaultActionTo(args, what); mocker->DescribeDefaultActionTo(args, what);
DescribeCallCountTo(why); DescribeCallCountTo(why);
// TODO(wan): allow the user to control whether unexpected calls // TODO(wan@google.com): allow the user to control whether
// should fail immediately or continue using a flag // unexpected calls should fail immediately or continue using a
// --gmock_unexpected_calls_are_fatal. // flag --gmock_unexpected_calls_are_fatal.
return DoDefault(); return NULL;
} }
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 << "Mock function call matches " << source_text() <<"...\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
// WillRepeatedly() clauses) against the cardinality if this hasn't
// been done before. Prints a warning if there are too many or too
// few actions.
// L < mutex_
void CheckActionCountIfNotDone() const {
bool should_check = false;
{
MutexLock l(&mutex_);
if (!action_count_checked_) {
action_count_checked_ = true;
should_check = true;
}
}
if (should_check) {
if (!cardinality_specified_) {
// The cardinality was inferred - no need to check the action
// count against it.
return;
}
// The cardinality was explicitly specified.
const int action_count = static_cast<int>(actions_.size());
const int upper_bound = cardinality().ConservativeUpperBound();
const int lower_bound = cardinality().ConservativeLowerBound();
bool too_many; // True if there are too many actions, or false
// if there are too few.
if (action_count > upper_bound ||
(action_count == upper_bound && repeated_action_specified_)) {
too_many = true;
} else if (0 < action_count && action_count < lower_bound &&
!repeated_action_specified_) {
too_many = false;
} else {
return;
}
::std::stringstream ss;
DescribeLocationTo(&ss);
ss << "Too " << (too_many ? "many" : "few")
<< " actions specified in " << source_text() << "...\n"
<< "Expected to be ";
cardinality().DescribeTo(&ss);
ss << ", but has " << (too_many ? "" : "only ")
<< action_count << " WillOnce()"
<< (action_count == 1 ? "" : "s");
if (repeated_action_specified_) {
ss << " and a WillRepeatedly()";
}
ss << ".";
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_;
bool repeated_action_specified_; // True if a WillRepeatedly() was speci
fied.
Action<F> repeated_action_; Action<F> repeated_action_;
bool retires_on_saturation_;
Clause last_clause_;
mutable bool action_count_checked_; // Under mutex_.
mutable Mutex mutex_; // Protects action_count_checked_.
GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation); 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
// ::testing::internal and import it into ::testing. // ::testing::internal and import it into ::testing.
// Logs a message including file and line number information.
void LogWithLocation(testing::internal::LogSeverity severity,
const char* file, int line,
const string& message);
template <typename F> template <typename F>
class MockSpec { class MockSpec {
public: public:
typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple; typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
typedef typename internal::Function<F>::ArgumentMatcherTuple typedef typename internal::Function<F>::ArgumentMatcherTuple
ArgumentMatcherTuple; ArgumentMatcherTuple;
// Constructs a MockSpec object, given the function mocker object // Constructs a MockSpec object, given the function mocker object
// that the spec is associated with. // that the spec is associated with.
explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker) explicit MockSpec(internal::FunctionMockerBase<F>* function_mocker)
: function_mocker_(function_mocker) {} : function_mocker_(function_mocker) {}
// Adds a new default action spec to the function mocker and returns // Adds a new default action spec to the function mocker and returns
// the newly created spec. // the newly created spec.
internal::DefaultActionSpec<F>& InternalDefaultActionSetAt( internal::OnCallSpec<F>& InternalDefaultActionSetAt(
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_->AddNewOnCallSpec(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) {
const string source_text(string("EXPECT_CALL(") + obj + ", " + call + " )"); const string source_text(string("EXPECT_CALL(") + obj + ", " + call + " )");
LogWithLocation(internal::INFO, file, line, source_text + " invoked"); LogWithLocation(internal::INFO, file, line, source_text + " invoked");
return function_mocker_->AddNewExpectation( return function_mocker_->AddNewExpectation(
file, line, source_text, matchers_); 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;
} }
// Logs a message including file and line number information.
void LogWithLocation(testing::internal::LogSeverity severity,
const char* file, int line,
const string& message) {
::std::ostringstream s;
s << file << ":" << line << ": " << message << ::std::endl;
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); 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.
#endif // _MSV_VER #endif // _MSV_VER
// C++ treats the void type specially. For example, you cannot define // C++ treats the void type specially. For example, you cannot define
// 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.
// when T is not void.
// Untyped base class for ActionResultHolder<T>.
class UntypedActionResultHolderBase {
public:
virtual ~UntypedActionResultHolderBase() {}
// Prints the held value as an action's result to os.
virtual void PrintAsActionResult(::std::ostream* os) const = 0;
};
// This generic definition is used when T is not void.
template <typename T> template <typename T>
class ActionResultHolder { class ActionResultHolder : public UntypedActionResultHolderBase {
public: public:
explicit ActionResultHolder(T a_value) : value_(a_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_; } // Returns the held value and deletes this object.
T GetValueAndDelete() const {
T retval(value_);
delete this;
return retval;
}
// 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 { virtual void PrintAsActionResult(::std::ostream* os) const {
*os << "\n Returns: "; *os << "\n Returns: ";
// T may be a reference type, so we don't use UniversalPrint().
UniversalPrinter<T>::Print(value_, os); UniversalPrinter<T>::Print(value_, os);
} }
// Performs the given mock function's default action and returns the // Performs the given mock function's default action and returns the
// result in a ActionResultHolder. // result in a new-ed ActionResultHolder.
template <typename Function, typename Arguments> template <typename F>
static ActionResultHolder PerformDefaultAction( static ActionResultHolder* PerformDefaultAction(
const FunctionMockerBase<Function>* func_mocker, const FunctionMockerBase<F>* func_mocker,
const Arguments& args, const typename Function<F>::ArgumentTuple& args,
const string& call_description) { const string& call_description) {
return ActionResultHolder( return new ActionResultHolder(
func_mocker->PerformDefaultAction(args, call_description)); func_mocker->PerformDefaultAction(args, call_description));
} }
// Performs the given action and returns the result in a // Performs the given action and returns the result in a new-ed
// ActionResultHolder. // ActionResultHolder.
template <typename Function, typename Arguments> template <typename F>
static ActionResultHolder PerformAction(const Action<Function>& action, static ActionResultHolder*
const Arguments& args) { PerformAction(const Action<F>& action,
return ActionResultHolder(action.Perform(args)); const typename Function<F>::ArgumentTuple& args) {
return new ActionResultHolder(action.Perform(args));
} }
private: private:
T value_; T value_;
// T could be a reference type, so = isn't supported. // T could be a reference type, so = isn't supported.
GTEST_DISALLOW_ASSIGN_(ActionResultHolder); GTEST_DISALLOW_ASSIGN_(ActionResultHolder);
}; };
// Specialization for T = void. // Specialization for T = void.
template <> template <>
class ActionResultHolder<void> { class ActionResultHolder<void> : public UntypedActionResultHolderBase {
public: public:
ActionResultHolder() {} void GetValueAndDelete() const { delete this; }
void value() const {}
void PrintAsActionResult(::std::ostream* /* os */) const {}
template <typename Function, typename Arguments> virtual void PrintAsActionResult(::std::ostream* /* os */) const {}
static ActionResultHolder PerformDefaultAction(
const FunctionMockerBase<Function>* func_mocker, // Performs the given mock function's default action and returns NULL;
const Arguments& args, template <typename F>
static ActionResultHolder* PerformDefaultAction(
const FunctionMockerBase<F>* func_mocker,
const typename Function<F>::ArgumentTuple& args,
const string& call_description) { const string& call_description) {
func_mocker->PerformDefaultAction(args, call_description); func_mocker->PerformDefaultAction(args, call_description);
return ActionResultHolder(); return NULL;
} }
template <typename Function, typename Arguments> // Performs the given action and returns NULL.
static ActionResultHolder PerformAction(const Action<Function>& action, template <typename F>
const Arguments& args) { static ActionResultHolder* PerformAction(
const Action<F>& action,
const typename Function<F>::ArgumentTuple& args) {
action.Perform(args); action.Perform(args);
return ActionResultHolder(); return NULL;
} }
}; };
// The base of the function mocker class for the given function type. // The base of the function mocker class for the given function type.
// We put the methods in this class instead of its child to avoid code // We put the methods in this class instead of its child to avoid code
// bloat. // bloat.
template <typename F> template <typename F>
class FunctionMockerBase : public UntypedFunctionMockerBase { class FunctionMockerBase : public UntypedFunctionMockerBase {
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;
typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple; typedef typename Function<F>::ArgumentMatcherTuple ArgumentMatcherTuple;
FunctionMockerBase() : mock_obj_(NULL), name_(""), current_spec_(this) {} FunctionMockerBase() : current_spec_(this) {}
// The destructor verifies that all expectations on this mock // The destructor verifies that all expectations on this mock
// function have been satisfied. If not, it will report Google Test // function have been satisfied. If not, it will report Google Test
// non-fatal failures for the violations. // non-fatal failures for the violations.
// L < g_gmock_mutex // L < g_gmock_mutex
virtual ~FunctionMockerBase() { virtual ~FunctionMockerBase() {
MutexLock l(&g_gmock_mutex); MutexLock l(&g_gmock_mutex);
VerifyAndClearExpectationsLocked(); VerifyAndClearExpectationsLocked();
Mock::UnregisterLocked(this); Mock::UnregisterLocked(this);
ClearDefaultActionsLocked();
} }
// Returns the ON_CALL spec that matches this mock function with the // Returns the ON_CALL spec that matches this mock function with the
// given arguments; returns NULL if no matching ON_CALL is found. // given arguments; returns NULL if no matching ON_CALL is found.
// L = * // L = *
const DefaultActionSpec<F>* FindDefaultActionSpec( const OnCallSpec<F>* FindOnCallSpec(
const ArgumentTuple& args) const { const ArgumentTuple& args) const {
for (typename std::vector<DefaultActionSpec<F> >::const_reverse_iterato for (UntypedOnCallSpecs::const_reverse_iterator it
r it = untyped_on_call_specs_.rbegin();
= default_actions_.rbegin(); it != untyped_on_call_specs_.rend(); ++it) {
it != default_actions_.rend(); ++it) { const OnCallSpec<F>* spec = static_cast<const OnCallSpec<F>*>(*it);
const DefaultActionSpec<F>& spec = *it; if (spec->Matches(args))
if (spec.Matches(args)) return spec;
return &spec;
} }
return NULL; return NULL;
} }
// Performs the default action of this mock function on the given argumen ts // Performs the default action of this mock function on the given argumen ts
// and returns the result. Asserts with a helpful call descrption if ther e is // and returns the result. Asserts with a helpful call descrption if ther e is
// no valid return value. This method doesn't depend on the mutable state of // no valid return value. This method doesn't depend on the mutable state of
// this object, and thus can be called concurrently without locking. // this object, and thus can be called concurrently without locking.
// L = * // L = *
Result PerformDefaultAction(const ArgumentTuple& args, Result PerformDefaultAction(const ArgumentTuple& args,
const string& call_description) const { const string& call_description) const {
const DefaultActionSpec<F>* const spec = FindDefaultActionSpec(args); const OnCallSpec<F>* const spec =
this->FindOnCallSpec(args);
if (spec != NULL) { if (spec != NULL) {
return spec->GetAction().Perform(args); return spec->GetAction().Perform(args);
} }
Assert(DefaultValue<Result>::Exists(), "", -1, Assert(DefaultValue<Result>::Exists(), "", -1,
call_description + "\n The mock function has no default actio n " call_description + "\n The mock function has no default actio n "
"set, and its return type has no default value set."); "set, and its return type has no default value set.");
return DefaultValue<Result>::Get(); return DefaultValue<Result>::Get();
} }
// Registers this function mocker and the mock object owning it; // Performs the default action with the given arguments and returns
// returns a reference to the function mocker object. This is only // the action's result. The call description string will be used in
// called by the ON_CALL() and EXPECT_CALL() macros. // the error message to describe the call in the case the default
// L < g_gmock_mutex // action fails. The caller is responsible for deleting the result.
FunctionMocker<F>& RegisterOwner(const void* mock_obj) { // L = *
{ virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction(
MutexLock l(&g_gmock_mutex); const void* untyped_args, // must point to an ArgumentTuple
mock_obj_ = mock_obj; const string& call_description) const {
} const ArgumentTuple& args =
Mock::Register(mock_obj, this); *static_cast<const ArgumentTuple*>(untyped_args);
return *::testing::internal::down_cast<FunctionMocker<F>*>(this); return ResultHolder::PerformDefaultAction(this, args, call_description)
;
} }
// The following two functions are from UntypedFunctionMockerBase. // Performs the given action with the given arguments and returns
// the action's result. The caller is responsible for deleting the
// Verifies that all expectations on this mock function have been // result.
// satisfied. Reports one or more Google Test non-fatal failures // L = *
// and returns false if not. virtual UntypedActionResultHolderBase* UntypedPerformAction(
// L >= g_gmock_mutex const void* untyped_action, const void* untyped_args) const {
virtual bool VerifyAndClearExpectationsLocked(); // Make a copy of the action before performing it, in case the
// action deletes the mock object (and thus deletes itself).
const Action<F> action = *static_cast<const Action<F>*>(untyped_action)
;
const ArgumentTuple& args =
*static_cast<const ArgumentTuple*>(untyped_args);
return ResultHolder::PerformAction(action, args);
}
// Clears the ON_CALL()s set on this mock function. // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked():
// clears the ON_CALL()s set on this mock function.
// L >= g_gmock_mutex // L >= g_gmock_mutex
virtual void ClearDefaultActionsLocked() { virtual void ClearDefaultActionsLocked() {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
default_actions_.clear(); for (UntypedOnCallSpecs::const_iterator it =
} untyped_on_call_specs_.begin();
it != untyped_on_call_specs_.end(); ++it) {
// Sets the name of the function being mocked. Will be called upon delete static_cast<const OnCallSpec<F>*>(*it);
// each invocation of this mock function.
// L < g_gmock_mutex
void SetOwnerAndName(const void* mock_obj, const char* name) {
// We protect name_ under g_gmock_mutex in case this mock function
// is called from two threads concurrently.
MutexLock l(&g_gmock_mutex);
mock_obj_ = mock_obj;
name_ = name;
}
// Returns the address of the mock object this method belongs to.
// Must be called after SetOwnerAndName() has been called.
// L < g_gmock_mutex
const void* MockObject() const {
const void* mock_obj;
{
// We protect mock_obj_ under g_gmock_mutex in case this mock
// function is called from two threads concurrently.
MutexLock l(&g_gmock_mutex);
mock_obj = mock_obj_;
}
return mock_obj;
}
// Returns the name of the function being mocked. Must be called
// after SetOwnerAndName() has been called.
// L < g_gmock_mutex
const char* Name() const {
const char* name;
{
// We protect name_ under g_gmock_mutex in case this mock
// function is called from two threads concurrently.
MutexLock l(&g_gmock_mutex);
name = name_;
} }
return name; untyped_on_call_specs_.clear();
} }
protected: protected:
template <typename Function> template <typename Function>
friend class MockSpec; friend class MockSpec;
typedef ActionResultHolder<Result> ResultHolder;
// Returns the result of invoking this mock function with the given // Returns the result of invoking this mock function with the given
// arguments. This function can be safely called from multiple // arguments. This function can be safely called from multiple
// threads concurrently. // threads concurrently.
// L < g_gmock_mutex // L < g_gmock_mutex
Result InvokeWith(const ArgumentTuple& args); Result InvokeWith(const ArgumentTuple& args) {
return static_cast<const ResultHolder*>(
this->UntypedInvokeWith(&args))->GetValueAndDelete();
}
// Adds and returns a default action spec for this mock function. // Adds and returns a default action spec for this mock function.
// L < g_gmock_mutex // L < g_gmock_mutex
DefaultActionSpec<F>& AddNewDefaultActionSpec( OnCallSpec<F>& AddNewOnCallSpec(
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)); OnCallSpec<F>* const on_call_spec = new OnCallSpec<F>(file, line, m);
return default_actions_.back(); untyped_on_call_specs_.push_back(on_call_spec);
return *on_call_spec;
} }
// 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, const char* file,
int line, int line,
const string& source_text, 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( TypedExpectation<F>* const expectation =
new TypedExpectation<F>(this, file, line, source_text, m)); new TypedExpectation<F>(this, file, line, source_text, m);
expectations_.push_back(expectation); const linked_ptr<ExpectationBase> untyped_expectation(expectation);
untyped_expectations_.push_back(untyped_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(untyped_expectation));
} }
return *expectation; return *expectation;
} }
// The current spec (either default action spec or expectation spec) // The current spec (either default action spec or expectation spec)
// being described on this function mocker. // being described on this function mocker.
MockSpec<F>& current_spec() { return current_spec_; } MockSpec<F>& current_spec() { return current_spec_; }
private: private:
template <typename Func> friend class TypedExpectation; template <typename Func> friend class TypedExpectation;
typedef std::vector<internal::linked_ptr<TypedExpectation<F> > > // Some utilities needed for implementing UntypedInvokeWith().
TypedExpectations;
// Returns an Expectation object that references and co-owns exp,
// which must be an expectation on this mock function.
Expectation GetHandleOf(TypedExpectation<F>* exp) {
for (typename TypedExpectations::const_iterator it = expectations_.begi
n();
it != expectations_.end(); ++it) {
if (it->get() == exp) {
return Expectation(*it);
}
}
Assert(false, __FILE__, __LINE__, "Cannot find expectation.");
return Expectation();
// The above statement is just to make the code compile, and will
// never be executed.
}
// Some utilities needed for implementing InvokeWith().
// Describes what default action will be performed for the given // Describes what default action will be performed for the given
// arguments. // arguments.
// L = * // L = *
void DescribeDefaultActionTo(const ArgumentTuple& args, void DescribeDefaultActionTo(const ArgumentTuple& args,
::std::ostream* os) const { ::std::ostream* os) const {
const DefaultActionSpec<F>* const spec = FindDefaultActionSpec(args); const OnCallSpec<F>* const spec = FindOnCallSpec(args);
if (spec == NULL) { if (spec == NULL) {
*os << (internal::type_equals<Result, void>::value ? *os << (internal::type_equals<Result, void>::value ?
"returning directly.\n" : "returning directly.\n" :
"returning default value.\n"); "returning default value.\n");
} else { } else {
*os << "taking default action specified at:\n" *os << "taking default action specified at:\n"
<< spec->file() << ":" << spec->line() << ":\n"; << FormatFileLocation(spec->file(), spec->line()) << "\n";
} }
} }
// Writes a message that the call is uninteresting (i.e. neither // Writes a message that the call is uninteresting (i.e. neither
// explicitly expected nor explicitly unexpected) to the given // explicitly expected nor explicitly unexpected) to the given
// ostream. // ostream.
// L < g_gmock_mutex // L < g_gmock_mutex
void DescribeUninterestingCall(const ArgumentTuple& args, virtual void UntypedDescribeUninterestingCall(const void* untyped_args,
::std::ostream* os) const { ::std::ostream* os) const {
const ArgumentTuple& args =
*static_cast<const ArgumentTuple*>(untyped_args);
*os << "Uninteresting mock function call - "; *os << "Uninteresting mock function call - ";
DescribeDefaultActionTo(args, os); DescribeDefaultActionTo(args, os);
*os << " Function call: " << Name(); *os << " Function call: " << Name();
UniversalPrinter<ArgumentTuple>::Print(args, os); UniversalPrint(args, os);
} }
// Returns the expectation that matches the given function arguments
// (or NULL is there's no match); when a match is found,
// untyped_action is set to point to the action that should be
// performed (or NULL if the action is "do default"), and
// is_excessive is modified to indicate whether the call exceeds the
// expected number.
//
// Critical section: We must find the matching expectation and the // Critical section: We must find the matching expectation and the
// corresponding action that needs to be taken in an ATOMIC // corresponding action that needs to be taken in an ATOMIC
// transaction. Otherwise another thread may call this mock // transaction. Otherwise another thread may call this mock
// method in the middle and mess up the state. // method in the middle and mess up the state.
// //
// However, performing the action has to be left out of the critical // However, performing the action has to be left out of the critical
// section. The reason is that we have no control on what the // section. The reason is that we have no control on what the
// action does (it can invoke an arbitrary user function or even a // action does (it can invoke an arbitrary user function or even a
// mock function) and excessive locking could cause a dead lock. // mock function) and excessive locking could cause a dead lock.
// L < g_gmock_mutex // L < g_gmock_mutex
bool FindMatchingExpectationAndAction( virtual const ExpectationBase* UntypedFindMatchingExpectation(
const ArgumentTuple& args, TypedExpectation<F>** exp, Action<F>* acti const void* untyped_args,
on, const void** untyped_action, bool* is_excessive,
bool* is_excessive, ::std::ostream* what, ::std::ostream* why) { ::std::ostream* what, ::std::ostream* why) {
const ArgumentTuple& args =
*static_cast<const ArgumentTuple*>(untyped_args);
MutexLock l(&g_gmock_mutex); MutexLock l(&g_gmock_mutex);
*exp = this->FindMatchingExpectationLocked(args); TypedExpectation<F>* exp = this->FindMatchingExpectationLocked(args);
if (*exp == NULL) { // A match wasn't found. if (exp == NULL) { // A match wasn't found.
*action = DoDefault();
this->FormatUnexpectedCallMessageLocked(args, what, why); this->FormatUnexpectedCallMessageLocked(args, what, why);
return false; return NULL;
} }
// This line must be done before calling GetActionForArguments(), // This line must be done before calling GetActionForArguments(),
// which will increment the call count for *exp and thus affect // which will increment the call count for *exp and thus affect
// its saturation status. // its saturation status.
*is_excessive = (*exp)->IsSaturated(); *is_excessive = exp->IsSaturated();
*action = (*exp)->GetActionForArguments(this, args, what, why); const Action<F>* action = exp->GetActionForArguments(this, args, what,
return true; why);
if (action != NULL && action->IsDoDefault())
action = NULL; // Normalize "do default" to NULL.
*untyped_action = action;
return exp;
}
// Prints the given function arguments to the ostream.
virtual void UntypedPrintArgs(const void* untyped_args,
::std::ostream* os) const {
const ArgumentTuple& args =
*static_cast<const ArgumentTuple*>(untyped_args);
UniversalPrint(args, os);
} }
// Returns the expectation that matches the arguments, or NULL if no // Returns the expectation that matches the arguments, or NULL if no
// expectation matches them. // expectation matches them.
// L >= g_gmock_mutex // L >= g_gmock_mutex
TypedExpectation<F>* FindMatchingExpectationLocked( TypedExpectation<F>* FindMatchingExpectationLocked(
const ArgumentTuple& args) const { const ArgumentTuple& args) const {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
for (typename TypedExpectations::const_reverse_iterator it = for (typename UntypedExpectations::const_reverse_iterator it =
expectations_.rbegin(); untyped_expectations_.rbegin();
it != expectations_.rend(); ++it) { it != untyped_expectations_.rend(); ++it) {
TypedExpectation<F>* const exp = it->get(); TypedExpectation<F>* const exp =
static_cast<TypedExpectation<F>*>(it->get());
if (exp->ShouldHandleArguments(args)) { if (exp->ShouldHandleArguments(args)) {
return exp; return exp;
} }
} }
return NULL; return NULL;
} }
// Returns a message that the arguments don't match any expectation. // Returns a message that the arguments don't match any expectation.
// L >= g_gmock_mutex // L >= g_gmock_mutex
void FormatUnexpectedCallMessageLocked(const ArgumentTuple& args, void FormatUnexpectedCallMessageLocked(const ArgumentTuple& args,
skipping to change at line 1608 skipping to change at line 1649
DescribeDefaultActionTo(args, os); DescribeDefaultActionTo(args, os);
PrintTriedExpectationsLocked(args, why); PrintTriedExpectationsLocked(args, why);
} }
// Prints a list of expectations that have been tried against the // Prints a list of expectations that have been tried against the
// current mock function call. // current mock function call.
// L >= g_gmock_mutex // L >= g_gmock_mutex
void PrintTriedExpectationsLocked(const ArgumentTuple& args, void PrintTriedExpectationsLocked(const ArgumentTuple& args,
::std::ostream* why) const { ::std::ostream* why) const {
g_gmock_mutex.AssertHeld(); g_gmock_mutex.AssertHeld();
const int count = static_cast<int>(expectations_.size()); const int count = static_cast<int>(untyped_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++) {
TypedExpectation<F>* const expectation =
static_cast<TypedExpectation<F>*>(untyped_expectations_[i].get())
;
*why << "\n"; *why << "\n";
expectations_[i]->DescribeLocationTo(why); expectation->DescribeLocationTo(why);
if (count > 1) { if (count > 1) {
*why << "tried expectation #" << i << ": "; *why << "tried expectation #" << i << ": ";
} }
*why << expectations_[i]->source_text() << "...\n"; *why << expectation->source_text() << "...\n";
expectations_[i]->ExplainMatchResultTo(args, why); expectation->ExplainMatchResultTo(args, why);
expectations_[i]->DescribeCallCountTo(why); expectation->DescribeCallCountTo(why);
} }
} }
// Address of the mock object this mock method belongs to. Only
// valid after this mock method has been called or
// ON_CALL/EXPECT_CALL has been invoked on it.
const void* mock_obj_; // Protected by g_gmock_mutex.
// Name of the function being mocked. Only valid after this mock
// method has been called.
const char* name_; // Protected by g_gmock_mutex.
// The current spec (either default action spec or expectation spec) // The current spec (either default action spec or expectation spec)
// being described on this function mocker. // being described on this function mocker.
MockSpec<F> current_spec_; MockSpec<F> current_spec_;
// All default action specs for this function mocker.
std::vector<DefaultActionSpec<F> > default_actions_;
// All expectations for this function mocker.
TypedExpectations expectations_;
// There is no generally useful and implementable semantics of // There is no generally useful and implementable semantics of
// copying a mock object, so copying a mock is usually a user error. // copying a mock object, so copying a mock is usually a user error.
// Thus we disallow copying function mockers. If the user really // Thus we disallow copying function mockers. If the user really
// wants to copy a mock object, he should implement his own copy // wants to copy a mock object, he should implement his own copy
// operation, for example: // operation, for example:
// //
// class MockFoo : public Foo { // class MockFoo : public Foo {
// public: // public:
// // Defines a copy constructor explicitly. // // Defines a copy constructor explicitly.
// MockFoo(const MockFoo& src) {} // MockFoo(const MockFoo& src) {}
// ... // ...
// }; // };
GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase); GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase);
}; // class FunctionMockerBase }; // class FunctionMockerBase
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) // Restores the warning state. # pragma warning(pop) // Restores the warning state.
#endif // _MSV_VER #endif // _MSV_VER
// Implements methods of FunctionMockerBase. // Implements methods of FunctionMockerBase.
// 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 and // satisfied. Reports one or more Google Test non-fatal failures and
// returns false if not. // returns false if not.
// L >= g_gmock_mutex // L >= g_gmock_mutex
template <typename F>
bool FunctionMockerBase<F>::VerifyAndClearExpectationsLocked() {
g_gmock_mutex.AssertHeld();
bool expectations_met = true;
for (typename TypedExpectations::const_iterator it = expectations_.begin(
);
it != expectations_.end(); ++it) {
TypedExpectation<F>* const exp = it->get();
if (exp->IsOverSaturated()) {
// There was an upper-bound violation. Since the error was
// already reported when it occurred, there is no need to do
// anything here.
expectations_met = false;
} else if (!exp->IsSatisfied()) {
expectations_met = false;
::std::stringstream ss;
ss << "Actual function call count doesn't match "
<< exp->source_text() << "...\n";
// No need to show the source file location of the expectation
// in the description, as the Expect() call that follows already
// takes care of it.
exp->MaybeDescribeExtraMatcherTo(&ss);
exp->DescribeCallCountTo(&ss);
Expect(false, exp->file(), exp->line(), ss.str());
}
}
expectations_.clear();
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'.
void ReportUninterestingCall(CallReaction reaction, const string& msg); void ReportUninterestingCall(CallReaction reaction, const string& msg);
// Calculates the result of invoking this mock function with the given
// arguments, prints it, and returns it.
// L < g_gmock_mutex
template <typename F>
typename Function<F>::Result FunctionMockerBase<F>::InvokeWith(
const typename Function<F>::ArgumentTuple& args) {
typedef ActionResultHolder<Result> ResultHolder;
if (expectations_.size() == 0) {
// No expectation is set on this mock method - we have an
// uninteresting call.
// We must get Google Mock's reaction on uninteresting calls
// made on this mock object BEFORE performing the action,
// because the action may DELETE the mock object and make the
// following expression meaningless.
const CallReaction reaction =
Mock::GetReactionOnUninterestingCalls(MockObject());
// True iff we need to print this call's arguments and return
// value. This definition must be kept in sync with
// the behavior of ReportUninterestingCall().
const bool need_to_report_uninteresting_call =
// If the user allows this uninteresting call, we print it
// only when he wants informational messages.
reaction == ALLOW ? LogIsVisible(INFO) :
// If the user wants this to be a warning, we print it only
// when he wants to see warnings.
reaction == WARN ? LogIsVisible(WARNING) :
// Otherwise, the user wants this to be an error, and we
// should always print detailed information in the error.
true;
if (!need_to_report_uninteresting_call) {
// Perform the action without printing the call information.
return PerformDefaultAction(args, "");
}
// Warns about the uninteresting call.
::std::stringstream ss;
DescribeUninterestingCall(args, &ss);
// Calculates the function result.
const ResultHolder result =
ResultHolder::PerformDefaultAction(this, args, ss.str());
// Prints the function result.
result.PrintAsActionResult(&ss);
ReportUninterestingCall(reaction, ss.str());
return result.value();
}
bool is_excessive = false;
::std::stringstream ss;
::std::stringstream why;
::std::stringstream loc;
Action<F> action;
TypedExpectation<F>* exp;
// The FindMatchingExpectationAndAction() function acquires and
// releases g_gmock_mutex.
const bool found = FindMatchingExpectationAndAction(
args, &exp, &action, &is_excessive, &ss, &why);
// True iff we need to print the call's arguments and return value.
// This definition must be kept in sync with the uses of Expect()
// and Log() in this function.
const bool need_to_report_call = !found || is_excessive || LogIsVisible(I
NFO);
if (!need_to_report_call) {
// Perform the action without printing the call information.
return action.IsDoDefault() ? PerformDefaultAction(args, "") :
action.Perform(args);
}
ss << " Function call: " << Name();
UniversalPrinter<ArgumentTuple>::Print(args, &ss);
// In case the action deletes a piece of the expectation, we
// generate the message beforehand.
if (found && !is_excessive) {
exp->DescribeLocationTo(&loc);
}
const ResultHolder result = action.IsDoDefault() ?
ResultHolder::PerformDefaultAction(this, args, ss.str()) :
ResultHolder::PerformAction(action, args);
result.PrintAsActionResult(&ss);
ss << "\n" << why.str();
if (!found) {
// No expectation matches this call - reports a failure.
Expect(false, NULL, -1, ss.str());
} else if (is_excessive) {
// We had an upper-bound violation and the failure message is in ss.
Expect(false, exp->file(), exp->line(), ss.str());
} else {
// We had an expected call and the matching expectation is
// described in ss.
Log(INFO, loc.str() + ss.str(), 2);
}
return result.value();
}
} // 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 MockSpec class template is // inside a header file. However, the MockSpec class template is
// meant to be defined in the ::testing namespace. The following line // 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 cannot // is just a trick for working around a bug in MSVC 8.0, which cannot
// handle it if we define MockSpec in ::testing. // handle it if we define MockSpec in ::testing.
using internal::MockSpec; using internal::MockSpec;
// Const(x) is a convenient function for obtaining a const reference // Const(x) is a convenient function for obtaining a const reference
 End of changes. 103 change blocks. 
501 lines changed or deleted 397 lines changed or added


 gmock.h   gmock.h 
skipping to change at line 58 skipping to change at line 58
// EXPECT_CALL(mock_object.Method(...)) // EXPECT_CALL(mock_object.Method(...))
// .With(...) ? // .With(...) ?
// .Times(...) ? // .Times(...) ?
// .InSequence(...) * // .InSequence(...) *
// .WillOnce(...) * // .WillOnce(...) *
// .WillRepeatedly(...) ? // .WillRepeatedly(...) ?
// .RetiresOnSaturation() ? ; // .RetiresOnSaturation() ? ;
// //
// where all clauses are optional and WillOnce() can be repeated. // where all clauses are optional and WillOnce() can be repeated.
#include <gmock/gmock-actions.h> #include "gmock/gmock-actions.h"
#include <gmock/gmock-cardinalities.h> #include "gmock/gmock-cardinalities.h"
#include <gmock/gmock-generated-actions.h> #include "gmock/gmock-generated-actions.h"
#include <gmock/gmock-generated-function-mockers.h> #include "gmock/gmock-generated-function-mockers.h"
#include <gmock/gmock-generated-matchers.h> #include "gmock/gmock-generated-matchers.h"
#include <gmock/gmock-more-actions.h> #include "gmock/gmock-more-actions.h"
#include <gmock/gmock-generated-nice-strict.h> #include "gmock/gmock-generated-nice-strict.h"
#include <gmock/gmock-matchers.h> #include "gmock/gmock-matchers.h"
#include <gmock/gmock-printers.h> #include "gmock/internal/gmock-internal-utils.h"
#include <gmock/internal/gmock-internal-utils.h>
namespace testing { namespace testing {
// Declares Google Mock flags that we want a user to use programmatically. // Declares Google Mock flags that we want a user to use programmatically.
GMOCK_DECLARE_bool_(catch_leaked_mocks); GMOCK_DECLARE_bool_(catch_leaked_mocks);
GMOCK_DECLARE_string_(verbose); GMOCK_DECLARE_string_(verbose);
// Initializes Google Mock. This must be called before running the // Initializes Google Mock. This must be called before running the
// tests. In particular, it parses the command line for the flags // tests. In particular, it parses the command line for the flags
// that Google Mock recognizes. Whenever a Google Mock flag is seen, // that Google Mock recognizes. Whenever a Google Mock flag is seen,
 End of changes. 1 change blocks. 
10 lines changed or deleted 9 lines changed or added


 gtest-death-test-internal.h   gtest-death-test-internal.h 
skipping to change at line 40 skipping to change at line 40
// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee) // Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
// //
// The Google C++ Testing Framework (Google Test) // The Google C++ Testing Framework (Google Test)
// //
// This header file defines internal utilities needed for implementing // This header file defines internal utilities needed for implementing
// death tests. They are subject to change without notice. // death tests. They are subject to change without notice.
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
#include <gtest/internal/gtest-internal.h> #include "gtest/internal/gtest-internal.h"
#include <stdio.h>
namespace testing { namespace testing {
namespace internal { namespace internal {
GTEST_DECLARE_string_(internal_run_death_test); GTEST_DECLARE_string_(internal_run_death_test);
// Names of the flags (needed for parsing Google Test flags). // Names of the flags (needed for parsing Google Test flags).
const char kDeathTestStyleFlag[] = "death_test_style"; const char kDeathTestStyleFlag[] = "death_test_style";
const char kDeathTestUseFork[] = "death_test_use_fork"; const char kDeathTestUseFork[] = "death_test_use_fork";
const char kInternalRunDeathTestFlag[] = "internal_run_death_test"; const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
skipping to change at line 99 skipping to change at line 101
GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel); GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel);
} GTEST_ATTRIBUTE_UNUSED_; } GTEST_ATTRIBUTE_UNUSED_;
// An enumeration of possible roles that may be taken when a death // An enumeration of possible roles that may be taken when a death
// test is encountered. EXECUTE means that the death test logic should // test is encountered. EXECUTE means that the death test logic should
// be executed immediately. OVERSEE means that the program should prepar e // be executed immediately. OVERSEE means that the program should prepar e
// the appropriate environment for a child process to execute the death // the appropriate environment for a child process to execute the death
// test, then wait for it to complete. // test, then wait for it to complete.
enum TestRole { OVERSEE_TEST, EXECUTE_TEST }; enum TestRole { OVERSEE_TEST, EXECUTE_TEST };
// An enumeration of the two reasons that a test might be aborted. // An enumeration of the three reasons that a test might be aborted.
enum AbortReason { TEST_ENCOUNTERED_RETURN_STATEMENT, TEST_DID_NOT_DIE }; enum AbortReason {
TEST_ENCOUNTERED_RETURN_STATEMENT,
TEST_THREW_EXCEPTION,
TEST_DID_NOT_DIE
};
// Assumes one of the above roles. // Assumes one of the above roles.
virtual TestRole AssumeRole() = 0; virtual TestRole AssumeRole() = 0;
// Waits for the death test to finish and returns its status. // Waits for the death test to finish and returns its status.
virtual int Wait() = 0; virtual int Wait() = 0;
// Returns true if the death test passed; that is, the test process // Returns true if the death test passed; that is, the test process
// exited during the test, its exit status matches a user-supplied // exited during the test, its exit status matches a user-supplied
// predicate, and its stderr output matches a user-supplied regular // predicate, and its stderr output matches a user-supplied regular
skipping to change at line 152 skipping to change at line 158
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.
GTEST_API_ bool ExitedUnsuccessfully(int exit_status); GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
// Traps C++ exceptions escaping statement and reports them as test
// failures. Note that trapping SEH exceptions is not implemented here.
# if GTEST_HAS_EXCEPTIONS
# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} catch (const ::std::exception& gtest_exception) { \
fprintf(\
stderr, \
"\n%s: Caught std::exception-derived exception escaping the " \
"death test statement. Exception message: %s\n", \
::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str()
, \
gtest_exception.what()); \
fflush(stderr); \
death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION)
; \
} catch (...) { \
death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION)
; \
}
# else
# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
# endif
// 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)) { \
goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
} \ } \
if (gtest_dt != NULL) { \ if (gtest_dt != NULL) { \
::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \ ::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \
gtest_dt_ptr(gtest_dt); \ gtest_dt_ptr(gtest_dt); \
switch (gtest_dt->AssumeRole()) { \ switch (gtest_dt->AssumeRole()) { \
case ::testing::internal::DeathTest::OVERSEE_TEST: \ case ::testing::internal::DeathTest::OVERSEE_TEST: \
if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \ if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \
goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
} \ } \
break; \ break; \
case ::testing::internal::DeathTest::EXECUTE_TEST: { \ case ::testing::internal::DeathTest::EXECUTE_TEST: { \
::testing::internal::DeathTest::ReturnSentinel \ ::testing::internal::DeathTest::ReturnSentinel \
gtest_sentinel(gtest_dt); \ gtest_sentinel(gtest_dt); \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE) ; \ gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE) ; \
break; \ break; \
} \ } \
default: \
break; \
} \ } \
} \ } \
} else \ } else \
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
skipping to change at line 257 skipping to change at line 290
// compile inside functions where ASSERT_DEATH doesn't // compile inside functions where ASSERT_DEATH doesn't
// compile. // compile.
// //
// The branch that has an always false condition is used to ensure that // The branch that has an always false condition is used to ensure that
// statement and regex are compiled (and thus syntactically correct) but // statement and regex are compiled (and thus syntactically correct) but
// never executed. The unreachable code macro protects the terminator // never executed. The unreachable code macro protects the terminator
// statement from generating an 'unreachable code' warning in case // statement from generating an 'unreachable code' warning in case
// statement unconditionally returns or throws. The Message constructor at // statement unconditionally returns or throws. The Message constructor at
// the end allows the syntax of streaming additional messages into the // the end allows the syntax of streaming additional messages into the
// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH. // macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
#define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \ # define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::AlwaysTrue()) { \ if (::testing::internal::AlwaysTrue()) { \
GTEST_LOG_(WARNING) \ GTEST_LOG_(WARNING) \
<< "Death tests are not supported on this platform.\n" \ << "Death tests are not supported on this platform.\n" \
<< "Statement '" #statement "' cannot be verified."; \ << "Statement '" #statement "' cannot be verified."; \
} else if (::testing::internal::AlwaysFalse()) { \ } else if (::testing::internal::AlwaysFalse()) { \
::testing::internal::RE::PartialMatch(".*", (regex)); \ ::testing::internal::RE::PartialMatch(".*", (regex)); \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
terminator; \ terminator; \
} else \ } else \
 End of changes. 7 change blocks. 
6 lines changed or deleted 42 lines changed or added


 gtest-death-test.h   gtest-death-test.h 
skipping to change at line 41 skipping to change at line 41
// //
// The Google C++ Testing Framework (Google Test) // The Google C++ Testing Framework (Google Test)
// //
// This header file defines the public API for death tests. It is // This header file defines the public API for death tests. It is
// #included by gtest.h so a user doesn't need to include this // #included by gtest.h so a user doesn't need to include this
// directly. // directly.
#ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ #ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
#define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ #define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
#include <gtest/internal/gtest-death-test-internal.h> #include "gtest/internal/gtest-death-test-internal.h"
namespace testing { namespace testing {
// This flag controls the style of death tests. Valid values are "threadsa fe", // This flag controls the style of death tests. Valid values are "threadsa fe",
// meaning that the death test child process will re-execute the test binar y // meaning that the death test child process will re-execute the test binar y
// from the start, running only a single death test, or "fast", // from the start, running only a single death test, or "fast",
// meaning that the child process will execute the test logic immediately // meaning that the child process will execute the test logic immediately
// after forking. // after forking.
GTEST_DECLARE_string_(death_test_style); GTEST_DECLARE_string_(death_test_style);
skipping to change at line 157 skipping to change at line 157
// path separator (e.g. path/to/foo_test and // path separator (e.g. path/to/foo_test and
// /absolute/path/to/bar_test are fine, but foo_test is not). This // /absolute/path/to/bar_test are fine, but foo_test is not). This
// is rarely a problem as people usually don't put the test binary // is rarely a problem as people usually don't put the test binary
// directory in PATH. // directory in PATH.
// //
// TODO(wan@google.com): make thread-safe death tests search the PATH. // TODO(wan@google.com): make thread-safe death tests search the PATH.
// Asserts that a given statement causes the program to exit, with an // Asserts that a given statement causes the program to exit, with an
// integer exit status that satisfies predicate, and emitting error output // integer exit status that satisfies predicate, and emitting error output
// that matches regex. // that matches regex.
#define ASSERT_EXIT(statement, predicate, regex) \ # define ASSERT_EXIT(statement, predicate, regex) \
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_) GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)
// Like ASSERT_EXIT, but continues on to successive tests in the // Like ASSERT_EXIT, but continues on to successive tests in the
// test case, if any: // test case, if any:
#define EXPECT_EXIT(statement, predicate, regex) \ # define EXPECT_EXIT(statement, predicate, regex) \
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_) GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)
// Asserts that a given statement causes the program to exit, either by // Asserts that a given statement causes the program to exit, either by
// explicitly exiting with a nonzero exit code or being killed by a // explicitly exiting with a nonzero exit code or being killed by a
// signal, and emitting error output that matches regex. // signal, and emitting error output that matches regex.
#define ASSERT_DEATH(statement, regex) \ # define ASSERT_DEATH(statement, regex) \
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 GTEST_API_ 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 GTEST_API_ 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,
// since the sideeffects of the call are only visible in opt mode, and not // since the sideeffects of the call are only visible in opt mode, and not
// in debug mode. // in debug mode.
// //
// In practice, this can be used to test functions that utilize the // In practice, this can be used to test functions that utilize the
// LOG(DFATAL) macro using the following style: // LOG(DFATAL) macro using the following style:
// //
// int DieInDebugOr12(int* sideeffect) { // int DieInDebugOr12(int* sideeffect) {
skipping to change at line 245 skipping to change at line 245
// need to test that a function has appropriate side-effects in opt // need to test that a function has appropriate side-effects in opt
// mode, include assertions against the side-effects. A general // mode, include assertions against the side-effects. A general
// pattern for this is: // pattern for this is:
// //
// EXPECT_DEBUG_DEATH({ // EXPECT_DEBUG_DEATH({
// // Side-effects here will have an effect after this statement in // // Side-effects here will have an effect after this statement in
// // opt mode, but none in debug mode. // // opt mode, but none in debug mode.
// EXPECT_EQ(12, DieInDebugOr12(&sideeffect)); // EXPECT_EQ(12, DieInDebugOr12(&sideeffect));
// }, "death"); // }, "death");
// //
#ifdef NDEBUG # ifdef NDEBUG
#define EXPECT_DEBUG_DEATH(statement, regex) \ # define EXPECT_DEBUG_DEATH(statement, regex) \
do { statement; } while (::testing::internal::AlwaysFalse()) do { statement; } while (::testing::internal::AlwaysFalse())
#define ASSERT_DEBUG_DEATH(statement, regex) \ # define ASSERT_DEBUG_DEATH(statement, regex) \
do { statement; } while (::testing::internal::AlwaysFalse()) do { statement; } while (::testing::internal::AlwaysFalse())
#else # else
#define EXPECT_DEBUG_DEATH(statement, regex) \ # define EXPECT_DEBUG_DEATH(statement, regex) \
EXPECT_DEATH(statement, regex) EXPECT_DEATH(statement, regex)
#define ASSERT_DEBUG_DEATH(statement, regex) \ # define ASSERT_DEBUG_DEATH(statement, regex) \
ASSERT_DEATH(statement, regex) ASSERT_DEATH(statement, regex)
#endif // NDEBUG for EXPECT_DEBUG_DEATH # endif // NDEBUG for EXPECT_DEBUG_DEATH
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
// EXPECT_DEATH_IF_SUPPORTED(statement, regex) and // EXPECT_DEATH_IF_SUPPORTED(statement, regex) and
// ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests i f // ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests i f
// death tests are supported; otherwise they just issue a warning. This is // death tests are supported; otherwise they just issue a warning. This is
// useful when you are combining death test assertions with normal test // useful when you are combining death test assertions with normal test
// assertions in one test. // assertions in one test.
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ # define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
EXPECT_DEATH(statement, regex) EXPECT_DEATH(statement, regex)
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ # define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
ASSERT_DEATH(statement, regex) ASSERT_DEATH(statement, regex)
#else #else
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ # define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, ) GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, )
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ # define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, return) GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, return)
#endif #endif
} // namespace testing } // namespace testing
#endif // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ #endif // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
 End of changes. 18 change blocks. 
22 lines changed or deleted 24 lines changed or added


 gtest-filepath.h   gtest-filepath.h 
skipping to change at line 43 skipping to change at line 43
// //
// This header file declares classes and functions used internally by // This header file declares classes and functions used internally by
// Google Test. They are subject to change without notice. // Google Test. They are subject to change without notice.
// //
// This file is #included in <gtest/internal/gtest-internal.h>. // This file is #included in <gtest/internal/gtest-internal.h>.
// Do not include this header file separately! // Do not include this header file separately!
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
#include <gtest/internal/gtest-string.h> #include "gtest/internal/gtest-string.h"
namespace testing { namespace testing {
namespace internal { namespace internal {
// FilePath - a class for file and directory pathname manipulation which // FilePath - a class for file and directory pathname manipulation which
// 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
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 gtest-internal.h   gtest-internal.h 
skipping to change at line 40 skipping to change at line 40
// Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee) // Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
// //
// The Google C++ Testing Framework (Google Test) // The Google C++ Testing Framework (Google Test)
// //
// This header file declares functions and macros used internally by // This header file declares functions and macros used internally by
// Google Test. They are subject to change without notice. // Google Test. They are subject to change without notice.
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
#include <gtest/internal/gtest-port.h> #include "gtest/internal/gtest-port.h"
#if GTEST_OS_LINUX #if GTEST_OS_LINUX
#include <stdlib.h> # include <stdlib.h>
#include <sys/types.h> # include <sys/types.h>
#include <sys/wait.h> # include <sys/wait.h>
#include <unistd.h> # include <unistd.h>
#endif // GTEST_OS_LINUX #endif // GTEST_OS_LINUX
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <iomanip> #include <iomanip>
#include <limits> #include <limits>
#include <set> #include <set>
#include <gtest/internal/gtest-string.h> #include "gtest/internal/gtest-string.h"
#include <gtest/internal/gtest-filepath.h> #include "gtest/internal/gtest-filepath.h"
#include <gtest/internal/gtest-type-util.h> #include "gtest/internal/gtest-type-util.h"
// Due to C++ preprocessor weirdness, we need double indirection to // Due to C++ preprocessor weirdness, we need double indirection to
// concatenate two tokens when one of them is __LINE__. Writing // concatenate two tokens when one of them is __LINE__. Writing
// //
// foo ## __LINE__ // foo ## __LINE__
// //
// will result in the token foo__LINE__, instead of foo followed by // will result in the token foo__LINE__, instead of foo followed by
// the current line number. For more details, see // the current line number. For more details, see
// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39. 6 // http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39. 6
#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar) #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
skipping to change at line 100 skipping to change at line 100
// //
// Note: Jeffrey Yasskin suggested an alternative fix by "using // Note: Jeffrey Yasskin suggested an alternative fix by "using
// ::operator<<;" in the definition of Message's operator<<. That fix // ::operator<<;" in the definition of Message's operator<<. That fix
// doesn't require a helper function, but unfortunately doesn't // doesn't require a helper function, but unfortunately doesn't
// compile with MSVC. // compile with MSVC.
template <typename T> template <typename T>
inline void GTestStreamToHelper(std::ostream* os, const T& val) { inline void GTestStreamToHelper(std::ostream* os, const T& val) {
*os << val; *os << val;
} }
class ProtocolMessage;
namespace proto2 { class Message; }
namespace testing { namespace testing {
// Forward declaration of classes. // Forward declarations.
class AssertionResult; // Result of an assertion. class AssertionResult; // Result of an assertion.
class Message; // Represents a failure message. class Message; // Represents a failure message.
class Test; // Represents a test. class Test; // Represents a test.
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.
template <typename T>
::std::string PrintToString(const T& value);
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
// 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;
skipping to change at line 153 skipping to change at line 159
// 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_POD_ #ifdef GTEST_ELLIPSIS_NEEDS_POD_
// We lose support for NULL detection where the compiler doesn't like // We lose support for NULL detection where the compiler doesn't like
// passing non-POD classes through ellipsis (...). // passing non-POD classes through ellipsis (...).
#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_POD_ #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.
GTEST_API_ 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 GTEST_API_ ScopedTrace { class GTEST_API_ ScopedTrace {
public: public:
skipping to change at line 192 skipping to change at line 198
// 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>
String StreamableToString(const T& streamable); String StreamableToString(const T& streamable);
// Formats a value to be used in a failure message. // The Symbian compiler has a bug that prevents it from selecting the
// correct overload of FormatForComparisonFailureMessage (see below)
#ifdef GTEST_NEEDS_IS_POINTER_ // unless we pass the first argument by reference. If we do that,
// however, Visual Age C++ 10.1 generates a compiler error. Therefore
// These are needed as the Nokia Symbian and IBM XL C/C++ compilers // we only apply the work-around for Symbian.
// cannot decide between const T& and const T* in a function template. #if defined(__SYMBIAN32__)
// These compilers _can_ decide between class template specializations # define GTEST_CREF_WORKAROUND_ const&
// for T and T*, so a tr1::type_traits-like is_pointer works, and we
// can overload on that.
// This overload makes sure that all pointers (including
// those to char or wchar_t) are printed as raw pointers.
template <typename T>
inline String FormatValueForFailureMessage(internal::true_type /*dummy*/,
T* pointer) {
return StreamableToString(static_cast<const void*>(pointer));
}
template <typename T>
inline String FormatValueForFailureMessage(internal::false_type /*dummy*/,
const T& value) {
return StreamableToString(value);
}
template <typename T>
inline String FormatForFailureMessage(const T& value) {
return FormatValueForFailureMessage(
typename internal::is_pointer<T>::type(), value);
}
#else #else
# define GTEST_CREF_WORKAROUND_
#endif
// These are needed as the above solution using is_pointer has the // When this operand is a const char* or char*, if the other operand
// limitation that T cannot be a type without external linkage, when
// compiled using MSVC.
template <typename T>
inline String FormatForFailureMessage(const T& value) {
return StreamableToString(value);
}
// This overload makes sure that all pointers (including
// those to char or wchar_t) are printed as raw pointers.
template <typename T>
inline String FormatForFailureMessage(T* pointer) {
return StreamableToString(static_cast<const void*>(pointer));
}
#endif // GTEST_NEEDS_IS_POINTER_
// These overloaded versions handle narrow and wide characters.
GTEST_API_ String FormatForFailureMessage(char ch);
GTEST_API_ String FormatForFailureMessage(wchar_t wchar);
// 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); otherwise
// we print it as a pointer to be safe.
// 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* GTEST_CREF_WORKAROUND_ 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* GTEST_CREF_WORKAROUND_ str, \
) {\ const operand2_type& /*operand2*/) {\
return operand1_printer(str);\ return operand1_printer(str);\
} }
GTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted) GTEST_FORMAT_IMPL_(::std::string, String::ShowCStringQuoted)
#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
#undef GTEST_FORMAT_IMPL_ #undef GTEST_FORMAT_IMPL_
// The next four overloads handle the case where the operand being
// printed is a char/wchar_t pointer and the other operand is not a
// string/wstring object. In such cases, we just print the operand as
// a pointer to be safe.
#define GTEST_FORMAT_CHAR_PTR_IMPL_(CharType) \
template <typename T> \
String FormatForComparisonFailureMessage(CharType* GTEST_CREF_WORKAROUND_
p, \
const T&) { \
return PrintToString(static_cast<const void*>(p)); \
}
GTEST_FORMAT_CHAR_PTR_IMPL_(char)
GTEST_FORMAT_CHAR_PTR_IMPL_(const char)
GTEST_FORMAT_CHAR_PTR_IMPL_(wchar_t)
GTEST_FORMAT_CHAR_PTR_IMPL_(const wchar_t)
#undef GTEST_FORMAT_CHAR_PTR_IMPL_
// Constructs and returns the message for an equality assertion // Constructs and returns the message for an equality assertion
// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
// //
// The first four parameters are the expressions used in the assertion // The first four parameters are the expressions used in the assertion
// and their values, as strings. For example, for ASSERT_EQ(foo, bar) // and their values, as strings. For example, for ASSERT_EQ(foo, bar)
// 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"
skipping to change at line 561 skipping to change at line 545
// {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.
GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr, GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr,
long hr); // NOLINT long hr); // NOLINT
GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr, GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
long hr); // NOLINT long hr); // NOLINT
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
// Formats a source file path and a line number as they would appear
// in a compiler error message.
inline String FormatFileLocation(const char* file, int line) {
const char* const file_name = file == NULL ? "unknown file" : file;
if (line < 0) {
return String::Format("%s:", file_name);
}
#ifdef _MSC_VER
return String::Format("%s(%d):", file_name, line);
#else
return String::Format("%s:%d:", file_name, line);
#endif // _MSC_VER
}
// Types of SetUpTestCase() and TearDownTestCase() functions. // Types of SetUpTestCase() and TearDownTestCase() functions.
typedef void (*SetUpTestCaseFunc)(); typedef void (*SetUpTestCaseFunc)();
typedef void (*TearDownTestCaseFunc)(); typedef void (*TearDownTestCaseFunc)();
// Creates a new TestInfo object and registers it with Google Test; // Creates a new TestInfo object and registers it with Google Test;
// returns the created object. // returns the created object.
// //
// Arguments: // Arguments:
// //
// test_case_name: name of the test case // test_case_name: name of the test case
// name: name of the test // name: name of the test
// test_case_comment: a comment on the test case that will be included in // type_param the name of the test's type parameter, or NULL if
// the test output // this is not a typed or a type-parameterized test.
// comment: a comment on the test that will be included in the // value_param text representation of the test's value parameter,
// test output // or NULL if this is not a type-parameterized test.
// 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.
GTEST_API_ 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* type_param,
const char* value_param,
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 // If *pstr starts with the given prefix, modifies *pstr to be right
// past the prefix and returns true; otherwise leaves *pstr unchanged // past the prefix and returns true; otherwise leaves *pstr unchanged
// and returns false. None of pstr, *pstr, and prefix can be NULL. // and returns false. None of pstr, *pstr, and prefix can be NULL.
bool SkipPrefix(const char* prefix, const char** pstr); GTEST_API_ 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 GTEST_API_ 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
skipping to change at line 650 skipping to change at line 621
::std::set<const char*> defined_test_names_; ::std::set<const char*> defined_test_names_;
}; };
// Skips to the first non-space char after the first comma in 'str'; // Skips to the first non-space char after the first comma in 'str';
// returns NULL if no comma is found in 'str'. // returns NULL if no comma is found in 'str'.
inline const char* SkipComma(const char* str) { inline const char* SkipComma(const char* str) {
const char* comma = strchr(str, ','); const char* comma = strchr(str, ',');
if (comma == NULL) { if (comma == NULL) {
return NULL; return NULL;
} }
while (isspace(*(++comma))) {} while (IsSpace(*(++comma))) {}
return comma; return comma;
} }
// Returns the prefix of 'str' before the first comma in it; returns // Returns the prefix of 'str' before the first comma in it; returns
// the entire string if it contains no comma. // the entire string if it contains no comma.
inline String GetPrefixUntilComma(const char* str) { inline String GetPrefixUntilComma(const char* str) {
const char* comma = strchr(str, ','); const char* comma = strchr(str, ',');
return comma == NULL ? String(str) : String(str, comma - str); return comma == NULL ? String(str) : String(str, comma - str);
} }
skipping to change at line 687 skipping to change at line 658
typedef typename Types::Head Type; typedef typename Types::Head Type;
typedef Fixture<Type> FixtureClass; typedef Fixture<Type> FixtureClass;
typedef typename GTEST_BIND_(TestSel, Type) TestClass; typedef typename GTEST_BIND_(TestSel, Type) TestClass;
// First, registers the first type-parameterized test in the type // First, registers the first type-parameterized test in the type
// list. // list.
MakeAndRegisterTestInfo( MakeAndRegisterTestInfo(
String::Format("%s%s%s/%d", prefix, prefix[0] == '\0' ? "" : "/", String::Format("%s%s%s/%d", prefix, prefix[0] == '\0' ? "" : "/",
case_name, index).c_str(), case_name, index).c_str(),
GetPrefixUntilComma(test_names).c_str(), GetPrefixUntilComma(test_names).c_str(),
String::Format("TypeParam = %s", GetTypeName<Type>().c_str()).c_str GetTypeName<Type>().c_str(),
(), NULL, // No value parameter.
"",
GetTypeId<FixtureClass>(), GetTypeId<FixtureClass>(),
TestClass::SetUpTestCase, TestClass::SetUpTestCase,
TestClass::TearDownTestCase, TestClass::TearDownTestCase,
new TestFactoryImpl<TestClass>); new TestFactoryImpl<TestClass>);
// Next, recurses (at compile time) with the tail of the type list. // Next, recurses (at compile time) with the tail of the type list.
return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail> return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
::Register(prefix, case_name, test_names, index + 1); ::Register(prefix, case_name, test_names, index + 1);
} }
}; };
skipping to change at line 765 skipping to change at line 736
// 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.
GTEST_API_ bool AlwaysTrue(); GTEST_API_ bool AlwaysTrue();
// Always returns false. // Always returns false.
inline bool AlwaysFalse() { return !AlwaysTrue(); } inline bool AlwaysFalse() { return !AlwaysTrue(); }
// Helper for suppressing false warning from Clang on a const char*
// variable declared in a conditional expression always being NULL in
// the else branch.
struct GTEST_API_ ConstCharPtr {
ConstCharPtr(const char* str) : value(str) {}
operator bool() const { return true; }
const char* value;
};
// 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 GTEST_API_ 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) {}
skipping to change at line 787 skipping to change at line 767
// 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);
private: private:
UInt32 state_; UInt32 state_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(Random); GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
}; };
// Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
// compiler error iff T1 and T2 are different types.
template <typename T1, typename T2>
struct CompileAssertTypesEqual;
template <typename T>
struct CompileAssertTypesEqual<T, T> {
};
// Removes the reference from a type if it is a reference type,
// otherwise leaves it unchanged. This is the same as
// tr1::remove_reference, which is not widely available yet.
template <typename T>
struct RemoveReference { typedef T type; }; // NOLINT
template <typename T>
struct RemoveReference<T&> { typedef T type; }; // NOLINT
// A handy wrapper around RemoveReference that works when the argument
// T depends on template parameters.
#define GTEST_REMOVE_REFERENCE_(T) \
typename ::testing::internal::RemoveReference<T>::type
// Removes const from a type if it is a const type, otherwise leaves
// it unchanged. This is the same as tr1::remove_const, which is not
// widely available yet.
template <typename T>
struct RemoveConst { typedef T type; }; // NOLINT
template <typename T>
struct RemoveConst<const T> { typedef T type; }; // NOLINT
// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above
// definition to fail to remove the const in 'const int[3]' and 'const
// char[3][4]'. The following specialization works around the bug.
// However, it causes trouble with GCC and thus needs to be
// conditionally compiled.
#if defined(_MSC_VER) || defined(__SUNPRO_CC) || defined(__IBMCPP__)
template <typename T, size_t N>
struct RemoveConst<const T[N]> {
typedef typename RemoveConst<T>::type type[N];
};
#endif
// A handy wrapper around RemoveConst that works when the argument
// T depends on template parameters.
#define GTEST_REMOVE_CONST_(T) \
typename ::testing::internal::RemoveConst<T>::type
// Turns const U&, U&, const U, and U all into U.
#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
// Adds reference to a type if it is not a reference type,
// otherwise leaves it unchanged. This is the same as
// tr1::add_reference, which is not widely available yet.
template <typename T>
struct AddReference { typedef T& type; }; // NOLINT
template <typename T>
struct AddReference<T&> { typedef T& type; }; // NOLINT
// A handy wrapper around AddReference that works when the argument T
// depends on template parameters.
#define GTEST_ADD_REFERENCE_(T) \
typename ::testing::internal::AddReference<T>::type
// Adds a reference to const on top of T as necessary. For example,
// it transforms
//
// char ==> const char&
// const char ==> const char&
// char& ==> const char&
// const char& ==> const char&
//
// The argument T must depend on some template parameters.
#define GTEST_REFERENCE_TO_CONST_(T) \
GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))
// ImplicitlyConvertible<From, To>::value is a compile-time bool
// constant that's true iff type From can be implicitly converted to
// type To.
template <typename From, typename To>
class ImplicitlyConvertible {
private:
// We need the following helper functions only for their types.
// They have no implementations.
// MakeFrom() is an expression whose type is From. We cannot simply
// use From(), as the type From may not have a public default
// constructor.
static From MakeFrom();
// These two functions are overloaded. Given an expression
// Helper(x), the compiler will pick the first version if x can be
// implicitly converted to type To; otherwise it will pick the
// second version.
//
// The first version returns a value of size 1, and the second
// version returns a value of size 2. Therefore, by checking the
// size of Helper(x), which can be done at compile time, we can tell
// which version of Helper() is used, and hence whether x can be
// implicitly converted to type To.
static char Helper(To);
static char (&Helper(...))[2]; // NOLINT
// We have to put the 'public' section after the 'private' section,
// or MSVC refuses to compile the code.
public:
// MSVC warns about implicitly converting from double to int for
// possible loss of data, so we need to temporarily disable the
// warning.
#ifdef _MSC_VER
# pragma warning(push) // Saves the current warning state.
# pragma warning(disable:4244) // Temporarily disables warning 4244.
static const bool value =
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
# pragma warning(pop) // Restores the warning state.
#elif defined(__BORLANDC__)
// C++Builder cannot use member overload resolution during template
// instantiation. The simplest workaround is to use its C++0x type trait
s
// functions (C++Builder 2009 and above only).
static const bool value = __is_convertible(From, To);
#else
static const bool value =
sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
#endif // _MSV_VER
};
template <typename From, typename To>
const bool ImplicitlyConvertible<From, To>::value;
// IsAProtocolMessage<T>::value is a compile-time bool constant that's
// true iff T is type ProtocolMessage, proto2::Message, or a subclass
// of those.
template <typename T>
struct IsAProtocolMessage
: public bool_constant<
ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||
ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {
};
// When the compiler sees expression IsContainerTest<C>(0), if C is an
// STL-style container class, the first overload of IsContainerTest
// will be viable (since both C::iterator* and C::const_iterator* are
// valid types and NULL can be implicitly converted to them). It will
// be picked over the second overload as 'int' is a perfect match for
// the type of argument 0. If C::iterator or C::const_iterator is not
// a valid type, the first overload is not viable, and the second
// overload will be picked. Therefore, we can determine whether C is
// a container class by checking the type of IsContainerTest<C>(0).
// The value of the expression is insignificant.
//
// Note that we look for both C::iterator and C::const_iterator. The
// reason is that C++ injects the name of a class as a member of the
// class itself (e.g. you can refer to class iterator as either
// 'iterator' or 'iterator::iterator'). If we look for C::iterator
// only, for example, we would mistakenly think that a class named
// iterator is an STL container.
//
// Also note that the simpler approach of overloading
// IsContainerTest(typename C::const_iterator*) and
// IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++.
typedef int IsContainer;
template <class C>
IsContainer IsContainerTest(int /* dummy */,
typename C::iterator* /* it */ = NULL,
typename C::const_iterator* /* const_it */ = NU
LL) {
return 0;
}
typedef char IsNotContainer;
template <class C>
IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; }
// EnableIf<condition>::type is void when 'Cond' is true, and
// undefined when 'Cond' is false. To use SFINAE to make a function
// overload only apply when a particular expression is true, add
// "typename EnableIf<expression>::type* = 0" as the last parameter.
template<bool> struct EnableIf;
template<> struct EnableIf<true> { typedef void type; }; // NOLINT
// Utilities for native arrays.
// ArrayEq() compares two k-dimensional native arrays using the
// elements' operator==, where k can be any integer >= 0. When k is
// 0, ArrayEq() degenerates into comparing a single pair of values.
template <typename T, typename U>
bool ArrayEq(const T* lhs, size_t size, const U* rhs);
// This generic version is used when k is 0.
template <typename T, typename U>
inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; }
// This overload is used when k >= 1.
template <typename T, typename U, size_t N>
inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) {
return internal::ArrayEq(lhs, N, rhs);
}
// This helper reduces code bloat. If we instead put its logic inside
// the previous ArrayEq() function, arrays with different sizes would
// lead to different copies of the template code.
template <typename T, typename U>
bool ArrayEq(const T* lhs, size_t size, const U* rhs) {
for (size_t i = 0; i != size; i++) {
if (!internal::ArrayEq(lhs[i], rhs[i]))
return false;
}
return true;
}
// Finds the first element in the iterator range [begin, end) that
// equals elem. Element may be a native array type itself.
template <typename Iter, typename Element>
Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) {
for (Iter it = begin; it != end; ++it) {
if (internal::ArrayEq(*it, elem))
return it;
}
return end;
}
// CopyArray() copies a k-dimensional native array using the elements'
// operator=, where k can be any integer >= 0. When k is 0,
// CopyArray() degenerates into copying a single value.
template <typename T, typename U>
void CopyArray(const T* from, size_t size, U* to);
// This generic version is used when k is 0.
template <typename T, typename U>
inline void CopyArray(const T& from, U* to) { *to = from; }
// This overload is used when k >= 1.
template <typename T, typename U, size_t N>
inline void CopyArray(const T(&from)[N], U(*to)[N]) {
internal::CopyArray(from, N, *to);
}
// This helper reduces code bloat. If we instead put its logic inside
// the previous CopyArray() function, arrays with different sizes
// would lead to different copies of the template code.
template <typename T, typename U>
void CopyArray(const T* from, size_t size, U* to) {
for (size_t i = 0; i != size; i++) {
internal::CopyArray(from[i], to + i);
}
}
// The relation between an NativeArray object (see below) and the
// native array it represents.
enum RelationToSource {
kReference, // The NativeArray references the native array.
kCopy // The NativeArray makes a copy of the native array and
// owns the copy.
};
// Adapts a native array to a read-only STL-style container. Instead
// of the complete STL container concept, this adaptor only implements
// members useful for Google Mock's container matchers. New members
// should be added as needed. To simplify the implementation, we only
// support Element being a raw type (i.e. having no top-level const or
// reference modifier). It's the client's responsibility to satisfy
// this requirement. Element can be an array type itself (hence
// multi-dimensional arrays are supported).
template <typename Element>
class NativeArray {
public:
// STL-style container typedefs.
typedef Element value_type;
typedef Element* iterator;
typedef const Element* const_iterator;
// Constructs from a native array.
NativeArray(const Element* array, size_t count, RelationToSource relation
) {
Init(array, count, relation);
}
// Copy constructor.
NativeArray(const NativeArray& rhs) {
Init(rhs.array_, rhs.size_, rhs.relation_to_source_);
}
~NativeArray() {
// Ensures that the user doesn't instantiate NativeArray with a
// const or reference type.
static_cast<void>(StaticAssertTypeEqHelper<Element,
GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>());
if (relation_to_source_ == kCopy)
delete[] array_;
}
// STL-style container methods.
size_t size() const { return size_; }
const_iterator begin() const { return array_; }
const_iterator end() const { return array_ + size_; }
bool operator==(const NativeArray& rhs) const {
return size() == rhs.size() &&
ArrayEq(begin(), size(), rhs.begin());
}
private:
// Initializes this object; makes a copy of the input array if
// 'relation' is kCopy.
void Init(const Element* array, size_t a_size, RelationToSource relation)
{
if (relation == kReference) {
array_ = array;
} else {
Element* const copy = new Element[a_size];
CopyArray(array, a_size, copy);
array_ = copy;
}
size_ = a_size;
relation_to_source_ = relation;
}
const Element* array_;
size_t size_;
RelationToSource relation_to_source_;
GTEST_DISALLOW_ASSIGN_(NativeArray);
};
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
#define GTEST_MESSAGE_(message, result_type) \ #define GTEST_MESSAGE_AT_(file, line, message, result_type) \
::testing::internal::AssertHelper(result_type, __FILE__, __LINE__, messag ::testing::internal::AssertHelper(result_type, file, line, message) \
e) \
= ::testing::Message() = ::testing::Message()
#define GTEST_MESSAGE_(message, result_type) \
GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
#define GTEST_FATAL_FAILURE_(message) \ #define GTEST_FATAL_FAILURE_(message) \
return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure) return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
#define GTEST_NONFATAL_FAILURE_(message) \ #define GTEST_NONFATAL_FAILURE_(message) \
GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure) GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
#define GTEST_SUCCESS_(message) \ #define GTEST_SUCCESS_(message) \
GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess) GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
// Suppresses MSVC warnings 4072 (unreachable code) for the code following // Suppresses MSVC warnings 4072 (unreachable code) for the code following
// statement if it returns or throws (or doesn't return or throw in some // statement if it returns or throws (or doesn't return or throw in some
// situations). // situations).
#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \ #define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
if (::testing::internal::AlwaysTrue()) { statement; } if (::testing::internal::AlwaysTrue()) { statement; }
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \ #define GTEST_TEST_THROW_(statement, expected_exception, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const char* gtest_msg = "") { \ if (::testing::internal::ConstCharPtr gtest_msg = "") { \
bool gtest_caught_expected = false; \ bool gtest_caught_expected = false; \
try { \ try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \ } \
catch (expected_exception const&) { \ catch (expected_exception const&) { \
gtest_caught_expected = true; \ gtest_caught_expected = true; \
} \ } \
catch (...) { \ catch (...) { \
gtest_msg = "Expected: " #statement " throws an exception of type " \ gtest_msg.value = \
#expected_exception ".\n Actual: it throws a different " "Expected: " #statement " throws an exception of type " \
\ #expected_exception ".\n Actual: it throws a different type."; \
"type."; \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
} \ } \
if (!gtest_caught_expected) { \ if (!gtest_caught_expected) { \
gtest_msg = "Expected: " #statement " throws an exception of type " \ gtest_msg.value = \
#expected_exception ".\n Actual: it throws nothing."; \ "Expected: " #statement " throws an exception of type " \
#expected_exception ".\n Actual: it throws nothing."; \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
} \ } \
} else \ } else \
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
fail(gtest_msg) fail(gtest_msg.value)
#define GTEST_TEST_NO_THROW_(statement, fail) \ #define GTEST_TEST_NO_THROW_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const char* gtest_msg = "") { \ if (::testing::internal::AlwaysTrue()) { \
try { \ try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \ } \
catch (...) { \ catch (...) { \
gtest_msg = "Expected: " #statement " doesn't throw an exception.\n"
\
" Actual: it throws."; \
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
} \ } \
} else \ } else \
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
fail(gtest_msg) fail("Expected: " #statement " doesn't throw an exception.\n" \
" Actual: it throws.")
#define GTEST_TEST_ANY_THROW_(statement, fail) \ #define GTEST_TEST_ANY_THROW_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const char* gtest_msg = "") { \ if (::testing::internal::AlwaysTrue()) { \
bool gtest_caught_any = false; \ bool gtest_caught_any = false; \
try { \ try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \ } \
catch (...) { \ catch (...) { \
gtest_caught_any = true; \ gtest_caught_any = true; \
} \ } \
if (!gtest_caught_any) { \ if (!gtest_caught_any) { \
gtest_msg = "Expected: " #statement " throws an exception.\n" \
" 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("Expected: " #statement " throws an exception.\n" \
" Actual: it doesn't.")
// Implements Boolean test assertions such as EXPECT_TRUE. expression can b e // Implements Boolean test assertions such as EXPECT_TRUE. expression can b e
// either a boolean expression or an AssertionResult. text is a textual // either a boolean expression or an AssertionResult. text is a textual
// represenation of expression as it was passed into the EXPECT_TRUE. // represenation of expression as it was passed into the EXPECT_TRUE.
#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \ #define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const ::testing::AssertionResult gtest_ar_ = \ if (const ::testing::AssertionResult gtest_ar_ = \
::testing::AssertionResult(expression)) \ ::testing::AssertionResult(expression)) \
; \ ; \
else \ else \
fail(::testing::internal::GetBoolAssertionFailureMessage(\ fail(::testing::internal::GetBoolAssertionFailureMessage(\
gtest_ar_, text, #actual, #expected).c_str()) 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 (::testing::internal::AlwaysTrue()) { \
::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 " \
"failures in the current thread.\n" \
" Actual: it does."; \
goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
} \ } \
} else \ } else \
GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \ GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
fail(gtest_msg) fail("Expected: " #statement " doesn't generate new fatal " \
"failures in the current thread.\n" \
" Actual: it does.")
// Expands to the name of the class that implements the given test. // Expands to the name of the class that implements the given test.
#define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ #define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
test_case_name##_##test_name##_Test test_case_name##_##test_name##_Test
// Helper macro for defining tests. // Helper macro for defining tests.
#define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\ #define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_cla ss {\ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_cla ss {\
public:\ public:\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
private:\ private:\
virtual void TestBody();\ virtual void TestBody();\
static ::testing::TestInfo* const test_info_;\ static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
GTEST_DISALLOW_COPY_AND_ASSIGN_(\ GTEST_DISALLOW_COPY_AND_ASSIGN_(\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
};\ };\
\ \
::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name )\ ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name )\
::test_info_ =\ ::test_info_ =\
::testing::internal::MakeAndRegisterTestInfo(\ ::testing::internal::MakeAndRegisterTestInfo(\
#test_case_name, #test_name, "", "", \ #test_case_name, #test_name, NULL, NULL, \
(parent_id), \ (parent_id), \
parent_class::SetUpTestCase, \ parent_class::SetUpTestCase, \
parent_class::TearDownTestCase, \ parent_class::TearDownTestCase, \
new ::testing::internal::TestFactoryImpl<\ new ::testing::internal::TestFactoryImpl<\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
 End of changes. 40 change blocks. 
119 lines changed or deleted 422 lines changed or added


 gtest-linked_ptr.h   gtest-linked_ptr.h 
skipping to change at line 74 skipping to change at line 74
// shared object concurrently. // shared object concurrently.
// TODO(wan@google.com): rename this to safe_linked_ptr to avoid // TODO(wan@google.com): rename this to safe_linked_ptr to avoid
// confusion with normal linked_ptr. // confusion with normal linked_ptr.
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_
#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.
GTEST_API_ GTEST_DECLARE_STATIC_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 )).
skipping to change at line 175 skipping to change at line 175
} }
// Smart pointer members. // Smart pointer members.
void reset(T* ptr = NULL) { void reset(T* ptr = NULL) {
depart(); depart();
capture(ptr); capture(ptr);
} }
T* get() const { return value_; } T* get() const { return value_; }
T* operator->() const { return value_; } T* operator->() const { return value_; }
T& operator*() const { return *value_; } T& operator*() const { return *value_; }
// Release ownership of the pointed object and returns it.
// Sole ownership by this linked_ptr object is required.
T* release() {
bool last = link_.depart();
assert(last);
T* v = value_;
value_ = NULL;
return v;
}
bool operator==(T* p) const { return value_ == p; } bool operator==(T* p) const { return value_ == p; }
bool operator!=(T* p) const { return value_ != p; } bool operator!=(T* p) const { return value_ != p; }
template <typename U> template <typename U>
bool operator==(linked_ptr<U> const& ptr) const { bool operator==(linked_ptr<U> const& ptr) const {
return value_ == ptr.get(); return value_ == ptr.get();
} }
template <typename U> template <typename U>
bool operator!=(linked_ptr<U> const& ptr) const { bool operator!=(linked_ptr<U> const& ptr) const {
return value_ != ptr.get(); return value_ != ptr.get();
 End of changes. 2 change blocks. 
10 lines changed or deleted 1 lines changed or added


 gtest-message.h   gtest-message.h 
skipping to change at line 51 skipping to change at line 51
// //
// 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 <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.
// It will remember the text in a StrStream. // It will remember the text in a stringstream.
// 2. Then you stream the Message object to an ostream. // 2. Then you stream the Message object to an ostream.
// This causes the text in the Message to be streamed // This causes the text in the Message to be streamed
// to the ostream. // to the ostream.
// //
// For example; // For example;
// //
// testing::Message foo; // testing::Message foo;
// foo << 1 << " != " << 2; // foo << 1 << " != " << 2;
// std::cout << foo; // std::cout << foo;
// //
// 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 stringstream 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 GTEST_API_ 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 stringstream separately because 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 ::std::stringstream) {
// By default, we want there to be enough precision when printing // By default, we want there to be enough precision when printing
// a double to a Message. // a double to a Message.
*ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2); *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 ::std::stringstream) { // 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 ::std::stringstream) {
*ss_ << str; *ss_ << str;
} }
~Message() { delete ss_; }
#if GTEST_OS_SYMBIAN #if GTEST_OS_SYMBIAN
// Streams a value (either a pointer or not) to this object. // Streams a value (either a pointer or not) to this object.
template <typename T> template <typename T>
inline Message& operator <<(const T& value) { inline Message& operator <<(const T& value) {
StreamHelper(typename internal::is_pointer<T>::type(), value); StreamHelper(typename internal::is_pointer<T>::type(), value);
return *this; return *this;
} }
#else #else
// Streams a non-pointer value to this object. // Streams a non-pointer value to this object.
template <typename T> template <typename T>
inline Message& operator <<(const T& val) { inline Message& operator <<(const T& val) {
::GTestStreamToHelper(ss_, val); ::GTestStreamToHelper(ss_.get(), val);
return *this; return *this;
} }
// Streams a pointer value to this object. // Streams a pointer value to this object.
// //
// This function is an overload of the previous one. When you // This function is an overload of the previous one. When you
// stream a pointer to a Message, this definition will be used as it // stream a pointer to a Message, this definition will be used as it
// is more specialized. (The C++ Standard, section // is more specialized. (The C++ Standard, section
// [temp.func.order].) If you stream a non-pointer, then the // [temp.func.order].) If you stream a non-pointer, then the
// previous definition will be used. // previous definition will be used.
skipping to change at line 144 skipping to change at line 143
// The reason for this overload is that streaming a NULL pointer to // The reason for this overload is that streaming a NULL pointer to
// ostream is undefined behavior. Depending on the compiler, you // ostream is undefined behavior. Depending on the compiler, you
// may get "0", "(nil)", "(null)", or an access violation. To // may get "0", "(nil)", "(null)", or an access violation. To
// ensure consistent result across compilers, we always treat NULL // ensure consistent result across compilers, we always treat NULL
// as "(null)". // as "(null)".
template <typename T> template <typename T>
inline Message& operator <<(T* const& pointer) { // NOLINT inline Message& operator <<(T* const& pointer) { // NOLINT
if (pointer == NULL) { if (pointer == NULL) {
*ss_ << "(null)"; *ss_ << "(null)";
} else { } else {
::GTestStreamToHelper(ss_, pointer); ::GTestStreamToHelper(ss_.get(), pointer);
} }
return *this; return *this;
} }
#endif // GTEST_OS_SYMBIAN #endif // GTEST_OS_SYMBIAN
// Since the basic IO manipulators are overloaded for both narrow // Since the basic IO manipulators are overloaded for both narrow
// and wide streams, we have to provide this specialized definition // and wide streams, we have to provide this specialized definition
// of operator <<, even though its body is the same as the // of operator <<, even though its body is the same as the
// templatized version above. Without this definition, streaming // templatized version above. Without this definition, streaming
// endl or other basic IO manipulators to Message will confuse the // endl or other basic IO manipulators to Message will confuse the
skipping to change at line 192 skipping to change at line 191
// Converts the given wide string to a narrow string using the UTF-8 // Converts the given wide string to a narrow string using the UTF-8
// encoding, and streams the result to this Message object. // encoding, and streams the result to this Message object.
Message& operator <<(const ::wstring& wstr); Message& operator <<(const ::wstring& wstr);
#endif // GTEST_HAS_GLOBAL_WSTRING #endif // GTEST_HAS_GLOBAL_WSTRING
// Gets the text streamed to this object so far as a String. // Gets the text streamed to this object so far as a String.
// Each '\0' character in the buffer is replaced with "\\0". // Each '\0' character in the buffer is replaced with "\\0".
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
internal::String GetString() const { internal::String GetString() const {
return internal::StrStreamToString(ss_); return internal::StringStreamToString(ss_.get());
} }
private: private:
#if GTEST_OS_SYMBIAN #if GTEST_OS_SYMBIAN
// These are needed as the Nokia Symbian Compiler cannot decide between // These are needed as the Nokia Symbian Compiler cannot decide between
// const T& and const T* in a function template. The Nokia compiler _can_ // const T& and const T* in a function template. The Nokia compiler _can_
// decide between class template specializations for T and T*, so a // decide between class template specializations for T and T*, so a
// tr1::type_traits-like is_pointer works, and we can overload on that. // tr1::type_traits-like is_pointer works, and we can overload on that.
template <typename T> template <typename T>
inline void StreamHelper(internal::true_type /*dummy*/, T* pointer) { inline void StreamHelper(internal::true_type /*dummy*/, T* pointer) {
if (pointer == NULL) { if (pointer == NULL) {
*ss_ << "(null)"; *ss_ << "(null)";
} else { } else {
skipping to change at line 206 skipping to change at line 206
#if GTEST_OS_SYMBIAN #if GTEST_OS_SYMBIAN
// These are needed as the Nokia Symbian Compiler cannot decide between // These are needed as the Nokia Symbian Compiler cannot decide between
// const T& and const T* in a function template. The Nokia compiler _can_ // const T& and const T* in a function template. The Nokia compiler _can_
// decide between class template specializations for T and T*, so a // decide between class template specializations for T and T*, so a
// tr1::type_traits-like is_pointer works, and we can overload on that. // tr1::type_traits-like is_pointer works, and we can overload on that.
template <typename T> template <typename T>
inline void StreamHelper(internal::true_type /*dummy*/, T* pointer) { inline void StreamHelper(internal::true_type /*dummy*/, T* pointer) {
if (pointer == NULL) { if (pointer == NULL) {
*ss_ << "(null)"; *ss_ << "(null)";
} else { } else {
::GTestStreamToHelper(ss_, pointer); ::GTestStreamToHelper(ss_.get(), pointer);
} }
} }
template <typename T> template <typename T>
inline void StreamHelper(internal::false_type /*dummy*/, const T& value) { inline void StreamHelper(internal::false_type /*dummy*/, const T& value) {
::GTestStreamToHelper(ss_, value); ::GTestStreamToHelper(ss_.get(), value);
} }
#endif // GTEST_OS_SYMBIAN #endif // GTEST_OS_SYMBIAN
// We'll hold the text streamed to this object here. // We'll hold the text streamed to this object here.
internal::StrStream* const ss_; const internal::scoped_ptr< ::std::stringstream> ss_;
// We declare (but don't implement) this to prevent the compiler // We declare (but don't implement) this to prevent the compiler
// from implementing the assignment operator. // from implementing the assignment operator.
void operator=(const Message&); void operator=(const Message&);
}; };
// Streams a Message to an ostream. // Streams a Message to an ostream.
inline std::ostream& operator <<(std::ostream& os, const Message& sb) { inline std::ostream& operator <<(std::ostream& os, const Message& sb) {
return os << sb.GetString(); return os << sb.GetString();
} }
 End of changes. 15 change blocks. 
15 lines changed or deleted 15 lines changed or added


 gtest-param-test.h   gtest-param-test.h 
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! // This file was GENERATED by command:
// pump.py gtest-param-test.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 50 skipping to change at line 52
#define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_ #define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
// Value-parameterized tests allow you to test your code with different // Value-parameterized tests allow you to test your code with different
// parameters without writing multiple copies of the same test. // parameters without writing multiple copies of the same test.
// //
// Here is how you use value-parameterized tests: // Here is how you use value-parameterized tests:
#if 0 #if 0
// To write value-parameterized tests, first you should define a fixture // To write value-parameterized tests, first you should define a fixture
// class. It must be derived from testing::TestWithParam<T>, where T is // class. It is usually derived from testing::TestWithParam<T> (see below f
// the type of your parameter values. TestWithParam<T> is itself derived or
// from testing::Test. T can be any copyable type. If it's a raw pointer, // another inheritance scheme that's sometimes useful in more complicated
// you are responsible for managing the lifespan of the pointed values. // class hierarchies), where the type of your parameter values.
// TestWithParam<T> is itself derived from testing::Test. T can be any
// copyable type. If it's a raw pointer, you are responsible for managing t
he
// lifespan of the pointed values.
class FooTest : public ::testing::TestWithParam<const char*> { class FooTest : public ::testing::TestWithParam<const char*> {
// You can implement all the usual class fixture members here. // You can implement all the usual class fixture members here.
}; };
// Then, use the TEST_P macro to define as many parameterized tests // Then, use the TEST_P macro to define as many parameterized tests
// for this fixture as you want. The _P suffix is for "parameterized" // for this fixture as you want. The _P suffix is for "parameterized"
// or "pattern", whichever you prefer to think. // or "pattern", whichever you prefer to think.
TEST_P(FooTest, DoesBlah) { TEST_P(FooTest, DoesBlah) {
skipping to change at line 148 skipping to change at line 152
// to dynamically determine a set of tests to run and on the other hand, // 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 // give the user a chance to inspect the generated tests with Google Test
// reflection API before RUN_ALL_TESTS() is executed. // 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.
//
//
// A parameterized test fixture must be derived from testing::Test and from
// testing::WithParamInterface<T>, where T is the type of the parameter
// values. Inheriting from TestWithParam<T> satisfies that requirement beca
use
// TestWithParam<T> inherits from both Test and WithParamInterface. In more
// complicated hierarchies, however, it is occasionally useful to inherit
// separately from Test and WithParamInterface. For example:
class BaseTest : public ::testing::Test {
// You can inherit all the usual members for a non-parameterized test
// fixture here.
};
class DerivedTest : public BaseTest, public ::testing::WithParamInterface<i
nt> {
// The usual test fixture members go here too.
};
TEST_F(BaseTest, HasFoo) {
// This is an ordinary non-parameterized test.
}
TEST_P(DerivedTest, DoesBlah) {
// GetParam works just the same here as if you inherit from TestWithParam
.
EXPECT_TRUE(foo.Blah(GetParam()));
}
#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
// scripts/fuse_gtest.py depends on gtest's own header being #included // scripts/fuse_gtest.py depends on gtest's own header being #included
// *unconditionally*. Therefore these #includes cannot be moved // *unconditionally*. Therefore these #includes cannot be moved
// inside #if GTEST_HAS_PARAM_TEST. // 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 #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
skipping to change at line 278 skipping to change at line 308
// list.push_back('b'); // list.push_back('b');
// return list; // return list;
// } // }
// ::std::list<char> l = GetParameterChars(); // ::std::list<char> l = GetParameterChars();
// INSTANTIATE_TEST_CASE_P(CharSequence2, // INSTANTIATE_TEST_CASE_P(CharSequence2,
// CharTest, // CharTest,
// ValuesIn(l.begin(), l.end())); // ValuesIn(l.begin(), l.end()));
// //
template <typename ForwardIterator> template <typename ForwardIterator>
internal::ParamGenerator< internal::ParamGenerator<
typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn( typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type
ForwardIterator begin, >
ForwardIterator end) { ValuesIn(ForwardIterator begin, ForwardIterator end) {
typedef typename ::std::iterator_traits<ForwardIterator>::value_type typedef typename ::testing::internal::IteratorTraits<ForwardIterator>
ParamType; ::value_type ParamType;
return internal::ParamGenerator<ParamType>( return internal::ParamGenerator<ParamType>(
new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end)); new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end));
} }
template <typename T, size_t N> template <typename T, size_t N>
internal::ParamGenerator<T> ValuesIn(const T (&array)[N]) { internal::ParamGenerator<T> ValuesIn(const T (&array)[N]) {
return ValuesIn(array, array + N); return ValuesIn(array, array + N);
} }
template <class Container> template <class Container>
skipping to change at line 1194 skipping to change at line 1223
// virtual void SetUp() { // virtual void SetUp() {
// external_flag = GetParam(); // external_flag = GetParam();
// } // }
// } // }
// INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool()); // INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool());
// //
inline internal::ParamGenerator<bool> Bool() { inline internal::ParamGenerator<bool> Bool() {
return Values(false, true); return Values(false, true);
} }
#if GTEST_HAS_COMBINE # if GTEST_HAS_COMBINE
// Combine() allows the user to combine two or more sequences to produce // Combine() allows the user to combine two or more sequences to produce
// values of a Cartesian product of those sequences' elements. // values of a Cartesian product of those sequences' elements.
// //
// Synopsis: // Synopsis:
// Combine(gen1, gen2, ..., genN) // Combine(gen1, gen2, ..., genN)
// - returns a generator producing sequences with elements coming from // - returns a generator producing sequences with elements coming from
// the Cartesian product of elements from the sequences generated by // the Cartesian product of elements from the sequences generated by
// gen1, gen2, ..., genN. The sequence elements will have a type of // gen1, gen2, ..., genN. The sequence elements will have a type of
// tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types // tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
// of elements from sequences produces by gen1, gen2, ..., genN. // of elements from sequences produces by gen1, gen2, ..., genN.
skipping to change at line 1346 skipping to change at line 1375
Generator10> Combine( Generator10> Combine(
const Generator1& g1, const Generator2& g2, const Generator3& g3, const Generator1& g1, const Generator2& g2, const Generator3& g3,
const Generator4& g4, const Generator5& g5, const Generator6& g6, const Generator4& g4, const Generator5& g5, const Generator6& g6,
const Generator7& g7, const Generator8& g8, const Generator9& g9, const Generator7& g7, const Generator8& g8, const Generator9& g9,
const Generator10& g10) { const Generator10& g10) {
return internal::CartesianProductHolder10<Generator1, Generator2, Generat or3, return internal::CartesianProductHolder10<Generator1, Generator2, Generat or3,
Generator4, Generator5, Generator6, Generator7, Generator8, Generator 9, Generator4, Generator5, Generator6, Generator7, Generator8, Generator 9,
Generator10>( Generator10>(
g1, g2, g3, g4, g5, g6, g7, g8, g9, g10); g1, g2, g3, g4, g5, g6, g7, g8, g9, g10);
} }
#endif // GTEST_HAS_COMBINE # endif // GTEST_HAS_COMBINE
#define TEST_P(test_case_name, test_name) \ # define TEST_P(test_case_name, test_name) \
class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
: public test_case_name { \ : public test_case_name { \
public: \ public: \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
virtual void TestBody(); \ virtual void TestBody(); \
private: \ private: \
static int AddToRegistry() { \ static int AddToRegistry() { \
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \ ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
GetTestCasePatternHolder<test_case_name>(\ GetTestCasePatternHolder<test_case_name>(\
#test_case_name, __FILE__, __LINE__)->AddTestPattern(\ #test_case_name, __FILE__, __LINE__)->AddTestPattern(\
skipping to change at line 1374 skipping to change at line 1403
} \ } \
static int gtest_registering_dummy_; \ static int gtest_registering_dummy_; \
GTEST_DISALLOW_COPY_AND_ASSIGN_(\ GTEST_DISALLOW_COPY_AND_ASSIGN_(\
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
}; \ }; \
int GTEST_TEST_CLASS_NAME_(test_case_name, \ int GTEST_TEST_CLASS_NAME_(test_case_name, \
test_name)::gtest_registering_dummy_ = \ test_name)::gtest_registering_dummy_ = \
GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \ GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody() void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
#define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \ # define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
::testing::internal::ParamGenerator<test_case_name::ParamType> \ ::testing::internal::ParamGenerator<test_case_name::ParamType> \
gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \ gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
int gtest_##prefix##test_case_name##_dummy_ = \ int gtest_##prefix##test_case_name##_dummy_ = \
::testing::UnitTest::GetInstance()->parameterized_test_registry(). \ ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
GetTestCasePatternHolder<test_case_name>(\ GetTestCasePatternHolder<test_case_name>(\
#test_case_name, __FILE__, __LINE__)->AddTestCaseInstantiatio n(\ #test_case_name, __FILE__, __LINE__)->AddTestCaseInstantiatio n(\
#prefix, \ #prefix, \
&gtest_##prefix##test_case_name##_EvalGenerator_, \ &gtest_##prefix##test_case_name##_EvalGenerator_, \
__FILE__, __LINE__) __FILE__, __LINE__)
 End of changes. 11 change blocks. 
19 lines changed or deleted 54 lines changed or added


 gtest-param-util-generated.h   gtest-param-util-generated.h 
// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! // This file was GENERATED by command:
// pump.py gtest-param-util-generated.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 50 skipping to change at line 52
// 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 // scripts/fuse_gtest.py depends on gtest's own header being #included
// *unconditionally*. Therefore these #includes cannot be moved // *unconditionally*. Therefore these #includes cannot be moved
// inside #if GTEST_HAS_PARAM_TEST. // inside #if GTEST_HAS_PARAM_TEST.
#include <gtest/internal/gtest-param-util.h> #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
namespace testing { namespace testing {
// Forward declarations of ValuesIn(), which is implemented in // Forward declarations of ValuesIn(), which is implemented in
// include/gtest/gtest-param-test.h. // include/gtest/gtest-param-test.h.
template <typename ForwardIterator> template <typename ForwardIterator>
internal::ParamGenerator< internal::ParamGenerator<
typename ::std::iterator_traits<ForwardIterator>::value_type> ValuesIn( typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type
ForwardIterator begin, ForwardIterator end); >
ValuesIn(ForwardIterator begin, ForwardIterator end);
template <typename T, size_t N> template <typename T, size_t N>
internal::ParamGenerator<T> ValuesIn(const T (&array)[N]); internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);
template <class Container> template <class Container>
internal::ParamGenerator<typename Container::value_type> ValuesIn( internal::ParamGenerator<typename Container::value_type> ValuesIn(
const Container& container); const Container& container);
namespace internal { namespace internal {
skipping to change at line 2829 skipping to change at line 2831
const T43 v43_; const T43 v43_;
const T44 v44_; const T44 v44_;
const T45 v45_; const T45 v45_;
const T46 v46_; const T46 v46_;
const T47 v47_; const T47 v47_;
const T48 v48_; const T48 v48_;
const T49 v49_; const T49 v49_;
const T50 v50_; const T50 v50_;
}; };
#if GTEST_HAS_COMBINE # if GTEST_HAS_COMBINE
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
// //
// Generates values from the Cartesian product of values produced // Generates values from the Cartesian product of values produced
// by the argument generators. // by the argument generators.
// //
template <typename T1, typename T2> template <typename T1, typename T2>
class CartesianProductGenerator2 class CartesianProductGenerator2
: public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2> > { : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2> > {
public: public:
typedef ::std::tr1::tuple<T1, T2> ParamType; typedef ::std::tr1::tuple<T1, T2> ParamType;
skipping to change at line 4804 skipping to change at line 4806
const Generator3 g3_; const Generator3 g3_;
const Generator4 g4_; const Generator4 g4_;
const Generator5 g5_; const Generator5 g5_;
const Generator6 g6_; const Generator6 g6_;
const Generator7 g7_; const Generator7 g7_;
const Generator8 g8_; const Generator8 g8_;
const Generator9 g9_; const Generator9 g9_;
const Generator10 g10_; const Generator10 g10_;
}; // class CartesianProductHolder10 }; // class CartesianProductHolder10
#endif // GTEST_HAS_COMBINE # endif // GTEST_HAS_COMBINE
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
#endif // GTEST_HAS_PARAM_TEST #endif // GTEST_HAS_PARAM_TEST
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_ #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
 End of changes. 5 change blocks. 
7 lines changed or deleted 10 lines changed or added


 gtest-param-util.h   gtest-param-util.h 
skipping to change at line 44 skipping to change at line 44
#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 // scripts/fuse_gtest.py depends on gtest's own header being #included
// *unconditionally*. Therefore these #includes cannot be moved // *unconditionally*. Therefore these #includes cannot be moved
// inside #if GTEST_HAS_PARAM_TEST. // inside #if GTEST_HAS_PARAM_TEST.
#include <gtest/internal/gtest-internal.h> #include "gtest/internal/gtest-internal.h"
#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"
#include "gtest/gtest-printers.h"
#if GTEST_HAS_PARAM_TEST #if GTEST_HAS_PARAM_TEST
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
skipping to change at line 174 skipping to change at line 175
ParamGenerator& operator=(const ParamGenerator& other) { ParamGenerator& operator=(const ParamGenerator& other) {
impl_ = other.impl_; impl_ = other.impl_;
return *this; return *this;
} }
iterator begin() const { return iterator(impl_->Begin()); } iterator begin() const { return iterator(impl_->Begin()); }
iterator end() const { return iterator(impl_->End()); } iterator end() const { return iterator(impl_->End()); }
private: private:
::testing::internal::linked_ptr<const ParamGeneratorInterface<T> > impl_; linked_ptr<const ParamGeneratorInterface<T> > impl_;
}; };
// Generates values from a range of two comparable values. Can be used to // Generates values from a range of two comparable values. Can be used to
// generate sequences of user-defined types that implement operator+() and // generate sequences of user-defined types that implement operator+() and
// operator<(). // operator<().
// This class is used in the Range() function. // This class is used in the Range() function.
template <typename T, typename IncrementT> template <typename T, typename IncrementT>
class RangeGenerator : public ParamGeneratorInterface<T> { class RangeGenerator : public ParamGeneratorInterface<T> {
public: public:
RangeGenerator(T begin, T end, IncrementT step) RangeGenerator(T begin, T end, IncrementT step)
skipping to change at line 287 skipping to change at line 288
return new Iterator(this, container_.end()); return new Iterator(this, container_.end());
} }
private: private:
typedef typename ::std::vector<T> ContainerType; typedef typename ::std::vector<T> ContainerType;
class Iterator : public ParamIteratorInterface<T> { class Iterator : public ParamIteratorInterface<T> {
public: public:
Iterator(const ParamGeneratorInterface<T>* base, Iterator(const ParamGeneratorInterface<T>* base,
typename ContainerType::const_iterator iterator) typename ContainerType::const_iterator iterator)
: base_(base), iterator_(iterator) {} : base_(base), iterator_(iterator) {}
virtual ~Iterator() {} virtual ~Iterator() {}
virtual const ParamGeneratorInterface<T>* BaseGenerator() const { virtual const ParamGeneratorInterface<T>* BaseGenerator() const {
return base_; return base_;
} }
virtual void Advance() { virtual void Advance() {
++iterator_; ++iterator_;
value_.reset(); value_.reset();
} }
virtual ParamIteratorInterface<T>* Clone() const { virtual ParamIteratorInterface<T>* Clone() const {
skipping to change at line 418 skipping to change at line 419
// and generators provided by INSTANTIATE_TEST_CASE_P macro invocations // and generators provided by INSTANTIATE_TEST_CASE_P macro invocations
// and uses that information to register all resulting test instances // and uses that information to register all resulting test instances
// in RegisterTests method. The ParameterizeTestCaseRegistry class holds // in RegisterTests method. The ParameterizeTestCaseRegistry class holds
// a collection of pointers to the ParameterizedTestCaseInfo objects // a collection of pointers to the ParameterizedTestCaseInfo objects
// and calls RegisterTests() on each of them when asked. // and calls RegisterTests() on each of them when asked.
class ParameterizedTestCaseInfoBase { class ParameterizedTestCaseInfoBase {
public: public:
virtual ~ParameterizedTestCaseInfoBase() {} virtual ~ParameterizedTestCaseInfoBase() {}
// Base part of test case name for display purposes. // Base part of test case name for display purposes.
virtual const String& GetTestCaseName() const = 0; virtual const string& GetTestCaseName() const = 0;
// Test case id to verify identity. // Test case id to verify identity.
virtual TypeId GetTestCaseTypeId() const = 0; virtual TypeId GetTestCaseTypeId() const = 0;
// UnitTest class invokes this method to register tests in this // UnitTest class invokes this method to register tests in this
// test case right before running them in RUN_ALL_TESTS macro. // test case right before running them in RUN_ALL_TESTS macro.
// This method should not be called more then once on any single // This method should not be called more then once on any single
// instance of a ParameterizedTestCaseInfoBase derived class. // instance of a ParameterizedTestCaseInfoBase derived class.
virtual void RegisterTests() = 0; virtual void RegisterTests() = 0;
protected: protected:
ParameterizedTestCaseInfoBase() {} ParameterizedTestCaseInfoBase() {}
skipping to change at line 455 skipping to change at line 456
// for declarations of public methods AddTestPattern() and // for declarations of public methods AddTestPattern() and
// AddTestCaseInstantiation(). // AddTestCaseInstantiation().
typedef typename TestCase::ParamType ParamType; typedef typename TestCase::ParamType ParamType;
// A function that returns an instance of appropriate generator type. // A function that returns an instance of appropriate generator type.
typedef ParamGenerator<ParamType>(GeneratorCreationFunc)(); typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
explicit ParameterizedTestCaseInfo(const char* name) explicit ParameterizedTestCaseInfo(const char* name)
: test_case_name_(name) {} : test_case_name_(name) {}
// Test case base name for display purposes. // Test case base name for display purposes.
virtual const String& GetTestCaseName() const { return test_case_name_; } virtual const string& GetTestCaseName() const { return test_case_name_; }
// Test case id to verify identity. // Test case id to verify identity.
virtual TypeId GetTestCaseTypeId() const { return GetTypeId<TestCase>(); } virtual TypeId GetTestCaseTypeId() const { return GetTypeId<TestCase>(); }
// TEST_P macro uses AddTestPattern() to record information // TEST_P macro uses AddTestPattern() to record information
// about a single test in a LocalTestInfo structure. // about a single test in a LocalTestInfo structure.
// test_case_name is the base name of the test case (without invocation // test_case_name is the base name of the test case (without invocation
// prefix). test_base_name is the name of an individual test without // prefix). test_base_name is the name of an individual test without
// parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is // parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is
// test case base name and DoBar is test base name. // test case base name and DoBar is test base name.
void AddTestPattern(const char* test_case_name, void AddTestPattern(const char* test_case_name,
const char* test_base_name, const char* test_base_name,
TestMetaFactoryBase<ParamType>* meta_factory) { TestMetaFactoryBase<ParamType>* meta_factory) {
tests_.push_back(linked_ptr<TestInfo>(new TestInfo(test_case_name, tests_.push_back(linked_ptr<TestInfo>(new TestInfo(test_case_name,
test_base_name, test_base_name,
meta_factory))); meta_factory)));
} }
// INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record informatio n // INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record informatio n
// about a generator. // about a generator.
int AddTestCaseInstantiation(const char* instantiation_name, int AddTestCaseInstantiation(const string& instantiation_name,
GeneratorCreationFunc* func, GeneratorCreationFunc* func,
const char* /* file */, const char* /* file */,
int /* line */) { int /* line */) {
instantiations_.push_back(::std::make_pair(instantiation_name, func)); instantiations_.push_back(::std::make_pair(instantiation_name, func));
return 0; // Return value used only to run this method in namespace sc ope. return 0; // Return value used only to run this method in namespace sc ope.
} }
// UnitTest class invokes this method to register tests in this test case // UnitTest class invokes this method to register tests in this test case
// test cases right before running tests in RUN_ALL_TESTS macro. // test cases right before running tests in RUN_ALL_TESTS macro.
// This method should not be called more then once on any single // This method should not be called more then once on any single
// instance of a ParameterizedTestCaseInfoBase derived class. // instance of a ParameterizedTestCaseInfoBase derived class.
// UnitTest has a guard to prevent from calling this method more then onc e. // UnitTest has a guard to prevent from calling this method more then onc e.
virtual void RegisterTests() { virtual void RegisterTests() {
for (typename TestInfoContainer::iterator test_it = tests_.begin(); for (typename TestInfoContainer::iterator test_it = tests_.begin();
test_it != tests_.end(); ++test_it) { test_it != tests_.end(); ++test_it) {
linked_ptr<TestInfo> test_info = *test_it; linked_ptr<TestInfo> test_info = *test_it;
for (typename InstantiationContainer::iterator gen_it = for (typename InstantiationContainer::iterator gen_it =
instantiations_.begin(); gen_it != instantiations_.end(); instantiations_.begin(); gen_it != instantiations_.end();
++gen_it) { ++gen_it) {
const String& instantiation_name = gen_it->first; const string& instantiation_name = gen_it->first;
ParamGenerator<ParamType> generator((*gen_it->second)()); ParamGenerator<ParamType> generator((*gen_it->second)());
Message test_case_name_stream; Message test_case_name_stream;
if ( !instantiation_name.empty() ) if ( !instantiation_name.empty() )
test_case_name_stream << instantiation_name.c_str() << "/"; test_case_name_stream << instantiation_name << "/";
test_case_name_stream << test_info->test_case_base_name.c_str(); test_case_name_stream << test_info->test_case_base_name;
int i = 0; int i = 0;
for (typename ParamGenerator<ParamType>::iterator param_it = for (typename ParamGenerator<ParamType>::iterator param_it =
generator.begin(); generator.begin();
param_it != generator.end(); ++param_it, ++i) { param_it != generator.end(); ++param_it, ++i) {
Message test_name_stream; Message test_name_stream;
test_name_stream << test_info->test_base_name.c_str() << "/" << i test_name_stream << test_info->test_base_name << "/" << i;
; MakeAndRegisterTestInfo(
::testing::internal::MakeAndRegisterTestInfo(
test_case_name_stream.GetString().c_str(), test_case_name_stream.GetString().c_str(),
test_name_stream.GetString().c_str(), test_name_stream.GetString().c_str(),
"", // test_case_comment NULL, // No type parameter.
"", // comment; TODO(vladl@google.com): provide parameter va PrintToString(*param_it).c_str(),
lue
// representation.
GetTestCaseTypeId(), GetTestCaseTypeId(),
TestCase::SetUpTestCase, TestCase::SetUpTestCase,
TestCase::TearDownTestCase, TestCase::TearDownTestCase,
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* a_test_case_base_name, TestInfo(const char* a_test_case_base_name,
const char* a_test_base_name, const char* a_test_base_name,
TestMetaFactoryBase<ParamType>* a_test_meta_factory) : TestMetaFactoryBase<ParamType>* a_test_meta_factory) :
test_case_base_name(a_test_case_base_name), test_case_base_name(a_test_case_base_name),
test_base_name(a_test_base_name), test_base_name(a_test_base_name),
test_meta_factory(a_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;
const String test_case_name_; const string test_case_name_;
TestInfoContainer tests_; TestInfoContainer tests_;
InstantiationContainer instantiations_; InstantiationContainer instantiations_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfo); GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfo);
}; // class ParameterizedTestCaseInfo }; // class ParameterizedTestCaseInfo
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
// //
// ParameterizedTestCaseRegistry contains a map of ParameterizedTestCaseInf oBase // ParameterizedTestCaseRegistry contains a map of ParameterizedTestCaseInf oBase
// classes accessed by test case names. TEST_P and INSTANTIATE_TEST_CASE_P // classes accessed by test case names. TEST_P and INSTANTIATE_TEST_CASE_P
skipping to change at line 581 skipping to change at line 581
int line) { int line) {
ParameterizedTestCaseInfo<TestCase>* typed_test_info = NULL; ParameterizedTestCaseInfo<TestCase>* typed_test_info = NULL;
for (TestCaseInfoContainer::iterator it = test_case_infos_.begin(); for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
it != test_case_infos_.end(); ++it) { it != test_case_infos_.end(); ++it) {
if ((*it)->GetTestCaseName() == test_case_name) { if ((*it)->GetTestCaseName() == test_case_name) {
if ((*it)->GetTestCaseTypeId() != GetTypeId<TestCase>()) { if ((*it)->GetTestCaseTypeId() != GetTypeId<TestCase>()) {
// Complain about incorrect usage of Google Test facilities // Complain about incorrect usage of Google Test facilities
// and terminate the program since we cannot guaranty correct // and terminate the program since we cannot guaranty correct
// test case setup and tear-down in this case. // test case setup and tear-down in this case.
ReportInvalidTestCaseType(test_case_name, file, line); ReportInvalidTestCaseType(test_case_name, file, line);
abort(); posix::Abort();
} else { } else {
// At this point we are sure that the object we found is of the s ame // At this point we are sure that the object we found is of the s ame
// type we are looking for, so we downcast it to that type // type we are looking for, so we downcast it to that type
// without further checks. // without further checks.
typed_test_info = CheckedDowncastToActualType< typed_test_info = CheckedDowncastToActualType<
ParameterizedTestCaseInfo<TestCase> >(*it); ParameterizedTestCaseInfo<TestCase> >(*it);
} }
break; break;
} }
} }
 End of changes. 14 change blocks. 
23 lines changed or deleted 21 lines changed or added


 gtest-port.h   gtest-port.h 
skipping to change at line 53 skipping to change at line 53
// GTEST_HAS_CLONE - Define it to 1/0 to indicate that clone(2) // GTEST_HAS_CLONE - Define it to 1/0 to indicate that clone(2)
// is/isn't available. // is/isn't available.
// GTEST_HAS_EXCEPTIONS - Define it to 1/0 to indicate that exception s // GTEST_HAS_EXCEPTIONS - Define it to 1/0 to indicate that exception s
// are enabled. // are enabled.
// GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string // GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string
// is/isn't available (some systems define // is/isn't available (some systems define
// ::string, which is different to std::string ). // ::string, which is different to std::string ).
// GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string // GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
// is/isn't available (some systems define // is/isn't available (some systems define
// ::wstring, which is different to std::wstri ng). // ::wstring, which is different to std::wstri ng).
// GTEST_HAS_POSIX_RE - Define it to 1/0 to indicate that POSIX reg
ular
// expressions are/aren't available.
// GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread. h> // GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread. h>
// is/isn't available. // is/isn't available.
// GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/i sn't // GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/i sn't
// enabled. // enabled.
// GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that // GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that
// std::wstring does/doesn't work (Google Test can // std::wstring does/doesn't work (Google Test can
// be used where std::wstring is unavailable). // be used where std::wstring is unavailable).
// GTEST_HAS_TR1_TUPLE - Define it to 1/0 to indicate tr1::tuple // GTEST_HAS_TR1_TUPLE - Define it to 1/0 to indicate tr1::tuple
// is/isn't available. // is/isn't available.
// GTEST_HAS_SEH - Define it to 1/0 to indicate whether the // GTEST_HAS_SEH - Define it to 1/0 to indicate whether the
// compiler supports Microsoft's "Structured // compiler supports Microsoft's "Structured
// Exception Handling". // Exception Handling".
// GTEST_HAS_STREAM_REDIRECTION
// - Define it to 1/0 to indicate whether the
// platform supports I/O stream redirection us
ing
// dup() and dup2().
// GTEST_USE_OWN_TR1_TUPLE - Define it to 1/0 to indicate whether Google // GTEST_USE_OWN_TR1_TUPLE - Define it to 1/0 to indicate whether Google
// Test's own tr1 tuple implementation should be // Test's own tr1 tuple implementation should be
// used. Unused when the user sets // used. Unused when the user sets
// GTEST_HAS_TR1_TUPLE to 0. // GTEST_HAS_TR1_TUPLE to 0.
// GTEST_LINKED_AS_SHARED_LIBRARY // GTEST_LINKED_AS_SHARED_LIBRARY
// - Define to 1 when compiling tests that use // - Define to 1 when compiling tests that use
// Google Test as a shared library (known as // Google Test as a shared library (known as
// DLL on Windows). // DLL on Windows).
// GTEST_CREATE_SHARED_LIBRARY // GTEST_CREATE_SHARED_LIBRARY
// - Define to 1 when compiling Google Test itse lf // - Define to 1 when compiling Google Test itse lf
// as a shared library. // as a shared library.
// This header defines the following utilities: // This header defines the following utilities:
// //
// Macros indicating the current platform (defined to 1 if compiled on // Macros indicating the current platform (defined to 1 if compiled on
// the given platform; otherwise undefined): // the given platform; otherwise undefined):
// GTEST_OS_AIX - IBM AIX // GTEST_OS_AIX - IBM AIX
// GTEST_OS_CYGWIN - Cygwin // GTEST_OS_CYGWIN - Cygwin
// GTEST_OS_HPUX - HP-UX
// GTEST_OS_LINUX - Linux // GTEST_OS_LINUX - Linux
// GTEST_OS_LINUX_ANDROID - Google Android
// GTEST_OS_MAC - Mac OS X // GTEST_OS_MAC - Mac OS X
// GTEST_OS_NACL - Google Native Client (NaCl)
// GTEST_OS_SOLARIS - Sun Solaris // GTEST_OS_SOLARIS - Sun Solaris
// GTEST_OS_SYMBIAN - Symbian // GTEST_OS_SYMBIAN - Symbian
// GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile) // GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile)
// GTEST_OS_WINDOWS_DESKTOP - Windows Desktop // GTEST_OS_WINDOWS_DESKTOP - Windows Desktop
// GTEST_OS_WINDOWS_MINGW - MinGW // GTEST_OS_WINDOWS_MINGW - MinGW
// GTEST_OS_WINDOWS_MOBILE - Windows Mobile // GTEST_OS_WINDOWS_MOBILE - Windows Mobile
// GTEST_OS_ZOS - z/OS // GTEST_OS_ZOS - z/OS
// //
// Among the platforms, Cygwin, Linux, Max OS X, and Windows have the // Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
// most stable support. Since core members of the Google Test project // most stable support. Since core members of the Google Test project
skipping to change at line 110 skipping to change at line 119
// Note that it is possible that none of the GTEST_OS_* macros are defined. // Note that it is possible that none of the GTEST_OS_* macros are defined.
// //
// Macros indicating available Google Test features (defined to 1 if // Macros indicating available Google Test features (defined to 1 if
// the corresponding feature is supported; otherwise undefined): // the corresponding feature is supported; otherwise undefined):
// GTEST_HAS_COMBINE - the Combine() function (for value-parameteriz ed // GTEST_HAS_COMBINE - the Combine() function (for value-parameteriz ed
// tests) // tests)
// GTEST_HAS_DEATH_TEST - death tests // GTEST_HAS_DEATH_TEST - death tests
// GTEST_HAS_PARAM_TEST - value-parameterized tests // GTEST_HAS_PARAM_TEST - value-parameterized tests
// GTEST_HAS_TYPED_TEST - typed tests // GTEST_HAS_TYPED_TEST - typed tests
// GTEST_HAS_TYPED_TEST_P - type-parameterized tests // GTEST_HAS_TYPED_TEST_P - type-parameterized tests
// GTEST_USES_POSIX_RE - enhanced POSIX regex is used. // GTEST_USES_POSIX_RE - enhanced POSIX regex is used. Do not confuse
with
// GTEST_HAS_POSIX_RE (see above) which users ca
n
// define themselves.
// GTEST_USES_SIMPLE_RE - our own simple regex is used; // GTEST_USES_SIMPLE_RE - our own simple regex is used;
// the above two are mutually exclusive. // the above two are mutually exclusive.
// GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ(). // GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
// //
// Macros for basic C++ coding: // Macros for basic C++ coding:
// GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning. // GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
// GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a // GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a
// variable don't have to be used. // variable don't have to be used.
// GTEST_DISALLOW_ASSIGN_ - disables operator=. // GTEST_DISALLOW_ASSIGN_ - disables operator=.
// GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=. // GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
skipping to change at line 132 skipping to change at line 143
// //
// Synchronization: // Synchronization:
// Mutex, MutexLock, ThreadLocal, GetThreadCount() // Mutex, MutexLock, ThreadLocal, GetThreadCount()
// - synchronization primitives. // - synchronization primitives.
// GTEST_IS_THREADSAFE - defined to 1 to indicate that the above // GTEST_IS_THREADSAFE - defined to 1 to indicate that the above
// synchronization primitives have real implementat ions // synchronization primitives have real implementat ions
// and Google Test is thread-safe; or 0 otherwise. // and Google Test is thread-safe; or 0 otherwise.
// //
// Template meta programming: // Template meta programming:
// is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only. // is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only.
// IteratorTraits - partial implementation of std::iterator_traits, which
// is not available in libCstd when compiled with Sun C+
+.
// //
// Smart pointers: // Smart pointers:
// scoped_ptr - as in TR2. // scoped_ptr - as in TR2.
// //
// Regular expressions: // Regular expressions:
// RE - a simple regular expression class using the POSIX // RE - a simple regular expression class using the POSIX
// Extended Regular Expression syntax. Not available on // Extended Regular Expression syntax on UNIX-like
// Windows. // platforms, or a reduced regular exception syntax on
// other platforms, including Windows.
// //
// Logging: // Logging:
// GTEST_LOG_() - logs messages at the specified severity level. // GTEST_LOG_() - logs messages at the specified severity level.
// LogToStderr() - directs all log messages to stderr. // LogToStderr() - directs all log messages to stderr.
// FlushInfoLog() - flushes informational log messages. // FlushInfoLog() - flushes informational log messages.
// //
// Stdout and stderr capturing: // Stdout and stderr capturing:
// CaptureStdout() - starts capturing stdout. // CaptureStdout() - starts capturing stdout.
// GetCapturedStdout() - stops capturing stdout and returns the captured // GetCapturedStdout() - stops capturing stdout and returns the captured
// string. // string.
skipping to change at line 172 skipping to change at line 186
// GTEST_DECLARE_*() - declares a flag. // GTEST_DECLARE_*() - declares a flag.
// GTEST_DEFINE_*() - defines a flag. // GTEST_DEFINE_*() - defines a flag.
// GetArgvs() - returns the command line as a vector of strings. // GetArgvs() - returns the command line as a vector of strings.
// //
// Environment variable utilities: // Environment variable utilities:
// GetEnv() - gets the value of an environment variable. // GetEnv() - gets the value of an environment variable.
// BoolFromGTestEnv() - parses a bool environment variable. // BoolFromGTestEnv() - parses a bool environment variable.
// Int32FromGTestEnv() - parses an Int32 environment variable. // Int32FromGTestEnv() - parses an Int32 environment variable.
// StringFromGTestEnv() - parses a string environment variable. // StringFromGTestEnv() - parses a string environment variable.
#include <stddef.h> // For ptrdiff_t #include <ctype.h> // for isspace, etc
#include <stddef.h> // for ptrdiff_t
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifndef _WIN32_WCE #ifndef _WIN32_WCE
#include <sys/stat.h> # include <sys/types.h>
# include <sys/stat.h>
#endif // !_WIN32_WCE #endif // !_WIN32_WCE
#include <iostream> // NOLINT #include <iostream> // NOLINT
#include <sstream> // NOLINT #include <sstream> // NOLINT
#include <string> // NOLINT #include <string> // NOLINT
#define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com" #define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
#define GTEST_FLAG_PREFIX_ "gtest_" #define GTEST_FLAG_PREFIX_ "gtest_"
#define GTEST_FLAG_PREFIX_DASH_ "gtest-" #define GTEST_FLAG_PREFIX_DASH_ "gtest-"
#define GTEST_FLAG_PREFIX_UPPER_ "GTEST_" #define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
#define GTEST_NAME_ "Google Test" #define GTEST_NAME_ "Google Test"
#define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/" #define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
// Determines the version of gcc that is used to compile this. // Determines the version of gcc that is used to compile this.
#ifdef __GNUC__ #ifdef __GNUC__
// 40302 means version 4.3.2. // 40302 means version 4.3.2.
#define GTEST_GCC_VER_ \ # define GTEST_GCC_VER_ \
(__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
#endif // __GNUC__ #endif // __GNUC__
// Determines the platform on which Google Test is compiled. // Determines the platform on which Google Test is compiled.
#ifdef __CYGWIN__ #ifdef __CYGWIN__
#define GTEST_OS_CYGWIN 1 # define GTEST_OS_CYGWIN 1
#elif defined __SYMBIAN32__ #elif defined __SYMBIAN32__
#define GTEST_OS_SYMBIAN 1 # define GTEST_OS_SYMBIAN 1
#elif defined _WIN32 #elif defined _WIN32
#define GTEST_OS_WINDOWS 1 # define GTEST_OS_WINDOWS 1
#ifdef _WIN32_WCE # ifdef _WIN32_WCE
#define GTEST_OS_WINDOWS_MOBILE 1 # define GTEST_OS_WINDOWS_MOBILE 1
#elif defined(__MINGW__) || defined(__MINGW32__) # elif defined(__MINGW__) || defined(__MINGW32__)
#define GTEST_OS_WINDOWS_MINGW 1 # define GTEST_OS_WINDOWS_MINGW 1
#else # else
#define GTEST_OS_WINDOWS_DESKTOP 1 # define GTEST_OS_WINDOWS_DESKTOP 1
#endif // _WIN32_WCE # endif // _WIN32_WCE
#elif defined __APPLE__ #elif defined __APPLE__
#define GTEST_OS_MAC 1 # define GTEST_OS_MAC 1
#elif defined __linux__ #elif defined __linux__
#define GTEST_OS_LINUX 1 # define GTEST_OS_LINUX 1
# ifdef ANDROID
# define GTEST_OS_LINUX_ANDROID 1
# endif // ANDROID
#elif defined __MVS__ #elif defined __MVS__
#define GTEST_OS_ZOS 1 # define GTEST_OS_ZOS 1
#elif defined(__sun) && defined(__SVR4) #elif defined(__sun) && defined(__SVR4)
#define GTEST_OS_SOLARIS 1 # define GTEST_OS_SOLARIS 1
#elif defined(_AIX) #elif defined(_AIX)
#define GTEST_OS_AIX 1 # define GTEST_OS_AIX 1
#elif defined(__hpux)
# define GTEST_OS_HPUX 1
#elif defined __native_client__
# define GTEST_OS_NACL 1
#endif // __CYGWIN__ #endif // __CYGWIN__
#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_SYMBIAN | // Brings in definitions for functions used in the testing::internal::posix
| \ // namespace (read, write, close, chdir, isatty, stat). We do not currently
GTEST_OS_SOLARIS || GTEST_OS_AIX // use them on Windows Mobile.
#if !GTEST_OS_WINDOWS
// This assumes that non-Windows OSes provide unistd.h. For OSes where this
// is not the case, we need to include headers that provide the functions
// mentioned above.
# include <unistd.h>
# if !GTEST_OS_NACL
// TODO(vladl@google.com): Remove this condition when Native Client SDK add
s
// strings.h (tracked in
// http://code.google.com/p/nativeclient/issues/detail?id=1175).
# include <strings.h> // Native Client doesn't provide strings.h.
# endif
#elif !GTEST_OS_WINDOWS_MOBILE
# include <direct.h>
# include <io.h>
#endif
// Defines this to true iff Google Test can use POSIX regular expressions.
#ifndef GTEST_HAS_POSIX_RE
# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
#endif
#if GTEST_HAS_POSIX_RE
// On some platforms, <regex.h> needs someone to define size_t, and // On some platforms, <regex.h> needs someone to define size_t, and
// won't compile otherwise. We can #include it here as we already // won't compile otherwise. We can #include it here as we already
// included <stdlib.h>, which is guaranteed to define size_t through // included <stdlib.h>, which is guaranteed to define size_t through
// <stddef.h>. // <stddef.h>.
#include <regex.h> // NOLINT # include <regex.h> // NOLINT
#include <strings.h> // NOLINT
#include <sys/types.h> // NOLINT
#include <time.h> // NOLINT
#include <unistd.h> // NOLINT
#define GTEST_USES_POSIX_RE 1 # define GTEST_USES_POSIX_RE 1
#elif GTEST_OS_WINDOWS #elif GTEST_OS_WINDOWS
#if !GTEST_OS_WINDOWS_MOBILE
#include <direct.h> // NOLINT
#include <io.h> // NOLINT
#endif
// <regex.h> is not available on Windows. Use our own simple regex // <regex.h> is not available on Windows. Use our own simple regex
// implementation instead. // implementation instead.
#define GTEST_USES_SIMPLE_RE 1 # define GTEST_USES_SIMPLE_RE 1
#else #else
// <regex.h> may not be available on this platform. Use our own // <regex.h> may not be available on this platform. Use our own
// simple regex implementation instead. // simple regex implementation instead.
#define GTEST_USES_SIMPLE_RE 1 # define GTEST_USES_SIMPLE_RE 1
#endif // GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC || #endif // GTEST_HAS_POSIX_RE
// GTEST_OS_SYMBIAN || GTEST_OS_SOLARIS || GTEST_OS_AIX
#ifndef GTEST_HAS_EXCEPTIONS #ifndef GTEST_HAS_EXCEPTIONS
// The user didn't tell us whether exceptions are enabled, so we need // The user didn't tell us whether exceptions are enabled, so we need
// to figure it out. // to figure it out.
#if defined(_MSC_VER) || defined(__BORLANDC__) # if defined(_MSC_VER) || defined(__BORLANDC__)
// MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIO NS // MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIO NS
// macro to enable exceptions, so we'll do the same. // macro to enable exceptions, so we'll do the same.
// Assumes that exceptions are enabled by default. // Assumes that exceptions are enabled by default.
#ifndef _HAS_EXCEPTIONS # ifndef _HAS_EXCEPTIONS
#define _HAS_EXCEPTIONS 1 # define _HAS_EXCEPTIONS 1
#endif // _HAS_EXCEPTIONS # endif // _HAS_EXCEPTIONS
#define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS # define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
#elif defined(__GNUC__) && __EXCEPTIONS # elif defined(__GNUC__) && __EXCEPTIONS
// gcc defines __EXCEPTIONS to 1 iff exceptions are enabled. // gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
#define GTEST_HAS_EXCEPTIONS 1 # define GTEST_HAS_EXCEPTIONS 1
#elif defined(__SUNPRO_CC) # elif defined(__SUNPRO_CC)
// Sun Pro CC supports exceptions. However, there is no compile-time way o f // Sun Pro CC supports exceptions. However, there is no compile-time way o f
// detecting whether they are enabled or not. Therefore, we assume that // detecting whether they are enabled or not. Therefore, we assume that
// they are enabled unless the user tells us otherwise. // they are enabled unless the user tells us otherwise.
#define GTEST_HAS_EXCEPTIONS 1 # define GTEST_HAS_EXCEPTIONS 1
#elif defined(__IBMCPP__) && __EXCEPTIONS # elif defined(__IBMCPP__) && __EXCEPTIONS
// xlC defines __EXCEPTIONS to 1 iff exceptions are enabled. // xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
#define GTEST_HAS_EXCEPTIONS 1 # define GTEST_HAS_EXCEPTIONS 1
#else # elif defined(__HP_aCC)
// Exception handling is in effect by default in HP aCC compiler. It has to
// be turned of by +noeh compiler option if desired.
# define GTEST_HAS_EXCEPTIONS 1
# else
// For other compilers, we assume exceptions are disabled to be // For other compilers, we assume exceptions are disabled to be
// conservative. // conservative.
#define GTEST_HAS_EXCEPTIONS 0 # define GTEST_HAS_EXCEPTIONS 0
#endif // defined(_MSC_VER) || defined(__BORLANDC__) # endif // defined(_MSC_VER) || defined(__BORLANDC__)
#endif // GTEST_HAS_EXCEPTIONS #endif // GTEST_HAS_EXCEPTIONS
#if !defined(GTEST_HAS_STD_STRING) #if !defined(GTEST_HAS_STD_STRING)
// Even though we don't use this macro any longer, we keep it in case // Even though we don't use this macro any longer, we keep it in case
// some clients still depend on it. // some clients still depend on it.
#define GTEST_HAS_STD_STRING 1 # define GTEST_HAS_STD_STRING 1
#elif !GTEST_HAS_STD_STRING #elif !GTEST_HAS_STD_STRING
// The user told us that ::std::string isn't available. // The user told us that ::std::string isn't available.
#error "Google Test cannot be used where ::std::string isn't available." # error "Google Test cannot be used where ::std::string isn't available."
#endif // !defined(GTEST_HAS_STD_STRING) #endif // !defined(GTEST_HAS_STD_STRING)
#ifndef GTEST_HAS_GLOBAL_STRING #ifndef GTEST_HAS_GLOBAL_STRING
// The user didn't tell us whether ::string is available, so we need // The user didn't tell us whether ::string is available, so we need
// to figure it out. // to figure it out.
#define GTEST_HAS_GLOBAL_STRING 0 # define GTEST_HAS_GLOBAL_STRING 0
#endif // GTEST_HAS_GLOBAL_STRING #endif // GTEST_HAS_GLOBAL_STRING
#ifndef GTEST_HAS_STD_WSTRING #ifndef GTEST_HAS_STD_WSTRING
// The user didn't tell us whether ::std::wstring is available, so we need // The user didn't tell us whether ::std::wstring is available, so we need
// to figure it out. // to figure it out.
// TODO(wan@google.com): uses autoconf to detect whether ::std::wstring // TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
// is available. // is available.
// Cygwin 1.5 and below doesn't support ::std::wstring. // Cygwin 1.7 and below doesn't support ::std::wstring.
// Cygwin 1.7 might add wstring support; this should be updated when clear. // Solaris' libc++ doesn't support it either. Android has
// Solaris' libc++ doesn't support it either. // no support for it at least as recent as Froyo (2.2).
#define GTEST_HAS_STD_WSTRING (!(GTEST_OS_CYGWIN || GTEST_OS_SOLARIS)) # define GTEST_HAS_STD_WSTRING \
(!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
#endif // GTEST_HAS_STD_WSTRING #endif // GTEST_HAS_STD_WSTRING
#ifndef GTEST_HAS_GLOBAL_WSTRING #ifndef GTEST_HAS_GLOBAL_WSTRING
// The user didn't tell us whether ::wstring is available, so we need // The user didn't tell us whether ::wstring is available, so we need
// to figure it out. // to figure it out.
#define GTEST_HAS_GLOBAL_WSTRING \ # define GTEST_HAS_GLOBAL_WSTRING \
(GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING) (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
#endif // GTEST_HAS_GLOBAL_WSTRING #endif // GTEST_HAS_GLOBAL_WSTRING
// Determines whether RTTI is available. // Determines whether RTTI is available.
#ifndef GTEST_HAS_RTTI #ifndef GTEST_HAS_RTTI
// The user didn't tell us whether RTTI is enabled, so we need to // The user didn't tell us whether RTTI is enabled, so we need to
// figure it out. // figure it out.
#ifdef _MSC_VER # ifdef _MSC_VER
#ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled. # ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled.
#define GTEST_HAS_RTTI 1 # define GTEST_HAS_RTTI 1
#else # else
#define GTEST_HAS_RTTI 0 # define GTEST_HAS_RTTI 0
#endif # endif
// Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled. // Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
#elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302) # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
#ifdef __GXX_RTTI # ifdef __GXX_RTTI
#define GTEST_HAS_RTTI 1 # define GTEST_HAS_RTTI 1
#else # else
#define GTEST_HAS_RTTI 0 # define GTEST_HAS_RTTI 0
#endif // __GXX_RTTI # endif // __GXX_RTTI
// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if // Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
// both the typeid and dynamic_cast features are present. // both the typeid and dynamic_cast features are present.
#elif defined(__IBMCPP__) && (__IBMCPP__ >= 900) # elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
#ifdef __RTTI_ALL__ # ifdef __RTTI_ALL__
#define GTEST_HAS_RTTI 1 # define GTEST_HAS_RTTI 1
#else # else
#define GTEST_HAS_RTTI 0 # define GTEST_HAS_RTTI 0
#endif # endif
#else # else
// For all other compilers, we assume RTTI is enabled. // For all other compilers, we assume RTTI is enabled.
#define GTEST_HAS_RTTI 1 # define GTEST_HAS_RTTI 1
#endif // _MSC_VER # endif // _MSC_VER
#endif // GTEST_HAS_RTTI #endif // GTEST_HAS_RTTI
// It's this header's responsibility to #include <typeinfo> when RTTI // It's this header's responsibility to #include <typeinfo> when RTTI
// is enabled. // is enabled.
#if GTEST_HAS_RTTI #if GTEST_HAS_RTTI
#include <typeinfo> # include <typeinfo>
#endif #endif
// Determines whether Google Test can use the pthreads library. // Determines whether Google Test can use the pthreads library.
#ifndef GTEST_HAS_PTHREAD #ifndef GTEST_HAS_PTHREAD
// The user didn't tell us explicitly, so we assume pthreads support is // The user didn't tell us explicitly, so we assume pthreads support is
// available on Linux and Mac. // available on Linux and Mac.
// //
// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0 // To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
// to your compiler flags. // to your compiler flags.
#define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC) # define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX )
#endif // GTEST_HAS_PTHREAD #endif // GTEST_HAS_PTHREAD
#if GTEST_HAS_PTHREAD
// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD i
s
// true.
# include <pthread.h> // NOLINT
// For timespec and nanosleep, used below.
# include <time.h> // NOLINT
#endif
// Determines whether Google Test can use tr1/tuple. You can define // Determines whether Google Test can use tr1/tuple. You can define
// this macro to 0 to prevent Google Test from using tuple (any // this macro to 0 to prevent Google Test from using tuple (any
// feature depending on tuple with be disabled in this mode). // feature depending on tuple with be disabled in this mode).
#ifndef GTEST_HAS_TR1_TUPLE #ifndef GTEST_HAS_TR1_TUPLE
// The user didn't tell us not to do it, so we assume it's OK. // The user didn't tell us not to do it, so we assume it's OK.
#define GTEST_HAS_TR1_TUPLE 1 # define GTEST_HAS_TR1_TUPLE 1
#endif // GTEST_HAS_TR1_TUPLE #endif // GTEST_HAS_TR1_TUPLE
// Determines whether Google Test's own tr1 tuple implementation // Determines whether Google Test's own tr1 tuple implementation
// should be used. // should be used.
#ifndef GTEST_USE_OWN_TR1_TUPLE #ifndef GTEST_USE_OWN_TR1_TUPLE
// The user didn't tell us, so we need to figure it out. // The user didn't tell us, so we need to figure it out.
// We use our own TR1 tuple if we aren't sure the user has an // We use our own TR1 tuple if we aren't sure the user has an
// implementation of it already. At this time, GCC 4.0.0+ and MSVC // implementation of it already. At this time, GCC 4.0.0+ and MSVC
// 2010 are the only mainstream compilers that come with a TR1 tuple // 2010 are the only mainstream compilers that come with a TR1 tuple
// implementation. NVIDIA's CUDA NVCC compiler pretends to be GCC by // implementation. NVIDIA's CUDA NVCC compiler pretends to be GCC by
// defining __GNUC__ and friends, but cannot compile GCC's tuple // defining __GNUC__ and friends, but cannot compile GCC's tuple
// implementation. MSVC 2008 (9.0) provides TR1 tuple in a 323 MB // implementation. MSVC 2008 (9.0) provides TR1 tuple in a 323 MB
// Feature Pack download, which we cannot assume the user has. // Feature Pack download, which we cannot assume the user has.
#if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) ) \ # if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000 )) \
|| _MSC_VER >= 1600 || _MSC_VER >= 1600
#define GTEST_USE_OWN_TR1_TUPLE 0 # define GTEST_USE_OWN_TR1_TUPLE 0
#else # else
#define GTEST_USE_OWN_TR1_TUPLE 1 # define GTEST_USE_OWN_TR1_TUPLE 1
#endif # endif
#endif // GTEST_USE_OWN_TR1_TUPLE #endif // GTEST_USE_OWN_TR1_TUPLE
// To avoid conditional compilation everywhere, we make it // To avoid conditional compilation everywhere, we make it
// gtest-port.h's responsibility to #include the header implementing // gtest-port.h's responsibility to #include the header implementing
// tr1/tuple. // tr1/tuple.
#if GTEST_HAS_TR1_TUPLE #if GTEST_HAS_TR1_TUPLE
#if GTEST_USE_OWN_TR1_TUPLE # if GTEST_USE_OWN_TR1_TUPLE
#include <gtest/internal/gtest-tuple.h> # include "gtest/internal/gtest-tuple.h"
#elif GTEST_OS_SYMBIAN # elif GTEST_OS_SYMBIAN
// On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to // On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
// use STLport's tuple implementation, which unfortunately doesn't // use STLport's tuple implementation, which unfortunately doesn't
// work as the copy of STLport distributed with Symbian is incomplete. // work as the copy of STLport distributed with Symbian is incomplete.
// By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to // By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
// use its own tuple implementation. // use its own tuple implementation.
#ifdef BOOST_HAS_TR1_TUPLE # ifdef BOOST_HAS_TR1_TUPLE
#undef BOOST_HAS_TR1_TUPLE # undef BOOST_HAS_TR1_TUPLE
#endif // BOOST_HAS_TR1_TUPLE # endif // BOOST_HAS_TR1_TUPLE
// This prevents <boost/tr1/detail/config.hpp>, which defines // This prevents <boost/tr1/detail/config.hpp>, which defines
// BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>. // BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
#define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED # define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
#include <tuple> # include <tuple>
#elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000) # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
// GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does // GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does
// not conform to the TR1 spec, which requires the header to be <tuple>. // not conform to the TR1 spec, which requires the header to be <tuple>.
#if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 # if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
// Until version 4.3.2, gcc has a bug that causes <tr1/functional>, // Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
// which is #included by <tr1/tuple>, to not compile when RTTI is // which is #included by <tr1/tuple>, to not compile when RTTI is
// disabled. _TR1_FUNCTIONAL is the header guard for // disabled. _TR1_FUNCTIONAL is the header guard for
// <tr1/functional>. Hence the following #define is a hack to prevent // <tr1/functional>. Hence the following #define is a hack to prevent
// <tr1/functional> from being included. // <tr1/functional> from being included.
#define _TR1_FUNCTIONAL 1 # define _TR1_FUNCTIONAL 1
#include <tr1/tuple> # include <tr1/tuple>
#undef _TR1_FUNCTIONAL // Allows the user to #include # undef _TR1_FUNCTIONAL // Allows the user to #include
// <tr1/functional> if he chooses to. // <tr1/functional> if he chooses to.
#else # else
#include <tr1/tuple> // NOLINT # include <tr1/tuple> // NOLINT
#endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302 # endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
#else # else
// If the compiler is not GCC 4.0+, we assume the user is using a // If the compiler is not GCC 4.0+, we assume the user is using a
// spec-conforming TR1 implementation. // spec-conforming TR1 implementation.
#include <tuple> // NOLINT # include <tuple> // NOLINT
#endif // GTEST_USE_OWN_TR1_TUPLE # endif // GTEST_USE_OWN_TR1_TUPLE
#endif // GTEST_HAS_TR1_TUPLE #endif // GTEST_HAS_TR1_TUPLE
// Determines whether clone(2) is supported. // Determines whether clone(2) is supported.
// Usually it will only be available on Linux, excluding // Usually it will only be available on Linux, excluding
// Linux on the Itanium architecture. // Linux on the Itanium architecture.
// Also see http://linux.die.net/man/2/clone. // Also see http://linux.die.net/man/2/clone.
#ifndef GTEST_HAS_CLONE #ifndef GTEST_HAS_CLONE
// The user didn't tell us, so we need to figure it out. // The user didn't tell us, so we need to figure it out.
#if GTEST_OS_LINUX && !defined(__ia64__) # if GTEST_OS_LINUX && !defined(__ia64__)
#define GTEST_HAS_CLONE 1 # define GTEST_HAS_CLONE 1
#else # else
#define GTEST_HAS_CLONE 0 # define GTEST_HAS_CLONE 0
#endif // GTEST_OS_LINUX && !defined(__ia64__) # endif // GTEST_OS_LINUX && !defined(__ia64__)
#endif // GTEST_HAS_CLONE #endif // GTEST_HAS_CLONE
// Determines whether to support stream redirection. This is used to test // Determines whether to support stream redirection. This is used to test
// output correctness and to implement death tests. // output correctness and to implement death tests.
#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN #ifndef GTEST_HAS_STREAM_REDIRECTION
#define GTEST_HAS_STREAM_REDIRECTION_ 1 // By default, we assume that stream redirection is supported on all
#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN // platforms except known mobile ones.
# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN
# define GTEST_HAS_STREAM_REDIRECTION 0
# else
# define GTEST_HAS_STREAM_REDIRECTION 1
# endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
#endif // GTEST_HAS_STREAM_REDIRECTION
// Determines whether to support death tests. // Determines whether to support death tests.
// Google Test does not support death tests for VC 7.1 and earlier as // Google Test does not support death tests for VC 7.1 and earlier as
// abort() in a VC 7.1 application compiled as GUI in debug config // abort() in a VC 7.1 application compiled as GUI in debug config
// pops up a dialog window that cannot be suppressed programmatically. // pops up a dialog window that cannot be suppressed programmatically.
#if (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ #if (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
(GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \ (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX) GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX)
#define GTEST_HAS_DEATH_TEST 1 # define GTEST_HAS_DEATH_TEST 1
#include <vector> // NOLINT # include <vector> // NOLINT
#endif #endif
// We don't support MSVC 7.1 with exceptions disabled now. Therefore // We don't support MSVC 7.1 with exceptions disabled now. Therefore
// all the compilers we care about are adequate for supporting // all the compilers we care about are adequate for supporting
// value-parameterized tests. // value-parameterized tests.
#define GTEST_HAS_PARAM_TEST 1 #define GTEST_HAS_PARAM_TEST 1
// Determines whether to support type-driven tests. // Determines whether to support type-driven tests.
// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0, // Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
// Sun Pro CC, and IBM Visual Age support. // Sun Pro CC, IBM Visual Age, and HP aCC support.
#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \ #if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
defined(__IBMCPP__) defined(__IBMCPP__) || defined(__HP_aCC)
#define GTEST_HAS_TYPED_TEST 1 # define GTEST_HAS_TYPED_TEST 1
#define GTEST_HAS_TYPED_TEST_P 1 # define GTEST_HAS_TYPED_TEST_P 1
#endif #endif
// Determines whether to support Combine(). This only makes sense when // Determines whether to support Combine(). This only makes sense when
// value-parameterized tests are enabled. The implementation doesn't // value-parameterized tests are enabled. The implementation doesn't
// work on Sun Studio since it doesn't understand templated conversion // work on Sun Studio since it doesn't understand templated conversion
// operators. // operators.
#if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC) #if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
#define GTEST_HAS_COMBINE 1 # define GTEST_HAS_COMBINE 1
#endif #endif
// Determines whether the system compiler uses UTF-16 for encoding wide str ings. // Determines whether the system compiler uses UTF-16 for encoding wide str ings.
#define GTEST_WIDE_STRING_USES_UTF16_ \ #define GTEST_WIDE_STRING_USES_UTF16_ \
(GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AI X) (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AI X)
// Determines whether test results can be streamed to a socket.
#if GTEST_OS_LINUX
# define GTEST_CAN_STREAM_RESULTS_ 1
#endif
// Defines some utility macros. // Defines some utility macros.
// The GNU compiler emits a warning if nested "if" statements are followed by // The GNU compiler emits a warning if nested "if" statements are followed by
// an "else" statement and braces are not used to explicitly disambiguate t he // an "else" statement and braces are not used to explicitly disambiguate t he
// "else" binding. This leads to problems with code like: // "else" binding. This leads to problems with code like:
// //
// if (gate) // if (gate)
// ASSERT_*(condition) << "Some message"; // ASSERT_*(condition) << "Some message";
// //
// The "switch (0) case 0:" idiom is used to suppress this. // The "switch (0) case 0:" idiom is used to suppress this.
#ifdef __INTEL_COMPILER #ifdef __INTEL_COMPILER
#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ # define GTEST_AMBIGUOUS_ELSE_BLOCKER_
#else #else
#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: // NOLINT # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLI NT
#endif #endif
// Use this annotation at the end of a struct/class definition to // Use this annotation at the end of a struct/class definition to
// prevent the compiler from optimizing away instances that are never // prevent the compiler from optimizing away instances that are never
// used. This is useful when all interesting logic happens inside the // used. This is useful when all interesting logic happens inside the
// c'tor and / or d'tor. Example: // c'tor and / or d'tor. Example:
// //
// struct Foo { // struct Foo {
// Foo() { ... } // Foo() { ... }
// } GTEST_ATTRIBUTE_UNUSED_; // } GTEST_ATTRIBUTE_UNUSED_;
// //
// Also use it after a variable or parameter declaration to tell the // Also use it after a variable or parameter declaration to tell the
// compiler the variable/parameter does not have to be used. // compiler the variable/parameter does not have to be used.
#if defined(__GNUC__) && !defined(COMPILER_ICC) #if defined(__GNUC__) && !defined(COMPILER_ICC)
#define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
#else #else
#define GTEST_ATTRIBUTE_UNUSED_ # define GTEST_ATTRIBUTE_UNUSED_
#endif #endif
// A macro to disallow operator= // A macro to disallow operator=
// This should be used in the private: declarations for a class. // This should be used in the private: declarations for a class.
#define GTEST_DISALLOW_ASSIGN_(type)\ #define GTEST_DISALLOW_ASSIGN_(type)\
void operator=(type const &) void operator=(type const &)
// A macro to disallow copy constructor and operator= // A macro to disallow copy constructor and operator=
// This should be used in the private: declarations for a class. // This should be used in the private: declarations for a class.
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\ #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
type(type const &);\ type(type const &);\
GTEST_DISALLOW_ASSIGN_(type) GTEST_DISALLOW_ASSIGN_(type)
// Tell the compiler to warn about unused return values for functions decla red // Tell the compiler to warn about unused return values for functions decla red
// with this macro. The macro should be used on function declarations // with this macro. The macro should be used on function declarations
// following the argument list: // following the argument list:
// //
// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; // Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
#if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC ) #if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC )
#define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) # define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
#else #else
#define GTEST_MUST_USE_RESULT_ # define GTEST_MUST_USE_RESULT_
#endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC #endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
// Determine whether the compiler supports Microsoft's Structured Exception // Determine whether the compiler supports Microsoft's Structured Exception
// Handling. This is supported by several Windows compilers but generally // Handling. This is supported by several Windows compilers but generally
// does not exist on any other system. // does not exist on any other system.
#ifndef GTEST_HAS_SEH #ifndef GTEST_HAS_SEH
// The user didn't tell us, so we need to figure it out. // The user didn't tell us, so we need to figure it out.
#if defined(_MSC_VER) || defined(__BORLANDC__) # if defined(_MSC_VER) || defined(__BORLANDC__)
// These two compilers are known to support SEH. // These two compilers are known to support SEH.
#define GTEST_HAS_SEH 1 # define GTEST_HAS_SEH 1
#else # else
// Assume no SEH. // Assume no SEH.
#define GTEST_HAS_SEH 0 # define GTEST_HAS_SEH 0
#endif # endif
#endif // GTEST_HAS_SEH #endif // GTEST_HAS_SEH
#ifdef _MSC_VER #ifdef _MSC_VER
#if GTEST_LINKED_AS_SHARED_LIBRARY # if GTEST_LINKED_AS_SHARED_LIBRARY
#define GTEST_API_ __declspec(dllimport) # define GTEST_API_ __declspec(dllimport)
#elif GTEST_CREATE_SHARED_LIBRARY # elif GTEST_CREATE_SHARED_LIBRARY
#define GTEST_API_ __declspec(dllexport) # define GTEST_API_ __declspec(dllexport)
#endif # endif
#endif // _MSC_VER #endif // _MSC_VER
#ifndef GTEST_API_ #ifndef GTEST_API_
#define GTEST_API_ # define GTEST_API_
#endif
#ifdef __GNUC__
// Ask the compiler to never inline a given function.
# define GTEST_NO_INLINE_ __attribute__((noinline))
#else
# define GTEST_NO_INLINE_
#endif #endif
namespace testing { namespace testing {
class Message; class Message;
namespace internal { namespace internal {
class String; class String;
typedef ::std::stringstream StrStream; // The GTEST_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
// size of a static array:
//
// GTEST_COMPILE_ASSERT_(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYP
ES,
// content_type_names_incorrect_size);
//
// or to make sure a struct is smaller than a certain size:
//
// GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
//
// The second argument to the macro is the name of the variable. If
// the expression is false, most compilers will issue a warning/error
// containing the name of the variable.
template <bool>
struct CompileAssert {
};
#define GTEST_COMPILE_ASSERT_(expr, msg) \
typedef ::testing::internal::CompileAssert<(bool(expr))> \
msg[bool(expr) ? 1 : -1]
// Implementation details of GTEST_COMPILE_ASSERT_:
//
// - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
// elements (and thus is invalid) when the expression is false.
//
// - The simpler definition
//
// #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1
: -1]
//
// does not work, as gcc supports variable-length arrays whose sizes
// are determined at run-time (this is gcc's extension and not part
// of the C++ standard). As a result, gcc fails to reject the
// following code with the simple definition:
//
// int foo;
// GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo i
s
// // not a compile-time constant.
//
// - By using the type CompileAssert<(bool(expr))>, we ensures that
// expr is a compile-time constant. (Template arguments must be
// determined at compile-time.)
//
// - The outter parentheses in CompileAssert<(bool(expr))> are necessary
// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
//
// CompileAssert<bool(expr)>
//
// instead, these compilers will refuse to compile
//
// GTEST_COMPILE_ASSERT_(5 > 0, some_message);
//
// (They seem to think the ">" in "5 > 0" marks the end of the
// template argument list.)
//
// - The array size is (bool(expr) ? 1 : -1), instead of simply
//
// ((expr) ? 1 : -1).
//
// This is to avoid running into a bug in MS VC 7.1, which
// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
// StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.
h.
//
// This template is declared, but intentionally undefined.
template <typename T1, typename T2>
struct StaticAssertTypeEqHelper;
template <typename T>
struct StaticAssertTypeEqHelper<T, T> {};
#if GTEST_HAS_GLOBAL_STRING
typedef ::string string;
#else
typedef ::std::string string;
#endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_GLOBAL_WSTRING
typedef ::wstring wstring;
#elif GTEST_HAS_STD_WSTRING
typedef ::std::wstring wstring;
#endif // GTEST_HAS_GLOBAL_WSTRING
// A helper for suppressing warnings on constant condition. It just // A helper for suppressing warnings on constant condition. It just
// returns 'condition'. // returns 'condition'.
GTEST_API_ bool IsTrue(bool condition); GTEST_API_ bool IsTrue(bool condition);
// Defines scoped_ptr. // Defines scoped_ptr.
// This implementation of scoped_ptr is PARTIAL - it only contains // This implementation of scoped_ptr is PARTIAL - it only contains
// enough stuff to satisfy Google Test's need. // enough stuff to satisfy Google Test's need.
template <typename T> template <typename T>
skipping to change at line 712 skipping to change at line 867
private: private:
void Init(const char* regex); void Init(const char* regex);
// We use a const char* instead of a string, as Google Test may be used // We use a const char* instead of a string, as Google Test may be used
// where string is not available. We also do not use Google Test's own // where string is not available. We also do not use Google Test's own
// String type here, in order to simplify dependencies between the // String type here, in order to simplify dependencies between the
// files. // files.
const char* pattern_; const char* pattern_;
bool is_valid_; bool is_valid_;
#if GTEST_USES_POSIX_RE #if GTEST_USES_POSIX_RE
regex_t full_regex_; // For FullMatch(). regex_t full_regex_; // For FullMatch().
regex_t partial_regex_; // For PartialMatch(). regex_t partial_regex_; // For PartialMatch().
#else // GTEST_USES_SIMPLE_RE #else // GTEST_USES_SIMPLE_RE
const char* full_pattern_; // For FullMatch(); const char* full_pattern_; // For FullMatch();
#endif #endif
GTEST_DISALLOW_ASSIGN_(RE); GTEST_DISALLOW_ASSIGN_(RE);
}; };
// Formats a source file path and a line number as they would appear
// in an error message from the compiler used to compile this code.
GTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
// Formats a file location for compiler-independent XML output.
// Although this function is not platform dependent, we put it next to
// FormatFileLocation in order to contrast the two functions.
GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char*
file,
int line);
// Defines logging utilities: // Defines logging utilities:
// GTEST_LOG_(severity) - logs messages at the specified severity level. The // GTEST_LOG_(severity) - logs messages at the specified severity level. The
// message itself is streamed into the macro. // message itself is streamed into the macro.
// LogToStderr() - directs all log messages to stderr. // LogToStderr() - directs all log messages to stderr.
// FlushInfoLog() - flushes informational log messages. // FlushInfoLog() - flushes informational log messages.
enum GTestLogSeverity { enum GTestLogSeverity {
GTEST_INFO, GTEST_INFO,
GTEST_WARNING, GTEST_WARNING,
GTEST_ERROR, GTEST_ERROR,
skipping to change at line 793 skipping to change at line 963
// doesn't expand to a balanced 'if' statement, so enclose the macro // doesn't expand to a balanced 'if' statement, so enclose the macro
// in {} if you need to use it as the only statement in an 'if' // in {} if you need to use it as the only statement in an 'if'
// branch. // branch.
#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \ #define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
if (const int gtest_error = (posix_call)) \ if (const int gtest_error = (posix_call)) \
GTEST_LOG_(FATAL) << #posix_call << "failed with error " \ GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
<< gtest_error << gtest_error
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
// //
// Use ImplicitCast_ as a safe version of static_cast for upcasting in
// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
// const Foo*). When you use ImplicitCast_, the compiler checks that
// the cast is safe. Such explicit ImplicitCast_s are necessary in
// surprisingly many situations where C++ demands an exact type match
// instead of an argument type convertable to a target type.
//
// The syntax for using ImplicitCast_ is the same as for static_cast:
//
// ImplicitCast_<ToType>(expr)
//
// ImplicitCast_ would have been part of the C++ standard library,
// but the proposal was submitted too late. It will probably make
// its way into the language in the future.
//
// This relatively ugly name is intentional. It prevents clashes with
// similar functions users may have (e.g., implicit_cast). The internal
// namespace alone is not enough because the function can be found by ADL.
template<typename To>
inline To ImplicitCast_(To x) { return x; }
// When you upcast (that is, cast a pointer from type Foo to type
// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
// always succeed. When you downcast (that is, cast a pointer from
// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
// how do you know the pointer is really of type SubclassOfFoo? It
// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus,
// when you downcast, you should use this macro. In debug mode, we
// 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<>
// instead. Thus, it's important to test in debug mode to make sure
// the cast is legal!
// This is the only place in the code we should use dynamic_cast<>.
// In particular, you SHOULDN'T be using dynamic_cast<> in order to
// do RTTI (eg code like this:
// if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
// if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
// You should design the code some other way not to need this.
//
// This relatively ugly name is intentional. It prevents clashes with
// similar functions users may have (e.g., down_cast). The internal
// namespace alone is not enough because the function can be found by ADL.
template<typename To, typename From> // use like this: DownCast_<T*>(foo);
inline To DownCast_(From* f) { // so we only accept pointers
// 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
// optimized build at run-time, as it will be optimized away
// completely.
if (false) {
const To to = NULL;
::testing::internal::ImplicitCast_<From*>(to);
}
#if GTEST_HAS_RTTI
// RTTI: debug mode only!
GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
#endif
return static_cast<To>(f);
}
// Downcasts the pointer of type Base to Derived. // Downcasts the pointer of type Base to Derived.
// Derived must be a subclass of Base. The parameter MUST // Derived must be a subclass of Base. The parameter MUST
// point to a class of type Derived, not any subclass of it. // point to a class of type Derived, not any subclass of it.
// When RTTI is available, the function performs a runtime // When RTTI is available, the function performs a runtime
// check to enforce this. // check to enforce this.
template <class Derived, class Base> template <class Derived, class Base>
Derived* CheckedDowncastToActualType(Base* base) { Derived* CheckedDowncastToActualType(Base* base) {
#if GTEST_HAS_RTTI #if GTEST_HAS_RTTI
GTEST_CHECK_(typeid(*base) == typeid(Derived)); GTEST_CHECK_(typeid(*base) == typeid(Derived));
return dynamic_cast<Derived*>(base); // NOLINT return dynamic_cast<Derived*>(base); // NOLINT
#else #else
return static_cast<Derived*>(base); // Poor man's downcast. return static_cast<Derived*>(base); // Poor man's downcast.
#endif #endif
} }
#if GTEST_HAS_STREAM_REDIRECTION_ #if GTEST_HAS_STREAM_REDIRECTION
// Defines the stderr capturer: // Defines the stderr capturer:
// CaptureStdout - starts capturing stdout. // CaptureStdout - starts capturing stdout.
// GetCapturedStdout - stops capturing stdout and returns the captured st ring. // GetCapturedStdout - stops capturing stdout and returns the captured st ring.
// CaptureStderr - starts capturing stderr. // CaptureStderr - starts capturing stderr.
// GetCapturedStderr - stops capturing stderr and returns the captured st ring. // GetCapturedStderr - stops capturing stderr and returns the captured st ring.
// //
GTEST_API_ void CaptureStdout(); GTEST_API_ void CaptureStdout();
GTEST_API_ String GetCapturedStdout(); GTEST_API_ String GetCapturedStdout();
GTEST_API_ void CaptureStderr(); GTEST_API_ void CaptureStderr();
GTEST_API_ String GetCapturedStderr(); GTEST_API_ String GetCapturedStderr();
#endif // GTEST_HAS_STREAM_REDIRECTION_ #endif // GTEST_HAS_STREAM_REDIRECTION
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
// A copy of all command line arguments. Set by InitGoogleTest(). // A copy of all command line arguments. Set by InitGoogleTest().
extern ::std::vector<String> g_argvs; extern ::std::vector<String> g_argvs;
// GTEST_HAS_DEATH_TEST implies we have ::std::string. // GTEST_HAS_DEATH_TEST implies we have ::std::string.
const ::std::vector<String>& GetArgvs(); const ::std::vector<String>& GetArgvs();
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
skipping to change at line 954 skipping to change at line 1184
const T param_; // User-supplied parameter to the thread function. const T param_; // User-supplied parameter to the thread function.
// When non-NULL, used to block execution until the controller thread // When non-NULL, used to block execution until the controller thread
// notifies. // notifies.
Notification* const thread_can_start_; Notification* const thread_can_start_;
bool finished_; // true iff we know that the thread function has finishe d. bool finished_; // true iff we know that the thread function has finishe d.
pthread_t thread_; // The native thread object. pthread_t thread_; // The native thread object.
GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam); GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
}; };
// gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD i
s
// true.
#include <pthread.h>
// MutexBase and Mutex implement mutex on pthreads-based platforms. They // MutexBase and Mutex implement mutex on pthreads-based platforms. They
// are used in conjunction with class MutexLock: // are used in conjunction with class MutexLock:
// //
// Mutex mutex; // Mutex mutex;
// ... // ...
// MutexLock lock(&mutex); // Acquires the mutex and releases it at the end // MutexLock lock(&mutex); // Acquires the mutex and releases it at the end
// // of the current scope. // // of the current scope.
// //
// MutexBase implements behavior for both statically and dynamically // MutexBase implements behavior for both statically and dynamically
// allocated mutexes. Do not use MutexBase directly. Instead, write // allocated mutexes. Do not use MutexBase directly. Instead, write
skipping to change at line 1012 skipping to change at line 1238
// be used before the dynamic initialization stage. Therefore we // be used before the dynamic initialization stage. Therefore we
// must be able to initialize a static mutex object at link time. // must be able to initialize a static mutex object at link time.
// This means MutexBase has to be a POD and its member variables // This means MutexBase has to be a POD and its member variables
// have to be public. // have to be public.
public: public:
pthread_mutex_t mutex_; // The underlying pthread mutex. pthread_mutex_t mutex_; // The underlying pthread mutex.
pthread_t owner_; // The thread holding the mutex; 0 means no one holds it. pthread_t owner_; // The thread holding the mutex; 0 means no one holds it.
}; };
// Forward-declares a static mutex. // Forward-declares a static mutex.
#define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
extern ::testing::internal::MutexBase mutex extern ::testing::internal::MutexBase mutex
// Defines and statically (i.e. at link time) initializes a static mutex. // Defines and statically (i.e. at link time) initializes a static mutex.
#define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, 0 } ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, 0 }
// The Mutex class can only be used for mutexes created at runtime. It // The Mutex class can only be used for mutexes created at runtime. It
// shares its API with MutexBase otherwise. // shares its API with MutexBase otherwise.
class Mutex : public MutexBase { class Mutex : public MutexBase {
public: public:
Mutex() { Mutex() {
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL)); GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
owner_ = 0; owner_ = 0;
} }
skipping to change at line 1163 skipping to change at line 1389
return new_holder->pointer(); return new_holder->pointer();
} }
// A key pthreads uses for looking up per-thread values. // A key pthreads uses for looking up per-thread values.
const pthread_key_t key_; const pthread_key_t key_;
const T default_; // The default value for each thread. const T default_; // The default value for each thread.
GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
}; };
#define GTEST_IS_THREADSAFE 1 # define GTEST_IS_THREADSAFE 1
#else // GTEST_HAS_PTHREAD #else // GTEST_HAS_PTHREAD
// A dummy implementation of synchronization primitives (mutex, lock, // A dummy implementation of synchronization primitives (mutex, lock,
// and thread-local variable). Necessary for compiling Google Test where // and thread-local variable). Necessary for compiling Google Test where
// mutex is not supported - using Google Test in multiple threads is not // mutex is not supported - using Google Test in multiple threads is not
// supported on such platforms. // supported on such platforms.
class Mutex { class Mutex {
public: public:
Mutex() {} Mutex() {}
void AssertHeld() const {} void AssertHeld() const {}
}; };
#define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
extern ::testing::internal::Mutex mutex extern ::testing::internal::Mutex mutex
#define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex # define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
class GTestMutexLock { class GTestMutexLock {
public: public:
explicit GTestMutexLock(Mutex*) {} // NOLINT explicit GTestMutexLock(Mutex*) {} // NOLINT
}; };
typedef GTestMutexLock MutexLock; typedef GTestMutexLock MutexLock;
template <typename T> template <typename T>
class ThreadLocal { class ThreadLocal {
skipping to change at line 1205 skipping to change at line 1431
T* pointer() { return &value_; } T* pointer() { return &value_; }
const T* pointer() const { return &value_; } const T* pointer() const { return &value_; }
const T& get() const { return value_; } const T& get() const { return value_; }
void set(const T& value) { value_ = value; } void set(const T& value) { value_ = value; }
private: private:
T value_; T value_;
}; };
// The above synchronization primitives have dummy implementations. // The above synchronization primitives have dummy implementations.
// Therefore Google Test is not thread-safe. // Therefore Google Test is not thread-safe.
#define GTEST_IS_THREADSAFE 0 # define GTEST_IS_THREADSAFE 0
#endif // GTEST_HAS_PTHREAD #endif // GTEST_HAS_PTHREAD
// Returns the number of threads running in the process, or 0 to indicate t hat // Returns the number of threads running in the process, or 0 to indicate t hat
// we cannot detect it. // we cannot detect it.
GTEST_API_ size_t GetThreadCount(); GTEST_API_ size_t GetThreadCount();
// Passing non-POD classes through ellipsis (...) crashes the ARM // Passing non-POD classes through ellipsis (...) crashes the ARM
// compiler and generates a warning in Sun Studio. The Nokia Symbian // compiler and generates a warning in Sun Studio. The Nokia Symbian
// and the IBM XL C/C++ compiler try to instantiate a copy constructor // and the IBM XL C/C++ compiler try to instantiate a copy constructor
// for objects passed through ellipsis (...), failing for uncopyable // for objects passed through ellipsis (...), failing for uncopyable
// objects. We define this to ensure that only POD is passed through // objects. We define this to ensure that only POD is passed through
// ellipsis on these systems. // ellipsis on these systems.
#if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC) #if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC)
// We lose support for NULL detection where the compiler doesn't like // We lose support for NULL detection where the compiler doesn't like
// passing non-POD classes through ellipsis (...). // passing non-POD classes through ellipsis (...).
#define GTEST_ELLIPSIS_NEEDS_POD_ 1 # define GTEST_ELLIPSIS_NEEDS_POD_ 1
#else #else
#define GTEST_CAN_COMPARE_NULL 1 # define GTEST_CAN_COMPARE_NULL 1
#endif #endif
// The Nokia Symbian and IBM XL C/C++ compilers cannot decide between // The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
// const T& and const T* in a function template. These compilers // const T& and const T* in a function template. These compilers
// _can_ decide between class template specializations for T and T*, // _can_ decide between class template specializations for T and T*,
// so a tr1::type_traits-like is_pointer works. // so a tr1::type_traits-like is_pointer works.
#if defined(__SYMBIAN32__) || defined(__IBMCPP__) #if defined(__SYMBIAN32__) || defined(__IBMCPP__)
#define GTEST_NEEDS_IS_POINTER_ 1 # define GTEST_NEEDS_IS_POINTER_ 1
#endif #endif
template <bool bool_value> template <bool bool_value>
struct bool_constant { struct bool_constant {
typedef bool_constant<bool_value> type; typedef bool_constant<bool_value> type;
static const bool value = bool_value; static const bool value = bool_value;
}; };
template <bool bool_value> const bool bool_constant<bool_value>::value; template <bool bool_value> const bool bool_constant<bool_value>::value;
typedef bool_constant<false> false_type; typedef bool_constant<false> false_type;
typedef bool_constant<true> true_type; typedef bool_constant<true> true_type;
template <typename T> template <typename T>
struct is_pointer : public false_type {}; struct is_pointer : public false_type {};
template <typename T> template <typename T>
struct is_pointer<T*> : public true_type {}; struct is_pointer<T*> : public true_type {};
template <typename Iterator>
struct IteratorTraits {
typedef typename Iterator::value_type value_type;
};
template <typename T>
struct IteratorTraits<T*> {
typedef T value_type;
};
template <typename T>
struct IteratorTraits<const T*> {
typedef T value_type;
};
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
#define GTEST_PATH_SEP_ "\\" # define GTEST_PATH_SEP_ "\\"
#define GTEST_HAS_ALT_PATH_SEP_ 1 # define GTEST_HAS_ALT_PATH_SEP_ 1
// The biggest signed integer type the compiler supports. // The biggest signed integer type the compiler supports.
typedef __int64 BiggestInt; typedef __int64 BiggestInt;
#else #else
#define GTEST_PATH_SEP_ "/" # define GTEST_PATH_SEP_ "/"
#define GTEST_HAS_ALT_PATH_SEP_ 0 # define GTEST_HAS_ALT_PATH_SEP_ 0
typedef long long BiggestInt; // NOLINT typedef long long BiggestInt; // NOLINT
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
// Utilities for char.
// isspace(int ch) and friends accept an unsigned char or EOF. char
// may be signed, depending on the compiler (or compiler flags).
// Therefore we need to cast a char to unsigned char before calling
// isspace(), etc.
inline bool IsAlpha(char ch) {
return isalpha(static_cast<unsigned char>(ch)) != 0;
}
inline bool IsAlNum(char ch) {
return isalnum(static_cast<unsigned char>(ch)) != 0;
}
inline bool IsDigit(char ch) {
return isdigit(static_cast<unsigned char>(ch)) != 0;
}
inline bool IsLower(char ch) {
return islower(static_cast<unsigned char>(ch)) != 0;
}
inline bool IsSpace(char ch) {
return isspace(static_cast<unsigned char>(ch)) != 0;
}
inline bool IsUpper(char ch) {
return isupper(static_cast<unsigned char>(ch)) != 0;
}
inline bool IsXDigit(char ch) {
return isxdigit(static_cast<unsigned char>(ch)) != 0;
}
inline char ToLower(char ch) {
return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
}
inline char ToUpper(char ch) {
return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
}
// The testing::internal::posix namespace holds wrappers for common // The testing::internal::posix namespace holds wrappers for common
// POSIX functions. These wrappers hide the differences between // POSIX functions. These wrappers hide the differences between
// Windows/MSVC and POSIX systems. Since some compilers define these // Windows/MSVC and POSIX systems. Since some compilers define these
// standard functions as macros, the wrapper cannot have the same name // standard functions as macros, the wrapper cannot have the same name
// as the wrapped function. // as the wrapped function.
namespace posix { namespace posix {
// Functions with a different name on Windows. // Functions with a different name on Windows.
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
typedef struct _stat StatStruct; typedef struct _stat StatStruct;
#ifdef __BORLANDC__ # ifdef __BORLANDC__
inline int IsATTY(int fd) { return isatty(fd); } inline int IsATTY(int fd) { return isatty(fd); }
inline int StrCaseCmp(const char* s1, const char* s2) { inline int StrCaseCmp(const char* s1, const char* s2) {
return stricmp(s1, s2); return stricmp(s1, s2);
} }
inline char* StrDup(const char* src) { return strdup(src); } inline char* StrDup(const char* src) { return strdup(src); }
#else // !__BORLANDC__ # else // !__BORLANDC__
#if GTEST_OS_WINDOWS_MOBILE # if GTEST_OS_WINDOWS_MOBILE
inline int IsATTY(int /* fd */) { return 0; } inline int IsATTY(int /* fd */) { return 0; }
#else # else
inline int IsATTY(int fd) { return _isatty(fd); } inline int IsATTY(int fd) { return _isatty(fd); }
#endif // GTEST_OS_WINDOWS_MOBILE # endif // GTEST_OS_WINDOWS_MOBILE
inline int StrCaseCmp(const char* s1, const char* s2) { inline int StrCaseCmp(const char* s1, const char* s2) {
return _stricmp(s1, s2); return _stricmp(s1, s2);
} }
inline char* StrDup(const char* src) { return _strdup(src); } inline char* StrDup(const char* src) { return _strdup(src); }
#endif // __BORLANDC__ # endif // __BORLANDC__
#if GTEST_OS_WINDOWS_MOBILE # if GTEST_OS_WINDOWS_MOBILE
inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)) ; } inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)) ; }
// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
// time and thus not defined there. // time and thus not defined there.
#else # else
inline int FileNo(FILE* file) { return _fileno(file); } inline int FileNo(FILE* file) { return _fileno(file); }
inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf ); } inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf ); }
inline int RmDir(const char* dir) { return _rmdir(dir); } inline int RmDir(const char* dir) { return _rmdir(dir); }
inline bool IsDir(const StatStruct& st) { inline bool IsDir(const StatStruct& st) {
return (_S_IFDIR & st.st_mode) != 0; return (_S_IFDIR & st.st_mode) != 0;
} }
#endif // GTEST_OS_WINDOWS_MOBILE # endif // GTEST_OS_WINDOWS_MOBILE
#else #else
typedef struct stat StatStruct; typedef struct stat StatStruct;
inline int FileNo(FILE* file) { return fileno(file); } inline int FileNo(FILE* file) { return fileno(file); }
inline int IsATTY(int fd) { return isatty(fd); } inline int IsATTY(int fd) { return isatty(fd); }
inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf) ; } inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf) ; }
inline int StrCaseCmp(const char* s1, const char* s2) { inline int StrCaseCmp(const char* s1, const char* s2) {
return strcasecmp(s1, s2); return strcasecmp(s1, s2);
skipping to change at line 1327 skipping to change at line 1604
inline char* StrDup(const char* src) { return strdup(src); } inline char* StrDup(const char* src) { return strdup(src); }
inline int RmDir(const char* dir) { return rmdir(dir); } inline int RmDir(const char* dir) { return rmdir(dir); }
inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
// Functions deprecated by MSVC 8.0. // Functions deprecated by MSVC 8.0.
#ifdef _MSC_VER #ifdef _MSC_VER
// Temporarily disable warning 4996 (deprecated function). // Temporarily disable warning 4996 (deprecated function).
#pragma warning(push) # pragma warning(push)
#pragma warning(disable:4996) # pragma warning(disable:4996)
#endif #endif
inline const char* StrNCpy(char* dest, const char* src, size_t n) { inline const char* StrNCpy(char* dest, const char* src, size_t n) {
return strncpy(dest, src, n); return strncpy(dest, src, n);
} }
// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and // ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
// StrError() aren't needed on Windows CE at this time and thus not // StrError() aren't needed on Windows CE at this time and thus not
// defined there. // defined there.
skipping to change at line 1377 skipping to change at line 1654
// Environment variables which we programmatically clear will be set to t he // Environment variables which we programmatically clear will be set to t he
// empty string rather than unset (NULL). Handle that case. // empty string rather than unset (NULL). Handle that case.
const char* const env = getenv(name); const char* const env = getenv(name);
return (env != NULL && env[0] != '\0') ? env : NULL; return (env != NULL && env[0] != '\0') ? env : NULL;
#else #else
return getenv(name); return getenv(name);
#endif #endif
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) // Restores the warning state. # pragma warning(pop) // Restores the warning state.
#endif #endif
#if GTEST_OS_WINDOWS_MOBILE #if GTEST_OS_WINDOWS_MOBILE
// Windows CE has no C library. The abort() function is used in // Windows CE has no C library. The abort() function is used in
// several places in Google Test. This implementation provides a reasonable // several places in Google Test. This implementation provides a reasonable
// imitation of standard behaviour. // imitation of standard behaviour.
void Abort(); void Abort();
#else #else
inline void Abort() { abort(); } inline void Abort() { abort(); }
#endif // GTEST_OS_WINDOWS_MOBILE #endif // GTEST_OS_WINDOWS_MOBILE
 End of changes. 113 change blocks. 
175 lines changed or deleted 459 lines changed or added


 gtest-spi.h   gtest-spi.h 
skipping to change at line 38 skipping to change at line 38
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// //
// Author: wan@google.com (Zhanyong Wan) // Author: wan@google.com (Zhanyong Wan)
// //
// Utilities for testing Google Test itself and code that uses Google Test // Utilities for testing Google Test itself and code that uses Google Test
// (e.g. frameworks built on top of Google Test). // (e.g. frameworks built on top of Google Test).
#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_ #ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_
#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_ #define GTEST_INCLUDE_GTEST_GTEST_SPI_H_
#include <gtest/gtest.h> #include "gtest/gtest.h"
namespace testing { namespace testing {
// 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
skipping to change at line 101 skipping to change at line 101
// 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 GTEST_API_ 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 string& 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_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker); GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
}; };
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
// A set of macros for testing Google Test assertions or code that's expect ed // A set of macros for testing Google Test assertions or code that's expect ed
// to generate Google Test fatal failures. It verifies that the given // to generate Google Test fatal failures. It verifies that the given
 End of changes. 3 change blocks. 
3 lines changed or deleted 3 lines changed or added


 gtest-string.h   gtest-string.h 
skipping to change at line 46 skipping to change at line 46
// 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__ #ifdef __BORLANDC__
// string.h is not guaranteed to provide strcpy on C++ Builder. // string.h is not guaranteed to provide strcpy on C++ Builder.
#include <mem.h> # include <mem.h>
#endif #endif
#include <string.h> #include <string.h>
#include <gtest/internal/gtest-port.h> #include "gtest/internal/gtest-port.h"
#include <string> #include <string>
namespace testing { namespace testing {
namespace internal { namespace internal {
// String - a UTF-8 string class. // String - a UTF-8 string class.
// //
// For historic reasons, we don't use std::string. // For historic reasons, we don't use std::string.
// //
skipping to change at line 299 skipping to change at line 299
} else { } else {
ConstructNonNull(rhs.c_str(), rhs.length()); ConstructNonNull(rhs.c_str(), rhs.length());
} }
} }
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 c_str_ 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 a_length) { void ConstructNonNull(const char* buffer, size_t a_length) {
char* const str = new char[a_length + 1]; char* const str = new char[a_length + 1];
memcpy(str, buffer, a_length); memcpy(str, buffer, a_length);
str[a_length] = '\0'; str[a_length] = '\0';
c_str_ = str; c_str_ = str;
length_ = a_length; length_ = a_length;
} }
skipping to change at line 332 skipping to change at line 332
if (c_str[i] == '\0') { if (c_str[i] == '\0') {
os << "\\0"; os << "\\0";
} 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 stringstream's buffer as a String. Each '\0'
// character in the buffer is replaced with "\\0". // character in the buffer is replaced with "\\0".
GTEST_API_ String StrStreamToString(StrStream* stream); GTEST_API_ String StringStreamToString(::std::stringstream* 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. 5 change blocks. 
5 lines changed or deleted 5 lines changed or added


 gtest-test-part.h   gtest-test-part.h 
skipping to change at line 38 skipping to change at line 38
// 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 <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 GTEST_API_ 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
 End of changes. 1 change blocks. 
2 lines changed or deleted 2 lines changed or added


 gtest-tuple.h   gtest-tuple.h 
skipping to change at line 47 skipping to change at line 47
#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.
// Sun Studio versions < 12 also have the above bug. // Sun Studio versions < 12 also have the above bug.
#if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590) #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, \
void, void, void> void, void, void>
#define GTEST_2_TUPLE_(T) tuple<T##0, T##1, void, void, void, void, void, \ #define GTEST_2_TUPLE_(T) tuple<T##0, T##1, void, void, void, void, void, \
void, void, void> void, void, void>
 End of changes. 2 change blocks. 
2 lines changed or deleted 2 lines changed or added


 gtest-type-util.h   gtest-type-util.h 
skipping to change at line 47 skipping to change at line 47
// tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND! // tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
// //
// Currently we support at most 50 types in a list, and at most 50 // Currently we support at most 50 types in a list, and at most 50
// type-parameterized tests in one type-parameterized test case. // type-parameterized tests in one type-parameterized test case.
// Please contact googletestframework@googlegroups.com if you need // Please contact googletestframework@googlegroups.com if you need
// more. // more.
#ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
#define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
#include <gtest/internal/gtest-port.h> #include "gtest/internal/gtest-port.h"
#include <gtest/internal/gtest-string.h> #include "gtest/internal/gtest-string.h"
#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__ # elif defined(__HP_aCC)
# include <acxx_demangle.h>
# endif // __GLIBCXX__
namespace testing { namespace testing {
namespace internal { namespace internal {
// 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
// two types are equal.
template <typename T1, typename T2>
struct AssertTypeEq;
template <typename T>
struct AssertTypeEq<T, T> {
typedef bool type;
};
// GetTypeName<T>() returns a human-readable name of type T. // GetTypeName<T>() returns a human-readable name of type T.
// NB: This function is also used in Google Mock, so don't move it inside o
f
// the typed-test-only section below.
template <typename T> template <typename T>
String GetTypeName() { String GetTypeName() {
#if GTEST_HAS_RTTI # if GTEST_HAS_RTTI
const char* const name = typeid(T).name(); const char* const name = typeid(T).name();
#ifdef __GLIBCXX__ # if defined(__GLIBCXX__) || defined(__HP_aCC)
int status = 0; int status = 0;
// gcc's implementation of typeid(T).name() mangles the type name, // gcc's implementation of typeid(T).name() mangles the type name,
// so we have to demangle it. // so we have to demangle it.
char* const readable_name = abi::__cxa_demangle(name, 0, 0, &status); # ifdef __GLIBCXX__
using abi::__cxa_demangle;
# endif // __GLIBCXX__
char* const readable_name = __cxa_demangle(name, 0, 0, &status);
const String name_str(status == 0 ? readable_name : name); const String name_str(status == 0 ? readable_name : name);
free(readable_name); free(readable_name);
return name_str; return name_str;
#else # else
return name; return name;
#endif // __GLIBCXX__ # endif // __GLIBCXX__ || __HP_aCC
# else
#else
return "<type>"; return "<type>";
#endif // GTEST_HAS_RTTI
# endif // GTEST_HAS_RTTI
} }
#if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
// 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
// two types are equal.
template <typename T1, typename T2>
struct AssertTypeEq;
template <typename T>
struct AssertTypeEq<T, T> {
typedef bool type;
};
// A unique type used as the default value for the arguments of class // A unique type used as the default value for the arguments of class
// template Types. This allows us to simulate variadic templates // template Types. This allows us to simulate variadic templates
// (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't // (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
// support directly. // support directly.
struct None {}; struct None {};
// The following family of struct and struct templates are used to // The following family of struct and struct templates are used to
// represent type lists. In particular, TypesN<T1, T2, ..., TN> // represent type lists. In particular, TypesN<T1, T2, ..., TN>
// represents a type list with N types (T1, T2, ..., and TN) in it. // represents a type list with N types (T1, T2, ..., and TN) in it.
// Except for Types0, every struct in the family has two member types: // Except for Types0, every struct in the family has two member types:
skipping to change at line 1613 skipping to change at line 1622
T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T 45, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T 45,
T46, T47, T48, T49, internal::None> { T46, T47, T48, T49, internal::None> {
typedef internal::Types49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T 12, typedef internal::Types49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T 12,
T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
T41, T42, T43, T44, T45, T46, T47, T48, T49> type; T41, T42, T43, T44, T45, T46, T47, T48, T49> type;
}; };
namespace internal { namespace internal {
#define GTEST_TEMPLATE_ template <typename T> class # define GTEST_TEMPLATE_ template <typename T> class
// The template "selector" struct TemplateSel<Tmpl> is used to // The template "selector" struct TemplateSel<Tmpl> is used to
// represent Tmpl, which must be a class template with one type // represent Tmpl, which must be a class template with one type
// parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined // parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
// as the type Tmpl<T>. This allows us to actually instantiate the // as the type Tmpl<T>. This allows us to actually instantiate the
// template "selected" by TemplateSel<Tmpl>. // template "selected" by TemplateSel<Tmpl>.
// //
// This trick is necessary for simulating typedef for class templates, // This trick is necessary for simulating typedef for class templates,
// which C++ doesn't support directly. // which C++ doesn't support directly.
template <GTEST_TEMPLATE_ Tmpl> template <GTEST_TEMPLATE_ Tmpl>
struct TemplateSel { struct TemplateSel {
template <typename T> template <typename T>
struct Bind { struct Bind {
typedef Tmpl<T> type; typedef Tmpl<T> type;
}; };
}; };
#define GTEST_BIND_(TmplSel, T) \ # define GTEST_BIND_(TmplSel, T) \
TmplSel::template Bind<T>::type TmplSel::template Bind<T>::type
// A unique struct template used as the default value for the // A unique struct template used as the default value for the
// arguments of class template Templates. This allows us to simulate // arguments of class template Templates. This allows us to simulate
// variadic templates (e.g. Templates<int>, Templates<int, double>, // variadic templates (e.g. Templates<int>, Templates<int, double>,
// and etc), which C++ doesn't support directly. // and etc), which C++ doesn't support directly.
template <typename T> template <typename T>
struct NoneT {}; struct NoneT {};
// The following family of struct and struct templates are used to // The following family of struct and struct templates are used to
skipping to change at line 3314 skipping to change at line 3323
struct TypeList<Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T1 3, struct TypeList<Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T1 3,
T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T 28, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T 28,
T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T 43, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T 43,
T44, T45, T46, T47, T48, T49, T50> > { T44, T45, T46, T47, T48, T49, T50> > {
typedef typename Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, typedef typename Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
T41, T42, T43, T44, T45, T46, T47, T48, T49, T50>::type type; T41, T42, T43, T44, T45, T46, T47, T48, T49, T50>::type type;
}; };
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing
#endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
 End of changes. 16 change blocks. 
30 lines changed or deleted 40 lines changed or added


 gtest-typed-test.h   gtest-typed-test.h 
skipping to change at line 149 skipping to change at line 149
// different instances. // different instances.
typedef testing::Types<char, int, unsigned int> MyTypes; typedef testing::Types<char, int, unsigned int> MyTypes;
INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes); INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
// If the type list contains only one type, you can write that type // If the type list contains only one type, you can write that type
// directly without Types<...>: // directly without Types<...>:
// INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int); // INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int);
#endif // 0 #endif // 0
#include <gtest/internal/gtest-port.h> #include "gtest/internal/gtest-port.h"
#include <gtest/internal/gtest-type-util.h> #include "gtest/internal/gtest-type-util.h"
// 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 // The 'Types' template argument below must have spaces around it
// since some compilers may choke on '>>' when passing a template // since some compilers may choke on '>>' when passing a template
// instance (e.g. Types<int>) // 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(); \
}; \ }; \
bool gtest_##CaseName##_##TestName##_registered_ = \ bool gtest_##CaseName##_##TestName##_registered_ GTEST_ATTRIBUTE_UNUSED_ = \
::testing::internal::TypeParameterizedTest< \ ::testing::internal::TypeParameterizedTest< \
CaseName, \ CaseName, \
::testing::internal::TemplateSel< \ ::testing::internal::TemplateSel< \
GTEST_TEST_CLASS_NAME_(CaseName, TestName)>, \ GTEST_TEST_CLASS_NAME_(CaseName, TestName)>, \
GTEST_TYPE_PARAMS_(CaseName)>::Register(\ GTEST_TYPE_PARAMS_(CaseName)>::Register(\
"", #CaseName, #TestName, 0); \ "", #CaseName, #TestName, 0); \
template <typename gtest_TypeParam_> \ template <typename gtest_TypeParam_> \
void GTEST_TEST_CLASS_NAME_(CaseName, TestName)<gtest_TypeParam_>::TestBo dy() void GTEST_TEST_CLASS_NAME_(CaseName, TestName)<gtest_TypeParam_>::TestBo dy()
#endif // GTEST_HAS_TYPED_TEST #endif // GTEST_HAS_TYPED_TEST
// Implements type-parameterized tests. // Implements type-parameterized tests.
#if GTEST_HAS_TYPED_TEST_P #if GTEST_HAS_TYPED_TEST_P
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
// //
// Expands to the namespace name that the type-parameterized tests for // Expands to the namespace name that the type-parameterized tests for
// the given type-parameterized test case are defined in. The exact // the given type-parameterized test case are defined in. The exact
// name of the namespace is subject to change without notice. // name of the namespace is subject to change without notice.
#define GTEST_CASE_NAMESPACE_(TestCaseName) \ # define GTEST_CASE_NAMESPACE_(TestCaseName) \
gtest_case_##TestCaseName##_ gtest_case_##TestCaseName##_
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
// //
// Expands to the name of the variable used to remember the names of // Expands to the name of the variable used to remember the names of
// the defined tests in the given test case. // the defined tests in the given test case.
#define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \ # define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \
gtest_typed_test_case_p_state_##TestCaseName##_ gtest_typed_test_case_p_state_##TestCaseName##_
// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY. // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.
// //
// Expands to the name of the variable used to remember the names of // Expands to the name of the variable used to remember the names of
// the registered tests in the given test case. // the registered tests in the given test case.
#define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \ # define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \
gtest_registered_test_names_##TestCaseName##_ gtest_registered_test_names_##TestCaseName##_
// The variables defined in the type-parameterized test macros are // The variables defined in the type-parameterized test macros are
// static as typically these macros are used in a .h file that can be // static as typically these macros are used in a .h file that can be
// #included in multiple translation units linked together. // #included in multiple translation units linked together.
#define TYPED_TEST_CASE_P(CaseName) \ # define TYPED_TEST_CASE_P(CaseName) \
static ::testing::internal::TypedTestCasePState \ static ::testing::internal::TypedTestCasePState \
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName) GTEST_TYPED_TEST_CASE_P_STATE_(CaseName)
#define TYPED_TEST_P(CaseName, TestName) \ # define TYPED_TEST_P(CaseName, TestName) \
namespace GTEST_CASE_NAMESPACE_(CaseName) { \ namespace GTEST_CASE_NAMESPACE_(CaseName) { \
template <typename gtest_TypeParam_> \ template <typename gtest_TypeParam_> \
class TestName : public CaseName<gtest_TypeParam_> { \ class TestName : 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(); \
}; \ }; \
static bool gtest_##TestName##_defined_ = \ static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \
GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).AddTestName(\ GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).AddTestName(\
__FILE__, __LINE__, #CaseName, #TestName); \ __FILE__, __LINE__, #CaseName, #TestName); \
} \ } \
template <typename gtest_TypeParam_> \ template <typename gtest_TypeParam_> \
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 // The 'Types' template argument below must have spaces around it
// since some compilers may choke on '>>' when passing a template // since some compilers may choke on '>>' when passing a template
// instance (e.g. Types<int>) // 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 GTEST_ATTRIBUTE_UNUSED_ = \
::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. 13 change blocks. 
15 lines changed or deleted 15 lines changed or added


 gtest.h   gtest.h 
skipping to change at line 57 skipping to change at line 57
// 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 <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-printers.h"
#include <gtest/gtest-test-part.h> #include "gtest/gtest_prod.h"
#include <gtest/gtest-typed-test.h> #include "gtest/gtest-test-part.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 Linux, in addition to ::std::string, Google also makes use of // On Linux, in addition to ::std::string, Google also makes use of
// class ::string, which has the same interface as ::std::string, but // class ::string, which has the same interface as ::std::string, but
// has a different implementation. // has a different implementation.
// //
// The user can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that // The user can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
// ::string is available AND is a distinct type to ::std::string, or // ::string is available AND is a distinct type to ::std::string, or
// define it to 0 to indicate otherwise. // define it to 0 to indicate otherwise.
// //
skipping to change at line 139 skipping to change at line 140
// This flag specifies the maximum number of stack frames to be // This flag specifies the maximum number of stack frames to be
// printed in a failure message. // printed in a failure message.
GTEST_DECLARE_int32_(stack_trace_depth); GTEST_DECLARE_int32_(stack_trace_depth);
// When this flag is specified, a failed assertion will throw an // When this flag is specified, a failed assertion will throw an
// exception if exceptions are enabled, or exit the program with a // exception if exceptions are enabled, or exit the program with a
// non-zero code otherwise. // non-zero code otherwise.
GTEST_DECLARE_bool_(throw_on_failure); GTEST_DECLARE_bool_(throw_on_failure);
// When this flag is set with a "host:port" string, on supported
// platforms test results are streamed to the specified port on
// the specified host machine.
GTEST_DECLARE_string_(stream_result_to);
// The upper limit for valid stack trace depths. // The upper limit for valid stack trace depths.
const int kMaxStackTraceDepth = 100; const int kMaxStackTraceDepth = 100;
namespace internal { namespace internal {
class AssertHelper; class AssertHelper;
class DefaultGlobalTestPartResultReporter; class DefaultGlobalTestPartResultReporter;
class ExecDeathTest; class ExecDeathTest;
class NoExecDeathTest; class NoExecDeathTest;
class FinalSuccessChecker; class FinalSuccessChecker;
class GTestFlagSaver; class GTestFlagSaver;
class TestInfoImpl;
class TestResultAccessor; class TestResultAccessor;
class TestEventListenersAccessor; class TestEventListenersAccessor;
class TestEventRepeater; class TestEventRepeater;
class WindowsDeathTest; class WindowsDeathTest;
class UnitTestImpl* GetUnitTestImpl(); class UnitTestImpl* GetUnitTestImpl();
void ReportFailureInUnknownLocation(TestPartResult::Type result_type, void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
const String& message); const String& message);
class PrettyUnitTestResultPrinter;
class XmlUnitTestResultPrinter;
// 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 in gtest-internal.h but defined here, so that it has access // Declared in gtest-internal.h but defined here, 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>
String StreamableToString(const T& streamable) { String StreamableToString(const T& streamable) {
return (Message() << streamable).GetString(); return (Message() << streamable).GetString();
} }
} // namespace internal } // namespace internal
// The friend relationship of some of these classes is cyclic.
// If we don't forward declare them the compiler might confuse the classes
// in friendship clauses with same named classes on the scope.
class Test;
class TestCase;
class TestInfo;
class UnitTest;
// 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 describes how it failed. // remembers a non-empty message that describes how it failed.
// //
// To create an instance of this class, use one of the factory functions // To create an instance of this class, use one of the factory functions
// (AssertionSuccess() and AssertionFailure()). // (AssertionSuccess() and AssertionFailure()).
// //
// This class is useful for two purposes: // This class is useful for two purposes:
// 1. Defining predicate functions to be used with Boolean test assertion s // 1. Defining predicate functions to be used with Boolean test assertion s
// EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts // EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
skipping to change at line 273 skipping to change at line 284
operator bool() const { return success_; } // NOLINT operator bool() const { return success_; } // NOLINT
// Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
AssertionResult operator!() const; AssertionResult operator!() const;
// Returns the text streamed into this AssertionResult. Test assertions // Returns the text streamed into this AssertionResult. Test assertions
// use it when they fail (i.e., the predicate's outcome doesn't match the // 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 // assertion's expectation). When nothing has been streamed into the
// object, returns an empty string. // object, returns an empty string.
const char* message() const { const char* message() const {
return message_.get() != NULL && message_->c_str() != NULL ? return message_.get() != NULL ? message_->c_str() : "";
message_->c_str() : "";
} }
// TODO(vladl@google.com): Remove this after making sure no clients use i t. // TODO(vladl@google.com): Remove this after making sure no clients use i t.
// Deprecated; please use message() instead. // Deprecated; please use message() instead.
const char* failure_message() const { return message(); } const char* failure_message() const { return message(); }
// Streams a custom failure message into this object. // Streams a custom failure message into this object.
template <typename T> AssertionResult& operator<<(const T& value); template <typename T> AssertionResult& operator<<(const T& value) {
AppendMessage(Message() << value);
return *this;
}
// Allows streaming basic output manipulators such as endl or flush into
// this object.
AssertionResult& operator<<(
::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
AppendMessage(Message() << basic_manipulator);
return *this;
}
private: private:
// No implementation - we want AssertionResult to be // Appends the contents of message to message_.
// copy-constructible but not assignable. void AppendMessage(const Message& a_message) {
void operator=(const AssertionResult& other); if (message_.get() == NULL)
message_.reset(new ::std::string);
message_->append(a_message.GetString().c_str());
}
// Stores result of the assertion predicate. // Stores result of the assertion predicate.
bool success_; bool success_;
// Stores the message describing the condition in case the expectation // Stores the message describing the condition in case the expectation
// construct is not satisfied with the predicate's outcome. // construct is not satisfied with the predicate's outcome.
// Referenced via a pointer to avoid taking too much stack frame space // Referenced via a pointer to avoid taking too much stack frame space
// with test assertions. // with test assertions.
internal::scoped_ptr<internal::String> message_; internal::scoped_ptr< ::std::string> message_;
}; // class AssertionResult
// Streams a custom failure message into this object. GTEST_DISALLOW_ASSIGN_(AssertionResult);
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.
GTEST_API_ AssertionResult AssertionSuccess(); GTEST_API_ AssertionResult AssertionSuccess();
// Makes a failed assertion result. // Makes a failed assertion result.
GTEST_API_ AssertionResult AssertionFailure(); GTEST_API_ AssertionResult AssertionFailure();
// Makes a failed assertion result with the given failure message. // Makes a failed assertion result with the given failure message.
// Deprecated; use AssertionFailure() << msg. // Deprecated; use AssertionFailure() << msg.
GTEST_API_ AssertionResult AssertionFailure(const Message& msg); GTEST_API_ AssertionResult AssertionFailure(const Message& msg);
skipping to change at line 343 skipping to change at line 358
// 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 GTEST_API_ Test { class GTEST_API_ Test {
public: public:
friend class internal::TestInfoImpl; friend class TestInfo;
// 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();
// Sets up the stuff shared by all tests in this test case. // Sets up the stuff shared by all tests in this test case.
skipping to change at line 420 skipping to change at line 435
// //
// A sub-class must implement this to define the test logic. // A sub-class must implement this to define the test logic.
// //
// DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM. // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
// Instead, use the TEST or TEST_F macro. // Instead, use the TEST or TEST_F macro.
virtual void TestBody() = 0; virtual void TestBody() = 0;
// Sets up, executes, and tears down the test. // Sets up, executes, and tears down the test.
void Run(); void Run();
// Deletes self. We deliberately pick an unusual name for this
// internal method to avoid clashing with names used in user TESTs.
void DeleteSelf_() { delete this; }
// Uses a GTestFlagSaver to save and restore all Google Test flags. // Uses a GTestFlagSaver to save and restore all Google Test flags.
const internal::GTestFlagSaver* const gtest_flag_saver_; const internal::GTestFlagSaver* const gtest_flag_saver_;
// Often a user mis-spells SetUp() as Setup() and spends a long time // Often a user mis-spells SetUp() as Setup() and spends a long time
// wondering why it is never called by Google Test. The declaration of // wondering why it is never called by Google Test. The declaration of
// the following method is solely for catching such an error at // the following method is solely for catching such an error at
// compile time: // compile time:
// //
// - The return type is deliberately chosen to be not void, so it // - The return type is deliberately chosen to be not void, so it
// will be a conflict if a user declares void Setup() in his test // will be a conflict if a user declares void Setup() in his test
skipping to change at line 534 skipping to change at line 553
// Returns the i-th test property. i can range from 0 to // Returns the i-th test property. i can range from 0 to
// test_property_count() - 1. If i is not in that range, aborts the // test_property_count() - 1. If i is not in that range, aborts the
// program. // program.
const TestProperty& GetTestProperty(int i) const; const TestProperty& GetTestProperty(int i) const;
private: private:
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::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 std::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.
skipping to change at line 614 skipping to change at line 632
// 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 GTEST_API_ 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 { return test_case_name_.c_str(); }
// Returns the test name. // Returns the test name.
const char* name() const; const char* name() const { return name_.c_str(); }
// Returns the test case comment. // Returns the name of the parameter type, or NULL if this is not a typed
const char* test_case_comment() const; // or a type-parameterized test.
const char* type_param() const {
if (type_param_.get() != NULL)
return type_param_->c_str();
return NULL;
}
// Returns the test comment. // Returns the text representation of the value parameter, or NULL if thi
const char* comment() const; s
// is not a value-parameterized test.
const char* value_param() const {
if (value_param_.get() != NULL)
return value_param_->c_str();
return NULL;
}
// Returns true if this test should run, that is if the test is not disab led // Returns true if this test should run, that is if the test is not disab led
// (or it is disabled but the also_run_disabled_tests flag has been speci fied) // (or it is disabled but the also_run_disabled_tests flag has been speci fied)
// and its full name matches the user-specified filter. // and its full name matches the user-specified filter.
// //
// Google Test allows the user to filter the tests by their full names. // Google Test allows the user to filter the tests by their full names.
// The full name of a test Bar in test case Foo is defined as // The full name of a test Bar in test case Foo is defined as
// "Foo.Bar". Only the tests that match the filter will run. // "Foo.Bar". Only the tests that match the filter will run.
// //
// A filter is a colon-separated list of glob (not regex) patterns, // A filter is a colon-separated list of glob (not regex) patterns,
// optionally followed by a '-' and a colon-separated list of // optionally followed by a '-' and a colon-separated list of
// negative patterns (tests to exclude). A test is run if it // negative patterns (tests to exclude). A test is run if it
// matches one of the positive patterns and does not match any of // matches one of the positive patterns and does not match any of
// the negative patterns. // the negative patterns.
// //
// For example, *A*:Foo.* is a filter that matches any string that // For example, *A*:Foo.* is a filter that matches any string that
// contains the character 'A' or starts with "Foo.". // contains the character 'A' or starts with "Foo.".
bool should_run() const; bool should_run() const { return should_run_; }
// Returns the result of the test. // Returns the result of the test.
const TestResult* result() const; const TestResult* result() const { return &result_; }
private: private:
#if GTEST_HAS_DEATH_TEST #if GTEST_HAS_DEATH_TEST
friend class internal::DefaultDeathTestFactory; friend class internal::DefaultDeathTestFactory;
#endif // GTEST_HAS_DEATH_TEST #endif // GTEST_HAS_DEATH_TEST
friend class Test; friend class Test;
friend class TestCase; friend class TestCase;
friend class internal::TestInfoImpl;
friend class internal::UnitTestImpl; friend class internal::UnitTestImpl;
friend TestInfo* internal::MakeAndRegisterTestInfo( friend TestInfo* internal::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* type_param,
const char* value_param,
internal::TypeId fixture_class_id, internal::TypeId fixture_class_id,
Test::SetUpTestCaseFunc set_up_tc, Test::SetUpTestCaseFunc set_up_tc,
Test::TearDownTestCaseFunc tear_down_tc, Test::TearDownTestCaseFunc tear_down_tc,
internal::TestFactoryBase* factory); internal::TestFactoryBase* factory);
// Returns true if this test matches the user-specified filter.
bool matches_filter() const;
// Increments the number of death tests encountered in this test so
// far.
int increment_death_test_count();
// Accessors for the implementation object.
internal::TestInfoImpl* impl() { return impl_; }
const internal::TestInfoImpl* impl() const { return impl_; }
// Constructs a TestInfo object. The newly constructed instance assumes // Constructs a TestInfo object. The newly constructed instance assumes
// ownership of the factory object. // ownership of the factory object.
TestInfo(const char* test_case_name, const char* name, TestInfo(const char* test_case_name, const char* name,
const char* test_case_comment, const char* comment, const char* a_type_param,
const char* a_value_param,
internal::TypeId fixture_class_id, internal::TypeId fixture_class_id,
internal::TestFactoryBase* factory); internal::TestFactoryBase* factory);
// An opaque implementation object. // Increments the number of death tests encountered in this test so
internal::TestInfoImpl* impl_; // far.
int increment_death_test_count() {
return result_.increment_death_test_count();
}
// Creates the test object, runs it, records its result, and then
// deletes it.
void Run();
static void ClearTestResult(TestInfo* test_info) {
test_info->result_.Clear();
}
// These fields are immutable properties of the test.
const std::string test_case_name_; // Test case name
const std::string name_; // Test name
// Name of the parameter type, or NULL if this is not a typed or a
// type-parameterized test.
const internal::scoped_ptr<const ::std::string> type_param_;
// Text representation of the value parameter, or NULL if this is not a
// value-parameterized test.
const internal::scoped_ptr<const ::std::string> value_param_;
const internal::TypeId fixture_class_id_; // ID of the test fixture cla
ss
bool should_run_; // True iff this test should run
bool is_disabled_; // True iff this test is disabled
bool matches_filter_; // True if this test matches the
// user-specified filter.
internal::TestFactoryBase* const factory_; // The factory that creates
// the test object
// This field is mutable and needs to be reset before running the
// test for the second time.
TestResult result_;
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 GTEST_API_ 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
// a_type_param: the name of the test's type parameter, or NULL if
// this is not a type-parameterized test.
// 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 case // tear_down_tc: pointer to the function that tears down the test case
TestCase(const char* name, const char* comment, TestCase(const char* name, const char* a_type_param,
Test::SetUpTestCaseFunc set_up_tc, Test::SetUpTestCaseFunc set_up_tc,
Test::TearDownTestCaseFunc tear_down_tc); Test::TearDownTestCaseFunc tear_down_tc);
// Destructor of TestCase. // Destructor of TestCase.
virtual ~TestCase(); virtual ~TestCase();
// Gets the name of the TestCase. // Gets the name of the TestCase.
const char* name() const { return name_.c_str(); } const char* name() const { return name_.c_str(); }
// Returns the test case comment. // Returns the name of the parameter type, or NULL if this is not a
const char* comment() const { return comment_.c_str(); } // type-parameterized test case.
const char* type_param() const {
if (type_param_.get() != NULL)
return type_param_->c_str();
return NULL;
}
// Returns true if any test in this test case should run. // Returns true if any test in this test case should run.
bool should_run() const { return should_run_; } bool should_run() const { return should_run_; }
// Gets the number of successful tests in this test case. // Gets the number of successful tests in this test case.
int successful_test_count() const; int successful_test_count() const;
// Gets the number of failed tests in this test case. // Gets the number of failed tests in this test case.
int failed_test_count() const; int failed_test_count() const;
skipping to change at line 779 skipping to change at line 837
void ClearResult(); void ClearResult();
// Clears the results of all tests in the given test case. // Clears the results of all tests in the given test case.
static void ClearTestCaseResult(TestCase* test_case) { static void ClearTestCaseResult(TestCase* test_case) {
test_case->ClearResult(); test_case->ClearResult();
} }
// Runs every test in this TestCase. // Runs every test in this TestCase.
void Run(); void Run();
// Runs SetUpTestCase() for this TestCase. This wrapper is needed
// for catching exceptions thrown from SetUpTestCase().
void RunSetUpTestCase() { (*set_up_tc_)(); }
// Runs TearDownTestCase() for this TestCase. This wrapper is
// needed for catching exceptions thrown from TearDownTestCase().
void RunTearDownTestCase() { (*tear_down_tc_)(); }
// Returns true iff test passed. // Returns true iff test passed.
static bool TestPassed(const TestInfo * test_info); static bool TestPassed(const TestInfo* test_info) {
return test_info->should_run() && test_info->result()->Passed();
}
// Returns true iff test failed. // Returns true iff test failed.
static bool TestFailed(const TestInfo * test_info); static bool TestFailed(const TestInfo* test_info) {
return test_info->should_run() && test_info->result()->Failed();
}
// Returns true iff test is disabled. // Returns true iff test is disabled.
static bool TestDisabled(const TestInfo * test_info); static bool TestDisabled(const TestInfo* test_info) {
return test_info->is_disabled_;
}
// Returns true if the given test should run. // Returns true if the given test should run.
static bool ShouldRunTest(const TestInfo *test_info); static bool ShouldRunTest(const TestInfo* test_info) {
return test_info->should_run();
}
// Shuffles the tests in this test case. // Shuffles the tests in this test case.
void ShuffleTests(internal::Random* random); void ShuffleTests(internal::Random* random);
// 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. // Name of the parameter type, or NULL if this is not a typed or a
internal::String comment_; // type-parameterized test.
const internal::scoped_ptr<const ::std::string> type_param_;
// 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.
std::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.
std::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.
skipping to change at line 879 skipping to change at line 954
// Fired after environment set-up for each iteration of tests ends. // Fired after environment set-up for each iteration of tests ends.
virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0; virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
// Fired before the test case starts. // Fired before the test case starts.
virtual void OnTestCaseStart(const TestCase& test_case) = 0; virtual void OnTestCaseStart(const TestCase& test_case) = 0;
// Fired before the test starts. // Fired before the test starts.
virtual void OnTestStart(const TestInfo& test_info) = 0; virtual void OnTestStart(const TestInfo& test_info) = 0;
// Fired after a failed assertion or a SUCCESS(). // Fired after a failed assertion or a SUCCEED() invocation.
virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0 ; virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0 ;
// Fired after the test ends. // Fired after the test ends.
virtual void OnTestEnd(const TestInfo& test_info) = 0; virtual void OnTestEnd(const TestInfo& test_info) = 0;
// Fired after the test case ends. // Fired after the test case ends.
virtual void OnTestCaseEnd(const TestCase& test_case) = 0; virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
// Fired before environment tear-down for each iteration of tests starts. // Fired before environment tear-down for each iteration of tests starts.
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0; virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
skipping to change at line 964 skipping to change at line 1039
// controlled by this flag and substitute it with custom one. Note that // controlled by this flag and substitute it with custom one. Note that
// removing this object from the listener list with Release transfers its // removing this object from the listener list with Release transfers its
// ownership to the caller and makes this function return NULL the next // ownership to the caller and makes this function return NULL the next
// time. // time.
TestEventListener* default_xml_generator() const { TestEventListener* default_xml_generator() const {
return default_xml_generator_; return default_xml_generator_;
} }
private: private:
friend class TestCase; friend class TestCase;
friend class TestInfo;
friend class internal::DefaultGlobalTestPartResultReporter; friend class internal::DefaultGlobalTestPartResultReporter;
friend class internal::NoExecDeathTest; friend class internal::NoExecDeathTest;
friend class internal::TestEventListenersAccessor; friend class internal::TestEventListenersAccessor;
friend class internal::TestInfoImpl;
friend class internal::UnitTestImpl; friend class internal::UnitTestImpl;
// Returns repeater that broadcasts the TestEventListener events to all // Returns repeater that broadcasts the TestEventListener events to all
// subscribers. // subscribers.
TestEventListener* repeater(); TestEventListener* repeater();
// Sets the default_result_printer attribute to the provided listener. // Sets the default_result_printer attribute to the provided listener.
// The listener is also added to the listener list and previous // The listener is also added to the listener list and previous
// default_result_printer is removed from it and deleted. The listener ca n // default_result_printer is removed from it and deleted. The listener ca n
// also be NULL in which case it will not be added to the list. Does // also be NULL in which case it will not be added to the list. Does
skipping to change at line 1209 skipping to change at line 1284
// //
// Calling the function for the second time has no user-visible effect. // Calling the function for the second time has no user-visible effect.
GTEST_API_ 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.
GTEST_API_ 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.
GTEST_API_ inline String FormatForFailureMessage(const ::std::string& str)
{
return (Message() << '"' << str << '"').GetString();
}
#if GTEST_HAS_STD_WSTRING
GTEST_API_ inline String FormatForFailureMessage(const ::std::wstring& wstr
) {
return (Message() << "L\"" << wstr << '"').GetString();
}
#endif // GTEST_HAS_STD_WSTRING
// These overloaded versions handle ::string and ::wstring.
#if GTEST_HAS_GLOBAL_STRING
GTEST_API_ inline String FormatForFailureMessage(const ::string& str) {
return (Message() << '"' << str << '"').GetString();
}
#endif // GTEST_HAS_GLOBAL_STRING
#if GTEST_HAS_GLOBAL_WSTRING
GTEST_API_ inline String FormatForFailureMessage(const ::wstring& wstr) {
return (Message() << "L\"" << wstr << '"').GetString();
}
#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.
// //
// The default implementation ignores the type of the other operand. // The default implementation ignores the type of the other operand.
// Some specialized versions are used to handle formatting wide or // Some specialized versions are used to handle formatting wide or
// narrow C strings. // narrow C strings.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
template <typename T1, typename T2> template <typename T1, typename T2>
String FormatForComparisonFailureMessage(const T1& value, String FormatForComparisonFailureMessage(const T1& value,
const T2& /* other_operand */) { const T2& /* other_operand */) {
return FormatForFailureMessage(value); // C++Builder compiles this incorrectly if the namespace isn't explicitly
// given.
return ::testing::PrintToString(value);
} }
// The helper function for {ASSERT|EXPECT}_EQ. // The helper function for {ASSERT|EXPECT}_EQ.
template <typename T1, typename T2> template <typename T1, typename T2>
AssertionResult CmpHelperEQ(const char* expected_expression, AssertionResult CmpHelperEQ(const char* expected_expression,
const char* actual_expression, const char* actual_expression,
const T1& expected, const T1& expected,
const T2& actual) { const T2& actual) {
#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:4389) // Temporarily disables warning on # pragma warning(disable:4389) // Temporarily disables warning on
// signed/unsigned mismatch. // signed/unsigned mismatch.
#endif #endif
if (expected == actual) { if (expected == actual) {
return AssertionSuccess(); return AssertionSuccess();
} }
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning(pop) // Restores the warning state. # pragma warning(pop) // Restores the warning state.
#endif #endif
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
skipping to change at line 1319 skipping to change at line 1372
static AssertionResult Compare(const char* expected_expression, static AssertionResult Compare(const char* expected_expression,
const char* actual_expression, const char* actual_expression,
BiggestInt expected, BiggestInt expected,
BiggestInt actual) { BiggestInt actual) {
return CmpHelperEQ(expected_expression, actual_expression, expected, return CmpHelperEQ(expected_expression, actual_expression, expected,
actual); actual);
} }
}; };
// This specialization is used when the first argument to ASSERT_EQ() // This specialization is used when the first argument to ASSERT_EQ()
// is a null pointer literal. // is a null pointer literal, like NULL, false, or 0.
template <> template <>
class EqHelper<true> { class EqHelper<true> {
public: public:
// We define two overloaded versions of Compare(). The first // We define two overloaded versions of Compare(). The first
// version will be picked when the second argument to ASSERT_EQ() is // version will be picked when the second argument to ASSERT_EQ() is
// NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or
// EXPECT_EQ(false, a_bool). // EXPECT_EQ(false, a_bool).
template <typename T1, typename T2> template <typename T1, typename T2>
static AssertionResult Compare(const char* expected_expression, static AssertionResult Compare(
const char* actual_expression, const char* expected_expression,
const T1& expected, const char* actual_expression,
const T2& actual) { const T1& expected,
const T2& actual,
// The following line prevents this overload from being considered if
T2
// is not a pointer type. We need this because ASSERT_EQ(NULL, my_pt
r)
// expands to Compare("", "", NULL, my_ptr), which requires a convers
ion
// to match the Secret* in the other overload, which would otherwise
make
// this template match better.
typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
return CmpHelperEQ(expected_expression, actual_expression, expected, return CmpHelperEQ(expected_expression, actual_expression, expected,
actual); actual);
} }
// This version will be picked when the second argument to // This version will be picked when the second argument to ASSERT_EQ() is
// ASSERT_EQ() is a pointer, e.g. ASSERT_EQ(NULL, a_pointer). a
template <typename T1, typename T2> // pointer, e.g. ASSERT_EQ(NULL, a_pointer).
static AssertionResult Compare(const char* expected_expression, template <typename T>
const char* actual_expression, static AssertionResult Compare(
const T1& /* expected */, const char* expected_expression,
T2* actual) { const char* actual_expression,
// We used to have a second template parameter instead of Secret*. T
hat
// template parameter would deduce to 'long', making this a better ma
tch
// than the first overload even without the first overload's EnableIf
.
// Unfortunately, gcc with -Wconversion-null warns when "passing NULL
to
// non-pointer argument" (even a deduced integral argument), so the o
ld
// implementation caused warnings in user code.
Secret* /* expected (NULL) */,
T* actual) {
// We already know that 'expected' is a null pointer. // We already know that 'expected' is a null pointer.
return CmpHelperEQ(expected_expression, actual_expression, return CmpHelperEQ(expected_expression, actual_expression,
static_cast<T2*>(NULL), actual); static_cast<T*>(NULL), actual);
} }
}; };
// A macro for implementing the helper functions needed to implement // A macro for implementing the helper functions needed to implement
// ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste // ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste
// of similar code. // of similar code.
// //
// For each templatized helper function, we also define an overloaded // For each templatized helper function, we also define an overloaded
// version for BiggestInt in order to reduce code bloat and allow // version for BiggestInt in order to reduce code bloat and allow
// anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled // anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled
// with gcc 4. // with gcc 4.
// //
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM. // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
#define GTEST_IMPL_CMP_HELPER_(op_name, op)\ #define GTEST_IMPL_CMP_HELPER_(op_name, op)\
template <typename T1, typename T2>\ template <typename T1, typename T2>\
AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \ AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
const T1& val1, const T2& val2) {\ const T1& val1, const T2& val2) {\
if (val1 op val2) {\ if (val1 op val2) {\
return AssertionSuccess();\ return AssertionSuccess();\
} else {\ } else {\
Message msg;\ return AssertionFailure() \
msg << "Expected: (" << expr1 << ") " #op " (" << expr2\ << "Expected: (" << expr1 << ") " #op " (" << expr2\
<< "), actual: " << FormatForComparisonFailureMessage(val1, val2)\ << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
<< " vs " << FormatForComparisonFailureMessage(val2, val1);\ << " vs " << FormatForComparisonFailureMessage(val2, val1);\
return AssertionFailure(msg);\
}\ }\
}\ }\
GTEST_API_ AssertionResult CmpHelper##op_name(\ GTEST_API_ AssertionResult CmpHelper##op_name(\
const char* expr1, const char* expr2, 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
skipping to change at line 1497 skipping to change at line 1563
AssertionResult CmpHelperFloatingPointEQ(const char* expected_expression, AssertionResult CmpHelperFloatingPointEQ(const char* expected_expression,
const char* actual_expression, const char* actual_expression,
RawType expected, RawType expected,
RawType actual) { RawType actual) {
const FloatingPoint<RawType> lhs(expected), rhs(actual); const FloatingPoint<RawType> lhs(expected), rhs(actual);
if (lhs.AlmostEquals(rhs)) { if (lhs.AlmostEquals(rhs)) {
return AssertionSuccess(); return AssertionSuccess();
} }
StrStream expected_ss; ::std::stringstream expected_ss;
expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2) expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
<< expected; << expected;
StrStream actual_ss; ::std::stringstream actual_ss;
actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2 ) actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2 )
<< actual; << actual;
return EqFailure(expected_expression, return EqFailure(expected_expression,
actual_expression, actual_expression,
StrStreamToString(&expected_ss), StringStreamToString(&expected_ss),
StrStreamToString(&actual_ss), StringStreamToString(&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.
GTEST_API_ 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,
skipping to change at line 1566 skipping to change at line 1632
}; };
AssertHelperData* const data_; AssertHelperData* const data_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper); GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);
}; };
} // namespace internal } // namespace internal
#if GTEST_HAS_PARAM_TEST #if GTEST_HAS_PARAM_TEST
// The abstract base class that all value-parameterized tests inherit from. // The pure interface class that all value-parameterized tests inherit from
.
// A value-parameterized class must inherit from both ::testing::Test and
// ::testing::WithParamInterface. In most cases that just means inheriting
// from ::testing::TestWithParam, but more complicated test hierarchies
// may need to inherit from Test and WithParamInterface at different levels
.
// //
// This class adds support for accessing the test parameter value via // This interface has support for accessing the test parameter value via
// the GetParam() method. // the GetParam() method.
// //
// Use it with one of the parameter generator defining functions, like Rang e(), // Use it with one of the parameter generator defining functions, like Rang e(),
// Values(), ValuesIn(), Bool(), and Combine(). // Values(), ValuesIn(), Bool(), and Combine().
// //
// class FooTest : public ::testing::TestWithParam<int> { // class FooTest : public ::testing::TestWithParam<int> {
// protected: // protected:
// FooTest() { // FooTest() {
// // Can use GetParam() here. // // Can use GetParam() here.
// } // }
skipping to change at line 1597 skipping to change at line 1667
// } // }
// }; // };
// TEST_P(FooTest, DoesBar) { // TEST_P(FooTest, DoesBar) {
// // Can use GetParam() method here. // // Can use GetParam() method here.
// Foo foo; // Foo foo;
// ASSERT_TRUE(foo.DoesBar(GetParam())); // ASSERT_TRUE(foo.DoesBar(GetParam()));
// } // }
// INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10)) ; // INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10)) ;
template <typename T> template <typename T>
class TestWithParam : public Test { class WithParamInterface {
public: public:
typedef T ParamType; typedef T ParamType;
virtual ~WithParamInterface() {}
// The current parameter value. Is also available in the test fixture's // The current parameter value. Is also available in the test fixture's
// constructor. // constructor. This member function is non-static, even though it only
// references static data, to reduce the opportunity for incorrect uses
// like writing 'WithParamInterface<bool>::GetParam()' for a test that
// uses a fixture whose parameter type is int.
const ParamType& GetParam() const { return *parameter_; } const ParamType& GetParam() const { return *parameter_; }
private: private:
// Sets parameter value. The caller is responsible for making sure the va lue // Sets parameter value. The caller is responsible for making sure the va lue
// remains alive and unchanged throughout the current test. // remains alive and unchanged throughout the current test.
static void SetParam(const ParamType* parameter) { static void SetParam(const ParamType* parameter) {
parameter_ = parameter; parameter_ = parameter;
} }
// Static value used for accessing parameter during a test lifetime. // Static value used for accessing parameter during a test lifetime.
static const ParamType* parameter_; static const ParamType* parameter_;
// TestClass must be a subclass of TestWithParam<T>. // TestClass must be a subclass of WithParamInterface<T> and Test.
template <class TestClass> friend class internal::ParameterizedTestFactor y; template <class TestClass> friend class internal::ParameterizedTestFactor y;
}; };
template <typename T> template <typename T>
const T* TestWithParam<T>::parameter_ = NULL; const T* WithParamInterface<T>::parameter_ = NULL;
// Most value-parameterized classes can ignore the existence of
// WithParamInterface, and can just inherit from ::testing::TestWithParam.
template <typename T>
class TestWithParam : public Test, public WithParamInterface<T> {
};
#endif // GTEST_HAS_PARAM_TEST #endif // GTEST_HAS_PARAM_TEST
// Macros for indicating success/failure in test code. // Macros for indicating success/failure in test code.
// ADD_FAILURE unconditionally adds a failure to the current test. // ADD_FAILURE unconditionally adds a failure to the current test.
// SUCCEED generates a success - it doesn't automatically make the // SUCCEED generates a success - it doesn't automatically make the
// current test successful, as a test is only successful when it has // current test successful, as a test is only successful when it has
// no failure. // no failure.
// //
skipping to change at line 1652 skipping to change at line 1733
// //
// 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 nonfatal failure at the given source file location with
// a generic message.
#define ADD_FAILURE_AT(file, line) \
GTEST_MESSAGE_AT_(file, line, "Failed", \
::testing::TestPartResult::kNonFatalFailure)
// Generates a fatal failure with a generic message. // Generates a fatal failure with a generic message.
#define GTEST_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 // Define this macro to 1 to omit the definition of FAIL(), which is a
// generic name and clashes with some other libraries. // generic name and clashes with some other libraries.
#if !GTEST_DONT_DEFINE_FAIL #if !GTEST_DONT_DEFINE_FAIL
#define FAIL() GTEST_FAIL() # define FAIL() GTEST_FAIL()
#endif #endif
// Generates a success with a generic message. // Generates a success with a generic message.
#define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded") #define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
// Define this macro to 1 to omit the definition of SUCCEED(), which // Define this macro to 1 to omit the definition of SUCCEED(), which
// is a generic name and clashes with some other libraries. // is a generic name and clashes with some other libraries.
#if !GTEST_DONT_DEFINE_SUCCEED #if !GTEST_DONT_DEFINE_SUCCEED
#define SUCCEED() GTEST_SUCCEED() # define SUCCEED() GTEST_SUCCEED()
#endif #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 1710 skipping to change at line 1797
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) \
GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \ GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
GTEST_FATAL_FAILURE_) GTEST_FATAL_FAILURE_)
// Includes the auto-generated header that implements a family of // Includes the auto-generated header that implements a family of
// generic predicate assertion macros. // generic predicate assertion macros.
#include <gtest/gtest_pred_impl.h> #include "gtest/gtest_pred_impl.h"
// Macros for testing equalities and inequalities. // Macros for testing equalities and inequalities.
// //
// * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual // * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual
// * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2 // * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
// * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2 // * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
// * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2 // * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
// * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2 // * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
// * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2 // * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
// //
skipping to change at line 1773 skipping to change at line 1860
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual)
#define EXPECT_LE(val1, val2) \ #define EXPECT_LE(val1, val2) \
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
#define EXPECT_LT(val1, val2) \ #define EXPECT_LT(val1, val2) \
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
#define EXPECT_GE(val1, val2) \ #define EXPECT_GE(val1, val2) \
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
#define EXPECT_GT(val1, val2) \ #define EXPECT_GT(val1, val2) \
EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
#define ASSERT_EQ(expected, actual) \ #define GTEST_ASSERT_EQ(expected, actual) \
ASSERT_PRED_FORMAT2(::testing::internal:: \ ASSERT_PRED_FORMAT2(::testing::internal:: \
EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \ EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
expected, actual) expected, actual)
#define ASSERT_NE(val1, val2) \ #define GTEST_ASSERT_NE(val1, val2) \
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2) ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
#define ASSERT_LE(val1, val2) \ #define GTEST_ASSERT_LE(val1, val2) \
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2) ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
#define ASSERT_LT(val1, val2) \ #define GTEST_ASSERT_LT(val1, val2) \
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2) ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
#define ASSERT_GE(val1, val2) \ #define GTEST_ASSERT_GE(val1, val2) \
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2) ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
#define ASSERT_GT(val1, val2) \ #define GTEST_ASSERT_GT(val1, val2) \
ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
// ASSERT_XY(), which clashes with some users' own code.
#if !GTEST_DONT_DEFINE_ASSERT_EQ
# define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
#endif
#if !GTEST_DONT_DEFINE_ASSERT_NE
# define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
#endif
#if !GTEST_DONT_DEFINE_ASSERT_LE
# define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
#endif
#if !GTEST_DONT_DEFINE_ASSERT_LT
# define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
#endif
#if !GTEST_DONT_DEFINE_ASSERT_GE
# define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
#endif
#if !GTEST_DONT_DEFINE_ASSERT_GT
# define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
#endif
// C String Comparisons. All tests treat NULL and any non-NULL string // C String Comparisons. All tests treat NULL and any non-NULL string
// as different. Two NULLs are equal. // as different. Two NULLs are equal.
// //
// * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2 // * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2
// * {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2 // * {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2
// * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring ca se // * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring ca se
// * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring ca se // * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring ca se
// //
// For wide or narrow string objects, you can use the // For wide or narrow string objects, you can use the
// {ASSERT|EXPECT}_??() macros. // {ASSERT|EXPECT}_??() macros.
skipping to change at line 1883 skipping to change at line 1997
// 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
// string representation of the error, if available, as well as the // string representation of the error, if available, as well as the
// hex result code. // hex result code.
#define EXPECT_HRESULT_SUCCEEDED(expr) \ # define EXPECT_HRESULT_SUCCEEDED(expr) \
EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
#define ASSERT_HRESULT_SUCCEEDED(expr) \ # define ASSERT_HRESULT_SUCCEEDED(expr) \
ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr)) ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
#define EXPECT_HRESULT_FAILED(expr) \ # define EXPECT_HRESULT_FAILED(expr) \
EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
#define ASSERT_HRESULT_FAILED(expr) \ # define ASSERT_HRESULT_FAILED(expr) \
ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr)) ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
#endif // GTEST_OS_WINDOWS #endif // GTEST_OS_WINDOWS
// Macros that execute statement and check that it doesn't generate new fat al // Macros that execute statement and check that it doesn't generate new fat al
// failures in the current thread. // failures in the current thread.
// //
// * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement); // * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
// //
// Examples: // Examples:
skipping to change at line 1927 skipping to change at line 2041
// The message argument can be anything streamable to std::ostream. // The message argument can be anything streamable to std::ostream.
// //
// In the implementation, we include the current line number as part // In the implementation, we include the current line number as part
// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s // of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
// to appear in the same block - as long as they are on different // to appear in the same block - as long as they are on different
// lines. // lines.
#define SCOPED_TRACE(message) \ #define SCOPED_TRACE(message) \
::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE __)(\ ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE __)(\
__FILE__, __LINE__, ::testing::Message() << (message)) __FILE__, __LINE__, ::testing::Message() << (message))
namespace internal {
// This template is declared, but intentionally undefined.
template <typename T1, typename T2>
struct StaticAssertTypeEqHelper;
template <typename T>
struct StaticAssertTypeEqHelper<T, T> {};
} // namespace internal
// Compile-time assertion for type equality. // Compile-time assertion for type equality.
// StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are // StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
// the same type. The value it returns is not interesting. // the same type. The value it returns is not interesting.
// //
// Instead of making StaticAssertTypeEq a class template, we make it a // Instead of making StaticAssertTypeEq a class template, we make it a
// function template that invokes a helper class template. This // function template that invokes a helper class template. This
// prevents a user from misusing StaticAssertTypeEq<T1, T2> by // prevents a user from misusing StaticAssertTypeEq<T1, T2> by
// defining objects of that type. // defining objects of that type.
// //
// CAVEAT: // CAVEAT:
skipping to change at line 1970 skipping to change at line 2073
// void Test1() { Foo<bool> foo; } // void Test1() { Foo<bool> foo; }
// //
// will NOT generate a compiler error, as Foo<bool>::Bar() is never // will NOT generate a compiler error, as Foo<bool>::Bar() is never
// actually instantiated. Instead, you need: // actually instantiated. Instead, you need:
// //
// void Test2() { Foo<bool> foo; foo.Bar(); } // void Test2() { Foo<bool> foo; foo.Bar(); }
// //
// to cause a compiler error. // to cause a compiler error.
template <typename T1, typename T2> template <typename T1, typename T2>
bool StaticAssertTypeEq() { bool StaticAssertTypeEq() {
internal::StaticAssertTypeEqHelper<T1, T2>(); (void)internal::StaticAssertTypeEqHelper<T1, T2>();
return true; return true;
} }
// Defines a test. // Defines a test.
// //
// The first parameter is the name of the test case, and the second // The first parameter is the name of the test case, and the second
// parameter is the name of the test within the test case. // parameter is the name of the test within the test case.
// //
// The convention is to end the test case name with "Test". For // The convention is to end the test case name with "Test". For
// example, a test case for the Foo class can be named FooTest. // example, a test case for the Foo class can be named FooTest.
skipping to change at line 2006 skipping to change at line 2109
// 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 GTEST_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 // Define this macro to 1 to omit the definition of TEST(), which
// is a generic name and clashes with some other libraries. // is a generic name and clashes with some other libraries.
#if !GTEST_DONT_DEFINE_TEST #if !GTEST_DONT_DEFINE_TEST
#define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_nam e) # define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_na me)
#endif #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:
 End of changes. 75 change blocks. 
148 lines changed or deleted 263 lines changed or added


 gtest_pred_impl.h   gtest_pred_impl.h 
skipping to change at line 30 skipping to change at line 30
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file is AUTOMATICALLY GENERATED on 10/02/2008 by command // This file is AUTOMATICALLY GENERATED on 09/24/2010 by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND! // 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
// //
// Implements a family of generic predicate assertion macros. // Implements a family of generic predicate assertion macros.
#ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ #ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
#define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_ #define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
// Makes sure this header is not included before gtest.h. // Makes sure this header is not included before gtest.h.
#ifndef GTEST_INCLUDE_GTEST_GTEST_H_ #ifndef GTEST_INCLUDE_GTEST_GTEST_H_
#error Do not include gtest_pred_impl.h directly. Include gtest.h instead. # error Do not include gtest_pred_impl.h directly. Include gtest.h instead .
#endif // GTEST_INCLUDE_GTEST_GTEST_H_ #endif // GTEST_INCLUDE_GTEST_GTEST_H_
// This header implements a family of generic predicate assertion // This header implements a family of generic predicate assertion
// macros: // macros:
// //
// ASSERT_PRED_FORMAT1(pred_format, v1) // ASSERT_PRED_FORMAT1(pred_format, v1)
// ASSERT_PRED_FORMAT2(pred_format, v1, v2) // ASSERT_PRED_FORMAT2(pred_format, v1, v2)
// ... // ...
// //
// where pred_format is a function or functor that takes n (in the // where pred_format is a function or functor that takes n (in the
skipping to change at line 92 skipping to change at line 92
// Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use // Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use
// this in your code. // this in your code.
template <typename Pred, template <typename Pred,
typename T1> typename T1>
AssertionResult AssertPred1Helper(const char* pred_text, AssertionResult AssertPred1Helper(const char* pred_text,
const char* e1, const char* e1,
Pred pred, Pred pred,
const T1& v1) { const T1& v1) {
if (pred(v1)) return AssertionSuccess(); if (pred(v1)) return AssertionSuccess();
Message msg; return AssertionFailure() << pred_text << "("
msg << pred_text << "(" << e1 << ") evaluates to false, where"
<< e1 << ") evaluates to false, where" << "\n" << e1 << " evaluates to " << v1;
<< "\n" << e1 << " evaluates to " << v1;
return AssertionFailure(msg);
} }
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\ #define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
GTEST_ASSERT_(pred_format(#v1, v1),\ GTEST_ASSERT_(pred_format(#v1, v1),\
on_failure) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
// this in your code. // this in your code.
skipping to change at line 136 skipping to change at line 134
typename T1, typename T1,
typename T2> typename T2>
AssertionResult AssertPred2Helper(const char* pred_text, AssertionResult AssertPred2Helper(const char* pred_text,
const char* e1, const char* e1,
const char* e2, const char* e2,
Pred pred, Pred pred,
const T1& v1, const T1& v1,
const T2& v2) { const T2& v2) {
if (pred(v1, v2)) return AssertionSuccess(); if (pred(v1, v2)) return AssertionSuccess();
Message msg; return AssertionFailure() << pred_text << "("
msg << pred_text << "(" << e1 << ", "
<< e1 << ", " << e2 << ") evaluates to false, where"
<< e2 << ") evaluates to false, where" << "\n" << e1 << " evaluates to " << v1
<< "\n" << e1 << " evaluates to " << v1 << "\n" << e2 << " evaluates to " << v2;
<< "\n" << e2 << " evaluates to " << v2;
return AssertionFailure(msg);
} }
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\ #define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2),\ GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2),\
on_failure) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
// this in your code. // this in your code.
skipping to change at line 187 skipping to change at line 183
AssertionResult AssertPred3Helper(const char* pred_text, AssertionResult AssertPred3Helper(const char* pred_text,
const char* e1, const char* e1,
const char* e2, const char* e2,
const char* e3, const char* e3,
Pred pred, Pred pred,
const T1& v1, const T1& v1,
const T2& v2, const T2& v2,
const T3& v3) { const T3& v3) {
if (pred(v1, v2, v3)) return AssertionSuccess(); if (pred(v1, v2, v3)) return AssertionSuccess();
Message msg; return AssertionFailure() << pred_text << "("
msg << pred_text << "(" << e1 << ", "
<< e1 << ", " << e2 << ", "
<< e2 << ", " << e3 << ") evaluates to false, where"
<< e3 << ") evaluates to false, where" << "\n" << e1 << " evaluates to " << v1
<< "\n" << e1 << " evaluates to " << v1 << "\n" << e2 << " evaluates to " << v2
<< "\n" << e2 << " evaluates to " << v2 << "\n" << e3 << " evaluates to " << v3;
<< "\n" << e3 << " evaluates to " << v3;
return AssertionFailure(msg);
} }
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\ #define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3),\ GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3),\
on_failure) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
// this in your code. // this in your code.
skipping to change at line 245 skipping to change at line 239
const char* e2, const char* e2,
const char* e3, const char* e3,
const char* e4, const char* e4,
Pred pred, Pred pred,
const T1& v1, const T1& v1,
const T2& v2, const T2& v2,
const T3& v3, const T3& v3,
const T4& v4) { const T4& v4) {
if (pred(v1, v2, v3, v4)) return AssertionSuccess(); if (pred(v1, v2, v3, v4)) return AssertionSuccess();
Message msg; return AssertionFailure() << pred_text << "("
msg << pred_text << "(" << e1 << ", "
<< e1 << ", " << e2 << ", "
<< e2 << ", " << e3 << ", "
<< e3 << ", " << e4 << ") evaluates to false, where"
<< e4 << ") evaluates to false, where" << "\n" << e1 << " evaluates to " << v1
<< "\n" << e1 << " evaluates to " << v1 << "\n" << e2 << " evaluates to " << v2
<< "\n" << e2 << " evaluates to " << v2 << "\n" << e3 << " evaluates to " << v3
<< "\n" << e3 << " evaluates to " << v3 << "\n" << e4 << " evaluates to " << v4;
<< "\n" << e4 << " evaluates to " << v4;
return AssertionFailure(msg);
} }
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\ #define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4),\ GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4),\
on_failure) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
// this in your code. // this in your code.
skipping to change at line 310 skipping to change at line 302
const char* e4, const char* e4,
const char* e5, const char* e5,
Pred pred, Pred pred,
const T1& v1, const T1& v1,
const T2& v2, const T2& v2,
const T3& v3, const T3& v3,
const T4& v4, const T4& v4,
const T5& v5) { const T5& v5) {
if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess(); if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
Message msg; return AssertionFailure() << pred_text << "("
msg << pred_text << "(" << e1 << ", "
<< e1 << ", " << e2 << ", "
<< e2 << ", " << e3 << ", "
<< e3 << ", " << e4 << ", "
<< e4 << ", " << e5 << ") evaluates to false, where"
<< e5 << ") evaluates to false, where" << "\n" << e1 << " evaluates to " << v1
<< "\n" << e1 << " evaluates to " << v1 << "\n" << e2 << " evaluates to " << v2
<< "\n" << e2 << " evaluates to " << v2 << "\n" << e3 << " evaluates to " << v3
<< "\n" << e3 << " evaluates to " << v3 << "\n" << e4 << " evaluates to " << v4
<< "\n" << e4 << " evaluates to " << v4 << "\n" << e5 << " evaluates to " << v5;
<< "\n" << e5 << " evaluates to " << v5;
return AssertionFailure(msg);
} }
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5. // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
// Don't use this in your code. // Don't use this in your code.
#define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\ #define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5),\ GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5),\
on_failure) on_failure)
// Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use // Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
// this in your code. // this in your code.
 End of changes. 7 change blocks. 
47 lines changed or deleted 37 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/