squeeze-backports
Victor Seva 13 years ago
parent 0b671fa994
commit a3908d5456

@ -1,4 +1,5 @@
#!/usr/bin/env lua5.1 #!/usr/bin/env lua5.1
require 'ngcp.utils'
require 'ngcp.xavp' require 'ngcp.xavp'
-- class NGCPDomainPrefs -- class NGCPDomainPrefs
@ -30,34 +31,36 @@ NGCPDomainPrefs_MT = { __index = NGCPDomainPrefs }
local keys = {} local keys = {}
local result = {} local result = {}
local row = cur:fetch({}, "a") local row = cur:fetch({}, "a")
local xavp
if row then if row then
while row do while row do
--sr.log("info", string.format("result:%s row:%s", table.tostring(result), table.tostring(row))) --sr.log("info", string.format("result:%s row:%s", table.tostring(result), table.tostring(row)))
table.insert(result, row) table.insert(result, row)
table.insert(keys, row.attribute) table.add(keys, row.attribute)
row = cur:fetch({}, "a") row = cur:fetch({}, "a")
end end
else else
sr.log("dbg", string.format("no results for query:%s", query)) sr.log("dbg", string.format("no results for query:%s", query))
end end
xavp = NGCPXAvp:new(level,'domain',result) NGCPDomainPrefs:xavp(level, result)
cur:close() cur:close()
con:close() con:close()
return keys return keys
end end
function NGCPDomainPrefs:xavp(level, l)
if level ~= 'caller' and level ~= 'callee' then
error(string.format("unknown level:%s. It has to be [caller|callee]", tostring(level)))
end
return NGCPXAvp:new(level,'dom_prefs', l)
end
function NGCPDomainPrefs:clean(vtype) function NGCPDomainPrefs:clean(vtype)
local xavp
if not vtype then if not vtype then
sr.pv.unset("$xavp(domain)") NGCPDomainPrefs:xavp('callee'):clean()
elseif vtype == 'callee' then NGCPDomainPrefs:xavp('caller'):clean()
xavp = NGCPXAvp:new('callee','domain',{}) else
xavp:clean() NGCPDomainPrefs:xavp(vtype):clean()
elseif vtype == 'caller' then
xavp = NGCPXAvp:new('caller','domain',{})
xavp:clean()
end end
end end
-- class -- class

@ -48,18 +48,18 @@ NGCP_MT = { __index = NGCP }
config = NGCPConfig:new() config = NGCPConfig:new()
} }
t.prefs = { t.prefs = {
domain = NGCPDomainPrefs:new(t.config), dom = NGCPDomainPrefs:new(t.config),
user = NGCPUserPrefs:new(t.config), usr = NGCPUserPrefs:new(t.config),
peer = NGCPPeerPrefs:new(t.config), peer = NGCPPeerPrefs:new(t.config),
real = NGCPPeerPrefs:new(), real = NGCPPeerPrefs:new(),
} }
return t return t
end end
function NGCP:caller_load(uuid, domain, peer) function NGCP:caller_load(uuid, domain, peer)
local keys = { local keys = {
domain = self.prefs.domain:caller_load(domain), domain = self.prefs.dom:caller_load(domain),
user = self.prefs.user:caller_load(uuid), user = self.prefs.usr:caller_load(uuid),
peer = self.prefs.peer:caller_load(peer) peer = self.prefs.peer:caller_load(peer)
} }
local unique_keys = table.deepcopy(keys.domain) local unique_keys = table.deepcopy(keys.domain)
@ -72,8 +72,8 @@ NGCP_MT = { __index = NGCP }
function NGCP:callee_load(uuid, domain, peer) function NGCP:callee_load(uuid, domain, peer)
local keys = { local keys = {
domain = self.prefs.domain:callee_load(domain), domain = self.prefs.dom:callee_load(domain),
user = self.prefs.user:callee_load(uuid), user = self.prefs.usr:callee_load(uuid),
peer = self.prefs.peer:caller_load(peer) peer = self.prefs.peer:caller_load(peer)
} }
local unique_keys = table.deepcopy(keys.domain) local unique_keys = table.deepcopy(keys.domain)

@ -1,4 +1,5 @@
#!/usr/bin/env lua5.1 #!/usr/bin/env lua5.1
require 'ngcp.utils'
require 'ngcp.xavp' require 'ngcp.xavp'
-- class NGCPPeerPrefs -- class NGCPPeerPrefs
@ -16,43 +17,50 @@ NGCPPeerPrefs_MT = { __index = NGCPPeerPrefs }
end end
function NGCPPeerPrefs:caller_load(uuid) function NGCPPeerPrefs:caller_load(uuid)
NGCPPeerPrefs._load(self,"caller",uuid) return self:_load("caller",uuid)
end end
function NGCPPeerPrefs:callee_load(uuid) function NGCPPeerPrefs:callee_load(uuid)
NGCPPeerPrefs._load(self,"callee",uuid) return self:_load("callee",uuid)
end end
function NGCPPeerPrefs:_load(level, uuid) function NGCPPeerPrefs:_load(level, uuid)
local con = self.config:getDBConnection() local con = assert (self.config:getDBConnection())
local query = "SELECT * FROM " .. self.db_table .. " WHERE uuid = '" .. uuid .. "'" local query = "SELECT * FROM " .. self.db_table .. " WHERE uuid = '" .. uuid .. "'"
local cur = assert (con:execute(query)) local cur = assert (con:execute(query))
local keys = {}
local result = {} local result = {}
local row = cur:fetch(result, "a") local row = cur:fetch({}, "a")
if row then if row then
while row do while row do
sr.log("info", string.format("result:%s row:%s", table.tostring(result), table.tostring(row))) --sr.log("info", string.format("result:%s row:%s", table.tostring(result), table.tostring(row)))
table.insert(result, row) table.insert(result, row)
table.add(keys, row.attribute)
row = cur:fetch({}, "a") row = cur:fetch({}, "a")
end end
else else
sr.log("dbg", string.format("no results for query:%s", query)) sr.log("dbg", string.format("no results for query:%s", query))
end end
self.xavp = NGCPXAvp:new(level,'peer',result) self:xavp(level, result)
cur:close() cur:close()
con:close() con:close()
return keys
end
function NGCPPeerPrefs:xavp(level, l)
if level ~= 'caller' and level ~= 'callee' then
error(string.format("unknown level:%s. It has to be [caller|callee]", tostring(level)))
end
return NGCPXAvp:new(level,'peer_prefs', l)
end end
function NGCPPeerPrefs:clean(vtype) function NGCPPeerPrefs:clean(vtype)
local xavp
if not vtype then if not vtype then
sr.pv.unset("$xavp(peer)") NGCPPeerPrefs:xavp('callee'):clean()
elseif vtype == 'callee' then NGCPPeerPrefs:xavp('caller'):clean()
xavp = NGCPXAvp:new('callee','peer',{}) else
xavp:clean() NGCPPeerPrefs:xavp(vtype):clean()
elseif vtype == 'caller' then
xavp = NGCPXAvp:new('caller','peer',{})
xavp:clean()
end end
end end
-- class -- class

