Skip to content

Commit

Permalink
Merge pull request #24 from lf-lang/unit_test
Browse files Browse the repository at this point in the history
Adding basic unit tests
  • Loading branch information
chanijjani authored Mar 15, 2024
2 parents 2e41e50 + e7476e0 commit da9bf64
Show file tree
Hide file tree
Showing 11 changed files with 1,730 additions and 23 deletions.
2 changes: 2 additions & 0 deletions rust/rti/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ edition = "2021"
byteorder = "1"
priority-queue = "2.0.2"
zerocopy = { version = "0.7.32", features = ["derive"] }
socket-server-mocker = "0.0.4"
rand = "0.8"
138 changes: 138 additions & 0 deletions rust/rti/src/federate_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,141 @@ impl FederateInfo {
self.server_ip_addr = server_ip_addr;
}
}

#[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_enclave_positive() {
let federate_info = FederateInfo::new();
let enclave = federate_info.enclave();
assert!(enclave == &SchedulingNode::new());
}

#[test]
fn test_enclave_mut_positive() {
let mut federate_info = FederateInfo::new();
let enclave_mut = federate_info.enclave_mut();
assert!(enclave_mut == &mut 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_queue_positive() {
let federate_info = FederateInfo::new();
let in_transit_message_tags = federate_info.in_transit_message_queue();
assert!(in_transit_message_tags == &InTransitMessageQueue::new())
}

#[test]
fn test_in_transit_message_queue_mut_positive() {
let mut federate_info = FederateInfo::new();
let in_transit_message_tags = federate_info.in_transit_message_queue_mut();
assert!(in_transit_message_tags == &mut InTransitMessageQueue::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() {
// TODO: Enable below
// let mut federate_info = FederateInfo::new();
// 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);
}
}
1 change: 1 addition & 0 deletions rust/rti/src/in_transit_message_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::RTIRemote;

use std::sync::{Arc, RwLock};

#[derive(PartialEq)]
pub struct InTransitMessageQueue {
queue: PriorityQueue<Tag, usize>,
}
Expand Down
Loading

0 comments on commit da9bf64

Please sign in to comment.