Skip to content

Commit

Permalink
Test updates
Browse files Browse the repository at this point in the history
Happiness is often a rebound from hard work.
opussf committed Jun 8, 2024
1 parent f5c0166 commit 7c5bfe8
Showing 2 changed files with 107 additions and 23 deletions.
97 changes: 78 additions & 19 deletions test/wowStubs.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-----------------------------------------
-- Author : Opussf
-- Date : February 18 2024
-- Revision: 9.2
-- Date : May 15 2024
-- Revision: 9.4.3
-----------------------------------------
-- These are functions from wow that have been needed by addons so far
-- Not a complete list of the functions.
@@ -596,6 +596,7 @@ UIErrorsFrame={ ["AddMessage"] = function( self, msg )
{ ["msg"] = msg, ["chatType"] = "UIErrorsFrame", ["language"] = "", ["channel"] = "UIErrorsFrame" }
)
end, }
WeeklyRewardsFrame = CreateFrame()

-- stub some external API functions (try to keep alphabetical)
function BuyMerchantItem( index, quantity )
@@ -793,6 +794,10 @@ function GetAchievementNumCriteria( achievementID )
return #Achievements[achievementID]["criteria"]
end
end
function GetCurrentRegion()
-- @TODO: find region info
return 1
end
function GetSpecialization()
return 2
end
@@ -1133,6 +1138,10 @@ function GetPlayerInfoByGUID( playerGUID )
-- localClass, englishClass, localRace, englishRace, gender, name, realm = GetPlayerInfoByGUID( playerGUID )
return "Warlock", "Warlock", "Human", "Human", 3, "testPlayer", "testRealm"
end
function GetQuestResetTime()
-- @TODO: Find out more about this
return 5
end
function GetRaidRosterInfo( raidIndex )
-- http://www.wowwiki.com/API_GetRaidRosterInfo
-- returns name, rank, subgroup, level, class, fileName, zone, online, isDead, role, isML
@@ -1218,9 +1227,14 @@ function GetUnitSpeed( lookupStr )
end
--[[
function HasNewMail()
-- @TODO: Research this
return true
end
]]
function GetWeeklyQuestResetTime()
-- @TODO: Research this
return 15
end
function GetXPExhaustion()
-- TODO:
return 3618
@@ -1693,32 +1707,65 @@ end
----------
-- Macros
----------
myMacros = {} -- ["macroName"] = { ["icon"] = "", ["text"] = "", ["isLocal"] = true }
myMacros = {
["general"] = {}, -- [1] = { ["name"] = "", ["icon"] = "", ["text"] = "" } 1-120 = general
["personal"] = {}, -- 1-18 = personal (+120)
["sort"] = function()
table.sort( myMacros.general, function( l, r ) return( l.name < r.name ); end )
table.sort( myMacros.personal, function( l, r ) return( l.name < r.name ); end )
end,
}
function GetMacroInfo( macroName )
-- returns: macroName, macroIcon, macroText, isLocal (bool)
if myMacros[macroName] then
return macroName, myMacros[macroName][icon], myMacros[macroName][text], myMacros[macroName][isLocal] or false
-- returns: macroName, macroIcon, macroText
if macroName then
local mIndex = GetMacroIndexByName( macroName )
if mIndex ~= 0 then
local location = mIndex > 120 and "personal" or "general"
mIndex = mIndex>120 and mIndex-120 or mIndex
return myMacros[location][mIndex].name, myMacros[location][mIndex].icon, myMacros[location][mIndex].text
end
end
end
function GetMacroIndexByName( macroName )
-- returns index, or 0 if not found (seems to go from highest to lowest - person to general )
for index = 18, 1, -1 do
if myMacros.personal[index] and myMacros.personal[index].name == macroName then
return index+120
end
end
for index = 120, 1, -1 do
if myMacros.general[index] and myMacros.general[index].name == macroName then
return index
end
end
return 0
end
function CreateMacro( macroName, macroIcon, macroText, perChar )
-- returns: macroID
if macroName and not myMacros[macroName] then
myMacros[macroName] = { ["icon"] = macroIcon, ["text"] = macroText }
return 1 -- return the ID
if macroName then
local mIndex = GetMacroIndexByName( macroName )
if mIndex == 0 then
local location = perChar and "personal" or "general"
table.insert( myMacros[location], { ["name"] = macroName, ["icon"] = macroIcon, ["text"] = macroText } )
myMacros.sort()
return( GetMacroIndexByName( macroName ) ) -- return the ID
end
end
end
function EditMacto( macroName, newName, newIcon, body, islocal, perChar )
function EditMacro( macroName, newName, newIcon, body )
-- macroName is name or index
-- returns: new macroID
if macroName and myMacros[macroName] then
if newName then
myMacros[newName] = myMacros[macroName]
macroName = newName
if macroName then
mIndex = tonumber(macroName) or GetMacroIndexByName( macroName )
if mIndex ~= 0 then
local location = mIndex > 120 and "personal" or "general"
mIndex = mIndex>120 and mIndex-120 or mIndex
myMacros[location][mIndex].name = newName or myMacros[location][mIndex].name
myMacros[location][mIndex].icon = newIcon or myMacros[location][mIndex].icon
myMacros[location][mIndex].text = body or myMacros[location][mIndex].text
myMacros.sort()
return( GetMacroIndexByName( macroName ) ) -- return the ID
end
if newIcon then
myMacros[macroName].icon = newIcon
end
myMacros[macroName].text = body
return 1 -- return the ID
end
end

