188 lines
10 KiB
Lua
188 lines
10 KiB
Lua
-- Exercise the original peer protocol through the current game-frame entry points.
|
|
local root=arg[1] or "."
|
|
dofile(root.."/client_addons/GatewayDiagnostics/TurtleData.lua")
|
|
local name, guid, class, range, shown, inspected, time = "Peer","Player-70-12345678",1,true,true,"target",100
|
|
local secret={}
|
|
function issecretvalue(v) return v==secret end
|
|
function GetTime() return time end
|
|
function UnitName(u) return u=="player" and "Local" or name end
|
|
function GetNormalizedRealmName() return "Home" end
|
|
function UnitGUID() return guid end
|
|
function UnitClass() return "Warrior","WARRIOR",class end
|
|
function UnitIsUnit(a,b) return a==b end
|
|
function UnitIsPlayer() return true end
|
|
function UnitIsVisible() return true end
|
|
function CanInspect() return true end
|
|
function UnitCanAttack() return false end
|
|
function UnitIsDeadOrGhost() return false end
|
|
function CheckInteractDistance(u,idx) assert(u=="target" and idx==1); return range end
|
|
Enum={RegisterAddonMessagePrefixResult={Success=0},SendAddonMessageResult={Success=0}}
|
|
local sends,frames,gearRequests={},{},{}
|
|
C_ChatInfo={
|
|
RegisterAddonMessagePrefix=function(p) assert(p=="GWInspectTalent" or p=="GWInspectGear"); return 0 end,
|
|
SendAddonMessage=function(...)
|
|
local packet={...}
|
|
if packet[1]=="GWInspectGear" then gearRequests[#gearRequests+1]=packet else sends[#sends+1]=packet end
|
|
return 0
|
|
end,
|
|
}
|
|
local widget={}
|
|
widget.__index=widget
|
|
local function new() return setmetatable({events={},scripts={}},widget) end
|
|
function widget:RegisterEvent(k) self.events[k]=true end
|
|
function widget:SetScript(k,v) self.scripts[k]=v end
|
|
for _,k in ipairs({"SetSize","SetPoint","SetWidth","SetJustifyH","SetAllPoints","SetColorTexture","SetFrameLevel"}) do widget[k]=function() end end
|
|
function widget:CreateTexture() return new() end
|
|
function widget:CreateFontString() return new() end
|
|
function widget:SetText(v) self.value=v end
|
|
function widget:SetEnabled(v) self.enabled=v end
|
|
function widget:SetShown(v) self.shown=v end
|
|
function widget:Show() self.shown=true end
|
|
function widget:Hide() self.shown=false end
|
|
function CreateFrame(kind,_,parent)
|
|
local f=new(); f.parent=parent; frames[#frames+1]=f; return f
|
|
end
|
|
local pane={DisabledOverlay={GetFrameLevel=function()return 10 end}, IsVisible=function() return shown end,
|
|
IsInspecting=function()return inspected~=nil end, GetInspectUnit=function() return inspected end}
|
|
PlayerSpellsFrame={TalentsFrame=pane,IsVisible=function()return shown end}
|
|
PlayerSpellsUtil={OpenToClassTalentsTab=function() end}
|
|
local observedOpen
|
|
function hooksecurefunc(tbl, name, callback)
|
|
assert(tbl==PlayerSpellsUtil and name=="OpenToClassTalentsTab"); observedOpen=callback
|
|
end
|
|
dofile(root.."/client_addons/WoWHybridUI/NativeInspectEquipment.lua")
|
|
frames={}
|
|
dofile(root.."/client_addons/WoWHybridUI/NativeInspectTalents.lua")
|
|
local api=WoWHybridInspectTalents
|
|
local event=frames[1]
|
|
local function update() event.scripts.OnUpdate(event,.26) end
|
|
local function emit(eventName,...) return event.scripts.OnEvent(event,eventName,...)end
|
|
update()
|
|
local panel=frames[2]
|
|
assert(panel and panel.request.shown and panel.request.enabled and #sends==0)
|
|
observedOpen(nil);assert(#sends==0)
|
|
observedOpen("target");observedOpen("target");panel.request.scripts.OnClick()
|
|
assert(#sends==1 and table.concat(sends[1],"|")=="GWInspectTalent|request Peer|WHISPER|Local")
|
|
assert(#gearRequests==1 and table.concat(gearRequests[1],"|")=="GWInspectGear|70 305419896|WHISPER|Local")
|
|
assert(not api.SendRequest("Peer") and not api.Receive("Foreign-Other","INSTalentEND;"))
|
|
local tabs={}
|
|
for _,tab in ipairs(GatewayTurtleData.tabs) do
|
|
if tab.classMask==1 then
|
|
local nodes={}
|
|
for _,node in ipairs(GatewayTurtleData.talents) do if node.tab==tab.id then nodes[#nodes+1]=node end end
|
|
table.sort(nodes,function(a,b) return a.row*4+a.column < b.row*4+b.column end)
|
|
tabs[tab.order+1]={name=tab.name,nodes=nodes}
|
|
end
|
|
end
|
|
local function payloads()
|
|
local messages={}
|
|
for ti,t in ipairs(tabs) do
|
|
messages[#messages+1]=table.concat({"INSTalentTabInfo",ti,t.name,1,#t.nodes},";")
|
|
for ni,node in ipairs(t.nodes) do
|
|
messages[#messages+1]=table.concat({"INSTalentInfo",ti,ni,node.ranks[1].name,node.row+1,node.column+1,ni==1 and 1 or 0,#node.ranks,0,-1,-1,-1},";")
|
|
end
|
|
end
|
|
messages[#messages+1]="INSTalentEND;"
|
|
return messages
|
|
end
|
|
local rows=payloads()
|
|
local function wire(row,sender,recipient,channel)
|
|
emit("CHAT_MSG_ADDON","GWInspectTalent",row,channel or "GUILD",sender or "Peer-Home",recipient or "")
|
|
end
|
|
wire(rows[1],"Wrong");wire(rows[1],nil,"Wrong");wire(rows[1],nil,nil,"WHISPER");wire(rows[1],nil,nil,secret)
|
|
for _,row in ipairs(rows) do wire(row) end
|
|
assert(not panel.request.shown and panel.tabs[1].value=="Arms (1)")
|
|
assert(panel.text.value:find("Improved Heroic Strike 1/3",1,true))
|
|
panel.tabs[2].scripts.OnClick()
|
|
assert(panel.text.value:find(tabs[2].nodes[1].ranks[1].name,1,true) and not panel.text.value:find("Improved Heroic Strike",1,true))
|
|
assert(#sends==1 and not api.Receive("Peer","INSTalentEND;"))
|
|
-- The peer enumerates a tree independently of the order used to draw our grid.
|
|
assert(api.SendRequest("Peer"))
|
|
for _,row in ipairs(rows) do
|
|
local swapped=row:gsub("^INSTalentInfo;1;([12]);",function(i)
|
|
return "INSTalentInfo;1;"..(3-tonumber(i))..";"
|
|
end)
|
|
wire(swapped)
|
|
end
|
|
panel.tabs[1].scripts.OnClick()
|
|
assert(panel.text.value:find("Improved Heroic Strike 1/3",1,true))
|
|
-- Both a reused wire index and a second index claiming the same node invalidate a reply.
|
|
for _,bad in ipairs({(rows[3]:gsub("^INSTalentInfo;1;2;", "INSTalentInfo;1;1;")),
|
|
(rows[2]:gsub("^INSTalentInfo;1;1;", "INSTalentInfo;1;2;"))}) do
|
|
assert(api.SendRequest("Peer") and api.Receive("Peer",rows[1]) and api.Receive("Peer",rows[2]))
|
|
assert(not api.Receive("Peer",bad))
|
|
assert(not api.Receive("Peer","INSTalentEND;"))
|
|
end
|
|
-- A cancelled old peer must consume its terminator before another request to that peer.
|
|
name,guid="Other","Player-B";emit("PLAYER_TARGET_CHANGED");assert(panel.request.shown)
|
|
assert(api.SendRequest("Other"))
|
|
name,guid="Peer","Player-70-12345678";emit("PLAYER_TARGET_CHANGED");assert(api.SendRequest("Peer"))
|
|
assert(not api.Receive("Other",rows[1]))
|
|
name,guid="Other","Player-B";emit("PLAYER_TARGET_CHANGED");assert(not api.SendRequest("Other"))
|
|
assert(not api.Receive("Other","INSTalentEND;") and api.SendRequest("Other"))
|
|
assert(api.Receive("Other",rows[1]))
|
|
assert(not api.Receive("Other",rows[2]:gsub("Improved Heroic Strike","|Hurl:never|h")))
|
|
assert(not api.Receive("Other","INSTalentEND;") and api.SendRequest("Other"))
|
|
assert(api.Receive("Other",rows[1]) and not api.Receive("Other",rows[1]))
|
|
assert(not api.Receive("Other","INSTalentEND;") and api.SendRequest("Other"))
|
|
for i=1,#rows-2 do assert(api.Receive("Other",rows[i])) end
|
|
assert(not api.Receive("Other","INSTalentEND;"))
|
|
assert(api.SendRequest("Other"))
|
|
assert(api.Receive("Other",rows[1]:gsub(";1;18$",";2;18")))
|
|
for i=2,#rows-1 do assert(api.Receive("Other",rows[i])) end
|
|
assert(not api.Receive("Other","INSTalentEND;"))
|
|
assert(api.SendRequest("Other")); time=time+16;update()
|
|
assert(panel.text.value:find("complete",1,true) and not api.SendRequest("Other"))
|
|
assert(not api.Receive("Other","INSTalentEND;") and api.SendRequest("Other"))
|
|
range=false;update();assert(not panel.shown and not api.Receive("Other",rows[1]))
|
|
range=true;emit("PLAYER_LEAVING_WORLD");update()
|
|
inspected=nil;update();assert(not panel.shown and not api.SendRequest("Other"))
|
|
inspected="target";guid=secret;update();assert(not panel.shown and not api.SendRequest("Other"))
|
|
guid="Player-B";shown=false;update();assert(not api.SendRequest("Other"))
|
|
-- A silent source may never deliver END. All cancelled peers recover after
|
|
-- the native 20-second request lifetime plus the five-second margin.
|
|
shown=true;range=true;emit("PLAYER_LEAVING_WORLD")
|
|
local function selectPeer(i)
|
|
local suffix=string.char(65+math.floor(i/26),65+i%26)
|
|
name,guid="Test"..suffix,"Player-"..suffix
|
|
emit("PLAYER_TARGET_CHANGED")
|
|
end
|
|
for i=1,32 do selectPeer(i);assert(api.SendRequest(name)) end
|
|
selectPeer(33);assert(not api.SendRequest(name))
|
|
time=time+24;update();assert(not api.SendRequest(name))
|
|
time=time+1;update();assert(api.SendRequest(name))
|
|
selectPeer(1);assert(api.SendRequest(name))
|
|
-- Show Talents on A, then B, then A again while A's old response is still arriving.
|
|
emit("PLAYER_LEAVING_WORLD")
|
|
selectPeer(1);observedOpen("target")
|
|
selectPeer(2);observedOpen("target")
|
|
selectPeer(1);local beforeReturn=#sends
|
|
observedOpen("target");observedOpen("target")
|
|
wire(rows[1],name);update();assert(#sends==beforeReturn)
|
|
wire("INSTalentEND;",name);update();update()
|
|
assert(#sends==beforeReturn+1,"returning to the same peer lost the Show Talents click")
|
|
for _,row in ipairs(rows) do wire(row,name) end
|
|
assert(panel.tabs[1].value=="Arms (1)")
|
|
-- Switching away while waiting cancels that click.
|
|
selectPeer(3);observedOpen("target");local retired=name
|
|
selectPeer(4);selectPeer(3);observedOpen("target")
|
|
selectPeer(4);local beforeLate=#sends
|
|
wire("INSTalentEND;",retired);selectPeer(3);update();assert(#sends==beforeLate)
|
|
-- Original Warlock spell strings include a trailing space on Emberstorm ranks 3-5.
|
|
emit("PLAYER_LEAVING_WORLD")
|
|
class=9;selectPeer(5)
|
|
local ember,tree,tabName,nodeCount
|
|
for _,node in ipairs(GatewayTurtleData.talents) do if node.id==335 then ember=node end end
|
|
for _,tab in ipairs(GatewayTurtleData.tabs) do
|
|
if tab.id==ember.tab then tree,tabName=tab.order+1,tab.name end
|
|
end
|
|
nodeCount=0
|
|
for _,node in ipairs(GatewayTurtleData.talents) do if node.tab==ember.tab then nodeCount=nodeCount+1 end end
|
|
for _,case in ipairs({{3,"Emberstorm ",true},{2,"Emberstorm ",false},{5,"Emberstorm",true},{5,"Emberstorm ",false}}) do
|
|
assert(api.SendRequest(name))
|
|
assert(api.Receive(name,table.concat({"INSTalentTabInfo",tree,tabName,case[1],nodeCount},";")))
|
|
assert(api.Receive(name,table.concat({"INSTalentInfo",tree,1,case[2],ember.row+1,ember.column+1,case[1],#ember.ranks,0,-1,-1,-1},";"))==case[3])
|
|
api.Receive(name,"INSTalentEND;")
|
|
end
|
|
print("PASS: explicit addressed request, 3 complete trees, exact ranks, sender/recipient, A/B/A, timeout, range, self/hidden, malicious text, partial and inconsistent totals")
|