Add tests for AxisToButton rule. (WIP)
This commit is contained in:
parent
47fac539da
commit
e93187b8a5
4 changed files with 76 additions and 14 deletions
|
@ -8,8 +8,6 @@ import (
|
||||||
|
|
||||||
// MappingRuleAxisToButton represents a rule that converts an axis input into a (potentially repeating)
|
// MappingRuleAxisToButton represents a rule that converts an axis input into a (potentially repeating)
|
||||||
// button output.
|
// button output.
|
||||||
//
|
|
||||||
// TODO: Add Tests
|
|
||||||
type MappingRuleAxisToButton struct {
|
type MappingRuleAxisToButton struct {
|
||||||
MappingRuleBase
|
MappingRuleBase
|
||||||
Input *RuleTargetAxis
|
Input *RuleTargetAxis
|
||||||
|
@ -38,9 +36,8 @@ func NewMappingRuleAxisToButton(base MappingRuleBase, input *RuleTargetAxis, out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rule *MappingRuleAxisToButton) MatchEvent(device *evdev.InputDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
func (rule *MappingRuleAxisToButton) MatchEvent(device RuleTargetDevice, event *evdev.InputEvent, mode *string) (*evdev.InputDevice, *evdev.InputEvent) {
|
||||||
// TODO: we're using this instead of the RuleTarget's MatchEvent because we need to check inside the deadzone
|
|
||||||
// We should find a cleaner way to do this...
|
|
||||||
if !rule.MappingRuleBase.modeCheck(mode) ||
|
if !rule.MappingRuleBase.modeCheck(mode) ||
|
||||||
!rule.Input.MatchEventDeviceAndCode(device, event) {
|
!rule.Input.MatchEventDeviceAndCode(device, event) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
59
internal/mappingrules/mapping_rule_axis_to_button_test.go
Normal file
59
internal/mappingrules/mapping_rule_axis_to_button_test.go
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
package mappingrules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/holoplot/go-evdev"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MappingRuleAxisToButtonTests struct {
|
||||||
|
suite.Suite
|
||||||
|
inputDevice *InputDeviceMock
|
||||||
|
inputRule *RuleTargetAxis
|
||||||
|
outputDevice *evdev.InputDevice
|
||||||
|
outputRule *RuleTargetButton
|
||||||
|
mode *string
|
||||||
|
base MappingRuleBase
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *MappingRuleAxisToButtonTests) 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,
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
|
t.inputRule, _ = NewRuleTargetAxis("test-input", t.inputDevice, evdev.ABS_X, false, int32(0), int32(1000))
|
||||||
|
|
||||||
|
t.outputDevice = &evdev.InputDevice{}
|
||||||
|
t.outputRule, _ = NewRuleTargetButton("test-output", t.outputDevice, evdev.ABS_X, false)
|
||||||
|
t.base = NewMappingRuleBase("", []string{"*"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *MappingRuleAxisToButtonTests) TestMatchEvent() {
|
||||||
|
testRule := NewMappingRuleAxisToButton(t.base, t.inputRule, t.outputRule, 0, 0)
|
||||||
|
|
||||||
|
// A valid input should set a nextevent
|
||||||
|
testRule.MatchEvent(t.inputDevice, &evdev.InputEvent{
|
||||||
|
Type: evdev.EV_ABS,
|
||||||
|
Code: evdev.ABS_X,
|
||||||
|
Value: 1001,
|
||||||
|
}, t.mode)
|
||||||
|
t.NotEqual(NoNextEvent, testRule.nextEvent)
|
||||||
|
|
||||||
|
// And a deadzone value should clear it
|
||||||
|
testRule.MatchEvent(t.inputDevice, &evdev.InputEvent{
|
||||||
|
Type: evdev.EV_ABS,
|
||||||
|
Code: evdev.ABS_X,
|
||||||
|
Value: 500,
|
||||||
|
}, t.mode)
|
||||||
|
t.Equal(NoNextEvent, testRule.nextEvent)
|
||||||
|
|
||||||
|
// TODO: more tests here... check repeats
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *MappingRuleAxisToButtonTests) TestTimerEvent() {
|
||||||
|
// STUB
|
||||||
|
}
|
|
@ -15,15 +15,6 @@ type RuleTargetAxisTests struct {
|
||||||
call *mock.Call
|
call *mock.Call
|
||||||
}
|
}
|
||||||
|
|
||||||
type InputDeviceMock struct {
|
|
||||||
mock.Mock
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *InputDeviceMock) AbsInfos() (map[evdev.EvCode]evdev.AbsInfo, error) {
|
|
||||||
args := m.Called()
|
|
||||||
return args.Get(0).(map[evdev.EvCode]evdev.AbsInfo), args.Error(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *RuleTargetAxisTests) SetupTest() {
|
func (t *RuleTargetAxisTests) SetupTest() {
|
||||||
t.mock = new(InputDeviceMock)
|
t.mock = new(InputDeviceMock)
|
||||||
t.call = t.mock.On("AbsInfos").Return(map[evdev.EvCode]evdev.AbsInfo{
|
t.call = t.mock.On("AbsInfos").Return(map[evdev.EvCode]evdev.AbsInfo{
|
||||||
|
|
15
internal/mappingrules/test_mocks.go
Normal file
15
internal/mappingrules/test_mocks.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package mappingrules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/holoplot/go-evdev"
|
||||||
|
"github.com/stretchr/testify/mock"
|
||||||
|
)
|
||||||
|
|
||||||
|
type InputDeviceMock struct {
|
||||||
|
mock.Mock
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *InputDeviceMock) AbsInfos() (map[evdev.EvCode]evdev.AbsInfo, error) {
|
||||||
|
args := m.Called()
|
||||||
|
return args.Get(0).(map[evdev.EvCode]evdev.AbsInfo), args.Error(1)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue