From c02861d6166bd888d208104c731cd0e52e0ee714 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 25 Mar 2018 23:18:47 +0200 Subject: [PATCH] test: Added test for device info --- src/protocol/v7.rs | 2 +- tests/test_protocol_v7.rs | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/protocol/v7.rs b/src/protocol/v7.rs index cc771992..55e9c546 100644 --- a/src/protocol/v7.rs +++ b/src/protocol/v7.rs @@ -741,7 +741,7 @@ impl Event { pub enum Orientation { /// Portrait device orientation. Portrait, - /// Landscaope device orientation. + /// Landscape device orientation. Landscape, } diff --git a/tests/test_protocol_v7.rs b/tests/test_protocol_v7.rs index 79da5cad..ff6b6f04 100644 --- a/tests/test_protocol_v7.rs +++ b/tests/test_protocol_v7.rs @@ -854,6 +854,61 @@ fn test_other_data() { ); } +#[test] +fn test_contexts() { + let event = v7::Event { + contexts: { + let mut m = v7::Map::new(); + m.insert("device".into(), v7::ContextType::Device(v7::DeviceContext { + name: Some("iphone".into()), + family: Some("iphone".into()), + model: Some("iphone7,3".into()), + model_id: Some("AH223".into()), + arch: Some("arm64".into()), + battery_level: Some(58.5.into()), + orientation: Some(v7::Orientation::Landscape), + }.into()).into()); + m.insert("os".into(), v7::ContextType::Os(v7::OsContext { + name: Some("iOS".into()), + version: Some("11.4.2".into()), + build: Some("ADSA23".into()), + kernel_version: Some("17.4.0".into()), + rooted: Some(true), + }).into()); + m.insert("magicvm".into(), v7::ContextType::Runtime(v7::RuntimeContext { + name: Some("magicvm".into()), + version: Some("5.3".into()), + }).into()); + m.insert("othervm".into(), v7::Context { + data: v7::ContextType::Runtime(v7::RuntimeContext { + name: Some("magicvm".into()), + version: Some("5.3".into()), + }), + extra: { + let mut m = v7::Map::new(); + m.insert("extra_stuff".into(), "extra_value".into()); + m + } + }); + m + }, + ..Default::default() + }; + + assert_roundtrip(&event); + assert_eq!( + serde_json::to_string(&event).unwrap(), + "{\"contexts\":{\"device\":{\"name\":\"iphone\",\"family\":\"iphone\",\ + \"model\":\"iphone7,3\",\"model_id\":\"AH223\",\"arch\":\"arm64\",\ + \"battery_level\":58.5,\"orientation\":\"landscape\",\"type\"\ + :\"device\"},\"os\":{\"name\":\"iOS\",\"version\":\"11.4.2\",\"build\":\ + \"ADSA23\",\"kernel_version\":\"17.4.0\",\"rooted\":true,\"type\":\"os\"}\ + ,\"magicvm\":{\"name\":\"magicvm\",\"version\":\"5.3\",\"type\":\ + \"runtime\"},\"othervm\":{\"name\":\"magicvm\",\"version\":\"5.3\",\ + \"type\":\"runtime\",\"extra_stuff\":\"extra_value\"}}}" + ); +} + #[test] fn test_addr_format() { assert_eq!(serde_json::to_string(&v7::Addr(0)).unwrap(), "\"0x0\"");