sysvmq/tests/main.rs
finga 24d9d5090e
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
sysvmq: Implement send and recv and refactor
Implement sending to and receiving from SysV IPC message queues. While
at it refactor the whole library. Write documentation for the sysvmq
library.
2023-12-08 01:50:02 +01:00

68 lines
2.2 KiB
Rust

use sysvmq::SysvMq;
#[test]
fn new_send_recv_delete() {
let mut mq = SysvMq::new(0).expect("could not create SysV message queue with key 0");
let msg = b"this is a test";
let mut buf = [0u8; 14];
mq.send(msg)
.expect("could not send message to SysV message queue");
mq.recv(&mut buf)
.expect("could not receive message from SysV message queue");
mq.delete().expect("could not destroy SysV message queue");
assert_eq!(msg, &buf);
}
#[test]
fn separate_send_recv_clone() {
let mut sender = SysvMq::new(0).expect("could not create SysV message queue with key 0");
let mut receiver = sender.clone();
let msg = b"this is another test";
let mut buf = [0u8; 20];
sender
.send(msg)
.expect("could not send message to SysV message queue");
receiver
.recv(&mut buf)
.expect("could not receive message from SysV message queue");
sender
.delete()
.expect("could not destroy SysV message queue");
assert_eq!(msg, &buf);
}
#[test]
fn separate_send_recv_open() {
let mut sender = SysvMq::new(0).expect("could not create SysV message queue with key 0");
let mut receiver = SysvMq::open(sender.key, sender.id)
.expect("could not create second handle to SysV message queue");
let msg = b"this is another test";
let mut buf = [0u8; 20];
sender
.send(msg)
.expect("could not send message to SysV message queue");
receiver
.recv(&mut buf)
.expect("could not receive message from SysV message queue");
sender
.delete()
.expect("could not destroy SysV message queue");
assert_eq!(msg, &buf);
}
#[test]
fn change_mode() {
let mut mq = SysvMq::new(0).expect("could not create SysV message queue with key 0");
let init_stats = mq
.stat()
.expect("could not get stats from SysV message queue");
mq.mode(0o666)
.expect("could not set mode of SysV message queue");
let new_stats = mq
.stat()
.expect("could not get stats from SysV message queue");
mq.delete().expect("could not destroy SysV message queue");
assert_eq!(0o644, init_stats.msg_perm.mode);
assert_eq!(0o666, new_stats.msg_perm.mode);
}