Gmock - matching structures

后端 未结 5 1842
误落风尘
误落风尘 2021-02-07 16:10

How can I match value of an element in a union for an input argument e.g - if I mock a method with the following signatiure -

    struct SomeStruct
    {   
           


        
5条回答
  •  星月不相逢
    2021-02-07 16:54

    Maybe useless as the question has been answered long time ago but here is a solution that works with any structure and which does not use MATCHER or FIELD.

    Suppose we are checking: methodName(const Foo& foo):

    using ::testing::_;
    
    struct Foo {
        ...
        ...
    };
    
    EXPECT_CALL(mockObject, methodName(_))
        .WillOnce([&expectedFoo](const Foo& foo) {
            // Here, gtest macros can be used to test struct Foo's members
            // one by one for example (ASSERT_TRUE, ASSERT_EQ, ...)
            ASSERT_EQ(foo.arg1, expectedFoo.arg1);
        });
    

提交回复
热议问题