diff --git a/CMakeLists.txt b/CMakeLists.txt index 33320def..69d09570 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,9 +204,8 @@ option(BOOST_STATIC "Link with static boost libraries" OFF) # This is useful on Windows, if linking against standard GLEW dll fails option(GLEW_STATIC "Link statically with GLEW" OFF) -# Sometimes helpful if there are different versions of gmock/gtest installed on system vs bundled +# Sometimes helpful if there is a different version of gtest installed on system vs bundled option(FORCE_BUNDLED_GTEST "Force the use of bundled gtest" OFF) -option(FORCE_BUNDLED_GMOCK "Force the use of bundled gmock" OFF) # Default build type if not given is debug if(NOT DEFINED CMAKE_BUILD_TYPE) @@ -389,22 +388,8 @@ if(TESTS) add_subdirectory(${GTEST_SRC_DIR} lib/gtest) - # Google Mock library - find_path(GMOCK_SRC_DIR NAMES src/gmock.cc src/gmock-all.cc PATHS /usr/src PATH_SUFFIXES gmock) - find_path(GMOCK_INCLUDE_DIR gmock/gmock.h PATHS /usr/include) - if(NOT(FORCE_BUNDLED_GMOCK) AND GMOCK_SRC_DIR AND GMOCK_INCLUDE_DIR) - message(STATUS "Using system gmock library in ${GMOCK_SRC_DIR}") - - include_directories(${GMOCK_SRC_DIR}) - # gmock-all.cc includes all other sources - add_library(gmock STATIC ${GMOCK_SRC_DIR}/src/gmock-all.cc) - else() - message(STATUS "Using bundled gmock library") - set(GMOCK_SRC_DIR ${colobot_SOURCE_DIR}/lib/gmock) - set(GMOCK_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/gmock/include) - add_subdirectory(${GMOCK_SRC_DIR} lib/gmock) - endif() - + # Hippomocks library + set(HIPPOMOCKS_INCLUDE_DIR ${colobot_SOURCE_DIR}/lib/hippomocks) # Tests targets enable_testing() diff --git a/lib/gmock/CMakeLists.txt b/lib/gmock/CMakeLists.txt deleted file mode 100644 index e7ff8035..00000000 --- a/lib/gmock/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -cmake_minimum_required(VERSION 2.8) - -set(CMAKE_CXX_FLAGS "${${ORIGINAL_CXX_FLAGS}}") - -include_directories(. include ${GTEST_INCLUDE_DIR}) - -# gmock-all.cc includes all other sources -add_library(gmock STATIC src/gmock-all.cc) diff --git a/lib/gmock/COPYING.txt b/lib/gmock/COPYING.txt deleted file mode 100644 index 1941a11f..00000000 --- a/lib/gmock/COPYING.txt +++ /dev/null @@ -1,28 +0,0 @@ -Copyright 2008, Google Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/gmock/README.txt b/lib/gmock/README.txt deleted file mode 100644 index 390886f7..00000000 --- a/lib/gmock/README.txt +++ /dev/null @@ -1,5 +0,0 @@ -This directory contains part of distribution of Google Test (http://code.google.com/p/googletest/) - - a C++ framework for unit tests. There are source files, include headers and a custom CMakeLists.txt -to compile static library. Only these files are kept from the official distribution as only -they are necessary. For more info, see the original README file from gtest: REDME-gtest.txt. -License info is kept in the original COPYING.txt. diff --git a/lib/gmock/include/gmock/gmock-actions.h b/lib/gmock/include/gmock/gmock-actions.h deleted file mode 100644 index d6a3e148..00000000 --- a/lib/gmock/include/gmock/gmock-actions.h +++ /dev/null @@ -1,1076 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements some commonly used actions. - -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ - -#include -#include - -#ifndef _WIN32_WCE -# include -#endif - -#include "gmock/internal/gmock-internal-utils.h" -#include "gmock/internal/gmock-port.h" - -namespace testing { - -// To implement an action Foo, define: -// 1. a class FooAction that implements the ActionInterface interface, and -// 2. a factory function that creates an Action object from a -// const FooAction*. -// -// The two-level delegation design follows that of Matcher, providing -// consistency for extension developers. It also eases ownership -// management as Action objects can now be copied like plain values. - -namespace internal { - -template -class ActionAdaptor; - -// BuiltInDefaultValue::Get() returns the "built-in" default -// 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 -// std::string. For any other type T, this value is undefined and the -// function will abort the process. -template -class BuiltInDefaultValue { - public: - // This function returns true iff type T has a built-in default value. - static bool Exists() { return false; } - static T Get() { - Assert(false, __FILE__, __LINE__, - "Default action undefined for the function return type."); - return internal::Invalid(); - // The above statement will never be reached, but is required in - // order for this function to compile. - } -}; - -// This partial specialization says that we use the same built-in -// default value for T and const T. -template -class BuiltInDefaultValue { - public: - static bool Exists() { return BuiltInDefaultValue::Exists(); } - static T Get() { return BuiltInDefaultValue::Get(); } -}; - -// This partial specialization defines the default values for pointer -// types. -template -class BuiltInDefaultValue { - public: - static bool Exists() { return true; } - static T* Get() { return NULL; } -}; - -// The following specializations define the default values for -// specific types we care about. -#define GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(type, value) \ - template <> \ - class BuiltInDefaultValue { \ - public: \ - static bool Exists() { return true; } \ - static type Get() { return value; } \ - } - -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(void, ); // NOLINT -#if GTEST_HAS_GLOBAL_STRING -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::string, ""); -#endif // GTEST_HAS_GLOBAL_STRING -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(::std::string, ""); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(bool, false); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned char, '\0'); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed char, '\0'); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(char, '\0'); - -// There's no need for a default action for signed wchar_t, as that -// type is the same as wchar_t for gcc, and invalid for MSVC. -// -// There's also no need for a default action for unsigned wchar_t, as -// that type is the same as unsigned int for gcc, and invalid for -// MSVC. -#if GMOCK_WCHAR_T_IS_NATIVE_ -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(wchar_t, 0U); // NOLINT -#endif - -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned short, 0U); // NOLINT -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed short, 0); // NOLINT -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned int, 0U); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed int, 0); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(unsigned long, 0UL); // NOLINT -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(signed long, 0L); // NOLINT -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(UInt64, 0); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(Int64, 0); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(float, 0); -GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_(double, 0); - -#undef GMOCK_DEFINE_DEFAULT_ACTION_FOR_RETURN_TYPE_ - -} // namespace internal - -// When an unexpected function call is encountered, Google Mock will -// let it return a default value if the user has specified one for its -// return type, or if the return type has a built-in default value; -// otherwise Google Mock won't know what value to return and will have -// to abort the process. -// -// The DefaultValue class allows a user to specify the -// default value for a type T that is both copyable and publicly -// destructible (i.e. anything that can be used as a function return -// type). The usage is: -// -// // Sets the default value for type T to be foo. -// DefaultValue::Set(foo); -template -class DefaultValue { - public: - // Sets the default value for type T; requires T to be - // copy-constructable and have a public destructor. - static void Set(T x) { - delete value_; - value_ = new T(x); - } - - // Unsets the default value for type T. - static void Clear() { - delete value_; - value_ = NULL; - } - - // Returns true iff the user has set the default value for type T. - static bool IsSet() { return value_ != NULL; } - - // Returns true if T has a default return value set by the user or there - // exists a built-in default value. - static bool Exists() { - return IsSet() || internal::BuiltInDefaultValue::Exists(); - } - - // Returns the default value for type T if the user has set one; - // otherwise returns the built-in default value if there is one; - // otherwise aborts the process. - static T Get() { - return value_ == NULL ? - internal::BuiltInDefaultValue::Get() : *value_; - } - private: - static const T* value_; -}; - -// This partial specialization allows a user to set default values for -// reference types. -template -class DefaultValue { - public: - // Sets the default value for type T&. - static void Set(T& x) { // NOLINT - address_ = &x; - } - - // Unsets the default value for type T&. - static void Clear() { - address_ = NULL; - } - - // Returns true iff the user has set the default value for type T&. - static bool IsSet() { return address_ != NULL; } - - // Returns true if T has a default return value set by the user or there - // exists a built-in default value. - static bool Exists() { - return IsSet() || internal::BuiltInDefaultValue::Exists(); - } - - // Returns the default value for type T& if the user has set one; - // otherwise returns the built-in default value if there is one; - // otherwise aborts the process. - static T& Get() { - return address_ == NULL ? - internal::BuiltInDefaultValue::Get() : *address_; - } - private: - static T* address_; -}; - -// This specialization allows DefaultValue::Get() to -// compile. -template <> -class DefaultValue { - public: - static bool Exists() { return true; } - static void Get() {} -}; - -// Points to the user-set default value for type T. -template -const T* DefaultValue::value_ = NULL; - -// Points to the user-set default value for type T&. -template -T* DefaultValue::address_ = NULL; - -// Implement this interface to define an action for function type F. -template -class ActionInterface { - public: - typedef typename internal::Function::Result Result; - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - ActionInterface() {} - virtual ~ActionInterface() {} - - // Performs the action. This method is not const, as in general an - // action can have side effects and be stateful. For example, a - // get-the-next-element-from-the-collection action will need to - // remember the current element. - virtual Result Perform(const ArgumentTuple& args) = 0; - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface); -}; - -// An Action is a copyable and IMMUTABLE (except by assignment) -// object that represents an action to be taken when a mock function -// of type F is called. The implementation of Action is just a -// linked_ptr to const ActionInterface, so copying is fairly cheap. -// Don't inherit from Action! -// -// You can view an object implementing ActionInterface as a -// concrete action (including its current state), and an Action -// object as a handle to it. -template -class Action { - public: - typedef typename internal::Function::Result Result; - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - // Constructs a null Action. Needed for storing Action objects in - // STL containers. - Action() : impl_(NULL) {} - - // Constructs an Action from its implementation. A NULL impl is - // used to represent the "do-default" action. - explicit Action(ActionInterface* impl) : impl_(impl) {} - - // Copy constructor. - Action(const Action& action) : impl_(action.impl_) {} - - // This constructor allows us to turn an Action object into an - // Action, as long as F's arguments can be implicitly converted - // to Func's and Func's return type can be implicitly converted to - // F's. - template - explicit Action(const Action& action); - - // Returns true iff this is the DoDefault() action. - bool IsDoDefault() const { return impl_.get() == NULL; } - - // Performs the action. Note that this method is const even though - // the corresponding method in ActionInterface is not. The reason - // is that a const Action means that it cannot be re-bound to - // another concrete action, not that the concrete action it binds to - // cannot change state. (Think of the difference between a const - // pointer and a pointer to 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); - } - - private: - template - friend class internal::ActionAdaptor; - - internal::linked_ptr > impl_; -}; - -// The PolymorphicAction class template makes it easy to implement a -// polymorphic action (i.e. an action that can be used in mock -// functions of than one type, e.g. Return()). -// -// To define a polymorphic action, a user first provides a COPYABLE -// implementation class that has a Perform() method template: -// -// class FooAction { -// public: -// template -// Result Perform(const ArgumentTuple& args) const { -// // Processes the arguments and returns a result, using -// // tr1::get(args) to get the N-th (0-based) argument in the tuple. -// } -// ... -// }; -// -// Then the user creates the polymorphic action using -// MakePolymorphicAction(object) where object has type FooAction. See -// the definition of Return(void) and SetArgumentPointee(value) for -// complete examples. -template -class PolymorphicAction { - public: - explicit PolymorphicAction(const Impl& impl) : impl_(impl) {} - - template - operator Action() const { - return Action(new MonomorphicImpl(impl_)); - } - - private: - template - class MonomorphicImpl : public ActionInterface { - public: - typedef typename internal::Function::Result Result; - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} - - virtual Result Perform(const ArgumentTuple& args) { - return impl_.template Perform(args); - } - - private: - Impl impl_; - - GTEST_DISALLOW_ASSIGN_(MonomorphicImpl); - }; - - Impl impl_; - - GTEST_DISALLOW_ASSIGN_(PolymorphicAction); -}; - -// Creates an Action from its implementation and returns it. The -// created Action object owns the implementation. -template -Action MakeAction(ActionInterface* impl) { - return Action(impl); -} - -// Creates a polymorphic action from its implementation. This is -// easier to use than the PolymorphicAction constructor as it -// doesn't require you to explicitly write the template argument, e.g. -// -// MakePolymorphicAction(foo); -// vs -// PolymorphicAction(foo); -template -inline PolymorphicAction MakePolymorphicAction(const Impl& impl) { - return PolymorphicAction(impl); -} - -namespace internal { - -// Allows an Action object to pose as an Action, as long as F2 -// and F1 are compatible. -template -class ActionAdaptor : public ActionInterface { - public: - typedef typename internal::Function::Result Result; - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - explicit ActionAdaptor(const Action& from) : impl_(from.impl_) {} - - virtual Result Perform(const ArgumentTuple& args) { - return impl_->Perform(args); - } - - private: - const internal::linked_ptr > impl_; - - GTEST_DISALLOW_ASSIGN_(ActionAdaptor); -}; - -// Implements the polymorphic Return(x) action, which can be used in -// any function that returns the type of x, regardless of the argument -// types. -// -// Note: The value passed into Return must be converted into -// Function::Result when this action is cast to Action rather than -// when that action is performed. This is important in scenarios like -// -// MOCK_METHOD1(Method, T(U)); -// ... -// { -// Foo foo; -// X x(&foo); -// EXPECT_CALL(mock, Method(_)).WillOnce(Return(x)); -// } -// -// In the example above the variable x holds reference to foo which leaves -// scope and gets destroyed. If copying X just copies a reference to foo, -// that copy will be left with a hanging reference. If conversion to T -// makes a copy of foo, the above code is safe. To support that scenario, we -// need to make sure that the type conversion happens inside the EXPECT_CALL -// statement, and conversion of the result of Return to Action is a -// good place for that. -// -template -class ReturnAction { - public: - // Constructs a ReturnAction object from the value to be returned. - // 'value' is passed by value instead of by const reference in order - // to allow Return("string literal") to compile. - explicit ReturnAction(R value) : value_(value) {} - - // This template type conversion operator allows Return(x) to be - // used in ANY function that returns x's type. - template - operator Action() const { - // Assert statement belongs here because this is the best place to verify - // conditions on F. It produces the clearest error messages - // in most compilers. - // Impl really belongs in this scope as a local class but can't - // because MSVC produces duplicate symbols in different translation units - // in this case. Until MS fixes that bug we put Impl into the class scope - // and put the typedef both here (for use in assert statement) and - // in the Impl class. But both definitions must be the same. - typedef typename Function::Result Result; - GTEST_COMPILE_ASSERT_( - !internal::is_reference::value, - use_ReturnRef_instead_of_Return_to_return_a_reference); - return Action(new Impl(value_)); - } - - private: - // Implements the Return(x) action for a particular function type F. - template - class Impl : public ActionInterface { - public: - typedef typename Function::Result Result; - typedef typename Function::ArgumentTuple ArgumentTuple; - - // The implicit cast is necessary when Result has more than one - // single-argument constructor (e.g. Result is std::vector) and R - // has a type conversion operator template. In that case, value_(value) - // won't compile as the compiler doesn't known which constructor of - // Result to call. ImplicitCast_ forces the compiler to convert R to - // Result without considering explicit constructors, thus resolving the - // ambiguity. value_ is then initialized using its copy constructor. - explicit Impl(R value) - : value_(::testing::internal::ImplicitCast_(value)) {} - - virtual Result Perform(const ArgumentTuple&) { return value_; } - - private: - GTEST_COMPILE_ASSERT_(!internal::is_reference::value, - Result_cannot_be_a_reference_type); - Result value_; - - GTEST_DISALLOW_ASSIGN_(Impl); - }; - - R value_; - - GTEST_DISALLOW_ASSIGN_(ReturnAction); -}; - -// Implements the ReturnNull() action. -class ReturnNullAction { - public: - // Allows ReturnNull() to be used in any pointer-returning function. - template - static Result Perform(const ArgumentTuple&) { - GTEST_COMPILE_ASSERT_(internal::is_pointer::value, - ReturnNull_can_be_used_to_return_a_pointer_only); - return NULL; - } -}; - -// Implements the Return() action. -class ReturnVoidAction { - public: - // Allows Return() to be used in any void-returning function. - template - static void Perform(const ArgumentTuple&) { - CompileAssertTypesEqual(); - } -}; - -// Implements the polymorphic ReturnRef(x) action, which can be used -// in any function that returns a reference to the type of x, -// regardless of the argument types. -template -class ReturnRefAction { - public: - // Constructs a ReturnRefAction object from the reference to be returned. - explicit ReturnRefAction(T& ref) : ref_(ref) {} // NOLINT - - // This template type conversion operator allows ReturnRef(x) to be - // used in ANY function that returns a reference to x's type. - template - operator Action() const { - typedef typename Function::Result Result; - // Asserts that the function return type is a reference. This - // catches the user error of using ReturnRef(x) when Return(x) - // should be used, and generates some helpful error message. - GTEST_COMPILE_ASSERT_(internal::is_reference::value, - use_Return_instead_of_ReturnRef_to_return_a_value); - return Action(new Impl(ref_)); - } - - private: - // Implements the ReturnRef(x) action for a particular function type F. - template - class Impl : public ActionInterface { - public: - typedef typename Function::Result Result; - typedef typename Function::ArgumentTuple ArgumentTuple; - - explicit Impl(T& ref) : ref_(ref) {} // NOLINT - - virtual Result Perform(const ArgumentTuple&) { - return ref_; - } - - private: - T& ref_; - - GTEST_DISALLOW_ASSIGN_(Impl); - }; - - T& ref_; - - GTEST_DISALLOW_ASSIGN_(ReturnRefAction); -}; - -// Implements the polymorphic ReturnRefOfCopy(x) action, which can be -// used in any function that returns a reference to the type of x, -// regardless of the argument types. -template -class ReturnRefOfCopyAction { - public: - // Constructs a ReturnRefOfCopyAction object from the reference to - // be returned. - explicit ReturnRefOfCopyAction(const T& value) : value_(value) {} // NOLINT - - // This template type conversion operator allows ReturnRefOfCopy(x) to be - // used in ANY function that returns a reference to x's type. - template - operator Action() const { - typedef typename Function::Result Result; - // Asserts that the function return type is a reference. This - // catches the user error of using ReturnRefOfCopy(x) when Return(x) - // should be used, and generates some helpful error message. - GTEST_COMPILE_ASSERT_( - internal::is_reference::value, - use_Return_instead_of_ReturnRefOfCopy_to_return_a_value); - return Action(new Impl(value_)); - } - - private: - // Implements the ReturnRefOfCopy(x) action for a particular function type F. - template - class Impl : public ActionInterface { - public: - typedef typename Function::Result Result; - typedef typename Function::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. -class DoDefaultAction { - public: - // This template type conversion operator allows DoDefault() to be - // used in any function. - template - operator Action() const { return Action(NULL); } -}; - -// Implements the Assign action to set a given pointer referent to a -// particular value. -template -class AssignAction { - public: - AssignAction(T1* ptr, T2 value) : ptr_(ptr), value_(value) {} - - template - void Perform(const ArgumentTuple& /* args */) const { - *ptr_ = value_; - } - - private: - T1* const ptr_; - const T2 value_; - - GTEST_DISALLOW_ASSIGN_(AssignAction); -}; - -#if !GTEST_OS_WINDOWS_MOBILE - -// Implements the SetErrnoAndReturn action to simulate return from -// various system calls and libc functions. -template -class SetErrnoAndReturnAction { - public: - SetErrnoAndReturnAction(int errno_value, T result) - : errno_(errno_value), - result_(result) {} - template - Result Perform(const ArgumentTuple& /* args */) const { - errno = errno_; - return result_; - } - - private: - const int errno_; - const T result_; - - GTEST_DISALLOW_ASSIGN_(SetErrnoAndReturnAction); -}; - -#endif // !GTEST_OS_WINDOWS_MOBILE - -// Implements the SetArgumentPointee(x) action for any function -// whose N-th argument (0-based) is a pointer to x's type. The -// template parameter kIsProto is true iff type A is ProtocolMessage, -// proto2::Message, or a sub-class of those. -template -class SetArgumentPointeeAction { - public: - // Constructs an action that sets the variable pointed to by the - // N-th function argument to 'value'. - explicit SetArgumentPointeeAction(const A& value) : value_(value) {} - - template - void Perform(const ArgumentTuple& args) const { - CompileAssertTypesEqual(); - *::std::tr1::get(args) = value_; - } - - private: - const A value_; - - GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction); -}; - -template -class SetArgumentPointeeAction { - public: - // Constructs an action that sets the variable pointed to by the - // N-th function argument to 'proto'. Both ProtocolMessage and - // proto2::Message have the CopyFrom() method, so the same - // implementation works for both. - explicit SetArgumentPointeeAction(const Proto& proto) : proto_(new Proto) { - proto_->CopyFrom(proto); - } - - template - void Perform(const ArgumentTuple& args) const { - CompileAssertTypesEqual(); - ::std::tr1::get(args)->CopyFrom(*proto_); - } - - private: - const internal::linked_ptr proto_; - - GTEST_DISALLOW_ASSIGN_(SetArgumentPointeeAction); -}; - -// Implements the InvokeWithoutArgs(f) action. The template argument -// FunctionImpl is the implementation type of f, which can be either a -// function pointer or a functor. InvokeWithoutArgs(f) can be used as an -// Action as long as f's type is compatible with F (i.e. f can be -// assigned to a tr1::function). -template -class InvokeWithoutArgsAction { - public: - // The c'tor makes a copy of function_impl (either a function - // pointer or a functor). - explicit InvokeWithoutArgsAction(FunctionImpl function_impl) - : function_impl_(function_impl) {} - - // Allows InvokeWithoutArgs(f) to be used as any action whose type is - // compatible with f. - template - Result Perform(const ArgumentTuple&) { return function_impl_(); } - - private: - FunctionImpl function_impl_; - - GTEST_DISALLOW_ASSIGN_(InvokeWithoutArgsAction); -}; - -// Implements the InvokeWithoutArgs(object_ptr, &Class::Method) action. -template -class InvokeMethodWithoutArgsAction { - public: - InvokeMethodWithoutArgsAction(Class* obj_ptr, MethodPtr method_ptr) - : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} - - template - Result Perform(const ArgumentTuple&) const { - return (obj_ptr_->*method_ptr_)(); - } - - private: - Class* const obj_ptr_; - const MethodPtr method_ptr_; - - GTEST_DISALLOW_ASSIGN_(InvokeMethodWithoutArgsAction); -}; - -// Implements the IgnoreResult(action) action. -template -class IgnoreResultAction { - public: - explicit IgnoreResultAction(const A& action) : action_(action) {} - - template - operator Action() const { - // Assert statement belongs here because this is the best place to verify - // conditions on F. It produces the clearest error messages - // in most compilers. - // Impl really belongs in this scope as a local class but can't - // because MSVC produces duplicate symbols in different translation units - // in this case. Until MS fixes that bug we put Impl into the class scope - // and put the typedef both here (for use in assert statement) and - // in the Impl class. But both definitions must be the same. - typedef typename internal::Function::Result Result; - - // Asserts at compile time that F returns void. - CompileAssertTypesEqual(); - - return Action(new Impl(action_)); - } - - private: - template - class Impl : public ActionInterface { - public: - typedef typename internal::Function::Result Result; - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - explicit Impl(const A& action) : action_(action) {} - - virtual void Perform(const ArgumentTuple& args) { - // Performs the action and ignores its result. - action_.Perform(args); - } - - private: - // Type OriginalFunction is the same as F except that its return - // type is IgnoredValue. - typedef typename internal::Function::MakeResultIgnoredValue - OriginalFunction; - - const Action action_; - - GTEST_DISALLOW_ASSIGN_(Impl); - }; - - const A action_; - - GTEST_DISALLOW_ASSIGN_(IgnoreResultAction); -}; - -// A ReferenceWrapper object represents a reference to type T, -// which can be either const or not. It can be explicitly converted -// from, and implicitly converted to, a T&. Unlike a reference, -// ReferenceWrapper can be copied and can survive template type -// inference. This is used to support by-reference arguments in the -// InvokeArgument(...) action. The idea was from "reference -// wrappers" in tr1, which we don't have in our source tree yet. -template -class ReferenceWrapper { - public: - // Constructs a ReferenceWrapper object from a T&. - explicit ReferenceWrapper(T& l_value) : pointer_(&l_value) {} // NOLINT - - // Allows a ReferenceWrapper object to be implicitly converted to - // a T&. - operator T&() const { return *pointer_; } - private: - T* pointer_; -}; - -// Allows the expression ByRef(x) to be printed as a reference to x. -template -void PrintTo(const ReferenceWrapper& ref, ::std::ostream* os) { - T& value = ref; - UniversalPrinter::Print(value, os); -} - -// Does two actions sequentially. Used for implementing the DoAll(a1, -// a2, ...) action. -template -class DoBothAction { - public: - DoBothAction(Action1 action1, Action2 action2) - : action1_(action1), action2_(action2) {} - - // This template type conversion operator allows DoAll(a1, ..., a_n) - // to be used in ANY function of compatible type. - template - operator Action() const { - return Action(new Impl(action1_, action2_)); - } - - private: - // Implements the DoAll(...) action for a particular function type F. - template - class Impl : public ActionInterface { - public: - typedef typename Function::Result Result; - typedef typename Function::ArgumentTuple ArgumentTuple; - typedef typename Function::MakeResultVoid VoidResult; - - Impl(const Action& action1, const Action& action2) - : action1_(action1), action2_(action2) {} - - virtual Result Perform(const ArgumentTuple& args) { - action1_.Perform(args); - return action2_.Perform(args); - } - - private: - const Action action1_; - const Action action2_; - - GTEST_DISALLOW_ASSIGN_(Impl); - }; - - Action1 action1_; - Action2 action2_; - - GTEST_DISALLOW_ASSIGN_(DoBothAction); -}; - -} // namespace internal - -// An Unused object can be implicitly constructed from ANY value. -// This is handy when defining actions that ignore some or all of the -// mock function arguments. For example, given -// -// MOCK_METHOD3(Foo, double(const string& label, double x, double y)); -// MOCK_METHOD3(Bar, double(int index, double x, double y)); -// -// instead of -// -// double DistanceToOriginWithLabel(const string& label, double x, double y) { -// return sqrt(x*x + y*y); -// } -// double DistanceToOriginWithIndex(int index, double x, double y) { -// return sqrt(x*x + y*y); -// } -// ... -// EXEPCT_CALL(mock, Foo("abc", _, _)) -// .WillOnce(Invoke(DistanceToOriginWithLabel)); -// EXEPCT_CALL(mock, Bar(5, _, _)) -// .WillOnce(Invoke(DistanceToOriginWithIndex)); -// -// you could write -// -// // We can declare any uninteresting argument as Unused. -// double DistanceToOrigin(Unused, double x, double y) { -// return sqrt(x*x + y*y); -// } -// ... -// EXEPCT_CALL(mock, Foo("abc", _, _)).WillOnce(Invoke(DistanceToOrigin)); -// EXEPCT_CALL(mock, Bar(5, _, _)).WillOnce(Invoke(DistanceToOrigin)); -typedef internal::IgnoredValue Unused; - -// This constructor allows us to turn an Action object into an -// Action, as long as To's arguments can be implicitly converted -// to From's and From's return type cann be implicitly converted to -// To's. -template -template -Action::Action(const Action& from) - : impl_(new internal::ActionAdaptor(from)) {} - -// Creates an action that returns 'value'. 'value' is passed by value -// instead of const reference - otherwise Return("string literal") -// will trigger a compiler error about using array as initializer. -template -internal::ReturnAction Return(R value) { - return internal::ReturnAction(value); -} - -// Creates an action that returns NULL. -inline PolymorphicAction ReturnNull() { - return MakePolymorphicAction(internal::ReturnNullAction()); -} - -// Creates an action that returns from a void function. -inline PolymorphicAction Return() { - return MakePolymorphicAction(internal::ReturnVoidAction()); -} - -// Creates an action that returns the reference to a variable. -template -inline internal::ReturnRefAction ReturnRef(R& x) { // NOLINT - return internal::ReturnRefAction(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 -inline internal::ReturnRefOfCopyAction ReturnRefOfCopy(const R& x) { - return internal::ReturnRefOfCopyAction(x); -} - -// Creates an action that does the default action for the give mock function. -inline internal::DoDefaultAction DoDefault() { - return internal::DoDefaultAction(); -} - -// Creates an action that sets the variable pointed by the N-th -// (0-based) function argument to 'value'. -template -PolymorphicAction< - internal::SetArgumentPointeeAction< - N, T, internal::IsAProtocolMessage::value> > -SetArgPointee(const T& x) { - return MakePolymorphicAction(internal::SetArgumentPointeeAction< - N, T, internal::IsAProtocolMessage::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 -PolymorphicAction< - internal::SetArgumentPointeeAction > -SetArgPointee(const char* p) { - return MakePolymorphicAction(internal::SetArgumentPointeeAction< - N, const char*, false>(p)); -} - -template -PolymorphicAction< - internal::SetArgumentPointeeAction > -SetArgPointee(const wchar_t* p) { - return MakePolymorphicAction(internal::SetArgumentPointeeAction< - N, const wchar_t*, false>(p)); -} -#endif - -// The following version is DEPRECATED. -template -PolymorphicAction< - internal::SetArgumentPointeeAction< - N, T, internal::IsAProtocolMessage::value> > -SetArgumentPointee(const T& x) { - return MakePolymorphicAction(internal::SetArgumentPointeeAction< - N, T, internal::IsAProtocolMessage::value>(x)); -} - -// Creates an action that sets a pointer referent to a given value. -template -PolymorphicAction > Assign(T1* ptr, T2 val) { - return MakePolymorphicAction(internal::AssignAction(ptr, val)); -} - -#if !GTEST_OS_WINDOWS_MOBILE - -// Creates an action that sets errno and returns the appropriate error. -template -PolymorphicAction > -SetErrnoAndReturn(int errval, T result) { - return MakePolymorphicAction( - internal::SetErrnoAndReturnAction(errval, result)); -} - -#endif // !GTEST_OS_WINDOWS_MOBILE - -// Various overloads for InvokeWithoutArgs(). - -// Creates an action that invokes 'function_impl' with no argument. -template -PolymorphicAction > -InvokeWithoutArgs(FunctionImpl function_impl) { - return MakePolymorphicAction( - internal::InvokeWithoutArgsAction(function_impl)); -} - -// Creates an action that invokes the given method on the given object -// with no argument. -template -PolymorphicAction > -InvokeWithoutArgs(Class* obj_ptr, MethodPtr method_ptr) { - return MakePolymorphicAction( - internal::InvokeMethodWithoutArgsAction( - obj_ptr, method_ptr)); -} - -// Creates an action that performs an_action and throws away its -// result. In other words, it changes the return type of an_action to -// void. an_action MUST NOT return void, or the code won't compile. -template -inline internal::IgnoreResultAction IgnoreResult(const A& an_action) { - return internal::IgnoreResultAction(an_action); -} - -// Creates a reference wrapper for the given L-value. If necessary, -// you can explicitly specify the type of the reference. For example, -// suppose 'derived' is an object of type Derived, ByRef(derived) -// would wrap a Derived&. If you want to wrap a const Base& instead, -// where Base is a base class of Derived, just write: -// -// ByRef(derived) -template -inline internal::ReferenceWrapper ByRef(T& l_value) { // NOLINT - return internal::ReferenceWrapper(l_value); -} - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ diff --git a/lib/gmock/include/gmock/gmock-cardinalities.h b/lib/gmock/include/gmock/gmock-cardinalities.h deleted file mode 100644 index 954a86ea..00000000 --- a/lib/gmock/include/gmock/gmock-cardinalities.h +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements some commonly used cardinalities. More -// cardinalities can be defined by the user implementing the -// CardinalityInterface interface if necessary. - -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ - -#include -#include // NOLINT -#include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" - -namespace testing { - -// To implement a cardinality Foo, define: -// 1. a class FooCardinality that implements the -// CardinalityInterface interface, and -// 2. a factory function that creates a Cardinality object from a -// const FooCardinality*. -// -// The two-level delegation design follows that of Matcher, providing -// consistency for extension developers. It also eases ownership -// management as Cardinality objects can now be copied like plain values. - -// The implementation of a cardinality. -class CardinalityInterface { - public: - virtual ~CardinalityInterface() {} - - // Conservative estimate on the lower/upper bound of the number of - // calls allowed. - virtual int ConservativeLowerBound() const { return 0; } - virtual int ConservativeUpperBound() const { return INT_MAX; } - - // Returns true iff call_count calls will satisfy this cardinality. - virtual bool IsSatisfiedByCallCount(int call_count) const = 0; - - // Returns true iff call_count calls will saturate this cardinality. - virtual bool IsSaturatedByCallCount(int call_count) const = 0; - - // Describes self to an ostream. - virtual void DescribeTo(::std::ostream* os) const = 0; -}; - -// A Cardinality is a copyable and IMMUTABLE (except by assignment) -// object that specifies how many times a mock function is expected to -// be called. The implementation of Cardinality is just a linked_ptr -// to const CardinalityInterface, so copying is fairly cheap. -// Don't inherit from Cardinality! -class Cardinality { - public: - // Constructs a null cardinality. Needed for storing Cardinality - // objects in STL containers. - Cardinality() {} - - // Constructs a Cardinality from its implementation. - explicit Cardinality(const CardinalityInterface* impl) : impl_(impl) {} - - // Conservative estimate on the lower/upper bound of the number of - // calls allowed. - int ConservativeLowerBound() const { return impl_->ConservativeLowerBound(); } - int ConservativeUpperBound() const { return impl_->ConservativeUpperBound(); } - - // Returns true iff call_count calls will satisfy this cardinality. - bool IsSatisfiedByCallCount(int call_count) const { - return impl_->IsSatisfiedByCallCount(call_count); - } - - // Returns true iff call_count calls will saturate this cardinality. - bool IsSaturatedByCallCount(int call_count) const { - return impl_->IsSaturatedByCallCount(call_count); - } - - // Returns true iff call_count calls will over-saturate this - // cardinality, i.e. exceed the maximum number of allowed calls. - bool IsOverSaturatedByCallCount(int call_count) const { - return impl_->IsSaturatedByCallCount(call_count) && - !impl_->IsSatisfiedByCallCount(call_count); - } - - // Describes self to an ostream - void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } - - // Describes the given actual call count to an ostream. - static void DescribeActualCallCountTo(int actual_call_count, - ::std::ostream* os); - private: - internal::linked_ptr impl_; -}; - -// Creates a cardinality that allows at least n calls. -Cardinality AtLeast(int n); - -// Creates a cardinality that allows at most n calls. -Cardinality AtMost(int n); - -// Creates a cardinality that allows any number of calls. -Cardinality AnyNumber(); - -// Creates a cardinality that allows between min and max calls. -Cardinality Between(int min, int max); - -// Creates a cardinality that allows exactly n calls. -Cardinality Exactly(int n); - -// Creates a cardinality from its implementation. -inline Cardinality MakeCardinality(const CardinalityInterface* c) { - return Cardinality(c); -} - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_CARDINALITIES_H_ diff --git a/lib/gmock/include/gmock/gmock-generated-actions.h b/lib/gmock/include/gmock/gmock-generated-actions.h deleted file mode 100644 index 635bb595..00000000 --- a/lib/gmock/include/gmock/gmock-generated-actions.h +++ /dev/null @@ -1,2419 +0,0 @@ -// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! - -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements some commonly used variadic actions. - -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ - -#include "gmock/gmock-actions.h" -#include "gmock/internal/gmock-port.h" - -namespace testing { -namespace internal { - -// InvokeHelper knows how to unpack an N-tuple and invoke an N-ary -// function or method with the unpacked values, where F is a function -// type that takes N arguments. -template -class InvokeHelper; - -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple<>&) { - return function(); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple<>&) { - return (obj_ptr->*method_ptr)(); - } -}; - -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return function(get<0>(args)); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return (obj_ptr->*method_ptr)(get<0>(args)); - } -}; - -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return function(get<0>(args), get<1>(args)); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args)); - } -}; - -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return function(get<0>(args), get<1>(args), get<2>(args)); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args)); - } -}; - -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args)); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), - get<3>(args)); - } -}; - -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), - get<4>(args)); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), - get<3>(args), get<4>(args)); - } -}; - -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), - get<4>(args), get<5>(args)); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), - get<3>(args), get<4>(args), get<5>(args)); - } -}; - -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), - get<4>(args), get<5>(args), get<6>(args)); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), - get<3>(args), get<4>(args), get<5>(args), get<6>(args)); - } -}; - -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), - get<4>(args), get<5>(args), get<6>(args), get<7>(args)); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), - get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args)); - } -}; - -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), - get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args)); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), - get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), - get<8>(args)); - } -}; - -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return function(get<0>(args), get<1>(args), get<2>(args), get<3>(args), - get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), - get<9>(args)); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return (obj_ptr->*method_ptr)(get<0>(args), get<1>(args), get<2>(args), - get<3>(args), get<4>(args), get<5>(args), get<6>(args), get<7>(args), - get<8>(args), get<9>(args)); - } -}; - -// CallableHelper has static methods for invoking "callables", -// i.e. function pointers and functors. It uses overloading to -// provide a uniform interface for invoking different kinds of -// callables. In particular, you can use: -// -// CallableHelper::Call(callable, a1, a2, ..., an) -// -// to invoke an n-ary callable, where R is its return type. If an -// argument, say a2, needs to be passed by reference, you should write -// ByRef(a2) instead of a2 in the above expression. -template -class CallableHelper { - public: - // Calls a nullary callable. - template - static R Call(Function function) { return function(); } - - // Calls a unary callable. - - // We deliberately pass a1 by value instead of const reference here - // in case it is a C-string literal. If we had declared the - // parameter as 'const A1& a1' and write Call(function, "Hi"), the - // compiler would've thought A1 is 'char[3]', which causes trouble - // when you need to copy a value of type A1. By declaring the - // parameter as 'A1 a1', the compiler will correctly infer that A1 - // is 'const char*' when it sees Call(function, "Hi"). - // - // Since this function is defined inline, the compiler can get rid - // of the copying of the arguments. Therefore the performance won't - // be hurt. - template - static R Call(Function function, A1 a1) { return function(a1); } - - // Calls a binary callable. - template - static R Call(Function function, A1 a1, A2 a2) { - return function(a1, a2); - } - - // Calls a ternary callable. - template - static R Call(Function function, A1 a1, A2 a2, A3 a3) { - return function(a1, a2, a3); - } - - // Calls a 4-ary callable. - template - static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4) { - return function(a1, a2, a3, a4); - } - - // Calls a 5-ary callable. - template - static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { - return function(a1, a2, a3, a4, a5); - } - - // Calls a 6-ary callable. - template - static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { - return function(a1, a2, a3, a4, a5, a6); - } - - // Calls a 7-ary callable. - template - static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, - A7 a7) { - return function(a1, a2, a3, a4, a5, a6, a7); - } - - // Calls a 8-ary callable. - template - static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, - A7 a7, A8 a8) { - return function(a1, a2, a3, a4, a5, a6, a7, a8); - } - - // Calls a 9-ary callable. - template - static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, - A7 a7, A8 a8, A9 a9) { - return function(a1, a2, a3, a4, a5, a6, a7, a8, a9); - } - - // Calls a 10-ary callable. - template - static R Call(Function function, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, - A7 a7, A8 a8, A9 a9, A10 a10) { - return function(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); - } - -}; // class CallableHelper - -// An INTERNAL macro for extracting the type of a tuple field. It's -// subject to change without notice - DO NOT USE IN USER CODE! -#define GMOCK_FIELD_(Tuple, N) \ - typename ::std::tr1::tuple_element::type - -// SelectArgs::type is the -// type of an n-ary function whose i-th (1-based) argument type is the -// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple -// type, and whose return type is Result. For example, -// SelectArgs, 0, 3>::type -// is int(bool, long). -// -// SelectArgs::Select(args) -// returns the selected fields (k1, k2, ..., k_n) of args as a tuple. -// For example, -// SelectArgs, 2, 0>::Select( -// ::std::tr1::make_tuple(true, 'a', 2.5)) -// returns ::std::tr1::tuple (2.5, true). -// -// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be -// in the range [0, 10]. Duplicates are allowed and they don't have -// to be in an ascending or descending order. - -template -class SelectArgs { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), - GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), - GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9), - GMOCK_FIELD_(ArgumentTuple, k10)); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - using ::std::tr1::get; - return SelectedArgs(get(args), get(args), get(args), - get(args), get(args), get(args), get(args), - get(args), get(args), get(args)); - } -}; - -template -class SelectArgs { - public: - typedef Result type(); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& /* args */) { - using ::std::tr1::get; - return SelectedArgs(); - } -}; - -template -class SelectArgs { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1)); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - using ::std::tr1::get; - return SelectedArgs(get(args)); - } -}; - -template -class SelectArgs { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2)); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - using ::std::tr1::get; - return SelectedArgs(get(args), get(args)); - } -}; - -template -class SelectArgs { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3)); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - using ::std::tr1::get; - return SelectedArgs(get(args), get(args), get(args)); - } -}; - -template -class SelectArgs { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4)); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - using ::std::tr1::get; - return SelectedArgs(get(args), get(args), get(args), - get(args)); - } -}; - -template -class SelectArgs { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5)); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - using ::std::tr1::get; - return SelectedArgs(get(args), get(args), get(args), - get(args), get(args)); - } -}; - -template -class SelectArgs { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), - GMOCK_FIELD_(ArgumentTuple, k6)); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - using ::std::tr1::get; - return SelectedArgs(get(args), get(args), get(args), - get(args), get(args), get(args)); - } -}; - -template -class SelectArgs { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), - GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7)); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - using ::std::tr1::get; - return SelectedArgs(get(args), get(args), get(args), - get(args), get(args), get(args), get(args)); - } -}; - -template -class SelectArgs { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), - GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), - GMOCK_FIELD_(ArgumentTuple, k8)); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - using ::std::tr1::get; - return SelectedArgs(get(args), get(args), get(args), - get(args), get(args), get(args), get(args), - get(args)); - } -}; - -template -class SelectArgs { - public: - typedef Result type(GMOCK_FIELD_(ArgumentTuple, k1), - GMOCK_FIELD_(ArgumentTuple, k2), GMOCK_FIELD_(ArgumentTuple, k3), - GMOCK_FIELD_(ArgumentTuple, k4), GMOCK_FIELD_(ArgumentTuple, k5), - GMOCK_FIELD_(ArgumentTuple, k6), GMOCK_FIELD_(ArgumentTuple, k7), - GMOCK_FIELD_(ArgumentTuple, k8), GMOCK_FIELD_(ArgumentTuple, k9)); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - using ::std::tr1::get; - return SelectedArgs(get(args), get(args), get(args), - get(args), get(args), get(args), get(args), - get(args), get(args)); - } -}; - -#undef GMOCK_FIELD_ - -// Implements the WithArgs action. -template -class WithArgsAction { - public: - explicit WithArgsAction(const InnerAction& action) : action_(action) {} - - template - operator Action() const { return MakeAction(new Impl(action_)); } - - private: - template - class Impl : public ActionInterface { - public: - typedef typename Function::Result Result; - typedef typename Function::ArgumentTuple ArgumentTuple; - - explicit Impl(const InnerAction& action) : action_(action) {} - - virtual Result Perform(const ArgumentTuple& args) { - return action_.Perform(SelectArgs::Select(args)); - } - - private: - typedef typename SelectArgs::type InnerFunctionType; - - Action action_; - }; - - const InnerAction action_; - - GTEST_DISALLOW_ASSIGN_(WithArgsAction); -}; - -// A macro from the ACTION* family (defined later in this file) -// defines an action that can be used in a mock function. Typically, -// these actions only care about a subset of the arguments of the mock -// function. For example, if such an action only uses the second -// argument, it can be used in any mock function that takes >= 2 -// arguments where the type of the second argument is compatible. -// -// Therefore, the action implementation must be prepared to take more -// arguments than it needs. The ExcessiveArg type is used to -// represent those excessive arguments. In order to keep the compiler -// error messages tractable, we define it in the testing namespace -// instead of testing::internal. However, this is an INTERNAL TYPE -// and subject to change without notice, so a user MUST NOT USE THIS -// TYPE DIRECTLY. -struct ExcessiveArg {}; - -// A helper class needed for implementing the ACTION* macros. -template -class ActionHelper { - public: - static Result Perform(Impl* impl, const ::std::tr1::tuple<>& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl<>(args, ExcessiveArg(), - ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg()); - } - - template - static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl(args, get<0>(args), - ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg()); - } - - template - static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl(args, get<0>(args), - get<1>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg()); - } - - template - static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl(args, get<0>(args), - get<1>(args), get<2>(args), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg()); - } - - template - static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl(args, get<0>(args), - get<1>(args), get<2>(args), get<3>(args), ExcessiveArg(), - ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg()); - } - - template - static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl(args, - get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), - ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg()); - } - - template - static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl(args, - get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), - get<5>(args), ExcessiveArg(), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg()); - } - - template - static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl(args, - get<0>(args), get<1>(args), get<2>(args), get<3>(args), get<4>(args), - get<5>(args), get<6>(args), ExcessiveArg(), ExcessiveArg(), - ExcessiveArg()); - } - - template - static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), - get<4>(args), get<5>(args), get<6>(args), get<7>(args), ExcessiveArg(), - ExcessiveArg()); - } - - template - static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), - get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), - ExcessiveArg()); - } - - template - static Result Perform(Impl* impl, const ::std::tr1::tuple& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl(args, get<0>(args), get<1>(args), get<2>(args), get<3>(args), - get<4>(args), get<5>(args), get<6>(args), get<7>(args), get<8>(args), - get<9>(args)); - } -}; - -} // namespace internal - -// Various overloads for Invoke(). - -// WithArgs(an_action) creates an action that passes -// the selected arguments of the mock function to an_action and -// performs it. It serves as an adaptor between actions with -// different argument lists. C++ doesn't support default arguments for -// function templates, so we have to overload it. -template -inline internal::WithArgsAction -WithArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -template -inline internal::WithArgsAction -WithArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -template -inline internal::WithArgsAction -WithArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -template -inline internal::WithArgsAction -WithArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -template -inline internal::WithArgsAction -WithArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -template -inline internal::WithArgsAction -WithArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -template -inline internal::WithArgsAction -WithArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -template -inline internal::WithArgsAction -WithArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -template -inline internal::WithArgsAction -WithArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -template -inline internal::WithArgsAction -WithArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -// Creates an action that does actions a1, a2, ..., sequentially in -// each invocation. -template -inline internal::DoBothAction -DoAll(Action1 a1, Action2 a2) { - return internal::DoBothAction(a1, a2); -} - -template -inline internal::DoBothAction > -DoAll(Action1 a1, Action2 a2, Action3 a3) { - return DoAll(a1, DoAll(a2, a3)); -} - -template -inline internal::DoBothAction > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4) { - return DoAll(a1, DoAll(a2, a3, a4)); -} - -template -inline internal::DoBothAction > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5) { - return DoAll(a1, DoAll(a2, a3, a4, a5)); -} - -template -inline internal::DoBothAction > > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6) { - return DoAll(a1, DoAll(a2, a3, a4, a5, a6)); -} - -template -inline internal::DoBothAction > > > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, - Action7 a7) { - return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7)); -} - -template -inline internal::DoBothAction > > > > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, - Action7 a7, Action8 a8) { - return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8)); -} - -template -inline internal::DoBothAction > > > > > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, - Action7 a7, Action8 a8, Action9 a9) { - return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9)); -} - -template -inline internal::DoBothAction > > > > > > > > -DoAll(Action1 a1, Action2 a2, Action3 a3, Action4 a4, Action5 a5, Action6 a6, - Action7 a7, Action8 a8, Action9 a9, Action10 a10) { - return DoAll(a1, DoAll(a2, a3, a4, a5, a6, a7, a8, a9, a10)); -} - -} // namespace testing - -// The ACTION* family of macros can be used in a namespace scope to -// define custom actions easily. The syntax: -// -// ACTION(name) { statements; } -// -// will define an action with the given name that executes the -// statements. The value returned by the statements will be used as -// the return value of the action. Inside the statements, you can -// refer to the K-th (0-based) argument of the mock function by -// 'argK', and refer to its type by 'argK_type'. For example: -// -// ACTION(IncrementArg1) { -// arg1_type temp = arg1; -// return ++(*temp); -// } -// -// allows you to write -// -// ...WillOnce(IncrementArg1()); -// -// You can also refer to the entire argument tuple and its type by -// 'args' and 'args_type', and refer to the mock function type and its -// return type by 'function_type' and 'return_type'. -// -// Note that you don't need to specify the types of the mock function -// arguments. However rest assured that your code is still type-safe: -// you'll get a compiler error if *arg1 doesn't support the ++ -// operator, or if the type of ++(*arg1) isn't compatible with the -// mock function's return type, for example. -// -// Sometimes you'll want to parameterize the action. For that you can use -// another macro: -// -// ACTION_P(name, param_name) { statements; } -// -// For example: -// -// ACTION_P(Add, n) { return arg0 + n; } -// -// will allow you to write: -// -// ...WillOnce(Add(5)); -// -// Note that you don't need to provide the type of the parameter -// either. If you need to reference the type of a parameter named -// 'foo', you can write 'foo_type'. For example, in the body of -// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type -// of 'n'. -// -// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P10 to support -// multi-parameter actions. -// -// For the purpose of typing, you can view -// -// ACTION_Pk(Foo, p1, ..., pk) { ... } -// -// as shorthand for -// -// template -// FooActionPk Foo(p1_type p1, ..., pk_type pk) { ... } -// -// In particular, you can provide the template type arguments -// explicitly when invoking Foo(), as in Foo(5, false); -// although usually you can rely on the compiler to infer the types -// for you automatically. You can assign the result of expression -// Foo(p1, ..., pk) to a variable of type FooActionPk. This can be useful when composing actions. -// -// You can also overload actions with different numbers of parameters: -// -// ACTION_P(Plus, a) { ... } -// ACTION_P2(Plus, a, b) { ... } -// -// While it's tempting to always use the ACTION* macros when defining -// a new action, you should also consider implementing ActionInterface -// or using MakePolymorphicAction() instead, especially if you need to -// use the action a lot. While these approaches require more work, -// they give you more control on the types of the mock function -// arguments and the action parameters, which in general leads to -// better compiler error messages that pay off in the long run. They -// also allow overloading actions based on parameter types (as opposed -// to just based on the number of parameters). -// -// CAVEAT: -// -// ACTION*() can only be used in a namespace scope. The reason is -// that C++ doesn't yet allow function-local types to be used to -// instantiate templates. The up-coming C++0x standard will fix this. -// Once that's done, we'll consider supporting using ACTION*() inside -// a function. -// -// MORE INFORMATION: -// -// To learn more about using these macros, please search for 'ACTION' -// on http://code.google.com/p/googlemock/wiki/CookBook. - -// An internal macro needed for implementing ACTION*(). -#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\ - const args_type& args GTEST_ATTRIBUTE_UNUSED_,\ - arg0_type arg0 GTEST_ATTRIBUTE_UNUSED_,\ - arg1_type arg1 GTEST_ATTRIBUTE_UNUSED_,\ - arg2_type arg2 GTEST_ATTRIBUTE_UNUSED_,\ - arg3_type arg3 GTEST_ATTRIBUTE_UNUSED_,\ - arg4_type arg4 GTEST_ATTRIBUTE_UNUSED_,\ - arg5_type arg5 GTEST_ATTRIBUTE_UNUSED_,\ - arg6_type arg6 GTEST_ATTRIBUTE_UNUSED_,\ - arg7_type arg7 GTEST_ATTRIBUTE_UNUSED_,\ - arg8_type arg8 GTEST_ATTRIBUTE_UNUSED_,\ - arg9_type arg9 GTEST_ATTRIBUTE_UNUSED_ - -// Sometimes you want to give an action explicit template parameters -// that cannot be inferred from its value parameters. ACTION() and -// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that -// and can be viewed as an extension to ACTION() and ACTION_P*(). -// -// The syntax: -// -// ACTION_TEMPLATE(ActionName, -// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m), -// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; } -// -// defines an action template that takes m explicit template -// parameters and n value parameters. name_i is the name of the i-th -// template parameter, and kind_i specifies whether it's a typename, -// an integral constant, or a template. p_i is the name of the i-th -// value parameter. -// -// Example: -// -// // DuplicateArg(output) converts the k-th argument of the mock -// // function to type T and copies it to *output. -// ACTION_TEMPLATE(DuplicateArg, -// HAS_2_TEMPLATE_PARAMS(int, k, typename, T), -// AND_1_VALUE_PARAMS(output)) { -// *output = T(std::tr1::get(args)); -// } -// ... -// int n; -// EXPECT_CALL(mock, Foo(_, _)) -// .WillOnce(DuplicateArg<1, unsigned char>(&n)); -// -// To create an instance of an action template, write: -// -// ActionName(v1, ..., v_n) -// -// where the ts are the template arguments and the vs are the value -// arguments. The value argument types are inferred by the compiler. -// If you want to explicitly specify the value argument types, you can -// provide additional template arguments: -// -// ActionName(v1, ..., v_n) -// -// where u_i is the desired type of v_i. -// -// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the -// number of value parameters, but not on the number of template -// parameters. Without the restriction, the meaning of the following -// is unclear: -// -// OverloadedAction(x); -// -// Are we using a single-template-parameter action where 'bool' refers -// to the type of x, or are we using a two-template-parameter action -// where the compiler is asked to infer the type of x? -// -// Implementation notes: -// -// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and -// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for -// implementing ACTION_TEMPLATE. The main trick we use is to create -// new macro invocations when expanding a macro. For example, we have -// -// #define ACTION_TEMPLATE(name, template_params, value_params) -// ... GMOCK_INTERNAL_DECL_##template_params ... -// -// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...) -// to expand to -// -// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ... -// -// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the -// preprocessor will continue to expand it to -// -// ... typename T ... -// -// This technique conforms to the C++ standard and is portable. It -// allows us to implement action templates using O(N) code, where N is -// the maximum number of template/value parameters supported. Without -// using it, we'd have to devote O(N^2) amount of code to implement all -// combinations of m and n. - -// Declares the template parameters. -#define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0 -#define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ - name1) kind0 name0, kind1 name1 -#define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2) kind0 name0, kind1 name1, kind2 name2 -#define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \ - kind3 name3 -#define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \ - kind2 name2, kind3 name3, kind4 name4 -#define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \ - kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5 -#define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ - name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \ - kind5 name5, kind6 name6 -#define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ - kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \ - kind4 name4, kind5 name5, kind6 name6, kind7 name7 -#define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ - kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \ - kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \ - kind8 name8 -#define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ - name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ - name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \ - kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \ - kind6 name6, kind7 name7, kind8 name8, kind9 name9 - -// Lists the template parameters. -#define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0 -#define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \ - name1) name0, name1 -#define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2) name0, name1, name2 -#define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3) name0, name1, name2, name3 -#define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \ - name4 -#define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \ - name2, name3, name4, name5 -#define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ - name6) name0, name1, name2, name3, name4, name5, name6 -#define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ - kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7 -#define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \ - kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \ - kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \ - name6, name7, name8 -#define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \ - name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \ - name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \ - name3, name4, name5, name6, name7, name8, name9 - -// Declares the types of value parameters. -#define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS() -#define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type -#define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \ - typename p0##_type, typename p1##_type -#define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \ - typename p0##_type, typename p1##_type, typename p2##_type -#define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ - typename p0##_type, typename p1##_type, typename p2##_type, \ - typename p3##_type -#define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ - typename p0##_type, typename p1##_type, typename p2##_type, \ - typename p3##_type, typename p4##_type -#define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ - typename p0##_type, typename p1##_type, typename p2##_type, \ - typename p3##_type, typename p4##_type, typename p5##_type -#define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ - p6) , typename p0##_type, typename p1##_type, typename p2##_type, \ - typename p3##_type, typename p4##_type, typename p5##_type, \ - typename p6##_type -#define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ - p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \ - typename p3##_type, typename p4##_type, typename p5##_type, \ - typename p6##_type, typename p7##_type -#define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ - p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \ - typename p3##_type, typename p4##_type, typename p5##_type, \ - typename p6##_type, typename p7##_type, typename p8##_type -#define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ - p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \ - typename p2##_type, typename p3##_type, typename p4##_type, \ - typename p5##_type, typename p6##_type, typename p7##_type, \ - typename p8##_type, typename p9##_type - -// Initializes the value parameters. -#define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\ - () -#define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\ - (p0##_type gmock_p0) : p0(gmock_p0) -#define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\ - (p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), p1(gmock_p1) -#define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\ - (p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) -#define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\ - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3) -#define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\ - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) -#define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\ - (p0##_type gmock_p0, p1##_type gmock_p1, 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), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) -#define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\ - (p0##_type gmock_p0, p1##_type gmock_p1, 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), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) -#define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\ - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \ - p6##_type gmock_p6, 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), \ - p7(gmock_p7) -#define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7, p8)\ - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4, 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), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8) -#define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7, p8, p9)\ - (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4, 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), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8), p9(gmock_p9) - -// Declares the fields for storing the value parameters. -#define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS() -#define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0; -#define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \ - p1##_type p1; -#define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \ - p1##_type p1; p2##_type p2; -#define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \ - p1##_type p1; p2##_type p2; p3##_type p3; -#define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ - p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; -#define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ - p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ - p5##_type p5; -#define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ - p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ - p5##_type p5; p6##_type p6; -#define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \ - p5##_type p5; p6##_type p6; p7##_type p7; -#define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ - p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; -#define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \ - p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \ - p9##_type p9; - -// Lists the value parameters. -#define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS() -#define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0 -#define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1 -#define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2 -#define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3 -#define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \ - p2, p3, p4 -#define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \ - p1, p2, p3, p4, p5 -#define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ - p6) p0, p1, p2, p3, p4, p5, p6 -#define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7) p0, p1, p2, p3, p4, p5, p6, p7 -#define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8 -#define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9 - -// Lists the value parameter types. -#define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS() -#define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type -#define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \ - p1##_type -#define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \ - p1##_type, p2##_type -#define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \ - p0##_type, p1##_type, p2##_type, p3##_type -#define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \ - p0##_type, p1##_type, p2##_type, p3##_type, p4##_type -#define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \ - p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type -#define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ - p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \ - p6##_type -#define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ - p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ - p5##_type, p6##_type, p7##_type -#define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ - p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ - p5##_type, p6##_type, p7##_type, p8##_type -#define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ - p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \ - p5##_type, p6##_type, p7##_type, p8##_type, p9##_type - -// Declares the value parameters. -#define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS() -#define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0 -#define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \ - p1##_type p1 -#define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \ - p1##_type p1, p2##_type p2 -#define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \ - p1##_type p1, p2##_type p2, p3##_type p3 -#define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \ - p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4 -#define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \ - p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ - p5##_type p5 -#define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \ - p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ - p5##_type p5, p6##_type p6 -#define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \ - p5##_type p5, p6##_type p6, p7##_type p7 -#define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ - p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8 -#define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ - p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ - p9##_type p9 - -// The suffix of the class template implementing the action template. -#define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS() -#define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P -#define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2 -#define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3 -#define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4 -#define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5 -#define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6 -#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, \ - p7) P8 -#define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7, p8) P9 -#define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \ - p7, p8, p9) P10 - -// The name of the class template implementing the action template. -#define GMOCK_ACTION_CLASS_(name, value_params)\ - GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params) - -#define ACTION_TEMPLATE(name, template_params, value_params)\ - template \ - class GMOCK_ACTION_CLASS_(name, value_params) {\ - public:\ - GMOCK_ACTION_CLASS_(name, value_params)\ - GMOCK_INTERNAL_INIT_##value_params {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - GMOCK_INTERNAL_DEFN_##value_params\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(\ - new gmock_Impl(GMOCK_INTERNAL_LIST_##value_params));\ - }\ - GMOCK_INTERNAL_DEFN_##value_params\ - private:\ - GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\ - };\ - template \ - inline GMOCK_ACTION_CLASS_(name, value_params)<\ - GMOCK_INTERNAL_LIST_##template_params\ - GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\ - GMOCK_INTERNAL_DECL_##value_params) {\ - return GMOCK_ACTION_CLASS_(name, value_params)<\ - GMOCK_INTERNAL_LIST_##template_params\ - GMOCK_INTERNAL_LIST_TYPE_##value_params>(\ - GMOCK_INTERNAL_LIST_##value_params);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - GMOCK_ACTION_CLASS_(name, value_params)<\ - GMOCK_INTERNAL_LIST_##template_params\ - GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl::\ - gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION(name)\ - class name##Action {\ - public:\ - name##Action() {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl() {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl());\ - }\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##Action);\ - };\ - inline name##Action name() {\ - return name##Action();\ - }\ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##Action::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P(name, p0)\ - template \ - class name##ActionP {\ - public:\ - name##ActionP(p0##_type gmock_p0) : p0(gmock_p0) {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - explicit gmock_Impl(p0##_type gmock_p0) : p0(gmock_p0) {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - p0##_type p0;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl(p0));\ - }\ - p0##_type p0;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP);\ - };\ - template \ - inline name##ActionP name(p0##_type p0) {\ - return name##ActionP(p0);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P2(name, p0, p1)\ - template \ - class name##ActionP2 {\ - public:\ - name##ActionP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ - p1(gmock_p1) {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ - p1(gmock_p1) {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - p0##_type p0;\ - p1##_type p1;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl(p0, p1));\ - }\ - p0##_type p0;\ - p1##_type p1;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP2);\ - };\ - template \ - inline name##ActionP2 name(p0##_type p0, \ - p1##_type p1) {\ - return name##ActionP2(p0, p1);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP2::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P3(name, p0, p1, p2)\ - template \ - class name##ActionP3 {\ - public:\ - name##ActionP3(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl(p0, p1, p2));\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP3);\ - };\ - template \ - inline name##ActionP3 name(p0##_type p0, \ - p1##_type p1, p2##_type p2) {\ - return name##ActionP3(p0, p1, p2);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP3::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P4(name, p0, p1, p2, p3)\ - template \ - class name##ActionP4 {\ - public:\ - name##ActionP4(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \ - p2(gmock_p2), p3(gmock_p3) {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3) {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl(p0, p1, p2, p3));\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP4);\ - };\ - template \ - inline name##ActionP4 name(p0##_type p0, p1##_type p1, p2##_type p2, \ - p3##_type p3) {\ - return name##ActionP4(p0, p1, \ - p2, p3);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP4::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P5(name, p0, p1, p2, p3, p4)\ - template \ - class name##ActionP5 {\ - public:\ - name##ActionP5(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, \ - p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4) {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4) : p0(gmock_p0), \ - p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), p4(gmock_p4) {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4));\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP5);\ - };\ - template \ - inline name##ActionP5 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ - p4##_type p4) {\ - return name##ActionP5(p0, p1, p2, p3, p4);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP5::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P6(name, p0, p1, p2, p3, p4, p5)\ - template \ - class name##ActionP6 {\ - public:\ - name##ActionP6(p0##_type gmock_p0, p1##_type gmock_p1, \ - 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), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - 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) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4, p5));\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP6);\ - };\ - template \ - inline name##ActionP6 name(p0##_type p0, p1##_type p1, p2##_type p2, \ - p3##_type p3, p4##_type p4, p5##_type p5) {\ - return name##ActionP6(p0, p1, p2, p3, p4, p5);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP6::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P7(name, p0, p1, p2, p3, p4, p5, p6)\ - template \ - class name##ActionP7 {\ - public:\ - name##ActionP7(p0##_type gmock_p0, p1##_type gmock_p1, \ - 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), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ - p6(gmock_p6) {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - 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, \ - p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4, p5, \ - p6));\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP7);\ - };\ - template \ - inline name##ActionP7 name(p0##_type p0, p1##_type p1, \ - p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ - p6##_type p6) {\ - return name##ActionP7(p0, p1, p2, p3, p4, p5, p6);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP7::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P8(name, p0, p1, p2, p3, p4, p5, p6, p7)\ - template \ - class name##ActionP8 {\ - public:\ - name##ActionP8(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ - p5##_type gmock_p5, p6##_type gmock_p6, \ - 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), \ - p7(gmock_p7) {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - 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, \ - p6##_type gmock_p6, 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), p7(gmock_p7) {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4, p5, \ - p6, p7));\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP8);\ - };\ - template \ - inline name##ActionP8 name(p0##_type p0, \ - p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ - p6##_type p6, p7##_type p7) {\ - return name##ActionP8(p0, p1, p2, p3, p4, p5, \ - p6, p7);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP8::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8)\ - template \ - class name##ActionP9 {\ - public:\ - name##ActionP9(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ - 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), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8) {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - 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, \ - p6##_type gmock_p6, p7##_type gmock_p7, \ - 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), p8(gmock_p8) {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - p8##_type p8;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4, p5, \ - p6, p7, p8));\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - p8##_type p8;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP9);\ - };\ - template \ - inline name##ActionP9 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ - p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ - p8##_type p8) {\ - return name##ActionP9(p0, p1, p2, \ - p3, p4, p5, p6, p7, p8);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP9::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -#define ACTION_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)\ - template \ - class name##ActionP10 {\ - public:\ - name##ActionP10(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ - 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), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - 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, \ - p6##_type gmock_p6, p7##_type gmock_p7, 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), \ - p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template \ - return_type gmock_PerformImpl(const args_type& args, arg0_type arg0, \ - arg1_type arg1, arg2_type arg2, arg3_type arg3, arg4_type arg4, \ - arg5_type arg5, arg6_type arg6, arg7_type arg7, arg8_type arg8, \ - arg9_type arg9) const;\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - p8##_type p8;\ - p9##_type p9;\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl(p0, p1, p2, p3, p4, p5, \ - p6, p7, p8, p9));\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - p8##_type p8;\ - p9##_type p9;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##ActionP10);\ - };\ - template \ - inline name##ActionP10 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ - p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ - p9##_type p9) {\ - return name##ActionP10(p0, \ - p1, p2, p3, p4, p5, p6, p7, p8, p9);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - name##ActionP10::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -// TODO(wan@google.com): move the following to a different .h file -// such that we don't have to run 'pump' every time the code is -// updated. -namespace testing { - -// The ACTION*() macros trigger warning C4100 (unreferenced formal -// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in -// the macro definition, as the warnings are generated when the macro -// is expanded and macro expansion cannot contain #pragma. Therefore -// we suppress them here. -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4100) -#endif - -// Various overloads for InvokeArgument(). -// -// The InvokeArgument(a1, a2, ..., a_k) action invokes the N-th -// (0-based) argument, which must be a k-ary callable, of the mock -// function, with arguments a1, a2, ..., a_k. -// -// Notes: -// -// 1. The arguments are passed by value by default. If you need to -// pass an argument by reference, wrap it inside ByRef(). For -// example, -// -// InvokeArgument<1>(5, string("Hello"), ByRef(foo)) -// -// passes 5 and string("Hello") by value, and passes foo by -// reference. -// -// 2. If the callable takes an argument by reference but ByRef() is -// not used, it will receive the reference to a copy of the value, -// instead of the original value. For example, when the 0-th -// argument of the mock function takes a const string&, the action -// -// InvokeArgument<0>(string("Hello")) -// -// makes a copy of the temporary string("Hello") object and passes a -// reference of the copy, instead of the original temporary object, -// to the callable. This makes it easy for a user to define an -// InvokeArgument action from temporary values and have it performed -// later. - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_0_VALUE_PARAMS()) { - return internal::CallableHelper::Call( - ::std::tr1::get(args)); -} - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_1_VALUE_PARAMS(p0)) { - return internal::CallableHelper::Call( - ::std::tr1::get(args), p0); -} - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_2_VALUE_PARAMS(p0, p1)) { - return internal::CallableHelper::Call( - ::std::tr1::get(args), p0, p1); -} - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_3_VALUE_PARAMS(p0, p1, p2)) { - return internal::CallableHelper::Call( - ::std::tr1::get(args), p0, p1, p2); -} - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_4_VALUE_PARAMS(p0, p1, p2, p3)) { - return internal::CallableHelper::Call( - ::std::tr1::get(args), p0, p1, p2, p3); -} - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) { - return internal::CallableHelper::Call( - ::std::tr1::get(args), p0, p1, p2, p3, p4); -} - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) { - return internal::CallableHelper::Call( - ::std::tr1::get(args), p0, p1, p2, p3, p4, p5); -} - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) { - return internal::CallableHelper::Call( - ::std::tr1::get(args), p0, p1, p2, p3, p4, p5, p6); -} - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) { - return internal::CallableHelper::Call( - ::std::tr1::get(args), p0, p1, p2, p3, p4, p5, p6, p7); -} - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) { - return internal::CallableHelper::Call( - ::std::tr1::get(args), p0, p1, p2, p3, p4, p5, p6, p7, p8); -} - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) { - return internal::CallableHelper::Call( - ::std::tr1::get(args), p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); -} - -// Various overloads for ReturnNew(). -// -// The ReturnNew(a1, a2, ..., a_k) action returns a pointer to a new -// instance of type T, constructed on the heap with constructor arguments -// a1, a2, ..., and a_k. The caller assumes ownership of the returned value. -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_0_VALUE_PARAMS()) { - return new T(); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_1_VALUE_PARAMS(p0)) { - return new T(p0); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_2_VALUE_PARAMS(p0, p1)) { - return new T(p0, p1); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_3_VALUE_PARAMS(p0, p1, p2)) { - return new T(p0, p1, p2); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_4_VALUE_PARAMS(p0, p1, p2, p3)) { - return new T(p0, p1, p2, p3); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) { - return new T(p0, p1, p2, p3, p4); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) { - return new T(p0, p1, p2, p3, p4, p5); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) { - return new T(p0, p1, p2, p3, p4, p5, p6); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) { - return new T(p0, p1, p2, p3, p4, p5, p6, p7); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) { - return new T(p0, p1, p2, p3, p4, p5, p6, p7, p8); -} - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - 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); -} - -#ifdef _MSC_VER -# pragma warning(pop) -#endif - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ diff --git a/lib/gmock/include/gmock/gmock-generated-actions.h.pump b/lib/gmock/include/gmock/gmock-generated-actions.h.pump deleted file mode 100644 index 001fd7d0..00000000 --- a/lib/gmock/include/gmock/gmock-generated-actions.h.pump +++ /dev/null @@ -1,825 +0,0 @@ -$$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-actions.h. -$$ -$var n = 10 $$ The maximum arity we support. -$$}} This meta comment fixes auto-indentation in editors. -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements some commonly used variadic actions. - -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ - -#include "gmock/gmock-actions.h" -#include "gmock/internal/gmock-port.h" - -namespace testing { -namespace internal { - -// InvokeHelper knows how to unpack an N-tuple and invoke an N-ary -// function or method with the unpacked values, where F is a function -// type that takes N arguments. -template -class InvokeHelper; - - -$range i 0..n -$for i [[ -$range j 1..i -$var types = [[$for j [[, typename A$j]]]] -$var as = [[$for j, [[A$j]]]] -$var args = [[$if i==0 [[]] $else [[ args]]]] -$var import = [[$if i==0 [[]] $else [[ - using ::std::tr1::get; - -]]]] -$var gets = [[$for j, [[get<$(j - 1)>(args)]]]] -template -class InvokeHelper > { - public: - template - static R Invoke(Function function, const ::std::tr1::tuple<$as>&$args) { -$import return function($gets); - } - - template - static R InvokeMethod(Class* obj_ptr, - MethodPtr method_ptr, - const ::std::tr1::tuple<$as>&$args) { -$import return (obj_ptr->*method_ptr)($gets); - } -}; - - -]] -// CallableHelper has static methods for invoking "callables", -// i.e. function pointers and functors. It uses overloading to -// provide a uniform interface for invoking different kinds of -// callables. In particular, you can use: -// -// CallableHelper::Call(callable, a1, a2, ..., an) -// -// to invoke an n-ary callable, where R is its return type. If an -// argument, say a2, needs to be passed by reference, you should write -// ByRef(a2) instead of a2 in the above expression. -template -class CallableHelper { - public: - // Calls a nullary callable. - template - static R Call(Function function) { return function(); } - - // Calls a unary callable. - - // We deliberately pass a1 by value instead of const reference here - // in case it is a C-string literal. If we had declared the - // parameter as 'const A1& a1' and write Call(function, "Hi"), the - // compiler would've thought A1 is 'char[3]', which causes trouble - // when you need to copy a value of type A1. By declaring the - // parameter as 'A1 a1', the compiler will correctly infer that A1 - // is 'const char*' when it sees Call(function, "Hi"). - // - // Since this function is defined inline, the compiler can get rid - // of the copying of the arguments. Therefore the performance won't - // be hurt. - template - static R Call(Function function, A1 a1) { return function(a1); } - -$range i 2..n -$for i -[[ -$var arity = [[$if i==2 [[binary]] $elif i==3 [[ternary]] $else [[$i-ary]]]] - - // Calls a $arity callable. - -$range j 1..i -$var typename_As = [[$for j, [[typename A$j]]]] -$var Aas = [[$for j, [[A$j a$j]]]] -$var as = [[$for j, [[a$j]]]] -$var typename_Ts = [[$for j, [[typename T$j]]]] -$var Ts = [[$for j, [[T$j]]]] - template - static R Call(Function function, $Aas) { - return function($as); - } - -]] - -}; // class CallableHelper - -// An INTERNAL macro for extracting the type of a tuple field. It's -// subject to change without notice - DO NOT USE IN USER CODE! -#define GMOCK_FIELD_(Tuple, N) \ - typename ::std::tr1::tuple_element::type - -$range i 1..n - -// SelectArgs::type is the -// type of an n-ary function whose i-th (1-based) argument type is the -// k{i}-th (0-based) field of ArgumentTuple, which must be a tuple -// type, and whose return type is Result. For example, -// SelectArgs, 0, 3>::type -// is int(bool, long). -// -// SelectArgs::Select(args) -// returns the selected fields (k1, k2, ..., k_n) of args as a tuple. -// For example, -// SelectArgs, 2, 0>::Select( -// ::std::tr1::make_tuple(true, 'a', 2.5)) -// returns ::std::tr1::tuple (2.5, true). -// -// The numbers in list k1, k2, ..., k_n must be >= 0, where n can be -// in the range [0, $n]. Duplicates are allowed and they don't have -// to be in an ascending or descending order. - -template -class SelectArgs { - public: - typedef Result type($for i, [[GMOCK_FIELD_(ArgumentTuple, k$i)]]); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& args) { - using ::std::tr1::get; - return SelectedArgs($for i, [[get(args)]]); - } -}; - - -$for i [[ -$range j 1..n -$range j1 1..i-1 -template -class SelectArgs { - public: - typedef Result type($for j1, [[GMOCK_FIELD_(ArgumentTuple, k$j1)]]); - typedef typename Function::ArgumentTuple SelectedArgs; - static SelectedArgs Select(const ArgumentTuple& [[]] -$if i == 1 [[/* args */]] $else [[args]]) { - using ::std::tr1::get; - return SelectedArgs($for j1, [[get(args)]]); - } -}; - - -]] -#undef GMOCK_FIELD_ - -$var ks = [[$for i, [[k$i]]]] - -// Implements the WithArgs action. -template -class WithArgsAction { - public: - explicit WithArgsAction(const InnerAction& action) : action_(action) {} - - template - operator Action() const { return MakeAction(new Impl(action_)); } - - private: - template - class Impl : public ActionInterface { - public: - typedef typename Function::Result Result; - typedef typename Function::ArgumentTuple ArgumentTuple; - - explicit Impl(const InnerAction& action) : action_(action) {} - - virtual Result Perform(const ArgumentTuple& args) { - return action_.Perform(SelectArgs::Select(args)); - } - - private: - typedef typename SelectArgs::type InnerFunctionType; - - Action action_; - }; - - const InnerAction action_; - - GTEST_DISALLOW_ASSIGN_(WithArgsAction); -}; - -// A macro from the ACTION* family (defined later in this file) -// defines an action that can be used in a mock function. Typically, -// these actions only care about a subset of the arguments of the mock -// function. For example, if such an action only uses the second -// argument, it can be used in any mock function that takes >= 2 -// arguments where the type of the second argument is compatible. -// -// Therefore, the action implementation must be prepared to take more -// arguments than it needs. The ExcessiveArg type is used to -// represent those excessive arguments. In order to keep the compiler -// error messages tractable, we define it in the testing namespace -// instead of testing::internal. However, this is an INTERNAL TYPE -// and subject to change without notice, so a user MUST NOT USE THIS -// TYPE DIRECTLY. -struct ExcessiveArg {}; - -// A helper class needed for implementing the ACTION* macros. -template -class ActionHelper { - public: -$range i 0..n -$for i - -[[ -$var template = [[$if i==0 [[]] $else [[ -$range j 0..i-1 - template <$for j, [[typename A$j]]> -]]]] -$range j 0..i-1 -$var As = [[$for j, [[A$j]]]] -$var as = [[$for j, [[get<$j>(args)]]]] -$range k 1..n-i -$var eas = [[$for k, [[ExcessiveArg()]]]] -$var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]] -$template - static Result Perform(Impl* impl, const ::std::tr1::tuple<$As>& args) { - using ::std::tr1::get; - return impl->template gmock_PerformImpl<$As>(args, $arg_list); - } - -]] -}; - -} // namespace internal - -// Various overloads for Invoke(). - -// WithArgs(an_action) creates an action that passes -// the selected arguments of the mock function to an_action and -// performs it. It serves as an adaptor between actions with -// different argument lists. C++ doesn't support default arguments for -// function templates, so we have to overload it. - -$range i 1..n -$for i [[ -$range j 1..i -template <$for j [[int k$j, ]]typename InnerAction> -inline internal::WithArgsAction -WithArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - - -]] -// Creates an action that does actions a1, a2, ..., sequentially in -// each invocation. -$range i 2..n -$for i [[ -$range j 2..i -$var types = [[$for j, [[typename Action$j]]]] -$var Aas = [[$for j [[, Action$j a$j]]]] - -template -$range k 1..i-1 - -inline $for k [[internal::DoBothAction]] - -DoAll(Action1 a1$Aas) { -$if i==2 [[ - - return internal::DoBothAction(a1, a2); -]] $else [[ -$range j2 2..i - - return DoAll(a1, DoAll($for j2, [[a$j2]])); -]] - -} - -]] - -} // namespace testing - -// The ACTION* family of macros can be used in a namespace scope to -// define custom actions easily. The syntax: -// -// ACTION(name) { statements; } -// -// will define an action with the given name that executes the -// statements. The value returned by the statements will be used as -// the return value of the action. Inside the statements, you can -// refer to the K-th (0-based) argument of the mock function by -// 'argK', and refer to its type by 'argK_type'. For example: -// -// ACTION(IncrementArg1) { -// arg1_type temp = arg1; -// return ++(*temp); -// } -// -// allows you to write -// -// ...WillOnce(IncrementArg1()); -// -// You can also refer to the entire argument tuple and its type by -// 'args' and 'args_type', and refer to the mock function type and its -// return type by 'function_type' and 'return_type'. -// -// Note that you don't need to specify the types of the mock function -// arguments. However rest assured that your code is still type-safe: -// you'll get a compiler error if *arg1 doesn't support the ++ -// operator, or if the type of ++(*arg1) isn't compatible with the -// mock function's return type, for example. -// -// Sometimes you'll want to parameterize the action. For that you can use -// another macro: -// -// ACTION_P(name, param_name) { statements; } -// -// For example: -// -// ACTION_P(Add, n) { return arg0 + n; } -// -// will allow you to write: -// -// ...WillOnce(Add(5)); -// -// Note that you don't need to provide the type of the parameter -// either. If you need to reference the type of a parameter named -// 'foo', you can write 'foo_type'. For example, in the body of -// ACTION_P(Add, n) above, you can write 'n_type' to refer to the type -// of 'n'. -// -// We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P$n to support -// multi-parameter actions. -// -// For the purpose of typing, you can view -// -// ACTION_Pk(Foo, p1, ..., pk) { ... } -// -// as shorthand for -// -// template -// FooActionPk Foo(p1_type p1, ..., pk_type pk) { ... } -// -// In particular, you can provide the template type arguments -// explicitly when invoking Foo(), as in Foo(5, false); -// although usually you can rely on the compiler to infer the types -// for you automatically. You can assign the result of expression -// Foo(p1, ..., pk) to a variable of type FooActionPk. This can be useful when composing actions. -// -// You can also overload actions with different numbers of parameters: -// -// ACTION_P(Plus, a) { ... } -// ACTION_P2(Plus, a, b) { ... } -// -// While it's tempting to always use the ACTION* macros when defining -// a new action, you should also consider implementing ActionInterface -// or using MakePolymorphicAction() instead, especially if you need to -// use the action a lot. While these approaches require more work, -// they give you more control on the types of the mock function -// arguments and the action parameters, which in general leads to -// better compiler error messages that pay off in the long run. They -// also allow overloading actions based on parameter types (as opposed -// to just based on the number of parameters). -// -// CAVEAT: -// -// ACTION*() can only be used in a namespace scope. The reason is -// that C++ doesn't yet allow function-local types to be used to -// instantiate templates. The up-coming C++0x standard will fix this. -// Once that's done, we'll consider supporting using ACTION*() inside -// a function. -// -// MORE INFORMATION: -// -// To learn more about using these macros, please search for 'ACTION' -// on http://code.google.com/p/googlemock/wiki/CookBook. - -$range i 0..n -$range k 0..n-1 - -// An internal macro needed for implementing ACTION*(). -#define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\ - const args_type& args GTEST_ATTRIBUTE_UNUSED_ -$for k [[,\ - arg$k[[]]_type arg$k GTEST_ATTRIBUTE_UNUSED_]] - - -// Sometimes you want to give an action explicit template parameters -// that cannot be inferred from its value parameters. ACTION() and -// ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that -// and can be viewed as an extension to ACTION() and ACTION_P*(). -// -// The syntax: -// -// ACTION_TEMPLATE(ActionName, -// HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m), -// AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; } -// -// defines an action template that takes m explicit template -// parameters and n value parameters. name_i is the name of the i-th -// template parameter, and kind_i specifies whether it's a typename, -// an integral constant, or a template. p_i is the name of the i-th -// value parameter. -// -// Example: -// -// // DuplicateArg(output) converts the k-th argument of the mock -// // function to type T and copies it to *output. -// ACTION_TEMPLATE(DuplicateArg, -// HAS_2_TEMPLATE_PARAMS(int, k, typename, T), -// AND_1_VALUE_PARAMS(output)) { -// *output = T(std::tr1::get(args)); -// } -// ... -// int n; -// EXPECT_CALL(mock, Foo(_, _)) -// .WillOnce(DuplicateArg<1, unsigned char>(&n)); -// -// To create an instance of an action template, write: -// -// ActionName(v1, ..., v_n) -// -// where the ts are the template arguments and the vs are the value -// arguments. The value argument types are inferred by the compiler. -// If you want to explicitly specify the value argument types, you can -// provide additional template arguments: -// -// ActionName(v1, ..., v_n) -// -// where u_i is the desired type of v_i. -// -// ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the -// number of value parameters, but not on the number of template -// parameters. Without the restriction, the meaning of the following -// is unclear: -// -// OverloadedAction(x); -// -// Are we using a single-template-parameter action where 'bool' refers -// to the type of x, or are we using a two-template-parameter action -// where the compiler is asked to infer the type of x? -// -// Implementation notes: -// -// GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and -// GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for -// implementing ACTION_TEMPLATE. The main trick we use is to create -// new macro invocations when expanding a macro. For example, we have -// -// #define ACTION_TEMPLATE(name, template_params, value_params) -// ... GMOCK_INTERNAL_DECL_##template_params ... -// -// which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...) -// to expand to -// -// ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ... -// -// Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the -// preprocessor will continue to expand it to -// -// ... typename T ... -// -// This technique conforms to the C++ standard and is portable. It -// allows us to implement action templates using O(N) code, where N is -// the maximum number of template/value parameters supported. Without -// using it, we'd have to devote O(N^2) amount of code to implement all -// combinations of m and n. - -// Declares the template parameters. - -$range j 1..n -$for j [[ -$range m 0..j-1 -#define GMOCK_INTERNAL_DECL_HAS_$j[[]] -_TEMPLATE_PARAMS($for m, [[kind$m, name$m]]) $for m, [[kind$m name$m]] - - -]] - -// Lists the template parameters. - -$for j [[ -$range m 0..j-1 -#define GMOCK_INTERNAL_LIST_HAS_$j[[]] -_TEMPLATE_PARAMS($for m, [[kind$m, name$m]]) $for m, [[name$m]] - - -]] - -// Declares the types of value parameters. - -$for i [[ -$range j 0..i-1 -#define GMOCK_INTERNAL_DECL_TYPE_AND_$i[[]] -_VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]] - - -]] - -// Initializes the value parameters. - -$for i [[ -$range j 0..i-1 -#define GMOCK_INTERNAL_INIT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])\ - ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(gmock_p$j)]] - - -]] - -// Declares the fields for storing the value parameters. - -$for i [[ -$range j 0..i-1 -#define GMOCK_INTERNAL_DEFN_AND_$i[[]] -_VALUE_PARAMS($for j, [[p$j]]) $for j [[p$j##_type p$j; ]] - - -]] - -// Lists the value parameters. - -$for i [[ -$range j 0..i-1 -#define GMOCK_INTERNAL_LIST_AND_$i[[]] -_VALUE_PARAMS($for j, [[p$j]]) $for j, [[p$j]] - - -]] - -// Lists the value parameter types. - -$for i [[ -$range j 0..i-1 -#define GMOCK_INTERNAL_LIST_TYPE_AND_$i[[]] -_VALUE_PARAMS($for j, [[p$j]]) $for j [[, p$j##_type]] - - -]] - -// Declares the value parameters. - -$for i [[ -$range j 0..i-1 -#define GMOCK_INTERNAL_DECL_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]]) [[]] -$for j, [[p$j##_type p$j]] - - -]] - -// The suffix of the class template implementing the action template. -$for i [[ - - -$range j 0..i-1 -#define GMOCK_INTERNAL_COUNT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]]) [[]] -$if i==1 [[P]] $elif i>=2 [[P$i]] -]] - - -// The name of the class template implementing the action template. -#define GMOCK_ACTION_CLASS_(name, value_params)\ - GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params) - -$range k 0..n-1 - -#define ACTION_TEMPLATE(name, template_params, value_params)\ - template \ - class GMOCK_ACTION_CLASS_(name, value_params) {\ - public:\ - GMOCK_ACTION_CLASS_(name, value_params)\ - GMOCK_INTERNAL_INIT_##value_params {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template <$for k, [[typename arg$k[[]]_type]]>\ - return_type gmock_PerformImpl(const args_type& args[[]] -$for k [[, arg$k[[]]_type arg$k]]) const;\ - GMOCK_INTERNAL_DEFN_##value_params\ - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(\ - new gmock_Impl(GMOCK_INTERNAL_LIST_##value_params));\ - }\ - GMOCK_INTERNAL_DEFN_##value_params\ - private:\ - GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\ - };\ - template \ - inline GMOCK_ACTION_CLASS_(name, value_params)<\ - GMOCK_INTERNAL_LIST_##template_params\ - GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\ - GMOCK_INTERNAL_DECL_##value_params) {\ - return GMOCK_ACTION_CLASS_(name, value_params)<\ - GMOCK_INTERNAL_LIST_##template_params\ - GMOCK_INTERNAL_LIST_TYPE_##value_params>(\ - GMOCK_INTERNAL_LIST_##value_params);\ - }\ - template \ - template \ - template \ - typename ::testing::internal::Function::Result\ - GMOCK_ACTION_CLASS_(name, value_params)<\ - GMOCK_INTERNAL_LIST_##template_params\ - GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl::\ - gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const - -$for i - -[[ -$var template = [[$if i==0 [[]] $else [[ -$range j 0..i-1 - - template <$for j, [[typename p$j##_type]]>\ -]]]] -$var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]] - $else [[P$i]]]]]] -$range j 0..i-1 -$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] -$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]] -$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]] -$var param_field_decls = [[$for j -[[ - - p$j##_type p$j;\ -]]]] -$var param_field_decls2 = [[$for j -[[ - - p$j##_type p$j;\ -]]]] -$var params = [[$for j, [[p$j]]]] -$var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]] -$var typename_arg_types = [[$for k, [[typename arg$k[[]]_type]]]] -$var arg_types_and_names = [[$for k, [[arg$k[[]]_type arg$k]]]] -$var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]] - $else [[ACTION_P$i]]]] - -#define $macro_name(name$for j [[, p$j]])\$template - class $class_name {\ - public:\ - $class_name($ctor_param_list)$inits {}\ - template \ - class gmock_Impl : public ::testing::ActionInterface {\ - public:\ - typedef F function_type;\ - typedef typename ::testing::internal::Function::Result return_type;\ - typedef typename ::testing::internal::Function::ArgumentTuple\ - args_type;\ - [[$if i==1 [[explicit ]]]]gmock_Impl($ctor_param_list)$inits {}\ - virtual return_type Perform(const args_type& args) {\ - return ::testing::internal::ActionHelper::\ - Perform(this, args);\ - }\ - template <$typename_arg_types>\ - return_type gmock_PerformImpl(const args_type& args, [[]] -$arg_types_and_names) const;\$param_field_decls - private:\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template operator ::testing::Action() const {\ - return ::testing::Action(new gmock_Impl($params));\ - }\$param_field_decls2 - private:\ - GTEST_DISALLOW_ASSIGN_($class_name);\ - };\$template - inline $class_name$param_types name($param_types_and_names) {\ - return $class_name$param_types($params);\ - }\$template - template \ - template <$typename_arg_types>\ - typename ::testing::internal::Function::Result\ - $class_name$param_types::gmock_Impl::gmock_PerformImpl(\ - GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const -]] -$$ } // This meta comment fixes auto-indentation in Emacs. It won't -$$ // show up in the generated code. - - -// TODO(wan@google.com): move the following to a different .h file -// such that we don't have to run 'pump' every time the code is -// updated. -namespace testing { - -// The ACTION*() macros trigger warning C4100 (unreferenced formal -// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in -// the macro definition, as the warnings are generated when the macro -// is expanded and macro expansion cannot contain #pragma. Therefore -// we suppress them here. -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4100) -#endif - -// Various overloads for InvokeArgument(). -// -// The InvokeArgument(a1, a2, ..., a_k) action invokes the N-th -// (0-based) argument, which must be a k-ary callable, of the mock -// function, with arguments a1, a2, ..., a_k. -// -// Notes: -// -// 1. The arguments are passed by value by default. If you need to -// pass an argument by reference, wrap it inside ByRef(). For -// example, -// -// InvokeArgument<1>(5, string("Hello"), ByRef(foo)) -// -// passes 5 and string("Hello") by value, and passes foo by -// reference. -// -// 2. If the callable takes an argument by reference but ByRef() is -// not used, it will receive the reference to a copy of the value, -// instead of the original value. For example, when the 0-th -// argument of the mock function takes a const string&, the action -// -// InvokeArgument<0>(string("Hello")) -// -// makes a copy of the temporary string("Hello") object and passes a -// reference of the copy, instead of the original temporary object, -// to the callable. This makes it easy for a user to define an -// InvokeArgument action from temporary values and have it performed -// later. - -$range i 0..n -$for i [[ -$range j 0..i-1 - -ACTION_TEMPLATE(InvokeArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])) { - return internal::CallableHelper::Call( - ::std::tr1::get(args)$for j [[, p$j]]); -} - -]] - -// Various overloads for ReturnNew(). -// -// The ReturnNew(a1, a2, ..., a_k) action returns a pointer to a new -// instance of type T, constructed on the heap with constructor arguments -// a1, a2, ..., and a_k. The caller assumes ownership of the returned value. -$range i 0..n -$for i [[ -$range j 0..i-1 -$var ps = [[$for j, [[p$j]]]] - -ACTION_TEMPLATE(ReturnNew, - HAS_1_TEMPLATE_PARAMS(typename, T), - AND_$i[[]]_VALUE_PARAMS($ps)) { - return new T($ps); -} - -]] - -#ifdef _MSC_VER -# pragma warning(pop) -#endif - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_ diff --git a/lib/gmock/include/gmock/gmock-generated-function-mockers.h b/lib/gmock/include/gmock/gmock-generated-function-mockers.h deleted file mode 100644 index 509d46cb..00000000 --- a/lib/gmock/include/gmock/gmock-generated-function-mockers.h +++ /dev/null @@ -1,929 +0,0 @@ -// This file was GENERATED by command: -// pump.py gmock-generated-function-mockers.h.pump -// DO NOT EDIT BY HAND!!! - -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements function mockers of various arities. - -#ifndef 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/internal/gmock-internal-utils.h" - -namespace testing { -namespace internal { - -template -class FunctionMockerBase; - -// Note: class FunctionMocker really belongs to the ::testing -// namespace. However if we define it in ::testing, MSVC will -// complain when classes in ::testing::internal declare it as a -// friend class template. To workaround this compiler bug, we define -// FunctionMocker in ::testing::internal and import it into ::testing. -template -class FunctionMocker; - -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F(); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With() { - return this->current_spec(); - } - - R Invoke() { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple()); - } -}; - -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F(A1); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With(const Matcher& m1) { - this->current_spec().SetMatchers(::std::tr1::make_tuple(m1)); - return this->current_spec(); - } - - R Invoke(A1 a1) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1)); - } -}; - -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F(A1, A2); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With(const Matcher& m1, const Matcher& m2) { - this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2)); - return this->current_spec(); - } - - R Invoke(A1 a1, A2 a2) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2)); - } -}; - -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F(A1, A2, A3); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With(const Matcher& m1, const Matcher& m2, - const Matcher& m3) { - this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3)); - return this->current_spec(); - } - - R Invoke(A1 a1, A2 a2, A3 a3) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3)); - } -}; - -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F(A1, A2, A3, A4); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With(const Matcher& m1, const Matcher& m2, - const Matcher& m3, const Matcher& m4) { - this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4)); - return this->current_spec(); - } - - R Invoke(A1 a1, A2 a2, A3 a3, A4 a4) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4)); - } -}; - -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F(A1, A2, A3, A4, A5); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With(const Matcher& m1, const Matcher& m2, - const Matcher& m3, const Matcher& m4, const Matcher& m5) { - this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, - m5)); - return this->current_spec(); - } - - R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5)); - } -}; - -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F(A1, A2, A3, A4, A5, A6); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With(const Matcher& m1, const Matcher& m2, - const Matcher& m3, const Matcher& m4, const Matcher& m5, - const Matcher& m6) { - this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, - m6)); - return this->current_spec(); - } - - R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6)); - } -}; - -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F(A1, A2, A3, A4, A5, A6, A7); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With(const Matcher& m1, const Matcher& m2, - const Matcher& m3, const Matcher& m4, const Matcher& m5, - const Matcher& m6, const Matcher& m7) { - this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, - m6, m7)); - return this->current_spec(); - } - - R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7)); - } -}; - -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F(A1, A2, A3, A4, A5, A6, A7, A8); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With(const Matcher& m1, const Matcher& m2, - const Matcher& m3, const Matcher& m4, const Matcher& m5, - const Matcher& m6, const Matcher& m7, const Matcher& m8) { - this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, - m6, m7, m8)); - return this->current_spec(); - } - - R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8)); - } -}; - -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With(const Matcher& m1, const Matcher& m2, - const Matcher& m3, const Matcher& m4, const Matcher& m5, - const Matcher& m6, const Matcher& m7, const Matcher& m8, - const Matcher& m9) { - this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, - m6, m7, m8, m9)); - return this->current_spec(); - } - - R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9)); - } -}; - -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With(const Matcher& m1, const Matcher& m2, - const Matcher& m3, const Matcher& m4, const Matcher& m5, - const Matcher& m6, const Matcher& m7, const Matcher& m8, - const Matcher& m9, const Matcher& m10) { - this->current_spec().SetMatchers(::std::tr1::make_tuple(m1, m2, m3, m4, m5, - m6, m7, m8, m9, m10)); - return this->current_spec(); - } - - R Invoke(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, - A10 a10) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple(a1, a2, a3, a4, a5, a6, a7, a8, a9, - a10)); - } -}; - -} // namespace internal - -// The style guide prohibits "using" statements in a namespace scope -// inside a header file. However, the FunctionMocker class template -// is meant to be defined in the ::testing namespace. The following -// line is just a trick for working around a bug in MSVC 8.0, which -// cannot handle it if we define FunctionMocker in ::testing. -using internal::FunctionMocker; - -// The result type of function type F. -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_RESULT_(tn, F) tn ::testing::internal::Function::Result - -// The type of argument N of function type F. -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_ARG_(tn, F, N) tn ::testing::internal::Function::Argument##N - -// The matcher type for argument N of function type F. -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_MATCHER_(tn, F, N) const ::testing::Matcher& - -// The variable for mocking the given method. -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_MOCKER_(arity, constness, Method) \ - GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) - -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD0_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method() constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == 0, \ - this_method_does_not_take_0_arguments); \ - GMOCK_MOCKER_(0, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(0, constness, Method).Invoke(); \ - } \ - ::testing::MockSpec& \ - gmock_##Method() constness { \ - GMOCK_MOCKER_(0, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(0, constness, Method).With(); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_(0, constness, Method) - -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD1_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1) constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == 1, \ - this_method_does_not_take_1_argument); \ - GMOCK_MOCKER_(1, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(1, constness, Method).Invoke(gmock_a1); \ - } \ - ::testing::MockSpec& \ - gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1) constness { \ - GMOCK_MOCKER_(1, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(1, constness, Method).With(gmock_a1); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_(1, constness, Method) - -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD2_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ - GMOCK_ARG_(tn, F, 2) gmock_a2) constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == 2, \ - this_method_does_not_take_2_arguments); \ - GMOCK_MOCKER_(2, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(2, constness, Method).Invoke(gmock_a1, gmock_a2); \ - } \ - ::testing::MockSpec& \ - gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ - GMOCK_MATCHER_(tn, F, 2) gmock_a2) constness { \ - GMOCK_MOCKER_(2, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(2, constness, Method).With(gmock_a1, gmock_a2); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_(2, constness, Method) - -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD3_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ - GMOCK_ARG_(tn, F, 2) gmock_a2, \ - GMOCK_ARG_(tn, F, 3) gmock_a3) constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == 3, \ - this_method_does_not_take_3_arguments); \ - GMOCK_MOCKER_(3, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(3, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3); \ - } \ - ::testing::MockSpec& \ - gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ - GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ - GMOCK_MATCHER_(tn, F, 3) gmock_a3) constness { \ - GMOCK_MOCKER_(3, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(3, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_(3, constness, Method) - -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD4_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ - GMOCK_ARG_(tn, F, 2) gmock_a2, \ - GMOCK_ARG_(tn, F, 3) gmock_a3, \ - GMOCK_ARG_(tn, F, 4) gmock_a4) constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == 4, \ - this_method_does_not_take_4_arguments); \ - GMOCK_MOCKER_(4, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(4, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4); \ - } \ - ::testing::MockSpec& \ - gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ - GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ - GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ - GMOCK_MATCHER_(tn, F, 4) gmock_a4) constness { \ - GMOCK_MOCKER_(4, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(4, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_(4, constness, Method) - -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD5_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ - GMOCK_ARG_(tn, F, 2) gmock_a2, \ - GMOCK_ARG_(tn, F, 3) gmock_a3, \ - GMOCK_ARG_(tn, F, 4) gmock_a4, \ - GMOCK_ARG_(tn, F, 5) gmock_a5) constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == 5, \ - this_method_does_not_take_5_arguments); \ - GMOCK_MOCKER_(5, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(5, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5); \ - } \ - ::testing::MockSpec& \ - gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ - GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ - GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ - GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ - GMOCK_MATCHER_(tn, F, 5) gmock_a5) constness { \ - GMOCK_MOCKER_(5, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(5, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_(5, constness, Method) - -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD6_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ - GMOCK_ARG_(tn, F, 2) gmock_a2, \ - GMOCK_ARG_(tn, F, 3) gmock_a3, \ - GMOCK_ARG_(tn, F, 4) gmock_a4, \ - GMOCK_ARG_(tn, F, 5) gmock_a5, \ - GMOCK_ARG_(tn, F, 6) gmock_a6) constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == 6, \ - this_method_does_not_take_6_arguments); \ - GMOCK_MOCKER_(6, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(6, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ - } \ - ::testing::MockSpec& \ - gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ - GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ - GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ - GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ - GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ - GMOCK_MATCHER_(tn, F, 6) gmock_a6) constness { \ - GMOCK_MOCKER_(6, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(6, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_(6, constness, Method) - -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD7_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ - GMOCK_ARG_(tn, F, 2) gmock_a2, \ - GMOCK_ARG_(tn, F, 3) gmock_a3, \ - GMOCK_ARG_(tn, F, 4) gmock_a4, \ - GMOCK_ARG_(tn, F, 5) gmock_a5, \ - GMOCK_ARG_(tn, F, 6) gmock_a6, \ - GMOCK_ARG_(tn, F, 7) gmock_a7) constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == 7, \ - this_method_does_not_take_7_arguments); \ - GMOCK_MOCKER_(7, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(7, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ - } \ - ::testing::MockSpec& \ - gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ - GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ - GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ - GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ - GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ - GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ - GMOCK_MATCHER_(tn, F, 7) gmock_a7) constness { \ - GMOCK_MOCKER_(7, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(7, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_(7, constness, Method) - -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD8_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ - GMOCK_ARG_(tn, F, 2) gmock_a2, \ - GMOCK_ARG_(tn, F, 3) gmock_a3, \ - GMOCK_ARG_(tn, F, 4) gmock_a4, \ - GMOCK_ARG_(tn, F, 5) gmock_a5, \ - GMOCK_ARG_(tn, F, 6) gmock_a6, \ - GMOCK_ARG_(tn, F, 7) gmock_a7, \ - GMOCK_ARG_(tn, F, 8) gmock_a8) constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == 8, \ - this_method_does_not_take_8_arguments); \ - GMOCK_MOCKER_(8, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(8, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ - } \ - ::testing::MockSpec& \ - gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ - GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ - GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ - GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ - GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ - GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ - GMOCK_MATCHER_(tn, F, 7) gmock_a7, \ - GMOCK_MATCHER_(tn, F, 8) gmock_a8) constness { \ - GMOCK_MOCKER_(8, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(8, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_(8, constness, Method) - -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD9_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ - GMOCK_ARG_(tn, F, 2) gmock_a2, \ - GMOCK_ARG_(tn, F, 3) gmock_a3, \ - GMOCK_ARG_(tn, F, 4) gmock_a4, \ - GMOCK_ARG_(tn, F, 5) gmock_a5, \ - GMOCK_ARG_(tn, F, 6) gmock_a6, \ - GMOCK_ARG_(tn, F, 7) gmock_a7, \ - GMOCK_ARG_(tn, F, 8) gmock_a8, \ - GMOCK_ARG_(tn, F, 9) gmock_a9) constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == 9, \ - this_method_does_not_take_9_arguments); \ - GMOCK_MOCKER_(9, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(9, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ - gmock_a9); \ - } \ - ::testing::MockSpec& \ - gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ - GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ - GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ - GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ - GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ - GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ - GMOCK_MATCHER_(tn, F, 7) gmock_a7, \ - GMOCK_MATCHER_(tn, F, 8) gmock_a8, \ - GMOCK_MATCHER_(tn, F, 9) gmock_a9) constness { \ - GMOCK_MOCKER_(9, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(9, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, \ - gmock_a9); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_(9, constness, Method) - -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD10_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method(GMOCK_ARG_(tn, F, 1) gmock_a1, \ - GMOCK_ARG_(tn, F, 2) gmock_a2, \ - GMOCK_ARG_(tn, F, 3) gmock_a3, \ - GMOCK_ARG_(tn, F, 4) gmock_a4, \ - GMOCK_ARG_(tn, F, 5) gmock_a5, \ - GMOCK_ARG_(tn, F, 6) gmock_a6, \ - GMOCK_ARG_(tn, F, 7) gmock_a7, \ - GMOCK_ARG_(tn, F, 8) gmock_a8, \ - GMOCK_ARG_(tn, F, 9) gmock_a9, \ - GMOCK_ARG_(tn, F, 10) gmock_a10) constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == 10, \ - this_method_does_not_take_10_arguments); \ - GMOCK_MOCKER_(10, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_(10, constness, Method).Invoke(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ - gmock_a10); \ - } \ - ::testing::MockSpec& \ - gmock_##Method(GMOCK_MATCHER_(tn, F, 1) gmock_a1, \ - GMOCK_MATCHER_(tn, F, 2) gmock_a2, \ - GMOCK_MATCHER_(tn, F, 3) gmock_a3, \ - GMOCK_MATCHER_(tn, F, 4) gmock_a4, \ - GMOCK_MATCHER_(tn, F, 5) gmock_a5, \ - GMOCK_MATCHER_(tn, F, 6) gmock_a6, \ - GMOCK_MATCHER_(tn, F, 7) gmock_a7, \ - GMOCK_MATCHER_(tn, F, 8) gmock_a8, \ - GMOCK_MATCHER_(tn, F, 9) gmock_a9, \ - GMOCK_MATCHER_(tn, F, 10) gmock_a10) constness { \ - GMOCK_MOCKER_(10, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_(10, constness, Method).With(gmock_a1, gmock_a2, \ - gmock_a3, gmock_a4, gmock_a5, gmock_a6, gmock_a7, gmock_a8, gmock_a9, \ - gmock_a10); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_(10, constness, Method) - -#define MOCK_METHOD0(m, F) GMOCK_METHOD0_(, , , m, F) -#define MOCK_METHOD1(m, F) GMOCK_METHOD1_(, , , m, F) -#define MOCK_METHOD2(m, F) GMOCK_METHOD2_(, , , m, F) -#define MOCK_METHOD3(m, F) GMOCK_METHOD3_(, , , m, F) -#define MOCK_METHOD4(m, F) GMOCK_METHOD4_(, , , m, F) -#define MOCK_METHOD5(m, F) GMOCK_METHOD5_(, , , m, F) -#define MOCK_METHOD6(m, F) GMOCK_METHOD6_(, , , m, F) -#define MOCK_METHOD7(m, F) GMOCK_METHOD7_(, , , m, F) -#define MOCK_METHOD8(m, F) GMOCK_METHOD8_(, , , m, F) -#define MOCK_METHOD9(m, F) GMOCK_METHOD9_(, , , m, F) -#define MOCK_METHOD10(m, F) GMOCK_METHOD10_(, , , m, F) - -#define MOCK_CONST_METHOD0(m, F) GMOCK_METHOD0_(, const, , m, F) -#define MOCK_CONST_METHOD1(m, F) GMOCK_METHOD1_(, const, , m, F) -#define MOCK_CONST_METHOD2(m, F) GMOCK_METHOD2_(, const, , m, F) -#define MOCK_CONST_METHOD3(m, F) GMOCK_METHOD3_(, const, , m, F) -#define MOCK_CONST_METHOD4(m, F) GMOCK_METHOD4_(, const, , m, F) -#define MOCK_CONST_METHOD5(m, F) GMOCK_METHOD5_(, const, , m, F) -#define MOCK_CONST_METHOD6(m, F) GMOCK_METHOD6_(, const, , m, F) -#define MOCK_CONST_METHOD7(m, F) GMOCK_METHOD7_(, const, , m, F) -#define MOCK_CONST_METHOD8(m, F) GMOCK_METHOD8_(, const, , m, F) -#define MOCK_CONST_METHOD9(m, F) GMOCK_METHOD9_(, const, , m, F) -#define MOCK_CONST_METHOD10(m, F) GMOCK_METHOD10_(, const, , m, F) - -#define MOCK_METHOD0_T(m, F) GMOCK_METHOD0_(typename, , , m, F) -#define MOCK_METHOD1_T(m, F) GMOCK_METHOD1_(typename, , , m, F) -#define MOCK_METHOD2_T(m, F) GMOCK_METHOD2_(typename, , , m, F) -#define MOCK_METHOD3_T(m, F) GMOCK_METHOD3_(typename, , , m, F) -#define MOCK_METHOD4_T(m, F) GMOCK_METHOD4_(typename, , , m, F) -#define MOCK_METHOD5_T(m, F) GMOCK_METHOD5_(typename, , , m, F) -#define MOCK_METHOD6_T(m, F) GMOCK_METHOD6_(typename, , , m, F) -#define MOCK_METHOD7_T(m, F) GMOCK_METHOD7_(typename, , , m, F) -#define MOCK_METHOD8_T(m, F) GMOCK_METHOD8_(typename, , , m, F) -#define MOCK_METHOD9_T(m, F) GMOCK_METHOD9_(typename, , , m, F) -#define MOCK_METHOD10_T(m, F) GMOCK_METHOD10_(typename, , , m, F) - -#define MOCK_CONST_METHOD0_T(m, F) GMOCK_METHOD0_(typename, const, , m, F) -#define MOCK_CONST_METHOD1_T(m, F) GMOCK_METHOD1_(typename, const, , m, F) -#define MOCK_CONST_METHOD2_T(m, F) GMOCK_METHOD2_(typename, const, , m, F) -#define MOCK_CONST_METHOD3_T(m, F) GMOCK_METHOD3_(typename, const, , m, F) -#define MOCK_CONST_METHOD4_T(m, F) GMOCK_METHOD4_(typename, const, , m, F) -#define MOCK_CONST_METHOD5_T(m, F) GMOCK_METHOD5_(typename, const, , m, F) -#define MOCK_CONST_METHOD6_T(m, F) GMOCK_METHOD6_(typename, const, , m, F) -#define MOCK_CONST_METHOD7_T(m, F) GMOCK_METHOD7_(typename, const, , m, F) -#define MOCK_CONST_METHOD8_T(m, F) GMOCK_METHOD8_(typename, const, , m, F) -#define MOCK_CONST_METHOD9_T(m, F) GMOCK_METHOD9_(typename, const, , m, F) -#define MOCK_CONST_METHOD10_T(m, F) GMOCK_METHOD10_(typename, const, , m, F) - -#define MOCK_METHOD0_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD0_(, , ct, m, F) -#define MOCK_METHOD1_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD1_(, , ct, m, F) -#define MOCK_METHOD2_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD2_(, , ct, m, F) -#define MOCK_METHOD3_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD3_(, , ct, m, F) -#define MOCK_METHOD4_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD4_(, , ct, m, F) -#define MOCK_METHOD5_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD5_(, , ct, m, F) -#define MOCK_METHOD6_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD6_(, , ct, m, F) -#define MOCK_METHOD7_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD7_(, , ct, m, F) -#define MOCK_METHOD8_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD8_(, , ct, m, F) -#define MOCK_METHOD9_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD9_(, , ct, m, F) -#define MOCK_METHOD10_WITH_CALLTYPE(ct, m, F) GMOCK_METHOD10_(, , ct, m, F) - -#define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD0_(, const, ct, m, F) -#define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD1_(, const, ct, m, F) -#define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD2_(, const, ct, m, F) -#define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD3_(, const, ct, m, F) -#define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD4_(, const, ct, m, F) -#define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD5_(, const, ct, m, F) -#define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD6_(, const, ct, m, F) -#define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD7_(, const, ct, m, F) -#define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD8_(, const, ct, m, F) -#define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD9_(, const, ct, m, F) -#define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD10_(, const, ct, m, F) - -#define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD0_(typename, , ct, m, F) -#define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD1_(typename, , ct, m, F) -#define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD2_(typename, , ct, m, F) -#define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD3_(typename, , ct, m, F) -#define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD4_(typename, , ct, m, F) -#define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD5_(typename, , ct, m, F) -#define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD6_(typename, , ct, m, F) -#define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD7_(typename, , ct, m, F) -#define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD8_(typename, , ct, m, F) -#define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD9_(typename, , ct, m, F) -#define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD10_(typename, , ct, m, F) - -#define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD0_(typename, const, ct, m, F) -#define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD1_(typename, const, ct, m, F) -#define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD2_(typename, const, ct, m, F) -#define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD3_(typename, const, ct, m, F) -#define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD4_(typename, const, ct, m, F) -#define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD5_(typename, const, ct, m, F) -#define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD6_(typename, const, ct, m, F) -#define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD7_(typename, const, ct, m, F) -#define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD8_(typename, const, ct, m, F) -#define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD9_(typename, const, ct, m, F) -#define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD10_(typename, const, ct, m, F) - -// A MockFunction class has one mock method whose type is F. It is -// useful when you just want your test code to emit some messages and -// have Google Mock verify the right messages are sent (and perhaps at -// the right times). For example, if you are exercising code: -// -// Foo(1); -// Foo(2); -// Foo(3); -// -// and want to verify that Foo(1) and Foo(3) both invoke -// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: -// -// TEST(FooTest, InvokesBarCorrectly) { -// MyMock mock; -// MockFunction check; -// { -// InSequence s; -// -// EXPECT_CALL(mock, Bar("a")); -// EXPECT_CALL(check, Call("1")); -// EXPECT_CALL(check, Call("2")); -// EXPECT_CALL(mock, Bar("a")); -// } -// Foo(1); -// check.Call("1"); -// Foo(2); -// check.Call("2"); -// Foo(3); -// } -// -// The expectation spec says that the first Bar("a") must happen -// before check point "1", the second Bar("a") must happen after check -// point "2", and nothing should happen between the two check -// points. The explicit check points make it easy to tell which -// Bar("a") is called by which call to Foo(). -template -class MockFunction; - -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD0_T(Call, R()); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD1_T(Call, R(A0)); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD2_T(Call, R(A0, A1)); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD3_T(Call, R(A0, A1, A2)); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD4_T(Call, R(A0, A1, A2, A3)); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD5_T(Call, R(A0, A1, A2, A3, A4)); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD6_T(Call, R(A0, A1, A2, A3, A4, A5)); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD7_T(Call, R(A0, A1, A2, A3, A4, A5, A6)); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD8_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7)); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD9_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8)); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD10_T(Call, R(A0, A1, A2, A3, A4, A5, A6, A7, A8, A9)); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ diff --git a/lib/gmock/include/gmock/gmock-generated-function-mockers.h.pump b/lib/gmock/include/gmock/gmock-generated-function-mockers.h.pump deleted file mode 100644 index 4f82d622..00000000 --- a/lib/gmock/include/gmock/gmock-generated-function-mockers.h.pump +++ /dev/null @@ -1,258 +0,0 @@ -$$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-function-mockers.h. -$$ -$var n = 10 $$ The maximum arity we support. -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements function mockers of various arities. - -#ifndef 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/internal/gmock-internal-utils.h" - -namespace testing { -namespace internal { - -template -class FunctionMockerBase; - -// Note: class FunctionMocker really belongs to the ::testing -// namespace. However if we define it in ::testing, MSVC will -// complain when classes in ::testing::internal declare it as a -// friend class template. To workaround this compiler bug, we define -// FunctionMocker in ::testing::internal and import it into ::testing. -template -class FunctionMocker; - - -$range i 0..n -$for i [[ -$range j 1..i -$var typename_As = [[$for j [[, typename A$j]]]] -$var As = [[$for j, [[A$j]]]] -$var as = [[$for j, [[a$j]]]] -$var Aas = [[$for j, [[A$j a$j]]]] -$var ms = [[$for j, [[m$j]]]] -$var matchers = [[$for j, [[const Matcher& m$j]]]] -template -class FunctionMocker : public - internal::FunctionMockerBase { - public: - typedef R F($As); - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - - MockSpec& With($matchers) { - -$if i >= 1 [[ - this->current_spec().SetMatchers(::std::tr1::make_tuple($ms)); - -]] - return this->current_spec(); - } - - R Invoke($Aas) { - // Even though gcc and MSVC don't enforce it, 'this->' is required - // by the C++ standard [14.6.4] here, as the base class type is - // dependent on the template argument (and thus shouldn't be - // looked into when resolving InvokeWith). - return this->InvokeWith(ArgumentTuple($as)); - } -}; - - -]] -} // namespace internal - -// The style guide prohibits "using" statements in a namespace scope -// inside a header file. However, the FunctionMocker class template -// is meant to be defined in the ::testing namespace. The following -// line is just a trick for working around a bug in MSVC 8.0, which -// cannot handle it if we define FunctionMocker in ::testing. -using internal::FunctionMocker; - -// The result type of function type F. -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_RESULT_(tn, F) tn ::testing::internal::Function::Result - -// The type of argument N of function type F. -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_ARG_(tn, F, N) tn ::testing::internal::Function::Argument##N - -// The matcher type for argument N of function type F. -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_MATCHER_(tn, F, N) const ::testing::Matcher& - -// The variable for mocking the given method. -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_MOCKER_(arity, constness, Method) \ - GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__) - - -$for i [[ -$range j 1..i -$var arg_as = [[$for j, \ - [[GMOCK_ARG_(tn, F, $j) gmock_a$j]]]] -$var as = [[$for j, [[gmock_a$j]]]] -$var matcher_as = [[$for j, \ - [[GMOCK_MATCHER_(tn, F, $j) gmock_a$j]]]] -// INTERNAL IMPLEMENTATION - DON'T USE IN USER CODE!!! -#define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, F) \ - GMOCK_RESULT_(tn, F) ct Method($arg_as) constness { \ - GTEST_COMPILE_ASSERT_(::std::tr1::tuple_size< \ - tn ::testing::internal::Function::ArgumentTuple>::value == $i, \ - this_method_does_not_take_$i[[]]_argument[[$if i != 1 [[s]]]]); \ - GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \ - return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \ - } \ - ::testing::MockSpec& \ - gmock_##Method($matcher_as) constness { \ - GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \ - return GMOCK_MOCKER_($i, constness, Method).With($as); \ - } \ - mutable ::testing::FunctionMocker GMOCK_MOCKER_($i, constness, Method) - - -]] -$for i [[ -#define MOCK_METHOD$i(m, F) GMOCK_METHOD$i[[]]_(, , , m, F) - -]] - - -$for i [[ -#define MOCK_CONST_METHOD$i(m, F) GMOCK_METHOD$i[[]]_(, const, , m, F) - -]] - - -$for i [[ -#define MOCK_METHOD$i[[]]_T(m, F) GMOCK_METHOD$i[[]]_(typename, , , m, F) - -]] - - -$for i [[ -#define MOCK_CONST_METHOD$i[[]]_T(m, F) [[]] -GMOCK_METHOD$i[[]]_(typename, const, , m, F) - -]] - - -$for i [[ -#define MOCK_METHOD$i[[]]_WITH_CALLTYPE(ct, m, F) [[]] -GMOCK_METHOD$i[[]]_(, , ct, m, F) - -]] - - -$for i [[ -#define MOCK_CONST_METHOD$i[[]]_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD$i[[]]_(, const, ct, m, F) - -]] - - -$for i [[ -#define MOCK_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD$i[[]]_(typename, , ct, m, F) - -]] - - -$for i [[ -#define MOCK_CONST_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, F) \ - GMOCK_METHOD$i[[]]_(typename, const, ct, m, F) - -]] - -// A MockFunction class has one mock method whose type is F. It is -// useful when you just want your test code to emit some messages and -// have Google Mock verify the right messages are sent (and perhaps at -// the right times). For example, if you are exercising code: -// -// Foo(1); -// Foo(2); -// Foo(3); -// -// and want to verify that Foo(1) and Foo(3) both invoke -// mock.Bar("a"), but Foo(2) doesn't invoke anything, you can write: -// -// TEST(FooTest, InvokesBarCorrectly) { -// MyMock mock; -// MockFunction check; -// { -// InSequence s; -// -// EXPECT_CALL(mock, Bar("a")); -// EXPECT_CALL(check, Call("1")); -// EXPECT_CALL(check, Call("2")); -// EXPECT_CALL(mock, Bar("a")); -// } -// Foo(1); -// check.Call("1"); -// Foo(2); -// check.Call("2"); -// Foo(3); -// } -// -// The expectation spec says that the first Bar("a") must happen -// before check point "1", the second Bar("a") must happen after check -// point "2", and nothing should happen between the two check -// points. The explicit check points make it easy to tell which -// Bar("a") is called by which call to Foo(). -template -class MockFunction; - - -$for i [[ -$range j 0..i-1 -template -class MockFunction { - public: - MockFunction() {} - - MOCK_METHOD$i[[]]_T(Call, R($for j, [[A$j]])); - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction); -}; - - -]] -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_ diff --git a/lib/gmock/include/gmock/gmock-generated-matchers.h b/lib/gmock/include/gmock/gmock-generated-matchers.h deleted file mode 100644 index 6feaf1a2..00000000 --- a/lib/gmock/include/gmock/gmock-generated-matchers.h +++ /dev/null @@ -1,2054 +0,0 @@ -// This file was GENERATED by command: -// pump.py gmock-generated-matchers.h.pump -// DO NOT EDIT BY HAND!!! - -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements some commonly used variadic matchers. - -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ - -#include -#include -#include -#include "gmock/gmock-matchers.h" - -namespace testing { -namespace internal { - -// The type of the i-th (0-based) field of Tuple. -#define GMOCK_FIELD_TYPE_(Tuple, i) \ - typename ::std::tr1::tuple_element::type - -// TupleFields is for selecting fields from a -// tuple of type Tuple. It has two members: -// -// type: a tuple type whose i-th field is the ki-th field of Tuple. -// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple. -// -// For example, in class TupleFields, 2, 0>, we have: -// -// type is tuple, and -// GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true). - -template -class TupleFields; - -// This generic version is used when there are 10 selectors. -template -class TupleFields { - public: - typedef ::std::tr1::tuple type; - static type GetSelectedFields(const Tuple& t) { - using ::std::tr1::get; - return type(get(t), get(t), get(t), get(t), get(t), - get(t), get(t), get(t), get(t), get(t)); - } -}; - -// The following specialization is used for 0 ~ 9 selectors. - -template -class TupleFields { - public: - typedef ::std::tr1::tuple<> type; - static type GetSelectedFields(const Tuple& /* t */) { - using ::std::tr1::get; - return type(); - } -}; - -template -class TupleFields { - public: - typedef ::std::tr1::tuple type; - static type GetSelectedFields(const Tuple& t) { - using ::std::tr1::get; - return type(get(t)); - } -}; - -template -class TupleFields { - public: - typedef ::std::tr1::tuple type; - static type GetSelectedFields(const Tuple& t) { - using ::std::tr1::get; - return type(get(t), get(t)); - } -}; - -template -class TupleFields { - public: - typedef ::std::tr1::tuple type; - static type GetSelectedFields(const Tuple& t) { - using ::std::tr1::get; - return type(get(t), get(t), get(t)); - } -}; - -template -class TupleFields { - public: - typedef ::std::tr1::tuple type; - static type GetSelectedFields(const Tuple& t) { - using ::std::tr1::get; - return type(get(t), get(t), get(t), get(t)); - } -}; - -template -class TupleFields { - public: - typedef ::std::tr1::tuple type; - static type GetSelectedFields(const Tuple& t) { - using ::std::tr1::get; - return type(get(t), get(t), get(t), get(t), get(t)); - } -}; - -template -class TupleFields { - public: - typedef ::std::tr1::tuple type; - static type GetSelectedFields(const Tuple& t) { - using ::std::tr1::get; - return type(get(t), get(t), get(t), get(t), get(t), - get(t)); - } -}; - -template -class TupleFields { - public: - typedef ::std::tr1::tuple type; - static type GetSelectedFields(const Tuple& t) { - using ::std::tr1::get; - return type(get(t), get(t), get(t), get(t), get(t), - get(t), get(t)); - } -}; - -template -class TupleFields { - public: - typedef ::std::tr1::tuple type; - static type GetSelectedFields(const Tuple& t) { - using ::std::tr1::get; - return type(get(t), get(t), get(t), get(t), get(t), - get(t), get(t), get(t)); - } -}; - -template -class TupleFields { - public: - typedef ::std::tr1::tuple type; - static type GetSelectedFields(const Tuple& t) { - using ::std::tr1::get; - return type(get(t), get(t), get(t), get(t), get(t), - get(t), get(t), get(t), get(t)); - } -}; - -#undef GMOCK_FIELD_TYPE_ - -// Implements the Args() matcher. -template -class ArgsMatcherImpl : public MatcherInterface { - public: - // ArgsTuple may have top-level const or reference modifiers. - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple; - typedef typename internal::TupleFields::type SelectedArgs; - typedef Matcher MonomorphicInnerMatcher; - - template - explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) - : inner_matcher_(SafeMatcherCast(inner_matcher)) {} - - virtual bool MatchAndExplain(ArgsTuple args, - MatchResultListener* listener) const { - const SelectedArgs& selected_args = GetSelectedArgs(args); - if (!listener->IsInterested()) - return inner_matcher_.Matches(selected_args); - - PrintIndices(listener->stream()); - *listener << "are " << PrintToString(selected_args); - - StringMatchResultListener inner_listener; - const bool match = inner_matcher_.MatchAndExplain(selected_args, - &inner_listener); - PrintIfNotEmpty(inner_listener.str(), listener->stream()); - return match; - } - - virtual void DescribeTo(::std::ostream* os) const { - *os << "are a tuple "; - PrintIndices(os); - inner_matcher_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "are a tuple "; - PrintIndices(os); - inner_matcher_.DescribeNegationTo(os); - } - - private: - static SelectedArgs GetSelectedArgs(ArgsTuple args) { - return TupleFields::GetSelectedFields(args); - } - - // Prints the indices of the selected fields. - static void PrintIndices(::std::ostream* os) { - *os << "whose fields ("; - const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 }; - for (int i = 0; i < 10; i++) { - if (indices[i] < 0) - break; - - if (i >= 1) - *os << ", "; - - *os << "#" << indices[i]; - } - *os << ") "; - } - - const MonomorphicInnerMatcher inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl); -}; - -template -class ArgsMatcher { - public: - explicit ArgsMatcher(const InnerMatcher& inner_matcher) - : inner_matcher_(inner_matcher) {} - - template - operator Matcher() const { - return MakeMatcher(new ArgsMatcherImpl(inner_matcher_)); - } - - private: - const InnerMatcher inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(ArgsMatcher); -}; - -// Implements ElementsAre() of 1-10 arguments. - -template -class ElementsAreMatcher1 { - public: - explicit ElementsAreMatcher1(const T1& e1) : e1_(e1) {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - // Nokia's Symbian Compiler has a nasty bug where the object put - // in a one-element local array is not destructed when the array - // goes out of scope. This leads to obvious badness as we've - // added the linked_ptr in it to our other linked_ptrs list. - // Hence we implement ElementsAreMatcher1 specially to avoid using - // a local array. - const Matcher matcher = - MatcherCast(e1_); - return MakeMatcher(new ElementsAreMatcherImpl(&matcher, 1)); - } - - private: - const T1& e1_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher1); -}; - -template -class ElementsAreMatcher2 { - public: - ElementsAreMatcher2(const T1& e1, const T2& e2) : e1_(e1), e2_(e2) {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - const Matcher matchers[] = { - MatcherCast(e1_), - MatcherCast(e2_), - }; - - return MakeMatcher(new ElementsAreMatcherImpl(matchers, 2)); - } - - private: - const T1& e1_; - const T2& e2_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher2); -}; - -template -class ElementsAreMatcher3 { - public: - ElementsAreMatcher3(const T1& e1, const T2& e2, const T3& e3) : e1_(e1), - e2_(e2), e3_(e3) {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - const Matcher matchers[] = { - MatcherCast(e1_), - MatcherCast(e2_), - MatcherCast(e3_), - }; - - return MakeMatcher(new ElementsAreMatcherImpl(matchers, 3)); - } - - private: - const T1& e1_; - const T2& e2_; - const T3& e3_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher3); -}; - -template -class ElementsAreMatcher4 { - public: - ElementsAreMatcher4(const T1& e1, const T2& e2, const T3& e3, - const T4& e4) : e1_(e1), e2_(e2), e3_(e3), e4_(e4) {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - const Matcher matchers[] = { - MatcherCast(e1_), - MatcherCast(e2_), - MatcherCast(e3_), - MatcherCast(e4_), - }; - - return MakeMatcher(new ElementsAreMatcherImpl(matchers, 4)); - } - - private: - const T1& e1_; - const T2& e2_; - const T3& e3_; - const T4& e4_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher4); -}; - -template -class ElementsAreMatcher5 { - public: - ElementsAreMatcher5(const T1& e1, const T2& e2, const T3& e3, const T4& e4, - const T5& e5) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5) {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - const Matcher matchers[] = { - MatcherCast(e1_), - MatcherCast(e2_), - MatcherCast(e3_), - MatcherCast(e4_), - MatcherCast(e5_), - }; - - return MakeMatcher(new ElementsAreMatcherImpl(matchers, 5)); - } - - private: - const T1& e1_; - const T2& e2_; - const T3& e3_; - const T4& e4_; - const T5& e5_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher5); -}; - -template -class ElementsAreMatcher6 { - public: - ElementsAreMatcher6(const T1& e1, const T2& e2, const T3& e3, const T4& e4, - const T5& e5, const T6& e6) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), - e5_(e5), e6_(e6) {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - const Matcher matchers[] = { - MatcherCast(e1_), - MatcherCast(e2_), - MatcherCast(e3_), - MatcherCast(e4_), - MatcherCast(e5_), - MatcherCast(e6_), - }; - - return MakeMatcher(new ElementsAreMatcherImpl(matchers, 6)); - } - - private: - const T1& e1_; - const T2& e2_; - const T3& e3_; - const T4& e4_; - const T5& e5_; - const T6& e6_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher6); -}; - -template -class ElementsAreMatcher7 { - public: - ElementsAreMatcher7(const T1& e1, const T2& e2, const T3& e3, const T4& e4, - const T5& e5, const T6& e6, const T7& e7) : e1_(e1), e2_(e2), e3_(e3), - e4_(e4), e5_(e5), e6_(e6), e7_(e7) {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - const Matcher matchers[] = { - MatcherCast(e1_), - MatcherCast(e2_), - MatcherCast(e3_), - MatcherCast(e4_), - MatcherCast(e5_), - MatcherCast(e6_), - MatcherCast(e7_), - }; - - return MakeMatcher(new ElementsAreMatcherImpl(matchers, 7)); - } - - private: - const T1& e1_; - const T2& e2_; - const T3& e3_; - const T4& e4_; - const T5& e5_; - const T6& e6_; - const T7& e7_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher7); -}; - -template -class ElementsAreMatcher8 { - public: - ElementsAreMatcher8(const T1& e1, const T2& e2, const T3& e3, const T4& e4, - 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) {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - const Matcher matchers[] = { - MatcherCast(e1_), - MatcherCast(e2_), - MatcherCast(e3_), - MatcherCast(e4_), - MatcherCast(e5_), - MatcherCast(e6_), - MatcherCast(e7_), - MatcherCast(e8_), - }; - - return MakeMatcher(new ElementsAreMatcherImpl(matchers, 8)); - } - - private: - const T1& e1_; - const T2& e2_; - const T3& e3_; - const T4& e4_; - const T5& e5_; - const T6& e6_; - const T7& e7_; - const T8& e8_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher8); -}; - -template -class ElementsAreMatcher9 { - public: - ElementsAreMatcher9(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) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6), - e7_(e7), e8_(e8), e9_(e9) {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - const Matcher matchers[] = { - MatcherCast(e1_), - MatcherCast(e2_), - MatcherCast(e3_), - MatcherCast(e4_), - MatcherCast(e5_), - MatcherCast(e6_), - MatcherCast(e7_), - MatcherCast(e8_), - MatcherCast(e9_), - }; - - return MakeMatcher(new ElementsAreMatcherImpl(matchers, 9)); - } - - private: - 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_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher9); -}; - -template -class ElementsAreMatcher10 { - public: - 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 T10& e10) : e1_(e1), e2_(e2), e3_(e3), e4_(e4), e5_(e5), e6_(e6), - e7_(e7), e8_(e8), e9_(e9), e10_(e10) {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - const Matcher matchers[] = { - MatcherCast(e1_), - MatcherCast(e2_), - MatcherCast(e3_), - MatcherCast(e4_), - MatcherCast(e5_), - MatcherCast(e6_), - MatcherCast(e7_), - MatcherCast(e8_), - MatcherCast(e9_), - MatcherCast(e10_), - }; - - return MakeMatcher(new ElementsAreMatcherImpl(matchers, 10)); - } - - private: - 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 T10& e10_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher10); -}; - -} // namespace internal - -// Args(a_matcher) matches a tuple if the selected -// fields of it matches a_matcher. C++ doesn't support default -// arguments for function templates, so we have to overload it. -template -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - -template -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - -template -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - -template -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - -template -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - -template -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - -template -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - -template -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - -template -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - -template -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - -template -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - -// ElementsAre(e0, e1, ..., e_n) matches an STL-style container with -// (n + 1) elements, where the i-th element in the container must -// match the i-th argument in the list. Each argument of -// ElementsAre() can be either a value or a matcher. We support up to -// 10 arguments. -// -// NOTE: Since ElementsAre() cares about the order of the elements, it -// must not be used with containers whose elements's order is -// undefined (e.g. hash_map). - -inline internal::ElementsAreMatcher0 ElementsAre() { - return internal::ElementsAreMatcher0(); -} - -template -inline internal::ElementsAreMatcher1 ElementsAre(const T1& e1) { - return internal::ElementsAreMatcher1(e1); -} - -template -inline internal::ElementsAreMatcher2 ElementsAre(const T1& e1, - const T2& e2) { - return internal::ElementsAreMatcher2(e1, e2); -} - -template -inline internal::ElementsAreMatcher3 ElementsAre(const T1& e1, - const T2& e2, const T3& e3) { - return internal::ElementsAreMatcher3(e1, e2, e3); -} - -template -inline internal::ElementsAreMatcher4 ElementsAre(const T1& e1, - const T2& e2, const T3& e3, const T4& e4) { - return internal::ElementsAreMatcher4(e1, e2, e3, e4); -} - -template -inline internal::ElementsAreMatcher5 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, - const T5& e5) { - return internal::ElementsAreMatcher5(e1, e2, e3, e4, e5); -} - -template -inline internal::ElementsAreMatcher6 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, - const T5& e5, const T6& e6) { - return internal::ElementsAreMatcher6(e1, e2, e3, e4, - e5, e6); -} - -template -inline internal::ElementsAreMatcher7 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, - const T5& e5, const T6& e6, const T7& e7) { - return internal::ElementsAreMatcher7(e1, e2, e3, - e4, e5, e6, e7); -} - -template -inline internal::ElementsAreMatcher8 ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4, - const T5& e5, const T6& e6, const T7& e7, const T8& e8) { - return internal::ElementsAreMatcher8(e1, e2, - e3, e4, e5, e6, e7, e8); -} - -template -inline internal::ElementsAreMatcher9 ElementsAre(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) { - return internal::ElementsAreMatcher9(e1, - e2, e3, e4, e5, e6, e7, e8, e9); -} - -template -inline internal::ElementsAreMatcher10 ElementsAre(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 T10& e10) { - return internal::ElementsAreMatcher10(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10); -} - -// ElementsAreArray(array) and ElementAreArray(array, count) are like -// ElementsAre(), except that they take an array of values or -// matchers. The former form infers the size of 'array', which must -// be a static C-style array. In the latter form, 'array' can either -// be a static array or a pointer to a dynamically created array. - -template -inline internal::ElementsAreArrayMatcher ElementsAreArray( - const T* first, size_t count) { - return internal::ElementsAreArrayMatcher(first, count); -} - -template -inline internal::ElementsAreArrayMatcher -ElementsAreArray(const T (&array)[N]) { - return internal::ElementsAreArrayMatcher(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 firing. - -template -inline internal::BothOfMatcher -AllOf(Matcher1 m1, Matcher2 m2) { - return internal::BothOfMatcher(m1, m2); -} - -template -inline internal::BothOfMatcher > -AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) { - return ::testing::AllOf(m1, ::testing::AllOf(m2, m3)); -} - -template -inline internal::BothOfMatcher > > -AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) { - return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4)); -} - -template -inline internal::BothOfMatcher > > > -AllOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) { - return ::testing::AllOf(m1, ::testing::AllOf(m2, m3, m4, m5)); -} - -template -inline internal::BothOfMatcher > > > > -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 -inline internal::BothOfMatcher > > > > > -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 -inline internal::BothOfMatcher > > > > > > -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 -inline internal::BothOfMatcher > > > > > > > -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 -inline internal::BothOfMatcher > > > > > > > > -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 firing. - -template -inline internal::EitherOfMatcher -AnyOf(Matcher1 m1, Matcher2 m2) { - return internal::EitherOfMatcher(m1, m2); -} - -template -inline internal::EitherOfMatcher > -AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3) { - return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3)); -} - -template -inline internal::EitherOfMatcher > > -AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4) { - return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4)); -} - -template -inline internal::EitherOfMatcher > > > -AnyOf(Matcher1 m1, Matcher2 m2, Matcher3 m3, Matcher4 m4, Matcher5 m5) { - return ::testing::AnyOf(m1, ::testing::AnyOf(m2, m3, m4, m5)); -} - -template -inline internal::EitherOfMatcher > > > > -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 -inline internal::EitherOfMatcher > > > > > -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 -inline internal::EitherOfMatcher > > > > > > -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 -inline internal::EitherOfMatcher > > > > > > > -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 -inline internal::EitherOfMatcher > > > > > > > > -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 - - -// The MATCHER* family of macros can be used in a namespace scope to -// define custom matchers easily. -// -// Basic Usage -// =========== -// -// The syntax -// -// MATCHER(name, description_string) { statements; } -// -// defines a matcher with the given name that executes the statements, -// which must return a bool to indicate if the match succeeds. Inside -// the statements, you can refer to the value being matched by 'arg', -// and refer to its type by 'arg_type'. -// -// The description string documents what the matcher does, and is used -// to generate the failure message when the match fails. Since a -// MATCHER() is usually defined in a header file shared by multiple -// C++ source files, we require the description to be a C-string -// literal to avoid possible side effects. It can be empty, in which -// case we'll use the sequence of words in the matcher name as the -// description. -// -// For example: -// -// MATCHER(IsEven, "") { return (arg % 2) == 0; } -// -// allows you to write -// -// // Expects mock_foo.Bar(n) to be called where n is even. -// EXPECT_CALL(mock_foo, Bar(IsEven())); -// -// or, -// -// // Verifies that the value of some_expression is even. -// EXPECT_THAT(some_expression, IsEven()); -// -// If the above assertion fails, it will print something like: -// -// Value of: some_expression -// Expected: is even -// Actual: 7 -// -// where the description "is even" is automatically calculated from the -// matcher name IsEven. -// -// Argument Type -// ============= -// -// Note that the type of the value being matched (arg_type) is -// determined by the context in which you use the matcher and is -// supplied to you by the compiler, so you don't need to worry about -// declaring it (nor can you). This allows the matcher to be -// polymorphic. For example, IsEven() can be used to match any type -// where the value of "(arg % 2) == 0" can be implicitly converted to -// a bool. In the "Bar(IsEven())" example above, if method Bar() -// takes an int, 'arg_type' will be int; if it takes an unsigned long, -// 'arg_type' will be unsigned long; and so on. -// -// Parameterizing Matchers -// ======================= -// -// Sometimes you'll want to parameterize the matcher. For that you -// can use another macro: -// -// MATCHER_P(name, param_name, description_string) { statements; } -// -// For example: -// -// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; } -// -// will allow you to write: -// -// EXPECT_THAT(Blah("a"), HasAbsoluteValue(n)); -// -// which may lead to this message (assuming n is 10): -// -// Value of: Blah("a") -// Expected: has absolute value 10 -// Actual: -9 -// -// Note that both the matcher description and its parameter are -// printed, making the message human-friendly. -// -// In the matcher definition body, you can write 'foo_type' to -// reference the type of a parameter named 'foo'. For example, in the -// body of MATCHER_P(HasAbsoluteValue, value) above, you can write -// 'value_type' to refer to the type of 'value'. -// -// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to -// support multi-parameter matchers. -// -// Describing Parameterized Matchers -// ================================= -// -// The last argument to MATCHER*() is a string-typed expression. The -// expression can reference all of the matcher's parameters and a -// special bool-typed variable named 'negation'. When 'negation' is -// false, the expression should evaluate to the matcher's description; -// otherwise it should evaluate to the description of the negation of -// the matcher. For example, -// -// using testing::PrintToString; -// -// MATCHER_P2(InClosedRange, low, hi, -// string(negation ? "is not" : "is") + " in range [" + -// PrintToString(low) + ", " + PrintToString(hi) + "]") { -// return low <= arg && arg <= hi; -// } -// ... -// EXPECT_THAT(3, InClosedRange(4, 6)); -// EXPECT_THAT(3, Not(InClosedRange(2, 4))); -// -// would generate two failures that contain the text: -// -// Expected: is in range [4, 6] -// ... -// Expected: is not in range [2, 4] -// -// If you specify "" as the description, the failure message will -// contain the sequence of words in the matcher name followed by the -// parameter values printed as a tuple. For example, -// -// MATCHER_P2(InClosedRange, low, hi, "") { ... } -// ... -// EXPECT_THAT(3, InClosedRange(4, 6)); -// EXPECT_THAT(3, Not(InClosedRange(2, 4))); -// -// would generate two failures that contain the text: -// -// Expected: in closed range (4, 6) -// ... -// Expected: not (in closed range (2, 4)) -// -// Types of Matcher Parameters -// =========================== -// -// For the purpose of typing, you can view -// -// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... } -// -// as shorthand for -// -// template -// FooMatcherPk -// Foo(p1_type p1, ..., pk_type pk) { ... } -// -// When you write Foo(v1, ..., vk), the compiler infers the types of -// the parameters v1, ..., and vk for you. If you are not happy with -// the result of the type inference, you can specify the types by -// explicitly instantiating the template, as in Foo(5, -// false). As said earlier, you don't get to (or need to) specify -// 'arg_type' as that's determined by the context in which the matcher -// is used. You can assign the result of expression Foo(p1, ..., pk) -// to a variable of type FooMatcherPk. This -// can be useful when composing matchers. -// -// While you can instantiate a matcher template with reference types, -// passing the parameters by pointer usually makes your code more -// readable. If, however, you still want to pass a parameter by -// reference, be aware that in the failure message generated by the -// matcher you will see the value of the referenced object but not its -// address. -// -// Explaining Match Results -// ======================== -// -// Sometimes the matcher description alone isn't enough to explain why -// the match has failed or succeeded. For example, when expecting a -// long string, it can be very helpful to also print the diff between -// the expected string and the actual one. To achieve that, you can -// optionally stream additional information to a special variable -// named result_listener, whose type is a pointer to class -// MatchResultListener: -// -// MATCHER_P(EqualsLongString, str, "") { -// if (arg == str) return true; -// -// *result_listener << "the difference: " -/// << DiffStrings(str, arg); -// return false; -// } -// -// Overloading Matchers -// ==================== -// -// You can overload matchers with different numbers of parameters: -// -// MATCHER_P(Blah, a, description_string1) { ... } -// MATCHER_P2(Blah, a, b, description_string2) { ... } -// -// Caveats -// ======= -// -// When defining a new matcher, you should also consider implementing -// MatcherInterface or using MakePolymorphicMatcher(). These -// approaches require more work than the MATCHER* macros, but also -// give you more control on the types of the value being matched and -// the matcher parameters, which may leads to better compiler error -// messages when the matcher is used wrong. They also allow -// overloading matchers based on parameter types (as opposed to just -// based on the number of parameters). -// -// MATCHER*() can only be used in a namespace scope. The reason is -// that C++ doesn't yet allow function-local types to be used to -// instantiate templates. The up-coming C++0x standard will fix this. -// Once that's done, we'll consider supporting using MATCHER*() inside -// a function. -// -// More Information -// ================ -// -// To learn more about using these macros, please search for 'MATCHER' -// on http://code.google.com/p/googlemock/wiki/CookBook. - -#define MATCHER(name, description)\ - class name##Matcher {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - gmock_Impl()\ - {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\ - 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);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl());\ - }\ - name##Matcher() {\ - }\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##Matcher);\ - };\ - inline name##Matcher name() {\ - return name##Matcher();\ - }\ - template \ - bool name##Matcher::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const - -#define MATCHER_P(name, p0, description)\ - template \ - class name##MatcherP {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - explicit gmock_Impl(p0##_type gmock_p0)\ - : p0(gmock_p0) {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\ - p0##_type p0;\ - 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)));\ - }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0));\ - }\ - name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\ - }\ - p0##_type p0;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP);\ - };\ - template \ - inline name##MatcherP name(p0##_type p0) {\ - return name##MatcherP(p0);\ - }\ - template \ - template \ - bool name##MatcherP::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const - -#define MATCHER_P2(name, p0, p1, description)\ - template \ - class name##MatcherP2 {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\ - : p0(gmock_p0), p1(gmock_p1) {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\ - p0##_type p0;\ - p1##_type p1;\ - 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, p1)));\ - }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1));\ - }\ - name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \ - p1(gmock_p1) {\ - }\ - p0##_type p0;\ - p1##_type p1;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\ - };\ - template \ - inline name##MatcherP2 name(p0##_type p0, \ - p1##_type p1) {\ - return name##MatcherP2(p0, p1);\ - }\ - template \ - template \ - bool name##MatcherP2::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const - -#define MATCHER_P3(name, p0, p1, p2, description)\ - template \ - class name##MatcherP3 {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - 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, p1, \ - p2)));\ - }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2));\ - }\ - name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\ - };\ - template \ - inline name##MatcherP3 name(p0##_type p0, \ - p1##_type p1, p2##_type p2) {\ - return name##MatcherP3(p0, p1, p2);\ - }\ - template \ - template \ - bool name##MatcherP3::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const - -#define MATCHER_P4(name, p0, p1, p2, p3, description)\ - template \ - class name##MatcherP4 {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - 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, p1, p2, p3)));\ - }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3));\ - }\ - 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(gmock_p2), p3(gmock_p3) {\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\ - };\ - template \ - inline name##MatcherP4 name(p0##_type p0, p1##_type p1, p2##_type p2, \ - p3##_type p3) {\ - return name##MatcherP4(p0, \ - p1, p2, p3);\ - }\ - template \ - template \ - bool name##MatcherP4::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const - -#define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\ - template \ - class name##MatcherP5 {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \ - p3##_type gmock_p3, p4##_type gmock_p4)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4) {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - 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, p1, p2, p3, p4)));\ - }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4));\ - }\ - name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, \ - p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \ - p3(gmock_p3), p4(gmock_p4) {\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\ - };\ - template \ - inline name##MatcherP5 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ - p4##_type p4) {\ - return name##MatcherP5(p0, p1, p2, p3, p4);\ - }\ - template \ - template \ - bool name##MatcherP5::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const - -#define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\ - template \ - class name##MatcherP6 {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - 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)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5) {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - 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, p1, p2, p3, p4, p5)));\ - }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5));\ - }\ - name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \ - 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), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\ - };\ - template \ - inline name##MatcherP6 name(p0##_type p0, p1##_type p1, p2##_type p2, \ - p3##_type p3, p4##_type p4, p5##_type p5) {\ - return name##MatcherP6(p0, p1, p2, p3, p4, p5);\ - }\ - template \ - template \ - bool name##MatcherP6::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const - -#define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\ - template \ - class name##MatcherP7 {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - 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, \ - p6##_type gmock_p6)\ - : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \ - p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - 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, p1, p2, p3, p4, p5, \ - p6)));\ - }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6));\ - }\ - name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \ - 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), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \ - p6(gmock_p6) {\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\ - };\ - template \ - inline name##MatcherP7 name(p0##_type p0, p1##_type p1, \ - p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ - p6##_type p6) {\ - return name##MatcherP7(p0, p1, p2, p3, p4, p5, p6);\ - }\ - template \ - template \ - bool name##MatcherP7::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const - -#define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\ - template \ - class name##MatcherP8 {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - 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, \ - p6##_type gmock_p6, 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), p7(gmock_p7) {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - 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, p1, p2, \ - p3, p4, p5, p6, p7)));\ - }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7));\ - }\ - name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ - p5##_type gmock_p5, p6##_type gmock_p6, \ - 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), \ - p7(gmock_p7) {\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\ - };\ - template \ - inline name##MatcherP8 name(p0##_type p0, \ - p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \ - p6##_type p6, p7##_type p7) {\ - return name##MatcherP8(p0, p1, p2, p3, p4, p5, \ - p6, p7);\ - }\ - template \ - template \ - bool name##MatcherP8::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const - -#define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\ - template \ - class name##MatcherP9 {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - 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, \ - p6##_type gmock_p6, p7##_type gmock_p7, 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), \ - p8(gmock_p8) {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - p8##_type p8;\ - 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, p1, p2, p3, p4, p5, p6, p7, p8)));\ - }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7, p8));\ - }\ - name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ - 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), \ - p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \ - p8(gmock_p8) {\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - p8##_type p8;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\ - };\ - template \ - inline name##MatcherP9 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ - p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \ - p8##_type p8) {\ - return name##MatcherP9(p0, p1, p2, \ - p3, p4, p5, p6, p7, p8);\ - }\ - template \ - template \ - bool name##MatcherP9::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const - -#define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\ - template \ - class name##MatcherP10 {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - 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, \ - p6##_type gmock_p6, p7##_type gmock_p7, 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), p7(gmock_p7), \ - p8(gmock_p8), p9(gmock_p9) {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - p8##_type p8;\ - p9##_type p9;\ - 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, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\ - }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\ - }\ - name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \ - p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \ - 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), \ - p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \ - p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\ - }\ - p0##_type p0;\ - p1##_type p1;\ - p2##_type p2;\ - p3##_type p3;\ - p4##_type p4;\ - p5##_type p5;\ - p6##_type p6;\ - p7##_type p7;\ - p8##_type p8;\ - p9##_type p9;\ - private:\ - GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\ - };\ - template \ - inline name##MatcherP10 name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \ - p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \ - p9##_type p9) {\ - return name##MatcherP10(p0, \ - p1, p2, p3, p4, p5, p6, p7, p8, p9);\ - }\ - template \ - template \ - bool name##MatcherP10::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ diff --git a/lib/gmock/include/gmock/gmock-generated-matchers.h.pump b/lib/gmock/include/gmock/gmock-generated-matchers.h.pump deleted file mode 100644 index 8c09444c..00000000 --- a/lib/gmock/include/gmock/gmock-generated-matchers.h.pump +++ /dev/null @@ -1,651 +0,0 @@ -$$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-actions.h. -$$ -$var n = 10 $$ The maximum arity we support. -$$ }} This line fixes auto-indentation of the following code in Emacs. -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements some commonly used variadic matchers. - -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ - -#include -#include -#include -#include "gmock/gmock-matchers.h" - -namespace testing { -namespace internal { - -$range i 0..n-1 - -// The type of the i-th (0-based) field of Tuple. -#define GMOCK_FIELD_TYPE_(Tuple, i) \ - typename ::std::tr1::tuple_element::type - -// TupleFields is for selecting fields from a -// tuple of type Tuple. It has two members: -// -// type: a tuple type whose i-th field is the ki-th field of Tuple. -// GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple. -// -// For example, in class TupleFields, 2, 0>, we have: -// -// type is tuple, and -// GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true). - -template -class TupleFields; - -// This generic version is used when there are $n selectors. -template -class TupleFields { - public: - typedef ::std::tr1::tuple<$for i, [[GMOCK_FIELD_TYPE_(Tuple, k$i)]]> type; - static type GetSelectedFields(const Tuple& t) { - using ::std::tr1::get; - return type($for i, [[get(t)]]); - } -}; - -// The following specialization is used for 0 ~ $(n-1) selectors. - -$for i [[ -$$ }}} -$range j 0..i-1 -$range k 0..n-1 - -template -class TupleFields { - public: - typedef ::std::tr1::tuple<$for j, [[GMOCK_FIELD_TYPE_(Tuple, k$j)]]> type; - static type GetSelectedFields(const Tuple& $if i==0 [[/* t */]] $else [[t]]) { - using ::std::tr1::get; - return type($for j, [[get(t)]]); - } -}; - -]] - -#undef GMOCK_FIELD_TYPE_ - -// Implements the Args() matcher. - -$var ks = [[$for i, [[k$i]]]] -template -class ArgsMatcherImpl : public MatcherInterface { - public: - // ArgsTuple may have top-level const or reference modifiers. - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple; - typedef typename internal::TupleFields::type SelectedArgs; - typedef Matcher MonomorphicInnerMatcher; - - template - explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher) - : inner_matcher_(SafeMatcherCast(inner_matcher)) {} - - virtual bool MatchAndExplain(ArgsTuple args, - MatchResultListener* listener) const { - const SelectedArgs& selected_args = GetSelectedArgs(args); - if (!listener->IsInterested()) - return inner_matcher_.Matches(selected_args); - - PrintIndices(listener->stream()); - *listener << "are " << PrintToString(selected_args); - - StringMatchResultListener inner_listener; - const bool match = inner_matcher_.MatchAndExplain(selected_args, - &inner_listener); - PrintIfNotEmpty(inner_listener.str(), listener->stream()); - return match; - } - - virtual void DescribeTo(::std::ostream* os) const { - *os << "are a tuple "; - PrintIndices(os); - inner_matcher_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "are a tuple "; - PrintIndices(os); - inner_matcher_.DescribeNegationTo(os); - } - - private: - static SelectedArgs GetSelectedArgs(ArgsTuple args) { - return TupleFields::GetSelectedFields(args); - } - - // Prints the indices of the selected fields. - static void PrintIndices(::std::ostream* os) { - *os << "whose fields ("; - const int indices[$n] = { $ks }; - for (int i = 0; i < $n; i++) { - if (indices[i] < 0) - break; - - if (i >= 1) - *os << ", "; - - *os << "#" << indices[i]; - } - *os << ") "; - } - - const MonomorphicInnerMatcher inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl); -}; - -template -class ArgsMatcher { - public: - explicit ArgsMatcher(const InnerMatcher& inner_matcher) - : inner_matcher_(inner_matcher) {} - - template - operator Matcher() const { - return MakeMatcher(new ArgsMatcherImpl(inner_matcher_)); - } - - private: - const InnerMatcher inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(ArgsMatcher); -}; - -// Implements ElementsAre() of 1-$n arguments. - - -$range i 1..n -$for i [[ -$range j 1..i -template <$for j, [[typename T$j]]> -class ElementsAreMatcher$i { - public: - $if i==1 [[explicit ]]ElementsAreMatcher$i($for j, [[const T$j& e$j]])$if i > 0 [[ : ]] - $for j, [[e$j[[]]_(e$j)]] {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - -$if i==1 [[ - - // Nokia's Symbian Compiler has a nasty bug where the object put - // in a one-element local array is not destructed when the array - // goes out of scope. This leads to obvious badness as we've - // added the linked_ptr in it to our other linked_ptrs list. - // Hence we implement ElementsAreMatcher1 specially to avoid using - // a local array. - const Matcher matcher = - MatcherCast(e1_); - return MakeMatcher(new ElementsAreMatcherImpl(&matcher, 1)); -]] $else [[ - - const Matcher matchers[] = { - -$for j [[ - MatcherCast(e$j[[]]_), - -]] - }; - - return MakeMatcher(new ElementsAreMatcherImpl(matchers, $i)); -]] - - } - - private: - -$for j [[ - const T$j& e$j[[]]_; - -]] - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher$i); -}; - - -]] -} // namespace internal - -// Args(a_matcher) matches a tuple if the selected -// fields of it matches a_matcher. C++ doesn't support default -// arguments for function templates, so we have to overload it. - -$range i 0..n -$for i [[ -$range j 1..i -template <$for j [[int k$j, ]]typename InnerMatcher> -inline internal::ArgsMatcher -Args(const InnerMatcher& matcher) { - return internal::ArgsMatcher(matcher); -} - - -]] -// ElementsAre(e0, e1, ..., e_n) matches an STL-style container with -// (n + 1) elements, where the i-th element in the container must -// match the i-th argument in the list. Each argument of -// ElementsAre() can be either a value or a matcher. We support up to -// $n arguments. -// -// NOTE: Since ElementsAre() cares about the order of the elements, it -// must not be used with containers whose elements's order is -// undefined (e.g. hash_map). - -inline internal::ElementsAreMatcher0 ElementsAre() { - return internal::ElementsAreMatcher0(); -} - -$range i 1..n -$for i [[ -$range j 1..i - -template <$for j, [[typename T$j]]> -inline internal::ElementsAreMatcher$i<$for j, [[T$j]]> ElementsAre($for j, [[const T$j& e$j]]) { - return internal::ElementsAreMatcher$i<$for j, [[T$j]]>($for j, [[e$j]]); -} - -]] - -// ElementsAreArray(array) and ElementAreArray(array, count) are like -// ElementsAre(), except that they take an array of values or -// matchers. The former form infers the size of 'array', which must -// be a static C-style array. In the latter form, 'array' can either -// be a static array or a pointer to a dynamically created array. - -template -inline internal::ElementsAreArrayMatcher ElementsAreArray( - const T* first, size_t count) { - return internal::ElementsAreArrayMatcher(first, count); -} - -template -inline internal::ElementsAreArrayMatcher -ElementsAreArray(const T (&array)[N]) { - return internal::ElementsAreArrayMatcher(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 firing. - -$range i 2..n -$for i [[ -$range j 1..i -$range k 1..i-1 - -template <$for j, [[typename Matcher$j]]> -inline $for k[[internal::BothOfMatcher ]] - -AllOf($for j, [[Matcher$j m$j]]) { - -$if i == 2 [[ - return internal::BothOfMatcher(m1, m2); -]] $else [[ - return ::testing::AllOf(m1, ::testing::AllOf($for k, [[m$(k + 1)]])); -]] - -} - -]] - -// AnyOf(m1, m2, ..., mk) matches any value that matches any of the given -// sub-matchers. AnyOf is called fully qualified to prevent ADL from firing. - -$range i 2..n -$for i [[ -$range j 1..i -$range k 1..i-1 - -template <$for j, [[typename Matcher$j]]> -inline $for k[[internal::EitherOfMatcher ]] - -AnyOf($for j, [[Matcher$j m$j]]) { - -$if i == 2 [[ - return internal::EitherOfMatcher(m1, m2); -]] $else [[ - return ::testing::AnyOf(m1, ::testing::AnyOf($for k, [[m$(k + 1)]])); -]] - -} - -]] - -} // namespace testing -$$ } // This Pump meta comment fixes auto-indentation in Emacs. It will not -$$ // show up in the generated code. - - -// The MATCHER* family of macros can be used in a namespace scope to -// define custom matchers easily. -// -// Basic Usage -// =========== -// -// The syntax -// -// MATCHER(name, description_string) { statements; } -// -// defines a matcher with the given name that executes the statements, -// which must return a bool to indicate if the match succeeds. Inside -// the statements, you can refer to the value being matched by 'arg', -// and refer to its type by 'arg_type'. -// -// The description string documents what the matcher does, and is used -// to generate the failure message when the match fails. Since a -// MATCHER() is usually defined in a header file shared by multiple -// C++ source files, we require the description to be a C-string -// literal to avoid possible side effects. It can be empty, in which -// case we'll use the sequence of words in the matcher name as the -// description. -// -// For example: -// -// MATCHER(IsEven, "") { return (arg % 2) == 0; } -// -// allows you to write -// -// // Expects mock_foo.Bar(n) to be called where n is even. -// EXPECT_CALL(mock_foo, Bar(IsEven())); -// -// or, -// -// // Verifies that the value of some_expression is even. -// EXPECT_THAT(some_expression, IsEven()); -// -// If the above assertion fails, it will print something like: -// -// Value of: some_expression -// Expected: is even -// Actual: 7 -// -// where the description "is even" is automatically calculated from the -// matcher name IsEven. -// -// Argument Type -// ============= -// -// Note that the type of the value being matched (arg_type) is -// determined by the context in which you use the matcher and is -// supplied to you by the compiler, so you don't need to worry about -// declaring it (nor can you). This allows the matcher to be -// polymorphic. For example, IsEven() can be used to match any type -// where the value of "(arg % 2) == 0" can be implicitly converted to -// a bool. In the "Bar(IsEven())" example above, if method Bar() -// takes an int, 'arg_type' will be int; if it takes an unsigned long, -// 'arg_type' will be unsigned long; and so on. -// -// Parameterizing Matchers -// ======================= -// -// Sometimes you'll want to parameterize the matcher. For that you -// can use another macro: -// -// MATCHER_P(name, param_name, description_string) { statements; } -// -// For example: -// -// MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; } -// -// will allow you to write: -// -// EXPECT_THAT(Blah("a"), HasAbsoluteValue(n)); -// -// which may lead to this message (assuming n is 10): -// -// Value of: Blah("a") -// Expected: has absolute value 10 -// Actual: -9 -// -// Note that both the matcher description and its parameter are -// printed, making the message human-friendly. -// -// In the matcher definition body, you can write 'foo_type' to -// reference the type of a parameter named 'foo'. For example, in the -// body of MATCHER_P(HasAbsoluteValue, value) above, you can write -// 'value_type' to refer to the type of 'value'. -// -// We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P$n to -// support multi-parameter matchers. -// -// Describing Parameterized Matchers -// ================================= -// -// The last argument to MATCHER*() is a string-typed expression. The -// expression can reference all of the matcher's parameters and a -// special bool-typed variable named 'negation'. When 'negation' is -// false, the expression should evaluate to the matcher's description; -// otherwise it should evaluate to the description of the negation of -// the matcher. For example, -// -// using testing::PrintToString; -// -// MATCHER_P2(InClosedRange, low, hi, -// string(negation ? "is not" : "is") + " in range [" + -// PrintToString(low) + ", " + PrintToString(hi) + "]") { -// return low <= arg && arg <= hi; -// } -// ... -// EXPECT_THAT(3, InClosedRange(4, 6)); -// EXPECT_THAT(3, Not(InClosedRange(2, 4))); -// -// would generate two failures that contain the text: -// -// Expected: is in range [4, 6] -// ... -// Expected: is not in range [2, 4] -// -// If you specify "" as the description, the failure message will -// contain the sequence of words in the matcher name followed by the -// parameter values printed as a tuple. For example, -// -// MATCHER_P2(InClosedRange, low, hi, "") { ... } -// ... -// EXPECT_THAT(3, InClosedRange(4, 6)); -// EXPECT_THAT(3, Not(InClosedRange(2, 4))); -// -// would generate two failures that contain the text: -// -// Expected: in closed range (4, 6) -// ... -// Expected: not (in closed range (2, 4)) -// -// Types of Matcher Parameters -// =========================== -// -// For the purpose of typing, you can view -// -// MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... } -// -// as shorthand for -// -// template -// FooMatcherPk -// Foo(p1_type p1, ..., pk_type pk) { ... } -// -// When you write Foo(v1, ..., vk), the compiler infers the types of -// the parameters v1, ..., and vk for you. If you are not happy with -// the result of the type inference, you can specify the types by -// explicitly instantiating the template, as in Foo(5, -// false). As said earlier, you don't get to (or need to) specify -// 'arg_type' as that's determined by the context in which the matcher -// is used. You can assign the result of expression Foo(p1, ..., pk) -// to a variable of type FooMatcherPk. This -// can be useful when composing matchers. -// -// While you can instantiate a matcher template with reference types, -// passing the parameters by pointer usually makes your code more -// readable. If, however, you still want to pass a parameter by -// reference, be aware that in the failure message generated by the -// matcher you will see the value of the referenced object but not its -// address. -// -// Explaining Match Results -// ======================== -// -// Sometimes the matcher description alone isn't enough to explain why -// the match has failed or succeeded. For example, when expecting a -// long string, it can be very helpful to also print the diff between -// the expected string and the actual one. To achieve that, you can -// optionally stream additional information to a special variable -// named result_listener, whose type is a pointer to class -// MatchResultListener: -// -// MATCHER_P(EqualsLongString, str, "") { -// if (arg == str) return true; -// -// *result_listener << "the difference: " -/// << DiffStrings(str, arg); -// return false; -// } -// -// Overloading Matchers -// ==================== -// -// You can overload matchers with different numbers of parameters: -// -// MATCHER_P(Blah, a, description_string1) { ... } -// MATCHER_P2(Blah, a, b, description_string2) { ... } -// -// Caveats -// ======= -// -// When defining a new matcher, you should also consider implementing -// MatcherInterface or using MakePolymorphicMatcher(). These -// approaches require more work than the MATCHER* macros, but also -// give you more control on the types of the value being matched and -// the matcher parameters, which may leads to better compiler error -// messages when the matcher is used wrong. They also allow -// overloading matchers based on parameter types (as opposed to just -// based on the number of parameters). -// -// MATCHER*() can only be used in a namespace scope. The reason is -// that C++ doesn't yet allow function-local types to be used to -// instantiate templates. The up-coming C++0x standard will fix this. -// Once that's done, we'll consider supporting using MATCHER*() inside -// a function. -// -// More Information -// ================ -// -// To learn more about using these macros, please search for 'MATCHER' -// on http://code.google.com/p/googlemock/wiki/CookBook. - -$range i 0..n -$for i - -[[ -$var macro_name = [[$if i==0 [[MATCHER]] $elif i==1 [[MATCHER_P]] - $else [[MATCHER_P$i]]]] -$var class_name = [[name##Matcher[[$if i==0 [[]] $elif i==1 [[P]] - $else [[P$i]]]]]] -$range j 0..i-1 -$var template = [[$if i==0 [[]] $else [[ - - template <$for j, [[typename p$j##_type]]>\ -]]]] -$var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] -$var impl_ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]] -$var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]] -$var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]] -$var params = [[$for j, [[p$j]]]] -$var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]] -$var param_types_and_names = [[$for j, [[p$j##_type p$j]]]] -$var param_field_decls = [[$for j -[[ - - p$j##_type p$j;\ -]]]] -$var param_field_decls2 = [[$for j -[[ - - p$j##_type p$j;\ -]]]] - -#define $macro_name(name$for j [[, p$j]], description)\$template - class $class_name {\ - public:\ - template \ - class gmock_Impl : public ::testing::MatcherInterface {\ - public:\ - [[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\ - $impl_inits {}\ - virtual bool MatchAndExplain(\ - arg_type arg, ::testing::MatchResultListener* result_listener) const;\ - virtual void DescribeTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(false);\ - }\ - virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\ - *gmock_os << FormatDescription(true);\ - }\$param_field_decls - 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<$for j, [[p$j##_type]]>($for j, [[p$j]])));\ - }\ - GTEST_DISALLOW_ASSIGN_(gmock_Impl);\ - };\ - template \ - operator ::testing::Matcher() const {\ - return ::testing::Matcher(\ - new gmock_Impl($params));\ - }\ - $class_name($ctor_param_list)$inits {\ - }\$param_field_decls2 - private:\ - GTEST_DISALLOW_ASSIGN_($class_name);\ - };\$template - inline $class_name$param_types name($param_types_and_names) {\ - return $class_name$param_types($params);\ - }\$template - template \ - bool $class_name$param_types::gmock_Impl::MatchAndExplain(\ - arg_type arg,\ - ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\ - const -]] - - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_ diff --git a/lib/gmock/include/gmock/gmock-generated-nice-strict.h b/lib/gmock/include/gmock/gmock-generated-nice-strict.h deleted file mode 100644 index 6099e81e..00000000 --- a/lib/gmock/include/gmock/gmock-generated-nice-strict.h +++ /dev/null @@ -1,274 +0,0 @@ -// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! - -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Implements class templates NiceMock and StrictMock. -// -// Given a mock class MockFoo that is created using Google Mock, -// NiceMock is a subclass of MockFoo that allows -// uninteresting calls (i.e. calls to mock methods that have no -// EXPECT_CALL specs), and StrictMock is a subclass of -// MockFoo that treats all uninteresting calls as errors. -// -// NiceMock and StrictMock "inherits" the constructors of their -// respective base class, with up-to 10 arguments. Therefore you can -// write NiceMock(5, "a") to construct a nice mock where -// MockFoo has a constructor that accepts (int, const char*), for -// example. -// -// A known limitation is that NiceMock and -// StrictMock only works for mock methods defined using the -// MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. If a -// mock method is defined in a base class of MockFoo, the "nice" or -// "strict" modifier may not affect it, depending on the compiler. In -// particular, nesting NiceMock and StrictMock is NOT supported. -// -// Another known limitation is that the constructors of the base mock -// cannot have arguments passed by non-const reference, which are -// banned by the Google C++ style guide anyway. - -#ifndef 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/internal/gmock-port.h" - -namespace testing { - -template -class NiceMock : public MockClass { - public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - NiceMock() { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - // C++ doesn't (yet) allow inheritance of constructors, so we have - // to define it for each arity. - template - explicit NiceMock(const A1& a1) : MockClass(a1) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - template - NiceMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - NiceMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - NiceMock(const A1& a1, const A2& a2, const A3& a3, - const A4& a4) : MockClass(a1, a2, a3, a4) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - NiceMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5) : MockClass(a1, a2, a3, a4, a5) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - 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) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - 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, - a6, a7) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - 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(a1, - a2, a3, a4, a5, a6, a7, a8) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - 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) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - 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 A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - virtual ~NiceMock() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_(this)); - } - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); -}; - -template -class StrictMock : public MockClass { - public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - StrictMock() { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - explicit StrictMock(const A1& a1) : MockClass(a1) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - template - StrictMock(const A1& a1, const A2& a2) : MockClass(a1, a2) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - StrictMock(const A1& a1, const A2& a2, const A3& a3) : MockClass(a1, a2, a3) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - StrictMock(const A1& a1, const A2& a2, const A3& a3, - const A4& a4) : MockClass(a1, a2, a3, a4) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - StrictMock(const A1& a1, const A2& a2, const A3& a3, const A4& a4, - const A5& a5) : MockClass(a1, a2, a3, a4, a5) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - 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) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - 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, - a6, a7) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - 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(a1, - a2, a3, a4, a5, a6, a7, a8) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - 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) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - 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 A10& a10) : MockClass(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - virtual ~StrictMock() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_(this)); - } - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); -}; - -// The following specializations catch some (relatively more common) -// user errors of nesting nice and strict mocks. They do NOT catch -// all possible errors. - -// These specializations are declared but not defined, as NiceMock and -// StrictMock cannot be nested. -template -class NiceMock >; -template -class NiceMock >; -template -class StrictMock >; -template -class StrictMock >; - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ diff --git a/lib/gmock/include/gmock/gmock-generated-nice-strict.h.pump b/lib/gmock/include/gmock/gmock-generated-nice-strict.h.pump deleted file mode 100644 index b7964db3..00000000 --- a/lib/gmock/include/gmock/gmock-generated-nice-strict.h.pump +++ /dev/null @@ -1,160 +0,0 @@ -$$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-nice-strict.h. -$$ -$var n = 10 $$ The maximum arity we support. -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Implements class templates NiceMock and StrictMock. -// -// Given a mock class MockFoo that is created using Google Mock, -// NiceMock is a subclass of MockFoo that allows -// uninteresting calls (i.e. calls to mock methods that have no -// EXPECT_CALL specs), and StrictMock is a subclass of -// MockFoo that treats all uninteresting calls as errors. -// -// NiceMock and StrictMock "inherits" the constructors of their -// respective base class, with up-to $n arguments. Therefore you can -// write NiceMock(5, "a") to construct a nice mock where -// MockFoo has a constructor that accepts (int, const char*), for -// example. -// -// A known limitation is that NiceMock and -// StrictMock only works for mock methods defined using the -// MOCK_METHOD* family of macros DIRECTLY in the MockFoo class. If a -// mock method is defined in a base class of MockFoo, the "nice" or -// "strict" modifier may not affect it, depending on the compiler. In -// particular, nesting NiceMock and StrictMock is NOT supported. -// -// Another known limitation is that the constructors of the base mock -// cannot have arguments passed by non-const reference, which are -// banned by the Google C++ style guide anyway. - -#ifndef 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/internal/gmock-port.h" - -namespace testing { - -template -class NiceMock : public MockClass { - public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - NiceMock() { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - // C++ doesn't (yet) allow inheritance of constructors, so we have - // to define it for each arity. - template - explicit NiceMock(const A1& a1) : MockClass(a1) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - -$range i 2..n -$for i [[ -$range j 1..i - template <$for j, [[typename A$j]]> - NiceMock($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) { - ::testing::Mock::AllowUninterestingCalls( - internal::ImplicitCast_(this)); - } - - -]] - virtual ~NiceMock() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_(this)); - } - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(NiceMock); -}; - -template -class StrictMock : public MockClass { - public: - // We don't factor out the constructor body to a common method, as - // we have to avoid a possible clash with members of MockClass. - StrictMock() { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - template - explicit StrictMock(const A1& a1) : MockClass(a1) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - -$for i [[ -$range j 1..i - template <$for j, [[typename A$j]]> - StrictMock($for j, [[const A$j& a$j]]) : MockClass($for j, [[a$j]]) { - ::testing::Mock::FailUninterestingCalls( - internal::ImplicitCast_(this)); - } - - -]] - virtual ~StrictMock() { - ::testing::Mock::UnregisterCallReaction( - internal::ImplicitCast_(this)); - } - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(StrictMock); -}; - -// The following specializations catch some (relatively more common) -// user errors of nesting nice and strict mocks. They do NOT catch -// all possible errors. - -// These specializations are declared but not defined, as NiceMock and -// StrictMock cannot be nested. -template -class NiceMock >; -template -class NiceMock >; -template -class StrictMock >; -template -class StrictMock >; - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_ diff --git a/lib/gmock/include/gmock/gmock-matchers.h b/lib/gmock/include/gmock/gmock-matchers.h deleted file mode 100644 index c21fa515..00000000 --- a/lib/gmock/include/gmock/gmock-matchers.h +++ /dev/null @@ -1,3066 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements some commonly used argument matchers. More -// matchers can be defined by the user implementing the -// MatcherInterface interface if necessary. - -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ - -#include -#include -#include // NOLINT -#include -#include -#include -#include - -#include "gmock/internal/gmock-internal-utils.h" -#include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" - -namespace testing { - -// To implement a matcher Foo for type T, define: -// 1. a class FooMatcherImpl that implements the -// MatcherInterface interface, and -// 2. a factory function that creates a Matcher object from a -// FooMatcherImpl*. -// -// The two-level delegation design makes it possible to allow a user -// to write "v" instead of "Eq(v)" where a Matcher is expected, which -// is impossible if we pass matchers by pointers. It also eases -// ownership management as Matcher objects can now be copied like -// plain values. - -// MatchResultListener is an abstract class. Its << operator can be -// used by a matcher to explain why a value matches or doesn't match. -// -// TODO(wan@google.com): add method -// bool InterestedInWhy(bool result) const; -// to indicate whether the listener is interested in why the match -// result is 'result'. -class MatchResultListener { - public: - // Creates a listener object with the given underlying ostream. The - // listener does not own the ostream. - explicit MatchResultListener(::std::ostream* os) : stream_(os) {} - virtual ~MatchResultListener() = 0; // Makes this class abstract. - - // Streams x to the underlying ostream; does nothing if the ostream - // is NULL. - template - MatchResultListener& operator<<(const T& x) { - if (stream_ != NULL) - *stream_ << x; - return *this; - } - - // Returns the underlying ostream. - ::std::ostream* stream() { return stream_; } - - // Returns true iff the listener is interested in an explanation of - // the match result. A matcher's MatchAndExplain() method can use - // this information to avoid generating the explanation when no one - // intends to hear it. - bool IsInterested() const { return stream_ != NULL; } - - private: - ::std::ostream* const stream_; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(MatchResultListener); -}; - -inline MatchResultListener::~MatchResultListener() { -} - -// The implementation of a matcher. -template -class MatcherInterface { - public: - virtual ~MatcherInterface() {} - - // Returns true iff the matcher matches x; also explains the match - // result to 'listener', in the form of a non-restrictive relative - // clause ("which ...", "whose ...", etc) that describes x. For - // example, the MatchAndExplain() method of the Pointee(...) matcher - // should generate an explanation like "which points to ...". - // - // You should override this method when defining a new matcher. - // - // It's the responsibility of the caller (Google Mock) to guarantee - // that 'listener' is not NULL. This helps to simplify a matcher's - // implementation when it doesn't care about the performance, as it - // can talk to 'listener' without checking its validity first. - // However, in order to implement dummy listeners efficiently, - // listener->stream() may be NULL. - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const = 0; - - // Describes this matcher to an ostream. The function should print - // a verb phrase that describes the property a value matching this - // matcher should have. The subject of the verb phrase is the value - // being matched. For example, the DescribeTo() method of the Gt(7) - // matcher prints "is greater than 7". - virtual void DescribeTo(::std::ostream* os) const = 0; - - // Describes the negation of this matcher to an ostream. For - // example, if the description of this matcher is "is greater than - // 7", the negated description could be "is not greater than 7". - // You are not required to override this when implementing - // MatcherInterface, but it is highly advised so that your matcher - // can produce good error messages. - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "not ("; - DescribeTo(os); - *os << ")"; - } -}; - -namespace internal { - -// A match result listener that ignores the explanation. -class DummyMatchResultListener : public MatchResultListener { - public: - DummyMatchResultListener() : MatchResultListener(NULL) {} - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(DummyMatchResultListener); -}; - -// A match result listener that forwards the explanation to a given -// ostream. The difference between this and MatchResultListener is -// that the former is concrete. -class StreamMatchResultListener : public MatchResultListener { - public: - explicit StreamMatchResultListener(::std::ostream* os) - : MatchResultListener(os) {} - - private: - GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamMatchResultListener); -}; - -// A match result listener that stores the explanation in a string. -class StringMatchResultListener : public MatchResultListener { - public: - StringMatchResultListener() : MatchResultListener(&ss_) {} - - // Returns the explanation heard so far. - internal::string str() const { return ss_.str(); } - - private: - ::std::stringstream ss_; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener); -}; - -// An internal class for implementing Matcher, which will derive -// from it. We put functionalities common to all Matcher -// specializations here to avoid code duplication. -template -class MatcherBase { - public: - // Returns true iff the matcher matches x; also explains the match - // result to 'listener'. - bool MatchAndExplain(T x, MatchResultListener* listener) const { - return impl_->MatchAndExplain(x, listener); - } - - // Returns true iff this matcher matches x. - bool Matches(T x) const { - DummyMatchResultListener dummy; - return MatchAndExplain(x, &dummy); - } - - // Describes this matcher to an ostream. - void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); } - - // Describes the negation of this matcher to an ostream. - void DescribeNegationTo(::std::ostream* os) const { - impl_->DescribeNegationTo(os); - } - - // Explains why x matches, or doesn't match, the matcher. - void ExplainMatchResultTo(T x, ::std::ostream* os) const { - StreamMatchResultListener listener(os); - MatchAndExplain(x, &listener); - } - - protected: - MatcherBase() {} - - // Constructs a matcher from its implementation. - explicit MatcherBase(const MatcherInterface* impl) - : impl_(impl) {} - - virtual ~MatcherBase() {} - - private: - // shared_ptr (util/gtl/shared_ptr.h) and linked_ptr have similar - // interfaces. The former dynamically allocates a chunk of memory - // to hold the reference count, while the latter tracks all - // references using a circular linked list without allocating - // memory. It has been observed that linked_ptr performs better in - // typical scenarios. However, shared_ptr can out-perform - // linked_ptr when there are many more uses of the copy constructor - // than the default constructor. - // - // If performance becomes a problem, we should see if using - // shared_ptr helps. - ::testing::internal::linked_ptr > impl_; -}; - -} // namespace internal - -// A Matcher is a copyable and IMMUTABLE (except by assignment) -// object that can check whether a value of type T matches. The -// implementation of Matcher is just a linked_ptr to const -// MatcherInterface, so copying is fairly cheap. Don't inherit -// from Matcher! -template -class Matcher : public internal::MatcherBase { - public: - // Constructs a null matcher. Needed for storing Matcher objects in STL - // containers. A default-constructed matcher is not yet initialized. You - // cannot use it until a valid value has been assigned to it. - Matcher() {} - - // Constructs a matcher from its implementation. - explicit Matcher(const MatcherInterface* impl) - : internal::MatcherBase(impl) {} - - // Implicit constructor here allows people to write - // EXPECT_CALL(foo, Bar(5)) instead of EXPECT_CALL(foo, Bar(Eq(5))) sometimes - Matcher(T value); // NOLINT -}; - -// The following two specializations allow the user to write str -// instead of Eq(str) and "foo" instead of Eq("foo") when a string -// matcher is expected. -template <> -class Matcher - : public internal::MatcherBase { - public: - Matcher() {} - - explicit Matcher(const MatcherInterface* impl) - : internal::MatcherBase(impl) {} - - // Allows the user to write str instead of Eq(str) sometimes, where - // str is a string object. - Matcher(const internal::string& s); // NOLINT - - // Allows the user to write "foo" instead of Eq("foo") sometimes. - Matcher(const char* s); // NOLINT -}; - -template <> -class Matcher - : public internal::MatcherBase { - public: - Matcher() {} - - explicit Matcher(const MatcherInterface* impl) - : internal::MatcherBase(impl) {} - - // Allows the user to write str instead of Eq(str) sometimes, where - // str is a string object. - Matcher(const internal::string& s); // NOLINT - - // Allows the user to write "foo" instead of Eq("foo") sometimes. - Matcher(const char* s); // NOLINT -}; - -// The PolymorphicMatcher class template makes it easy to implement a -// polymorphic matcher (i.e. a matcher that can match values of more -// than one type, e.g. Eq(n) and NotNull()). -// -// To define a polymorphic matcher, a user should provide an Impl -// class that has a DescribeTo() method and a DescribeNegationTo() -// method, and define a member function (or member function template) -// -// bool MatchAndExplain(const Value& value, -// MatchResultListener* listener) const; -// -// See the definition of NotNull() for a complete example. -template -class PolymorphicMatcher { - public: - explicit PolymorphicMatcher(const Impl& an_impl) : impl_(an_impl) {} - - // Returns a mutable reference to the underlying matcher - // implementation object. - Impl& mutable_impl() { return impl_; } - - // Returns an immutable reference to the underlying matcher - // implementation object. - const Impl& impl() const { return impl_; } - - template - operator Matcher() const { - return Matcher(new MonomorphicImpl(impl_)); - } - - private: - template - class MonomorphicImpl : public MatcherInterface { - public: - explicit MonomorphicImpl(const Impl& impl) : impl_(impl) {} - - virtual void DescribeTo(::std::ostream* os) const { - impl_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - impl_.DescribeNegationTo(os); - } - - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { - return impl_.MatchAndExplain(x, listener); - } - - private: - const Impl impl_; - - GTEST_DISALLOW_ASSIGN_(MonomorphicImpl); - }; - - Impl impl_; - - GTEST_DISALLOW_ASSIGN_(PolymorphicMatcher); -}; - -// Creates a matcher from its implementation. This is easier to use -// than the Matcher constructor as it doesn't require you to -// explicitly write the template argument, e.g. -// -// MakeMatcher(foo); -// vs -// Matcher(foo); -template -inline Matcher MakeMatcher(const MatcherInterface* impl) { - return Matcher(impl); -}; - -// Creates a polymorphic matcher from its implementation. This is -// easier to use than the PolymorphicMatcher constructor as it -// doesn't require you to explicitly write the template argument, e.g. -// -// MakePolymorphicMatcher(foo); -// vs -// PolymorphicMatcher(foo); -template -inline PolymorphicMatcher MakePolymorphicMatcher(const Impl& impl) { - return PolymorphicMatcher(impl); -} - -// In order to be safe and clear, casting between different matcher -// types is done explicitly via MatcherCast(m), which takes a -// matcher m and returns a Matcher. It compiles only when T can be -// statically converted to the argument type of m. -template -Matcher MatcherCast(M m); - -// Implements SafeMatcherCast(). -// -// We use an intermediate class to do the actual safe casting as Nokia's -// Symbian compiler cannot decide between -// template ... (M) and -// template ... (const Matcher&) -// for function templates but can for member function templates. -template -class SafeMatcherCastImpl { - public: - // This overload handles polymorphic matchers only since monomorphic - // matchers are handled by the next one. - template - static inline Matcher Cast(M polymorphic_matcher) { - return Matcher(polymorphic_matcher); - } - - // This overload handles monomorphic matchers. - // - // In general, if type T can be implicitly converted to type U, we can - // safely convert a Matcher to a Matcher (i.e. Matcher is - // contravariant): just keep a copy of the original Matcher, convert the - // argument from type T to U, and then pass it to the underlying Matcher. - // The only exception is when U is a reference and T is not, as the - // underlying Matcher may be interested in the argument's address, which - // is not preserved in the conversion from T to U. - template - static inline Matcher Cast(const Matcher& matcher) { - // Enforce that T can be implicitly converted to U. - GTEST_COMPILE_ASSERT_((internal::ImplicitlyConvertible::value), - T_must_be_implicitly_convertible_to_U); - // Enforce that we are not converting a non-reference type T to a reference - // type U. - GTEST_COMPILE_ASSERT_( - internal::is_reference::value || !internal::is_reference::value, - cannot_convert_non_referentce_arg_to_reference); - // In case both T and U are arithmetic types, enforce that the - // conversion is not lossy. - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT; - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(U) RawU; - const bool kTIsOther = GMOCK_KIND_OF_(RawT) == internal::kOther; - const bool kUIsOther = GMOCK_KIND_OF_(RawU) == internal::kOther; - GTEST_COMPILE_ASSERT_( - kTIsOther || kUIsOther || - (internal::LosslessArithmeticConvertible::value), - conversion_of_arithmetic_types_must_be_lossless); - return MatcherCast(matcher); - } -}; - -template -inline Matcher SafeMatcherCast(const M& polymorphic_matcher) { - return SafeMatcherCastImpl::Cast(polymorphic_matcher); -} - -// A() returns a matcher that matches any value of type T. -template -Matcher A(); - -// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION -// and MUST NOT BE USED IN USER CODE!!! -namespace internal { - -// If the explanation is not empty, prints it to the ostream. -inline void PrintIfNotEmpty(const internal::string& explanation, - std::ostream* os) { - if (explanation != "" && os != NULL) { - *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 explains -// the match result to the listener. Returns the match result. -// 'listener' must not be NULL. -// Value cannot be passed by const reference, because some matchers take a -// non-const argument. -template -bool MatchPrintAndExplain(Value& value, const Matcher& matcher, - MatchResultListener* listener) { - if (!listener->IsInterested()) { - // If the listener is not interested, we do not need to construct the - // inner explanation. - return matcher.Matches(value); - } - - StringMatchResultListener inner_listener; - const bool match = matcher.MatchAndExplain(value, &inner_listener); - - UniversalPrint(value, listener->stream()); -#if GTEST_HAS_RTTI - const string& type_name = GetTypeName(); - if (IsReadableTypeName(type_name)) - *listener->stream() << " (of type " << type_name << ")"; -#endif - PrintIfNotEmpty(inner_listener.str(), listener->stream()); - - return match; -} - -// An internal helper class for doing compile-time loop on a tuple's -// fields. -template -class TuplePrefix { - public: - // TuplePrefix::Matches(matcher_tuple, value_tuple) returns true - // iff the first N fields of matcher_tuple matches the first N - // fields of value_tuple, respectively. - template - static bool Matches(const MatcherTuple& matcher_tuple, - const ValueTuple& value_tuple) { - using ::std::tr1::get; - return TuplePrefix::Matches(matcher_tuple, value_tuple) - && get(matcher_tuple).Matches(get(value_tuple)); - } - - // TuplePrefix::ExplainMatchFailuresTo(matchers, values, os) - // describes failures in matching the first N fields of matchers - // against the first N fields of values. If there is no failure, - // nothing will be streamed to os. - template - static void ExplainMatchFailuresTo(const MatcherTuple& matchers, - const ValueTuple& values, - ::std::ostream* os) { - using ::std::tr1::tuple_element; - using ::std::tr1::get; - - // First, describes failures in the first N - 1 fields. - TuplePrefix::ExplainMatchFailuresTo(matchers, values, os); - - // Then describes the failure (if any) in the (N - 1)-th (0-based) - // field. - typename tuple_element::type matcher = - get(matchers); - typedef typename tuple_element::type Value; - Value value = get(values); - StringMatchResultListener listener; - if (!matcher.MatchAndExplain(value, &listener)) { - // TODO(wan): include in the message the name of the parameter - // as used in MOCK_METHOD*() when possible. - *os << " Expected arg #" << N - 1 << ": "; - get(matchers).DescribeTo(os); - *os << "\n Actual: "; - // We remove the reference in type Value to prevent the - // universal printer from printing the address of value, which - // isn't interesting to the user most of the time. The - // matcher's MatchAndExplain() method handles the case when - // the address is interesting. - internal::UniversalPrint(value, os); - PrintIfNotEmpty(listener.str(), os); - *os << "\n"; - } - } -}; - -// The base case. -template <> -class TuplePrefix<0> { - public: - template - static bool Matches(const MatcherTuple& /* matcher_tuple */, - const ValueTuple& /* value_tuple */) { - return true; - } - - template - static void ExplainMatchFailuresTo(const MatcherTuple& /* matchers */, - const ValueTuple& /* values */, - ::std::ostream* /* os */) {} -}; - -// TupleMatches(matcher_tuple, value_tuple) returns true iff all -// matchers in matcher_tuple match the corresponding fields in -// value_tuple. It is a compiler error if matcher_tuple and -// value_tuple have different number of fields or incompatible field -// types. -template -bool TupleMatches(const MatcherTuple& matcher_tuple, - const ValueTuple& value_tuple) { - using ::std::tr1::tuple_size; - // Makes sure that matcher_tuple and value_tuple have the same - // number of fields. - GTEST_COMPILE_ASSERT_(tuple_size::value == - tuple_size::value, - matcher_and_value_have_different_numbers_of_fields); - return TuplePrefix::value>:: - Matches(matcher_tuple, value_tuple); -} - -// Describes failures in matching matchers against values. If there -// is no failure, nothing will be streamed to os. -template -void ExplainMatchFailureTupleTo(const MatcherTuple& matchers, - const ValueTuple& values, - ::std::ostream* os) { - using ::std::tr1::tuple_size; - TuplePrefix::value>::ExplainMatchFailuresTo( - matchers, values, os); -} - -// The MatcherCastImpl class template is a helper for implementing -// MatcherCast(). We need this helper in order to partially -// specialize the implementation of MatcherCast() (C++ allows -// class/struct templates to be partially specialized, but not -// function templates.). - -// This general version is used when MatcherCast()'s argument is a -// polymorphic matcher (i.e. something that can be converted to a -// Matcher but is not one yet; for example, Eq(value)). -template -class MatcherCastImpl { - public: - static Matcher Cast(M polymorphic_matcher) { - return Matcher(polymorphic_matcher); - } -}; - -// This more specialized version is used when MatcherCast()'s argument -// is already a Matcher. This only compiles when type T can be -// statically converted to type U. -template -class MatcherCastImpl > { - public: - static Matcher Cast(const Matcher& source_matcher) { - return Matcher(new Impl(source_matcher)); - } - - private: - class Impl : public MatcherInterface { - public: - explicit Impl(const Matcher& source_matcher) - : source_matcher_(source_matcher) {} - - // We delegate the matching logic to the source matcher. - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { - return source_matcher_.MatchAndExplain(static_cast(x), listener); - } - - virtual void DescribeTo(::std::ostream* os) const { - source_matcher_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - source_matcher_.DescribeNegationTo(os); - } - - private: - const Matcher source_matcher_; - - GTEST_DISALLOW_ASSIGN_(Impl); - }; -}; - -// This even more specialized version is used for efficiently casting -// a matcher to its own type. -template -class MatcherCastImpl > { - public: - static Matcher Cast(const Matcher& matcher) { return matcher; } -}; - -// Implements A(). -template -class AnyMatcherImpl : public MatcherInterface { - public: - virtual bool MatchAndExplain( - T /* x */, MatchResultListener* /* listener */) const { return true; } - virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; } - virtual void DescribeNegationTo(::std::ostream* os) const { - // This is mostly for completeness' safe, as it's not very useful - // to write Not(A()). However we cannot completely rule out - // such a possibility, and it doesn't hurt to be prepared. - *os << "never matches"; - } -}; - -// Implements _, a matcher that matches any value of any -// type. This is a polymorphic matcher, so we need a template type -// conversion operator to make it appearing as a Matcher for any -// type T. -class AnythingMatcher { - public: - template - operator Matcher() const { return A(); } -}; - -// Implements a matcher that compares a given value with a -// pre-supplied value using one of the ==, <=, <, etc, operators. The -// two values being compared don't have to have the same type. -// -// The matcher defined here is polymorphic (for example, Eq(5) can be -// used to match an int, a short, a double, etc). Therefore we use -// a template type conversion operator in the implementation. -// -// We define this as a macro in order to eliminate duplicated source -// code. -// -// The following template definition assumes that the Rhs parameter is -// a "bare" type (i.e. neither 'const T' nor 'T&'). -#define GMOCK_IMPLEMENT_COMPARISON_MATCHER_( \ - name, op, relation, negated_relation) \ - template class name##Matcher { \ - public: \ - explicit name##Matcher(const Rhs& rhs) : rhs_(rhs) {} \ - template \ - operator Matcher() const { \ - return MakeMatcher(new Impl(rhs_)); \ - } \ - private: \ - template \ - class Impl : public MatcherInterface { \ - public: \ - explicit Impl(const Rhs& rhs) : rhs_(rhs) {} \ - virtual bool MatchAndExplain(\ - Lhs lhs, MatchResultListener* /* listener */) const { \ - return lhs op rhs_; \ - } \ - virtual void DescribeTo(::std::ostream* os) const { \ - *os << relation " "; \ - UniversalPrint(rhs_, os); \ - } \ - virtual void DescribeNegationTo(::std::ostream* os) const { \ - *os << negated_relation " "; \ - UniversalPrint(rhs_, os); \ - } \ - private: \ - Rhs rhs_; \ - GTEST_DISALLOW_ASSIGN_(Impl); \ - }; \ - Rhs rhs_; \ - GTEST_DISALLOW_ASSIGN_(name##Matcher); \ - } - -// Implements Eq(v), Ge(v), Gt(v), Le(v), Lt(v), and Ne(v) -// respectively. -GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to"); -GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ge, >=, "is >=", "isn't >="); -GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Gt, >, "is >", "isn't >"); -GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Le, <=, "is <=", "isn't <="); -GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Lt, <, "is <", "isn't <"); -GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Ne, !=, "isn't equal to", "is equal to"); - -#undef GMOCK_IMPLEMENT_COMPARISON_MATCHER_ - -// Implements the polymorphic IsNull() matcher, which matches any raw or smart -// pointer that is NULL. -class IsNullMatcher { - public: - template - bool MatchAndExplain(const Pointer& p, - MatchResultListener* /* listener */) const { - return GetRawPointer(p) == NULL; - } - - void DescribeTo(::std::ostream* os) const { *os << "is NULL"; } - void DescribeNegationTo(::std::ostream* os) const { - *os << "isn't NULL"; - } -}; - -// Implements the polymorphic NotNull() matcher, which matches any raw or smart -// pointer that is not NULL. -class NotNullMatcher { - public: - template - bool MatchAndExplain(const Pointer& p, - MatchResultListener* /* listener */) const { - return GetRawPointer(p) != NULL; - } - - void DescribeTo(::std::ostream* os) const { *os << "isn't NULL"; } - void DescribeNegationTo(::std::ostream* os) const { - *os << "is NULL"; - } -}; - -// Ref(variable) matches any argument that is a reference to -// 'variable'. This matcher is polymorphic as it can match any -// super type of the type of 'variable'. -// -// The RefMatcher template class implements Ref(variable). It can -// only be instantiated with a reference type. This prevents a user -// from mistakenly using Ref(x) to match a non-reference function -// argument. For example, the following will righteously cause a -// compiler error: -// -// int n; -// Matcher m1 = Ref(n); // This won't compile. -// Matcher m2 = Ref(n); // This will compile. -template -class RefMatcher; - -template -class RefMatcher { - // Google Mock is a generic framework and thus needs to support - // mocking any function types, including those that take non-const - // reference arguments. Therefore the template parameter T (and - // Super below) can be instantiated to either a const type or a - // non-const type. - public: - // RefMatcher() takes a T& instead of const T&, as we want the - // compiler to catch using Ref(const_value) as a matcher for a - // non-const reference. - explicit RefMatcher(T& x) : object_(x) {} // NOLINT - - template - operator Matcher() const { - // By passing object_ (type T&) to Impl(), which expects a Super&, - // we make sure that Super is a super type of T. In particular, - // this catches using Ref(const_value) as a matcher for a - // non-const reference, as you cannot implicitly convert a const - // reference to a non-const reference. - return MakeMatcher(new Impl(object_)); - } - - private: - template - class Impl : public MatcherInterface { - public: - explicit Impl(Super& x) : object_(x) {} // NOLINT - - // MatchAndExplain() takes a Super& (as opposed to const Super&) - // in order to match the interface MatcherInterface. - virtual bool MatchAndExplain( - Super& x, MatchResultListener* listener) const { - *listener << "which is located @" << static_cast(&x); - return &x == &object_; - } - - virtual void DescribeTo(::std::ostream* os) const { - *os << "references the variable "; - UniversalPrinter::Print(object_, os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "does not reference the variable "; - UniversalPrinter::Print(object_, os); - } - - private: - const Super& object_; - - GTEST_DISALLOW_ASSIGN_(Impl); - }; - - T& object_; - - GTEST_DISALLOW_ASSIGN_(RefMatcher); -}; - -// Polymorphic helper functions for narrow and wide string matchers. -inline bool CaseInsensitiveCStringEquals(const char* lhs, const char* rhs) { - return String::CaseInsensitiveCStringEquals(lhs, rhs); -} - -inline bool CaseInsensitiveCStringEquals(const wchar_t* lhs, - const wchar_t* rhs) { - return String::CaseInsensitiveWideCStringEquals(lhs, rhs); -} - -// String comparison for narrow or wide strings that can have embedded NUL -// characters. -template -bool CaseInsensitiveStringEquals(const StringType& s1, - const StringType& s2) { - // Are the heads equal? - if (!CaseInsensitiveCStringEquals(s1.c_str(), s2.c_str())) { - return false; - } - - // Skip the equal heads. - const typename StringType::value_type nul = 0; - const size_t i1 = s1.find(nul), i2 = s2.find(nul); - - // Are we at the end of either s1 or s2? - if (i1 == StringType::npos || i2 == StringType::npos) { - return i1 == i2; - } - - // Are the tails equal? - return CaseInsensitiveStringEquals(s1.substr(i1 + 1), s2.substr(i2 + 1)); -} - -// String matchers. - -// Implements equality-based string matchers like StrEq, StrCaseNe, and etc. -template -class StrEqualityMatcher { - public: - typedef typename StringType::const_pointer ConstCharPointer; - - StrEqualityMatcher(const StringType& str, bool expect_eq, - bool case_sensitive) - : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {} - - // When expect_eq_ is true, returns true iff s is equal to string_; - // otherwise returns true iff s is not equal to string_. - bool MatchAndExplain(ConstCharPointer s, - MatchResultListener* listener) const { - if (s == NULL) { - return !expect_eq_; - } - return MatchAndExplain(StringType(s), listener); - } - - bool MatchAndExplain(const StringType& s, - MatchResultListener* /* listener */) const { - const bool eq = case_sensitive_ ? s == string_ : - CaseInsensitiveStringEquals(s, string_); - return expect_eq_ == eq; - } - - void DescribeTo(::std::ostream* os) const { - DescribeToHelper(expect_eq_, os); - } - - void DescribeNegationTo(::std::ostream* os) const { - DescribeToHelper(!expect_eq_, os); - } - - private: - void DescribeToHelper(bool expect_eq, ::std::ostream* os) const { - *os << (expect_eq ? "is " : "isn't "); - *os << "equal to "; - if (!case_sensitive_) { - *os << "(ignoring case) "; - } - UniversalPrint(string_, os); - } - - const StringType string_; - const bool expect_eq_; - const bool case_sensitive_; - - GTEST_DISALLOW_ASSIGN_(StrEqualityMatcher); -}; - -// Implements the polymorphic HasSubstr(substring) matcher, which -// can be used as a Matcher as long as T can be converted to a -// string. -template -class HasSubstrMatcher { - public: - typedef typename StringType::const_pointer ConstCharPointer; - - explicit HasSubstrMatcher(const StringType& substring) - : substring_(substring) {} - - // These overloaded methods allow HasSubstr(substring) to be used as a - // Matcher as long as T can be converted to string. Returns true - // iff s contains substring_ as a substring. - bool MatchAndExplain(ConstCharPointer s, - MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(StringType(s), listener); - } - - bool MatchAndExplain(const StringType& s, - MatchResultListener* /* listener */) const { - return s.find(substring_) != StringType::npos; - } - - // Describes what this matcher matches. - void DescribeTo(::std::ostream* os) const { - *os << "has substring "; - UniversalPrint(substring_, os); - } - - void DescribeNegationTo(::std::ostream* os) const { - *os << "has no substring "; - UniversalPrint(substring_, os); - } - - private: - const StringType substring_; - - GTEST_DISALLOW_ASSIGN_(HasSubstrMatcher); -}; - -// Implements the polymorphic StartsWith(substring) matcher, which -// can be used as a Matcher as long as T can be converted to a -// string. -template -class StartsWithMatcher { - public: - typedef typename StringType::const_pointer ConstCharPointer; - - explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) { - } - - // These overloaded methods allow StartsWith(prefix) to be used as a - // Matcher as long as T can be converted to string. Returns true - // iff s starts with prefix_. - bool MatchAndExplain(ConstCharPointer s, - MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(StringType(s), listener); - } - - bool MatchAndExplain(const StringType& s, - MatchResultListener* /* listener */) const { - return s.length() >= prefix_.length() && - s.substr(0, prefix_.length()) == prefix_; - } - - void DescribeTo(::std::ostream* os) const { - *os << "starts with "; - UniversalPrint(prefix_, os); - } - - void DescribeNegationTo(::std::ostream* os) const { - *os << "doesn't start with "; - UniversalPrint(prefix_, os); - } - - private: - const StringType prefix_; - - GTEST_DISALLOW_ASSIGN_(StartsWithMatcher); -}; - -// Implements the polymorphic EndsWith(substring) matcher, which -// can be used as a Matcher as long as T can be converted to a -// string. -template -class EndsWithMatcher { - public: - typedef typename StringType::const_pointer ConstCharPointer; - - explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {} - - // These overloaded methods allow EndsWith(suffix) to be used as a - // Matcher as long as T can be converted to string. Returns true - // iff s ends with suffix_. - bool MatchAndExplain(ConstCharPointer s, - MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(StringType(s), listener); - } - - bool MatchAndExplain(const StringType& s, - MatchResultListener* /* listener */) const { - return s.length() >= suffix_.length() && - s.substr(s.length() - suffix_.length()) == suffix_; - } - - void DescribeTo(::std::ostream* os) const { - *os << "ends with "; - UniversalPrint(suffix_, os); - } - - void DescribeNegationTo(::std::ostream* os) const { - *os << "doesn't end with "; - UniversalPrint(suffix_, os); - } - - private: - const StringType suffix_; - - GTEST_DISALLOW_ASSIGN_(EndsWithMatcher); -}; - -// Implements polymorphic matchers MatchesRegex(regex) and -// ContainsRegex(regex), which can be used as a Matcher as long as -// T can be converted to a string. -class MatchesRegexMatcher { - public: - MatchesRegexMatcher(const RE* regex, bool full_match) - : regex_(regex), full_match_(full_match) {} - - // These overloaded methods allow MatchesRegex(regex) to be used as - // a Matcher as long as T can be converted to string. Returns - // true iff s matches regular expression regex. When full_match_ is - // true, a full match is done; otherwise a partial match is done. - bool MatchAndExplain(const char* s, - MatchResultListener* listener) const { - return s != NULL && MatchAndExplain(internal::string(s), listener); - } - - bool MatchAndExplain(const internal::string& s, - MatchResultListener* /* listener */) const { - return full_match_ ? RE::FullMatch(s, *regex_) : - RE::PartialMatch(s, *regex_); - } - - void DescribeTo(::std::ostream* os) const { - *os << (full_match_ ? "matches" : "contains") - << " regular expression "; - UniversalPrinter::Print(regex_->pattern(), os); - } - - void DescribeNegationTo(::std::ostream* os) const { - *os << "doesn't " << (full_match_ ? "match" : "contain") - << " regular expression "; - UniversalPrinter::Print(regex_->pattern(), os); - } - - private: - const internal::linked_ptr regex_; - const bool full_match_; - - GTEST_DISALLOW_ASSIGN_(MatchesRegexMatcher); -}; - -// Implements a matcher that compares the two fields of a 2-tuple -// using one of the ==, <=, <, etc, operators. The two fields being -// compared don't have to have the same type. -// -// The matcher defined here is polymorphic (for example, Eq() can be -// used to match a tuple, a tuple, -// etc). Therefore we use a template type conversion operator in the -// implementation. -// -// We define this as a macro in order to eliminate duplicated source -// code. -#define GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(name, op, relation) \ - class name##2Matcher { \ - public: \ - template \ - operator Matcher< ::std::tr1::tuple >() const { \ - return MakeMatcher(new Impl< ::std::tr1::tuple >); \ - } \ - template \ - operator Matcher&>() const { \ - return MakeMatcher(new Impl&>); \ - } \ - private: \ - template \ - class Impl : public MatcherInterface { \ - public: \ - virtual bool MatchAndExplain( \ - Tuple args, \ - MatchResultListener* /* listener */) const { \ - return ::std::tr1::get<0>(args) op ::std::tr1::get<1>(args); \ - } \ - virtual void DescribeTo(::std::ostream* os) const { \ - *os << "are " relation; \ - } \ - virtual void DescribeNegationTo(::std::ostream* os) const { \ - *os << "aren't " relation; \ - } \ - }; \ - } - -// Implements Eq(), Ge(), Gt(), Le(), Lt(), and Ne() respectively. -GMOCK_IMPLEMENT_COMPARISON2_MATCHER_(Eq, ==, "an equal pair"); -GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( - Ge, >=, "a pair where the first >= the second"); -GMOCK_IMPLEMENT_COMPARISON2_MATCHER_( - Gt, >, "a pair where the first > the second"); -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_ - -// Implements the Not(...) matcher for a particular argument type T. -// We do not nest it inside the NotMatcher class template, as that -// will prevent different instantiations of NotMatcher from sharing -// the same NotMatcherImpl class. -template -class NotMatcherImpl : public MatcherInterface { - public: - explicit NotMatcherImpl(const Matcher& matcher) - : matcher_(matcher) {} - - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { - return !matcher_.MatchAndExplain(x, listener); - } - - virtual void DescribeTo(::std::ostream* os) const { - matcher_.DescribeNegationTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - matcher_.DescribeTo(os); - } - - private: - const Matcher matcher_; - - GTEST_DISALLOW_ASSIGN_(NotMatcherImpl); -}; - -// Implements the Not(m) matcher, which matches a value that doesn't -// match matcher m. -template -class NotMatcher { - public: - explicit NotMatcher(InnerMatcher matcher) : matcher_(matcher) {} - - // This template type conversion operator allows Not(m) to be used - // to match any type m can match. - template - operator Matcher() const { - return Matcher(new NotMatcherImpl(SafeMatcherCast(matcher_))); - } - - private: - InnerMatcher matcher_; - - GTEST_DISALLOW_ASSIGN_(NotMatcher); -}; - -// Implements the AllOf(m1, m2) matcher for a particular argument type -// T. We do not nest it inside the BothOfMatcher class template, as -// that will prevent different instantiations of BothOfMatcher from -// sharing the same BothOfMatcherImpl class. -template -class BothOfMatcherImpl : public MatcherInterface { - public: - BothOfMatcherImpl(const Matcher& matcher1, const Matcher& matcher2) - : matcher1_(matcher1), matcher2_(matcher2) {} - - virtual void DescribeTo(::std::ostream* os) const { - *os << "("; - matcher1_.DescribeTo(os); - *os << ") and ("; - matcher2_.DescribeTo(os); - *os << ")"; - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "("; - matcher1_.DescribeNegationTo(os); - *os << ") or ("; - matcher2_.DescribeNegationTo(os); - *os << ")"; - } - - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { - // If either matcher1_ or matcher2_ doesn't match x, we only need - // to explain why one of them fails. - StringMatchResultListener listener1; - if (!matcher1_.MatchAndExplain(x, &listener1)) { - *listener << listener1.str(); - return false; - } - - StringMatchResultListener listener2; - if (!matcher2_.MatchAndExplain(x, &listener2)) { - *listener << listener2.str(); - return false; - } - - // Otherwise we need to explain why *both* of them match. - const internal::string s1 = listener1.str(); - const internal::string s2 = listener2.str(); - - if (s1 == "") { - *listener << s2; - } else { - *listener << s1; - if (s2 != "") { - *listener << ", and " << s2; - } - } - return true; - } - - private: - const Matcher matcher1_; - const Matcher matcher2_; - - GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl); -}; - -// Used for implementing the AllOf(m_1, ..., m_n) matcher, which -// matches a value that matches all of the matchers m_1, ..., and m_n. -template -class BothOfMatcher { - public: - BothOfMatcher(Matcher1 matcher1, Matcher2 matcher2) - : matcher1_(matcher1), matcher2_(matcher2) {} - - // This template type conversion operator allows a - // BothOfMatcher object to match any type that - // both Matcher1 and Matcher2 can match. - template - operator Matcher() const { - return Matcher(new BothOfMatcherImpl(SafeMatcherCast(matcher1_), - SafeMatcherCast(matcher2_))); - } - - private: - Matcher1 matcher1_; - Matcher2 matcher2_; - - GTEST_DISALLOW_ASSIGN_(BothOfMatcher); -}; - -// Implements the AnyOf(m1, m2) matcher for a particular argument type -// T. We do not nest it inside the AnyOfMatcher class template, as -// that will prevent different instantiations of AnyOfMatcher from -// sharing the same EitherOfMatcherImpl class. -template -class EitherOfMatcherImpl : public MatcherInterface { - public: - EitherOfMatcherImpl(const Matcher& matcher1, const Matcher& matcher2) - : matcher1_(matcher1), matcher2_(matcher2) {} - - virtual void DescribeTo(::std::ostream* os) const { - *os << "("; - matcher1_.DescribeTo(os); - *os << ") or ("; - matcher2_.DescribeTo(os); - *os << ")"; - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "("; - matcher1_.DescribeNegationTo(os); - *os << ") and ("; - matcher2_.DescribeNegationTo(os); - *os << ")"; - } - - virtual bool MatchAndExplain(T x, MatchResultListener* listener) const { - // If either matcher1_ or matcher2_ matches x, we just need to - // explain why *one* of them matches. - StringMatchResultListener listener1; - if (matcher1_.MatchAndExplain(x, &listener1)) { - *listener << listener1.str(); - return true; - } - - StringMatchResultListener listener2; - if (matcher2_.MatchAndExplain(x, &listener2)) { - *listener << listener2.str(); - return true; - } - - // Otherwise we need to explain why *both* of them fail. - const internal::string s1 = listener1.str(); - const internal::string s2 = listener2.str(); - - if (s1 == "") { - *listener << s2; - } else { - *listener << s1; - if (s2 != "") { - *listener << ", and " << s2; - } - } - return false; - } - - private: - const Matcher matcher1_; - const Matcher matcher2_; - - GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl); -}; - -// Used for implementing the AnyOf(m_1, ..., m_n) matcher, which -// matches a value that matches at least one of the matchers m_1, ..., -// and m_n. -template -class EitherOfMatcher { - public: - EitherOfMatcher(Matcher1 matcher1, Matcher2 matcher2) - : matcher1_(matcher1), matcher2_(matcher2) {} - - // This template type conversion operator allows a - // EitherOfMatcher object to match any type that - // both Matcher1 and Matcher2 can match. - template - operator Matcher() const { - return Matcher(new EitherOfMatcherImpl( - SafeMatcherCast(matcher1_), SafeMatcherCast(matcher2_))); - } - - private: - Matcher1 matcher1_; - Matcher2 matcher2_; - - GTEST_DISALLOW_ASSIGN_(EitherOfMatcher); -}; - -// Used for implementing Truly(pred), which turns a predicate into a -// matcher. -template -class TrulyMatcher { - public: - explicit TrulyMatcher(Predicate pred) : predicate_(pred) {} - - // 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 - // argument is passed by reference as the predicate may be - // interested in the address of the argument. - template - bool MatchAndExplain(T& x, // NOLINT - MatchResultListener* /* listener */) const { - // Without the if-statement, MSVC sometimes warns about converting - // a value to bool (warning 4800). - // - // We cannot write 'return !!predicate_(x);' as that doesn't work - // when predicate_(x) returns a class convertible to bool but - // having no operator!(). - if (predicate_(x)) - return true; - return false; - } - - void DescribeTo(::std::ostream* os) const { - *os << "satisfies the given predicate"; - } - - void DescribeNegationTo(::std::ostream* os) const { - *os << "doesn't satisfy the given predicate"; - } - - private: - Predicate predicate_; - - GTEST_DISALLOW_ASSIGN_(TrulyMatcher); -}; - -// Used for implementing Matches(matcher), which turns a matcher into -// a predicate. -template -class MatcherAsPredicate { - public: - explicit MatcherAsPredicate(M matcher) : matcher_(matcher) {} - - // This template operator() allows Matches(m) to be used as a - // predicate on type T where m is a matcher on type T. - // - // The argument x is passed by reference instead of by value, as - // some matcher may be interested in its address (e.g. as in - // Matches(Ref(n))(x)). - template - bool operator()(const T& x) const { - // We let matcher_ commit to a particular type here instead of - // when the MatcherAsPredicate object was constructed. This - // allows us to write Matches(m) where m is a polymorphic matcher - // (e.g. Eq(5)). - // - // If we write Matcher(matcher_).Matches(x) here, it won't - // compile when matcher_ has type Matcher; if we write - // Matcher(matcher_).Matches(x) here, it won't compile - // when matcher_ has type Matcher; if we just write - // matcher_.Matches(x), it won't compile when matcher_ is - // polymorphic, e.g. Eq(5). - // - // MatcherCast() is necessary for making the code work - // in all of the above situations. - return MatcherCast(matcher_).Matches(x); - } - - private: - M matcher_; - - GTEST_DISALLOW_ASSIGN_(MatcherAsPredicate); -}; - -// For implementing ASSERT_THAT() and EXPECT_THAT(). The template -// argument M must be a type that can be converted to a matcher. -template -class PredicateFormatterFromMatcher { - public: - explicit PredicateFormatterFromMatcher(const M& m) : matcher_(m) {} - - // This template () operator allows a PredicateFormatterFromMatcher - // object to act as a predicate-formatter suitable for using with - // Google Test's EXPECT_PRED_FORMAT1() macro. - template - AssertionResult operator()(const char* value_text, const T& x) const { - // We convert matcher_ to a Matcher *now* instead of - // when the PredicateFormatterFromMatcher object was constructed, - // as matcher_ may be polymorphic (e.g. NotNull()) and we won't - // know which type to instantiate it to until we actually see the - // type of x here. - // - // We write MatcherCast(matcher_) instead of - // Matcher(matcher_), as the latter won't compile when - // matcher_ has type Matcher (e.g. An()). - const Matcher matcher = MatcherCast(matcher_); - StringMatchResultListener listener; - if (MatchPrintAndExplain(x, matcher, &listener)) - return AssertionSuccess(); - - ::std::stringstream ss; - ss << "Value of: " << value_text << "\n" - << "Expected: "; - matcher.DescribeTo(&ss); - ss << "\n Actual: " << listener.str(); - return AssertionFailure() << ss.str(); - } - - private: - const M matcher_; - - GTEST_DISALLOW_ASSIGN_(PredicateFormatterFromMatcher); -}; - -// A helper function for converting a matcher to a predicate-formatter -// without the user needing to explicitly write the type. This is -// used for implementing ASSERT_THAT() and EXPECT_THAT(). -template -inline PredicateFormatterFromMatcher -MakePredicateFormatterFromMatcher(const M& matcher) { - return PredicateFormatterFromMatcher(matcher); -} - -// Implements the polymorphic floating point equality matcher, which -// matches two float values using ULP-based approximation. The -// template is meant to be instantiated with FloatType being either -// float or double. -template -class FloatingEqMatcher { - public: - // Constructor for FloatingEqMatcher. - // The matcher's input will be compared with rhs. The matcher treats two - // NANs as equal if nan_eq_nan is true. Otherwise, under IEEE standards, - // equality comparisons between NANs will always return false. - FloatingEqMatcher(FloatType rhs, bool nan_eq_nan) : - rhs_(rhs), nan_eq_nan_(nan_eq_nan) {} - - // Implements floating point equality matcher as a Matcher. - template - class Impl : public MatcherInterface { - public: - Impl(FloatType rhs, bool nan_eq_nan) : - rhs_(rhs), nan_eq_nan_(nan_eq_nan) {} - - virtual bool MatchAndExplain(T value, - MatchResultListener* /* listener */) const { - const FloatingPoint lhs(value), rhs(rhs_); - - // Compares NaNs first, if nan_eq_nan_ is true. - if (nan_eq_nan_ && lhs.is_nan()) { - return rhs.is_nan(); - } - - return lhs.AlmostEquals(rhs); - } - - virtual void DescribeTo(::std::ostream* os) const { - // os->precision() returns the previously set precision, which we - // store to restore the ostream to its original configuration - // after outputting. - const ::std::streamsize old_precision = os->precision( - ::std::numeric_limits::digits10 + 2); - if (FloatingPoint(rhs_).is_nan()) { - if (nan_eq_nan_) { - *os << "is NaN"; - } else { - *os << "never matches"; - } - } else { - *os << "is approximately " << rhs_; - } - os->precision(old_precision); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - // As before, get original precision. - const ::std::streamsize old_precision = os->precision( - ::std::numeric_limits::digits10 + 2); - if (FloatingPoint(rhs_).is_nan()) { - if (nan_eq_nan_) { - *os << "isn't NaN"; - } else { - *os << "is anything"; - } - } else { - *os << "isn't approximately " << rhs_; - } - // Restore original precision. - os->precision(old_precision); - } - - private: - const FloatType rhs_; - const bool nan_eq_nan_; - - GTEST_DISALLOW_ASSIGN_(Impl); - }; - - // The following 3 type conversion operators allow FloatEq(rhs) and - // NanSensitiveFloatEq(rhs) to be used as a Matcher, a - // Matcher, or a Matcher, but nothing else. - // (While Google's C++ coding style doesn't allow arguments passed - // by non-const reference, we may see them in code not conforming to - // the style. Therefore Google Mock needs to support them.) - operator Matcher() const { - return MakeMatcher(new Impl(rhs_, nan_eq_nan_)); - } - - operator Matcher() const { - return MakeMatcher(new Impl(rhs_, nan_eq_nan_)); - } - - operator Matcher() const { - return MakeMatcher(new Impl(rhs_, nan_eq_nan_)); - } - private: - const FloatType rhs_; - const bool nan_eq_nan_; - - GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher); -}; - -// Implements the Pointee(m) matcher for matching a pointer whose -// pointee matches matcher m. The pointer can be either raw or smart. -template -class PointeeMatcher { - public: - explicit PointeeMatcher(const InnerMatcher& matcher) : matcher_(matcher) {} - - // This type conversion operator template allows Pointee(m) to be - // used as a matcher for any pointer type whose pointee type is - // compatible with the inner matcher, where type Pointer can be - // either a raw pointer or a smart pointer. - // - // The reason we do this instead of relying on - // MakePolymorphicMatcher() is that the latter is not flexible - // enough for implementing the DescribeTo() method of Pointee(). - template - operator Matcher() const { - return MakeMatcher(new Impl(matcher_)); - } - - private: - // The monomorphic implementation that works for a particular pointer type. - template - class Impl : public MatcherInterface { - public: - typedef typename PointeeOf::type Pointee; - - explicit Impl(const InnerMatcher& matcher) - : matcher_(MatcherCast(matcher)) {} - - virtual void DescribeTo(::std::ostream* os) const { - *os << "points to a value that "; - matcher_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "does not point to a value that "; - matcher_.DescribeTo(os); - } - - virtual bool MatchAndExplain(Pointer pointer, - MatchResultListener* listener) const { - if (GetRawPointer(pointer) == NULL) - return false; - - *listener << "which points to "; - return MatchPrintAndExplain(*pointer, matcher_, listener); - } - - private: - const Matcher matcher_; - - GTEST_DISALLOW_ASSIGN_(Impl); - }; - - const InnerMatcher matcher_; - - GTEST_DISALLOW_ASSIGN_(PointeeMatcher); -}; - -// Implements the Field() matcher for matching a field (i.e. member -// variable) of an object. -template -class FieldMatcher { - public: - FieldMatcher(FieldType Class::*field, - const Matcher& matcher) - : field_(field), matcher_(matcher) {} - - void DescribeTo(::std::ostream* os) const { - *os << "is an object whose given field "; - matcher_.DescribeTo(os); - } - - void DescribeNegationTo(::std::ostream* os) const { - *os << "is an object whose given field "; - matcher_.DescribeNegationTo(os); - } - - template - bool MatchAndExplain(const T& value, MatchResultListener* listener) const { - return MatchAndExplainImpl( - typename ::testing::internal:: - is_pointer::type(), - value, listener); - } - - private: - // The first argument of MatchAndExplainImpl() is needed to help - // Symbian's C++ compiler choose which overload to use. Its type is - // true_type iff the Field() matcher is used to match a pointer. - bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, - MatchResultListener* listener) const { - *listener << "whose given field is "; - return MatchPrintAndExplain(obj.*field_, matcher_, listener); - } - - bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, - MatchResultListener* listener) const { - if (p == NULL) - return false; - - *listener << "which points to an object "; - // Since *p has a field, it must be a class/struct/union type and - // thus cannot be a pointer. Therefore we pass false_type() as - // the first argument. - return MatchAndExplainImpl(false_type(), *p, listener); - } - - const FieldType Class::*field_; - const Matcher matcher_; - - GTEST_DISALLOW_ASSIGN_(FieldMatcher); -}; - -// Implements the Property() matcher for matching a property -// (i.e. return value of a getter method) of an object. -template -class PropertyMatcher { - public: - // The property may have a reference type, so 'const PropertyType&' - // may cause double references and fail to compile. That's why we - // need GTEST_REFERENCE_TO_CONST, which works regardless of - // PropertyType being a reference or not. - typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty; - - PropertyMatcher(PropertyType (Class::*property)() const, - const Matcher& matcher) - : property_(property), matcher_(matcher) {} - - void DescribeTo(::std::ostream* os) const { - *os << "is an object whose given property "; - matcher_.DescribeTo(os); - } - - void DescribeNegationTo(::std::ostream* os) const { - *os << "is an object whose given property "; - matcher_.DescribeNegationTo(os); - } - - template - bool MatchAndExplain(const T&value, MatchResultListener* listener) const { - return MatchAndExplainImpl( - typename ::testing::internal:: - is_pointer::type(), - value, listener); - } - - private: - // The first argument of MatchAndExplainImpl() is needed to help - // Symbian's C++ compiler choose which overload to use. Its type is - // true_type iff the Property() matcher is used to match a pointer. - bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj, - MatchResultListener* listener) const { - *listener << "whose given property is "; - // Cannot pass the return value (for example, int) to MatchPrintAndExplain, - // which takes a non-const reference as argument. - RefToConstProperty result = (obj.*property_)(); - return MatchPrintAndExplain(result, matcher_, listener); - } - - bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p, - MatchResultListener* listener) const { - if (p == NULL) - return false; - - *listener << "which points to an object "; - // Since *p has a property method, it must be a class/struct/union - // type and thus cannot be a pointer. Therefore we pass - // false_type() as the first argument. - return MatchAndExplainImpl(false_type(), *p, listener); - } - - PropertyType (Class::*property_)() const; - const Matcher matcher_; - - GTEST_DISALLOW_ASSIGN_(PropertyMatcher); -}; - -// Type traits specifying various features of different functors for ResultOf. -// The default template specifies features for functor objects. -// Functor classes have to typedef argument_type and result_type -// to be compatible with ResultOf. -template -struct CallableTraits { - typedef typename Functor::result_type ResultType; - typedef Functor StorageType; - - static void CheckIsValid(Functor /* functor */) {} - template - static ResultType Invoke(Functor f, T arg) { return f(arg); } -}; - -// Specialization for function pointers. -template -struct CallableTraits { - typedef ResType ResultType; - typedef ResType(*StorageType)(ArgType); - - static void CheckIsValid(ResType(*f)(ArgType)) { - GTEST_CHECK_(f != NULL) - << "NULL function pointer is passed into ResultOf()."; - } - template - static ResType Invoke(ResType(*f)(ArgType), T arg) { - return (*f)(arg); - } -}; - -// Implements the ResultOf() matcher for matching a return value of a -// unary function of an object. -template -class ResultOfMatcher { - public: - typedef typename CallableTraits::ResultType ResultType; - - ResultOfMatcher(Callable callable, const Matcher& matcher) - : callable_(callable), matcher_(matcher) { - CallableTraits::CheckIsValid(callable_); - } - - template - operator Matcher() const { - return Matcher(new Impl(callable_, matcher_)); - } - - private: - typedef typename CallableTraits::StorageType CallableStorageType; - - template - class Impl : public MatcherInterface { - public: - Impl(CallableStorageType callable, const Matcher& matcher) - : callable_(callable), matcher_(matcher) {} - - virtual void DescribeTo(::std::ostream* os) const { - *os << "is mapped by the given callable to a value that "; - matcher_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "is mapped by the given callable to a value that "; - matcher_.DescribeNegationTo(os); - } - - virtual bool MatchAndExplain(T obj, MatchResultListener* listener) const { - *listener << "which is mapped by the given callable to "; - // Cannot pass the return value (for example, int) to - // MatchPrintAndExplain, which takes a non-const reference as argument. - ResultType result = - CallableTraits::template Invoke(callable_, obj); - return MatchPrintAndExplain(result, matcher_, listener); - } - - private: - // Functors often define operator() as non-const method even though - // they are actualy stateless. But we need to use them even when - // 'this' is a const pointer. It's the user's responsibility not to - // use stateful callables with ResultOf(), which does't guarantee - // how many times the callable will be invoked. - mutable CallableStorageType callable_; - const Matcher matcher_; - - GTEST_DISALLOW_ASSIGN_(Impl); - }; // class Impl - - const CallableStorageType callable_; - const Matcher matcher_; - - GTEST_DISALLOW_ASSIGN_(ResultOfMatcher); -}; - -// Implements an equality matcher for any STL-style container whose elements -// support ==. This matcher is like Eq(), but its failure explanations provide -// more detailed information that is useful when the container is used as a set. -// The failure message reports elements that are in one of the operands but not -// the other. The failure messages do not report duplicate or out-of-order -// elements in the containers (which don't properly matter to sets, but can -// occur if the containers are vectors or lists, for example). -// -// Uses the container's const_iterator, value_type, operator ==, -// begin(), and end(). -template -class ContainerEqMatcher { - public: - typedef internal::StlContainerView View; - typedef typename View::type StlContainer; - typedef typename View::const_reference StlContainerReference; - - // We make a copy of rhs in case the elements in it are modified - // after this matcher is created. - explicit ContainerEqMatcher(const Container& rhs) : rhs_(View::Copy(rhs)) { - // Makes sure the user doesn't instantiate this class template - // with a const or reference type. - (void)testing::StaticAssertTypeEq(); - } - - void DescribeTo(::std::ostream* os) const { - *os << "equals "; - UniversalPrint(rhs_, os); - } - void DescribeNegationTo(::std::ostream* os) const { - *os << "does not equal "; - UniversalPrint(rhs_, os); - } - - template - bool MatchAndExplain(const LhsContainer& lhs, - MatchResultListener* listener) const { - // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug - // that causes LhsContainer to be a const type sometimes. - typedef internal::StlContainerView - LhsView; - typedef typename LhsView::type LhsStlContainer; - StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); - if (lhs_stl_container == rhs_) - return true; - - ::std::ostream* const os = listener->stream(); - if (os != NULL) { - // Something is different. Check for extra values first. - bool printed_header = false; - for (typename LhsStlContainer::const_iterator it = - lhs_stl_container.begin(); - it != lhs_stl_container.end(); ++it) { - if (internal::ArrayAwareFind(rhs_.begin(), rhs_.end(), *it) == - rhs_.end()) { - if (printed_header) { - *os << ", "; - } else { - *os << "which has these unexpected elements: "; - printed_header = true; - } - UniversalPrint(*it, os); - } - } - - // Now check for missing values. - bool printed_header2 = false; - for (typename StlContainer::const_iterator it = rhs_.begin(); - it != rhs_.end(); ++it) { - if (internal::ArrayAwareFind( - lhs_stl_container.begin(), lhs_stl_container.end(), *it) == - lhs_stl_container.end()) { - if (printed_header2) { - *os << ", "; - } else { - *os << (printed_header ? ",\nand" : "which") - << " doesn't have these expected elements: "; - printed_header2 = true; - } - UniversalPrint(*it, os); - } - } - } - - return false; - } - - private: - const StlContainer rhs_; - - GTEST_DISALLOW_ASSIGN_(ContainerEqMatcher); -}; - -// Implements Pointwise(tuple_matcher, rhs_container). tuple_matcher -// must be able to be safely cast to Matcher >, where T1 and T2 are the types of elements in the LHS -// container and the RHS container respectively. -template -class PointwiseMatcher { - public: - typedef internal::StlContainerView 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& rhs) - : 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(); - } - - template - operator Matcher() const { - return MakeMatcher(new Impl(tuple_matcher_, rhs_)); - } - - template - class Impl : public MatcherInterface { - 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 InnerMatcherArg; - - Impl(const TupleMatcher& tuple_matcher, const RhsStlContainer& rhs) - // mono_tuple_matcher_ holds a monomorphic version of the tuple matcher. - : mono_tuple_matcher_(SafeMatcherCast(tuple_matcher)), - rhs_(rhs) {} - - virtual void DescribeTo(::std::ostream* os) const { - *os << "contains " << rhs_.size() - << " values, where each value and its corresponding value in "; - UniversalPrinter::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.begin(); - 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 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 -class QuantifierMatcherImpl : public MatcherInterface { - public: - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef StlContainerView View; - typedef typename View::type StlContainer; - typedef typename View::const_reference StlContainerReference; - typedef typename StlContainer::value_type Element; - - template - explicit QuantifierMatcherImpl(InnerMatcher inner_matcher) - : inner_matcher_( - testing::SafeMatcherCast(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_listener); - - 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 inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(QuantifierMatcherImpl); -}; - -// Implements Contains(element_matcher) for the given argument type Container. -// Symmetric to EachMatcherImpl. -template -class ContainsMatcherImpl : public QuantifierMatcherImpl { - public: - template - explicit ContainsMatcherImpl(InnerMatcher inner_matcher) - : QuantifierMatcherImpl(inner_matcher) {} - - // Describes what this matcher does. - virtual void DescribeTo(::std::ostream* os) const { - *os << "contains at least one element that "; - this->inner_matcher_.DescribeTo(os); - } - - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "doesn't contain any element that "; - this->inner_matcher_.DescribeTo(os); - } - - virtual bool MatchAndExplain(Container container, - MatchResultListener* listener) const { - return this->MatchAndExplainImpl(false, container, listener); - } - - private: - GTEST_DISALLOW_ASSIGN_(ContainsMatcherImpl); -}; - -// Implements Each(element_matcher) for the given argument type Container. -// Symmetric to ContainsMatcherImpl. -template -class EachMatcherImpl : public QuantifierMatcherImpl { - public: - template - explicit EachMatcherImpl(InnerMatcher inner_matcher) - : QuantifierMatcherImpl(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). -template -class ContainsMatcher { - public: - explicit ContainsMatcher(M m) : inner_matcher_(m) {} - - template - operator Matcher() const { - return MakeMatcher(new ContainsMatcherImpl(inner_matcher_)); - } - - private: - const M inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(ContainsMatcher); -}; - -// Implements polymorphic Each(element_matcher). -template -class EachMatcher { - public: - explicit EachMatcher(M m) : inner_matcher_(m) {} - - template - operator Matcher() const { - return MakeMatcher(new EachMatcherImpl(inner_matcher_)); - } - - private: - const M inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(EachMatcher); -}; - -// Implements Key(inner_matcher) for the given argument pair type. -// Key(inner_matcher) matches an std::pair whose 'first' field matches -// inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an -// std::map that contains at least one element whose key is >= 5. -template -class KeyMatcherImpl : public MatcherInterface { - public: - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType; - typedef typename RawPairType::first_type KeyType; - - template - explicit KeyMatcherImpl(InnerMatcher inner_matcher) - : inner_matcher_( - testing::SafeMatcherCast(inner_matcher)) { - } - - // Returns true iff 'key_value.first' (the key) matches the inner matcher. - virtual bool MatchAndExplain(PairType key_value, - MatchResultListener* listener) const { - StringMatchResultListener inner_listener; - const bool match = inner_matcher_.MatchAndExplain(key_value.first, - &inner_listener); - const internal::string explanation = inner_listener.str(); - if (explanation != "") { - *listener << "whose first field is a value " << explanation; - } - return match; - } - - // Describes what this matcher does. - virtual void DescribeTo(::std::ostream* os) const { - *os << "has a key that "; - inner_matcher_.DescribeTo(os); - } - - // Describes what the negation of this matcher does. - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "doesn't have a key that "; - inner_matcher_.DescribeTo(os); - } - - private: - const Matcher inner_matcher_; - - GTEST_DISALLOW_ASSIGN_(KeyMatcherImpl); -}; - -// Implements polymorphic Key(matcher_for_key). -template -class KeyMatcher { - public: - explicit KeyMatcher(M m) : matcher_for_key_(m) {} - - template - operator Matcher() const { - return MakeMatcher(new KeyMatcherImpl(matcher_for_key_)); - } - - private: - const M matcher_for_key_; - - GTEST_DISALLOW_ASSIGN_(KeyMatcher); -}; - -// Implements Pair(first_matcher, second_matcher) for the given argument pair -// type with its two matchers. See Pair() function below. -template -class PairMatcherImpl : public MatcherInterface { - public: - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(PairType) RawPairType; - typedef typename RawPairType::first_type FirstType; - typedef typename RawPairType::second_type SecondType; - - template - PairMatcherImpl(FirstMatcher first_matcher, SecondMatcher second_matcher) - : first_matcher_( - testing::SafeMatcherCast(first_matcher)), - second_matcher_( - testing::SafeMatcherCast(second_matcher)) { - } - - // Describes what this matcher does. - virtual void DescribeTo(::std::ostream* os) const { - *os << "has a first field that "; - first_matcher_.DescribeTo(os); - *os << ", and has a second field that "; - second_matcher_.DescribeTo(os); - } - - // Describes what the negation of this matcher does. - virtual void DescribeNegationTo(::std::ostream* os) const { - *os << "has a first field that "; - first_matcher_.DescribeNegationTo(os); - *os << ", or has a second field that "; - second_matcher_.DescribeNegationTo(os); - } - - // Returns true iff 'a_pair.first' matches first_matcher and 'a_pair.second' - // matches second_matcher. - virtual bool MatchAndExplain(PairType a_pair, - MatchResultListener* listener) const { - if (!listener->IsInterested()) { - // If the listener is not interested, we don't need to construct the - // explanation. - return first_matcher_.Matches(a_pair.first) && - second_matcher_.Matches(a_pair.second); - } - StringMatchResultListener first_inner_listener; - if (!first_matcher_.MatchAndExplain(a_pair.first, - &first_inner_listener)) { - *listener << "whose first field does not match"; - PrintIfNotEmpty(first_inner_listener.str(), listener->stream()); - return false; - } - StringMatchResultListener second_inner_listener; - if (!second_matcher_.MatchAndExplain(a_pair.second, - &second_inner_listener)) { - *listener << "whose second field does not match"; - PrintIfNotEmpty(second_inner_listener.str(), listener->stream()); - return false; - } - ExplainSuccess(first_inner_listener.str(), second_inner_listener.str(), - listener); - return true; - } - - private: - void ExplainSuccess(const internal::string& first_explanation, - const internal::string& second_explanation, - MatchResultListener* listener) const { - *listener << "whose both fields match"; - if (first_explanation != "") { - *listener << ", where the first field is a value " << first_explanation; - } - if (second_explanation != "") { - *listener << ", "; - if (first_explanation != "") { - *listener << "and "; - } else { - *listener << "where "; - } - *listener << "the second field is a value " << second_explanation; - } - } - - const Matcher first_matcher_; - const Matcher second_matcher_; - - GTEST_DISALLOW_ASSIGN_(PairMatcherImpl); -}; - -// Implements polymorphic Pair(first_matcher, second_matcher). -template -class PairMatcher { - public: - PairMatcher(FirstMatcher first_matcher, SecondMatcher second_matcher) - : first_matcher_(first_matcher), second_matcher_(second_matcher) {} - - template - operator Matcher () const { - return MakeMatcher( - new PairMatcherImpl( - first_matcher_, second_matcher_)); - } - - private: - const FirstMatcher first_matcher_; - const SecondMatcher second_matcher_; - - GTEST_DISALLOW_ASSIGN_(PairMatcher); -}; - -// Implements ElementsAre() and ElementsAreArray(). -template -class ElementsAreMatcherImpl : public MatcherInterface { - public: - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef internal::StlContainerView View; - typedef typename View::type StlContainer; - typedef typename View::const_reference StlContainerReference; - typedef typename StlContainer::value_type Element; - - // Constructs the matcher from a sequence of element values or - // element matchers. - template - ElementsAreMatcherImpl(InputIter first, size_t a_count) { - matchers_.reserve(a_count); - InputIter it = first; - for (size_t i = 0; i != a_count; ++i, ++it) { - matchers_.push_back(MatcherCast(*it)); - } - } - - // Describes what this matcher does. - virtual void DescribeTo(::std::ostream* os) const { - if (count() == 0) { - *os << "is empty"; - } else if (count() == 1) { - *os << "has 1 element that "; - matchers_[0].DescribeTo(os); - } else { - *os << "has " << Elements(count()) << " where\n"; - for (size_t i = 0; i != count(); ++i) { - *os << "element #" << i << " "; - matchers_[i].DescribeTo(os); - if (i + 1 < count()) { - *os << ",\n"; - } - } - } - } - - // Describes what the negation of this matcher does. - virtual void DescribeNegationTo(::std::ostream* os) const { - if (count() == 0) { - *os << "isn't empty"; - return; - } - - *os << "doesn't have " << Elements(count()) << ", or\n"; - for (size_t i = 0; i != count(); ++i) { - *os << "element #" << i << " "; - matchers_[i].DescribeNegationTo(os); - if (i + 1 < count()) { - *os << ", or\n"; - } - } - } - - virtual bool MatchAndExplain(Container container, - MatchResultListener* listener) const { - StlContainerReference stl_container = View::ConstReference(container); - const size_t actual_count = stl_container.size(); - if (actual_count != count()) { - // The element count doesn't match. If the container is empty, - // there's no need to explain anything as Google Mock already - // prints the empty container. Otherwise we just need to show - // how many elements there actually are. - if (actual_count != 0) { - *listener << "which has " << Elements(actual_count); - } - return false; - } - - typename StlContainer::const_iterator it = stl_container.begin(); - // explanations[i] is the explanation of the element at index i. - std::vector explanations(count()); - for (size_t i = 0; i != count(); ++it, ++i) { - StringMatchResultListener s; - if (matchers_[i].MatchAndExplain(*it, &s)) { - explanations[i] = s.str(); - } else { - // The container has the right size but the i-th element - // doesn't match its expectation. - *listener << "whose element #" << i << " doesn't match"; - PrintIfNotEmpty(s.str(), listener->stream()); - return false; - } - } - - // Every element matches its expectation. We need to explain why - // (the obvious ones can be skipped). - bool reason_printed = false; - for (size_t i = 0; i != count(); ++i) { - const internal::string& s = explanations[i]; - if (!s.empty()) { - if (reason_printed) { - *listener << ",\nand "; - } - *listener << "whose element #" << i << " matches, " << s; - reason_printed = true; - } - } - - return true; - } - - private: - static Message Elements(size_t count) { - return Message() << count << (count == 1 ? " element" : " elements"); - } - - size_t count() const { return matchers_.size(); } - std::vector > matchers_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreMatcherImpl); -}; - -// Implements ElementsAre() of 0 arguments. -class ElementsAreMatcher0 { - public: - ElementsAreMatcher0() {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - const Matcher* const matchers = NULL; - return MakeMatcher(new ElementsAreMatcherImpl(matchers, 0)); - } -}; - -// Implements ElementsAreArray(). -template -class ElementsAreArrayMatcher { - public: - ElementsAreArrayMatcher(const T* first, size_t count) : - first_(first), count_(count) {} - - template - operator Matcher() const { - typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer; - typedef typename internal::StlContainerView::type::value_type - Element; - - return MakeMatcher(new ElementsAreMatcherImpl(first_, count_)); - } - - private: - const T* const first_; - const size_t count_; - - GTEST_DISALLOW_ASSIGN_(ElementsAreArrayMatcher); -}; - -// Returns the description for a matcher defined using the MATCHER*() -// macro where the user-supplied description string is "", if -// 'negation' is false; otherwise returns the description of the -// negation of the matcher. 'param_values' contains a list of strings -// that are the print-out of the matcher's parameters. -string FormatMatcherDescription(bool negation, const char* matcher_name, - const Strings& param_values); - -} // namespace internal - -// Implements MatcherCast(). -template -inline Matcher MatcherCast(M matcher) { - return internal::MatcherCastImpl::Cast(matcher); -} - -// _ is a matcher that matches anything of any type. -// -// This definition is fine as: -// -// 1. The C++ standard permits using the name _ in a namespace that -// is not the global namespace or ::std. -// 2. The AnythingMatcher class has no data member or constructor, -// so it's OK to create global variables of this type. -// 3. c-style has approved of using _ in this case. -const internal::AnythingMatcher _ = {}; -// Creates a matcher that matches any value of the given type T. -template -inline Matcher A() { return MakeMatcher(new internal::AnyMatcherImpl()); } - -// Creates a matcher that matches any value of the given type T. -template -inline Matcher An() { return A(); } - -// Creates a polymorphic matcher that matches anything equal to x. -// Note: if the parameter of Eq() were declared as const T&, Eq("foo") -// wouldn't compile. -template -inline internal::EqMatcher Eq(T x) { return internal::EqMatcher(x); } - -// Constructs a Matcher from a 'value' of type T. The constructed -// matcher matches any value that's equal to 'value'. -template -Matcher::Matcher(T value) { *this = Eq(value); } - -// Creates a monomorphic matcher that matches anything with type Lhs -// and equal to rhs. A user may need to use this instead of Eq(...) -// in order to resolve an overloading ambiguity. -// -// TypedEq(x) is just a convenient short-hand for Matcher(Eq(x)) -// or Matcher(x), but more readable than the latter. -// -// We could define similar monomorphic matchers for other comparison -// operations (e.g. TypedLt, TypedGe, and etc), but decided not to do -// it yet as those are used much less than Eq() in practice. A user -// can always write Matcher(Lt(5)) to be explicit about the type, -// for example. -template -inline Matcher TypedEq(const Rhs& rhs) { return Eq(rhs); } - -// Creates a polymorphic matcher that matches anything >= x. -template -inline internal::GeMatcher Ge(Rhs x) { - return internal::GeMatcher(x); -} - -// Creates a polymorphic matcher that matches anything > x. -template -inline internal::GtMatcher Gt(Rhs x) { - return internal::GtMatcher(x); -} - -// Creates a polymorphic matcher that matches anything <= x. -template -inline internal::LeMatcher Le(Rhs x) { - return internal::LeMatcher(x); -} - -// Creates a polymorphic matcher that matches anything < x. -template -inline internal::LtMatcher Lt(Rhs x) { - return internal::LtMatcher(x); -} - -// Creates a polymorphic matcher that matches anything != x. -template -inline internal::NeMatcher Ne(Rhs x) { - return internal::NeMatcher(x); -} - -// Creates a polymorphic matcher that matches any NULL pointer. -inline PolymorphicMatcher IsNull() { - return MakePolymorphicMatcher(internal::IsNullMatcher()); -} - -// Creates a polymorphic matcher that matches any non-NULL pointer. -// This is convenient as Not(NULL) doesn't compile (the compiler -// thinks that that expression is comparing a pointer with an integer). -inline PolymorphicMatcher NotNull() { - return MakePolymorphicMatcher(internal::NotNullMatcher()); -} - -// Creates a polymorphic matcher that matches any argument that -// references variable x. -template -inline internal::RefMatcher Ref(T& x) { // NOLINT - return internal::RefMatcher(x); -} - -// Creates a matcher that matches any double argument approximately -// equal to rhs, where two NANs are considered unequal. -inline internal::FloatingEqMatcher DoubleEq(double rhs) { - return internal::FloatingEqMatcher(rhs, false); -} - -// Creates a matcher that matches any double argument approximately -// equal to rhs, including NaN values when rhs is NaN. -inline internal::FloatingEqMatcher NanSensitiveDoubleEq(double rhs) { - return internal::FloatingEqMatcher(rhs, true); -} - -// Creates a matcher that matches any float argument approximately -// equal to rhs, where two NANs are considered unequal. -inline internal::FloatingEqMatcher FloatEq(float rhs) { - return internal::FloatingEqMatcher(rhs, false); -} - -// Creates a matcher that matches any double argument approximately -// equal to rhs, including NaN values when rhs is NaN. -inline internal::FloatingEqMatcher NanSensitiveFloatEq(float rhs) { - return internal::FloatingEqMatcher(rhs, true); -} - -// Creates a matcher that matches a pointer (raw or smart) that points -// to a value that matches inner_matcher. -template -inline internal::PointeeMatcher Pointee( - const InnerMatcher& inner_matcher) { - return internal::PointeeMatcher(inner_matcher); -} - -// Creates a matcher that matches an object whose given field matches -// 'matcher'. For example, -// Field(&Foo::number, Ge(5)) -// matches a Foo object x iff x.number >= 5. -template -inline PolymorphicMatcher< - internal::FieldMatcher > Field( - FieldType Class::*field, const FieldMatcher& matcher) { - return MakePolymorphicMatcher( - internal::FieldMatcher( - field, MatcherCast(matcher))); - // The call to MatcherCast() is required for supporting inner - // matchers of compatible types. For example, it allows - // Field(&Foo::bar, m) - // to compile where bar is an int32 and m is a matcher for int64. -} - -// Creates a matcher that matches an object whose given property -// matches 'matcher'. For example, -// Property(&Foo::str, StartsWith("hi")) -// matches a Foo object x iff x.str() starts with "hi". -template -inline PolymorphicMatcher< - internal::PropertyMatcher > Property( - PropertyType (Class::*property)() const, const PropertyMatcher& matcher) { - return MakePolymorphicMatcher( - internal::PropertyMatcher( - property, - MatcherCast(matcher))); - // The call to MatcherCast() is required for supporting inner - // matchers of compatible types. For example, it allows - // Property(&Foo::bar, m) - // 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 -// a callable to x matches 'matcher'. -// For example, -// ResultOf(f, StartsWith("hi")) -// matches a Foo object x iff f(x) starts with "hi". -// callable parameter can be a function, function pointer, or a functor. -// Callable has to satisfy the following conditions: -// * It is required to keep no state affecting the results of -// the calls on it and make no assumptions about how many calls -// will be made. Any state it keeps must be protected from the -// concurrent access. -// * If it is a function object, it has to define type result_type. -// We recommend deriving your functor classes from std::unary_function. -template -internal::ResultOfMatcher ResultOf( - Callable callable, const ResultOfMatcher& matcher) { - return internal::ResultOfMatcher( - callable, - MatcherCast::ResultType>( - matcher)); - // The call to MatcherCast() is required for supporting inner - // matchers of compatible types. For example, it allows - // ResultOf(Function, m) - // to compile where Function() returns an int32 and m is a matcher for int64. -} - -// String matchers. - -// Matches a string equal to str. -inline PolymorphicMatcher > - StrEq(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, true, true)); -} - -// Matches a string not equal to str. -inline PolymorphicMatcher > - StrNe(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, false, true)); -} - -// Matches a string equal to str, ignoring case. -inline PolymorphicMatcher > - StrCaseEq(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, true, false)); -} - -// Matches a string not equal to str, ignoring case. -inline PolymorphicMatcher > - StrCaseNe(const internal::string& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, false, false)); -} - -// Creates a matcher that matches any string, std::string, or C string -// that contains the given substring. -inline PolymorphicMatcher > - HasSubstr(const internal::string& substring) { - return MakePolymorphicMatcher(internal::HasSubstrMatcher( - substring)); -} - -// Matches a string that starts with 'prefix' (case-sensitive). -inline PolymorphicMatcher > - StartsWith(const internal::string& prefix) { - return MakePolymorphicMatcher(internal::StartsWithMatcher( - prefix)); -} - -// Matches a string that ends with 'suffix' (case-sensitive). -inline PolymorphicMatcher > - EndsWith(const internal::string& suffix) { - return MakePolymorphicMatcher(internal::EndsWithMatcher( - suffix)); -} - -// Matches a string that fully matches regular expression 'regex'. -// The matcher takes ownership of 'regex'. -inline PolymorphicMatcher MatchesRegex( - const internal::RE* regex) { - return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true)); -} -inline PolymorphicMatcher MatchesRegex( - const internal::string& regex) { - return MatchesRegex(new internal::RE(regex)); -} - -// Matches a string that contains regular expression 'regex'. -// The matcher takes ownership of 'regex'. -inline PolymorphicMatcher ContainsRegex( - const internal::RE* regex) { - return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false)); -} -inline PolymorphicMatcher ContainsRegex( - const internal::string& regex) { - return ContainsRegex(new internal::RE(regex)); -} - -#if GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING -// Wide string matchers. - -// Matches a string equal to str. -inline PolymorphicMatcher > - StrEq(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, true, true)); -} - -// Matches a string not equal to str. -inline PolymorphicMatcher > - StrNe(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, false, true)); -} - -// Matches a string equal to str, ignoring case. -inline PolymorphicMatcher > - StrCaseEq(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, true, false)); -} - -// Matches a string not equal to str, ignoring case. -inline PolymorphicMatcher > - StrCaseNe(const internal::wstring& str) { - return MakePolymorphicMatcher(internal::StrEqualityMatcher( - str, false, false)); -} - -// Creates a matcher that matches any wstring, std::wstring, or C wide string -// that contains the given substring. -inline PolymorphicMatcher > - HasSubstr(const internal::wstring& substring) { - return MakePolymorphicMatcher(internal::HasSubstrMatcher( - substring)); -} - -// Matches a string that starts with 'prefix' (case-sensitive). -inline PolymorphicMatcher > - StartsWith(const internal::wstring& prefix) { - return MakePolymorphicMatcher(internal::StartsWithMatcher( - prefix)); -} - -// Matches a string that ends with 'suffix' (case-sensitive). -inline PolymorphicMatcher > - EndsWith(const internal::wstring& suffix) { - return MakePolymorphicMatcher(internal::EndsWithMatcher( - suffix)); -} - -#endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING - -// Creates a polymorphic matcher that matches a 2-tuple where the -// first field == the second field. -inline internal::Eq2Matcher Eq() { return internal::Eq2Matcher(); } - -// Creates a polymorphic matcher that matches a 2-tuple where the -// first field >= the second field. -inline internal::Ge2Matcher Ge() { return internal::Ge2Matcher(); } - -// Creates a polymorphic matcher that matches a 2-tuple where the -// first field > the second field. -inline internal::Gt2Matcher Gt() { return internal::Gt2Matcher(); } - -// Creates a polymorphic matcher that matches a 2-tuple where the -// first field <= the second field. -inline internal::Le2Matcher Le() { return internal::Le2Matcher(); } - -// Creates a polymorphic matcher that matches a 2-tuple where the -// first field < the second field. -inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); } - -// Creates a polymorphic matcher that matches a 2-tuple where the -// first field != the second field. -inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); } - -// Creates a matcher that matches any value of type T that m doesn't -// match. -template -inline internal::NotMatcher Not(InnerMatcher m) { - return internal::NotMatcher(m); -} - -// Returns a matcher that matches anything that satisfies the given -// predicate. The predicate can be any unary function or functor -// whose return type can be implicitly converted to bool. -template -inline PolymorphicMatcher > -Truly(Predicate pred) { - return MakePolymorphicMatcher(internal::TrulyMatcher(pred)); -} - -// Returns a matcher that matches an equal container. -// 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 and order differences are not explained.) -template -inline PolymorphicMatcher > - ContainerEq(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 MakePolymorphicMatcher( - internal::ContainerEqMatcher(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 >, where T1 and T2 are the types of elements in the -// LHS container and the RHS container respectively. -template -inline internal::PointwiseMatcher -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( - tuple_matcher, rhs); -} - -// Matches an STL-style container or a native array that contains at -// least one element matching the given value or matcher. -// -// Examples: -// ::std::set page_ids; -// page_ids.insert(3); -// page_ids.insert(1); -// EXPECT_THAT(page_ids, Contains(1)); -// EXPECT_THAT(page_ids, Contains(Gt(2))); -// EXPECT_THAT(page_ids, Not(Contains(4))); -// -// ::std::map page_lengths; -// page_lengths[1] = 100; -// EXPECT_THAT(page_lengths, -// Contains(::std::pair(1, 100))); -// -// const char* user_ids[] = { "joe", "mike", "tom" }; -// EXPECT_THAT(user_ids, Contains(Eq(::std::string("tom")))); -template -inline internal::ContainsMatcher Contains(M matcher) { - return internal::ContainsMatcher(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 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 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 -inline internal::EachMatcher Each(M matcher) { - return internal::EachMatcher(matcher); -} - -// Key(inner_matcher) matches an std::pair whose 'first' field matches -// inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an -// std::map that contains at least one element whose key is >= 5. -template -inline internal::KeyMatcher Key(M inner_matcher) { - return internal::KeyMatcher(inner_matcher); -} - -// Pair(first_matcher, second_matcher) matches a std::pair whose 'first' field -// matches first_matcher and whose 'second' field matches second_matcher. For -// example, EXPECT_THAT(map_type, ElementsAre(Pair(Ge(5), "foo"))) can be used -// to match a std::map that contains exactly one element whose key -// is >= 5 and whose value equals "foo". -template -inline internal::PairMatcher -Pair(FirstMatcher first_matcher, SecondMatcher second_matcher) { - return internal::PairMatcher( - first_matcher, second_matcher); -} - -// Returns a predicate that is satisfied by anything that matches the -// given matcher. -template -inline internal::MatcherAsPredicate Matches(M matcher) { - return internal::MatcherAsPredicate(matcher); -} - -// Returns true iff the value matches the matcher. -template -inline bool Value(const T& value, M matcher) { - return testing::Matches(matcher)(value); -} - -// Matches the value against the given matcher and explains the match -// result to listener. -template -inline bool ExplainMatchResult( - M matcher, const T& value, MatchResultListener* listener) { - return SafeMatcherCast(matcher).MatchAndExplain(value, listener); -} - -// AllArgs(m) is a synonym of m. This is useful in -// -// EXPECT_CALL(foo, Bar(_, _)).With(AllArgs(Eq())); -// -// which is easier to read than -// -// EXPECT_CALL(foo, Bar(_, _)).With(Eq()); -template -inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; } - -// These macros allow using matchers to check values in Google Test -// tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher) -// succeed iff the value matches the matcher. If the assertion fails, -// the value and the description of the matcher will be printed. -#define ASSERT_THAT(value, matcher) ASSERT_PRED_FORMAT1(\ - ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) -#define EXPECT_THAT(value, matcher) EXPECT_PRED_FORMAT1(\ - ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_ diff --git a/lib/gmock/include/gmock/gmock-more-actions.h b/lib/gmock/include/gmock/gmock-more-actions.h deleted file mode 100644 index fc5e5ca8..00000000 --- a/lib/gmock/include/gmock/gmock-more-actions.h +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements some actions that depend on gmock-generated-actions.h. - -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ - -#include - -#include "gmock/gmock-generated-actions.h" - -namespace testing { -namespace internal { - -// Implements the Invoke(f) action. The template argument -// FunctionImpl is the implementation type of f, which can be either a -// function pointer or a functor. Invoke(f) can be used as an -// Action as long as f's type is compatible with F (i.e. f can be -// assigned to a tr1::function). -template -class InvokeAction { - public: - // The c'tor makes a copy of function_impl (either a function - // pointer or a functor). - explicit InvokeAction(FunctionImpl function_impl) - : function_impl_(function_impl) {} - - template - Result Perform(const ArgumentTuple& args) { - return InvokeHelper::Invoke(function_impl_, args); - } - - private: - FunctionImpl function_impl_; - - GTEST_DISALLOW_ASSIGN_(InvokeAction); -}; - -// Implements the Invoke(object_ptr, &Class::Method) action. -template -class InvokeMethodAction { - public: - InvokeMethodAction(Class* obj_ptr, MethodPtr method_ptr) - : obj_ptr_(obj_ptr), method_ptr_(method_ptr) {} - - template - Result Perform(const ArgumentTuple& args) const { - return InvokeHelper::InvokeMethod( - obj_ptr_, method_ptr_, args); - } - - private: - Class* const obj_ptr_; - const MethodPtr method_ptr_; - - GTEST_DISALLOW_ASSIGN_(InvokeMethodAction); -}; - -} // namespace internal - -// Various overloads for Invoke(). - -// Creates an action that invokes 'function_impl' with the mock -// function's arguments. -template -PolymorphicAction > Invoke( - FunctionImpl function_impl) { - return MakePolymorphicAction( - internal::InvokeAction(function_impl)); -} - -// Creates an action that invokes the given method on the given object -// with the mock function's arguments. -template -PolymorphicAction > Invoke( - Class* obj_ptr, MethodPtr method_ptr) { - return MakePolymorphicAction( - internal::InvokeMethodAction(obj_ptr, method_ptr)); -} - -// WithoutArgs(inner_action) can be used in a mock function with a -// non-empty argument list to perform inner_action, which takes no -// argument. In other words, it adapts an action accepting no -// argument to one that accepts (and ignores) arguments. -template -inline internal::WithArgsAction -WithoutArgs(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -// WithArg(an_action) creates an action that passes the k-th -// (0-based) argument of the mock function to an_action and performs -// it. It adapts an action accepting one argument to one that accepts -// multiple arguments. For convenience, we also provide -// WithArgs(an_action) (defined below) as a synonym. -template -inline internal::WithArgsAction -WithArg(const InnerAction& action) { - return internal::WithArgsAction(action); -} - -// The ACTION*() macros trigger warning C4100 (unreferenced formal -// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in -// the macro definition, as the warnings are generated when the macro -// is expanded and macro expansion cannot contain #pragma. Therefore -// we suppress them here. -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable:4100) -#endif - -// Action ReturnArg() returns the k-th argument of the mock function. -ACTION_TEMPLATE(ReturnArg, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_0_VALUE_PARAMS()) { - return std::tr1::get(args); -} - -// Action SaveArg(pointer) saves the k-th (0-based) argument of the -// mock function to *pointer. -ACTION_TEMPLATE(SaveArg, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_1_VALUE_PARAMS(pointer)) { - *pointer = ::std::tr1::get(args); -} - -// Action SaveArgPointee(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(args); -} - -// Action SetArgReferee(value) assigns 'value' to the variable -// referenced by the k-th (0-based) argument of the mock function. -ACTION_TEMPLATE(SetArgReferee, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_1_VALUE_PARAMS(value)) { - typedef typename ::std::tr1::tuple_element::type argk_type; - // Ensures that argument #k is a reference. If you get a compiler - // error on the next line, you are using SetArgReferee(value) in - // a mock function whose k-th (0-based) argument is not a reference. - GTEST_COMPILE_ASSERT_(internal::is_reference::value, - SetArgReferee_must_be_used_with_a_reference_argument); - ::std::tr1::get(args) = value; -} - -// Action SetArrayArgument(first, last) copies the elements in -// source range [first, last) to the array pointed to by the k-th -// (0-based) argument, which can be either a pointer or an -// iterator. The action does not take ownership of the elements in the -// source range. -ACTION_TEMPLATE(SetArrayArgument, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_2_VALUE_PARAMS(first, last)) { - // Microsoft compiler deprecates ::std::copy, so we want to suppress warning - // 4996 (Function call with parameters that may be unsafe) there. -#ifdef _MSC_VER -# pragma warning(push) // Saves the current warning state. -# pragma warning(disable:4996) // Temporarily disables warning 4996. -#endif - ::std::copy(first, last, ::std::tr1::get(args)); -#ifdef _MSC_VER -# pragma warning(pop) // Restores the warning state. -#endif -} - -// Action DeleteArg() deletes the k-th (0-based) argument of the mock -// function. -ACTION_TEMPLATE(DeleteArg, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_0_VALUE_PARAMS()) { - delete ::std::tr1::get(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 -// to throw the given exception. Any copyable value can be thrown. -#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; } -# ifdef _MSC_VER -# pragma warning(pop) // Restores the warning state. -# endif - -#endif // GTEST_HAS_EXCEPTIONS - -#ifdef _MSC_VER -# pragma warning(pop) -#endif - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_ diff --git a/lib/gmock/include/gmock/gmock-spec-builders.h b/lib/gmock/include/gmock/gmock-spec-builders.h deleted file mode 100644 index 400d4d71..00000000 --- a/lib/gmock/include/gmock/gmock-spec-builders.h +++ /dev/null @@ -1,1749 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements the ON_CALL() and EXPECT_CALL() macros. -// -// A user can use the ON_CALL() macro to specify the default action of -// a mock method. The syntax is: -// -// ON_CALL(mock_object, Method(argument-matchers)) -// .With(multi-argument-matcher) -// .WillByDefault(action); -// -// where the .With() clause is optional. -// -// A user can use the EXPECT_CALL() macro to specify an expectation on -// a mock method. The syntax is: -// -// EXPECT_CALL(mock_object, Method(argument-matchers)) -// .With(multi-argument-matchers) -// .Times(cardinality) -// .InSequence(sequences) -// .After(expectations) -// .WillOnce(action) -// .WillRepeatedly(action) -// .RetiresOnSaturation(); -// -// where all clauses are optional, and .InSequence()/.After()/ -// .WillOnce() can appear any number of times. - -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ - -#include -#include -#include -#include -#include - -#include "gmock/gmock-actions.h" -#include "gmock/gmock-cardinalities.h" -#include "gmock/gmock-matchers.h" -#include "gmock/internal/gmock-internal-utils.h" -#include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" - -namespace testing { - -// An abstract handle of an expectation. -class Expectation; - -// A set of expectation handles. -class ExpectationSet; - -// Anything inside the 'internal' namespace IS INTERNAL IMPLEMENTATION -// and MUST NOT BE USED IN USER CODE!!! -namespace internal { - -// Implements a mock function. -template class FunctionMocker; - -// Base class for expectations. -class ExpectationBase; - -// Implements an expectation. -template class TypedExpectation; - -// Helper class for testing the Expectation class template. -class ExpectationTester; - -// Base class for function mockers. -template class FunctionMockerBase; - -// Protects the mock object registry (in class Mock), all function -// mockers, and all expectations. -// -// The reason we don't use more fine-grained protection is: when a -// mock function Foo() is called, it needs to consult its expectations -// 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 -// time, it could affect the "retired" attributes of Foo()'s -// expectations when InSequence() is used, and thus affect which -// expectation gets picked. Therefore, we sequence all mock function -// calls to ensure the integrity of the mock objects' states. -GTEST_DECLARE_STATIC_MUTEX_(g_gmock_mutex); - -// Untyped base class for ActionResultHolder. -class UntypedActionResultHolderBase; - -// Abstract base class of FunctionMockerBase. This is the -// type-agnostic part of the function mocker interface. Its pure -// virtual methods are implemented by FunctionMockerBase. -class UntypedFunctionMockerBase { - public: - UntypedFunctionMockerBase(); - virtual ~UntypedFunctionMockerBase(); - - // Verifies that all expectations on this mock function have been - // satisfied. Reports one or more Google Test non-fatal failures - // and returns false if not. - // L >= g_gmock_mutex - bool VerifyAndClearExpectationsLocked(); - - // Clears the ON_CALL()s set on this mock function. - // L >= g_gmock_mutex - 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 UntypedOnCallSpecs; - - typedef std::vector > - 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 - -// Untyped base class for OnCallSpec. -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) const { - Assert(property, file_, line_, failure_message); - } - - // Expects that the ON_CALL() statement has a certain property. - void ExpectSpecProperty(bool property, const string& failure_message) const { - 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 -class OnCallSpec : public UntypedOnCallSpecBase { - public: - typedef typename Function::ArgumentTuple ArgumentTuple; - typedef typename Function::ArgumentMatcherTuple ArgumentMatcherTuple; - - // Constructs an OnCallSpec object from the information inside - // the parenthesis of an ON_CALL() statement. - OnCallSpec(const char* a_file, int a_line, - const ArgumentMatcherTuple& matchers) - : UntypedOnCallSpecBase(a_file, a_line), - matchers_(matchers), - // By default, extra_matcher_ should match anything. However, - // we cannot initialize it with _ as that triggers a compiler - // bug in Symbian's C++ compiler (cannot decide between two - // overloaded constructors of Matcher). - extra_matcher_(A()) { - } - - // Implements the .With() clause. - OnCallSpec& With(const Matcher& m) { - // Makes sure this is called at most once. - ExpectSpecProperty(last_clause_ < kWith, - ".With() cannot appear " - "more than once in an ON_CALL()."); - last_clause_ = kWith; - - extra_matcher_ = m; - return *this; - } - - // Implements the .WillByDefault() clause. - OnCallSpec& WillByDefault(const Action& action) { - ExpectSpecProperty(last_clause_ < kWillByDefault, - ".WillByDefault() must appear " - "exactly once in an ON_CALL()."); - last_clause_ = kWillByDefault; - - ExpectSpecProperty(!action.IsDoDefault(), - "DoDefault() cannot be used in ON_CALL()."); - action_ = action; - return *this; - } - - // Returns true iff the given arguments match the matchers. - bool Matches(const ArgumentTuple& args) const { - return TupleMatches(matchers_, args) && extra_matcher_.Matches(args); - } - - // Returns the action specified by the user. - const Action& GetAction() const { - AssertSpecProperty(last_clause_ == kWillByDefault, - ".WillByDefault() must appear exactly " - "once in an ON_CALL()."); - return action_; - } - - private: - // The information in statement - // - // ON_CALL(mock_object, Method(matchers)) - // .With(multi-argument-matcher) - // .WillByDefault(action); - // - // is recorded in the data members like this: - // - // source file that contains the statement => file_ - // line number of the statement => line_ - // matchers => matchers_ - // multi-argument-matcher => extra_matcher_ - // action => action_ - ArgumentMatcherTuple matchers_; - Matcher extra_matcher_; - Action action_; -}; // class OnCallSpec - -// Possible reactions on uninteresting calls. TODO(wan@google.com): -// rename the enum values to the kFoo style. -enum CallReaction { - ALLOW, - WARN, - FAIL -}; - -} // namespace internal - -// Utilities for manipulating mock objects. -class Mock { - public: - // The following public methods can be called concurrently. - - // Tells Google Mock to ignore mock_obj when checking for leaked - // mock objects. - static void AllowLeak(const void* mock_obj); - - // Verifies and clears all expectations on the given mock object. - // If the expectations aren't satisfied, generates one or more - // Google Test non-fatal failures and returns false. - static bool VerifyAndClearExpectations(void* mock_obj); - - // Verifies all expectations on the given mock object and clears its - // default actions and expectations. Returns true iff the - // verification was successful. - static bool VerifyAndClear(void* mock_obj); - private: - friend class internal::UntypedFunctionMockerBase; - - // Needed for a function mocker to register itself (so that we know - // how to clear a mock object). - template - friend class internal::FunctionMockerBase; - - template - friend class NiceMock; - - template - friend class StrictMock; - - // Tells Google Mock to allow uninteresting calls on the given mock - // object. - // L < g_gmock_mutex - static void AllowUninterestingCalls(const void* mock_obj); - - // Tells Google Mock to warn the user about uninteresting calls on - // the given mock object. - // L < g_gmock_mutex - static void WarnUninterestingCalls(const void* mock_obj); - - // Tells Google Mock to fail uninteresting calls on the given mock - // object. - // L < g_gmock_mutex - static void FailUninterestingCalls(const void* mock_obj); - - // Tells Google Mock the given mock object is being destroyed and - // its entry in the call-reaction table should be removed. - // L < g_gmock_mutex - static void UnregisterCallReaction(const void* mock_obj); - - // Returns the reaction Google Mock will have on uninteresting calls - // made on the given mock object. - // L < g_gmock_mutex - static internal::CallReaction GetReactionOnUninterestingCalls( - const void* mock_obj); - - // Verifies that all expectations on the given mock object have been - // satisfied. Reports one or more Google Test non-fatal failures - // and returns false if not. - // L >= g_gmock_mutex - static bool VerifyAndClearExpectationsLocked(void* mock_obj); - - // Clears all ON_CALL()s set on the given mock object. - // L >= g_gmock_mutex - static void ClearDefaultActionsLocked(void* mock_obj); - - // Registers a mock object and a mock method it owns. - // L < g_gmock_mutex - static void Register(const void* mock_obj, - internal::UntypedFunctionMockerBase* mocker); - - // Tells Google Mock where in the source code mock_obj is used in an - // ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this - // information helps the user identify which object it is. - // L < g_gmock_mutex - static void RegisterUseByOnCallOrExpectCall( - const void* mock_obj, const char* file, int line); - - // Unregisters a mock method; removes the owning mock object from - // the registry when the last mock method associated with it has - // been unregistered. This is called only in the destructor of - // FunctionMockerBase. - // L >= g_gmock_mutex - static void UnregisterLocked(internal::UntypedFunctionMockerBase* mocker); -}; // class Mock - -// An abstract handle of an expectation. Useful in the .After() -// clause of EXPECT_CALL() for setting the (partial) order of -// expectations. The syntax: -// -// Expectation e1 = EXPECT_CALL(...)...; -// EXPECT_CALL(...).After(e1)...; -// -// sets two expectations where the latter can only be matched after -// the former has been satisfied. -// -// Notes: -// - This class is copyable and has value semantics. -// - Constness is shallow: a const Expectation object itself cannot -// be modified, but the mutable methods of the ExpectationBase -// object it references can be called via expectation_base(). -// - The constructors and destructor are defined out-of-line because -// the Symbian WINSCW compiler wants to otherwise instantiate them -// when it sees this class definition, at which point it doesn't have -// ExpectationBase available yet, leading to incorrect destruction -// in the linked_ptr (or compilation errors if using a checking -// linked_ptr). -class Expectation { - public: - // Constructs a null object that doesn't reference any expectation. - Expectation(); - - ~Expectation(); - - // This single-argument ctor must not be explicit, in order to support the - // Expectation e = EXPECT_CALL(...); - // syntax. - // - // A TypedExpectation object stores its pre-requisites as - // Expectation objects, and needs to call the non-const Retire() - // method on the ExpectationBase objects they reference. Therefore - // Expectation must receive a *non-const* reference to the - // ExpectationBase object. - Expectation(internal::ExpectationBase& exp); // NOLINT - - // The compiler-generated copy ctor and operator= work exactly as - // intended, so we don't need to define our own. - - // Returns true iff rhs references the same expectation as this object does. - bool operator==(const Expectation& rhs) const { - return expectation_base_ == rhs.expectation_base_; - } - - bool operator!=(const Expectation& rhs) const { return !(*this == rhs); } - - private: - friend class ExpectationSet; - friend class Sequence; - friend class ::testing::internal::ExpectationBase; - friend class ::testing::internal::UntypedFunctionMockerBase; - - template - friend class ::testing::internal::FunctionMockerBase; - - template - friend class ::testing::internal::TypedExpectation; - - // This comparator is needed for putting Expectation objects into a set. - class Less { - public: - bool operator()(const Expectation& lhs, const Expectation& rhs) const { - return lhs.expectation_base_.get() < rhs.expectation_base_.get(); - } - }; - - typedef ::std::set Set; - - Expectation( - const internal::linked_ptr& expectation_base); - - // Returns the expectation this object references. - const internal::linked_ptr& - expectation_base() const { - return expectation_base_; - } - - // A linked_ptr that co-owns the expectation this handle references. - internal::linked_ptr expectation_base_; -}; - -// A set of expectation handles. Useful in the .After() clause of -// EXPECT_CALL() for setting the (partial) order of expectations. The -// syntax: -// -// ExpectationSet es; -// es += EXPECT_CALL(...)...; -// es += EXPECT_CALL(...)...; -// EXPECT_CALL(...).After(es)...; -// -// sets three expectations where the last one can only be matched -// after the first two have both been satisfied. -// -// This class is copyable and has value semantics. -class ExpectationSet { - public: - // A bidirectional iterator that can read a const element in the set. - typedef Expectation::Set::const_iterator const_iterator; - - // An object stored in the set. This is an alias of Expectation. - typedef Expectation::Set::value_type value_type; - - // Constructs an empty set. - ExpectationSet() {} - - // This single-argument ctor must not be explicit, in order to support the - // ExpectationSet es = EXPECT_CALL(...); - // syntax. - ExpectationSet(internal::ExpectationBase& exp) { // NOLINT - *this += Expectation(exp); - } - - // This single-argument ctor implements implicit conversion from - // Expectation and thus must not be explicit. This allows either an - // Expectation or an ExpectationSet to be used in .After(). - ExpectationSet(const Expectation& e) { // NOLINT - *this += e; - } - - // The compiler-generator ctor and operator= works exactly as - // intended, so we don't need to define our own. - - // Returns true iff rhs contains the same set of Expectation objects - // as this does. - bool operator==(const ExpectationSet& rhs) const { - return expectations_ == rhs.expectations_; - } - - bool operator!=(const ExpectationSet& rhs) const { return !(*this == rhs); } - - // Implements the syntax - // expectation_set += EXPECT_CALL(...); - ExpectationSet& operator+=(const Expectation& e) { - expectations_.insert(e); - return *this; - } - - int size() const { return static_cast(expectations_.size()); } - - const_iterator begin() const { return expectations_.begin(); } - const_iterator end() const { return expectations_.end(); } - - private: - Expectation::Set expectations_; -}; - - -// Sequence objects are used by a user to specify the relative order -// in which the expectations should match. They are copyable (we rely -// on the compiler-defined copy constructor and assignment operator). -class Sequence { - public: - // Constructs an empty sequence. - Sequence() : last_expectation_(new Expectation) {} - - // Adds an expectation to this sequence. The caller must ensure - // that no other thread is accessing this Sequence object. - void AddExpectation(const Expectation& expectation) const; - - private: - // The last expectation in this sequence. We use a linked_ptr here - // because Sequence objects are copyable and we want the copies to - // be aliases. The linked_ptr allows the copies to co-own and share - // the same Expectation object. - internal::linked_ptr last_expectation_; -}; // class Sequence - -// An object of this type causes all EXPECT_CALL() statements -// encountered in its scope to be put in an anonymous sequence. The -// work is done in the constructor and destructor. You should only -// create an InSequence object on the stack. -// -// The sole purpose for this class is to support easy definition of -// sequential expectations, e.g. -// -// { -// InSequence dummy; // The name of the object doesn't matter. -// -// // The following expectations must match in the order they appear. -// EXPECT_CALL(a, Bar())...; -// EXPECT_CALL(a, Baz())...; -// ... -// EXPECT_CALL(b, Xyz())...; -// } -// -// You can create InSequence objects in multiple threads, as long as -// they are used to affect different mock objects. The idea is that -// each thread can create and set up its own mocks as if it's the only -// thread. However, for clarity of your tests we recommend you to set -// up mocks in the main thread unless you have a good reason not to do -// so. -class InSequence { - public: - InSequence(); - ~InSequence(); - private: - bool sequence_created_; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(InSequence); // NOLINT -} GTEST_ATTRIBUTE_UNUSED_; - -namespace internal { - -// Points to the implicit sequence introduced by a living InSequence -// object (if any) in the current thread or NULL. -extern ThreadLocal g_gmock_implicit_sequence; - -// Base class for implementing expectations. -// -// There are two reasons for having a type-agnostic base class for -// Expectation: -// -// 1. We need to store collections of expectations of different -// types (e.g. all pre-requisites of a particular expectation, all -// expectations in a sequence). Therefore these expectation objects -// must share a common base class. -// -// 2. We can avoid binary code bloat by moving methods not depending -// on the template argument of Expectation to the base class. -// -// This class is internal and mustn't be used by user code directly. -class ExpectationBase { - public: - // source_text is the EXPECT_CALL(...) source that created this Expectation. - ExpectationBase(const char* file, int line, const string& source_text); - - virtual ~ExpectationBase(); - - // Where in the source file was the expectation spec defined? - const char* file() const { return file_; } - int line() const { return line_; } - const char* source_text() const { return source_text_.c_str(); } - // Returns the cardinality specified in the expectation spec. - const Cardinality& cardinality() const { return cardinality_; } - - // Describes the source file location of this expectation. - void DescribeLocationTo(::std::ostream* os) const { - *os << FormatFileLocation(file(), line()) << " "; - } - - // Describes how many times a function call matching this - // expectation has occurred. - // L >= g_gmock_mutex - 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: - friend class ::testing::Expectation; - friend class UntypedFunctionMockerBase; - - enum Clause { - // Don't change the order of the enum members! - kNone, - kWith, - kTimes, - kInSequence, - kAfter, - kWillOnce, - kWillRepeatedly, - kRetiresOnSaturation - }; - - typedef std::vector UntypedActions; - - // Returns an Expectation object that references and co-owns this - // expectation. - virtual Expectation GetHandle() = 0; - - // Asserts that the EXPECT_CALL() statement has the given property. - void AssertSpecProperty(bool property, const string& failure_message) const { - Assert(property, file_, line_, failure_message); - } - - // Expects that the EXPECT_CALL() statement has the given property. - void ExpectSpecProperty(bool property, const string& failure_message) const { - Expect(property, file_, line_, failure_message); - } - - // Explicitly specifies the cardinality of this expectation. Used - // by the subclasses to implement the .Times() clause. - void SpecifyCardinality(const Cardinality& cardinality); - - // Returns true iff the user specified the cardinality explicitly - // using a .Times(). - bool cardinality_specified() const { return cardinality_specified_; } - - // Sets the cardinality of this expectation spec. - void set_cardinality(const Cardinality& a_cardinality) { - cardinality_ = a_cardinality; - } - - // The following group of methods should only be called after the - // EXPECT_CALL() statement, and only when g_gmock_mutex is held by - // the current thread. - - // Retires all pre-requisites of this expectation. - // L >= g_gmock_mutex - void RetireAllPreRequisites(); - - // Returns true iff this expectation is retired. - // L >= g_gmock_mutex - bool is_retired() const { - g_gmock_mutex.AssertHeld(); - return retired_; - } - - // Retires this expectation. - // L >= g_gmock_mutex - void Retire() { - g_gmock_mutex.AssertHeld(); - retired_ = true; - } - - // Returns true iff this expectation is satisfied. - // L >= g_gmock_mutex - bool IsSatisfied() const { - g_gmock_mutex.AssertHeld(); - return cardinality().IsSatisfiedByCallCount(call_count_); - } - - // Returns true iff this expectation is saturated. - // L >= g_gmock_mutex - bool IsSaturated() const { - g_gmock_mutex.AssertHeld(); - return cardinality().IsSaturatedByCallCount(call_count_); - } - - // Returns true iff this expectation is over-saturated. - // L >= g_gmock_mutex - bool IsOverSaturated() const { - g_gmock_mutex.AssertHeld(); - return cardinality().IsOverSaturatedByCallCount(call_count_); - } - - // Returns true iff all pre-requisites of this expectation are satisfied. - // L >= g_gmock_mutex - bool AllPrerequisitesAreSatisfied() const; - - // Adds unsatisfied pre-requisites of this expectation to 'result'. - // L >= g_gmock_mutex - void FindUnsatisfiedPrerequisites(ExpectationSet* result) const; - - // Returns the number this expectation has been invoked. - // L >= g_gmock_mutex - int call_count() const { - g_gmock_mutex.AssertHeld(); - return call_count_; - } - - // Increments the number this expectation has been invoked. - // L >= g_gmock_mutex - void IncrementCallCount() { - g_gmock_mutex.AssertHeld(); - call_count_++; - } - - // 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::internal::ExpectationTester; - - template - 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 - // an EXPECT_CALL() statement finishes. - const char* file_; // The file that contains the expectation. - int line_; // The line number of the expectation. - const string source_text_; // The EXPECT_CALL(...) source text. - // True iff the cardinality is specified explicitly. - bool cardinality_specified_; - Cardinality cardinality_; // The cardinality of the expectation. - // The immediate pre-requisites (i.e. expectations that must be - // satisfied before this expectation can be matched) of this - // expectation. We use linked_ptr in the set because we want an - // Expectation object to be co-owned by its FunctionMocker and its - // successors. This allows multiple mock objects to be deleted at - // different times. - ExpectationSet immediate_prerequisites_; - - // This group of fields are the current state of the expectation, - // and can change as the mock function is called. - int call_count_; // How many times this expectation has been invoked. - bool retired_; // True iff this expectation has retired. - UntypedActions untyped_actions_; - bool extra_matcher_specified_; - bool repeated_action_specified_; // True if a WillRepeatedly() was specified. - 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); -}; // class ExpectationBase - -// Impements an expectation for the given function type. -template -class TypedExpectation : public ExpectationBase { - public: - typedef typename Function::ArgumentTuple ArgumentTuple; - typedef typename Function::ArgumentMatcherTuple ArgumentMatcherTuple; - typedef typename Function::Result Result; - - TypedExpectation(FunctionMockerBase* owner, - const char* a_file, int a_line, const string& a_source_text, - const ArgumentMatcherTuple& m) - : ExpectationBase(a_file, a_line, a_source_text), - owner_(owner), - matchers_(m), - // By default, extra_matcher_ should match anything. However, - // we cannot initialize it with _ as that triggers a compiler - // bug in Symbian's C++ compiler (cannot decide between two - // overloaded constructors of Matcher). - extra_matcher_(A()), - repeated_action_(DoDefault()) {} - - virtual ~TypedExpectation() { - // Check the validity of the action count if it hasn't been done - // yet (for example, if the expectation was never used). - CheckActionCountIfNotDone(); - for (UntypedActions::const_iterator it = untyped_actions_.begin(); - it != untyped_actions_.end(); ++it) { - delete static_cast*>(*it); - } - } - - // Implements the .With() clause. - TypedExpectation& With(const Matcher& m) { - if (last_clause_ == kWith) { - ExpectSpecProperty(false, - ".With() cannot appear " - "more than once in an EXPECT_CALL()."); - } else { - ExpectSpecProperty(last_clause_ < kWith, - ".With() must be the first " - "clause in an EXPECT_CALL()."); - } - last_clause_ = kWith; - - extra_matcher_ = m; - extra_matcher_specified_ = true; - return *this; - } - - // Implements the .Times() clause. - TypedExpectation& Times(const Cardinality& a_cardinality) { - ExpectationBase::UntypedTimes(a_cardinality); - return *this; - } - - // Implements the .Times() clause. - TypedExpectation& Times(int n) { - return Times(Exactly(n)); - } - - // Implements the .InSequence() clause. - TypedExpectation& InSequence(const Sequence& s) { - ExpectSpecProperty(last_clause_ <= kInSequence, - ".InSequence() cannot appear after .After()," - " .WillOnce(), .WillRepeatedly(), or " - ".RetiresOnSaturation()."); - last_clause_ = kInSequence; - - s.AddExpectation(GetHandle()); - return *this; - } - TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2) { - return InSequence(s1).InSequence(s2); - } - TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, - const Sequence& s3) { - return InSequence(s1, s2).InSequence(s3); - } - TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, - const Sequence& s3, const Sequence& s4) { - return InSequence(s1, s2, s3).InSequence(s4); - } - TypedExpectation& InSequence(const Sequence& s1, const Sequence& s2, - const Sequence& s3, const Sequence& s4, - const Sequence& s5) { - return InSequence(s1, s2, s3, s4).InSequence(s5); - } - - // Implements that .After() clause. - TypedExpectation& After(const ExpectationSet& s) { - ExpectSpecProperty(last_clause_ <= kAfter, - ".After() cannot appear after .WillOnce()," - " .WillRepeatedly(), or " - ".RetiresOnSaturation()."); - last_clause_ = kAfter; - - for (ExpectationSet::const_iterator it = s.begin(); it != s.end(); ++it) { - immediate_prerequisites_ += *it; - } - return *this; - } - TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2) { - return After(s1).After(s2); - } - TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, - const ExpectationSet& s3) { - return After(s1, s2).After(s3); - } - TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, - const ExpectationSet& s3, const ExpectationSet& s4) { - return After(s1, s2, s3).After(s4); - } - TypedExpectation& After(const ExpectationSet& s1, const ExpectationSet& s2, - const ExpectationSet& s3, const ExpectationSet& s4, - const ExpectationSet& s5) { - return After(s1, s2, s3, s4).After(s5); - } - - // Implements the .WillOnce() clause. - TypedExpectation& WillOnce(const Action& action) { - ExpectSpecProperty(last_clause_ <= kWillOnce, - ".WillOnce() cannot appear after " - ".WillRepeatedly() or .RetiresOnSaturation()."); - last_clause_ = kWillOnce; - - untyped_actions_.push_back(new Action(action)); - if (!cardinality_specified()) { - set_cardinality(Exactly(static_cast(untyped_actions_.size()))); - } - return *this; - } - - // Implements the .WillRepeatedly() clause. - TypedExpectation& WillRepeatedly(const Action& action) { - if (last_clause_ == kWillRepeatedly) { - ExpectSpecProperty(false, - ".WillRepeatedly() cannot appear " - "more than once in an EXPECT_CALL()."); - } else { - ExpectSpecProperty(last_clause_ < kWillRepeatedly, - ".WillRepeatedly() cannot appear " - "after .RetiresOnSaturation()."); - } - last_clause_ = kWillRepeatedly; - repeated_action_specified_ = true; - - repeated_action_ = action; - if (!cardinality_specified()) { - set_cardinality(AtLeast(static_cast(untyped_actions_.size()))); - } - - // Now that no more action clauses can be specified, we check - // whether their count makes sense. - CheckActionCountIfNotDone(); - return *this; - } - - // Implements the .RetiresOnSaturation() clause. - TypedExpectation& RetiresOnSaturation() { - ExpectSpecProperty(last_clause_ < kRetiresOnSaturation, - ".RetiresOnSaturation() cannot appear " - "more than once."); - last_clause_ = kRetiresOnSaturation; - retires_on_saturation_ = true; - - // Now that no more action clauses can be specified, we check - // whether their count makes sense. - CheckActionCountIfNotDone(); - return *this; - } - - // Returns the matchers for the arguments as specified inside the - // EXPECT_CALL() macro. - const ArgumentMatcherTuple& matchers() const { - return matchers_; - } - - // Returns the matcher specified by the .With() clause. - const Matcher& extra_matcher() const { - return extra_matcher_; - } - - // Returns the action specified by the .WillRepeatedly() clause. - const Action& repeated_action() const { return repeated_action_; } - - // If this mock method has an extra matcher (i.e. .With(matcher)), - // describes it to the ostream. - virtual void MaybeDescribeExtraMatcherTo(::std::ostream* os) { - if (extra_matcher_specified_) { - *os << " Expected args: "; - extra_matcher_.DescribeTo(os); - *os << "\n"; - } - } - - private: - template - friend class FunctionMockerBase; - - // Returns an Expectation object that references and co-owns this - // expectation. - virtual Expectation GetHandle() { - return owner_->GetHandleOf(this); - } - - // The following methods will be called only after the EXPECT_CALL() - // statement finishes and when the current thread holds - // g_gmock_mutex. - - // Returns true iff this expectation matches the given arguments. - // L >= g_gmock_mutex - bool Matches(const ArgumentTuple& args) const { - g_gmock_mutex.AssertHeld(); - return TupleMatches(matchers_, args) && extra_matcher_.Matches(args); - } - - // Returns true iff this expectation should handle the given arguments. - // L >= g_gmock_mutex - bool ShouldHandleArguments(const ArgumentTuple& args) const { - g_gmock_mutex.AssertHeld(); - - // In case the action count wasn't checked when the expectation - // was defined (e.g. if this expectation has no WillRepeatedly() - // or RetiresOnSaturation() clause), we check it when the - // expectation is used for the first time. - CheckActionCountIfNotDone(); - return !is_retired() && AllPrerequisitesAreSatisfied() && Matches(args); - } - - // Describes the result of matching the arguments against this - // expectation to the given ostream. - // L >= g_gmock_mutex - void ExplainMatchResultTo(const ArgumentTuple& args, - ::std::ostream* os) const { - g_gmock_mutex.AssertHeld(); - - if (is_retired()) { - *os << " Expected: the expectation is active\n" - << " Actual: it is retired\n"; - } else if (!Matches(args)) { - if (!TupleMatches(matchers_, args)) { - ExplainMatchFailureTupleTo(matchers_, args, os); - } - StringMatchResultListener listener; - if (!extra_matcher_.MatchAndExplain(args, &listener)) { - *os << " Expected args: "; - extra_matcher_.DescribeTo(os); - *os << "\n Actual: don't match"; - - internal::PrintIfNotEmpty(listener.str(), os); - *os << "\n"; - } - } else if (!AllPrerequisitesAreSatisfied()) { - *os << " Expected: all pre-requisites are satisfied\n" - << " Actual: the following immediate pre-requisites " - << "are not satisfied:\n"; - ExpectationSet unsatisfied_prereqs; - FindUnsatisfiedPrerequisites(&unsatisfied_prereqs); - int i = 0; - for (ExpectationSet::const_iterator it = unsatisfied_prereqs.begin(); - it != unsatisfied_prereqs.end(); ++it) { - it->expectation_base()->DescribeLocationTo(os); - *os << "pre-requisite #" << i++ << "\n"; - } - *os << " (end of pre-requisites)\n"; - } else { - // This line is here just for completeness' sake. It will never - // be executed as currently the ExplainMatchResultTo() function - // is called only when the mock function call does NOT match the - // expectation. - *os << "The call matches the expectation.\n"; - } - } - - // Returns the action that should be taken for the current invocation. - // L >= g_gmock_mutex - const Action& GetCurrentAction(const FunctionMockerBase* mocker, - const ArgumentTuple& args) const { - g_gmock_mutex.AssertHeld(); - const int count = call_count(); - Assert(count >= 1, __FILE__, __LINE__, - "call_count() is <= 0 when GetCurrentAction() is " - "called - this should never happen."); - - const int action_count = static_cast(untyped_actions_.size()); - if (action_count > 0 && !repeated_action_specified_ && - count > action_count) { - // If there is at least one WillOnce() and no WillRepeatedly(), - // we warn the user when the WillOnce() clauses ran out. - ::std::stringstream ss; - DescribeLocationTo(&ss); - ss << "Actions ran out in " << source_text() << "...\n" - << "Called " << count << " times, but only " - << action_count << " WillOnce()" - << (action_count == 1 ? " is" : "s are") << " specified - "; - mocker->DescribeDefaultActionTo(args, &ss); - Log(WARNING, ss.str(), 1); - } - - return count <= action_count ? - *static_cast*>(untyped_actions_[count - 1]) : - repeated_action(); - } - - // Given the arguments of a mock function call, if the call will - // over-saturate this expectation, returns the default action; - // otherwise, returns the next action in this expectation. Also - // describes *what* happened to 'what', and explains *why* Google - // Mock does it to 'why'. This method is not const as it calls - // IncrementCallCount(). A return value of NULL means the default - // action. - // L >= g_gmock_mutex - const Action* GetActionForArguments(const FunctionMockerBase* mocker, - const ArgumentTuple& args, - ::std::ostream* what, - ::std::ostream* why) { - g_gmock_mutex.AssertHeld(); - if (IsSaturated()) { - // We have an excessive call. - IncrementCallCount(); - *what << "Mock function called more times than expected - "; - mocker->DescribeDefaultActionTo(args, what); - DescribeCallCountTo(why); - - // TODO(wan@google.com): allow the user to control whether - // unexpected calls should fail immediately or continue using a - // flag --gmock_unexpected_calls_are_fatal. - return NULL; - } - - IncrementCallCount(); - RetireAllPreRequisites(); - - if (retires_on_saturation_ && IsSaturated()) { - Retire(); - } - - // Must be done after IncrementCount()! - *what << "Mock function call matches " << source_text() <<"...\n"; - return &(GetCurrentAction(mocker, args)); - } - - // All the fields below won't change once the EXPECT_CALL() - // statement finishes. - FunctionMockerBase* const owner_; - ArgumentMatcherTuple matchers_; - Matcher extra_matcher_; - Action repeated_action_; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(TypedExpectation); -}; // class TypedExpectation - -// A MockSpec object is used by ON_CALL() or EXPECT_CALL() for -// specifying the default behavior of, or expectation on, a mock -// function. - -// Note: class MockSpec really belongs to the ::testing namespace. -// However if we define it in ::testing, MSVC will complain when -// classes in ::testing::internal declare it as a friend class -// template. To workaround this compiler bug, we define MockSpec in -// ::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 -class MockSpec { - public: - typedef typename internal::Function::ArgumentTuple ArgumentTuple; - typedef typename internal::Function::ArgumentMatcherTuple - ArgumentMatcherTuple; - - // Constructs a MockSpec object, given the function mocker object - // that the spec is associated with. - explicit MockSpec(internal::FunctionMockerBase* function_mocker) - : function_mocker_(function_mocker) {} - - // Adds a new default action spec to the function mocker and returns - // the newly created spec. - internal::OnCallSpec& InternalDefaultActionSetAt( - const char* file, int line, const char* obj, const char* call) { - LogWithLocation(internal::INFO, file, line, - string("ON_CALL(") + obj + ", " + call + ") invoked"); - return function_mocker_->AddNewOnCallSpec(file, line, matchers_); - } - - // Adds a new expectation spec to the function mocker and returns - // the newly created spec. - internal::TypedExpectation& InternalExpectedAt( - const char* file, int line, const char* obj, const char* call) { - const string source_text(string("EXPECT_CALL(") + obj + ", " + call + ")"); - LogWithLocation(internal::INFO, file, line, source_text + " invoked"); - return function_mocker_->AddNewExpectation( - file, line, source_text, matchers_); - } - - private: - template - friend class internal::FunctionMocker; - - void SetMatchers(const ArgumentMatcherTuple& matchers) { - matchers_ = matchers; - } - - // The function mocker that owns this spec. - internal::FunctionMockerBase* const function_mocker_; - // The argument matchers specified in the spec. - ArgumentMatcherTuple matchers_; - - GTEST_DISALLOW_ASSIGN_(MockSpec); -}; // class MockSpec - -// MSVC warns about using 'this' in base member initializer list, so -// 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 constructor only. - -#ifdef _MSC_VER -# pragma warning(push) // Saves the current warning state. -# pragma warning(disable:4355) // Temporarily disables warning 4355. -#endif // _MSV_VER - -// C++ treats the void type specially. For example, you cannot define -// a void-typed variable or pass a void value to a function. -// ActionResultHolder holds a value of type T, where T must be a -// copyable type or void (T doesn't need to be default-constructable). -// It hides the syntactic difference between void and other types, and -// is used to unify the code for invoking both void-returning and -// non-void-returning mock functions. - -// Untyped base class for ActionResultHolder. -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 -class ActionResultHolder : public UntypedActionResultHolderBase { - public: - explicit ActionResultHolder(T a_value) : value_(a_value) {} - - // The compiler-generated copy constructor and assignment operator - // are exactly what we need, so we don't need to define them. - - // 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. - virtual void PrintAsActionResult(::std::ostream* os) const { - *os << "\n Returns: "; - // T may be a reference type, so we don't use UniversalPrint(). - UniversalPrinter::Print(value_, os); - } - - // Performs the given mock function's default action and returns the - // result in a new-ed ActionResultHolder. - template - static ActionResultHolder* PerformDefaultAction( - const FunctionMockerBase* func_mocker, - const typename Function::ArgumentTuple& args, - const string& call_description) { - return new ActionResultHolder( - func_mocker->PerformDefaultAction(args, call_description)); - } - - // Performs the given action and returns the result in a new-ed - // ActionResultHolder. - template - static ActionResultHolder* - PerformAction(const Action& action, - const typename Function::ArgumentTuple& args) { - return new ActionResultHolder(action.Perform(args)); - } - - private: - T value_; - - // T could be a reference type, so = isn't supported. - GTEST_DISALLOW_ASSIGN_(ActionResultHolder); -}; - -// Specialization for T = void. -template <> -class ActionResultHolder : public UntypedActionResultHolderBase { - public: - void GetValueAndDelete() const { delete this; } - - virtual void PrintAsActionResult(::std::ostream* /* os */) const {} - - // Performs the given mock function's default action and returns NULL; - template - static ActionResultHolder* PerformDefaultAction( - const FunctionMockerBase* func_mocker, - const typename Function::ArgumentTuple& args, - const string& call_description) { - func_mocker->PerformDefaultAction(args, call_description); - return NULL; - } - - // Performs the given action and returns NULL. - template - static ActionResultHolder* PerformAction( - const Action& action, - const typename Function::ArgumentTuple& args) { - action.Perform(args); - return NULL; - } -}; - -// 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 -// bloat. -template -class FunctionMockerBase : public UntypedFunctionMockerBase { - public: - typedef typename Function::Result Result; - typedef typename Function::ArgumentTuple ArgumentTuple; - typedef typename Function::ArgumentMatcherTuple ArgumentMatcherTuple; - - FunctionMockerBase() : current_spec_(this) {} - - // The destructor verifies that all expectations on this mock - // function have been satisfied. If not, it will report Google Test - // non-fatal failures for the violations. - // L < g_gmock_mutex - virtual ~FunctionMockerBase() { - MutexLock l(&g_gmock_mutex); - VerifyAndClearExpectationsLocked(); - Mock::UnregisterLocked(this); - ClearDefaultActionsLocked(); - } - - // Returns the ON_CALL spec that matches this mock function with the - // given arguments; returns NULL if no matching ON_CALL is found. - // L = * - const OnCallSpec* FindOnCallSpec( - const ArgumentTuple& args) const { - for (UntypedOnCallSpecs::const_reverse_iterator it - = untyped_on_call_specs_.rbegin(); - it != untyped_on_call_specs_.rend(); ++it) { - const OnCallSpec* spec = static_cast*>(*it); - if (spec->Matches(args)) - return spec; - } - - return NULL; - } - - // Performs the default action of this mock function on the given arguments - // and returns the result. Asserts with a helpful call descrption if there is - // no valid return value. This method doesn't depend on the mutable state of - // this object, and thus can be called concurrently without locking. - // L = * - Result PerformDefaultAction(const ArgumentTuple& args, - const string& call_description) const { - const OnCallSpec* const spec = - this->FindOnCallSpec(args); - if (spec != NULL) { - return spec->GetAction().Perform(args); - } - Assert(DefaultValue::Exists(), "", -1, - call_description + "\n The mock function has no default action " - "set, and its return type has no default value set."); - return DefaultValue::Get(); - } - - // 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. The caller is responsible for deleting the result. - // L = * - virtual UntypedActionResultHolderBase* UntypedPerformDefaultAction( - const void* untyped_args, // must point to an ArgumentTuple - const string& call_description) const { - const ArgumentTuple& args = - *static_cast(untyped_args); - return ResultHolder::PerformDefaultAction(this, args, call_description); - } - - // Performs the given action with the given arguments and returns - // the action's result. The caller is responsible for deleting the - // result. - // L = * - virtual UntypedActionResultHolderBase* UntypedPerformAction( - const void* untyped_action, const void* untyped_args) const { - // Make a copy of the action before performing it, in case the - // action deletes the mock object (and thus deletes itself). - const Action action = *static_cast*>(untyped_action); - const ArgumentTuple& args = - *static_cast(untyped_args); - return ResultHolder::PerformAction(action, args); - } - - // Implements UntypedFunctionMockerBase::ClearDefaultActionsLocked(): - // clears the ON_CALL()s set on this mock function. - // L >= g_gmock_mutex - virtual void ClearDefaultActionsLocked() { - g_gmock_mutex.AssertHeld(); - for (UntypedOnCallSpecs::const_iterator it = - untyped_on_call_specs_.begin(); - it != untyped_on_call_specs_.end(); ++it) { - delete static_cast*>(*it); - } - untyped_on_call_specs_.clear(); - } - - protected: - template - friend class MockSpec; - - typedef ActionResultHolder ResultHolder; - - // Returns the result of invoking this mock function with the given - // arguments. This function can be safely called from multiple - // threads concurrently. - // L < g_gmock_mutex - Result InvokeWith(const ArgumentTuple& args) { - return static_cast( - this->UntypedInvokeWith(&args))->GetValueAndDelete(); - } - - // Adds and returns a default action spec for this mock function. - // L < g_gmock_mutex - OnCallSpec& AddNewOnCallSpec( - const char* file, int line, - const ArgumentMatcherTuple& m) { - Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); - OnCallSpec* const on_call_spec = new OnCallSpec(file, line, m); - untyped_on_call_specs_.push_back(on_call_spec); - return *on_call_spec; - } - - // Adds and returns an expectation spec for this mock function. - // L < g_gmock_mutex - TypedExpectation& AddNewExpectation( - const char* file, - int line, - const string& source_text, - const ArgumentMatcherTuple& m) { - Mock::RegisterUseByOnCallOrExpectCall(MockObject(), file, line); - TypedExpectation* const expectation = - new TypedExpectation(this, file, line, source_text, m); - const linked_ptr untyped_expectation(expectation); - untyped_expectations_.push_back(untyped_expectation); - - // Adds this expectation into the implicit sequence if there is one. - Sequence* const implicit_sequence = g_gmock_implicit_sequence.get(); - if (implicit_sequence != NULL) { - implicit_sequence->AddExpectation(Expectation(untyped_expectation)); - } - - return *expectation; - } - - // The current spec (either default action spec or expectation spec) - // being described on this function mocker. - MockSpec& current_spec() { return current_spec_; } - - private: - template friend class TypedExpectation; - - // Some utilities needed for implementing UntypedInvokeWith(). - - // Describes what default action will be performed for the given - // arguments. - // L = * - void DescribeDefaultActionTo(const ArgumentTuple& args, - ::std::ostream* os) const { - const OnCallSpec* const spec = FindOnCallSpec(args); - - if (spec == NULL) { - *os << (internal::type_equals::value ? - "returning directly.\n" : - "returning default value.\n"); - } else { - *os << "taking default action specified at:\n" - << FormatFileLocation(spec->file(), spec->line()) << "\n"; - } - } - - // 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 { - const ArgumentTuple& args = - *static_cast(untyped_args); - *os << "Uninteresting mock function call - "; - DescribeDefaultActionTo(args, os); - *os << " Function call: " << Name(); - 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 - // corresponding action that needs to be taken in an ATOMIC - // transaction. Otherwise another thread may call this mock - // method in the middle and mess up the state. - // - // However, performing the action has to be left out of the critical - // section. The reason is that we have no control on what the - // action does (it can invoke an arbitrary user function or even a - // mock function) and excessive locking could cause a dead lock. - // 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) { - const ArgumentTuple& args = - *static_cast(untyped_args); - MutexLock l(&g_gmock_mutex); - TypedExpectation* exp = this->FindMatchingExpectationLocked(args); - if (exp == NULL) { // A match wasn't found. - this->FormatUnexpectedCallMessageLocked(args, what, why); - return NULL; - } - - // This line must be done before calling GetActionForArguments(), - // which will increment the call count for *exp and thus affect - // its saturation status. - *is_excessive = exp->IsSaturated(); - const Action* action = exp->GetActionForArguments(this, args, what, 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(untyped_args); - UniversalPrint(args, os); - } - - // Returns the expectation that matches the arguments, or NULL if no - // expectation matches them. - // L >= g_gmock_mutex - TypedExpectation* FindMatchingExpectationLocked( - const ArgumentTuple& args) const { - g_gmock_mutex.AssertHeld(); - for (typename UntypedExpectations::const_reverse_iterator it = - untyped_expectations_.rbegin(); - it != untyped_expectations_.rend(); ++it) { - TypedExpectation* const exp = - static_cast*>(it->get()); - if (exp->ShouldHandleArguments(args)) { - return exp; - } - } - return NULL; - } - - // Returns a message that the arguments don't match any expectation. - // L >= g_gmock_mutex - void FormatUnexpectedCallMessageLocked(const ArgumentTuple& args, - ::std::ostream* os, - ::std::ostream* why) const { - g_gmock_mutex.AssertHeld(); - *os << "\nUnexpected mock function call - "; - DescribeDefaultActionTo(args, os); - PrintTriedExpectationsLocked(args, why); - } - - // Prints a list of expectations that have been tried against the - // current mock function call. - // L >= g_gmock_mutex - void PrintTriedExpectationsLocked(const ArgumentTuple& args, - ::std::ostream* why) const { - g_gmock_mutex.AssertHeld(); - const int count = static_cast(untyped_expectations_.size()); - *why << "Google Mock tried the following " << count << " " - << (count == 1 ? "expectation, but it didn't match" : - "expectations, but none matched") - << ":\n"; - for (int i = 0; i < count; i++) { - TypedExpectation* const expectation = - static_cast*>(untyped_expectations_[i].get()); - *why << "\n"; - expectation->DescribeLocationTo(why); - if (count > 1) { - *why << "tried expectation #" << i << ": "; - } - *why << expectation->source_text() << "...\n"; - expectation->ExplainMatchResultTo(args, why); - expectation->DescribeCallCountTo(why); - } - } - - // The current spec (either default action spec or expectation spec) - // being described on this function mocker. - MockSpec current_spec_; - - // There is no generally useful and implementable semantics of - // copying a mock object, so copying a mock is usually a user error. - // Thus we disallow copying function mockers. If the user really - // wants to copy a mock object, he should implement his own copy - // operation, for example: - // - // class MockFoo : public Foo { - // public: - // // Defines a copy constructor explicitly. - // MockFoo(const MockFoo& src) {} - // ... - // }; - GTEST_DISALLOW_COPY_AND_ASSIGN_(FunctionMockerBase); -}; // class FunctionMockerBase - -#ifdef _MSC_VER -# pragma warning(pop) // Restores the warning state. -#endif // _MSV_VER - -// Implements methods of FunctionMockerBase. - -// Verifies that all expectations on this mock function have been -// satisfied. Reports one or more Google Test non-fatal failures and -// returns false if not. -// L >= g_gmock_mutex - -// Reports an uninteresting call (whose description is in msg) in the -// manner specified by 'reaction'. -void ReportUninterestingCall(CallReaction reaction, const string& msg); - -} // namespace internal - -// The style guide prohibits "using" statements in a namespace scope -// inside a header file. However, the MockSpec class template is -// meant to be defined in the ::testing namespace. The following line -// is just a trick for working around a bug in MSVC 8.0, which cannot -// handle it if we define MockSpec in ::testing. -using internal::MockSpec; - -// Const(x) is a convenient function for obtaining a const reference -// to x. This is useful for setting expectations on an overloaded -// const mock method, e.g. -// -// class MockFoo : public FooInterface { -// public: -// MOCK_METHOD0(Bar, int()); -// MOCK_CONST_METHOD0(Bar, int&()); -// }; -// -// MockFoo foo; -// // Expects a call to non-const MockFoo::Bar(). -// EXPECT_CALL(foo, Bar()); -// // Expects a call to const MockFoo::Bar(). -// EXPECT_CALL(Const(foo), Bar()); -template -inline const T& Const(const T& x) { return x; } - -// Constructs an Expectation object that references and co-owns exp. -inline Expectation::Expectation(internal::ExpectationBase& exp) // NOLINT - : expectation_base_(exp.GetHandle().expectation_base()) {} - -} // namespace testing - -// A separate macro is required to avoid compile errors when the name -// of the method used in call is a result of macro expansion. -// See CompilesWithMethodNameExpandedFromMacro tests in -// internal/gmock-spec-builders_test.cc for more details. -#define GMOCK_ON_CALL_IMPL_(obj, call) \ - ((obj).gmock_##call).InternalDefaultActionSetAt(__FILE__, __LINE__, \ - #obj, #call) -#define ON_CALL(obj, call) GMOCK_ON_CALL_IMPL_(obj, call) - -#define GMOCK_EXPECT_CALL_IMPL_(obj, call) \ - ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call) -#define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call) - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_ diff --git a/lib/gmock/include/gmock/gmock.h b/lib/gmock/include/gmock/gmock.h deleted file mode 100644 index ba9fa286..00000000 --- a/lib/gmock/include/gmock/gmock.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This is the main header file a user should include. - -#ifndef GMOCK_INCLUDE_GMOCK_GMOCK_H_ -#define GMOCK_INCLUDE_GMOCK_GMOCK_H_ - -// This file implements the following syntax: -// -// ON_CALL(mock_object.Method(...)) -// .With(...) ? -// .WillByDefault(...); -// -// where With() is optional and WillByDefault() must appear exactly -// once. -// -// EXPECT_CALL(mock_object.Method(...)) -// .With(...) ? -// .Times(...) ? -// .InSequence(...) * -// .WillOnce(...) * -// .WillRepeatedly(...) ? -// .RetiresOnSaturation() ? ; -// -// where all clauses are optional and WillOnce() can be repeated. - -#include "gmock/gmock-actions.h" -#include "gmock/gmock-cardinalities.h" -#include "gmock/gmock-generated-actions.h" -#include "gmock/gmock-generated-function-mockers.h" -#include "gmock/gmock-generated-matchers.h" -#include "gmock/gmock-more-actions.h" -#include "gmock/gmock-generated-nice-strict.h" -#include "gmock/gmock-matchers.h" -#include "gmock/internal/gmock-internal-utils.h" - -namespace testing { - -// Declares Google Mock flags that we want a user to use programmatically. -GMOCK_DECLARE_bool_(catch_leaked_mocks); -GMOCK_DECLARE_string_(verbose); - -// Initializes Google Mock. This must be called before running the -// tests. In particular, it parses the command line for the flags -// that Google Mock recognizes. Whenever a Google Mock flag is seen, -// it is removed from argv, and *argc is decremented. -// -// No value is returned. Instead, the Google Mock flag variables are -// updated. -// -// Since Google Test is needed for Google Mock to work, this function -// also initializes Google Test and parses its flags, if that hasn't -// been done. -void InitGoogleMock(int* argc, char** argv); - -// This overloaded version can be used in Windows programs compiled in -// UNICODE mode. -void InitGoogleMock(int* argc, wchar_t** argv); - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_GMOCK_H_ diff --git a/lib/gmock/include/gmock/internal/gmock-generated-internal-utils.h b/lib/gmock/include/gmock/internal/gmock-generated-internal-utils.h deleted file mode 100644 index 1b52dceb..00000000 --- a/lib/gmock/include/gmock/internal/gmock-generated-internal-utils.h +++ /dev/null @@ -1,277 +0,0 @@ -// This file was GENERATED by a script. DO NOT EDIT BY HAND!!! - -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file contains template meta-programming utility classes needed -// for implementing Google Mock. - -#ifndef 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" - -namespace testing { - -template -class Matcher; - -namespace internal { - -// An IgnoredValue object can be implicitly constructed from ANY value. -// This is used in implementing the IgnoreResult(a) action. -class IgnoredValue { - public: - // This constructor template allows any value to be implicitly - // converted to IgnoredValue. The object has no data member and - // doesn't try to remember anything about the argument. We - // deliberately omit the 'explicit' keyword in order to allow the - // conversion to be implicit. - template - IgnoredValue(const T&) {} -}; - -// MatcherTuple::type is a tuple type where each field is a Matcher -// for the corresponding field in tuple type T. -template -struct MatcherTuple; - -template <> -struct MatcherTuple< ::std::tr1::tuple<> > { - typedef ::std::tr1::tuple< > type; -}; - -template -struct MatcherTuple< ::std::tr1::tuple > { - typedef ::std::tr1::tuple > type; -}; - -template -struct MatcherTuple< ::std::tr1::tuple > { - typedef ::std::tr1::tuple, Matcher > type; -}; - -template -struct MatcherTuple< ::std::tr1::tuple > { - typedef ::std::tr1::tuple, Matcher, Matcher > type; -}; - -template -struct MatcherTuple< ::std::tr1::tuple > { - typedef ::std::tr1::tuple, Matcher, Matcher, - Matcher > type; -}; - -template -struct MatcherTuple< ::std::tr1::tuple > { - typedef ::std::tr1::tuple, Matcher, Matcher, Matcher, - Matcher > type; -}; - -template -struct MatcherTuple< ::std::tr1::tuple > { - typedef ::std::tr1::tuple, Matcher, Matcher, Matcher, - Matcher, Matcher > type; -}; - -template -struct MatcherTuple< ::std::tr1::tuple > { - typedef ::std::tr1::tuple, Matcher, Matcher, Matcher, - Matcher, Matcher, Matcher > type; -}; - -template -struct MatcherTuple< ::std::tr1::tuple > { - typedef ::std::tr1::tuple, Matcher, Matcher, Matcher, - Matcher, Matcher, Matcher, Matcher > type; -}; - -template -struct MatcherTuple< ::std::tr1::tuple > { - typedef ::std::tr1::tuple, Matcher, Matcher, Matcher, - Matcher, Matcher, Matcher, Matcher, Matcher > type; -}; - -template -struct MatcherTuple< ::std::tr1::tuple > { - typedef ::std::tr1::tuple, Matcher, Matcher, Matcher, - Matcher, Matcher, Matcher, Matcher, Matcher, - Matcher > type; -}; - -// Template struct Function, where F must be a function type, contains -// the following typedefs: -// -// Result: the function's return type. -// ArgumentN: the type of the N-th argument, where N starts with 1. -// ArgumentTuple: the tuple type consisting of all parameters of F. -// ArgumentMatcherTuple: the tuple type consisting of Matchers for all -// parameters of F. -// MakeResultVoid: the function type obtained by substituting void -// for the return type of F. -// MakeResultIgnoredValue: -// the function type obtained by substituting Something -// for the return type of F. -template -struct Function; - -template -struct Function { - typedef R Result; - typedef ::std::tr1::tuple<> ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(); - typedef IgnoredValue MakeResultIgnoredValue(); -}; - -template -struct Function - : Function { - typedef A1 Argument1; - typedef ::std::tr1::tuple ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1); - typedef IgnoredValue MakeResultIgnoredValue(A1); -}; - -template -struct Function - : Function { - typedef A2 Argument2; - typedef ::std::tr1::tuple ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2); -}; - -template -struct Function - : Function { - typedef A3 Argument3; - typedef ::std::tr1::tuple ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3); -}; - -template -struct Function - : Function { - typedef A4 Argument4; - typedef ::std::tr1::tuple ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4); -}; - -template -struct Function - : Function { - typedef A5 Argument5; - typedef ::std::tr1::tuple ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5); -}; - -template -struct Function - : Function { - typedef A6 Argument6; - typedef ::std::tr1::tuple ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6); -}; - -template -struct Function - : Function { - typedef A7 Argument7; - typedef ::std::tr1::tuple ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7); -}; - -template -struct Function - : Function { - typedef A8 Argument8; - typedef ::std::tr1::tuple ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8); -}; - -template -struct Function - : Function { - typedef A9 Argument9; - typedef ::std::tr1::tuple ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8, - A9); -}; - -template -struct Function - : Function { - typedef A10 Argument10; - typedef ::std::tr1::tuple ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); - typedef IgnoredValue MakeResultIgnoredValue(A1, A2, A3, A4, A5, A6, A7, A8, - A9, A10); -}; - -} // namespace internal - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ diff --git a/lib/gmock/include/gmock/internal/gmock-generated-internal-utils.h.pump b/lib/gmock/include/gmock/internal/gmock-generated-internal-utils.h.pump deleted file mode 100644 index 821e474e..00000000 --- a/lib/gmock/include/gmock/internal/gmock-generated-internal-utils.h.pump +++ /dev/null @@ -1,136 +0,0 @@ -$$ -*- mode: c++; -*- -$$ This is a Pump source file. Please use Pump to convert it to -$$ gmock-generated-function-mockers.h. -$$ -$var n = 10 $$ The maximum arity we support. -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file contains template meta-programming utility classes needed -// for implementing Google Mock. - -#ifndef 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" - -namespace testing { - -template -class Matcher; - -namespace internal { - -// An IgnoredValue object can be implicitly constructed from ANY value. -// This is used in implementing the IgnoreResult(a) action. -class IgnoredValue { - public: - // This constructor template allows any value to be implicitly - // converted to IgnoredValue. The object has no data member and - // doesn't try to remember anything about the argument. We - // deliberately omit the 'explicit' keyword in order to allow the - // conversion to be implicit. - template - IgnoredValue(const T&) {} -}; - -// MatcherTuple::type is a tuple type where each field is a Matcher -// for the corresponding field in tuple type T. -template -struct MatcherTuple; - - -$range i 0..n -$for i [[ -$range j 1..i -$var typename_As = [[$for j, [[typename A$j]]]] -$var As = [[$for j, [[A$j]]]] -$var matcher_As = [[$for j, [[Matcher]]]] -template <$typename_As> -struct MatcherTuple< ::std::tr1::tuple<$As> > { - typedef ::std::tr1::tuple<$matcher_As > type; -}; - - -]] -// Template struct Function, where F must be a function type, contains -// the following typedefs: -// -// Result: the function's return type. -// ArgumentN: the type of the N-th argument, where N starts with 1. -// ArgumentTuple: the tuple type consisting of all parameters of F. -// ArgumentMatcherTuple: the tuple type consisting of Matchers for all -// parameters of F. -// MakeResultVoid: the function type obtained by substituting void -// for the return type of F. -// MakeResultIgnoredValue: -// the function type obtained by substituting Something -// for the return type of F. -template -struct Function; - -template -struct Function { - typedef R Result; - typedef ::std::tr1::tuple<> ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid(); - typedef IgnoredValue MakeResultIgnoredValue(); -}; - - -$range i 1..n -$for i [[ -$range j 1..i -$var typename_As = [[$for j [[, typename A$j]]]] -$var As = [[$for j, [[A$j]]]] -$var matcher_As = [[$for j, [[Matcher]]]] -$range k 1..i-1 -$var prev_As = [[$for k, [[A$k]]]] -template -struct Function - : Function { - typedef A$i Argument$i; - typedef ::std::tr1::tuple<$As> ArgumentTuple; - typedef typename MatcherTuple::type ArgumentMatcherTuple; - typedef void MakeResultVoid($As); - typedef IgnoredValue MakeResultIgnoredValue($As); -}; - - -]] -} // namespace internal - -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_ diff --git a/lib/gmock/include/gmock/internal/gmock-internal-utils.h b/lib/gmock/include/gmock/internal/gmock-internal-utils.h deleted file mode 100644 index f0fd8682..00000000 --- a/lib/gmock/include/gmock/internal/gmock-internal-utils.h +++ /dev/null @@ -1,463 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file defines some utilities useful for implementing Google -// Mock. They are subject to change without notice, so please DO NOT -// USE THEM IN USER CODE. - -#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ -#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ - -#include -#include // NOLINT -#include - -#include "gmock/internal/gmock-generated-internal-utils.h" -#include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" - -namespace testing { -namespace internal { - -// 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 -// treated as one word. For example, both "FooBar123" and -// "foo_bar_123" are converted to "foo bar 123". -string ConvertIdentifierNameToWords(const char* id_name); - -// PointeeOf::type is the type of a value pointed to by a -// Pointer, which can be either a smart pointer or a raw pointer. The -// following default implementation is for the case where Pointer is a -// smart pointer. -template -struct PointeeOf { - // Smart pointer classes define type element_type as the type of - // their pointees. - typedef typename Pointer::element_type type; -}; -// This specialization is for the raw pointer case. -template -struct PointeeOf { typedef T type; }; // NOLINT - -// GetRawPointer(p) returns the raw pointer underlying p when p is a -// smart pointer, or returns p itself when p is already a raw pointer. -// The following default implementation is for the smart pointer case. -template -inline typename Pointer::element_type* GetRawPointer(const Pointer& p) { - return p.get(); -} -// This overloaded version is for the raw pointer case. -template -inline Element* GetRawPointer(Element* p) { return p; } - -// This comparator allows linked_ptr to be stored in sets. -template -struct LinkedPtrLessThan { - bool operator()(const ::testing::internal::linked_ptr& lhs, - const ::testing::internal::linked_ptr& rhs) const { - return lhs.get() < rhs.get(); - } -}; - -// Symbian compilation can be done with wchar_t being either a native -// type or a typedef. Using Google Mock with OpenC without 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 -// same as unsigned short when the compiler option /Zc:wchar_t- is -// specified. It defines _NATIVE_WCHAR_T_DEFINED symbol when wchar_t -// is a native type. -#if (GTEST_OS_SYMBIAN && defined(_STLP_NO_WCHAR_T)) || \ - (defined(_MSC_VER) && !defined(_NATIVE_WCHAR_T_DEFINED)) -// wchar_t is a typedef. -#else -# define GMOCK_WCHAR_T_IS_NATIVE_ 1 -#endif - -// 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. -// -// Still, Google Mock is designed to work even if the user uses signed -// wchar_t or unsigned wchar_t (obviously, assuming the compiler -// supports them). -// -// To gcc, -// wchar_t == signed wchar_t != unsigned wchar_t == unsigned int -#ifdef __GNUC__ -// signed/unsigned wchar_t are valid types. -# define GMOCK_HAS_SIGNED_WCHAR_T_ 1 -#endif - -// In what follows, we use the term "kind" to indicate whether a type -// is bool, an integer type (excluding bool), a floating-point type, -// or none of them. This categorization is useful for determining -// when a matcher argument type can be safely converted to another -// type in the implementation of SafeMatcherCast. -enum TypeKind { - kBool, kInteger, kFloatingPoint, kOther -}; - -// KindOf::value is the kind of type T. -template struct KindOf { - enum { value = kOther }; // The default kind. -}; - -// This macro declares that the kind of 'type' is 'kind'. -#define GMOCK_DECLARE_KIND_(type, kind) \ - template <> struct KindOf { enum { value = kind }; } - -GMOCK_DECLARE_KIND_(bool, kBool); - -// All standard integer types. -GMOCK_DECLARE_KIND_(char, kInteger); -GMOCK_DECLARE_KIND_(signed char, kInteger); -GMOCK_DECLARE_KIND_(unsigned char, kInteger); -GMOCK_DECLARE_KIND_(short, kInteger); // NOLINT -GMOCK_DECLARE_KIND_(unsigned short, kInteger); // NOLINT -GMOCK_DECLARE_KIND_(int, kInteger); -GMOCK_DECLARE_KIND_(unsigned int, kInteger); -GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT -GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT - -#if GMOCK_WCHAR_T_IS_NATIVE_ -GMOCK_DECLARE_KIND_(wchar_t, kInteger); -#endif - -// Non-standard integer types. -GMOCK_DECLARE_KIND_(Int64, kInteger); -GMOCK_DECLARE_KIND_(UInt64, kInteger); - -// All standard floating-point types. -GMOCK_DECLARE_KIND_(float, kFloatingPoint); -GMOCK_DECLARE_KIND_(double, kFloatingPoint); -GMOCK_DECLARE_KIND_(long double, kFloatingPoint); - -#undef GMOCK_DECLARE_KIND_ - -// Evaluates to the kind of 'type'. -#define GMOCK_KIND_OF_(type) \ - static_cast< ::testing::internal::TypeKind>( \ - ::testing::internal::KindOf::value) - -// Evaluates to true iff integer type T is signed. -#define GMOCK_IS_SIGNED_(T) (static_cast(-1) < 0) - -// LosslessArithmeticConvertibleImpl::value -// is true iff arithmetic type From can be losslessly converted to -// arithmetic type To. -// -// 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 -// reference) built-in arithmetic types, kFromKind is the kind of -// From, and kToKind is the kind of To; the value is -// implementation-defined when the above pre-condition is violated. -template -struct LosslessArithmeticConvertibleImpl : public false_type {}; - -// Converting bool to bool is lossless. -template <> -struct LosslessArithmeticConvertibleImpl - : public true_type {}; // NOLINT - -// Converting bool to any integer type is lossless. -template -struct LosslessArithmeticConvertibleImpl - : public true_type {}; // NOLINT - -// Converting bool to any floating-point type is lossless. -template -struct LosslessArithmeticConvertibleImpl - : public true_type {}; // NOLINT - -// Converting an integer to bool is lossy. -template -struct LosslessArithmeticConvertibleImpl - : public false_type {}; // NOLINT - -// Converting an integer to another non-bool integer is lossless iff -// the target type's range encloses the source type's range. -template -struct LosslessArithmeticConvertibleImpl - : public bool_constant< - // When converting from a smaller size to a larger size, we are - // fine as long as we are not converting from signed to unsigned. - ((sizeof(From) < sizeof(To)) && - (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) || - // When converting between the same size, the signedness must match. - ((sizeof(From) == sizeof(To)) && - (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT - -#undef GMOCK_IS_SIGNED_ - -// Converting an integer to a floating-point type may be lossy, since -// the format of a floating-point number is implementation-defined. -template -struct LosslessArithmeticConvertibleImpl - : public false_type {}; // NOLINT - -// Converting a floating-point to bool is lossy. -template -struct LosslessArithmeticConvertibleImpl - : public false_type {}; // NOLINT - -// Converting a floating-point to an integer is lossy. -template -struct LosslessArithmeticConvertibleImpl - : public false_type {}; // NOLINT - -// Converting a floating-point to another floating-point is lossless -// iff the target type is at least as big as the source type. -template -struct LosslessArithmeticConvertibleImpl< - kFloatingPoint, From, kFloatingPoint, To> - : public bool_constant {}; // NOLINT - -// LosslessArithmeticConvertible::value is true iff arithmetic -// type From can be losslessly converted to arithmetic type To. -// -// 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 -// reference) built-in arithmetic types; the value is -// implementation-defined when the above pre-condition is violated. -template -struct LosslessArithmeticConvertible - : public LosslessArithmeticConvertibleImpl< - GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT - -// This interface knows how to report a Google Mock failure (either -// non-fatal or fatal). -class FailureReporterInterface { - public: - // The type of a failure (either non-fatal or fatal). - enum FailureType { - NONFATAL, FATAL - }; - - virtual ~FailureReporterInterface() {} - - // Reports a failure that occurred at the given source file location. - virtual void ReportFailure(FailureType type, const char* file, int line, - const string& message) = 0; -}; - -// Returns the failure reporter used by Google Mock. -FailureReporterInterface* GetFailureReporter(); - -// Asserts that condition is true; aborts the process with the given -// message if condition is false. We cannot use LOG(FATAL) or CHECK() -// as Google Mock might be used to mock the log sink itself. We -// inline this function to prevent it from showing up in the stack -// trace. -inline void Assert(bool condition, const char* file, int line, - const string& msg) { - if (!condition) { - GetFailureReporter()->ReportFailure(FailureReporterInterface::FATAL, - file, line, msg); - } -} -inline void Assert(bool condition, const char* file, int line) { - Assert(condition, file, line, "Assertion failed."); -} - -// Verifies that condition is true; generates a non-fatal failure if -// condition is false. -inline void Expect(bool condition, const char* file, int line, - const string& msg) { - if (!condition) { - GetFailureReporter()->ReportFailure(FailureReporterInterface::NONFATAL, - file, line, msg); - } -} -inline void Expect(bool condition, const char* file, int line) { - Expect(condition, file, line, "Expectation failed."); -} - -// Severity level of a log. -enum LogSeverity { - INFO = 0, - WARNING = 1 -}; - -// Valid values for the --gmock_verbose flag. - -// All logs (informational and warnings) are printed. -const char kInfoVerbosity[] = "info"; -// Only warnings are printed. -const char kWarningVerbosity[] = "warning"; -// No logs are printed. -const char kErrorVerbosity[] = "error"; - -// Returns true iff a log with the given severity is visible according -// to the --gmock_verbose flag. -bool LogIsVisible(LogSeverity severity); - -// Prints the given message to stdout iff 'severity' >= the level -// specified by the --gmock_verbose flag. If stack_frames_to_skip >= -// 0, also prints the stack trace excluding the top -// stack_frames_to_skip frames. In opt mode, any positive -// stack_frames_to_skip is treated as 0, since we don't know which -// function calls will be inlined by the compiler and need to be -// conservative. -void Log(LogSeverity severity, const string& message, int stack_frames_to_skip); - -// TODO(wan@google.com): group all type utilities together. - -// Type traits. - -// is_reference::value is non-zero iff T is a reference type. -template struct is_reference : public false_type {}; -template struct is_reference : public true_type {}; - -// type_equals::value is non-zero iff T1 and T2 are the same type. -template struct type_equals : public false_type {}; -template struct type_equals : public true_type {}; - -// remove_reference::type removes the reference from type T, if any. -template struct remove_reference { typedef T type; }; // NOLINT -template struct remove_reference { typedef T type; }; // NOLINT - -// Invalid() returns an invalid value of type T. This is useful -// 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 -// crashes). -template -inline T Invalid() { - return *static_cast::type*>(NULL); -} -template <> -inline void Invalid() {} - -// Given a raw type (i.e. having no top-level reference or const -// modifier) RawContainer that's either an STL-style container or a -// native array, class StlContainerView has the -// following members: -// -// - type is a type that provides an STL-style container view to -// (i.e. implements the STL container concept for) RawContainer; -// - const_reference is a type that provides a reference to a const -// RawContainer; -// - ConstReference(raw_container) returns a const reference to an STL-style -// container view to raw_container, which is a RawContainer. -// - Copy(raw_container) returns an STL-style container view of a -// copy of raw_container, which is a RawContainer. -// -// This generic version is used when RawContainer itself is already an -// STL-style container. -template -class StlContainerView { - public: - typedef RawContainer type; - typedef const type& const_reference; - - static const_reference ConstReference(const RawContainer& container) { - // Ensures that RawContainer is not a const type. - testing::StaticAssertTypeEq(); - return container; - } - static type Copy(const RawContainer& container) { return container; } -}; - -// This specialization is used when RawContainer is a native array type. -template -class StlContainerView { - public: - typedef GTEST_REMOVE_CONST_(Element) RawElement; - typedef internal::NativeArray type; - // NativeArray can represent a native array either by value or by - // reference (selected by a constructor argument), so 'const type' - // can be used to reference a const native array. We cannot - // 'typedef const type& const_reference' here, as that would mean - // ConstReference() has to return a reference to a local variable. - typedef const type const_reference; - - static const_reference ConstReference(const Element (&array)[N]) { - // Ensures that Element is not a const type. - testing::StaticAssertTypeEq(); -#if GTEST_OS_SYMBIAN - // The Nokia Symbian compiler confuses itself in template instantiation - // for this call without the cast to Element*: - // function call '[testing::internal::NativeArray].NativeArray( - // {lval} const char *[4], long, testing::internal::RelationToSource)' - // does not match - // 'testing::internal::NativeArray::NativeArray( - // char *const *, unsigned int, testing::internal::RelationToSource)' - // (instantiating: 'testing::internal::ContainsMatcherImpl - // ::Matches(const char * (&)[4]) const') - // (instantiating: 'testing::internal::StlContainerView:: - // ConstReference(const char * (&)[4])') - // (and though the N parameter type is mismatched in the above explicit - // conversion of it doesn't help - only the conversion of the array). - return type(const_cast(&array[0]), N, kReference); -#else - return type(array, N, kReference); -#endif // GTEST_OS_SYMBIAN - } - static type Copy(const Element (&array)[N]) { -#if GTEST_OS_SYMBIAN - return type(const_cast(&array[0]), N, kCopy); -#else - return type(array, N, kCopy); -#endif // GTEST_OS_SYMBIAN - } -}; - -// This specialization is used when RawContainer is a native array -// represented as a (pointer, size) tuple. -template -class StlContainerView< ::std::tr1::tuple > { - public: - typedef GTEST_REMOVE_CONST_( - typename internal::PointeeOf::type) RawElement; - typedef internal::NativeArray type; - typedef const type const_reference; - - static const_reference ConstReference( - const ::std::tr1::tuple& array) { - using ::std::tr1::get; - return type(get<0>(array), get<1>(array), kReference); - } - static type Copy(const ::std::tr1::tuple& array) { - using ::std::tr1::get; - return type(get<0>(array), get<1>(array), kCopy); - } -}; - -// The following specialization prevents the user from instantiating -// StlContainer with a reference type. -template class StlContainerView; - -} // namespace internal -} // namespace testing - -#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ diff --git a/lib/gmock/include/gmock/internal/gmock-port.h b/lib/gmock/include/gmock/internal/gmock-port.h deleted file mode 100644 index 3b9cc479..00000000 --- a/lib/gmock/include/gmock/internal/gmock-port.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: vadimb@google.com (Vadim Berman) -// -// Low-level types and utilities for porting Google Mock to various -// platforms. They are subject to change without notice. DO NOT USE -// THEM IN USER CODE. - -#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ -#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ - -#include -#include -#include - -// Most of the types needed for porting Google Mock are also required -// for Google Test and are defined in gtest-port.h. -#include "gtest/internal/gtest-linked_ptr.h" -#include "gtest/internal/gtest-port.h" - -// To avoid conditional compilation everywhere, we make it -// gmock-port.h's responsibility to #include the header implementing -// tr1/tuple. gmock-port.h does this via gtest-port.h, which is -// guaranteed to pull in the tuple header. - -// For MS Visual C++, check the compiler version. At least VS 2003 is -// required to compile Google Mock. -#if defined(_MSC_VER) && _MSC_VER < 1310 -# error "At least Visual C++ 2003 (7.1) is required to compile Google Mock." -#endif - -// Macro for referencing flags. This is public as we want the user to -// use this syntax to reference Google Mock flags. -#define GMOCK_FLAG(name) FLAGS_gmock_##name - -// Macros for declaring flags. -#define GMOCK_DECLARE_bool_(name) extern bool GMOCK_FLAG(name) -#define GMOCK_DECLARE_int32_(name) \ - extern ::testing::internal::Int32 GMOCK_FLAG(name) -#define GMOCK_DECLARE_string_(name) \ - extern ::testing::internal::String GMOCK_FLAG(name) - -// Macros for defining flags. -#define GMOCK_DEFINE_bool_(name, default_val, doc) \ - bool GMOCK_FLAG(name) = (default_val) -#define GMOCK_DEFINE_int32_(name, default_val, doc) \ - ::testing::internal::Int32 GMOCK_FLAG(name) = (default_val) -#define GMOCK_DEFINE_string_(name, default_val, doc) \ - ::testing::internal::String GMOCK_FLAG(name) = (default_val) - -#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_ diff --git a/lib/gmock/src/gmock-all.cc b/lib/gmock/src/gmock-all.cc deleted file mode 100644 index 7aebce7a..00000000 --- a/lib/gmock/src/gmock-all.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) -// -// Google C++ Mocking Framework (Google Mock) -// -// This file #includes all Google Mock implementation .cc files. The -// purpose is to allow a user to build Google Mock by compiling this -// file alone. - -// This line ensures that gmock.h can be compiled on its own, even -// when it's fused. -#include "gmock/gmock.h" - -// The following lines pull in the real gmock *.cc files. -#include "src/gmock-cardinalities.cc" -#include "src/gmock-internal-utils.cc" -#include "src/gmock-matchers.cc" -#include "src/gmock-spec-builders.cc" -#include "src/gmock.cc" diff --git a/lib/gmock/src/gmock-cardinalities.cc b/lib/gmock/src/gmock-cardinalities.cc deleted file mode 100644 index 1a7902b4..00000000 --- a/lib/gmock/src/gmock-cardinalities.cc +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements cardinalities. - -#include "gmock/gmock-cardinalities.h" - -#include -#include // NOLINT -#include -#include -#include "gmock/internal/gmock-internal-utils.h" -#include "gtest/gtest.h" - -namespace testing { - -namespace { - -// Implements the Between(m, n) cardinality. -class BetweenCardinalityImpl : public CardinalityInterface { - public: - BetweenCardinalityImpl(int min, int max) - : min_(min >= 0 ? min : 0), - max_(max >= min_ ? max : min_) { - std::stringstream ss; - if (min < 0) { - ss << "The invocation lower bound must be >= 0, " - << "but is actually " << min << "."; - internal::Expect(false, __FILE__, __LINE__, ss.str()); - } else if (max < 0) { - ss << "The invocation upper bound must be >= 0, " - << "but is actually " << max << "."; - internal::Expect(false, __FILE__, __LINE__, ss.str()); - } else if (min > max) { - ss << "The invocation upper bound (" << max - << ") must be >= the invocation lower bound (" << min - << ")."; - internal::Expect(false, __FILE__, __LINE__, ss.str()); - } - } - - // Conservative estimate on the lower/upper bound of the number of - // calls allowed. - virtual int ConservativeLowerBound() const { return min_; } - virtual int ConservativeUpperBound() const { return max_; } - - virtual bool IsSatisfiedByCallCount(int call_count) const { - return min_ <= call_count && call_count <= max_ ; - } - - virtual bool IsSaturatedByCallCount(int call_count) const { - return call_count >= max_; - } - - virtual void DescribeTo(::std::ostream* os) const; - private: - const int min_; - const int max_; - - GTEST_DISALLOW_COPY_AND_ASSIGN_(BetweenCardinalityImpl); -}; - -// Formats "n times" in a human-friendly way. -inline internal::string FormatTimes(int n) { - if (n == 1) { - return "once"; - } else if (n == 2) { - return "twice"; - } else { - std::stringstream ss; - ss << n << " times"; - return ss.str(); - } -} - -// Describes the Between(m, n) cardinality in human-friendly text. -void BetweenCardinalityImpl::DescribeTo(::std::ostream* os) const { - if (min_ == 0) { - if (max_ == 0) { - *os << "never called"; - } else if (max_ == INT_MAX) { - *os << "called any number of times"; - } else { - *os << "called at most " << FormatTimes(max_); - } - } else if (min_ == max_) { - *os << "called " << FormatTimes(min_); - } else if (max_ == INT_MAX) { - *os << "called at least " << FormatTimes(min_); - } else { - // 0 < min_ < max_ < INT_MAX - *os << "called between " << min_ << " and " << max_ << " times"; - } -} - -} // Unnamed namespace - -// Describes the given call count to an ostream. -void Cardinality::DescribeActualCallCountTo(int actual_call_count, - ::std::ostream* os) { - if (actual_call_count > 0) { - *os << "called " << FormatTimes(actual_call_count); - } else { - *os << "never called"; - } -} - -// Creates a cardinality that allows at least n calls. -Cardinality AtLeast(int n) { return Between(n, INT_MAX); } - -// Creates a cardinality that allows at most n calls. -Cardinality AtMost(int n) { return Between(0, n); } - -// Creates a cardinality that allows any number of calls. -Cardinality AnyNumber() { return AtLeast(0); } - -// Creates a cardinality that allows between min and max calls. -Cardinality Between(int min, int max) { - return Cardinality(new BetweenCardinalityImpl(min, max)); -} - -// Creates a cardinality that allows exactly n calls. -Cardinality Exactly(int n) { return Between(n, n); } - -} // namespace testing diff --git a/lib/gmock/src/gmock-internal-utils.cc b/lib/gmock/src/gmock-internal-utils.cc deleted file mode 100644 index dd38132a..00000000 --- a/lib/gmock/src/gmock-internal-utils.cc +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file defines some utilities useful for implementing Google -// Mock. They are subject to change without notice, so please DO NOT -// USE THEM IN USER CODE. - -#include "gmock/internal/gmock-internal-utils.h" - -#include -#include // NOLINT -#include -#include "gmock/gmock.h" -#include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" - -namespace testing { -namespace internal { - -// 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 -// treated as one word. For example, both "FooBar123" and -// "foo_bar_123" are converted to "foo bar 123". -string ConvertIdentifierNameToWords(const char* id_name) { - string result; - char prev_char = '\0'; - for (const char* p = id_name; *p != '\0'; prev_char = *(p++)) { - // We don't care about the current locale as the input is - // guaranteed to be a valid C++ identifier name. - const bool starts_new_word = IsUpper(*p) || - (!IsAlpha(prev_char) && IsLower(*p)) || - (!IsDigit(prev_char) && IsDigit(*p)); - - if (IsAlNum(*p)) { - if (starts_new_word && result != "") - result += ' '; - result += ToLower(*p); - } - } - return result; -} - -// This class reports Google Mock failures as Google Test failures. A -// user can define another class in a similar fashion if he intends to -// use Google Mock with a testing framework other than Google Test. -class GoogleTestFailureReporter : public FailureReporterInterface { - public: - virtual void ReportFailure(FailureType type, const char* file, int line, - const string& message) { - AssertHelper(type == FATAL ? - TestPartResult::kFatalFailure : - TestPartResult::kNonFatalFailure, - file, - line, - message.c_str()) = Message(); - if (type == FATAL) { - posix::Abort(); - } - } -}; - -// Returns the global failure reporter. Will create a -// GoogleTestFailureReporter and return it the first time called. -FailureReporterInterface* GetFailureReporter() { - // Points to the global failure reporter used by Google Mock. gcc - // guarantees that the following use of failure_reporter is - // thread-safe. We may need to add additional synchronization to - // protect failure_reporter if we port Google Mock to other - // compilers. - static FailureReporterInterface* const failure_reporter = - new GoogleTestFailureReporter(); - return failure_reporter; -} - -// Protects global resources (stdout in particular) used by Log(). -static GTEST_DEFINE_STATIC_MUTEX_(g_log_mutex); - -// Returns true iff a log with the given severity is visible according -// to the --gmock_verbose flag. -bool LogIsVisible(LogSeverity severity) { - if (GMOCK_FLAG(verbose) == kInfoVerbosity) { - // Always show the log if --gmock_verbose=info. - return true; - } else if (GMOCK_FLAG(verbose) == kErrorVerbosity) { - // Always hide it if --gmock_verbose=error. - return false; - } else { - // If --gmock_verbose is neither "info" nor "error", we treat it - // as "warning" (its default value). - return severity == WARNING; - } -} - -// Prints the given message to stdout iff 'severity' >= the level -// specified by the --gmock_verbose flag. If stack_frames_to_skip >= -// 0, also prints the stack trace excluding the top -// stack_frames_to_skip frames. In opt mode, any positive -// stack_frames_to_skip is treated as 0, since we don't know which -// function calls will be inlined by the compiler and need to be -// conservative. -void Log(LogSeverity severity, const string& message, - int stack_frames_to_skip) { - if (!LogIsVisible(severity)) - return; - - // Ensures that logs from different threads don't interleave. - MutexLock l(&g_log_mutex); - - // "using ::std::cout;" doesn't work with Symbian's STLport, where cout is a - // macro. - - if (severity == WARNING) { - // Prints a GMOCK WARNING marker to make the warnings easily searchable. - std::cout << "\nGMOCK WARNING:"; - } - // Pre-pends a new-line to message if it doesn't start with one. - if (message.empty() || message[0] != '\n') { - std::cout << "\n"; - } - std::cout << message; - if (stack_frames_to_skip >= 0) { -#ifdef NDEBUG - // In opt mode, we have to be conservative and skip no stack frame. - const int actual_to_skip = 0; -#else - // In dbg mode, we can do what the caller tell us to do (plus one - // for skipping this function's stack frame). - const int actual_to_skip = stack_frames_to_skip + 1; -#endif // NDEBUG - - // Appends a new-line to message if it doesn't end with one. - if (!message.empty() && *message.rbegin() != '\n') { - std::cout << "\n"; - } - std::cout << "Stack trace:\n" - << ::testing::internal::GetCurrentOsStackTraceExceptTop( - ::testing::UnitTest::GetInstance(), actual_to_skip); - } - std::cout << ::std::flush; -} - -} // namespace internal -} // namespace testing diff --git a/lib/gmock/src/gmock-matchers.cc b/lib/gmock/src/gmock-matchers.cc deleted file mode 100644 index a5e6824d..00000000 --- a/lib/gmock/src/gmock-matchers.cc +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements Matcher, Matcher, and -// utilities for defining matchers. - -#include "gmock/gmock-matchers.h" -#include "gmock/gmock-generated-matchers.h" - -#include -#include -#include - -namespace testing { - -// Constructs a matcher that matches a const string& whose value is -// equal to s. -Matcher::Matcher(const internal::string& s) { - *this = Eq(s); -} - -// Constructs a matcher that matches a const string& whose value is -// equal to s. -Matcher::Matcher(const char* s) { - *this = Eq(internal::string(s)); -} - -// Constructs a matcher that matches a string whose value is equal to s. -Matcher::Matcher(const internal::string& s) { *this = Eq(s); } - -// Constructs a matcher that matches a string whose value is equal to s. -Matcher::Matcher(const char* s) { - *this = Eq(internal::string(s)); -} - -namespace internal { - -// Joins a vector of strings as if they are fields of a tuple; returns -// the joined string. -string JoinAsTuple(const Strings& fields) { - switch (fields.size()) { - case 0: - return ""; - case 1: - return fields[0]; - default: - string result = "(" + fields[0]; - for (size_t i = 1; i < fields.size(); i++) { - result += ", "; - result += fields[i]; - } - result += ")"; - return result; - } -} - -// Returns the description for a matcher defined using the MATCHER*() -// macro where the user-supplied description string is "", if -// 'negation' is false; otherwise returns the description of the -// negation of the matcher. 'param_values' contains a list of strings -// that are the print-out of the matcher's parameters. -string FormatMatcherDescription(bool negation, const char* matcher_name, - const Strings& param_values) { - string result = ConvertIdentifierNameToWords(matcher_name); - if (param_values.size() >= 1) - result += " " + JoinAsTuple(param_values); - return negation ? "not (" + result + ")" : result; -} - -} // namespace internal -} // namespace testing diff --git a/lib/gmock/src/gmock-spec-builders.cc b/lib/gmock/src/gmock-spec-builders.cc deleted file mode 100644 index aa33cc44..00000000 --- a/lib/gmock/src/gmock-spec-builders.cc +++ /dev/null @@ -1,797 +0,0 @@ -// Copyright 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -// Google Mock - a framework for writing C++ mock classes. -// -// This file implements the spec builder syntax (ON_CALL and -// EXPECT_CALL). - -#include "gmock/gmock-spec-builders.h" - -#include -#include // NOLINT -#include -#include -#include -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC -# include // NOLINT -#endif - -namespace testing { -namespace internal { - -// Protects the mock object registry (in class Mock), all function -// mockers, and all expectations. -GTEST_DEFINE_STATIC_MUTEX_(g_gmock_mutex); - -// 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); -} - -// Constructs an ExpectationBase object. -ExpectationBase::ExpectationBase(const char* a_file, - int a_line, - const string& a_source_text) - : file_(a_file), - line_(a_line), - source_text_(a_source_text), - cardinality_specified_(false), - cardinality_(Exactly(1)), - call_count_(0), - retired_(false), - extra_matcher_specified_(false), - repeated_action_specified_(false), - retires_on_saturation_(false), - last_clause_(kNone), - action_count_checked_(false) {} - -// Destructs an ExpectationBase object. -ExpectationBase::~ExpectationBase() {} - -// Explicitly specifies the cardinality of this expectation. Used by -// the subclasses to implement the .Times() clause. -void ExpectationBase::SpecifyCardinality(const Cardinality& a_cardinality) { - cardinality_specified_ = true; - cardinality_ = a_cardinality; -} - -// Retires all pre-requisites of this expectation. -void ExpectationBase::RetireAllPreRequisites() { - if (is_retired()) { - // We can take this short-cut as we never retire an expectation - // until we have retired all its pre-requisites. - return; - } - - for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); - it != immediate_prerequisites_.end(); ++it) { - ExpectationBase* const prerequisite = it->expectation_base().get(); - if (!prerequisite->is_retired()) { - prerequisite->RetireAllPreRequisites(); - prerequisite->Retire(); - } - } -} - -// Returns true iff all pre-requisites of this expectation have been -// satisfied. -// L >= g_gmock_mutex -bool ExpectationBase::AllPrerequisitesAreSatisfied() const { - g_gmock_mutex.AssertHeld(); - for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); - it != immediate_prerequisites_.end(); ++it) { - if (!(it->expectation_base()->IsSatisfied()) || - !(it->expectation_base()->AllPrerequisitesAreSatisfied())) - return false; - } - return true; -} - -// Adds unsatisfied pre-requisites of this expectation to 'result'. -// L >= g_gmock_mutex -void ExpectationBase::FindUnsatisfiedPrerequisites( - ExpectationSet* result) const { - g_gmock_mutex.AssertHeld(); - for (ExpectationSet::const_iterator it = immediate_prerequisites_.begin(); - it != immediate_prerequisites_.end(); ++it) { - if (it->expectation_base()->IsSatisfied()) { - // If *it is satisfied and has a call count of 0, some of its - // pre-requisites may not be satisfied yet. - if (it->expectation_base()->call_count_ == 0) { - it->expectation_base()->FindUnsatisfiedPrerequisites(result); - } - } else { - // Now that we know *it is unsatisfied, we are not so interested - // in whether its pre-requisites are satisfied. Therefore we - // don't recursively call FindUnsatisfiedPrerequisites() here. - *result += *it; - } - } -} - -// Describes how many times a function call matching this -// expectation has occurred. -// L >= g_gmock_mutex -void ExpectationBase::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"); -} - -// 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 ExpectationBase::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(untyped_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". - } -} - -// Implements the .Times() clause. -void ExpectationBase::UntypedTimes(const Cardinality& a_cardinality) { - if (last_clause_ == kTimes) { - 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; - - SpecifyCardinality(a_cardinality); -} - -// Points to the implicit sequence introduced by a living InSequence -// object (if any) in the current thread or NULL. -ThreadLocal g_gmock_implicit_sequence; - -// Reports an uninteresting call (whose description is in msg) in the -// manner specified by 'reaction'. -void ReportUninterestingCall(CallReaction reaction, const string& msg) { - switch (reaction) { - case ALLOW: - Log(INFO, msg, 3); - break; - case WARN: - Log(WARNING, msg, 3); - break; - default: // FAIL - Expect(false, NULL, -1, msg); - } -} - -UntypedFunctionMockerBase::UntypedFunctionMockerBase() - : mock_obj_(NULL), name_("") {} - -UntypedFunctionMockerBase::~UntypedFunctionMockerBase() {} - -// 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. -// L < g_gmock_mutex -void UntypedFunctionMockerBase::RegisterOwner(const void* mock_obj) { - { - MutexLock l(&g_gmock_mutex); - mock_obj_ = mock_obj; - } - Mock::Register(mock_obj, this); -} - -// 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 UntypedFunctionMockerBase::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 name of the function being mocked. Must be called -// after RegisterOwner() or SetOwnerAndName() has been called. -// L < g_gmock_mutex -const void* UntypedFunctionMockerBase::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); - Assert(mock_obj_ != NULL, __FILE__, __LINE__, - "MockObject() must not be called before RegisterOwner() or " - "SetOwnerAndName() has been called."); - mock_obj = mock_obj_; - } - return mock_obj; -} - -// Returns the name of this mock method. Must be called after -// SetOwnerAndName() has been called. -// L < g_gmock_mutex -const char* UntypedFunctionMockerBase::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); - Assert(name_ != NULL, __FILE__, __LINE__, - "Name() must not be called before SetOwnerAndName() has " - "been called."); - name = name_; - } - return name; -} - -// Calculates the result of invoking this mock function with the given -// arguments, prints it, and returns it. The caller is responsible -// for deleting the result. -// L < g_gmock_mutex -const UntypedActionResultHolderBase* -UntypedFunctionMockerBase::UntypedInvokeWith(const void* const untyped_args) { - if (untyped_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 this->UntypedPerformDefaultAction(untyped_args, ""); - } - - // Warns about the uninteresting call. - ::std::stringstream ss; - this->UntypedDescribeUninterestingCall(untyped_args, &ss); - - // Calculates the function result. - const UntypedActionResultHolderBase* const result = - this->UntypedPerformDefaultAction(untyped_args, ss.str()); - - // Prints the function result. - if (result != NULL) - result->PrintAsActionResult(&ss); - - ReportUninterestingCall(reaction, ss.str()); - return result; - } - - bool is_excessive = false; - ::std::stringstream ss; - ::std::stringstream why; - ::std::stringstream loc; - const void* untyped_action = NULL; - - // The UntypedFindMatchingExpectation() function acquires and - // releases g_gmock_mutex. - const ExpectationBase* const untyped_expectation = - this->UntypedFindMatchingExpectation( - untyped_args, &untyped_action, &is_excessive, - &ss, &why); - const bool found = untyped_expectation != NULL; - - // 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(INFO); - if (!need_to_report_call) { - // Perform the action without printing the call information. - return - untyped_action == NULL ? - this->UntypedPerformDefaultAction(untyped_args, "") : - this->UntypedPerformAction(untyped_action, untyped_args); - } - - ss << " Function call: " << Name(); - this->UntypedPrintArgs(untyped_args, &ss); - - // In case the action deletes a piece of the expectation, we - // generate the message beforehand. - if (found && !is_excessive) { - untyped_expectation->DescribeLocationTo(&loc); - } - - const UntypedActionResultHolderBase* const result = - untyped_action == NULL ? - this->UntypedPerformDefaultAction(untyped_args, ss.str()) : - this->UntypedPerformAction(untyped_action, untyped_args); - if (result != NULL) - 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, untyped_expectation->file(), - untyped_expectation->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; -} - -// Returns an Expectation object that references and co-owns exp, -// which must be an expectation on this mock function. -Expectation UntypedFunctionMockerBase::GetHandleOf(ExpectationBase* exp) { - for (UntypedExpectations::const_iterator it = - untyped_expectations_.begin(); - it != untyped_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. -} - -// Verifies that all expectations on this mock function have been -// satisfied. Reports one or more Google Test non-fatal failures -// and returns false if not. -// L >= g_gmock_mutex -bool UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked() { - g_gmock_mutex.AssertHeld(); - bool expectations_met = true; - for (UntypedExpectations::const_iterator it = - untyped_expectations_.begin(); - it != untyped_expectations_.end(); ++it) { - ExpectationBase* const untyped_expectation = it->get(); - if (untyped_expectation->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 (!untyped_expectation->IsSatisfied()) { - expectations_met = false; - ::std::stringstream ss; - ss << "Actual function call count doesn't match " - << untyped_expectation->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. - untyped_expectation->MaybeDescribeExtraMatcherTo(&ss); - untyped_expectation->DescribeCallCountTo(&ss); - Expect(false, untyped_expectation->file(), - untyped_expectation->line(), ss.str()); - } - } - untyped_expectations_.clear(); - return expectations_met; -} - -} // namespace internal - -// Class Mock. - -namespace { - -typedef std::set FunctionMockers; - -// The current state of a mock object. Such information is needed for -// detecting leaked mock objects and explicitly verifying a mock's -// expectations. -struct MockObjectState { - MockObjectState() - : first_used_file(NULL), first_used_line(-1), leakable(false) {} - - // Where in the source file an ON_CALL or EXPECT_CALL is first - // invoked on this mock object. - const char* first_used_file; - int first_used_line; - ::std::string first_used_test_case; - ::std::string first_used_test; - bool leakable; // true iff it's OK to leak the object. - FunctionMockers function_mockers; // All registered methods of the object. -}; - -// A global registry holding the state of all mock objects that are -// alive. A mock object is added to this registry the first time -// Mock::AllowLeak(), ON_CALL(), or EXPECT_CALL() is called on it. It -// is removed from the registry in the mock object's destructor. -class MockObjectRegistry { - public: - // Maps a mock object (identified by its address) to its state. - typedef std::map StateMap; - - // This destructor will be called when a program exits, after all - // tests in it have been run. By then, there should be no mock - // object alive. Therefore we report any living object as test - // failure, unless the user explicitly asked us to ignore it. - ~MockObjectRegistry() { - // "using ::std::cout;" doesn't work with Symbian's STLport, where cout is - // a macro. - - if (!GMOCK_FLAG(catch_leaked_mocks)) - return; - - int leaked_count = 0; - for (StateMap::const_iterator it = states_.begin(); it != states_.end(); - ++it) { - if (it->second.leakable) // The user said it's fine to leak this object. - continue; - - // TODO(wan@google.com): Print the type of the leaked object. - // This can help the user identify the leaked object. - std::cout << "\n"; - const MockObjectState& state = it->second; - std::cout << internal::FormatFileLocation(state.first_used_file, - state.first_used_line); - std::cout << " ERROR: this mock object"; - if (state.first_used_test != "") { - std::cout << " (used in test " << state.first_used_test_case << "." - << state.first_used_test << ")"; - } - std::cout << " should be deleted but never is. Its address is @" - << it->first << "."; - leaked_count++; - } - if (leaked_count > 0) { - std::cout << "\nERROR: " << leaked_count - << " leaked mock " << (leaked_count == 1 ? "object" : "objects") - << " found at program exit.\n"; - std::cout.flush(); - ::std::cerr.flush(); - // RUN_ALL_TESTS() has already returned when this destructor is - // called. Therefore we cannot use the normal Google Test - // failure reporting mechanism. - _exit(1); // We cannot call exit() as it is not reentrant and - // may already have been called. - } - } - - StateMap& states() { return states_; } - private: - StateMap states_; -}; - -// Protected by g_gmock_mutex. -MockObjectRegistry g_mock_object_registry; - -// Maps a mock object to the reaction Google Mock should have when an -// uninteresting method is called. Protected by g_gmock_mutex. -std::map g_uninteresting_call_reaction; - -// Sets the reaction Google Mock should have when an uninteresting -// method of the given mock object is called. -// L < g_gmock_mutex -void SetReactionOnUninterestingCalls(const void* mock_obj, - internal::CallReaction reaction) { - internal::MutexLock l(&internal::g_gmock_mutex); - g_uninteresting_call_reaction[mock_obj] = reaction; -} - -} // namespace - -// Tells Google Mock to allow uninteresting calls on the given mock -// object. -// L < g_gmock_mutex -void Mock::AllowUninterestingCalls(const void* mock_obj) { - SetReactionOnUninterestingCalls(mock_obj, internal::ALLOW); -} - -// Tells Google Mock to warn the user about uninteresting calls on the -// given mock object. -// L < g_gmock_mutex -void Mock::WarnUninterestingCalls(const void* mock_obj) { - SetReactionOnUninterestingCalls(mock_obj, internal::WARN); -} - -// Tells Google Mock to fail uninteresting calls on the given mock -// object. -// L < g_gmock_mutex -void Mock::FailUninterestingCalls(const void* mock_obj) { - SetReactionOnUninterestingCalls(mock_obj, internal::FAIL); -} - -// Tells Google Mock the given mock object is being destroyed and its -// entry in the call-reaction table should be removed. -// L < g_gmock_mutex -void Mock::UnregisterCallReaction(const void* mock_obj) { - internal::MutexLock l(&internal::g_gmock_mutex); - g_uninteresting_call_reaction.erase(mock_obj); -} - -// Returns the reaction Google Mock will have on uninteresting calls -// made on the given mock object. -// L < g_gmock_mutex -internal::CallReaction Mock::GetReactionOnUninterestingCalls( - const void* mock_obj) { - internal::MutexLock l(&internal::g_gmock_mutex); - return (g_uninteresting_call_reaction.count(mock_obj) == 0) ? - internal::WARN : g_uninteresting_call_reaction[mock_obj]; -} - -// Tells Google Mock to ignore mock_obj when checking for leaked mock -// objects. -// L < g_gmock_mutex -void Mock::AllowLeak(const void* mock_obj) { - internal::MutexLock l(&internal::g_gmock_mutex); - g_mock_object_registry.states()[mock_obj].leakable = true; -} - -// Verifies and clears all expectations on the given mock object. If -// the expectations aren't satisfied, generates one or more Google -// Test non-fatal failures and returns false. -// L < g_gmock_mutex -bool Mock::VerifyAndClearExpectations(void* mock_obj) { - internal::MutexLock l(&internal::g_gmock_mutex); - return VerifyAndClearExpectationsLocked(mock_obj); -} - -// Verifies all expectations on the given mock object and clears its -// default actions and expectations. Returns true iff the -// verification was successful. -// L < g_gmock_mutex -bool Mock::VerifyAndClear(void* mock_obj) { - internal::MutexLock l(&internal::g_gmock_mutex); - ClearDefaultActionsLocked(mock_obj); - return VerifyAndClearExpectationsLocked(mock_obj); -} - -// Verifies and clears all expectations on the given mock object. If -// the expectations aren't satisfied, generates one or more Google -// Test non-fatal failures and returns false. -// L >= g_gmock_mutex -bool Mock::VerifyAndClearExpectationsLocked(void* mock_obj) { - internal::g_gmock_mutex.AssertHeld(); - if (g_mock_object_registry.states().count(mock_obj) == 0) { - // No EXPECT_CALL() was set on the given mock object. - return true; - } - - // Verifies and clears the expectations on each mock method in the - // given mock object. - bool expectations_met = true; - FunctionMockers& mockers = - g_mock_object_registry.states()[mock_obj].function_mockers; - for (FunctionMockers::const_iterator it = mockers.begin(); - it != mockers.end(); ++it) { - if (!(*it)->VerifyAndClearExpectationsLocked()) { - expectations_met = false; - } - } - - // We don't clear the content of mockers, as they may still be - // needed by ClearDefaultActionsLocked(). - return expectations_met; -} - -// Registers a mock object and a mock method it owns. -// L < g_gmock_mutex -void Mock::Register(const void* mock_obj, - internal::UntypedFunctionMockerBase* mocker) { - internal::MutexLock l(&internal::g_gmock_mutex); - g_mock_object_registry.states()[mock_obj].function_mockers.insert(mocker); -} - -// Tells Google Mock where in the source code mock_obj is used in an -// ON_CALL or EXPECT_CALL. In case mock_obj is leaked, this -// information helps the user identify which object it is. -// L < g_gmock_mutex -void Mock::RegisterUseByOnCallOrExpectCall( - const void* mock_obj, const char* file, int line) { - internal::MutexLock l(&internal::g_gmock_mutex); - MockObjectState& state = g_mock_object_registry.states()[mock_obj]; - if (state.first_used_file == NULL) { - state.first_used_file = file; - state.first_used_line = line; - const TestInfo* const test_info = - UnitTest::GetInstance()->current_test_info(); - if (test_info != NULL) { - // TODO(wan@google.com): record the test case name when the - // ON_CALL or EXPECT_CALL is invoked from SetUpTestCase() or - // TearDownTestCase(). - state.first_used_test_case = test_info->test_case_name(); - state.first_used_test = test_info->name(); - } - } -} - -// Unregisters a mock method; removes the owning mock object from the -// registry when the last mock method associated with it has been -// unregistered. This is called only in the destructor of -// FunctionMockerBase. -// L >= g_gmock_mutex -void Mock::UnregisterLocked(internal::UntypedFunctionMockerBase* mocker) { - internal::g_gmock_mutex.AssertHeld(); - for (MockObjectRegistry::StateMap::iterator it = - g_mock_object_registry.states().begin(); - it != g_mock_object_registry.states().end(); ++it) { - FunctionMockers& mockers = it->second.function_mockers; - if (mockers.erase(mocker) > 0) { - // mocker was in mockers and has been just removed. - if (mockers.empty()) { - g_mock_object_registry.states().erase(it); - } - return; - } - } -} - -// Clears all ON_CALL()s set on the given mock object. -// L >= g_gmock_mutex -void Mock::ClearDefaultActionsLocked(void* mock_obj) { - internal::g_gmock_mutex.AssertHeld(); - - if (g_mock_object_registry.states().count(mock_obj) == 0) { - // No ON_CALL() was set on the given mock object. - return; - } - - // Clears the default actions for each mock method in the given mock - // object. - FunctionMockers& mockers = - g_mock_object_registry.states()[mock_obj].function_mockers; - for (FunctionMockers::const_iterator it = mockers.begin(); - it != mockers.end(); ++it) { - (*it)->ClearDefaultActionsLocked(); - } - - // We don't clear the content of mockers, as they may still be - // needed by VerifyAndClearExpectationsLocked(). -} - -Expectation::Expectation() {} - -Expectation::Expectation( - const internal::linked_ptr& an_expectation_base) - : expectation_base_(an_expectation_base) {} - -Expectation::~Expectation() {} - -// Adds an expectation to a sequence. -void Sequence::AddExpectation(const Expectation& expectation) const { - if (*last_expectation_ != expectation) { - if (last_expectation_->expectation_base() != NULL) { - expectation.expectation_base()->immediate_prerequisites_ - += *last_expectation_; - } - *last_expectation_ = expectation; - } -} - -// Creates the implicit sequence if there isn't one. -InSequence::InSequence() { - if (internal::g_gmock_implicit_sequence.get() == NULL) { - internal::g_gmock_implicit_sequence.set(new Sequence); - sequence_created_ = true; - } else { - sequence_created_ = false; - } -} - -// Deletes the implicit sequence if it was created by the constructor -// of this object. -InSequence::~InSequence() { - if (sequence_created_) { - delete internal::g_gmock_implicit_sequence.get(); - internal::g_gmock_implicit_sequence.set(NULL); - } -} - -} // namespace testing diff --git a/lib/gmock/src/gmock.cc b/lib/gmock/src/gmock.cc deleted file mode 100644 index 700bcb2e..00000000 --- a/lib/gmock/src/gmock.cc +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -#include "gmock/gmock.h" -#include "gmock/internal/gmock-port.h" - -namespace testing { - -// TODO(wan@google.com): support using environment variables to -// control the flag values, like what Google Test does. - -GMOCK_DEFINE_bool_(catch_leaked_mocks, true, - "true iff Google Mock should report leaked mock objects " - "as failures."); - -GMOCK_DEFINE_string_(verbose, internal::kWarningVerbosity, - "Controls how verbose Google Mock's output is." - " Valid values:\n" - " info - prints all messages.\n" - " warning - prints warnings and errors.\n" - " error - prints errors only."); - -namespace internal { - -// Parses a string as a command line flag. The string should have the -// format "--gmock_flag=value". When def_optional is true, the -// "=value" part can be omitted. -// -// Returns the value of the flag, or NULL if the parsing failed. -static const char* ParseGoogleMockFlagValue(const char* str, - const char* flag, - bool def_optional) { - // str and flag must not be NULL. - if (str == NULL || flag == NULL) return NULL; - - // The flag must start with "--gmock_". - const String flag_str = String::Format("--gmock_%s", flag); - const size_t flag_len = flag_str.length(); - if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL; - - // Skips the flag name. - const char* flag_end = str + flag_len; - - // When def_optional is true, it's OK to not have a "=value" part. - if (def_optional && (flag_end[0] == '\0')) { - return flag_end; - } - - // If def_optional is true and there are more characters after the - // flag name, or if def_optional is false, there must be a '=' after - // the flag name. - if (flag_end[0] != '=') return NULL; - - // Returns the string after "=". - return flag_end + 1; -} - -// Parses a string for a Google Mock bool flag, in the form of -// "--gmock_flag=value". -// -// On success, stores the value of the flag in *value, and returns -// true. On failure, returns false without changing *value. -static bool ParseGoogleMockBoolFlag(const char* str, const char* flag, - bool* value) { - // Gets the value of the flag as a string. - const char* const value_str = ParseGoogleMockFlagValue(str, flag, true); - - // Aborts if the parsing failed. - if (value_str == NULL) return false; - - // Converts the string value to a bool. - *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F'); - return true; -} - -// Parses a string for a Google Mock string flag, in the form of -// "--gmock_flag=value". -// -// On success, stores the value of the flag in *value, and returns -// true. On failure, returns false without changing *value. -static bool ParseGoogleMockStringFlag(const char* str, const char* flag, - String* value) { - // Gets the value of the flag as a string. - const char* const value_str = ParseGoogleMockFlagValue(str, flag, false); - - // Aborts if the parsing failed. - if (value_str == NULL) return false; - - // Sets *value to the value of the flag. - *value = value_str; - return true; -} - -// The internal implementation of InitGoogleMock(). -// -// The type parameter CharType can be instantiated to either char or -// wchar_t. -template -void InitGoogleMockImpl(int* argc, CharType** argv) { - // Makes sure Google Test is initialized. InitGoogleTest() is - // idempotent, so it's fine if the user has already called it. - InitGoogleTest(argc, argv); - if (*argc <= 0) return; - - for (int i = 1; i != *argc; i++) { - const String arg_string = StreamableToString(argv[i]); - const char* const arg = arg_string.c_str(); - - // Do we see a Google Mock flag? - if (ParseGoogleMockBoolFlag(arg, "catch_leaked_mocks", - &GMOCK_FLAG(catch_leaked_mocks)) || - ParseGoogleMockStringFlag(arg, "verbose", &GMOCK_FLAG(verbose))) { - // Yes. Shift the remainder of the argv list left by one. Note - // that argv has (*argc + 1) elements, the last one always being - // NULL. The following loop moves the trailing NULL element as - // well. - for (int j = i; j != *argc; j++) { - argv[j] = argv[j + 1]; - } - - // Decrements the argument count. - (*argc)--; - - // We also need to decrement the iterator as we just removed - // an element. - i--; - } - } -} - -} // namespace internal - -// Initializes Google Mock. This must be called before running the -// tests. In particular, it parses a command line for the flags that -// Google Mock recognizes. Whenever a Google Mock flag is seen, it is -// removed from argv, and *argc is decremented. -// -// No value is returned. Instead, the Google Mock flag variables are -// updated. -// -// Since Google Test is needed for Google Mock to work, this function -// also initializes Google Test and parses its flags, if that hasn't -// been done. -void InitGoogleMock(int* argc, char** argv) { - internal::InitGoogleMockImpl(argc, argv); -} - -// This overloaded version can be used in Windows programs compiled in -// UNICODE mode. -void InitGoogleMock(int* argc, wchar_t** argv) { - internal::InitGoogleMockImpl(argc, argv); -} - -} // namespace testing diff --git a/lib/gmock/src/gmock_main.cc b/lib/gmock/src/gmock_main.cc deleted file mode 100644 index 9d8aea22..00000000 --- a/lib/gmock/src/gmock_main.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Author: wan@google.com (Zhanyong Wan) - -#include -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -// MS C++ compiler/linker has a bug on Windows (not on Windows CE), which -// causes a link error when _tmain is defined in a static library and UNICODE -// is enabled. For this reason instead of _tmain, main function is used on -// Windows. See the following link to track the current status of this bug: -// http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=394464 // NOLINT -#if GTEST_OS_WINDOWS_MOBILE -# include // NOLINT - -int _tmain(int argc, TCHAR** argv) { -#else -int main(int argc, char** argv) { -#endif // GTEST_OS_WINDOWS_MOBILE - std::cout << "Running main() from gmock_main.cc\n"; - // Since Google Mock depends on Google Test, InitGoogleMock() is - // also responsible for initializing Google Test. Therefore there's - // no need for calling testing::InitGoogleTest() separately. - testing::InitGoogleMock(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/lib/hippomocks/README.md b/lib/hippomocks/README.md new file mode 100644 index 00000000..d38390bd --- /dev/null +++ b/lib/hippomocks/README.md @@ -0,0 +1,6 @@ +Hippomocks +========== + +Single-header mocking framework. + +https://github.com/dascandy/hippomocks diff --git a/lib/hippomocks/hippomocks.h b/lib/hippomocks/hippomocks.h new file mode 100644 index 00000000..920ec55c --- /dev/null +++ b/lib/hippomocks/hippomocks.h @@ -0,0 +1,6294 @@ +// HippoMocks, a library for using mocks in unit testing of C++ code. +// Copyright (C) 2008, Bas van Tiel, Christian Rexwinkel, Mike Looijmans, +// Peter Bindels +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// +// You can also retrieve it from http://www.gnu.org/licenses/lgpl-2.1.html + +#ifndef HIPPOMOCKS_H +#define HIPPOMOCKS_H + +// If you want to put all HippoMocks symbols into the global namespace, use the define below. +//#define NO_HIPPOMOCKS_NAMESPACE + +// The DEFAULT_AUTOEXPECT is an option that determines whether tests are, by default, under- or +// overspecified. Auto-expect, by function, adds an expectation to the current ExpectCall that +// it will happen after the previous ExpectCall. For many people this is an intuitive and logical +// thing when writing a C++ program. Usually, this makes your test workable but overspecified. +// Overspecified means that your test will fail on working code that does things in a different +// order. The alternative, underspecified, allows code to pass your test that does things in a +// different order, where that different order should be considered wrong. Consider reading a +// file, where it needs to be first opened, then read and then closed. +// +// The default is to make tests overspecified. At least it prevents faulty code from passing +// unit tests. To locally disable (or enable) this behaviour, set the boolean autoExpect on your +// MockRepository to false (or true). To globally override, redefine DEFAULT_AUTOEXPECT to false. +#ifndef DEFAULT_AUTOEXPECT +#define DEFAULT_AUTOEXPECT true +#endif + +#ifdef NO_HIPPOMOCKS_NAMESPACE +#define HM_NS +#else +#define HM_NS HippoMocks:: +#endif + +#ifdef _MSC_VER +#ifdef _WIN64 +#define WINCALL +#else +#define WINCALL __stdcall +#endif +#endif +#ifndef DEBUGBREAK +#ifdef _MSC_VER +extern "C" __declspec(dllimport) int WINCALL IsDebuggerPresent(); +extern "C" __declspec(dllimport) void WINCALL DebugBreak(); +#define DEBUGBREAK(e) if (IsDebuggerPresent()) DebugBreak(); else (void)0 +#else +#define DEBUGBREAK(e) +#endif +#endif + +#ifndef DONTCARE_NAME +#define DONTCARE_NAME _ +#endif + +#ifndef VIRT_FUNC_LIMIT +#define VIRT_FUNC_LIMIT 1024 +#elif VIRT_FUNC_LIMIT > 1024 +#error Adjust the code to support more than 1024 virtual functions before setting the VIRT_FUNC_LIMIT above 1024 +#endif + +#ifdef __GNUC__ +#define EXTRA_DESTRUCTOR +#endif + +#ifdef __EDG__ +#define FUNCTION_BASE 3 +#define FUNCTION_STRIDE 2 +#else +#define FUNCTION_BASE 0 +#define FUNCTION_STRIDE 1 +#endif + +#if defined(_M_IX86) || defined(__i386__) || defined(i386) || defined(_X86_) || defined(__THW_INTEL) || defined(__x86_64__) || defined(_M_X64) +#define SOME_X86 +#elif defined(arm) || defined(__arm__) || defined(ARM) || defined(_ARM_) +#define SOME_ARM +#endif + +#if defined(__x86_64__) || defined(_M_X64) +#define CMOCK_FUNC_PLATFORMIS64BIT +#endif + +#ifdef SOME_X86 +#if defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)) +#define _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT +#elif defined(__linux__) && defined(__GNUC__) +#define _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT +#elif defined(__APPLE__) +#define _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT +#endif +#elif defined(SOME_ARM) && defined(__GNUC__) +#define _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT + +// This clear-cache is *required*. The tests will fail if you remove it. +extern "C" void __clear_cache(char *beg, char *end); +#endif + +#if defined(__GNUC__) && !defined(__EXCEPTIONS) +#define HM_NO_EXCEPTIONS +class X{}; +#define BASE_EXCEPTION X +#else +#ifndef BASE_EXCEPTION +#define BASE_EXCEPTION std::exception +#include +#endif +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +// these warnings are pointless and huge, and will confuse new users. +#pragma warning(push) +// If you can't generate an assignment operator the least you can do is shut up. +#pragma warning(disable: 4512) +// Alignment not right in a union? +#pragma warning(disable: 4121) +// No deprecated warnings on functions that really aren't deprecated at all. +#pragma warning(disable: 4996) + +// Tell Microsoft to conform to C++ (as far as is possible...) +#pragma pointers_to_members(full_generality, virtual_inheritance) +#endif + +#ifndef NO_HIPPOMOCKS_NAMESPACE +namespace HippoMocks +{ +#endif + +//Type-safe exception wrapping +class ExceptionHolder +{ +public: + virtual ~ExceptionHolder() {} + virtual void rethrow() = 0; + template + static ExceptionHolder *Create(T ex); +}; + +template +class ExceptionWrapper : public ExceptionHolder { + T exception; +public: + ExceptionWrapper(T exception) : exception(exception) {} + void rethrow() { throw exception; } +}; + +template +ExceptionHolder *ExceptionHolder::Create(T ex) +{ + return new ExceptionWrapper(ex); +} + +#ifdef HM_NO_EXCEPTIONS +#define RAISEEXCEPTION(e) { std::string err = e.what(); DEBUGBREAK(e); printf("Mock error found - Fatal due to no exception support:\n"); \ + printf("%s\n", err.c_str()); \ + abort(); exit(-1); } +#define RAISELATENTEXCEPTION(e) { std::string err = e.what(); DEBUGBREAK(e); printf("Mock error found - Fatal due to no exception support:\n"); \ + printf("%s\n", err.c_str()); \ + abort(); exit(-1); } +#else +#define RAISEEXCEPTION(e) { DEBUGBREAK(e); throw e; } +#define RAISELATENTEXCEPTION(e) { DEBUGBREAK(e); if (std::uncaught_exception()) \ + MockRepoInstanceHolder<0>::instance->SetLatentException(ExceptionHolder::Create(e)); \ + else throw e; } +#endif + +#ifdef _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT +#include + +#if defined(_WIN32) +#ifndef NO_HIPPOMOCKS_NAMESPACE +} +#endif + +// De-windows.h-ified import to avoid including that file. +#ifdef _WIN64 +extern "C" __declspec(dllimport) int WINCALL VirtualProtect(void *func, unsigned long long byteCount, unsigned long flags, unsigned long *oldFlags); +#else +extern "C" __declspec(dllimport) int WINCALL VirtualProtect(void *func, unsigned long byteCount, unsigned long flags, unsigned long *oldFlags); +#endif + +#ifndef PAGE_EXECUTE_READWRITE +#define PAGE_EXECUTE_READWRITE 0x40 +#endif + +#ifndef NO_HIPPOMOCKS_NAMESPACE +namespace HippoMocks { +#endif + +class Unprotect +{ +public: + Unprotect(void *location, size_t byteCount) + : origFunc(location) + , byteCount(byteCount) + { + VirtualProtect(origFunc, byteCount, PAGE_EXECUTE_READWRITE, &oldprotect); + } + ~Unprotect() + { + unsigned long dontcare; + VirtualProtect(origFunc, byteCount, oldprotect, &dontcare); + } +private: + void *origFunc; + size_t byteCount; + unsigned long oldprotect; +}; +#else +#include +#include + +class Unprotect +{ +public: + Unprotect(void *location, size_t byteCount) + : origFunc((intptr_t)location & (~0xFFF)) + , byteCount(byteCount + ((intptr_t)location - origFunc)) + { + mprotect((void *)origFunc, this->byteCount, PROT_READ|PROT_WRITE|PROT_EXEC); + }; + ~Unprotect() + { + mprotect((void *)origFunc, byteCount, PROT_READ|PROT_EXEC); + } +private: + intptr_t origFunc; + int byteCount; +}; +#endif + +typedef unsigned int e9ptrsize_t; + +template +T horrible_cast(U u) +{ + union { T t; U u; } un; + un.u = u; + return un.t; +} + +class Replace +{ +private: + void *origFunc; + char backupData[16]; // typical use is 5 for 32-bit and 14 for 64-bit code. +public: + template + Replace(T funcptr, T replacement) + : origFunc(horrible_cast(funcptr)) + { + Unprotect _allow_write(origFunc, sizeof(backupData)); + memcpy(backupData, origFunc, sizeof(backupData)); +#ifdef SOME_X86 +#ifdef CMOCK_FUNC_PLATFORMIS64BIT + if (llabs((long long)origFunc - (long long)replacement) < 0x80000000LL) { +#endif + *(unsigned char *)origFunc = 0xE9; + *(e9ptrsize_t*)(horrible_cast(origFunc) + 1) = (e9ptrsize_t)(horrible_cast(replacement) - horrible_cast(origFunc) - sizeof(e9ptrsize_t) - 1); +#ifdef CMOCK_FUNC_PLATFORMIS64BIT + } else { + unsigned char *funcptr = (unsigned char *)origFunc; + funcptr[0] = 0xFF; // jmp (rip + imm32) + funcptr[1] = 0x25; + funcptr[2] = 0x00; // imm32 of 0, so immediately after the instruction + funcptr[3] = 0x00; + funcptr[4] = 0x00; + funcptr[5] = 0x00; + *(long long*)(horrible_cast(origFunc) + 6) = (long long)(horrible_cast(replacement)); + } +#endif +#elif defined(SOME_ARM) + unsigned int *rawptr = (unsigned int *)((intptr_t)(origFunc) & (~3)); + if ((intptr_t)origFunc & 1) { + rawptr[0] = 0x6800A001; + rawptr[1] = 0x46874687; + rawptr[2] = (intptr_t)replacement; + } else { + rawptr[0] = 0xE59FF000; + rawptr[1] = (intptr_t)replacement; + rawptr[2] = (intptr_t)replacement; + } + __clear_cache((char *)rawptr, (char *)rawptr+16); +#endif + } + ~Replace() + { + Unprotect _allow_write(origFunc, sizeof(backupData)); + memcpy(origFunc, backupData, sizeof(backupData)); +#ifdef SOME_ARM + unsigned int *rawptr = (unsigned int *)((intptr_t)(origFunc) & (~3)); + __clear_cache((char *)rawptr, (char *)rawptr+16); +#endif + } +}; +#endif + +class MockRepository; + +struct +RegistrationType +{ + RegistrationType( unsigned minimum, unsigned max ) : minimum( minimum ), maximum( max ) {} + unsigned minimum; + unsigned maximum; +}; + +inline +bool operator==( RegistrationType const& rhs, RegistrationType const& lhs ) +{ + return rhs.minimum == lhs.minimum && rhs.maximum == lhs.maximum; +} + + +const RegistrationType Any = RegistrationType((std::numeric_limits::min)(), (std::numeric_limits::max)()); +const RegistrationType Never = RegistrationType((std::numeric_limits::min)(), (std::numeric_limits::min)()); +const RegistrationType Once = RegistrationType( 1, 1 ); + + + + +// base type +class base_mock { +public: + void destroy() { unwriteVft(); delete this; } + virtual ~base_mock() {} + void *rewriteVft(void *newVf) + { + void *oldVf = *(void **)this; + *(void **)this = newVf; + return oldVf; + } + void reset() + { + unwriteVft(); + mock_reset(); + } + virtual void mock_reset() = 0; + void unwriteVft() + { + *(void **)this = (*(void ***)this)[VIRT_FUNC_LIMIT+1]; + } +}; + +template +class ByRef +{ +public: + explicit ByRef(T &arg) : arg(arg) {} + void operator()() { arg(); } + T &arg; +}; + +template +ByRef byRef(T &arg) { + return ByRef(arg); +} + +class NullType +{ +public: + bool operator==(const NullType &) const + { + return true; + } +}; + +class DontCare { +private: + inline DontCare &Instance(); +}; +static DontCare DONTCARE_NAME; +inline DontCare &DontCare::Instance() +{ + return DONTCARE_NAME; +} + +template +struct OutParam: public DontCare +{ + explicit OutParam(T value): value(value) {} + T value; +}; + +template +OutParam Out(T t) { return OutParam(t); } + +template +struct InParam; + +template +struct InParam: public DontCare +{ + explicit InParam(T& value): value(value) + { + } + T& value; +}; + +template +struct InParam: public DontCare +{ + explicit InParam(T*& value): value(value) + { + } + T*& value; +}; + +template +InParam In(T& t) { return InParam(t); } + +template +InParam In(T*& t) { return InParam(t); } + +struct NotPrintable { template NotPrintable(T const&) {} }; + +inline std::ostream &operator<<(std::ostream &os, NotPrintable const&) +{ + os << "???"; + return os; +} + +inline std::ostream &operator<<(std::ostream &os, DontCare const&) +{ + os << "_"; + return os; +} + +template +inline std::ostream &operator<<(std::ostream &os, ByRef &ref) { + os << "byRef(" << (T)ref << ")"; + return os; +} + +template +struct printArg +{ + static inline void print(std::ostream &os, T arg, bool withComma) + { + if (withComma) + os << ","; + os << arg; + } +}; + +template <> +struct printArg +{ + static void print(std::ostream &, NullType , bool) + { + } +}; + +class base_tuple +{ +protected: + base_tuple() + { + } +public: + virtual ~base_tuple() + { + } + virtual void printTo(std::ostream &os) const = 0; +}; + +template +struct no_cref { typedef X type; }; + +template +struct no_cref { typedef X type; }; + +template struct with_const { typedef const A type; }; +template struct with_const { typedef const A &type; }; +template struct with_const { typedef const A type; }; +template struct with_const { typedef const A &type; }; + +template struct base_type { typedef T type; }; +template struct base_type { typedef T type; }; +template struct base_type { typedef T type; }; +template struct base_type { typedef T type; }; + +template +struct comparer +{ + static inline bool compare(typename with_const::type a, typename with_const::type b) + { + return a == b; + } + static inline bool compare(DontCare, typename with_const::type) + { + return true; + } + template + static inline bool compare(const ByRef &a, typename with_const::type b) + { + return &a.arg == &b; + } +}; + +template +struct IsOutParamType { enum { value = false }; }; +template +struct IsOutParamType > { enum { value = true }; }; + +template +struct IsInParamType { enum { value = false }; }; +template +struct IsInParamType > { enum { value = true }; }; +template +struct IsInParamType > { enum { value = true }; }; + +template +struct do_assign; + +template +struct do_assign +{ + static void assign_to(T1 outparam, T2 *refparam) + { + *refparam = outparam.value; + } + static void assign_from(T1 inparam, T2 *refparam) + { + inparam.value = refparam; + } +}; + +template +struct do_assign +{ + static void assign_to(T1 outparam, T2 &refparam) + { + refparam = outparam.value; + } + static void assign_from(T1 inparam, T2 &refparam) + { + inparam.value = refparam; + } +}; + +template +struct do_assign +{ + static void assign_to(T1, T2) {} + static void assign_from(T1, T2) {} +}; + +template +void out_assign(T1 a, T2 b) +{ + do_assign::type>::value >::assign_to(a, b); +} + +template +void in_assign(T1 a, T2 b) +{ + do_assign::type>::value >::assign_from(a, b); +} + +template +class ref_tuple : public base_tuple +{ +public: + A a; + B b; + C c; + D d; + E e; + F f; + G g; + H h; + I i; + J j; + K k; + L l; + M m; + N n; + O o; + P p; + ref_tuple(A a = A(), B b = B(), C c = C(), D d = D(), E e = E(), F f = F(), G g = G(), H h = H(), I i = I(), J j = J(), K k = K(), L l = L(), M m = M(), N n = N(), O o = O(), P p = P()) + : a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h), i(i), j(j), k(k), l(l), m(m), n(n), o(o), p(p) + {} + virtual void printTo(std::ostream &os) const + { + os << "("; + printArg::print(os, a, false); + printArg::print(os, b, true); + printArg::print(os, c, true); + printArg::print(os, d, true); + printArg::print(os, e, true); + printArg::print(os, f, true); + printArg::print(os, g, true); + printArg::print(os, h, true); + printArg::print(os, i, true); + printArg::print(os, j, true); + printArg::print(os, k, true); + printArg::print(os, l, true); + printArg::print(os, m, true); + printArg::print(os, n, true); + printArg::print(os, o, true); + printArg

::compare(p, to.p)); + } + void assign_from(ref_tuple &from) + { + in_assign< typename store_as::type, A>(a, from.a); + in_assign< typename store_as::type, B>(b, from.b); + in_assign< typename store_as::type, C>(c, from.c); + in_assign< typename store_as::type, D>(d, from.d); + in_assign< typename store_as::type, E>(e, from.e); + in_assign< typename store_as::type, F>(f, from.f); + in_assign< typename store_as::type, G>(g, from.g); + in_assign< typename store_as::type, H>(h, from.h); + in_assign< typename store_as::type, I>(i, from.i); + in_assign< typename store_as::type, J>(j, from.j); + in_assign< typename store_as::type, K>(k, from.k); + in_assign< typename store_as::type, L>(l, from.l); + in_assign< typename store_as::type, M>(m, from.m); + in_assign< typename store_as::type, N>(n, from.n); + in_assign< typename store_as::type, O>(o, from.o); + in_assign< typename store_as::type, P>(p, from.p); + } + void assign_to(ref_tuple &to) + { + out_assign< typename store_as::type, A>(a, to.a); + out_assign< typename store_as::type, B>(b, to.b); + out_assign< typename store_as::type, C>(c, to.c); + out_assign< typename store_as::type, D>(d, to.d); + out_assign< typename store_as::type, E>(e, to.e); + out_assign< typename store_as::type, F>(f, to.f); + out_assign< typename store_as::type, G>(g, to.g); + out_assign< typename store_as::type, H>(h, to.h); + out_assign< typename store_as::type, I>(i, to.i); + out_assign< typename store_as::type, J>(j, to.j); + out_assign< typename store_as::type, K>(k, to.k); + out_assign< typename store_as::type, L>(l, to.l); + out_assign< typename store_as::type, M>(m, to.m); + out_assign< typename store_as::type, N>(n, to.n); + out_assign< typename store_as::type, O>(o, to.o); + out_assign< typename store_as::type, P>(p, to.p); + } + virtual void printTo(std::ostream &os) const + { + os << "("; + printArg::type>::print(os, a, false); + printArg::type>::print(os, b, true); + printArg::type>::print(os, c, true); + printArg::type>::print(os, d, true); + printArg::type>::print(os, e, true); + printArg::type>::print(os, f, true); + printArg::type>::print(os, g, true); + printArg::type>::print(os, h, true); + printArg::type>::print(os, i, true); + printArg::type>::print(os, j, true); + printArg::type>::print(os, k, true); + printArg::type>::print(os, l, true); + printArg::type>::print(os, m, true); + printArg::type>::print(os, n, true); + printArg::type>::print(os, o, true); + printArg::type>::print(os, p, true); + os << ")"; + } +}; + +inline std::ostream &operator<<(std::ostream &os, const MockRepository &repo); + +class BaseException +#ifndef HM_NO_EXCEPTIONS + : public BASE_EXCEPTION +#endif +{ +public: + ~BaseException() throw() {} + const char *what() const throw() { return txt.c_str(); } +protected: + std::string txt; +}; + +// exception types +class ExpectationException : public BaseException { +public: + ExpectationException(MockRepository *repo, const base_tuple *tuple, const char *funcName) + { + std::stringstream text; + text << "Function "; + text << funcName; + if (tuple) + tuple->printTo(text); + else + text << "(...)"; + text << " called with mismatching expectation!" << std::endl; + text << *repo; + txt = text.str(); + } +}; + +#ifdef LINUX_TARGET +#include +#endif + +class NotImplementedException : public BaseException { +public: + NotImplementedException(MockRepository *repo) + { + std::stringstream text; + text << "Function called without expectation!" << std::endl; + text << *repo; + +#ifdef LINUX_TARGET + void* stacktrace[256]; + size_t size = backtrace( stacktrace, sizeof(stacktrace) ); + if( size > 0 ) + { + text << "Stackdump:" << std::endl; + char **symbols = backtrace_symbols( stacktrace, size ); + for( size_t i = 0; i < size; i = i + 1 ) + { + text << symbols[i] << std::endl; + } + free( symbols ); + } +#endif + + txt = text.str(); + } +}; + +class CallMissingException : public BaseException { +public: + CallMissingException(MockRepository *repo) + { + std::stringstream text; + text << "Function with expectation not called!" << std::endl; + text << *repo; + txt = text.str(); + } +}; + +class ZombieMockException : public BaseException { +public: + ZombieMockException(MockRepository *repo) + { + std::stringstream text; + text << "Function called on mock that has already been destroyed!" << std::endl; + text << *repo; + +#ifdef LINUX_TARGET + void* stacktrace[256]; + size_t size = backtrace( stacktrace, sizeof(stacktrace) ); + if( size > 0 ) + { + text << "Stackdump:" << std::endl; + char **symbols = backtrace_symbols( stacktrace, size ); + for( size_t i = 0; i < size; i = i + 1 ) + { + text << symbols[i] << std::endl; + } + free( symbols ); + } +#endif + + txt = text.str(); + } +}; + +class NoResultSetUpException : public BaseException { +public: + NoResultSetUpException(MockRepository *repo, const base_tuple *tuple, const char *funcName) + { + std::stringstream text; + text << "No result set up on call to "; + text << funcName; + if (tuple) + tuple->printTo(text); + else + text << "(...)"; + text << std::endl; + text << *repo; + +#ifdef LINUX_TARGET + void* stacktrace[256]; + size_t size = backtrace( stacktrace, sizeof(stacktrace) ); + if( size > 0 ) + { + text << "Stackdump:" << std::endl; + char **symbols = backtrace_symbols( stacktrace, size ); + for( size_t i = 0; i < size; i = i + 1 ) + { + text << symbols[i] << std::endl; + } + free( symbols ); + } +#endif + + txt = text.str(); + } +}; + +// function-index-of-type +class func_index { +public: + int lci; + virtual int f0(int) { return lci=0; } virtual int f1(int) { return lci=1; } virtual int f2(int) { return lci=2; } virtual int f3(int) { return lci=3; } + virtual int f4(int) { return lci=4; } virtual int f5(int) { return lci=5; } virtual int f6(int) { return lci=6; } virtual int f7(int) { return lci=7; } + virtual int f8(int) { return lci=8; } virtual int f9(int) { return lci=9; } virtual int f10(int) { return lci=10; } virtual int f11(int) { return lci=11; } + virtual int f12(int) { return lci=12; } virtual int f13(int) { return lci=13; } virtual int f14(int) { return lci=14; } virtual int f15(int) { return lci=15; } + virtual int f16(int) { return lci=16; } virtual int f17(int) { return lci=17; } virtual int f18(int) { return lci=18; } virtual int f19(int) { return lci=19; } + virtual int f20(int) { return lci=20; } virtual int f21(int) { return lci=21; } virtual int f22(int) { return lci=22; } virtual int f23(int) { return lci=23; } + virtual int f24(int) { return lci=24; } virtual int f25(int) { return lci=25; } virtual int f26(int) { return lci=26; } virtual int f27(int) { return lci=27; } + virtual int f28(int) { return lci=28; } virtual int f29(int) { return lci=29; } virtual int f30(int) { return lci=30; } virtual int f31(int) { return lci=31; } + virtual int f32(int) { return lci=32; } virtual int f33(int) { return lci=33; } virtual int f34(int) { return lci=34; } virtual int f35(int) { return lci=35; } + virtual int f36(int) { return lci=36; } virtual int f37(int) { return lci=37; } virtual int f38(int) { return lci=38; } virtual int f39(int) { return lci=39; } + virtual int f40(int) { return lci=40; } virtual int f41(int) { return lci=41; } virtual int f42(int) { return lci=42; } virtual int f43(int) { return lci=43; } + virtual int f44(int) { return lci=44; } virtual int f45(int) { return lci=45; } virtual int f46(int) { return lci=46; } virtual int f47(int) { return lci=47; } + virtual int f48(int) { return lci=48; } virtual int f49(int) { return lci=49; } virtual int f50(int) { return lci=50; } virtual int f51(int) { return lci=51; } + virtual int f52(int) { return lci=52; } virtual int f53(int) { return lci=53; } virtual int f54(int) { return lci=54; } virtual int f55(int) { return lci=55; } + virtual int f56(int) { return lci=56; } virtual int f57(int) { return lci=57; } virtual int f58(int) { return lci=58; } virtual int f59(int) { return lci=59; } + virtual int f60(int) { return lci=60; } virtual int f61(int) { return lci=61; } virtual int f62(int) { return lci=62; } virtual int f63(int) { return lci=63; } + virtual int f64(int) { return lci=64; } virtual int f65(int) { return lci=65; } virtual int f66(int) { return lci=66; } virtual int f67(int) { return lci=67; } + virtual int f68(int) { return lci=68; } virtual int f69(int) { return lci=69; } virtual int f70(int) { return lci=70; } virtual int f71(int) { return lci=71; } + virtual int f72(int) { return lci=72; } virtual int f73(int) { return lci=73; } virtual int f74(int) { return lci=74; } virtual int f75(int) { return lci=75; } + virtual int f76(int) { return lci=76; } virtual int f77(int) { return lci=77; } virtual int f78(int) { return lci=78; } virtual int f79(int) { return lci=79; } + virtual int f80(int) { return lci=80; } virtual int f81(int) { return lci=81; } virtual int f82(int) { return lci=82; } virtual int f83(int) { return lci=83; } + virtual int f84(int) { return lci=84; } virtual int f85(int) { return lci=85; } virtual int f86(int) { return lci=86; } virtual int f87(int) { return lci=87; } + virtual int f88(int) { return lci=88; } virtual int f89(int) { return lci=89; } virtual int f90(int) { return lci=90; } virtual int f91(int) { return lci=91; } + virtual int f92(int) { return lci=92; } virtual int f93(int) { return lci=93; } virtual int f94(int) { return lci=94; } virtual int f95(int) { return lci=95; } + virtual int f96(int) { return lci=96; } virtual int f97(int) { return lci=97; } virtual int f98(int) { return lci=98; } virtual int f99(int) { return lci=99; } + virtual int f100(int) { return lci=100; } virtual int f101(int) { return lci=101; } virtual int f102(int) { return lci=102; } virtual int f103(int) { return lci=103; } + virtual int f104(int) { return lci=104; } virtual int f105(int) { return lci=105; } virtual int f106(int) { return lci=106; } virtual int f107(int) { return lci=107; } + virtual int f108(int) { return lci=108; } virtual int f109(int) { return lci=109; } virtual int f110(int) { return lci=110; } virtual int f111(int) { return lci=111; } + virtual int f112(int) { return lci=112; } virtual int f113(int) { return lci=113; } virtual int f114(int) { return lci=114; } virtual int f115(int) { return lci=115; } + virtual int f116(int) { return lci=116; } virtual int f117(int) { return lci=117; } virtual int f118(int) { return lci=118; } virtual int f119(int) { return lci=119; } + virtual int f120(int) { return lci=120; } virtual int f121(int) { return lci=121; } virtual int f122(int) { return lci=122; } virtual int f123(int) { return lci=123; } + virtual int f124(int) { return lci=124; } virtual int f125(int) { return lci=125; } virtual int f126(int) { return lci=126; } virtual int f127(int) { return lci=127; } + virtual int f128(int) { return lci=128; } virtual int f129(int) { return lci=129; } virtual int f130(int) { return lci=130; } virtual int f131(int) { return lci=131; } + virtual int f132(int) { return lci=132; } virtual int f133(int) { return lci=133; } virtual int f134(int) { return lci=134; } virtual int f135(int) { return lci=135; } + virtual int f136(int) { return lci=136; } virtual int f137(int) { return lci=137; } virtual int f138(int) { return lci=138; } virtual int f139(int) { return lci=139; } + virtual int f140(int) { return lci=140; } virtual int f141(int) { return lci=141; } virtual int f142(int) { return lci=142; } virtual int f143(int) { return lci=143; } + virtual int f144(int) { return lci=144; } virtual int f145(int) { return lci=145; } virtual int f146(int) { return lci=146; } virtual int f147(int) { return lci=147; } + virtual int f148(int) { return lci=148; } virtual int f149(int) { return lci=149; } virtual int f150(int) { return lci=150; } virtual int f151(int) { return lci=151; } + virtual int f152(int) { return lci=152; } virtual int f153(int) { return lci=153; } virtual int f154(int) { return lci=154; } virtual int f155(int) { return lci=155; } + virtual int f156(int) { return lci=156; } virtual int f157(int) { return lci=157; } virtual int f158(int) { return lci=158; } virtual int f159(int) { return lci=159; } + virtual int f160(int) { return lci=160; } virtual int f161(int) { return lci=161; } virtual int f162(int) { return lci=162; } virtual int f163(int) { return lci=163; } + virtual int f164(int) { return lci=164; } virtual int f165(int) { return lci=165; } virtual int f166(int) { return lci=166; } virtual int f167(int) { return lci=167; } + virtual int f168(int) { return lci=168; } virtual int f169(int) { return lci=169; } virtual int f170(int) { return lci=170; } virtual int f171(int) { return lci=171; } + virtual int f172(int) { return lci=172; } virtual int f173(int) { return lci=173; } virtual int f174(int) { return lci=174; } virtual int f175(int) { return lci=175; } + virtual int f176(int) { return lci=176; } virtual int f177(int) { return lci=177; } virtual int f178(int) { return lci=178; } virtual int f179(int) { return lci=179; } + virtual int f180(int) { return lci=180; } virtual int f181(int) { return lci=181; } virtual int f182(int) { return lci=182; } virtual int f183(int) { return lci=183; } + virtual int f184(int) { return lci=184; } virtual int f185(int) { return lci=185; } virtual int f186(int) { return lci=186; } virtual int f187(int) { return lci=187; } + virtual int f188(int) { return lci=188; } virtual int f189(int) { return lci=189; } virtual int f190(int) { return lci=190; } virtual int f191(int) { return lci=191; } + virtual int f192(int) { return lci=192; } virtual int f193(int) { return lci=193; } virtual int f194(int) { return lci=194; } virtual int f195(int) { return lci=195; } + virtual int f196(int) { return lci=196; } virtual int f197(int) { return lci=197; } virtual int f198(int) { return lci=198; } virtual int f199(int) { return lci=199; } + virtual int f200(int) { return lci=200; } virtual int f201(int) { return lci=201; } virtual int f202(int) { return lci=202; } virtual int f203(int) { return lci=203; } + virtual int f204(int) { return lci=204; } virtual int f205(int) { return lci=205; } virtual int f206(int) { return lci=206; } virtual int f207(int) { return lci=207; } + virtual int f208(int) { return lci=208; } virtual int f209(int) { return lci=209; } virtual int f210(int) { return lci=210; } virtual int f211(int) { return lci=211; } + virtual int f212(int) { return lci=212; } virtual int f213(int) { return lci=213; } virtual int f214(int) { return lci=214; } virtual int f215(int) { return lci=215; } + virtual int f216(int) { return lci=216; } virtual int f217(int) { return lci=217; } virtual int f218(int) { return lci=218; } virtual int f219(int) { return lci=219; } + virtual int f220(int) { return lci=220; } virtual int f221(int) { return lci=221; } virtual int f222(int) { return lci=222; } virtual int f223(int) { return lci=223; } + virtual int f224(int) { return lci=224; } virtual int f225(int) { return lci=225; } virtual int f226(int) { return lci=226; } virtual int f227(int) { return lci=227; } + virtual int f228(int) { return lci=228; } virtual int f229(int) { return lci=229; } virtual int f230(int) { return lci=230; } virtual int f231(int) { return lci=231; } + virtual int f232(int) { return lci=232; } virtual int f233(int) { return lci=233; } virtual int f234(int) { return lci=234; } virtual int f235(int) { return lci=235; } + virtual int f236(int) { return lci=236; } virtual int f237(int) { return lci=237; } virtual int f238(int) { return lci=238; } virtual int f239(int) { return lci=239; } + virtual int f240(int) { return lci=240; } virtual int f241(int) { return lci=241; } virtual int f242(int) { return lci=242; } virtual int f243(int) { return lci=243; } + virtual int f244(int) { return lci=244; } virtual int f245(int) { return lci=245; } virtual int f246(int) { return lci=246; } virtual int f247(int) { return lci=247; } + virtual int f248(int) { return lci=248; } virtual int f249(int) { return lci=249; } virtual int f250(int) { return lci=250; } virtual int f251(int) { return lci=251; } + virtual int f252(int) { return lci=252; } virtual int f253(int) { return lci=253; } virtual int f254(int) { return lci=254; } virtual int f255(int) { return lci=255; } + virtual int f256(int) { return lci=256; } virtual int f257(int) { return lci=257; } virtual int f258(int) { return lci=258; } virtual int f259(int) { return lci=259; } + virtual int f260(int) { return lci=260; } virtual int f261(int) { return lci=261; } virtual int f262(int) { return lci=262; } virtual int f263(int) { return lci=263; } + virtual int f264(int) { return lci=264; } virtual int f265(int) { return lci=265; } virtual int f266(int) { return lci=266; } virtual int f267(int) { return lci=267; } + virtual int f268(int) { return lci=268; } virtual int f269(int) { return lci=269; } virtual int f270(int) { return lci=270; } virtual int f271(int) { return lci=271; } + virtual int f272(int) { return lci=272; } virtual int f273(int) { return lci=273; } virtual int f274(int) { return lci=274; } virtual int f275(int) { return lci=275; } + virtual int f276(int) { return lci=276; } virtual int f277(int) { return lci=277; } virtual int f278(int) { return lci=278; } virtual int f279(int) { return lci=279; } + virtual int f280(int) { return lci=280; } virtual int f281(int) { return lci=281; } virtual int f282(int) { return lci=282; } virtual int f283(int) { return lci=283; } + virtual int f284(int) { return lci=284; } virtual int f285(int) { return lci=285; } virtual int f286(int) { return lci=286; } virtual int f287(int) { return lci=287; } + virtual int f288(int) { return lci=288; } virtual int f289(int) { return lci=289; } virtual int f290(int) { return lci=290; } virtual int f291(int) { return lci=291; } + virtual int f292(int) { return lci=292; } virtual int f293(int) { return lci=293; } virtual int f294(int) { return lci=294; } virtual int f295(int) { return lci=295; } + virtual int f296(int) { return lci=296; } virtual int f297(int) { return lci=297; } virtual int f298(int) { return lci=298; } virtual int f299(int) { return lci=299; } + virtual int f300(int) { return lci=300; } virtual int f301(int) { return lci=301; } virtual int f302(int) { return lci=302; } virtual int f303(int) { return lci=303; } + virtual int f304(int) { return lci=304; } virtual int f305(int) { return lci=305; } virtual int f306(int) { return lci=306; } virtual int f307(int) { return lci=307; } + virtual int f308(int) { return lci=308; } virtual int f309(int) { return lci=309; } virtual int f310(int) { return lci=310; } virtual int f311(int) { return lci=311; } + virtual int f312(int) { return lci=312; } virtual int f313(int) { return lci=313; } virtual int f314(int) { return lci=314; } virtual int f315(int) { return lci=315; } + virtual int f316(int) { return lci=316; } virtual int f317(int) { return lci=317; } virtual int f318(int) { return lci=318; } virtual int f319(int) { return lci=319; } + virtual int f320(int) { return lci=320; } virtual int f321(int) { return lci=321; } virtual int f322(int) { return lci=322; } virtual int f323(int) { return lci=323; } + virtual int f324(int) { return lci=324; } virtual int f325(int) { return lci=325; } virtual int f326(int) { return lci=326; } virtual int f327(int) { return lci=327; } + virtual int f328(int) { return lci=328; } virtual int f329(int) { return lci=329; } virtual int f330(int) { return lci=330; } virtual int f331(int) { return lci=331; } + virtual int f332(int) { return lci=332; } virtual int f333(int) { return lci=333; } virtual int f334(int) { return lci=334; } virtual int f335(int) { return lci=335; } + virtual int f336(int) { return lci=336; } virtual int f337(int) { return lci=337; } virtual int f338(int) { return lci=338; } virtual int f339(int) { return lci=339; } + virtual int f340(int) { return lci=340; } virtual int f341(int) { return lci=341; } virtual int f342(int) { return lci=342; } virtual int f343(int) { return lci=343; } + virtual int f344(int) { return lci=344; } virtual int f345(int) { return lci=345; } virtual int f346(int) { return lci=346; } virtual int f347(int) { return lci=347; } + virtual int f348(int) { return lci=348; } virtual int f349(int) { return lci=349; } virtual int f350(int) { return lci=350; } virtual int f351(int) { return lci=351; } + virtual int f352(int) { return lci=352; } virtual int f353(int) { return lci=353; } virtual int f354(int) { return lci=354; } virtual int f355(int) { return lci=355; } + virtual int f356(int) { return lci=356; } virtual int f357(int) { return lci=357; } virtual int f358(int) { return lci=358; } virtual int f359(int) { return lci=359; } + virtual int f360(int) { return lci=360; } virtual int f361(int) { return lci=361; } virtual int f362(int) { return lci=362; } virtual int f363(int) { return lci=363; } + virtual int f364(int) { return lci=364; } virtual int f365(int) { return lci=365; } virtual int f366(int) { return lci=366; } virtual int f367(int) { return lci=367; } + virtual int f368(int) { return lci=368; } virtual int f369(int) { return lci=369; } virtual int f370(int) { return lci=370; } virtual int f371(int) { return lci=371; } + virtual int f372(int) { return lci=372; } virtual int f373(int) { return lci=373; } virtual int f374(int) { return lci=374; } virtual int f375(int) { return lci=375; } + virtual int f376(int) { return lci=376; } virtual int f377(int) { return lci=377; } virtual int f378(int) { return lci=378; } virtual int f379(int) { return lci=379; } + virtual int f380(int) { return lci=380; } virtual int f381(int) { return lci=381; } virtual int f382(int) { return lci=382; } virtual int f383(int) { return lci=383; } + virtual int f384(int) { return lci=384; } virtual int f385(int) { return lci=385; } virtual int f386(int) { return lci=386; } virtual int f387(int) { return lci=387; } + virtual int f388(int) { return lci=388; } virtual int f389(int) { return lci=389; } virtual int f390(int) { return lci=390; } virtual int f391(int) { return lci=391; } + virtual int f392(int) { return lci=392; } virtual int f393(int) { return lci=393; } virtual int f394(int) { return lci=394; } virtual int f395(int) { return lci=395; } + virtual int f396(int) { return lci=396; } virtual int f397(int) { return lci=397; } virtual int f398(int) { return lci=398; } virtual int f399(int) { return lci=399; } + virtual int f400(int) { return lci=400; } virtual int f401(int) { return lci=401; } virtual int f402(int) { return lci=402; } virtual int f403(int) { return lci=403; } + virtual int f404(int) { return lci=404; } virtual int f405(int) { return lci=405; } virtual int f406(int) { return lci=406; } virtual int f407(int) { return lci=407; } + virtual int f408(int) { return lci=408; } virtual int f409(int) { return lci=409; } virtual int f410(int) { return lci=410; } virtual int f411(int) { return lci=411; } + virtual int f412(int) { return lci=412; } virtual int f413(int) { return lci=413; } virtual int f414(int) { return lci=414; } virtual int f415(int) { return lci=415; } + virtual int f416(int) { return lci=416; } virtual int f417(int) { return lci=417; } virtual int f418(int) { return lci=418; } virtual int f419(int) { return lci=419; } + virtual int f420(int) { return lci=420; } virtual int f421(int) { return lci=421; } virtual int f422(int) { return lci=422; } virtual int f423(int) { return lci=423; } + virtual int f424(int) { return lci=424; } virtual int f425(int) { return lci=425; } virtual int f426(int) { return lci=426; } virtual int f427(int) { return lci=427; } + virtual int f428(int) { return lci=428; } virtual int f429(int) { return lci=429; } virtual int f430(int) { return lci=430; } virtual int f431(int) { return lci=431; } + virtual int f432(int) { return lci=432; } virtual int f433(int) { return lci=433; } virtual int f434(int) { return lci=434; } virtual int f435(int) { return lci=435; } + virtual int f436(int) { return lci=436; } virtual int f437(int) { return lci=437; } virtual int f438(int) { return lci=438; } virtual int f439(int) { return lci=439; } + virtual int f440(int) { return lci=440; } virtual int f441(int) { return lci=441; } virtual int f442(int) { return lci=442; } virtual int f443(int) { return lci=443; } + virtual int f444(int) { return lci=444; } virtual int f445(int) { return lci=445; } virtual int f446(int) { return lci=446; } virtual int f447(int) { return lci=447; } + virtual int f448(int) { return lci=448; } virtual int f449(int) { return lci=449; } virtual int f450(int) { return lci=450; } virtual int f451(int) { return lci=451; } + virtual int f452(int) { return lci=452; } virtual int f453(int) { return lci=453; } virtual int f454(int) { return lci=454; } virtual int f455(int) { return lci=455; } + virtual int f456(int) { return lci=456; } virtual int f457(int) { return lci=457; } virtual int f458(int) { return lci=458; } virtual int f459(int) { return lci=459; } + virtual int f460(int) { return lci=460; } virtual int f461(int) { return lci=461; } virtual int f462(int) { return lci=462; } virtual int f463(int) { return lci=463; } + virtual int f464(int) { return lci=464; } virtual int f465(int) { return lci=465; } virtual int f466(int) { return lci=466; } virtual int f467(int) { return lci=467; } + virtual int f468(int) { return lci=468; } virtual int f469(int) { return lci=469; } virtual int f470(int) { return lci=470; } virtual int f471(int) { return lci=471; } + virtual int f472(int) { return lci=472; } virtual int f473(int) { return lci=473; } virtual int f474(int) { return lci=474; } virtual int f475(int) { return lci=475; } + virtual int f476(int) { return lci=476; } virtual int f477(int) { return lci=477; } virtual int f478(int) { return lci=478; } virtual int f479(int) { return lci=479; } + virtual int f480(int) { return lci=480; } virtual int f481(int) { return lci=481; } virtual int f482(int) { return lci=482; } virtual int f483(int) { return lci=483; } + virtual int f484(int) { return lci=484; } virtual int f485(int) { return lci=485; } virtual int f486(int) { return lci=486; } virtual int f487(int) { return lci=487; } + virtual int f488(int) { return lci=488; } virtual int f489(int) { return lci=489; } virtual int f490(int) { return lci=490; } virtual int f491(int) { return lci=491; } + virtual int f492(int) { return lci=492; } virtual int f493(int) { return lci=493; } virtual int f494(int) { return lci=494; } virtual int f495(int) { return lci=495; } + virtual int f496(int) { return lci=496; } virtual int f497(int) { return lci=497; } virtual int f498(int) { return lci=498; } virtual int f499(int) { return lci=499; } + virtual int f500(int) { return lci=500; } virtual int f501(int) { return lci=501; } virtual int f502(int) { return lci=502; } virtual int f503(int) { return lci=503; } + virtual int f504(int) { return lci=504; } virtual int f505(int) { return lci=505; } virtual int f506(int) { return lci=506; } virtual int f507(int) { return lci=507; } + virtual int f508(int) { return lci=508; } virtual int f509(int) { return lci=509; } virtual int f510(int) { return lci=510; } virtual int f511(int) { return lci=511; } + virtual int f512(int) { return lci=512; } virtual int f513(int) { return lci=513; } virtual int f514(int) { return lci=514; } virtual int f515(int) { return lci=515; } + virtual int f516(int) { return lci=516; } virtual int f517(int) { return lci=517; } virtual int f518(int) { return lci=518; } virtual int f519(int) { return lci=519; } + virtual int f520(int) { return lci=520; } virtual int f521(int) { return lci=521; } virtual int f522(int) { return lci=522; } virtual int f523(int) { return lci=523; } + virtual int f524(int) { return lci=524; } virtual int f525(int) { return lci=525; } virtual int f526(int) { return lci=526; } virtual int f527(int) { return lci=527; } + virtual int f528(int) { return lci=528; } virtual int f529(int) { return lci=529; } virtual int f530(int) { return lci=530; } virtual int f531(int) { return lci=531; } + virtual int f532(int) { return lci=532; } virtual int f533(int) { return lci=533; } virtual int f534(int) { return lci=534; } virtual int f535(int) { return lci=535; } + virtual int f536(int) { return lci=536; } virtual int f537(int) { return lci=537; } virtual int f538(int) { return lci=538; } virtual int f539(int) { return lci=539; } + virtual int f540(int) { return lci=540; } virtual int f541(int) { return lci=541; } virtual int f542(int) { return lci=542; } virtual int f543(int) { return lci=543; } + virtual int f544(int) { return lci=544; } virtual int f545(int) { return lci=545; } virtual int f546(int) { return lci=546; } virtual int f547(int) { return lci=547; } + virtual int f548(int) { return lci=548; } virtual int f549(int) { return lci=549; } virtual int f550(int) { return lci=550; } virtual int f551(int) { return lci=551; } + virtual int f552(int) { return lci=552; } virtual int f553(int) { return lci=553; } virtual int f554(int) { return lci=554; } virtual int f555(int) { return lci=555; } + virtual int f556(int) { return lci=556; } virtual int f557(int) { return lci=557; } virtual int f558(int) { return lci=558; } virtual int f559(int) { return lci=559; } + virtual int f560(int) { return lci=560; } virtual int f561(int) { return lci=561; } virtual int f562(int) { return lci=562; } virtual int f563(int) { return lci=563; } + virtual int f564(int) { return lci=564; } virtual int f565(int) { return lci=565; } virtual int f566(int) { return lci=566; } virtual int f567(int) { return lci=567; } + virtual int f568(int) { return lci=568; } virtual int f569(int) { return lci=569; } virtual int f570(int) { return lci=570; } virtual int f571(int) { return lci=571; } + virtual int f572(int) { return lci=572; } virtual int f573(int) { return lci=573; } virtual int f574(int) { return lci=574; } virtual int f575(int) { return lci=575; } + virtual int f576(int) { return lci=576; } virtual int f577(int) { return lci=577; } virtual int f578(int) { return lci=578; } virtual int f579(int) { return lci=579; } + virtual int f580(int) { return lci=580; } virtual int f581(int) { return lci=581; } virtual int f582(int) { return lci=582; } virtual int f583(int) { return lci=583; } + virtual int f584(int) { return lci=584; } virtual int f585(int) { return lci=585; } virtual int f586(int) { return lci=586; } virtual int f587(int) { return lci=587; } + virtual int f588(int) { return lci=588; } virtual int f589(int) { return lci=589; } virtual int f590(int) { return lci=590; } virtual int f591(int) { return lci=591; } + virtual int f592(int) { return lci=592; } virtual int f593(int) { return lci=593; } virtual int f594(int) { return lci=594; } virtual int f595(int) { return lci=595; } + virtual int f596(int) { return lci=596; } virtual int f597(int) { return lci=597; } virtual int f598(int) { return lci=598; } virtual int f599(int) { return lci=599; } + virtual int f600(int) { return lci=600; } virtual int f601(int) { return lci=601; } virtual int f602(int) { return lci=602; } virtual int f603(int) { return lci=603; } + virtual int f604(int) { return lci=604; } virtual int f605(int) { return lci=605; } virtual int f606(int) { return lci=606; } virtual int f607(int) { return lci=607; } + virtual int f608(int) { return lci=608; } virtual int f609(int) { return lci=609; } virtual int f610(int) { return lci=610; } virtual int f611(int) { return lci=611; } + virtual int f612(int) { return lci=612; } virtual int f613(int) { return lci=613; } virtual int f614(int) { return lci=614; } virtual int f615(int) { return lci=615; } + virtual int f616(int) { return lci=616; } virtual int f617(int) { return lci=617; } virtual int f618(int) { return lci=618; } virtual int f619(int) { return lci=619; } + virtual int f620(int) { return lci=620; } virtual int f621(int) { return lci=621; } virtual int f622(int) { return lci=622; } virtual int f623(int) { return lci=623; } + virtual int f624(int) { return lci=624; } virtual int f625(int) { return lci=625; } virtual int f626(int) { return lci=626; } virtual int f627(int) { return lci=627; } + virtual int f628(int) { return lci=628; } virtual int f629(int) { return lci=629; } virtual int f630(int) { return lci=630; } virtual int f631(int) { return lci=631; } + virtual int f632(int) { return lci=632; } virtual int f633(int) { return lci=633; } virtual int f634(int) { return lci=634; } virtual int f635(int) { return lci=635; } + virtual int f636(int) { return lci=636; } virtual int f637(int) { return lci=637; } virtual int f638(int) { return lci=638; } virtual int f639(int) { return lci=639; } + virtual int f640(int) { return lci=640; } virtual int f641(int) { return lci=641; } virtual int f642(int) { return lci=642; } virtual int f643(int) { return lci=643; } + virtual int f644(int) { return lci=644; } virtual int f645(int) { return lci=645; } virtual int f646(int) { return lci=646; } virtual int f647(int) { return lci=647; } + virtual int f648(int) { return lci=648; } virtual int f649(int) { return lci=649; } virtual int f650(int) { return lci=650; } virtual int f651(int) { return lci=651; } + virtual int f652(int) { return lci=652; } virtual int f653(int) { return lci=653; } virtual int f654(int) { return lci=654; } virtual int f655(int) { return lci=655; } + virtual int f656(int) { return lci=656; } virtual int f657(int) { return lci=657; } virtual int f658(int) { return lci=658; } virtual int f659(int) { return lci=659; } + virtual int f660(int) { return lci=660; } virtual int f661(int) { return lci=661; } virtual int f662(int) { return lci=662; } virtual int f663(int) { return lci=663; } + virtual int f664(int) { return lci=664; } virtual int f665(int) { return lci=665; } virtual int f666(int) { return lci=666; } virtual int f667(int) { return lci=667; } + virtual int f668(int) { return lci=668; } virtual int f669(int) { return lci=669; } virtual int f670(int) { return lci=670; } virtual int f671(int) { return lci=671; } + virtual int f672(int) { return lci=672; } virtual int f673(int) { return lci=673; } virtual int f674(int) { return lci=674; } virtual int f675(int) { return lci=675; } + virtual int f676(int) { return lci=676; } virtual int f677(int) { return lci=677; } virtual int f678(int) { return lci=678; } virtual int f679(int) { return lci=679; } + virtual int f680(int) { return lci=680; } virtual int f681(int) { return lci=681; } virtual int f682(int) { return lci=682; } virtual int f683(int) { return lci=683; } + virtual int f684(int) { return lci=684; } virtual int f685(int) { return lci=685; } virtual int f686(int) { return lci=686; } virtual int f687(int) { return lci=687; } + virtual int f688(int) { return lci=688; } virtual int f689(int) { return lci=689; } virtual int f690(int) { return lci=690; } virtual int f691(int) { return lci=691; } + virtual int f692(int) { return lci=692; } virtual int f693(int) { return lci=693; } virtual int f694(int) { return lci=694; } virtual int f695(int) { return lci=695; } + virtual int f696(int) { return lci=696; } virtual int f697(int) { return lci=697; } virtual int f698(int) { return lci=698; } virtual int f699(int) { return lci=699; } + virtual int f700(int) { return lci=700; } virtual int f701(int) { return lci=701; } virtual int f702(int) { return lci=702; } virtual int f703(int) { return lci=703; } + virtual int f704(int) { return lci=704; } virtual int f705(int) { return lci=705; } virtual int f706(int) { return lci=706; } virtual int f707(int) { return lci=707; } + virtual int f708(int) { return lci=708; } virtual int f709(int) { return lci=709; } virtual int f710(int) { return lci=710; } virtual int f711(int) { return lci=711; } + virtual int f712(int) { return lci=712; } virtual int f713(int) { return lci=713; } virtual int f714(int) { return lci=714; } virtual int f715(int) { return lci=715; } + virtual int f716(int) { return lci=716; } virtual int f717(int) { return lci=717; } virtual int f718(int) { return lci=718; } virtual int f719(int) { return lci=719; } + virtual int f720(int) { return lci=720; } virtual int f721(int) { return lci=721; } virtual int f722(int) { return lci=722; } virtual int f723(int) { return lci=723; } + virtual int f724(int) { return lci=724; } virtual int f725(int) { return lci=725; } virtual int f726(int) { return lci=726; } virtual int f727(int) { return lci=727; } + virtual int f728(int) { return lci=728; } virtual int f729(int) { return lci=729; } virtual int f730(int) { return lci=730; } virtual int f731(int) { return lci=731; } + virtual int f732(int) { return lci=732; } virtual int f733(int) { return lci=733; } virtual int f734(int) { return lci=734; } virtual int f735(int) { return lci=735; } + virtual int f736(int) { return lci=736; } virtual int f737(int) { return lci=737; } virtual int f738(int) { return lci=738; } virtual int f739(int) { return lci=739; } + virtual int f740(int) { return lci=740; } virtual int f741(int) { return lci=741; } virtual int f742(int) { return lci=742; } virtual int f743(int) { return lci=743; } + virtual int f744(int) { return lci=744; } virtual int f745(int) { return lci=745; } virtual int f746(int) { return lci=746; } virtual int f747(int) { return lci=747; } + virtual int f748(int) { return lci=748; } virtual int f749(int) { return lci=749; } virtual int f750(int) { return lci=750; } virtual int f751(int) { return lci=751; } + virtual int f752(int) { return lci=752; } virtual int f753(int) { return lci=753; } virtual int f754(int) { return lci=754; } virtual int f755(int) { return lci=755; } + virtual int f756(int) { return lci=756; } virtual int f757(int) { return lci=757; } virtual int f758(int) { return lci=758; } virtual int f759(int) { return lci=759; } + virtual int f760(int) { return lci=760; } virtual int f761(int) { return lci=761; } virtual int f762(int) { return lci=762; } virtual int f763(int) { return lci=763; } + virtual int f764(int) { return lci=764; } virtual int f765(int) { return lci=765; } virtual int f766(int) { return lci=766; } virtual int f767(int) { return lci=767; } + virtual int f768(int) { return lci=768; } virtual int f769(int) { return lci=769; } virtual int f770(int) { return lci=770; } virtual int f771(int) { return lci=771; } + virtual int f772(int) { return lci=772; } virtual int f773(int) { return lci=773; } virtual int f774(int) { return lci=774; } virtual int f775(int) { return lci=775; } + virtual int f776(int) { return lci=776; } virtual int f777(int) { return lci=777; } virtual int f778(int) { return lci=778; } virtual int f779(int) { return lci=779; } + virtual int f780(int) { return lci=780; } virtual int f781(int) { return lci=781; } virtual int f782(int) { return lci=782; } virtual int f783(int) { return lci=783; } + virtual int f784(int) { return lci=784; } virtual int f785(int) { return lci=785; } virtual int f786(int) { return lci=786; } virtual int f787(int) { return lci=787; } + virtual int f788(int) { return lci=788; } virtual int f789(int) { return lci=789; } virtual int f790(int) { return lci=790; } virtual int f791(int) { return lci=791; } + virtual int f792(int) { return lci=792; } virtual int f793(int) { return lci=793; } virtual int f794(int) { return lci=794; } virtual int f795(int) { return lci=795; } + virtual int f796(int) { return lci=796; } virtual int f797(int) { return lci=797; } virtual int f798(int) { return lci=798; } virtual int f799(int) { return lci=799; } + virtual int f800(int) { return lci=800; } virtual int f801(int) { return lci=801; } virtual int f802(int) { return lci=802; } virtual int f803(int) { return lci=803; } + virtual int f804(int) { return lci=804; } virtual int f805(int) { return lci=805; } virtual int f806(int) { return lci=806; } virtual int f807(int) { return lci=807; } + virtual int f808(int) { return lci=808; } virtual int f809(int) { return lci=809; } virtual int f810(int) { return lci=810; } virtual int f811(int) { return lci=811; } + virtual int f812(int) { return lci=812; } virtual int f813(int) { return lci=813; } virtual int f814(int) { return lci=814; } virtual int f815(int) { return lci=815; } + virtual int f816(int) { return lci=816; } virtual int f817(int) { return lci=817; } virtual int f818(int) { return lci=818; } virtual int f819(int) { return lci=819; } + virtual int f820(int) { return lci=820; } virtual int f821(int) { return lci=821; } virtual int f822(int) { return lci=822; } virtual int f823(int) { return lci=823; } + virtual int f824(int) { return lci=824; } virtual int f825(int) { return lci=825; } virtual int f826(int) { return lci=826; } virtual int f827(int) { return lci=827; } + virtual int f828(int) { return lci=828; } virtual int f829(int) { return lci=829; } virtual int f830(int) { return lci=830; } virtual int f831(int) { return lci=831; } + virtual int f832(int) { return lci=832; } virtual int f833(int) { return lci=833; } virtual int f834(int) { return lci=834; } virtual int f835(int) { return lci=835; } + virtual int f836(int) { return lci=836; } virtual int f837(int) { return lci=837; } virtual int f838(int) { return lci=838; } virtual int f839(int) { return lci=839; } + virtual int f840(int) { return lci=840; } virtual int f841(int) { return lci=841; } virtual int f842(int) { return lci=842; } virtual int f843(int) { return lci=843; } + virtual int f844(int) { return lci=844; } virtual int f845(int) { return lci=845; } virtual int f846(int) { return lci=846; } virtual int f847(int) { return lci=847; } + virtual int f848(int) { return lci=848; } virtual int f849(int) { return lci=849; } virtual int f850(int) { return lci=850; } virtual int f851(int) { return lci=851; } + virtual int f852(int) { return lci=852; } virtual int f853(int) { return lci=853; } virtual int f854(int) { return lci=854; } virtual int f855(int) { return lci=855; } + virtual int f856(int) { return lci=856; } virtual int f857(int) { return lci=857; } virtual int f858(int) { return lci=858; } virtual int f859(int) { return lci=859; } + virtual int f860(int) { return lci=860; } virtual int f861(int) { return lci=861; } virtual int f862(int) { return lci=862; } virtual int f863(int) { return lci=863; } + virtual int f864(int) { return lci=864; } virtual int f865(int) { return lci=865; } virtual int f866(int) { return lci=866; } virtual int f867(int) { return lci=867; } + virtual int f868(int) { return lci=868; } virtual int f869(int) { return lci=869; } virtual int f870(int) { return lci=870; } virtual int f871(int) { return lci=871; } + virtual int f872(int) { return lci=872; } virtual int f873(int) { return lci=873; } virtual int f874(int) { return lci=874; } virtual int f875(int) { return lci=875; } + virtual int f876(int) { return lci=876; } virtual int f877(int) { return lci=877; } virtual int f878(int) { return lci=878; } virtual int f879(int) { return lci=879; } + virtual int f880(int) { return lci=880; } virtual int f881(int) { return lci=881; } virtual int f882(int) { return lci=882; } virtual int f883(int) { return lci=883; } + virtual int f884(int) { return lci=884; } virtual int f885(int) { return lci=885; } virtual int f886(int) { return lci=886; } virtual int f887(int) { return lci=887; } + virtual int f888(int) { return lci=888; } virtual int f889(int) { return lci=889; } virtual int f890(int) { return lci=890; } virtual int f891(int) { return lci=891; } + virtual int f892(int) { return lci=892; } virtual int f893(int) { return lci=893; } virtual int f894(int) { return lci=894; } virtual int f895(int) { return lci=895; } + virtual int f896(int) { return lci=896; } virtual int f897(int) { return lci=897; } virtual int f898(int) { return lci=898; } virtual int f899(int) { return lci=899; } + virtual int f900(int) { return lci=900; } virtual int f901(int) { return lci=901; } virtual int f902(int) { return lci=902; } virtual int f903(int) { return lci=903; } + virtual int f904(int) { return lci=904; } virtual int f905(int) { return lci=905; } virtual int f906(int) { return lci=906; } virtual int f907(int) { return lci=907; } + virtual int f908(int) { return lci=908; } virtual int f909(int) { return lci=909; } virtual int f910(int) { return lci=910; } virtual int f911(int) { return lci=911; } + virtual int f912(int) { return lci=912; } virtual int f913(int) { return lci=913; } virtual int f914(int) { return lci=914; } virtual int f915(int) { return lci=915; } + virtual int f916(int) { return lci=916; } virtual int f917(int) { return lci=917; } virtual int f918(int) { return lci=918; } virtual int f919(int) { return lci=919; } + virtual int f920(int) { return lci=920; } virtual int f921(int) { return lci=921; } virtual int f922(int) { return lci=922; } virtual int f923(int) { return lci=923; } + virtual int f924(int) { return lci=924; } virtual int f925(int) { return lci=925; } virtual int f926(int) { return lci=926; } virtual int f927(int) { return lci=927; } + virtual int f928(int) { return lci=928; } virtual int f929(int) { return lci=929; } virtual int f930(int) { return lci=930; } virtual int f931(int) { return lci=931; } + virtual int f932(int) { return lci=932; } virtual int f933(int) { return lci=933; } virtual int f934(int) { return lci=934; } virtual int f935(int) { return lci=935; } + virtual int f936(int) { return lci=936; } virtual int f937(int) { return lci=937; } virtual int f938(int) { return lci=938; } virtual int f939(int) { return lci=939; } + virtual int f940(int) { return lci=940; } virtual int f941(int) { return lci=941; } virtual int f942(int) { return lci=942; } virtual int f943(int) { return lci=943; } + virtual int f944(int) { return lci=944; } virtual int f945(int) { return lci=945; } virtual int f946(int) { return lci=946; } virtual int f947(int) { return lci=947; } + virtual int f948(int) { return lci=948; } virtual int f949(int) { return lci=949; } virtual int f950(int) { return lci=950; } virtual int f951(int) { return lci=951; } + virtual int f952(int) { return lci=952; } virtual int f953(int) { return lci=953; } virtual int f954(int) { return lci=954; } virtual int f955(int) { return lci=955; } + virtual int f956(int) { return lci=956; } virtual int f957(int) { return lci=957; } virtual int f958(int) { return lci=958; } virtual int f959(int) { return lci=959; } + virtual int f960(int) { return lci=960; } virtual int f961(int) { return lci=961; } virtual int f962(int) { return lci=962; } virtual int f963(int) { return lci=963; } + virtual int f964(int) { return lci=964; } virtual int f965(int) { return lci=965; } virtual int f966(int) { return lci=966; } virtual int f967(int) { return lci=967; } + virtual int f968(int) { return lci=968; } virtual int f969(int) { return lci=969; } virtual int f970(int) { return lci=970; } virtual int f971(int) { return lci=971; } + virtual int f972(int) { return lci=972; } virtual int f973(int) { return lci=973; } virtual int f974(int) { return lci=974; } virtual int f975(int) { return lci=975; } + virtual int f976(int) { return lci=976; } virtual int f977(int) { return lci=977; } virtual int f978(int) { return lci=978; } virtual int f979(int) { return lci=979; } + virtual int f980(int) { return lci=980; } virtual int f981(int) { return lci=981; } virtual int f982(int) { return lci=982; } virtual int f983(int) { return lci=983; } + virtual int f984(int) { return lci=984; } virtual int f985(int) { return lci=985; } virtual int f986(int) { return lci=986; } virtual int f987(int) { return lci=987; } + virtual int f988(int) { return lci=988; } virtual int f989(int) { return lci=989; } virtual int f990(int) { return lci=990; } virtual int f991(int) { return lci=991; } + virtual int f992(int) { return lci=992; } virtual int f993(int) { return lci=993; } virtual int f994(int) { return lci=994; } virtual int f995(int) { return lci=995; } + virtual int f996(int) { return lci=996; } virtual int f997(int) { return lci=997; } virtual int f998(int) { return lci=998; } virtual int f999(int) { return lci=999; } + virtual int f1000(int) { return lci=1000; } virtual int f1001(int) { return lci=1001; } virtual int f1002(int) { return lci=1002; } virtual int f1003(int) { return lci=1003; } + virtual int f1004(int) { return lci=1004; } virtual int f1005(int) { return lci=1005; } virtual int f1006(int) { return lci=1006; } virtual int f1007(int) { return lci=1007; } + virtual int f1008(int) { return lci=1008; } virtual int f1009(int) { return lci=1009; } virtual int f1010(int) { return lci=1010; } virtual int f1011(int) { return lci=1011; } + virtual int f1012(int) { return lci=1012; } virtual int f1013(int) { return lci=1013; } virtual int f1014(int) { return lci=1014; } virtual int f1015(int) { return lci=1015; } + virtual int f1016(int) { return lci=1016; } virtual int f1017(int) { return lci=1017; } virtual int f1018(int) { return lci=1018; } virtual int f1019(int) { return lci=1019; } + virtual int f1020(int) { return lci=1020; } virtual int f1021(int) { return lci=1021; } virtual int f1022(int) { return lci=1022; } virtual int f1023(int) { return lci=1023; } + virtual ~func_index() {} +}; + +#ifdef _MSC_VER +template +int virtual_function_index(unsigned char *func) { + if (*func == 0xE9) + { + return virtual_function_index<0>(func + 5 + *(unsigned int *)(func+1)); + } + else + { +#ifdef _WIN64 + // Add one to the pointer to skip the REX prefix used to access 64-bit registers. + func++; +#endif + switch(*(unsigned int *)func) + { // mov ecx, this; jump [eax + v/Ib/Iw] + case 0x20ff018b: return 0; + case 0x60ff018b: return *(unsigned char *)(func + sizeof(int)) / sizeof(void*); + case 0xA0ff018b: return *(unsigned long *)(func + sizeof(int)) / sizeof(void*); + default: return -1; + } + } +} +#endif + +template +std::pair virtual_index(T t) +{ +#if defined(__GNUG__) + union { + T t; + struct + { + unsigned long value; + unsigned long baseoffs; + } u; + } conv; + conv.t = t; +#if defined(SOME_ARM) + // ARM ABI says the bit is in bsaeoffs instead, and that the value is shiffted left 1. + // This because valid ARM pointers may have the LSB set, so the "is virtual" bit had to be moved. + if (conv.u.baseoffs & 1) + return std::pair(conv.u.baseoffs / (sizeof(void*) * 2), conv.u.value / sizeof(void *)); +#else + // simple Itanium ABI implementation, used by everything but Microsoft and embedded EDG-based compilers + if (conv.u.value & 1) + return std::pair(conv.u.baseoffs / sizeof(void*), conv.u.value / sizeof(void *)); +#endif + +#elif defined(_MSC_VER) + union { + T t; + struct + { + unsigned char *value; + unsigned long baseoffs; + } u; + } conv; + conv.t = t; + + int value = virtual_function_index<0>((unsigned char *)conv.u.value); + if (value != -1) + return std::pair((int)(conv.u.baseoffs/sizeof(void*)), value); +#elif defined(__EDG__) + union { + T t; + struct { + short delta; + short vindex; + long vtordisp; + } u; + } conv; + conv.t = t; + + if (conv.u.vindex != 0) + return std::pair((conv.u.delta + conv.u.vtordisp)/sizeof(void*), conv.u.vindex * 2 + 1); +#else +#error No virtual indexing found for this compiler! Please contact the maintainers of HippoMocks +#endif + + return std::pair(-1, 0); +} + +template +T getNonvirtualMemberFunctionAddress(U u) +{ +#ifdef __EDG__ + // Edison Design Group C++ frontend (Comeau, Portland Group, Greenhills, etc) + union { + struct { + short delta; + short vindex; + T t; + } mfp_structure; + U u; + } conv; +#else + // Visual Studio, GCC, others + union { + struct { + T t; + } mfp_structure; + U u; + } conv; +#endif + conv.u = u; + return conv.mfp_structure.t; +} + +class TypeDestructable { +public: + virtual ~TypeDestructable() {} +}; + +template +class MemberWrap : public TypeDestructable { +private: + A *member; +public: + MemberWrap(A *member) + : member(member) + { + new (member) A(); + } + ~MemberWrap() + { + member->~A(); + } +}; + +// mock types +template +class mock : public base_mock +{ + typedef void (*funcptr)(); + friend class MockRepository; + unsigned char remaining[sizeof(T)]; + void NotImplemented() { + mock *realMock = getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + RAISEEXCEPTION(:: HM_NS NotImplementedException(repo)); + } +protected: + std::map funcTables; + void (*notimplementedfuncs[VIRT_FUNC_LIMIT])(); +public: + bool isZombie; + std::list members; + MockRepository *repo; + std::map, int> funcMap; + mock(MockRepository *repo) + : isZombie(false) + , repo(repo) + { + for (int i = 0; i < VIRT_FUNC_LIMIT; i++) + { + notimplementedfuncs[i] = getNonvirtualMemberFunctionAddress(&mock::NotImplemented); + } + funcptr *funcTable = new funcptr[VIRT_FUNC_LIMIT+2]; + memcpy(funcTable, notimplementedfuncs, sizeof(funcptr) * VIRT_FUNC_LIMIT); + ((void **)funcTable)[VIRT_FUNC_LIMIT] = this; + ((void **)funcTable)[VIRT_FUNC_LIMIT+1] = *(void **)this; + funcTables[0] = funcTable; + *(void **)this = funcTable; + for (unsigned int i = 1; i < sizeof(remaining) / sizeof(funcptr); i++) + { + ((void **)this)[i] = (void *)notimplementedfuncs; + } + } + ~mock() + { + for (std::list::iterator i = members.begin(); i != members.end(); ++i) + { + delete *i; + } + for (std::map::iterator i = funcTables.begin(); i != funcTables.end(); ++i) + { + delete [] i->second; + } + } + void mock_reset() + { + MockRepository *repo = this->repo; + // ugly but simple + this->~mock(); + new (this) mock(repo); + } + mock *getRealThis() + { + void ***base = (void ***)this; + return (mock *)((*base)[VIRT_FUNC_LIMIT]); + } + std::pair translateX(int x) + { + for (std::map, int>::iterator i = funcMap.begin(); i != funcMap.end(); ++i) + { + if (i->second == x+1) return i->first; + } + return std::pair(-1, 0); + } + template + void mockedDestructor(int); +}; + +// Do() function wrapping +class VirtualDestructable { public: virtual ~VirtualDestructable() {} }; + +template +class TupleInvocable : public VirtualDestructable +{ +public: + virtual Y operator()(const base_tuple &tupl) = 0; +}; + +template +class Invocable : public TupleInvocable +{ +public: + virtual Y operator()(A a = A(), B b = B(), C c = C(), D d = D(), E e = E(), F f = F(), G g = G(), H h = H(), I i = I(), J j = J(), K k = K(), L l = L(), M m = M(), N n = N(), O o = O(), P p = P()) = 0; + virtual Y operator()(const base_tuple &tupl) { + const ref_tuple &rTupl = reinterpret_cast &>(tupl); + return (*this)(rTupl.a, rTupl.b, rTupl.c, rTupl.d, rTupl.e, rTupl.f, rTupl.g, rTupl.h, + rTupl.i, rTupl.j, rTupl.k, rTupl.l, rTupl.m, rTupl.n, rTupl.o, rTupl.p); + } +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p) + { + return t(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, NullType) + { + return t(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, NullType, NullType) + { + return t(a,b,c,d,e,f,g,h,i,j,k,l,m,n); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, NullType, NullType, NullType) + { + return t(a,b,c,d,e,f,g,h,i,j,k,l,m); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, NullType, NullType, NullType, NullType) + { + return t(a,b,c,d,e,f,g,h,i,j,k,l); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, NullType, NullType, NullType, NullType, NullType) + { + return t(a,b,c,d,e,f,g,h,i,j,k); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, NullType, NullType, NullType, NullType, NullType, NullType) + { + return t(a,b,c,d,e,f,g,h,i,j); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable{ + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, F f, G g, H h, I i, NullType, NullType, NullType, NullType, NullType, NullType, NullType) + { + return t(a,b,c,d,e,f,g,h,i); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, F f, G g, H h, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType) + { + return t(a,b,c,d,e,f,g,h); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, F f, G g, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType) + { + return t(a,b,c,d,e,f,g); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, F f, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType) + { + return t(a,b,c,d,e,f); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, E e, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType) + { + return t(a,b,c,d,e); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, D d, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType) + { + return t(a,b,c,d); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, C c, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType) + { + return t(a,b,c); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, B b, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType) + { + return t(a,b); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(A a, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType) + { + return t(a); + } + using Invocable::operator(); +}; +template +class DoWrapper : public Invocable { + T t; +public: + DoWrapper(T t) : t(t) {} + virtual Y operator()(NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType, NullType) + { + return t(); + } + using Invocable::operator(); +}; + +class ReturnValueHolder { +public: + virtual ~ReturnValueHolder() {} +}; + +template +class ReturnValueWrapper : public ReturnValueHolder { +public: + typename no_cref::type rv; + ReturnValueWrapper(T rv) : rv(rv) {} +}; + +//Call wrapping +class Call { +public: + virtual bool matchesArgs(const base_tuple &tuple) = 0; + virtual void assignArgs(base_tuple &tuple) = 0; + ReturnValueHolder *retVal; +#ifndef HM_NO_EXCEPTIONS + ExceptionHolder *eHolder; +#endif + base_mock *mock; + VirtualDestructable *functor; + VirtualDestructable *matchFunctor; + std::pair funcIndex; + std::list previousCalls; + unsigned called; + RegistrationType expectation; + bool satisfied; + int lineno; + const char *funcName; + const char *fileName; +protected: + Call(RegistrationType expectation, base_mock *mock, const std::pair &funcIndex, int X, const char *funcName, const char *fileName) + : retVal(0), +#ifndef HM_NO_EXCEPTIONS + eHolder(0), +#endif + mock(mock), + functor(0), + matchFunctor(0), + funcIndex(funcIndex), + called( 0 ), + expectation(expectation), + satisfied(false), + lineno(X), + funcName(funcName), + fileName(fileName) + { + } +public: + virtual const base_tuple *getArgs() const = 0; + virtual ~Call() + { +#ifndef HM_NO_EXCEPTIONS + delete eHolder; +#endif + delete functor; + delete matchFunctor; + delete retVal; + } +}; + +std::ostream &operator<<(std::ostream &os, const Call &call); + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k, const CL & l, const CM & m, const CN & n, const CO & o, const CP & p) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k, const CL & l, const CM & m, const CN & n, const CO & o, const CP & p) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k, const CL & l, const CM & m, const CN & n, const CO & o) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k, const CL & l, const CM & m, const CN & n, const CO & o) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k, const CL & l, const CM & m, const CN & n) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k, const CL & l, const CM & m, const CN & n) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k, const CL & l, const CM & m) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k, const CL & l, const CM & m) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k, const CL & l) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,l,NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k, const CL & l) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,l,NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j, const CK & k) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,k,NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i, const CJ & j) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,j,NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h, const CI & i) { + args = new copy_tuple(a,b,c,d,e,f,g,h,i,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h) { + args = new copy_tuple(a,b,c,d,e,f,g,h,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g, const CH & h) { + args = new copy_tuple(a,b,c,d,e,f,g,h,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g) { + args = new copy_tuple(a,b,c,d,e,f,g,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f, const CG & g) { + args = new copy_tuple(a,b,c,d,e,f,g,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f) { + args = new copy_tuple(a,b,c,d,e,f,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e, const CF & f) { + args = new copy_tuple(a,b,c,d,e,f,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e) { + args = new copy_tuple(a,b,c,d,e,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d, const CE & e) { + args = new copy_tuple(a,b,c,d,e,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d) { + args = new copy_tuple(a,b,c,d,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c, const CD & d) { + args = new copy_tuple(a,b,c,d,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c) { + args = new copy_tuple(a,b,c,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b, const CC & c) { + args = new copy_tuple(a,b,c,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b) { + args = new copy_tuple(a,b,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a, const CB & b) { + args = new copy_tuple(a,b,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA & a) { + args = new copy_tuple(a,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName), args(0) {} + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &tupl) { + return (!args && !matchFunctor) || + (args && (*args == reinterpret_cast &>(tupl))) || + (matchFunctor && (*(TupleInvocable *)(matchFunctor))(tupl)); + } + void assignArgs(base_tuple &tupl) { + if(args) { + args->assign_to(static_cast &>(tupl)); + args->assign_from(static_cast &>(tupl)); + } + } + template + TCall &With(const CA &a) { + args = new copy_tuple(a,NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + return *this; + } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + template + TCall &Match(T function) { matchFunctor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName) { + args = new copy_tuple + (NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + } + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &) { return true; } + void assignArgs(base_tuple &) {} + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } + Call &Return(Y obj) { retVal = new ReturnValueWrapper(obj); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; +template <> +class TCall : public Call { +private: + ref_comparable_assignable_tuple *args; +public: + const base_tuple *getArgs() const { return args; } + TCall(RegistrationType expectation, base_mock *mock, std::pair funcIndex, int X, const char *funcName, const char *fileName) : Call(expectation, mock, funcIndex, X, funcName ,fileName) { + args = new copy_tuple + (NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType(),NullType()); + } + ~TCall() { delete args; } + bool matchesArgs(const base_tuple &) { return true; } + void assignArgs(base_tuple &) { } + TCall &After(Call &call) { + previousCalls.push_back(&call); + return *this; + } + template + TCall &Do(T function) { functor = new DoWrapper(function); return *this; } +#ifndef HM_NO_EXCEPTIONS + template + Call &Throw(Ex exception) { eHolder = new ExceptionWrapper(exception); return *this; } +#endif +}; + +template +class MockRepoInstanceHolder { +public: + static MockRepository *instance; +}; + +template +MockRepository *MockRepoInstanceHolder::instance; + +inline +bool satisfied( std::list const& previousCalls ) +{ + for (std::list::const_iterator callsBefore = previousCalls.begin(); + callsBefore != previousCalls.end(); ++callsBefore) + { + if (!(*callsBefore)->satisfied) + { + return false; + } + } + return true; +} + + +class MockRepository { +private: + friend inline std::ostream &operator<<(std::ostream &os, const MockRepository &repo); + std::list mocks; + std::map staticFuncMap; +#ifdef _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT + std::list staticReplaces; +#endif + + std::list neverCalls; + std::list expectations; + std::list optionals; +public: + bool autoExpect; +private: + + void addAutoExpectTo( Call* call ) + { + if (autoExpect && expectations.size() > 0) + { + call->previousCalls.push_back(expectations.back()); + } + } + + + void addCall( Call* call, RegistrationType expect ) + { + if( expect == Never ) { + addAutoExpectTo( call ); + neverCalls.push_back(call); + } + else if( expect.minimum == expect.maximum ) + { + addAutoExpectTo( call ); + expectations.push_back(call); + } + else + { + optionals.push_back(call); + } + } + +#ifndef HM_NO_EXCEPTIONS + ExceptionHolder *latentException; +#endif +public: +#ifndef HM_NO_EXCEPTIONS + void SetLatentException(ExceptionHolder *holder) + { + latentException = holder; + } +#endif +#ifdef _MSC_VER +#ifdef _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT +#define OnCallFunc(func) RegisterExpect_<__COUNTER__>(&func, HM_NS Any, #func, __FILE__, __LINE__) +#define ExpectCallFunc(func) RegisterExpect_<__COUNTER__>(&func, HM_NS Once, #func, __FILE__, __LINE__) +#define NeverCallFunc(func) RegisterExpect_<__COUNTER__>(&func, HM_NS Never, #func, __FILE__, __LINE__) +#define OnCallFuncOverload(func) RegisterExpect_<__COUNTER__>(func, HM_NS Any, #func, __FILE__, __LINE__) +#define ExpectCallFuncOverload(func) RegisterExpect_<__COUNTER__>(func, HM_NS Once, #func, __FILE__, __LINE__) +#define NeverCallFuncOverload(func) RegisterExpect_<__COUNTER__>(func, HM_NS Never, #func, __FILE__, __LINE__) +#endif +#define OnCall(obj, func) RegisterExpect_<__COUNTER__>(obj, &func, HM_NS Any, #func, __FILE__, __LINE__) +#define OnCalls(obj, func, minimum) RegisterExpect_<__COUNTER__>(obj, &func, HM_NS RegistrationType(minimum,(std::numeric_limits::max)()), #func, __FILE__, __LINE__) +#define ExpectCall(obj, func) RegisterExpect_<__COUNTER__>(obj, &func, HM_NS Once, #func, __FILE__, __LINE__) +#define ExpectCalls(obj, func, num) RegisterExpect_<__COUNTER__>(obj, &func, HM_NS RegistrationType(num,num), #func, __FILE__, __LINE__) +#define NeverCall(obj, func) RegisterExpect_<__COUNTER__>(obj, &func, HM_NS Never, #func, __FILE__, __LINE__) +#define OnCallOverload(obj, func) RegisterExpect_<__COUNTER__>(obj, func, HM_NS Any, #func, __FILE__, __LINE__) +#define ExpectCallOverload(obj, func) RegisterExpect_<__COUNTER__>(obj, func, HM_NS Once, #func, __FILE__, __LINE__) +#define NeverCallOverload(obj, func) RegisterExpect_<__COUNTER__>(obj, func, HM_NS Never, #func, __FILE__, __LINE__) +#define OnCallDestructor(obj) RegisterExpectDestructor<__COUNTER__>(obj, HM_NS Any, __FILE__, __LINE__) +#define ExpectCallDestructor(obj) RegisterExpectDestructor<__COUNTER__>(obj, HM_NS Once, __FILE__, __LINE__) +#define NeverCallDestructor(obj) RegisterExpectDestructor<__COUNTER__>(obj, HM_NS Never, __FILE__, __LINE__) +#else +#ifdef _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT +#define OnCallFunc(func) RegisterExpect_<__LINE__>(&func, HM_NS Any, #func, __FILE__, __LINE__) +#define ExpectCallFunc(func) RegisterExpect_<__LINE__>(&func, HM_NS Once, #func, __FILE__, __LINE__) +#define NeverCallFunc(func) RegisterExpect_<__LINE__>(&func, HM_NS Never, #func, __FILE__, __LINE__) +#define OnCallFuncOverload(func) RegisterExpect_<__LINE__>(func, HM_NS Any, #func, __FILE__, __LINE__) +#define ExpectCallFuncOverload(func) RegisterExpect_<__LINE__>(func, HM_NS Once, #func, __FILE__, __LINE__) +#define NeverCallFuncOverload(func) RegisterExpect_<__LINE__>(func, HM_NS Never, #func, __FILE__, __LINE__) +#endif +#define OnCall(obj, func) RegisterExpect_<__LINE__>(obj, &func, HM_NS Any, #func, __FILE__, __LINE__) +#define OnCalls(obj, func, minimum) RegisterExpect_<__LINE__>(obj, &func, HM_NS RegistrationType(minimum,(std::numeric_limits::max)()), #func, __FILE__, __LINE__) +#define ExpectCall(obj, func) RegisterExpect_<__LINE__>(obj, &func, HM_NS Once, #func, __FILE__, __LINE__) +#define ExpectCalls(obj, func, num) RegisterExpect_<__LINE__>(obj, &func, HM_NS RegistrationType(num,num), #func, __FILE__, __LINE__) +#define NeverCall(obj, func) RegisterExpect_<__LINE__>(obj, &func, HM_NS Never, #func, __FILE__, __LINE__) +#define OnCallOverload(obj, func) RegisterExpect_<__LINE__>(obj, func, HM_NS Any, #func, __FILE__, __LINE__) +#define ExpectCallOverload(obj, func) RegisterExpect_<__LINE__>(obj, func, HM_NS Once, #func, __FILE__, __LINE__) +#define NeverCallOverload(obj, func) RegisterExpect_<__LINE__>(obj, func, HM_NS Never, #func, __FILE__, __LINE__) +#define OnCallDestructor(obj) RegisterExpectDestructor<__LINE__>(obj, HM_NS Any, __FILE__, __LINE__) +#define ExpectCallDestructor(obj) RegisterExpectDestructor<__LINE__>(obj, HM_NS Once, __FILE__, __LINE__) +#define NeverCallDestructor(obj) RegisterExpectDestructor<__LINE__>(obj, HM_NS Never, __FILE__, __LINE__) +#endif + template + void Member(A *mck, C B::*member) + { + C A::*realMember = (C A::*)member; + C *realRealMember = &(mck->*realMember); + mock *realMock = (mock *)mck; + realMock->members.push_back(new MemberWrap(realRealMember)); + } + template + TCall &RegisterExpectDestructor(Z2 *mck, RegistrationType expect, const char *fileName, unsigned long lineNo); + +#ifdef _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT + template + TCall &RegisterExpect_(Y (*func)(), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E,F), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E,F,G), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K,L), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K,L,M), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + +#if defined(_MSC_VER) && !defined(_WIN64) + template + TCall &RegisterExpect_(Y (__stdcall *func)(), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K,L), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K,L,M), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); +#endif +#endif + + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + + //GCC 3.x doesn't seem to understand overloading on const or non-const member function. Volatile appears to work though. +#if !defined(__GNUC__) || __GNUC__ > 3 + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)() volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)())(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P))(func), expect, funcName ,fileName, lineNo); } + + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)() const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)())(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P))(func), expect, funcName ,fileName, lineNo); } + + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)() const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) + { return RegisterExpect_(mck, (Y(Z::*)())(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) + { return RegisterExpect_(mck, (Y(Z::*)(A))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) + { return RegisterExpect_(mck, (Y(Z::*)(A,B))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P))(func), expect, funcName ,fileName, lineNo); } +#endif + +#if defined(_MSC_VER) && !defined(_WIN64) + // COM only support - you can duplicate this for cdecl and fastcall if you want to, but those are not as common as COM. + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::* func)(), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo); + + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)() volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)())(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P) volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P))(func), expect, funcName ,fileName, lineNo); } + + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)() const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)())(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P) const volatile, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P))(func), expect, funcName ,fileName, lineNo); } + + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)() const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)())(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O))(func), expect, funcName ,fileName, lineNo); } + template + TCall &RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P) const, RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) { return RegisterExpect_(mck, (Y(__stdcall Z::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P))(func), expect, funcName ,fileName, lineNo); } +#endif + + + template + void BasicRegisterExpect(mock *zMock, int baseOffset, int funcIndex, void (base_mock::*func)(), int X); +#ifdef _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT + int BasicStaticRegisterExpect(void (*func)(), void (*fp)(), int X) + { + if (staticFuncMap.find(func) == staticFuncMap.end()) + { + staticFuncMap[func] = X; + staticReplaces.push_back(new Replace(func, fp)); + } + return staticFuncMap[func]; + } +#endif + + void doCall( Call* call, const base_tuple &tuple ) + { + ++call->called; + + call->satisfied = call->called >= call->expectation.minimum; + + call->assignArgs(const_cast(tuple)); + #ifndef HM_NO_EXCEPTIONS + if (call->eHolder) + call->eHolder->rethrow(); + #endif + } + + void doVoidFunctor( Call* call, const base_tuple &tuple ) + { + if (call->functor != NULL) + (*(TupleInvocable *)(call->functor))(tuple); + } + + template + Z doReturnFunctor( Call* call, const base_tuple &tuple ) + { + if (call->functor != NULL) + { + if(call->retVal == NULL) + { + return (*(TupleInvocable *)(call->functor))(tuple); + } + else + { + (*(TupleInvocable *)(call->functor))(tuple); + } + } + + if (call->retVal) + return ((ReturnValueWrapper *)call->retVal)->rv; + + RAISEEXCEPTION(NoResultSetUpException(this, call->getArgs(), call->funcName)); + } + + void doVoidCall( Call* call, const base_tuple &tuple, bool const makeLatent ) + { + if( call->called < call->expectation.maximum ) + { + doCall( call, tuple ); + doVoidFunctor( call, tuple ); + } + else + { + doThrow( call, makeLatent ); + } + } + + template + Z doReturnCall( Call* call, const base_tuple &tuple ) + { + if( call->called < call->expectation.maximum ) + { + doCall( call, tuple ); + return doReturnFunctor( call, tuple ); + } + RAISEEXCEPTION(ExpectationException(this, call->getArgs(), call->funcName)); + } + + + void doThrow( Call * call, bool const makeLatent ) + { + call->satisfied = true; + + if (makeLatent) + { + #ifndef HM_NO_EXCEPTIONS + if (latentException) + return; + #endif + RAISELATENTEXCEPTION(ExpectationException(this, call->getArgs(), call->funcName)); + } + else + { + RAISEEXCEPTION(ExpectationException(this, call->getArgs(), call->funcName)); + } + } + + const char *funcName( base_mock *mock, std::pair funcno ) + { + const char *funcName = NULL; + for (std::list::iterator i = expectations.begin(); i != expectations.end() && !funcName; ++i) + { + Call *call = *i; + if (call->mock == mock && + call->funcIndex == funcno) + funcName = call->funcName; + } + for (std::list::iterator i = optionals.begin(); i != optionals.end() && !funcName; ++i) + { + Call *call = *i; + if (call->mock == mock && + call->funcIndex == funcno) + funcName = call->funcName; + } + for (std::list::iterator i = neverCalls.begin(); i != neverCalls.end() && !funcName; ++i) + { + Call *call = *i; + if (call->mock == mock && + call->funcIndex == funcno) + funcName = call->funcName; + } + return funcName; + } + + bool + matches( Call *call, base_mock *mock, std::pair funcno, const base_tuple &tuple ) + { + return call->mock == mock && + call->funcIndex == funcno && + call->matchesArgs(tuple) && + satisfied( call->previousCalls ); + + } + + bool + isUnsatisfied( Call *call, base_mock *mock, std::pair funcno, const base_tuple &tuple ) + { + return ! call->satisfied && matches( call, mock, funcno, tuple ); + } + + template + Z DoExpectation(base_mock *mock, std::pair funcno, const base_tuple &tuple); + + void DoVoidExpectation(base_mock *mock, std::pair funcno, const base_tuple &tuple, bool makeLatent = false) + { + for (std::list::reverse_iterator i = neverCalls.rbegin(); i != neverCalls.rend(); ++i) + { + Call *call = *i; + if ( matches( call, mock, funcno, tuple ) ) + { + doThrow( call, makeLatent ); + return; + } + } + for (std::list::reverse_iterator i = expectations.rbegin(); i != expectations.rend(); ++i) + { + Call *call = *i; + if ( isUnsatisfied( call, mock, funcno, tuple ) ) + { + doVoidCall( call, tuple, makeLatent ); + return; + } + } + for (std::list::reverse_iterator i = optionals.rbegin(); i != optionals.rend(); ++i) + { + Call *call = *i; + if ( matches( call, mock, funcno, tuple ) ) + { + doVoidCall( call, tuple, makeLatent ); + return; + } + } + + if (makeLatent) + { +#ifndef HM_NO_EXCEPTIONS + if (latentException) + return; +#endif + RAISELATENTEXCEPTION(ExpectationException(this, &tuple, funcName(mock, funcno))); + } + else + { + RAISEEXCEPTION(ExpectationException(this, &tuple, funcName(mock, funcno))); + } + } + MockRepository() + : autoExpect(DEFAULT_AUTOEXPECT) +#ifndef HM_NO_EXCEPTIONS + , latentException(0) +#endif + { + MockRepoInstanceHolder<0>::instance = this; + } + ~MockRepository() + // If we're on a recent enough compiler that's not VS2012 (as it doesn't have noexcept) +#if __cplusplus > 199711L && (!defined(_MSC_VER) || _MSC_VER > 1700) +noexcept(false) +#endif + { + MockRepoInstanceHolder<0>::instance = 0; +#ifndef HM_NO_EXCEPTIONS + if (!std::uncaught_exception()) + { + try + { +#endif + VerifyAll(); +#ifndef HM_NO_EXCEPTIONS + } + catch(...) + { + delete latentException; + reset(); + for (std::list::iterator i = mocks.begin(); i != mocks.end(); i++) + { + (*i)->destroy(); + } +#ifdef _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT + for (std::list::iterator i = staticReplaces.begin(); i != staticReplaces.end(); i++) + { + delete *i; + } +#endif + throw; + } + } + if (latentException) + { + try + { + latentException->rethrow(); + } + catch(BASE_EXCEPTION e) + { + printf("Latent exception masked!\nException:\n%s\n", e.what()); + } + delete latentException; + } +#endif + reset(); + for (std::list::iterator i = mocks.begin(); i != mocks.end(); i++) + { + (*i)->destroy(); + } +#ifdef _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT + for (std::list::iterator i = staticReplaces.begin(); i != staticReplaces.end(); i++) + { + delete *i; + } +#endif + } + void reset() + { + for (std::list::iterator i = expectations.begin(); i != expectations.end(); i++) + { + delete *i; + } + expectations.clear(); + for (std::list::iterator i = neverCalls.begin(); i != neverCalls.end(); i++) + { + delete *i; + } + neverCalls.clear(); + for (std::list::iterator i = optionals.begin(); i != optionals.end(); i++) + { + delete *i; + } + optionals.clear(); + for (std::list::iterator i = mocks.begin(); i != mocks.end(); i++) + { + (*i)->reset(); + } + } + + void VerifyAll() + { +#ifndef HM_NO_EXCEPTIONS + if (latentException) + latentException->rethrow(); +#endif + + for (std::list::iterator i = expectations.begin(); i != expectations.end(); i++) + { + if (!(*i)->satisfied) { + RAISEEXCEPTION(CallMissingException(this)); + } + } + } + void VerifyPartial(base_mock *obj) + { +#ifndef HM_NO_EXCEPTIONS + if (latentException) + return; +#endif + for (std::list::iterator i = expectations.begin(); i != expectations.end(); i++) + { + if ((*i)->mock == (base_mock *)obj && + !(*i)->satisfied ) + { + RAISELATENTEXCEPTION(CallMissingException(this)); + } + } + } + template + base *Mock(); +}; + +// mock function providers +template +class mockFuncs : public mock { +private: + mockFuncs(); +public: + template + Y expectation0() + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple<>()); + } + template + Y expectation1(A a) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a)); + } + template + Y expectation2(A a, B b) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b)); + } + template + Y expectation3(A a, B b, C c) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c)); + } + template + Y expectation4(A a, B b, C c, D d) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d)); + } + template + Y expectation5(A a, B b, C c, D d, E e) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e)); + } + template + Y expectation6(A a, B b, C c, D d, E e, F f) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f)); + } + template + Y expectation7(A a, B b, C c, D d, E e, F f, G g) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g)); + } + template + Y expectation8(A a, B b, C c, D d, E e, F f, G g, H h) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h)); + } + template + Y expectation9(A a, B b, C c, D d, E e, F f, G g, H h, I i) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i)); + } + template + Y expectation10(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j)); + } + template + Y expectation11(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k)); + } + template + Y expectation12(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l)); + } + template + Y expectation13(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m)); + } + template + Y expectation14(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n)); + } + template + Y expectation15(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); + } + template + Y expectation16(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + return repo->template DoExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); + } + + template + static Y static_expectation0() + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple<>()); + } + template + static Y static_expectation1(A a) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a)); + } + template + static Y static_expectation2(A a, B b) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b)); + } + template + static Y static_expectation3(A a, B b, C c) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c)); + } + template + static Y static_expectation4(A a, B b, C c, D d) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d)); + } + template + static Y static_expectation5(A a, B b, C c, D d, E e) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e)); + } + template + static Y static_expectation6(A a, B b, C c, D d, E e, F f) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f)); + } + template + static Y static_expectation7(A a, B b, C c, D d, E e, F f, G g) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g)); + } + template + static Y static_expectation8(A a, B b, C c, D d, E e, F f, G g, H h) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h)); + } + template + static Y static_expectation9(A a, B b, C c, D d, E e, F f, G g, H h, I i) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i)); + } + template + static Y static_expectation10(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j)); + } + template + static Y static_expectation11(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k)); + } + template + static Y static_expectation12(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l)); + } + template + static Y static_expectation13(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m)); + } + template + static Y static_expectation14(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n)); + } + template + static Y static_expectation15(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); + } + template + static Y static_expectation16(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); + } + +#ifdef _MSC_VER + template + Y __stdcall stdcallexpectation0() + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple<>()); + } + template + Y __stdcall stdcallexpectation1(A a) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a)); + } + template + Y __stdcall stdcallexpectation2(A a, B b) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b)); + } + template + Y __stdcall stdcallexpectation3(A a, B b, C c) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c)); + } + template + Y __stdcall stdcallexpectation4(A a, B b, C c, D d) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d)); + } + template + Y __stdcall stdcallexpectation5(A a, B b, C c, D d, E e) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e)); + } + template + Y __stdcall stdcallexpectation6(A a, B b, C c, D d, E e, F f) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f)); + } + template + Y __stdcall stdcallexpectation7(A a, B b, C c, D d, E e, F f, G g) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g)); + } + template + Y __stdcall stdcallexpectation8(A a, B b, C c, D d, E e, F f, G g, H h) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h)); + } + template + Y __stdcall stdcallexpectation9(A a, B b, C c, D d, E e, F f, G g, H h, I i) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i)); + } + template + Y __stdcall stdcallexpectation10(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j)); + } + template + Y __stdcall stdcallexpectation11(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k)); + } + template + Y __stdcall stdcallexpectation12(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l)); + } + template + Y __stdcall stdcallexpectation13(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m)); + } + template + Y __stdcall stdcallexpectation14(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n)); + } + template + Y __stdcall stdcallexpectation15(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); + } + template + Y __stdcall stdcallexpectation16(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p) + { + MockRepository *repo = mock::repo; + return repo->template DoExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); + } +#if defined(_MSC_VER) && !defined(_WIN64) + template + static Y __stdcall static_stdcallexpectation0() + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple<>()); + } + template + static Y __stdcall static_stdcallexpectation1(A a) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a)); + } + template + static Y __stdcall static_stdcallexpectation2(A a, B b) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b)); + } + template + static Y __stdcall static_stdcallexpectation3(A a, B b, C c) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c)); + } + template + static Y __stdcall static_stdcallexpectation4(A a, B b, C c, D d) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d)); + } + template + static Y __stdcall static_stdcallexpectation5(A a, B b, C c, D d, E e) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e)); + } + template + static Y __stdcall static_stdcallexpectation6(A a, B b, C c, D d, E e, F f) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f)); + } + template + static Y __stdcall static_stdcallexpectation7(A a, B b, C c, D d, E e, F f, G g) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g)); + } + template + static Y __stdcall static_stdcallexpectation8(A a, B b, C c, D d, E e, F f, G g, H h) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h)); + } + template + static Y __stdcall static_stdcallexpectation9(A a, B b, C c, D d, E e, F f, G g, H h, I i) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i)); + } + template + static Y __stdcall static_stdcallexpectation10(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j)); + } + template + static Y __stdcall static_stdcallexpectation11(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k)); + } + template + static Y __stdcall static_stdcallexpectation12(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l)); + } + template + static Y __stdcall static_stdcallexpectation13(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m)); + } + template + static Y __stdcall static_stdcallexpectation14(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n)); + } + template + static Y __stdcall static_stdcallexpectation15(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); + } + template + static Y __stdcall static_stdcallexpectation16(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p) + { + return MockRepoInstanceHolder<0>::instance->template DoExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); + } +#endif +#endif +}; + +template +class mockFuncs : public mock { +private: + mockFuncs(); +public: + template + void expectation0() + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple<>()); + } + template + void expectation1(A a) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a)); + } + template + void expectation2(A a, B b) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b)); + } + template + void expectation3(A a, B b, C c) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c)); + } + template + void expectation4(A a, B b, C c, D d) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d)); + } + template + void expectation5(A a, B b, C c, D d, E e) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e)); + } + template + void expectation6(A a, B b, C c, D d, E e, F f) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f)); + } + template + void expectation7(A a, B b, C c, D d, E e, F f, G g) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g)); + } + template + void expectation8(A a, B b, C c, D d, E e, F f, G g, H h) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h)); + } + template + void expectation9(A a, B b, C c, D d, E e, F f, G g, H h, I i) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i)); + } + template + void expectation10(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j)); + } + template + void expectation11(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k)); + } + template + void expectation12(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l)); + } + template + void expectation13(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m)); + } + template + void expectation14(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n)); + } + template + void expectation15(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); + } + template + void expectation16(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p) + { + mock *realMock = mock::getRealThis(); + if (realMock->isZombie) + RAISEEXCEPTION(ZombieMockException(realMock->repo)); + MockRepository *repo = realMock->repo; + repo->DoVoidExpectation(realMock, realMock->translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); + } + template + static void static_expectation0() + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple<>()); + } + template + static void static_expectation1(A a) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a)); + } + template + static void static_expectation2(A a, B b) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b)); + } + template + static void static_expectation3(A a, B b, C c) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c)); + } + template + static void static_expectation4(A a, B b, C c, D d) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d)); + } + template + static void static_expectation5(A a, B b, C c, D d, E e) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e)); + } + template + static void static_expectation6(A a, B b, C c, D d, E e, F f) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f)); + } + template + static void static_expectation7(A a, B b, C c, D d, E e, F f, G g) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g)); + } + template + static void static_expectation8(A a, B b, C c, D d, E e, F f, G g, H h) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h)); + } + template + static void static_expectation9(A a, B b, C c, D d, E e, F f, G g, H h, I i) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i)); + } + template + static void static_expectation10(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j)); + } + template + static void static_expectation11(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k)); + } + template + static void static_expectation12(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l)); + } + template + static void static_expectation13(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m)); + } + template + static void static_expectation14(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n)); + } + template + static void static_expectation15(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); + } + template + static void static_expectation16(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p) + { + MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); + } + +#ifdef _MSC_VER + template + void __stdcall stdcallexpectation0() + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple<>()); + } + template + void __stdcall stdcallexpectation1(A a) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a)); + } + template + void __stdcall stdcallexpectation2(A a, B b) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b)); + } + template + void __stdcall stdcallexpectation3(A a, B b, C c) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c)); + } + template + void __stdcall stdcallexpectation4(A a, B b, C c, D d) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d)); + } + template + void __stdcall stdcallexpectation5(A a, B b, C c, D d, E e) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e)); + } + template + void __stdcall stdcallexpectation6(A a, B b, C c, D d, E e, F f) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f)); + } + template + void __stdcall stdcallexpectation7(A a, B b, C c, D d, E e, F f, G g) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g)); + } + template + void __stdcall stdcallexpectation8(A a, B b, C c, D d, E e, F f, G g, H h) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h)); + } + template + void __stdcall stdcallexpectation9(A a, B b, C c, D d, E e, F f, G g, H h, I i) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i)); + } + template + void __stdcall stdcallexpectation10(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j)); + } + template + void __stdcall stdcallexpectation11(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k)); + } + template + void __stdcall stdcallexpectation12(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l)); + } + template + void __stdcall stdcallexpectation13(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m)); + } + template + void __stdcall stdcallexpectation14(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n)); + } + template + void __stdcall stdcallexpectation15(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); + } + template + void __stdcall stdcallexpectation16(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p) + { + MockRepository *repo = mock::repo; + repo->DoVoidExpectation(this, mock::translateX(X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); + } +#if defined(_MSC_VER) && !defined(_WIN64) + template + static void __stdcall static_stdcallexpectation0() + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple<>()); + } + template + static void __stdcall static_stdcallexpectation1(A a) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a)); + } + template + static void __stdcall static_stdcallexpectation2(A a, B b) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b)); + } + template + static void __stdcall static_stdcallexpectation3(A a, B b, C c) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c)); + } + template + static void __stdcall static_stdcallexpectation4(A a, B b, C c, D d) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d)); + } + template + static void __stdcall static_stdcallexpectation5(A a, B b, C c, D d, E e) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e)); + } + template + static void __stdcall static_stdcallexpectation6(A a, B b, C c, D d, E e, F f) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f)); + } + template + static void __stdcall static_stdcallexpectation7(A a, B b, C c, D d, E e, F f, G g) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g)); + } + template + static void __stdcall static_stdcallexpectation8(A a, B b, C c, D d, E e, F f, G g, H h) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h)); + } + template + static void __stdcall static_stdcallexpectation9(A a, B b, C c, D d, E e, F f, G g, H h, I i) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i)); + } + template + static void __stdcall static_stdcallexpectation10(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j)); + } + template + static void __stdcall static_stdcallexpectation11(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k)); + } + template + static void __stdcall static_stdcallexpectation12(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l)); + } + template + static void __stdcall static_stdcallexpectation13(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m)); + } + template + static void __stdcall static_stdcallexpectation14(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n)); + } + template + static void __stdcall static_stdcallexpectation15(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); + } + template + static void __stdcall static_stdcallexpectation16(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p) + { + return MockRepoInstanceHolder<0>::instance->DoVoidExpectation(NULL, std::pair(0, X), ref_tuple(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); + } +#endif +#endif +}; + +template +template +void mock::mockedDestructor(int) +{ + repo->DoVoidExpectation(this, translateX(X), ref_tuple<>(), true); + repo->VerifyPartial(this); + isZombie = true; +} + +template +void MockRepository::BasicRegisterExpect(mock *zMock, int baseOffset, int funcIndex, void (base_mock::*func)(), int X) +{ + if (funcIndex > VIRT_FUNC_LIMIT) RAISEEXCEPTION(NotImplementedException(this)); + if ((unsigned int)baseOffset * sizeof(void*) + sizeof(void*)-1 > sizeof(Z)) RAISEEXCEPTION(NotImplementedException(this)); + if (zMock->funcMap.find(std::make_pair(baseOffset, funcIndex)) == zMock->funcMap.end()) + { + if (zMock->funcTables.find(baseOffset) == zMock->funcTables.end()) + { + typedef void (*funcptr)(); + funcptr *funcTable = new funcptr[VIRT_FUNC_LIMIT+1]; + memcpy(funcTable, zMock->notimplementedfuncs, sizeof(funcptr) * VIRT_FUNC_LIMIT); + ((void **)funcTable)[VIRT_FUNC_LIMIT] = zMock; + zMock->funcTables[baseOffset] = funcTable; + ((void **)zMock)[baseOffset] = funcTable; + } + zMock->funcMap[std::make_pair(baseOffset, funcIndex)] = X+1; + zMock->funcTables[baseOffset][funcIndex] = getNonvirtualMemberFunctionAddress(func); + } +} + +template +TCall &MockRepository::RegisterExpectDestructor(Z2 *mck, RegistrationType expect, const char *fileName, unsigned long lineNo) +{ + func_index idx; + ((Z2 *)&idx)->~Z2(); + int funcIndex = idx.lci * FUNCTION_STRIDE + FUNCTION_BASE; + void (mock::*member)(int); + member = &mock::template mockedDestructor; + BasicRegisterExpect(reinterpret_cast *>(mck), + 0, funcIndex, + reinterpret_cast(member), X); +#ifdef EXTRA_DESTRUCTOR + BasicRegisterExpect(reinterpret_cast *>(mck), + 0, funcIndex+1, + reinterpret_cast(member), X); +#endif + TCall *call = new TCall(Once, reinterpret_cast(mck), std::pair(0, funcIndex), lineNo, "destructor", fileName); + addCall( call, expect ); + return *call; +} + +#if defined(_MSC_VER) && !defined(_WIN64) +// Support for COM, see declarations +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(); + mfp = &mockFuncs::template stdcallexpectation0; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A); + mfp = &mockFuncs::template stdcallexpectation1; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B); + mfp = &mockFuncs::template stdcallexpectation2; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C); + mfp = &mockFuncs::template stdcallexpectation3; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D); + mfp = &mockFuncs::template stdcallexpectation4; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E); + mfp = &mockFuncs::template stdcallexpectation5; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E,F); + mfp = &mockFuncs::template stdcallexpectation6; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E,F,G); + mfp = &mockFuncs::template stdcallexpectation7; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E,F,G,H); + mfp = &mockFuncs::template stdcallexpectation8; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I); + mfp = &mockFuncs::template stdcallexpectation9; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J); + mfp = &mockFuncs::template stdcallexpectation10; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K); + mfp = &mockFuncs::template stdcallexpectation11; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K,L); + mfp = &mockFuncs::template stdcallexpectation12; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K,L,M); + mfp = &mockFuncs::template stdcallexpectation13; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N); + mfp = &mockFuncs::template stdcallexpectation14; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O); + mfp = &mockFuncs::template stdcallexpectation15; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} + +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (__stdcall Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + int funcIndex = getFunctionIndex(func); + Y (__stdcall mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P); + mfp = &mockFuncs::template stdcallexpectation16; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +#endif + +#ifdef _HIPPOMOCKS__ENABLE_CFUNC_MOCKING_SUPPORT +template +TCall &MockRepository::RegisterExpect_(Y (*func)(), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(); + fp = &mockFuncs::template static_expectation0; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A); + fp = &mockFuncs::template static_expectation1; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B); + fp = &mockFuncs::template static_expectation2; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C); + fp = &mockFuncs::template static_expectation3; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D); + fp = &mockFuncs::template static_expectation4; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E); + fp = &mockFuncs::template static_expectation5; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E,F), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E,F); + fp = &mockFuncs::template static_expectation6; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E,F,G), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E,F,G); + fp = &mockFuncs::template static_expectation7; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E,F,G,H); + fp = &mockFuncs::template static_expectation8; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E,F,G,H,I); + fp = &mockFuncs::template static_expectation9; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E,F,G,H,I,J); + fp = &mockFuncs::template static_expectation10; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E,F,G,H,I,J,K); + fp = &mockFuncs::template static_expectation11; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K,L), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E,F,G,H,I,J,K,L); + fp = &mockFuncs::template static_expectation12; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K,L,M), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E,F,G,H,I,J,K,L,M); + fp = &mockFuncs::template static_expectation13; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N); + fp = &mockFuncs::template static_expectation14; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O); + fp = &mockFuncs::template static_expectation15; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} + +template +TCall &MockRepository::RegisterExpect_(Y (*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (*fp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P); + fp = &mockFuncs::template static_expectation16; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} + +#if defined(_MSC_VER) && !defined(_WIN64) +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(); + fp = &mockFuncs::template static_stdcallexpectation0; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A); + fp = &mockFuncs::template static_stdcallexpectation1; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B); + fp = &mockFuncs::template static_stdcallexpectation2; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C); + fp = &mockFuncs::template static_stdcallexpectation3; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D); + fp = &mockFuncs::template static_stdcallexpectation4; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E); + fp = &mockFuncs::template static_stdcallexpectation5; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E,F); + fp = &mockFuncs::template static_stdcallexpectation6; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E,F,G); + fp = &mockFuncs::template static_stdcallexpectation7; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E,F,G,H); + fp = &mockFuncs::template static_stdcallexpectation8; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E,F,G,H,I); + fp = &mockFuncs::template static_stdcallexpectation9; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E,F,G,H,I,J); + fp = &mockFuncs::template static_stdcallexpectation10; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E,F,G,H,I,J,K); + fp = &mockFuncs::template static_stdcallexpectation11; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K,L), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E,F,G,H,I,J,K,L); + fp = &mockFuncs::template static_stdcallexpectation12; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K,L,M), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E,F,G,H,I,J,K,L,M); + fp = &mockFuncs::template static_stdcallexpectation13; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N); + fp = &mockFuncs::template static_stdcallexpectation14; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O); + fp = &mockFuncs::template static_stdcallexpectation15; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} + +template +TCall &MockRepository::RegisterExpect_(Y (__stdcall *func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + Y (__stdcall *fp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P); + fp = &mockFuncs::template static_stdcallexpectation16; + int index = BasicStaticRegisterExpect(reinterpret_cast(func), reinterpret_cast(fp),X); + TCall *call = new TCall(expect, NULL, std::pair(0, index), lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +#endif +#endif + +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y (Z2::*)())func); + Y (mockFuncs::*mfp)(); + mfp = &mockFuncs::template expectation0; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A))func); + Y (mockFuncs::*mfp)(A); + mfp = &mockFuncs::template expectation1; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B))func); + Y (mockFuncs::*mfp)(A,B); + mfp = &mockFuncs::template expectation2; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C))func); + Y (mockFuncs::*mfp)(A,B,C); + mfp = &mockFuncs::template expectation3; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D))func); + Y (mockFuncs::*mfp)(A,B,C,D); + mfp = &mockFuncs::template expectation4; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E))func); + Y (mockFuncs::*mfp)(A,B,C,D,E); + mfp = &mockFuncs::template expectation5; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E,F))func); + Y (mockFuncs::*mfp)(A,B,C,D,E,F); + mfp = &mockFuncs::template expectation6; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E,F,G))func); + Y (mockFuncs::*mfp)(A,B,C,D,E,F,G); + mfp = &mockFuncs::template expectation7; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E,F,G,H))func); + Y (mockFuncs::*mfp)(A,B,C,D,E,F,G,H); + mfp = &mockFuncs::template expectation8; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E,F,G,H,I))func); + Y (mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I); + mfp = &mockFuncs::template expectation9; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E,F,G,H,I,J))func); + Y (mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J); + mfp = &mockFuncs::template expectation10; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E,F,G,H,I,J,K))func); + Y (mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K); + mfp = &mockFuncs::template expectation11; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E,F,G,H,I,J,K,L))func); + Y (mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K,L); + mfp = &mockFuncs::template expectation12; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E,F,G,H,I,J,K,L,M))func); + Y (mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K,L,M); + mfp = &mockFuncs::template expectation13; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N))func); + Y (mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N); + mfp = &mockFuncs::template expectation14; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O))func); + Y (mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O); + mfp = &mockFuncs::template expectation15; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} + +template +TCall &MockRepository::RegisterExpect_(Z2 *mck, Y (Z::*func)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P), RegistrationType expect, const char *funcName, const char *fileName, unsigned long lineNo) +{ + std::pair funcIndex = virtual_index((Y(Z2::*)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P))func); + Y (mockFuncs::*mfp)(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P); + mfp = &mockFuncs::template expectation16; + BasicRegisterExpect(reinterpret_cast *>(mck), + funcIndex.first, funcIndex.second, + reinterpret_cast(mfp),X); + TCall *call = new TCall(expect, reinterpret_cast(mck), funcIndex, lineNo, funcName ,fileName); + addCall( call, expect ); + return *call; +} + +template +Z MockRepository::DoExpectation(base_mock *mock, std::pair funcno, const base_tuple &tuple) +{ + for (std::list::reverse_iterator i = neverCalls.rbegin(); i != neverCalls.rend(); ++i) + { + Call *call = *i; + if ( matches( call, mock, funcno, tuple ) ) + { + call->satisfied = true; + RAISEEXCEPTION(ExpectationException(this, call->getArgs(), call->funcName)); + } + } + for (std::list::reverse_iterator i = expectations.rbegin(); i != expectations.rend(); ++i) + { + Call *call = *i; + if( isUnsatisfied( call, mock, funcno, tuple ) ) + { + return doReturnCall( call, tuple ); + } + } + for (std::list::reverse_iterator i = optionals.rbegin(); i != optionals.rend(); ++i) + { + Call *call = *i; + if ( matches( call, mock, funcno, tuple ) ) + { + return doReturnCall( call, tuple ); + } + } + RAISEEXCEPTION(ExpectationException(this, &tuple, funcName(mock,funcno))); +} +template +base *MockRepository::Mock() { + mock *m = new mock(this); + mocks.push_back(m); + return reinterpret_cast(m); +} +inline std::ostream &operator<<(std::ostream &os, const Call &call) +{ + os << call.fileName << "(" << call.lineno << ") "; + if (call.expectation == Once) + os << "Expectation for "; + else + os << "Result set for "; + + os << call.funcName; + + if (call.getArgs()) + call.getArgs()->printTo(os); + else + os << "(...)"; + + os << " on the mock at 0x" << call.mock << " was "; + + if (!call.satisfied) + os << "not "; + + if (call.expectation == Once) + os << "satisfied." << std::endl; + else + os << "used." << std::endl; + + return os; +} + +inline std::ostream &operator<<(std::ostream &os, const MockRepository &repo) +{ + if (repo.expectations.size()) + { + os << "Expections set:" << std::endl; + for (std::list::const_iterator exp = repo.expectations.begin(); exp != repo.expectations.end(); ++exp) + os << **exp; + os << std::endl; + } + + if (repo.neverCalls.size()) + { + os << "Functions explicitly expected to not be called:" << std::endl; + for (std::list::const_iterator exp = repo.neverCalls.begin(); exp != repo.neverCalls.end(); ++exp) + os << **exp; + os << std::endl; + } + + if (repo.optionals.size()) + { + os << "Optional results set up:" << std::endl; + for (std::list::const_iterator exp = repo.optionals.begin(); exp != repo.optionals.end(); ++exp) + os << **exp; + os << std::endl; + } + return os; +} + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +#ifndef NO_HIPPOMOCKS_NAMESPACE +} + +using HippoMocks::MockRepository; +using HippoMocks::DONTCARE_NAME; +using HippoMocks::Call; +using HippoMocks::Out; +using HippoMocks::In; +#endif + +#undef DEBUGBREAK +#undef BASE_EXCEPTION +#undef RAISEEXCEPTION +#undef RAISELATENTEXCEPTION +#undef DONTCARE_NAME +#undef VIRT_FUNC_LIMIT +#undef EXTRA_DESTRUCTOR +#undef FUNCTION_BASE +#undef FUNCTION_STRIDE +#undef CFUNC_MOCK_PLATFORMIS64BIT + +#endif + diff --git a/src/app/system.cpp b/src/app/system.cpp index 2ceea6ab..6b18f63a 100644 --- a/src/app/system.cpp +++ b/src/app/system.cpp @@ -41,10 +41,6 @@ template<> CSystemUtils* CSingleton::m_instance = nullptr; -CSystemUtils::CSystemUtils() -{ -} - CSystemUtils* CSystemUtils::Create() { assert(m_instance == nullptr); diff --git a/src/app/system.h b/src/app/system.h index 327f60dc..ab25801b 100644 --- a/src/app/system.h +++ b/src/app/system.h @@ -90,9 +90,6 @@ struct SystemTimeStamp; */ class CSystemUtils : public CSingleton { -protected: - CSystemUtils(); - public: //! Creates system utils for specific platform static CSystemUtils* Create(); diff --git a/src/common/singleton.h b/src/common/singleton.h index eab7ec5e..1913a248 100644 --- a/src/common/singleton.h +++ b/src/common/singleton.h @@ -64,8 +64,6 @@ public: #ifdef TESTS static void ReplaceInstance(T* newInstance) { - assert(newInstance != nullptr); - delete m_instance; m_instance = newInstance; } #endif diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index cd745c3a..c121f04b 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -30,14 +30,13 @@ include_directories( include_directories( SYSTEM ${GTEST_INCLUDE_DIR} - ${GMOCK_INCLUDE_DIR} + ${HIPPOMOCKS_INCLUDE_DIR} ${COLOBOT_SYSTEM_INCLUDES} ) # Libraries set(LIBS gtest - gmock colobotbase ${COLOBOT_LIBS} ) diff --git a/test/unit/app/app_test.cpp b/test/unit/app/app_test.cpp index d4dade99..0fb26afa 100644 --- a/test/unit/app/app_test.cpp +++ b/test/unit/app/app_test.cpp @@ -16,6 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see http://gnu.org/licenses */ + #include "app/app.h" #if defined(PLATFORM_WINDOWS) @@ -26,13 +27,14 @@ #include "app/system_other.h" #endif -#include "app/system_mock.h" +#include +#include #include +#include -using testing::_; -using testing::InSequence; -using testing::Return; +using namespace HippoMocks; +namespace ph = std::placeholders; struct FakeSystemTimeStamp : public SystemTimeStamp { @@ -42,11 +44,10 @@ struct FakeSystemTimeStamp : public SystemTimeStamp long long time; }; - class CApplicationWrapper : public CApplication { public: - virtual Event CreateUpdateEvent() OVERRIDE + Event CreateUpdateEvent() OVERRIDE { return CApplication::CreateUpdateEvent(); } @@ -55,10 +56,17 @@ public: class ApplicationUT : public testing::Test { protected: - ApplicationUT(); + ApplicationUT() : + m_systemUtils(nullptr), + m_stampUid(0), + m_currentTime(0) + {} - virtual void SetUp() OVERRIDE; - virtual void TearDown() OVERRIDE; + ~ApplicationUT() NOEXCEPT + {} + + void SetUp() OVERRIDE; + void TearDown() OVERRIDE; void NextInstant(long long diff); @@ -73,41 +81,37 @@ protected: long long relTimeReal, long long absTimeReal); protected: - CApplicationWrapper* app; - CSystemUtilsMock* systemUtils; + std::unique_ptr m_app; + MockRepository m_mocks; + CSystemUtils* m_systemUtils; private: int m_stampUid; long long m_currentTime; }; -ApplicationUT::ApplicationUT() - : m_stampUid(0) - , m_currentTime(0) -{} - void ApplicationUT::SetUp() { - systemUtils = new CSystemUtilsMock(); + m_systemUtils = m_mocks.Mock(); + CSystemUtils::ReplaceInstance(m_systemUtils); - ON_CALL(*systemUtils, CreateTimeStamp()).WillByDefault(Invoke(this, &ApplicationUT::CreateTimeStamp)); - ON_CALL(*systemUtils, DestroyTimeStamp(_)).WillByDefault(Invoke(this, &ApplicationUT::DestroyTimeStamp)); - ON_CALL(*systemUtils, CopyTimeStamp(_, _)).WillByDefault(Invoke(this, &ApplicationUT::CopyTimeStamp)); - ON_CALL(*systemUtils, GetCurrentTimeStamp(_)).WillByDefault(Invoke(this, &ApplicationUT::GetCurrentTimeStamp)); - ON_CALL(*systemUtils, TimeStampExactDiff(_, _)).WillByDefault(Invoke(this, &ApplicationUT::TimeStampExactDiff)); + m_mocks.OnCall(m_systemUtils, CSystemUtils::GetDataPath).Return(""); + m_mocks.OnCall(m_systemUtils, CSystemUtils::GetLangPath).Return(""); + m_mocks.OnCall(m_systemUtils, CSystemUtils::GetSaveDir).Return(""); - EXPECT_CALL(*systemUtils, CreateTimeStamp()).Times(3 + PCNT_MAX*2); - app = new CApplicationWrapper(); + m_mocks.OnCall(m_systemUtils, CSystemUtils::CreateTimeStamp).Do(std::bind(&ApplicationUT::CreateTimeStamp, this)); + m_mocks.OnCall(m_systemUtils, CSystemUtils::DestroyTimeStamp).Do(std::bind(&ApplicationUT::DestroyTimeStamp, this, ph::_1)); + m_mocks.OnCall(m_systemUtils, CSystemUtils::CopyTimeStamp).Do(std::bind(&ApplicationUT::CopyTimeStamp, this, ph::_1, ph::_2)); + m_mocks.OnCall(m_systemUtils, CSystemUtils::GetCurrentTimeStamp).Do(std::bind(&ApplicationUT::GetCurrentTimeStamp, this, ph::_1)); + m_mocks.OnCall(m_systemUtils, CSystemUtils::TimeStampExactDiff).Do(std::bind(&ApplicationUT::TimeStampExactDiff, this, ph::_1, ph::_2)); + + m_app.reset(new CApplicationWrapper()); } void ApplicationUT::TearDown() { - EXPECT_CALL(*systemUtils, DestroyTimeStamp(_)).Times(3 + PCNT_MAX*2); - delete app; - app = nullptr; - - delete systemUtils; - systemUtils = nullptr; + m_app.reset(); + CSystemUtils::ReplaceInstance(nullptr); } SystemTimeStamp* ApplicationUT::CreateTimeStamp() @@ -144,29 +148,22 @@ void ApplicationUT::TestCreateUpdateEvent(long long relTimeExact, long long absT float relTime, float absTime, long long relTimeReal, long long absTimeReal) { - { - InSequence seq; - EXPECT_CALL(*systemUtils, CopyTimeStamp(_, _)); - EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); - EXPECT_CALL(*systemUtils, TimeStampExactDiff(_, _)).Times(2); - } - - Event event = app->CreateUpdateEvent(); + Event event = m_app->CreateUpdateEvent(); EXPECT_EQ(EVENT_FRAME, event.type); EXPECT_FLOAT_EQ(relTime, event.rTime); - EXPECT_FLOAT_EQ(relTime, app->GetRelTime()); - EXPECT_FLOAT_EQ(absTime, app->GetAbsTime()); - EXPECT_EQ(relTimeExact, app->GetExactRelTime()); - EXPECT_EQ(absTimeExact, app->GetExactAbsTime()); - EXPECT_EQ(relTimeReal, app->GetRealRelTime()); - EXPECT_EQ(absTimeReal, app->GetRealAbsTime()); + EXPECT_FLOAT_EQ(relTime, m_app->GetRelTime()); + EXPECT_FLOAT_EQ(absTime, m_app->GetAbsTime()); + EXPECT_EQ(relTimeExact, m_app->GetExactRelTime()); + EXPECT_EQ(absTimeExact, m_app->GetExactAbsTime()); + EXPECT_EQ(relTimeReal, m_app->GetRealRelTime()); + EXPECT_EQ(absTimeReal, m_app->GetRealAbsTime()); } TEST_F(ApplicationUT, UpdateEventTimeCalculation_SimulationSuspended) { - app->SuspendSimulation(); - Event event = app->CreateUpdateEvent(); + m_app->SuspendSimulation(); + Event event = m_app->CreateUpdateEvent(); EXPECT_EQ(EVENT_NULL, event.type); } @@ -218,20 +215,13 @@ TEST_F(ApplicationUT, UpdateEventTimeCalculation_NegativeTimeOperation) NextInstant(-1111); - { - InSequence seq; - EXPECT_CALL(*systemUtils, CopyTimeStamp(_, _)); - EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); - EXPECT_CALL(*systemUtils, TimeStampExactDiff(_, _)).Times(2); - } - Event event = app->CreateUpdateEvent(); + Event event = m_app->CreateUpdateEvent(); EXPECT_EQ(EVENT_NULL, event.type); } TEST_F(ApplicationUT, UpdateEventTimeCalculation_ChangingSimulationSpeed) { - EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); - app->SetSimulationSpeed(2.0f); + m_app->SetSimulationSpeed(2.0f); // 1st update -- speed 2x @@ -260,8 +250,7 @@ TEST_F(ApplicationUT, UpdateEventTimeCalculation_ChangingSimulationSpeed) TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); // 3rd update -- speed 4x - EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); - app->SetSimulationSpeed(4.0f); + m_app->SetSimulationSpeed(4.0f); relTimeReal = 300; absTimeReal += relTimeReal; @@ -275,8 +264,7 @@ TEST_F(ApplicationUT, UpdateEventTimeCalculation_ChangingSimulationSpeed) TestCreateUpdateEvent(relTimeExact, absTimeExact, relTime, absTime, relTimeReal, absTimeReal); // 4th update -- speed 1x - EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); - app->SetSimulationSpeed(1.0f); + m_app->SetSimulationSpeed(1.0f); relTimeReal = 400; absTimeReal += relTimeReal; @@ -307,7 +295,7 @@ TEST_F(ApplicationUT, UpdateEventTimeCalculation_SuspendingAndResumingSimulation // 2nd update -- simulation suspended - app->SuspendSimulation(); + m_app->SuspendSimulation(); long long suspensionTime = 5000; @@ -315,12 +303,7 @@ TEST_F(ApplicationUT, UpdateEventTimeCalculation_SuspendingAndResumingSimulation // 3rd update -- simulation resumed - { - InSequence seq; - EXPECT_CALL(*systemUtils, GetCurrentTimeStamp(_)); - EXPECT_CALL(*systemUtils, CopyTimeStamp(_, _)); - } - app->ResumeSimulation(); + m_app->ResumeSimulation(); relTimeReal = 200; absTimeReal += relTimeReal; diff --git a/test/unit/app/system_linux_test.cpp b/test/unit/app/system_linux_test.cpp index 7b734c68..e4966023 100644 --- a/test/unit/app/system_linux_test.cpp +++ b/test/unit/app/system_linux_test.cpp @@ -21,18 +21,12 @@ #include -class CSystemUtilsLinuxWrapper : public CSystemUtilsLinux -{ -public: - CSystemUtilsLinuxWrapper() {} -}; - class SystemUtilsLinuxUT : public testing::Test { protected: static const long long SEC = 1000000000; - CSystemUtilsLinuxWrapper systemUtils; + CSystemUtilsLinux m_systemUtils; }; @@ -46,10 +40,10 @@ TEST_F(SystemUtilsLinuxUT, TimeStampDiff) after.clockTime.tv_sec = 1; after.clockTime.tv_nsec = 900; - long long tDiff = systemUtils.TimeStampExactDiff(&before, &after); + long long tDiff = m_systemUtils.TimeStampExactDiff(&before, &after); EXPECT_EQ( 800, tDiff); - tDiff = systemUtils.TimeStampExactDiff(&after, &before); + tDiff = m_systemUtils.TimeStampExactDiff(&after, &before); EXPECT_EQ(-800, tDiff); // ------- @@ -60,10 +54,10 @@ TEST_F(SystemUtilsLinuxUT, TimeStampDiff) after.clockTime.tv_sec = 3; after.clockTime.tv_nsec = 500; - tDiff = systemUtils.TimeStampExactDiff(&before, &after); + tDiff = m_systemUtils.TimeStampExactDiff(&before, &after); EXPECT_EQ( SEC + 300, tDiff); - tDiff = systemUtils.TimeStampExactDiff(&after, &before); + tDiff = m_systemUtils.TimeStampExactDiff(&after, &before); EXPECT_EQ(-SEC - 300, tDiff); // ------- @@ -74,9 +68,9 @@ TEST_F(SystemUtilsLinuxUT, TimeStampDiff) after.clockTime.tv_sec = 4; after.clockTime.tv_nsec = 100; - tDiff = systemUtils.TimeStampExactDiff(&before, &after); + tDiff = m_systemUtils.TimeStampExactDiff(&before, &after); EXPECT_EQ( SEC - 100, tDiff); - tDiff = systemUtils.TimeStampExactDiff(&after, &before); + tDiff = m_systemUtils.TimeStampExactDiff(&after, &before); EXPECT_EQ(-SEC + 100, tDiff); } diff --git a/test/unit/app/system_mock.h b/test/unit/app/system_mock.h deleted file mode 100644 index ac7e5908..00000000 --- a/test/unit/app/system_mock.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsiteс.ch; http://colobot.info; http://github.com/colobot - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://gnu.org/licenses - */ -#pragma once - -#include "app/system.h" - -#include - -class CSystemUtilsMock : public CSystemUtils -{ -public: - CSystemUtilsMock(bool defaultExpects = false) - { - if (defaultExpects) - SetDefaultExpects(); - } - - virtual ~CSystemUtilsMock() {} - - void SetDefaultExpects() - { - using testing::_; - using testing::Return; - using testing::AnyNumber; - - EXPECT_CALL(*this, CreateTimeStamp()).Times(AnyNumber()).WillRepeatedly(Return(nullptr)); - EXPECT_CALL(*this, DestroyTimeStamp(_)).Times(AnyNumber()); - EXPECT_CALL(*this, CopyTimeStamp(_, _)).Times(AnyNumber()); - EXPECT_CALL(*this, GetCurrentTimeStamp(_)).Times(AnyNumber()); - - EXPECT_CALL(*this, GetTimeStampResolution(_)).Times(AnyNumber()).WillRepeatedly(Return(0.0f)); - EXPECT_CALL(*this, GetTimeStampExactResolution()).Times(AnyNumber()).WillRepeatedly(Return(0ll)); - EXPECT_CALL(*this, TimeStampDiff(_, _, _)).Times(AnyNumber()).WillRepeatedly(Return(0.0f)); - EXPECT_CALL(*this, TimeStampExactDiff(_, _)).Times(AnyNumber()).WillRepeatedly(Return(0ll)); - } - - MOCK_METHOD0(Init, void()); - - MOCK_METHOD3(SystemDialog, SystemDialogResult(SystemDialogType, const std::string &title, const std::string &message)); - MOCK_METHOD3(ConsoleSystemDialog, SystemDialogResult(SystemDialogType type, const std::string& title, const std::string& message)); - - MOCK_METHOD0(CreateTimeStamp, SystemTimeStamp*()); - MOCK_METHOD1(DestroyTimeStamp, void (SystemTimeStamp *stamp)); - MOCK_METHOD2(CopyTimeStamp, void (SystemTimeStamp *dst, SystemTimeStamp *src)); - MOCK_METHOD1(GetCurrentTimeStamp, void (SystemTimeStamp *stamp)); - MOCK_METHOD1(GetTimeStampResolution, float (SystemTimeUnit unit)); - MOCK_METHOD0(GetTimeStampExactResolution, long long()); - MOCK_METHOD3(TimeStampDiff, float(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit)); - MOCK_METHOD2(TimeStampExactDiff, long long(SystemTimeStamp *before, SystemTimeStamp *after)); - MOCK_METHOD1(Usleep, void(int usec)); -}; diff --git a/test/unit/app/system_windows_test.cpp b/test/unit/app/system_windows_test.cpp index cfba1ae2..265ef488 100644 --- a/test/unit/app/system_windows_test.cpp +++ b/test/unit/app/system_windows_test.cpp @@ -21,60 +21,49 @@ #include -class CSystemUtilsWindowsWrapper : public CSystemUtilsWindows -{ -public: - CSystemUtilsWindowsWrapper() {} - - void SetFrequency(long long counterFrequency) - { - m_counterFrequency = counterFrequency; - } -}; - class SystemUtilsWindowsUT : public testing::Test { protected: static const long long SEC = 1000000000; - CSystemUtilsWindowsWrapper systemUtils; + CSystemUtilsWindows m_systemUtils; }; TEST_F(SystemUtilsWindowsUT, TimerResolution) { - systemUtils.SetFrequency(SEC); - EXPECT_EQ(1u, systemUtils.GetTimeStampExactResolution()); + m_systemUtils.SetFrequency(SEC); + EXPECT_EQ(1u, m_systemUtils.GetTimeStampExactResolution()); - systemUtils.SetFrequency(SEC/3); - EXPECT_EQ(3u, systemUtils.GetTimeStampExactResolution()); + m_systemUtils.SetFrequency(SEC/3); + EXPECT_EQ(3u, m_systemUtils.GetTimeStampExactResolution()); } TEST_F(SystemUtilsWindowsUT, TimeStampDiff) { - systemUtils.SetFrequency(SEC); + m_systemUtils.SetFrequency(SEC); SystemTimeStamp before, after; before.counterValue = 100; after.counterValue = 200; - long long tDiff = systemUtils.TimeStampExactDiff(&before, &after); + long long tDiff = m_systemUtils.TimeStampExactDiff(&before, &after); EXPECT_EQ( 100, tDiff); - tDiff = systemUtils.TimeStampExactDiff(&after, &before); + tDiff = m_systemUtils.TimeStampExactDiff(&after, &before); EXPECT_EQ(-100, tDiff); // ------- - systemUtils.SetFrequency(SEC/3); + m_systemUtils.SetFrequency(SEC/3); before.counterValue = 200; after.counterValue = 400; - tDiff = systemUtils.TimeStampExactDiff(&before, &after); + tDiff = m_systemUtils.TimeStampExactDiff(&before, &after); EXPECT_EQ( 200*3, tDiff); - tDiff = systemUtils.TimeStampExactDiff(&after, &before); + tDiff = m_systemUtils.TimeStampExactDiff(&after, &before); EXPECT_EQ(-200*3, tDiff); } diff --git a/test/unit/graphics/core/device_mock.h b/test/unit/graphics/core/device_mock.h deleted file mode 100644 index 5ab0b7d5..00000000 --- a/test/unit/graphics/core/device_mock.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsiteс.ch; http://colobot.info; http://github.com/colobot - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://gnu.org/licenses - */ -#pragma once - -#include "graphics/core/device.h" - -#include - -class CDeviceMock : public Gfx::CDevice -{ -public: - CDeviceMock() {} - - MOCK_METHOD0(DebugHook, void()); - MOCK_METHOD0(DebugLights, void()); - - MOCK_METHOD0(Create, bool()); - MOCK_METHOD0(Destroy, void()); - - MOCK_METHOD0(BeginScene, void()); - MOCK_METHOD0(EndScene, void()); - - MOCK_METHOD0(Clear, void()); - - MOCK_METHOD2(SetTransform, void(Gfx::TransformType type, const Math::Matrix &matrix)); - - MOCK_METHOD1(SetMaterial, void(const Gfx::Material &material)); - - MOCK_METHOD0(GetMaxLightCount, int()); - - MOCK_METHOD2(SetLight, void(int index, const Gfx::Light &light)); - MOCK_METHOD1(GetLight, const Gfx::Light&(int index)); - - MOCK_METHOD2(SetLightEnabled, void(int index, bool enabled)); - - MOCK_METHOD2(CreateTexture, Gfx::Texture(CImage *image, const Gfx::TextureCreateParams ¶ms)); - MOCK_METHOD2(CreateTexture, Gfx::Texture(ImageData *data, const Gfx::TextureCreateParams ¶ms)); - - MOCK_METHOD1(DestroyTexture, void(const Gfx::Texture &texture)); - MOCK_METHOD0(DestroyAllTextures, void()); - - MOCK_METHOD0(GetMaxTextureStageCount, int()); - - MOCK_METHOD2(SetTexture, void(int index, const Gfx::Texture &texture)); - MOCK_METHOD2(SetTexture, void(int index, unsigned int textureId)); - - MOCK_METHOD2(SetTextureEnabled, void(int index, bool enabled)); - - MOCK_METHOD2(SetTextureStageParams, void(int index, const Gfx::TextureStageParams ¶ms)); - - MOCK_METHOD3(SetTextureStageWrap, void(int index, Gfx::TexWrapMode wrapS, Gfx::TexWrapMode wrapT)); - - MOCK_METHOD4(DrawPrimitive, void(Gfx::PrimitiveType type, const Gfx::Vertex *vertices, int vertexCount, Gfx::Color color)); - MOCK_METHOD4(DrawPrimitive, void(Gfx::PrimitiveType type, const Gfx::VertexTex2 *vertices, int vertexCount, Gfx::Color color)); - MOCK_METHOD3(DrawPrimitive, void(Gfx::PrimitiveType type, const Gfx::VertexCol *vertices, int vertexCount)); - - MOCK_METHOD3(CreateStaticBuffer, unsigned int(Gfx::PrimitiveType primitiveType, const Gfx::Vertex* vertices, int vertexCount)); - MOCK_METHOD3(CreateStaticBuffer, unsigned int(Gfx::PrimitiveType primitiveType, const Gfx::VertexTex2* vertices, int vertexCount)); - MOCK_METHOD3(CreateStaticBuffer, unsigned int(Gfx::PrimitiveType primitiveType, const Gfx::VertexCol* vertices, int vertexCount)); - - MOCK_METHOD4(UpdateStaticBuffer, void(unsigned int bufferId, Gfx::PrimitiveType primitiveType, const Gfx::Vertex* vertices, int vertexCount)); - MOCK_METHOD4(UpdateStaticBuffer, void(unsigned int bufferId, Gfx::PrimitiveType primitiveType, const Gfx::VertexTex2* vertices, int vertexCount)); - MOCK_METHOD4(UpdateStaticBuffer, void(unsigned int bufferId, Gfx::PrimitiveType primitiveType, const Gfx::VertexCol* vertices, int vertexCount)); - - MOCK_METHOD1(DrawStaticBuffer, void(unsigned int bufferId)); - - MOCK_METHOD1(DestroyStaticBuffer, void(unsigned int bufferId)); - - MOCK_METHOD2(ComputeSphereVisibility, int(const Math::Vector ¢er, float radius)); - - MOCK_METHOD2(SetRenderState, void(Gfx::RenderState state, bool enabled)); - MOCK_METHOD1(GetRenderState, bool(Gfx::RenderState state)); - - MOCK_METHOD1(SetDepthTestFunc, void(Gfx::CompFunc func)); - - MOCK_METHOD1(SetDepthBias, void(float factor)); - - MOCK_METHOD2(SetAlphaTestFunc, void(Gfx::CompFunc func, float refValue)); - - MOCK_METHOD2(SetBlendFunc, void(Gfx::BlendFunc srcBlend, Gfx::BlendFunc dstBlend)); - - MOCK_METHOD1(SetClearColor, void(const Gfx::Color &color)); - - MOCK_METHOD1(SetGlobalAmbient, void(const Gfx::Color &color)); - - MOCK_METHOD5(SetFogParams, void(Gfx::FogMode mode, const Gfx::Color &color, float start, float end, float density)); - - MOCK_METHOD1(SetCullMode, void(Gfx::CullMode mode)); - - MOCK_METHOD1(SetShadeModel, void(Gfx::ShadeModel model)); - - MOCK_METHOD1(SetFillMode, void(Gfx::FillMode mode)); - - MOCK_CONST_METHOD0(GetFrameBufferPixels, void*()); -}; diff --git a/test/unit/graphics/engine/engine_mock.h b/test/unit/graphics/engine/engine_mock.h deleted file mode 100644 index 72ceddbb..00000000 --- a/test/unit/graphics/engine/engine_mock.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsiteс.ch; http://colobot.info; http://github.com/colobot - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://gnu.org/licenses - */ -#include "graphics/engine/engine.h" - -#include - -class CEngineMock : public Gfx::CEngine -{ -public: - CEngineMock() : Gfx::CEngine(nullptr) {} - - MOCK_METHOD0(GetPause, bool()); - - MOCK_METHOD0(GetEyePt, Math::Vector()); - MOCK_METHOD0(GetLookatPt, Math::Vector()); -}; diff --git a/test/unit/graphics/engine/lightman_test.cpp b/test/unit/graphics/engine/lightman_test.cpp index d493afb8..ac5b76ef 100644 --- a/test/unit/graphics/engine/lightman_test.cpp +++ b/test/unit/graphics/engine/lightman_test.cpp @@ -18,26 +18,31 @@ */ #include "graphics/engine/lightman.h" -#include "app/system_mock.h" - -#include "graphics/core/device_mock.h" -#include "graphics/engine/engine_mock.h" +#include "graphics/core/device.h" #include +#include + +#include +#include using namespace Gfx; - -using testing::_; -using testing::Invoke; -using testing::Return; +using namespace HippoMocks; +namespace ph = std::placeholders; class LightManagerUT : public testing::Test { protected: - LightManagerUT() - : systemUtils(true) - , lightManager(&engine) + LightManagerUT() : + m_systemUtils(nullptr), + m_engine(nullptr), + m_device(nullptr) {} + ~LightManagerUT() NOEXCEPT + {} + + void SetUp() OVERRIDE; + void TearDown() OVERRIDE; void PrepareLightTesting(int maxLights, Math::Vector eyePos); void CheckLightSorting(EngineObjectType objectType, const std::vector& expectedLights); @@ -46,66 +51,88 @@ protected: Math::Vector pos, EngineObjectType includeType, EngineObjectType excludeType); - CSystemUtilsMock systemUtils; - CLightManager lightManager; - CEngineMock engine; - CDeviceMock device; + std::unique_ptr m_lightManager; + MockRepository m_mocks; + CSystemUtils* m_systemUtils; + CEngine* m_engine; + CDevice* m_device; private: - std::vector dynamicLights; - std::vector expectedLightTypes; - int maxLightsCount; + std::vector m_dynamicLights; + std::vector m_expectedLightTypes; + int m_maxLightsCount; }; +void LightManagerUT::SetUp() +{ + m_systemUtils = m_mocks.Mock(); + CSystemUtils::ReplaceInstance(m_systemUtils); + m_engine = m_mocks.Mock(); + m_device = m_mocks.Mock(); + + m_lightManager.reset(new CLightManager(m_engine)); +} + +void LightManagerUT::TearDown() +{ + CSystemUtils::ReplaceInstance(nullptr); +} + void LightManagerUT::PrepareLightTesting(int maxLights, Math::Vector eyePos) { - maxLightsCount = maxLights; + m_maxLightsCount = maxLights; - EXPECT_CALL(device, GetMaxLightCount()).WillOnce(Return(maxLights)); - lightManager.SetDevice(&device); + m_mocks.OnCall(m_device, CDevice::GetMaxLightCount).Return(maxLights); - ON_CALL(device, SetLight(_, _)).WillByDefault(Invoke(this, &LightManagerUT::CheckLight)); + m_lightManager->SetDevice(m_device); - EXPECT_CALL(engine, GetEyePt()).WillRepeatedly(Return(eyePos)); + m_mocks.OnCall(m_device, CDevice::SetLight).Do(std::bind(&LightManagerUT::CheckLight, this, ph::_1, ph::_2)); + + m_mocks.OnCall(m_engine, CEngine::GetEyePt).Return(eyePos); } void LightManagerUT::CheckLightSorting(EngineObjectType objectType, const std::vector& expectedLights) { - expectedLightTypes = expectedLights; + m_expectedLightTypes = expectedLights; - EXPECT_CALL(device, SetLight(_, _)).Times(expectedLights.size()); + for (int i = 0; i < m_maxLightsCount; ++i) + { + if (i < static_cast( expectedLights.size() )) + { + m_mocks.ExpectCall(m_device, CDevice::SetLight).With(i, _); + m_mocks.ExpectCall(m_device, CDevice::SetLightEnabled).With(i, true); + } + else + { + m_mocks.ExpectCall(m_device, CDevice::SetLightEnabled).With(i, false); + } + } - for (int i = 0; i < static_cast( expectedLights.size() ); ++i) - EXPECT_CALL(device, SetLightEnabled(i, true)); - - for (int i = expectedLights.size(); i < maxLightsCount; ++i) - EXPECT_CALL(device, SetLightEnabled(i, false)); - - lightManager.UpdateDeviceLights(objectType); + m_lightManager->UpdateDeviceLights(objectType); } void LightManagerUT::CheckLight(int index, const Light& light) { - ASSERT_TRUE(index >= 0 && index < static_cast( expectedLightTypes.size() )); - ASSERT_EQ(expectedLightTypes[index], light.type); + ASSERT_TRUE(index >= 0 && index < static_cast( m_expectedLightTypes.size() )); + ASSERT_EQ(m_expectedLightTypes[index], light.type); } void LightManagerUT::AddLight(int type, LightPriority priority, bool used, bool enabled, Math::Vector pos, EngineObjectType includeType, EngineObjectType excludeType) { - int rank = lightManager.CreateLight(priority); + int rank = m_lightManager->CreateLight(priority); Light light; light.type = static_cast(type); light.position = pos; - lightManager.SetLight(rank, light); + m_lightManager->SetLight(rank, light); - lightManager.SetLightEnabled(rank, enabled); - lightManager.SetLightIncludeType(rank, includeType); - lightManager.SetLightExcludeType(rank, excludeType); + m_lightManager->SetLightEnabled(rank, enabled); + m_lightManager->SetLightIncludeType(rank, includeType); + m_lightManager->SetLightExcludeType(rank, excludeType); if (!used) - lightManager.DeleteLight(rank); + m_lightManager->DeleteLight(rank); } TEST_F(LightManagerUT, LightSorting_UnusedOrDisabledAreSkipped)

::print(os, p, true); + os << ")"; + } +}; + +template +class ref_comparable_assignable_tuple : public base_tuple +{ +public: + virtual bool operator==(const ref_tuple &bo) = 0; + virtual void assign_from(ref_tuple &from) = 0; + virtual void assign_to(ref_tuple &to) = 0; +}; + +template struct no_array { typedef T type; }; +template struct no_array { typedef T* type; }; + +template +struct store_as +{ + typedef typename no_array::type type; +}; + +template +struct store_as +{ + typedef typename no_array::type type; +}; + +template +class copy_tuple : public ref_comparable_assignable_tuple +{ +public: + typename store_as::type a; + typename store_as::type b; + typename store_as::type c; + typename store_as::type d; + typename store_as::type e; + typename store_as::type f; + typename store_as::type g; + typename store_as::type h; + typename store_as::type i; + typename store_as::type j; + typename store_as::type k; + typename store_as::type l; + typename store_as::type m; + typename store_as::type n; + typename store_as::type o; + typename store_as::type p; + copy_tuple(typename store_as::type a, typename store_as::type b, + typename store_as::type c, typename store_as::type d, + typename store_as::type e, typename store_as::type f, + typename store_as::type g, typename store_as::type h, + typename store_as::type i, typename store_as::type j, + typename store_as::type k, typename store_as::type l, + typename store_as::type m, typename store_as::type n, + typename store_as::type o, typename store_as::type p) + : a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h), i(i), j(j), k(k), l(l), m(m), n(n), o(o), p(p) + {} + bool operator==(const ref_tuple &to) + { + return (comparer::compare(a, to.a) && + comparer::compare(b, to.b) && + comparer::compare(c, to.c) && + comparer::compare(d, to.d) && + comparer::compare(e, to.e) && + comparer::compare(f, to.f) && + comparer::compare(g, to.g) && + comparer::compare(h, to.h) && + comparer::compare(i, to.i) && + comparer::compare(j, to.j) && + comparer::compare(k, to.k) && + comparer::compare(l, to.l) && + comparer::compare(m, to.m) && + comparer::compare(n, to.n) && + comparer::compare(o, to.o) && + comparer