Beispiel #1
0
ssize_t MockUDPSocket::SendTo(const uint8_t *buffer,
                              unsigned int size,
                              const ola::network::IPV4Address &ip_address,
                              unsigned short port) const {
    if (m_discard_mode)
        return size;

    OLA_ASSERT_FALSE(m_expected_calls.empty());
    expected_call call = m_expected_calls.front();

    OLA_ASSERT_DATA_EQUALS(call.data, call.size, buffer, size);
    OLA_ASSERT_EQ(call.address, ip_address);
    OLA_ASSERT_EQ(call.port, port);
    if (call.free_data)
        delete[] call.data;

    m_expected_calls.pop();
    return size;
}
Beispiel #2
0
/**
 * Called when there is new data available. Make sure it matches what we
 * expected and if there is return data send it.
 */
void MockEndpoint::DescriptorReady() {
  OLA_ASSERT_FALSE(m_expected_data.empty());

  while (m_descriptor->DataRemaining()) {
    expected_data call = m_expected_data.front();
    m_expected_data.pop();

    uint8_t data[call.expected_data_frame.length];
    unsigned int data_received = 0;

    while (data_received != call.expected_data_frame.length) {
      unsigned int offset = data_received;
      m_descriptor->Receive(data + offset,
                            call.expected_data_frame.length - offset,
                            data_received);
      data_received += offset;
    }

    OLA_ASSERT_DATA_EQUALS(call.expected_data_frame.data,
                           call.expected_data_frame.length,
                           data,
                           data_received);

    if (call.free_request)
      delete[] call.expected_data_frame.data;

    if (call.send_response)
      OLA_ASSERT_TRUE(m_descriptor->Send(call.return_data_frame.data,
                                         call.return_data_frame.length));

    if (call.callback)
      call.callback->Run();

    if (call.free_response)
      delete[] call.return_data_frame.data;
  }
}