Clean up some of our tests.
This commit is contained in:
parent
2f7e11e8a2
commit
8f3b8f4b47
1 changed files with 22 additions and 31 deletions
|
@ -13,8 +13,7 @@ type MappingRuleButtonTests struct {
|
||||||
wrongInputDevice *evdev.InputDevice
|
wrongInputDevice *evdev.InputDevice
|
||||||
outputDevice *evdev.InputDevice
|
outputDevice *evdev.InputDevice
|
||||||
mode *string
|
mode *string
|
||||||
sampleRule *MappingRuleButton
|
base MappingRuleBase
|
||||||
invertedRule *MappingRuleButton
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MappingRuleButtonTests) SetupTest() {
|
func (t *MappingRuleButtonTests) SetupTest() {
|
||||||
|
@ -23,70 +22,62 @@ func (t *MappingRuleButtonTests) SetupTest() {
|
||||||
t.outputDevice = &evdev.InputDevice{}
|
t.outputDevice = &evdev.InputDevice{}
|
||||||
mode := "*"
|
mode := "*"
|
||||||
t.mode = &mode
|
t.mode = &mode
|
||||||
|
t.base = NewMappingRuleBase("", []string{})
|
||||||
// TODO: implement a constructor function...
|
|
||||||
t.sampleRule = &MappingRuleButton{
|
|
||||||
MappingRuleBase: MappingRuleBase{
|
|
||||||
Modes: []string{"*"},
|
|
||||||
},
|
|
||||||
Input: NewRuleTargetButton("", t.inputDevice, evdev.BTN_TRIGGER, false),
|
|
||||||
Output: NewRuleTargetButton("", t.outputDevice, evdev.BTN_TRIGGER, false),
|
|
||||||
}
|
|
||||||
|
|
||||||
t.invertedRule = &MappingRuleButton{
|
|
||||||
MappingRuleBase: MappingRuleBase{
|
|
||||||
Modes: []string{"*"},
|
|
||||||
},
|
|
||||||
Output: NewRuleTargetButton("", t.outputDevice, evdev.BTN_TRIGGER, false),
|
|
||||||
Input: NewRuleTargetButton("", t.inputDevice, evdev.BTN_TRIGGER, true),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MappingRuleButtonTests) TestMatchEvent() {
|
func (t *MappingRuleButtonTests) TestMatchEvent() {
|
||||||
|
inputButton, _ := NewRuleTargetButton("", t.inputDevice, evdev.BTN_TRIGGER, false)
|
||||||
|
outputButton, _ := NewRuleTargetButton("", t.outputDevice, evdev.BTN_TRIGGER, false)
|
||||||
|
testRule := NewMappingRuleButton(t.base, inputButton, outputButton)
|
||||||
|
|
||||||
// A matching input event should produce an output event
|
// A matching input event should produce an output event
|
||||||
correctOutput := &evdev.InputEvent{
|
expected := &evdev.InputEvent{
|
||||||
Type: evdev.EV_KEY,
|
Type: evdev.EV_KEY,
|
||||||
Code: evdev.BTN_TRIGGER,
|
Code: evdev.BTN_TRIGGER,
|
||||||
Value: 1,
|
Value: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, event := t.sampleRule.MatchEvent(
|
_, event := testRule.MatchEvent(
|
||||||
t.inputDevice,
|
t.inputDevice,
|
||||||
&evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, t.mode)
|
&evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, t.mode)
|
||||||
t.EqualValues(correctOutput, event)
|
t.EqualValues(expected, event)
|
||||||
|
|
||||||
// An input event from the wrong device should produce a nil event
|
// An input event from the wrong device should produce a nil event
|
||||||
_, event = t.sampleRule.MatchEvent(
|
_, event = testRule.MatchEvent(
|
||||||
t.wrongInputDevice,
|
t.wrongInputDevice,
|
||||||
&evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, t.mode)
|
&evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, t.mode)
|
||||||
t.Nil(event)
|
t.Nil(event)
|
||||||
|
|
||||||
// An input event from the wrong button should produce a nil event
|
// An input event from the wrong button should produce a nil event
|
||||||
_, event = t.sampleRule.MatchEvent(
|
_, event = testRule.MatchEvent(
|
||||||
t.inputDevice,
|
t.inputDevice,
|
||||||
&evdev.InputEvent{Code: evdev.BTN_TOP, Value: 1}, t.mode)
|
&evdev.InputEvent{Code: evdev.BTN_TOP, Value: 1}, t.mode)
|
||||||
t.Nil(event)
|
t.Nil(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MappingRuleButtonTests) TestMatchEventInverted() {
|
func (t *MappingRuleButtonTests) TestMatchEventInverted() {
|
||||||
|
inputButton, _ := NewRuleTargetButton("", t.inputDevice, evdev.BTN_TRIGGER, true)
|
||||||
|
outputButton, _ := NewRuleTargetButton("", t.outputDevice, evdev.BTN_TRIGGER, false)
|
||||||
|
testRule := NewMappingRuleButton(t.base, inputButton, outputButton)
|
||||||
|
|
||||||
// A matching input event should produce an output event
|
// A matching input event should produce an output event
|
||||||
correctOutput := &evdev.InputEvent{
|
expected := &evdev.InputEvent{
|
||||||
Type: evdev.EV_KEY,
|
Type: evdev.EV_KEY,
|
||||||
Code: evdev.BTN_TRIGGER,
|
Code: evdev.BTN_TRIGGER,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should get the opposite value out that we send in
|
// Should get the opposite value out that we send in
|
||||||
correctOutput.Value = 0
|
expected.Value = 0
|
||||||
_, event := t.invertedRule.MatchEvent(
|
_, event := testRule.MatchEvent(
|
||||||
t.inputDevice,
|
t.inputDevice,
|
||||||
&evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, t.mode)
|
&evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 1}, t.mode)
|
||||||
t.EqualValues(correctOutput, event)
|
t.EqualValues(expected, event)
|
||||||
|
|
||||||
correctOutput.Value = 1
|
expected.Value = 1
|
||||||
_, event = t.invertedRule.MatchEvent(
|
_, event = testRule.MatchEvent(
|
||||||
t.inputDevice,
|
t.inputDevice,
|
||||||
&evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 0}, t.mode)
|
&evdev.InputEvent{Code: evdev.BTN_TRIGGER, Value: 0}, t.mode)
|
||||||
t.EqualValues(correctOutput, event)
|
t.EqualValues(expected, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunnerMatching(t *testing.T) {
|
func TestRunnerMatching(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue