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 16// @ts-ignore 17import {heap, HeapStruct,NativeMemoryRender} from "../../../../dist/trace/database/ui-worker/ProcedureWorkerHeap.js"; 18// @ts-ignore 19import {Rect} from "../../../../dist/trace/component/trace/timer-shaft/Rect.js"; 20 21describe(' Test', () => { 22 23 it('HeapTest01', () => { 24 let dataList = new Array(); 25 dataList.push({startTime: 0, dur: 10, frame: {x:0, y:9, width:10, height:10}}) 26 dataList.push({startTime: 1, dur: 111}) 27 let rect = new Rect(0, 10, 10, 10); 28 let res = [{ 29 startTs: 0, 30 dur: 10, 31 length:1, 32 frame: "" 33 }] 34 heap(dataList, res, 1, 100254, 100254, rect,true) 35 }) 36 37 it('HeapTest02', () => { 38 let dataList = new Array(); 39 dataList.push({startTime: 0, dur: 10, frame: {x:0, y:9, width:10, height:10}}) 40 dataList.push({startTime: 1, dur: 111, frame: {x:0, y:9, width:10, height:10}}) 41 let rect = new Rect(0, 10, 10, 10); 42 let res = [{ 43 startTs: 0, 44 dur: 10, 45 length:0, 46 frame: "" 47 }] 48 heap(dataList, res, 1, 100254, 100254, rect,false) 49 }) 50 51 it('HeapTest03', () => { 52 const canvas = document.createElement('canvas'); 53 canvas.width = 1; 54 canvas.height = 1; 55 const ctx = canvas.getContext('2d'); 56 57 const data = { 58 frame: { 59 x: 20, 60 y: 20, 61 width: 100, 62 height: 100 63 }, 64 startNS: 200, 65 value: 50 66 } 67 expect(HeapStruct.draw(ctx, data)).toBeUndefined() 68 }) 69 it('HeapTest04', () => { 70 const canvas = document.createElement('canvas'); 71 canvas.width = 1; 72 canvas.height = 1; 73 const ctx = canvas.getContext('2d'); 74 75 const data = { 76 frame: { 77 x: 20, 78 y: 20, 79 width: 100, 80 height: 100 81 }, 82 maxHeapSize: 200, 83 value: 50 84 } 85 expect(HeapStruct.draw(ctx, data)).toBeUndefined() 86 }) 87 88 it('HeapTest05', function () { 89 let nativeMemoryRender = new NativeMemoryRender() 90 let req = { 91 lazyRefresh:true, 92 type:"", 93 startNS:1, 94 endNS:1, 95 totalNS:1, 96 frame: { 97 x: 20, 98 y: 20, 99 width: 100, 100 height: 100 101 }, 102 useCache:false, 103 range:{ 104 refresh:"", 105 }, 106 canvas:'', 107 context:{ 108 font:"11px sans-serif", 109 fillStyle:"#ec407a", 110 globalAlpha:0.6, 111 }, 112 lineColor:'', 113 isHover:'', 114 hoverX:1, 115 params:'', 116 wakeupBean:undefined, 117 flagMoveInfo:'', 118 flagSelectedInfo:'', 119 slicesTime:3, 120 id:1, 121 x: 20, 122 y: 20, 123 width: 100, 124 height: 100, 125 } 126 window.postMessage = jest.fn(()=>true) 127 expect(nativeMemoryRender.render(req,[],[])).toBeUndefined() 128 }); 129});