mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
test: more uimanager scheduler test
This commit is contained in:
@@ -49,7 +49,7 @@ local function _serialize(what, outt, indent, max_lv, history)
|
||||
elseif type(what) == "number" then
|
||||
if isUbuntuTouch then
|
||||
-- FIXME: the `SDL_CreateRenderer` function in Ubuntu touch somehow
|
||||
-- use a strange locale that formats number like this: 1.10000000000000g+02
|
||||
-- use a strange locale that formats number like this: 1.10000000000000g+02
|
||||
-- which cannot be recognized by loadfile after the number is dumped.
|
||||
-- Here the workaround is to preserve enough precision in "%.13e" format.
|
||||
insert(outt, string.format("%.13e", what))
|
||||
@@ -59,7 +59,7 @@ local function _serialize(what, outt, indent, max_lv, history)
|
||||
elseif type(what) == "boolean" then
|
||||
insert(outt, tostring(what))
|
||||
elseif type(what) == "function" then
|
||||
insert(outt, "nil --[[ FUNCTION ]]")
|
||||
insert(outt, tostring(what))
|
||||
elseif type(what) == "nil" then
|
||||
insert(outt, "nil")
|
||||
end
|
||||
|
||||
@@ -227,9 +227,7 @@ end
|
||||
-- UIManager:unschedule(self.anonymousFunction)
|
||||
function UIManager:unschedule(action)
|
||||
for i = #self._task_queue, 1, -1 do
|
||||
local task = self._task_queue[i]
|
||||
if task.action == action then
|
||||
-- remove from table
|
||||
if self._task_queue[i].action == action then
|
||||
table.remove(self._task_queue, i)
|
||||
end
|
||||
end
|
||||
|
||||
4
kodev
4
kodev
@@ -309,7 +309,9 @@ OPTIONS:
|
||||
if [ ! -z $2 ]; then
|
||||
test_path="${test_path}/$2"
|
||||
fi
|
||||
busted --lua=./luajit ${opts} -o ./spec/$1/unit/verbose_print --exclude-tags=notest ${test_path}
|
||||
busted --lua=./luajit ${opts} \
|
||||
-o ./spec/$1/unit/verbose_print \
|
||||
--exclude-tags=notest ${test_path}
|
||||
|
||||
popd
|
||||
}
|
||||
|
||||
@@ -113,6 +113,25 @@ describe("UIManager spec", function()
|
||||
assert.are.same('quux', UIManager._task_queue[5].action)
|
||||
end)
|
||||
|
||||
it("should unschedule all the tasks with the same action", function()
|
||||
local now = { util.gettime() }
|
||||
local noop1 = function() end
|
||||
UIManager:quit()
|
||||
UIManager._task_queue = {
|
||||
{ time = {now[1] - 15, now[2] }, action = '3' },
|
||||
{ time = {now[1] - 10, now[2] }, action = '1' },
|
||||
{ time = {now[1], now[2] - 6 }, action = '3' },
|
||||
{ time = {now[1], now[2] - 5 }, action = '2' },
|
||||
{ time = now, action = '3' },
|
||||
}
|
||||
-- insert into the tail slot
|
||||
UIManager:unschedule('3')
|
||||
assert.are.same({
|
||||
{ time = {now[1] - 10, now[2] }, action = '1' },
|
||||
{ time = {now[1], now[2] - 5 }, action = '2' },
|
||||
}, UIManager._task_queue)
|
||||
end)
|
||||
|
||||
it("should not have race between unschedule and _checkTasks", function()
|
||||
local now = { util.gettime() }
|
||||
local run_count = 0
|
||||
|
||||
Reference in New Issue
Block a user