diff --git a/rust/rti/src/federate_info.rs b/rust/rti/src/federate_info.rs index 2ed3cea..1f12fc6 100644 --- a/rust/rti/src/federate_info.rs +++ b/rust/rti/src/federate_info.rs @@ -81,6 +81,18 @@ impl FederateInfo { self.clock_synchronization_enabled } + pub fn in_transit_message_tags(&mut self) -> &mut InTransitMessageRecordQueue { + &mut self.in_transit_message_tags + } + + pub fn server_hostname(&self) -> String { + self.server_hostname.clone() + } + + pub fn server_port(&self) -> i32 { + self.server_port + } + pub fn set_requested_stop(&mut self, requested_stop: bool) { self.requested_stop = requested_stop; } @@ -93,10 +105,6 @@ impl FederateInfo { self.clock_synchronization_enabled = clock_synchronization_enabled; } - pub fn in_transit_message_tags(&mut self) -> &mut InTransitMessageRecordQueue { - &mut self.in_transit_message_tags - } - pub fn set_server_hostname(&mut self, server_hostname: String) { self.server_hostname = server_hostname; } @@ -105,3 +113,134 @@ impl FederateInfo { self.server_port = server_port; } } + +#[cfg(test)] +mod tests { + use super::*; + use std::net::TcpStream; + + #[test] + fn test_new_positive() { + let federate_info = FederateInfo::new(); + // TODO: Check federate_info + assert!(true); + } + + #[test] + fn test_e_positive() { + let federate_info = FederateInfo::new(); + let e = federate_info.e(); + assert!(e == &SchedulingNode::new()); + } + + #[test] + fn test_enclave_positive() { + let mut federate_info = FederateInfo::new(); + let enclave = federate_info.enclave(); + assert!(enclave == &SchedulingNode::new()); + } + + #[test] + fn test_requested_stop_positive() { + let federate_info = FederateInfo::new(); + let is_requested_stop = federate_info.requested_stop(); + assert!(is_requested_stop == false); + } + + #[test] + fn test_initial_stream_positive() { + let federate_info = FederateInfo::new(); + let initial_stream = federate_info.stream(); + // TODO: Check initial_stream + assert!(true); + } + + #[test] + fn test_clock_synchronization_enabled_positive() { + let federate_info = FederateInfo::new(); + let is_clock_synchronization_enabled = federate_info.clock_synchronization_enabled(); + assert!(is_clock_synchronization_enabled == true); + } + + #[test] + fn test_in_transit_message_tags_positive() { + let mut federate_info = FederateInfo::new(); + let in_transit_message_tags = federate_info.in_transit_message_tags(); + assert!(in_transit_message_tags == &mut InTransitMessageRecordQueue::new()) + } + + #[test] + fn test_set_requested_stop_as_true_positive() { + let mut federate_info = FederateInfo::new(); + federate_info.set_requested_stop(true); + assert!(federate_info.requested_stop() == true); + } + + #[test] + fn test_set_requested_stop_as_false_positive() { + let mut federate_info = FederateInfo::new(); + federate_info.set_requested_stop(false); + assert!(federate_info.requested_stop() == false); + } + + #[test] + fn test_set_stream_with_valid_stream_positive() { + let mut federate_info = FederateInfo::new(); + // TODO: Enable below + // match TcpStream::connect("127.0.0.1:8080") { + // Ok(valid_stream) => { + // federate_info.set_stream(valid_stream); + // assert!(federate_info.stream() == valid_stream); + // } + // Err(_e) => { + // assert!(false); + // } + // }; + } + + #[test] + fn test_set_clock_synchronization_enabled_with_true_positive() { + let mut federate_info = FederateInfo::new(); + federate_info.set_clock_synchronization_enabled(true); + assert!(federate_info.clock_synchronization_enabled() == true); + } + + #[test] + fn test_set_clock_synchronization_enabled_with_false_positive() { + let mut federate_info = FederateInfo::new(); + federate_info.set_clock_synchronization_enabled(false); + assert!(federate_info.clock_synchronization_enabled() == false); + } + + #[test] + fn test_set_server_hostname_with_valid_name_positive() { + let mut federate_info = FederateInfo::new(); + let server_name = String::from("test_rust_rti_server"); + federate_info.set_server_hostname(server_name.clone()); + assert!(federate_info.server_hostname() == server_name); + } + + #[test] + fn test_set_server_hostname_with_invalid_name_negative() { + let mut federate_info = FederateInfo::new(); + let server_name = String::from(""); + federate_info.set_server_hostname(server_name.clone()); + assert!(federate_info.server_hostname().len() == 0); + } + + #[test] + fn test_set_server_port_with_valid_port_positive() { + let mut federate_info = FederateInfo::new(); + let server_port = 8080; + federate_info.set_server_port(server_port); + assert!(federate_info.server_port() == server_port); + } + + #[test] + fn test_set_server_port_with_invalid_port_negative() { + let mut federate_info = FederateInfo::new(); + let server_port = -1; + federate_info.set_server_port(server_port); + assert!(federate_info.server_port() < 0); + } +} diff --git a/rust/rti/src/message_record/message_record.rs b/rust/rti/src/message_record/message_record.rs index 519ecaa..f683b33 100644 --- a/rust/rti/src/message_record/message_record.rs +++ b/rust/rti/src/message_record/message_record.rs @@ -19,6 +19,7 @@ use crate::tag::{Instant, Tag}; * @brief Queue to keep a record of in-transit messages. * */ +#[derive(PartialEq)] pub struct InTransitMessageRecordQueue { main_queue: PriorityQueue, // The primary queue. transfer_queue: PriorityQueue, // Queue used for housekeeping. diff --git a/rust/rti/src/rti_common.rs b/rust/rti/src/rti_common.rs index a52d428..317f921 100644 --- a/rust/rti/src/rti_common.rs +++ b/rust/rti/src/rti_common.rs @@ -28,6 +28,7 @@ const IS_IN_ZERO_DELAY_CYCLE: i32 = 1; const IS_IN_CYCLE: i32 = 2; /** Mode of execution of a federate. */ +#[derive(PartialEq)] enum ExecutionMode { FAST, REALTIME, @@ -41,6 +42,7 @@ pub enum SchedulingNodeState { } /** Struct for minimum delays from upstream nodes. */ +#[derive(PartialEq)] pub struct MinimumDelay { id: i32, // ID of the upstream node. min_delay: Tag, // Minimum delay from upstream. @@ -69,6 +71,7 @@ impl MinimumDelay { * denoted with ~>) because those connections do not impose * any scheduling constraints. */ +#[derive(PartialEq)] pub struct SchedulingNode { id: u16, // ID of this scheduling node. completed: Tag, // The largest logical tag completed by the federate (or NEVER if no LTC has been received). diff --git a/rust/rti/src/tag.rs b/rust/rti/src/tag.rs index be08273..dc66037 100644 --- a/rust/rti/src/tag.rs +++ b/rust/rti/src/tag.rs @@ -173,7 +173,7 @@ impl Tag { // ); result } - + pub fn lf_tag_add(a: &Tag, b: &Tag) -> Tag { if a.time() == NEVER || b.time() == NEVER { return Tag::never_tag(); @@ -205,4 +205,4 @@ mod tests { let t2 = Tag::new(0, 0); assert_eq!(0, Tag::lf_tag_compare(&t1, &t2)) } -} \ No newline at end of file +}