• 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
16jest.mock('../../../../src/trace/component/trace/base/TraceRow', () => {
17  return {};
18});
19
20import {
21  EnergyPowerStruct,
22  EnergyPowerRender,
23  power,
24} from '../../../../src/trace/database/ui-worker/ProcedureWorkerEnergyPower';
25
26describe('ProcedureWorkerEnergyPower Test', () => {
27  it('ProcedureWorkerEnergyPowerTest01', function () {
28    let req = {
29      context: {
30        globalAlpha: 1.0,
31        lineWidth: 1,
32        fillStyle: '#333',
33      },
34    };
35    let data = {
36      cpu: 1,
37      location: 2,
38      gpu: 1,
39      display: 1,
40      camera: 1,
41      bluetooth: 3,
42      flashlight: 10,
43      audio: 16,
44      wifiscan: 1,
45      ts: 10,
46      frame: {
47        x: 20,
48        y: 20,
49        width: 100,
50        height: 100,
51      },
52    };
53    let row = { frame: 20 };
54    EnergyPowerStruct.drawHistogram = jest.fn(() => true);
55    EnergyPowerStruct.drawPolyline = jest.fn(() => true);
56    expect(EnergyPowerStruct.draw(req, 3, data, row)).toBeUndefined();
57  });
58
59  it('ProcedureWorkerEnergyPowerTest02', function () {
60    let frame = {
61      x: 20,
62      y: 20,
63      width: 100,
64      height: 100,
65    };
66    let node = {
67      ts: 10,
68      frame: {
69        x: 20,
70        y: 20,
71        width: 100,
72        height: 100,
73      },
74    };
75    expect(EnergyPowerStruct.setPowerFrame(node, 1, 2, 5, 3, frame)).toBeUndefined();
76  });
77
78  it('ProcedureWorkerEnergyPowerTest03', function () {
79    let frame = {
80      x: 20,
81      y: 20,
82      width: 100,
83      height: 100,
84    };
85    let node = {
86      ts: 1,
87      frame: {
88        x: 20,
89        y: 20,
90        width: 100,
91        height: 100,
92      },
93    };
94    expect(EnergyPowerStruct.setPowerFrame(node, 1, 2, 2000000002, 2000000000, frame)).toBeUndefined();
95  });
96
97  it('ProcedureWorkerEnergyPowerTest04', function () {
98    expect(EnergyPowerStruct.getHistogramColor('CPU')).toBe('#92D6CC');
99  });
100
101  it('ProcedureWorkerEnergyPowerTest05', function () {
102    expect(EnergyPowerStruct.getHistogramColor('LOCATION')).toBe('#61CFBE');
103  });
104
105  it('ProcedureWorkerEnergyPowerTest06', function () {
106    expect(EnergyPowerStruct.getHistogramColor('GPU')).toBe('#86C5E3');
107  });
108
109  it('ProcedureWorkerEnergyPowerTest07', function () {
110    expect(EnergyPowerStruct.getHistogramColor('DISPLAY')).toBe('#46B1E3');
111  });
112
113  it('ProcedureWorkerEnergyPowerTest08', function () {
114    expect(EnergyPowerStruct.getHistogramColor('CAMERA')).toBe('#C386F0');
115  });
116
117  it('ProcedureWorkerEnergyPowerTest09', function () {
118    expect(EnergyPowerStruct.getHistogramColor('BLUETOOTH')).toBe('#8981F7');
119  });
120
121  it('ProcedureWorkerEnergyPowerTest10', function () {
122    expect(EnergyPowerStruct.getHistogramColor('AUDIO')).toBe('#AC49F5');
123  });
124
125  it('ProcedureWorkerEnergyPowerTest11', function () {
126    expect(EnergyPowerStruct.getHistogramColor('WIFISCAN')).toBe('#92C4BD');
127  });
128
129  it('ProcedureWorkerEnergyPowerTest12', function () {
130    expect(EnergyPowerStruct.getHistogramColor('WIFISCANxcda')).toBe('#564AF7');
131  });
132
133  it('ProcedureWorkerEnergyPowerTest13', function () {
134    expect(EnergyPowerStruct).not.toBeUndefined();
135  });
136
137  it('ProcedureWorkerEnergyPowerTest14', function () {
138    let energyPowerRender = new EnergyPowerRender();
139    let energyPowerReq = {
140      lazyRefresh: true,
141      type: '',
142      startNS: 1,
143      endNS: 8,
144      totalNS: 7,
145      frame: {
146        x: 90,
147        y: 20,
148        width: 1011,
149        height: 100,
150      },
151      useCache: false,
152      range: {
153        refresh: '',
154      },
155      canvas: 'c',
156      context: {
157        font: '10px sans-serif',
158        fillStyle: '#ec407a',
159        globalAlpha: 0.8,
160        canvas: {
161          clientWidth: 14,
162        },
163        clearRect: jest.fn(() => true),
164        beginPath: jest.fn(() => true),
165        stroke: jest.fn(() => true),
166        fillRect: jest.fn(() => false),
167        closePath: jest.fn(() => true),
168        measureText: jest.fn(() => true),
169        fillText: jest.fn(() => true),
170      },
171      lineColor: '#ffffff',
172      isHover: '',
173      hoverX: 1,
174      params: '21',
175      wakeupBean: undefined,
176      flagMoveInfo: '',
177      flagSelectedInfo: '',
178      slicesTime: 5,
179      id: 1,
180      x: 20,
181      y: 20,
182      width: 80,
183      height: 80,
184    };
185    window.postMessage = jest.fn(() => true);
186    expect(energyPowerRender.render(energyPowerReq, [], [])).toBeUndefined();
187  });
188
189  it('ProcedureWorkerEnergyPowerTest15', function () {
190    let frame = {
191      x: 50,
192      y: 33,
193      width: 800,
194      height: 500,
195    };
196    let energyPowerDataList = new Array();
197    energyPowerDataList.push({
198      startNS: 0,
199      dur: 90,
200      length: 16,
201      frame: { x: 0, y: 9, width: 20, height: 12 },
202    });
203    energyPowerDataList.push({ startNS: 71, dur: 32, length: 12 });
204    power(energyPowerDataList, [{ length: 1 }], 1, 3, 2, frame, true, '');
205  });
206
207  it('ProcedureWorkerEnergyPowerTest16', function () {
208    let frame = {
209      x: 98,
210      y: 90,
211      width: 500,
212      height: 700,
213    };
214    let energyPowerDataList = new Array();
215    energyPowerDataList.push({
216      startNS: 0,
217      dur: 50,
218      length: 67,
219      frame: { x: 0, y: 9, width: 60, height: 60 },
220    });
221    energyPowerDataList.push({ startNS: 12, dur: 82, length: 16 });
222    power(energyPowerDataList, [{ length: 0 }], 1, 3, 2, frame, false, '');
223  });
224});
225