Files
pfQuest/tests/tracker_all_quests.lua

176 lines
13 KiB
Lua

-- Run with Lua 5.1 from a pfQuest release directory. All quest data are synthetic.
local old = arg[1] == 'before'
local widgets = {}
local function noop() end
local function frame(kind)
local f = setmetatable({kind=kind, scripts={}, height=0, shown=true}, {__index=widgets})
return f
end
for name in string.gmatch('SetPoint ClearAllPoints SetParent SetWidth SetMovable EnableMouse SetClampedToScreen SetAllPoints SetVertexColor SetAlpha SetFont SetTextColor SetJustifyH RegisterEvent UnregisterEvent UnregisterAllEvents RegisterForClicks SetColorTexture SetFontObject', '%S+') do widgets[name]=noop end
function widgets:GetObjectType() return self.kind end
function widgets:GetChildren() end
function widgets:HasScript() return true end
function widgets:SetScript(k,v) self.scripts[k]=v end
function widgets:GetScript(k) return self.scripts[k] end
function widgets:HookScript(k,v) self.scripts[k]=v end
function widgets:Show() self.shown=true end
function widgets:Hide() self.shown=false end
function widgets:IsShown() return self.shown end
function widgets:SetHeight(h) self.height=h end
function widgets:GetHeight() return self.height end
function widgets:CreateFontString() return frame('FontString') end
function widgets:CreateTexture() return frame('Texture') end
function widgets:SetTexture(t) self.tex=t end
function widgets:SetText(t) self.labelValue=t end
function widgets:GetStringWidth() return #(self.labelValue or '') end
local rows, ids, watch, baseline = {}, {}, false, {}
for i=1,32 do
if i%2==1 then rows[#rows+1]={title='Section '..i,isHeader=true} end
rows[#rows+1]={title='Active '..i,questID=4000+i,level=i}
ids[4000+i]=#rows
end
local g=setmetatable({SlashCmdList={},StaticPopupDialogs={},NUM_CHAT_WINDOWS=0,QUIT_NOW='Quit',CANCEL='Cancel'}, {__index=_G})
g._G=g; g.CreateFrame=frame; g.Minimap=frame('Minimap'); g.UIParent=frame('Frame'); g.GetBuildInfo=function() return '1.60.1','70334','date',16001 end
g.GetCVar=function() return '0' end; g.GetPlayerFacing=function() return 0 end; g.GetTime=function() return 1 end;g.UnitLevel=function()return 35 end
g.GetQuestDifficultyColor=function()return {r=1,g=1,b=1} end
g.ceil=math.ceil;g.strfind=string.find;g.gfind=string.gmatch;g.strlower=string.lower;g.strlen=string.len;g.strsub=string.sub;g.gsub=string.gsub;g.geterrorhandler=function()return error end
g.C_QuestLog={
GetInfo=function(i) return rows[i] end,
GetQuestIDForLogIndex=function(i) return rows[i] and rows[i].questID end,
GetLogIndexForQuestID=function(id) return ids[id] end,
GetNumQuestLogEntries=function() return #rows,32 end,
GetQuestObjectives=function() return {} end,
GetQuestWatchType=function(id) if watch and id%2==0 then return 1 end end,
IsComplete=function(id)return id==4032 end,
}
local function loadModule(path) local f=assert(loadfile(path)); setfenv(f,g); f() end
loadModule('compat/forever.lua'); loadModule('compat/client.lua'); local e=g.pfQuestEnv
local loc=setmetatable({}, {__index=function(_,k)return k end});e.pfQuest_Loc=loc;e.pfQuestConfig={path='pfQuest'};e.pfQuest_config={};e.pfUI={font_default='test-font'};e.pfMap={str2rgb=function() return 1,1,1 end,tooltip={GetColor=function()return 1,1,1 end}}
if arg[1] == 'native' or arg[1] == 'native-before' then
local nativeBefore = arg[1] == 'native-before'
local clock=10;g.GetTime=function() return clock end
g.GetLocale=function() return 'enUS' end
g.bit=g.bit or {band=function() error('unexpected bit masking in this fixture') end}
for line in io.lines('pfQuest.toc') do
local path=line:gsub('\\','/'):gsub('\r',''); if path:match('^db/.*%.lua$') then loadModule(path) end
end
loadModule('database.lua'); loadModule('quest.lua'); loadModule('tracker.lua')
local q,t=e.pfQuest,e.pfQuest.tracker
rows,ids={},{};local active,objectives,watched={}, {}, {}; local selected
local function add(id,title,level)
rows[#rows+1]={title=title,questID=id,questLogIndex=#rows+1,level=level,isHeader=false,isCollapsed=false,frequency=0}
ids[id]=#rows;active[id]=true
end
local function header(title,collapsed) rows[#rows+1]={title=title,questID=0,isHeader=true,isCollapsed=collapsed} end
local function obj(text,kind,have,need,done) return {text=text,type=kind,numFulfilled=have,numRequired=need,finished=done} end
local chosen={};for id,meta in pairs(e.pfDB.quests.loc) do
if #chosen<13 and e.pfDB.quests.data[id] and id~=7441 and id~=3341 and meta.T and not chosen[meta.T] then
chosen[#chosen+1]=id;chosen[meta.T]=true
end
end
table.sort(chosen);header('Normal quests',false)
for _,id in ipairs(chosen) do add(id,e.pfDB.quests.loc[id].T,17) end
header('Dungeons and professions',true)
local shown=#rows
assert(e.pfDB.quests.data[7441] and e.pfDB.quests.data[3341]);add(7441,e.pfDB.quests.loc[7441].T,58);add(3341,e.pfDB.quests.loc[3341].T,42)
local daily,trade,twinA,twinB,elite=990001,990002,990003,990004,990005
for id=daily,elite do assert(not e.pfDB.quests.data[id]) end
add(daily,'Call to Arms: Dungeon',60);rows[#rows].frequency=1
add(trade,'Dustwallow Fishing',40);add(twinA,'Twin Brothers',30);add(twinB,'Twin Brothers',31);add(elite,'Tanaris group quest',60)
objectives[trade]={obj('0/1 Mastercraft Fishing Rod','item',0,1,false),obj('0/1 Darkmoon Special','item',0,1,false),obj("0/1 Fisherman's Backpack",'item',0,1,false)}
objectives[twinA]={obj('Speak to the elder','event',0,0,false)}; objectives[twinB]={obj('3/5 Fish','item',3,5,false)}
objectives[daily]={obj('Complete the dungeon','event',0,1,false)};watched[elite]=true
g.Enum={QuestTag={Dungeon=81,Group=1}}
g.C_QuestLog.GetQuestIDForLogIndex=function(i) return rows[i] and not rows[i].isHeader and rows[i].questID or nil end
g.C_QuestLog.GetNumQuestLogEntries=function() return shown,20 end
g.C_QuestLog.GetQuestObjectives=function(id)assert(active[id]);return objectives[id] end
g.C_QuestLog.IsComplete=function(id)return id==chosen[1] end
g.C_QuestLog.IsOnQuest=function(id)return active[id] or false end
g.C_QuestLog.GetQuestWatchType=function(id) if watched[id] then return 0 end end
g.C_QuestLog.GetQuestTagInfo=function(id) if id==7441 or id==3341 then return {tagID=81,tagName='Dungeon'} elseif id==elite then return {tagID=1,tagName='Group'} end end
g.C_QuestLog.SetSelectedQuest=function(id)selected=id end
g.WorldMapFrame=frame("Frame");g.OpenQuestLog=function() g.WorldMapFrame:Show() end
g.ShowUIPanel=function() error("tracker passed its placeholder to the panel manager") end
e.pfQuest_config.trackerexpand='1';e.pfQuest_config.trackerlevel='1';e.pfQuest_config.trackingmethod='5'
local function readButtons()
local count,byId=0,{};for _,button in ipairs(t.buttons) do if not button.empty and button:IsShown() then
assert(not byId[button.questid]);count=count+1;byId[button.questid]=button
end end;return count,byId
end
if not nativeBefore then
-- Tracker can render immediately, before the location DB cache has been initialized.
t.Reset();t.DoLayout();assert(readButtons()==20)
end
q:UpdateQuestlog();t.Reset();t.DoLayout();local count,b=readButtons()
print('native membership',count,'/ 20; visible count',shown,'; indexed entries',#rows)
if nativeBefore then assert(count==13);print('baseline 13/20 reproduced');return end
assert(count==20);for id in pairs(active) do assert(b[id] and q.questlog[id]) end
assert(b[7441].text.labelValue:match('%[58D%]') and b[3341].text.labelValue:match('%[42D%]'));assert(b[elite].text.labelValue:match('%[60%+%]'))
assert(b[twinA]~=b[twinB] and b[twinA].level==30 and b[twinB].level==31 and b[twinA].perc==0 and b[twinB].perc==60)
for i,o in ipairs(objectives[trade]) do assert(b[trade].objectives[i].labelValue=='|cffffffff- '..o.text) end
assert(b[daily].title=='Call to Arms: Dungeon' and b[daily].objectives[1].labelValue:find('Complete the dungeon',1,true))
assert(not b[daily].tracked and b[elite].tracked)
for id=daily,elite do assert(e.pfDatabase:SearchQuestID(id,{addon='PFQUEST',qlogid=ids[id]})==nil) end
t.ButtonAdd('Different punctuation in map DB',{addon='PFQUEST',questid=7441,cluster=true,texture='known-native-pin'});t.DoLayout();assert(readButtons()==20 and b[7441].title==e.pfDB.quests.loc[7441].T)
t.ButtonAdd('Twin Brothers',{addon='PFQUEST',questid=999999,texture='unrelated'});t.DoLayout();assert(readButtons()==20)
g.pfQuestEnv.this=b[twinB];g.pfQuestEnv.arg1='RightButton';t.ButtonClick();assert(selected==twinB)
-- Hard filters may omit a cached quest from the indexed array. Keep it only while confirmed active.
local hidden=rows[#rows];rows[#rows]=nil;ids[elite]=nil;q:UpdateQuestlog();t.Reset();t.DoLayout();assert(readButtons()==20 and q.questlog[elite].qlogid==nil)
active[elite]=nil;q:UpdateQuestlog();t.SyncQuestRows();t.DoLayout();assert(readButtons()==19 and not q.questlog[elite]);add(elite,hidden.title,hidden.level)
q:UpdateQuestlog();t.SyncQuestRows();t.DoLayout();assert(readButtons()==20)
-- No static map DB, map watch settings or transient objective cache miss may remove a quest.
for method=1,5 do e.pfQuest_config.trackingmethod=tostring(method);t.Reset();t.DoLayout();assert(readButtons()==20) end
objectives[trade]=nil;t.Reset();t.DoLayout();local _,now=readButtons();assert(now[trade].perc==0 and now[trade].icon.tex=='pfQuest\\img\\complete')
-- Dispatch the real 70334 event shapes through the installed frame adapter.
e.this=nil;e.arg1=nil
g.WorldMapFrame=frame('Frame');g.WorldMapFrame:Hide();g.MouseIsOver=function()return false end
widgets.SetFrameStrata=noop;widgets.GetAlpha=function()return 1 end
local fresh=990008;active[fresh]=true;g.C_QuestLog.GetTitleForQuestID=function(id)assert(id==fresh);return 'Filtered on acceptance' end
g.C_QuestLog.GetQuestDifficultyLevel=function(id)assert(id==fresh);return 25 end
t.scripts.OnEvent(t,'QUEST_ACCEPTED',fresh);t.scripts.OnUpdate(t,0.2);t.DoLayout();assert(readButtons()==21)
active[fresh]=nil;clock=11;t.scripts.OnEvent(t,'QUEST_REMOVED',fresh,false);t.scripts.OnUpdate(t,0.2);t.DoLayout();assert(readButtons()==20)
print('native dungeon / daily / profession objectives / duplicate IDs / filter / re-add / objective-cache miss / no unknown-ID map data: PASS')
return
end
e.pfDatabase={GetQuestIDs=function(_,i)return {rows[i].questID} end};loadModule('quest.lua');loadModule('tracker.lua');loadModule('slashcmd.lua')
local q,t=e.pfQuest,e.pfQuest.tracker
local function count(tbl) local n=0; for _ in pairs(tbl) do n=n+1 end; return n end
local function visible()
local keys={}; for _,button in ipairs(t.buttons) do if not button.empty and button:IsShown() then assert(not keys[button.title]);keys[button.title]=button end end;return keys
end
q:UpdateQuestlog();local cached=count(q.questlog);print('actual_cache',cached,'log_indices',#rows)
if not old then assert(cached==32 and q.questlog[4032].qlogid==48) end
for _,method in ipairs({'1','2','3','4','5'}) do
e.pfQuest_config.trackingmethod=method
for _,state in ipairs({false,true}) do
watch=state;q:UpdateQuestlog();t.Reset();t.DoLayout(); local seen=visible()
print('quest_rows',method,watch and 'mixed' or 'unwatched',count(seen))
if not old then
assert(count(seen)==32);for i=1,32 do assert(seen['Active '..i].questid==4000+i);assert(not not seen['Active '..i].tracked == (watch and i%2==0)) end
assert(seen['Active 32'].icon.tex=='pfQuest\\img\\complete_c')
end
baseline[method..tostring(watch)]=count(seen)
end
end
if old then assert(baseline['1false']==25 and baseline['2false']==0 and baseline['5true']==0) end
t:Hide();g.SlashCmdList.PFDB('tracker');assert(t:IsShown())
-- Collapsing the stock quest log must preserve accepted quests in the all-quests tracker.
if not old then
rows[1].isCollapsed=true;t.DoLayout();assert(count(visible())==32);rows[1].isCollapsed=false;t.DoLayout();assert(count(visible())==32)
end
for _,mode in ipairs({'DATABASE_TRACKING','GIVER_TRACKING'}) do
t.mode=mode;t.Reset()
for i=1,40 do
local node=mode=='DATABASE_TRACKING' and {addon='PFDB'} or {addon='PFQUEST',layer=1,questid=6000+i}
t.ButtonAdd('Result '..i,node)
end
t.DoLayout();local shown=count(visible());print('filtered_rows',mode,shown);assert(shown==25)
end
if not old then
t.mode='QUEST_TRACKING';t.Reset();t.DoLayout();assert(count(visible())==32)
for i=#rows,1,-1 do if rows[i].questID==4032 then table.remove(rows,i);break end end
q:UpdateQuestlog();t.Reset();t.DoLayout();assert(count(visible())==31 and not visible()['Active 32'])
end
print(old and 'prior behavior reproduced' or 'all tracker checks passed')