1/* 2 * Copyright (C) 2022 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 16import { Serialize } from '../../../src/hdc/common/Serialize'; 17 18describe('Serialize Test', () => { 19 it('Serialize Test01', function () { 20 let banne = { 21 banner: 1, 22 authType: 1, 23 sessionId: 1, 24 connectKey: 1, 25 buf: 'buf', 26 version: 'Ver: 3.0.0b', 27 }; 28 expect(Serialize.serializeSessionHandShake(banne)).not.toBeUndefined(); 29 }); 30 it('Serialize Test02', function () { 31 let payloadProtect = { 32 channelId: 1, 33 commandFlag: 1, 34 checkSum: 1, 35 vCode: 1, 36 }; 37 expect(Serialize.serializePayloadProtect(payloadProtect)).not.toBeUndefined(); 38 }); 39 it('Serialize Test03', function () { 40 let transferConfig = { 41 fileSize: 1, 42 atime: 1, 43 mtime: 1, 44 options: 1, 45 path: 1, 46 optionalName: 1, 47 updateIfNew: 1, 48 compressType: 1, 49 holdTimestamp: 1, 50 functionName: 1, 51 clientCwd: 1, 52 reserve1: 1, 53 reserve2: 1, 54 }; 55 expect(Serialize.serializeTransferConfig(transferConfig)).not.toBeUndefined(); 56 }); 57 it('Serialize Test04', function () { 58 let transferPayload = { 59 index: 1, 60 compressType: 1, 61 compressSize: 1, 62 uncompressSize: 1, 63 }; 64 expect(Serialize.serializeTransferPayload(transferPayload)).not.toBeUndefined(); 65 }); 66 it('Serialize Test06', function () { 67 let data = { 68 buffer: 1, 69 }; 70 // @ts-ignore 71 let uint8Array = new Uint8Array(data); 72 let dataBuffer = uint8Array.buffer; 73 expect(Serialize.parseTransferConfig(data)).not.toBeUndefined(); 74 }); 75 it('Serialize Test05', function () { 76 let tagKey = 1; 77 expect(Serialize.readTagWireType(tagKey)).not.toBeUndefined(); 78 }); 79 it('Serialize Test07', function () { 80 let data = { 81 buffer: 1, 82 }; 83 // @ts-ignore 84 let uint8Array = new Uint8Array(data); 85 let dataBuffer = uint8Array.buffer; 86 expect(Serialize.parsePayloadProtect(data)).not.toBeUndefined(); 87 }); 88 89 it('Serialize Test08', function () { 90 expect(Serialize.writeVarIntU64(100_000_000)).not.toBeUndefined(); 91 }); 92 93 it('Serialize Test09', function () { 94 let data = { 95 buffer: 1, 96 }; 97 // @ts-ignore 98 let uint8Array = new Uint8Array(data); 99 expect(Serialize.parseString(uint8Array, 1)).not.toBeUndefined(); 100 }); 101 102 it('Serialize Test10', function () { 103 let data = { 104 buffer: 1, 105 }; 106 // @ts-ignore 107 let uint8Array = new Uint8Array(data); 108 expect(Serialize.parseHandshake(uint8Array)).toEqual({ 109 _authType: -1, 110 _banner: '', 111 _buf: '', 112 _connectKey: '', 113 _sessionId: -1, 114 _version: '', 115 }); 116 }); 117 118 it('Serialize Test11', function () { 119 expect(Serialize.writeVarIntU32(100_000_000)).not.toBeUndefined(); 120 }); 121}); 122