2
0
mirror of https://github.com/koreader/koreader synced 2024-11-11 19:11:14 +00:00
koreader/spec/unit/touch_probe_spec.lua
2016-04-02 23:06:09 -07:00

63 lines
2.0 KiB
Lua

describe("touch probe module", function()
setup(function()
require("commonrequire")
end)
it("should probe properly for kobo touch", function()
local Device = require("device")
local TouchProbe = require("utils/kobo_touch_probe"):new{}
local need_to_switch_xy
TouchProbe.saveSwitchXYSetting = function(_, new_need_to_switch_xy)
need_to_switch_xy = new_need_to_switch_xy
end
-- for kobo touch, we have mirror_x, then switch_xy
-- tap lower right corner
local x, y = Device.screen:getWidth()-40, Device.screen:getHeight()-40
need_to_switch_xy = nil
TouchProbe:onTapProbe(nil, {
pos = {
x = y,
y = Device.screen:getWidth()-x,
}
})
assert.is.same(TouchProbe.curr_probe_step, 1)
assert.truthy(need_to_switch_xy)
-- now only test mirror_x
-- tap lower right corner
local x, y = Device.screen:getWidth()-40, Device.screen:getHeight()-40
need_to_switch_xy = nil
TouchProbe:onTapProbe(nil, {
pos = {
x = Device.screen:getWidth()-x,
y = y,
}
})
assert.is.same(TouchProbe.curr_probe_step, 1)
assert.falsy(need_to_switch_xy)
-- now only test switch_xy
-- tap lower right corner
local x, y = Device.screen:getWidth()-40, Device.screen:getHeight()-40
need_to_switch_xy = nil
TouchProbe:onTapProbe(nil, {
pos = {
x = y,
y = x,
}
})
assert.is.same(TouchProbe.curr_probe_step, 2)
assert.falsy(need_to_switch_xy)
-- tap upper right corner
local x, y = Device.screen:getWidth()-40, 40
TouchProbe:onTapProbe(nil, {
pos = {
x = y,
y = x,
}
})
assert.is.same(TouchProbe.curr_probe_step, 2)
assert.truthy(need_to_switch_xy)
end)
end)