Skip to content

Commit

Permalink
Add serialization tests for DeviceInfo and its variants
Browse files Browse the repository at this point in the history
  • Loading branch information
samclane committed Nov 5, 2024
1 parent c2e1a9a commit 32592f4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/device_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 32592f4

Please sign in to comment.