提交 20b7aa28 编写于 作者: L lee-wen-qiang
上级 e0ec19de
...@@ -666,6 +666,96 @@ static napi_value createAndGetStringUtf8(napi_env env, napi_callback_info info) ...@@ -666,6 +666,96 @@ static napi_value createAndGetStringUtf8(napi_env env, napi_callback_info info)
return output; return output;
} }
static napi_value CreateAndGetStringUtf16(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value args[1];
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments.");
napi_valuetype valuetype;
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype));
NAPI_ASSERT(env, valuetype == napi_string, "Expect a string.");
char16_t buffer[128]; // 128: char16_t type of element size
size_t buffer_size = 128; // 128: char16_t type of element size
size_t copied = 0;
NAPI_CALL(env, napi_get_value_string_utf16(env, args[0], buffer, buffer_size, &copied));
napi_value result;
NAPI_CALL(env, napi_create_string_utf16(env, buffer, copied, &result));
return result;
}
static napi_value StringUtf16OfCase(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value args[1];
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL));
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments.");
napi_valuetype valuetype;
NAPI_CALL(env, napi_typeof(env, args[0], &valuetype));
NAPI_ASSERT(env, valuetype == napi_string, "Expects a string.");
char16_t buffer[5]; // 5: char16_t type of element size
size_t buffer_size = 5; // 5: char16_t type of element size
size_t copied = 0;
NAPI_CALL(env,
napi_get_value_string_utf16(env, args[0], buffer, buffer_size, &copied));
napi_value result;
NAPI_CALL(env, napi_create_string_utf16(env, buffer, copied, &result));
return result;
}
static const napi_type_tag typeTags[5] = {
{0xdaf987b3cc62481a, 0xb745b0497f299531},
{0xbb7936c374084d9b, 0xa9548d0762eeedb9},
{0xa5ed9ce2e4c00c38, 0xa9548d0762eeedb1},
{0, 0},
{0xa5ed9ce2e4c00c38, 0xdaf987b3cc62481a},
};
static napi_value TypeTaggedInstance(napi_env env, napi_callback_info info) {
size_t argc = 1;
uint32_t typeIndex = 0;
napi_value instance = nullptr;
napi_value whichType = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &whichType, NULL, NULL));
NAPI_CALL(env, napi_get_value_uint32(env, whichType, &typeIndex));
NAPI_ASSERT(env, typeIndex <= 5, "typeIndex out of range");
NAPI_CALL(env, napi_create_object(env, &instance));
NAPI_CALL(env, napi_type_tag_object(env, instance, &typeTags[typeIndex]));
return instance;
}
static napi_value CheckTypeTag(napi_env env, napi_callback_info info) {
size_t argc = 2;
bool result;
napi_value argv[2];
napi_value jsResult = nullptr;
uint32_t typeIndex;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, NULL, NULL));
NAPI_CALL(env, napi_get_value_uint32(env, argv[0], &typeIndex));
NAPI_ASSERT(env, typeIndex <= 5, "typeIndex out of range");
NAPI_CALL(env, napi_check_object_type_tag(env, argv[1], &typeTags[typeIndex], &result));
NAPI_CALL(env, napi_get_boolean(env, result, &jsResult));
return jsResult;
}
static napi_value getPrototype(napi_env env, napi_callback_info info) static napi_value getPrototype(napi_env env, napi_callback_info info)
{ {
napi_value testWrapClass = nullptr; napi_value testWrapClass = nullptr;
...@@ -2192,6 +2282,10 @@ static napi_value Init(napi_env env, napi_value exports) ...@@ -2192,6 +2282,10 @@ static napi_value Init(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("napiCreateBigintInt64", napiCreateBigintInt64), DECLARE_NAPI_FUNCTION("napiCreateBigintInt64", napiCreateBigintInt64),
DECLARE_NAPI_FUNCTION("napiCreateBigintWords", napiCreateBigintWords), DECLARE_NAPI_FUNCTION("napiCreateBigintWords", napiCreateBigintWords),
DECLARE_NAPI_FUNCTION("napiGetCbInfo", napiGetCbInfo), DECLARE_NAPI_FUNCTION("napiGetCbInfo", napiGetCbInfo),
DECLARE_NAPI_FUNCTION("checkTypeTag", CheckTypeTag),
DECLARE_NAPI_FUNCTION("typeTaggedInstance", TypeTaggedInstance),
DECLARE_NAPI_FUNCTION("stringUtf16OfCase", StringUtf16OfCase),
DECLARE_NAPI_FUNCTION("createAndGetStringUtf16", CreateAndGetStringUtf16),
{ "napiCancelAsyncWork", nullptr, napiCancelAsyncWork, nullptr, nullptr, nullptr, napi_default, nullptr }, { "napiCancelAsyncWork", nullptr, napiCancelAsyncWork, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "testAsyncWork", nullptr, testAsyncWork, nullptr, nullptr, nullptr, napi_default, nullptr }, { "testAsyncWork", nullptr, testAsyncWork, nullptr, nullptr, nullptr, napi_default, nullptr },
{ "testPromise", nullptr, testPromise, nullptr, nullptr, nullptr, napi_default, nullptr }, { "testPromise", nullptr, testPromise, nullptr, nullptr, nullptr, napi_default, nullptr },
......
...@@ -1339,5 +1339,89 @@ export default function nativeApiStringJsunit() { ...@@ -1339,5 +1339,89 @@ export default function nativeApiStringJsunit() {
expect(value).assertEqual(0); expect(value).assertEqual(0);
done(); done();
}); });
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0093
* @tc.name aceNapiTest093
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest093', 0, async function (done) {
console.info('aceNapiTest093 START');
let value = napitest.createAndGetStringUtf16('he');
console.info('aceNapiTest093 testString result is: ' + value + "--" + JSON.stringify(value));
let value1 = napitest.stringUtf16OfCase('abc2r42');
console.info('aceNapiTest093 testString result is: ' + value1 + "--" + JSON.stringify(value1));
expect(value).assertEqual('he');
expect(value1).assertEqual('abc2');
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0094
* @tc.name aceNapiTest094
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest094', 0, async function (done) {
console.info('aceNapiTest094 START');
let valueeEmpty = napitest.createAndGetStringUtf16(' ');
console.info('aceNapiTest094 testString result is: ' + valueeEmpty + "--" + JSON.stringify(valueeEmpty));
expect(valueeEmpty).assertEqual(' ');
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0095
* @tc.name aceNapiTest095
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest095', 0, async function (done) {
console.info('aceNapiTest095 START');
let obj1 = napitest.typeTaggedInstance(0);
let obj2 = napitest.typeTaggedInstance(1);
let obj3 = napitest.typeTaggedInstance(2);
let obj4 = napitest.typeTaggedInstance(3);
let isTag = napitest.checkTypeTag(0, obj1);
let isTag1 = napitest.checkTypeTag(1, obj2);
let isTag2 = napitest.checkTypeTag(2, obj3);
let isTag3 = napitest.checkTypeTag(3, obj4);
console.info('aceNapiTest095 testTypeTag result is: ' + isTag + "--" + JSON.stringify(isTag));
expect(isTag).assertTrue();
console.info('aceNapiTest095 testTypeTag result is: ' + isTag1 + "--" + JSON.stringify(isTag1));
expect(isTag1).assertTrue();
console.info('aceNapiTest095 testTypeTag result is: ' + isTag2 + "--" + JSON.stringify(isTag2));
expect(isTag2).assertTrue();
console.info('aceNapiTest095 testTypeTag result is: ' + isTag3 + "--" + JSON.stringify(isTag3));
expect(isTag3).assertTrue();
done();
});
/**
* @tc.number SUB_ACE_BASIC_ETS_NAPI_0096
* @tc.name aceNapiTest096
* @tc.desc aceNapiEtsTest
*/
it('aceNapiTest096', 0, async function (done) {
console.info('aceNapiTest096 START');
let obj1 = napitest.typeTaggedInstance(0);
let obj2 = napitest.typeTaggedInstance(1);
let obj3 = napitest.typeTaggedInstance(2);
let obj4 = napitest.typeTaggedInstance(3);
let isTag = napitest.checkTypeTag(1, obj1);
let isTag1 = napitest.checkTypeTag(0, obj2);
let isTag2 = napitest.checkTypeTag(1, obj4);
let isTag3 = napitest.checkTypeTag(3, obj3);
let isTag4 = napitest.checkTypeTag(4, obj3);
console.info('aceNapiTest096 testTypeTag result is: ' + isTag + "--" + JSON.stringify(isTag));
expect(isTag).assertFalse();
console.info('aceNapiTest096 testTypeTag result is: ' + isTag1 + "--" + JSON.stringify(isTag1));
expect(isTag1).assertFalse();
console.info('aceNapiTest096 testTypeTag result is: ' + isTag2 + "--" + JSON.stringify(isTag2));
expect(isTag2).assertFalse();
console.info('aceNapiTest096 testTypeTag result is: ' + isTag3 + "--" + JSON.stringify(isTag3));
expect(isTag3).assertFalse();
console.info('aceNapiTest096 testTypeTag result is: ' + isTag4 + "--" + JSON.stringify(isTag4));
expect(isTag4).assertFalse();
done();
});
}) })
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册