* Move all physical device initialization logic to main functions
* Move all virtual device initialization to virtualbuffer package. * Factor out common eventcode helper logic into a new package.
This commit is contained in:
parent
1b374bccc6
commit
727985f91c
17 changed files with 777 additions and 771 deletions
|
@ -11,10 +11,11 @@ import (
|
|||
|
||||
type EventBufferTests struct {
|
||||
suite.Suite
|
||||
device *VirtualDeviceMock
|
||||
writeOneCall *mock.Call
|
||||
device *VirtualDeviceMock
|
||||
buffer *EventBuffer
|
||||
}
|
||||
|
||||
// Mocks
|
||||
type VirtualDeviceMock struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
@ -24,65 +25,65 @@ func (m *VirtualDeviceMock) WriteOne(event *evdev.InputEvent) error {
|
|||
return args.Error(0)
|
||||
}
|
||||
|
||||
// Setup
|
||||
func TestRunnerEventBufferTests(t *testing.T) {
|
||||
suite.Run(t, new(EventBufferTests))
|
||||
}
|
||||
|
||||
func (t *EventBufferTests) SetupTest() {
|
||||
t.device = new(VirtualDeviceMock)
|
||||
}
|
||||
|
||||
func (t *EventBufferTests) SetupSubTest() {
|
||||
t.device = new(VirtualDeviceMock)
|
||||
t.writeOneCall = t.device.On("WriteOne").Return(nil)
|
||||
}
|
||||
|
||||
func (t *EventBufferTests) TearDownSubTest() {
|
||||
t.writeOneCall.Unset()
|
||||
t.buffer = &EventBuffer{Device: t.device}
|
||||
}
|
||||
|
||||
// Tests
|
||||
func (t *EventBufferTests) TestNewEventBuffer() {
|
||||
buffer := NewEventBuffer(t.device)
|
||||
t.Equal(t.device, buffer.Device)
|
||||
t.Len(buffer.events, 0)
|
||||
t.Equal(t.device, t.buffer.Device)
|
||||
t.Len(t.buffer.events, 0)
|
||||
}
|
||||
|
||||
func (t *EventBufferTests) TestEventBufferAddEvent() {
|
||||
buffer := NewEventBuffer(t.device)
|
||||
buffer.AddEvent(&evdev.InputEvent{})
|
||||
buffer.AddEvent(&evdev.InputEvent{})
|
||||
buffer.AddEvent(&evdev.InputEvent{})
|
||||
t.Len(buffer.events, 3)
|
||||
}
|
||||
|
||||
func (t *EventBufferTests) TestEventBufferSendEvents() {
|
||||
t.Run("3 Events", func() {
|
||||
buffer := NewEventBuffer(t.device)
|
||||
buffer.AddEvent(&evdev.InputEvent{})
|
||||
buffer.AddEvent(&evdev.InputEvent{})
|
||||
buffer.AddEvent(&evdev.InputEvent{})
|
||||
errs := buffer.SendEvents()
|
||||
|
||||
t.Len(errs, 0)
|
||||
t.device.AssertNumberOfCalls(t.T(), "WriteOne", 4)
|
||||
})
|
||||
|
||||
t.Run("No Events", func() {
|
||||
buffer := NewEventBuffer(t.device)
|
||||
errs := buffer.SendEvents()
|
||||
|
||||
t.Len(errs, 0)
|
||||
t.device.AssertNumberOfCalls(t.T(), "WriteOne", 0)
|
||||
})
|
||||
|
||||
t.Run("Bad Event", func() {
|
||||
t.writeOneCall.Unset()
|
||||
t.writeOneCall = t.device.On("WriteOne").Return(errors.New("Fail"))
|
||||
|
||||
buffer := NewEventBuffer(t.device)
|
||||
buffer.AddEvent(&evdev.InputEvent{})
|
||||
errs := buffer.SendEvents()
|
||||
t.Len(errs, 2)
|
||||
})
|
||||
|
||||
func (t *EventBufferTests) TestEventBuffer() {
|
||||
|
||||
t.Run("AddEvent", func() {
|
||||
t.buffer.AddEvent(&evdev.InputEvent{})
|
||||
t.buffer.AddEvent(&evdev.InputEvent{})
|
||||
t.buffer.AddEvent(&evdev.InputEvent{})
|
||||
t.Len(t.buffer.events, 3)
|
||||
})
|
||||
|
||||
t.Run("SendEvents", func() {
|
||||
t.Run("3 Events", func() {
|
||||
writeOneCall := t.device.On("WriteOne").Return(nil)
|
||||
|
||||
t.buffer.AddEvent(&evdev.InputEvent{})
|
||||
t.buffer.AddEvent(&evdev.InputEvent{})
|
||||
t.buffer.AddEvent(&evdev.InputEvent{})
|
||||
errs := t.buffer.SendEvents()
|
||||
|
||||
t.Len(errs, 0)
|
||||
t.device.AssertNumberOfCalls(t.T(), "WriteOne", 4)
|
||||
|
||||
writeOneCall.Unset()
|
||||
})
|
||||
|
||||
t.Run("No Events", func() {
|
||||
writeOneCall := t.device.On("WriteOne").Return(nil)
|
||||
|
||||
errs := t.buffer.SendEvents()
|
||||
|
||||
t.Len(errs, 0)
|
||||
t.device.AssertNumberOfCalls(t.T(), "WriteOne", 0)
|
||||
|
||||
writeOneCall.Unset()
|
||||
})
|
||||
|
||||
t.Run("Bad Event", func() {
|
||||
writeOneCall := t.device.On("WriteOne").Return(errors.New("Fail"))
|
||||
|
||||
t.buffer.AddEvent(&evdev.InputEvent{})
|
||||
errs := t.buffer.SendEvents()
|
||||
t.Len(errs, 2)
|
||||
|
||||
writeOneCall.Unset()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue