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