chronos38 / googlemock

Automatically exported from code.google.com/p/googlemock
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

SetArgumentPointee should support string literal parameters. #61

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
SetArgumentPointee<0>("hello") should compile but doesn't.

Original issue reported on code.google.com by zhanyong...@gmail.com on 7 Aug 2009 at 6:38

GoogleCodeExporter commented 9 years ago
I tried to add a template class specialization in gmock-actions.h file, so that 
we would have a specialized action to handle C strings, but I was not able to 
compile it together with a test that uses SetArgumentPointee<0>("string"). From 
compiler errors, I'm guessing that although I'm defining the specialized class 
as taking char* in the constructor, there is another code somewhere that 
actually constructs SetArgumentPointee with <char> instead of <char*>.

Am I guessing correctly? Where should I look for the other code that does this?

Piotr

Original comment by pgo...@gmail.com on 24 Nov 2010 at 1:35

GoogleCodeExporter commented 9 years ago
Hi Piotr,

Would you mind posting the question to the mailing list?  That will reach far 
more people.  (We have no dedicated people monitoring the issue tracker.)  
Thanks.

Original comment by w...@google.com on 24 Nov 2010 at 5:37

GoogleCodeExporter commented 9 years ago
I have a fix that's waiting to be reviewed.

Original comment by w...@google.com on 1 Dec 2010 at 8:08

GoogleCodeExporter commented 9 years ago
Fixed in r352.

Original comment by w...@google.com on 3 Dec 2010 at 7:02

GoogleCodeExporter commented 9 years ago
I've built gmock off r352, but I still can't get this to work with the below 
test program.

#include <gtest/gtest.h>
#include <gmock/gmock.h>
using namespace testing;

class BoomStream
{
    public:
        MOCK_METHOD1(read, void(char* s));
};

TEST(BoomTest, Boom) {
    char text[] = "ABCDEFGHIJKLMNOP";
    BoomStream bs; 
    EXPECT_CALL(bs, read(_)).WillOnce(SetArgumentPointee<0>("OHAI!"));
    bs.read(text);
}

ERROR

/usr/local/include/gmock/gmock-actions.h:732: error: invalid conversion from 
'const 
char* const' to 'char'

Am I doing it wrong?

Original comment by lists%th...@gtempaccount.com on 7 Dec 2010 at 10:29