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