diff --git a/ngcp/pp.lua b/ngcp/pp.lua index a452f28..e1c9bcc 100644 --- a/ngcp/pp.lua +++ b/ngcp/pp.lua @@ -19,6 +19,7 @@ -- local utils = require 'ngcp.utils' local NGCPPrefs = require 'ngcp.pref' +local NGCPXAvp = require 'ngcp.xavp' -- class NGCPPeerPrefs local NGCPPeerPrefs = utils.inheritsFrom(NGCPPrefs) @@ -35,5 +36,15 @@ function NGCPPeerPrefs:new(config) return instance end +function NGCPPeerPrefs:clean(vtype) + NGCPPrefs.clean(self, vtype) + if not vtype then + NGCPXAvp:new('callee', 'prefs'):clean() + NGCPXAvp:new('caller', 'prefs'):clean() + else + NGCPXAvp:new(vtype, 'prefs'):clean() + end +end + -- class return NGCPPeerPrefs diff --git a/tests/ngcp_pp.lua b/tests/ngcp_pp.lua index af494da..5f7793d 100644 --- a/tests/ngcp_pp.lua +++ b/tests/ngcp_pp.lua @@ -22,7 +22,7 @@ local lemock = require('lemock') local utils = require 'ngcp.utils' local utable = utils.table local PPFetch = require 'tests_v.pp_vars' - +local NGCPXAvp = require 'ngcp.xavp' local ksrMock = require 'mocks.ksr' KSR = ksrMock:new() @@ -234,6 +234,24 @@ TestNGCPPeerPrefs = {} --class lu.assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") end + function TestNGCPPeerPrefs:test_clean_prefs() + local xavp_pref = NGCPXAvp:new('callee', 'prefs') + local xavp = NGCPPeerPrefs:xavp('callee') + xavp("testid",1) + xavp("foo","foo") + xavp_pref("two",2) + lu.assertEquals(KSR.pv.get("$xavp(callee_prefs=>two)"),2) + lu.assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>testid)"),1) + lu.assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>foo)"),"foo") + lu.assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller") + lu.assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") + self.d:clean('callee') + lu.assertEquals(KSR.pv.get("$xavp(caller_peer_prefs=>dummy)"),"caller") + lu.assertEquals(KSR.pv.get("$xavp(callee_peer_prefs=>dummy)"),"callee") + lu.assertNil(KSR.pv.get("$xavp(peer)")) + lu.assertEquals(KSR.pv.get("$xavp(callee_prefs=>dummy)"), "callee") + end + function TestNGCPPeerPrefs:test_tostring() local callee_xavp = NGCPPeerPrefs:xavp('callee') callee_xavp("testid",1)