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 16import { FuncStruct } from '../../../src/trace/bean/FuncStruct'; 17jest.mock('../../../src/trace/component/trace/base/TraceRow', () => { 18 return {}; 19}); 20 21describe('FuncStruct Test', () => { 22 const canvas = document.createElement('canvas'); 23 canvas.width = 1; 24 canvas.height = 1; 25 const ctx = canvas.getContext('2d'); 26 27 const dataResource = { 28 frame: { 29 x: 20, 30 y: 20, 31 }, 32 }; 33 34 const durData = { 35 frame: { 36 x: 20, 37 y: 20, 38 width: 100, 39 height: 100, 40 }, 41 dur: 5, 42 }; 43 44 FuncStruct.isSelected = jest.fn(() => true); 45 46 it('FuncStructTest01', function () { 47 expect(FuncStruct.draw(ctx, dataResource)).toBeUndefined(); 48 }); 49 50 it('FuncStructTest02', function () { 51 expect(FuncStruct.draw(ctx, durData)).toBeUndefined(); 52 }); 53 54 it('FuncStructTest04', function () { 55 expect( 56 FuncStruct.isSelected({ 57 startTs: 10, 58 dur: 10, 59 funName: '', 60 }) 61 ).toBeTruthy(); 62 }); 63 64 it('FuncStructTest05', function () { 65 expect( 66 FuncStruct.isBinder({ 67 startTs: 10, 68 dur: 10, 69 funName: null, 70 }) 71 ).toBeFalsy(); 72 }); 73 74 75 it('FuncStructTest08', function () { 76 expect( 77 FuncStruct.isBinderAsync({ 78 startTs: 10, 79 dur: 10, 80 funName: null, 81 }) 82 ).toBeFalsy(); 83 }); 84 85 it('FuncStructTest09', function () { 86 expect( 87 FuncStruct.isBinderAsync({ 88 startTs: 20, 89 dur: 20, 90 funName: 'funName', 91 }) 92 ).toBeFalsy(); 93 }); 94}); 95