GithubHelp home page GithubHelp logo

Comments (3)

GoogleCodeExporter avatar GoogleCodeExporter commented on May 29, 2024
Was rereading the docs and see a comment in the Section Combining Actions in 
Cookbook:
It says " Only the return value of the last action in the sequence will be 
used."

So I am thinking that the only way to correctly return an output param for a 
function
that returns a non void type is to use a DoAll with the SetArgumentPointee 
first in
the list of combined actions and the Return action last.  Makes sense when I 
think
about it and having looked at the code some more I see that is how it works.  
Looks
like this is not a problem afterall.

Original comment by [email protected] on 25 Dec 2008 at 4:50

from googlemock.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 29, 2024
So my corrected code would be:
#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::internal::Function;
class Foo
{
public:
  virtual bool func(int*) = 0;
};

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


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

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

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

  Bar bar(&foo);

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

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

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

  return RUN_ALL_TESTS();
}


Original comment by [email protected] on 25 Dec 2008 at 4:56

from googlemock.

GoogleCodeExporter avatar GoogleCodeExporter commented on May 29, 2024
This is by design.  DoAll() is the intended solution.

Original comment by [email protected] on 26 Dec 2008 at 6:56

  • Changed state: WontFix

from googlemock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.