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';
17import { ProcessMemStruct, MemRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerMem';
18import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect';
19import { mem } from '../../../../src/trace/database/ui-worker/ProcedureWorkerCommon';
20jest.mock('../../../../src/trace/component/SpSystemTrace',()=>{
21  return {}
22})
23describe(' Test', () => {
24  it('MemTest01', () => {
25    let frame = {
26      x: 0,
27      y: 9,
28      width: 10,
29      height: 10,
30    };
31    let memDataList = new Array();
32    memDataList.push({
33      startTime: 10,
34      duration: 12,
35      frame: { x: 0, y: 12, width: 14, height: 120 },
36    });
37    memDataList.push({
38      startTime: 2,
39      duration: 131,
40      frame: { x: 0, y: 3, width: 30, height: 30 },
41    });
42    let rect = new Rect(0, 33, 10, 7);
43    mem(memDataList, [{ length: 0 }], 2, 100254, 100254, frame, false);
44  });
45
46  it('MemTest02', () => {
47    let frame = {
48      x: 0,
49      y: 9,
50      width: 10,
51      height: 10,
52    };
53    let memDataList = new Array();
54    memDataList.push({
55      startTime: 0,
56      duration: 40,
57      frame: { x: 0, y: 44, width: 144, height: 40 },
58    });
59    memDataList.push({
60      startTime: 22,
61      duration: 16,
62      frame: { x: 0, y: 49, width: 130, height: 3 },
63    });
64    let rect = new Rect(0, 14, 10, 40);
65    mem(memDataList, [{ length: 0 }], 2, 100254, 100254, frame, true);
66  });
67
68  it('MemTest03', () => {
69    const canvas = document.createElement('canvas');
70    canvas.width = 4;
71    canvas.height = 4;
72    const ctx = canvas.getContext('2d');
73
74    const data = {
75      frame: {
76        x: 270,
77        y: 207,
78        width: 100,
79        height: 100,
80      },
81      startNS: 200,
82      value: 50,
83    };
84    expect(ProcessMemStruct.draw(ctx, data)).toBeUndefined();
85  });
86
87  it('MemTest04', function () {
88    let memRender = new MemRender();
89    let memReq = {
90      lazyRefresh: true,
91      type: '',
92      startNS: 2,
93      endNS: 45,
94      totalNS: 43,
95      frame: {
96        x: 150,
97        y: 210,
98        width: 200,
99        height: 220,
100      },
101      useCache: false,
102      range: {
103        refresh: '',
104      },
105      canvas: 'a',
106      context: {
107        font: '11px sans-serif',
108        fillStyle: '#408dec',
109        globalAlpha: 0.49,
110        clearRect: jest.fn(() => true),
111        fillRect: jest.fn(() => true),
112        beginPath: jest.fn(() => true),
113        stroke: jest.fn(() => true),
114        closePath: jest.fn(() => true),
115        measureText: jest.fn(() => []),
116        fillText: jest.fn(() => true),
117      },
118      lineColor: '#d90606',
119      isHover: '',
120      hoverX: 1,
121      params: '',
122      wakeupBean: undefined,
123      flagMoveInfo: '',
124      flagSelectedInfo: '',
125      slicesTime: 5,
126      id: 1,
127      x: 66,
128      y: 66,
129      width: 100,
130      height: 100,
131    };
132    window.postMessage = jest.fn(() => true);
133    TraceRow.range = jest.fn(() => true);
134    TraceRow.range!.startNS = jest.fn(() => 0);
135    TraceRow.range!.endNS = jest.fn(() => 27763331331);
136    TraceRow.range!.totalNS = jest.fn(() => 27763331331);
137    expect(memRender.renderMainThread(memReq,new TraceRow<ProcessMemStruct>())).toBeUndefined();
138  });
139});
140