@ -24,19 +24,21 @@ NGCPRealPrefs_MT = { __index = NGCPRealPrefs }
function NGCPRealPrefs:_load(level, keys) function NGCPRealPrefs:_load(level, keys)
local _,v local _,v
local xavp = { local xavp = {
real = NGCPXAvp:new(level,'real', {}), real = NGCPRealPrefs:xavp(level),
domain = NGCPXAvp:new(level,'domain', {}), dom = NGCPDomainPrefs:xavp(level),
user = NGCPXAvp:new(level,'user', {}), usr = NGCPUserPrefs:xavp(level)
} }
local real_keys = {} local real_keys = {}
local value local value
for _,v in pairs(keys) do for _,v in pairs(keys) do
value = xavp.user(v) value = xavp.usr(v)
if not value then if not value then
value = xavp.domain(v) value = xavp.dom(v)
--sr.log("info", string.format("key:%s value:%s from domain", v, value))
end end
if value then if value then
table.add(real_keys, v) table.add(real_keys, v)
--sr.log("info", string.format("key:%s value:%s", v, value))
xavp.real(v, value) xavp.real(v, value)
else else
sr.log("err", string.format("key:%s not in user or domain", v)) sr.log("err", string.format("key:%s not in user or domain", v))
@ -45,16 +47,19 @@ NGCPRealPrefs_MT = { __index = NGCPRealPrefs }
return real_keys return real_keys
end end
function NGCPRealPrefs:clean() function NGCPRealPrefs:xavp(level, l)
local xavp if level ~= 'caller' and level ~= 'callee' then
error(string.format("unknown level:%s. It has to be [caller|callee]", tostring(level)))
end
return NGCPXAvp:new(level,'real_prefs', l)
end
function NGCPRealPrefs:clean(vtype)
if not vtype then if not vtype then
sr.pv.unset("$xavp(real)") NGCPRealPrefs:xavp('callee'):clean()
elseif vtype == 'callee' then NGCPRealPrefs:xavp('caller'):clean()
xavp = NGCPXAvp:new('callee','real',{}) else
xavp:clean() NGCPRealPrefs:xavp(vtype):clean()
elseif vtype == 'caller' then
xavp = NGCPXAvp:new('caller','real',{})
xavp:clean()
end end
end end
-- class -- class

@ -1,4 +1,5 @@
#!/usr/bin/env lua5.1 #!/usr/bin/env lua5.1
require 'ngcp.utils'
require 'ngcp.xavp' require 'ngcp.xavp'
-- class NGCPUserPrefs -- class NGCPUserPrefs
@ -30,34 +31,36 @@ NGCPUserPrefs_MT = { __index = NGCPUserPrefs }
local keys = {} local keys = {}
local result = {} local result = {}
local row = cur:fetch({}, "a") local row = cur:fetch({}, "a")
local xavp
if row then if row then
while row do while row do
--sr.log("info", string.format("result:%s row:%s", table.tostring(result), table.tostring(row))) --sr.log("info", string.format("result:%s row:%s", table.tostring(result), table.tostring(row)))
table.insert(result, row) table.insert(result, row)
table.insert(keys, row.attribute) table.add(keys, row.attribute)
row = cur:fetch({}, "a") row = cur:fetch({}, "a")
end end
else else
sr.log("dbg", string.format("no results for query:%s", query)) sr.log("dbg", string.format("no results for query:%s", query))
end end
xavp = NGCPXAvp:new(level,'user',result) NGCPUserPrefs:xavp(level,result)
cur:close() cur:close()
con:close() con:close()
return keys return keys
end end
function NGCPUserPrefs:xavp(level, l)
if level ~= 'caller' and level ~= 'callee' then
error(string.format("unknown level:%s. It has to be [caller|callee]", tostring(level)))
end
return NGCPXAvp:new(level,'usr_prefs', l)
end
function NGCPUserPrefs:clean(vtype) function NGCPUserPrefs:clean(vtype)
local xavp
if not vtype then if not vtype then
sr.pv.unset("$xavp(user)") NGCPUserPrefs:xavp('callee'):clean()
elseif vtype == 'callee' then NGCPUserPrefs:xavp('caller'):clean()
xavp = NGCPXAvp:new('callee','user',{}) else
xavp:clean() NGCPUserPrefs:xavp(vtype):clean()
elseif vtype == 'caller' then
xavp = NGCPXAvp:new('caller','user',{})
xavp:clean()
end end
end end
-- class -- class

