diff --git a/ngcp/dp.lua b/ngcp/dp.lua index 731a4fa..deb0657 100644 --- a/ngcp/dp.lua +++ b/ngcp/dp.lua @@ -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, diff --git a/ngcp/ngcp.lua b/ngcp/ngcp.lua index 3098f2d..ab00266 100644 --- a/ngcp/ngcp.lua +++ b/ngcp/ngcp.lua @@ -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 ) diff --git a/ngcp/pp.lua b/ngcp/pp.lua index d90f82c..978e6f2 100644 --- a/ngcp/pp.lua +++ b/ngcp/pp.lua @@ -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, diff --git a/ngcp/rp.lua b/ngcp/rp.lua index 9cf7526..41beb3d 100644 --- a/ngcp/rp.lua +++ b/ngcp/rp.lua @@ -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 diff --git a/ngcp/up.lua b/ngcp/up.lua index 5f876cf..58a6013 100644 --- a/ngcp/up.lua +++ b/ngcp/up.lua @@ -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, diff --git a/ngcp/xavp.lua b/ngcp/xavp.lua index a14a05d..bcf157e 100644 --- a/ngcp/xavp.lua +++ b/ngcp/xavp.lua @@ -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 \ No newline at end of file diff --git a/tests/ngcp.lua b/tests/ngcp.lua index 797b709..28bbe08 100644 --- a/tests/ngcp.lua +++ b/tests/ngcp.lua @@ -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() diff --git a/tests/ngcp_dp.lua b/tests/ngcp_dp.lua index 15505fb..4dfd702 100644 --- a/tests/ngcp_dp.lua +++ b/tests/ngcp_dp.lua @@ -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 \ No newline at end of file diff --git a/tests/ngcp_pp.lua b/tests/ngcp_pp.lua index eba7f22..5a820c7 100644 --- a/tests/ngcp_pp.lua +++ b/tests/ngcp_pp.lua @@ -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 \ No newline at end of file diff --git a/tests/ngcp_rp.lua b/tests/ngcp_rp.lua index d8fed69..f808d02 100644 --- a/tests/ngcp_rp.lua +++ b/tests/ngcp_rp.lua @@ -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 \ No newline at end of file diff --git a/tests/ngcp_up.lua b/tests/ngcp_up.lua index a517495..8d7eac8 100644 --- a/tests/ngcp_up.lua +++ b/tests/ngcp_up.lua @@ -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 \ No newline at end of file diff --git a/tests/ngcp_xavp.lua b/tests/ngcp_xavp.lua index 25d830f..071f324 100644 --- a/tests/ngcp_xavp.lua +++ b/tests/ngcp_xavp.lua @@ -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()