How to match argument reference in Google Mock

2,125 views
Skip to first unread message

Zangw

unread,
Apr 27, 2014, 10:19:25 PM4/27/14
to googl...@googlegroups.com

I am newer for google mock. Now I have one question about how to match the argument reference? here are the codes

    class Parameter{
    public:
        int m_idata;
        char m_cdata;
        bool Parameter::operator ==(const Parameter& element) const{
            return (m_idata == element.m_idata && m_cdata == element.m_cdata);
        }
    };

    class FooInterface{
    public:
        virtual ~FooInterface() {}

        virtual void SetParameter(Parameter& val) = 0;
    };
    // mock class
    class MockFoo: public FooInterface {
    public:        
        MOCK_METHOD1(SetParameter, void(Parameter& val));
    };

    TEST(FooTest, setParameterTest)
    {   
            MockFoo mockFoo;

            EXPECT_CALL(mockFoo, SetParameter(An<Parameter&>())); // How to match argument reference???

            Parameter para;
            mockFoo.SetParameter(para);  // there is an exception here, why???
    }

and I also try those codes to match SetParameter()

Parameter test_para;
EXPECT_CALL(mockFoo, SetParameter(Ref(test_para)));

And

EXPECT_CALL(mockFoo, SetParameter(A<Parameter&>()));

Both those two codes can also cause exception... Could any one tell me how to match the argument reference Parameter& in the function SetParameter()?

Vlad Losev

unread,
May 8, 2014, 4:17:54 PM5/8/14
to Google C++ Mocking Framework
What kinds of exceptions are you seeing? What are the error messages? What OS and what compiler are you using? Can you provide a short but complete code snippet?


--

---
You received this message because you are subscribed to the Google Groups "Google C++ Mocking Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to googlemock+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/googlemock/276dcced-9ca3-4953-a738-319c0c953917%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages