72 lines
3.8 KiB
Lua
72 lines
3.8 KiB
Lua
local now, timers, info, left, added = 0, {}, {}, {}, {}
|
|
local listener, voteHook
|
|
function GetTime() return now end
|
|
function GetLootRollItemInfo(id) return nil, info[id] end
|
|
function GetLootRollTimeLeft(id) return left[id] or 0 end
|
|
C_Timer = {After = function(_, f) timers[#timers + 1] = f end}
|
|
function CreateFrame()
|
|
local f = {}
|
|
function f:RegisterEvent() end
|
|
function f:SetScript(_, cb) listener = cb end
|
|
return f
|
|
end
|
|
function RollOnLoot() end
|
|
function hooksecurefunc(name, cb) assert(name == "RollOnLoot"); voteHook = cb end
|
|
GroupLootContainer = {waitingRolls = {}, rollFrames = {}}
|
|
function GroupLootContainer_AddRoll(id, duration)
|
|
added[#added + 1] = {id, duration}
|
|
GroupLootContainer.waitingRolls[#GroupLootContainer.waitingRolls + 1] = {rollID = id}
|
|
end
|
|
local function event(e, ...) listener(nil, e, ...) end
|
|
local function tick()
|
|
now = now + .25
|
|
local run = timers; timers = {}
|
|
for _, f in ipairs(run) do f() end
|
|
end
|
|
local function start(id, duration)
|
|
left[id] = duration or 60000
|
|
event("START_LOOT_ROLL", id, duration or 60000)
|
|
end
|
|
local secure = false
|
|
function issecure() return secure end
|
|
dofile(arg[1]); assert(listener == nil and voteHook == nil and #timers == 0)
|
|
secure = true
|
|
dofile(arg[1])
|
|
start(1); tick(); assert(#added == 0 and #timers == 1)
|
|
info[1] = "Ready"; event("GET_ITEM_INFO_RECEIVED", 99, true); tick()
|
|
assert(#added == 1 and added[1][1] == 1 and added[1][2] == 59500)
|
|
tick(); assert(#added == 1 and #timers == 0)
|
|
-- Cached starts are solely native-owned; no duplicate after normal display/vote.
|
|
info[2] = "Cached"; start(2); tick(); assert(#added == 1)
|
|
-- Native may have acquired the frame before our item cache retry.
|
|
start(3); GroupLootContainer.rollFrames[1] = {rollID = 3, IsShown = function() return true end}
|
|
info[3] = "Ready"; tick(); assert(#added == 1)
|
|
start(4); GroupLootContainer.waitingRolls[#GroupLootContainer.waitingRolls + 1] = {rollID = 4}
|
|
info[4] = "Ready"; tick(); assert(#added == 1)
|
|
-- Queued recovery uses the native queue, without a four-frame addon limit.
|
|
for id = 10, 17 do start(id); info[id] = "Ready" end
|
|
tick(); assert(#added == 9)
|
|
-- Cancel/expiry/session reset and real votes never resurrect a roll.
|
|
start(20); event("CANCEL_LOOT_ROLL", 20); info[20] = "Ready"; tick(); assert(#added == 9)
|
|
start(21); left[21] = 0; info[21] = "Ready"; tick(); assert(#added == 9)
|
|
start(22); voteHook(22, 1); info[22] = "Ready"; tick(); assert(#added == 9)
|
|
start(23); event("CANCEL_ALL_LOOT_ROLLS"); info[23] = "Ready"; tick(); assert(#added == 9 and #timers == 0)
|
|
start(24); event("PLAYER_LEAVING_WORLD"); info[24] = "Ready"; tick(); assert(#added == 9)
|
|
start(25, 100); info[25] = "Ready"; tick(); assert(#added == 9)
|
|
-- Do not extend a deadline on duplicate START, nor use a stale native timer.
|
|
start(26, 500); tick(); start(26, 60000); info[26] = "Ready"; tick(); assert(#added == 9)
|
|
-- An uncached start during loading retries only after loading ends.
|
|
event("LOADING_SCREEN_ENABLED"); start(30); info[30] = "Ready"; tick(); assert(#added == 9)
|
|
event("LOADING_SCREEN_DISABLED"); tick(); assert(#added == 10 and added[10][2] == 59500)
|
|
-- A never-loaded item stays bounded by the original countdown.
|
|
start(31, 500); tick(); tick(); assert(#timers == 0 and #added == 10)
|
|
-- An uncached native waiting-queue entry must stay recoverable until it has data.
|
|
start(35); GroupLootContainer.waitingRolls[#GroupLootContainer.waitingRolls + 1] = {rollID = 35}
|
|
tick(); assert(#added == 10 and #timers == 1)
|
|
table.remove(GroupLootContainer.waitingRolls); info[35] = "Ready"; tick(); assert(#added == 11)
|
|
print("loot cache retry: cache miss, duplicate, 8 queued rolls, loading, expiry, cancellation and vote PASS")
|
|
|
|
-- A later insecure callback cannot enter native managed layout.
|
|
start(36); info[36] = "Ready"; secure = false; tick(); secure = true
|
|
assert(#added == 11)
|