• 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 {thread, ThreadStruct,ThreadRender} from "../../../../dist/trace/database/ui-worker/ProcedureWorkerThread.js";
18// @ts-ignore
19import {Rect} from "../../../../dist/trace/component/trace/timer-shaft/Rect.js";
20
21describe(' ThreadTest', () => {
22
23    let frame={
24        x:0,
25        y:9,
26        width:10,
27        height:10
28    }
29    it('ThreadTest01', () => {
30        let dataList = new Array();
31        dataList.push({startTime: 0, dur: 10, frame: {x:0, y:9, width:10, height:10}})
32        dataList.push({startTime: 1, dur: 111})
33        let rect = new Rect(0, 10, 10, 10);
34        thread(dataList, [{length: 0}], 1, 100254, 100254, frame,true)
35    })
36
37    it('ThreadTest02', () => {
38        let dataList = new Array();
39        dataList.push({startTime: 0, dur: 10, frame: {x:0, y:9, width:10, height:10}})
40        dataList.push({startTime: 1, dur: 111, frame: {x:0, y:9, width:10, height:10}})
41        let rect = new Rect(0, 10, 10, 10);
42        thread(dataList, [{length: 0}], 1, 100254, 100254, frame,false)
43    })
44
45    it('ThreadTest03', () => {
46        const canvas = document.createElement('canvas');
47        canvas.width = 1;
48        canvas.height = 1;
49        const ctx = canvas.getContext('2d');
50
51        const data = {
52            frame: {
53                x: 20,
54                y: 20,
55                width: 100,
56                height: 100
57            },
58            startNS: 200,
59            value: 50
60        }
61        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
62    })
63
64    it('ThreadTest04', () => {
65        const canvas = document.createElement('canvas');
66        canvas.width = 1;
67        canvas.height = 1;
68        const ctx = canvas.getContext('2d');
69
70        const data = {
71            frame: {
72                x: 20,
73                y: 20,
74                width: 100,
75                height: 100
76            },
77            startNS: 200,
78            value: 50,
79            state:"S"
80        }
81        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
82    })
83
84    it('ThreadTest05', () => {
85        const canvas = document.createElement('canvas');
86        canvas.width = 1;
87        canvas.height = 1;
88        const ctx = canvas.getContext('2d');
89
90        const data = {
91            frame: {
92                x: 20,
93                y: 20,
94                width: 100,
95                height: 100
96            },
97            startNS: 200,
98            value: 50,
99            state:"R"
100        }
101        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
102    })
103
104    it('ThreadTest06', () => {
105        const canvas = document.createElement('canvas');
106        canvas.width = 1;
107        canvas.height = 1;
108        const ctx = canvas.getContext('2d');
109
110        const data = {
111            frame: {
112                x: 20,
113                y: 20,
114                width: 100,
115                height: 100
116            },
117            startNS: 200,
118            value: 50,
119            state:"D"
120        }
121        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
122    })
123
124    it('ThreadTest07', () => {
125        const canvas = document.createElement('canvas');
126        canvas.width = 1;
127        canvas.height = 1;
128        const ctx = canvas.getContext('2d');
129
130        const data = {
131            frame: {
132                x: 20,
133                y: 20,
134                width: 100,
135                height: 100
136            },
137            startNS: 200,
138            value: 50,
139            state:"Running"
140        }
141        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
142    })
143
144    it('ThreadTest08', () => {
145        const canvas = document.createElement('canvas');
146        canvas.width = 1;
147        canvas.height = 1;
148        const ctx = canvas.getContext('2d');
149
150        const data = {
151            frame: {
152                x: 20,
153                y: 20,
154                width: 100,
155                height: 100
156            },
157            startNS: 200,
158            value: 50,
159            state:"T"
160        }
161        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
162    })
163
164    it('ThreadTest09', () => {
165        const d1 = {
166            cpu:1,
167            tid:1,
168            state:"",
169            startTime:1,
170            dur:1
171        }
172        const d2 = {
173            cpu:1,
174            tid:1,
175            state:"",
176            startTime:1,
177            dur:1
178        }
179        expect(ThreadStruct.equals(d1, d2)).toBeTruthy()
180    })
181
182    it('ThreadTest10', function () {
183        let threadRender = new ThreadRender()
184        let  req = {
185            lazyRefresh:true,
186            type:"",
187            startNS:1,
188            endNS:1,
189            totalNS:1,
190            frame: {
191                x: 20,
192                y: 20,
193                width: 100,
194                height: 100
195            },
196            useCache:false,
197            range:{
198                refresh:"",
199            },
200            canvas:'',
201            context:{
202                font:"11px sans-serif",
203                fillStyle:"#ec407a",
204                globalAlpha:0.6,
205            },
206            lineColor:'',
207            isHover:'',
208            hoverX:1,
209            params:'',
210            wakeupBean:undefined,
211            flagMoveInfo:'',
212            flagSelectedInfo:'',
213            slicesTime:3,
214            id:1,
215            x: 20,
216            y: 20,
217            width: 100,
218            height: 100
219        }
220        window.postMessage = jest.fn(()=>true)
221        expect(threadRender.render(req,[],[])).toBeUndefined()
222    });
223});