/* * Copyright (C) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; import { IrqRender, IrqStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerIrq'; jest.mock('../../../../src/trace/component/SpSystemTrace', () => { return {}; }); describe('ProcedureWorkerIrq Test', () => { it('ProcedureWorkerIrq01', () => { const canvas = document.createElement('canvas'); canvas.width = 4; canvas.height = 4; const ctx = canvas.getContext('2d'); const data = { frame: { x: 210, y: 210, width: 100, height: 100, }, id: 155, startNS: 1745, name: '4515', dur: 4555, argSetId: 10, }; expect(IrqStruct.draw(ctx!, data, true)).toBeUndefined(); }); it('ProcedureWorkerIrq02', () => { const canvas = document.createElement('canvas'); canvas.width = 1; canvas.height = 1; const ctx = canvas.getContext('2d'); let data = { textMetricsWidth: 1 }; expect( IrqStruct.draw( ctx, '253', 2, { x: 20, y: 20, width: 100, height: 100, }, data ) ).toBeUndefined(); }); it('ProcedureWorkerIrq03', () => { let irqRender = new IrqRender(); let req = { lazyRefresh: true, type: '', startNS: 5, endNS: 9, totalNS: 4, frame: { x: 32, y: 20, width: 170, height: 180, }, useCache: true, range: { refresh: '', }, canvas: 'b', context: { font: '12px sans-serif', fillStyle: '#a1697d', globalAlpha: 0.5, measureText: jest.fn(() => true), clearRect: jest.fn(() => true), stroke: jest.fn(() => true), closePath: jest.fn(() => false), beginPath: jest.fn(() => true), fillRect: jest.fn(() => false), fillText: jest.fn(() => true), }, lineColor: '', isHover: 'true', hoverX: 0, params: '', wakeupBean: undefined, flagMoveInfo: '', flagSelectedInfo: '', slicesTime: 4, id: 1, x: 24, y: 24, width: 100, height: 100, }; window.postMessage = jest.fn(() => true); TraceRow.range = jest.fn(() => true); TraceRow.range.startNS = jest.fn(() => 1); expect(irqRender.renderMainThread(req,new TraceRow())); }); });