chromium/services/device/public/cpp/hid/hid_report_descriptor_unittest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <stddef.h>
#include <stdint.h>

#include <limits>
#include <sstream>
#include <unordered_map>
#include <utility>

#include "services/device/public/cpp/hid/hid_report_descriptor.h"
#include "services/device/public/cpp/hid/hid_report_type.h"
#include "services/device/public/cpp/hid/hid_report_utils.h"
#include "services/device/public/cpp/test/test_report_descriptors.h"
#include "services/device/public/mojom/hid.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace device {

namespace {
HidReport;
HidReportMap;
HidCollectionVector;

// HID unit values.
constexpr uint32_t kUnitCandela =;
constexpr uint32_t kUnitDegrees =;
constexpr uint32_t kUnitInch =;
constexpr uint32_t kUnitNewton =;
constexpr uint32_t kUnitSecond =;

// Report info bitfield values. The bits are:
//   bit 0: Data (0) | Constant (1)
//   bit 1: Array (0) | Variable (1)
//   bit 2: Absolute (0) | Relative (1)
//   bit 3: No Wrap (0) | Wrap (1)
//   bit 4: Linear (0) | Non-Linear (1)
//   bit 5: Preferred State (0) | No Preferred State (1)
//   bit 6: No Null Value (0) | Has Null Value (1)
//   bit 7: Non-Volatile (0) | Volatile (1)
//   bit 8: Bit Field (0) | Buffered Bytes (1)
constexpr uint16_t kNonNullableArray =;
constexpr uint16_t kConstantArray =;
constexpr uint16_t kAbsoluteVariable =;
constexpr uint16_t kConstant =;
constexpr uint16_t kRelativeVariable =;
constexpr uint16_t kConstantRelativeVariable =;
constexpr uint16_t kNonLinearVariable =;
constexpr uint16_t kAbsoluteVariablePreferredState =;
constexpr uint16_t kConstantAbsoluteVariablePreferredState =;
constexpr uint16_t kNullableArray =;
constexpr uint16_t kNullableAbsoluteVariable =;
constexpr uint16_t kVolatileConstant =;
constexpr uint16_t kBufferedBytes =;

// Bit-width and mask for the usage ID field in a 32-bit usage value.
constexpr size_t kUsageIdSizeBits =;
constexpr uint32_t kUsageIdMask =;

// Combined usage page and usage ID values. The usage page occupies the high 16
// bits, the usage ID occupies the low 16 bits.
constexpr uint32_t kUsageButton =;
constexpr uint32_t kUsageConsumer =;
constexpr uint32_t kUsageConsumerControl =;
constexpr uint32_t kUsageConsumerModeStep =;
constexpr uint32_t kUsageConsumerFastForward =;
constexpr uint32_t kUsageConsumerRewind =;
constexpr uint32_t kUsageConsumerScanNextTrack =;
constexpr uint32_t kUsageConsumerScanPreviousTrack =;
constexpr uint32_t kUsageConsumerStop =;
constexpr uint32_t kUsageConsumerPlayPause =;
constexpr uint32_t kUsageConsumerMute =;
constexpr uint32_t kUsageConsumerVolumeIncrement =;
constexpr uint32_t kUsageConsumerVolumeDecrement =;
constexpr uint32_t kUsageConsumerACHome =;
constexpr uint32_t kUsageConsumerACBack =;
constexpr uint32_t kUsageDigitizer =;
constexpr uint32_t kUsageDigitizerDigitizer =;
constexpr uint32_t kUsageDigitizerBarrelSwitch =;
constexpr uint32_t kUsageDigitizerInRange =;
constexpr uint32_t kUsageDigitizerPuck =;
constexpr uint32_t kUsageDigitizerStylus =;
constexpr uint32_t kUsageDigitizerTipPressure =;
constexpr uint32_t kUsageDigitizerTipSwitch =;
constexpr uint32_t kUsageGenericDesktop =;
constexpr uint32_t kUsageGenericDesktopDial =;
constexpr uint32_t kUsageGenericDesktopGamePad =;
constexpr uint32_t kUsageGenericDesktopHatSwitch =;
constexpr uint32_t kUsageGenericDesktopJoystick =;
constexpr uint32_t kUsageGenericDesktopKeyboard =;
constexpr uint32_t kUsageGenericDesktopMouse =;
constexpr uint32_t kUsageGenericDesktopPointer =;
constexpr uint32_t kUsageGenericDesktopRx =;
constexpr uint32_t kUsageGenericDesktopRy =;
constexpr uint32_t kUsageGenericDesktopRz =;
constexpr uint32_t kUsageGenericDesktopSystemControl =;
constexpr uint32_t kUsageGenericDesktopSystemMainMenu =;
constexpr uint32_t kUsageGenericDesktopVbrx =;
constexpr uint32_t kUsageGenericDesktopVbry =;
constexpr uint32_t kUsageGenericDesktopVbrz =;
constexpr uint32_t kUsageGenericDesktopVx =;
constexpr uint32_t kUsageGenericDesktopVy =;
constexpr uint32_t kUsageGenericDesktopVz =;
constexpr uint32_t kUsageGenericDesktopWheel =;
constexpr uint32_t kUsageGenericDesktopX =;
constexpr uint32_t kUsageGenericDesktopY =;
constexpr uint32_t kUsageGenericDesktopZ =;
constexpr uint32_t kUsageGenericDeviceBatteryStrength =;
constexpr uint32_t kUsageKeyboard =;
constexpr uint32_t kUsageKeyboardApplication =;
constexpr uint32_t kUsageKeyboardLeftControl =;
constexpr uint32_t kUsageKeyboardRightGui =;
constexpr uint32_t kUsageLed =;
constexpr uint32_t kUsageLedNumLock =;
constexpr uint32_t kUsageLedCapsLock =;
constexpr uint32_t kUsageLedScrollLock =;
constexpr uint32_t kUsageLedCompose =;
constexpr uint32_t kUsageLedKana =;
constexpr uint32_t kUsageLedMute =;
constexpr uint32_t kUsageLedOffHook =;
constexpr uint32_t kUsageLedRing =;
constexpr uint32_t kUsageLedSpeaker =;
constexpr uint32_t kUsageLedHold =;
constexpr uint32_t kUsageLedMicrophone =;
constexpr uint32_t kUsageLedOnLine =;
constexpr uint32_t kUsageMonitor0 =;
constexpr uint32_t kUsageMonitorControl =;
constexpr uint32_t kUsageMonitorEdidInfo =;
constexpr uint32_t kUsageMonitorVdifInfo =;
constexpr uint32_t kUsageMonitor2 =;
constexpr uint32_t kUsageMonitorBrightness =;
constexpr uint32_t kUsageMonitorContrast =;
constexpr uint32_t kUsageMonitorRedVideoGain =;
constexpr uint32_t kUsageMonitorGreenVideoGain =;
constexpr uint32_t kUsageMonitorBlueVideoGain =;
constexpr uint32_t kUsageMonitorHorizontalPosition =;
constexpr uint32_t kUsageMonitorHorizontalSize =;
constexpr uint32_t kUsageMonitorVerticalPosition =;
constexpr uint32_t kUsageMonitorVerticalSize =;
constexpr uint32_t kUsageMonitorTrapezoidalDistortion =;
constexpr uint32_t kUsageMonitorTilt =;
constexpr uint32_t kUsageMonitorRedVideoBlackLevel =;
constexpr uint32_t kUsageMonitorGreenVideoBlackLevel =;
constexpr uint32_t kUsageMonitorBlueVideoBlackLevel =;
constexpr uint32_t kUsagePid =;
constexpr uint32_t kUsagePidSetEffectReport =;
constexpr uint32_t kUsagePidDuration =;
constexpr uint32_t kUsagePidMagnitude =;
constexpr uint32_t kUsagePidLoopCount =;
constexpr uint32_t kUsagePidDCEnableActuators =;
constexpr uint32_t kUsagePidStartDelay =;
constexpr uint32_t kUsageSimulation =;
constexpr uint32_t kUsageSimulationAccelerator =;
constexpr uint32_t kUsageSimulationBrake =;
constexpr uint32_t kUsageTelephony =;
constexpr uint32_t kUsageTelephonyHeadset =;
constexpr uint32_t kUsageTelephonyKeyPad =;
constexpr uint32_t kUsageTelephonyProgrammableButton =;
constexpr uint32_t kUsageTelephonyHookSwitch =;
constexpr uint32_t kUsageTelephonyFlash =;
constexpr uint32_t kUsageTelephonyRedial =;
constexpr uint32_t kUsageTelephonyLine =;
constexpr uint32_t kUsageTelephonyPhoneMute =;
constexpr uint32_t kUsageTelephonySpeedDial =;
constexpr uint32_t kUsageTelephonyLineBusyTone =;
constexpr uint32_t kUsageTelephonyRinger =;
constexpr uint32_t kUsageTelephonyPhoneKey0 =;
constexpr uint32_t kUsageTelephonyPhoneKeyPound =;
constexpr uint32_t kUsageVendor =;
constexpr uint32_t kUsageVendor02 =;
constexpr uint32_t kUsageVendor05 =;
constexpr uint32_t kUsageVendor30 =;
constexpr uint32_t kUsageVendor40 =;
constexpr uint32_t kUsageVendor80 =;

// Report item tags.
constexpr HidReportDescriptorItem::Tag kInput =;
constexpr HidReportDescriptorItem::Tag kOutput =;
constexpr HidReportDescriptorItem::Tag kFeature =;
constexpr uint32_t kCollectionTypeApplication =;
constexpr uint32_t kCollectionTypeLogical =;
constexpr uint32_t kCollectionTypePhysical =;

}  // namespace

