• 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
16jest.mock('../../../../dist/trace/component/trace/base/TraceRow.js', () => {
17  return {};
18});
19
20// @ts-ignore
21import {
22  proc,
23  ProcessStruct,
24  ProcessRender,
25} from '../../../../dist/trace/database/ui-worker/ProcedureWorkerProcess.js';
26// @ts-ignore
27import { Rect } from '../../../../dist/trace/component/trace/timer-shaft/Rect.js';
28
29jest.mock('../../../../dist/trace/database/ui-worker/ProcedureWorker.js', () => {
30  return {};
31});
32
33describe(' ProcessTest', () => {
34  let res = [
35    {
36      startNS: 6,
37      dur: 650,
38      frame: {
39        x: 99,
40        y: 92,
41        width: 190,
42        height: 193,
43      },
44    },
45  ];
46  it('ProcessTest01', () => {
47    let dataList = new Array();
48    dataList.push({
49      startTime: 0,
50      dur: 10,
51      frame: { x: 0, y: 9, width: 10, height: 10 },
52    });
53    dataList.push({ startTime: 1, dur: 111 });
54    let rect = new Rect(0, 10, 10, 10);
55    proc(dataList, res, 1, 100254, 100254, rect);
56  });
57
58  it('ProcessTest02', () => {
59    let processDataList = new Array();
60    processDataList.push({
61      startTime: 450,
62      dur: 150,
63      frame: { x: 32, y: 3, width: 10, height: 120 },
64    });
65    processDataList.push({
66      startTime: 1,
67      dur: 51,
68      frame: { x: 30, y: 93, width: 20, height: 10 },
69    });
70    let rect = new Rect(0, 10, 10, 50);
71    proc(processDataList, res, 1, 100254, 100254, rect);
72  });
73
74  it('ProcessTest04', () => {
75    const node = {
76      frame: {
77        x: 104,
78        y: 20,
79        width: 105,
80        height: 100,
81      },
82      startNS: 200,
83      value: 30,
84      startTime: 0,
85      dur: 0,
86    };
87    const frame = {
88      x: 20,
89      y: 120,
90      width: 100,
91      height: 100,
92    };
93    expect(ProcessStruct.setFrame(node, 1, 1, 1, frame)).toBeUndefined();
94  });
95
96  it('ProcessTest05', () => {
97    const node = {
98      frame: {
99        x: 201,
100        y: 20,
101        width: 3,
102        height: 100,
103      },
104      startNS: 200,
105      value: 50,
106      startTime: 2,
107      dur: 2,
108    };
109    const frame = {
110      x: 20,
111      y: 40,
112      width: 100,
113      height: 100,
114    };
115    expect(ProcessStruct.setFrame(node, 1, 1, 1, frame)).toBeUndefined();
116  });
117
118  it('ProcessTest06', function () {
119    let processRender = new ProcessRender();
120    let processReq = {
121      lazyRefresh: true,
122      type: '',
123      startNS: 15,
124      endNS: 16,
125      totalNS: 1,
126      frame: {
127        x: 55,
128        y: 55,
129        width: 125,
130        height: 105,
131      },
132      useCache: false,
133      range: {
134        refresh: '',
135      },
136      canvas: 'a',
137      context: {
138        font: '11px sans-serif',
139        fillStyle: '#26e2c5',
140        globalAlpha: 0.7,
141        clearRect: jest.fn(() => true),
142        beginPath: jest.fn(() => false),
143        closePath: jest.fn(() => true),
144        measureText: jest.fn(() => true),
145        fillRect: jest.fn(() => true),
146        stroke: jest.fn(() => []),
147        fill: jest.fn(() => true),
148      },
149      lineColor: '#a50101',
150      isHover: '',
151      hoverX: 34,
152      params: '',
153      wakeupBean: undefined,
154      flagMoveInfo: '',
155      flagSelectedInfo: '',
156      slicesTime: 55,
157      id: 1,
158      x: 20,
159      y: 20,
160      width: 123,
161      height: 123,
162    };
163    window.postMessage = jest.fn(() => true);
164    expect(processRender.render(processReq, [], [])).toBeUndefined();
165  });
166});
167