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 {cpu, CpuStruct} from "../../../dist/trace/database/ProcedureWorkerCPU.js"; 18// @ts-ignore 19import {Rect} from "../../../dist/trace/component/trace/timer-shaft/Rect.js"; 20 21describe(' Test', () => { 22 const dataSource = { 23 frame: { 24 x: 20, 25 y: 20, 26 width: 100, 27 height: 100 28 }, 29 startNS: 200, 30 processId : '' 31 } 32 33 it('CPUTest01', () => { 34 let dataList = new Array(); 35 dataList.push({startTime: 0, dur: 10, frame: {x:0, y:9, width:10, height:10}}) 36 dataList.push({startTime: 1, dur: 111}) 37 let rect = new Rect(0, 10, 10, 10); 38 cpu(dataList, new Set(), 1, 100254, 100254, rect) 39 }) 40 41 it('CPUTest02', () => { 42 let dataList = new Array(); 43 dataList.push({startTime: 0, dur: 10, frame: {x:0, y:9, width:10, height:10}}) 44 dataList.push({startTime: 1, dur: 111, frame: {x:0, y:9, width:10, height:10}}) 45 let rect = new Rect(0, 10, 10, 10); 46 cpu(dataList, new Set(), 1, 100254, 100254, rect) 47 }) 48 49 it('CPUTest03', () => { 50 const canvas = document.createElement('canvas'); 51 canvas.width = 1; 52 canvas.height = 1; 53 const ctx = canvas.getContext('2d'); 54 55 const data = { 56 frame: { 57 x: 20, 58 y: 20, 59 width: 100, 60 height: 100 61 }, 62 startNS: 200, 63 value: 50 64 } 65 expect(CpuStruct.draw(ctx, data)).toBeUndefined() 66 }) 67 68 it('CPUTest04', () => { 69 expect(CpuStruct.equals(new CpuStruct(),new CpuStruct())).toBeTruthy(); 70 }) 71 it('CPUTest06', () => { 72 expect(CpuStruct.equals([],dataSource)).toBeFalsy() 73 }) 74 75 76 it('CPUTest05', () => { 77 const canvas = document.createElement('canvas'); 78 canvas.width = 1; 79 canvas.height = 1; 80 const ctx = canvas.getContext('2d'); 81 82 const data = { 83 frame: { 84 x: 20, 85 y: 20, 86 width: 100, 87 height: 100 88 }, 89 startNS: 200, 90 value: 50 91 } 92 expect(CpuStruct.draw(ctx, data)).toBeUndefined() 93 }) 94 95});