62 lines
2.2 KiB
Lua
62 lines
2.2 KiB
Lua
local path = assert(arg[1])
|
|
local name = "cooldownViewerEnabled"
|
|
local value, swing, fail, writes, reads
|
|
local frame
|
|
function CreateFrame(kind, id)
|
|
assert(kind == "Frame" and id == nil)
|
|
frame = {}
|
|
function frame:RegisterEvent(event) assert(event == "PLAYER_LOGIN"); self.event = event end
|
|
function frame:UnregisterEvent(event) assert(self.event == event); self.event = nil end
|
|
function frame:SetScript(event, callback) assert(event == "OnEvent"); self.callback = callback end
|
|
return frame
|
|
end
|
|
C_CVar = {}
|
|
function C_CVar.GetCVar(key)
|
|
assert(key == name, "Addon read another CVar")
|
|
reads = reads + 1
|
|
return value
|
|
end
|
|
function C_CVar.SetCVar(key, setting)
|
|
assert(key == name and setting == "0", "Addon wrote another setting")
|
|
writes = writes + 1
|
|
if fail then return false end
|
|
value = setting
|
|
return true
|
|
end
|
|
local function login()
|
|
assert(loadfile(path))()
|
|
assert(frame.event == "PLAYER_LOGIN")
|
|
frame.callback(frame,frame.event)
|
|
assert(frame.event == nil)
|
|
end
|
|
for _, swingValue in ipairs({"0","1"}) do
|
|
swing = swingValue
|
|
reads,writes,value,fail = 0,0,"1",false
|
|
WoWHybridCooldownViewerDefaultApplied = nil
|
|
login()
|
|
assert(reads == 1 and writes == 1 and value == "0" and WoWHybridCooldownViewerDefaultApplied == true)
|
|
value = "1"
|
|
login()
|
|
assert(reads == 1 and writes == 1 and value == "1" and swing == swingValue)
|
|
print("PASS first login and player opt-in after reload, swing setting "..swingValue)
|
|
end
|
|
reads,writes,value = 0,0,"0"
|
|
WoWHybridCooldownViewerDefaultApplied = nil
|
|
login()
|
|
assert(writes == 0 and WoWHybridCooldownViewerDefaultApplied)
|
|
value = "1"
|
|
login()
|
|
assert(value == "1" and reads == 1 and writes == 0)
|
|
print("PASS initially disabled, later opt-in retained")
|
|
reads,writes,value = 0,0,nil
|
|
WoWHybridCooldownViewerDefaultApplied = nil
|
|
login()
|
|
assert(reads == 1 and writes == 0 and not WoWHybridCooldownViewerDefaultApplied)
|
|
value,fail = "1",true
|
|
login()
|
|
assert(reads == 2 and writes == 1 and value == "1" and not WoWHybridCooldownViewerDefaultApplied)
|
|
fail = false
|
|
login()
|
|
assert(reads == 3 and writes == 2 and value == "0" and WoWHybridCooldownViewerDefaultApplied)
|
|
print("PASS unknown setting and rejected write remain retryable")
|