Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetArgumentReferee #17

Closed
GoogleCodeExporter opened this issue Apr 6, 2015 · 3 comments
Closed

SetArgumentReferee #17

GoogleCodeExporter opened this issue Apr 6, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

Possible Enhancement:


template <size_t N, typename A, bool kIsProto>
class SetArgumentRefereeAction {
 public:
  // Constructs an action that sets the variable pointed to by the
  // N-th function argument to 'value'.
  explicit SetArgumentRefereeAction(const A& value) : value_(value) {}

  template <typename Result, typename ArgumentTuple>
      void Perform(const ArgumentTuple& args) const {
           CompileAssertTypesEqual<void, Result>();
       ::std::tr1::get<N>(args) = value_;
  }

 private:
  const A value_;
};

template <size_t N, typename T>
PolymorphicAction<
  internal::SetArgumentRefereeAction<
    N, T, internal::IsAProtocolMessage<T>::value> >
SetArgumentReferee(const T& x) {
  return MakePolymorphicAction(internal::SetArgumentRefereeAction<
      N, T, internal::IsAProtocolMessage<T>::value>(x));
}

with following test case:
#include <gmock/gmock.h>
#include <memory>

using testing::_;
using testing::Return;
using testing::Action;
using testing::ActionInterface;
using testing::MakeAction;
using testing::DoAll;
using testing::SetArgumentPointee;
using testing::SetArgumentReferee;
using testing::internal::Function;

class Foo
{
public:
  virtual bool func(int*) = 0;
  virtual bool funcRef(int&) = 0;
};

class MockFoo : public Foo
{
public:
  MOCK_METHOD1(func, bool(int*));
  MOCK_METHOD1(funcRef, bool(int&));
};

class Bar
{
public:
  explicit Bar(Foo* pFoo) : m_pFoo(pFoo)
  {
  }

  int CallIt()
  {
    int i = 0;
    m_pFoo->func(&i);
    return i;
  }

  int CallItRef()
  {
    int i = 0;
    m_pFoo->funcRef(i);
    return i;
  }

  Foo* m_pFoo;
};

TEST(Testitout, argpointee)
{
  MockFoo foo;
  EXPECT_CALL(foo, func(_))
    .WillOnce(DoAll(SetArgumentPointee<0>(5),Return(true)));

  EXPECT_CALL(foo, funcRef(_))
    .WillOnce(DoAll(SetArgumentReferee<0>(5),Return(true)));

  Bar bar(&foo);

  EXPECT_EQ(5, bar.CallIt());
  EXPECT_EQ(5, bar.CallItRef());
}

int main(int argc, char **argv) {

  std::cout << "Running main() from gtest_main.cc\n";
  testing::InitGoogleTest(&argc, argv);

  return RUN_ALL_TESTS();
}

Original issue reported on code.google.com by ecurbks...@gmail.com on 25 Dec 2008 at 6:02

@GoogleCodeExporter
Copy link
Author

Original comment by shiq...@gmail.com on 26 Dec 2008 at 6:58

  • Added labels: OpSys-All, Priority-Low, Type-Enhancement
  • Removed labels: Priority-Medium, Type-Defect

@GoogleCodeExporter
Copy link
Author

Original comment by shiq...@gmail.com on 26 Dec 2008 at 6:59

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

I've implemented SetArgReferee<k>(value) in the trunk, using the ACTION_P macro.

Original comment by zhanyong...@gmail.com on 19 Feb 2009 at 10:38

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant