M2: USB-Tastatur-Handling - evdev-Integration, Scancode-Mapping, Tests, systemd-Service, Dokumentation
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package usb
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestKeyToChar(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
code uint16
|
||||
eventType string
|
||||
want string
|
||||
wantOK bool
|
||||
}{
|
||||
{"slash press", KEY_SLASH, "press", "/", true},
|
||||
{"slash release", KEY_SLASH, "release", "", false},
|
||||
{"asterisk press", KEY_ASTERISK, "press", "*", true},
|
||||
{"asterisk release", KEY_ASTERISK, "release", "", false},
|
||||
{"plus press", KEY_PLUS, "press", "+", true},
|
||||
{"minus press", KEY_MINUS, "press", "-", true},
|
||||
{"unknown key", 42, "press", "", false},
|
||||
{"unknown code release", 42, "release", "", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, ok := KeyToChar(tt.code, tt.eventType)
|
||||
if ok != tt.wantOK {
|
||||
t.Errorf("KeyToChar() ok = %v, want %v", ok, tt.wantOK)
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("KeyToChar() = %q, want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestScanToAction(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
code uint16
|
||||
want Action
|
||||
wantOK bool
|
||||
}{
|
||||
{"slash -> red", KEY_SLASH, ActionScoreRed, true},
|
||||
{"asterisk -> green", KEY_ASTERISK, ActionScoreGreen, true},
|
||||
{"plus -> next", KEY_PLUS, ActionNextRound, true},
|
||||
{"minus -> reset", KEY_MINUS, ActionReset, true},
|
||||
{"unknown", 42, "", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, ok := ScanToAction(tt.code)
|
||||
if ok != tt.wantOK {
|
||||
t.Errorf("ScanToAction() ok = %v, want %v", ok, tt.wantOK)
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("ScanToAction() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user