• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
17jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
18  return {};
19});
20import { AllstatesStruct, AllStatesRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerAllStates';
21import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect';
22jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
23  return {};
24});
25jest
26  .spyOn(require('../../../../src/trace/database/ui-worker/ProcedureWorkerCommon'), 'isFrameContainPoint')
27  .mockReturnValue(true);
28describe('Test', () => {
29  let row: TraceRow<AllstatesStruct>;
30  let context: CanvasRenderingContext2D;
31
32  row = TraceRow.skeleton<AllstatesStruct>();
33  row.isHover = true;
34  TraceRow.range = {
35    startNS: 0,
36    endNS: 1000000,
37    totalNS: 1000000,
38  };
39
40  row.dataList = [
41    {
42      argSetID: 100,
43      translateY: 50,
44      textMetricsWidth: 100,
45      frame: new Rect(0, 0, 100, 100),
46      state: 'fs',
47      name: 'all-state',
48    },
49    {
50      argSetID: 85,
51      translateY: 50,
52      textMetricsWidth: 100,
53      frame: new Rect(0, 0, 200, 200),
54    },
55  ];
56
57  context = {
58    save: jest.fn(),
59    translate: jest.fn(),
60    rect: jest.fn(),
61    clip: jest.fn(),
62    strokeStyle: '#000000',
63    strokeRect: jest.fn(),
64    fillRect: jest.fn(),
65    fillText: jest.fn(),
66    measureText: jest.fn().mockReturnValue({ width: 10 }),
67    beginPath: jest.fn(),
68    closePath: jest.fn(),
69    stroke: jest.fn(),
70    clearRect: jest.fn(),
71    fill: jest.fn(),
72    fillStyle: '#000000',
73    globalAlpha: 0.5,
74    font: '10px sans-serif',
75    canvas: {
76      clientWidth: 800,
77    },
78  } as unknown as CanvasRenderingContext2D;
79
80  it('AllStatesRenderTest01', () => {
81    const xpowerStatisticRender = new AllStatesRender();
82    xpowerStatisticRender.renderMainThread({ context, useCache: false, type: 'cpu', translateY: 5 }, row);
83    expect(context.beginPath).toHaveBeenCalled();
84    expect(context.closePath).toHaveBeenCalled();
85  });
86
87  it('AllStatesRenderTest02', () => {
88    AllstatesStruct.hoverThreadStruct = undefined;
89    expect(AllstatesStruct.drawThread(context, row.dataList[0])).toBeUndefined();
90  });
91});
92