• 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('../../../../src/trace/component/trace/base/TraceRow', () => {
17  return {};
18});
19
20import { func, FuncStruct, FuncRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerFunc';
21import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect';
22import { markAsUntransferable } from 'worker_threads';
23
24describe(' ProcedureWorkerFuncTest', () => {
25  it('FuncTest01', () => {
26    let funcDataList = new Array();
27    funcDataList.push({
28      startTime: 10,
29      dur: 410,
30      frame: { x: 0, y: 9, width: 10, height: 10 },
31    });
32    funcDataList.push({ startTime: 17, dur: 141 });
33    let rect = new Rect(0, 30, 30, 30);
34    let res = [
35      {
36        startTs: 31,
37        dur: 140,
38        length: 16,
39        frame: '',
40      },
41    ];
42    func(funcDataList, res, 1, 100254, 100254, rect, true);
43  });
44
45  it('FuncTest02', () => {
46    let funcDataList = new Array();
47    funcDataList.push({
48      startTime: 450,
49      dur: 140,
50      frame: { x: 0, y: 93, width: 120, height: 320 },
51    });
52    funcDataList.push({
53      startTime: 41,
54      dur: 661,
55      frame: { x: 70, y: 9, width: 16, height: 17 },
56    });
57    let rect = new Rect(30, 50, 53, 13);
58    let res = [
59      {
60        startTs: 10,
61        dur: 10,
62        length: 60,
63        frame: '',
64      },
65    ];
66    func(funcDataList, res, 1, 100254, 100254, rect, false);
67  });
68
69  it('FuncTest03', () => {
70    const canvas = document.createElement('canvas');
71    canvas.width = 9;
72    canvas.height = 9;
73    const ctx = canvas.getContext('2d');
74
75    const data = {
76      frame: {
77        x: 209,
78        y: 209,
79        width: 100,
80        height: 100,
81      },
82      startNS: 200,
83      value: 50,
84      dur: undefined || null || 0,
85      funName: '',
86    };
87    expect(FuncStruct.draw(ctx, data)).toBeUndefined();
88  });
89
90  it('FuncTest04', () => {
91    const canvas = document.createElement('canvas');
92    canvas.width = 1;
93    canvas.height = 1;
94    const ctx = canvas.getContext('2d');
95
96    const data = {
97      frame: {
98        x: 240,
99        y: 240,
100        width: 100,
101        height: 100,
102      },
103      startNS: 200,
104      value: 50,
105      dur: 10,
106      funName: 'H:Task PerformTask End: taskId : 1, executeId : 1, performResult : IsCanceled',
107    };
108    expect(FuncStruct.draw(ctx, data)).toBeUndefined();
109  });
110
111  it('FuncTest07', function () {
112    let str = '';
113    expect(FuncStruct.isBinder({})).toBe(false);
114  });
115
116  it('FuncTest08', function () {
117    let data = {
118      startTs: 2,
119      depth: 1,
120    };
121    expect(FuncStruct.isSelected(data)).toBe(false);
122  });
123
124  it('FuncTest09', function () {
125    let funcRender = new FuncRender();
126    let req = {
127      lazyRefresh: undefined,
128      type: '',
129      startNS: 31,
130      endNS: 71,
131      totalNS: 40,
132      frame: {
133        x: 30,
134        y: 22,
135        width: 550,
136        height: 150,
137      },
138      useCache: false,
139      range: {
140        refresh: '',
141      },
142      canvas: '',
143      context: {
144        font: '11px sans-serif',
145        fillStyle: '#30a16f',
146        globalAlpha: 0.556,
147        height: 177,
148        width: 150,
149      },
150      lineColor: '#014d5f',
151      isHover: '',
152      hoverX: 21,
153      wakeupBean: undefined,
154      flagMoveInfo: '',
155      flagSelectedInfo: '',
156      slicesTime: 53,
157      id: 64,
158      x: 760,
159      y: 67,
160      width: 106,
161      height: 170,
162      params: {
163        isLive: false,
164        maxHeight: 222,
165        dpr: 431,
166        hoverFuncStruct: '',
167        selectFuncStruct: undefined,
168      },
169    };
170    window.postMessage = jest.fn(() => true);
171    expect(funcRender.render(req, [], [])).toBeUndefined();
172  });
173});
174