From e299dee48d9da5f202df1abf5e52d53c21f7f2f4 Mon Sep 17 00:00:00 2001 From: caochuan Date: Mon, 3 Jul 2023 17:18:17 +0800 Subject: [PATCH] add receiver release test Signed-off-by: caochuan Change-Id: I18d8a1f3ba0b5d6eb2ffc0ab705cb2c13967f6ff --- .../main/cpp/napi/image_receiver_mdk_test.cpp | 34 ++++++++++ .../main/cpp/napi/image_receiver_mdk_test.h | 2 + .../src/main/ets/test/receiverNDK.test.ets | 65 +++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/cpp/napi/image_receiver_mdk_test.cpp b/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/cpp/napi/image_receiver_mdk_test.cpp index e916f3684..be24fc826 100644 --- a/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/cpp/napi/image_receiver_mdk_test.cpp +++ b/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/cpp/napi/image_receiver_mdk_test.cpp @@ -51,6 +51,8 @@ napi_value ImageReceiverNDKTest::Init(napi_env env, napi_value exports) STATIC_FUNCTION("imageSize", JsImageSize), STATIC_FUNCTION("imageFormat", JsImageFormat), STATIC_FUNCTION("imageGetComponent", JsImageGetComponent), + STATIC_FUNCTION("receiverRelease", JsReceiverRelease), + STATIC_FUNCTION("imageRelease", JsImageRelease), }; napi_define_properties(env, exports, sizeof(props) / sizeof(props[0]), props); return exports; @@ -183,6 +185,22 @@ napi_value ImageReceiverNDKTest::JsOn(napi_env env, napi_callback_info info) return result; } +napi_value ImageReceiverNDKTest::JsReceiverRelease(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + napi_get_undefined(env, &result); + + ImageReceiverNative *native = getNativeReceiver(env, info); + if (native == nullptr) + { + return result; + } + + int32_t res = OH_Image_Receiver_Release(native); + napi_create_int32(env, res, &result); + return result; +} + static void setInt32NamedProperty(napi_env env, napi_value object, const char* utf8name, int32_t value) { napi_value tmp; @@ -276,6 +294,22 @@ static ImageNative* getNativeImage(napi_env env, napi_callback_info info) return OH_Image_InitImageNative(env, argValue[NUM_0]); } +napi_value ImageReceiverNDKTest::JsImageRelease(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + napi_get_undefined(env, &result); + + ImageNative *native = getNativeImage(env, info); + if (native == nullptr) + { + return result; + } + + int32_t res = OH_Image_Release(native); + napi_create_int32(env, res, &result); + return result; +} + napi_value ImageReceiverNDKTest::JsImageClipRect(napi_env env, napi_callback_info info) { napi_value result = nullptr; diff --git a/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/cpp/napi/image_receiver_mdk_test.h b/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/cpp/napi/image_receiver_mdk_test.h index 1957bb783..186561e20 100644 --- a/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/cpp/napi/image_receiver_mdk_test.h +++ b/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/cpp/napi/image_receiver_mdk_test.h @@ -41,6 +41,8 @@ public: static napi_value JsImageSize(napi_env env, napi_callback_info info); static napi_value JsImageFormat(napi_env env, napi_callback_info info); static napi_value JsImageGetComponent(napi_env env, napi_callback_info info); + static napi_value JsReceiverRelease(napi_env env, napi_callback_info info); + static napi_value JsImageRelease(napi_env env, napi_callback_info info); private: static uint32_t sOnEvnentCount; diff --git a/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/ets/test/receiverNDK.test.ets b/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/ets/test/receiverNDK.test.ets index 38d4ee737..62e480a9f 100644 --- a/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/ets/test/receiverNDK.test.ets +++ b/multimedia/image/image_js_standard/imageReceiverNDK/entry/src/main/ets/test/receiverNDK.test.ets @@ -365,5 +365,70 @@ export default function ImageReceiverNDKTest() { done(); } }) + + /** + * @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_0900 + * @tc.name : img.release + * @tc.desc : 1.createImageReceiver + * : 2.readLatestImage + * : 3.release + * @tc.size : MEDIUM + * @tc.type : Functional + * @tc.level : Level 0 + */ + it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_0900', 0, async function (done) { + let mlg = logger("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0900"); + try { + mlg.log("SUB_GRAPHIC_IMAGE_RECEIVERNDK_0900"); + let myReceiver = ndkTest.createImageReceiver(WIDTH, HEIGHT, RECEIVER_FORMAT, CAPACITY); + let onRet = ndkTest.on(myReceiver); + mlg.log("onRet " + JSON.stringify(onRet)); + expect(onRet != undefined).assertTrue(); + var dummy = myReceiver.test; + mlg.log("dummy test !!! ") + let myLatestImage = ndkTest.readLatestImage(myReceiver); + let myImageComponent = ndkTest.imageGetComponent(myLatestImage, JPEG); + var bufferArr = new Uint8Array(myImageComponent.byteBuffer); + mlg.log("myImageComponent.byteBuffer size " + JSON.stringify(bufferArr.length)); + for (var i = 0; i < 30; i++) { + mlg.log("myImageComponent.byteBuffer data " + JSON.stringify(bufferArr[i])); + } + expect(myImageComponent.byteBuffer != undefined).assertTrue(); + let releaseRes = ndkTest.imageRelease(myLatestImage); + mlg.log('release result ' + JSON.stringify(releaseRes)); + expect(releaseRes != undefined).assertTrue(); + done(); + } catch (error) { + mlg.log("Test exception " + error); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.number : SUB_GRAPHIC_IMAGE_RECEIVERNDK_1000 + * @tc.name : receiver.release + * @tc.desc : 1.createImageReceiver + * : 2.release + * @tc.size : MEDIUM + * @tc.type : Functional + * @tc.level : Level 0 + */ + it('SUB_GRAPHIC_IMAGE_RECEIVERNDK_1000', 0, async function (done) { + let mlg = logger("SUB_GRAPHIC_IMAGE_RECEIVERNDK_1000"); + try { + mlg.log("SUB_GRAPHIC_IMAGE_RECEIVERNDK_1000"); + let myReceiver = ndkTest.createImageReceiver(WIDTH, HEIGHT, RECEIVER_FORMAT, CAPACITY); + + let releaseRes = ndkTest.receiverRelease(myReceiver); + mlg.log('release result ' + JSON.stringify(releaseRes)); + expect(releaseRes != undefined).assertTrue(); + done(); + } catch (error) { + mlg.log("Test exception " + error); + expect().assertFail(); + done(); + } + }) }) } -- GitLab