1fb726d48Sopenharmony_ci/*
2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License.
5fb726d48Sopenharmony_ci * You may obtain a copy of the License at
6fb726d48Sopenharmony_ci *
7fb726d48Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8fb726d48Sopenharmony_ci *
9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and
13fb726d48Sopenharmony_ci * limitations under the License.
14fb726d48Sopenharmony_ci */
15fb726d48Sopenharmony_ci
16fb726d48Sopenharmony_ciimport {
17fb726d48Sopenharmony_ci  hiSysEventDataReceiver,
18fb726d48Sopenharmony_ci  chartHiSysEventDataSql
19fb726d48Sopenharmony_ci} from '../../../../src/trace/database/data-trafic/HiSysEventDataReceiver';
20fb726d48Sopenharmony_ciimport { TraficEnum } from '../../../../src/trace/database/data-trafic/utils/QueryEnum';
21fb726d48Sopenharmony_ci
22fb726d48Sopenharmony_cidescribe('hiSysEventDataReceiver Test', () => {
23fb726d48Sopenharmony_ci  let data;
24fb726d48Sopenharmony_ci  let proc;
25fb726d48Sopenharmony_ci
26fb726d48Sopenharmony_ci  beforeEach(() => {
27fb726d48Sopenharmony_ci    data = {
28fb726d48Sopenharmony_ci      params: {
29fb726d48Sopenharmony_ci        trafic: TraficEnum.ProtoBuffer,
30fb726d48Sopenharmony_ci        sharedArrayBuffers: {
31fb726d48Sopenharmony_ci          id: new Uint16Array([1, 2, 3]),
32fb726d48Sopenharmony_ci        },
33fb726d48Sopenharmony_ci      },
34fb726d48Sopenharmony_ci    };
35fb726d48Sopenharmony_ci    proc = jest.fn((sql) => [
36fb726d48Sopenharmony_ci      {hiSysEventData: {id: 4, ts: 4.4, pid: 40, tid: 400, seq: 0.4, uid: 4000, dur: 40000, depth: 4}},
37fb726d48Sopenharmony_ci      {hiSysEventData: {id: 5, ts: 5.5, pid: 50, tid: 500, seq: 0.5, uid: 5000, dur: 50000, depth: 5}},
38fb726d48Sopenharmony_ci    ]);
39fb726d48Sopenharmony_ci  });
40fb726d48Sopenharmony_ci  it('hiSysEventDataReceiverTest01', () => {
41fb726d48Sopenharmony_ci    const args = {
42fb726d48Sopenharmony_ci      recordStartNS: 1000,
43fb726d48Sopenharmony_ci      endNS: 3000,
44fb726d48Sopenharmony_ci      startNS: 2000,
45fb726d48Sopenharmony_ci      width: 10
46fb726d48Sopenharmony_ci    };
47fb726d48Sopenharmony_ci    expect(chartHiSysEventDataSql(args)).toBeTruthy();
48fb726d48Sopenharmony_ci  });
49fb726d48Sopenharmony_ci  it('hiSysEventDataReceiverTest02', () => {
50fb726d48Sopenharmony_ci    const mockPostMessage = jest.fn();
51fb726d48Sopenharmony_ci    global.postMessage = mockPostMessage;
52fb726d48Sopenharmony_ci    hiSysEventDataReceiver(data, proc);
53fb726d48Sopenharmony_ci    expect(mockPostMessage).toHaveBeenCalledTimes(1);
54fb726d48Sopenharmony_ci  });
55fb726d48Sopenharmony_ci});