From 4acb0d5131b2b75431f25a78e63fbbfd644c566e Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Thu, 11 Apr 2013 13:14:55 +0200 Subject: [PATCH] Initializate dummy vars just in the creation. On clear... create them. --- ngcp/dp.lua | 4 +++- ngcp/pp.lua | 2 ++ ngcp/pref.lua | 43 ++++++------------------------------------- ngcp/rp.lua | 4 +++- ngcp/up.lua | 4 +++- ngcp/xavp.lua | 2 ++ tests/ngcp.lua | 38 +++++++++++++++++++++++++++----------- tests/ngcp_dp.lua | 10 +++++----- tests/ngcp_pp.lua | 10 +++++----- tests/ngcp_rp.lua | 14 +++++++------- tests/ngcp_up.lua | 10 +++++----- tests/ngcp_xavp.lua | 8 ++++---- 12 files changed, 72 insertions(+), 77 deletions(-) diff --git a/ngcp/dp.lua b/ngcp/dp.lua index 28e71e0..731a4fa 100644 --- a/ngcp/dp.lua +++ b/ngcp/dp.lua @@ -1,6 +1,6 @@ #!/usr/bin/env lua5.1 require 'ngcp.utils' -require 'ngcp.xavp' +require 'ngcp.pref' -- class NGCPDomainPrefs NGCPDomainPrefs = { @@ -13,6 +13,8 @@ NGCPDomainPrefs_MT = { __index = NGCPDomainPrefs } config = config, db_table = "dom_preferences" } + -- creates xavp dom + NGCPPrefs.init("dom_prefs") return setmetatable( t, NGCPDomainPrefs_MT ) end diff --git a/ngcp/pp.lua b/ngcp/pp.lua index 8d5b640..d90f82c 100644 --- a/ngcp/pp.lua +++ b/ngcp/pp.lua @@ -13,6 +13,8 @@ NGCPPeerPrefs_MT = { __index = NGCPPeerPrefs } config = config, db_table = "peer_preferences" } + -- creates xavp peer + NGCPPrefs.init("peer_prefs") return setmetatable( t, NGCPPeerPrefs_MT ) end diff --git a/ngcp/pref.lua b/ngcp/pref.lua index 5db0a5e..a49c6f8 100644 --- a/ngcp/pref.lua +++ b/ngcp/pref.lua @@ -1,5 +1,5 @@ #!/usr/bin/env lua5.1 -require 'ngcp.kam_utils' +require 'ngcp.xavp' -- class NGCPPrefs NGCPPrefs = { @@ -7,44 +7,13 @@ NGCPPrefs = { } NGCPPrefs_MT = { __index = NGCPPrefs } - function NGCPPrefs:new() - local t = NGCPPrefs.init() - setmetatable( t, NGCPPrefs_MT ) - return t - end - - function NGCPPrefs.init() - local t = { - inbound = {}, - outbound = {}, - common = {}, - groups = {'inbound', 'outbound', 'common'} - } - --print("NGCPPrefs:init" .. "\n" .. table.tostring(t)) - return t - end - - function NGCPPrefs._cleanvars(t) - for k,_ in pairs(t) do - t[k] = "" + function NGCPPrefs.init(group) + local _,v, xavp + local levels = {"caller", "callee"} + for _,v in pairs(levels) do + xavp = NGCPXAvp.init(v,group) end end - function NGCPPrefs:clean(group) - --print("NGCPPrefs:clean") - --print(table.tostring(getmetatable(self))) - --print(table.tostring(self)) - if group then - if self[group] then - clean_avp(self[group]) - NGCPPrefs._cleanvars(self[group]) - end - else - for k,v in pairs(self.groups) do - clean_avp(self[v]) - NGCPPrefs._cleanvars(self[v]) - end - end - end -- class --EOF \ No newline at end of file diff --git a/ngcp/rp.lua b/ngcp/rp.lua index 9620fc0..eb3617f 100644 --- a/ngcp/rp.lua +++ b/ngcp/rp.lua @@ -1,6 +1,6 @@ #!/usr/bin/env lua5.1 require 'ngcp.utils' -require 'ngcp.xavp' +require 'ngcp.pref' -- class NGCPRealPrefs NGCPRealPrefs = { @@ -10,6 +10,8 @@ NGCPRealPrefs_MT = { __index = NGCPRealPrefs } function NGCPRealPrefs:new() local t = {} + -- creates xavp real + NGCPPrefs.init("real_prefs") return setmetatable( t, NGCPRealPrefs_MT ) end diff --git a/ngcp/up.lua b/ngcp/up.lua index 9159ab2..5f876cf 100644 --- a/ngcp/up.lua +++ b/ngcp/up.lua @@ -1,6 +1,6 @@ #!/usr/bin/env lua5.1 require 'ngcp.utils' -require 'ngcp.xavp' +require 'ngcp.pref' -- class NGCPUserPrefs NGCPUserPrefs = { @@ -13,6 +13,8 @@ NGCPUserPrefs_MT = { __index = NGCPUserPrefs } config = config, db_table = "usr_preferences" } + -- creates xavp usr + NGCPPrefs.init("usr_prefs") return setmetatable( t, NGCPUserPrefs_MT ) end diff --git a/ngcp/xavp.lua b/ngcp/xavp.lua index 3f7e961..908b87a 100644 --- a/ngcp/xavp.lua +++ b/ngcp/xavp.lua @@ -90,6 +90,7 @@ NGCPXAvp_MT = { local name = string.format("$xavp(%s=>dummy)", self.name) if not sr.pv.get(name) then NGCPXAvp._setvalue(name, 0, self.level) + sr.log("dbg",string.format("%s created with dummy value:%s", name, self.level)) end for i=1,#l do name = string.format("$xavp(%s[0]=>%s)", self.name, l[i].attribute) @@ -100,6 +101,7 @@ NGCPXAvp_MT = { function NGCPXAvp:clean() sr.pv.unset(string.format("$xavp(%s)", self.name)) + sr.pv.sets(string.format("$xavp(%s=>dummy)", self.name), self.level) end -- class --EOF \ No newline at end of file diff --git a/tests/ngcp.lua b/tests/ngcp.lua index b01c292..703f04e 100644 --- a/tests/ngcp.lua +++ b/tests/ngcp.lua @@ -23,10 +23,12 @@ require 'ngcp.ngcp' TestNGCP = {} --class function TestNGCP:setUp() + sr.log("dbg", "TestNGCP:setUp") self.ngcp = NGCP:new() end function TestNGCP:tearDown() + sr.log("dbg", "TestNGCP:tearDown") sr.pv.unset("$xavp(caller_dom_prefs)") sr.pv.unset("$xavp(callee_dom_prefs)") sr.pv.unset("$xavp(caller_peer_prefs)") @@ -55,13 +57,21 @@ TestNGCP = {} --class end function TestNGCP:test_prefs_init() - --print("TestNGCP:test_prefs_init") + sr.log("dbg", "TestNGCP:test_prefs_init") assertTrue(self.ngcp) assertTrue(self.ngcp.prefs) assertTrue(self.ngcp.prefs.peer) + assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller") + assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") assertTrue(self.ngcp.prefs.usr) + assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller") + assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee") assertTrue(self.ngcp.prefs.dom) + assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller") + assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee") assertTrue(self.ngcp.prefs.real) + assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller") + assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee") end function TestNGCP:test_caller_usr_load_empty() @@ -86,10 +96,10 @@ TestNGCP = {} --class xavp("foo","foo") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo") - assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"), "caller") self.ngcp:clean() - assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>dummy)")) - assertFalse(sr.pv.get("$xavp(callee_usr_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller") + assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee") assertFalse(sr.pv.get("$xavp(user)")) end @@ -98,21 +108,27 @@ TestNGCP = {} --class local _,v for _,v in pairs(groups) do - assertEquals(sr.pv.get(string.format("$xavp(caller_%s_prefs=>dummy)", v), "caller")) + xavp = self.ngcp.prefs[v]:xavp("caller") + xavp(string.format("test_%s", v), v) + assertEquals(sr.pv.get(string.format("$xavp(caller_%s_prefs=>test_%s)", v, v)), v) + assertEquals(sr.pv.get(string.format("$xavp(caller_%s_prefs=>dummy)", v)), "caller") self.ngcp:clean("caller", v) - assertFalse(sr.pv.get(string.format("$xavp(caller_%s_prefs=>dummy)", v))) + assertEquals(sr.pv.get(string.format("$xavp(caller_%s_prefs=>dummy)", v)), "caller") end assertError(self.ngcp.clean, self.ngcp, "caller", "whatever") end function TestNGCP:test_clean_callee_groups() local groups = {"peer", "usr", "dom", "real"} - local _,v + local _,v, xavp for _,v in pairs(groups) do - assertEquals(sr.pv.get(string.format("$xavp(callee_%s_prefs=>dummy)", v), "callee")) + xavp = self.ngcp.prefs[v]:xavp("callee") + xavp(string.format("test_%s", v), v) + assertEquals(sr.pv.get(string.format("$xavp(callee_%s_prefs=>test_%s)", v, v)), v) + assertEquals(sr.pv.get(string.format("$xavp(callee_%s_prefs=>dummy)", v)), "callee") self.ngcp:clean("callee", v) - assertFalse(sr.pv.get(string.format("$xavp(callee_%s_prefs=>dummy)", v))) + assertEquals(sr.pv.get(string.format("$xavp(callee_%s_prefs=>dummy)", v)), "callee") end assertError(self.ngcp.clean, self.ngcp, "callee", "whatever") end @@ -136,7 +152,7 @@ TestNGCP = {} --class assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>foo)")) assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo") - assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"), "callee") end function TestNGCP:test_caller_clean() @@ -153,7 +169,7 @@ TestNGCP = {} --class assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") self.ngcp:clean('caller') - assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller") assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>other)")) assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)")) assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1) diff --git a/tests/ngcp_dp.lua b/tests/ngcp_dp.lua index 7814c4a..e6fa765 100644 --- a/tests/ngcp_dp.lua +++ b/tests/ngcp_dp.lua @@ -124,10 +124,10 @@ TestNGCPDomainPrefs = {} --class xavp("foo","foo") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>foo)"),"foo") - assertFalse(sr.pv.get("$xavp(caller_dom_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller") self.d:clean() - assertFalse(sr.pv.get("$xavp(caller_dom_prefs=>dummy)")) - assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller") + assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee") assertFalse(sr.pv.get("$xavp(domain)")) end @@ -150,7 +150,7 @@ TestNGCPDomainPrefs = {} --class assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>foo)")) assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo") - assertFalse(sr.pv.get("$xavp(callee_dom_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee") end function TestNGCPDomainPrefs:test_caller_clean() @@ -167,7 +167,7 @@ TestNGCPDomainPrefs = {} --class assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>dummy)"),"callee") self.d:clean('caller') - assertFalse(sr.pv.get("$xavp(caller_dom_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_dom_prefs=>dummy)"),"caller") assertFalse(sr.pv.get("$xavp(caller_dom_prefs=>other)")) assertFalse(sr.pv.get("$xavp(caller_dom_prefs=>otherfoo)")) assertEquals(sr.pv.get("$xavp(callee_dom_prefs=>testid)"),1) diff --git a/tests/ngcp_pp.lua b/tests/ngcp_pp.lua index 044dee2..37c88bc 100644 --- a/tests/ngcp_pp.lua +++ b/tests/ngcp_pp.lua @@ -124,11 +124,11 @@ TestNGCPPeerPrefs = {} --class xavp("foo","foo") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo") - assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") self.d:clean() - assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>dummy)")) - assertFalse(sr.pv.get("$xavp(callee_peer_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller") + assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") assertFalse(sr.pv.get("$xavp(peer)")) end @@ -151,7 +151,7 @@ TestNGCPPeerPrefs = {} --class assertFalse(sr.pv.get("$xavp(callee_peer_prefs=>foo)")) assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo") - assertFalse(sr.pv.get("$xavp(callee_peer_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") end function TestNGCPPeerPrefs:test_caller_clean() @@ -168,7 +168,7 @@ TestNGCPPeerPrefs = {} --class assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") self.d:clean('caller') - assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller") assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>other)")) assertFalse(sr.pv.get("$xavp(caller_peer_prefs=>otherfoo)")) assertEquals(sr.pv.get("$xavp(callee_peer_prefs=>testid)"),1) diff --git a/tests/ngcp_rp.lua b/tests/ngcp_rp.lua index 3c5dafa..06901e4 100644 --- a/tests/ngcp_rp.lua +++ b/tests/ngcp_rp.lua @@ -150,8 +150,8 @@ TestNGCPRealPrefs = {} --class end function TestNGCPRealPrefs:test_set() - assertFalse(sr.pv.get("$xavp(callee_real_prefs=>dummy)")) - assertFalse(sr.pv.get("$xavp(callee_real_prefs)")) + assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"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)")) @@ -172,12 +172,12 @@ TestNGCPRealPrefs = {} --class assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1) callee_xavp("foo","foo") assertEquals(sr.pv.get("$xavp(callee_real_prefs=>foo)"),"foo") - assertFalse(sr.pv.get("$xavp(caller_real_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller") self.real:clean() - assertFalse(sr.pv.get("$xavp(caller_real_prefs=>dummy)")) - assertFalse(sr.pv.get("$xavp(callee_real_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_real_prefs=>dummy)"),"caller") + assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee") end function TestNGCPRealPrefs:test_callee_clean() @@ -204,7 +204,7 @@ TestNGCPRealPrefs = {} --class assertFalse(sr.pv.get("$xavp(callee_real_prefs=>foo)")) assertEquals(sr.pv.get("$xavp(caller_real_prefs=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_real_prefs=>otherfoo)"),"foo") - assertFalse(sr.pv.get("$xavp(callee_real_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee") end function TestNGCPRealPrefs:test_caller_clean() @@ -226,7 +226,7 @@ TestNGCPRealPrefs = {} --class self.real:clean('caller') - assertFalse(sr.pv.get("$xavp(caller_real_prefs=>dummy)")) + 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)")) assertEquals(sr.pv.get("$xavp(callee_real_prefs=>testid)"),1) diff --git a/tests/ngcp_up.lua b/tests/ngcp_up.lua index 1660179..a5628cc 100644 --- a/tests/ngcp_up.lua +++ b/tests/ngcp_up.lua @@ -132,10 +132,10 @@ TestNGCPUserPrefs = {} --class xavp("foo","foo") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1) assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>foo)"),"foo") - assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller") + assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller") self.d:clean() - assertFalse(sr.pv.get("$xavp(caller_usr_prefs)")) - assertFalse(sr.pv.get("$xavp(callee_usr_prefs)")) + assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"), "caller") + assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"), "callee") end function TestNGCPUserPrefs:test_callee_clean() @@ -157,7 +157,7 @@ TestNGCPUserPrefs = {} --class assertFalse(sr.pv.get("$xavp(callee_usr_prefs=>foo)")) assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>other)"),1) assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>otherfoo)"),"foo") - assertFalse(sr.pv.get("$xavp(callee_usr_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee") end function TestNGCPUserPrefs:test_caller_clean() @@ -174,7 +174,7 @@ TestNGCPUserPrefs = {} --class assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>otherfoo)"),"foo") assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>dummy)"),"callee") self.d:clean('caller') - assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>dummy)")) + assertEquals(sr.pv.get("$xavp(caller_usr_prefs=>dummy)"),"caller") assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>other)")) assertFalse(sr.pv.get("$xavp(caller_usr_prefs=>otherfoo)")) assertEquals(sr.pv.get("$xavp(callee_usr_prefs=>testid)"),1) diff --git a/tests/ngcp_xavp.lua b/tests/ngcp_xavp.lua index af036e5..20fa263 100644 --- a/tests/ngcp_xavp.lua +++ b/tests/ngcp_xavp.lua @@ -81,9 +81,9 @@ TestNGCPXAvp = {} --class assertEquals(sr.pv.get("$xavp(caller_peer=>testid)"),1) assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"),"caller") xavp:clean() + assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"),"caller") assertFalse(xavp("testid")) assertFalse(sr.pv.get("$xavp(caller_peer=>testid)")) - assertFalse(sr.pv.get("$xavp(caller_peer)")) end function TestNGCPXAvp:test_clean_all() @@ -93,12 +93,12 @@ TestNGCPXAvp = {} --class 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(caller_peer=>dummy)"),"caller") 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)")) + assertEquals(sr.pv.get("$xavp(callee_peer=>dummy)"), "callee") + assertEquals(sr.pv.get("$xavp(caller_peer=>dummy)"), "caller") end