1/* 2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 16import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium'; 17import image from '@ohos.multimedia.image'; 18import drawing from '@ohos.graphics.drawing'; 19import common2D from '@ohos.graphics.common2D'; 20import { getEnumCount } from './utils'; 21 22export default function drawingTsCanvasPart4Test() { 23 describe('DrawingTsCanvasPart4Test', () => { 24 let pixel: image.PixelMap; 25 const DEFAULT = 0; 26 // Defines a test suite. Two parameters are supported: test suite name and test suite function. 27 beforeAll(async () => { 28 const color: ArrayBuffer = new ArrayBuffer(40000); // 96为需要创建的像素buffer大小,取值为:height * width *4 29 let opts: image.InitializationOptions = { 30 editable: true, pixelFormat: 3, size: { 31 height: 100, width: 100 32 } 33 } 34 pixel = await image.createPixelMap(color, opts); 35 }) 36 beforeEach(() => { 37 // Presets an action, which is performed before each unit test case starts. 38 // The number of execution times is the same as the number of test cases defined by **it**. 39 // This API supports only one parameter: preset action function. 40 }) 41 afterEach(() => { 42 // Presets a clear action, which is performed after each unit test case ends. 43 // The number of execution times is the same as the number of test cases defined by **it**. 44 // This API supports only one parameter: clear action function. 45 }) 46 afterAll(() => { 47 // Presets a clear action, which is performed after all test cases of the test suite end. 48 // This API supports only one parameter: clear action function. 49 }) 50 51 52 /** 53 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2500 54 * @tc.name : testCanvasSaveLayerNormal 55 * @tc.desc : testCanvasSaveLayerNormal 56 * @tc.size : SmallTest 57 * @tc.type : Function 58 * @tc.level : Level0 59 */ 60 it('testCanvasSaveLayerNormal', DEFAULT, () => { 61 const msg = 'testCanvasSaveLayerNormal'; 62 try { 63 const canvas = new drawing.Canvas(pixel); 64 const rect: common2D.Rect = { 65 left: 0, right: 100, top: 0, bottom: 100 66 }; 67 const brush = new drawing.Brush(); 68 69 canvas.saveLayer(rect, brush) 70 canvas.saveLayer(null, brush) 71 canvas.saveLayer(rect, null) 72 73 console.info(msg + 'test successed'); 74 } catch (e) { 75 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 76 expect().assertFail(); 77 } 78 }) 79 80 81 /** 82 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2501 83 * @tc.name : testCanvasSaveLayerUndefined 84 * @tc.desc : testCanvasSaveLayerUndefined 85 * @tc.size : SmallTest 86 * @tc.type : Function 87 * @tc.level : Level3 88 */ 89 it('testCanvasSaveLayerUndefined', 3, () => { 90 const msg = 'testCanvasSaveLayerUndefined'; 91 const canvas = new drawing.Canvas(pixel); 92 const brush = new drawing.Brush(); 93 const rect: common2D.Rect = { 94 left: 0, right: 100, top: 0, bottom: 100 95 }; 96 97 try { 98 canvas.saveLayer(undefined, brush) 99 console.info(msg + `test error`); 100 expect().assertFail() 101 } catch (e) { 102 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 103 expect(e.code).assertEqual(401); 104 } 105 106 try { 107 canvas.saveLayer(rect, undefined) 108 console.info(msg + `test error`); 109 expect().assertFail() 110 } catch (e) { 111 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 112 expect(e.code).assertEqual(401); 113 } 114 }) 115 116 117 /** 118 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2600 119 * @tc.name : testCanvasClearNormal 120 * @tc.desc : testCanvasClearNormal 121 * @tc.size : SmallTest 122 * @tc.type : Function 123 * @tc.level : Level0 124 */ 125 it('testCanvasClearNormal', DEFAULT, () => { 126 const msg = 'testCanvasClearNormal'; 127 try { 128 const canvas = new drawing.Canvas(pixel); 129 canvas.clear({ 130 alpha: 255, red: 255, green: 0, blue: 0 131 }); 132 canvas.clear({ 133 alpha: 255.1, red: 255.1, green: 255.1, blue: 255.1 134 }); 135 canvas.clear({ 136 alpha: 0.1, red: 0.1, green: 0.1, blue: 0.1 137 }); 138 139 console.info(msg + 'test successes'); 140 } catch (e) { 141 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 142 expect().assertFail(); 143 } 144 }) 145 146 147 /** 148 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2601 149 * @tc.name : testCanvasClearMultipleCalls 150 * @tc.desc : testCanvasClearMultipleCalls 151 * @tc.size : SmallTest 152 * @tc.type : Function 153 * @tc.level : Level3 154 */ 155 it('testCanvasClearMultipleCalls', 3, () => { 156 const msg = 'testCanvasClearMultipleCalls'; 157 try { 158 const canvas = new drawing.Canvas(pixel); 159 for (let i = 0; i < 20; i += 1) { 160 canvas.clear({ 161 alpha: Math.random() * 256, red: Math.random() * 256, 162 green: Math.random() * 256, blue: Math.random() * 256 163 }) 164 } 165 console.info(msg + 'test successes'); 166 } catch (e) { 167 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 168 expect().assertFail(); 169 } 170 }) 171 172 173 /** 174 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2602 175 * @tc.name : testCanvasClearToNull 176 * @tc.desc : testCanvasClearToNull 177 * @tc.size : SmallTest 178 * @tc.type : Function 179 * @tc.level : Level3 180 */ 181 it('testCanvasClearToNull', 3, () => { 182 const msg = 'testCanvasClearToNull'; 183 const canvas = new drawing.Canvas(pixel); 184 185 186 try { 187 canvas.clear(null); 188 console.info(msg + `test error`); 189 expect().assertFail() 190 } catch (e) { 191 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 192 expect(e.code).assertEqual(401); 193 } 194 195 try { 196 canvas.clear(undefined); 197 console.info(msg + `test error`); 198 expect().assertFail() 199 } catch (e) { 200 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 201 expect(e.code).assertEqual(401); 202 } 203 204 }) 205 206 207 /** 208 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2604 209 * @tc.name : testCanvasClearAbnormal 210 * @tc.desc : testCanvasClearAbnormal 211 * @tc.size : SmallTest 212 * @tc.type : Function 213 * @tc.level : Level3 214 */ 215 it('testCanvasClearAbnormal', 3, () => { 216 const msg = 'testCanvasClearAbnormal'; 217 const canvas = new drawing.Canvas(pixel); 218 try { 219 220 try { 221 canvas.clear({ 222 alpha: 256, red: 255, green: 0, blue: 0 223 }); 224 console.info(msg + `test error`); 225 expect().assertFail() 226 } catch (e) { 227 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 228 expect(e.code).assertEqual(401); 229 } 230 231 try { 232 canvas.clear({ 233 alpha: 255, red: 256, green: 0, blue: 0 234 }); 235 console.info(msg + `test error`); 236 expect().assertFail() 237 } catch (e) { 238 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 239 expect(e.code).assertEqual(401); 240 } 241 242 try { 243 canvas.clear({ 244 alpha: 255, red: 255, green: 256, blue: 0 245 }); 246 console.info(msg + `test error`); 247 expect().assertFail() 248 } catch (e) { 249 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 250 expect(e.code).assertEqual(401); 251 } 252 253 try { 254 canvas.clear({ 255 alpha: 255, red: 255, green: 0, blue: 256 256 }); 257 console.info(msg + `test error`); 258 expect().assertFail() 259 } catch (e) { 260 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 261 expect(e.code).assertEqual(401); 262 } 263 264 try { 265 canvas.clear({ 266 alpha: -1, red: 255, green: 0, blue: 0 267 }); 268 console.info(msg + `test error`); 269 expect().assertFail() 270 } catch (e) { 271 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 272 expect(e.code).assertEqual(401); 273 } 274 275 try { 276 canvas.clear({ 277 alpha: 255, red: -1, green: 0, blue: 0 278 }); 279 console.info(msg + `test error`); 280 expect().assertFail() 281 } catch (e) { 282 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 283 expect(e.code).assertEqual(401); 284 } 285 286 try { 287 canvas.clear({ 288 alpha: 255, red: 255, green: -1, blue: 0 289 }); 290 console.info(msg + `test error`); 291 expect().assertFail() 292 } catch (e) { 293 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 294 expect(e.code).assertEqual(401); 295 } 296 297 try { 298 canvas.clear({ 299 alpha: 255, red: 255, green: 0, blue: -1 300 }); 301 console.info(msg + `test error`); 302 expect().assertFail() 303 } catch (e) { 304 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 305 expect(e.code).assertEqual(401); 306 } 307 308 console.info(msg + 'test successes'); 309 } catch (e) { 310 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 311 expect().assertFail(); 312 } 313 }) 314 315 316 /** 317 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2700 318 * @tc.name : testCanvasGetWidthAndHeightNormal 319 * @tc.desc : testCanvasGetWidthAndHeightNormal 320 * @tc.size : SmallTest 321 * @tc.type : Function 322 * @tc.level : Level0 323 */ 324 it('testCanvasGetWidthAndHeightNormal', DEFAULT, () => { 325 const msg = 'testCanvasGetWidthAndHeightNormal'; 326 const canvas = new drawing.Canvas(pixel); 327 try { 328 let width = canvas.getWidth(); 329 let height = canvas.getHeight(); 330 console.info(msg + 'test successes'); 331 expect(width).assertEqual(100); 332 expect(height).assertEqual(100); 333 } catch (e) { 334 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 335 expect().assertFail(); 336 } 337 }) 338 339 340 /** 341 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2701 342 * @tc.name : testCanvasGetWidthAndHeightMultipleCalls 343 * @tc.desc : testCanvasGetWidthAndHeightMultipleCalls 344 * @tc.size : SmallTest 345 * @tc.type : Function 346 * @tc.level : Level3 347 */ 348 it('testCanvasGetWidthAndHeightMultipleCalls', 3, () => { 349 const msg = 'testCanvasGetWidthAndHeightMultipleCalls'; 350 const canvas = new drawing.Canvas(pixel); 351 try { 352 for (let i = 0; i < 20; i += 1) { 353 let width = canvas.getWidth(); 354 let height = canvas.getHeight(); 355 expect(width).assertEqual(100); 356 expect(height).assertEqual(100); 357 } 358 console.info(msg + 'test successes'); 359 } catch (e) { 360 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 361 expect().assertFail(); 362 } 363 }) 364 365 366 /** 367 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2800 368 * @tc.name : testCanvasDrawOvalNormal 369 * @tc.desc : testCanvasDrawOvalNormal 370 * @tc.size : SmallTest 371 * @tc.type : Function 372 * @tc.level : Level0 373 */ 374 it('testCanvasDrawOvalNormal', DEFAULT, () => { 375 const msg = 'testCanvasDrawOvalNormal'; 376 const canvas = new drawing.Canvas(pixel); 377 const maxVal = Number.MAX_VALUE; 378 379 try { 380 canvas.drawOval({ 381 left: 100, right: 400, top: 50, bottom: 200 382 }); 383 canvas.drawOval({ 384 left: 100.1, right: 400.1, top: 50.1, bottom: 200.1 385 }); 386 canvas.drawOval({ 387 left: -100, right: 400, top: -50, bottom: 200 388 }); 389 canvas.drawOval({ 390 left: 100, right: -400, top: 50, bottom: -200 391 }); 392 canvas.drawOval({ 393 left: 100, right: 100, top: 100, bottom: 200 394 }); 395 canvas.drawOval({ 396 left: 100, right: 100, top: 100, bottom: 100 397 }); 398 canvas.drawOval({ 399 left: maxVal, right: maxVal, top: maxVal, bottom: maxVal 400 }); 401 console.info(msg + 'test successes'); 402 } catch (e) { 403 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 404 expect().assertFail(); 405 } 406 }) 407 408 409 /** 410 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2801 411 * @tc.name : testCanvasDrawOvalMultipleCalls 412 * @tc.desc : testCanvasDrawOvalMultipleCalls 413 * @tc.size : SmallTest 414 * @tc.type : Function 415 * @tc.level : Level3 416 */ 417 it('testCanvasDrawOvalMultipleCalls', 3, () => { 418 const msg = 'testCanvasDrawOvalMultipleCalls'; 419 const canvas = new drawing.Canvas(pixel); 420 try { 421 for (let i = 0; i < 20; i += 1) { 422 canvas.drawOval({ 423 left: Math.random(), right: Math.random(), top: Math.random(), bottom: Math.random() 424 }); 425 } 426 427 console.info(msg + 'test successes'); 428 } catch (e) { 429 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 430 expect().assertFail(); 431 } 432 }) 433 434 435 /** 436 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2802 437 * @tc.name : testCanvasDrawOvalToNull 438 * @tc.desc : testCanvasDrawOvalToNull 439 * @tc.size : SmallTest 440 * @tc.type : Function 441 * @tc.level : Level3 442 */ 443 it('testCanvasDrawOvalToNull', 3, () => { 444 const msg = 'testCanvasDrawOvalToNull'; 445 const canvas = new drawing.Canvas(pixel); 446 447 try { 448 canvas.drawOval(null); 449 console.info(msg + `test error`); 450 expect().assertFail() 451 } catch (e) { 452 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 453 expect(e.code).assertEqual(401); 454 } 455 456 try { 457 canvas.drawOval(undefined); 458 console.info(msg + `test error`); 459 expect().assertFail() 460 } catch (e) { 461 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 462 expect(e.code).assertEqual(401); 463 } 464 465 try { 466 canvas.drawOval({ 467 left: null, right: 400, top: 50, bottom: 200 468 }); 469 console.info(msg + `test error`); 470 expect().assertFail() 471 } catch (e) { 472 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 473 expect(e.code).assertEqual(401); 474 } 475 476 try { 477 canvas.drawOval({ 478 left: 100, right: null, top: 50, bottom: 200 479 }); 480 console.info(msg + `test error`); 481 expect().assertFail() 482 } catch (e) { 483 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 484 expect(e.code).assertEqual(401); 485 } 486 487 try { 488 canvas.drawOval({ 489 left: 100, right: 400, top: null, bottom: 200 490 }); 491 console.info(msg + `test error`); 492 expect().assertFail() 493 } catch (e) { 494 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 495 expect(e.code).assertEqual(401); 496 } 497 498 try { 499 canvas.drawOval({ 500 left: 100, right: 400, top: 50, bottom: null 501 }); 502 console.info(msg + `test error`); 503 expect().assertFail() 504 } catch (e) { 505 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 506 expect(e.code).assertEqual(401); 507 } 508 509 try { 510 canvas.drawOval({ 511 left: undefined, right: 400, top: 50, bottom: 200 512 }); 513 console.info(msg + `test error`); 514 expect().assertFail() 515 } catch (e) { 516 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 517 expect(e.code).assertEqual(401); 518 } 519 520 try { 521 canvas.drawOval({ 522 left: 100, right: undefined, top: 50, bottom: 200 523 }); 524 console.info(msg + `test error`); 525 expect().assertFail() 526 } catch (e) { 527 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 528 expect(e.code).assertEqual(401); 529 } 530 531 try { 532 canvas.drawOval({ 533 left: 100, right: 400, top: undefined, bottom: 200 534 }); 535 console.info(msg + `test error`); 536 expect().assertFail() 537 } catch (e) { 538 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 539 expect(e.code).assertEqual(401); 540 } 541 542 try { 543 canvas.drawOval({ 544 left: 100, right: 400, top: 50, bottom: undefined 545 }); 546 console.info(msg + `test error`); 547 expect().assertFail() 548 } catch (e) { 549 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 550 expect(e.code).assertEqual(401); 551 } 552 553 }) 554 555 556 /** 557 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2900 558 * @tc.name : testCanvasDrawArcNormal 559 * @tc.desc : testCanvasDrawArcNormal 560 * @tc.size : SmallTest 561 * @tc.type : Function 562 * @tc.level : Level0 563 */ 564 it('testCanvasDrawArcNormal', DEFAULT, () => { 565 const msg = 'testCanvasDrawArcNormal'; 566 const canvas = new drawing.Canvas(pixel); 567 const maxVal = Number.MAX_VALUE; 568 try { 569 canvas.drawArc({ 570 left: 100, right: 400, top: 50, bottom: 200 571 }, 90, 180); 572 canvas.drawArc({ 573 left: 100.1, right: 400.1, top: 50.1, bottom: 200.1 574 }, 450, 450); 575 canvas.drawArc({ 576 left: -100, right: 400, top: -50, bottom: 200 577 }, -90, -90); 578 canvas.drawArc({ 579 left: 100, right: -400, top: 50, bottom: -200 580 }, 90, 180); 581 canvas.drawArc({ 582 left: 100, right: 100, top: 100, bottom: 200 583 }, -90, 180); 584 canvas.drawArc({ 585 left: 100, right: 100, top: 100, bottom: 100 586 }, 90, -180); 587 canvas.drawArc({ 588 left: maxVal, right: maxVal, top: maxVal, bottom: maxVal 589 }, 90, 180); 590 console.info(msg + 'test successes'); 591 } catch (e) { 592 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 593 expect().assertFail(); 594 } 595 }) 596 597 598 /** 599 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2901 600 * @tc.name : testCanvasDrawArcMultipleCalls 601 * @tc.desc : testCanvasDrawArcMultipleCalls 602 * @tc.size : SmallTest 603 * @tc.type : Function 604 * @tc.level : Level3 605 */ 606 it('testCanvasDrawArcMultipleCalls', 3, () => { 607 const msg = 'testCanvasDrawArcMultipleCalls'; 608 const canvas = new drawing.Canvas(pixel); 609 try { 610 for (let i = 0; i < 20; i += 1) { 611 canvas.drawArc({ 612 left: Math.random(), right: Math.random(), top: Math.random(), bottom: Math.random() 613 }, 90, 180); 614 } 615 console.info(msg + 'test successes'); 616 } catch (e) { 617 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 618 expect().assertFail(); 619 } 620 }) 621 622 623 /** 624 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_2902 625 * @tc.name : testCanvasDrawArcToNull 626 * @tc.desc : testCanvasDrawArcToNull 627 * @tc.size : SmallTest 628 * @tc.type : Function 629 * @tc.level : Level3 630 */ 631 it('testCanvasDrawArcToNull', 3, () => { 632 const msg = 'testCanvasDrawArcToNull'; 633 const canvas = new drawing.Canvas(pixel); 634 635 try { 636 canvas.drawArc(null, 90, 180); 637 console.info(msg + `test error`); 638 expect().assertFail() 639 } catch (e) { 640 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 641 expect(e.code).assertEqual(401); 642 } 643 644 try { 645 canvas.drawArc(undefined, 90, 180); 646 console.info(msg + `test error`); 647 expect().assertFail() 648 } catch (e) { 649 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 650 expect(e.code).assertEqual(401); 651 } 652 653 try { 654 canvas.drawArc({ 655 left: null, right: 400, top: 50, bottom: 200 656 }, 90, 180); 657 console.info(msg + `test error`); 658 expect().assertFail() 659 } catch (e) { 660 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 661 expect(e.code).assertEqual(401); 662 } 663 664 try { 665 canvas.drawArc({ 666 left: 100, right: null, top: 50, bottom: 200 667 }, 90, 180); 668 console.info(msg + `test error`); 669 expect().assertFail() 670 } catch (e) { 671 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 672 expect(e.code).assertEqual(401); 673 } 674 675 try { 676 canvas.drawArc({ 677 left: 100, right: 400, top: null, bottom: 200 678 }, 90, 180); 679 console.info(msg + `test error`); 680 expect().assertFail() 681 } catch (e) { 682 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 683 expect(e.code).assertEqual(401); 684 } 685 686 try { 687 canvas.drawArc({ 688 left: 100, right: 400, top: 50, bottom: null 689 }, 90, 180); 690 console.info(msg + `test error`); 691 expect().assertFail() 692 } catch (e) { 693 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 694 expect(e.code).assertEqual(401); 695 } 696 697 try { 698 canvas.drawArc({ 699 left: undefined, right: 400, top: 50, bottom: 200 700 }, 90, 180); 701 console.info(msg + `test error`); 702 expect().assertFail() 703 } catch (e) { 704 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 705 expect(e.code).assertEqual(401); 706 } 707 708 try { 709 canvas.drawArc({ 710 left: 100, right: undefined, top: 50, bottom: 200 711 }, 90, 180); 712 console.info(msg + `test error`); 713 expect().assertFail() 714 } catch (e) { 715 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 716 expect(e.code).assertEqual(401); 717 } 718 719 try { 720 canvas.drawArc({ 721 left: 100, right: 400, top: undefined, bottom: 200 722 }, 90, 180); 723 console.info(msg + `test error`); 724 expect().assertFail() 725 } catch (e) { 726 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 727 expect(e.code).assertEqual(401); 728 } 729 730 try { 731 canvas.drawArc({ 732 left: 100, right: 400, top: 50, bottom: undefined 733 }, 90, 180); 734 console.info(msg + `test error`); 735 expect().assertFail() 736 } catch (e) { 737 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 738 expect(e.code).assertEqual(401); 739 } 740 741 try { 742 canvas.drawArc({ 743 left: 100, right: 400, top: 50, bottom: 200 744 }, null, 180); 745 console.info(msg + `test error`); 746 expect().assertFail() 747 } catch (e) { 748 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 749 expect(e.code).assertEqual(401); 750 } 751 752 try { 753 canvas.drawArc({ 754 left: 100, right: 400, top: 50, bottom: 200 755 }, 90, null); 756 console.info(msg + `test error`); 757 expect().assertFail() 758 } catch (e) { 759 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 760 expect(e.code).assertEqual(401); 761 } 762 763 try { 764 canvas.drawArc({ 765 left: 100, right: 400, top: 50, bottom: 200 766 }, undefined, 180); 767 console.info(msg + `test error`); 768 expect().assertFail() 769 } catch (e) { 770 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 771 expect(e.code).assertEqual(401); 772 } 773 774 try { 775 canvas.drawArc({ 776 left: 100, right: 400, top: 50, bottom: 200 777 }, 90, undefined); 778 console.info(msg + `test error`); 779 expect().assertFail() 780 } catch (e) { 781 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 782 expect(e.code).assertEqual(401); 783 } 784 785 }) 786 787 788 /** 789 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_3000 790 * @tc.name : testCanvasDrawPointsNormal 791 * @tc.desc : testCanvasDrawPointsNormal 792 * @tc.size : SmallTest 793 * @tc.type : Function 794 * @tc.level : Level0 795 */ 796 it('testCanvasDrawPointsNormal', DEFAULT, () => { 797 const msg = 'testCanvasDrawPointsNormal'; 798 const canvas = new drawing.Canvas(pixel); 799 try { 800 canvas.drawPoints([{ 801 x: 100, y: 200 802 }, { 803 x: 150, y: 230 804 }, { 805 x: 200, y: 300 806 }], drawing.PointMode.POINTS); 807 canvas.drawPoints([{ 808 x: 100, y: 200 809 }, { 810 x: 150.1, y: 230.1 811 }, { 812 x: 200, y: 300 813 }], drawing.PointMode.LINES); 814 canvas.drawPoints([{ 815 x: 100, y: 200 816 }, { 817 x: 150, y: 230 818 }, { 819 x: 200, y: 300 820 }], drawing.PointMode.POLYGON); 821 canvas.drawPoints([{ 822 x: 100, y: 200 823 }, { 824 x: -150, y: 230 825 }, { 826 x: 200, y: -300 827 }]); 828 console.info(msg + 'test successes'); 829 } catch (e) { 830 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 831 expect().assertFail(); 832 } 833 }) 834 835 836 /** 837 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_3001 838 * @tc.name : testCanvasDrawPointsMultipleCalls 839 * @tc.desc : testCanvasDrawPointsMultipleCalls 840 * @tc.size : SmallTest 841 * @tc.type : Function 842 * @tc.level : Level3 843 */ 844 it('testCanvasDrawPointsMultipleCalls', 3, () => { 845 const msg = 'testCanvasDrawPointsMultipleCalls'; 846 const canvas = new drawing.Canvas(pixel); 847 try { 848 for (let i = 0; i < 20; i += 1) { 849 const randomEnum = Math.floor(getEnumCount(drawing.PointMode) * Math.random()) 850 canvas.drawPoints([{ 851 x: Math.random(), y: Math.random() 852 }, { 853 x: Math.random(), y: Math.random() 854 }, { 855 x: Math.random(), y: Math.random() 856 }], randomEnum); 857 } 858 console.info(msg + 'test successes'); 859 } catch (e) { 860 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 861 expect().assertFail(); 862 } 863 }) 864 865 866 /** 867 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_3002 868 * @tc.name : testCanvasDrawPointsToNull 869 * @tc.desc : testCanvasDrawPointsToNull 870 * @tc.size : SmallTest 871 * @tc.type : Function 872 * @tc.level : Level3 873 */ 874 it('testCanvasDrawPointsToNull', 3, () => { 875 const msg = 'testCanvasDrawPointsToNull'; 876 const canvas = new drawing.Canvas(pixel); 877 878 try { 879 canvas.drawPoints(null, drawing.PointMode.POINTS); 880 console.info(msg + `test error`); 881 expect().assertFail() 882 } catch (e) { 883 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 884 expect(e.code).assertEqual(401); 885 } 886 887 try { 888 canvas.drawPoints([{ 889 x: 100, y: 200 890 }, { 891 x: 150, y: 230 892 }, { 893 x: 200, y: 300 894 }], null); 895 console.info(msg + `test error`); 896 expect().assertFail() 897 } catch (e) { 898 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 899 expect(e.code).assertEqual(401); 900 } 901 902 try { 903 canvas.drawPoints(undefined, drawing.PointMode.POINTS); 904 console.info(msg + `test error`); 905 expect().assertFail() 906 } catch (e) { 907 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 908 expect(e.code).assertEqual(401); 909 } 910 911 try { 912 canvas.drawPoints([{ 913 x: 100, y: 200 914 }, { 915 x: 150, y: 230 916 }, { 917 x: 200, y: 300 918 }], undefined); 919 console.info(msg + `test error`); 920 expect().assertFail() 921 } catch (e) { 922 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 923 expect(e.code).assertEqual(401); 924 } 925 926 }) 927 928 /** 929 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_3004 930 * @tc.name : testCanvasDrawPointsAbnormal 931 * @tc.desc : testCanvasDrawPointsAbnormal 932 * @tc.size : SmallTest 933 * @tc.type : Function 934 * @tc.level : Level3 935 */ 936 it('testCanvasDrawPointsAbnormal', 3, () => { 937 const msg = 'testCanvasDrawPointsAbnormal'; 938 const canvas = new drawing.Canvas(pixel); 939 940 try { 941 canvas.drawPoints([{ 942 x: 100, y: 200 943 }, { 944 x: 150, y: 230 945 }, { 946 x: 200, y: 300 947 }], 10); 948 console.info(msg + `test error`); 949 expect().assertFail() 950 } catch (e) { 951 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 952 expect(e.code).assertEqual(401); 953 } 954 try { 955 canvas.drawPoints([]); 956 console.info(msg + `test error`); 957 expect().assertFail() 958 } catch (e) { 959 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 960 expect(e.code).assertEqual(401); 961 } 962 }) 963 964 965 /** 966 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_3100 967 * @tc.name : testCanvasConcatMatrixNormal 968 * @tc.desc : testCanvasConcatMatrixNormal 969 * @tc.size : SmallTest 970 * @tc.type : Function 971 * @tc.level : Level0 972 */ 973 it('testCanvasConcatMatrixNormal', DEFAULT, () => { 974 const msg = 'testCanvasConcatMatrixNormal'; 975 const canvas = new drawing.Canvas(pixel); 976 try { 977 let matrix = new drawing.Matrix(); 978 canvas.concatMatrix(matrix); 979 matrix.setMatrix([5, 0, 0, 0, 1, 2, 0, 0, 1]); 980 canvas.concatMatrix(matrix); 981 console.info(msg + 'test successes'); 982 } catch (e) { 983 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 984 expect().assertFail(); 985 } 986 }) 987 988 989 /** 990 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_3101 991 * @tc.name : testCanvasConcatMatrixMultipleCalls 992 * @tc.desc : testCanvasConcatMatrixMultipleCalls 993 * @tc.size : SmallTest 994 * @tc.type : Function 995 * @tc.level : Level3 996 */ 997 it('testCanvasConcatMatrixMultipleCalls', 3, () => { 998 const msg = 'testCanvasConcatMatrixMultipleCalls'; 999 const canvas = new drawing.Canvas(pixel); 1000 try { 1001 for (let i = 0; i < 20; i += 1) { 1002 let matrix = new drawing.Matrix(); 1003 canvas.concatMatrix(matrix); 1004 } 1005 console.info(msg + 'test successes'); 1006 } catch (e) { 1007 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 1008 expect().assertFail(); 1009 } 1010 }) 1011 1012 1013 /** 1014 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_3102 1015 * @tc.name : testCanvasConcatMatrixToNull 1016 * @tc.desc : testCanvasConcatMatrixToNull 1017 * @tc.size : SmallTest 1018 * @tc.type : Function 1019 * @tc.level : Level3 1020 */ 1021 it('testCanvasConcatMatrixToNull', 3, () => { 1022 const msg = 'testCanvasConcatMatrixToNull'; 1023 const canvas = new drawing.Canvas(pixel); 1024 1025 try { 1026 canvas.concatMatrix(null); 1027 console.info(msg + `test error`); 1028 expect().assertFail() 1029 } catch (e) { 1030 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 1031 expect(e.code).assertEqual(401); 1032 } 1033 1034 try { 1035 canvas.concatMatrix(undefined); 1036 console.info(msg + `test error`); 1037 expect().assertFail() 1038 } catch (e) { 1039 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 1040 expect(e.code).assertEqual(401); 1041 } 1042 }) 1043 1044 1045 /** 1046 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_3200 1047 * @tc.name : testCanvasSetMatrixNormal 1048 * @tc.desc : testCanvasSetMatrixNormal 1049 * @tc.size : SmallTest 1050 * @tc.type : Function 1051 * @tc.level : Level0 1052 */ 1053 it('testCanvasSetMatrixNormal', DEFAULT, () => { 1054 const msg = 'testCanvasSetMatrixNormal'; 1055 const canvas = new drawing.Canvas(pixel); 1056 try { 1057 let matrix = new drawing.Matrix(); 1058 canvas.setMatrix(matrix); 1059 matrix.setMatrix([5.1, 1.1, 1.1, 1.1, 1.1, 1.1, 5.1, 0.3, 1.7]); 1060 canvas.setMatrix(matrix); 1061 console.info(msg + 'test successes'); 1062 } catch (e) { 1063 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 1064 expect().assertFail(); 1065 } 1066 }) 1067 1068 1069 /** 1070 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_3201 1071 * @tc.name : testCanvasSetMatrixMultipleCalls 1072 * @tc.desc : testCanvasSetMatrixMultipleCalls 1073 * @tc.size : SmallTest 1074 * @tc.type : Function 1075 * @tc.level : Level3 1076 */ 1077 it('testCanvasSetMatrixMultipleCalls', 3, () => { 1078 const msg = 'testCanvasSetMatrixMultipleCalls'; 1079 const canvas = new drawing.Canvas(pixel); 1080 try { 1081 for (let i = 0; i < 20; i += 1) { 1082 const matrix = new drawing.Matrix() 1083 canvas.setMatrix(matrix) 1084 } 1085 console.info(msg + 'test successes'); 1086 } catch (e) { 1087 console.info(msg + `test errorCode is: ${e.code} + errormsg is: ${e.message}`); 1088 expect().assertFail(); 1089 } 1090 }) 1091 1092 1093 /** 1094 * @tc.number : SUB_BASIC_GRAPHICS_SPECIAL_API_TS_DRAWING_CANVAS_3202 1095 * @tc.name : testCanvasSetMatrixToNull 1096 * @tc.desc : testCanvasSetMatrixToNull 1097 * @tc.size : SmallTest 1098 * @tc.type : Function 1099 * @tc.level : Level3 1100 */ 1101 it('testCanvasSetMatrixToNull', 3, () => { 1102 const msg = 'testCanvasSetMatrixToNull'; 1103 const canvas = new drawing.Canvas(pixel); 1104 1105 try { 1106 canvas.setMatrix(null); 1107 console.info(msg + `test error`); 1108 expect().assertFail() 1109 } catch (e) { 1110 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 1111 expect(e.code).assertEqual(401); 1112 } 1113 1114 try { 1115 canvas.setMatrix(undefined); 1116 console.info(msg + `test error`); 1117 expect().assertFail() 1118 } catch (e) { 1119 console.info(msg + `test successes. errorCode is: ${e.code} + errormsg is: ${e.message}}`); 1120 expect(e.code).assertEqual(401); 1121 } 1122 }) 1123 1124 1125 }) 1126}