diff --git a/interfaces/native/vibrator/BUILD.gn b/interfaces/native/vibrator/BUILD.gn index 4515757fb7b7f4b8650ff5234dc41db4bbccdeec..522fbccac67064a5735b3667acc5d1a6d53f77f4 100755 --- a/interfaces/native/vibrator/BUILD.gn +++ b/interfaces/native/vibrator/BUILD.gn @@ -15,7 +15,7 @@ import("//build/ohos.gni") SUBSYSTEM_DIR = "//base/sensors/miscdevice" ohos_ndk_library("libvibrator_ndk") { - output_name = "vibrator" + output_name = "vibrator_agent" ndk_description_file = "./libvibrator.json" min_compact_version = "6" } @@ -33,7 +33,7 @@ config("vibrator_config") { } ohos_shared_library("vibrator_interface_native") { - output_name = "vibrator" + output_name = "vibrator_agent" sources = [ "src/vibrator_agent.cpp" ] include_dirs = [ diff --git a/interfaces/plugin/BUILD.gn b/interfaces/plugin/BUILD.gn index d9ed9f302827484309cb186ec0683eba9f61501b..0f8a1b7aa9d952f64aff14dbdd3539c28a3f431b 100755 --- a/interfaces/plugin/BUILD.gn +++ b/interfaces/plugin/BUILD.gn @@ -13,7 +13,7 @@ #import("//build/config/ohos/rules.gni") import("//build/ohos.gni") -ohos_shared_library("vibrator_js") { +ohos_shared_library("vibrator") { include_dirs = [ "//third_party/node/src", "//native_engine", @@ -44,5 +44,5 @@ ohos_shared_library("vibrator_js") { } group("vibrator_js_target") { - deps = [ ":vibrator_js" ] + deps = [ ":vibrator" ] } diff --git a/interfaces/plugin/vibrate/test/unittest/BUILD.gn b/interfaces/plugin/vibrate/test/unittest/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..308e8f731161b62faabdcf832dcab2e5c39af877 --- /dev/null +++ b/interfaces/plugin/vibrate/test/unittest/BUILD.gn @@ -0,0 +1,26 @@ +# 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("//build/test.gni") +module_output_path = "miscdevice/interfaces" + +ohos_js_unittest("VibratorJsTest") { + module_out_path = module_output_path + hap_profile = "./config.json" + certificate_profile = "//test/developertest/signature/openharmony_sx.p7b" +} + +group("unittest") { + testonly = true + deps = [ ":VibratorJsTest" ] +} diff --git a/interfaces/plugin/vibrate/test/unittest/ExampleJsunit.test.js b/interfaces/plugin/vibrate/test/unittest/ExampleJsunit.test.js new file mode 100755 index 0000000000000000000000000000000000000000..3234acad887758e8a1150015933141245bfce9e2 --- /dev/null +++ b/interfaces/plugin/vibrate/test/unittest/ExampleJsunit.test.js @@ -0,0 +1,440 @@ +/* + * 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 vibrator from '@ohos.vibrator' + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe("VibratorJsTest", 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:VibratorJsTest001 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest001", 0, async function (done) { + function vibrateCallback(error) { + if (error) { + console.info('VibratorJsTest001 vibrator error'); + expect(false).assertTrue(); + } else { + console.info('VibratorJsTest001 vibrator success'); + expect(true).assertTrue(); + } + done(); + } + vibrator.vibrate(10, vibrateCallback); + }) + + /* + * @tc.name:VibratorJsTest002 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest002", 0, async function (done) { + function vibrateCallback(error) { + if (error) { + console.info('VibratorJsTest002 vibrator success'); + expect(true).assertTrue(); + } else { + console.info('VibratorJsTest002 vibrator error'); + expect(false).assertTrue(); + } + done(); + } + vibrator.vibrate(-1, vibrateCallback); + }) + + /* + * @tc.name:VibratorJsTest003 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest003", 0, async function (done) { + function vibrateCallback(error) { + if (error) { + console.info('VibratorJsTest003 vibrator success'); + expect(true).assertTrue(); + } else { + console.info('VibratorJsTest003 vibrator error'); + expect(false).assertTrue(); + } + done(); + } + vibrator.vibrate(1000000000000, vibrateCallback); + }) + + /* + * @tc.name:VibratorJsTest004 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest004", 0, async function (done) { + function vibrateCallback(error) { + if (error) { + console.info('VibratorJsTest004 vibrator error'); + expect(false).assertTrue(); + } else { + console.info('VibratorJsTest004 vibrator success'); + expect(true).assertTrue(); + } + done(); + } + vibrator.vibrate(1800000, vibrateCallback); + }) + + /* + * @tc.name:VibratorJsTest005 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest005", 0, async function (done) { + function vibrateCallback(error) { + if (error) { + console.info('VibratorJsTest005 vibrator success'); + expect(true).assertTrue(); + } else { + console.info('VibratorJsTest005 vibrator error'); + expect(false).assertTrue(); + } + done(); + } + vibrator.vibrate("", vibrateCallback); + }) + + /* + * @tc.name:VibratorJsTest006 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest006", 0, async function (done) { + function vibrateCallback(error) { + if (error) { + console.info('VibratorJsTest006 vibrator success'); + expect(true).assertTrue(); + } else { + console.info('VibratorJsTest006 vibrator error'); + expect(false).assertTrue(); + } + done(); + } + vibrator.vibrate("xxx", vibrateCallback); + }) + + /* + * @tc.name:VibratorJsTest007 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest007", 0, async function (done) { + function vibrateCallback(error) { + if (error) { + console.info('VibratorJsTest007 vibrator error'); + expect(false).assertTrue(); + } else { + console.info('VibratorJsTest007 vibrator success'); + expect(true).assertTrue(); + } + done(); + } + vibrator.vibrate("haptic.clock.timer", vibrateCallback); + }) + + /* + * @tc.name:VibratorJsTest008 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest008", 0, async function (done) { + function vibrateCallback(error) { + if (error) { + console.info('VibratorJsTest008 stop error'); + expect(false).assertTrue(); + } else { + console.info('VibratorJsTest008 stop success'); + expect(true).assertTrue(); + } + done(); + } + vibrator.stop("preset", vibrateCallback); + }) + + /* + * @tc.name:VibratorJsTest009 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest009", 0, async function (done) { + console.info('----------------------SensorJsTest001---------------------------'); + function stopPromise() { + return new Promise((resolve, reject) => { + vibrator.stop("time", (error)=>{ + if (error) { + console.info('VibratorJsTest009 stop error'); + expect(false).assertTrue(); + reject(); + } else { + console.info('VibratorJsTest009 stop success'); + expect(true).assertTrue(); + resolve(); + } + }); + }) + } + + let promise = new Promise((resolve, reject) => { + vibrator.vibrate(180000, (error)=>{ + if (error) { + console.info('VibratorJsTest009 vibrate error'); + expect(false).assertTrue(); + reject(); + } else { + console.info('VibratorJsTest009 vibrate success'); + expect(true).assertTrue(); + resolve(); + } + }); + }) + + await promise.then(() =>{ + return stopPromise(); + }, ()=>{ + console.info("VibratorJsTest009 reject"); + }) + done(); + }) + + /* + * @tc.name:VibratorJsTest010 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest010", 0, async function (done) { + function vibrateCallback(error) { + if (error) { + console.info('VibratorJsTest010 stop success'); + expect(true).assertTrue(); + } else { + console.info('VibratorJsTest010 stop off'); + expect(false).assertTrue(); + } + done(); + } + vibrator.stop("", vibrateCallback); + }) + + /* + * @tc.name:VibratorJsTest011 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest011", 0, async function (done) { + vibrator.vibrate(1000).then(() => { + console.log("VibratorJsTest011 vibrate success"); + expect(true).assertTrue(); + done(); + }, (error)=>{ + expect(false).assertTrue(); + console.log("VibratorJsTest011 vibrate error"); + done(); + }); + }) + + /* + * @tc.name:VibratorJsTest012 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest012", 0, async function (done) { + vibrator.vibrate(-1).then(() => { + console.log("VibratorJsTest012 vibrate error"); + expect(false).assertTrue(); + done(); + }, (error)=>{ + expect(true).assertTrue(); + console.log("VibratorJsTest012 vibrate success"); + done(); + }); + }) + + /* + * @tc.name:VibratorJsTest013 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest013", 0, async function (done) { + vibrator.vibrate(1000000000000000).then(() => { + console.log("VibratorJsTest013 vibrate error"); + expect(false).assertTrue(); + done(); + }, (error)=>{ + expect(true).assertTrue(); + console.log("VibratorJsTest013 vibrate success"); + done(); + }); + }) + + /* + * @tc.name:VibratorJsTest014 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest014", 0, async function (done) { + vibrator.vibrate("haptic.clock.timer").then(() => { + console.log("VibratorJsTest014 vibrate success"); + expect(true).assertTrue(); + done(); + }, (error)=>{ + expect(false).assertTrue(); + console.log("VibratorJsTest014 vibrate error"); + done(); + }); + }) + + /* + * @tc.name:VibratorJsTest015 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest015", 0, async function (done) { + vibrator.vibrate("").then(() => { + console.log("VibratorJsTest015 vibrate error"); + expect(false).assertTrue(); + done(); + }, (error)=>{ + expect(true).assertTrue(); + console.log("VibratorJsTest015 vibrate success"); + done(); + }); + }) + + /* + * @tc.name:VibratorJsTest016 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest016", 0, async function (done) { + vibrator.stop("").then(() => { + console.log("VibratorJsTest016 stop error"); + expect(false).assertTrue(); + done(); + }, (error)=>{ + expect(true).assertTrue(); + console.log("VibratorJsTest016 stop success"); + done(); + }); + }) + + /* + * @tc.name:VibratorJsTest017 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest017", 0, async function (done) { + vibrator.stop("preset").then(() => { + console.log("VibratorJsTest017 off success"); + expect(true).assertTrue(); + done(); + }, (error)=>{ + expect(false).assertTrue(); + console.log("VibratorJsTest017 off error"); + done(); + }); + }) + + /* + * @tc.name:VibratorJsTest018 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("VibratorJsTest018", 0, async function (done) { + function stopPromise() { + return new Promise((resolve, reject) => { + vibrator.stop("time").then(() => { + console.log("VibratorJsTest018 stop success"); + expect(true).assertTrue(); + resolve(); + }, (error)=>{ + expect(false).assertTrue(); + console.log("VibratorJsTest018 stop error"); + reject(); + }); + }) + } + + let promise = new Promise((resolve, reject) => { + vibrator.vibrate(180000).then(() => { + console.log("VibratorJsTest018 vibrate success"); + expect(true).assertTrue(); + resolve(); + }, (error)=>{ + expect(false).assertTrue(); + console.log("VibratorJsTest018 vibrate error"); + reject(); + }); + }) + + await promise.then(() =>{ + return stopPromise(); + }, ()=>{ + console.info("VibratorJsTest018 reject"); + }) + done(); + }) +}) diff --git a/interfaces/plugin/vibrate/test/unittest/config.json b/interfaces/plugin/vibrate/test/unittest/config.json new file mode 100755 index 0000000000000000000000000000000000000000..2ca858952259de571e07105b05eca8eaed0d7db4 --- /dev/null +++ b/interfaces/plugin/vibrate/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