input_linux_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package input
  2. import "testing"
  3. // import "os"
  4. // import "syscall"
  5. // import "fmt"
  6. import "gitlab.com/beoran/galago/os/linux"
  7. const IN = "by-id/usb-0583_USB_2-axis_8-button_gamepad-event-joystick"
  8. func TestGetDriverVersion(t * testing.T) {
  9. device , err := Open(IN)
  10. if err != nil {
  11. t.Errorf("Error Open: %s\n", err)
  12. return
  13. }
  14. defer device.Close()
  15. version, err := device.DriverVersion()
  16. if err != nil {
  17. t.Errorf("Error GetDriverVersion: %s (%s %x)\n", err,
  18. "EVIOCGVERSION", linux.EVIOCGVERSION)
  19. return
  20. }
  21. if version != linux.EV_VERSION {
  22. t.Errorf("Version %x should be %x", version, linux.EV_VERSION)
  23. }
  24. t.Logf("GetDriverVersion: %d", version)
  25. }
  26. func TestGetName(t * testing.T) {
  27. device , err := Open(IN)
  28. if err != nil {
  29. t.Errorf("Error Open: %s\n", err)
  30. return
  31. }
  32. defer device.Close()
  33. name, err := device.Name()
  34. if err != nil {
  35. t.Errorf("Error GetName: %s\n", err)
  36. return
  37. }
  38. t.Logf("GetName: %s", name)
  39. }
  40. func TestGetId(t * testing.T) {
  41. device , err := Open(IN)
  42. if err != nil {
  43. t.Errorf("Error Open: %s\n", err)
  44. return
  45. }
  46. defer device.Close()
  47. id, err := device.Id()
  48. if err != nil {
  49. t.Errorf("Error GetId: %s\n", err)
  50. return
  51. }
  52. t.Logf("GetId: bustype 0x%x, vendor 0x%x, product 0x%x, version 0x%x",
  53. id.Bustype, id.Vendor, id.Product, id.Version)
  54. }