- don't leak globals, libs should return metatable - fix requires - remove unnecessary declarations of variables - split mocks/sr - remove unused tests - fix tests Change-Id: I2bda46410cf62c61c38ce1a9bf4b96f1a7a961bcchanges/68/1268/7
parent
eb0c0d9c31
commit
51a8be0b69
@ -0,0 +1,2 @@
|
||||
globals = {'sr', '_ENV'}
|
||||
ignore = { '212' }
|
@ -0,0 +1,98 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
|
||||
local logging = require('logging')
|
||||
local log_file = require('logging.file')
|
||||
|
||||
local hdrMock = {
|
||||
__class__ = 'hdrMock',
|
||||
headers = {},
|
||||
headers_reply = {},
|
||||
_logger = log_file('reports/sr_hdr_%s.log', '%Y-%m-%d'),
|
||||
_logger_levels = {
|
||||
dbg = logging.DEBUG,
|
||||
info = logging.INFO,
|
||||
warn = logging.WARN,
|
||||
err = logging.ERROR,
|
||||
crit = logging.FATAL
|
||||
}
|
||||
}
|
||||
function hdrMock.new()
|
||||
local t = {}
|
||||
|
||||
t.__class__ = 'hdrMock'
|
||||
t.headers = {}
|
||||
t.headers_reply = {}
|
||||
|
||||
function t._is_header(text)
|
||||
local result = string.match(text,'[^:]+: .+\r\n$')
|
||||
if result then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function t._get_header(text)
|
||||
if text then
|
||||
local pattern = "^" .. text .. ": (.+)\r\n$"
|
||||
for _,v in ipairs(t.headers) do
|
||||
local result = string.match(v, pattern)
|
||||
--print(string.format("v:%s pattern:%s result:%s", v, pattern, tostring(result)))
|
||||
if result then
|
||||
return result
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function t.append(text)
|
||||
if text then
|
||||
if not t._is_header(text) then
|
||||
error("text: " .. text .. " malformed header")
|
||||
end
|
||||
table.insert(t.headers, text)
|
||||
end
|
||||
end
|
||||
|
||||
function t.insert(text)
|
||||
if text then
|
||||
if not t._is_header(text) then
|
||||
error("text: " .. text .. " malformed header")
|
||||
end
|
||||
table.insert(t.headers, 1, text)
|
||||
end
|
||||
end
|
||||
|
||||
function t.remove(text)
|
||||
if text then
|
||||
for i,v in ipairs(t.headers) do
|
||||
if string.starts(v, text .. ":") then
|
||||
table.remove(t.headers, i)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local hdrMock_MT = { __index = hdrMock }
|
||||
setmetatable(t, hdrMock_MT)
|
||||
return t
|
||||
end
|
||||
-- end class
|
||||
return hdrMock
|
@ -0,0 +1,381 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
|
||||
local logging = require ('logging')
|
||||
local log_file = require ('logging.file')
|
||||
local utils = require 'ngcp.utils'
|
||||
local utable = utils.table
|
||||
|
||||
local pvMock = {
|
||||
__class__ = 'pvMock',
|
||||
vars = {},
|
||||
hdr = nil,
|
||||
_logger = log_file('reports/sr_pv_%s.log', '%Y-%m-%d'),
|
||||
_logger_levels = {
|
||||
dbg = logging.DEBUG,
|
||||
info = logging.INFO,
|
||||
warn = logging.WARN,
|
||||
err = logging.ERROR,
|
||||
crit = logging.FATAL
|
||||
}
|
||||
}
|
||||
function pvMock.new(hdr)
|
||||
local t = {}
|
||||
|
||||
t.__class__ = 'pvMock'
|
||||
-- fake pseudo vars go here
|
||||
t.vars_pv = {
|
||||
ro = {
|
||||
si = "127.0.0.1",
|
||||
sp = "9090"
|
||||
},
|
||||
rw = {
|
||||
rU = "noname"
|
||||
}
|
||||
}
|
||||
t.vars = {}
|
||||
t.hdr = hdr
|
||||
|
||||
function t._is_xavp(id)
|
||||
local patterns = {
|
||||
'%$xavp%(([%w_^%[]+)%)$',
|
||||
'%$xavp%(([%w_^%[]+)%[(%d+)%]%)$',
|
||||
'%$xavp%(([%w_^%[]+)=>([%w_^%[]+)%)$',
|
||||
'%$xavp%(([%w_^%[]+)%[(%d+)%]=>([%w_^%[]+)%)$',
|
||||
'%$xavp%(([%w_^%[]+)=>([%w_^%[]+)%[(%d+)%]%)$',
|
||||
'%$xavp%(([%w_^%[]+)%[(%d+)%]=>([%w_^%[]+)%[(%d+)%]%)$',
|
||||
'%$xavp%(([%w_^%[]+)%[(%d+)%]=>([%w_^%[]+)%[%*%]%)$'
|
||||
}
|
||||
local logger = logging.file('reports/sr_pv_%s.log', '%Y-%m-%d')
|
||||
for _,v in pairs(patterns) do
|
||||
for _id, indx, key, kindx in string.gmatch(id, v) do
|
||||
logger:log(logging.DEBUG, string.format("_:%d id:%s v:%s _id:%s indx:%s key:%s kindx:%s", _, id, v, tostring(_id), tostring(indx), tostring(key), tostring(kindx)))
|
||||
if _ == 5 or _ == 3 then
|
||||
kindx = key
|
||||
key = indx
|
||||
indx = nil
|
||||
else
|
||||
indx = tonumber(indx)
|
||||
end
|
||||
if kindx then
|
||||
kindx = tonumber(kindx)
|
||||
end
|
||||
return { id=_id, key=key,
|
||||
indx=indx, kindx=kindx, clean=(v==patterns[7]),
|
||||
type='xavp' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function t._clean_id(id)
|
||||
local k
|
||||
k = string.gsub(id, 's:', '')
|
||||
k = string.gsub(k, 'i:', '')
|
||||
return k
|
||||
end
|
||||
|
||||
function t._is_avp(id)
|
||||
local _id
|
||||
local patterns = {
|
||||
'%$avp%(([%w_]+)%)$',
|
||||
'%$%(avp%(([%w_]+)%)%)$',
|
||||
'%$%(avp%(([%w_]+)%)%[%*%]%)$'
|
||||
}
|
||||
_id = t._clean_id(id)
|
||||
for _,v in pairs(patterns) do
|
||||
for i in string.gmatch(_id, v) do
|
||||
return { id=i, clean=(v==patterns[3]), type='avp' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function t._is_var(id)
|
||||
local patterns = {
|
||||
'%$var%(([%w_]+)%)$',
|
||||
'%$%(var%(([%w_]+)%)%)$',
|
||||
}
|
||||
for _,v in pairs(patterns) do
|
||||
for key in string.gmatch(id, v) do
|
||||
return { id=key, clean=false, type='var' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function t._is_dlg_var(id)
|
||||
local patterns = {
|
||||
'%$dlg_var%(([%w_]+)%)$',
|
||||
'%$%(dlg_var%(([%w_]+)%)%)$',
|
||||
}
|
||||
for _,v in pairs(patterns) do
|
||||
for key in string.gmatch(id, v) do
|
||||
return { id=key, clean=false, type='dlg_var' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function t._is_hdr(id)
|
||||
local patterns = {
|
||||
'%$hdr%(([^:]+)%)$',
|
||||
}
|
||||
for _,v in pairs(patterns) do
|
||||
for key in string.gmatch(id, v) do
|
||||
return { id=key, clean=false, type='hdr' }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function t._is_pv(id)
|
||||
local real_id = string.match(id, '%$(%w+)$')
|
||||
if not real_id then
|
||||
return
|
||||
end
|
||||
for k,_ in pairs(t.vars_pv) do
|
||||
for k0,_ in pairs(t.vars_pv[k]) do
|
||||
--print(string.format("id:%s, k:%s k0:%s", real_id, k, k0))
|
||||
if real_id == k0 then
|
||||
return { id=k0, clean=false, type='pv', mode=k}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function t._is(id)
|
||||
if not id then
|
||||
error("id empty")
|
||||
end
|
||||
local result = t._is_xavp(id)
|
||||
|
||||
if not result then
|
||||
result = t._is_avp(id)
|
||||
end
|
||||
if not result then
|
||||
result = t._is_var(id)
|
||||
end
|
||||
if not result then
|
||||
result = t._is_dlg_var(id)
|
||||
end
|
||||
if not result then
|
||||
result = t._is_hdr(id)
|
||||
end
|
||||
if not result then
|
||||
result = t._is_pv(id)
|
||||
end
|
||||
if not result then
|
||||
error(string.format("not implemented or wrong id:%s", id))
|
||||
end
|
||||
result.private_id = result.type .. ':' .. result.id
|
||||
return result
|
||||
end
|
||||
|
||||
function t.get(id)
|
||||
local result = t._is(id)
|
||||
if not result then
|
||||
return
|
||||
end
|
||||
|
||||
if result.type == 'var' or result.type == 'dlg_var' then
|
||||
return t.vars[result.private_id]
|
||||
elseif result.type == 'xavp' then
|
||||
if not t.vars[result.private_id] then
|
||||
return
|
||||
end
|
||||
if not result.kindx then
|
||||
result.kindx = 0
|
||||
end
|
||||
if not result.key then
|
||||
if not result.indx then
|
||||
return t.vars[result.private_id]
|
||||
end
|
||||
end
|
||||
if not result.indx then
|
||||
result.indx = 0
|
||||
end
|
||||
if t.vars[result.private_id][result.indx] then
|
||||
if t.vars[result.private_id][result.indx][result.key] then
|
||||
if result.clean then
|
||||
return t.vars[result.private_id][result.indx][result.key]
|
||||
end
|
||||
if t.vars[result.private_id][result.indx][result.key][result.kindx] then
|
||||
return t.vars[result.private_id][result.indx][result.key][result.kindx]
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif result.type == 'avp' then
|
||||
if t.vars[result.private_id] then
|
||||
local l = t.vars[result.private_id]:list()
|
||||
if result.clean then
|
||||
return l
|
||||
else
|
||||
return l[1]
|
||||
end
|
||||
end
|
||||
elseif result.type == 'hdr' then
|
||||
if t.hdr then
|
||||
return t.hdr._get_header(result.id)
|
||||
end
|
||||
elseif result.type == 'pv' then
|
||||
return t.vars_pv[result.mode][result.id]
|
||||
end
|
||||
end
|
||||
|
||||
function t._addvalue_new(result, value)
|
||||
local temp
|
||||
if result.type == 'var' or result.type == 'dlg_var' then
|
||||
t.vars[result.private_id] = value
|
||||
elseif result.type == 'xavp' then
|
||||
if not result.indx then
|
||||
result.indx = 0
|
||||
end
|
||||
if not result.kindx then
|
||||
result.kindx = 0
|
||||
end
|
||||
if result.indx ~= 0 or result.kindx ~= 0 then
|
||||
error(string.format("xavp(%s) has not been initilizated", result.id))
|
||||
end
|
||||
t.vars[result.private_id] = utils.Stack:new()
|
||||
temp = {}
|
||||
temp[result.key] = utils.Stack:new()
|
||||
temp[result.key]:push(value)
|
||||
t.vars[result.private_id]:push(temp)
|
||||
elseif result.type == 'avp' then
|
||||
t.vars[result.private_id] = utils.Stack:new()
|
||||
t.vars[result.private_id]:push(value)
|
||||
elseif result.type == 'pv' and result.mode == 'rw' then
|
||||
t.vars_pv.rw[result.id] = value
|
||||
end
|
||||
end
|
||||
|
||||
function t._addvalue_with_value(result, value)
|
||||
local temp
|
||||
if result.type == 'var' or result.type == 'dlg_var' then
|
||||
t.vars[result.private_id] = value
|
||||
elseif result.type == 'xavp' then
|
||||
if not result.indx then
|
||||
if result.kindx and result.kindx ~= 0 then
|
||||
error(string.format("kindx:%d must be 0", result.kindx))
|
||||
end
|
||||
temp = {}
|
||||
temp[result.key] = utils.Stack:new()
|
||||
temp[result.key]:push(value)
|
||||
t.vars[result.private_id]:push(temp)
|
||||
else
|
||||
if t.vars[result.private_id][result.indx] == nil then
|
||||
error(string.format("xavp(%s[%d]) does not exist", result.id, result.indx))
|
||||
elseif t.vars[result.private_id][result.indx] == false then
|
||||
t.vars[result.private_id][result.indx] = {}
|
||||
end
|
||||
if not result.kindx then
|
||||
result.kindx = 0
|
||||
end
|
||||
if not t.vars[result.private_id][result.indx][result.key] then
|
||||
t.vars[result.private_id][result.indx][result.key] = utils.Stack:new()
|
||||
--error(string.format("t:%s result:%s", utable.tostring(t.vars[result.private_id]), utable.tostring(result)))
|
||||
end
|
||||
t.vars[result.private_id][result.indx][result.key]:push(value)
|
||||
end
|
||||
elseif result.type == 'avp' then
|
||||
t.vars[result.private_id]:push(value)
|
||||
elseif result.type == 'pv' and result.mode == 'rw' then
|
||||
t.vars_pv.rw[result.id] = value
|
||||
end
|
||||
end
|
||||
|
||||
function t._addvalue(id, value)
|
||||
local result = t._is(id)
|
||||
if result.clean then
|
||||
-- clean var
|
||||
t.log("dbg",string.format("sr.pv erase avp[%s]", result.id))
|
||||
t.vars[result.private_id] = nil
|
||||
end
|
||||
if not t.vars[result.private_id] then
|
||||
t._addvalue_new(result, value)
|
||||
else
|
||||
t._addvalue_with_value(result, value)
|
||||
end
|
||||
t.log("dbg", string.format("sr.pv vars:%s", utable.tostring(t.vars)))
|
||||
end
|
||||
|
||||
function t.seti(id, value)
|
||||
if type(value) ~= 'number' then
|
||||
error("value is not a number")
|
||||
end
|
||||
t._addvalue(id, value)
|
||||
end
|
||||
|
||||
function t.sets(id, value)
|
||||
if type(value) ~= 'string' then
|
||||
error("value is not a string")
|
||||
end
|
||||
t._addvalue(id, value)
|
||||
end
|
||||
|
||||
function t.unset(id)
|
||||
local result = t._is(id)
|
||||
if result.type == 'xavp' then
|
||||
if t.vars[result.private_id] then
|
||||
if not result.key then
|
||||
if not result.indx then
|
||||
-- xavp(g) -> clean all
|
||||
t.vars[result.private_id] = nil
|
||||
return
|
||||
else
|
||||
-- xavp(g[0])
|
||||
t.vars[result.private_id][result.indx] = false
|
||||
return
|
||||
end
|
||||
else
|
||||
if not result.indx then
|
||||
result.indx = 0
|
||||
end
|
||||
end
|
||||
-- xavp(g[1]=>k)
|
||||
t.vars[result.private_id][result.indx][result.key] = nil
|
||||
end
|
||||
elseif result.type == 'avp' then
|
||||
t.vars[result.private_id] = nil
|
||||
elseif result.type == 'var' or result.type == 'dlg_var' then
|
||||
t.vars[result.private_id] = nil
|
||||
end
|
||||
t.log("dbg", string.format("sr.pv vars:%s", utable.tostring(t.vars)))
|
||||
end
|
||||
|
||||
function t.is_null(id)
|
||||
local result = t._is(id)
|
||||
if not result then
|
||||
return true
|
||||
end
|
||||
if not t.vars[result.private_id] then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function t.log(level, message)
|
||||
if not t._logger_levels[level] then
|
||||
error(string.format("level %s unknown", level))
|
||||
end
|
||||
t._logger:log(t._logger_levels[level], message)
|
||||
end
|
||||
|
||||
local pvMock_MT = { __index = pvMock }
|
||||
setmetatable(t, pvMock_MT)
|
||||
return t
|
||||
end
|
||||
-- end class
|
||||
return pvMock
|
@ -0,0 +1,82 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
|
||||
local logging = require ('logging')
|
||||
local log_file = require ('logging.file')
|
||||
|
||||
-- class xavpMock
|
||||
local xavpMock = {
|
||||
__class__ = 'xavpMock',
|
||||
_logger = log_file("reports/xavp_%s.log", "%Y-%m-%d"),
|
||||
_logger_levels = {
|
||||
dbg = logging.DEBUG,
|
||||
info = logging.INFO,
|
||||
warn = logging.WARN,
|
||||
err = logging.ERROR,
|
||||
crit = logging.FATAL
|
||||
}
|
||||
}
|
||||
function xavpMock.new(pv)
|
||||
local t = {}
|
||||
|
||||
t.__class__ = 'hdrMock'
|
||||
t.pv = pv
|
||||
|
||||
function t._get_xavp(xavp_name, index, mode)
|
||||
local private_id = "xavp:" .. xavp_name
|
||||
local temp = {}
|
||||
if not t.pv.vars[private_id] then
|
||||
error(string.format("%s not found", xavp_name))
|
||||
elseif not t.pv.vars[private_id][index] then
|
||||
error(string.format("%s[%d] not found", xavp_name, index))
|
||||
end
|
||||
if mode == 0 then
|
||||
for k,v in pairs(t.pv.vars[private_id][index]) do
|
||||
temp[k] = v:list()
|
||||
end
|
||||
else
|
||||
for k,v in pairs(t.pv.vars[private_id][index]) do
|
||||
temp[k] = v[0]
|
||||
end
|
||||
end
|
||||
return temp
|
||||
end
|
||||
|
||||
function t.get_keys(xavp_name, index)
|
||||
local output = {}
|
||||
|
||||
local xavp = t._get_xavp(xavp_name, index, 1)
|
||||
for k,_ in pairs(xavp) do
|
||||
table.insert(output, k)
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
function t.get(xavp_name, index, mode)
|
||||
if not mode then mode = 0 end
|
||||
local xavp = t._get_xavp(xavp_name, index, mode)
|
||||
return xavp
|
||||
end
|
||||
|
||||
local xavpMock_MT = { __index = xavpMock }
|
||||
setmetatable(t, xavpMock_MT)
|
||||
return t
|
||||
end
|
||||
--end class
|
||||
return xavpMock
|
@ -1,2 +1,2 @@
|
||||
globals = {'sr', '_ENV'}
|
||||
ignore = { 'NGCP.*', '212' }
|
||||
ignore = { '212' }
|
||||
|
@ -1,3 +1,3 @@
|
||||
globals = {'sr', 'srMock'}
|
||||
-- until we fix the luaunit new format at run_tests.sh
|
||||
ignore = {'assert.*'}
|
||||
ignore = {'assert.*', '212'}
|
||||
|
@ -1,104 +0,0 @@
|
||||
|
||||
require('luaunit')
|
||||
|
||||
TestToto = {} --class
|
||||
|
||||
function TestToto:setUp()
|
||||
-- set up tests
|
||||
self.a = 1
|
||||
self.s = 'hop'
|
||||
end
|
||||
|
||||
function TestToto:test1_withFailure()
|
||||
print( "some stuff test 1" )
|
||||
assertEquals( self.a , 1 )
|
||||
-- will fail
|
||||
assertEquals( self.a , 2 )
|
||||
assertEquals( self.a , 2 )
|
||||
end
|
||||
|
||||
function TestToto:test2_withFailure()
|
||||
print( "some stuff test 2" )
|
||||
assertEquals( self.a , 1 )
|
||||
assertEquals( self.s , 'hop' )
|
||||
-- will fail
|
||||
assertEquals( self.s , 'bof' )
|
||||
assertEquals( self.s , 'bof' )
|
||||
end
|
||||
|
||||
function TestToto:test3()
|
||||
print( "some stuff test 3" )
|
||||
assertEquals( self.a , 1 )
|
||||
assertEquals( self.s , 'hop' )
|
||||
assertEquals( type(self.a), 'number' )
|
||||
end
|
||||
-- class TestToto
|
||||
|
||||
TestTiti = {} --class
|
||||
function TestTiti:setUp()
|
||||
-- set up tests
|
||||
self.a = 1
|
||||
self.s = 'hop'
|
||||
print( 'TestTiti:setUp' )
|
||||
end
|
||||
|
||||
function TestTiti:tearDown()
|
||||
-- some tearDown() code if necessary
|
||||
print( 'TestTiti:tearDown' )
|
||||
end
|
||||
|
||||
function TestTiti:test1_withFailure()
|
||||
print( "some stuff test 1" )
|
||||
assertEquals( self.a , 1 )
|
||||
-- will fail
|
||||
assertEquals( self.a , 2 )
|
||||
assertEquals( self.a , 2 )
|
||||
end
|
||||
|
||||
function TestTiti:test2_withFailure()
|
||||
print( "some stuff test 2" )
|
||||
assertEquals( self.a , 1 )
|
||||
assertEquals( self.s , 'hop' )
|
||||
-- will fail
|
||||
assertEquals( self.s , 'bof' )
|
||||
assertEquals( self.s , 'bof' )
|
||||
end
|
||||
|
||||
function TestTiti:test3()
|
||||
print( "some stuff test 3" )
|
||||
assertEquals( self.a , 1 )
|
||||
assertEquals( self.s , 'hop' )
|
||||
end
|
||||
-- class TestTiti
|
||||
|
||||
-- simple test functions that were written previously can be integrated
|
||||
-- in luaunit too
|
||||
function test1_withFailure()
|
||||
assert( 1 == 1)
|
||||
-- will fail
|
||||
assert( 1 == 2)
|
||||
end
|
||||
|
||||
function test2_withFailure()
|
||||
assert( 'a' == 'a')
|
||||
-- will fail
|
||||
assert( 'a' == 'b')
|
||||
end
|
||||
|
||||
function test3()
|
||||
assert( 1 == 1)
|
||||
assert( 'a' == 'a')
|
||||
end
|
||||
|
||||
-- LuaUnit:run( 'test2_withFailure' ) -- run only one test function
|
||||
-- LuaUnit:run( 'TestFunctions:test1_withFailure' )
|
||||
-- LuaUnit:run( 'TestToto' ) -- run only on test class
|
||||
-- LuaUnit:run( 'TestTiti:test3') -- run only one test method of a test class
|
||||
-- LuaUnit:run() -- run everything
|
||||
|
||||
---- Control test output:
|
||||
lu = LuaUnit
|
||||
-- lu:setOutputType( "NIL" )
|
||||
lu:setOutputType( "TAP" )
|
||||
lu:setVerbosity( 0 )
|
||||
lu:run()
|
@ -1,574 +0,0 @@
|
||||
--
|
||||
-- Copyright 2013 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
--
|
||||
require('luaunit')
|
||||
require 'mocks.sr'
|
||||
|
||||
TestMock = {}
|
||||
function TestMock:testMock()
|
||||
mc = lemock.controller()
|
||||
m = mc:mock()
|
||||
m.pv = mc:mock()
|
||||
m.titi( 42 )
|
||||
m.toto( 33, "abc", { 21} )
|
||||
end
|
||||
|
||||
TestHDRMock = {}
|
||||
function TestHDRMock:setUp()
|
||||
self.hdr = hdrMock:new()
|
||||
end
|
||||
|
||||
function TestHDRMock:tearDown()
|
||||
self.hdr.headers = {}
|
||||
self.hdr.headers_reply = {}
|
||||
end
|
||||
|
||||
function TestHDRMock:test_is_header()
|
||||
assertTrue(self.hdr._is_header("From: hi@there.com\r\n"))
|
||||
assertFalse(self.hdr._is_header("From hi@there.com\r\n"))
|
||||
assertFalse(self.hdr._is_header("From: hi@there.com\r"))
|
||||
assertFalse(self.hdr._is_header("From : hi@there.com\n"))
|
||||
assertFalse(self.hdr._is_header("From : hi@there.com\n\r"))
|
||||
assertTrue(self.hdr._is_header("From: hi@there.com:8080\r\n"))
|
||||
end
|
||||
|
||||
function TestHDRMock:test_append()
|
||||
assertFalse(self.hdr._get_header("From"))
|
||||
self.hdr.append("From: hi@there.com\r\n")
|
||||
assertEquals(self.hdr.headers, {"From: hi@there.com\r\n"})
|
||||
self.hdr.append("To: bye@there.com\r\n")
|
||||
assertEquals(self.hdr.headers, {"From: hi@there.com\r\n", "To: bye@there.com\r\n"})
|
||||
end
|
||||
|
||||
function TestHDRMock:test_insert()
|
||||
assertFalse(self.hdr._get_header("From"))
|
||||
self.hdr.insert("From: hi@there.com\r\n")
|
||||
assertEquals(self.hdr.headers, {"From: hi@there.com\r\n"})
|
||||
self.hdr.insert("To: bye@there.com\r\n")
|
||||
assertEquals(self.hdr.headers, {"To: bye@there.com\r\n", "From: hi@there.com\r\n"})
|
||||
end
|
||||
|
||||
function TestHDRMock:test_get_header()
|
||||
self:test_append()
|
||||
assertEquals(self.hdr._get_header("From"), "hi@there.com")
|
||||
end
|
||||
-- end class
|
||||
|
||||
TestSRMock = {}
|
||||
function TestSRMock:setUp()
|
||||
self.sr = srMock:new()
|
||||
end
|
||||
|
||||
function TestSRMock:tearDown()
|
||||
self.sr.pv.vars = {}
|
||||
end
|
||||
|
||||
function TestSRMock:test_ini()
|
||||
assertTrue(self.sr.pv)
|
||||
end
|
||||
|
||||
function TestSRMock:test_clean_id()
|
||||
assertEquals(self.sr.pv._clean_id('s:u25'), 'u25')
|
||||
assertEquals(self.sr.pv._clean_id('i:u25'), 'u25')
|
||||
assertEquals(self.sr.pv._clean_id('u25'), 'u25')
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_pv_simple()
|
||||
local result
|
||||
result = self.sr.pv._is_pv("$si")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'pv')
|
||||
assertEquals(result.id, 'si')
|
||||
assertEquals(result.key, nil)
|
||||
assertEquals(result.mode, 'ro')
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_pv_rw()
|
||||
local result
|
||||
result = self.sr.pv._is_pv("$rU")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'pv')
|
||||
assertEquals(result.id, 'rU')
|
||||
assertEquals(result.key, nil)
|
||||
assertEquals(result.mode, 'rw')
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_hdr_simple()
|
||||
local result
|
||||
result = self.sr.pv._is_hdr("$hdr(id)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'hdr')
|
||||
assertEquals(result.id, 'id')
|
||||
assertEquals(result.key, nil)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_hdr_complex()
|
||||
local result
|
||||
result = self.sr.pv._is_hdr("$hdr($si)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'hdr')
|
||||
assertEquals(result.id, '$si')
|
||||
assertEquals(result.key, nil)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_xavp_simple()
|
||||
local result
|
||||
result = self.sr.pv._is_xavp("$xavp(id=>key)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id')
|
||||
assertEquals(result.key, 'key')
|
||||
assertIsNil(result.indx)
|
||||
assertIsNil(result.kindx)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_xavp_complex()
|
||||
local result
|
||||
result = self.sr.pv._is_xavp("$xavp(id1[8]=>key3g2)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id1')
|
||||
assertEquals(result.key, 'key3g2')
|
||||
assertEquals(result.indx, 8)
|
||||
assertIsNil(result.kindx)
|
||||
assertFalse(result.clean)
|
||||
result = self.sr.pv._is_xavp("$xavp(id2g1f[9]=>keygg33_f)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id2g1f')
|
||||
assertEquals(result.key, 'keygg33_f')
|
||||
assertEquals(result.indx, 9)
|
||||
assertIsNil(result.kindx)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_xavp_complex_indx()
|
||||
local result
|
||||
result = self.sr.pv._is_xavp("$xavp(id1[8]=>key3g2)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id1')
|
||||
assertEquals(result.key, 'key3g2')
|
||||
assertEquals(result.indx, 8)
|
||||
assertIsNil(result.kindx)
|
||||
assertFalse(result.clean)
|
||||
result = self.sr.pv._is_xavp("$xavp(id2g1f[9]=>keygg33_f[2])")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id2g1f')
|
||||
assertEquals(result.key, 'keygg33_f')
|
||||
assertEquals(result.indx, 9)
|
||||
assertEquals(result.kindx, 2)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_xavp_complex_indx2()
|
||||
result = self.sr.pv._is_xavp("$xavp(gogo[9]=>gogo[*])")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'gogo')
|
||||
assertEquals(result.key, 'gogo')
|
||||
assertEquals(result.indx, 9)
|
||||
assertFalse(result.kindx)
|
||||
assertTrue(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_xavp_simple_nokey()
|
||||
local result
|
||||
result = self.sr.pv._is_xavp("$xavp(id1[8])")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id1')
|
||||
assertFalse(result.key)
|
||||
assertEquals(result.indx, 8)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_xavp_simple_nokey_noindx()
|
||||
local result
|
||||
result = self.sr.pv._is_xavp("$xavp(id1)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id1')
|
||||
assertFalse(result.key)
|
||||
assertIsNil(result.indx)
|
||||
assertIsNil(result.kindx)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_avp_simple()
|
||||
local result
|
||||
result = self.sr.pv._is_avp("$avp(id2_f)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'avp')
|
||||
--print(table.tostring(result))
|
||||
assertEquals(result.id, 'id2_f')
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_avp_simple1()
|
||||
local result
|
||||
result = self.sr.pv._is_avp("$(avp(s:id))")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'avp')
|
||||
--print(table.tostring(result))
|
||||
assertEquals(result.id, 'id')
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_avp_simple2()
|
||||
local result
|
||||
result = self.sr.pv._is_avp("$(avp(id))")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'avp')
|
||||
--print(table.tostring(result))
|
||||
assertEquals(result.id, 'id')
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_avp_simple3()
|
||||
local result
|
||||
result = self.sr.pv._is_avp("$(avp(s:id)[*])")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'avp')
|
||||
assertEquals(result.id, 'id')
|
||||
--print(table.tostring(result))
|
||||
assertTrue(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_var_simple()
|
||||
local result
|
||||
result = self.sr.pv._is_var("$var(id)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'var')
|
||||
assertEquals(result.id, 'id')
|
||||
--print(table.tostring(result))
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestSRMock:test_var_sets()
|
||||
self.sr.pv.sets("$var(hithere)", "value")
|
||||
assertEquals(self.sr.pv.get("$var(hithere)"), "value")
|
||||
assertError(self.sr.pv.sets, "$var(hithere)", 1)
|
||||
assertError(self.sr.pv.sets, "$var(s:hithere)", "1")
|
||||
assertError(self.sr.pv.sets, "$(var(hithere)[*])", "1")
|
||||
assertError(self.sr.pv.sets, "$(var(s:hithere))", "1")
|
||||
self.sr.pv.sets("$(var(hithere))", "new_value")
|
||||
assertEquals(self.sr.pv.get("$var(hithere)"), "new_value")
|
||||
assertEquals(self.sr.pv.vars["var:hithere"], "new_value")
|
||||
end
|
||||
|
||||
function TestSRMock:test_var_seti()
|
||||
self.sr.pv.seti("$var(hithere)", 0)
|
||||
assertEquals(self.sr.pv.get("$var(hithere)"), 0)
|
||||
assertError(self.sr.pv.seti, "$var(hithere)", "1")
|
||||
assertError(self.sr.pv.sets, "$var(s:hithere)", 1)
|
||||
assertError(self.sr.pv.sets, "$(var(hithere)[*])", 1)
|
||||
assertError(self.sr.pv.sets, "$(var(s:hithere))", 1)
|
||||
assertEquals(self.sr.pv.get("$var(hithere)"), 0)
|
||||
self.sr.pv.seti("$var(hithere)", 1)
|
||||
assertEquals(self.sr.pv.get("$var(hithere)"), 1)
|
||||
assertEquals(self.sr.pv.vars["var:hithere"], 1)
|
||||
end
|
||||
|
||||
function TestSRMock:test_avp_sets()
|
||||
self.sr.pv.sets("$avp(s:hithere)", "value")
|
||||
assertEquals(self.sr.pv.get("$avp(hithere)"), "value")
|
||||
assertError(self.sr.pv.sets, "$avp(hithere)", 1)
|
||||
self.sr.pv.sets("$(avp(hithere)[*])", "1")
|
||||
assertEquals(self.sr.pv.get("$avp(s:hithere)"), "1")
|
||||
self.sr.pv.sets("$(avp(hithere))", "new_value")
|
||||
assertEquals(self.sr.pv.vars["avp:hithere"]:list(), {"new_value","1"})
|
||||
assertEquals(self.sr.pv.get("$avp(hithere)"), "new_value")
|
||||
assertEquals(self.sr.pv.get("$(avp(hithere))"), "new_value")
|
||||
end
|
||||
|
||||
function TestSRMock:test_avp_sets_all()
|
||||
self.sr.pv.sets("$avp(s:hithere)", "value")
|
||||
assertEquals(self.sr.pv.get("$avp(hithere)"), "value")
|
||||
assertEquals(self.sr.pv.get("$(avp(hithere)[*])"), {"value"})
|
||||
self.sr.pv.sets("$avp(s:hithere)", "value1")
|
||||
assertEquals(self.sr.pv.get("$(avp(hithere)[*])"), {"value1","value"})
|
||||
end
|
||||
|
||||
function TestSRMock:test_avp_seti()
|
||||
self.sr.pv.seti("$avp(s:hithere)", 0)
|
||||
assertEquals(self.sr.pv.get("$avp(s:hithere)"), 0)
|
||||
assertError(self.sr.pv.seti, "$avp(s:hithere)", "1")
|
||||
self.sr.pv.seti("$(avp(hithere))", 2)
|
||||
assertEquals(self.sr.pv.vars["avp:hithere"]:list(), {2,0})
|
||||
assertEquals(self.sr.pv.get("$avp(hithere)"), 2)
|
||||
assertEquals(self.sr.pv.get("$(avp(hithere))"), 2)
|
||||
end
|
||||
|
||||
function TestSRMock:test_xavp_sets()
|
||||
self.sr.pv.sets("$xavp(g=>hithere)", "value")
|
||||
assertEquals(self.sr.pv.get("$xavp(g=>hithere)"), "value")
|
||||
self.sr.pv.sets("$xavp(g=>bythere)", "value_bye")
|
||||
assertEquals(self.sr.pv.get("$xavp(g=>bythere)"), "value_bye")
|
||||
end
|
||||
|
||||
function TestSRMock:test_xavp_sets_multi()
|
||||
self.sr.pv.sets("$xavp(g=>hithere)", "value1")
|
||||
assertEquals(self.sr.pv.get("$xavp(g=>hithere)"), "value1")
|
||||
self.sr.pv.sets("$xavp(g[0]=>hithere)", "value0")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>hithere)"), "value0")
|
||||
assertEquals(self.sr.pv.get("$xavp(g=>hithere[1])"), "value1")
|
||||
end
|
||||
|
||||
function TestSRMock:test_xavp_sets1()
|
||||
self.sr.pv.sets("$xavp(g=>hithere)", "value")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>hithere)"), "value")
|
||||
self.sr.pv.sets("$xavp(g=>hithere)", "value_bye")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>hithere)"), "value_bye")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[1]=>hithere)"), "value")
|
||||
end
|
||||
|
||||
function TestSRMock:test_xavp_sets1_multi()
|
||||
self.sr.pv.sets("$xavp(g=>hithere)", "value1")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>hithere)"), "value1")
|
||||
self.sr.pv.sets("$xavp(g[0]=>hithere)", "value0")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>hithere)"), "value0")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>hithere[1])"), "value1")
|
||||
self.sr.pv.sets("$xavp(g=>hithere)", "value_bye")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>hithere)"), "value_bye")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[1]=>hithere)"), "value0")
|
||||
end
|
||||
|
||||
function TestSRMock:test_xavp_seti()
|
||||
self.sr.pv.seti("$xavp(t=>hithere)", 0)
|
||||
assertEquals(self.sr.pv.get("$xavp(t[0]=>hithere)"), 0)
|
||||
assertEquals(self.sr.pv.get("$xavp(t=>hithere)"), 0)
|
||||
assertError(self.sr.pv.seti, "$xavp(t=>hithere)", "1")
|
||||
assertError(self.sr.pv.seti, "$xavp(t[6]=>hithere)", "1")
|
||||
end
|
||||
|
||||
function TestSRMock:test_xavp_get()
|
||||
self.sr.pv.sets("$xavp(g=>hithere)", "value")
|
||||
assertTrue(self.sr.pv.get, "$xavp(g)")
|
||||
end
|
||||
|
||||
function TestSRMock:test_xavp_get_multi()
|
||||
self.sr.pv.sets("$xavp(g=>hithere)", "value1")
|
||||
self.sr.pv.sets("$xavp(g[0]=>hithere)", "value2")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>hithere[0])"), "value2")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>hithere[1])"), "value1")
|
||||
end
|
||||
|
||||
function TestSRMock:test_avp_get_simple()
|
||||
self.sr.pv.sets("$avp(s:hithere)", "value")
|
||||
assertEquals(self.sr.pv.get("$avp(s:hithere)"), "value")
|
||||
end
|
||||
|
||||
function TestSRMock:test_avp_get_simple2()
|
||||
self.sr.pv.seti("$avp(s:hithere)", 1)
|
||||
assertEquals(self.sr.pv.get("$avp(s:hithere)"), 1)
|
||||
end
|
||||
|
||||
function TestSRMock:test_avp_get()
|
||||
local vals = {1,2,3}
|
||||
for i=1,#vals do
|
||||
self.sr.pv.seti("$avp(s:hithere)", vals[i])
|
||||
end
|
||||
local l = self.sr.pv.get("$(avp(s:hithere)[*])")
|
||||
assertTrue(type(l), 'table')
|
||||
assertEquals(#l,#vals)
|
||||
--print(table.tostring(l))
|
||||
v = 1
|
||||
for i=#vals,1,-1 do
|
||||
assertEquals(l[i],vals[v])
|
||||
v = v + 1
|
||||
end
|
||||
end
|
||||
|
||||
function TestSRMock:test_avp_get_all()
|
||||
self.sr.pv.sets("$avp(s:hithere)", "value")
|
||||
assertEquals(self.sr.pv.get("$avp(hithere)"), "value")
|
||||
assertEquals(self.sr.pv.get("$(avp(hithere)[*])"), {"value"})
|
||||
self.sr.pv.sets("$avp(s:hithere)", "value1")
|
||||
assertEquals(self.sr.pv.get("$(avp(hithere)[*])"), {"value1","value"})
|
||||
self.sr.pv.sets("$(avp(s:hithere)[*])", "new_value")
|
||||
assertEquals(self.sr.pv.get("$avp(s:hithere)"), "new_value")
|
||||
assertEquals(self.sr.pv.get("$(avp(s:hithere)[*])"), {"new_value"})
|
||||
end
|
||||
|
||||
function TestSRMock:test_hdr_get()
|
||||
self.sr.hdr.insert("From: hola\r\n")
|
||||
assertEquals(self.sr.hdr.headers, {"From: hola\r\n"})
|
||||
assertEquals(self.sr.pv.get("$hdr(From)"), "hola")
|
||||
end
|
||||
|
||||
function TestSRMock:test_pv_seti()
|
||||
self.sr.pv.seti("$rU", 0)
|
||||
assertEquals(self.sr.pv.get("$rU"), 0)
|
||||
end
|
||||
|
||||
function TestSRMock:test_pv_sets()
|
||||
self.sr.pv.sets("$rU", "0")
|
||||
assertEquals(self.sr.pv.get("$rU"), "0")
|
||||
end
|
||||
|
||||
function TestSRMock:test_unset_var()
|
||||
self.sr.pv.sets("$var(hithere)", "value")
|
||||
assertEquals(self.sr.pv.get("$var(hithere)"), "value")
|
||||
self.sr.pv.unset("$var(hithere)")
|
||||
assertEquals(self.sr.pv.get("$var(hithere)"), nil)
|
||||
self.sr.pv.unset("$var(hithere)")
|
||||
end
|
||||
|
||||
function TestSRMock:test_unset_avp()
|
||||
self.sr.pv.sets("$avp(s:hithere)", "value")
|
||||
assertEquals(self.sr.pv.get("$avp(hithere)"), "value")
|
||||
self.sr.pv.unset("$avp(s:hithere)")
|
||||
assertEquals(self.sr.pv.get("$avp(hithere)"), nil)
|
||||
self.sr.pv.unset("$avp(s:hithere)")
|
||||
assertEquals(self.sr.pv.get("$avp(s:hithere)"), nil)
|
||||
end
|
||||
|
||||
function TestSRMock:test_unset_xavp()
|
||||
self.sr.pv.sets("$xavp(g=>t)", "value")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>t)"), "value")
|
||||
self.sr.pv.sets("$xavp(g=>t)", "value1")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>t)"), "value1")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[1]=>t)"), "value")
|
||||
--
|
||||
self.sr.pv.unset("$xavp(g[0]=>t)")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>t)"), nil)
|
||||
assertEquals(self.sr.pv.get("$xavp(g[1]=>t)"), "value")
|
||||
--
|
||||
self.sr.pv.unset("$xavp(g[1])")
|
||||
assertFalse(self.sr.pv.get("$xavp(g[1])"))
|
||||
self.sr.pv.unset("$xavp(g)")
|
||||
assertEquals(self.sr.pv.get("$xavp(g)"), nil)
|
||||
end
|
||||
|
||||
function TestSRMock:test_unset_xavp1()
|
||||
self.sr.pv.sets("$xavp(g=>t)", "value")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>t)"), "value")
|
||||
self.sr.pv.sets("$xavp(g=>t)", "value1")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>t)"), "value1")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[1]=>t)"), "value")
|
||||
self.sr.pv.sets("$xavp(g[1]=>z)", "value_z")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[1]=>z)"), "value_z")
|
||||
--
|
||||
self.sr.pv.unset("$xavp(g[0])")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[0]=>t)"), nil)
|
||||
assertEquals(self.sr.pv.get("$xavp(g[1]=>t)"), "value")
|
||||
assertEquals(self.sr.pv.get("$xavp(g[1]=>z)"), "value_z")
|
||||
assertFalse(self.sr.pv.get("$xavp(g[0])"))
|
||||
--
|
||||
self.sr.pv.unset("$xavp(g[1])")
|
||||
assertFalse(self.sr.pv.get("$xavp(g[1])"))
|
||||
self.sr.pv.unset("$xavp(g)")
|
||||
assertEquals(self.sr.pv.get("$xavp(g)"), nil)
|
||||
end
|
||||
|
||||
function TestSRMock:test_is_null()
|
||||
assertTrue(self.sr.pv.is_null("$avp(s:hithere)"))
|
||||
self.sr.pv.unset("$avp(s:hithere)")
|
||||
assertTrue(self.sr.pv.is_null("$avp(s:hithere)"))
|
||||
self.sr.pv.sets("$avp(s:hithere)", "value")
|
||||
assertFalse(self.sr.pv.is_null("$avp(s:hithere)"))
|
||||
self.sr.pv.sets("$avp(s:hithere)", "value")
|
||||
assertFalse(self.sr.pv.is_null("$avp(s:hithere)"))
|
||||
end
|
||||
|
||||
function TestSRMock:test_log()
|
||||
assertTrue(self.sr.log)
|
||||
self.sr.log("dbg", "Hi dude!")
|
||||
assertError(self.sr.log, "debug", "Hi dude!")
|
||||
end
|
||||
|
||||
function TestSRMock:test_avp_set_clean()
|
||||
self.sr.pv.seti("$(avp(s:hithere)[*])", 0)
|
||||
assertEquals(self.sr.pv.get("$avp(s:hithere)"), 0)
|
||||
assertEquals(self.sr.pv.get("$(avp(s:hithere)[*])"), {0})
|
||||
self.sr.pv.seti("$(avp(s:hithere)[*])", 1)
|
||||
assertEquals(self.sr.pv.get("$avp(s:hithere)"), 1)
|
||||
assertEquals(self.sr.pv.get("$(avp(s:hithere)[*])"), {1})
|
||||
end
|
||||
-- end class
|
||||
|
||||
TestXAVPMock = {}
|
||||
function TestXAVPMock:setUp()
|
||||
self.pv = pvMock:new()
|
||||
self.xavp = xavpMock:new(self.pv)
|
||||
|
||||
self.pv.sets("$xavp(test=>uno)", "uno")
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>uno)"), "uno")
|
||||
self.pv.seti("$xavp(test[0]=>dos)", 4)
|
||||
self.pv.seti("$xavp(test[0]=>dos)", 2)
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>dos)"), 2)
|
||||
self.pv.seti("$xavp(test=>uno)", 3)
|
||||
self.pv.seti("$xavp(test[0]=>uno)", 1)
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>uno)"), 1)
|
||||
self.pv.sets("$xavp(test[0]=>dos)", "dos")
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>dos)"), "dos")
|
||||
self.pv.seti("$xavp(test[0]=>tres)", 3)
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>tres)"), 3)
|
||||
--
|
||||
assertEquals(self.pv.get("$xavp(test[1]=>uno)"), "uno")
|
||||
assertEquals(self.pv.get("$xavp(test[1]=>dos)"), 2)
|
||||
end
|
||||
|
||||
function TestXAVPMock:tearDown()
|
||||
self.pv.vars = {}
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_keys()
|
||||
local l = self.xavp.get_keys("test", 0)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {"uno", "dos", "tres"})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_keys_1()
|
||||
local l = self.xavp.get_keys("test", 1)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {"uno", "dos"})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_simple()
|
||||
local l = self.xavp.get("test", 0, 1)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {uno=1, dos="dos", tres=3})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_simple_1()
|
||||
local l = self.xavp.get("test", 1, 1)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {uno="uno", dos=2})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get()
|
||||
local l = self.xavp.get("test", 0, 0)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {uno={1,3}, dos={"dos"}, tres={3}})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_1()
|
||||
local l = self.xavp.get("test", 1, 0)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {uno={"uno"}, dos={2,4}})
|
||||
end
|
||||
--EOF
|
@ -0,0 +1,68 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
--
|
||||
|
||||
require('luaunit')
|
||||
local hdrMock = require 'mocks.hdr'
|
||||
|
||||
-- luacheck: ignore TestHDRMock
|
||||
TestHDRMock = {}
|
||||
function TestHDRMock:setUp()
|
||||
self.hdr = hdrMock.new()
|
||||
end
|
||||
|
||||
function TestHDRMock:tearDown()
|
||||
self.hdr.headers = {}
|
||||
self.hdr.headers_reply = {}
|
||||
end
|
||||
|
||||
function TestHDRMock:test_is_header()
|
||||
assertTrue(self.hdr._is_header("From: hi@there.com\r\n"))
|
||||
assertFalse(self.hdr._is_header("From hi@there.com\r\n"))
|
||||
assertFalse(self.hdr._is_header("From: hi@there.com\r"))
|
||||
assertFalse(self.hdr._is_header("From : hi@there.com\n"))
|
||||
assertFalse(self.hdr._is_header("From : hi@there.com\n\r"))
|
||||
assertTrue(self.hdr._is_header("From: hi@there.com:8080\r\n"))
|
||||
end
|
||||
|
||||
function TestHDRMock:test_append()
|
||||
assertFalse(self.hdr._get_header("From"))
|
||||
self.hdr.append("From: hi@there.com\r\n")
|
||||
assertEquals(self.hdr.headers, {"From: hi@there.com\r\n"})
|
||||
self.hdr.append("To: bye@there.com\r\n")
|
||||
assertEquals(self.hdr.headers, {"From: hi@there.com\r\n", "To: bye@there.com\r\n"})
|
||||
end
|
||||
|
||||
function TestHDRMock:test_insert()
|
||||
assertFalse(self.hdr._get_header("From"))
|
||||
self.hdr.insert("From: hi@there.com\r\n")
|
||||
assertEquals(self.hdr.headers, {"From: hi@there.com\r\n"})
|
||||
self.hdr.insert("To: bye@there.com\r\n")
|
||||
assertEquals(self.hdr.headers, {"To: bye@there.com\r\n", "From: hi@there.com\r\n"})
|
||||
end
|
||||
|
||||
function TestHDRMock:test_get_header()
|
||||
self:test_append()
|
||||
assertEquals(self.hdr._get_header("From"), "hi@there.com")
|
||||
end
|
||||
|
||||
function TestHDRMock:test_hdr_get()
|
||||
self.hdr.insert("From: hola\r\n")
|
||||
assertEquals(self.hdr.headers, {"From: hola\r\n"})
|
||||
end
|
@ -0,0 +1,443 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
--
|
||||
|
||||
require('luaunit')
|
||||
local hdrMock = require 'mocks.hdr'
|
||||
local pvMock = require 'mocks.pv'
|
||||
|
||||
-- luacheck: ignore TestPVMock
|
||||
TestPVMock = {}
|
||||
function TestPVMock:setUp()
|
||||
local hdr = hdrMock.new()
|
||||
self.pv = pvMock.new(hdr)
|
||||
end
|
||||
|
||||
function TestPVMock:tearDown()
|
||||
self.pv.vars = {}
|
||||
end
|
||||
|
||||
function TestPVMock:test_ini()
|
||||
assertTrue(self.pv)
|
||||
end
|
||||
|
||||
function TestPVMock:test_clean_id()
|
||||
assertEquals(self.pv._clean_id('s:u25'), 'u25')
|
||||
assertEquals(self.pv._clean_id('i:u25'), 'u25')
|
||||
assertEquals(self.pv._clean_id('u25'), 'u25')
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_pv_simple()
|
||||
local result = self.pv._is_pv("$si")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'pv')
|
||||
assertEquals(result.id, 'si')
|
||||
assertEquals(result.key, nil)
|
||||
assertEquals(result.mode, 'ro')
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_pv_rw()
|
||||
local result = self.pv._is_pv("$rU")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'pv')
|
||||
assertEquals(result.id, 'rU')
|
||||
assertEquals(result.key, nil)
|
||||
assertEquals(result.mode, 'rw')
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_hdr_simple()
|
||||
local result = self.pv._is_hdr("$hdr(id)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'hdr')
|
||||
assertEquals(result.id, 'id')
|
||||
assertEquals(result.key, nil)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_hdr_complex()
|
||||
local result = self.pv._is_hdr("$hdr($si)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'hdr')
|
||||
assertEquals(result.id, '$si')
|
||||
assertEquals(result.key, nil)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_xavp_simple()
|
||||
local result = self.pv._is_xavp("$xavp(id=>key)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id')
|
||||
assertEquals(result.key, 'key')
|
||||
assertIsNil(result.indx)
|
||||
assertIsNil(result.kindx)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_xavp_complex()
|
||||
local result = self.pv._is_xavp("$xavp(id1[8]=>key3g2)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id1')
|
||||
assertEquals(result.key, 'key3g2')
|
||||
assertEquals(result.indx, 8)
|
||||
assertIsNil(result.kindx)
|
||||
assertFalse(result.clean)
|
||||
result = self.pv._is_xavp("$xavp(id2g1f[9]=>keygg33_f)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id2g1f')
|
||||
assertEquals(result.key, 'keygg33_f')
|
||||
assertEquals(result.indx, 9)
|
||||
assertIsNil(result.kindx)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_xavp_complex_indx()
|
||||
local result = self.pv._is_xavp("$xavp(id1[8]=>key3g2)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id1')
|
||||
assertEquals(result.key, 'key3g2')
|
||||
assertEquals(result.indx, 8)
|
||||
assertIsNil(result.kindx)
|
||||
assertFalse(result.clean)
|
||||
result = self.pv._is_xavp("$xavp(id2g1f[9]=>keygg33_f[2])")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id2g1f')
|
||||
assertEquals(result.key, 'keygg33_f')
|
||||
assertEquals(result.indx, 9)
|
||||
assertEquals(result.kindx, 2)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_xavp_complex_indx2()
|
||||
local result = self.pv._is_xavp("$xavp(gogo[9]=>gogo[*])")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'gogo')
|
||||
assertEquals(result.key, 'gogo')
|
||||
assertEquals(result.indx, 9)
|
||||
assertFalse(result.kindx)
|
||||
assertTrue(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_xavp_simple_nokey()
|
||||
local result = self.pv._is_xavp("$xavp(id1[8])")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id1')
|
||||
assertFalse(result.key)
|
||||
assertEquals(result.indx, 8)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_xavp_simple_nokey_noindx()
|
||||
local result = self.pv._is_xavp("$xavp(id1)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'xavp')
|
||||
assertEquals(result.id, 'id1')
|
||||
assertFalse(result.key)
|
||||
assertIsNil(result.indx)
|
||||
assertIsNil(result.kindx)
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_avp_simple()
|
||||
local result = self.pv._is_avp("$avp(id2_f)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'avp')
|
||||
--print(table.tostring(result))
|
||||
assertEquals(result.id, 'id2_f')
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_avp_simple1()
|
||||
local result = self.pv._is_avp("$(avp(s:id))")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'avp')
|
||||
--print(table.tostring(result))
|
||||
assertEquals(result.id, 'id')
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_avp_simple2()
|
||||
local result = self.pv._is_avp("$(avp(id))")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'avp')
|
||||
--print(table.tostring(result))
|
||||
assertEquals(result.id, 'id')
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_avp_simple3()
|
||||
local result = self.pv._is_avp("$(avp(s:id)[*])")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'avp')
|
||||
assertEquals(result.id, 'id')
|
||||
--print(table.tostring(result))
|
||||
assertTrue(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_var_simple()
|
||||
local result = self.pv._is_var("$var(id)")
|
||||
assertTrue(result)
|
||||
assertEquals(result.type, 'var')
|
||||
assertEquals(result.id, 'id')
|
||||
--print(table.tostring(result))
|
||||
assertFalse(result.clean)
|
||||
end
|
||||
|
||||
function TestPVMock:test_var_sets()
|
||||
self.pv.sets("$var(hithere)", "value")
|
||||
assertEquals(self.pv.get("$var(hithere)"), "value")
|
||||
assertError(self.pv.sets, "$var(hithere)", 1)
|
||||
assertError(self.pv.sets, "$var(s:hithere)", "1")
|
||||
assertError(self.pv.sets, "$(var(hithere)[*])", "1")
|
||||
assertError(self.pv.sets, "$(var(s:hithere))", "1")
|
||||
self.pv.sets("$(var(hithere))", "new_value")
|
||||
assertEquals(self.pv.get("$var(hithere)"), "new_value")
|
||||
assertEquals(self.pv.vars["var:hithere"], "new_value")
|
||||
end
|
||||
|
||||
function TestPVMock:test_var_seti()
|
||||
self.pv.seti("$var(hithere)", 0)
|
||||
assertEquals(self.pv.get("$var(hithere)"), 0)
|
||||
assertError(self.pv.seti, "$var(hithere)", "1")
|
||||
assertError(self.pv.sets, "$var(s:hithere)", 1)
|
||||
assertError(self.pv.sets, "$(var(hithere)[*])", 1)
|
||||
assertError(self.pv.sets, "$(var(s:hithere))", 1)
|
||||
assertEquals(self.pv.get("$var(hithere)"), 0)
|
||||
self.pv.seti("$var(hithere)", 1)
|
||||
assertEquals(self.pv.get("$var(hithere)"), 1)
|
||||
assertEquals(self.pv.vars["var:hithere"], 1)
|
||||
end
|
||||
|
||||
function TestPVMock:test_avp_sets()
|
||||
self.pv.sets("$avp(s:hithere)", "value")
|
||||
assertEquals(self.pv.get("$avp(hithere)"), "value")
|
||||
assertError(self.pv.sets, "$avp(hithere)", 1)
|
||||
self.pv.sets("$(avp(hithere)[*])", "1")
|
||||
assertEquals(self.pv.get("$avp(s:hithere)"), "1")
|
||||
self.pv.sets("$(avp(hithere))", "new_value")
|
||||
assertEquals(self.pv.vars["avp:hithere"]:list(), {"new_value","1"})
|
||||
assertEquals(self.pv.get("$avp(hithere)"), "new_value")
|
||||
assertEquals(self.pv.get("$(avp(hithere))"), "new_value")
|
||||
end
|
||||
|
||||
function TestPVMock:test_avp_sets_all()
|
||||
self.pv.sets("$avp(s:hithere)", "value")
|
||||
assertEquals(self.pv.get("$avp(hithere)"), "value")
|
||||
assertEquals(self.pv.get("$(avp(hithere)[*])"), {"value"})
|
||||
self.pv.sets("$avp(s:hithere)", "value1")
|
||||
assertEquals(self.pv.get("$(avp(hithere)[*])"), {"value1","value"})
|
||||
end
|
||||
|
||||
function TestPVMock:test_avp_seti()
|
||||
self.pv.seti("$avp(s:hithere)", 0)
|
||||
assertEquals(self.pv.get("$avp(s:hithere)"), 0)
|
||||
assertError(self.pv.seti, "$avp(s:hithere)", "1")
|
||||
self.pv.seti("$(avp(hithere))", 2)
|
||||
assertEquals(self.pv.vars["avp:hithere"]:list(), {2,0})
|
||||
assertEquals(self.pv.get("$avp(hithere)"), 2)
|
||||
assertEquals(self.pv.get("$(avp(hithere))"), 2)
|
||||
end
|
||||
|
||||
function TestPVMock:test_xavp_sets()
|
||||
self.pv.sets("$xavp(g=>hithere)", "value")
|
||||
assertEquals(self.pv.get("$xavp(g=>hithere)"), "value")
|
||||
self.pv.sets("$xavp(g=>bythere)", "value_bye")
|
||||
assertEquals(self.pv.get("$xavp(g=>bythere)"), "value_bye")
|
||||
end
|
||||
|
||||
function TestPVMock:test_xavp_sets_multi()
|
||||
self.pv.sets("$xavp(g=>hithere)", "value1")
|
||||
assertEquals(self.pv.get("$xavp(g=>hithere)"), "value1")
|
||||
self.pv.sets("$xavp(g[0]=>hithere)", "value0")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>hithere)"), "value0")
|
||||
assertEquals(self.pv.get("$xavp(g=>hithere[1])"), "value1")
|
||||
end
|
||||
|
||||
function TestPVMock:test_xavp_sets1()
|
||||
self.pv.sets("$xavp(g=>hithere)", "value")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>hithere)"), "value")
|
||||
self.pv.sets("$xavp(g=>hithere)", "value_bye")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>hithere)"), "value_bye")
|
||||
assertEquals(self.pv.get("$xavp(g[1]=>hithere)"), "value")
|
||||
end
|
||||
|
||||
function TestPVMock:test_xavp_sets1_multi()
|
||||
self.pv.sets("$xavp(g=>hithere)", "value1")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>hithere)"), "value1")
|
||||
self.pv.sets("$xavp(g[0]=>hithere)", "value0")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>hithere)"), "value0")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>hithere[1])"), "value1")
|
||||
self.pv.sets("$xavp(g=>hithere)", "value_bye")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>hithere)"), "value_bye")
|
||||
assertEquals(self.pv.get("$xavp(g[1]=>hithere)"), "value0")
|
||||
end
|
||||
|
||||
function TestPVMock:test_xavp_seti()
|
||||
self.pv.seti("$xavp(t=>hithere)", 0)
|
||||
assertEquals(self.pv.get("$xavp(t[0]=>hithere)"), 0)
|
||||
assertEquals(self.pv.get("$xavp(t=>hithere)"), 0)
|
||||
assertError(self.pv.seti, "$xavp(t=>hithere)", "1")
|
||||
assertError(self.pv.seti, "$xavp(t[6]=>hithere)", "1")
|
||||
end
|
||||
|
||||
function TestPVMock:test_xavp_get()
|
||||
self.pv.sets("$xavp(g=>hithere)", "value")
|
||||
assertTrue(self.pv.get, "$xavp(g)")
|
||||
end
|
||||
|
||||
function TestPVMock:test_xavp_get_multi()
|
||||
self.pv.sets("$xavp(g=>hithere)", "value1")
|
||||
self.pv.sets("$xavp(g[0]=>hithere)", "value2")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>hithere[0])"), "value2")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>hithere[1])"), "value1")
|
||||
end
|
||||
|
||||
function TestPVMock:test_avp_get_simple()
|
||||
self.pv.sets("$avp(s:hithere)", "value")
|
||||
assertEquals(self.pv.get("$avp(s:hithere)"), "value")
|
||||
end
|
||||
|
||||
function TestPVMock:test_avp_get_simple2()
|
||||
self.pv.seti("$avp(s:hithere)", 1)
|
||||
assertEquals(self.pv.get("$avp(s:hithere)"), 1)
|
||||
end
|
||||
|
||||
function TestPVMock:test_avp_get()
|
||||
local vals = {1,2,3}
|
||||
for i=1,#vals do
|
||||
self.pv.seti("$avp(s:hithere)", vals[i])
|
||||
end
|
||||
local l = self.pv.get("$(avp(s:hithere)[*])")
|
||||
assertTrue(type(l), 'table')
|
||||
assertEquals(#l,#vals)
|
||||
--print(table.tostring(l))
|
||||
local v = 1
|
||||
for i=#vals,1,-1 do
|
||||
assertEquals(l[i],vals[v])
|
||||
v = v + 1
|
||||
end
|
||||
end
|
||||
|
||||
function TestPVMock:test_avp_get_all()
|
||||
self.pv.sets("$avp(s:hithere)", "value")
|
||||
assertEquals(self.pv.get("$avp(hithere)"), "value")
|
||||
assertEquals(self.pv.get("$(avp(hithere)[*])"), {"value"})
|
||||
self.pv.sets("$avp(s:hithere)", "value1")
|
||||
assertEquals(self.pv.get("$(avp(hithere)[*])"), {"value1","value"})
|
||||
self.pv.sets("$(avp(s:hithere)[*])", "new_value")
|
||||
assertEquals(self.pv.get("$avp(s:hithere)"), "new_value")
|
||||
assertEquals(self.pv.get("$(avp(s:hithere)[*])"), {"new_value"})
|
||||
end
|
||||
|
||||
function TestPVMock:test_hdr_get()
|
||||
self.pv.hdr.insert("From: hola\r\n")
|
||||
assertEquals(self.pv.get("$hdr(From)"), "hola")
|
||||
end
|
||||
|
||||
function TestPVMock:test_pv_seti()
|
||||
self.pv.seti("$rU", 0)
|
||||
assertEquals(self.pv.get("$rU"), 0)
|
||||
end
|
||||
|
||||
function TestPVMock:test_pv_sets()
|
||||
self.pv.sets("$rU", "0")
|
||||
assertEquals(self.pv.get("$rU"), "0")
|
||||
end
|
||||
|
||||
function TestPVMock:test_unset_var()
|
||||
self.pv.sets("$var(hithere)", "value")
|
||||
assertEquals(self.pv.get("$var(hithere)"), "value")
|
||||
self.pv.unset("$var(hithere)")
|
||||
assertEquals(self.pv.get("$var(hithere)"), nil)
|
||||
self.pv.unset("$var(hithere)")
|
||||
end
|
||||
|
||||
function TestPVMock:test_unset_avp()
|
||||
self.pv.sets("$avp(s:hithere)", "value")
|
||||
assertEquals(self.pv.get("$avp(hithere)"), "value")
|
||||
self.pv.unset("$avp(s:hithere)")
|
||||
assertEquals(self.pv.get("$avp(hithere)"), nil)
|
||||
self.pv.unset("$avp(s:hithere)")
|
||||
assertEquals(self.pv.get("$avp(s:hithere)"), nil)
|
||||
end
|
||||
|
||||
function TestPVMock:test_unset_xavp()
|
||||
self.pv.sets("$xavp(g=>t)", "value")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>t)"), "value")
|
||||
self.pv.sets("$xavp(g=>t)", "value1")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>t)"), "value1")
|
||||
assertEquals(self.pv.get("$xavp(g[1]=>t)"), "value")
|
||||
--
|
||||
self.pv.unset("$xavp(g[0]=>t)")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>t)"), nil)
|
||||
assertEquals(self.pv.get("$xavp(g[1]=>t)"), "value")
|
||||
--
|
||||
self.pv.unset("$xavp(g[1])")
|
||||
assertFalse(self.pv.get("$xavp(g[1])"))
|
||||
self.pv.unset("$xavp(g)")
|
||||
assertEquals(self.pv.get("$xavp(g)"), nil)
|
||||
end
|
||||
|
||||
function TestPVMock:test_unset_xavp1()
|
||||
self.pv.sets("$xavp(g=>t)", "value")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>t)"), "value")
|
||||
self.pv.sets("$xavp(g=>t)", "value1")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>t)"), "value1")
|
||||
assertEquals(self.pv.get("$xavp(g[1]=>t)"), "value")
|
||||
self.pv.sets("$xavp(g[1]=>z)", "value_z")
|
||||
assertEquals(self.pv.get("$xavp(g[1]=>z)"), "value_z")
|
||||
--
|
||||
self.pv.unset("$xavp(g[0])")
|
||||
assertEquals(self.pv.get("$xavp(g[0]=>t)"), nil)
|
||||
assertEquals(self.pv.get("$xavp(g[1]=>t)"), "value")
|
||||
assertEquals(self.pv.get("$xavp(g[1]=>z)"), "value_z")
|
||||
assertFalse(self.pv.get("$xavp(g[0])"))
|
||||
--
|
||||
self.pv.unset("$xavp(g[1])")
|
||||
assertFalse(self.pv.get("$xavp(g[1])"))
|
||||
self.pv.unset("$xavp(g)")
|
||||
assertEquals(self.pv.get("$xavp(g)"), nil)
|
||||
end
|
||||
|
||||
function TestPVMock:test_is_null()
|
||||
assertTrue(self.pv.is_null("$avp(s:hithere)"))
|
||||
self.pv.unset("$avp(s:hithere)")
|
||||
assertTrue(self.pv.is_null("$avp(s:hithere)"))
|
||||
self.pv.sets("$avp(s:hithere)", "value")
|
||||
assertFalse(self.pv.is_null("$avp(s:hithere)"))
|
||||
self.pv.sets("$avp(s:hithere)", "value")
|
||||
assertFalse(self.pv.is_null("$avp(s:hithere)"))
|
||||
end
|
||||
|
||||
function TestPVMock:test_avp_set_clean()
|
||||
self.pv.seti("$(avp(s:hithere)[*])", 0)
|
||||
assertEquals(self.pv.get("$avp(s:hithere)"), 0)
|
||||
assertEquals(self.pv.get("$(avp(s:hithere)[*])"), {0})
|
||||
self.pv.seti("$(avp(s:hithere)[*])", 1)
|
||||
assertEquals(self.pv.get("$avp(s:hithere)"), 1)
|
||||
assertEquals(self.pv.get("$(avp(s:hithere)[*])"), {1})
|
||||
end
|
@ -0,0 +1,87 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
--
|
||||
|
||||
require('luaunit')
|
||||
local pvMock = require 'mocks.pv'
|
||||
local xavpMock = require 'mocks.xavp'
|
||||
|
||||
-- luacheck: ignore TestXAVPMock
|
||||
TestXAVPMock = {}
|
||||
function TestXAVPMock:setUp()
|
||||
self.pv = pvMock.new()
|
||||
self.xavp = xavpMock.new(self.pv)
|
||||
|
||||
self.pv.sets("$xavp(test=>uno)", "uno")
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>uno)"), "uno")
|
||||
self.pv.seti("$xavp(test[0]=>dos)", 4)
|
||||
self.pv.seti("$xavp(test[0]=>dos)", 2)
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>dos)"), 2)
|
||||
self.pv.seti("$xavp(test=>uno)", 3)
|
||||
self.pv.seti("$xavp(test[0]=>uno)", 1)
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>uno)"), 1)
|
||||
self.pv.sets("$xavp(test[0]=>dos)", "dos")
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>dos)"), "dos")
|
||||
self.pv.seti("$xavp(test[0]=>tres)", 3)
|
||||
assertEquals(self.pv.get("$xavp(test[0]=>tres)"), 3)
|
||||
--
|
||||
assertEquals(self.pv.get("$xavp(test[1]=>uno)"), "uno")
|
||||
assertEquals(self.pv.get("$xavp(test[1]=>dos)"), 2)
|
||||
end
|
||||
|
||||
function TestXAVPMock:tearDown()
|
||||
self.pv.vars = {}
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_keys()
|
||||
local l = self.xavp.get_keys("test", 0)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {"uno", "dos", "tres"})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_keys_1()
|
||||
local l = self.xavp.get_keys("test", 1)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {"uno", "dos"})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_simple()
|
||||
local l = self.xavp.get("test", 0, 1)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {uno=1, dos="dos", tres=3})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_simple_1()
|
||||
local l = self.xavp.get("test", 1, 1)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {uno="uno", dos=2})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get()
|
||||
local l = self.xavp.get("test", 0, 0)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {uno={1,3}, dos={"dos"}, tres={3}})
|
||||
end
|
||||
|
||||
function TestXAVPMock:test_get_1()
|
||||
local l = self.xavp.get("test", 1, 0)
|
||||
assertTrue(l)
|
||||
assertItemsEquals(l, {uno={"uno"}, dos={2,4}})
|
||||
end
|
||||
--EOF
|
@ -0,0 +1,48 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
--
|
||||
|
||||
local lemock = require('lemock')
|
||||
require('luaunit')
|
||||
|
||||
local srMock = require 'mocks.sr'
|
||||
sr = srMock:new()
|
||||
|
||||
local mc
|
||||
|
||||
-- luacheck: ignore TestNGCPDlgList
|
||||
TestNGCPDlgList = {} --class
|
||||
|
||||
function TestNGCPDlgList:setUp()
|
||||
mc = lemock.controller()
|
||||
self.fake_redis = mc:mock()
|
||||
self.central = mc:mock()
|
||||
self.pair = mc:mock()
|
||||
|
||||
package.loaded.redis = self.fake_redis
|
||||
local NGCPDlgList = require 'ngcp.dlglist'
|
||||
|
||||
self.dlg = NGCPDlgList.new()
|
||||
assertTrue(self.dlg)
|
||||
|
||||
self.dlg.central = self.central;
|
||||
self.dlg.pair = self.pair
|
||||
end
|
||||
|
||||
-- class
|
@ -0,0 +1,142 @@
|
||||
--
|
||||
-- Copyright 2013-2015 SipWise Team <development@sipwise.com>
|
||||
--
|
||||
-- This program is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- This package is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-- .
|
||||
-- On Debian systems, the complete text of the GNU General
|
||||
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
--
|
||||
require('luaunit')
|
||||
local utils = require 'ngcp.utils'
|
||||
local Stack = utils.Stack
|
||||
|
||||
-- luacheck: ignore TestStack
|
||||
TestStack = {}
|
||||
function TestStack:test()
|
||||
local s = Stack.new()
|
||||
assertEquals(type(s), 'table')
|
||||
assertEquals(s.__class__, 'Stack')
|
||||
end
|
||||
|
||||
function TestStack:test_size()
|
||||
local s = Stack:new()
|
||||
assertEquals(s:size(),0)
|
||||
s:push(1)
|
||||
assertEquals(s:size(),1)
|
||||
s:pop()
|
||||
assertEquals(s:size(),0)
|
||||
end
|
||||
|
||||
function TestStack:test_push()
|
||||
local s s = Stack:new()
|
||||
s:push(1)
|
||||
assertEquals(s:size(),1)
|
||||
end
|
||||
|
||||
function TestStack:test_pop()
|
||||
local s = Stack:new()
|
||||
assertEquals(s:pop(), nil)
|
||||
s:push(1)
|
||||
assertEquals(s:size(),1)
|
||||
assertEquals(s:pop(),1)
|
||||
assertEquals(s:size(),0)
|
||||
end
|
||||
|
||||
function TestStack:test_get()
|
||||
local s = Stack:new()
|
||||
s:push(1)
|
||||
assertEquals(s:get(0),1)
|
||||
s:push({1,2,3})
|
||||
assertEquals(s:get(0),{1,2,3})
|
||||
assertEquals(s:get(1),1)
|
||||
assertError(s.get, s, -1)
|
||||
assertIsNil(s:get(2))
|
||||
end
|
||||
|
||||
function TestStack:test_get_op()
|
||||
local s = Stack:new()
|
||||
s:push(1)
|
||||
assertEquals(s[0],1)
|
||||
s:push({1,2,3})
|
||||
assertEquals(s[0],{1,2,3})
|
||||
assertEquals(s[1],1)
|
||||
assertIsNil(s[2])
|
||||
end
|
||||
|
||||
function TestStack:test_set()
|
||||
local s = Stack:new()
|
||||
s:push(1)
|
||||
s:push({1,2,3})
|
||||
assertEquals(s:size(),2)
|
||||
assertEquals(s:get(0),{1,2,3})
|
||||
assertEquals(s:get(1),1)
|
||||
s:set(1, 2)
|
||||
assertEquals(s:size(),2)
|
||||
assertEquals(s:get(0),{1,2,3})
|
||||
assertEquals(s:get(1),2)
|
||||
s:set(2, 3)
|
||||
assertEquals(s:size(),2)
|
||||
assertEquals(s:get(0),{1,2,3})
|
||||
assertEquals(s:get(1),2)
|
||||
assertIsNil(s:get(2))
|
||||
assertError(s.set, s, "no", -1)
|
||||
assertError(s.set, s, -1, 2)
|
||||
end
|
||||
|
||||
function TestStack:test_set_op()
|
||||
local s = Stack:new()
|
||||
s:push(1)
|
||||
s:push({1,2,3})
|
||||
assertEquals(s:size(),2)
|
||||
assertEquals(s:get(0),{1,2,3})
|
||||
assertEquals(s:get(1),1)
|
||||
s[1] = 2
|
||||
assertEquals(s:size(),2)
|
||||
assertEquals(s:get(0),{1,2,3})
|
||||
assertEquals(s:get(1),2)
|
||||
s[0] = "new"
|
||||
assertEquals(s:size(),2)
|
||||
assertEquals(s:get(0),"new")
|
||||
assertEquals(s:get(1),2)
|
||||
s[1] = "old"
|
||||
assertEquals(s:get(0),"new")
|
||||
assertEquals(s:get(1),"old")
|
||||
assertEquals(s:size(),2)
|
||||
s[2] = "error"
|
||||
assertEquals(s:get(0),"new")
|
||||
assertEquals(s:get(1),"old")
|
||||
assertIsNil(s:get(2))
|
||||
assertEquals(s:size(),2)
|
||||
end
|
||||
|
||||
function TestStack:test_list()
|
||||
local s = Stack:new()
|
||||
local l = s:list()
|
||||
assertEquals(#l, 0)
|
||||
s:push(1)
|
||||
s:push({1,2,3})
|
||||
assertEquals(s:size(),2)
|
||||
l = s:list()
|
||||
assertItemsEquals(l[1],{1,2,3})
|
||||
assertEquals(l[2],1)
|
||||
assertEquals(s:size(),2)
|
||||
end
|
||||
|
||||
function TestStack:test_tostring()
|
||||
local s = Stack:new()
|
||||
s:push(1)
|
||||
assertEquals(tostring(s), "{1}")
|
||||
s:push(2)
|
||||
assertEquals(tostring(s), "{2,1}")
|
||||
end
|
Loading…
Reference in new issue