Skip to content

Commit c02861d

Browse files
committed
test: Added test for device info
1 parent a5bdedc commit c02861d

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/protocol/v7.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ impl Event {
741741
pub enum Orientation {
742742
/// Portrait device orientation.
743743
Portrait,
744-
/// Landscaope device orientation.
744+
/// Landscape device orientation.
745745
Landscape,
746746
}
747747

tests/test_protocol_v7.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,61 @@ fn test_other_data() {
854854
);
855855
}
856856

857+
#[test]
858+
fn test_contexts() {
859+
let event = v7::Event {
860+
contexts: {
861+
let mut m = v7::Map::new();
862+
m.insert("device".into(), v7::ContextType::Device(v7::DeviceContext {
863+
name: Some("iphone".into()),
864+
family: Some("iphone".into()),
865+
model: Some("iphone7,3".into()),
866+
model_id: Some("AH223".into()),
867+
arch: Some("arm64".into()),
868+
battery_level: Some(58.5.into()),
869+
orientation: Some(v7::Orientation::Landscape),
870+
}.into()).into());
871+
m.insert("os".into(), v7::ContextType::Os(v7::OsContext {
872+
name: Some("iOS".into()),
873+
version: Some("11.4.2".into()),
874+
build: Some("ADSA23".into()),
875+
kernel_version: Some("17.4.0".into()),
876+
rooted: Some(true),
877+
}).into());
878+
m.insert("magicvm".into(), v7::ContextType::Runtime(v7::RuntimeContext {
879+
name: Some("magicvm".into()),
880+
version: Some("5.3".into()),
881+
}).into());
882+
m.insert("othervm".into(), v7::Context {
883+
data: v7::ContextType::Runtime(v7::RuntimeContext {
884+
name: Some("magicvm".into()),
885+
version: Some("5.3".into()),
886+
}),
887+
extra: {
888+
let mut m = v7::Map::new();
889+
m.insert("extra_stuff".into(), "extra_value".into());
890+
m
891+
}
892+
});
893+
m
894+
},
895+
..Default::default()
896+
};
897+
898+
assert_roundtrip(&event);
899+
assert_eq!(
900+
serde_json::to_string(&event).unwrap(),
901+
"{\"contexts\":{\"device\":{\"name\":\"iphone\",\"family\":\"iphone\",\
902+
\"model\":\"iphone7,3\",\"model_id\":\"AH223\",\"arch\":\"arm64\",\
903+
\"battery_level\":58.5,\"orientation\":\"landscape\",\"type\"\
904+
:\"device\"},\"os\":{\"name\":\"iOS\",\"version\":\"11.4.2\",\"build\":\
905+
\"ADSA23\",\"kernel_version\":\"17.4.0\",\"rooted\":true,\"type\":\"os\"}\
906+
,\"magicvm\":{\"name\":\"magicvm\",\"version\":\"5.3\",\"type\":\
907+
\"runtime\"},\"othervm\":{\"name\":\"magicvm\",\"version\":\"5.3\",\
908+
\"type\":\"runtime\",\"extra_stuff\":\"extra_value\"}}}"
909+
);
910+
}
911+
857912
#[test]
858913
fn test_addr_format() {
859914
assert_eq!(serde_json::to_string(&v7::Addr(0)).unwrap(), "\"0x0\"");

0 commit comments

Comments
 (0)