Gmock - matching structures

后端 未结 5 1832
误落风尘
误落风尘 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-07 17:08

    This is basically answered above but I want to give you one more good example:

    // some test type
    struct Foo {
        bool b;
        int i;
    };
    
    // define a matcher if ==operator is not needed in production
    MATCHER_P(EqFoo, other, "Equality matcher for type Foo") {
        return std::tie(arg.b, arg.i) == std::tie(other.b, other.i);
    }
    
    // example usage in your test
    const Foo test_value {true, 42};
    EXPECT_CALL(your_mock, YourMethod(EqFoo(test_value)));
    

提交回复
热议问题