Implement axis targets, axis -> button and axis -> relative axis mappings. #1

Merged
anna merged 11 commits from axis-features into main 2025-07-15 19:55:20 +00:00
Showing only changes of commit 8bbb84da85 - Show all commits

View file

@ -1,6 +1,9 @@
package mappingrules package mappingrules
import ( import (
"testing"
"time"
"github.com/holoplot/go-evdev" "github.com/holoplot/go-evdev"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )
@ -51,9 +54,34 @@ func (t *MappingRuleAxisToButtonTests) TestMatchEvent() {
}, t.mode) }, t.mode)
t.Equal(NoNextEvent, testRule.nextEvent) t.Equal(NoNextEvent, testRule.nextEvent)
// TODO: more tests here... check repeats testRule = NewMappingRuleAxisToButton(t.base, t.inputRule, t.outputRule, 750, 250)
testRule.MatchEvent(t.inputDevice, &evdev.InputEvent{
Type: evdev.EV_ABS,
Code: evdev.ABS_X,
Value: 10000,
}, t.mode)
t.Equal(time.Duration(250*time.Millisecond), testRule.nextEvent)
testRule.MatchEvent(t.inputDevice, &evdev.InputEvent{
Type: evdev.EV_ABS,
Code: evdev.ABS_X,
Value: 1001,
}, t.mode)
t.True(testRule.nextEvent > time.Duration(700*time.Millisecond))
testRule.MatchEvent(t.inputDevice, &evdev.InputEvent{
Type: evdev.EV_ABS,
Code: evdev.ABS_X,
Value: 5500,
}, t.mode)
t.Equal(time.Duration(500*time.Millisecond), testRule.nextEvent)
} }
func (t *MappingRuleAxisToButtonTests) TestTimerEvent() { // TODO: to add TimerEvent tests we need to use an interface to mock time.
// STUB // func (t *MappingRuleAxisToButtonTests) TestTimerEvent() {
// // STUB
// }
func TestRunnerMappingRuleAxisToButtonTests(t *testing.T) {
suite.Run(t, new(MappingRuleAxisToButtonTests))
} }