use super::super::*;
#[test]
fn event_detection_enable_defaults_true() {
let ee = EventEnrollmentObject::new(1, "EE-1", EventType::CHANGE_OF_BITSTRING).unwrap();
assert_eq!(
ee.read_property(PropertyIdentifier::EVENT_DETECTION_ENABLE, None)
.unwrap(),
PropertyValue::Boolean(true)
);
}
#[test]
fn event_detection_enable_appears_in_property_list() {
let ee = EventEnrollmentObject::new(1, "EE-1", EventType::CHANGE_OF_BITSTRING).unwrap();
assert!(
ee.property_list()
.contains(&PropertyIdentifier::EVENT_DETECTION_ENABLE),
"a required property must be advertised, or PICS under-reports it"
);
}
#[test]
fn event_detection_enable_is_writable() {
let mut ee = EventEnrollmentObject::new(1, "EE-1", EventType::CHANGE_OF_BITSTRING).unwrap();
ee.write_property(
PropertyIdentifier::EVENT_DETECTION_ENABLE,
None,
PropertyValue::Boolean(false),
None,
)
.unwrap();
assert_eq!(
ee.read_property(PropertyIdentifier::EVENT_DETECTION_ENABLE, None)
.unwrap(),
PropertyValue::Boolean(false)
);
}
#[test]
fn event_detection_enable_rejects_wrong_type() {
let mut ee = EventEnrollmentObject::new(1, "EE-1", EventType::CHANGE_OF_BITSTRING).unwrap();
assert!(
ee.write_property(
PropertyIdentifier::EVENT_DETECTION_ENABLE,
None,
PropertyValue::Unsigned(0),
None,
)
.is_err(),
"a BOOLEAN property must reject a non-Boolean write"
);
assert_eq!(
ee.read_property(PropertyIdentifier::EVENT_DETECTION_ENABLE, None)
.unwrap(),
PropertyValue::Boolean(true)
);
}
#[test]
fn disabling_detection_resets_event_state_to_normal() {
let mut ee = EventEnrollmentObject::new(1, "EE-1", EventType::CHANGE_OF_BITSTRING).unwrap();
ee.set_event_state(EventState::HIGH_LIMIT);
assert_eq!(
ee.read_property(PropertyIdentifier::EVENT_STATE, None)
.unwrap(),
PropertyValue::Enumerated(EventState::HIGH_LIMIT.to_raw()),
"precondition: the enrollment is in an alarm state"
);
ee.write_property(
PropertyIdentifier::EVENT_DETECTION_ENABLE,
None,
PropertyValue::Boolean(false),
None,
)
.unwrap();
assert_eq!(
ee.read_property(PropertyIdentifier::EVENT_STATE, None)
.unwrap(),
PropertyValue::Enumerated(EventState::NORMAL.to_raw()),
"disabling detection must reset Event_State, not freeze it"
);
}
#[test]
fn disabled_detection_reports_initial_acked_transitions() {
let mut ee = EventEnrollmentObject::new(1, "EE-1", EventType::CHANGE_OF_BITSTRING).unwrap();
ee.write_property(
PropertyIdentifier::EVENT_DETECTION_ENABLE,
None,
PropertyValue::Boolean(false),
None,
)
.unwrap();
assert_eq!(
ee.read_property(PropertyIdentifier::ACKED_TRANSITIONS, None)
.unwrap(),
PropertyValue::BitString {
unused_bits: 5,
data: vec![0xE0],
}
);
}
#[test]
fn disabled_detection_refuses_non_normal_internal_state() {
let mut ee = EventEnrollmentObject::new(1, "EE-1", EventType::CHANGE_OF_BITSTRING).unwrap();
ee.write_property(
PropertyIdentifier::EVENT_DETECTION_ENABLE,
None,
PropertyValue::Boolean(false),
None,
)
.unwrap();
assert!(
ee.set_event_state_internal(EventState::HIGH_LIMIT).is_err(),
"no transition may occur while detection is disabled"
);
assert_eq!(
ee.read_property(PropertyIdentifier::EVENT_STATE, None)
.unwrap(),
PropertyValue::Enumerated(EventState::NORMAL.to_raw()),
"the refused write must leave Event_State at NORMAL"
);
}
#[test]
fn disabled_detection_still_permits_normal_internal_state() {
let mut ee = EventEnrollmentObject::new(1, "EE-1", EventType::CHANGE_OF_BITSTRING).unwrap();
ee.write_property(
PropertyIdentifier::EVENT_DETECTION_ENABLE,
None,
PropertyValue::Boolean(false),
None,
)
.unwrap();
assert!(ee.set_event_state_internal(EventState::NORMAL).is_ok());
}
#[test]
fn re_enabling_detection_resumes_from_normal() {
let mut ee = EventEnrollmentObject::new(1, "EE-1", EventType::CHANGE_OF_BITSTRING).unwrap();
ee.set_event_state(EventState::LOW_LIMIT);
for enabled in [false, true] {
ee.write_property(
PropertyIdentifier::EVENT_DETECTION_ENABLE,
None,
PropertyValue::Boolean(enabled),
None,
)
.unwrap();
}
assert_eq!(
ee.read_property(PropertyIdentifier::EVENT_STATE, None)
.unwrap(),
PropertyValue::Enumerated(EventState::NORMAL.to_raw()),
"re-enabling must not restore LOW_LIMIT"
);
assert!(ee.set_event_state_internal(EventState::LOW_LIMIT).is_ok());
}
#[test]
fn disabled_detection_ignores_non_normal_seed() {
let mut ee = EventEnrollmentObject::new(1, "EE-1", EventType::CHANGE_OF_BITSTRING).unwrap();
ee.write_property(
PropertyIdentifier::EVENT_DETECTION_ENABLE,
None,
PropertyValue::Boolean(false),
None,
)
.unwrap();
ee.set_event_state(EventState::HIGH_LIMIT);
assert_eq!(
ee.read_property(PropertyIdentifier::EVENT_STATE, None)
.unwrap(),
PropertyValue::Enumerated(EventState::NORMAL.to_raw()),
"a non-NORMAL seed must not take effect while detection is disabled"
);
}
#[test]
fn enabled_detection_accepts_seed() {
let mut ee = EventEnrollmentObject::new(1, "EE-1", EventType::CHANGE_OF_BITSTRING).unwrap();
ee.set_event_state(EventState::HIGH_LIMIT);
assert_eq!(
ee.read_property(PropertyIdentifier::EVENT_STATE, None)
.unwrap(),
PropertyValue::Enumerated(EventState::HIGH_LIMIT.to_raw())
);
}