crosvm/msg_socket/tests/struct.rs
Zach Reizner 3c71bb953e msg_socket_on_derive: use fully qualified types
The types from msg_socket were assumed to be in scope for the custom
derive implementation, which would cause mysterious compiler errors if
the custom derive was invoked in a module without msg_socket types in
scope.

This CL uses fully qualified types in the generated output to avoid
these errors.

This change also uses `extern crate msg_socket` in case the call site
doesn't have it in scope.

BUG=None
TEST=cargo test -p msg_on_socket_derive

Change-Id: Ie6443cd4ffc070d27e71de123090a58f19846472
Reviewed-on: https://chromium-review.googlesource.com/1314208
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Jingkui Wang <jkwang@google.com>
2018-11-07 06:35:06 -08:00

35 lines
733 B
Rust

extern crate msg_on_socket_derive;
extern crate msg_socket;
extern crate sys_util;
use sys_util::EventFd;
use msg_socket::*;
#[derive(MsgOnSocket)]
struct Request {
field0: u8,
field1: EventFd,
field2: u32,
}
#[derive(MsgOnSocket)]
struct DummyResponse {}
#[test]
fn sock_send_recv_struct() {
let (req, res) = pair::<Request, DummyResponse>().unwrap();
let e0 = EventFd::new().unwrap();
let e1 = e0.try_clone().unwrap();
req.send(&Request {
field0: 2,
field1: e0,
field2: 0xf0f0,
}).unwrap();
let r = res.recv().unwrap();
assert_eq!(r.field0, 2);
assert_eq!(r.field2, 0xf0f0);
r.field1.write(0x0f0f).unwrap();
assert_eq!(e1.read().unwrap(), 0x0f0f);
}