input_linux_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 TestGetTopology(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. name, err := device.Topology()
  48. if err != nil {
  49. t.Errorf("Error Topology: %s\n", err)
  50. return
  51. }
  52. t.Logf("Topology: %s", name)
  53. }
  54. func TestGetId(t * testing.T) {
  55. device , err := Open(IN)
  56. if err != nil {
  57. t.Errorf("Error Open: %s\n", err)
  58. return
  59. }
  60. defer device.Close()
  61. id, err := device.Id()
  62. if err != nil {
  63. t.Errorf("Error GetId: %s\n", err)
  64. return
  65. }
  66. t.Logf("GetId: bustype 0x%x, vendor 0x%x, product 0x%x, version 0x%x",
  67. id.Bustype, id.Vendor, id.Product, id.Version)
  68. }
  69. func TestSupportedEvents(t * testing.T) {
  70. device , err := Open(IN)
  71. if err != nil {
  72. t.Errorf("Error Open: %s\n", err)
  73. return
  74. }
  75. defer device.Close()
  76. events, err := device.SupportedEvents()
  77. t.Logf("Supported events:\n")
  78. for i, ev := range events {
  79. t.Logf("Supported: %d: %d %s", i, int(ev), ev.Name())
  80. }
  81. }
  82. func TestSupportedAxes(t * testing.T) {
  83. device , err := Open(IN)
  84. if err != nil {
  85. t.Errorf("Error Open: %s\n", err)
  86. return
  87. }
  88. defer device.Close()
  89. axes, err := device.SupportedAxes()
  90. t.Logf("Supported axes:\n")
  91. for i, ax := range axes {
  92. t.Logf("Supported: %d: %d %s\n", i, uint(ax.Index), ax.String())
  93. }
  94. }
  95. func TestReadEvents(t * testing.T) {
  96. device , err := Open(IN)
  97. if err != nil {
  98. t.Errorf("Error Open: %s\n", err)
  99. return
  100. }
  101. defer device.Close()
  102. events, err := device.ReadEvents()
  103. if err != nil {
  104. t.Errorf("Error ReadEvents: %s\n", err)
  105. return
  106. }
  107. t.Logf("Events:\n")
  108. for i, ev := range events {
  109. t.Logf("Event: %d: %s\n", i, ev.String())
  110. }
  111. }