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 { CpuStruct } from '../../../src/trace/bean/CpuStruct';
17
18describe('CpuStruct Test', () => {
19  const canvas = document.createElement('canvas');
20  canvas.width = 1;
21  canvas.height = 1;
22  const ctx = canvas.getContext('2d');
23  CpuStruct.selectCpuStruct = {};
24
25  const data = {
26    frame: {
27      x: 653,
28      y: 109,
29      width: 654,
30      height: 332,
31    },
32    startNS: 200,
33    value: 50,
34  };
35  const data1 = {
36    frame: {
37      x: 23,
38      y: 9,
39      width: 90,
40      height: 60,
41    },
42    startNS: 132,
43    value: 980,
44  };
45
46  it('CpuStructTest01', function () {
47    expect(CpuStruct.draw(ctx, data)).toBeUndefined();
48    expect(data).toMatchInlineSnapshot(`
49{
50  "frame": {
51    "height": 332,
52    "width": 654,
53    "x": 653,
54    "y": 109,
55  },
56  "startNS": 200,
57  "value": 50,
58}
59`);
60  });
61
62  it('CpuStructTest02', function () {
63    expect(CpuStruct.equals({}, data)).toBeTruthy();
64  });
65
66  it('CpuStructTest03', function () {
67    expect(CpuStruct.equals(data, data)).toBeTruthy();
68  });
69
70  it('CpuStructTest04', function () {
71    expect(CpuStruct.equals(data, data1)).toBeTruthy();
72  });
73
74  it('CpuStructTest05', function () {
75    expect(CpuStruct.draw(ctx, data1)).toBeUndefined();
76    expect(data1).toMatchInlineSnapshot(`
77{
78  "frame": {
79    "height": 60,
80    "width": 90,
81    "x": 23,
82    "y": 9,
83  },
84  "startNS": 132,
85  "value": 980,
86}
87`);
88  });
89
90  it('CpuStructTest06', function () {
91    expect(CpuStruct.equals({}, data1)).toBeTruthy();
92    expect(CpuStruct.draw(ctx, data)).toBeUndefined();
93    expect(data).toMatchInlineSnapshot(`
94{
95  "frame": {
96    "height": 332,
97    "width": 654,
98    "x": 653,
99    "y": 109,
100  },
101  "startNS": 200,
102  "value": 50,
103}
104`);
105  });
106});
107