• 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} from "../../../dist/trace/database/ProcedureWorkerThread.js";
18// @ts-ignore
19import {Rect} from "../../../dist/trace/component/trace/timer-shaft/Rect.js";
20
21describe(' ThreadTest', () => {
22
23    it('ThreadTest01', () => {
24        let dataList = new Array();
25        dataList.push({startTime: 0, dur: 10, frame: {x:0, y:9, width:10, height:10}})
26        dataList.push({startTime: 1, dur: 111})
27        let rect = new Rect(0, 10, 10, 10);
28        thread(dataList, new Set(), 1, 100254, 100254, rect)
29    })
30
31    it('ThreadTest02', () => {
32        let dataList = new Array();
33        dataList.push({startTime: 0, dur: 10, frame: {x:0, y:9, width:10, height:10}})
34        dataList.push({startTime: 1, dur: 111, frame: {x:0, y:9, width:10, height:10}})
35        let rect = new Rect(0, 10, 10, 10);
36        thread(dataList, new Set(), 1, 100254, 100254, rect)
37    })
38
39    it('ThreadTest03', () => {
40        const canvas = document.createElement('canvas');
41        canvas.width = 1;
42        canvas.height = 1;
43        const ctx = canvas.getContext('2d');
44
45        const data = {
46            frame: {
47                x: 20,
48                y: 20,
49                width: 100,
50                height: 100
51            },
52            startNS: 200,
53            value: 50
54        }
55        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
56    })
57
58    it('ThreadTest04', () => {
59        const canvas = document.createElement('canvas');
60        canvas.width = 1;
61        canvas.height = 1;
62        const ctx = canvas.getContext('2d');
63
64        const data = {
65            frame: {
66                x: 20,
67                y: 20,
68                width: 100,
69                height: 100
70            },
71            startNS: 200,
72            value: 50,
73            state:"S"
74        }
75        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
76    })
77
78    it('ThreadTest05', () => {
79        const canvas = document.createElement('canvas');
80        canvas.width = 1;
81        canvas.height = 1;
82        const ctx = canvas.getContext('2d');
83
84        const data = {
85            frame: {
86                x: 20,
87                y: 20,
88                width: 100,
89                height: 100
90            },
91            startNS: 200,
92            value: 50,
93            state:"R"
94        }
95        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
96    })
97
98    it('ThreadTest06', () => {
99        const canvas = document.createElement('canvas');
100        canvas.width = 1;
101        canvas.height = 1;
102        const ctx = canvas.getContext('2d');
103
104        const data = {
105            frame: {
106                x: 20,
107                y: 20,
108                width: 100,
109                height: 100
110            },
111            startNS: 200,
112            value: 50,
113            state:"D"
114        }
115        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
116    })
117
118    it('ThreadTest07', () => {
119        const canvas = document.createElement('canvas');
120        canvas.width = 1;
121        canvas.height = 1;
122        const ctx = canvas.getContext('2d');
123
124        const data = {
125            frame: {
126                x: 20,
127                y: 20,
128                width: 100,
129                height: 100
130            },
131            startNS: 200,
132            value: 50,
133            state:"Running"
134        }
135        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
136    })
137
138    it('ThreadTest08', () => {
139        const canvas = document.createElement('canvas');
140        canvas.width = 1;
141        canvas.height = 1;
142        const ctx = canvas.getContext('2d');
143
144        const data = {
145            frame: {
146                x: 20,
147                y: 20,
148                width: 100,
149                height: 100
150            },
151            startNS: 200,
152            value: 50,
153            state:"T"
154        }
155        expect(ThreadStruct.draw(ctx, data)).toBeUndefined()
156    })
157
158    it('ThreadTest09', () => {
159        const d1 = {
160            cpu:1,
161            tid:1,
162            state:"",
163            startTime:1,
164            dur:1
165        }
166        const d2 = {
167            cpu:1,
168            tid:1,
169            state:"",
170            startTime:1,
171            dur:1
172        }
173        expect(ThreadStruct.equals(d1, d2)).toBeTruthy()
174    })
175});