-- Runs ShipRoutes against a mock of the WoW map API. -- arg[1] = addon folder (ShipRoutes) local dir = arg[1] or "ShipRoutes" local failures = 0 local function check(cond, msg) if not cond then failures = failures + 1 io.write("FAIL: ", msg, "\n") end end -- world rects: top/bottom are world X, left/right world Y local RECTS = { [1415] = { inst = 0, top = 4000, bottom = -16000, left = 4000, right = -7000, type = 2 }, [1414] = { inst = 1, top = 10000, bottom = -12000, left = 5000, right = -8000, type = 2 }, [1437] = { inst = 0, top = -2000, bottom = -4500, left = 0, right = -3000, type = 3 }, -- "Wetlands" [2521] = { inst = 2991, top = 2500, bottom = 0, left = 1500, right = -1500, type = 3 }, } local ON_WORLD = { [1415] = { 0.55, 0.95, 0.1, 0.9 }, [1414] = { 0.05, 0.45, 0.1, 0.9 } } Enum = { UIMapType = { Cosmic = 0, World = 1, Continent = 2, Zone = 3 } } function CreateVector2D(x, y) return { x = x, y = y, GetXY = function(self) return self.x, self.y end } end C_Map = { GetMapInfo = function(id) if id == 947 then return { mapID = 947, mapType = 1 } end local r = RECTS[id] return r and { mapID = id, mapType = r.type } end, GetWorldPosFromMapPos = function(id, v) local r = RECTS[id] if not r then return nil end return r.inst, CreateVector2D(r.top + (r.bottom - r.top) * v.y, r.left + (r.right - r.left) * v.x) end, GetMapRectOnMap = function(id, top) local r = top == 947 and ON_WORLD[id] if r then return r[1], r[2], r[3], r[4] end end, GetMapInfoAtPosition = function(id, u, v) return { mapID = id * 10 } end, } function CreateFromMixins(...) local t = {} for i = 1, select("#", ...) do for k, v in pairs((select(i, ...))) do t[k] = v end end return t end MapCanvasDataProviderMixin = { OnAdded = function(self, map) self.owningMap = map end, GetMap = function(self) return self.owningMap end, } MapCanvasPinMixin = { UseFrameLevelType = function() end, SetScalingLimits = function() end, CheckMouseButtonPassthrough = function(self, b) self.passthrough = b end, GetMap = function(self) return self.map end, } local function region() local r = { shown = true } function r:Show() self.shown = true end function r:Hide() self.shown = false end function r:SetThickness(t) self.thickness = t end function r:SetColorTexture(cr, cg, cb, ca) self.color = { cr, cg, cb, ca } end function r:SetStartPoint(_, _, x, y) self.x1, self.y1 = x, y end function r:SetEndPoint(_, _, x, y) self.x2, self.y2 = x, y end function r:SetVertexColor(cr, cg, cb, ca) self.vertex = { cr, cg, cb, ca } end function r:SetTexture(p) self.texture = p end function r:SetRotation(a) self.rotation = a end return r end local eventFrame local allLines = {} function CreateFrame(kind, _, parent) local f = { scripts = {} } function f:RegisterEvent() end function f:SetScript(name, fn) self.scripts[name] = fn end function f:SetAllPoints() end function f:SetFrameLevel(l) self.level = l end function f:CreateLine(_, layer) local l = region() l.layer = layer allLines[#allLines + 1] = l return l end if not parent then eventFrame = f end return f end local canvas = { GetWidth = function() return 1000 end, GetHeight = function() return 700 end } local pins = {} local mapID = 1415 local shownMap WorldMapFrame = { AddDataProvider = function(self, p) p:OnAdded(self); self.provider = p end, GetCanvas = function() return canvas end, GetMapID = function() return mapID end, GetCanvasScale = function() return 2 end, GetPinFrameLevelsManager = function() return { GetValidFrameLevel = function() return 100 end } end, RemoveAllPinsByTemplate = function() pins = {} end, SetMapID = function(_, id) shownMap = id end, AcquirePin = function(self, template, ...) assert(template == "ShipRoutesPinTemplate") local pin = CreateFromMixins(ShipRoutesPinMixin) pin.map = self pin.Disc, pin.Ring, pin.Glyph = region(), region(), region() function pin:SetSize(w) self.size = w end function pin:SetPosition(u, v) self.u, self.v = u, v end pin:OnLoad() pin:OnAcquired(...) pins[#pins + 1] = pin return pin end, } local tipLines = {} GameTooltip = { SetOwner = function() tipLines = {} end, SetText = function(_, t) tipLines[#tipLines + 1] = t end, AddLine = function(_, t) tipLines[#tipLines + 1] = t end, Show = function() end, Hide = function() end, } local faction = "Alliance" function UnitFactionGroup() return faction end local realPrint = print local printed function print(msg) printed = msg end SlashCmdList = {} local ns = {} assert(loadfile(dir .. "/Data.lua"))("ShipRoutes", ns) assert(loadfile(dir .. "/ShipRoutes.lua"))("ShipRoutes", ns) eventFrame.scripts.OnEvent(eventFrame, "ADDON_LOADED", "ShipRoutes") local provider = WorldMapFrame.provider check(provider ~= nil, "provider attached to the world map") local function find(kind, name) for _, p in ipairs(pins) do if p.kind == kind then local stop = p.route.stops[p.index] if stop[1] == name then return p end end end end local function visibleLines() local n = 0 for _, l in ipairs(allLines) do if l.shown then n = n + 1 end end return n end -- the data itself check(#ns.routes == 12, "twelve routes, got " .. #ns.routes) for _, r in ipairs(ns.routes) do check(#r.stops >= 2, "route " .. r.path .. " has two or more stops") for _, p in ipairs(r.parts) do check(#p >= 4 and #p % 2 == 0, "route " .. r.path .. " part has coordinate pairs") end end -- projection: EK corner and centre local proj = ns.GetProjector(1415) local u, v = proj(0, 4000, 4000) check(math.abs(u) < 1e-9 and math.abs(v) < 1e-9, "top left projects to 0,0") u, v = proj(0, -6000, -1500) check(math.abs(u - 0.5) < 1e-9 and math.abs(v - 0.5) < 1e-9, "centre projects to 0.5,0.5") check(proj(1, 0, 0) == nil, "other instance does not project") -- Eastern Kingdoms provider:RefreshAllData() check(find("dock", "Stormwind Harbor") ~= nil, "Stormwind Harbor dock on EK") check(find("dock", "Southshore") ~= nil, "Southshore dock on EK") check(find("dock", "Theramore Isle") == nil, "no Kalimdor docks on EK") local exitToTheramore = find("exit", "Theramore Isle") check(exitToTheramore ~= nil, "exit arrow toward Theramore on EK") check(exitToTheramore and exitToTheramore.Glyph.rotation ~= nil, "exit arrow is rotated") check(visibleLines() > 50, "route lines drawn on EK, got " .. visibleLines()) check(provider.overlay.level == 100, "overlay frame level set") for _, l in ipairs(allLines) do if l.shown then check(math.abs(l.thickness - l.px / 2) < 1e-9, "line thickness divides by canvas scale") break end end -- tooltip at Menethil's Southshore pier local menethil for _, p in ipairs(pins) do if p.kind == "dock" and p.route.path == 11167 and p.route.stops[p.index][1] == "Menethil Harbor" then menethil = p end end check(menethil ~= nil, "Menethil pier of the Southshore boat") menethil:OnMouseEnter() local tip = table.concat(tipLines, "\n") check(tip:find("Boat to Southshore, then Auberdine", 1, true), "tooltip lists next stops in order:\n" .. tip) check(tip:find("Also from here:", 1, true) and tip:find("Boat to Theramore Isle", 1, true), "tooltip lists the other pier:\n" .. tip) check(provider.highlight == menethil.route, "hover highlights the route") local dim, bright = 0, 0 for _, l in ipairs(allLines) do if l.shown and l.layer == "ARTWORK" then if l.color[4] < 0.5 then dim = dim + 1 else bright = bright + 1 end end end check(dim > 0 and bright > 0, "other routes dim while one is highlighted") menethil:OnMouseLeave() check(provider.highlight == nil, "leaving clears the highlight") -- click opens the next stop's zone menethil:OnMouseClickAction("LeftButton") check(shownMap == 14150, "click shows Southshore's zone, got " .. tostring(shownMap)) shownMap = nil menethil:OnMouseClickAction("RightButton") check(shownMap == nil, "right click does nothing") check(menethil.passthrough == "RightButton", "right click passes through to the map") -- world map: both continents, jump connectors instead of exit arrows mapID = 947 provider:RefreshAllData() check(find("dock", "Theramore Isle") ~= nil and find("dock", "Menethil Harbor") ~= nil, "both continents on the world map") check(find("exit", "Theramore Isle") == nil, "no exit arrow when the far side shows") check(find("dock", "Zephras Isle") == nil, "Zephras Isle not placed on the mock world map") -- zone map: docks outside it are left out mapID = 1437 provider:RefreshAllData() check(find("dock", "Menethil Harbor") ~= nil, "Menethil on its zone map") check(find("dock", "Stormwind Harbor") == nil, "Stormwind not on the Wetlands map") -- faction filter faction = "Horde" mapID = 1415 SlashCmdList.SHIPROUTES("mine") check(find("dock", "Stormwind Harbor") == nil, "Alliance docks hidden for Horde with /routes mine") check(find("dock", "Grom'gol") ~= nil, "Horde docks kept") check(find("dock", "Booty Bay") ~= nil, "neutral docks kept") check(find("dock", "Dalaran") ~= nil, "unknown-faction docks kept") SlashCmdList.SHIPROUTES("all") check(find("dock", "Stormwind Harbor") ~= nil, "/routes all shows Alliance docks again") -- toggle SlashCmdList.SHIPROUTES("") check(#pins == 0 and visibleLines() == 0, "/routes hides everything") check(ShipRoutesDB.hidden == true, "hidden is saved") SlashCmdList.SHIPROUTES("") check(#pins > 0, "/routes shows it again") if failures > 0 then realPrint(failures .. " failure(s)") os.exit(1) end realPrint("ok")