Added __tostring() properly to ngcp, xavp and prefs

squeeze-backports
Victor Seva 13 years ago
parent 6ed63ee7c7
commit 9a3a80834a

@ -8,6 +8,15 @@ NGCPDomainPrefs = {
}
NGCPDomainPrefs_MT = { __index = NGCPDomainPrefs }
NGCPDomainPrefs_MT.__tostring = function ()
local output = ''
local xavp = NGCPXAvp:new('caller','dom_prefs')
output = string.format("caller_dom_prefs:%s\n", tostring(xavp))
xavp = NGCPXAvp:new('callee','dom_prefs')
output = output .. string.format("callee_dom_prefs:%s\n", tostring(xavp))
return output
end
function NGCPDomainPrefs:new(config)
local t = {
config = config,

@ -53,6 +53,15 @@ NGCP = {
}
NGCP_MT = { __index = NGCP }
NGCP_MT.__tostring = function (t)
local k,v
output = ''
for k,v in pairs(t.prefs) do
output = output .. tostring(v)
end
return output
end
function NGCP:new()
local t = NGCP.init()
setmetatable( t, NGCP_MT )

@ -8,6 +8,15 @@ NGCPPeerPrefs = {
}
NGCPPeerPrefs_MT = { __index = NGCPPeerPrefs }
NGCPPeerPrefs_MT.__tostring = function ()
local output = ''
local xavp = NGCPXAvp:new('caller','peer_prefs')
output = string.format("caller_peer_prefs:%s\n", tostring(xavp))
xavp = NGCPXAvp:new('callee','peer_prefs')
output = output .. string.format("callee_peer_prefs:%s\n", tostring(xavp))
return output
end
function NGCPPeerPrefs:new(config)
local t = {
config = config,

@ -8,6 +8,15 @@ NGCPRealPrefs = {
}
NGCPRealPrefs_MT = { __index = NGCPRealPrefs }
NGCPRealPrefs_MT.__tostring = function ()
local output = ''
local xavp = NGCPXAvp:new('caller','real_prefs')
output = string.format("caller_real_prefs:%s\n", tostring(xavp))
xavp = NGCPXAvp:new('callee','real_prefs')
output = output .. string.format("callee_real_prefs:%s\n", tostring(xavp))
return output
end
function NGCPRealPrefs:new()
local t = {}
-- creates xavp real

@ -8,6 +8,15 @@ NGCPUserPrefs = {
}
NGCPUserPrefs_MT = { __index = NGCPUserPrefs }
NGCPUserPrefs_MT.__tostring = function ()
local output = ''
local xavp = NGCPXAvp:new('caller','usr_prefs')
output = string.format("caller_usr_prefs:%s\n", tostring(xavp))
xavp = NGCPXAvp:new('callee','usr_prefs')
output = output .. string.format("callee_usr_prefs:%s\n", tostring(xavp))
return output
end
function NGCPUserPrefs:new(config)
local t = {
config = config,

@ -30,6 +30,17 @@ NGCPXAvp_MT = {
error("value is not a number or string")
end
end
NGCPXAvp_MT.__tostring = function (t)
local l,k,v
local output
l = sr.xavp.get(t.name, 0)
if l then
output = table.tostring(l)
end
sr.log("dbg", string.format("output:%s", output))
return output
end
setmetatable( t, NGCPXAvp_MT )
return t
end
@ -103,17 +114,5 @@ NGCPXAvp_MT = {
sr.pv.unset(string.format("$xavp(%s)", self.name))
sr.pv.sets(string.format("$xavp(%s=>dummy)", self.name), self.level)
end
function NGCPXAvp.__tostring(xavp)
local l,k,v
local output
l = sr.xavp.get(xavp.name, 0)
if l then
output = table.tostring(l)
end
sr.log("dbg", string.format("output:%s", output))
return output
end
-- class
--EOF

@ -504,6 +504,10 @@ TestNGCP = {} --class
assertEquals(sr.pv.get("$avp(s:caller_ip_header)"), nil)
end
function TestNGCP:test_tostring()
assertEquals(tostring(self.ngcp), 'caller_usr_prefs:{dummy="caller"}\ncallee_usr_prefs:{dummy="callee"}\ncaller_real_prefs:{dummy="caller"}\ncallee_real_prefs:{dummy="callee"}\ncaller_peer_prefs:{dummy="caller"}\ncallee_peer_prefs:{dummy="callee"}\ncaller_dom_prefs:{dummy="caller"}\ncallee_dom_prefs:{dummy="callee"}\n')
end
function TestNGCP:test_log_var()
self:test_caller_usr_load()
self.ngcp:log_var()

@ -156,5 +156,15 @@ TestNGCPDomainPrefs = {} --class
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee")
end
function TestNGCPDomainPrefs:test_tostring()
local callee_xavp = NGCPDomainPrefs:xavp('callee')
callee_xavp("testid",1)
callee_xavp("foo","foo")
local caller_xavp = NGCPDomainPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(tostring(self.d), 'caller_dom_prefs:{other=1,otherfoo="foo",dummy="caller"}\ncallee_dom_prefs:{dummy="callee",testid=1,foo="foo"}\n')
end
-- class TestNGCPDomainPrefs
--EOF

@ -157,5 +157,15 @@ TestNGCPPeerPrefs = {} --class
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee")
end
function TestNGCPPeerPrefs:test_tostring()
local callee_xavp = NGCPPeerPrefs:xavp('callee')
callee_xavp("testid",1)
callee_xavp("foo","foo")
local caller_xavp = NGCPPeerPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(tostring(self.d), 'caller_peer_prefs:{other=1,otherfoo="foo",dummy="caller"}\ncallee_peer_prefs:{dummy="callee",testid=1,foo="foo"}\n')
end
-- class TestNGCPPeerPrefs
--EOF

@ -174,9 +174,9 @@ TestNGCPRealPrefs = {} --class
callee_xavp("foo","foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
self.real:clean()
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
end
@ -187,19 +187,19 @@ TestNGCPRealPrefs = {} --class
callee_xavp("testid",1)
callee_xavp("foo","foo")
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
self.real:clean('callee')
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),'caller')
assertFalse(sr.pv.get("$xavp(callee_real_prefs=>testid)"))
assertFalse(sr.pv.get("$xavp(callee_real_prefs=>foo)"))
@ -214,19 +214,19 @@ TestNGCPRealPrefs = {} --class
callee_xavp("testid",1)
callee_xavp("foo","foo")
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1)
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>other)"),1)
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
self.real:clean('caller')
assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller")
assertFalse(sr.pv.get("$xavp(caller_real_prefs=>other)"))
assertFalse(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"))
@ -234,5 +234,15 @@ TestNGCPRealPrefs = {} --class
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee")
end
function TestNGCPRealPrefs:test_tostring()
local callee_xavp = NGCPRealPrefs:xavp("callee")
local caller_xavp = NGCPRealPrefs:xavp("caller")
callee_xavp("testid",1)
callee_xavp("foo","foo")
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(tostring(self.real),'caller_real_prefs:{other=1,otherfoo="foo",dummy="caller"}\ncallee_real_prefs:{dummy="callee",testid=1,foo="foo"}\n')
end
-- class TestNGCPRealPrefs
--EOF

@ -107,7 +107,7 @@ TestNGCPUserPrefs = {} --class
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>ac)"),"1")
assertItemsEquals(keys, {"account_id", "cli", "cc", "ac"})
end
function TestNGCPUserPrefs:test_clean()
local xavp = NGCPUserPrefs:xavp('callee')
xavp("testid",1)
@ -163,5 +163,15 @@ TestNGCPUserPrefs = {} --class
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo")
assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee")
end
function TestNGCPUserPrefs:test_tostring()
local callee_xavp = NGCPUserPrefs:xavp('callee')
callee_xavp("testid",1)
callee_xavp("foo","foo")
local caller_xavp = NGCPUserPrefs:xavp('caller')
caller_xavp("other",1)
caller_xavp("otherfoo","foo")
assertEquals(tostring(self.d),'caller_usr_prefs:{other=1,otherfoo="foo",dummy="caller"}\ncallee_usr_prefs:{dummy="callee",testid=1,foo="foo"}\n')
end
-- class TestNGCPUserPrefs
--EOF

@ -103,7 +103,7 @@ TestNGCPXAvp = {} --class
function TestNGCPXAvp:test_tostring()
local xavp = NGCPXAvp:new("caller", "peer", {})
assertEquals(xavp:__tostring(), '{dummy="caller"}')
assertEquals(tostring(xavp), '{dummy="caller"}')
end
function TestNGCPXAvp:test_keys()

Loading…
Cancel
Save