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