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