@ -1,4 +1,5 @@
#!/usr/bin/env lua5.1 #!/usr/bin/env lua5.1
require 'ngcp.utils'
-- class NGCPXAvp -- class NGCPXAvp
NGCPXAvp = { NGCPXAvp = {
@ -13,15 +14,17 @@ NGCPXAvp_MT = {
if not key then if not key then
error("key is empty") error("key is empty")
end end
local id = string.format("$xavp(%s[%d]=>%s)", t.group, t.level, key) local id = string.format("$xavp(%s[0]=>%s)", t.name, key)
--print(string.format("id:%s", id)) --print(string.format("id:%s", id))
if not value then if not value then
return sr.pv.get(id) return sr.pv.get(id)
elseif type(value) == "number" then elseif type(value) == "number" then
table.add(t.keys, key) table.add(t.keys, key)
sr.log("info", string.format("seti: [%s]:%d", id, value))
sr.pv.seti(id, value) sr.pv.seti(id, value)
elseif type(value) == "string" then elseif type(value) == "string" then
table.add(t.keys, key) table.add(t.keys, key)
sr.log("info", string.format("sets: [%s]:%s", id, value))
sr.pv.sets(id, value) sr.pv.sets(id, value)
else else
error("value is not a number or string") error("value is not a number or string")
@ -36,20 +39,16 @@ NGCPXAvp_MT = {
error("unknown level. It has to be [caller|callee]") error("unknown level. It has to be [caller|callee]")
end end
if not l then if not l then
error("list empty") l = {}
end end
local t = { local t = {
group = group, group = group,
level = level,
name = level .. '_' .. group,
keys = {} keys = {}
} }
if level == 'callee' then NGCPXAvp._create(t, l)
t.level = 1
else
t.level = 0
end
NGCPXAvp._create(t, t.level,group,l)
return t return t
end end
@ -61,6 +60,9 @@ NGCPXAvp_MT = {
end end
if vtype == 0 then if vtype == 0 then
sr.log("dbg",string.format("sr.pv.sets->%s:%s", id, value)) sr.log("dbg",string.format("sr.pv.sets->%s:%s", id, value))
if type(value) == 'number' then
value = tostring(value)
end
sr.pv.sets(id, value) sr.pv.sets(id, value)
elseif vtype == 1 then elseif vtype == 1 then
if type(value) == "string" then if type(value) == "string" then
@ -76,44 +78,28 @@ NGCPXAvp_MT = {
if type(check) == 'table' then if type(check) == 'table' then
check = table.tostring(check) check = table.tostring(check)
end end
--sr.log("info", string.format("%s:%s", id, check))
else else
--error(string.format("%s:nil", id))
sr.log("err", string.format("%s:nil", id)) sr.log("err", string.format("%s:nil", id))
end end
end end
end end
function NGCPXAvp:_create(level, group, l) function NGCPXAvp:_create(l)
local i local i
local name_callee = string.format("$xavp(%s[1]=>dummy)", group) local name = string.format("$xavp(%s=>dummy)", self.name)
local name_caller = string.format("$xavp(%s[0]=>dummy)", group) if not sr.pv.get(name) then
local name = string.format("$xavp(%s=>dummy)", group) NGCPXAvp._setvalue(name, 0, self.level)
if not sr.pv.get(name_callee) then
if not sr.pv.get(name_caller) then
-- create dummy vars
NGCPXAvp._setvalue(name, 0, "callee") -- callee -> [0]
NGCPXAvp._setvalue(name, 0, "caller") -- caller -> [0]; calle -> [1]
else
-- caller [0] ok
NGCPXAvp._setvalue(name_callee, 0, "callee")
end
else
if not sr.pv.get(name_caller) then
-- callee [1] ok
NGCPXAvp._setvalue(name_caller, 0, "caller")
end
end end
for i=1,#l do for i=1,#l do
name = string.format("$xavp(%s[%d]=>%s)", group, level, l[i].attribute) name = string.format("$xavp(%s[0]=>%s)", self.name, l[i].attribute)
table.add(self.keys, l[i].attribute) table.add(self.keys, l[i].attribute)
NGCPXAvp._setvalue(name, l[i].type, l[i].value) NGCPXAvp._setvalue(name, l[i].type, l[i].value)
end end
end end
function NGCPXAvp:clean() function NGCPXAvp:clean()
local levels = {"caller", "callee"} sr.pv.unset(string.format("$xavp(%s)", self.name))
sr.pv.unset(string.format("$xavp(%s[%d])", self.group, self.level))
sr.pv.sets(string.format("$xavp(%s[%d]=>dummy)", self.group, self.level), levels[self.level+1])
end end
-- class -- class
--EOF --EOF

@ -3,7 +3,7 @@
mkdir -p reports mkdir -p reports
rm -rf reports/* rm -rf reports/*
for f in tests/*.lua; do for f in tests/test_*.lua; do
NAME=$(basename ${f} .lua) NAME=$(basename ${f} .lua)
lua5.1 ${f} > reports/${NAME}.tap lua5.1 ${f} > reports/${NAME}.tap
done done

@ -330,9 +330,4 @@ TestSRMock = {}
assertEquals(self.sr.pv.get("$avp(s:hithere)"), 1) assertEquals(self.sr.pv.get("$avp(s:hithere)"), 1)
assertEquals(self.sr.pv.get("$(avp(s:hithere)[*])"), {1}) assertEquals(self.sr.pv.get("$(avp(s:hithere)[*])"), {1})
end end
---- Control test output:
lu = LuaUnit
lu:setOutputType( "TAP" )
lu:setVerbosity( 1 )
lu:run()
--EOF --EOF

@ -26,6 +26,18 @@ TestNGCP = {} --class
self.ngcp = NGCP:new() self.ngcp = NGCP:new()
end end
function TestNGCP:tearDown()
sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_peer_prefs)")
sr.pv.unset("$xavp(callee_peer_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.log("info", "---cleaned---")
end
function TestNGCP:test_config() function TestNGCP:test_config()
assertTrue(self.ngcp.config) assertTrue(self.ngcp.config)
end end
@ -47,73 +59,67 @@ TestNGCP = {} --class
assertTrue(self.ngcp) assertTrue(self.ngcp)
assertTrue(self.ngcp.prefs) assertTrue(self.ngcp.prefs)
assertTrue(self.ngcp.prefs.peer) assertTrue(self.ngcp.prefs.peer)
assertTrue(self.ngcp.prefs.user) assertTrue(self.ngcp.prefs.usr)
assertTrue(self.ngcp.prefs.domain) assertTrue(self.ngcp.prefs.dom)
assertTrue(self.ngcp.prefs.real) assertTrue(self.ngcp.prefs.real)
end end
function TestNGCP:test_clean() function TestNGCP:test_clean()
local xavp = NGCPXAvp:new('callee','user',{}) local xavp = NGCPXAvp:new('callee','usr_prefs')
xavp("testid",1) xavp("testid",1)
xavp("foo","foo") xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(user[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(user[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(user[0]=>dummy)"),"caller") assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"))
self.ngcp:clean() self.ngcp:clean()
assertFalse(sr.pv.get("$xavp(user[0]=>dummy)")) assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(user[1]=>dummy)")) assertFalse(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(user)")) assertFalse(sr.pv.get("$xavp(user)"))
end end
function TestNGCP:test_callee_clean() function TestNGCP:test_callee_clean()
local callee_xavp = NGCPXAvp:new('callee','domain',{}) local callee_xavp = NGCPDomainPrefs:xavp('callee')
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
callee_xavp("testid",1) callee_xavp("testid",1)
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
callee_xavp("foo","foo") callee_xavp("foo","foo")
local caller_xavp = NGCPXAvp:new('caller','domain',{}) assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
local caller_xavp = NGCPDomainPrefs:xavp('caller')
caller_xavp("other",1) caller_xavp("other",1)
assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1)
caller_xavp("otherfoo","foo") caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(domain[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(domain[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
assertEquals(sr.pv.get("$xavp(domain[0]=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(domain[0]=>other)"),1)
assertEquals(sr.pv.get("$xavp(domain[0]=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(domain[1]=>dummy)"),"callee")
self.ngcp:clean('callee') self.ngcp:clean('callee')
assertEquals(sr.pv.get("$xavp(domain[0]=>dummy)"),'caller') assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),'caller')
assertFalse(sr.pv.get("$xavp(domain[1]=>testid)")) assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>testid)"))
assertFalse(sr.pv.get("$xavp(domain[1]=>foo)")) assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(domain[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(domain[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(domain[1]=>dummy)"),"callee") assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"))
end end
function TestNGCP:test_caller_clean() function TestNGCP:test_caller_clean()
local callee_xavp = NGCPXAvp:new('callee','peer',{}) local callee_xavp = NGCPXAvp:new('callee','peer_prefs')
callee_xavp("testid",1) callee_xavp("testid",1)
callee_xavp("foo","foo") callee_xavp("foo","foo")
local caller_xavp = NGCPXAvp:new('caller','peer',{}) local caller_xavp = NGCPXAvp:new('caller','peer_prefs')
caller_xavp("other",1) caller_xavp("other",1)
caller_xavp("otherfoo","foo") caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(peer[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(peer[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(peer[0]=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(peer[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(peer[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(peer[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
self.ngcp:clean('caller') self.ngcp:clean('caller')
assertEquals(sr.pv.get("$xavp(peer[0]=>dummy)"),'caller') assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(peer[0]=>other)")) assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>other)"))
assertFalse(sr.pv.get("$xavp(peer[0]=>otherfoo)")) assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(peer[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(peer[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(peer[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
end end
-- class TestNGCP -- class TestNGCP
---- Control test output:
lu = LuaUnit
lu:setOutputType( "TAP" )
lu:setVerbosity( 1 )
lu:run()
--EOF --EOF

@ -54,10 +54,4 @@ TestNGCPAvp = {} --class
assertFalse(self.avp()) assertFalse(self.avp())
end end
-- class TestNGCPAvp -- class TestNGCPAvp
---- Control test output:
lu = LuaUnit
lu:setOutputType( "TAP" )
lu:setVerbosity( 1 )
lu:run()
--EOF --EOF

@ -1,10 +1,15 @@
#!/usr/bin/env lua5.1 #!/usr/bin/env lua5.1
require('luaunit') require('luaunit')
require 'mocks.sr'
require 'ngcp.utils' require 'ngcp.utils'
require 'tests_v.dp_vars' require 'tests_v.dp_vars'
require('lemock')
sr = srMock:new()
if not sr then
require 'mocks.sr'
sr = srMock:new()
else
argv = {}
end
local mc = nil local mc = nil
DPFetch = { DPFetch = {
@ -49,7 +54,15 @@ TestNGCPDomainPrefs = {} --class
end end
function TestNGCPDomainPrefs:tearDown() function TestNGCPDomainPrefs:tearDown()
sr.pv.vars = {} sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_peer_prefs)")
sr.pv.unset("$xavp(callee_peer_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.log("info", "---cleaned---")
end end
function TestNGCPDomainPrefs:test_init() function TestNGCPDomainPrefs:test_init()
@ -71,8 +84,8 @@ TestNGCPDomainPrefs = {} --class
local keys = self.d:caller_load("192.168.51.56") local keys = self.d:caller_load("192.168.51.56")
mc:verify() mc:verify()
assertEquals(sr.pv.get("$xavp(domain[0]=>sst_enable)"),"no") assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>sst_enable)"),"no")
assertEquals(sr.pv.get("$xavp(domain[0]=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE") assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertItemsEquals(keys, {"sst_enable", "sst_refresh_method"}) assertItemsEquals(keys, {"sst_enable", "sst_refresh_method"})
end end
@ -90,72 +103,66 @@ TestNGCPDomainPrefs = {} --class
local keys = self.d:callee_load("192.168.51.56") local keys = self.d:callee_load("192.168.51.56")
mc:verify() mc:verify()
assertEquals(sr.pv.get("$xavp(domain[1]=>sst_enable)"),"no") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>sst_enable)"),"no")
assertEquals(sr.pv.get("$xavp(domain[1]=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertItemsEquals(keys, {"sst_enable", "sst_refresh_method"}) assertItemsEquals(keys, {"sst_enable", "sst_refresh_method"})
end end
function TestNGCPDomainPrefs:test_clean() function TestNGCPDomainPrefs:test_clean()
local xavp = NGCPXAvp:new('callee','domain',{}) local xavp = NGCPDomainPrefs:xavp('callee')
xavp("testid",1) xavp("testid",1)
xavp("foo","foo") xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(domain[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(domain[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(domain[0]=>dummy)"),"caller") assertFalse(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"))
self.d:clean() self.d:clean()
assertFalse(sr.pv.get("$xavp(domain[0]=>dummy)")) assertFalse(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(domain[1]=>dummy)")) assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(domain)")) assertFalse(sr.pv.get("$xavp(domain)"))
end end
function TestNGCPDomainPrefs:test_callee_clean() function TestNGCPDomainPrefs:test_callee_clean()
local callee_xavp = NGCPXAvp:new('callee','domain',{}) local callee_xavp = NGCPDomainPrefs:xavp('callee')
callee_xavp("testid",1) callee_xavp("testid",1)
callee_xavp("foo","foo") callee_xavp("foo","foo")
local caller_xavp = NGCPXAvp:new('caller','domain',{}) local caller_xavp = NGCPDomainPrefs:xavp('caller')
caller_xavp("other",1) caller_xavp("other",1)
caller_xavp("otherfoo","foo") caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(domain[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(domain[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(domain[0]=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(domain[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(domain[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(domain[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
self.d:clean('callee') self.d:clean('callee')
assertEquals(sr.pv.get("$xavp(domain[0]=>dummy)"),'caller') assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),'caller')
assertFalse(sr.pv.get("$xavp(domain[1]=>testid)")) assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>testid)"))
assertFalse(sr.pv.get("$xavp(domain[1]=>foo)")) assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(domain[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(domain[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(domain[1]=>dummy)"),"callee") assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"))
end end
function TestNGCPDomainPrefs:test_caller_clean() function TestNGCPDomainPrefs:test_caller_clean()
local callee_xavp = NGCPXAvp:new('callee','domain',{}) local callee_xavp = NGCPDomainPrefs:xavp('callee')
callee_xavp("testid",1) callee_xavp("testid",1)
callee_xavp("foo","foo") callee_xavp("foo","foo")
local caller_xavp = NGCPXAvp:new('caller','domain',{}) local caller_xavp = NGCPDomainPrefs:xavp('caller')
caller_xavp("other",1) caller_xavp("other",1)
caller_xavp("otherfoo","foo") caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(domain[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(domain[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(domain[0]=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(domain[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(domain[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(domain[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
self.d:clean('caller') self.d:clean('caller')
assertEquals(sr.pv.get("$xavp(domain[0]=>dummy)"),'caller') assertFalse(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(domain[0]=>other)")) assertFalse(sr.pv.get("$xavp(caller_dom_prefs=>other)"))
assertFalse(sr.pv.get("$xavp(domain[0]=>otherfoo)")) assertFalse(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(domain[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(domain[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(domain[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
end end
-- class TestNGCPDomainPrefs -- class TestNGCPDomainPrefs
---- Control test output:
lu = LuaUnit
lu:setOutputType( "TAP" )
lu:setVerbosity( 1 )
lu:run()
--EOF --EOF

@ -1,10 +1,15 @@
#!/usr/bin/env lua5.1 #!/usr/bin/env lua5.1
require('luaunit') require('luaunit')
require 'mocks.sr'
require 'ngcp.utils' require 'ngcp.utils'
require 'tests_v.pp_vars' require 'tests_v.pp_vars'
require('lemock')
sr = srMock:new()
if not sr then
require 'mocks.sr'
sr = srMock:new()
else
argv = {}
end
local mc = nil local mc = nil
PPFetch = { PPFetch = {
@ -49,7 +54,15 @@ TestNGCPPeerPrefs = {} --class
end end
function TestNGCPPeerPrefs:tearDown() function TestNGCPPeerPrefs:tearDown()
sr.pv.vars = {} sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_peer_prefs)")
sr.pv.unset("$xavp(callee_peer_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.log("info", "---cleaned---")
end end
function TestNGCPPeerPrefs:test_init() function TestNGCPPeerPrefs:test_init()
@ -68,16 +81,12 @@ TestNGCPPeerPrefs = {} --class
self.con:close() self.con:close()
mc:replay() mc:replay()
self.d:caller_load("2") local keys = self.d:caller_load("2")
mc:verify() mc:verify()
assertTrue(self.d.xavp) assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"), "caller")
assertEquals(self.d.xavp("sst_enable"),"no") assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>sst_enable)"),"no")
assertEquals(sr.pv.get("$xavp(peer[0]=>dummy)"), "caller") assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(self.d.xavp("dummy"),"caller")
assertEquals(sr.pv.get("$xavp(peer[0]=>sst_enable)"),"no")
assertEquals(sr.pv.get("$xavp(peer[0]=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertIsNil(self.d.xavp("error_key"))
end end
function TestNGCPPeerPrefs:test_callee_load() function TestNGCPPeerPrefs:test_callee_load()
@ -91,79 +100,70 @@ TestNGCPPeerPrefs = {} --class
self.con:close() self.con:close()
mc:replay() mc:replay()
self.d:callee_load("2") local keys = self.d:callee_load("2")
mc:verify() mc:verify()
assertTrue(self.d.xavp) assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"), "callee")
assertEquals(self.d.xavp("sst_enable"),"no") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>sst_enable)"),"no")
--print(table.tostring(sr.pv.vars)) assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertEquals(sr.pv.get("$xavp(peer[1]=>dummy)"), "callee")
assertEquals(sr.pv.get("$xavp(peer[1]=>sst_enable)"),"no")
assertEquals(sr.pv.get("$xavp(peer[1]=>sst_refresh_method)"), "UPDATE_FALLBACK_INVITE")
assertIsNil(self.d.xavp("error_key"))
end end
function TestNGCPPeerPrefs:test_clean() function TestNGCPPeerPrefs:test_clean()
local xavp = NGCPXAvp:new('callee','peer',{}) local xavp = NGCPPeerPrefs:xavp('callee')
xavp("testid",1) xavp("testid",1)
xavp("foo","foo") xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(peer[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(peer[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(peer[0]=>dummy)"),"caller") assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"))
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
self.d:clean() self.d:clean()
assertFalse(sr.pv.get("$xavp(peer[0]=>dummy)")) assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(peer[1]=>dummy)")) assertFalse(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(peer)")) assertFalse(sr.pv.get("$xavp(peer)"))
end end
function TestNGCPPeerPrefs:test_callee_clean() function TestNGCPPeerPrefs:test_callee_clean()
local callee_xavp = NGCPXAvp:new('callee','peer',{}) local callee_xavp = NGCPPeerPrefs:xavp('callee')
callee_xavp("testid",1) callee_xavp("testid",1)
callee_xavp("foo","foo") callee_xavp("foo","foo")
local caller_xavp = NGCPXAvp:new('caller','peer',{}) local caller_xavp = NGCPPeerPrefs:xavp('caller')
caller_xavp("other",1) caller_xavp("other",1)
caller_xavp("otherfoo","foo") caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(peer[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(peer[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(peer[0]=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(peer[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(peer[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(peer[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
self.d:clean('callee') self.d:clean('callee')
assertEquals(sr.pv.get("$xavp(peer[0]=>dummy)"),'caller') assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),'caller')
assertFalse(sr.pv.get("$xavp(peer[1]=>testid)")) assertFalse(sr.pv.get("$xavp(callee_peer_prefs=>testid)"))
assertFalse(sr.pv.get("$xavp(peer[1]=>foo)")) assertFalse(sr.pv.get("$xavp(callee_peer_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(peer[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(peer[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(peer[1]=>dummy)"),"callee") assertFalse(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"))
end end
function TestNGCPPeerPrefs:test_caller_clean() function TestNGCPPeerPrefs:test_caller_clean()
local callee_xavp = NGCPXAvp:new('callee','peer',{}) local callee_xavp = NGCPPeerPrefs:xavp('callee')
callee_xavp("testid",1) callee_xavp("testid",1)
callee_xavp("foo","foo") callee_xavp("foo","foo")
local caller_xavp = NGCPXAvp:new('caller','peer',{}) local caller_xavp = NGCPPeerPrefs:xavp('caller')
caller_xavp("other",1) caller_xavp("other",1)
caller_xavp("otherfoo","foo") caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(peer[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(peer[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(peer[0]=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(peer[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(peer[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(peer[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
self.d:clean('caller') self.d:clean('caller')
assertEquals(sr.pv.get("$xavp(peer[0]=>dummy)"),'caller') assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(peer[0]=>other)")) assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>other)"))
assertFalse(sr.pv.get("$xavp(peer[0]=>otherfoo)")) assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(peer[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(peer[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(peer[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
end end
-- class TestNGCPPeerPrefs -- class TestNGCPPeerPrefs
---- Control test output:
lu = LuaUnit
lu:setOutputType( "TAP" )
lu:setVerbosity( 1 )
lu:run()
--EOF --EOF

@ -4,12 +4,12 @@ require 'ngcp.utils'
require 'ngcp.rp' require 'ngcp.rp'
require 'tests_v.dp_vars' require 'tests_v.dp_vars'
require 'tests_v.up_vars' require 'tests_v.up_vars'
require 'lemock'
if not sr then if not sr then
require 'mocks.sr' require 'mocks.sr'
sr = srMock:new() sr = srMock:new()
else else
require 'lemock'
argv = {} argv = {}
end end
local mc = nil local mc = nil
@ -46,20 +46,28 @@ TestNGCPRealPrefs = {} --class
end end
function TestNGCPRealPrefs:tearDown() function TestNGCPRealPrefs:tearDown()
sr.pv.vars = {} sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_peer_prefs)")
sr.pv.unset("$xavp(callee_peer_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.log("info", "---cleaned---")
end end
function TestNGCPRealPrefs:test_caller_load() function TestNGCPRealPrefs:test_caller_load()
local keys = {"uno"} local keys = {"uno"}
local xavp = { local xavp = {
domain = NGCPXAvp:new("caller", "domain", {}), domain = NGCPDomainPrefs:xavp("caller"),
user = NGCPXAvp:new("caller", "user", {}), user = NGCPUserPrefs:xavp("caller"),
real = NGCPXAvp:new("caller", "real", {}) real = NGCPRealPrefs:xavp("caller")
} }
xavp.domain("uno",1) xavp.domain("uno",1)
assertEquals(sr.pv.get("$xavp(domain[0]=>uno)"),1) assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>uno)"),1)
xavp.user("uno",2) xavp.user("uno",2)
assertEquals(sr.pv.get("$xavp(user[0]=>uno)"),2) assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>uno)"),2)
local real_keys = self.real:caller_load(keys) local real_keys = self.real:caller_load(keys)
assertEquals(real_keys, keys) assertEquals(real_keys, keys)
assertEquals(xavp.real("uno"),2) assertEquals(xavp.real("uno"),2)
@ -68,14 +76,14 @@ TestNGCPRealPrefs = {} --class
function TestNGCPRealPrefs:test_caller_load1() function TestNGCPRealPrefs:test_caller_load1()
local keys = {"uno", "dos"} local keys = {"uno", "dos"}
local xavp = { local xavp = {
domain = NGCPXAvp:new("caller", "domain", {}), domain = NGCPDomainPrefs:xavp("caller"),
user = NGCPXAvp:new("caller", "user", {}), user = NGCPUserPrefs:xavp("caller"),
real = NGCPXAvp:new("caller", "real", {}) real = NGCPRealPrefs:xavp("caller")
} }
xavp.domain("uno",1) xavp.domain("uno",1)
assertEquals(sr.pv.get("$xavp(domain[0]=>uno)"),1) assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>uno)"),1)
xavp.user("dos",2) xavp.user("dos",2)
assertEquals(sr.pv.get("$xavp(user[0]=>dos)"),2) assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dos)"),2)
local real_keys = self.real:caller_load(keys) local real_keys = self.real:caller_load(keys)
assertEquals(real_keys, keys) assertEquals(real_keys, keys)
assertEquals(xavp.real("uno"),1) assertEquals(xavp.real("uno"),1)
@ -85,14 +93,14 @@ TestNGCPRealPrefs = {} --class
function TestNGCPRealPrefs:test_callee_load() function TestNGCPRealPrefs:test_callee_load()
local keys = {"uno"} local keys = {"uno"}
local xavp = { local xavp = {
domain = NGCPXAvp:new("callee", "domain", {}), domain = NGCPDomainPrefs:xavp("callee"),
user = NGCPXAvp:new("callee", "user", {}), user = NGCPUserPrefs:xavp("callee"),
real = NGCPXAvp:new("callee", "real", {}) real = NGCPRealPrefs:xavp("callee")
} }
xavp.domain("uno",1) xavp.domain("uno",1)
assertEquals(sr.pv.get("$xavp(domain[1]=>uno)"),1) assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>uno)"),1)
xavp.user("uno",2) xavp.user("uno",2)
assertEquals(sr.pv.get("$xavp(user[1]=>uno)"),2) assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>uno)"),2)
local real_keys = self.real:callee_load(keys) local real_keys = self.real:callee_load(keys)
assertEquals(real_keys, keys) assertEquals(real_keys, keys)
assertEquals(xavp.real("uno"),2) assertEquals(xavp.real("uno"),2)
@ -101,81 +109,103 @@ TestNGCPRealPrefs = {} --class
function TestNGCPRealPrefs:test_callee_load1() function TestNGCPRealPrefs:test_callee_load1()
local keys = {"uno", "dos"} local keys = {"uno", "dos"}
local xavp = { local xavp = {
domain = NGCPXAvp:new("callee", "domain", {}), domain = NGCPDomainPrefs:xavp("callee"),
user = NGCPXAvp:new("callee", "user", {}), user = NGCPUserPrefs:xavp("callee"),
real = NGCPXAvp:new("callee", "real", {}) real = NGCPRealPrefs:xavp("callee")
} }
xavp.domain("uno",1) xavp.domain("uno",1)
assertEquals(sr.pv.get("$xavp(domain[1]=>uno)"),1) assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>uno)"),1)
xavp.user("dos",2) xavp.user("dos",2)
assertEquals(sr.pv.get("$xavp(user[1]=>dos)"),2) assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dos)"),2)
local real_keys = self.real:callee_load(keys) local real_keys = self.real:callee_load(keys)
assertEquals(real_keys, keys) assertEquals(real_keys, keys)
assertEquals(xavp.real("uno"),1) assertEquals(xavp.real("uno"),1)
assertEquals(xavp.real("dos"),2) assertEquals(xavp.real("dos"),2)
end end
function TestNGCPRealPrefs:test_set()
assertFalse(sr.pv.get("$xavp(callee_real_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(callee_real_prefs)"))
assertFalse(sr.pv.get("$xavp(callee_real_prefs=>testid)"))
assertFalse(sr.pv.get("$xavp(callee_real_prefs=>foo)"))
local callee_xavp = NGCPRealPrefs:xavp("callee")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),'callee')
callee_xavp("testid", 1)
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"), 1)
callee_xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
end
function TestNGCPRealPrefs:test_clean() function TestNGCPRealPrefs:test_clean()
local xavp = NGCPXAvp:new('callee','real',{}) local callee_xavp = NGCPRealPrefs:xavp("callee")
xavp("testid",1) assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),'callee')
xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(real[1]=>testid)"),1) callee_xavp("testid",1)
assertEquals(sr.pv.get("$xavp(real[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(real[0]=>dummy)"),"caller") callee_xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertFalse(sr.pv.get("$xavp(caller_real_prefs=>dummy)"))
self.real:clean() self.real:clean()
assertFalse(sr.pv.get("$xavp(real[0]=>dummy)"))
assertFalse(sr.pv.get("$xavp(real[1]=>dummy)")) assertFalse(sr.pv.get("$xavp(caller_real_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(real)")) assertFalse(sr.pv.get("$xavp(callee_real_prefs=>dummy)"))
end end
function TestNGCPRealPrefs:test_callee_clean() function TestNGCPRealPrefs:test_callee_clean()
local callee_xavp = NGCPXAvp:new('callee','real',{}) local callee_xavp = NGCPRealPrefs:xavp("callee")
local caller_xavp = NGCPRealPrefs:xavp("caller")
callee_xavp("testid",1) callee_xavp("testid",1)
callee_xavp("foo","foo") callee_xavp("foo","foo")
local caller_xavp = NGCPXAvp:new('caller','real',{})
caller_xavp("other",1) caller_xavp("other",1)
caller_xavp("otherfoo","foo") caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(real[1]=>testid)"),1)
assertEquals(sr.pv.get("$xavp(real[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(real[0]=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(real[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(real[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_real_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(real[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
self.real:clean('callee') self.real:clean('callee')
assertEquals(sr.pv.get("$xavp(real[0]=>dummy)"),'caller')
assertFalse(sr.pv.get("$xavp(real[1]=>testid)")) assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),'caller')
assertFalse(sr.pv.get("$xavp(real[1]=>foo)")) assertFalse(sr.pv.get("$xavp(callee_real_prefs=>testid)"))
assertEquals(sr.pv.get("$xavp(real[0]=>other)"),1) assertFalse(sr.pv.get("$xavp(callee_real_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(real[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_real_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(real[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo")
assertFalse(sr.pv.get("$xavp(callee_real_prefs=>dummy)"))
end end
function TestNGCPRealPrefs:test_caller_clean() function TestNGCPRealPrefs:test_caller_clean()
local callee_xavp = NGCPXAvp:new('callee','real',{}) local callee_xavp = NGCPRealPrefs:xavp("callee")
local caller_xavp = NGCPRealPrefs:xavp("caller")
callee_xavp("testid",1) callee_xavp("testid",1)
callee_xavp("foo","foo") callee_xavp("foo","foo")
local caller_xavp = NGCPXAvp:new('caller','real',{})
caller_xavp("other",1) caller_xavp("other",1)
caller_xavp("otherfoo","foo") caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(real[1]=>testid)"),1)
assertEquals(sr.pv.get("$xavp(real[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(real[0]=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(real[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(real[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_real_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(real[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
self.real:clean('caller') self.real:clean('caller')
assertEquals(sr.pv.get("$xavp(real[0]=>dummy)"),'caller')
assertFalse(sr.pv.get("$xavp(real[0]=>other)")) assertFalse(sr.pv.get("$xavp(caller_real_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(real[0]=>otherfoo)")) assertFalse(sr.pv.get("$xavp(caller_real_prefs=>other)"))
assertEquals(sr.pv.get("$xavp(real[1]=>testid)"),1) assertFalse(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(real[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(real[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
end end
-- class TestNGCPRealPrefs -- class TestNGCPRealPrefs
---- Control test output:
lu = LuaUnit
lu:setOutputType( "TAP" )
lu:setVerbosity( 1 )
lu:run()
--EOF --EOF

@ -1,10 +1,15 @@
#!/usr/bin/env lua5.1 #!/usr/bin/env lua5.1
require('luaunit') require('luaunit')
require 'mocks.sr'
require 'ngcp.utils' require 'ngcp.utils'
require 'tests_v.up_vars' require 'tests_v.up_vars'
require('lemock')
sr = srMock:new()
if not sr then
require 'mocks.sr'
sr = srMock:new()
else
argv = {}
end
local mc = nil local mc = nil
UPFetch = { UPFetch = {
@ -49,7 +54,15 @@ TestNGCPUserPrefs = {} --class
end end
function TestNGCPUserPrefs:tearDown() function TestNGCPUserPrefs:tearDown()
sr.pv.vars = {} sr.pv.unset("$xavp(caller_dom_prefs)")
sr.pv.unset("$xavp(callee_dom_prefs)")
sr.pv.unset("$xavp(caller_peer_prefs)")
sr.pv.unset("$xavp(callee_peer_prefs)")
sr.pv.unset("$xavp(caller_usr_prefs)")
sr.pv.unset("$xavp(callee_usr_prefs)")
sr.pv.unset("$xavp(caller_real_prefs)")
sr.pv.unset("$xavp(callee_real_prefs)")
sr.log("info", "---cleaned---")
end end
function TestNGCPUserPrefs:test_init() function TestNGCPUserPrefs:test_init()
@ -73,10 +86,10 @@ TestNGCPUserPrefs = {} --class
local keys = self.d:caller_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c") local keys = self.d:caller_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c")
mc:verify() mc:verify()
assertEquals(sr.pv.get("$xavp(user[0]=>account_id)"),2) assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>account_id)"),2)
assertEquals(sr.pv.get("$xavp(user[0]=>cli)"),"4311001") assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>cli)"),"4311001")
assertEquals(sr.pv.get("$xavp(user[0]=>cc)"),"43") assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>cc)"),"43")
assertEquals(sr.pv.get("$xavp(user[0]=>ac)"),"1") assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>ac)"),"1")
assertItemsEquals(keys, {"account_id", "cli", "cc", "ac"}) assertItemsEquals(keys, {"account_id", "cli", "cc", "ac"})
end end
@ -96,74 +109,67 @@ TestNGCPUserPrefs = {} --class
local keys = self.d:callee_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c") local keys = self.d:callee_load("ae736f72-21d1-4ea6-a3ea-4d7f56b3887c")
mc:verify() mc:verify()
assertEquals(sr.pv.get("$xavp(user[1]=>account_id)"),2) assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>account_id)"),2)
assertEquals(sr.pv.get("$xavp(user[1]=>cli)"),"4311001") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>cli)"),"4311001")
assertEquals(sr.pv.get("$xavp(user[1]=>cc)"),"43") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>cc)"),"43")
assertEquals(sr.pv.get("$xavp(user[1]=>ac)"),"1") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>ac)"),"1")
assertItemsEquals(keys, {"account_id", "cli", "cc", "ac"}) assertItemsEquals(keys, {"account_id", "cli", "cc", "ac"})
end end
function TestNGCPUserPrefs:test_clean() function TestNGCPUserPrefs:test_clean()
local xavp = NGCPXAvp:new('callee','user',{}) local xavp = NGCPUserPrefs:xavp('callee')
xavp("testid",1) xavp("testid",1)
xavp("foo","foo") xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(user[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(user[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(user[0]=>dummy)"),"caller") assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
self.d:clean() self.d:clean()
assertFalse(sr.pv.get("$xavp(user[0]=>dummy)")) assertFalse(sr.pv.get("$xavp(caller_usr_prefs)"))
assertFalse(sr.pv.get("$xavp(user[1]=>dummy)")) assertFalse(sr.pv.get("$xavp(callee_usr_prefs)"))
assertFalse(sr.pv.get("$xavp(user)"))
end end
function TestNGCPUserPrefs:test_callee_clean() function TestNGCPUserPrefs:test_callee_clean()
local callee_xavp = NGCPXAvp:new('callee','user',{}) local callee_xavp = NGCPUserPrefs:xavp('callee')
callee_xavp("testid",1) callee_xavp("testid",1)
callee_xavp("foo","foo") callee_xavp("foo","foo")
local caller_xavp = NGCPXAvp:new('caller','user',{}) local caller_xavp = NGCPUserPrefs:xavp('caller')
caller_xavp("other",1) caller_xavp("other",1)
caller_xavp("otherfoo","foo") caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(user[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(user[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(user[0]=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(user[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(user[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(user[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
self.d:clean('callee') self.d:clean('callee')
assertEquals(sr.pv.get("$xavp(user[0]=>dummy)"),'caller') assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),'caller')
assertFalse(sr.pv.get("$xavp(user[1]=>testid)")) assertFalse(sr.pv.get("$xavp(callee_usr_prefs=>testid)"))
assertFalse(sr.pv.get("$xavp(user[1]=>foo)")) assertFalse(sr.pv.get("$xavp(callee_usr_prefs=>foo)"))
assertEquals(sr.pv.get("$xavp(user[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(user[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(user[1]=>dummy)"),"callee") assertFalse(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"))
end end
function TestNGCPUserPrefs:test_caller_clean() function TestNGCPUserPrefs:test_caller_clean()
local callee_xavp = NGCPXAvp:new('callee','user',{}) local callee_xavp = NGCPUserPrefs:xavp('callee')
callee_xavp("testid",1) callee_xavp("testid",1)
callee_xavp("foo","foo") callee_xavp("foo","foo")
local caller_xavp = NGCPXAvp:new('caller','user',{}) local caller_xavp = NGCPUserPrefs:xavp('caller')
caller_xavp("other",1) caller_xavp("other",1)
caller_xavp("otherfoo","foo") caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(user[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(user[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(user[0]=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(user[0]=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(user[0]=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(user[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
self.d:clean('caller') self.d:clean('caller')
assertEquals(sr.pv.get("$xavp(user[0]=>dummy)"),'caller') assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"))
assertFalse(sr.pv.get("$xavp(user[0]=>other)")) assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>other)"))
assertFalse(sr.pv.get("$xavp(user[0]=>otherfoo)")) assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>otherfoo)"))
assertEquals(sr.pv.get("$xavp(user[1]=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(user[1]=>foo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(user[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
end end
-- class TestNGCPUserPrefs -- class TestNGCPUserPrefs
---- Control test output:
lu = LuaUnit
lu:setOutputType( "TAP" )
lu:setVerbosity( 1 )
lu:run()
--EOF --EOF

@ -1,9 +1,14 @@
#!/usr/bin/env lua5.1 #!/usr/bin/env lua5.1
require('luaunit') require('luaunit')
require 'mocks.sr'
require 'ngcp.xavp' require 'ngcp.xavp'
sr = srMock:new() if not sr then
require 'mocks.sr'
sr = srMock:new()
else
argv = {}
end
vals = { vals = {
{ {
id = 1, id = 1,
@ -37,60 +42,73 @@ vals = {
} }
} }
TestNGCPXAvp = {} --class TestNGCPXAvp = {} --class
function TestNGCPXAvp:setUp() function TestNGCPXAvp:test_create()
self.xavp = NGCPXAvp:new("caller", "peer", vals) local xavp = NGCPXAvp:new("caller", "peer", {})
end assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"),"caller")
xavp = NGCPXAvp:new("callee", "peer", {})
function TestNGCPXAvp:tearDown() assertEquals(sr.pv.get("$xavp(callee_peer=>dummy)"),"callee")
sr.pv.vars = {}
end end
function TestNGCPXAvp:test_xavp_id() function TestNGCPXAvp:test_xavp_id()
assertEquals(self.xavp.level, 0) local xavp = NGCPXAvp:new("caller", "peer", vals)
assertEquals(self.xavp.group, "peer") assertEquals(xavp.level, "caller")
assertEquals(xavp.group, "peer")
assertEquals(xavp.name, "caller_peer")
assertItemsEquals(xavp.keys, {"account_id","whatever","elsewhere"})
end end
function TestNGCPXAvp:test_xavp_get() function TestNGCPXAvp:test_xavp_get()
sr.pv.sets("$xavp(peer[0]=>testid)", "value") xavp = NGCPXAvp:new("caller", "peer", vals)
assertEquals(self.xavp("testid"), "value") sr.pv.sets("$xavp(caller_peer=>testid)", "value")
sr.pv.sets("$xavp(peer[0]=>testid)", "1") assertEquals(xavp("testid"), "value")
assertItemsEquals(self.xavp("testid"), "1") sr.pv.sets("$xavp(caller_peer=>testid)", "1")
assertItemsEquals(xavp("testid"), "1")
end end
function TestNGCPXAvp:test_xavp_set() function TestNGCPXAvp:test_xavp_set()
local xavp = NGCPXAvp:new("caller", "peer", vals)
local vals = {1,"2",3,nil} local vals = {1,"2",3,nil}
for i=1,#vals do for i=1,#vals do
self.xavp("testid",vals[i]) xavp("testid",vals[i])
assertEquals(self.xavp("testid"), vals[i]) assertEquals(xavp("testid"), vals[i])
assertEquals(sr.pv.get("$xavp(peer[0]=>testid)"),vals[i]) assertEquals(sr.pv.get("$xavp(caller_peer=>testid)"),vals[i])
end end
end end
function TestNGCPXAvp:test_clean() function TestNGCPXAvp:test_clean()
self.xavp("testid", 1) xavp = NGCPXAvp:new("caller", "peer", vals)
assertEquals(sr.pv.get("$xavp(peer[0]=>testid)"),1) xavp("testid", 1)
assertEquals(sr.pv.get("$xavp(peer[0]=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(caller_peer=>testid)"),1)
assertEquals(sr.pv.get("$xavp(peer[1]=>dummy)"),"callee") assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"),"caller")
self.xavp:clean() xavp:clean()
assertFalse(self.xavp("testid")) assertFalse(xavp("testid"))
assertFalse(sr.pv.get("$xavp(peer[0]=>testid)")) assertFalse(sr.pv.get("$xavp(caller_peer=>testid)"))
assertEquals(sr.pv.get("$xavp(peer[0]=>dummy)"),"caller") assertFalse(sr.pv.get("$xavp(caller_peer)"))
assertEquals(sr.pv.get("$xavp(peer[1]=>dummy)"),"callee") end
function TestNGCPXAvp:test_clean_all()
local xavp_caller = NGCPXAvp:new("caller", "peer", {})
assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"),"caller")
local xavp_callee = NGCPXAvp:new("callee", "peer", {})
assertEquals(sr.pv.get("$xavp(callee_peer=>dummy)"),"callee")
xavp_caller:clean()
assertFalse(sr.pv.get("$xavp(caller_peer=>dummy)"))
assertEquals(sr.pv.get("$xavp(callee_peer=>dummy)"),"callee")
xavp_callee:clean()
assertFalse(sr.pv.get("$xavp(callee_peer=>dummy)"))
assertFalse(sr.pv.get("$xavp(caller_peer=>dummy)"))
end end
function TestNGCPXAvp:test_keys() function TestNGCPXAvp:test_keys()
assertItemsEquals(self.xavp.keys, {"account_id","whatever","elsewhere"}) local xavp = NGCPXAvp:new("caller", "peer", vals)
self.xavp("testid", 1) xavp("testid", 1)
assertItemsEquals(self.xavp.keys, {"account_id","whatever","elsewhere","testid"}) assertItemsEquals(xavp.keys, {"account_id","whatever","elsewhere","testid"})
self.xavp:clean() xavp:clean()
assertItemsEquals(self.xavp.keys, {"account_id","whatever","elsewhere","testid"}) assertItemsEquals(xavp.keys, {"account_id","whatever","elsewhere","testid"})
end end
-- class TestNGCPXAvp -- class TestNGCPXAvp
---- Control test output:
lu = LuaUnit
lu:setOutputType( "TAP" )
lu:setVerbosity( 1 )
lu:run()
--EOF --EOF

@ -0,0 +1,13 @@
require 'tests.utils'
require 'tests.mocks'
require 'tests.ngcp_xavp'
require 'tests.ngcp_dp'
require 'tests.ngcp_up'
require 'tests.ngcp_pp'
require 'tests.ngcp_rp'
require 'tests.ngcp'
---- Control test output:
lu = LuaUnit
lu:setOutputType( "TAP" )
lu:setVerbosity( 1 )
lu:run()

@ -0,0 +1,11 @@
require 'tests.utils'
require 'tests.ngcp_xavp'
require 'tests.ngcp_dp'
require 'tests.ngcp_up'
require 'tests.ngcp_pp'
require 'tests.ngcp_rp'
---- Control test output:
lu = LuaUnit
lu:setOutputType( "TAP" )
lu:setVerbosity( 1 )
lu:run()

@ -1,6 +1,5 @@
#!/usr/bin/env lua5.1 #!/usr/bin/env lua5.1
require('luaunit') require('luaunit')
require 'mocks.sr'
require 'ngcp.utils' require 'ngcp.utils'
TestUtils = {} --class TestUtils = {} --class
@ -109,9 +108,4 @@ TestStack = {}
assertEquals(tostring(s), "{2,1}") assertEquals(tostring(s), "{2,1}")
end end
-- class TestStack -- class TestStack
---- Control test output:
lu = LuaUnit
lu:setOutputType( "TAP" )
lu:setVerbosity( 1 )
lu:run()
--EOF --EOF
Loading…
Cancel
Save