/*
 * Check that discovery works with a WTX device.
 */
void RobeWidgetDetectorTest::testWTXDevice() {
  uint8_t info_data[] = {1, 11, 3, 0, 0};
  uint8_t uid_data[] = {0x52, 0x53, 2, 0, 0, 10};
  m_endpoint->AddExpectedRobeDataAndReturn(
      INFO_REQUEST_LABEL,
      NULL,
      0,
      INFO_RESPONSE_LABEL,
      info_data,
      sizeof(info_data));
  m_endpoint->AddExpectedRobeDataAndReturn(
      UID_REQUEST_LABEL,
      NULL,
      0,
      UID_RESPONSE_LABEL,
      uid_data,
      sizeof(uid_data));

  m_detector->Discover(&m_descriptor);
  m_ss.Run();

  OLA_ASSERT(m_found_widget);
  OLA_ASSERT_FALSE(m_failed_widget);

  OLA_ASSERT_EQ(static_cast<uint8_t>(1),
                       m_device_info.hardware_version);
  OLA_ASSERT_EQ(static_cast<uint8_t>(11),
                       m_device_info.software_version);
  OLA_ASSERT_EQ(static_cast<uint8_t>(3),
                       m_device_info.eeprom_version);
  OLA_ASSERT_EQ(UID(0x5253, 0x200000a),
                       m_device_info.uid);
}
/*
 * Check that discovery fails with a locked RUI device.
 */
void RobeWidgetDetectorTest::testLockedRUIDevice() {
  // software version locked (0xe)
  uint8_t info_data[] = {1, 0xe, 3, 0, 0};
  uint8_t uid_data[] = {0x52, 0x53, 1, 0, 0, 10};
  m_endpoint->AddExpectedRobeDataAndReturn(
      INFO_REQUEST_LABEL,
      NULL,
      0,
      INFO_RESPONSE_LABEL,
      info_data,
      sizeof(info_data));
  m_endpoint->AddExpectedRobeDataAndReturn(
      UID_REQUEST_LABEL,
      NULL,
      0,
      UID_RESPONSE_LABEL,
      uid_data,
      sizeof(uid_data));

  m_detector->Discover(&m_descriptor);
  m_ss.Run();

  OLA_ASSERT_FALSE(m_found_widget);
  OLA_ASSERT(m_failed_widget);
}
/**
 * Check a widget that fails to respond
 */
void RobeWidgetDetectorTest::testTimeout() {
  m_endpoint->AddExpectedRobeMessage(INFO_REQUEST_LABEL, NULL, 0);
  m_detector->Discover(&m_descriptor);

  m_ss.Run();
  OLA_ASSERT_FALSE(m_found_widget);
  OLA_ASSERT(m_failed_widget);
}