diff options
| author | Max Audron <audron@cocaine.farm> | 2020-04-25 19:35:29 +0200 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2020-04-25 19:35:29 +0200 |
| commit | c546e2ef6c69bb1c6a86093f3cc7b2dab20d6ac4 (patch) | |
| tree | 5f761765863f39405a3ae6e27cb865ead6be2e38 /src/tests/variant_types.rs | |
| parent | finish FramedCodec (diff) | |
finish parsing of primitive types
Diffstat (limited to 'src/tests/variant_types.rs')
| -rw-r--r-- | src/tests/variant_types.rs | 73 |
1 files changed, 52 insertions, 21 deletions
diff --git a/src/tests/variant_types.rs b/src/tests/variant_types.rs index 6c49506..0381f07 100644 --- a/src/tests/variant_types.rs +++ b/src/tests/variant_types.rs @@ -1,20 +1,16 @@ -use crate::protocol::primitive::serialize::Serialize; use crate::protocol::primitive::deserialize::Deserialize; +use crate::protocol::primitive::serialize::Serialize; -use crate::protocol::primitive::{Variant, VariantList, VariantMap}; +use crate::protocol::primitive::{ + BufferInfo, BufferType, Message, Variant, VariantList, VariantMap, +}; #[test] pub fn serialize_variant_bool() { let test_variant_true = Variant::bool(true); let test_variant_false = Variant::bool(false); - assert_eq!( - test_variant_true.serialize().unwrap(), - [0, 0, 0, 1, 0, 1] - ); - assert_eq!( - test_variant_false.serialize().unwrap(), - [0, 0, 0, 1, 0, 0] - ); + assert_eq!(test_variant_true.serialize().unwrap(), [0, 0, 0, 1, 0, 1]); + assert_eq!(test_variant_false.serialize().unwrap(), [0, 0, 0, 1, 0, 0]); } #[test] @@ -49,23 +45,58 @@ pub fn deserialize_variantlist() { pub fn serialize_variantmap() { let mut test_variantmap = VariantMap::new(); test_variantmap.insert("Configured".to_string(), Variant::bool(true)); - let bytes = [0, 0, 0, 1, - 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101, 0, 100, - 0, 0, 0, 1, 0, 1].to_vec(); - assert_eq!( - test_variantmap.serialize().unwrap(), - bytes - ); + let bytes = [ + 0, 0, 0, 1, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, + 101, 0, 100, 0, 0, 0, 1, 0, 1, + ] + .to_vec(); + assert_eq!(test_variantmap.serialize().unwrap(), bytes); } #[test] pub fn deserialize_variantmap() { - let test_bytes: &[u8] = &[0, 0, 0, 1, - 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101, 0, 100, - 0, 0, 0, 1, 0, 1, 0, 0, 0, 1]; + let test_bytes: &[u8] = &[ + 0, 0, 0, 1, 0, 0, 0, 10, 0, 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, + 117, 0, 114, 0, 101, 0, 100, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, + ]; let (len, res) = VariantMap::parse(test_bytes).unwrap(); let mut test_variantmap = VariantMap::new(); test_variantmap.insert("Configured".to_string(), Variant::bool(true)); - assert_eq!(len, 34); + assert_eq!(len, 39); assert_eq!(res, test_variantmap); } + +#[test] +pub fn serialize_buffer_info() { + let test_buffer_info = BufferInfo { + id: 0, + network_id: 0, + buffer_type: BufferType::Status, + name: "test".to_string(), + }; + + let bytes = vec![ + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, + 0x74, 0x65, 0x73, 0x74, 0x0, + ]; + assert_eq!(test_buffer_info.serialize().unwrap(), bytes); +} + +#[test] +pub fn deserialize_buffer_info() { + let test_buffer_info = BufferInfo { + id: 0, + network_id: 0, + buffer_type: BufferType::Status, + name: "test".to_string(), + }; + + let bytes = vec![ + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, + 0x74, 0x65, 0x73, 0x74, 0x0, + ]; + let (len, res) = BufferInfo::parse(&bytes).unwrap(); + + assert_eq!(len, 23); + assert_eq!(res, test_buffer_info); +} |
