use crate::encode::Encode;
use crate::messages::GeoJson;
#[test]
fn test_geojson_schema_preserves_schema_name() {
let schema = GeoJson::get_schema();
assert!(schema.is_some());
assert_eq!(schema.unwrap().name, "foxglove.GeoJSON");
}
#[test]
fn test_log_message_can_be_encoded() {
use crate::messages::{log::Level, Log, Timestamp};
let msg = Log {
timestamp: Some(Timestamp::new(5, 10)),
level: Level::Error as i32,
message: "hello".to_string(),
name: "logger".to_string(),
file: "file".to_string(),
line: 123,
};
let schema = Log::get_schema();
assert!(schema.is_some());
assert_eq!(schema.unwrap().name, "foxglove.Log");
let mut buf = Vec::new();
msg.encode(&mut buf).expect("encoding should succeed");
assert!(!buf.is_empty());
}
#[test]
fn test_timestamp_creation() {
use crate::messages::Timestamp;
let ts = Timestamp::new(123, 456);
assert_eq!(ts.sec(), 123);
assert_eq!(ts.nsec(), 456);
}
#[test]
#[allow(deprecated)]
fn test_schemas_reexports_same_types_as_messages() {
use crate::messages;
use crate::schemas;
let msg_from_messages: messages::Log = messages::Log {
timestamp: Some(messages::Timestamp::new(1, 2)),
level: messages::log::Level::Info as i32,
message: "test".to_string(),
..Default::default()
};
let msg_from_schemas: schemas::Log = schemas::Log {
timestamp: Some(schemas::Timestamp::new(1, 2)),
level: schemas::log::Level::Info as i32,
message: "test".to_string(),
..Default::default()
};
let mut buf1 = Vec::new();
let mut buf2 = Vec::new();
msg_from_messages.encode(&mut buf1).unwrap();
msg_from_schemas.encode(&mut buf2).unwrap();
assert_eq!(buf1, buf2);
assert_eq!(
messages::Log::get_schema().unwrap().name,
schemas::Log::get_schema().unwrap().name
);
}
#[test]
#[allow(deprecated)]
fn test_schemas_reexports_common_types() {
use crate::messages;
use crate::schemas;
use std::any::TypeId;
assert_eq!(TypeId::of::<messages::Log>(), TypeId::of::<schemas::Log>());
assert_eq!(
TypeId::of::<messages::Timestamp>(),
TypeId::of::<schemas::Timestamp>()
);
assert_eq!(
TypeId::of::<messages::Duration>(),
TypeId::of::<schemas::Duration>()
);
assert_eq!(
TypeId::of::<messages::CompressedImage>(),
TypeId::of::<schemas::CompressedImage>()
);
assert_eq!(
TypeId::of::<messages::SceneUpdate>(),
TypeId::of::<schemas::SceneUpdate>()
);
assert_eq!(
TypeId::of::<messages::PointCloud>(),
TypeId::of::<schemas::PointCloud>()
);
}
#[test]
#[allow(deprecated)]
fn test_schemas_glob_import_works() {
#[allow(unused_imports)]
use crate::schemas::*;
let _ts = Timestamp::new(100, 200);
let _color = Color {
r: 1.0,
g: 0.5,
b: 0.0,
a: 1.0,
};
}