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// @ts-ignore 16import { 17 ChartStruct, 18 drawFlagLine, 19 drawLines, 20 getFrameChartColor, 21 getHeatColor, 22 Point, 23 Rect, 24 ns2s, 25 ns2x, 26 drawSelection, 27 drawWakeUp 28 // @ts-ignore 29} from "../../../../dist/trace/database/ui-worker/ProcedureWorkerCommon.js" 30// @ts-ignore 31import {Flag} from "../../../../dist/trace/database/ui-worker/ProcedureWorkerTimeline.js"; 32// @ts-ignore 33import {ColorUtils} from "../../../../dist/trace/component/trace/base/ColorUtils.js"; 34 35describe('ProcedureWorkerCommon Test', () => { 36 let rect = new Rect(); 37 38 39 it('ProcedureWorkerCommon01', function () { 40 expect(rect.contains(1, 2)).not.toBeUndefined(); 41 }); 42 43 it('ProcedureWorkerCommon02', function () { 44 expect(rect.containsWithPadding()).not.toBeUndefined(); 45 }); 46 47 it('ProcedureWorkerCommon03', function () { 48 let point = new Point(); 49 expect(point).not.toBeUndefined(); 50 }) 51 52 53 it('ProcedureWorkerCommon04', function () { 54 let rect = new Rect(); 55 expect(Rect.contains(rect, 1, 2)).toBe(false); 56 }) 57 58 59 it('ProcedureWorkerCommon05', function () { 60 let rect = new Rect(); 61 expect(Rect.containsWithPadding(rect, 1, 2, 1, 2)).toBe(false); 62 }) 63 64 it('ProcedureWorkerCommon06', function () { 65 let rect = new Rect(); 66 expect(Rect.containsWithMargin(rect, 1, 2, 1, 2, 1, 1)).toBe(false); 67 }) 68 69 70 it('ProcedureWorkerCommon07', function () { 71 let rect = new Rect(); 72 let rect2 = new Rect(); 73 expect(Rect.intersect(rect, rect2)).toBe(false); 74 }) 75 76 it('ProcedureWorkerCommon08', function () { 77 let rect = new Rect(); 78 expect(rect.containsWithMargin(1, 2, 3, 5, 4, 5)).toBe(false); 79 }) 80 81 it('ProcedureWorkerCommon09', function () { 82 let rect = new Rect(); 83 expect(rect.containsWithPadding(1, 2, 3, 5)).toBe(false); 84 }) 85 86 it('ProcedureWorkerCommon10', function () { 87 let rect = new Rect(); 88 let rect2 = new Rect(); 89 expect(rect.intersect(rect2)).toBe(false); 90 }) 91 92 93 it('ProcedureWorkerCommon011', function () { 94 expect(ColorUtils.formatNumberComma("11232")).toBe("11,232"); 95 }) 96 97 it('ProcedureWorkerCommon012', function () { 98 const canvas = document.createElement('canvas'); 99 canvas.width = 1; 100 canvas.height = 1; 101 const ctx = canvas.getContext('2d'); 102 let aaa = [1, 2, 3] 103 drawLines(ctx, aaa, 1, "#ffff") 104 expect(ColorUtils.formatNumberComma("11232")).toBe("11,232"); 105 }) 106 107 it('ProcedureWorkerCommon013', function () { 108 const canvas = document.createElement('canvas'); 109 canvas.width = 1; 110 canvas.height = 1; 111 const ctx = canvas.getContext('2d'); 112 let aaa = [1, 2, 3] 113 let flag = new Flag(1, 2, 3, 4, 5, "#FFF", false); 114 let rect2 = new Rect(); 115 drawFlagLine(ctx, aaa, flag, 1, 2, 2, rect2) 116 expect(ColorUtils.formatNumberComma("11232")).toBe("11,232"); 117 }) 118 119 120 it('ProcedureWorkerCommon20', function () { 121 expect(ns2s(2_000_000_000)).toBe("2.0 s"); 122 }); 123 124 it('ProcedureWorkerCommon21', function () { 125 expect(ns2s(2_000_000)).toBe("2.0 ms"); 126 }); 127 128 it('ProcedureWorkerCommon22', function () { 129 expect(ns2s(2_000)).toBe("2.0 μs"); 130 }); 131 132 it('ProcedureWorkerCommon23', function () { 133 expect(ns2s(1)).toBe("1.0 ns"); 134 }); 135 136 it('ProcedureWorkerCommon24', function () { 137 expect(ns2s(-1)).toBe("-1.0 s"); 138 }); 139 140 it('ProcedureWorkerCommon25', function () { 141 expect(ColorUtils.hashFunc("",10,10)).toBe(3); 142 }); 143 144 it('ProcedureWorkerCommon26', function () { 145 expect(ns2x(10,1,0,1,{width:2})).toBe(2); 146 }); 147 148 it('ProcedureWorkerCommon27', function () { 149 expect(ns2x(-10,1,0,1,{width:2})).toBe(0); 150 }); 151 152 it('ProcedureWorkerCommon28', function () { 153 const canvas = document.createElement('canvas'); 154 canvas.width = 1; 155 canvas.height = 1; 156 const ctx = canvas.getContext('2d'); 157 let flag = { 158 color:"", 159 x:1 160 } 161 let select ={ 162 color:"", 163 x:1, 164 time:"", 165 } 166 let frame ={ 167 height:1 168 } 169 let slicesTime ={ 170 startTime:1, 171 endTime:1, 172 color:"#dadada" 173 } 174 expect(drawFlagLine(ctx,flag,select,1,2,1,frame,slicesTime)).toBeUndefined(); 175 }); 176 177 it('ProcedureWorkerCommon29', function () { 178 let context = { 179 globalAlpha:0.5, 180 fillStyle:"#666666", 181 } 182 let params = { 183 isRangeSelect:'', 184 rangeSelectObject: { 185 startX:1, 186 endX:10, 187 startNS:1, 188 endNS:10, 189 }, 190 startNS:1, 191 endNS:10, 192 totalNS:9, 193 frame:{ 194 y:0, 195 }, 196 197 } 198 expect(drawSelection(context,params)).toBeUndefined(); 199 }); 200 201 it('ProcedureWorkerCommon30', function () { 202 const canvas = document.createElement('canvas'); 203 canvas.width = 1; 204 canvas.height = 1; 205 const context = canvas.getContext('2d'); 206 let wake = { 207 wakeupTime:2, 208 cpu:1 209 } 210 let frame = new Rect(0, 10, 10, 10); 211 expect(drawWakeUp(context,wake,1,2,1,frame,undefined,undefined)).toBeUndefined(); 212 }); 213}) 214 215