如何将两个 C 风格的数组匹配到 google 模拟中?

How to match two C-style arrays into google mock?

我想检查是否使用这两个 C 样式数组调用了 rbMapDataSecS_VerifySHA 函数。 我不能写 With 两次。 我怎样才能得到它?

Process finished with exit code 1 Failure .With() cannot appear more than once in an EXPECT_CALL().

EXPECT_CALL(g_objRbMapDataSecSMock, rbMapDataSecS_VerifySHA(_,size,_,buffSize))
                .With(Args<0, 1>(ElementsAreArray(data.begin(), data.end())))
                .With(Args<2, 3>(ElementsAreArray(buffer.begin(), buffer.end())))
                .Times(1)
                .WillRepeatedly(Return(map_data_sec_RET_OK));

好的,我更仔细地阅读了错误信息,问题很简单。

这是 MCVE,我在其中删除了您的实现细节,重现并修复了它:

using testing::_;
using testing::AllOf;
using testing::Args;

struct TestMock {
    MOCK_METHOD(bool, foo, (int a, int b), ());
};


TEST(MockUseWith, ReproduceIt)
{
    TestMock mock;

    EXPECT_CALL(mock, foo(_, _))
        .With(Args<0>(1))
        .With(Args<1>(2));

    mock.foo(1, 2);
}

TEST(MockUseWith, FixIt)
{
    TestMock mock;

    EXPECT_CALL(mock, foo(_, _))
        .With(AllOf(Args<0>(1), Args<1>(2)));

    mock.foo(1, 2);
}

https://godbolt.org/z/sajvrj