TT#4657 avp: add del(value)

Change-Id: I41309ffff4f1a9335911f7d48f6295ea123c7d25
changes/28/8828/2
Victor Seva 9 years ago
parent bf995f354a
commit 31dd6f2b81

@ -60,6 +60,17 @@ local NGCPAvp_MT = {
sr.log(level, tostring(self))
end
function NGCPAvp:del(value)
local values = self.all()
if not values or not value then return end
sr.pv.unset(self.id)
for i = #values, 1, -1 do
if values[i] ~= value then
self(values[i])
end
end
end
function NGCPAvp:clean()
sr.pv.unset(self.id)
end

@ -75,6 +75,28 @@ TestNGCPAvp = {} --class
assertItemsEquals(self.avp:all(), okvals)
end
function TestNGCPAvp:test_avp_del()
local vals = {1,2, {"3", 4}}
local okvals = {4, "3", 2, 1}
for i=1,#vals do
self.avp(vals[i])
end
assertItemsEquals(self.avp:all(), okvals)
self.avp:del(1)
assertItemsEquals(self.avp:all(), {4, "3", 2})
self.avp:del(4)
assertItemsEquals(self.avp:all(), {"3", 2})
self.avp:del(1)
assertItemsEquals(self.avp:all(), {"3", 2})
self.avp:del("3")
assertItemsEquals(self.avp:all(), {2})
self.avp:del(2)
assertNil(self.avp:all())
self.avp:del(nil)
assertNil(self.avp:all())
end
function TestNGCPAvp:test_clean()
self.avp(1)
self.avp:clean()

Loading…
Cancel
Save