• 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 */
15import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
16import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect';
17import { snapshot, SnapshotRender, SnapshotStruct} from '../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot';
18
19jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
20    return {};
21});
22jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
23    return {};
24});
25describe('ProcedureWorkerSnapshot Test', () => {
26    it('HeapSnapshotTest', () => {
27        const snapshotCanvas = document.createElement('canvas');
28        snapshotCanvas.width = 1;
29        snapshotCanvas.height = 1;
30        const ctx = snapshotCanvas.getContext('2d');
31        let dataList = new Array();
32        dataList.push({
33            startTime: 0,
34            dur: 10,
35            frame: { x: 0, y: 9, width: 10, height: 10 },
36        });
37        dataList.push({ startTime: 1, dur: 111 });
38        let rect = new Rect(0, 10, 10, 10);
39        let filter = [
40            {
41                end_time: 50,
42                end_ts: 1520000,
43                file_name: 'Snapshot0',
44                frame: { x: 0, y: 0, width: 25, height: 40 },
45                id: 0,
46                pid: 4243,
47                start_time: 0,
48                start_ts: 88473061693464,
49                textMetricsWidth: 50.5810546875,
50            },
51        ];
52        let list = [
53            {
54                end_time: 50,
55                end_ts: 1520000,
56                file_name: 'Snapshot0',
57                frame: { x: 0, y: 0, width: 6222, height: 62222 },
58                id: 0,
59                pid: 4243,
60                start_time: 0,
61                start_ts: 88473061693464,
62                textMetricsWidth: 50.5810546875,
63            },
64        ];
65        snapshot(list, filter, 100254, 100254, rect, { height: 40, width: 1407, x: 0, y: 0 });
66    });
67
68    it('SnapshotStructTest01', () => {
69        const data = {
70            cpu: 2,
71            startNs: 1,
72            value: 2444523,
73            frame: {
74                x: 40,
75                y: 40,
76                width: 650,
77                height: 144,
78            },
79            maxValue: undefined,
80            startTime: 1,
81            filterID: 2,
82            size: 102
83        };
84        const canvas = document.createElement('canvas');
85        canvas.width = 1;
86        canvas.height = 1;
87        const ctx = canvas.getContext('2d');
88        expect(SnapshotStruct.draw(ctx, data)).toBeUndefined();
89    });
90
91    it('SnapshotStructTest02', () => {
92        const data = {
93            cpu: 1,
94            startNs: 1,
95            value: 1854521,
96            frame: {
97                x: 60,
98                y: 60,
99                width: 100,
100                height: 66,
101            },
102            maxValue: undefined,
103            startTime: 1,
104            filterID: 2,
105        };
106        let node = {
107            start_time: 1,
108            end_time: 2,
109            frame: null,
110        };
111        expect(SnapshotStruct.setFrame(node, 0, 1, 2, data)).toBeUndefined();
112    });
113
114    it('SnapshotRenderTest03', () => {
115        let canvas = document.createElement('canvas') as HTMLCanvasElement;
116        let context = canvas.getContext('2d');
117        const data = {
118            context: context!,
119            useCache: true,
120            type: '',
121            traceRange: [],
122        };
123        let snapshotRender = new SnapshotRender();
124        expect(snapshotRender.renderMainThread(data, new TraceRow())).toBeUndefined();
125    });
126    it('SnapshotStructTest04', () => {
127        expect(SnapshotStruct).not.toBeUndefined();
128    });
129});
130