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