#include "device/gamepad/gamepad_blocklist.h"
#include <array>
#include "device/gamepad/gamepad_id_list.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace device {
namespace {
constexpr auto kBlockedDevices =
std::to_array<std::pair<uint16_t, uint16_t>>({
{0x045e, 0x0922},
{0x05ac, 0x3232},
{0x17ef, 0x6099},
});
constexpr size_t kBlockedDevicesLength = std::size(kBlockedDevices);
constexpr auto kBlockedVendorDevices =
std::to_array<std::pair<uint16_t, uint16_t>>({
{0x056a, 0x50b8},
{0x06cb, 0x000f},
{0x2833, 0x0001},
{0x2833, 0x0021},
{0x2833, 0x0031},
{0x2833, 0x0101},
{0x2833, 0x0201},
{0x2833, 0x0211},
{0x2833, 0x0330},
{0x2833, 0x1031},
{0x2833, 0x2021},
{0x2833, 0x2031},
{0x2833, 0x3031},
{0xb58e, 0x9e84},
});
constexpr size_t kBlockedVendorDevicesLength = std::size(kBlockedVendorDevices);
}
TEST(GamepadBlocklistTest, KnownGamepadsNotBlocked) {
const auto& gamepads = GamepadIdList::Get().GetGamepadListForTesting();
for (const auto& item : gamepads) {
uint16_t vendor = std::get<0>(item);
uint16_t product = std::get<1>(item);
EXPECT_FALSE(GamepadIsExcluded(vendor, product));
}
}
TEST(GamepadBlocklistTest, BlockedDevices) {
for (size_t i = 0; i < kBlockedDevicesLength; ++i) {
const uint16_t vendor = kBlockedDevices[i].first;
const uint16_t product = kBlockedDevices[i].second;
EXPECT_TRUE(GamepadIsExcluded(vendor, product));
EXPECT_FALSE(GamepadIsExcluded(vendor, product - 1));
EXPECT_FALSE(GamepadIsExcluded(vendor, product + 1));
}
}
TEST(GamepadBlocklistTest, BlockedVendors) {
for (size_t i = 0; i < kBlockedVendorDevicesLength; ++i) {
const uint16_t vendor = kBlockedVendorDevices[i].first;
const uint16_t product = kBlockedVendorDevices[i].second;
EXPECT_TRUE(GamepadIsExcluded(vendor, product));
EXPECT_TRUE(GamepadIsExcluded(vendor, product - 1));
EXPECT_TRUE(GamepadIsExcluded(vendor, product + 1));
}
}
}