71 lines
2 KiB
Go
71 lines
2 KiB
Go
package mappingrules
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/holoplot/go-evdev"
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
// TODO: revisit all of this after adding new functionality to
|
|
// RuleTargetAxis
|
|
type MappingRuleAxisCombinedTests struct {
|
|
suite.Suite
|
|
|
|
inputDevice *InputDeviceMock
|
|
outputDevice *evdev.InputDevice
|
|
inputTargetLower *RuleTargetAxis
|
|
inputTargetUpper *RuleTargetAxis
|
|
outputTarget *RuleTargetAxis
|
|
|
|
base MappingRuleBase
|
|
mode *string
|
|
}
|
|
|
|
func TestRunnerMappingRuleAxisCombined(t *testing.T) {
|
|
suite.Run(t, new(MappingRuleAxisCombinedTests))
|
|
}
|
|
|
|
func (t *MappingRuleAxisCombinedTests) SetupTest() {
|
|
mode := "*"
|
|
t.mode = &mode
|
|
t.inputDevice = new(InputDeviceMock)
|
|
t.inputDevice.On("AbsInfos").Return(map[evdev.EvCode]evdev.AbsInfo{
|
|
evdev.ABS_X: {
|
|
Minimum: 0,
|
|
Maximum: 10000,
|
|
},
|
|
evdev.ABS_Y: {
|
|
Minimum: 0,
|
|
Maximum: 10000,
|
|
},
|
|
}, nil)
|
|
|
|
t.outputDevice = &evdev.InputDevice{}
|
|
t.outputTarget, _ = NewRuleTargetAxis("test-output", t.outputDevice, evdev.ABS_X, false, 0, 0)
|
|
t.base = NewMappingRuleBase("", []string{"*"})
|
|
}
|
|
|
|
func (t *MappingRuleAxisCombinedTests) TestMatchEventSplitAxis() {
|
|
t.inputTargetLower, _ = NewRuleTargetAxisPartial("test-input", t.inputDevice, evdev.ABS_X, true, 0, 0, AxisValueMin, 0)
|
|
t.inputTargetUpper, _ = NewRuleTargetAxisPartial("test-input", t.inputDevice, evdev.ABS_Y, false, 0, 0, 0, AxisValueMax)
|
|
|
|
rule := NewMappingRuleAxisCombined(t.base, t.inputTargetLower, t.inputTargetUpper, t.outputTarget)
|
|
|
|
t.Run("Lower Input", func() {
|
|
device, event := rule.MatchEvent(t.inputDevice, &evdev.InputEvent{Type: evdev.EV_ABS, Code: evdev.ABS_X, Value: 10000}, t.mode)
|
|
t.Equal(t.outputDevice, device)
|
|
t.EqualValues(0, event.Value)
|
|
|
|
_, event = rule.MatchEvent(t.inputDevice, &evdev.InputEvent{Type: evdev.EV_ABS, Code: evdev.ABS_X, Value: 0}, t.mode)
|
|
t.EqualValues(AxisValueMin, event.Value)
|
|
|
|
_, event = rule.MatchEvent(t.inputDevice, &evdev.InputEvent{Type: evdev.EV_ABS, Code: evdev.ABS_X, Value: 5000}, t.mode)
|
|
t.EqualValues(0, event.Value)
|
|
})
|
|
|
|
t.Run("Upper Input Only", func() {
|
|
|
|
})
|
|
|
|
}
|