• 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 {cpu, CpuStruct,CpuRender,rtCpu,EmptyRender} from "../../../../dist/trace/database/ui-worker/ProcedureWorkerCPU.js";
18// @ts-ignore
19import {Rect} from "../../../../dist/trace/component/trace/timer-shaft/Rect.js";
20
21describe(' Test', () => {
22    const dataSource = {
23        frame: {
24            x: 20,
25            y: 20,
26            width: 100,
27            height: 100
28        },
29        startNS: 200,
30        processId : ''
31    }
32
33    it('CPUTest03', () => {
34        const canvas = document.createElement('canvas');
35        canvas.width = 1;
36        canvas.height = 1;
37        const ctx = canvas.getContext('2d');
38
39        const data = {
40            frame: {
41                x: 20,
42                y: 20,
43                width: 100,
44                height: 100
45            },
46            startNS: 200,
47            value: 50
48        }
49        expect(CpuStruct.draw(ctx, data)).toBeUndefined()
50    })
51
52    it('CPUTest04', () => {
53        expect(CpuStruct.equals(new CpuStruct(),new CpuStruct())).toBeTruthy();
54    })
55
56    it('CPUTest06', () => {
57        expect(CpuStruct.equals([],dataSource)).toBeFalsy()
58    })
59
60
61    it('CPUTest05', () => {
62        const canvas = document.createElement('canvas');
63        canvas.width = 1;
64        canvas.height = 1;
65        const ctx = canvas.getContext('2d');
66
67        const data = {
68            frame: {
69                x: 20,
70                y: 20,
71                width: 100,
72                height: 100
73            },
74            startNS: 200,
75            value: 50
76        }
77        expect(CpuStruct.draw(ctx, data)).toBeUndefined()
78    })
79
80
81    it('CPUTest07', function () {
82        let cpuRender = new CpuRender()
83        let node = [{
84            frame: {
85                x: 20,
86                y: 20,
87                width: 100,
88                height: 100
89            },
90            startNS: 200,
91            length:1,
92            height:2
93        }]
94        let  frame = {
95            x: 20,
96            y: 20,
97            width: 100,
98            height: 100
99        }
100        let list = [{
101            frame: {
102                x: 20,
103                y: 20,
104                width: 100,
105                height: 100
106            },
107            startNS: 200,
108            length:2,
109            height:2
110        }]
111        expect(cpuRender.cpu(list ,node,1,1,1,frame,true)).toBeUndefined()
112    });
113
114    it('CPUTest07', function () {
115        let cpuRender = new CpuRender()
116        let node = [{
117            frame: {
118                x: 20,
119                y: 20,
120                width: 100,
121                height: 100
122            },
123            startNS: 200,
124            length:1,
125            height:0
126        }]
127        let  frame = {
128            x: 20,
129            y: 20,
130            width: 100,
131            height: 100
132        }
133        let list = [{
134            frame: {
135                x: 20,
136                y: 20,
137                width: 100,
138                height: 100
139            },
140            startNS: 200,
141            length:2,
142            height:2
143        }]
144        expect(cpuRender.cpu(list ,node,1,1,1,frame,false)).toBeUndefined()
145    });
146
147    it('CPUTest08', () => {
148        let node = {
149            frame: {
150                x: 20,
151                y: 20,
152                width: 100,
153                height: 100
154            },
155            startNS: 200,
156            length:1,
157            height:0,
158            startTime:0,
159            dur:1
160        }
161        expect(CpuStruct.setCpuFrame(node,1,1,1,{width:10})).toBeUndefined()
162    })
163
164    it('CPUTest09', () => {
165        let node = {
166            frame: {
167                x: 20,
168                y: 20,
169                width: 100,
170                height: 100
171            },
172            startNS: 200,
173            length:1,
174            height:0,
175            startTime:2,
176            dur:1
177        }
178        expect(CpuStruct.setCpuFrame(node,1,1,1,{width:10})).toBeUndefined()
179    })
180
181    it('CPUTest10', function () {
182        let emptyRender = new EmptyRender()
183        let  req = {
184            type:"",
185            startNS:1,
186            endNS:1,
187            totalNS:1,
188            frame: {
189                x: 20,
190                y: 20,
191                width: 100,
192                height: 100
193            },
194            canvas:'',
195            context:{},
196            lineColor:'',
197            isHover:'',
198            hoverX:1,
199            params:'',
200            wakeupBean:undefined,
201            flagMoveInfo:'',
202            flagSelectedInfo:'',
203            slicesTime:3,
204            id:1,
205            x: 20,
206            y: 20,
207            width: 100,
208            height: 100
209        }
210        window.postMessage = jest.fn(()=>true)
211        expect(emptyRender.render(req,[],[])).toBeUndefined()
212    });
213
214    it('CPUTest11', function () {
215        let cpuRender = new CpuRender()
216        let  req = {
217            lazyRefresh:true,
218            type:"",
219            startNS:1,
220            endNS:1,
221            totalNS:1,
222            frame: {
223                x: 20,
224                y: 20,
225                width: 100,
226                height: 100
227            },
228            useCache:false,
229            range:{
230                refresh:"",
231            },
232            canvas:'',
233            context:{
234                font:"11px sans-serif",
235                fillStyle:"#ec407a",
236                globalAlpha:0.6,
237            },
238            lineColor:'',
239            isHover:'',
240            hoverX:1,
241            params:'',
242            wakeupBean:undefined,
243            flagMoveInfo:'',
244            flagSelectedInfo:'',
245            slicesTime:3,
246            id:1,
247            x: 20,
248            y: 20,
249            width: 100,
250            height: 100
251        }
252        window.postMessage = jest.fn(()=>true)
253        expect(cpuRender.render(req,[],[])).toBeUndefined()
254    });
255});