diff options
| author | Max Audron <audron@cocaine.farm> | 2020-01-17 10:47:50 +0100 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2020-01-17 10:48:44 +0100 |
| commit | de973723312c56a58651f12146668500697543c0 (patch) | |
| tree | f7cc1e5f9039101bc199e611901b162aa4ed13b1 /src/tests/base_types.rs | |
| parent | refactor parse impl (diff) | |
finish main parsing
Diffstat (limited to 'src/tests/base_types.rs')
| -rw-r--r-- | src/tests/base_types.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/tests/base_types.rs b/src/tests/base_types.rs index a35f243..99e6cd5 100644 --- a/src/tests/base_types.rs +++ b/src/tests/base_types.rs @@ -1,5 +1,6 @@ use crate::protocol::primitive::serialize::{Serialize, SerializeUTF8}; use crate::protocol::primitive::deserialize::{Deserialize, DeserializeUTF8}; +use crate::protocol::primitive::qread::QRead; use crate::protocol::primitive::*; @@ -18,6 +19,21 @@ pub fn serialize_string_utf8() { } #[test] +pub fn read_string() { + use std::io::Cursor; + + let test_bytes: Vec<u8> = vec![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]; + + let mut buf: Vec<u8> = [0; 24].to_vec(); + let len = String::read(&mut Cursor::new(&test_bytes), &mut buf); + + assert_eq!(len, 24); + + let result_bytes: Vec<u8> = vec![0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101, 0, 100]; + assert_eq!(buf, result_bytes); +} + +#[test] pub fn deserialize_string() { let test_bytes: &[u8] = &[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]; let (len, res) = String::parse(test_bytes); @@ -44,8 +60,23 @@ pub fn serialize_string_list() { } #[test] +pub fn read_string_list() { + use std::io::Cursor; + + let test_bytes: Vec<u8> = vec![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]; + + let mut buf: Vec<u8> = [0; 28].to_vec(); + let len = StringList::read(&mut Cursor::new(&test_bytes), &mut buf); + + assert_eq!(len, 28); + + let result_bytes: Vec<u8> = vec![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]; + assert_eq!(buf, result_bytes); +} + +#[test] pub fn deserialize_string_list() { - let test_bytes: &[u8] = &[0, 0, 0, 24, 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]; + 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]; let mut test_list = StringList::new(); test_list.push("Configured".to_string()); println!("aaaaa"); |
