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 { ThreadStruct } from '../../../dist/trace/bean/ThreadStruct.js'; 18jest.mock('../../../dist/trace/component/trace/base/TraceRow.js', () => { 19 return {}; 20}); 21 22describe('ThreadStruct Test', () => { 23 const canvas = document.createElement('canvas'); 24 canvas.width = 18; 25 canvas.height = 18; 26 const ctx = canvas.getContext('2d'); 27 const dataSource = { 28 frame: { 29 x: 55, 30 y: 55, 31 width: 32, 32 height: 111, 33 }, 34 startNS: 2400, 35 state: '', 36 }; 37 const equalsData = { 38 value: 50, 39 cpu: 1, 40 tid: 1, 41 state: 1, 42 startTime: 1, 43 dur: 1, 44 }; 45 it('ThreadStructTest01', function () { 46 expect(ThreadStruct.draw(ctx, dataSource)).toBeUndefined(); 47 }); 48 49 it('ThreadStructTest02', function () { 50 dataSource.state = 'S'; 51 expect(ThreadStruct.draw(ctx, dataSource)).toBeUndefined(); 52 }); 53 54 it('ThreadStructTest03', function () { 55 dataSource.state = 'R'; 56 expect(ThreadStruct.draw(ctx, dataSource)).toBeUndefined(); 57 }); 58 59 it('ThreadStructTest04', function () { 60 dataSource.state = 'D'; 61 expect(ThreadStruct.draw(ctx, dataSource)).toBeUndefined(); 62 }); 63 64 it('ThreadStructTest05', function () { 65 dataSource.state = 'Running'; 66 expect(ThreadStruct.draw(ctx, dataSource)).toBeUndefined(); 67 }); 68 69 it('ThreadStructTest11', function () { 70 dataSource.state = 'T' || 't'; 71 expect(ThreadStruct.draw(ctx, dataSource)).toBeUndefined(); 72 }); 73 74 it('ThreadStructTest08', function () { 75 expect(ThreadStruct.equals(equalsData, equalsData)).toBeTruthy(); 76 }); 77 78 it('ThreadStructTest09', function () { 79 expect(ThreadStruct.equals([], dataSource)).toBeFalsy(); 80 }); 81 82 it('ThreadStructTest10', function () { 83 dataSource.state = 'ThreadStructTest10'; 84 expect(ThreadStruct.getEndState(1)).toBe('Unknown State'); 85 }); 86}); 87