提交 dd51c4f5 编写于 作者: L lidanyang16

<lidanyang16@huawei.com>

Signed-off-by: Nlidanyang16 <lidanyang16@huawei.com>
上级 b4a2a52f
......@@ -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",
]
}
}
......@@ -55,6 +55,12 @@
"autoDesignWidth": false
}
}
],
"reqPermissions": [
{
"name": "ohos.permission.VIBRATE",
"reason": "need use ohos.permission.VIBRATE"
}
]
}
}
......@@ -13,4 +13,5 @@
* limitations under the License.
*/
require('./Vibrator.test.js')
require('./Vibrator_old.test.js')
require('./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();
}
......
......@@ -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(() => {
......
......@@ -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"
}
]
}
}
/*
* 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
/*
* 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
/*
* 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
/*
* 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);
})
})
/*
* 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
/*
* 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);
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册