net_util: add test for create_sockaddr()

Prepare for refactoring the create_sockaddr() function by adding a test
for the existing version.

BUG=b:365852007
TEST=cargo test -p net_util sockaddr

Change-Id: Ibe2d910df93f46702ce96615220a7e8e60cc6dc9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5760285
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Daniel Verkamp 2024-08-02 15:58:27 -07:00 committed by crosvm LUCI
parent e91ab42483
commit b222eb3351

View file

@ -666,3 +666,22 @@ pub mod fakes {
impl TapT for FakeTap {}
volatile_impl!(FakeTap);
}
#[cfg(test)]
pub mod tests {
use super::*;
#[test]
fn sockaddr_byte_order() {
let sa = create_sockaddr(net::Ipv4Addr::new(1, 2, 3, 4));
assert_eq!(sa.sa_family, 2); // AF_INET
assert_eq!(
sa.sa_data,
[
0, 0, // sin_port
1, 2, 3, 4, // sin_addr
0, 0, 0, 0, 0, 0, 0, 0, // sin_zero
]
);
}
}