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