138 lines
5.7 KiB
Lua
138 lines
5.7 KiB
Lua
-- Exercise the shipped Lua entry points using synthetic, server-shaped messages.
|
|
local dir = assert(arg[1])
|
|
local events, sent, timers, chat, combat, npc = nil, {}, {}, {}, false, nil
|
|
local player, registered, sendResult = "Viewer", {}, 0
|
|
local Widget = {}
|
|
local noop = function() end
|
|
function Widget:SetScript(kind, callback) self.scripts[kind] = callback end
|
|
function Widget:GetFrameLevel() return 2 end
|
|
function Widget:GetHeight() return self.height or 12 end
|
|
function Widget:SetHeight(height) self.height = height end
|
|
function Widget:Show() self.shown = true end
|
|
function Widget:Hide() self.shown = false end
|
|
function Widget:IsShown() return self.shown end
|
|
function Widget:SetEnabled(value) self.enabled = value end
|
|
function Widget:SetText(text) self.text = text end
|
|
function Widget:SetTexture(path) self.texture = path end
|
|
for _, method in ipairs({"RegisterEvent", "SetWidth", "SetPoint", "SetFrameStrata", "EnableMouse",
|
|
"SetFrameLevel", "SetAllPoints", "SetBackdrop", "SetJustifyH", "SetShadowOffset",
|
|
"SetTextColor", "ClearAllPoints", "SetTexCoord"}) do Widget[method] = noop end
|
|
function CreateFrame(kind, name, parent, template)
|
|
local frame = setmetatable({shown = true, scripts = {}, template = template}, {__index = Widget})
|
|
if name then _G[name] = frame end
|
|
if not events then events = frame end
|
|
return frame
|
|
end
|
|
function Widget:CreateTexture() return CreateFrame("Texture") end
|
|
function Widget:CreateFontString() return CreateFrame("FontString") end
|
|
UIParent = {}
|
|
UISpecialFrames = {}
|
|
DEFAULT_CHAT_FRAME = {AddMessage = function(_, msg) table.insert(chat, msg) end}
|
|
GetLocale = function() return arg[2] or "enUS" end
|
|
UnitFullName = function() return "Viewer", "Home" end
|
|
UnitName = function(unit) if unit == "npc" then return npc end return player end
|
|
UnitAffectingCombat = function() return combat end
|
|
SendChatMessage = function() error("70334 blocks addon SAY in the open world") end
|
|
C_ChatInfo = {
|
|
RegisterAddonMessagePrefix = function(prefix) registered[prefix] = true; return 0 end,
|
|
SendChatMessage = SendChatMessage,
|
|
SendAddonMessage = function(prefix, text, kind, target)
|
|
assert(prefix == "GWGRAVE" and kind == "WHISPER" and target == "Viewer")
|
|
if sendResult == 0 or sendResult == true then table.insert(sent, text) end
|
|
return sendResult
|
|
end,
|
|
}
|
|
C_Timer = {NewTimer = function(seconds, callback)
|
|
local t = {seconds = seconds, callback = callback, Cancel = function(self) self.cancelled = true end}
|
|
table.insert(timers, t)
|
|
return t
|
|
end}
|
|
local L = {}
|
|
assert(loadfile(dir .. "/Locale.lua"))("OctoReplayGrave", L)
|
|
assert(loadfile(dir .. "/Grave.lua"))("OctoReplayGrave", L)
|
|
local function fire(event, ...)
|
|
events.scripts.OnEvent(events, event, ...)
|
|
end
|
|
local function message(text, sender, channel)
|
|
fire("CHAT_MSG_ADDON", "OWLDTH", text, channel or "GUILD", sender or "Viewer-Home")
|
|
end
|
|
local id = "17365880163140632691"
|
|
local grave = "G|" .. id .. "|9007199254740993|Example|18|1|2|1|19|ok|Wolf"
|
|
fire("PLAYER_LOGIN")
|
|
assert(#sent == 0)
|
|
assert(registered.OWLDTH)
|
|
player = nil
|
|
fire("PLAYER_ENTERING_WORLD")
|
|
player, sendResult = "Viewer", 3
|
|
fire("PLAYER_ENTERING_WORLD")
|
|
assert(#sent == 0)
|
|
sendResult = 0
|
|
fire("PLAYER_ENTERING_WORLD")
|
|
fire("PLAYER_ENTERING_WORLD")
|
|
assert(#timers == 0 and not OctoReplayGraveFrame and #chat == 0)
|
|
assert(sent[1] == "CAPS" and #sent == 1)
|
|
npc = "Unrelated NPC"
|
|
fire("GOSSIP_SHOW")
|
|
assert(#sent == 1)
|
|
npc = L.KEEPER_ORTAK
|
|
fire("GOSSIP_SHOW")
|
|
assert(#sent == 2 and sent[2] == "CAPS")
|
|
message(grave, "Neighbor-Home")
|
|
message(grave, "Viewer-Away")
|
|
message(grave, "Viewer", "RAID")
|
|
message("B|2|0|1|0")
|
|
assert(not OctoReplayGraveFrame)
|
|
local words = string.rep("w", 240) .. " | carry on"
|
|
message("\1W|" .. words:sub(1, 235))
|
|
message("\2" .. words:sub(236))
|
|
message(grave)
|
|
local g = assert(OctoReplayGraveFrame)
|
|
assert(g:IsShown() and g.watch.enabled and g.wood:IsShown() and not g.stoneL:IsShown())
|
|
assert(g.title.text == string.format(L.HC_GRAVE_OF, "Example"))
|
|
assert(g.ident.text == string.format(L.HC_IDENT, 18, L.RACE_HUMAN, L.CLASS_PALADIN))
|
|
assert(g.words:IsShown() and g.words.text == string.format(L.HC_WORDS, words))
|
|
assert(g.cause.text == string.format(L.HC_FELL_TO_LVL, "Wolf", 19))
|
|
combat = true
|
|
fire("PLAYER_REGEN_DISABLED")
|
|
assert(not g.watch.enabled and g.reason.text == L.HC_COMBAT)
|
|
g.watch.scripts.OnClick()
|
|
assert(#sent == 2)
|
|
combat = false
|
|
fire("PLAYER_REGEN_ENABLED")
|
|
assert(g.watch.enabled)
|
|
sendResult = 3
|
|
g.watch.scripts.OnClick()
|
|
assert(#sent == 2 and #timers == 0 and g.watch:IsShown() and g.watch.enabled)
|
|
assert(g.status.text == L.HC_ERR_UNAVAIL)
|
|
sendResult = 0
|
|
g.watch.scripts.OnClick()
|
|
g.watch.scripts.OnClick()
|
|
assert(sent[3] == "WATCH " .. id and #sent == 3 and not g.watch:IsShown())
|
|
message("GW|start", "Neighbor-Home")
|
|
assert(g:IsShown())
|
|
message("GW|start")
|
|
assert(not g:IsShown() and timers[1].cancelled and timers[2].seconds == 60)
|
|
message("GW|end|done")
|
|
assert(not g:IsShown() and #chat == 1 and timers[2].cancelled)
|
|
message("W|stale")
|
|
message("G|x|malformed")
|
|
message("G|813|814|Other|31|2|1|3|0|private|")
|
|
assert(g.stoneL:IsShown() and not g.wood:IsShown() and not g.words:IsShown())
|
|
assert(g.reason.text == L.HC_PRIVATE and not g.watch.enabled)
|
|
assert(g.cause.text == L.HC_DROWNED)
|
|
message(grave)
|
|
g.watch.scripts.OnClick()
|
|
local deadline = timers[#timers]
|
|
assert(deadline.seconds == 25)
|
|
deadline.callback()
|
|
assert(g.watch.enabled and g.status.text == L.HC_NO_START)
|
|
g.watch.scripts.OnClick()
|
|
message("ERR|far")
|
|
assert(g.watch.enabled and g.status.text == L.HC_STAND_BY)
|
|
message("W|left behind")
|
|
fire("PLAYER_LEAVING_WORLD")
|
|
assert(not g:IsShown())
|
|
message(grave)
|
|
assert(not g.words:IsShown())
|
|
print("PASS grave capability, original localized facts and slab, sender, chunking, watch, refusal, timeout and transfer reset")
|