@@ -854,6 +854,61 @@ fn test_other_data() {
854
854
) ;
855
855
}
856
856
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
+
857
912
#[ test]
858
913
fn test_addr_format ( ) {
859
914
assert_eq ! ( serde_json:: to_string( & v7:: Addr ( 0 ) ) . unwrap( ) , "\" 0x0\" " ) ;
0 commit comments