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 { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 17import { 18 HeapTimelineRender, 19 HeapTimelineStruct, 20 HeapTimeline, 21} from '../../../../src/trace/database/ui-worker/ProcedureWorkerHeapTimeline'; 22jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 23 return {}; 24}); 25jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 26 return {}; 27}); 28describe('ProcedureWorkerHeapTimeline Test', () => { 29 it('HeapTimelineTest', () => { 30 const heapTimelineCanvas = document.createElement('canvas'); 31 heapTimelineCanvas.width = 11; 32 heapTimelineCanvas.height = 11; 33 const ctx = heapTimelineCanvas.getContext('2d'); 34 let dataList = new Array(); 35 dataList.push({ 36 startTime: 1, 37 dur: 101, 38 frame: { x: 0, y: 10, width: 10, height: 10 }, 39 }); 40 dataList.push({ startTime: 1, dur: 111 }); 41 let rect = new Rect(0, 10, 10, 10); 42 HeapTimeline(heapTimelineCanvas, ctx, 1, 100254, 100254, rect, (e: any) => {}); 43 }); 44 it('HeapTimelineStructTest01', () => { 45 const data = { 46 cpu: 3, 47 startNs: 3, 48 value: 111, 49 frame: { 50 x: 40, 51 y: 40, 52 width: 230, 53 height: 132, 54 }, 55 maxValue: undefined, 56 startTime: 1, 57 filterID: 3, 58 }; 59 const canvas = document.createElement('canvas'); 60 canvas.width = 1; 61 canvas.height = 1; 62 const ctx = canvas.getContext('2d'); 63 expect(HeapTimelineStruct.draw(ctx, data)).toBeUndefined(); 64 }); 65 it('HeapTimelineStructTest02', () => { 66 const data = { 67 cpu: 1, 68 startNs: 1, 69 value: 1, 70 frame: { 71 x: 20, 72 y: 20, 73 width: 100, 74 height: 100, 75 }, 76 maxValue: undefined, 77 startTime: 1, 78 filterID: 2, 79 }; 80 let frame = { 81 x: 20, 82 y: 20, 83 width: 100, 84 height: 100, 85 }; 86 expect(HeapTimelineStruct.setFrame(1, 2, 1, data, 0, 2, 2, frame)).toBeUndefined(); 87 }); 88 it('HeapTimelineStructTest03 ', function () { 89 let heapTimelineRender = new HeapTimelineRender(); 90 const canvas = document.createElement('canvas'); 91 canvas.width = 1; 92 canvas.height = 1; 93 const data = { 94 frame: { 95 x: 240, 96 y: 230, 97 width: 100, 98 height: 110, 99 }, 100 context: { 101 globalAlpha: 0.6, 102 measureText: jest.fn(() => true), 103 clearRect: jest.fn(() => true), 104 stroke: jest.fn(() => true), 105 closePath: jest.fn(() => false), 106 beginPath: jest.fn(() => true), 107 fillRect: jest.fn(() => false), 108 fillText: jest.fn(() => true), 109 }, 110 startNS: 200, 111 value: 50, 112 }; 113 expect(heapTimelineRender.renderMainThread(data,new TraceRow<HeapTimelineStruct>())).toBeUndefined() 114 }); 115}); 116