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 17 import {system,EnergySystemStruct,EnergySystemRender} from "../../../../dist/trace/database/ui-worker/ProcedureWorkerEnergySystem.js" 18 19 describe('ProcedureWorkerEnergySystem Test', () => { 20 21 it('ProcedureWorkerEnergySystemTest01', function () { 22 let frame = { 23 x: 20, 24 y: 20, 25 width: 100, 26 height: 100 27 } 28 let dataList = new Array(); 29 dataList.push({startNS: 0, dur: 10, length: 1, frame: {x: 0, y: 9, width: 10, height: 10}}) 30 dataList.push({startNS: 1, dur: 2, length: 1}) 31 system(dataList, [{length: 1}], 1, 3, 2, frame, true) 32 }); 33 34 it('ProcedureWorkerEnergySystemTest02', function () { 35 let frame = { 36 x: 20, 37 y: 20, 38 width: 100, 39 height: 100 40 } 41 let dataList = new Array(); 42 dataList.push({startNS: 0, dur: 10, length: 1, frame: {x: 0, y: 9, width: 10, height: 10}}) 43 dataList.push({startNS: 1, dur: 2, length: 1}) 44 system(dataList, [{length: 0}], 1, 3, 2, frame, false) 45 }); 46 47 it('ProcedureWorkerEnergyStateTest04', function () { 48 const canvas = document.createElement('canvas'); 49 canvas.width = 1; 50 canvas.height = 1; 51 const ctx = canvas.getContext('2d'); 52 53 const data = { 54 type :0, 55 frame: { 56 x: 20, 57 y: 20, 58 width: 100, 59 height: 100 60 } 61 } 62 expect(EnergySystemStruct.draw(ctx , data)).toBeUndefined() 63 }); 64 65 it('ProcedureWorkerEnergyStateTest05', function () { 66 const canvas = document.createElement('canvas'); 67 canvas.width = 1; 68 canvas.height = 1; 69 const ctx = canvas.getContext('2d'); 70 71 const data = { 72 type :1, 73 frame: { 74 x: 20, 75 y: 20, 76 width: 100, 77 height: 100 78 } 79 } 80 expect(EnergySystemStruct.draw(ctx , data)).toBeUndefined() 81 }); 82 83 it('ProcedureWorkerEnergyStateTest06', function () { 84 const canvas = document.createElement('canvas'); 85 canvas.width = 1; 86 canvas.height = 1; 87 const ctx = canvas.getContext('2d'); 88 89 const data = { 90 type :2, 91 frame: { 92 x: 20, 93 y: 20, 94 width: 100, 95 height: 100 96 } 97 } 98 expect(EnergySystemStruct.draw(ctx , data)).toBeUndefined() 99 }); 100 101 it('ProcedureWorkerEnergyStateTest07', function () { 102 let node = { 103 frame: { 104 x: 20, 105 y: 20, 106 width: 100, 107 height: 100 108 }, 109 startNS: 1, 110 value: 50, 111 startTs:3, 112 dur:3, 113 height:2, 114 type:0, 115 } 116 let frame = { 117 x: 20, 118 y: 20, 119 width: 100, 120 height: 100 121 } 122 expect(EnergySystemStruct.setSystemFrame(node , 1,1,3,2,frame)).toBeUndefined() 123 }); 124 125 it('ProcedureWorkerEnergyStateTest08', function () { 126 let node = { 127 frame: { 128 x: 20, 129 y: 20, 130 width: 100, 131 height: 100 132 }, 133 startNS: 3, 134 value: 50, 135 startTs:3, 136 dur:3, 137 height:2, 138 type:1, 139 } 140 let frame = { 141 x: 20, 142 y: 20, 143 width: 100, 144 height: 100 145 } 146 expect(EnergySystemStruct.setSystemFrame(node , 1,2,3,1,frame)).toBeUndefined() 147 }); 148 149 it('ProcedureWorkerEnergyStateTest09', function () { 150 let node = { 151 frame: { 152 x: 20, 153 y: 20, 154 width: 100, 155 height: 100 156 }, 157 startNS: 1, 158 value: 50, 159 startTs:3, 160 dur:3, 161 height:2, 162 type:2, 163 } 164 let frame = { 165 x: 20, 166 y: 20, 167 width: 100, 168 height: 100 169 } 170 expect(EnergySystemStruct.setSystemFrame(node , 1,1,3,2,frame)).toBeUndefined() 171 }); 172 173 it('ProcedureWorkerEnergyStateTest10', function () { 174 let energySystemRender = new EnergySystemRender() 175 let req = { 176 lazyRefresh:true, 177 type:"", 178 startNS:1, 179 endNS:1, 180 totalNS:1, 181 frame: { 182 x: 20, 183 y: 20, 184 width: 100, 185 height: 100 186 }, 187 useCache:false, 188 range:{ 189 refresh:"", 190 }, 191 canvas:'', 192 context:{ 193 font:"11px sans-serif", 194 fillStyle:"#ec407a", 195 globalAlpha:0.6, 196 height:150, 197 width:100 198 }, 199 lineColor:'', 200 isHover:'', 201 hoverX:1, 202 wakeupBean:undefined, 203 flagMoveInfo:'', 204 flagSelectedInfo:'', 205 slicesTime:3, 206 id:1, 207 x: 20, 208 y: 20, 209 width: 100, 210 height: 100, 211 params:{ 212 isLive:false, 213 maxHeight:2, 214 dpr:1, 215 hoverFuncStruct:'', 216 selectFuncStruct:undefined, 217 }, 218 } 219 window.postMessage = jest.fn(()=>true) 220 expect(energySystemRender.render(req,[{}],[])).toBeUndefined() 221 }); 222 }) 223