crosvm/msg_socket/tests/enum.rs
Stephen Barber d6945a09b8 crosvm: add license blurb to all files
A few files were missing license blurbs at the top, so update them all
to include them.

BUG=none
TEST=none

Change-Id: Ida101be2e5c255b8cffeb15f5b93f63bfd1b130b
Reviewed-on: https://chromium-review.googlesource.com/1577900
Commit-Ready: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-04-24 15:51:38 -07:00

68 lines
1.6 KiB
Rust

// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use sys_util::EventFd;
use msg_socket::*;
#[derive(MsgOnSocket)]
struct DummyRequest {}
#[derive(MsgOnSocket)]
enum Response {
A(u8),
B,
C(u32, EventFd),
D([u8; 4]),
E { f0: u8, f1: u32 },
}
#[test]
fn sock_send_recv_enum() {
let (req, res) = pair::<DummyRequest, Response>().unwrap();
let e0 = EventFd::new().unwrap();
let e1 = e0.try_clone().unwrap();
res.send(&Response::C(0xf0f0, e0)).unwrap();
let r = req.recv().unwrap();
match r {
Response::C(v, efd) => {
assert_eq!(v, 0xf0f0);
efd.write(0x0f0f).unwrap();
}
_ => panic!("wrong type"),
};
assert_eq!(e1.read().unwrap(), 0x0f0f);
res.send(&Response::B).unwrap();
match req.recv().unwrap() {
Response::B => {}
_ => panic!("Wrong enum type"),
};
res.send(&Response::A(0x3)).unwrap();
match req.recv().unwrap() {
Response::A(v) => assert_eq!(v, 0x3),
_ => panic!("Wrong enum type"),
};
res.send(&Response::D([0, 1, 2, 3])).unwrap();
match req.recv().unwrap() {
Response::D(v) => assert_eq!(v, [0, 1, 2, 3]),
_ => panic!("Wrong enum type"),
};
res.send(&Response::E {
f0: 0x12,
f1: 0x0f0f,
})
.unwrap();
match req.recv().unwrap() {
Response::E { f0, f1 } => {
assert_eq!(f0, 0x12);
assert_eq!(f1, 0x0f0f);
}
_ => panic!("Wrong enum type"),
};
}