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 e916f36843598beb49e011a540acfee89aae2c9c..be24fc826cb5df2246e83f754d1be970c18d2e02 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 1957bb7834030b69d5c326392d7dcde089f4b91e..186561e20be01157d1c88e4416d89fb1af3c9aa7 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 38d4ee737c73eb298a4d9592fd79d58ca45375a2..62e480a9f7b83021273b6972866dadbd9b41d951 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(); + } + }) }) }