use vast_protocol::v4::*; #[test] fn deserialize_v4() { let xml = r#" iabtechlab http://example.com/track/impression iabtechlab video ad 8465 http://example.com/tracking/start http://example.com/tracking/firstQuartile http://example.com/tracking/midpoint http://example.com/tracking/thirdQuartile http://example.com/tracking/complete http://example.com/tracking/progress-10 00:00:16 "#; let vast: VAST = vast_protocol::from_str(xml).unwrap(); assert_eq!("4.0", vast.version); assert_eq!("20001", vast.ad.id); assert_eq!(1, vast.ad.sequence.unwrap()); assert!(!vast.ad.conditional_ad.unwrap()); // InLine tag let in_line = vast.ad.in_line.unwrap(); assert_eq!("4.0", in_line.ad_system.version); // AdSystem tag assert_eq!("iabtechlab", in_line.ad_system.content.unwrap()); // Impression tag assert_eq!("Impression-ID", in_line.impression.id); assert_eq!( "http://example.com/track/impression", in_line.impression.content.unwrap() ); // Creative tag let creative = &in_line.creatives.content[0]; assert_eq!("5480", creative.id); assert_eq!(1, creative.sequence); assert_eq!("2447226", creative.ad_id); // UniversalAdId tag let universal_ad_id = &creative.universal_ad_ids[0]; assert_eq!("Ad-ID", universal_ad_id.id_registry); assert_eq!("8465", universal_ad_id.id_value.as_ref().unwrap()); assert_eq!("8465", universal_ad_id.content.as_ref().unwrap()); // Linear tag let linear = &creative.linear.as_ref().unwrap(); // TrackingEvent tag let event0 = &linear.tracking_events.content[0]; let event1 = &linear.tracking_events.content[1]; let event2 = &linear.tracking_events.content[2]; let event3 = &linear.tracking_events.content[3]; let event4 = &linear.tracking_events.content[4]; let event5 = &linear.tracking_events.content[5]; assert_eq!("start", event0.event); assert_eq!("firstQuartile", event1.event); assert_eq!("midpoint", event2.event); assert_eq!("thirdQuartile", event3.event); assert_eq!("complete", event4.event); assert_eq!("progress", event5.event); assert!(event0.offset.is_none()); assert!(event1.offset.is_none()); assert!(event2.offset.is_none()); assert!(event3.offset.is_none()); assert!(event4.offset.is_none()); assert_eq!("00:00:10", event5.offset.as_ref().unwrap()); assert_eq!( "http://example.com/tracking/start", event0.content.as_ref().unwrap() ); assert_eq!( "http://example.com/tracking/firstQuartile", event1.content.as_ref().unwrap() ); assert_eq!( "http://example.com/tracking/midpoint", event2.content.as_ref().unwrap() ); assert_eq!( "http://example.com/tracking/thirdQuartile", event3.content.as_ref().unwrap() ); assert_eq!( "http://example.com/tracking/complete", event4.content.as_ref().unwrap() ); assert_eq!( "http://example.com/tracking/progress-10", event5.content.as_ref().unwrap() ); // Duration tag assert_eq!("00:00:16", linear.duration.0); // MediaFile tag let media = &linear.media_files.content[0]; assert_eq!("5241", media.id.as_ref().unwrap()); assert_eq!("progressive", media.delivery); assert_eq!("video/mp4", media.r#type); assert_eq!(2000, media.bitrate.unwrap()); assert_eq!(1500, media.min_bitrate.unwrap()); assert_eq!(2500, media.max_bitrate.unwrap()); assert_eq!("1", media.scalable.as_ref().unwrap()); assert_eq!("H.264", media.codec.as_ref().unwrap()); assert_eq!("1", media.maintain_aspect_ratio.as_ref().unwrap()); assert!(media.api_framework.is_none()); assert_eq!( "https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro.mp4", media.content.as_ref().unwrap() ); }