129 lines
5.2 KiB
Lua
129 lines
5.2 KiB
Lua
-- Drive the native UpdateStats post-hook, the shipped StatCompare scanner and
|
|
-- its actual effect tables. Only the game APIs and the independent BCS rows
|
|
-- are mocked. Pass a second argument to print the baseline operation counts.
|
|
local addon = arg[1] .. "/client_addons/WoWHybridUI/"
|
|
local noop = function() end
|
|
local scans, requests, auraScans = 0, 0, 0
|
|
local itemLink = "|Hitem:1:0|h[Test]|h"
|
|
local equipped, cached, failScan = true, true, false
|
|
local bonus, tooltipReady = 3, true
|
|
local handlers = {}
|
|
local function tooltip()
|
|
return {
|
|
Hide = noop, SetOwner = noop, ClearLines = noop,
|
|
SetHyperlink = function(self) self.hasItem = true end,
|
|
SetInventoryItem = function(self, _, slot) self.hasItem = equipped and slot == 1 end,
|
|
NumLines = function(self)
|
|
scans = scans + 1
|
|
if failScan then error("fixture tooltip is unavailable") end
|
|
return self.hasItem and (tooltipReady and 2 or 1) or 0
|
|
end,
|
|
}
|
|
end
|
|
SCObjectTooltipTextLeft2 = { GetText = function() return "+" .. bonus .. " Strength" end }
|
|
BCS = {L = {}, RunScans = function(self) if self.needScanAuras then auraScans = auraScans + 1 end end}
|
|
HIGHLIGHT_FONT_COLOR_CODE, FONT_COLOR_CODE_CLOSE = "", ""
|
|
function GetInventoryItemID(_, slot) if equipped and slot == 1 then return 1 end end
|
|
function GetInventoryItemLink(_, slot) if equipped and slot == 1 then return itemLink end end
|
|
function UnitClass() return "Druid", "DRUID" end
|
|
C_Item = {
|
|
IsItemDataCachedByID = function() return cached end,
|
|
RequestLoadItemDataByID = function() requests = requests + 1 end,
|
|
}
|
|
local playerRows
|
|
function CreateFrame(kind, _, _, template)
|
|
if kind == "GameTooltip" then return tooltip() end
|
|
if template then
|
|
return {SetAllPoints = noop, SetFrameLevel = noop, EnableMouse = noop,
|
|
ScrollBox = {SetDataProvider = function(_, rows) playerRows = rows end}}
|
|
end
|
|
return { RegisterEvent = noop, SetScript = function(self, _, callback)
|
|
handlers[#handlers+1] = function(event) callback(self, event) end
|
|
end }
|
|
end
|
|
local function fire(event) for _, handler in ipairs(handlers) do handler(event) end end
|
|
CharacterStatsPaneScrollBox = {
|
|
GetUnit = function() return "player" end, IsVisible = function() return true end,
|
|
GetFrameLevel = function() return 1 end, UpdateStats = noop,
|
|
ScrollBox = {SetAlpha = noop, GetDataProvider = function()
|
|
return {Enumerate = function() return ipairs({}) end}
|
|
end},
|
|
}
|
|
function hooksecurefunc(frame, method, hook)
|
|
local original = frame[method]
|
|
frame[method] = function(self, ...) original(self, ...); hook(self, ...) end
|
|
end
|
|
ScrollUtil = { InitScrollBoxListWithScrollBar = noop }
|
|
ScrollBoxConstants = { RetainScrollPosition = 1 }
|
|
function CreateScrollBoxListLinearView() return { SetElementFactory = noop } end
|
|
function CreateDataProvider(rows) return rows end
|
|
local timer
|
|
C_Timer = { After = function(_, callback) timer = callback end }
|
|
for _, module in ipairs({"OctoStatCompareData", "OctoStatCompareScanner", "OctoStatComparePane", "OctoStatsPane"}) do
|
|
dofile(addon .. module .. ".lua")
|
|
end
|
|
local function refresh(expected)
|
|
playerRows = nil
|
|
CharacterStatsPaneScrollBox:UpdateStats()
|
|
assert(playerRows, "stats hook did not update the overlay")
|
|
-- Merged view: Strength gear is shown on the native Strength row (not as a separate Gear Bonuses row);
|
|
-- every row reads the same per-rebuild gear totals.
|
|
for _, row in ipairs(playerRows) do assert(row.labelText ~= "Strength", "strength gear listed twice") end
|
|
local gear = WoWHybridUI.statsGear
|
|
if expected == nil then assert(not (gear and gear.STR), "stale gear bonus")
|
|
else assert(gear and tonumber(gear.STR) == expected, "missing gear bonus") end
|
|
end
|
|
refresh(3)
|
|
local cold = scans
|
|
for _ = 1, 10 do refresh(3) end
|
|
local warm = scans - cold
|
|
print(string.format("StatCompare tooltip slots: first=%d next-ten=%d; BCS aura passes=%d", cold, warm, auraScans))
|
|
assert(cold == 19 and auraScans == 11)
|
|
if arg[2] == "baseline" then return end
|
|
assert(warm == 0, "unchanged gear rescanned")
|
|
local function checkRefresh(expected, slots)
|
|
local before = scans
|
|
refresh(expected)
|
|
assert(scans - before == slots, "unexpected tooltip visit count " .. (scans - before))
|
|
end
|
|
itemLink, bonus = "|Hitem:1:42|h[Test]|h", 7
|
|
checkRefresh(7, 19) -- same item, different enchant, even before the equipment event
|
|
bonus = 8
|
|
fire("UPDATE_INVENTORY_DURABILITY")
|
|
checkRefresh(8, 19)
|
|
bonus = 9
|
|
fire("PLAYER_LEVEL_UP")
|
|
checkRefresh(9, 19)
|
|
cached = false
|
|
checkRefresh(9, 19)
|
|
checkRefresh(9, 19)
|
|
assert(requests == 2)
|
|
cached, bonus = true, 10
|
|
fire("GET_ITEM_INFO_RECEIVED")
|
|
assert(timer); timer()
|
|
checkRefresh(10, 0)
|
|
itemLink = nil -- known ID, link still loading
|
|
checkRefresh(10, 19)
|
|
checkRefresh(10, 19)
|
|
itemLink = "|Hitem:1:0|h[Test]|h"
|
|
checkRefresh(10, 19)
|
|
tooltipReady = false
|
|
fire("PLAYER_EQUIPMENT_CHANGED")
|
|
checkRefresh(nil, 19)
|
|
checkRefresh(nil, 19)
|
|
tooltipReady = true
|
|
fire("GET_ITEM_INFO_RECEIVED")
|
|
assert(timer); timer()
|
|
checkRefresh(10, 0)
|
|
failScan = true
|
|
fire("PLAYER_EQUIPMENT_CHANGED")
|
|
checkRefresh(nil, 1)
|
|
failScan = false
|
|
checkRefresh(10, 19)
|
|
equipped = false
|
|
checkRefresh(nil, 19)
|
|
checkRefresh(nil, 0)
|
|
fire("PLAYER_ENTERING_WORLD")
|
|
checkRefresh(nil, 19)
|
|
print("PASS: gear changes, cold item and link, scan error, removal and character re-entry")
|