local bundle = assert(arg[1]) local tests = 0 local function check(ok, message) assert(ok, message); tests = tests + 1 end local function newClient(savedRuen, savedGun) local e = setmetatable({}, {__index = _G}) e._G = e e.RuenUIDB = savedRuen or {} e.GunSilencerForeverDB = savedGun e.SlashCmdList = {} e.UIParent, e.WorldFrame = {}, {} e.frames, e.muted, e.played, e.messages = {}, {}, {}, {} e.weaponSubclass, e.item = 3, 12345 e.locale = 'enUS' e.print = function(message) e.messages[#e.messages+1] = message end e.issecretvalue = function(value) return type(value) == 'table' and value.secret == true end e.CreateFrame = function(kind, name, parent, template) local f = {events = {}, scripts = {}} function f:RegisterEvent(event) self.events[event] = true end function f:RegisterUnitEvent(event, unit) self.events[event] = unit end function f:SetScript(script, callback) self.scripts[script] = callback end function f:SetOwner() end function f:SetInventoryItem() end function f:Hide() end e.frames[#e.frames+1] = f return f end e.GetInventoryItemID = function(unit, slot) check(slot == 18, 'use ranged equipment slot'); return e.item end e.C_Item = {GetItemInfoInstant = function() return nil,nil,nil,nil,nil,2,e.weaponSubclass end} e.C_EventUtils = {IsEventValid = function() return true end} e.C_Timer = {After = function(delay, callback) check(delay == 0.5 or delay == 2 or delay == 5, 'bounded appearance refresh only') end} e.C_Spell = {GetSpellInfo = function(id) if id == 75 then return {name=e.locale == 'ruRU' and 'Автоматическая стрельба' or 'Auto Shot'} end if id == 3044 or id == 14281 then return {name='Arcane Shot'} end if id == 999 then return {name='Other spell'} end return nil end} e.MuteSoundFile = function(id) e.muted[id] = true end e.UnmuteSoundFile = function(id) e.muted[id] = nil end e.PlaySoundFile = function(path, channel) e.played[#e.played+1] = {path=path,channel=channel} return not e.failPlayback end local upstream = assert(loadfile(bundle..'/GunSilencerForever/GunSilencerForever.lua')) setfenv(upstream,e);upstream('GunSilencerForever') e.event = function(event,...) for _, f in ipairs(e.frames) do if f.events[event] then f.scripts.OnEvent(f,event,...) end end end e.event('ADDON_LOADED','GunSilencerForever') e.P = {Localized=function(en,ru) return e.locale == 'ruRU' and ru or en end} local bridge=assert(loadfile(bundle..'/RuenUI/GunAudio.lua')) setfenv(bridge,e);bridge('RuenUI',e.P) return e end local e=newClient() check(e.P.InitializeGunAudio(), 'first-time setup succeeds') check(e.GunSilencerForeverDB.enabled and e.GunSilencerForeverDB.guns, 'guns enabled') check(e.GunSilencerForeverDB.volume==100, 'audible starting volume') check(not e.GunSilencerForeverDB.muteBowDraw, 'bow draw preserved') for _,id in ipairs({567721,567718,567722}) do check(e.muted[id], 'original gunshot muted') end for _,id in ipairs({567677,567675,567676,567719,567720,567723}) do check(not e.muted[id], 'bows and gun reload untouched') end for _,f in ipairs(e.frames) do check(not f.scripts.OnUpdate, 'no frame polling');check(not f.events.COMBAT_LOG_EVENT_UNFILTERED,'no restricted combat log') end e.event('UNIT_SPELLCAST_SUCCEEDED','player','shot-1',75) check(#e.played==1 and e.played[1].path:match('Shot_100.ogg$') and e.played[1].channel=='SFX','audible replacement on SFX') e.event('UNIT_SPELLCAST_SUCCEEDED','player','shot-1',75) check(#e.played==1,'duplicate cast suppressed') e.event('UNIT_SPELLCAST_SUCCEEDED','pet','pet-1',75) e.event('UNIT_SPELLCAST_SUCCEEDED','player','other-1',999) e.event('UNIT_SPELLCAST_SUCCEEDED','player','secret-1',{secret=true}) check(#e.played==1,'non-player, non-shot, secret casts ignored') e.P.GunAudioCommand('40');check(e.GunSilencerForeverDB.volume==40,'volume command') e.P.GunAudioCommand('volume 65');check(e.GunSilencerForeverDB.volume==70,'rounded volume command') check(e.P.GunAudioCommand('0')~=nil and e.GunSilencerForeverDB.volume==70,'reject accidental mute') e.P.GunAudioCommand('off');check(not next(e.muted),'off restores all original audio') e.event('UNIT_SPELLCAST_SUCCEEDED','player','off-1',75);check(#e.played==1,'off does not replay') e.P.InitializeGunAudio();check(not e.GunSilencerForeverDB.enabled,'setup does not override user toggle') local reloaded=newClient(e.RuenUIDB,e.GunSilencerForeverDB) reloaded.P.InitializeGunAudio();check(not next(reloaded.muted) and reloaded.GunSilencerForeverDB.volume==70,'reload preserves off and volume') e.P.GunAudioCommand('on');check(e.GunSilencerForeverDB.enabled and e.GunSilencerForeverDB.volume==70 and not e.GunSilencerForeverDB.muteBowDraw,'on keeps volume and original bow draw') e.event('UNIT_SPELLCAST_SUCCEEDED','player','rank-1',14281);check(#e.played==2,'other spell ranks recognized') for _,subclass in ipairs({2,18,19,0}) do e.weaponSubclass=subclass;e.event('PLAYER_EQUIPMENT_CHANGED',18) e.event('UNIT_SPELLCAST_SUCCEEDED','player','non-gun-'..subclass,75) check(#e.played==2,'bows/crossbows/wands/melee receive no rifle replacement') end e.weaponSubclass=3;e.locale='ruRU';e.event('PLAYER_ENTERING_WORLD') e.event('UNIT_SPELLCAST_SUCCEEDED','player','ru-1',75);check(#e.played==3,'localized Auto Shot recognized') e.failPlayback=true;e.event('UNIT_SPELLCAST_SUCCEEDED','player','bad-file',75) check(not next(e.muted),'failed playback restores originals') e.failPlayback=false;e.P.GunAudioCommand('on');check(e.muted[567721],'on retries failed playback') e.P.StopGunAudio();check(not next(e.muted),'ruen restore restores native audio') local disabled=newClient({disabled=true});disabled.P.InitializeGunAudio() check(not next(disabled.muted),'disabled Ruen does not introduce sound changes') local missing=newClient();missing.GunSilencerForeverDB=nil check(not missing.P.InitializeGunAudio(),'missing dependency leaves Ruen available') check(missing.P.GunAudioCommand('on'):find('Fully exit WoW',1,true),'missing addon gives restart instructions') print('PASS: '..tests..' checks (actual upstream addon and Ruen bridge, Lua 5.1).')