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 16import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 17import { SdkSliceRender, SdkSliceStruct } from '../../../../src/trace/database/ui-worker/ProduceWorkerSdkSlice'; 18jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 19 return {}; 20}); 21 22describe('ProduceWorkerSdkSlice Test', () => { 23 it('ProduceWorkerSdkSliceTest01', function () { 24 let sdkSliceRender = new SdkSliceRender(); 25 let list = [ 26 { 27 length: 19, 28 frame: { 29 x: 46, 30 Y: 140, 31 width: 780, 32 height: 80, 33 }, 34 }, 35 ]; 36 let res = [ 37 { 38 length: 81, 39 frame: null, 40 }, 41 ]; 42 expect(sdkSliceRender.sdkSlice(list, res, 1, 5, 4, true)).toBeUndefined(); 43 }); 44 45 it('ProduceWorkerSdkSliceTest02', function () { 46 let sdkSliceRender = new SdkSliceRender(); 47 let list = [ 48 { 49 length: 891, 50 frame: { 51 x: 17, 52 Y: 175, 53 width: 550, 54 height: 870, 55 }, 56 }, 57 ]; 58 let res = [ 59 { 60 length: 430, 61 frame: null, 62 }, 63 ]; 64 expect(sdkSliceRender.sdkSlice(list, res, 1, 5, 4, false)).toBeUndefined(); 65 }); 66 67 it('ProduceWorkerSdkSliceTest03', () => { 68 const data = { 69 startNs: 1, 70 value: 1, 71 frame: { 72 x: 20, 73 y: 20, 74 width: 100, 75 height: 100, 76 }, 77 start_ts: 1, 78 }; 79 const canvas = document.createElement('canvas'); 80 canvas.width = 1; 81 canvas.height = 1; 82 const ctx = canvas.getContext('2d'); 83 expect(SdkSliceStruct.draw(ctx, data)).toBeUndefined(); 84 }); 85 86 it('ProduceWorkerSdkSliceTest04', () => { 87 let node = { 88 startNs: 1, 89 value: 1, 90 frame: { 91 x: 20, 92 y: 20, 93 width: 100, 94 height: 100, 95 }, 96 start_ts: 1, 97 end_ts: 2, 98 }; 99 let frame = { 100 x: 20, 101 y: 20, 102 width: 100, 103 height: 100, 104 }; 105 expect(SdkSliceStruct.setSdkSliceFrame(node, 2, 2, 3, 1, frame)).toBeUndefined(); 106 }); 107 108 it('ProduceWorkerSdkSliceTest05', () => { 109 let node = { 110 startNs: 1, 111 value: 1, 112 frame: { 113 x: 20, 114 y: 20, 115 width: 100, 116 height: 100, 117 }, 118 start_ts: 3, 119 end_ts: 5, 120 }; 121 let frame = { 122 x: 20, 123 y: 20, 124 width: 100, 125 height: 100, 126 }; 127 expect(SdkSliceStruct.setSdkSliceFrame(node, 2, 2, 3, 1, frame)).toBeUndefined(); 128 }); 129 130 it('ProduceWorkerSdkSliceTest06', function () { 131 let sdkSliceRender = new SdkSliceRender(); 132 let sdkSliceReq = { 133 lazyRefresh: true, 134 type: '', 135 startNS: 21, 136 endNS: 31, 137 totalNS: 10, 138 frame: { 139 x: 20, 140 y: 10, 141 width: 100, 142 height: 200, 143 }, 144 useCache: false, 145 range: { 146 refresh: '', 147 }, 148 canvas: 'a', 149 context: { 150 font: '11px sans-serif', 151 fillStyle: '#2c441b', 152 globalAlpha: 0.75, 153 clearRect: jest.fn(() => true), 154 beginPath: jest.fn(() => true), 155 stroke: jest.fn(() => true), 156 closePath: jest.fn(() => true), 157 measureText: jest.fn(() => ''), 158 fillRect: jest.fn(() => true), 159 fillText: jest.fn(() => false), 160 }, 161 lineColor: '#993e00', 162 isHover: '', 163 hoverX: 51, 164 params: '', 165 wakeupBean: undefined, 166 flagMoveInfo: '', 167 flagSelectedInfo: '', 168 slicesTime: 66, 169 id: 1, 170 x: 70, 171 y: 80, 172 width: 15, 173 height: 15, 174 }; 175 window.postMessage = jest.fn(() => true); 176 expect(sdkSliceRender.render(sdkSliceReq, [], [])).toBeUndefined(); 177 }); 178 it('ProduceWorkerSdkSliceTest07', function () { 179 let sdkSliceRender = new SdkSliceRender(); 180 window.postMessage = jest.fn(() => true); 181 let canvas = document.createElement('canvas') as HTMLCanvasElement; 182 let context = canvas.getContext('2d'); 183 const data = { 184 context: context!, 185 useCache: true, 186 type: '', 187 traceRange: [], 188 }; 189 expect(sdkSliceRender.renderMainThread(data, new TraceRow())).toBeUndefined(); 190 }); 191}); 192