|
|
@ -1,5 +1,8 @@
|
|
|
|
describe("device module", function()
|
|
|
|
describe("device module", function()
|
|
|
|
local mock_fb, mock_input
|
|
|
|
local mock_fb, mock_input
|
|
|
|
|
|
|
|
local iopen = io.open
|
|
|
|
|
|
|
|
local osgetenv = os.getenv
|
|
|
|
|
|
|
|
|
|
|
|
setup(function()
|
|
|
|
setup(function()
|
|
|
|
mock_fb = {
|
|
|
|
mock_fb = {
|
|
|
|
new = function()
|
|
|
|
new = function()
|
|
|
@ -7,48 +10,51 @@ describe("device module", function()
|
|
|
|
getSize = function() return {w = 600, h = 800} end,
|
|
|
|
getSize = function() return {w = 600, h = 800} end,
|
|
|
|
getWidth = function() return 600 end,
|
|
|
|
getWidth = function() return 600 end,
|
|
|
|
getDPI = function() return 72 end,
|
|
|
|
getDPI = function() return 72 end,
|
|
|
|
setViewport = function() end
|
|
|
|
setViewport = function() end,
|
|
|
|
|
|
|
|
getRotationMode = function() return 0 end,
|
|
|
|
|
|
|
|
getScreenMode = function() return "portrait" end,
|
|
|
|
|
|
|
|
setRotationMode = function() end,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require("commonrequire")
|
|
|
|
require("commonrequire")
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = mock_fb
|
|
|
|
|
|
|
|
package.loaded['device/kindle/device'] = nil
|
|
|
|
|
|
|
|
package.loaded['device/kobo/device'] = nil
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
describe("kobo", function()
|
|
|
|
describe("kobo", function()
|
|
|
|
local TimeVal
|
|
|
|
local TimeVal
|
|
|
|
setup(function()
|
|
|
|
setup(function()
|
|
|
|
TimeVal = require("ui/timeval")
|
|
|
|
TimeVal = require("ui/timeval")
|
|
|
|
mock_fb = {
|
|
|
|
|
|
|
|
new = function()
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
getSize = function() return {w = 600, h = 800} end,
|
|
|
|
|
|
|
|
getWidth = function() return 600 end,
|
|
|
|
|
|
|
|
getDPI = function() return 72 end,
|
|
|
|
|
|
|
|
setViewport = function() end
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
it("should initialize properly on Kobo dahlia", function()
|
|
|
|
it("should initialize properly on Kobo dahlia", function()
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = mock_fb
|
|
|
|
|
|
|
|
stub(os, "getenv")
|
|
|
|
|
|
|
|
os.getenv.returns("dahlia")
|
|
|
|
os.getenv.returns("dahlia")
|
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
|
|
|
|
|
|
|
|
mock_input = require('device/input')
|
|
|
|
|
|
|
|
stub(mock_input, "open")
|
|
|
|
|
|
|
|
kobo_dev:init()
|
|
|
|
kobo_dev:init()
|
|
|
|
assert.is.same("Kobo_dahlia", kobo_dev.model)
|
|
|
|
assert.is.same("Kobo_dahlia", kobo_dev.model)
|
|
|
|
|
|
|
|
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = nil
|
|
|
|
|
|
|
|
os.getenv:revert()
|
|
|
|
|
|
|
|
mock_input.open:revert()
|
|
|
|
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
it("should setup eventAdjustHooks properly for input in trilogy", function()
|
|
|
|
it("should setup eventAdjustHooks properly for input in trilogy", function()
|
|
|
|
local saved_getenv = os.getenv
|
|
|
|
|
|
|
|
stub(os, "getenv")
|
|
|
|
|
|
|
|
os.getenv.invokes(function(key)
|
|
|
|
os.getenv.invokes(function(key)
|
|
|
|
if key == "PRODUCT" then
|
|
|
|
if key == "PRODUCT" then
|
|
|
|
return "trilogy"
|
|
|
|
return "trilogy"
|
|
|
@ -56,11 +62,8 @@ describe("device module", function()
|
|
|
|
return saved_getenv(key)
|
|
|
|
return saved_getenv(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
package.loaded['device/kobo/device'] = nil
|
|
|
|
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = mock_fb
|
|
|
|
|
|
|
|
mock_input = require('device/input')
|
|
|
|
|
|
|
|
stub(mock_input, "open")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package.loaded['device/kobo/device'] = nil
|
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
kobo_dev:init()
|
|
|
|
kobo_dev:init()
|
|
|
|
local Screen = kobo_dev.screen
|
|
|
|
local Screen = kobo_dev.screen
|
|
|
@ -93,17 +96,12 @@ describe("device module", function()
|
|
|
|
assert.is.same(y, ev_x.value)
|
|
|
|
assert.is.same(y, ev_x.value)
|
|
|
|
assert.is.same(ABS_Y, ev_x.code)
|
|
|
|
assert.is.same(ABS_Y, ev_x.code)
|
|
|
|
|
|
|
|
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = nil
|
|
|
|
|
|
|
|
os.getenv:revert()
|
|
|
|
|
|
|
|
mock_input.open:revert()
|
|
|
|
|
|
|
|
-- reset eventAdjustHook
|
|
|
|
-- reset eventAdjustHook
|
|
|
|
kobo_dev.input.eventAdjustHook = function() end
|
|
|
|
kobo_dev.input.eventAdjustHook = function() end
|
|
|
|
kobo_dev.touch_probe_ev_epoch_time = true
|
|
|
|
kobo_dev.touch_probe_ev_epoch_time = true
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
it("should setup eventAdjustHooks properly for trilogy with non-epoch ev time", function()
|
|
|
|
it("should setup eventAdjustHooks properly for trilogy with non-epoch ev time", function()
|
|
|
|
local saved_getenv = os.getenv
|
|
|
|
|
|
|
|
stub(os, "getenv")
|
|
|
|
|
|
|
|
os.getenv.invokes(function(key)
|
|
|
|
os.getenv.invokes(function(key)
|
|
|
|
if key == "PRODUCT" then
|
|
|
|
if key == "PRODUCT" then
|
|
|
|
return "trilogy"
|
|
|
|
return "trilogy"
|
|
|
@ -111,11 +109,6 @@ describe("device module", function()
|
|
|
|
return saved_getenv(key)
|
|
|
|
return saved_getenv(key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
package.loaded['device/kobo/device'] = nil
|
|
|
|
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = mock_fb
|
|
|
|
|
|
|
|
mock_input = require('device/input')
|
|
|
|
|
|
|
|
stub(mock_input, "open")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
kobo_dev:init()
|
|
|
|
kobo_dev:init()
|
|
|
|
local Screen = kobo_dev.screen
|
|
|
|
local Screen = kobo_dev.screen
|
|
|
@ -149,9 +142,6 @@ describe("device module", function()
|
|
|
|
assert.truthy(cur_sec - ev_x.time.sec < 10)
|
|
|
|
assert.truthy(cur_sec - ev_x.time.sec < 10)
|
|
|
|
assert.truthy(cur_sec - ev_y.time.sec < 10)
|
|
|
|
assert.truthy(cur_sec - ev_y.time.sec < 10)
|
|
|
|
|
|
|
|
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = nil
|
|
|
|
|
|
|
|
os.getenv:revert()
|
|
|
|
|
|
|
|
mock_input.open:revert()
|
|
|
|
|
|
|
|
kobo_dev.input.eventAdjustHook = function() end
|
|
|
|
kobo_dev.input.eventAdjustHook = function() end
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
@ -195,44 +185,44 @@ describe("device module", function()
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
describe("kindle #notest #nocov", function()
|
|
|
|
describe("kindle", function()
|
|
|
|
it("should initialize voyage without error", function()
|
|
|
|
it("should initialize voyage without error", function()
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = mock_fb
|
|
|
|
io.open = function(filename, mode)
|
|
|
|
stub(io, "open")
|
|
|
|
if filename == "/proc/usid" then
|
|
|
|
io.open.returns({
|
|
|
|
return {
|
|
|
|
read = function()
|
|
|
|
read = function() return "XX13XX" end,
|
|
|
|
return "XX13XX"
|
|
|
|
close = function() end
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
close = function() end
|
|
|
|
else
|
|
|
|
})
|
|
|
|
return iopen(filename, mode)
|
|
|
|
mock_input = require('device/input')
|
|
|
|
end
|
|
|
|
stub(mock_input, "open")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local kindle_dev = require("device/kindle/device")
|
|
|
|
local kindle_dev = require('device/kindle/device')
|
|
|
|
assert.is.same(kindle_dev.model, "KindleVoyage")
|
|
|
|
assert.is.same(kindle_dev.model, "KindleVoyage")
|
|
|
|
kindle_dev:init()
|
|
|
|
kindle_dev:init()
|
|
|
|
assert.is.same(kindle_dev.input.event_map[104], "LPgBack")
|
|
|
|
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.input.event_map[109], "LPgFwd")
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_min, 0)
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_min, 0)
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_max, 24)
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_max, 24)
|
|
|
|
|
|
|
|
|
|
|
|
io.open:revert()
|
|
|
|
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = nil
|
|
|
|
|
|
|
|
mock_input.open:revert()
|
|
|
|
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
it("should toggle frontlight", function()
|
|
|
|
it("should toggle frontlight", function()
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = mock_fb
|
|
|
|
io.open = function(filename, mode)
|
|
|
|
stub(io, "open")
|
|
|
|
if filename == "/proc/usid" then
|
|
|
|
io.open.returns({
|
|
|
|
return {
|
|
|
|
read = function()
|
|
|
|
read = function() return "XX13XX" end,
|
|
|
|
return "12"
|
|
|
|
close = function() end
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
close = function() end
|
|
|
|
elseif filename == "/sys/class/backlight/max77696-bl/brightness" then
|
|
|
|
})
|
|
|
|
return {
|
|
|
|
mock_input = require('device/input')
|
|
|
|
read = function() return "12" end,
|
|
|
|
stub(mock_input, "open")
|
|
|
|
close = function() end
|
|
|
|
stub(os, "execute")
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
return iopen(filename, mode)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local kindle_dev = require("device/kindle/device")
|
|
|
|
local kindle_dev = require("device/kindle/device")
|
|
|
|
kindle_dev:init()
|
|
|
|
kindle_dev:init()
|
|
|
@ -251,11 +241,46 @@ describe("device module", function()
|
|
|
|
kindle_dev.powerd:toggleFrontlight()
|
|
|
|
kindle_dev.powerd:toggleFrontlight()
|
|
|
|
assert.stub(os.execute).was_called_with(
|
|
|
|
assert.stub(os.execute).was_called_with(
|
|
|
|
"echo -n 5 > /sys/class/backlight/max77696-bl/brightness")
|
|
|
|
"echo -n 5 > /sys/class/backlight/max77696-bl/brightness")
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("oasis should interpret orientation event", function()
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
io.open:revert()
|
|
|
|
mock_ffi_input.waitForEvent:revert()
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = nil
|
|
|
|
UIManager.onRotation:revert()
|
|
|
|
mock_input.open:revert()
|
|
|
|
|
|
|
|
os.execute:revert()
|
|
|
|
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|