From 9384fd7eeb51231165e406e4e1af31f548b918b3 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 19 Jun 2023 23:25:48 +0200 Subject: [PATCH] jid: Test for the size of our structs This shows how big JIDs are represented on the stack and in other structs. --- jid/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/jid/src/lib.rs b/jid/src/lib.rs index 35df53d..9d3a9e2 100644 --- a/jid/src/lib.rs +++ b/jid/src/lib.rs @@ -769,6 +769,28 @@ mod tests { use std::collections::HashMap; use std::str::FromStr; + macro_rules! assert_size ( + ($t:ty, $sz:expr) => ( + assert_eq!(::std::mem::size_of::<$t>(), $sz); + ); + ); + + #[cfg(target_pointer_width = "32")] + #[test] + fn test_size() { + assert_size!(BareJid, 24); + assert_size!(FullJid, 36); + assert_size!(Jid, 36); + } + + #[cfg(target_pointer_width = "64")] + #[test] + fn test_size() { + assert_size!(BareJid, 48); + assert_size!(FullJid, 72); + assert_size!(Jid, 72); + } + #[test] fn can_parse_full_jids() { assert_eq!(