1 /*
2  * Copyright (C) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 //! unittest
16 #![allow(missing_docs)]
17 
18 #[cfg(test)]
19 mod tests {
20     use crate::serializer::native_struct;
21     use crate::serializer::serialize::Serialization;
22 
23     #[test]
if_session_hand_shake_worksnull24     fn if_session_hand_shake_works() {
25         let send = native_struct::SessionHandShake {
26             banner: "test_banner".to_string(),
27             auth_type: 1,
28             session_id: 2,
29             connect_key: "test_connect_key".to_string(),
30             buf: "test_buf".to_string(),
31             version: "test_version".to_string(),
32         };
33 
34         let serialized = send.serialize();
35         let mut recv = native_struct::SessionHandShake::default();
36         let suc = recv.parse(serialized);
37 
38         println!("{:#?}", recv);
39         assert!(suc.is_ok());
40         assert_eq!(recv, send);
41     }
42 
43     #[test]
if_session_transfer_payload_worksnull44     fn if_session_transfer_payload_works() {
45         let send = native_struct::TransferPayload {
46             index: 1 << 60,
47             compress_type: 1 << 6,
48             compress_size: 1 << 20,
49             uncompress_size: 1 << 23,
50         };
51 
52         let serialized = send.serialize();
53         let mut recv = native_struct::TransferPayload::default();
54         let suc = recv.parse(serialized);
55 
56         println!("{:#?}", recv);
57         assert!(suc.is_ok());
58         assert_eq!(recv, send);
59     }
60 
61     #[test]
if_transfer_config_worksnull62     fn if_transfer_config_works() {
63         let send = native_struct::TransferConfig {
64             file_size: 1 << 40,
65             atime: 1 << 50,
66             mtime: 1 << 60,
67             options: "options".to_string(),
68             path: "path".to_string(),
69             optional_name: "optional_name".to_string(),
70             update_if_new: true,
71             compress_type: 3,
72             hold_timestamp: false,
73             function_name: "function_name".to_string(),
74             client_cwd: "client_cwd\\client_cwd".to_string(),
75             reserve1: "reserve1".to_string(),
76             reserve2: "reserve2".to_string(),
77         };
78 
79         let serialized = send.serialize();
80         let mut recv = native_struct::TransferConfig {
81             ..Default::default()
82         };
83         let suc = recv.parse(serialized);
84 
85         println!("{:#?}", recv);
86         assert!(suc.is_ok());
87         assert_eq!(recv, send);
88     }
89 
90     #[test]
if_session_payload_head_worksnull91     fn if_session_payload_head_works() {
92         let send = native_struct::PayloadHead {
93             flag: [1, 2],
94             reserve: [3, 4],
95             protocol_ver: 0x11,
96             head_size: 0x22,
97             data_size: 0x33,
98         };
99         let serialized = send.serialize();
100         let mut recv = native_struct::PayloadHead::default();
101         let suc = recv.parse(serialized);
102 
103         println!("{:#?}", recv);
104         assert!(suc.is_ok());
105         assert_eq!(recv, send);
106     }
107 }
108