Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 谷歌模拟:如何从模拟参数中的指针复制内存?_C++_Unit Testing_Googlemock - Fatal编程技术网

C++ 谷歌模拟:如何从模拟参数中的指针复制内存?

C++ 谷歌模拟:如何从模拟参数中的指针复制内存?,c++,unit-testing,googlemock,C++,Unit Testing,Googlemock,我用签名模拟了以下函数: uint32 Icc_u_SendMessage(te_IccTransferType e_DataTxType, SW_e_IccMsgType e_MsgType, uint8 *const pui8_DataRef, const uint32 ui32_DataSize, const SW_e_CoreIdent e_MsgDestination) 我感兴趣的参数是Arg2(pui8_DataRef) 调用被测函数: MessageBuffer<ET_t_

我用签名模拟了以下函数:

uint32 Icc_u_SendMessage(te_IccTransferType e_DataTxType, SW_e_IccMsgType e_MsgType, uint8 *const pui8_DataRef, const uint32 ui32_DataSize, const SW_e_CoreIdent e_MsgDestination)
我感兴趣的参数是Arg2(
pui8_DataRef

调用被测函数:

MessageBuffer<ET_t_SignalToGs> s_locPayloadToGs; (Local)
iccReturnValue = c_ICC_Messages::ICC_ui32_SendMessage(c_ICC_Messages::e_TxSendRefCopyData, e_msg, (uint8*)&locPayloadToGs, u_size, e_dst);
谢谢

您可以定义您的:

只需将测试中的
SaveArgPointee(&expectedPayload)
替换为
SavePayload(&expectedPayload)

但是,您真正需要的是一个-它将匹配负载的现状,类似于:

MATCHER_P(matchPayload, expectedPayload)
{
    auto beginOfArray = get<2>(arg);
    auto sizeOfArray = get<3>(arg);
    auto endOfArray = beginOfArray  + sizeOfArray ;

    return expectedPayload->equalTo(beginOfArray , endOfArray);
           //               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
           //  that only my guess how it is possible to compare payloads   
}
ACTION_P(SavePayload, expectedPayload)
{
    auto beginOfArray = arg2;
    auto sizeOfArray = arg3;
    auto endOfArray = beginOfArray  + sizeOfArray ;

    expectedPayload->assign(beginOfArray , endOfArray);
    //               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
    //  that only my guess how it is possible to store payload
}
MATCHER_P(matchPayload, expectedPayload)
{
    auto beginOfArray = get<2>(arg);
    auto sizeOfArray = get<3>(arg);
    auto endOfArray = beginOfArray  + sizeOfArray ;

    return expectedPayload->equalTo(beginOfArray , endOfArray);
           //               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
           //  that only my guess how it is possible to compare payloads   
}
c_event_transceiver::MessageBuffer<c_event_transceiver::ET_t_SignalToGs> expectedPayload;
// expectedPayload - build it to be as this you expect
...

EXPECT_CALL(obj_MockIccMessages, ICC_ui32_SendMessage(c_ICC_Messages::e_TxSendRefCopyData,
                     e_MsgToGs,
                     _,
                     sizeof(expectedLocPayload),
                     c_event_transceiver::a_ConfigMapGsToCore[0].e_core))
.With(matchPayload(&expectedPayload)).WillOnce(Return(retSendMessage));