From 9ce95637cf407fcbe9c56915ca1b602807a9f2a2 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 15 Sep 2019 16:14:12 -0700 Subject: [PATCH] const LOGIN_PACKET in tests --- src/login/login.rs | 80 +++++++++++++--------------------------------- 1 file changed, 22 insertions(+), 58 deletions(-) diff --git a/src/login/login.rs b/src/login/login.rs index e729386..ba20ea9 100644 --- a/src/login/login.rs +++ b/src/login/login.rs @@ -132,7 +132,25 @@ impl ServerState for LoginServerState { mod test { use std::time::SystemTime; use super::*; - use elseware::utf8_to_array; + + const LOGIN_PACKET: RecvLoginPacket = RecvLoginPacket::Login(Login { + flag: 0, + tag: 65536, + guildcard: 0, + version: 65, + unknown1: [0, 0, 0, 255, 0, 14], + team: 0, + username: [116, 101, 115, 116, 117, 115, 101, 114, 0, 0, 0, 0, 0, 0, 0, 0], // utf8_to_array!("testuser", 16), + unknown2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + password: [109, 121, 112, 97, 115, 115, 119, 111, 114, 100, 0, 0, 0, 0, 0, 0], // utf8_to_array!("mypassword", 16), + unknown3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0], + hwinfo: [129, 1, 1, 1, 1, 1, 1, 1], + security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + }); #[test] fn test_correct_login() { @@ -157,25 +175,7 @@ mod test { let mut server = LoginServerState::new(TestData {}); - let send = server.handle(ClientId(1), &RecvLoginPacket::Login(Login { - flag: 0, - tag: 65536, - guildcard: 0, - version: 65, - unknown1: [0, 0, 0, 255, 0, 14], - team: 0, - username: utf8_to_array!("testuser", 16), - unknown2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - password: utf8_to_array!("mypassword", 16), - unknown3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0], - hwinfo: [129, 1, 1, 1, 1, 1, 1, 1], - security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - - })).unwrap().collect::>(); + let send = server.handle(ClientId(1), &LOGIN_PACKET).unwrap().collect::>(); assert!(send == vec![ (ClientId(1), SendLoginPacket::LoginResponse(LoginResponse { flag: 0, @@ -207,26 +207,8 @@ mod test { } let mut server = LoginServerState::new(TestData {}); + let send = server.handle(ClientId(1), &LOGIN_PACKET).unwrap().collect::>(); - let send = server.handle(ClientId(1), &RecvLoginPacket::Login(Login { - flag: 0, - tag: 65536, - guildcard: 0, - version: 65, - unknown1: [0, 0, 0, 255, 0, 14], - team: 0, - username: utf8_to_array!("testuser", 16), - unknown2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - password: utf8_to_array!("mypassword", 16), - unknown3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0], - hwinfo: [129, 1, 1, 1, 1, 1, 1, 1], - security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - - })).unwrap().collect::>(); assert!(send == vec![ (ClientId(1), SendLoginPacket::LoginResponse(LoginResponse { flag: 0, @@ -262,26 +244,8 @@ mod test { } let mut server = LoginServerState::new(TestData {}); + let send = server.handle(ClientId(1), &LOGIN_PACKET).unwrap().collect::>(); - let send = server.handle(ClientId(1), &RecvLoginPacket::Login(Login { - flag: 0, - tag: 65536, - guildcard: 0, - version: 65, - unknown1: [0, 0, 0, 255, 0, 14], - team: 0, - username: utf8_to_array!("testuser", 16), - unknown2: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - password: utf8_to_array!("mypassword", 16), - unknown3: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0], - hwinfo: [129, 1, 1, 1, 1, 1, 1, 1], - security_data: [74, 97, 107, 101, 115, 101, 114, 118, 50, 48, 50, 48, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], - - })).unwrap().collect::>(); assert!(send == vec![ (ClientId(1), SendLoginPacket::LoginResponse(LoginResponse { flag: 0,