diff --git a/frameworks/native/sensor/src/sensor_data_channel.cpp b/frameworks/native/sensor/src/sensor_data_channel.cpp index 38287de6567cfa0364edcc10b6d7186be72f7922..4a4e4602278e78ec4d99018068f6b976db64cd9f 100755 --- a/frameworks/native/sensor/src/sensor_data_channel.cpp +++ b/frameworks/native/sensor/src/sensor_data_channel.cpp @@ -148,7 +148,6 @@ int32_t SensorDataChannel::DestroySensorDataChannel() if (sensorDataThread_.joinable()) { sensorDataThread_.join(); } - // destroy sensor basic channel return DestroySensorBasicChannel(); } bool SensorDataChannel::IsThreadExit() diff --git a/interfaces/plugin/test/unittest/BUILD.gn b/interfaces/plugin/test/unittest/BUILD.gn index a49fc5949f9fb3a96cc51f962e0f0360a9fa6258..8aee9ed3d6f1037c0d622a10d480bbb453ebbd7f 100755 --- a/interfaces/plugin/test/unittest/BUILD.gn +++ b/interfaces/plugin/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 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 @@ -11,47 +11,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -#import("//build/config/ohos/rules.gni") -import("//build/ohos.gni") import("//build/test.gni") -module_output_path = "sensors/sensor/interfaces" -ohos_unittest("SensorJsTest") { - module_out_path = module_output_path - include_dirs = [ - "//third_party/node/src", - "//native_engine", - "//base/sensors/sensor/interfaces/native/include", - "//base/sensors/sensor/interfaces/plugin/include", - "//utils/native/base/include", - "./include", - "//third_party/libuv/include", - "//foundation/ace/napi", - "//foundation/ace/napi/interfaces/kits", - "//foundation/ace/napi/native_engine", - "//foundation/ace/napi/native_engine/impl/quickjs", - ] - defines = [ - "APP_LOG_TAG = \"sensroJs\"", - "LOG_DOMAIN = 0xD002700", - ] - sources = [ "sensor_js_test.cpp" ] - deps = [ - "//base/sensors/sensor/interfaces/native:sensor_interface_native", - "//base/sensors/sensor/interfaces/plugin:sensor", - "//foundation/ace/napi:ace_napi", - "//foundation/ace/napi/:ace_napi_quickjs", - "//third_party/googletest:gtest", - "//third_party/googletest:gtest_main", - "//third_party/libuv:uv_static", - "//third_party/quickjs:qjs", - "//utils/native/base:utils", - ] - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] - relative_install_dir = "module" - part_name = "sensor" - subsystem_name = "sensors" +module_output_path = "sensor/interfaces" +ohos_js_unittest("SensorJsTest") { + module_out_path = module_output_path + hap_profile = "./config.json" + certificate_profile = "//test/developertest/signature/openharmony_sx.p7b" } + group("unittest") { testonly = true deps = [ ":SensorJsTest" ] diff --git a/interfaces/plugin/test/unittest/ExampleJsunit.test.js b/interfaces/plugin/test/unittest/ExampleJsunit.test.js new file mode 100755 index 0000000000000000000000000000000000000000..51e86a1d9205d688f5cfd082fb2a4bd600e1c415 --- /dev/null +++ b/interfaces/plugin/test/unittest/ExampleJsunit.test.js @@ -0,0 +1,471 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import sensor from '@ohos.sensor' + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe("SensorJsTest", function () { + beforeAll(function() { + /* + * @tc.setup: setup invoked before all testcases + */ + console.info('beforeAll caled') + }) + + afterAll(function() { + /* + * @tc.teardown: teardown invoked after all testcases + */ + console.info('afterAll caled') + }) + + beforeEach(function() { + /* + * @tc.setup: setup invoked before each testcases + */ + console.info('beforeEach caled') + }) + + afterEach(function() { + /* + * @tc.teardown: teardown invoked after each testcases + */ + console.info('afterEach caled') + }) + + /* + * @tc.name:SensorJsTest001 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest001", 0, async function (done) { + console.info('----------------------SensorJsTest001---------------------------'); + function offPromise() { + return new Promise((resolve, reject) => { + console.info('setTimeout ..start') + setTimeout(()=>{ + sensor.off(0, (error) =>{ + if(error) { + console.info('SensorJsTest001 HYH_TEST off1 error'); + expect(false).assertTrue(); + reject(); + } else { + console.info('SensorJsTest001 HYH_TEST off1 error'); + expect(true).assertTrue(); + resolve() + } + }); + console.info('setTimeout ..end') + }, 1000) + }) + } + + let promise = new Promise((resolve, reject) => { + sensor.on(0, function(error, data) { + if (error) { + console.info('SensorJsTest001 HYH_TEST on error'); + expect(false).assertTrue(); + reject() + } else { + console.info('SensorJsTest001 HYH_TEST on success'); + expect(true).assertTrue(); + resolve() + } + }); + }) + + await promise.then(() =>{ + return offPromise(); + }, ()=>{ + console.info("SensorJsTest001 reject"); + }) + done(); + }) + + /* + * @tc.name:SensorJsTest002 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest002", 0, async function (done) { + console.info('----------------------SensorJsTest002---------------------------'); + function onSensorCallback(error, data) { + if (error) { + console.info('SensorJsTest002 HYH_TEST on error'); + expect(true).assertTrue(); + } else { + console.info('SensorJsTest002 HYH_TEST on success' + data.x); + expect(false).assertTrue(); + } + done(); + } + sensor.on(-1, onSensorCallback); + }) + + /* + * @tc.name:SensorJsTest003 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest003", 0, async function (done) { + console.info('----------------------SensorJsTest003---------------------------'); + let promise = new Promise((resolve,reject) => { + sensor.on(0, function(error, data){ + if (error) { + console.info('SensorJsTest003 HYH_TEST on error'); + expect(false).assertTrue(); + reject() + } else { + console.info('SensorJsTest003 HYH_TEST on success' + data.x); + expect(true).assertTrue(); + resolve() + } + }, {'interval': 100000000}); + }) + function offPromise() { + new Promise((resolve, reject) => { + console.info('setTimeout ..start') + setTimeout(()=>{ + sensor.off(0, (error) =>{ + if(error) { + console.info('SensorJsTest003 HYH_TEST off1 error'); + expect(false).assertTrue(); + reject(); + } else { + console.info('SensorJsTest003 HYH_TEST off1 error'); + expect(true).assertTrue(); + resolve() + } + }); + console.info('setTimeout ..end') + }, 1000) + }) + } + await promise.then(() =>{ + return offPromise(); + }) + done() + }) + + /* + * @tc.name:SensorJsTest004 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest004", 0, function () { + sensor.on(0, function(){}, {'interval': 100000000}, 5); + expect(true).assertTrue(); + }) + + /* + * @tc.name:SensorJsTest005 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest005", 0, async function (done) { + let promise1 = new Promise((resolve,reject) => { + sensor.on(0, function(error, data){ + if (error) { + console.info('SensorJsTest005 HYH_TEST on1 error'); + expect(false).assertTrue(); + reject() + } else { + console.info('SensorJsTest005 HYH_TEST on1 success' + data.x); + expect(true).assertTrue(); + resolve() + } + }); + }) + function promise2() { + new Promise((resolve,reject) => { + setTimeout(()=>{ + sensor.on(0, function(error, data){ + if (error) { + console.info('SensorJsTest005 HYH_TEST on2 error'); + expect(false).assertTrue(); + reject() + } else { + console.info('SensorJsTest005 HYH_TEST on2 success' + data.x); + expect(true).assertTrue(); + resolve() + } + }); + }, 1000) + }) + } + function offPromise() { + new Promise((resolve,reject) => { + console.info('setTimeout ..start') + setTimeout(()=>{ + sensor.off(0, (error) =>{ + if(error) { + console.info('SensorJsTest006 HYH_TEST off1 error'); + expect(false).assertTrue(); + reject(); + } else { + console.info('SensorJsTest006 HYH_TEST off1 error'); + expect(true).assertTrue(); + resolve() + } + }); + console.info('setTimeout ..end') + }, 1000) + }) + } + await promise1.then(() =>{ + return promise2(); + }).then(()=>{ + return offPromise(); + }) + done(); + }) + + /* + * @tc.name:SensorJsTest006 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest006", 0, async function (done) { + let promise1 = new Promise((resolve,reject) => { + sensor.on(0, function(error, data){ + if (error) { + console.info('SensorJsTest006 HYH_TEST on1 error'); + expect(false).assertTrue(); + reject() + } else { + console.info('SensorJsTest006 HYH_TEST on1 success' + data.x); + expect(true).assertTrue(); + resolve() + } + }); + }) + function offPromise() { + new Promise((resolve,reject) => { + console.info('setTimeout ..start') + setTimeout(()=>{ + sensor.off(0, (error) =>{ + if(error) { + console.info('SensorJsTest006 HYH_TEST off1 error'); + expect(false).assertTrue(); + reject(); + } else { + console.info('SensorJsTest006 HYH_TEST off1 error'); + expect(true).assertTrue(); + resolve() + } + }); + console.info('setTimeout ..end') + }, 1000) + }) + } + + function offPromise2() { + new Promise((resolve,reject) => { + console.info('setTimeout ..start') + setTimeout(()=>{ + sensor.off(0, (error) =>{ + if(error) { + console.info('SensorJsTest006 HYH_TEST off1 error'); + expect(true).assertTrue(); + resolve(); + } else { + console.info('SensorJsTest006 HYH_TEST off1 error'); + expect(false).assertTrue(); + reject() + } + }); + console.info('setTimeout ..end') + }, 1000) + }) + } + + await promise1.then(() =>{ + return offPromise(); + }).then(()=>{ + return offPromise2(); + }) + done(); + }) + + /* + * @tc.name:SensorJsTest007 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest007", 0, async function (done) { + function onceSensorCallback(error, data) { + if (error) { + console.info('SensorJsTest007 HYH_TEST on error'); + expect(false).assertTrue(); + } else { + console.info('SensorJsTest007 HYH_TEST on success' + data.x); + expect(true).assertTrue(); + } + done(); + } + sensor.once(0, onceSensorCallback); + }) + + /* + * @tc.name:SensorJsTest008 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest008", 0, async function (done) { + function onceSensorCallback(error, data) { + if (error) { + console.info('SensorJsTest008 HYH_TEST on error'); + expect(true).assertTrue(); + } else { + console.info('SensorJsTest008 HYH_TEST on success' + data.x); + expect(false).assertTrue(); + } + done(); + } + sensor.once(-1, onceSensorCallback); + }) + + /* + * @tc.name:SensorJsTest009 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest009", 0, async function (done) { + let onPromise = new Promise((resolve,reject) => { + sensor.on(0, function(error, data){ + if (error) { + console.info('SensorJsTest009 HYH_TEST on1 error'); + expect(false).assertTrue(); + reject() + } else { + console.info('SensorJsTest009 HYH_TEST on1 success' + data.x); + expect(true).assertTrue(); + resolve() + } + }); + }) + function oncePromise() { + new Promise((resolve,reject) => { + sensor.once(0, (error) =>{ + if (error) { + console.info('SensorJsTest009 HYH_TEST on error'); + expect(false).assertTrue(); + reject(); + } else { + console.info('SensorJsTest009 HYH_TEST on success' + data.x); + expect(true).assertTrue(); + resolve(); + } + }); + }) + } + + function offPromise() { + new Promise((resolve,reject) => { + console.info('setTimeout ..start') + sensor.off(0, (error) =>{ + if(error) { + console.info('SensorJsTest009 HYH_TEST off1 error'); + expect(false).assertTrue(); + reject(); + } else { + console.info('SensorJsTest009 HYH_TEST off1 error'); + expect(true).assertTrue(); + resolve() + } + }); + console.info('setTimeout ..end') + }) + } + + await onPromise.then(() =>{ + return oncePromise(); + }).then(()=>{ + return offPromise(); + }) + done(); + }) + + /* + * @tc.name:SensorJsTest010 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest010", 0, function () { + sensor.once(0, function(){}, 5); + expect(true).assertTrue(); + }) + + /* + * @tc.name:SensorJsTest011 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest011", 0, async function (done) { + function offCallback(error) { + if (error) { + console.info('SensorJsTest011 HYH_TEST on error'); + expect(true).assertTrue(); + } else { + console.info('SensorJsTest011 HYH_TEST on success' + data.x); + expect(false).assertTrue(); + } + done(); + } + sensor.off(-1, offCallback); + }) + + /* + * @tc.name:SensorJsTest012 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest012", 0, async function (done) { + function offCallback(error) { + if (error) { + console.info('SensorJsTest012 HYH_TEST on error'); + expect(false).assertTrue(); + } else { + console.info('SensorJsTest012 HYH_TEST on success' + data.x); + expect(true).assertTrue(); + } + done(); + } + sensor.off(0, offCallback); + }) + + /* + * @tc.name:SensorJsTest013 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest013", 0, function () { + sensor.off(0, function(){}, 5); + expect(true).assertTrue(); + }) +}) diff --git a/interfaces/plugin/test/unittest/config.json b/interfaces/plugin/test/unittest/config.json new file mode 100755 index 0000000000000000000000000000000000000000..2ca858952259de571e07105b05eca8eaed0d7db4 --- /dev/null +++ b/interfaces/plugin/test/unittest/config.json @@ -0,0 +1,61 @@ +{ + "app": { + "bundleName": "com.example.myapplication", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.myapplication", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.myapplication.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "MyApplication", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } + } + \ No newline at end of file diff --git a/interfaces/plugin/test/unittest/sensor_js_test.cpp b/interfaces/plugin/test/unittest/sensor_js_test.cpp deleted file mode 100755 index 6d00afd0e1681599f195560f5282eeb554526eb1..0000000000000000000000000000000000000000 --- a/interfaces/plugin/test/unittest/sensor_js_test.cpp +++ /dev/null @@ -1,595 +0,0 @@ -/* - * 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include "napi/native_api.h" -#include "napi/native_node_api.h" -#include "sensor_napi_utils.h" -#include "sensor_agent.h" -#include "native_engine.h" -#include "quickjs_native_engine.h" -#include "hilog/log.h" - -namespace OHOS { -namespace Sensors { -using namespace testing::ext; -using namespace OHOS::HiviewDFX; -static NativeEngine* g_nativeEngine = nullptr; -namespace { - using namespace OHOS::HiviewDFX; - static constexpr HiLogLabel LABEL = {LOG_CORE, 0xD002708, "SensorJsTest"}; -} - -class SensorJsTest : public testing::Test { -public: - void SetUp(); - void TearDown(); - SensorJsTest(); - virtual ~SensorJsTest(); -protected: - NativeEngine* engine_; -}; - -void SensorJsTest::SetUp() -{ - HiLog::Info(LABEL, "%{public}s begin", __func__); -} - -void SensorJsTest::TearDown() -{ - HiLog::Info(LABEL, "%{public}s end", __func__); -} - -SensorJsTest::SensorJsTest() -{ - JSRuntime* rt = JS_NewRuntime(); - if (rt == nullptr) { - return ; - } - - JSContext* ctx = JS_NewContext(rt); - if (ctx == nullptr) { - return ; - } - - js_std_add_helpers(ctx, 0, nullptr); - g_nativeEngine = new QuickJSNativeEngine(rt, ctx, 0); // default instance id 0 - engine_ = g_nativeEngine; - -} - -SensorJsTest::~SensorJsTest() { - delete g_nativeEngine; - g_nativeEngine = nullptr; -} - -/* - * @tc.name: IsMatchType_001 - * @tc.desc: Match napi_number - * @tc.type: FUNC - * @tc.require:SR000G54IU - */ -HWTEST_F(SensorJsTest, IsMatchType_001, TestSize.Level1) -{ - napi_env env = (napi_env)engine_; - uint32_t cppValue = UINT32_MAX; - napi_value napiValue = nullptr; - napi_create_uint32(env, cppValue, &napiValue); - - bool ret = IsMatchType(napiValue, napi_number, env); - ASSERT_EQ(ret, true); -} - -/* - * @tc.name: IsMatchType_002 - * @tc.desc: Match napi_string - * @tc.type: FUNC - * @tc.require:AR000G54IV - */ -HWTEST_F(SensorJsTest, IsMatchType_002, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - const char cppValue[] = "中文,English,123456,!@#"; - size_t cppValueStrLength = strlen(cppValue); - napi_value napiValue = nullptr; - napi_create_string_utf8(env, cppValue, cppValueStrLength, &napiValue); - - // call function - bool ret = IsMatchType(napiValue, napi_string, env); - ASSERT_EQ(ret, true); -} - -/* - * @tc.name: IsMatchType_003 - * @tc.desc: Match napi_symbol - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, IsMatchType_003, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - const char testStr[] = "testSymbol"; - napi_value result = nullptr; - napi_create_string_latin1(env, testStr, strlen(testStr), &result); - napi_value symbolVal = nullptr; - napi_create_symbol(env, result, &symbolVal); - - // call function - bool ret = IsMatchType(symbolVal, napi_symbol, env); - ASSERT_EQ(ret, true); -} - -/* - * @tc.name: IsMatchType_004 - * @tc.desc: Match napi_function - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, IsMatchType_004, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - const char* tetScriptStr = "new Date();"; - napi_value testScript = nullptr; - napi_create_string_utf8(env, tetScriptStr, strlen(tetScriptStr), &testScript); - napi_value date = nullptr; - napi_run_script(env, testScript, &date); - napi_value getTimeFunc = nullptr; - napi_get_named_property(env, date, "getTime", &getTimeFunc); - - // call function - bool ret = IsMatchType(getTimeFunc, napi_function, env); - ASSERT_EQ(ret, true); -} - -/* - * @tc.name: IsMatchType_005 - * @tc.desc: Match napi_boolean - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, IsMatchType_005, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - napi_value result = nullptr; - napi_get_boolean(env, true, &result); - - // call function - bool ret = IsMatchType(result, napi_boolean, env); - ASSERT_EQ(ret, true); -} - -/* - * @tc.name: GetNapiInt32_001 - * @tc.desc: change int32_t[INT32_MAX] to napi_value - * @tc.type: FUNC - * @tc.require: SR000FU58Q - */ -HWTEST_F(SensorJsTest, GetNapiInt32_001, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int32_t number = INT32_MAX; - - // call function - napi_value value = GetNapiInt32(number, env); - napi_valuetype ret; - napi_typeof(env, value, &ret); - ASSERT_EQ(ret, napi_number); -} - -/* - * @tc.name: GetNapiInt32_002 - * @tc.desc: change int32_t[INT32_MIN] to napi_value - * @tc.type: FUNC - * @tc.require: AR000FU73V - */ -HWTEST_F(SensorJsTest, GetNapiInt32_002, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int32_t number = INT32_MIN; - - // call function - napi_value value = GetNapiInt32(number, env); - napi_valuetype ret; - napi_typeof(env, value, &ret); - ASSERT_EQ(ret, napi_number); -} - -/* - * @tc.name: GetNapiInt32_003 - * @tc.desc: change int32_t[true] to napi_value - * @tc.type: FUNC - * @tc.require: AR000FU73V - */ -HWTEST_F(SensorJsTest, GetNapiInt32_003, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int32_t number = (int32_t)true; - - // call function - napi_value value = GetNapiInt32(number, env); - napi_valuetype ret; - napi_typeof(env, value, &ret); - ASSERT_EQ(ret, napi_number); -} - -/* - * @tc.name: GetNapiInt32_004 - * @tc.desc: change int32_t[true] to napi_value - * @tc.type: FUNC - * @tc.require: AR000FU73V - */ -HWTEST_F(SensorJsTest, GetNapiInt32_004, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int32_t number = (int32_t)false; - - // call function - napi_value value = GetNapiInt32(number, env); - napi_valuetype ret; - napi_typeof(env, value, &ret); - ASSERT_EQ(ret, napi_number); -} - -/* - * @tc.name: GetNapiInt32_005 - * @tc.desc: change int32_t[char] to napi_value - * @tc.type: FUNC - * @tc.require: AR000FU73V - */ -HWTEST_F(SensorJsTest, GetNapiInt32_005, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int32_t number = (int32_t)'a'; - - // call function - napi_value value = GetNapiInt32(number, env); - napi_valuetype ret; - napi_typeof(env, value, &ret); - ASSERT_EQ(ret, napi_number); -} - -/* - * @tc.name: NapiGetNamedProperty_001 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000FU73V - */ -HWTEST_F(SensorJsTest, NapiGetNamedProperty_001, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - const char* tetScriptStr = "new Date();"; - napi_value testScript = nullptr; - napi_create_string_utf8(env, tetScriptStr, strlen(tetScriptStr), &testScript); - napi_value date = nullptr; - napi_run_script(env, testScript, &date); - - // call function - napi_value value = NapiGetNamedProperty(date, "getTime", env); - napi_valuetype ret; - napi_typeof(env, value, &ret); - ASSERT_EQ(ret, napi_function); -} - -/* - * @tc.name: NapiGetNamedProperty_002 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000FU73V - */ -HWTEST_F(SensorJsTest, NapiGetNamedProperty_002, TestSize.Level1) -{ - // 定义变量 赋值 - napi_env env = (napi_env)engine_; - int32_t status=101; - napi_value message; - napi_create_int32(env, status, &message); - - // 定义变量为对象 - napi_value result; - napi_create_object(env, &result); - - // 赋值给object - napi_set_named_property(env, result, "code", message); - - napi_value value = NapiGetNamedProperty(result, "code", env); - napi_valuetype ret; - napi_typeof(env, value, &ret); - ASSERT_EQ(ret, napi_number); -} - -/* - * @tc.name: NapiGetNamedProperty_003 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000FU73V - */ -HWTEST_F(SensorJsTest, NapiGetNamedProperty_003, TestSize.Level1) -{ - // 定义变量 赋值 - napi_env env = (napi_env)engine_; - const char status[] = "type001"; - napi_value message; - napi_create_string_utf8(env, status, strlen(status), &message); - - // 定义变量为对象 - napi_value result; - napi_create_object(env, &result); - - // 赋值给object - napi_set_named_property(env, result, "code", message); - - napi_value value = NapiGetNamedProperty(result, "code", env); - napi_valuetype ret; - napi_typeof(env, value, &ret); - ASSERT_EQ(ret, napi_string); -} - -/* - * @tc.name: NapiGetNamedProperty_004 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, NapiGetNamedProperty_004, TestSize.Level1) -{ - // 定义变量 赋值 - napi_env env = (napi_env)engine_; - napi_value message; - napi_get_boolean(env, true, &message); - - // 定义变量为对象 - napi_value result; - napi_create_object(env, &result); - - // 赋值给object - napi_set_named_property(env, result, "code", message); - - - napi_value value = NapiGetNamedProperty(result, "code", env); - napi_valuetype ret; - napi_typeof(env, value, &ret); - ASSERT_EQ(ret, napi_boolean); -} - -/* - * @tc.name: NapiGetNamedProperty_005 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, NapiGetNamedProperty_005, TestSize.Level1) -{ - // 定义变量 赋值 - napi_env env = (napi_env)engine_; - const char testStr[] = "testSymbol"; - napi_value resultSymbol = nullptr; - napi_create_string_latin1(env, testStr, strlen(testStr), &resultSymbol); - napi_value message = nullptr; - napi_create_symbol(env, resultSymbol, &message); - - // 定义变量为对象 - napi_value result; - napi_create_object(env, &result); - - // 赋值给object - napi_set_named_property(env, result, "code", message); - - napi_value value = NapiGetNamedProperty(result, "code", env); - napi_valuetype ret; - napi_typeof(env, value, &ret); - ASSERT_EQ(ret, napi_symbol); -} -/* - * @tc.name: GetCppInt32_001 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, GetCppInt32_001, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int32_t number = INT32_MAX; - napi_value value; - napi_create_int32(env, number, &value); - - // call function - int32_t ret = GetCppInt32(value, env); - ASSERT_EQ(ret, (int32_t)INT32_MAX); -} - -/* - * @tc.name: GetCppInt32_002 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, GetCppInt32_002, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int32_t number = INT32_MIN; - napi_value value; - napi_create_int32(env, number, &value); - - // call function - int32_t ret = GetCppInt32(value, env); - ASSERT_EQ(ret, (int32_t)INT32_MIN); -} - -/* - * @tc.name: GetCppInt32_003 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, GetCppInt32_003, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int32_t number = (int32_t)true; - napi_value value; - napi_create_int32(env, number, &value); - - // call function - int32_t ret = GetCppInt32(value, env); - ASSERT_EQ(ret, (int32_t)true); -} - -/* - * @tc.name: GetCppInt32_004 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, GetCppInt32_004, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int32_t number = (int32_t)false; - napi_value value; - napi_create_int32(env, number, &value); - - // call function - int32_t ret = GetCppInt32(value, env); - ASSERT_EQ(ret, (int32_t)false); -} -/* - * @tc.name: GetCppInt32_005 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, GetCppInt32_005, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int32_t number = (int32_t)'b'; - napi_value value; - napi_create_int32(env, number, &value); - - // call function - int32_t ret = GetCppInt32(value, env); - ASSERT_EQ(ret, (int32_t)'b'); -} - -/* - * @tc.name: GetCppInt64_001 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, GetCppInt64_001, TestSize.Level1) -{ - // Construction parameters - int64_t tmpInt64Max = 9007199254740991;//9223372036854775807;9007199254740992 - napi_env env = (napi_env)engine_; - int64_t number = tmpInt64Max;//(int64_t)INT64_MAX; - napi_value value; - napi_create_int64(env, number, &value); - - // call function - int64_t ret = GetCppInt64(value, env); - ASSERT_EQ(ret, tmpInt64Max); -} - -/* - * @tc.name: GetCppInt64_002 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, GetCppInt64_002, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int64_t number = (int64_t)INT64_MIN; - napi_value value; - napi_create_int64(env, number, &value); - - // call function - int64_t ret = GetCppInt64(value, env); - ASSERT_EQ(ret, (int64_t)INT64_MIN); -} - -/* - * @tc.name: GetCppInt64_003 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, GetCppInt64_003, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int64_t number = (int64_t)true; - napi_value value; - napi_create_int64(env, number, &value); - - - // call function - int64_t ret = GetCppInt64(value, env); - ASSERT_EQ(ret, (int64_t)true); -} - -/* - * @tc.name: GetCppInt64_004 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, GetCppInt64_004, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int64_t number = (int64_t)false; - napi_value value; - napi_create_int64(env, number, &value); - - // call function - int64_t ret = GetCppInt64(value, env); - ASSERT_EQ(ret, (int64_t)false); -} -/* - * @tc.name: GetCppInt64_005 - * @tc.desc: Parse function in Json - * @tc.type: FUNC - * @tc.require: AR000G54IV - */ -HWTEST_F(SensorJsTest, GetCppInt64_005, TestSize.Level1) -{ - // Construction parameters - napi_env env = (napi_env)engine_; - int64_t number = (int64_t)'c'; - napi_value value; - napi_create_int64(env, number, &value); - - // call function - int64_t ret = GetCppInt64(value, env); - ASSERT_EQ(ret, (int64_t)'c'); -} -} // namespace Sensors -} // namespace OHOS \ No newline at end of file