#
# PRE: update
#

update {
	Filter-Id := 'foobarbaz'
	NAS-Port := 123456789
	Framed-IP-Address := 192.0.2.1
	Framed-IP-Address += 192.0.2.2
	Framed-IP-Address += 192.0.2.3
	Framed-IP-Address += 192.0.2.4
	control.Framed-IP-Address := 192.0.2.1
	control.Framed-IP-Address += 192.0.2.3
}

if (!((Framed-IP-Address[0] == 192.0.2.1)) || \
	(!(Framed-IP-Address[1] == 192.0.2.2)) || \
	(!(Framed-IP-Address[2] == 192.0.2.3)) || \
	(!(Framed-IP-Address[3] == 192.0.2.4))) {
	test_fail
}

# Remove Framed-IP-Address with a specific value
update {
	Framed-IP-Address -= 192.0.2.1
}

# Only the 2nd, 3rd and 4th Framed-IP-Address attributes should still be in the list
if (!((Framed-IP-Address[0] == 192.0.2.2)) || \
	(!(Framed-IP-Address[1] == 192.0.2.3)) || \
	(!(Framed-IP-Address[2] == 192.0.2.4)) || \
	(Framed-IP-Address[3])) {
	test_fail
}

# Remove Framed-IP-Address with a specific value (somewhere in the middle)
update {
	Framed-IP-Address -= 192.0.2.3
}

# Only the 1st, and 3rd Framed-IP-Address attributes should still be in the list
if (!((Framed-IP-Address[0] == 192.0.2.2)) || \
	(!(Framed-IP-Address[1] == 192.0.2.4)) || \
	(Framed-IP-Address[2])) {
	test_fail
}

# Remove Framed-IP-Address with a specific value (which doesn't exist)
update {
	Framed-IP-Address -= 192.0.2.3
}

# Only the 1st, and 3rd Framed-IP-Address attributes should still be in the list
if (!((Framed-IP-Address[0] == 192.0.2.2)) || \
	(!(Framed-IP-Address[1] == 192.0.2.4)) || \
	(Framed-IP-Address[2])) {
	test_fail
}

# Remove NAS-IP-Address (which doesn't exist - more to check for SEGV/assert)
update {
	NAS-IP-Address -= 192.0.2.3
}

# Remove Framed-IP-Address with a specific value
update {
	Framed-IP-Address -= 192.0.2.4
}

# Only the 1st, and 3rd Framed-IP-Address attributes should still be in the list
if (!((Framed-IP-Address[0] == 192.0.2.2)) || \
	(Framed-IP-Address[1])) {
	test_fail
}

# Remove Framed-IP-Address with a specific value
update {
	Framed-IP-Address -= 192.0.2.2
}

# Only the 1st, and 3rd Framed-IP-Address attributes should still be in the list
#  and the Framed-IP-Addres-0 attribute should be deleted
if (Framed-IP-Address) {
	test_fail
}

# Non Framed-IP-Address address attributes should still be in the request list
if (!((Filter-Id == 'foobarbaz')) || (!(NAS-Port == 123456789))) {
	test_fail
}

# But there should still be some in the control list
if (!((control.Framed-IP-Address[0] == 192.0.2.1)) || (!(control.Framed-IP-Address[1] == 192.0.2.3))) {
	test_fail
}

success
