Clamp values falling outside of the axis bounds.
This commit is contained in:
parent
681e1fef70
commit
a6ad1b609a
3 changed files with 17 additions and 6 deletions
|
@ -69,8 +69,8 @@ func (t *RuleTargetAxisTests) TestNewRuleTargetAxis() {
|
|||
|
||||
// If Absinfo has an error, we should create a device with permissive bounds
|
||||
t.call.Unset()
|
||||
t.mock.On("AbsInfos").Return(nil, errors.New("Test Error"))
|
||||
ruleTarget, err = NewRuleTargetAxis("", t.mock, evdev.ABS_Y, false, -500, 500)
|
||||
t.mock.On("AbsInfos").Return(map[evdev.EvCode]evdev.AbsInfo{}, errors.New("Test Error"))
|
||||
ruleTarget, err = NewRuleTargetAxis("", t.mock, evdev.ABS_X, false, 0, 0)
|
||||
t.Nil(err)
|
||||
t.Equal(AxisValueMax-AxisValueMin, ruleTarget.axisSize)
|
||||
}
|
||||
|
@ -92,6 +92,11 @@ func (t *RuleTargetAxisTests) TestNormalizeValue() {
|
|||
ruleTarget, _ = NewRuleTargetAxis("", t.mock, evdev.ABS_X, true, 0, 0)
|
||||
t.Equal(AxisValueMax, ruleTarget.NormalizeValue(int32(0)))
|
||||
t.Equal(AxisValueMin, ruleTarget.NormalizeValue(int32(10000)))
|
||||
|
||||
// Normalization past the stated axis bounds should clamp
|
||||
ruleTarget, _ = NewRuleTargetAxis("", t.mock, evdev.ABS_X, false, 0, 0)
|
||||
t.Equal(AxisValueMin, ruleTarget.NormalizeValue(int32(-30000)))
|
||||
t.Equal(AxisValueMax, ruleTarget.NormalizeValue(int32(30000)))
|
||||
}
|
||||
|
||||
func (t *RuleTargetAxisTests) TestMatchEvent() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue