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 {
17  chartCpuFreqDataSql,
18  chartCpuFreqDataSqlMem, cpuFreqDataReceiver
19} from '../../../../../src/trace/database/data-trafic/cpu/CpuFreqDataReceiver';
20
21describe('CpuFreqDataReceiver Test',()=>{
22  let data;
23  let proc;
24
25  beforeEach(() => {
26    data = {
27      id: "6a41c242-3e3e-4c3f-82f3-eab7102f0e9f",
28      name: 2,
29      action: "exec-proto",
30      params: {
31        cpu: 0,
32        startNS: 0,
33        endNS: 9427688540,
34        recordStartNS: 4049847357191,
35        recordEndNS: 4059275045731,
36        t: 1703754730919,
37        width: 549,
38        trafic: 2
39      }
40    };
41    proc = jest.fn((sql) => [
42      {cpuFreqData: {cpu: 4, value: 826000, dur: 0, startNs: 8252840103}},
43      {cpuFreqData: {cpu: 4, value: 826000, dur: 0, startNs: 8252840103}},
44    ]);
45  });
46  it('CpuFreqDataReceiverTest01 ', function () {
47    const args = {
48      recordStartNS: 1000,
49      endNS: 3000,
50      startNS: 2000,
51      width: 10
52    };
53    expect(chartCpuFreqDataSql (args)).toBeTruthy();
54    expect(chartCpuFreqDataSqlMem  (args)).toBeTruthy();
55  });
56  it('CpuFreqDataReceiverTest02 ', function () {
57    const mockPostMessage = jest.fn();
58    global.postMessage = mockPostMessage;
59    cpuFreqDataReceiver(data, proc);
60    expect(mockPostMessage).toHaveBeenCalledTimes(1);
61  });
62})