hid_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package hid
  2. import (
  3. "testing"
  4. "github.com/sstallion/go-hid"
  5. )
  6. func TestReadTimesOutWithoutData(t *testing.T) {
  7. // We can't directly inject an fd into the go-hid Device,
  8. // so we skip this test without a real HID device.
  9. t.Skip("requires real HID device")
  10. }
  11. // The signature is an exact pair, and the two halves are load-bearing in both
  12. // directions: a firmware that puts Raw HID on a neighbouring page is a board this
  13. // tool cannot address, and taking it anyway would mean writing lighting commands
  14. // to a collection that does not answer them. A board that does so has to show up
  15. // in the passed-over listing instead, which is what tells a user why.
  16. func TestRawHIDIsAnExactPair(t *testing.T) {
  17. tests := []struct {
  18. name string
  19. usagePage uint16
  20. usage uint16
  21. want bool
  22. }{
  23. {name: "the QMK Raw HID signature", usagePage: 0xff60, usage: 0x61, want: true},
  24. {name: "the Impact 80's own vendor interface", usagePage: 0xff80, usage: 0x61, want: false},
  25. {name: "another usage on the same page", usagePage: 0xff60, usage: 0x62, want: false},
  26. {name: "the keyboard collection of a keyboard", usagePage: 0x0001, usage: 0x06, want: false},
  27. {name: "the page with no usage", usagePage: 0xff60, usage: 0x00, want: false},
  28. }
  29. for _, tt := range tests {
  30. t.Run(tt.name, func(t *testing.T) {
  31. info := &hid.DeviceInfo{UsagePage: tt.usagePage, Usage: tt.usage}
  32. if got := isRawHID(info); got != tt.want {
  33. t.Errorf("isRawHID(%04X/%02X) = %t, want %t", tt.usagePage, tt.usage, got, tt.want)
  34. }
  35. })
  36. }
  37. }