Skip to content

Commit

Permalink
Add reply tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zargony committed Apr 1, 2014
1 parent 2e27cef commit a33df7e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ impl ReplyDirectory {
#[cfg(test)]
mod test {
use super::as_bytes;
use super::{Reply, ReplyRaw, ReplyEmpty, ReplyData};

#[test]
fn serialize_empty () {
Expand All @@ -190,4 +191,49 @@ mod test {
assert!(bytes == [&[0x12, 0x34, 0x78, 0x56]]);
});
}

#[test]
fn reply_raw () {
struct Data { a: u8, b: u8, c: u16 }
let data = Data { a: 0x12, b: 0x34, c: 0x5678 };
let reply: ReplyRaw<Data> = Reply::new(0xdeadbeef, proc(bytes) {
assert!(bytes == [
&[0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef, 0xbe, 0xad, 0xde, 0x00, 0x00, 0x00, 0x00],
&[0x12, 0x34, 0x78, 0x56],
]);
});
reply.ok(&data);
}

#[test]
fn reply_error () {
struct Data { a: u8, b: u8, c: u16 }
let reply: ReplyRaw<Data> = Reply::new(0xdeadbeef, proc(bytes) {
assert!(bytes == [
&[0x10, 0x00, 0x00, 0x00, 0xbe, 0xff, 0xff, 0xff, 0xef, 0xbe, 0xad, 0xde, 0x00, 0x00, 0x00, 0x00],
]);
});
reply.error(66);
}

#[test]
fn reply_empty () {
let reply: ReplyEmpty = Reply::new(0xdeadbeef, proc(bytes) {
assert!(bytes == [
&[0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef, 0xbe, 0xad, 0xde, 0x00, 0x00, 0x00, 0x00],
]);
});
reply.ok();
}

#[test]
fn reply_data () {
let reply: ReplyData = Reply::new(0xdeadbeef, proc(bytes) {
assert!(bytes == [
&[0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xef, 0xbe, 0xad, 0xde, 0x00, 0x00, 0x00, 0x00],
&[0xde, 0xad, 0xbe, 0xef],
]);
});
reply.ok([0xde, 0xad, 0xbe, 0xef]);
}
}

0 comments on commit a33df7e

Please sign in to comment.