input_linux_test.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. const IN2 = "by-id/usb-PixArt_USB_Optical_Mouse-event-mouse"
  9. func TestList(t * testing.T) {
  10. names, err := List()
  11. if err != nil {
  12. t.Errorf("Error List: %s\n", err)
  13. return
  14. }
  15. for _, name := range names {
  16. t.Logf("Device: %s\n", name)
  17. }
  18. }
  19. func TestGetDriverVersion(t * testing.T) {
  20. device , err := Open(IN)
  21. if err != nil {
  22. t.Errorf("Error Open: %s\n", err)
  23. return
  24. }
  25. defer device.Close()
  26. version, err := device.DriverVersion()
  27. if err != nil {
  28. t.Errorf("Error GetDriverVersion: %s (%s %x)\n", err,
  29. "EVIOCGVERSION", linux.EVIOCGVERSION)
  30. return
  31. }
  32. if version != linux.EV_VERSION {
  33. t.Errorf("Version %x should be %x", version, linux.EV_VERSION)
  34. }
  35. t.Logf("GetDriverVersion: %d", version)
  36. }
  37. func TestGetName(t * testing.T) {
  38. device , err := Open(IN)
  39. if err != nil {
  40. t.Errorf("Error Open: %s\n", err)
  41. return
  42. }
  43. defer device.Close()
  44. name, err := device.Name()
  45. if err != nil {
  46. t.Errorf("Error GetName: %s\n", err)
  47. return
  48. }
  49. t.Logf("GetName: %s", name)
  50. }
  51. func TestGetTopology(t * testing.T) {
  52. device , err := Open(IN)
  53. if err != nil {
  54. t.Errorf("Error Open: %s\n", err)
  55. return
  56. }
  57. defer device.Close()
  58. name, err := device.Topology()
  59. if err != nil {
  60. t.Errorf("Error Topology: %s\n", err)
  61. return
  62. }
  63. t.Logf("Topology: %s", name)
  64. }
  65. func TestGetId(t * testing.T) {
  66. device , err := Open(IN)
  67. if err != nil {
  68. t.Errorf("Error Open: %s\n", err)
  69. return
  70. }
  71. defer device.Close()
  72. id, err := device.Id()
  73. if err != nil {
  74. t.Errorf("Error GetId: %s\n", err)
  75. return
  76. }
  77. t.Logf("GetId: bustype 0x%x, vendor 0x%x, product 0x%x, version 0x%x",
  78. id.Bustype, id.Vendor, id.Product, id.Version)
  79. }
  80. func TestSupportedEvents(t * testing.T) {
  81. device , err := Open(IN)
  82. if err != nil {
  83. t.Errorf("Error Open: %s\n", err)
  84. return
  85. }
  86. defer device.Close()
  87. events, err := device.SupportedEvents()
  88. t.Logf("Supported events:\n")
  89. for i, ev := range events {
  90. t.Logf("Supported: %d: %d %s", i, int(ev), ev.Name())
  91. }
  92. }
  93. func TestSupportedKeys(t * testing.T) {
  94. device , err := Open(IN)
  95. if err != nil {
  96. t.Errorf("Error Open: %s\n", err)
  97. return
  98. }
  99. defer device.Close()
  100. keys, err := device.SupportedKeys()
  101. t.Logf("Supported keys:\n")
  102. for i, key := range keys {
  103. t.Logf("Supported: %d: %d %s", i, int(key), key.Name())
  104. }
  105. }
  106. func TestSupportedAxes(t * testing.T) {
  107. device , err := Open(IN)
  108. if err != nil {
  109. t.Errorf("Error Open: %s\n", err)
  110. return
  111. }
  112. defer device.Close()
  113. axes, err := device.SupportedAxes()
  114. t.Logf("Supported axes:\n")
  115. for i, ax := range axes {
  116. t.Logf("Supported: %d: %d %s\n", i, uint(ax.Index), ax.String())
  117. }
  118. }
  119. func TestRelativeAxes(t * testing.T) {
  120. device , err := Open(IN2)
  121. if err != nil {
  122. t.Errorf("Error Open: %s\n", err)
  123. return
  124. }
  125. defer device.Close()
  126. events, err := device.RelativeAxes()
  127. t.Logf("Supported relative axes:\n")
  128. for i, ev := range events {
  129. t.Logf("Supported: %d: %d %s", i, int(ev), ev.Name())
  130. }
  131. }
  132. func TestReadEvents(t * testing.T) {
  133. device , err := Open(IN)
  134. if err != nil {
  135. t.Errorf("Error Open: %s\n", err)
  136. return
  137. }
  138. defer device.Close()
  139. events, err := device.ReadEvents()
  140. if err != nil {
  141. t.Errorf("Error ReadEvents: %s\n", err)
  142. return
  143. }
  144. t.Logf("Events:\n")
  145. for i, ev := range events {
  146. t.Logf("Event: %d: %s\n", i, ev.String())
  147. }
  148. }