[Yunq] Rust tests for nested messages.
This commit is contained in:
parent
f94f56f9ec
commit
72e5d8c618
|
@ -13,3 +13,15 @@ message Cap {
|
|||
message Repeated {
|
||||
repeated u64 unsigned_ints;
|
||||
}
|
||||
|
||||
|
||||
message Nested {
|
||||
Basic basic;
|
||||
Cap cap1;
|
||||
Cap cap2;
|
||||
}
|
||||
|
||||
message RepeatedNested {
|
||||
repeated Basic basics;
|
||||
repeated Cap caps;
|
||||
}
|
||||
|
|
|
@ -71,10 +71,51 @@ mod tests {
|
|||
|
||||
let parsed = Repeated::parse(&buf, 0, &caps)?;
|
||||
|
||||
println!("{:?}", parsed.unsigned_ints);
|
||||
|
||||
assert!(parsed == rep);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_serialization() -> Result<(), ZError> {
|
||||
let nested = Nested {
|
||||
basic: Basic { unsigned_int: 82, signed_int: -1234, strn: "abc".to_string() },
|
||||
cap1: Cap { cap: 37},
|
||||
cap2: Cap { cap: 39},
|
||||
};
|
||||
|
||||
let mut buf = ByteBuffer::<1024>::new();
|
||||
let mut caps = Vec::new();
|
||||
nested.serialize(&mut buf, 0, &mut caps)?;
|
||||
|
||||
let parsed = Nested::parse(&buf, 0, &caps)?;
|
||||
|
||||
|
||||
assert!(parsed == nested);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_nested_serialization() -> Result<(), ZError> {
|
||||
let nested = RepeatedNested {
|
||||
basics: vec![Basic { unsigned_int: 82, signed_int: -1234, strn: "abc".to_string(),},
|
||||
Basic { unsigned_int: 21, signed_int: -8, strn: "def".to_string(), },],
|
||||
caps: vec![Cap{ cap: 123}, Cap {cap: 12343}],
|
||||
};
|
||||
|
||||
let mut buf = ByteBuffer::<1024>::new();
|
||||
let mut caps = Vec::new();
|
||||
nested.serialize(&mut buf, 0, &mut caps)?;
|
||||
|
||||
let parsed = RepeatedNested::parse(&buf, 0, &caps)?;
|
||||
|
||||
|
||||
assert!(parsed == nested);
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ pub fn serialize_repeated_message<T: YunqMessage, const N: usize>(
|
|||
caps: &mut Vec<z_cap_t>,
|
||||
) -> Result<usize, ZError> {
|
||||
for item in data {
|
||||
offset = item.serialize(buf, offset, caps)?;
|
||||
offset += item.serialize(buf, offset, caps)?;
|
||||
}
|
||||
Ok(offset)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue