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