class HidReportDescriptorTest : public testing::Test {};

TEST_F(HidReportDescriptorTest, ValidateDetails_Digitizer) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_Digitizer) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_Keyboard) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_Keyboard) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_Monitor) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_Monitor) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_Mouse) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_Mouse) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_LogitechUnifyingReceiver) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_LogitechUnifyingReceiver) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_SonyDualshock3) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_SonyDualshock3) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_SonyDualshock4) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_SonyDualshock4) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_XboxWirelessController) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_XboxWirelessController) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_NintendoSwitchProController) {}

TEST_F(HidReportDescriptorTest,
       ValidateCollections_NintendoSwitchProController) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_XboxAdaptiveController) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_XboxAdaptiveController) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_NexusPlayerController) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_NexusPlayerController) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_SteamControllerKeyboard) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_SteamControllerKeyboard) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_SteamControllerMouse) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_SteamControllerMouse) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_SteamControllerVendor) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_SteamControllerVendor) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_XSkillsUsbAdapter) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_XSkillsUsbAdapter) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_BelkinNostromoKeyboard) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_BelkinNostromoKeyboard) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_BelkinNostromoMouseAndExtra) {}

TEST_F(HidReportDescriptorTest,
       ValidateCollections_BelkinNostromoMouseAndExtra) {}

TEST_F(HidReportDescriptorTest, ValidateDetails_JabraLink380c) {}

TEST_F(HidReportDescriptorTest, ValidateCollections_JabraLink380c) {}

TEST_F(HidReportDescriptorTest, InvalidReportSizePermitted) {}

TEST_F(HidReportDescriptorTest, ReasonablyHugeReportNotIgnored) {}

TEST_F(HidReportDescriptorTest, UnreasonablyHugeReportIgnored) {}

TEST_F(HidReportDescriptorTest, HighlyNestedReportLimitsDepth) {}

TEST_F(HidReportDescriptorTest, ExtraEndCollectionIgnored) {}

TEST_F(HidReportDescriptorTest, ZeroByteLogicalMinMax) {}

TEST_F(HidReportDescriptorTest, OneByteLogicalMinMax) {}

TEST_F(HidReportDescriptorTest, TwoByteLogicalMinMax) {}

TEST_F(HidReportDescriptorTest, FourByteLogicalMinMax) {}

}  // namespace device