use crate::cot::Cot;
use crate::cot_base::Point;
use strum::IntoEnumIterator;
#[allow(dead_code)]
mod tests {
use super::*;
use crate::config::Config;
use crate::cot_base::CursorOnTarget;
use crate::cot_types::{
cot_classification_to_string, lookup_cot_type, CoTType, CotClassification,
};
use crate::udp_sender::UdpSender;
const LONGITUDE: f64 = 153.02351661489064;
const LATITUDE: f64 = -27.46891737509902;
#[test]
fn test_get_license() {
let path = Path::new("LICENSE");
let license = fs::read_to_string(path).expect("Unable to read file");
assert_eq!(license, "License will go here");
}
pub fn test_publish_all_cot_all(lat: f64, classification: CotClassification) {
let config = Config::get_instance();
let xml = UdpSender::new(
&config.lock().unwrap().udp.address as &str,
config.lock().unwrap().udp.port,
)
.expect("Couldn't setup multicast");
for (index, cot_type) in CoTType::iter().enumerate() {
let point = Point {
latitude: lat,
longitude: LONGITUDE,
hae: CursorOnTarget::HAE_NONE,
ce: CursorOnTarget::CE_NONE,
le: CursorOnTarget::LE_NONE,
};
let cot_type = lookup_cot_type(cot_type, classification.clone());
let cot = CursorOnTarget::new(
"CITY_#89436".to_string(),
None,
Some(cot_type.to_string()),
"h-e".to_string(),
None,
point,
);
let mut cot = Cot::new(
cot,
None,
"CITY_HALL".to_string(),
false,
None,
None,
Some(0.0),
None,
None,
None,
None,
None,
None,
);
let long = LONGITUDE + (index as f64 * 0.001);
let class = cot_classification_to_string(classification);
cot.cot.uid = format!("{}_ID_{}", class, index);
cot.cot.type_string = Some(cot_type.to_string());
cot.cot.point.longitude = long;
xml.send(&cot.cot.get_xml_bytes())
.expect("Failed to send CoT message");
xml.close();
}
}
#[test]
fn test_check_config() {
let path = Path::new("config.toml");
let config = fs::read_to_string(path).expect("Unable to read file");
assert!(config.contains("[general]"));
assert!(config.contains("[udp]"));
assert!(config.contains("[tcp]"));
assert!(config.contains("[ssl]"));
}
#[test]
fn test_publish_all_cot_friendly() {
test_publish_all_cot_all(LATITUDE + 0.001, CotClassification::Friend);
test_publish_all_cot_all(LATITUDE + 0.002, CotClassification::Hostile);
test_publish_all_cot_all(LATITUDE + 0.003, CotClassification::Neutral);
test_publish_all_cot_all(LATITUDE + 0.004, CotClassification::Unknown);
test_publish_all_cot_all(LATITUDE + 0.005, CotClassification::Pending);
test_publish_all_cot_all(LATITUDE + 0.006, CotClassification::AssumedFriend);
test_publish_all_cot_all(LATITUDE + 0.007, CotClassification::Suspect);
}
#[test]
fn send_building() {
let config =
Config::from_file(&Config::get_config_file_path()).expect("Failed to read config file");
let cot_type = lookup_cot_type(CoTType::GndBuilding, CotClassification::Friend);
let mut building = Cot::new(
CursorOnTarget::new(
"CITY_#89436".to_string(),
None,
Some(cot_type.to_string()),
"h-e".to_string(),
None,
Point {
latitude: LATITUDE,
longitude: LONGITUDE,
hae: CursorOnTarget::HAE_NONE,
ce: CursorOnTarget::CE_NONE,
le: CursorOnTarget::LE_NONE,
},
),
None,
"Brisbane City Hall".to_string(),
false,
None,
None,
None,
None,
None,
None,
None,
None,
None,
);
let xml = UdpSender::new(&config.udp.address as &str, config.udp.port)
.expect("Couldn't setup multicast");
xml.send(&building.cot.get_xml_bytes())
.expect("Failed to send CoT message");
}
#[test]
fn data_package() {
use crate::cot::FileShare;
use crate::data_package::create_data_package;
let mut fileshare = FileShare::new(
"TestPackage".to_string(),
uuid::Uuid::new_v4().to_string(),
"test".to_string(),
"http://localhost:8080".to_string(),
0,
"".to_string(),
"us".to_string(),
"ME".to_string(),
);
fileshare.add_file("./data/640x480.png");
fileshare.add_file("./data/800x600.png");
fileshare.add_file("./data/1920x1080.png");
create_data_package(&mut fileshare, "../target/.").expect("Failed to create data package");
}
}