2016-04-03 04:52:30 +00:00
|
|
|
describe("device module", function()
|
2017-08-08 20:35:40 +00:00
|
|
|
-- luacheck: push ignore
|
2016-04-03 04:52:30 +00:00
|
|
|
local mock_fb, mock_input
|
2016-08-13 10:47:38 +00:00
|
|
|
local iopen = io.open
|
|
|
|
local osgetenv = os.getenv
|
|
|
|
|
2016-04-03 04:52:30 +00:00
|
|
|
setup(function()
|
|
|
|
mock_fb = {
|
|
|
|
new = function()
|
|
|
|
return {
|
|
|
|
getSize = function() return {w = 600, h = 800} end,
|
|
|
|
getWidth = function() return 600 end,
|
|
|
|
getDPI = function() return 72 end,
|
2016-08-13 10:47:38 +00:00
|
|
|
setViewport = function() end,
|
|
|
|
getRotationMode = function() return 0 end,
|
|
|
|
getScreenMode = function() return "portrait" end,
|
|
|
|
setRotationMode = function() end,
|
2016-04-03 04:52:30 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
}
|
|
|
|
require("commonrequire")
|
2017-06-23 17:04:11 +00:00
|
|
|
package.unloadAll()
|
2016-04-03 04:52:30 +00:00
|
|
|
end)
|
|
|
|
|
2016-08-13 10:47:38 +00:00
|
|
|
before_each(function()
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = mock_fb
|
|
|
|
mock_input = require('device/input')
|
|
|
|
stub(mock_input, "open")
|
|
|
|
stub(os, "getenv")
|
|
|
|
stub(os, "execute")
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
mock_input.open:revert()
|
|
|
|
os.getenv:revert()
|
|
|
|
os.execute:revert()
|
|
|
|
|
|
|
|
os.getenv = osgetenv
|
|
|
|
io.open = iopen
|
|
|
|
end)
|
|
|
|
|
2016-04-03 04:52:30 +00:00
|
|
|
describe("kobo", function()
|
2016-05-24 05:38:08 +00:00
|
|
|
local TimeVal
|
2016-09-12 04:41:56 +00:00
|
|
|
local NickelConf
|
2016-04-03 04:52:30 +00:00
|
|
|
setup(function()
|
2016-05-24 05:38:08 +00:00
|
|
|
TimeVal = require("ui/timeval")
|
2016-09-12 04:41:56 +00:00
|
|
|
NickelConf = require("device/kobo/nickel_conf")
|
|
|
|
end)
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
stub(NickelConf.frontLightLevel, "get")
|
|
|
|
NickelConf.frontLightLevel.get.returns(0)
|
|
|
|
stub(NickelConf.frontLightState, "get")
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
NickelConf.frontLightLevel.get:revert()
|
|
|
|
NickelConf.frontLightState.get:revert()
|
2016-04-03 04:52:30 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("should initialize properly on Kobo dahlia", function()
|
|
|
|
os.getenv.returns("dahlia")
|
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
|
|
|
|
kobo_dev:init()
|
|
|
|
assert.is.same("Kobo_dahlia", kobo_dev.model)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should setup eventAdjustHooks properly for input in trilogy", function()
|
|
|
|
os.getenv.invokes(function(key)
|
|
|
|
if key == "PRODUCT" then
|
|
|
|
return "trilogy"
|
|
|
|
else
|
2018-05-10 10:26:07 +00:00
|
|
|
return osgetenv(key)
|
2016-04-03 04:52:30 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2016-08-13 10:47:38 +00:00
|
|
|
package.loaded['device/kobo/device'] = nil
|
2016-04-03 04:52:30 +00:00
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
kobo_dev:init()
|
|
|
|
local Screen = kobo_dev.screen
|
|
|
|
|
|
|
|
assert.is.same("Kobo_trilogy", kobo_dev.model)
|
|
|
|
assert.truthy(kobo_dev:needsTouchScreenProbe())
|
2019-01-08 01:59:47 +00:00
|
|
|
-- This gets reset to nil during Kobo:init() since #4450
|
|
|
|
assert.falsy(kobo_dev.touch_probe_ev_epoch_time)
|
2016-04-03 04:52:30 +00:00
|
|
|
G_reader_settings:saveSetting("kobo_touch_switch_xy", true)
|
|
|
|
kobo_dev:touchScreenProbe()
|
|
|
|
local x, y = Screen:getWidth()-5, 10
|
|
|
|
local EV_ABS = 3
|
|
|
|
local ABS_X = 00
|
|
|
|
local ABS_Y = 01
|
|
|
|
-- mirror x, then switch_xy
|
|
|
|
local ev_x = {
|
|
|
|
type = EV_ABS,
|
|
|
|
code = ABS_X,
|
|
|
|
value = y,
|
2019-01-08 01:59:47 +00:00
|
|
|
time = TimeVal:now(),
|
2016-04-03 04:52:30 +00:00
|
|
|
}
|
|
|
|
local ev_y = {
|
|
|
|
type = EV_ABS,
|
|
|
|
code = ABS_Y,
|
|
|
|
value = Screen:getWidth()-x,
|
2019-01-08 01:59:47 +00:00
|
|
|
time = TimeVal:now(),
|
2016-04-03 04:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
kobo_dev.input:eventAdjustHook(ev_x)
|
|
|
|
kobo_dev.input:eventAdjustHook(ev_y)
|
|
|
|
assert.is.same(x, ev_y.value)
|
|
|
|
assert.is.same(ABS_X, ev_y.code)
|
|
|
|
assert.is.same(y, ev_x.value)
|
|
|
|
assert.is.same(ABS_Y, ev_x.code)
|
|
|
|
|
2016-05-24 05:38:08 +00:00
|
|
|
-- reset eventAdjustHook
|
|
|
|
kobo_dev.input.eventAdjustHook = function() end
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should setup eventAdjustHooks properly for trilogy with non-epoch ev time", function()
|
|
|
|
os.getenv.invokes(function(key)
|
|
|
|
if key == "PRODUCT" then
|
|
|
|
return "trilogy"
|
|
|
|
else
|
2018-05-10 10:26:07 +00:00
|
|
|
return osgetenv(key)
|
2016-05-24 05:38:08 +00:00
|
|
|
end
|
|
|
|
end)
|
2019-01-08 01:59:47 +00:00
|
|
|
|
|
|
|
package.loaded['device/kobo/device'] = nil
|
2016-05-24 05:38:08 +00:00
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
kobo_dev:init()
|
|
|
|
local Screen = kobo_dev.screen
|
|
|
|
|
|
|
|
assert.is.same("Kobo_trilogy", kobo_dev.model)
|
2019-01-08 01:59:47 +00:00
|
|
|
assert.truthy(kobo_dev:needsTouchScreenProbe())
|
|
|
|
-- This gets reset to nil during Kobo:init() since #4450
|
|
|
|
assert.falsy(kobo_dev.touch_probe_ev_epoch_time)
|
|
|
|
kobo_dev:touchScreenProbe()
|
2016-05-24 05:38:08 +00:00
|
|
|
local x, y = Screen:getWidth()-5, 10
|
|
|
|
local EV_ABS = 3
|
|
|
|
local ABS_X = 00
|
|
|
|
local ABS_Y = 01
|
|
|
|
local ev_x = {
|
|
|
|
type = EV_ABS,
|
|
|
|
code = ABS_X,
|
|
|
|
value = x,
|
|
|
|
time = {sec = 1000}
|
|
|
|
}
|
|
|
|
local ev_y = {
|
|
|
|
type = EV_ABS,
|
|
|
|
code = ABS_Y,
|
|
|
|
value = y,
|
|
|
|
time = {sec = 1000}
|
|
|
|
}
|
|
|
|
|
|
|
|
kobo_dev.input:eventAdjustHook(ev_x)
|
|
|
|
kobo_dev.input:eventAdjustHook(ev_y)
|
|
|
|
local cur_sec = TimeVal:now().sec
|
|
|
|
assert.truthy(cur_sec - ev_x.time.sec < 10)
|
|
|
|
assert.truthy(cur_sec - ev_y.time.sec < 10)
|
|
|
|
|
2019-01-08 01:59:47 +00:00
|
|
|
-- reset eventAdjustHook
|
2016-05-24 05:38:08 +00:00
|
|
|
kobo_dev.input.eventAdjustHook = function() end
|
2016-04-03 04:52:30 +00:00
|
|
|
end)
|
2016-05-02 08:35:06 +00:00
|
|
|
|
|
|
|
it("should flush book settings before suspend", function()
|
|
|
|
local sample_pdf = "spec/front/unit/data/tall.pdf"
|
|
|
|
local ReaderUI = require("apps/reader/readerui")
|
|
|
|
local Device = require("device")
|
|
|
|
|
|
|
|
NickelConf.frontLightLevel.get.returns(1)
|
|
|
|
NickelConf.frontLightState.get.returns(0)
|
|
|
|
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
stub(Device, "suspend")
|
|
|
|
stub(Device.powerd, "beforeSuspend")
|
|
|
|
stub(Device, "isKobo")
|
|
|
|
|
|
|
|
Device.isKobo.returns(true)
|
|
|
|
UIManager:init()
|
|
|
|
|
|
|
|
ReaderUI:doShowReader(sample_pdf)
|
|
|
|
local readerui = ReaderUI._getRunningInstance()
|
|
|
|
stub(readerui, "onFlushSettings")
|
|
|
|
UIManager.event_handlers["PowerPress"]()
|
|
|
|
UIManager.event_handlers["PowerRelease"]()
|
|
|
|
assert.stub(readerui.onFlushSettings).was_called()
|
|
|
|
|
|
|
|
Device.suspend:revert()
|
|
|
|
Device.powerd.beforeSuspend:revert()
|
|
|
|
Device.isKobo:revert()
|
2016-08-12 06:05:18 +00:00
|
|
|
readerui.onFlushSettings:revert()
|
2016-05-02 08:35:06 +00:00
|
|
|
readerui:onClose()
|
|
|
|
end)
|
2016-04-03 04:52:30 +00:00
|
|
|
end)
|
2016-04-26 07:16:27 +00:00
|
|
|
|
2016-08-13 10:47:38 +00:00
|
|
|
describe("kindle", function()
|
2016-08-11 09:12:55 +00:00
|
|
|
it("should initialize voyage without error", function()
|
2016-08-13 10:47:38 +00:00
|
|
|
io.open = function(filename, mode)
|
|
|
|
if filename == "/proc/usid" then
|
|
|
|
return {
|
|
|
|
read = function() return "XX13XX" end,
|
|
|
|
close = function() end
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return iopen(filename, mode)
|
|
|
|
end
|
|
|
|
end
|
2016-04-26 07:16:27 +00:00
|
|
|
|
2016-08-13 10:47:38 +00:00
|
|
|
local kindle_dev = require('device/kindle/device')
|
2016-04-26 07:16:27 +00:00
|
|
|
assert.is.same(kindle_dev.model, "KindleVoyage")
|
|
|
|
kindle_dev:init()
|
|
|
|
assert.is.same(kindle_dev.input.event_map[104], "LPgBack")
|
|
|
|
assert.is.same(kindle_dev.input.event_map[109], "LPgFwd")
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_min, 0)
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_max, 24)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should toggle frontlight", function()
|
2016-08-13 10:47:38 +00:00
|
|
|
io.open = function(filename, mode)
|
|
|
|
if filename == "/proc/usid" then
|
|
|
|
return {
|
|
|
|
read = function() return "XX13XX" end,
|
|
|
|
close = function() end
|
|
|
|
}
|
|
|
|
elseif filename == "/sys/class/backlight/max77696-bl/brightness" then
|
|
|
|
return {
|
|
|
|
read = function() return "12" end,
|
|
|
|
close = function() end
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return iopen(filename, mode)
|
|
|
|
end
|
|
|
|
end
|
2016-04-26 07:16:27 +00:00
|
|
|
|
|
|
|
local kindle_dev = require("device/kindle/device")
|
|
|
|
kindle_dev:init()
|
|
|
|
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_intensity, 12)
|
|
|
|
kindle_dev.powerd:setIntensity(5)
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_intensity, 5)
|
|
|
|
|
|
|
|
kindle_dev.powerd:toggleFrontlight()
|
|
|
|
assert.stub(os.execute).was_called_with(
|
|
|
|
"echo -n 0 > /sys/class/backlight/max77696-bl/brightness")
|
2018-12-10 21:10:35 +00:00
|
|
|
-- Here be shenanigans: we don't override powerd's fl_intensity when we turn the light off,
|
|
|
|
-- so that we can properly turn it back on at the previous intensity ;)
|
2016-04-26 07:16:27 +00:00
|
|
|
assert.is.same(kindle_dev.powerd.fl_intensity, 5)
|
2018-12-10 21:10:35 +00:00
|
|
|
-- But if we were to cat /sys/class/backlight/max77696-bl/brightness, it should now be 0.
|
2016-04-26 07:16:27 +00:00
|
|
|
|
|
|
|
kindle_dev.powerd:toggleFrontlight()
|
2018-12-10 21:10:35 +00:00
|
|
|
assert.is.same(kindle_dev.powerd.fl_intensity, 5)
|
|
|
|
-- And /sys/class/backlight/max77696-bl/brightness is now !0
|
|
|
|
-- (exact value is HW-dependent, each model has a different curve, we let lipc do the work for us).
|
2016-08-13 10:47:38 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("oasis should interpret orientation event", function()
|
2017-06-23 17:04:11 +00:00
|
|
|
package.unload('device/kindle/device')
|
2016-08-13 10:47:38 +00:00
|
|
|
io.open = function(filename, mode)
|
|
|
|
if filename == "/proc/usid" then
|
|
|
|
return {
|
|
|
|
read = function()
|
|
|
|
return "XXX0GCXXX"
|
|
|
|
end,
|
|
|
|
close = function() end
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return iopen(filename, mode)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mock_ffi_input = require('ffi/input')
|
|
|
|
stub(mock_ffi_input, "waitForEvent")
|
|
|
|
mock_ffi_input.waitForEvent.returns({
|
|
|
|
type = 3,
|
|
|
|
time = {
|
|
|
|
usec = 450565,
|
|
|
|
sec = 1471081881
|
|
|
|
},
|
|
|
|
code = 24,
|
|
|
|
value = 16
|
|
|
|
})
|
|
|
|
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
stub(UIManager, "onRotation")
|
|
|
|
|
|
|
|
local kindle_dev = require('device/kindle/device')
|
|
|
|
assert.is.same("KindleOasis", kindle_dev.model)
|
|
|
|
kindle_dev:init()
|
|
|
|
|
|
|
|
kindle_dev.input:waitEvent()
|
|
|
|
assert.stub(UIManager.onRotation).was_called()
|
2016-04-26 07:16:27 +00:00
|
|
|
|
2016-08-13 10:47:38 +00:00
|
|
|
mock_ffi_input.waitForEvent:revert()
|
|
|
|
UIManager.onRotation:revert()
|
2016-04-26 07:16:27 +00:00
|
|
|
end)
|
|
|
|
end)
|
2017-08-08 20:35:40 +00:00
|
|
|
-- luacheck: pop
|
2016-04-03 04:52:30 +00:00
|
|
|
end)
|