An single test.
This commit is contained in:
parent
1f6c2517c0
commit
649fb5e377
1 changed files with 66 additions and 0 deletions
66
internal/mappingrules/matching_test.go
Normal file
66
internal/mappingrules/matching_test.go
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
package mappingrules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/holoplot/go-evdev"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSimpleRuleMatchEvent(t *testing.T) {
|
||||||
|
inputDevice := &evdev.InputDevice{}
|
||||||
|
wrongInputDevice := &evdev.InputDevice{}
|
||||||
|
outputDevice := &evdev.InputDevice{}
|
||||||
|
|
||||||
|
rule := &SimpleMappingRule{
|
||||||
|
MappingRuleBase: MappingRuleBase{
|
||||||
|
Output: &RuleTargetButton{
|
||||||
|
RuleTargetBase{
|
||||||
|
DeviceName: "test_output",
|
||||||
|
Device: outputDevice,
|
||||||
|
Code: evdev.BTN_TRIGGER,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Modes: []string{"*"},
|
||||||
|
},
|
||||||
|
Input: &RuleTargetButton{
|
||||||
|
RuleTargetBase{
|
||||||
|
DeviceName: "test_input",
|
||||||
|
Device: inputDevice,
|
||||||
|
Code: evdev.BTN_TRIGGER,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
mode := "*"
|
||||||
|
|
||||||
|
// A matching input event should produce an output event
|
||||||
|
event := rule.MatchEvent(inputDevice, &evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, &mode)
|
||||||
|
outputEvent := &evdev.InputEvent{
|
||||||
|
Type: evdev.EV_KEY,
|
||||||
|
Code: evdev.BTN_TRIGGER,
|
||||||
|
Value: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
if event == nil || *event != *outputEvent {
|
||||||
|
t.Errorf("Expected event to match %v, but got %v", outputEvent, event)
|
||||||
|
}
|
||||||
|
|
||||||
|
// if event.Type != outputEvent.Type ||
|
||||||
|
// event.Code != outputEvent.Code ||
|
||||||
|
// event.Value != outputEvent.Value {
|
||||||
|
// t.Errorf("Expected event to match %v, but got %v", outputEvent, event)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// An input event from the wrong device should produce a nil event
|
||||||
|
event = rule.MatchEvent(wrongInputDevice, &evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, &mode)
|
||||||
|
if event != nil {
|
||||||
|
t.Errorf("Expected event not to match, but got non-nil event %v", event)
|
||||||
|
}
|
||||||
|
|
||||||
|
// An input event from the wrong device should produce a nil event
|
||||||
|
event = rule.MatchEvent(wrongInputDevice, &evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, &mode)
|
||||||
|
if event != nil {
|
||||||
|
t.Errorf("Expected event not to match, but got non-nil event %v", event)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: test inversion, and everything else...
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue