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 */ 15import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 16import { func, FuncStruct, FuncRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerFunc'; 17import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 18 19 20jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 21 return {}; 22}); 23jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 24 return {}; 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, false); 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, 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 let funcRender = new FuncRender(); 94 const canvas = document.createElement('canvas'); 95 canvas.width = 1; 96 canvas.height = 1; 97 const ctx = canvas.getContext('2d'); 98 99 const data = { 100 frame: { 101 x: 240, 102 y: 240, 103 width: 100, 104 height: 100, 105 }, 106 context: { 107 font: '12px sans-serif', 108 fillStyle: '#a1697d', 109 globalAlpha: 0.6, 110 measureText: jest.fn(() => true), 111 clearRect: jest.fn(() => true), 112 stroke: jest.fn(() => true), 113 closePath: jest.fn(() => false), 114 beginPath: jest.fn(() => true), 115 fillRect: jest.fn(() => false), 116 fillText: jest.fn(() => true), 117 }, 118 startNS: 200, 119 value: 50, 120 dur: 10, 121 funName: 'H:Task PerformTask End: taskId : 1, executeId : 1, performResult : IsCanceled', 122 }; 123 TraceRow.range = jest.fn(() => true); 124 TraceRow.range.startNS = jest.fn(() => 1); 125 expect(FuncStruct.draw(ctx, data)).toBeUndefined(); 126 expect(funcRender.renderMainThread(data, new TraceRow<FuncStruct>())).toBeUndefined(); 127 expect(funcRender.render(data, [], [])).toBeUndefined(); 128 }); 129 130 it('FuncTest07', function () { 131 let str = ''; 132 expect(FuncStruct.isBinder({})).toBe(false); 133 }); 134 135 it('FuncTest08', function () { 136 let data = { 137 startTs: 2, 138 depth: 1, 139 }; 140 expect(FuncStruct.isSelected(data)).toBe(false); 141 }); 142 143 it('FuncTest09', function () { 144 let funcRender = new FuncRender(); 145 let req = { 146 lazyRefresh: undefined, 147 type: '', 148 startNS: 31, 149 endNS: 71, 150 totalNS: 40, 151 frame: { 152 x: 30, 153 y: 22, 154 width: 550, 155 height: 150, 156 }, 157 useCache: false, 158 range: { 159 refresh: '', 160 }, 161 canvas: '', 162 context: { 163 font: '11px sans-serif', 164 fillStyle: '#30a16f', 165 globalAlpha: 0.556, 166 height: 177, 167 width: 150, 168 }, 169 lineColor: '#014d5f', 170 isHover: '', 171 hoverX: 21, 172 wakeupBean: undefined, 173 flagMoveInfo: '', 174 flagSelectedInfo: '', 175 slicesTime: 53, 176 id: 64, 177 x: 760, 178 y: 67, 179 width: 106, 180 height: 170, 181 params: { 182 isLive: false, 183 maxHeight: 222, 184 dpr: 431, 185 hoverFuncStruct: '', 186 selectFuncStruct: undefined, 187 }, 188 }; 189 window.postMessage = jest.fn(() => true); 190 expect(funcRender.render(req, [], [])).toBeUndefined(); 191 }); 192}); 193