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 16jest.mock('../../../../dist/trace/component/trace/base/TraceRow.js', () => { 17 return {}; 18}); 19 20// @ts-ignore 21import { func, FuncStruct, FuncRender } from '../../../../dist/trace/database/ui-worker/ProcedureWorkerFunc.js'; 22// @ts-ignore 23import { Rect } from '../../../../dist/trace/component/trace/timer-shaft/Rect.js'; 24import { markAsUntransferable } from 'worker_threads'; 25 26describe(' ProcedureWorkerFuncTest', () => { 27 it('FuncTest01', () => { 28 let funcDataList = new Array(); 29 funcDataList.push({ 30 startTime: 10, 31 dur: 410, 32 frame: { x: 0, y: 9, width: 10, height: 10 }, 33 }); 34 funcDataList.push({ startTime: 17, dur: 141 }); 35 let rect = new Rect(0, 30, 30, 30); 36 let res = [ 37 { 38 startTs: 31, 39 dur: 140, 40 length: 16, 41 frame: '', 42 }, 43 ]; 44 func(funcDataList, res, 1, 100254, 100254, rect, true); 45 }); 46 47 it('FuncTest02', () => { 48 let funcDataList = new Array(); 49 funcDataList.push({ 50 startTime: 450, 51 dur: 140, 52 frame: { x: 0, y: 93, width: 120, height: 320 }, 53 }); 54 funcDataList.push({ 55 startTime: 41, 56 dur: 661, 57 frame: { x: 70, y: 9, width: 16, height: 17 }, 58 }); 59 let rect = new Rect(30, 50, 53, 13); 60 let res = [ 61 { 62 startTs: 10, 63 dur: 10, 64 length: 60, 65 frame: '', 66 }, 67 ]; 68 func(funcDataList, res, 1, 100254, 100254, rect, false); 69 }); 70 71 it('FuncTest03', () => { 72 const canvas = document.createElement('canvas'); 73 canvas.width = 9; 74 canvas.height = 9; 75 const ctx = canvas.getContext('2d'); 76 77 const data = { 78 frame: { 79 x: 209, 80 y: 209, 81 width: 100, 82 height: 100, 83 }, 84 startNS: 200, 85 value: 50, 86 dur: undefined || null || 0, 87 funName: '', 88 }; 89 expect(FuncStruct.draw(ctx, data)).toBeUndefined(); 90 }); 91 92 it('FuncTest04', () => { 93 const canvas = document.createElement('canvas'); 94 canvas.width = 1; 95 canvas.height = 1; 96 const ctx = canvas.getContext('2d'); 97 98 const data = { 99 frame: { 100 x: 240, 101 y: 240, 102 width: 100, 103 height: 100, 104 }, 105 startNS: 200, 106 value: 50, 107 dur: 10, 108 funName: 'H:Task PerformTask End: taskId : 1, executeId : 1, performResult : IsCanceled', 109 }; 110 expect(FuncStruct.draw(ctx, data)).toBeUndefined(); 111 }); 112 113 it('FuncTest07', function () { 114 let str = ''; 115 expect(FuncStruct.isBinder({})).toBe(false); 116 }); 117 118 it('FuncTest08', function () { 119 let data = { 120 startTs: 2, 121 depth: 1, 122 }; 123 expect(FuncStruct.isSelected(data)).toBe(false); 124 }); 125 126 it('FuncTest09', function () { 127 let funcRender = new FuncRender(); 128 let req = { 129 lazyRefresh: undefined, 130 type: '', 131 startNS: 31, 132 endNS: 71, 133 totalNS: 40, 134 frame: { 135 x: 30, 136 y: 22, 137 width: 550, 138 height: 150, 139 }, 140 useCache: false, 141 range: { 142 refresh: '', 143 }, 144 canvas: '', 145 context: { 146 font: '11px sans-serif', 147 fillStyle: '#30a16f', 148 globalAlpha: 0.556, 149 height: 177, 150 width: 150, 151 }, 152 lineColor: '#014d5f', 153 isHover: '', 154 hoverX: 21, 155 wakeupBean: undefined, 156 flagMoveInfo: '', 157 flagSelectedInfo: '', 158 slicesTime: 53, 159 id: 64, 160 x: 760, 161 y: 67, 162 width: 106, 163 height: 170, 164 params: { 165 isLive: false, 166 maxHeight: 222, 167 dpr: 431, 168 hoverFuncStruct: '', 169 selectFuncStruct: undefined, 170 }, 171 }; 172 window.postMessage = jest.fn(() => true); 173 expect(funcRender.render(req, [], [])).toBeUndefined(); 174 }); 175}); 176