From 32592f49c769651be5811f82dfa96813460e1d0a Mon Sep 17 00:00:00 2001 From: Sawyer McLane Date: Tue, 5 Nov 2024 14:32:30 -0700 Subject: [PATCH] Add serialization tests for DeviceInfo and its variants --- src/device_info.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/device_info.rs b/src/device_info.rs index 19cc9c3..c150429 100644 --- a/src/device_info.rs +++ b/src/device_info.rs @@ -637,4 +637,33 @@ mod tests { let color = handle_multizone(empty_data); assert!(color.is_none()); } + + #[test] + fn test_serde_bulb_info() { + let source = 1234; + let target = 5678; + let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 56700); + let bulb = BulbInfo::new(source, target, addr); + + let device_info = DeviceInfo::Bulb(Box::new(bulb.clone())); + + let serialized = serde_json::to_string(&device_info).unwrap(); + let deserialized: DeviceInfo = serde_json::from_str(&serialized).unwrap(); + + assert_eq!(device_info, deserialized); + } + + #[test] + fn test_serde_group_info() { + let group_ident = LifxIdent([1u8; 16]); + let group_label = LifxString::new(&CString::new("TestGroup").unwrap()); + let group = GroupInfo::new(group_ident, group_label); + + let device_info = DeviceInfo::Group(group.clone()); + + let serialized = serde_json::to_string(&device_info).unwrap(); + let deserialized: DeviceInfo = serde_json::from_str(&serialized).unwrap(); + + assert_eq!(device_info, deserialized); + } }