use super::super::*;
#[test]
fn mso_msv_relinquish_default_write_recaptures_present_value() {
for object in [
&mut MultiStateOutputObject::new(1, "MSO-1", 3).unwrap() as &mut dyn BACnetObject,
&mut MultiStateValueObject::new(1, "MSV-1", 3).unwrap() as &mut dyn BACnetObject,
] {
assert!(object.is_writable_property(PropertyIdentifier::RELINQUISH_DEFAULT));
object
.write_property(
PropertyIdentifier::RELINQUISH_DEFAULT,
None,
PropertyValue::Unsigned(2),
None,
)
.unwrap();
assert_eq!(
object
.read_property(PropertyIdentifier::RELINQUISH_DEFAULT, None)
.unwrap(),
PropertyValue::Unsigned(2)
);
assert_eq!(
object
.read_property(PropertyIdentifier::PRESENT_VALUE, None)
.unwrap(),
PropertyValue::Unsigned(2),
"with an empty priority array, PV must resolve to the written default"
);
for value in [
PropertyValue::Unsigned(0),
PropertyValue::Unsigned(4),
PropertyValue::Unsigned(u64::MAX),
PropertyValue::Real(2.0),
] {
assert!(
object
.write_property(PropertyIdentifier::RELINQUISH_DEFAULT, None, value, None)
.is_err(),
"invalid Relinquish_Default write must refuse"
);
assert_eq!(
object
.read_property(PropertyIdentifier::RELINQUISH_DEFAULT, None)
.unwrap(),
PropertyValue::Unsigned(2),
"refused writes must leave Relinquish_Default untouched"
);
}
}
let mut mso = MultiStateOutputObject::new(2, "MSO-2", 5).unwrap();
assert!(mso.set_relinquish_default(6).is_err());
assert!(mso.set_relinquish_default(0).is_err());
mso.set_relinquish_default(5).unwrap();
assert_eq!(
mso.read_property(PropertyIdentifier::PRESENT_VALUE, None)
.unwrap(),
PropertyValue::Unsigned(5)
);
}
#[test]
fn mso_relinquish_default_is_not_range_locked_after_store() {
let mut mso = MultiStateOutputObject::new(1, "MSO-1", 3).unwrap();
mso.set_relinquish_default(3).unwrap();
assert_eq!(
mso.read_property(PropertyIdentifier::PRESENT_VALUE, None)
.unwrap(),
PropertyValue::Unsigned(3)
);
mso.set_number_of_states(2).unwrap();
assert_eq!(
mso.read_property(PropertyIdentifier::RELINQUISH_DEFAULT, None)
.unwrap(),
PropertyValue::Unsigned(3)
);
assert_eq!(
mso.read_property(PropertyIdentifier::PRESENT_VALUE, None)
.unwrap(),
PropertyValue::Unsigned(3)
);
assert_eq!(
mso.read_property(PropertyIdentifier::RELIABILITY, None)
.unwrap(),
PropertyValue::Enumerated(Reliability::CONFIGURATION_ERROR.to_raw())
);
assert!(mso
.write_property(
PropertyIdentifier::NUMBER_OF_STATES,
None,
PropertyValue::Unsigned(3),
None
)
.is_err());
}