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