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 16jest.mock('../../../../src/trace/component/trace/base/TraceRow', () => { 17 return {}; 18}); 19 20import { fps, FpsStruct, FpsRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerFPS'; 21import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 22 23describe(' FPSTest', () => { 24 it('FpsTest01', () => { 25 const canvas = document.createElement('canvas'); 26 canvas.width = 1; 27 canvas.height = 1; 28 const ctx = canvas.getContext('2d'); 29 let dataList = new Array(); 30 dataList.push({ 31 startTime: 0, 32 dur: 10, 33 frame: { x: 0, y: 10, width: 10, height: 10 }, 34 }); 35 dataList.push({ startTime: 1, dur: 111 }); 36 let rect = new Rect(0, 10, 10, 10); 37 fps(dataList, [{ length: 1 }], 1, 100254, 100254, rect, true); 38 }); 39 40 it('FpsTest02', () => { 41 let fpsDataList = new Array(); 42 fpsDataList.push({ 43 startTime: 34, 44 dur: 14, 45 frame: { x: 40, y: 442, width: 230, height: 340 }, 46 }); 47 fpsDataList.push({ 48 startTime: 61, 49 dur: 156, 50 frame: { x: 60, y: 9, width: 10, height: 10 }, 51 }); 52 let rect = new Rect(0, 50, 50, 16); 53 fps(fpsDataList, [{ length: 0 }], 1, 100254, 100254, rect, false); 54 }); 55 56 it('FpsTest03', () => { 57 const canvas = document.createElement('canvas'); 58 canvas.width = 8; 59 canvas.height = 8; 60 const ctx = canvas.getContext('2d'); 61 62 const data = { 63 frame: { 64 x: 218, 65 y: 201, 66 width: 220, 67 height: 320, 68 }, 69 startNS: 255, 70 value: 4, 71 }; 72 73 expect(FpsStruct.draw(ctx, data)).toBeUndefined(); 74 }); 75 76 it('FpsTest04', () => { 77 const canvas = document.createElement('canvas'); 78 canvas.width = 1; 79 canvas.height = 8; 80 const ctx = canvas.getContext('2d'); 81 82 const data = { 83 frame: { 84 x: 80, 85 y: 30, 86 width: 320, 87 height: 220, 88 }, 89 startNS: 200, 90 value: 50, 91 }; 92 new FpsStruct(1); 93 FpsStruct.hoverFpsStruct = jest.fn(() => { 94 startNS: 200; 95 }); 96 FpsStruct.a = jest.fn(() => data); 97 expect(FpsStruct.draw(ctx, data)).toBeUndefined(); 98 }); 99 it('FpsTest05 ', () => { 100 const canvas = document.createElement('canvas'); 101 canvas.width = 1; 102 canvas.height = 1; 103 const ctx = canvas.getContext('2d'); 104 const Sourcedate = { 105 frame: { 106 x: 520, 107 y: 50, 108 width: 300, 109 height: 300, 110 }, 111 maxFps: 255, 112 value: 550, 113 }; 114 expect(FpsStruct.draw(ctx, Sourcedate)).toBeUndefined(); 115 }); 116}); 117