diff --git a/arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp b/arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp index bff825c1dcb2cd3d07d4ba3a41a22f9170ce9baa..ffe33370d36b7a9c5a99878b7a705d1cebff35f9 100644 --- a/arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp +++ b/arkui/ace_napi_test/entry/src/main/cpp/napi/napi_test.cpp @@ -1598,6 +1598,50 @@ static napi_value napiFatalerror(napi_env env, napi_callback_info info) return _value; } +static napi_value napiGetTypedarrayInfo(napi_env env, napi_callback_info info) +{ + napi_value arrayBuffer = nullptr; + void* arrayBufferPr = nullptr; + size_t arrayBufferSize = 200; + // create a JavaScript ArrayBuffer + napi_create_arraybuffer(env, arrayBufferSize, &arrayBufferPr, &arrayBuffer); + + // convert from N-API to C types + void* tmpArrayBufferPr = nullptr; + size_t arrayBufferLength = 0; + napi_get_arraybuffer_info(env, arrayBuffer, &tmpArrayBufferPr, &arrayBufferLength); + + NAPI_ASSERT(env, arrayBufferPr == tmpArrayBufferPr, "creat and get ArrayBuffer success"); + NAPI_ASSERT(env, arrayBufferSize == arrayBufferLength, "creat and get ArrayBuffer size success"); + + napi_value typedarray = nullptr; + // create a JavaScript TypedArray + napi_status status = napi_create_typedarray(env, napi_int8_array, arrayBufferSize, arrayBuffer, 0, &typedarray); + NAPI_ASSERT(env, status == napi_ok, "napi_create_typedarray success"); + + bool isTypedArray = false; + // Whether the given napi_value represents a TypedArray + napi_is_typedarray(env, typedarray, &isTypedArray); + NAPI_ASSERT(env, isTypedArray, "the type is TypeArray"); + + // convert from N-API to C types + napi_typedarray_type typedarrayType; + size_t typedarrayLength = 0; + void* typedarrayBufferPtr = nullptr; + napi_value tmpArrayBuffer = nullptr; + size_t byteOffset = 0; + // returns various properties of a typed array + napi_get_typedarray_info(env, typedarray, &typedarrayType, &typedarrayLength, &typedarrayBufferPtr, &tmpArrayBuffer, &byteOffset); + NAPI_ASSERT(env, typedarrayBufferPtr == arrayBufferPr, "napi_get_typedarray_info success"); + NAPI_ASSERT(env, arrayBufferSize == typedarrayLength, "napi_get_typedarray_info size success"); + + // return the value of success + napi_value _value; + NAPI_CALL(env, napi_create_int32(env, 0, &_value)); + + return _value; +} + EXTERN_C_START static napi_value Init(napi_env env, napi_value exports) @@ -1687,6 +1731,7 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("napiCreateBigintUint64", napiCreateBigintUint64), DECLARE_NAPI_FUNCTION("napiCreateBigintInt64", napiCreateBigintInt64), DECLARE_NAPI_FUNCTION("napiCreateBigintWords", napiCreateBigintWords), + DECLARE_NAPI_FUNCTION("napiGetTypedarrayInfo", napiGetTypedarrayInfo), { "napiCancelAsyncWork", nullptr, napiCancelAsyncWork, nullptr, nullptr, nullptr, napi_default, nullptr }, { "napiCreateFunction", nullptr, napiCreateFunction, nullptr, nullptr, nullptr, napi_default, nullptr }, DECLARE_NAPI_FUNCTION("napiFatalerror", napiFatalerror), }; diff --git a/arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets b/arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets index 9cba9a692937f6f0d4298a674c469b29e11cff14..85060b7ae947e10b13e4a630f7f9fad9a3b8f495 100644 --- a/arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets +++ b/arkui/ace_napi_test/entry/src/main/ets/test/NativeApiStringTest.ets @@ -252,6 +252,19 @@ export default function nativeApiStringJsunit() { expect(value).assertEqual(0) done(); }); + + /** + * @tc.number SUB_ACE_BASIC_ETS_NAPI_0018 + * @tc.name napiGetTypedarrayInfo + * @tc.desc aceNapiEtsTest + */ + it('napiGetTypedarrayInfo018', 0, async function (done) { + console.info('napiFatalerror START'); + value = napitest.napiGetTypedarrayInfo(); + console.info('napiGetTypedarrayInfo testString result is: ' + JSON.stringify(value)); + expect(value).assertEqual(0) + done(); + }); }) }