aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2020-01-17 12:30:27 +0100
committerMax Audron <audron@cocaine.farm>2020-01-17 12:30:27 +0100
commit07561131e9ec3d1f3aef99a8df2e3b9b7282156e (patch)
tree72830d0eff2dd04698cc9ae9d698d31cc139056f /src/tests
parentfinish main parsing (diff)
add error handling
Diffstat (limited to '')
-rw-r--r--src/tests/base_types.rs16
-rw-r--r--src/tests/handshake_types.rs8
-rw-r--r--src/tests/variant_types.rs31
3 files changed, 19 insertions, 36 deletions
diff --git a/src/tests/base_types.rs b/src/tests/base_types.rs
index 99e6cd5..45f1fd3 100644
--- a/src/tests/base_types.rs
+++ b/src/tests/base_types.rs
@@ -8,14 +8,14 @@ use crate::protocol::primitive::*;
pub fn serialize_string() {
let test_string: String = String::from("Configured");
- assert_eq!(test_string.serialize(), [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(), [0, 0, 0, 10, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100]);
+ assert_eq!(test_string.serialize_utf8().unwrap(), [0, 0, 0, 10, 67, 111, 110, 102, 105, 103, 117, 114, 101, 100]);
}
#[test]
@@ -25,7 +25,7 @@ pub fn read_string() {
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);
+ let len = String::read(&mut Cursor::new(&test_bytes), &mut buf).unwrap();
assert_eq!(len, 24);
@@ -36,7 +36,7 @@ pub fn read_string() {
#[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);
+ let (len, res) = String::parse(test_bytes).unwrap();
assert_eq!(res, "Configured");
assert_eq!(len, 24);
}
@@ -44,7 +44,7 @@ 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 (len, res) = String::parse_utf8(test_bytes);
+ let (len, res) = String::parse_utf8(test_bytes).unwrap();
assert_eq!(len, 14);
assert_eq!(res, "Configured");
}
@@ -54,7 +54,7 @@ pub fn serialize_string_list() {
let mut test_list = StringList::new();
test_list.push("Configured".to_string());
assert_eq!(
- test_list.serialize(),
+ 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]
)
}
@@ -66,7 +66,7 @@ pub fn read_string_list() {
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);
+ let len = StringList::read(&mut Cursor::new(&test_bytes), &mut buf).unwrap();
assert_eq!(len, 28);
@@ -80,7 +80,7 @@ pub fn deserialize_string_list() {
let mut test_list = StringList::new();
test_list.push("Configured".to_string());
println!("aaaaa");
- let (len, res) = StringList::parse(test_bytes);
+ 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 dd3387f..a664128 100644
--- a/src/tests/handshake_types.rs
+++ b/src/tests/handshake_types.rs
@@ -9,7 +9,7 @@ pub fn serialize_variantmap() {
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(),
+ test_variantmap.serialize().unwrap(),
bytes
);
}
@@ -23,7 +23,7 @@ pub fn read_variantmap() {
0, 0, 0, 1, 0, 1, 0, 0, 0, 1];
let mut buf: Vec<u8> = [0; 43].to_vec();
- let len = VariantMap::read(&mut Cursor::new(&test_bytes), &mut buf);
+ let len = VariantMap::read(&mut Cursor::new(&test_bytes), &mut buf).unwrap();
assert_eq!(len, 43);
@@ -41,7 +41,7 @@ pub fn deserialize_variantmap() {
let mut test_variantmap = VariantMap::new();
test_variantmap.insert("Configured".to_string(), Variant::bool(true));
- let (len, res) = VariantMap::parse(test_bytes);
+ let (len, res) = VariantMap::parse(test_bytes).unwrap();
assert_eq!(len, 43);
assert_eq!(res, test_variantmap);
@@ -55,7 +55,7 @@ pub fn deserialize_variantmap_utf8() {
let mut test_variantmap = VariantMap::new();
test_variantmap.insert("Configured".to_string(), Variant::bool(true));
- let (len, res) = VariantMap::parse(test_bytes);
+ let (len, res) = VariantMap::parse(test_bytes).unwrap();
assert_eq!(len, 33);
assert_eq!(res, test_variantmap);
diff --git a/src/tests/variant_types.rs b/src/tests/variant_types.rs
index 8c4dedc..6c49506 100644
--- a/src/tests/variant_types.rs
+++ b/src/tests/variant_types.rs
@@ -8,11 +8,11 @@ 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(),
+ test_variant_true.serialize().unwrap(),
[0, 0, 0, 1, 0, 1]
);
assert_eq!(
- test_variant_false.serialize(),
+ test_variant_false.serialize().unwrap(),
[0, 0, 0, 1, 0, 0]
);
}
@@ -20,7 +20,7 @@ pub fn serialize_variant_bool() {
#[test]
pub fn deserialize_variant_bool() {
let test_bytes: &[u8] = &[0, 0, 0, 1, 0, 1, 0, 0, 0, 1];
- let (len, res) = Variant::parse(test_bytes);
+ let (len, res) = Variant::parse(test_bytes).unwrap();
assert_eq!(len, 6);
assert_eq!(res, Variant::bool(true));
}
@@ -30,7 +30,7 @@ pub fn serialize_variantlist() {
let mut test_variantlist = VariantList::new();
test_variantlist.push(Variant::bool(true));
assert_eq!(
- test_variantlist.serialize(),
+ test_variantlist.serialize().unwrap(),
[0, 0, 0, 1, 0, 0, 0, 1, 0, 1]
);
}
@@ -38,7 +38,7 @@ pub fn serialize_variantlist() {
#[test]
pub fn deserialize_variantlist() {
let test_bytes: &[u8] = &[0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1];
- let (len, res) = VariantList::parse(test_bytes);
+ let (len, res) = VariantList::parse(test_bytes).unwrap();
let mut test_variantlist = VariantList::new();
test_variantlist.push(Variant::bool(true));
assert_eq!(len, 10);
@@ -53,7 +53,7 @@ pub fn serialize_variantmap() {
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(),
+ test_variantmap.serialize().unwrap(),
bytes
);
}
@@ -63,26 +63,9 @@ 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 (len, res) = VariantMap::parse(test_bytes);
+ 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!(res, test_variantmap);
}
-
-//
-// 0000 00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 ..............E.
-// 0010 00 e2 36 3d 40 00 40 06 05 d7 7f 00 00 01 7f 00 ..6=@.@.........
-// 0020 00 01 10 92 c0 dc e8 73 50 fe 2f 68 6d 9e 80 18 .......sP./hm...
-// 0030 02 00 fe d6 00 00 01 01 08 0a 5f 0a 31 00 5f 0a .........._.1._.
-// 0040 31 00 00 00 00 aa 00 00 00 0a 00 00 00 0c 00 00 1...............
-// 0050 00 00 0a 43 6f 6e 66 69 67 75 72 65 64 00 00 00 ...Configured...
-// 0060 01 00 01 00 00 00 0c 00 00 00 00 0c 43 6f 72 65 ............Core
-// 0070 46 65 61 74 75 72 65 73 00 00 00 03 00 00 00 fe Features........
-// 0080 ff 00 00 00 0c 00 00 00 00 0c 4c 6f 67 69 6e 45 ..........LoginE
-// 0090 6e 61 62 6c 65 64 00 00 00 01 00 01 00 00 00 0c nabled..........
-// 00a0 00 00 00 00 07 4d 73 67 54 79 70 65 00 00 00 0a .....MsgType....
-// 00b0 00 00 00 00 1a 00 43 00 6c 00 69 00 65 00 6e 00 ......C.l.i.e.n.
-// 00c0 74 00 49 00 6e 00 69 00 74 00 41 00 63 00 6b 00 t.I.n.i.t.A.c.k.
-// 00d0 00 00 0c 00 00 00 00 0f 53 74 6f 72 61 67 65 42 ........StorageB
-// 00e0 61 63 6b 65 6e 64 73 00 00 00 09 00 00 00 00 00 ackends.........