diff --git a/sensors/BUILD.gn b/sensors/BUILD.gn old mode 100755 new mode 100644 index ad043b1e2ed7f7bc794c5e063d59f5cb92187a85..198c9d65b4d75ba01722365e4e2b1445e89c0624 --- a/sensors/BUILD.gn +++ b/sensors/BUILD.gn @@ -15,17 +15,10 @@ import("//build/ohos_var.gni") group("sensor") { testonly = true - if (device_name == "m40") { - if (is_standard_system) { - deps = [ "sensor_standard:sensor_js_test" ] - } - } else if (device_name == "rk3568") { - if (is_standard_system) { - deps = [ "sensor_standard:sensor_js_test" ] - } - } else { - if (is_standard_system) { - deps = [ "sensor_standard:sensor_js_test" ] - } + if (is_standard_system) { + deps = [ + "miscdevice_standard:miscdevice_js_test", + "sensor_standard:sensor_js_test", + ] } } diff --git a/sensors/miscdevice_standard/src/main/config.json b/sensors/miscdevice_standard/src/main/config.json old mode 100755 new mode 100644 index 764f279caee28996e84cbbece7d224b097c2e836..8bebd310db83135aa6bf5cbc3bcfc7ede9d21550 --- a/sensors/miscdevice_standard/src/main/config.json +++ b/sensors/miscdevice_standard/src/main/config.json @@ -55,6 +55,12 @@ "autoDesignWidth": false } } + ], + "reqPermissions": [ + { + "name": "ohos.permission.VIBRATE", + "reason": "need use ohos.permission.VIBRATE" + } ] } } diff --git a/sensors/miscdevice_standard/src/main/js/default/test/List.test.js b/sensors/miscdevice_standard/src/main/js/default/test/List.test.js old mode 100755 new mode 100644 index 7986a5a95ac9bc80aa67cdf3d708622001132aa0..ff9a1be24f702141edbadae64154b31daf8576a3 --- a/sensors/miscdevice_standard/src/main/js/default/test/List.test.js +++ b/sensors/miscdevice_standard/src/main/js/default/test/List.test.js @@ -13,4 +13,5 @@ * limitations under the License. */ -require('./Vibrator.test.js') +require('./Vibrator_old.test.js') +require('./Vibrator_new.test.js') diff --git a/sensors/miscdevice_standard/src/main/js/default/test/Subscribe_vibrate.js b/sensors/miscdevice_standard/src/main/js/default/test/Vibrator_new.test.js similarity index 50% rename from sensors/miscdevice_standard/src/main/js/default/test/Subscribe_vibrate.js rename to sensors/miscdevice_standard/src/main/js/default/test/Vibrator_new.test.js index c54cfc57afd772934e571c596b800d12a05217f2..8e114c8743e7882b560453fcb3f262b5633fd303 100644 --- a/sensors/miscdevice_standard/src/main/js/default/test/Subscribe_vibrate.js +++ b/sensors/miscdevice_standard/src/main/js/default/test/Vibrator_new.test.js @@ -13,9 +13,10 @@ * limitations under the License. */ import vibrator from '@system.vibrator'; + import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' -describe("VibratorJsTest_misc_1", function () { +describe("VibratorJsTest_misc_2", function () { beforeAll(function () { /* @@ -54,183 +55,175 @@ describe("VibratorJsTest_misc_1", function () { let errMessage; /* - * @tc.name:VibratorJsTest0001 + * @tc.name:SubVibratorJsTest0001 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: SR000H0ALK, AR000H0ALM + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0190 */ - it("VibratorJsTest0001", 0, async function (done) { - console.info('----------------------VibratorJsTest0001---------------------------'); + it("SubVibratorJsTest0001", FUNCTION|MEDIUMTEST|LEVEL0, async function (done) { + console.info('----------------------SubVibratorJsTest0001---------------------------'); vibrator.vibrate({ mode: 'long', success: function () { - console.info("VibratorJsTest0001 success"); + console.info("SubVibratorJsTest0001 success"); done(); }, fail: function (data, code) { - console.log("VibratorJsTest0001 is failed, data: " + data + ", code: " + code); + console.log("SubVibratorJsTest0001 is failed, data: " + data + ", code: " + code); expect(false).assertTrue(); }, complete: function () { - console.log('VibratorJsTest0001 is completed'); + console.log('SubVibratorJsTest0001 is completed'); } }); }) /* - * @tc.name:VibratorJsTest0002 + * @tc.name:SubVibratorJsTest0002 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: SR000H0ALK, AR000H0ALM + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0200 */ - it("VibratorJsTest0002", 0, async function (done) { - console.info('----------------------VibratorJsTest0002---------------------------'); + it("SubVibratorJsTest0002", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------SubVibratorJsTest0002---------------------------'); vibrator.vibrate({ mode: 'short', success: function () { - console.info("VibratorJsTest0002 success"); + console.info("SubVibratorJsTest0002 success"); done(); }, fail: function (data, code) { - console.log("VibratorJsTest0002 is failed, data: " + data + ", code: " + code); + console.log("SubVibratorJsTest0002 is failed, data: " + data + ", code: " + code); expect(false).assertTrue(); }, complete: function () { - console.log('VibratorJsTest0002 is completed'); + console.log('SubVibratorJsTest0002 is completed'); } }); }) /* - * @tc.name:VibratorJsTest0003 + * @tc.name:SubVibratorJsTest0003 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: SR000H0ALK, AR000H0ALM + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0210 */ - it("VibratorJsTest0003", 0, async function (done) { - console.info('----------------------VibratorJsTest0003---------------------------'); + it("SubVibratorJsTest0003", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------SubVibratorJsTest0003---------------------------'); vibrator.vibrate({ mode: 'short', success: function () { - console.info("VibratorJsTest0003 success"); + console.info("SubVibratorJsTest0003 success"); done(); }, fail: function (data, code) { - console.error('VibratorJsTest0003 failed. Code: ' + code + '; Data: ' + data); + console.error('SubVibratorJsTest0003 failed. Code: ' + code + '; Data: ' + data); expect(false).assertTrue(); }, }); }) /* - * @tc.name:VibratorJsTest0004 + * @tc.name:SubVibratorJsTest0004 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: SR000H0ALK, AR000H0ALM + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0220 */ - it("VibratorJsTest0004", 0, async function (done) { - console.info('----------------------VibratorJsTest0004---------------------------'); + it("SubVibratorJsTest0004", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------SubVibratorJsTest0004---------------------------'); vibrator.vibrate({ mode: 'short', success: function () { - console.info("VibratorJsTest0004 success"); + console.info("SubVibratorJsTest0004 success"); done(); }, }); }) /* - * @tc.name:VibratorJsTest0005 + * @tc.name:SubVibratorJsTest0005 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: SR000H0ALK, AR000H0ALM + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0230 */ - it("VibratorJsTest0005", 0, async function (done) { - console.info('----------------------VibratorJsTest0005---------------------------'); + it("SubVibratorJsTest0005", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------SubVibratorJsTest0005---------------------------'); vibrator.vibrate({ success: function () { - console.info("VibratorJsTest0005 success"); + console.info("SubVibratorJsTest0005 success"); done(); }, fail: function (data, code) { - console.error('VibratorJsTest0005 failed. Code: ' + code + '; Data: ' + data); + console.error('SubVibratorJsTest0005 failed. Code: ' + code + '; Data: ' + data); expect(false).assertTrue(); }, }); }) /* - * @tc.name:VibratorJsTest0006 + * @tc.name:SubVibratorJsTest0006 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: SR000H0ALK, AR000H0ALM + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0240 */ - it("VibratorJsTest0006", 0, async function (done) { - console.info('----------------------VibratorJsTest0006---------------------------'); + it("SubVibratorJsTest0006", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------SubVibratorJsTest0006---------------------------'); vibrator.vibrate({ mode: 'long', inInvalid: 2, success: function () { - console.info("VibratorJsTest0006 success"); + console.info("SubVibratorJsTest0006 success"); done(); }, fail: function (data, code) { - console.error('VibratorJsTest0006 failed. Code: ' + code + '; Data: ' + data); + console.error('SubVibratorJsTest0006 failed. Code: ' + code + '; Data: ' + data); expect(false).assertTrue(); }, }); }) /* - * @tc.name:VibratorJsTest0007 + * @tc.name:SubVibratorJsTest0007 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: SR000H0ALK, AR000H0ALM + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0250 */ - it("VibratorJsTest0007", 0, async function (done) { - console.info('----------------------VibratorJsTest0007---------------------------'); + it("SubVibratorJsTest0007", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------SubVibratorJsTest0007---------------------------'); try { vibrator.vibrate({ mode: 'short', success: function () { - console.info("VibratorJsTest0007 success"); + console.info("SubVibratorJsTest0007 success"); expect(false).assertTrue(); done(); }, }, 25); } catch (error) { errMessage = error.toString().slice(39); - console.info('VibratorJsTest0007 error:' + error); + console.info('SubVibratorJsTest0007 error:' + error); expect(errMessage).assertEqual(errMessages[0]); done(); } }) /* - * @tc.name:VibratorJsTest0008 + * @tc.name:SubVibratorJsTest0008 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: SR000H0ALK, AR000H0ALM + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0260 */ - it("VibratorJsTest0008", 0, async function (done) { - console.info('----------------------VibratorJsTest0008---------------------------'); + it("SubVibratorJsTest0008", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------SubVibratorJsTest0008---------------------------'); vibrator.vibrate({ mode: 'short', success: function () { - console.info("VibratorJsTest0008 success"); + console.info("SubVibratorJsTest0008 success"); }, fail: function (data, code) { - console.error('VibratorJsTest0008 failed. Code: ' + code + '; Data: ' + data); + console.error('SubVibratorJsTest0008 failed. Code: ' + code + '; Data: ' + data); expect(false).assertTrue(); }, }); vibrator.vibrate({ mode: 'short', success: function () { - console.info("VibratorJsTest0008_1 success"); + console.info("SubVibratorJsTest0008_1 success"); }, fail: function (data, code) { - console.error('VibratorJsTest0008_1 failed. Code: ' + code + '; Data: ' + data); + console.error('SubVibratorJsTest0008_1 failed. Code: ' + code + '; Data: ' + data); expect(false).assertTrue(); }, }); @@ -240,54 +233,34 @@ describe("VibratorJsTest_misc_1", function () { }) /* - * @tc.name:VibratorJsTest0009 - * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: SR000H0ALK, AR000H0ALM - */ - it("VibratorJsTest0009", 0, async function (done) { - console.info('----------------------VibratorJsTest0009---------------------------'); - try { - vibrator.vibrate('xxx', done); - } catch (error) { - console.info('VibratorJsTest0009 error:' + error); - errMessage = error.toString().slice(68); - expect(errMessage).assertEqual(errMessages[1]); - done(); - } - }) - - /* - * @tc.name:VibratorJsTest0010 + * @tc.name:SubVibratorJsTest0009 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: SR000H0ALK, AR000H0ALM + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0270 */ - it("VibratorJsTest0010", 0, async function (done) { - console.info('----------------------VibratorJsTest0010---------------------------'); + it("SubVibratorJsTest0009", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------SubVibratorJsTest0009---------------------------'); try { - vibrator.vibrate(done); + vibrator.vibrate(); } catch (error) { errMessage = error.toString().slice(7); - console.info('VibratorJsTest0010 error:' + error); + console.info('SubVibratorJsTest0009 error:' + error); expect(errMessage).assertEqual(errMessages[2]); done(); } }) /* - * @tc.name:VibratorJsTest0011 + * @tc.name:SubVibratorJsTest0010 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: SR000H0ALK, AR000H0ALM + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0280 */ - it("VibratorJsTest0011", 0, async function (done) { - console.info('----------------------VibratorJsTest0011---------------------------'); + it("SubVibratorJsTest0010", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------SubVibratorJsTest0010---------------------------'); try { vibrator.vibrate({ mode: 'short', success: function () { - console.info("VibratorJsTest0011 success"); + console.info("SubVibratorJsTest0010 success"); expect(false).assertTrue(); done(); }, @@ -295,7 +268,7 @@ describe("VibratorJsTest_misc_1", function () { }, 25); } catch (error) { errMessage = error.toString().slice(39); - console.info('VibratorJsTest0011 error:' + error); + console.info('SubVibratorJsTest0010 error:' + error); expect(errMessage).assertEqual(errMessages[3]); done(); } diff --git a/sensors/miscdevice_standard/src/main/js/default/test/Vibrator.test.js b/sensors/miscdevice_standard/src/main/js/default/test/Vibrator_old.test.js old mode 100755 new mode 100644 similarity index 84% rename from sensors/miscdevice_standard/src/main/js/default/test/Vibrator.test.js rename to sensors/miscdevice_standard/src/main/js/default/test/Vibrator_old.test.js index dc05d2d99a4f226b0b4b50ec59d233378af5efe3..14762c5b14015e247a8e28900ead6f53aa0365ab --- a/sensors/miscdevice_standard/src/main/js/default/test/Vibrator.test.js +++ b/sensors/miscdevice_standard/src/main/js/default/test/Vibrator_old.test.js @@ -16,7 +16,7 @@ import vibrator from '@ohos.vibrator' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' -describe("VibratorJsTest_misc_2", function () { +describe("VibratorJsTest_misc_1", function () { beforeAll(function () { /* @@ -52,10 +52,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest001 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0010 */ - it("VibratorJsTest001", 0, async function (done) { + it("VibratorJsTest001", FUNCTION|MEDIUMTEST|LEVEL0, async function (done) { function vibrateCallback(error) { if (error) { console.info('VibratorJsTest001 vibrator error'); @@ -74,10 +73,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest002 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0020 */ - it("VibratorJsTest002", 0, async function (done) { + it("VibratorJsTest002", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { function vibrateCallback(error) { if (error) { console.info('VibratorJsTest002 vibrator success'); @@ -96,10 +94,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest003 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0030 */ - it("VibratorJsTest003", 0, async function (done) { + it("VibratorJsTest003", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { function vibrateCallback(error) { if (error) { console.info('VibratorJsTest003 vibrator success'); @@ -118,10 +115,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest004 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0040 */ - it("VibratorJsTest004", 0, async function (done) { + it("VibratorJsTest004", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { function vibrateCallback(error) { if (error) { console.info('VibratorJsTest004 vibrator error'); @@ -140,10 +136,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest005 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0050 */ - it("VibratorJsTest005", 0, async function (done) { + it("VibratorJsTest005", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { function vibrateCallback(error) { if (error) { console.info('VibratorJsTest005 vibrator success'); @@ -162,10 +157,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest006 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0060 */ - it("VibratorJsTest006", 0, async function (done) { + it("VibratorJsTest006", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { function vibrateCallback(error) { if (error) { console.info('VibratorJsTest006 vibrator success'); @@ -184,10 +178,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest007 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0070 */ - it("VibratorJsTest007", 0, async function (done) { + it("VibratorJsTest007", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { function vibrateCallback(error) { if (error) { console.info('VibratorJsTest007 vibrator error'); @@ -206,10 +199,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest008 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0080 */ - it("VibratorJsTest008", 0, async function (done) { + it("VibratorJsTest008", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { function vibrateCallback(error) { if (error) { console.info('VibratorJsTest008 stop error'); @@ -228,10 +220,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest009 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0090 */ - it("VibratorJsTest009", 0, async function (done) { + it("VibratorJsTest009", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { console.info('----------------------VibratorJsTest001---------------------------'); function stopPromise() { return new Promise((resolve, reject) => { @@ -282,10 +273,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest010 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0100 */ - it("VibratorJsTest010", 0, async function (done) { + it("VibratorJsTest010", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { function vibrateCallback(error) { if (error) { console.info('VibratorJsTest010 stop success'); @@ -304,10 +294,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest011 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0110 */ - it("VibratorJsTest011", 0, async function (done) { + it("VibratorJsTest011", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { vibrator.vibrate(1000).then(() => { console.log("VibratorJsTest011 vibrate success"); expect(true).assertTrue(); @@ -326,10 +315,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest012 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0120 */ - it("VibratorJsTest012", 0, async function (done) { + it("VibratorJsTest012", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { vibrator.vibrate(-1).then(() => { console.log("VibratorJsTest012 vibrate error"); expect(false).assertTrue(); @@ -348,10 +336,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest013 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0130 */ - it("VibratorJsTest013", 0, async function (done) { + it("VibratorJsTest013", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { vibrator.vibrate(1800000 + 1).then(() => { console.log("VibratorJsTest013 vibrate error"); expect(false).assertTrue(); @@ -370,10 +357,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest014 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0140 */ - it("VibratorJsTest014", 0, async function (done) { + it("VibratorJsTest014", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { vibrator.vibrate(vibrator.EffectId.EFFECT_CLOCK_TIMER).then(() => { console.log("VibratorJsTest014 vibrate success"); expect(true).assertTrue(); @@ -392,10 +378,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest015 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0150 */ - it("VibratorJsTest015", 0, async function (done) { + it("VibratorJsTest015", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { vibrator.vibrate("").then(() => { console.log("VibratorJsTest015 vibrate error"); expect(false).assertTrue(); @@ -414,10 +399,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest016 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0160 */ - it("VibratorJsTest016", 0, async function (done) { + it("VibratorJsTest016", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { vibrator.stop("").then(() => { console.log("VibratorJsTest016 stop error"); expect(false).assertTrue(); @@ -436,10 +420,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest017 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0170 */ - it("VibratorJsTest017", 0, async function (done) { + it("VibratorJsTest017", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { vibrator.stop("preset").then(() => { console.log("VibratorJsTest017 off success"); expect(true).assertTrue(); @@ -458,10 +441,9 @@ describe("VibratorJsTest_misc_2", function () { /* * @tc.name:VibratorJsTest018 * @tc.desc:verify app info is not null - * @tc.type: FUNC - * @tc.require: Issue Number + * @tc.number:SUB_SensorSystem_Vibrator_JsTest_0180 */ - it("VibratorJsTest018", 0, async function (done) { + it("VibratorJsTest018", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { function stopPromise() { return new Promise((resolve, reject) => { vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_TIME).then(() => { diff --git a/sensors/sensor_standard/src/main/config.json b/sensors/sensor_standard/src/main/config.json index 764f279caee28996e84cbbece7d224b097c2e836..783f74eaeebc1f1ba0476967950dc86ec35b407e 100644 --- a/sensors/sensor_standard/src/main/config.json +++ b/sensors/sensor_standard/src/main/config.json @@ -55,6 +55,16 @@ "autoDesignWidth": false } } + ], + "reqPermissions": [ + { + "name": "ohos.permission.ACCELEROMETER", + "reason": "need use ohos.permission.ACCELEROMETER" + }, + { + "name": "ohos.permission.GYROSCOPE", + "reason": "need use ohos.permission.GYROSCOPE" + } ] } } diff --git a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Gravity.js b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Gravity.js old mode 100755 new mode 100644 index d2bb819c85228ca3516d2f149c40f3d9fc59e88a..0a8a6189e45db55407b3020a9c421d0711e4958b --- a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Gravity.js +++ b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Gravity.js @@ -1,130 +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_sensor_9", 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.number: SUB_SensorsSystem_Gravity_JSTest_0010 - * @tc.name: SensorGravityJSTest001 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Gravity_JSTest_0010", 0, async function (done) { - console.info('----------------------SUB_SensorsSystem_Gravity_JSTest_0010---------------------------'); - function offPromise() { - return new Promise((resolve, reject) => { - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, (error) => { - if (error) { - console.info('SensorGravityJSTest001 off error'); - expect(false).assertTrue(); - console.info('setTimeout ..start') - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorGravityJSTest001 off success'); - expect(true).assertTrue(); - setTimeout(() => { - resolve(); - }, 500); - } - }, 1000) - }) - } - - let promise = new Promise((resolve, reject) => { - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function (error, data) { - if (error) { - console.info('SensorGravityJSTest001 on error'); - expect(false).assertTrue(); - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorGravityJSTest001 on success, x: ' + data.x + "y: " + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - setTimeout(() => { - resolve(); - }, 500); - } - }); - }) - - await promise.then(() => { - return offPromise(); - }, () => { - console.info("SensorGravityJSTest001 reject"); - }) - done(); - }) - - /* - * @tc.number: SUB_SensorsSystem_Gravity_JSTest_0050 - * @tc.name: SensorGravityJSTest005 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Gravity_JSTest_0050", 0, async function (done) { - function onceSensorCallback(error, data) { - if (error) { - console.info('SensorGravityJSTest005 once error'); - expect(false).assertTrue(); - } else { - console.info('SensorGravityJSTest005 on success, x: ' + data.x + "y: " + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - } - setTimeout(() => { - done(); - }, 500); - } - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, onceSensorCallback); - }) -}) +/* + * 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_sensor_9", 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') + }) + + let errMessages = ['The number of parameters is not valid', 'Should subscribe first', + 'string is not defined']; + + let errMessage; + + /* + * @tc.name:gravity_SensorJsTest001 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0010 + */ + it("gravity_SensorJsTest001", FUNCTION|MEDIUMTEST|LEVEL0, async function (done) { + console.info('----------------------gravity_SensorJsTest001---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + setTimeout(()=>{ + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY); + done(); + }, 500); + }) + + /* + * @tc.name:gravity_SensorJsTest002 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0020 + */ + it("gravity_SensorJsTest002", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------gravity_SensorJsTest002---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------gravity_SensorJsTest002 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY); + console.info('----------------------gravity_SensorJsTest002 off end---------------------------'); + done(); + }, 500); + }) + + /* + * @tc.name:gravity_SensorJsTest003 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0030 + */ + it("gravity_SensorJsTest003", FUNCTION|MEDIUMTEST|LEVEL3, function (done) { + console.info('----------------------gravity_SensorJsTest003---------------------------'); + function onSensorCallback(data) { + console.info('gravity_SensorJsTest003 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, onSensorCallback, {'interval': 100000000}, 5); + } catch (error) { + console.info('gravity_SensorJsTest003 error' +error); + errMessage = error.toString().slice(12, 49); + expect(errMessage).assertEqual(errMessages[0]); + done(); + } + }) + + /* + * @tc.name:gravity_SensorJsTest004 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0040 + */ + it("gravity_SensorJsTest004", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + setTimeout(()=>{ + expect(true).assertTrue(); + done(); + }, 500); + }) + + /* + * @tc.name:gravity_SensorJsTest005 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0050 + */ + it("gravity_SensorJsTest005", FUNCTION|MEDIUMTEST|LEVEL3, function (done) { + function onceSensorCallback(data) { + console.info('gravity_SensorJsTest005 on error'); + expect(false).assertTrue(); + done(); + } + try{ + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, onceSensorCallback, 5); + } catch (error) { + console.info('gravity_SensorJsTest005 error' +error); + errMessage = error.toString().slice(14, 51); + expect(errMessage).assertEqual(errMessages[0]); + done(); + } + }) + + /* + * @tc.name:gravity_SensorJsTest006 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0060 + */ + it("gravity_SensorJsTest006", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + try { + sensor.off(string, ""); + } catch (error) { + console.info('gravity_SensorJsTest006 error' + error); + errMessage = error.toString().slice(16, 40); + expect(errMessage).assertEqual(errMessages[2]); + done(); + } + }) + + /* + * @tc.name:gravity_SensorJsTest007 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0070 + */ + it("gravity_SensorJsTest007", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + function onSensorCallback(data) { + console.info('gravity_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:gravity_SensorJsTest008 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0080 + */ + it("gravity_SensorJsTest008", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + function onSensorCallback(data) { + console.info('gravity_SensorJsTest008 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.off(1000000, onSensorCallback); + } catch (error) { + console.info('gravity_SensorJsTest008 error' + error); + errMessage = error.toString().slice(13, 35); + expect(errMessage).assertEqual(errMessages[1]); + done(); + } + }) + + /* + * @tc.name:gravity_SensorJsTest009 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0090 + */ + it("gravity_SensorJsTest009", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2); + setTimeout(()=>{ + console.info('----------------------gravity_SensorJsTest009 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY); + console.info('----------------------gravity_SensorJsTest009 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:gravity_SensorJsTest010 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0100 + */ + it("gravity_SensorJsTest010", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2); + setTimeout(()=>{ + console.info('----------------------gravity_SensorJsTest010 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + console.info('----------------------gravity_SensorJsTest010 off end---------------------------'); + }, 500); + setTimeout(()=>{ + console.info('----------------------gravity_SensorJsTest010 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2); + console.info('----------------------gravity_SensorJsTest010 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:gravity_SensorJsTest011 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0110 + */ + it("gravity_SensorJsTest011", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------gravity_SensorJsTest011---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback, {'interval': 100000000}); + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2); + setTimeout(()=>{ + console.info('----------------------gravity_SensorJsTest011 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY); + console.info('----------------------gravity_SensorJsTest011 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:gravity_SensorJsTest012 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0120 + */ + it("gravity_SensorJsTest012", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------gravity_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('----------------------gravity_SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback); + console.info('----------------------gravity_SensorJsTest012 off end---------------------------'); + }, 500); + setTimeout(()=>{ + console.info('----------------------gravity_SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, callback2); + console.info('----------------------gravity_SensorJsTest012 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:gravity_SensorJsTest013 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0130 + */ + it("gravity_SensorJsTest013", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------gravity_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('----------------------gravity_SensorJsTest013 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY); + console.info('----------------------gravity_SensorJsTest013 off end---------------------------'); + done(); + }, 1000); + }) +}) \ No newline at end of file diff --git a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_MagneticField.js b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_MagneticField.js new file mode 100644 index 0000000000000000000000000000000000000000..27f700ba4c610ddb57b25ef6d2cf6bc0c50d784c --- /dev/null +++ b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_MagneticField.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_sensor_15", 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') + }) + + let errMessages = ['The number of parameters is not valid', 'Should subscribe first', + 'string is not defined']; + + let errMessage; + + /* + * @tc.name:magnetic_SensorJsTest001 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0010 + */ + it("magnetic_SensorJsTest001", FUNCTION|MEDIUMTEST|LEVEL0, async function (done) { + console.info('----------------------magnetic_SensorJsTest001---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback); + setTimeout(()=>{ + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD); + done(); + }, 500); + }) + + /* + * @tc.name:magnetic_SensorJsTest002 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0020 + */ + it("magnetic_SensorJsTest002", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------magnetic_SensorJsTest002---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------magnetic_SensorJsTest002 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD); + console.info('----------------------magnetic_SensorJsTest002 off end---------------------------'); + done(); + }, 500); + }) + + /* + * @tc.name:magnetic_SensorJsTest003 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0030 + */ + it("magnetic_SensorJsTest003", FUNCTION|MEDIUMTEST|LEVEL3, function (done) { + console.info('----------------------magnetic_SensorJsTest003---------------------------'); + function onSensorCallback(data) { + console.info('magnetic_SensorJsTest003 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, onSensorCallback, {'interval': 100000000}, 5); + } catch (error) { + console.info('magnetic_SensorJsTest003 error' +error); + errMessage = error.toString().slice(12, 49); + expect(errMessage).assertEqual(errMessages[0]); + done(); + } + }) + + /* + * @tc.name:magnetic_SensorJsTest004 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0040 + */ + it("magnetic_SensorJsTest004", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback); + setTimeout(()=>{ + expect(true).assertTrue(); + done(); + }, 500); + }) + + /* + * @tc.name:magnetic_SensorJsTest005 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0050 + */ + it("magnetic_SensorJsTest005", FUNCTION|MEDIUMTEST|LEVEL3, function (done) { + function onceSensorCallback(data) { + console.info('magnetic_SensorJsTest005 on error'); + expect(false).assertTrue(); + done(); + } + try{ + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, onceSensorCallback, 5); + } catch (error) { + console.info('magnetic_SensorJsTest005 error' +error); + errMessage = error.toString().slice(14, 51); + expect(errMessage).assertEqual(errMessages[0]); + done(); + } + }) + + /* + * @tc.name:magnetic_SensorJsTest006 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0060 + */ + it("magnetic_SensorJsTest006", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + try { + sensor.off(string, ""); + } catch (error) { + console.info('magnetic_SensorJsTest006 error' + error); + errMessage = error.toString().slice(16, 40); + expect(errMessage).assertEqual(errMessages[2]); + done(); + } + }) + + /* + * @tc.name:magnetic_SensorJsTest007 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0070 + */ + it("magnetic_SensorJsTest007", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + function onSensorCallback(data) { + console.info('magnetic_SensorJsTest007 on error'); + expect(false).assertTrue(); + done(); + } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, onSensorCallback); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, onSensorCallback); + setTimeout(()=>{ + expect(true).assertTrue(); + done(); + }, 500); + }) + + /* + * @tc.name:magnetic_SensorJsTest008 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0080 + */ + it("magnetic_SensorJsTest008", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + function onSensorCallback(data) { + console.info('magnetic_SensorJsTest008 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.off(1000000, onSensorCallback); + } catch (error) { + console.info('magnetic_SensorJsTest008 error' + error); + errMessage = error.toString().slice(13, 35); + expect(errMessage).assertEqual(errMessages[1]); + done(); + } + }) + + /* + * @tc.name:magnetic_SensorJsTest009 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0090 + */ + it("magnetic_SensorJsTest009", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback2); + setTimeout(()=>{ + console.info('----------------------magnetic_SensorJsTest009 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD); + console.info('----------------------magnetic_SensorJsTest009 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:magnetic_SensorJsTest010 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0100 + */ + it("magnetic_SensorJsTest010", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback2); + setTimeout(()=>{ + console.info('----------------------magnetic_SensorJsTest010 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback); + console.info('----------------------magnetic_SensorJsTest010 off end---------------------------'); + }, 500); + setTimeout(()=>{ + console.info('----------------------magnetic_SensorJsTest010 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback2); + console.info('----------------------magnetic_SensorJsTest010 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:magnetic_SensorJsTest011 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0110 + */ + it("magnetic_SensorJsTest011", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------magnetic_SensorJsTest011---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback, {'interval': 100000000}); + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback2); + setTimeout(()=>{ + console.info('----------------------magnetic_SensorJsTest011 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD); + console.info('----------------------magnetic_SensorJsTest011 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:magnetic_SensorJsTest012 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0120 + */ + it("magnetic_SensorJsTest012", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------magnetic_SensorJsTest012---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback, {'interval': 100000000}); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback2, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------magnetic_SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback); + console.info('----------------------magnetic_SensorJsTest012 off end---------------------------'); + }, 500); + setTimeout(()=>{ + console.info('----------------------magnetic_SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback2); + console.info('----------------------magnetic_SensorJsTest012 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:magnetic_SensorJsTest013 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_MAGNETIC_FIELD_JsTest_0130 + */ + it("magnetic_SensorJsTest013", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------magnetic_SensorJsTest013---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback, {'interval': 100000000}); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, callback2, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------magnetic_SensorJsTest013 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD); + console.info('----------------------magnetic_SensorJsTest013 off end---------------------------'); + done(); + }, 1000); + }) +}) \ No newline at end of file diff --git a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Magnetic_Field.js b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Magnetic_Field.js deleted file mode 100755 index 286a29762cb7ad459990031c74fa8c6d11f0b97b..0000000000000000000000000000000000000000 --- a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Magnetic_Field.js +++ /dev/null @@ -1,610 +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. - */ -import sensor from '@ohos.sensor' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -describe("SensorJsTest_sensor_15", 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.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0010 - * @tc.name: SensorMagneticFieldJSTest001 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0010", 0, async function (done) { - console.info('----------------------SUB_SensorsSystem_Magnetic_Field_JSTest_0010---------------------------'); - function offPromise() { - return new Promise((resolve, reject) => { - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, (error) => { - if (error) { - console.info('SensorMagneticFieldJSTest001 off error'); - expect(false).assertTrue(); - console.info('setTimeout ..start') - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest001 off success'); - expect(true).assertTrue(); - setTimeout(() => { - resolve(); - }, 500); - } - }, 1000) - }) - } - - let promise = new Promise((resolve, reject) => { - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, function (error, data) { - if (error) { - console.info('SensorMagneticFieldJSTest001 on error'); - expect(false).assertTrue(); - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest001 on success, x: ' + data.x + "y: " - + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - setTimeout(() => { - resolve(); - }, 500); - } - }); - }) - - await promise.then(() => { - return offPromise(); - }, () => { - console.info("SensorMagneticFieldJSTest001 reject"); - }) - done(); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0020 - * @tc.name: SensorMagneticFieldJSTest002 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0020", 0, async function (done) { - console.info('----------------------SUB_SensorsSystem_Magnetic_Field_JSTest_0020---------------------------'); - function onSensorCallback(error, data) { - if (error) { - console.info('SensorMagneticFieldJSTest002 on success'); - expect(true).assertTrue(); - } else { - console.info('SensorMagneticFieldJSTest002 on error'); - expect(false).assertTrue(); - } - setTimeout(() => { - done(); - }, 500); - } - sensor.on(-1, onSensorCallback); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0030 - * @tc.name: SensorMagneticFieldJSTest003 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0030", 0, async function (done) { - console.info('----------------------SUB_SensorsSystem_Magnetic_Field_JSTest_0030---------------------------'); - function offPromise() { - return new Promise((resolve, reject) => { - sensor.off(6, (error) => { - if (error) { - console.info('SensorMagneticFieldJSTest003 off error'); - expect(false).assertTrue(); - setTimeout((err) => { - done(); - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest003 off success'); - expect(true).assertTrue(); - setTimeout(() => { - done(); - resolve(); - }, 500); - } - }, 1000) - }) - } - - let promise = new Promise((resolve, reject) => { - sensor.on(6, function (error, data) { - if (error) { - console.info('SensorMagneticFieldJSTest003 on error'); - expect(false).assertTrue(); - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest003 on success x: ' + data.x + "y: " - + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - setTimeout(() => { - resolve(); - }, 500); - } - }, { 'interval': 200000000 }); - }) - - await promise.then(() => { - return offPromise(); - }, () => { - console.info("SensorMagneticFieldJSTest003 reject"); - }) - done(); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0040 - * @tc.name: SensorMagneticFieldJSTest004 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0040", 0, function () { - console.info('----------------------SensorMagneticFieldJSTest004---------------------------'); - sensor.on(6, function () { }, { 'interval': 100000000 }, 5); - expect(true).assertTrue(); - console.info('----------------------SensorMagneticFieldJSTest004--------------------------- end'); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0050 - * @tc.name: SensorMagneticFieldJSTest005 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0050", 0, async function (done) { - function onceSensorCallback(error, data) { - if (error) { - console.info('SensorMagneticFieldJSTest005 once error'); - expect(false).assertTrue(); - } else { - console.info('SensorMagneticFieldJSTest005 once success x: ' + data.x + "y: " - + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - } - setTimeout(() => { - done(); - }, 500); - } - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD, onceSensorCallback); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0060 - * @tc.name: SensorMagneticFieldJSTest006 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0060", 0, async function (done) { - function onceSensorCallback(error, data) { - if (error) { - console.info('SensorMagneticFieldJSTest006 on success'); - expect(true).assertTrue(); - } else { - console.info('SensorMagneticFieldJSTest006 on error'); - expect(false).assertTrue(); - } - setTimeout(() => { - done(); - }, 500); - } - sensor.once(-1, onceSensorCallback); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0070 - * @tc.name: SensorMagneticFieldJSTest007 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0070", 0, function () { - sensor.once(6, function () { }, 5); - expect(true).assertTrue(); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0080 - * @tc.name: SensorMagneticFieldJSTest008 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0080", 0, async function (done) { - function offCallback(error) { - if (error) { - console.info('SensorMagneticFieldJSTest008 off success'); - expect(true).assertTrue(); - } else { - console.info('SensorMagneticFieldJSTest008 off error'); - expect(false).assertTrue(); - } - setTimeout(() => { - done(); - }, 500); - } - sensor.off(-1, offCallback); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0090 - * @tc.name: SensorMagneticFieldJSTest009 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0090", 0, async function (done) { - function offCallback(error) { - if (error) { - console.info('SensorMagneticFieldJSTest009 off success'); - expect(true).assertTrue(); - } else { - console.info('SensorMagneticFieldJSTest009 off error'); - expect(false).assertTrue(); - } - setTimeout(() => { - done(); - }, 500); - } - sensor.off(6, offCallback); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0100 - * @tc.name: SensorMagneticFieldJSTest010 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0100", 0, async function (done) { - function offCallback(error) { - if (error) { - console.info('SensorMagneticFieldJSTest010 off success'); - expect(true).assertTrue(); - } else { - console.info('SensorMagneticFieldJSTest010 off error'); - expect(false).assertTrue(); - } - setTimeout(() => { - done(); - }, 500); - } - sensor.off(1000000, offCallback); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0110 - * @tc.name: SensorMagneticFieldJSTest011 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0110", 0, async function (done) { - function onceSensorCallback(error, data) { - if (error) { - console.info('SensorMagneticFieldJSTest011 once success'); - expect(true).assertTrue(); - } else { - console.info('SensorMagneticFieldJSTest011 once error'); - expect(false).assertTrue(); - } - setTimeout(() => { - done(); - }, 500); - } - sensor.once(1000000, onceSensorCallback); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0120 - * @tc.name: SensorMagneticFieldJSTest012 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0120", 0, async function (done) { - function onCallback(error) { - if (error) { - console.info('SensorMagneticFieldJSTest012 on success'); - expect(true).assertTrue(); - } else { - console.info('SensorMagneticFieldJSTest012 on error'); - expect(false).assertTrue(); - } - setTimeout(() => { - done(); - }, 500); - } - sensor.on(1000000, onCallback); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0130 - * @tc.name: SensorMagneticFieldJSTest013 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0130", 0, function () { - sensor.off(6, 5); - expect(true).assertTrue(); - }) - - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0140 - * @tc.name: SensorMagneticFieldJSTest014 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0140", 0, async function (done) { - console.info('----------------------SUB_SensorsSystem_Magnetic_Field_JSTest_0140---------------------------'); - function offPromise2() { - return new Promise((resolve, reject) => { - sensor.off(6, (error) => { - if (error) { - console.info('SensorMagneticFieldJSTest014 off2 success'); - expect(true).assertTrue(); - setTimeout((err) => { - done(); - reject(err) - }, 500); - } else { - console.info('SensorMagneticFieldJSTest014 off2 error'); - expect(false).assertTrue(); - setTimeout(() => { - done(); - resolve() - }, 500); - } - }); - }) - } - - function offPromise1() { - return new Promise((resolve, reject) => { - sensor.off(6, (error) => { - if (error) { - console.info('SensorMagneticFieldJSTest014 off1 error'); - expect(false).assertTrue(); - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest014 off1 success'); - expect(true).assertTrue(); - setTimeout(() => { - resolve(); - }, 500); - } - }); - }) - } - - let promise = new Promise((resolve, reject) => { - sensor.on(6, function (error, data) { - if (error) { - console.info('SensorMagneticFieldJSTest014 on error'); - expect(false).assertTrue(); - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest014 on success x: ' + data.x + "y: " - + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - setTimeout(() => { - resolve(); - }, 500); - } - }); - }) - - await promise.then(() => { - return offPromise1(); - }).then(() => { - return offPromise2(); - }); - done(); - }) - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0150 - * @tc.name: SensorMagneticFieldJSTest015 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0150", 0, async function (done) { - console.info('----------------------SUB_SensorsSystem_Magnetic_Field_JSTest_0150---------------------------'); - function offPromise() { - return new Promise((resolve, reject) => { - sensor.off(6, (error) => { - if (error) { - console.info('SensorMagneticFieldJSTest015 off error'); - expect(false).assertTrue(); - setTimeout((err) => { - done(); - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest015 off success'); - expect(true).assertTrue(); - setTimeout(() => { - done(); - resolve(); - }, 500); - } - }); - }) - } - function onPromise2() { - return new Promise((resolve, reject) => { - sensor.on(6, function (error, data) { - if (error) { - console.info('SensorMagneticFieldJSTest015 on2 error'); - expect(false).assertTrue(); - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest015 on2 success x: ' + data.x + "y: " - + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - setTimeout(() => { - resolve(); - }, 500); - } - }); - }) - } - - let onPromise1 = new Promise((resolve, reject) => { - sensor.on(6, function (error, data) { - if (error) { - console.info('SensorMagneticFieldJSTest015 on1 error'); - expect(false).assertTrue(); - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest015 on1 success x: ' + data.x + "y: " - + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - setTimeout(() => { - resolve(); - }, 500); - } - }); - }) - - await onPromise1.then(() => { - return onPromise2(); - }).then(() => { - return offPromise(); - }); - done(); - }) - - - /* - * @tc.number: SUB_SensorsSystem_Magnetic_Field_JSTest_0160 - * @tc.name: SensorMagneticFieldJSTest016 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Magnetic_Field_JSTest_0160", 0, async function (done) { - console.info('----------------------SUB_SensorsSystem_Magnetic_Field_JSTest_0160---------------------------'); - function offPromise() { - return new Promise((resolve, reject) => { - sensor.off(6, (error) => { - if (error) { - console.info('SensorMagneticFieldJSTest016 off error'); - expect(false).assertTrue(); - setTimeout((err) => { - done(); - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest016 off success'); - expect(true).assertTrue(); - setTimeout(() => { - done(); - resolve(); - }, 500); - } - }); - }) - } - function oncePromise() { - return new Promise((resolve, reject) => { - sensor.once(6, function (error, data) { - if (error) { - console.info('SensorMagneticFieldJSTest016 once error'); - expect(false).assertTrue(); - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest016 once success x: ' + data.x + "y: " - + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - setTimeout(() => { - resolve(); - }, 500); - } - }); - }) - } - - let onPromise1 = new Promise((resolve, reject) => { - sensor.on(6, function (error, data) { - if (error) { - console.info('SensorMagneticFieldJSTest016 on1 error'); - expect(false).assertTrue(); - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorMagneticFieldJSTest016 on1 success x: ' + data.x + "y: " - + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - setTimeout(() => { - resolve(); - }, 500); - } - }); - }) - - await onPromise1.then(() => { - return oncePromise(); - }).then(() => { - return offPromise(); - }); - done(); - }) -}) diff --git a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Orientating.js b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Orientating.js new file mode 100644 index 0000000000000000000000000000000000000000..448766d9c0651564e74f1998461d00e88f2f3c5a --- /dev/null +++ b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.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_sensor_16", 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') + }) + + let errMessages = ['The number of parameters is not valid', 'Should subscribe first', + 'string is not defined']; + + let errMessage; + + /* + * @tc.name:orientating_SensorJsTest001 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0010 + */ + it("orientating_SensorJsTest001", FUNCTION|MEDIUMTEST|LEVEL0, async function (done) { + console.info('----------------------orientating_SensorJsTest001---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + setTimeout(()=>{ + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION); + done(); + }, 500); + }) + + /* + * @tc.name:orientating_SensorJsTest002 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0020 + */ + it("orientating_SensorJsTest002", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------orientating_SensorJsTest002---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------orientating_SensorJsTest002 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION); + console.info('----------------------orientating_SensorJsTest002 off end---------------------------'); + done(); + }, 500); + }) + + /* + * @tc.name:orientating_SensorJsTest003 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0030 + */ + it("orientating_SensorJsTest003", FUNCTION|MEDIUMTEST|LEVEL3, function (done) { + console.info('----------------------orientating_SensorJsTest003---------------------------'); + function onSensorCallback(data) { + console.info('orientating_SensorJsTest003 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, onSensorCallback, {'interval': 100000000}, 5); + } catch (error) { + console.info('orientating_SensorJsTest005 error' + error); + errMessage = error.toString().slice(12, 49); + expect(errMessage).assertEqual(errMessages[0]); + done(); + } + }) + + /* + * @tc.name:orientating_SensorJsTest004 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0040 + */ + it("orientating_SensorJsTest004", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + setTimeout(()=>{ + expect(true).assertTrue(); + done(); + }, 500); + }) + + /* + * @tc.name:orientating_SensorJsTest005 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0050 + */ + it("orientating_SensorJsTest005", FUNCTION|MEDIUMTEST|LEVEL3, function (done) { + function onceSensorCallback(data) { + console.info('orientating_SensorJsTest005 on error'); + expect(false).assertTrue(); + done(); + } + try{ + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, onceSensorCallback, 5); + } catch (error) { + console.info('orientating_SensorJsTest005 error' + error); + errMessage = error.toString().slice(14, 51); + expect(errMessage).assertEqual(errMessages[0]); + done(); + } + }) + + /* + * @tc.name:orientating_SensorJsTest006 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0060 + */ + it("orientating_SensorJsTest006", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + try { + sensor.off(string, ""); + } catch (error) { + console.info('orientating_SensorJsTest006 error' + error); + errMessage = error.toString().slice(16, 40); + expect(errMessage).assertEqual(errMessages[2]); + done(); + } + }) + + /* + * @tc.name:orientating_SensorJsTest007 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0070 + */ + it("orientating_SensorJsTest007", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + function onSensorCallback(data) { + console.info('orientating_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:orientating_SensorJsTest008 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0080 + */ + it("orientating_SensorJsTest008", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + function onSensorCallback(data) { + console.info('orientating_SensorJsTest008 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.off(1000000, onSensorCallback); + } catch (error) { + console.info('orientating_SensorJsTest008 error' + error); + errMessage = error.toString().slice(13, 35); + expect(errMessage).assertEqual(errMessages[1]); + done(); + } + }) + + /* + * @tc.name:orientating_SensorJsTest009 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0090 + */ + it("orientating_SensorJsTest009", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback2); + setTimeout(()=>{ + console.info('----------------------orientating_SensorJsTest009 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION); + console.info('----------------------orientating_SensorJsTest009 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:orientating_SensorJsTest010 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0100 + */ + it("orientating_SensorJsTest010", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback2); + setTimeout(()=>{ + console.info('----------------------orientating_SensorJsTest010 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + console.info('----------------------orientating_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:orientating_SensorJsTest011 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0110 + */ + it("orientating_SensorJsTest011", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------orientating_SensorJsTest011---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback, {'interval': 100000000}); + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback2); + setTimeout(()=>{ + console.info('----------------------orientating_SensorJsTest011 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION); + console.info('----------------------orientating_SensorJsTest011 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:orientating_SensorJsTest012 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0120 + */ + it("orientating_SensorJsTest012", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------orientating_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('----------------------orientating_SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback); + console.info('----------------------orientating_SensorJsTest012 off end---------------------------'); + }, 500); + setTimeout(()=>{ + console.info('----------------------orientating_SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, callback2); + console.info('----------------------orientating_SensorJsTest012 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:orientating_SensorJsTest013 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ORIENTATION_JsTest_0130 + */ + it("orientating_SensorJsTest013", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------orientating_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('----------------------orientating_SensorJsTest013 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION); + console.info('----------------------orientating_SensorJsTest013 off end---------------------------'); + done(); + }, 1000); + }) +}) \ No newline at end of file diff --git a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Orientation.js b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Orientation.js deleted file mode 100755 index a46aeaac590b6a450a9c47cecae8f349219cf2cc..0000000000000000000000000000000000000000 --- a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Orientation.js +++ /dev/null @@ -1,132 +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. - */ -import sensor from '@ohos.sensor' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -describe("SensorJsTest_sensor_16", 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.number: SUB_SensorsSystem_Orientation_JSTest_0010 - * @tc.name: SensorOrientationJSTest001 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Orientation_JSTest_0010", 0, async function (done) { - console.info('----------------------SUB_SensorsSystem_Orientation_JSTest_0010---------------------------'); - function offPromise() { - return new Promise((resolve, reject) => { - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, (error) => { - if (error) { - console.info('SensorOrientationJSTest001 off error'); - expect(false).assertTrue(); - console.info('setTimeout ..start') - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorOrientationJSTest001 off success'); - expect(true).assertTrue(); - setTimeout(() => { - resolve(); - }, 500); - } - }, 1000) - }) - } - - let promise = new Promise((resolve, reject) => { - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function (error, data) { - if (error) { - console.info('SensorOrientationJSTest001 on error'); - expect(false).assertTrue(); - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorOrientationJSTest001 on success, x: ' + data.x + "y: " - + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - setTimeout(() => { - resolve(); - }, 500); - } - }); - }) - - await promise.then(() => { - return offPromise(); - }, () => { - console.info("SensorOrientationJSTest001 reject"); - }) - done(); - }) - - /* - * @tc.number: SUB_SensorsSystem_Orientation_JSTest_0050 - * @tc.name: SensorOrientationJSTest005 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Orientation_JSTest_0050", 0, async function (done) { - function onceSensorCallback(error, data) { - if (error) { - console.info('SensorOrientationJSTest005 once error'); - expect(false).assertTrue(); - } else { - console.info('SensorOrientationJSTest005 once success, x: ' + data.x + "y: " - + data.y + "z: " + data.z); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - } - setTimeout(() => { - done(); - }, 500); - } - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, onceSensorCallback); - }) -}) diff --git a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_RotatingVector.js b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_RotatingVector.js new file mode 100644 index 0000000000000000000000000000000000000000..a58afa212e73d5a70a2acf2ccd343d8a37c53211 --- /dev/null +++ b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_RotatingVector.js @@ -0,0 +1,307 @@ +/* + * 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_sensor_20", 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"); + expect(typeof(data.w)).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"); + expect(typeof(data.w)).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') + }) + + let errMessages = ['The number of parameters is not valid', 'Should subscribe first', + 'string is not defined']; + + let errMessage; + + /* + * @tc.name:rotatingvector_SensorJsTest001 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0010 + */ + it("rotatingvector_SensorJsTest001", FUNCTION|MEDIUMTEST|LEVEL0, async function (done) { + console.info('----------------------rotatingvector_SensorJsTest001---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback); + setTimeout(()=>{ + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR); + done(); + }, 500); + }) + + /* + * @tc.name:rotatingvector_SensorJsTest002 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0020 + */ + it("rotatingvector_SensorJsTest002", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------rotatingvector_SensorJsTest002---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------rotatingvector_SensorJsTest002 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR); + console.info('----------------------rotatingvector_SensorJsTest002 off end---------------------------'); + done(); + }, 500); + }) + + /* + * @tc.name:rotatingvector_SensorJsTest003 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0030 + */ + it("rotatingvector_SensorJsTest003", FUNCTION|MEDIUMTEST|LEVEL3, function (done) { + console.info('----------------------rotatingvector_SensorJsTest003---------------------------'); + function onSensorCallback(data) { + console.info('rotatingvector_SensorJsTest003 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, onSensorCallback, {'interval': 100000000}, 5); + } catch (error) { + console.info('rotatingvector_SensorJsTest003 error' +error); + errMessage = error.toString().slice(12, 49); + expect(errMessage).assertEqual(errMessages[0]); + done(); + } + }) + + /* + * @tc.name:rotatingvector_SensorJsTest004 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0040 + */ + it("rotatingvector_SensorJsTest004", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback); + setTimeout(()=>{ + expect(true).assertTrue(); + done(); + }, 500); + }) + + /* + * @tc.name:rotatingvector_SensorJsTest005 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0050 + */ + it("rotatingvector_SensorJsTest005", FUNCTION|MEDIUMTEST|LEVEL3, function (done) { + function onceSensorCallback(data) { + console.info('rotatingvector_SensorJsTest005 on error'); + expect(false).assertTrue(); + done(); + } + try{ + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, onceSensorCallback, 5); + } catch (error) { + console.info('rotatingvector_SensorJsTest005 error' +error); + errMessage = error.toString().slice(14, 51); + expect(errMessage).assertEqual(errMessages[0]); + done(); + } + }) + + /* + * @tc.name:rotatingvector_SensorJsTest006 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0060 + */ + it("rotatingvector_SensorJsTest006", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + try { + sensor.off(string, ""); + } catch (error) { + console.info('rotatingvector_SensorJsTest006 error' + error); + errMessage = error.toString().slice(16, 40); + expect(errMessage).assertEqual(errMessages[2]); + done(); + } + }) + + /* + * @tc.name:rotatingvector_SensorJsTest007 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0070 + */ + it("rotatingvector_SensorJsTest007", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + function onSensorCallback(data) { + console.info('rotatingvector_SensorJsTest007 on error'); + expect(false).assertTrue(); + done(); + } + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, onSensorCallback); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, onSensorCallback); + setTimeout(()=>{ + expect(true).assertTrue(); + done(); + }, 500); + }) + + /* + * @tc.name:rotatingvector_SensorJsTest008 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0080 + */ + it("rotatingvector_SensorJsTest008", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + function onSensorCallback(data) { + console.info('rotatingvector_SensorJsTest008 on error'); + expect(false).assertTrue(); + done(); + } + try { + sensor.off(1000000, onSensorCallback); + } catch (error) { + console.info('rotatingvector_SensorJsTest008 error' + error); + errMessage = error.toString().slice(13, 35); + expect(errMessage).assertEqual(errMessages[1]); + done(); + } + }) + + /* + * @tc.name:rotatingvector_SensorJsTest009 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0090 + */ + it("rotatingvector_SensorJsTest009", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback2); + setTimeout(()=>{ + console.info('----------------------rotatingvector_SensorJsTest009 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR); + console.info('----------------------rotatingvector_SensorJsTest009 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:rotatingvector_SensorJsTest010 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0100 + */ + it("rotatingvector_SensorJsTest010", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback2); + setTimeout(()=>{ + console.info('----------------------rotatingvector_SensorJsTest010 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback); + console.info('----------------------rotatingvector_SensorJsTest010 off end---------------------------'); + }, 500); + setTimeout(()=>{ + console.info('----------------------rotatingvector_SensorJsTest010 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback2); + console.info('----------------------rotatingvector_SensorJsTest010 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:rotatingvector_SensorJsTest011 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0110 + */ + it("rotatingvector_SensorJsTest011", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------rotatingvector_SensorJsTest011---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback, {'interval': 100000000}); + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback2); + setTimeout(()=>{ + console.info('----------------------rotatingvector_SensorJsTest011 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR); + console.info('----------------------rotatingvector_SensorJsTest011 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:rotatingvector_SensorJsTest012 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0120 + */ + it("rotatingvector_SensorJsTest012", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------rotatingvector_SensorJsTest012---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback, {'interval': 100000000}); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback2, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------rotatingvector_SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback); + console.info('----------------------rotatingvector_SensorJsTest012 off end---------------------------'); + }, 500); + setTimeout(()=>{ + console.info('----------------------rotatingvector_SensorJsTest012 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback2); + console.info('----------------------rotatingvector_SensorJsTest012 off end---------------------------'); + done(); + }, 1000); + }) + + /* + * @tc.name:rotatingvector_SensorJsTest013 + * @tc.desc:verify app info is not null + * @tc.number:SUB_SensorSystem_ROTATION_VECTOR_JsTest_0130 + */ + it("rotatingvector_SensorJsTest013", FUNCTION|MEDIUMTEST|LEVEL3, async function (done) { + console.info('----------------------rotatingvector_SensorJsTest013---------------------------'); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback, {'interval': 100000000}); + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, callback2, {'interval': 100000000}); + setTimeout(()=>{ + console.info('----------------------rotatingvector_SensorJsTest013 off in---------------------------'); + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR); + console.info('----------------------rotatingvector_SensorJsTest013 off end---------------------------'); + done(); + }, 1000); + }) +}) \ No newline at end of file diff --git a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Rotation_Vector.js b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Rotation_Vector.js deleted file mode 100755 index fd2f98ebeb87aadab12cea5d15d19141cd0acdfd..0000000000000000000000000000000000000000 --- a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Rotation_Vector.js +++ /dev/null @@ -1,134 +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. - */ -import sensor from '@ohos.sensor' - -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' - -describe("SensorJsTest_sensor_20", 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.number: SUB_SensorsSystem_Rotation_Vector_JSTest_0010 - * @tc.name: SensorRotationVectorJSTest001 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Rotation_Vector_JSTest_0010", 0, async function (done) { - console.info('----------------------SUB_SensorsSystem_Rotation_Vector_JSTest_0010--------------------------'); - function offPromise() { - return new Promise((resolve, reject) => { - sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, (error) => { - if (error) { - console.info('SensorRotationVectorJSTest001 off error'); - expect(false).assertTrue(); - console.info('setTimeout ..start') - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorRotationVectorJSTest001 off success'); - expect(true).assertTrue(); - setTimeout(() => { - resolve(); - }, 500); - } - }, 1000) - }) - } - - let promise = new Promise((resolve, reject) => { - sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function (error, data) { - if (error) { - console.info('SensorRotationVectorJSTest001 on error'); - expect(false).assertTrue(); - setTimeout((err) => { - reject(err); - }, 500); - } else { - console.info('SensorRotationVectorJSTest001 on success, x: ' - + data.x + "y: " + data.y + "z: " + data.z + "w: " + data.w); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - expect(typeof (data.w)).assertEqual("number"); - setTimeout(() => { - resolve(); - }, 500); - } - }); - }) - - await promise.then(() => { - return offPromise(); - }, () => { - console.info("SensorRotationVectorJSTest001 reject"); - }) - done(); - }) - - /* - * @tc.number: SUB_SensorsSystem_Rotation_Vector_JSTest_0050 - * @tc.name: SensorRotationVectorJSTest005 - * @tc.desc:verify app info is not null - */ - it("SUB_SensorsSystem_Rotation_Vector_JSTest_0050", 0, async function (done) { - function onceSensorCallback(error, data) { - if (error) { - console.info('SensorRotationVectorJSTest005 once error'); - expect(false).assertTrue(); - } else { - console.info('SensorRotationVectorJSTest005 on success, x: ' - + data.x + "y: " + data.y + "z: " + data.z + "w: " + data.w); - expect(typeof (data.x)).assertEqual("number"); - expect(typeof (data.y)).assertEqual("number"); - expect(typeof (data.z)).assertEqual("number"); - expect(typeof (data.w)).assertEqual("number"); - } - setTimeout(() => { - done(); - }, 500); - } - sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, onceSensorCallback); - }) -})