@@ -1735,6 +1782,18 @@ function C_ChatInfo.SendAddonMessage()
return true
end

----------
-- Toy info
----------
toyList = {} -- [id] = {true | false}
C_ToyBox = {}
function PlayerHasToy( id )
return toyList[id]
end
function C_ToyBox.IsToyUsable( id )
return toyList[id] and toyList[id][1]
end

-- A SAX parser takes a content handler, which provides these methods:
-- startDocument() -- called at the start of the Document
-- endDocument() -- called at the end of the Document
33 changes: 29 additions & 4 deletions test/wowTest.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-----------------------------------------
-- Author : Opussf
-- Date : February 18 2024
-- Revision: 9.2
-- Date : May 15 2024
-- Revision: 9.4.3
-----------------------------------------
-- This is an uber simple unit test implementation
-- It creates a dictionary called test.
@@ -78,7 +78,32 @@ function test.PairsByKeys( t, f ) -- This is an awesome function I found
end
return iter
end

function test.EscapeStr( strIn )
-- This escapes a str
strIn = string.gsub( strIn, "\\", "\\\\" )
strIn = string.gsub( strIn, "\"", "\\\"" )
return strIn
end
function test.dump( tableIn, depth )
depth = depth or 1
for k, v in test.PairsByKeys( tableIn ) do
io.write( ("%s[\"%s\"] = "):format( string.rep("\t", depth), k ) )
if ( type( v ) == "boolean" ) then
io.write( v and "true" or "false" )
elseif ( type( v ) == "table" ) then
io.write( "{\n" )
test.dump( v, depth+1 )
io.write( ("%s}"):format( string.rep("\t", depth) ) )
elseif ( type( v ) == "string" ) then
io.write( "\""..test.EscapeStr( v ).."\"" )
elseif ( type( v ) == "function" ) then
io.write( "function()" )
else
io.write( v )
end
io.write( ",\n" )
end
end
function test.toXML()
if test.outFileName then
local f = assert( io.open( test.outFileName, "w"))
@@ -116,7 +141,7 @@ function test.toCobertura()
table.insert( coberturaTable, "<packages>" )
table.insert( coberturaTable, "<package name='' line-rate='1' branch-rate='0' complexity='0'>" )
table.insert( coberturaTable, "<classes>" )
for file, lines in pairs( test.coverage ) do
for file, lines in test.PairsByKeys( test.coverage ) do
table.insert( coberturaTable, "<class name='' filename='"..file.."' line-rate='0' branch-rate='0' complexity='0'>" )
table.insert( coberturaTable, "<methods/>" )
table.insert( coberturaTable, "<lines>" )

0 comments on commit 7c5bfe8

Please sign in to comment.