Google Mock:无法设置操作,也无法使用SaveArg函数

时间:2018-08-06 21:23:22

标签: c++ gmock

可能我做错了,但这是我得到的:

namespace CoAP
{
    class IUDPProvider
    {
    public:
        virtual void Start(int port) = 0;
        virtual void Stop() = 0;

        virtual void SendPacket(uint8_t* buffer, int length, IPAddress ip, int port) = 0;

        virtual bool ReadNetworkPacket(uint8_t** buffer, int* length, IPAddress* address, int* port) = 0;
        virtual void DestroyNetworkPacket(uint8_t* buffer) = 0;
    };
}

其嘲讽如下:

class UDPProviderMock : public CoAP::IUDPProvider
{
public:
    MOCK_METHOD1(Start, void(int));
    MOCK_METHOD0(Stop, void());

    MOCK_METHOD4(SendPacket, void(uint8_t*, int, CoAP::IPAddress, int));

    MOCK_METHOD4(ReadNetworkPacket, bool(uint8_t**, int*, CoAP::IPAddress*, int*));
    MOCK_METHOD1(DestroyNetworkPacket, void(uint8_t*));
};

我正在尝试对其进行模拟,以检查前两个参数中实际获得了什么“ SendPacket”方法。我写的期望该行并将值复制到缓冲区的行如下:

uint8_t* responseBuffer;
int responseLength;
EXPECT_CALL(udpProviderMock, SendPacket(_, _, requestIPAddress, requestPort))
    .WillOnce(CopyBuffer<0, 1>(&responseBuffer, &responseLength));

我将动作定义为:

ACTION_TEMPLATE(CopyBuffer, HAS_2_TEMPLATE_PARAMS(int, k, int, t), AND_2_VALUE_PARAMS(pointer, length))
{
    //const void* bufferData = (void*)::std::tr1::get<k>(args);
    //const void* lengthData = (void*)::std::tr1::get<t>(args);

    //uint8_t* buffer = new uint8_t[(int)lengthData];
    //std::memcpy(buffer, bufferData, (int)lengthData);

    //*pointer = buffer;
    //*length = (int)lengthData;
}

注意:可能其中的代码已破旧,但是如果可以先进行调用,我正在进行故障排除。

由于出现错误C2440,我无法编译上面的代码:编译器无法从'const int'转换为'uint8_t *'。

我在做什么错了?

0 个答案:

没有答案