From 0b4969d6ba24774236f79818168f29e60a636056 Mon Sep 17 00:00:00 2001 From: renhw Date: Thu, 25 Aug 2022 18:53:27 +0800 Subject: [PATCH] fix receiver crash Signed-off-by: renhw --- .../src/main/js/test/receiver.test.js | 259 +++++------------- 1 file changed, 73 insertions(+), 186 deletions(-) diff --git a/multimedia/image/image_js_standard/imageReceiver/src/main/js/test/receiver.test.js b/multimedia/image/image_js_standard/imageReceiver/src/main/js/test/receiver.test.js index ab12cefff..3d646e493 100644 --- a/multimedia/image/image_js_standard/imageReceiver/src/main/js/test/receiver.test.js +++ b/multimedia/image/image_js_standard/imageReceiver/src/main/js/test/receiver.test.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 Huawei Device Co., Ltd. + * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -28,8 +28,6 @@ describe('ImageReceiver', function () { const CAPACITY = 8; const YCBCR_422_SP = 1000; const FORMATJPEG = 2000; - let globalreceiver; - let globalimg; beforeAll(async function () { console.info('beforeAll case'); @@ -40,22 +38,6 @@ describe('ImageReceiver', function () { }) afterEach(async function () { - if (globalreceiver != undefined) { - console.info('globalreceiver release start'); - try { - await globalreceiver.release(); - } catch (error) { - console.info('globalreceiver release fail'); - } - } - if (globalimg != undefined) { - try { - console.info('globalimg release start'); - await globalimg.release(); - } catch (error) { - console.info('globalimg release fail'); - } - } console.info('afterEach case'); }) @@ -74,47 +56,44 @@ describe('ImageReceiver', function () { done(); } catch (error) { expect(error.code == 1).assertTrue(); - console.info(`${testNum} err message: ` + error); + console.info(`${testNum} err message` + error); done(); } } async function getComponentProErr(done, testNum, param) { var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; let once = false; if (receiver == undefined) { expect(false).assertTrue(); done(); } else { receiver.on('imageArrival', () => { - if (once) { - return; - } - once = true; - receiver.readLatestImage(async (err, img) => { - globalimg = img; - if (img == undefined) { + if (once) { + return; + } + once = true; + receiver.readLatestImage(async (err, img) => { + if (img == undefined) { + expect(false).assertTrue(); + done(); + } else { + expect(img.size.width == WIDTH).assertTrue(); + expect(img.size.height == HEIGHT).assertTrue(); + expect(img.format == 12).assertTrue(); + expect(img.clipRect.size.width == WIDTH).assertTrue(); + expect(img.clipRect.size.height == HEIGHT).assertTrue(); + expect(img.clipRect.x == 0).assertTrue(); + expect(img.clipRect.y == 0).assertTrue(); + try { + await img.getComponent(param); expect(false).assertTrue(); + } catch (error) { + expect(error.code == 1).assertTrue(); + console.log(`${testNum} error msg: ` + error); done(); - } else { - expect(img.size.width == WIDTH).assertTrue(); - expect(img.size.height == HEIGHT).assertTrue(); - expect(img.format == 12).assertTrue(); - expect(img.clipRect.size.width == WIDTH).assertTrue(); - expect(img.clipRect.size.height == HEIGHT).assertTrue(); - expect(img.clipRect.x == 0).assertTrue(); - expect(img.clipRect.y == 0).assertTrue(); - try { - await img.getComponent(param); - expect(false).assertTrue(); - done(); - } catch (error) { - expect(error.code == 1).assertTrue(); - console.log(`${testNum} error msg: ` + error); - done(); - } } + } }) expect(true).assertTrue(); }) @@ -124,7 +103,6 @@ describe('ImageReceiver', function () { async function getComponentCbErr(done, testNum, param) { var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; let once = false; if (receiver == undefined) { expect(false).assertTrue(); @@ -136,7 +114,6 @@ describe('ImageReceiver', function () { } once = true; receiver.readLatestImage(async (err, img) => { - globalimg = img; if (img == undefined) { expect(false).assertTrue(); done(); @@ -151,7 +128,6 @@ describe('ImageReceiver', function () { try { img.getComponent(param, (err, component) => { expect(false).assertTrue(); - done(); }) } catch (error) { expect(error.code == 1).assertTrue(); @@ -166,9 +142,8 @@ describe('ImageReceiver', function () { } } - async function getComponentPromise(done, testNum, param, checkFormat, checkStride) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, YCBCR_422_SP, CAPACITY); - globalreceiver = receiver; + async function getComponentP(done, testNum, param) { + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); let once = false; if (receiver == undefined) { expect(false).assertTrue(); @@ -181,19 +156,18 @@ describe('ImageReceiver', function () { } once = true; receiver.readLatestImage((err, img) => { - globalimg = img; if (err) { expect(false).assertTrue(); done(); } else { expect(img.size.width == WIDTH).assertTrue(); expect(img.size.height == HEIGHT).assertTrue(); - checkFormat(img.format); + expect(img.format == 12).assertTrue(); expect(img.clipRect.size.width == WIDTH).assertTrue(); expect(img.clipRect.size.height == HEIGHT).assertTrue(); expect(img.clipRect.x == 0).assertTrue(); expect(img.clipRect.y == 0).assertTrue(); - console.info(`${testNum} ${param} img.format: ${img.format}`); + img.getComponent(param).then(component => { if (component == undefined) { expect(false).assertTrue(); @@ -201,7 +175,8 @@ describe('ImageReceiver', function () { } else { expect(component.componentType == param).assertTrue(); expect(component.byteBuffer != undefined).assertTrue(); - checkStride(component.rowStride, component.pixelStride); + expect(component.rowStride == 0).assertTrue(); + expect(component.pixelStride == 0).assertTrue(); done(); } }).catch(error => { @@ -213,16 +188,11 @@ describe('ImageReceiver', function () { }) expect(true).assertTrue(); }) - if (param == JPEG) { - var dummy = receiver.test - } else { - var dummy = receiver.testYUV; - } + var dummy = receiver.test; } - async function getComponentCb(done, testNum, param, checkFormat, checkStride) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, YCBCR_422_SP, CAPACITY); - globalreceiver = receiver; + async function getComponentCb(done, testNum, param) { + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); let once = false; if (receiver == undefined) { expect(false).assertTrue(); @@ -236,29 +206,28 @@ describe('ImageReceiver', function () { } once = true; receiver.readLatestImage((err, img) => { - globalimg = img; if (err) { expect(false).assertTrue(); done(); } else { expect(img.size.width == WIDTH).assertTrue(); expect(img.size.height == HEIGHT).assertTrue(); - checkFormat(img.format); + expect(img.format == 12).assertTrue(); expect(img.clipRect.size.width == WIDTH).assertTrue(); expect(img.clipRect.size.height == HEIGHT).assertTrue(); expect(img.clipRect.x == 0).assertTrue(); expect(img.clipRect.y == 0).assertTrue(); - console.info(`${testNum} ${param} img.format: ${img.format}`); + img.getComponent(param, (err, component) => { if (err) { expect(false).assertTrue(); - console.log(`${testNum} geterror: ` + err); - done(); + console.log(`${testNum} geterror: ` + err) } else { expect(component != undefined).assertTrue(); expect(component.componentType == param).assertTrue(); expect(component.byteBuffer != undefined).assertTrue(); - checkStride(component.rowStride, component.pixelStride); + expect(component.rowStride == 0).assertTrue(); + expect(component.pixelStride == 0).assertTrue(); done(); } }) @@ -266,18 +235,11 @@ describe('ImageReceiver', function () { }) expect(true).assertTrue(); }) - if (param == JPEG) { - console.info(`${testNum} ${param} `) - var dummy = receiver.test - } else { - console.info(`${testNum} ${param} `) - var dummy = receiver.testYUV; - } + var dummy = receiver.test; } async function onErr(done, testNum, param) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) expect(receiver != undefined).assertTrue(); if (receiver == undefined) { expect(false).assertTrue(); @@ -312,8 +274,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_001', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) if (receiver == undefined) { expect(false).assertTrue(); console.info('receiver_001 undefined') @@ -464,8 +425,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_001-10', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMATJPEG, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMATJPEG, CAPACITY) if (receiver == undefined) { expect(false).assertTrue(); console.info('Receiver_001-10 undefined') @@ -490,8 +450,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_001-11', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, YCBCR_422_SP, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, YCBCR_422_SP, CAPACITY) if (receiver == undefined) { expect(false).assertTrue(); console.info('Receiver_001-11 undefined') @@ -516,8 +475,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_002', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) if (receiver != undefined) { receiver.getReceivingSurfaceId().then(id => { console.info('Receiver_002 getReceivingSurfaceId [' + id + "]"); @@ -545,8 +503,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_003', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) if (receiver != undefined) { receiver.getReceivingSurfaceId((err, id) => { console.info('Receiver_003 getReceivingSurfaceId call back [' + id + "]"); @@ -570,8 +527,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_004', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) if (receiver != undefined) { receiver.release().then(() => { console.info('Receiver_004 release '); @@ -598,14 +554,13 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_005', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) if (receiver != undefined) { receiver.release((err) => { if (err) { expect(false).assertTrue(); console.info('Receiver_005 release fail'); - done(); + done() } else { console.info('Receiver_005 release call back'); expect(true).assertTrue(); @@ -615,7 +570,7 @@ describe('ImageReceiver', function () { } else { expect(false).assertTrue(); console.info('Receiver_005 finished'); - done(); + done() } }) @@ -630,12 +585,10 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_006', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) var dummy = receiver.test; if (receiver != undefined) { receiver.readLatestImage().then(img => { - globalimg = img; console.info('Receiver_006 readLatestImage Success'); expect(img != undefined).assertTrue(); done(); @@ -647,7 +600,7 @@ describe('ImageReceiver', function () { } else { expect(false).assertTrue(); console.info('Receiver_006 finished'); - done(); + done() } }) @@ -662,12 +615,10 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_007', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) var dummy = receiver.test; if (receiver != undefined) { receiver.readLatestImage((err, img) => { - globalimg = img; console.info('Receiver_007 readLatestImage call back Success'); expect(img != undefined).assertTrue(); done(); @@ -690,13 +641,11 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_008', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) var dummy = receiver.test; expect(receiver != undefined).assertTrue(); if (receiver != undefined) { receiver.readNextImage().then(img => { - globalimg = img; console.info('Receiver_008 readNextImage Success'); expect(img != undefined).assertTrue(); done() @@ -723,15 +672,12 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_009', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) var dummy = receiver.test; if (receiver != undefined) { receiver.readNextImage((err, img) => { - globalimg = img; if (err) { expect(false).assertTrue(); - done(); } else { console.info('Receiver_009 readNextImage call back Success'); expect(img != undefined).assertTrue(); @@ -758,14 +704,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_010', 0, async function (done) { - function checkFormat(format) { - expect(format == 12).assertTrue(); - } - function checkStride(rowStride, pixelStride) { - expect(rowStride == 8192).assertTrue(); - expect(pixelStride == 1).assertTrue(); - } - getComponentPromise(done, 'Receiver_010', JPEG, checkFormat, checkStride) + getComponentP(done, 'Receiver_010', JPEG) }) /** @@ -780,14 +719,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_010_1', 0, async function (done) { - function checkFormat(format) { - expect(format == 22).assertTrue(); - } - function checkStride(rowStride, pixelStride) { - expect(rowStride == 4096).assertTrue(); - expect(pixelStride == 2).assertTrue(); - } - getComponentPromise(done, 'Receiver_010_1', YUV_U, checkFormat, checkStride) + getComponentP(done, 'Receiver_010_1', YUV_U) }) /** @@ -802,14 +734,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_010_2', 0, async function (done) { - function checkFormat(format) { - expect(format == 22).assertTrue(); - } - function checkStride(rowStride, pixelStride) { - expect(rowStride == 4096).assertTrue(); - expect(pixelStride == 2).assertTrue(); - } - getComponentPromise(done, 'Receiver_010_2', YUV_V, checkFormat, checkStride) + getComponentP(done, 'Receiver_010_2', YUV_V) }) /** @@ -824,14 +749,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_010_3', 0, async function (done) { - function checkFormat(format) { - expect(format == 22).assertTrue(); - } - function checkStride(rowStride, pixelStride) { - expect(rowStride == 8192).assertTrue(); - expect(pixelStride == 1).assertTrue(); - } - getComponentPromise(done, 'Receiver_010_3', YUV_Y, checkFormat, checkStride) + getComponentP(done, 'Receiver_010_3', YUV_Y) }) /** @@ -846,16 +764,9 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_010_4', 0, async function (done) { - function checkFormat(format) { - expect(format == 12).assertTrue(); - } - function checkStride(rowStride, pixelStride) { - expect(rowStride == 8192).assertTrue(); - expect(pixelStride == 1).assertTrue(); - } - getComponentCb(done, 'Receiver_010_4', JPEG, checkFormat, checkStride) + getComponentCb(done, 'Receiver_010_4', JPEG) }) - + /** * @tc.number : Receiver_010_5 * @tc.name : getComponent-YUV_Y @@ -868,16 +779,9 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_010_5', 0, async function (done) { - function checkFormat(format) { - expect(format == 22).assertTrue(); - } - function checkStride(rowStride, pixelStride) { - expect(rowStride == 8192).assertTrue(); - expect(pixelStride == 1).assertTrue(); - } - getComponentCb(done, 'Receiver_010_5', YUV_Y, checkFormat, checkStride) + getComponentCb(done, 'Receiver_010_5', YUV_Y) }) - + /** * @tc.number : Receiver_010_6 * @tc.name : getComponent-YUV_V @@ -890,16 +794,9 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_010_6', 0, async function (done) { - function checkFormat(format) { - expect(format == 22).assertTrue(); - } - function checkStride(rowStride, pixelStride) { - expect(rowStride == 4096).assertTrue(); - expect(pixelStride == 2).assertTrue(); - } - getComponentCb(done, 'Receiver_010_6', YUV_V, checkFormat, checkStride) + getComponentCb(done, 'Receiver_010_6', YUV_V) }) - + /** * @tc.number : Receiver_010_7 * @tc.name : getComponent-YUV_U @@ -912,16 +809,9 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_010_7', 0, async function (done) { - function checkFormat(format) { - expect(format == 22).assertTrue(); - } - function checkStride(rowStride, pixelStride) { - expect(rowStride == 4096).assertTrue(); - expect(pixelStride == 2).assertTrue(); - } - getComponentCb(done, 'Receiver_010_7', YUV_U, checkFormat, checkStride) + getComponentCb(done, 'Receiver_010_7', YUV_U) }) - + /** * @tc.number : Receiver_011 * @tc.name : on @@ -932,8 +822,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_011', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) if (receiver == undefined) { expect(false).assertTrue(); done(); @@ -951,7 +840,7 @@ describe('ImageReceiver', function () { }) var dummy = receiver.test - await sleep(2000); + await sleep(2000) expect(pass).assertTrue(); done(); } @@ -970,8 +859,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_012', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) if (receiver == undefined) { expect(false).assertTrue(); done(); @@ -999,9 +887,9 @@ describe('ImageReceiver', function () { img.release().then(() => { expect(true).assertTrue(); - done(); + done() }).catch(error => { - console.log('Receiver_012 err' + error); + console.log('Receiver_012 err' + error) expect(false).assertTrue(); done(); }) @@ -1026,8 +914,7 @@ describe('ImageReceiver', function () { * @tc.level : Level 0 */ it('Receiver_013', 0, async function (done) { - var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY); - globalreceiver = receiver; + var receiver = image.createImageReceiver(WIDTH, HEIGHT, FORMAT, CAPACITY) if (receiver == undefined) { expect(false).assertTrue(); done(); @@ -1043,7 +930,7 @@ describe('ImageReceiver', function () { receiver.readLatestImage((err, img) => { if (img == undefined) { expect(false).assertTrue(); - done(); + done() return; } -- GitLab