|
| 1 | +--[[ |
| 2 | +LibPlayerSpells-1.0 - Additional information about player spells. |
| 3 | +(c) 2013-2014 Adirelle ([email protected]) |
| 4 | +
|
| 5 | +This file is part of LibPlayerSpells-1.0. |
| 6 | +
|
| 7 | +LibPlayerSpells-1.0 is free software: you can redistribute it and/or modify |
| 8 | +it under the terms of the GNU General Public License as published by |
| 9 | +the Free Software Foundation, either version 3 of the License, or |
| 10 | +(at your option) any later version. |
| 11 | +
|
| 12 | +LibPlayerSpells-1.0 is distributed in the hope that it will be useful, |
| 13 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +GNU General Public License for more details. |
| 16 | +
|
| 17 | +You should have received a copy of the GNU General Public License |
| 18 | +along with LibPlayerSpells-1.0. If not, see <http://www.gnu.org/licenses/>. |
| 19 | +--]] |
| 20 | + |
| 21 | +package.path = package.path .. ";./wowmock/?.lua" |
| 22 | +local LuaUnit = require('luaunit') |
| 23 | +local mockagne = require('mockagne') |
| 24 | +local wowmock = require('wowmock') |
| 25 | +local bit = require('bit') |
| 26 | + |
| 27 | +local when, any, verify = mockagne.when, mockagne.any, mockagne.verify |
| 28 | + |
| 29 | +local lib, G |
| 30 | + |
| 31 | +LibStub = false |
| 32 | + |
| 33 | +local function setup() |
| 34 | + G = mockagne:getMock() |
| 35 | + lib = wowmock("../LibPlayerSpells-1.0.lua", G) |
| 36 | +end |
| 37 | + |
| 38 | +testRegisterSpells = { setup = setup } |
| 39 | + |
| 40 | +-- lib:__RegisterSpells(category, interface, minor, newSpells, newProviders, newModifiers) |
| 41 | + |
| 42 | +function testRegisterSpells:test_unknown_category() |
| 43 | + assertEquals(pcall(lib.__RegisterSpells, lib, "foobar", 0, 0, {}), false) |
| 44 | +end |
| 45 | + |
| 46 | +function testRegisterSpells:test_new_data() |
| 47 | + lib:__RegisterSpells("HUNTER", 50000, 1, {}) |
| 48 | + local _, patch, rev = lib:GetVersionInfo("HUNTER") |
| 49 | + assertEquals(patch, 50000) |
| 50 | + assertEquals(rev, 1) |
| 51 | +end |
| 52 | + |
| 53 | +function testRegisterSpells:test_newer_revision() |
| 54 | + lib:__RegisterSpells("HUNTER", 50000, 1, {}) |
| 55 | + lib:__RegisterSpells("HUNTER", 50000, 2, {}) |
| 56 | + local _, patch, rev = lib:GetVersionInfo("HUNTER") |
| 57 | + assertEquals(patch, 50000) |
| 58 | + assertEquals(rev, 2) |
| 59 | +end |
| 60 | + |
| 61 | +function testRegisterSpells:test_newer_patch() |
| 62 | + lib:__RegisterSpells("HUNTER", 50000, 1, {}) |
| 63 | + lib:__RegisterSpells("HUNTER", 60000, 1, {}) |
| 64 | + local _, patch, rev = lib:GetVersionInfo("HUNTER") |
| 65 | + assertEquals(patch, 60000) |
| 66 | + assertEquals(rev, 1) |
| 67 | +end |
| 68 | + |
| 69 | +function testRegisterSpells:test_older_patch() |
| 70 | + lib:__RegisterSpells("HUNTER", 60000, 1, {}) |
| 71 | + lib:__RegisterSpells("HUNTER", 50000, 2, {}) |
| 72 | + local _, patch, rev = lib:GetVersionInfo("HUNTER") |
| 73 | + assertEquals(patch, 60000) |
| 74 | + assertEquals(rev, 1) |
| 75 | +end |
| 76 | + |
| 77 | +function testRegisterSpells:test_older_revision() |
| 78 | + lib:__RegisterSpells("HUNTER", 50000, 2, {}) |
| 79 | + lib:__RegisterSpells("HUNTER", 50000, 1, {}) |
| 80 | + local _, patch, rev = lib:GetVersionInfo("HUNTER") |
| 81 | + assertEquals(patch, 50000) |
| 82 | + assertEquals(rev, 2) |
| 83 | +end |
| 84 | + |
| 85 | +function testRegisterSpells:test_provider_inconsistency() |
| 86 | + local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, {}, {[5] = 6}) |
| 87 | + assertEquals(success, false) |
| 88 | +end |
| 89 | + |
| 90 | +function testRegisterSpells:test_modifier_inconsistency() |
| 91 | + local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, {}, {}, {[5] = 6}) |
| 92 | + assertEquals(success, false) |
| 93 | +end |
| 94 | + |
| 95 | +function testRegisterSpells:test_consistent_data() |
| 96 | + when(G.GetSpellLink(any())).thenAnswer("link") |
| 97 | + lib:__RegisterSpells("HUNTER", 1, 1, {[4] = "AURA", [5] = "AURA"}, {[4] = 8}, {[5] = 6}) |
| 98 | +end |
| 99 | + |
| 100 | +function testRegisterSpells:test_unknown_flag() |
| 101 | + local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, {[4] = "FOO"}) |
| 102 | + assertEquals(success, false) |
| 103 | +end |
| 104 | + |
| 105 | +function testRegisterSpells:test_unknown_spell() |
| 106 | + when(G.GetSpellLink(4)).thenAnswer(false) |
| 107 | + local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, { [4] = "AURA" }) |
| 108 | + assertEquals(success, false) |
| 109 | + verify(G.GetSpellLink(4)) |
| 110 | +end |
| 111 | + |
| 112 | +function testRegisterSpells:test_known_spell() |
| 113 | + when(G.GetSpellLink(4)).thenAnswer("link") |
| 114 | + lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "AURA" }) |
| 115 | + verify(G.GetSpellLink(4)) |
| 116 | +end |
| 117 | + |
| 118 | +function testRegisterSpells:test_key_id_value_flag() |
| 119 | + when(G.GetSpellLink(4)).thenAnswer("link") |
| 120 | + lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "AURA" }) |
| 121 | + assertEquals(lib.__categories.HUNTER[4], bit.bor(lib.constants.AURA, lib.constants.HUNTER)) |
| 122 | +end |
| 123 | + |
| 124 | +function testRegisterSpells:test_spell_list() |
| 125 | + when(G.GetSpellLink(any())).thenAnswer("link") |
| 126 | + lib:__RegisterSpells("HUNTER", 1, 1, { AURA = { 4, 5 } }) |
| 127 | + local db, c, bor = lib.__categories.HUNTER, lib.constants, bit.bor |
| 128 | + assertEquals(db[4], bor(c.AURA, c.HUNTER)) |
| 129 | + assertEquals(db[5], bor(c.AURA, c.HUNTER)) |
| 130 | +end |
| 131 | + |
| 132 | +function testRegisterSpells:test_nested() |
| 133 | + when(G.GetSpellLink(any())).thenAnswer("link") |
| 134 | + lib:__RegisterSpells("HUNTER", 1, 1, { |
| 135 | + AURA = { |
| 136 | + 4, |
| 137 | + [5] = "HARMFUL", |
| 138 | + HELPFUL = { |
| 139 | + 6, |
| 140 | + [7] = "COOLDOWN" |
| 141 | + } |
| 142 | + } |
| 143 | + }) |
| 144 | + local db, c, bor = lib.__categories.HUNTER, lib.constants, bit.bor |
| 145 | + assertEquals(db[4], bor(c.AURA, c.HUNTER)) |
| 146 | + assertEquals(db[5], bor(c.AURA, c.HUNTER, c.HARMFUL)) |
| 147 | + assertEquals(db[6], bor(c.AURA, c.HUNTER, c.HELPFUL)) |
| 148 | + assertEquals(db[7], bor(c.AURA, c.HUNTER, c.HELPFUL, c.COOLDOWN)) |
| 149 | +end |
| 150 | + |
| 151 | +function testRegisterSpells:test_multipart_string() |
| 152 | + when(G.GetSpellLink(4)).thenAnswer("link") |
| 153 | + lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "HELPFUL AURA" }) |
| 154 | + local db, c, bor = lib.__categories.HUNTER, lib.constants, bit.bor |
| 155 | + assertEquals(db[4], bor(c.AURA, c.HELPFUL, c.HUNTER)) |
| 156 | +end |
| 157 | + |
| 158 | +function testRegisterSpells:test_invalid_data() |
| 159 | + local success, msg = pcall(lib.__RegisterSpells, lib, "HUNTER", 1, 1, { [4] = function() end }) |
| 160 | + assertEquals(success, false) |
| 161 | +end |
| 162 | + |
| 163 | +function testRegisterSpells:test_database_conflict() |
| 164 | + when(G.GetSpellLink(4)).thenAnswer("link") |
| 165 | + lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "AURA" }) |
| 166 | + local success, msg = pcall(lib.__RegisterSpells, lib, "SHAMAN", 1, 1, { [4] = "HELPFUL" }) |
| 167 | + assertEquals(success, false) |
| 168 | +end |
| 169 | + |
| 170 | +--[[ Ignored until I figure out how to workaround the luabitop issue with 0x8000000 |
| 171 | +function testRegisterSpells:test_raidbuff() |
| 172 | + when(G.GetSpellLink(any())).thenAnswer("link") |
| 173 | + lib:__RegisterSpells("HUNTER", 1, 1, { [4] = "RAIDBUFF STAMINA" }) |
| 174 | + local c, bor = lib.constants, bit.bor |
| 175 | + assertEquals(lib.__specials.RAIDBUFF[4], c.STAMINA) |
| 176 | + assertEquals(lib.__categories.HUNTER[4], bor(c.HELPFUL, c.UNIQUE_AURA, c.AURA, c.HUNTER)) |
| 177 | +end |
| 178 | +]] |
| 179 | + |
| 180 | +os.exit(LuaUnit:Run()) |
0 commit comments