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 system, 22 EnergySystemStruct, 23 EnergySystemRender, 24} from '../../../../src/trace/database/ui-worker/ProcedureWorkerEnergySystem'; 25 26describe('ProcedureWorkerEnergySystem Test', () => { 27 it('ProcedureWorkerEnergySystemTest01', function () { 28 let frame = { 29 x: 20, 30 y: 20, 31 width: 100, 32 height: 100, 33 }; 34 let dataList = new Array(); 35 dataList.push({ 36 startNs: 0, 37 dur: 10, 38 length: 1, 39 frame: { x: 0, y: 9, width: 10, height: 10 }, 40 }); 41 dataList.push({ startNs: 1, dur: 2, length: 1 }); 42 system(dataList, [{ length: 1 }], 1, 3, 2, frame, true); 43 }); 44 45 it('ProcedureWorkerEnergySystemTest02', function () { 46 let frame = { 47 x: 20, 48 y: 20, 49 width: 100, 50 height: 100, 51 }; 52 53 let aa: any = []; 54 let dataList = new Array(); 55 dataList.push({ 56 startNs: 0, 57 dur: 10, 58 frame: { x: 0, y: 9, width: 10, height: 10 }, 59 }); 60 dataList.push({ startNs: 1, dur: 2 }); 61 aa[0] = dataList; 62 aa[1] = dataList; 63 aa[2] = dataList; 64 system(aa, [], 1, 3, 2, frame, false); 65 }); 66 67 it('ProcedureWorkerEnergyStateTest04', function () { 68 const canvas = document.createElement('canvas'); 69 canvas.width = 1; 70 canvas.height = 1; 71 const ctx = canvas.getContext('2d'); 72 73 const data = { 74 type: 0, 75 frame: { 76 x: 20, 77 y: 20, 78 width: 100, 79 height: 100, 80 }, 81 }; 82 expect(EnergySystemStruct.draw(ctx, data)).toBeUndefined(); 83 }); 84 85 it('ProcedureWorkerEnergyStateTest05', function () { 86 const canvas = document.createElement('canvas'); 87 canvas.width = 1; 88 canvas.height = 1; 89 const ctx = canvas.getContext('2d'); 90 91 const data = { 92 type: 1, 93 frame: { 94 x: 20, 95 y: 20, 96 width: 100, 97 height: 100, 98 }, 99 }; 100 expect(EnergySystemStruct.draw(ctx, data)).toBeUndefined(); 101 }); 102 103 it('ProcedureWorkerEnergyStateTest06', function () { 104 const canvas = document.createElement('canvas'); 105 canvas.width = 1; 106 canvas.height = 1; 107 const ctx = canvas.getContext('2d'); 108 109 const data = { 110 type: 2, 111 frame: { 112 x: 20, 113 y: 20, 114 width: 100, 115 height: 100, 116 }, 117 }; 118 expect(EnergySystemStruct.draw(ctx, data)).toBeUndefined(); 119 }); 120 121 it('ProcedureWorkerEnergyStateTest07', function () { 122 let node = { 123 frame: { 124 x: 10, 125 y: 30, 126 width: 202, 127 height: 202, 128 }, 129 startNS: 10, 130 value: 22, 131 startTs: 64, 132 dur: 66, 133 height: 2, 134 type: 2, 135 }; 136 let frame = { 137 x: 20, 138 y: 20, 139 width: 100, 140 height: 100, 141 }; 142 expect(EnergySystemStruct.setSystemFrame(node, 1, 1, 3, 2, frame)).toBeUndefined(); 143 }); 144 145 it('ProcedureWorkerEnergyStateTest08', function () { 146 let node = { 147 frame: { 148 x: 20, 149 y: 20, 150 width: 100, 151 height: 100, 152 }, 153 startNS: 3, 154 value: 50, 155 startTs: 3, 156 dur: 3, 157 height: 2, 158 type: 1, 159 }; 160 let frame = { 161 x: 20, 162 y: 20, 163 width: 100, 164 height: 100, 165 }; 166 expect(EnergySystemStruct.setSystemFrame(node, 1, 2, 3, 1, frame)).toBeUndefined(); 167 }); 168 169 it('ProcedureWorkerEnergyStateTest09', function () { 170 let node = { 171 frame: { 172 x: 50, 173 y: 50, 174 width: 700, 175 height: 170, 176 }, 177 startNS: 73, 178 value: 77, 179 startTs: 3, 180 dur: 13, 181 height: 12, 182 type: 12, 183 }; 184 let frame = { 185 x: 20, 186 y: 20, 187 width: 100, 188 height: 100, 189 }; 190 expect(EnergySystemStruct.setSystemFrame(node, 1, 1, 3, 2, frame)).toBeUndefined(); 191 }); 192}); 193