From 821e242c81d2c3dacbf11ffcaa08f3e874fdf908 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Tue, 17 May 2022 16:29:25 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E6=96=B9=E5=90=91=E3=80=81?= =?UTF-8?q?=E9=87=8D=E5=8A=9B=E4=BC=A0=E6=84=9F=E5=99=A8=E7=9A=84=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E4=B8=8E=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- .../plugin/test/ExampleJsunit.test_gravity.js | 305 ++++++++++++++++++ .../test/ExampleJsunit.test_orientating.js | 305 ++++++++++++++++++ 2 files changed, 610 insertions(+) create mode 100644 interfaces/plugin/test/ExampleJsunit.test_gravity.js create mode 100644 interfaces/plugin/test/ExampleJsunit.test_orientating.js diff --git a/interfaces/plugin/test/ExampleJsunit.test_gravity.js b/interfaces/plugin/test/ExampleJsunit.test_gravity.js new file mode 100644 index 00000000..2c66aefc --- /dev/null +++ b/interfaces/plugin/test/ExampleJsunit.test_gravity.js @@ -0,0 +1,305 @@ +/* + * 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 '@system.sensor' + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe("SensorJsTest", function () { + function callback(data) { + console.info("callback" + JSON.stringify(data)); + expect(typeof(data.x)).assertEqual("number"); + expect(typeof(data.y)).assertEqual("number"); + expect(typeof(data.z)).assertEqual("number"); + } + + function callback2(data) { + console.info("callback2" + JSON.stringify(data)); + expect(typeof(data.x)).assertEqual("number"); + expect(typeof(data.y)).assertEqual("number"); + expect(typeof(data.z)).assertEqual("number"); + } + + 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---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + setTimeout(()=>{ + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY); + done(); + }, 500); + }) + + /* + * @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---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------SensorJsTest002 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY); + console.info('----------------------SensorJsTest002 off end---------------------------'); + done(); + }, 500); + }) + + /* + * @tc.name:SensorJsTest003 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest003", 0, function (done) { + console.info('----------------------SensorJsTest003---------------------------'); + function onSensorCallback(data) { + console.info('SensorJsTest003 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, onSensorCallback, {'interval': 100000000}, 5); + } catch (error) { + console.info(error); + expect(true).assertTrue(); + done(); + } + }) + + /* + * @tc.name:SensorJsTest004 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest004", 0, async function (done) { + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + setTimeout(()=>{ + expect(true).assertTrue(); + done(); + }, 500); + }) + + /* + * @tc.name:SensorJsTest005 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest005", 0, function (done) { + function onceSensorCallback(data) { + console.info('SensorJsTest005 on error'); + expect(false).assertTrue(); + done(); + } + try{ + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, onceSensorCallback, 5); + } catch (error) { + console.info(error); + expect(true).assertTrue(); + 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) { + try { + sensor.off(string, ""); + } catch (error) { + console.info(error); + expect(true).assertTrue(); + 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 onSensorCallback(data) { + console.info('SensorJsTest007 on error'); + expect(false).assertTrue(); + done(); + } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, onSensorCallback); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, onSensorCallback); + setTimeout(()=>{ + expect(true).assertTrue(); + done(); + }, 500); + }) + + /* + * @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 onSensorCallback(data) { + console.info('SensorJsTest008 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.off(1000000, onSensorCallback); + } catch (error) { + console.info(error); + expect(true).assertTrue(); + done(); + } + }) + + /* + * @tc.name:SensorJsTest009 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest009", 0, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2); + setTimeout(()=>{ + console.info('----------------------SensorJsTest009 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY); + console.info('----------------------SensorJsTest009 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:SensorJsTest010 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest010", 0, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2); + setTimeout(()=>{ + console.info('----------------------SensorJsTest010 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + console.info('----------------------SensorJsTest010 off end---------------------------'); + }, 500); + setTimeout(()=>{ + console.info('----------------------SensorJsTest010 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2); + console.info('----------------------SensorJsTest010 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:SensorJsTest011 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest011", 0, async function (done) { + console.info('----------------------SensorJsTest011---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback, {'interval': 100000000}); + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2); + setTimeout(()=>{ + console.info('----------------------SensorJsTest011 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY); + console.info('----------------------SensorJsTest011 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:SensorJsTest012 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest012", 0, async function (done) { + console.info('----------------------SensorJsTest012---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback, {'interval': 100000000}); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + console.info('----------------------SensorJsTest012 off end---------------------------'); + }, 500); + setTimeout(()=>{ + console.info('----------------------SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2); + console.info('----------------------SensorJsTest012 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:SensorJsTest013 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest013", 0, async function (done) { + console.info('----------------------SensorJsTest013---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback, {'interval': 100000000}); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------SensorJsTest013 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY); + console.info('----------------------SensorJsTest013 off end---------------------------'); + done(); + }, 1000); + }) +}) \ No newline at end of file diff --git a/interfaces/plugin/test/ExampleJsunit.test_orientating.js b/interfaces/plugin/test/ExampleJsunit.test_orientating.js new file mode 100644 index 00000000..6516c8e9 --- /dev/null +++ b/interfaces/plugin/test/ExampleJsunit.test_orientating.js @@ -0,0 +1,305 @@ +/* + * 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 () { + function callback(data) { + console.info("callback" + JSON.stringify(data)); + expect(typeof(data.beta)).assertEqual("number"); + expect(typeof(data.gamma)).assertEqual("number"); + expect(typeof(data.alpha)).assertEqual("number"); + } + + function callback2(data) { + console.info("callback2" + JSON.stringify(data)); + expect(typeof(data.beta)).assertEqual("number"); + expect(typeof(data.gamma)).assertEqual("number"); + expect(typeof(data.alpha)).assertEqual("number"); + } + + 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---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + setTimeout(()=>{ + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION); + done(); + }, 500); + }) + + /* + * @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---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------SensorJsTest002 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION); + console.info('----------------------SensorJsTest002 off end---------------------------'); + done(); + }, 500); + }) + + /* + * @tc.name:SensorJsTest003 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest003", 0, function (done) { + console.info('----------------------SensorJsTest003---------------------------'); + function onSensorCallback(data) { + console.info('SensorJsTest003 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, onSensorCallback, {'interval': 100000000}, 5); + } catch (error) { + console.info(error); + expect(true).assertTrue(); + done(); + } + }) + + /* + * @tc.name:SensorJsTest004 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest004", 0, async function (done) { + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + setTimeout(()=>{ + expect(true).assertTrue(); + done(); + }, 500); + }) + + /* + * @tc.name:SensorJsTest005 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest005", 0, function (done) { + function onceSensorCallback(data) { + console.info('SensorJsTest005 on error'); + expect(false).assertTrue(); + done(); + } + try{ + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, onceSensorCallback, 5); + } catch (error) { + console.info(error); + expect(true).assertTrue(); + 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) { + try { + sensor.off(string, ""); + } catch (error) { + console.info(error); + expect(true).assertTrue(); + 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 onSensorCallback(data) { + console.info('SensorJsTest007 on error'); + expect(false).assertTrue(); + done(); + } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, onSensorCallback); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, onSensorCallback); + setTimeout(()=>{ + expect(true).assertTrue(); + done(); + }, 500); + }) + + /* + * @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 onSensorCallback(data) { + console.info('SensorJsTest008 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.off(1000000, onSensorCallback); + } catch (error) { + console.info(error); + expect(true).assertTrue(); + done(); + } + }) + + /* + * @tc.name:SensorJsTest009 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest009", 0, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback2); + setTimeout(()=>{ + console.info('----------------------SensorJsTest009 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION); + console.info('----------------------SensorJsTest009 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:SensorJsTest010 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest010", 0, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback2); + setTimeout(()=>{ + console.info('----------------------SensorJsTest010 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + console.info('----------------------SensorJsTest010 off end---------------------------'); + }, 500); + setTimeout(()=>{ + console.info('----------------------SensorJsTest010 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback2); + console.info('----------------------SensorJsTest010 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:SensorJsTest011 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest011", 0, async function (done) { + console.info('----------------------SensorJsTest011---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback, {'interval': 100000000}); + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback2); + setTimeout(()=>{ + console.info('----------------------SensorJsTest011 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION); + console.info('----------------------SensorJsTest011 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:SensorJsTest012 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest012", 0, async function (done) { + console.info('----------------------SensorJsTest012---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback, {'interval': 100000000}); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback2, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + console.info('----------------------SensorJsTest012 off end---------------------------'); + }, 500); + setTimeout(()=>{ + console.info('----------------------SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback2); + console.info('----------------------SensorJsTest012 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:SensorJsTest013 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: Issue Number + */ + it("SensorJsTest013", 0, async function (done) { + console.info('----------------------SensorJsTest013---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback, {'interval': 100000000}); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback2, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------SensorJsTest013 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION); + console.info('----------------------SensorJsTest013 off end---------------------------'); + done(); + }, 1000); + }) +}) \ No newline at end of file -- Gitee