aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/base_types.rs76
-rw-r--r--src/tests/handshake_types.rs80
-rw-r--r--src/tests/mod.rs1
-rw-r--r--src/tests/variant_types.rs73
4 files changed, 106 insertions, 124 deletions
diff --git a/src/tests/base_types.rs b/src/tests/base_types.rs
index 45f1fd3..4cc56ae 100644
--- a/src/tests/base_types.rs
+++ b/src/tests/base_types.rs
@@ -1,6 +1,5 @@
-use crate::protocol::primitive::serialize::{Serialize, SerializeUTF8};
use crate::protocol::primitive::deserialize::{Deserialize, DeserializeUTF8};
-use crate::protocol::primitive::qread::QRead;
+use crate::protocol::primitive::serialize::{Serialize, SerializeUTF8};
use crate::protocol::primitive::*;
@@ -8,34 +7,31 @@ use crate::protocol::primitive::*;
pub fn serialize_string() {
let test_string: String = String::from("Configured");
- assert_eq!(test_string.serialize().unwrap(), [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!(
+ test_string.serialize().unwrap(),
+ [
+ 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101, 0,
+ 100
+ ]
+ );
}
#[test]
pub fn serialize_string_utf8() {
let test_string: String = String::from("Configured");
- assert_eq!(test_string.serialize_utf8().unwrap(), [0, 0, 0, 10, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100]);
-}
-
-#[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).unwrap();
-
- 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);
+ assert_eq!(
+ test_string.serialize_utf8().unwrap(),
+ [0, 0, 0, 11, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100, 0]
+ );
}
#[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 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).unwrap();
assert_eq!(res, "Configured");
assert_eq!(len, 24);
@@ -43,43 +39,45 @@ pub fn deserialize_string() {
#[test]
pub fn deserialize_string_utf8() {
- let test_bytes: &[u8] = &[0, 0, 0, 10, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100, 0, 0, 0, 1];
+ let test_bytes: &[u8] = &[
+ 0, 0, 0, 10, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100, 0, 0, 0, 1,
+ ];
let (len, res) = String::parse_utf8(test_bytes).unwrap();
assert_eq!(len, 14);
assert_eq!(res, "Configured");
}
#[test]
+pub fn deserialize_string_utf8_null_terminated() {
+ let test_bytes: &[u8] = &[
+ 0, 0, 0, 11, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100, 0, 0, 0, 0, 1,
+ ];
+ let (len, res) = String::parse_utf8(test_bytes).unwrap();
+ assert_eq!(len, 15);
+ assert_eq!(res, "Configured");
+}
+
+#[test]
pub fn serialize_string_list() {
let mut test_list = StringList::new();
test_list.push("Configured".to_string());
assert_eq!(
test_list.serialize().unwrap(),
- [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, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114,
+ 0, 101, 0, 100
+ ]
)
}
#[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).unwrap();
-
- 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, 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 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");
let (len, res) = StringList::parse(test_bytes).unwrap();
assert_eq!(len, 28);
assert_eq!(test_list, res);
diff --git a/src/tests/handshake_types.rs b/src/tests/handshake_types.rs
index d9368b2..d18ec8a 100644
--- a/src/tests/handshake_types.rs
+++ b/src/tests/handshake_types.rs
@@ -1,71 +1,24 @@
-use crate::protocol::message::handshake::{VariantMap, HandshakeSerialize, HandshakeDeserialize, HandshakeQRead};
-use crate::protocol::primitive::{Variant};
+use crate::protocol::message::handshake::{HandshakeDeserialize, HandshakeSerialize, VariantMap};
+use crate::protocol::primitive::Variant;
#[test]
pub fn serialize_variantmap() {
let mut test_variantmap = VariantMap::new();
test_variantmap.insert("Configured".to_string(), Variant::bool(true));
- let bytes = [0, 0, 0, 2, 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].to_vec();
- assert_eq!(
- test_variantmap.serialize().unwrap(),
- bytes
- );
-}
-
-#[test]
-pub fn read_variantmap() {
- use std::io::Cursor;
-
- let test_bytes: Vec<u8> = vec![
- // len
- 0, 0, 0, 4, // 4
- // var
- 0, 0, 0, 10, 0, // 5
- // strlen, str
- 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101, 0, 100, // 24
- // bool
- 0, 0, 0, 1, 0, 1, // 6
- // var
- 0, 0, 0, 10, 0, // 5
- // strlen, str
- 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101, 0, 100, // 24
- // bool
- 0, 0, 0, 1, 0, 1, //6
- // extra
- 0, 0, 0, 1];
-
- let mut buf: Vec<u8> = [0; 74].to_vec();
- let len = VariantMap::read(&mut Cursor::new(&test_bytes), &mut buf).unwrap();
-
- assert_eq!(len, 74);
-
- let result_bytes: Vec<u8> = vec![
- // len
- 0, 0, 0, 4,
- // var
- 0, 0, 0, 10, 0,
- // strlen, str
- 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101, 0, 100,
- // bool
- 0, 0, 0, 1, 0, 1,
- // var
- 0, 0, 0, 10, 0,
- // strlen, str
- 0, 0, 0, 20, 0, 67, 0, 111, 0, 110, 0, 102, 0, 105, 0, 103, 0, 117, 0, 114, 0, 101, 0, 100,
- // bool
- 0, 0, 0, 1, 0, 1];
- assert_eq!(buf, result_bytes);
+ let bytes = [
+ 0, 0, 0, 2, 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,
+ ]
+ .to_vec();
+ assert_eq!(test_variantmap.serialize().unwrap(), bytes);
}
#[test]
pub fn deserialize_variantmap() {
- let test_bytes: &[u8] = &[0, 0, 0, 2,
- 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 test_bytes: &[u8] = &[
+ 0, 0, 0, 2, 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 mut test_variantmap = VariantMap::new();
test_variantmap.insert("Configured".to_string(), Variant::bool(true));
@@ -77,11 +30,10 @@ pub fn deserialize_variantmap() {
#[test]
pub fn deserialize_variantmap_utf8() {
- let test_bytes: &[u8] = &[0, 0, 0, 2,
- 0, 0, 0, 12, 0,
- 0, 0, 0, 10, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100,
- 0, 0, 0, 1, 0, 1,
- 0, 0, 0, 1];
+ let test_bytes: &[u8] = &[
+ 0, 0, 0, 2, 0, 0, 0, 12, 0, 0, 0, 0, 10, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100,
+ 0, 0, 0, 1, 0, 1, 0, 0, 0, 1,
+ ];
let mut test_variantmap = VariantMap::new();
test_variantmap.insert("Configured".to_string(), Variant::bool(true));
diff --git a/src/tests/mod.rs b/src/tests/mod.rs
index 4b030c7..16fd124 100644
--- a/src/tests/mod.rs
+++ b/src/tests/mod.rs
@@ -3,6 +3,7 @@ pub mod base_types;
#[allow(unused_imports)]
#[allow(unused_macros)]
#[allow(dead_code)]
+#[cfg(feature = "framing")]
pub mod frame;
pub mod handshake_types;
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);
+}