Gmock - matching structures

后端 未结 5 1851
误落风尘
误落风尘 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:48

    If there a need to explicitly test for specific value of just one field of a struct (or one "property" of a class), gmock has a simple way to test this with the "Field" and "Property" definitions. With a struct:

    EXPECT_CALL( someMock, SomeMethod( Field( &SomeStruct::data1, expectedValue )));
    

    Or, alternatively if we have SomeClass (intead of SomeStruct), that has private member variables and public getter functions:

    EXPECT_CALL( someMock, SomeMethod( Property( &SomeClass::getData1, expectedValue )));
    

提交回复
热议问题