未验证 提交 ed92c28d 编写于 作者: O openharmony_ci 提交者: Gitee

!6035 【Openharmony3.2.8.1】【master分支】【sensor子系统】【ToC】【RK3568】【必现】新增接口用例

Merge pull request !6035 from ldy/master
......@@ -15,8 +15,15 @@
import SystemParameterTest from './SensorOnOffTest.test.js'
import SensorJsTest_sensor_2 from './SensorGeomagneticTest.test.js'
import SensorJsTest_sensor_1 from './SensorGeneralalgorithm.test.js'
import SensorJsTest_sensor_3 from './SensorOnOffTest.test_oldAccelerometer.js'
import SensorJsTest_sensor_25 from './Subscribe_subscribeAccelerometer.js'
import SensorJsTest_sensor_39 from './SensorOnOffTest.test_newAccelerometer.js'
export default function testsuite() {
SensorJsTest_sensor_1()
SensorJsTest_sensor_2()
SystemParameterTest()
SensorJsTest_sensor_3()
SensorJsTest_sensor_25()
SensorJsTest_sensor_39()
}
......@@ -12,9 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// @ts-nocheck
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, TestType, Size, Level } from '@ohos/hypium'
import sensor from '@ohos.sensor'
......@@ -37,24 +34,21 @@ describe('SystemParameterTest', function () {
})
let testNullSensorId = -1;
let errCode = 401
let errMessage = 'The parameter invalid.'
/**
* @tc.number SUB_SENSORS_Sensor_JSTest_0020
* @tc.number SUB_SENSORS_Sensor_JSTest_0010
* @tc.name testRegisterSensortest001
* @tc.desc test get sensor data by wrong sensor id.
*/
it('testRegisterSensortest001', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('testRegisterSensortest001 start');
function onSensorCallback(data) {
console.info('testRegisterSensortest001 callback in');
expect(false).assertTrue();
done();
}
try {
sensor.on(testNullSensorId, onSensorCallback);
} catch (error) {
......
/*
* 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_6() {
describe("SensorJsTest_sensor_6", 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_Accelerometer_Uncalibrated_JSTest_0010
* @tc.name: SensorAccelerometerUncalibratedJSTest001
* @tc.desc: Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Accelerometer_Uncalibrated_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('------------SUB_SensorsSystem_Accelerometer_Uncalibrated_JSTest_0010-----------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, (error) => {
if (error) {
console.info('SensorAccelerometerUncalibratedJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorAccelerometerUncalibratedJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, function (error, data) {
if (error) {
console.info('SensorAccelerometerUncalibratedJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorAccelerometerUncalibratedJSTest001 on success, x: ' + data.x + "y: "
+ data.y + "z: " + data.z + "biasX:" + data.biasX + "biasY: "
+ data.biasY + "biasZ: " + data.biasZ);
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
expect(typeof (data.biasX)).assertEqual("number");
expect(typeof (data.biasY)).assertEqual("number");
expect(typeof (data.biasZ)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorAccelerometerUncalibratedJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Accelerometer_Uncalibrated_JSTest_0020
* @tc.name: SensorAccelerometerUncalibratedJSTest002
* @tc.desc: Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Accelerometer_Uncalibrated_JSTest_0020", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorAccelerometerUncalibratedJSTest002 once error');
expect(false).assertTrue();
} else {
console.info('SensorAccelerometerUncalibratedJSTest002 on success, x: ' + data.x + "y: "
+ data.y + "z: " + data.z + "biasX:" + data.biasX + "biasY: "
+ data.biasY + "biasZ: " + data.biasZ);
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
expect(typeof (data.biasX)).assertEqual("number");
expect(typeof (data.biasY)).assertEqual("number");
expect(typeof (data.biasZ)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_8() {
describe("SensorJsTest_sensor_8", 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_Barometer_JSTest_0010
* @tc.name: SensorBarometerJSTest001
* @tc.desc: Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Barometer_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('----------------------SUB_SensorsSystem_Barometer_JSTest_0010---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, (error) => {
if (error) {
console.info('SensorBarometerJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorBarometerJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, function (error, data) {
if (error) {
console.info('SensorBarometerJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorBarometerJSTest001 on success pressure: ' + data.pressure);
expect(typeof (data.pressure)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorBarometerJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Barometer_JSTest_0050
* @tc.name: SensorBarometerJSTest005
* @tc.desc: Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Barometer_JSTest_0050", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorBarometerJSTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorBarometerJSTest005 once success pressure: ' + data.pressure);
expect(typeof (data.pressure)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_10() {
describe("SensorJsTest_sensor_10", 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_Gyroscope_Uncalibrated_JSTest_0010
* @tc.name: SensorGyroscopeUncalibratedJSTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Gyroscope_Uncalibrated_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('-----------------SUB_SensorsSystem_Gyroscope_Uncalibrated_JSTest_0010----------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, (error) => {
if (error) {
console.info('SensorGyroscopeUncalibratedJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorGyroscopeUncalibratedJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, function (error, data) {
if (error) {
console.info('SensorGyroscopeUncalibratedJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorGyroscopeUncalibratedJSTest001 on success, x: ' + data.x + "y: "
+ data.y + "z: "
+ data.z + "biasX:" + data.biasX + "biasY: " + data.biasY + "biasZ: " + data.biasZ);
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
expect(typeof (data.biasX)).assertEqual("number");
expect(typeof (data.biasY)).assertEqual("number");
expect(typeof (data.biasZ)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorGyroscopeUncalibratedJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Gyroscope_Uncalibrated_JSTest_0050
* @tc.name: SensorGyroscopeUncalibratedJSTest005
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Gyroscope_Uncalibrated_JSTest_0050", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorGyroscopeUncalibratedJSTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorGyroscopeUncalibratedJSTest005 on success, x: ' + data.x + "y: " + data.y + "z: "
+ data.z + "biasX:" + data.biasX + "biasY: " + data.biasY + "biasZ: " + data.biasZ);
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
expect(typeof (data.biasX)).assertEqual("number");
expect(typeof (data.biasY)).assertEqual("number");
expect(typeof (data.biasZ)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_11() {
describe("SensorJsTest_sensor_11", 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_Heart_Rate_JSTest_0010
* @tc.name: SensorHeartRateJSTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Heart_Rate_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('----------------------SUB_SensorsSystem_Heart_Rate_JSTest_0010---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, (error) => {
if (error) {
console.info('SensorHeartRateJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorHeartRateJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, function (error, data) {
if (error) {
console.info('SensorHeartRateJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorHeartRateJSTest001 once success heartRate: ' + data.heartRate);
expect(typeof (data.heartRate)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorHeartRateJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Heart_Rate_JSTest_0050
* @tc.name: SensorHeartRateJSTest005
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Heart_Rate_JSTest_0050", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorHeartRateJSTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorHeartRateJSTest005 once success heartRate: ' + data.heartRate);
expect(typeof (data.heartRate)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_12() {
describe("SensorJsTest_sensor_12", 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_Humidity_JSTest_0010
* @tc.name: SensorHumidityJSTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Humidity_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('----------------------SUB_SensorsSystem_Humidity_JSTest_0010---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, (error) => {
if (error) {
console.info('SensorHumidityJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorHumidityJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, function (error, data) {
if (error) {
console.info('SensorHumidityJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorHumidityJSTest001 on success humidity: ' + data.humidity);
expect(typeof (data.humidity)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorHumidityJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Humidity_JSTest_0050
* @tc.name: SensorHumidityJSTest005
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Humidity_JSTest_0050", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorHumidityJSTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorHumidityJSTest005 once success humidity: ' + data.humidity);
expect(typeof (data.humidity)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_13() {
describe("SensorJsTest_sensor_13", 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_Linear_Acceleration_JSTest_0010
* @tc.name: SensorLinearAccelerationJSTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Linear_Acceleration_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('---------------SUB_SensorsSystem_Linear_Acceleration_JSTest_0010-----------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, (error) => {
if (error) {
console.info('SensorLinearAccelerationJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorLinearAccelerationJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, function (error, data) {
if (error) {
console.info('SensorLinearAccelerationJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorLinearAccelerationJSTest001 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("SensorLinearAccelerationJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Linear_Acceleration_JSTest_0050
* @tc.name: SensorLinearAccelerationJSTest005
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Linear_Acceleration_JSTest_0050", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorLinearAccelerationJSTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorLinearAccelerationJSTest005 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_LINEAR_ACCELERATION, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_14() {
describe("SensorJsTest_sensor_14", 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_Uncalibrated_JSTest_0010
* @tc.name: SensorMagneticFieldUncalibratedJSTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Magnetic_Field_Uncalibrated_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('----------SUB_SensorsSystem_Magnetic_Field_Uncalibrated_JSTest_0010-------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, (error) => {
if (error) {
console.info('SensorMagneticFieldUncalibratedJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorMagneticFieldUncalibratedJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, function (error, data) {
if (error) {
console.info('SensorMagneticFieldUncalibratedJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorMagneticFieldUncalibratedJSTest001 on success, x: ' + data.x + "y: "
+ data.y + "z: "
+ data.z + "biasX:" + data.biasX + "biasY: " + data.biasY + "biasZ: " + data.biasZ);
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
expect(typeof (data.biasX)).assertEqual("number");
expect(typeof (data.biasY)).assertEqual("number");
expect(typeof (data.biasZ)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorMagneticFieldUncalibratedJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Magnetic_Field_Uncalibrated_JSTest_0050
* @tc.name: SensorMagneticFieldUncalibratedJSTest005
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Magnetic_Field_Uncalibrated_JSTest_0050", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorMagneticFieldUncalibratedJSTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorMagneticFieldUncalibratedJSTest005 on success, x: ' + data.x + "y: " + data.y
+ "z: "
+ data.z + "biasX:" + data.biasX + "biasY: " + data.biasY + "biasZ: " + data.biasZ);
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
expect(typeof (data.biasX)).assertEqual("number");
expect(typeof (data.biasY)).assertEqual("number");
expect(typeof (data.biasZ)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_17() {
describe("SensorJsTest_sensor_17", 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_Pedometer_Detection_JSTest_0010
* @tc.name: SensorPedometerDetectionJSTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Pedometer_Detection_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('----------------------SUB_SensorsSystem_Pedometer_Detection_JSTest_0010-----------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, (error) => {
if (error) {
console.info('SensorPedometerDetectionJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorPedometerDetectionJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, function (error, data) {
if (error) {
console.info('SensorPedometerDetectionJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorPedometerDetectionJSTest001 once success scalar: ' + data.scalar);
expect(typeof (data.scalar)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorPedometerDetectionJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Pedometer_Detection_JSTest_0020
* @tc.name: SensorPedometerDetectionJSTest005
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Pedometer_Detection_JSTest_0050", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorPedometerDetectionJSTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorPedometerDetectionJSTest005 once success scalar: ' + data.scalar);
expect(typeof (data.scalar)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_19() {
describe("SensorJsTest_sensor_19", 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_Proxinity_JSTest_0010
* @tc.name: SensorProxinityJSTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Proxinity_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('----------------------SUB_SensorsSystem_Proxinity_JSTest_0010---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, (error) => {
if (error) {
console.info('SensorProxinityJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorProxinityJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, function (error, data) {
if (error) {
console.info('SensorProxinityJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorProxinityJSTest001 on success distance: ' + data.distance);
expect(typeof (data.distance)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorProxinityJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Proxinity_JSTest_0020
* @tc.name: SensorProxinityJSTest002
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SensorProxinityJSTest002", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorProxinityJSTest002 once error');
expect(false).assertTrue();
} else {
console.info('SensorProxinityJSTest002 once success distance: ' + data.distance);
expect(typeof (data.distance)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_21() {
describe("SensorJsTest_sensor_21", 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_Significant_Motion_JSTest_0010
* @tc.name: SensorSignificantMotionJSTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Significant_Motion_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('----------------------SUB_SensorsSystem_Significant_Motion_JSTest_0010------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, (error) => {
if (error) {
console.info('SensorSignificantMotionJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorSignificantMotionJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, function (error, data) {
if (error) {
console.info('SensorSignificantMotionJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorSignificantMotionJSTest001 once success scalar: ' + data.scalar);
expect(typeof (data.scalar)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorSignificantMotionJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Significant_Motion_JSTest_0020
* @tc.name: SensorSignificantMotionJSTest002
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SensorSignificantMotionJSTest002", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorSignificantMotionJSTest002 once error');
expect(false).assertTrue();
} else {
console.info('SensorSignificantMotionJSTest002 once success scalar: ' + data.scalar);
expect(typeof (data.scalar)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_22() {
describe("SensorJsTest_sensor_22", 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_Ambient_Temperature_JSTest_0010
* @tc.name: SensorAmbientTemperatureJSTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Ambient_Temperature_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('--------------------SUB_SensorsSystem_Ambient_Temperature_JSTest_0010-------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, (error) => {
if (error) {
console.info('SensorAmbientTemperatureJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorAmbientTemperatureJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, function (error, data) {
if (error) {
console.info('SensorAmbientTemperatureJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorAmbientTemperatureJSTest001 once success temperature: ' + data.temperature);
expect(typeof (data.temperature)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorAmbientTemperatureJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Ambient_Temperature_JSTest_0020
* @tc.name: SensorAmbientTemperatureJSTest002
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SensorAmbientTemperatureJSTest002", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorAmbientTemperatureJSTest002 once error');
expect(false).assertTrue();
} else {
console.info('SensorAmbientTemperatureJSTest002s once success temperature: ' + data.temperature);
expect(typeof (data.temperature)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_23() {
describe("SensorJsTest_sensor_23", 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_Wear_Detection_JSTest_0010
* @tc.name: SensorWearDetectionJSTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Wear_Detection_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('----------------------SensorWearDetectionJSTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, (error) => {
if (error) {
console.info('SensorWearDetectionJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorWearDetectionJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, function (error, data) {
if (error) {
console.info('SensorWearDetectionJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorWearDetectionJSTest001 once success value: ' + data.value);
expect(typeof (data.value)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorWearDetectionJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Wear_Detection_JSTest_0020
* @tc.name: SensorWearDetectionJSTest002
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SensorWearDetectionJSTest002", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorWearDetectionJSTest002 once error');
expect(false).assertTrue();
} else {
console.info('SensorWearDetectionJSTest002 once success value: ' + data.value);
expect(typeof (data.value)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_41() {
describe("SensorJsTest_sensor_41", function () {
function callback(data) {
console.info("callback" + JSON.stringify(data));
expect(typeof (data.intensity)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
}
function callback2(data) {
console.info("callback2" + JSON.stringify(data));
expect(typeof (data.intensity)).assertEqual("number");
expect(typeof (data.timestamp)).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')
})
const PARAMETER_ERROR_CODE = 401
const SERVICE_EXCEPTION_CODE = 14500101
const PARAMETER_ERROR_MSG = 'The parameter invalid.'
const SERVICE_EXCEPTION_MSG = 'Service exception.'
let invalid = -1;
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0140
* @tc.name: newAmbient_Light_SensorJsTest027
* @tc.desc: Functional Use Cases
*/
it("newAmbient_Light_SensorJsTest027", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('---------newAmbient_Light_SensorJsTest027--------------');
sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback);
setTimeout(()=>{
sensor.off(sensor.SensorId.AMBIENT_LIGHT);
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0150
* @tc.name: newAmbient_Light_SensorJsTest028
* @tc.desc: Illegal ID passed in
*/
it("newAmbient_Light_SensorJsTest028", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newAmbient_Light_SensorJsTest028--------------');
function onSensorCallback(data) {
console.info('newAmbient_Light_SensorJsTest028 callback in');
expect(false).assertTrue();
}
try {
sensor.on(invalid, onSensorCallback);
} catch (error) {
console.info("newAmbient_Light_SensorJsTest028 error:" + error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0160
* @tc.name: newAmbient_Light_SensorJsTest029
* @tc.desc: For normal scenarios
*/
it("newAmbient_Light_SensorJsTest029", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------SensorJsTest003--------------');
sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback, {'interval': 100000000});
setTimeout(()=>{
console.info('---------newAmbient_Light_SensorJsTest029 off in--------------');
sensor.off(sensor.SensorId.AMBIENT_LIGHT);
console.info('---------newAmbient_Light_SensorJsTest029 off end--------------');
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0170
* @tc.name: newAmbient_Light_SensorJsTest030
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newAmbient_Light_SensorJsTest030", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, function (done) {
console.info('---------newAmbient_Light_SensorJsTest030--------------');
function onSensorCallback(data) {
console.info('newAmbient_Light_SensorJsTest030 callback in');
expect(typeof (data.intensity)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
done();
}
try {
sensor.on(sensor.SensorId.AMBIENT_LIGHT, onSensorCallback, {'interval': 100000000}, 5);
} catch (error) {
console.info("newAmbient_Light_SensorJsTest030 error:" +error);
expect(false).assertTrue();
done();
}
setTimeout(()=>{
console.info('---------newAmbient_Light_SensorJsTest030 off in--------------');
sensor.off(sensor.SensorId.AMBIENT_LIGHT);
console.info('---------newAmbient_Light_SensorJsTest030 off end--------------');
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0180
* @tc.name: newAmbient_Light_SensorJsTest018
* @tc.desc: Once Normal Subscription Scenario Use Case
*/
it("newAmbient_Light_SensorJsTest018", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
sensor.once(sensor.SensorId.AMBIENT_LIGHT, callback);
setTimeout(()=>{
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0190
* @tc.name: newAmbient_Light_SensorJsTest019
* @tc.desc: Use case of illegal parameter passed into once interface
*/
it("newAmbient_Light_SensorJsTest019", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(data) {
console.info('newAmbient_Light_SensorJsTest019 callback in');
expect(false).assertTrue();
done();
}
try {
sensor.once(invalid, onceSensorCallback);
} catch (error) {
console.info("newAmbient_Light_SensorJsTest019 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0200
* @tc.name: newAmbient_Light_SensorJsTest020
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newAmbient_Light_SensorJsTest020", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, function (done) {
function onceSensorCallback(data) {
console.info('newAmbient_Light_SensorJsTest020 on error');
expect(typeof (data.intensity)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
done();
}
try{
sensor.once(sensor.SensorId.AMBIENT_LIGHT, onceSensorCallback, 5);
} catch (error) {
console.info('newAmbient_Light_SensorJsTest020 error:' +error);
expect(false).assertTrue();
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0210
* @tc.name: newAmbient_Light_SensorJsTest021
* @tc.desc: Use case of illegal parameter passed into off interface
*/
it("newAmbient_Light_SensorJsTest021", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
try {
sensor.off(invalid, callback);
} catch (error) {
console.info('newAmbient_Light_SensorJsTest021 error:' +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE)
expect(error.message).assertEqual(PARAMETER_ERROR_MSG)
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0220
* @tc.name: newAmbient_Light_SensorJsTest022
* @tc.desc: Unsubscribe directly without waiting after starting subscription
*/
it("newAmbient_Light_SensorJsTest022", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onSensorCallback(data) {
console.info('newAmbient_Light_SensorJsTest022 callback in');
expect(false).assertTrue();
done();
}
sensor.on(sensor.SensorId.AMBIENT_LIGHT, onSensorCallback);
sensor.off(sensor.SensorId.AMBIENT_LIGHT, onSensorCallback);
setTimeout(()=>{
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0230
* @tc.name: newAmbient_Light_SensorJsTest023
* @tc.desc:SensorId1000000 of incoming exception
*/
it("newAmbient_Light_SensorJsTest023", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onSensorCallback(data) {
console.info('newAmbient_Light_SensorJsTest023 on error');
expect(false).assertTrue();
}
try {
sensor.off(1000000, onSensorCallback);
} catch (error) {
console.info("newAmbient_Light_SensorJsTest023 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE)
expect(error.message).assertEqual(PARAMETER_ERROR_MSG)
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0240
* @tc.name: newAmbient_Light_SensorJsTest024
* @tc.desc:Call interface multiple times
*/
it("newAmbient_Light_SensorJsTest024", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
sensor.on(sensor.SensorId.AMBIENT_LIGHT, (data)=>{
console.info("newAmbient_Light_SensorJsTest024 callback: " + JSON.stringify(data));
expect(typeof (data.intensity)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
});
sensor.on(sensor.SensorId.AMBIENT_LIGHT, (data)=>{
console.info("newAmbient_Light_SensorJsTest024 callback2: " + JSON.stringify(data));
expect(typeof (data.intensity)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
});
setTimeout(()=>{
console.info('---------newAmbient_Light_SensorJsTest024 off in--------------');
sensor.off(sensor.SensorId.AMBIENT_LIGHT);
console.info('---------newAmbient_Light_SensorJsTest024 off end--------------');
done();
}, 1000);
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0250
* @tc.name: newAmbient_Light_SensorJsTest025
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newAmbient_Light_SensorJsTest025", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, function (done) {
try {
sensor.off(sensor.SensorId.AMBIENT_LIGHT, 5);
} catch (error) {
console.info('newAmbient_Light_SensorJsTest025 error:'+error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE)
expect(error.message).assertEqual(PARAMETER_ERROR_MSG)
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0260
* @tc.name: newAmbient_Light_SensorJsTest026
* @tc.desc:Call on interface and once interface respectively, and use an off interface to close
*/
it("newAmbient_Light_SensorJsTest026", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newAmbient_Light_SensorJsTest026--------------');
sensor.on(sensor.SensorId.AMBIENT_LIGHT, (data)=>{
console.info("newAmbient_Light_SensorJsTest026 callback: " + JSON.stringify(data));
expect(typeof (data.intensity)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
}, {'interval': 100000000});
sensor.once(sensor.SensorId.AMBIENT_LIGHT, (data)=>{
console.info("newAmbient_Light_SensorJsTest026 callback2: " + JSON.stringify(data));
expect(typeof (data.intensity)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
});
setTimeout(()=>{
console.info('---------newAmbient_Light_SensorJsTest026 off in--------------');
sensor.off(sensor.SensorId.AMBIENT_LIGHT);
console.info('---------newAmbient_Light_SensorJsTest026 off end--------------');
done();
}, 1000);
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0270
* @tc.name: newAmbient_Light_SensorJsTest027
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newAmbient_Light_SensorJsTest027", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newAmbient_Light_SensorJsTest027--------------');
sensor.on(sensor.SensorId.AMBIENT_LIGHT, (data)=>{
console.info("newAmbient_Light_SensorJsTest027 callback: " + JSON.stringify(data));
expect(typeof (data.intensity)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
}, {'interval': 100000000});
sensor.on(sensor.SensorId.AMBIENT_LIGHT, (data)=>{
console.info("newAmbient_Light_SensorJsTest027 callback2: " + JSON.stringify(data));
expect(typeof (data.intensity)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
}, {'interval': 100000000});
setTimeout(()=>{
console.info('---------newAmbient_Light_SensorJsTest027 off in--------------');
sensor.off(sensor.SensorId.AMBIENT_LIGHT);
console.info('---------newAmbient_Light_SensorJsTest027 off end--------------');
done();
}, 1000);
})
/*
* @tc.number:SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0280
* @tc.name: newAmbient_Light_SensorJsTest028
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newAmbient_Light_SensorJsTest028", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newAmbient_Light_SensorJsTest028--------------');
try {
sensor.on();
} catch (error) {
console.info("newAmbient_Light_SensorJsTest028 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
try {
sensor.once();
} catch (error) {
console.info("newAmbient_Light_SensorJsTest028 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
try {
sensor.off();
} catch (error) {
console.info("newAmbient_Light_SensorJsTest028 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0290
* @tc.name: newAmbient_Light_SensorJsTest029
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newAmbient_Light_SensorJsTest029", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('----------------------newAmbient_Light_SensorJsTest029--------------');
sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback);
sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback2);
setTimeout(() => {
console.info('----------------------newAmbient_Light_SensorJsTest029 off in--------------');
try {
sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback);
} catch (error) {
console.info("newAmbient_Light_SensorJsTest029 error:" + error);
}
console.info('----------------------newAmbient_Light_SensorJsTest029 off end--------------');
}, 500);
setTimeout(() => {
console.info('----------------------newAmbient_Light_SensorJsTest029 off in--------------');
sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback2);
console.info('----------------------newAmbient_Light_SensorJsTest029 off end--------------');
done();
}, 1000);
})
/*
* @tc.number: SUB_SensorsSystem_AMBIENT_LIGHT_JSTest_0300
* @tc.name: newAmbient_Light_SensorJsTest030
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newAmbient_Light_SensorJsTest030", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('----------------------newAmbient_Light_SensorJsTest030--------------');
sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback, { 'interval': 100000000 });
sensor.on(sensor.SensorId.AMBIENT_LIGHT, callback2, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------newAmbient_Light_SensorJsTest030 off in--------------');
try {
sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback);
} catch (error) {
console.info("newAmbient_Light_SensorJsTest030 error:" + error);
}
console
console.info('----------------------newAmbient_Light_SensorJsTest030 off end--------------');
}, 500);
setTimeout(() => {
console.info('----------------------newAmbient_Light_SensorJsTest030_2 off in--------------');
sensor.off(sensor.SensorId.AMBIENT_LIGHT, callback2);
console.info('----------------------newAmbient_Light_SensorJsTest030_2 off end--------------');
done();
}, 1000);
})
})}
/*
* 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_53() {
describe("SensorJsTest_sensor_53", function () {
function callback(data) {
console.info("callback" + JSON.stringify(data));
expect(typeof (data.pressure)).assertEqual("number");
}
function callback2(data) {
console.info("callback2" + JSON.stringify(data));
expect(typeof (data.pressure)).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')
})
const PARAMETER_ERROR_CODE = 401
const PARAMETER_ERROR_MSG = 'The parameter invalid.'
const SERVICE_EXCEPTION_CODE = 14500101
const SERVICE_EXCEPTION_MSG = 'Service exception.'
let invalid = -1;
let errMessages = ['ReferenceError: string is not defined','TypeError: is not callable','ReferenceError: xxx is not defined']
let errMessage
/*
* @tc.number:SUB_SensorsSystem_BAROMETER_JSTest_0120
* @tc.name: newBarometer_SensorJsTest012
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newBarometer_SensorJsTest012", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('--------newBarometer_SensorJsTest012--------');
try {
sensor.on(sensor.SensorId.BAROMETER, callback);
} catch (error) {
console.info("newBarometer_SensorJsTest012 error:" + error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
setTimeout(() => {
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.number: SUB_SensorsSystem_BAROMETER_JSTest_0130
* @tc.name: newBarometer_SensorJsTest013
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newBarometer_SensorJsTest013", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('--------newBarometer_SensorJsTest013--------');
try {
sensor.on(sensor.SensorId.BAROMETER ,callback, { 'interval': 100000000 });
} catch (error) {
console.info("newBarometer_SensorJsTest013 error:" + error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_BAROMETER_JSTest_0140
* @tc.name: newBarometer_SensorJsTest014
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newBarometer_SensorJsTest014", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('--------newBarometer_SensorJsTest014--------');
function onSensorCallback(data) {
console.info('newBarometer_SensorJsTest014 on error');
expect(typeof (data.pressure)).assertEqual("number");
}
try {
sensor.on(sensor.SensorId.BAROMETER,
onSensorCallback, { 'interval': 100000000 }, 5);
} catch (error) {
console.info("newBarometer_SensorJsTest014 error:" + error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_BAROMETER_JSTest_0150
* @tc.name: newBarometer_SensorJsTest015
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newBarometer_SensorJsTest015", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('--------newBarometer_SensorJsTest015--------');
try{
sensor.once(sensor.SensorId.BAROMETER, callback);
} catch (error) {
console.info("newBarometer_SensorJsTest015 error:" + error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_BAROMETER_JSTest_0160
* @tc.name: newBarometer_SensorJsTest016
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newBarometer_SensorJsTest016", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('--------newBarometer_SensorJsTest016--------');
function onceSensorCallback(data) {
console.info('newBarometer_SensorJsTest016 on error');
expect(typeof (data.pressure)).assertEqual("number");
}
try {
sensor.once(sensor.SensorId.BAROMETER, onceSensorCallback, 5);
} catch (error) {
console.info("newBarometer_SensorJsTest016 error:" + error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_BAROMETER_JSTest_0170
* @tc.name: newBarometer_SensorJsTest017
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newBarometer_SensorJsTest017", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('--------newBarometer_SensorJsTest017--------');
try {
sensor.off(string, "");
} catch (error) {
errMessage
console.info("newBarometer_SensorJsTest017 error:" + error);
errMessage = error.toString();
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_BAROMETER_JSTest_0180
* @tc.name: newBarometer_SensorJsTest018
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newBarometer_SensorJsTest018", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('--------newBarometer_SensorJsTest018--------');
function onSensorCallback(data) {
console.info('newBarometer_SensorJsTest018 on error');
expect(typeof (data.pressure)).assertEqual("number");
}
try {
sensor.on(sensor.SensorId.BAROMETER, onSensorCallback);
sensor.off(sensor.SensorId.BAROMETER);
} catch (error) {
console.info("newBarometer_SensorJsTest018 error:" + error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_BAROMETER_JSTest_0190
* @tc.name: newBarometer_SensorJsTest019
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newBarometer_SensorJsTest019", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('--------newBarometer_SensorJsTest019--------');
function onSensorCallback(data) {
console.info('newBarometer_SensorJsTest019 on error');
expect(typeof (data.pressure)).assertEqual("number");
}
try {
sensor.off(1000000, onSensorCallback);
} catch (error) {
console.info("newBarometer_SensorJsTest019 error:" + error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_BAROMETER_JSTest_0200
* @tc.name: newBarometer_SensorJsTest020
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newBarometer_SensorJsTest020", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('--------newBarometer_SensorJsTest020--------');
function onSensorCallback(data) {
console.info('newBarometer_SensorJsTest020 on error');
expect(typeof (data.pressure)).assertEqual("number");
}
try {
sensor.off(invalid, onSensorCallback);
} catch (error) {
console.info("newBarometer_SensorJsTest020 error:" + error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_BAROMETER_JSTest_0210
* @tc.name: newBarometer_SensorJsTest021
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newBarometer_SensorJsTest021", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('--------newBarometer_SensorJsTest021--------');
function onSensorCallback(data) {
console.info('newBarometer_SensorJsTest021 on error');
expect(typeof (data.pressure)).assertEqual("number");
}
try {
sensor.xxx(sensor.SensorId.BAROMETER, onSensorCallback);
} catch (error) {
console.info("newBarometer_SensorJsTest021 error:" + error);
errMessage = error.toString();
expect(errMessage).assertEqual(errMessages[1]);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_BAROMETER_JSTest_0220
* @tc.name: newBarometer_SensorJsTest022
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newBarometer_SensorJsTest022", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('--------newBarometer_SensorJsTest022--------');
function onSensorCallback(data) {
console.info('newBarometer_SensorJsTest022 on error');
expect(typeof (data.pressure)).assertEqual("number");
}
try {
xxx.on(sensor.SensorId.BAROMETER, onSensorCallback);
} catch (error) {
console.info("newBarometer_SensorJsTest022 error:" + error);
errMessage = error.toString();
expect(errMessage).assertEqual(errMessages[2]);
done();
}
})
})}
......@@ -51,49 +51,49 @@ describe("SensorJsTest_sensor_35", function () {
})
let errMessage;
let invild;
let invild = -1;
const PARAMETER_ERROR_CODE = 401
const SERVICE_EXCEPTION_CODE = 14500101
const PARAMETER_ERROR_MSG = 'The parameter invalid.'
const SERVICE_EXCEPTION_MSG = 'Service exception.'
let errMessages = ['Wrong argument type, should be function', 'The number of parameters is not valid',
'xxx is not defined'];
/**
* @tc.number:SUB_SensorsSystem_GetSensorLists_JSTest_0010
* @tc.name: getSensorLists_SensorJsTest001
* @tc.desc: Verification results of the incorrect parameters of the test interface.
*/
it("getSensorLists_SensorJsTest001", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info("---------------------------getSensorLists_SensorJsTest001----------------------------------");
sensor.getSensorList().then((data) => {
for (let i = 0; i < data.length; i++) {
it("getSensorLists_SensorJsTest001",TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info("---------------------------getSensorLists_SensorJsTest001----------------------------------");
sensor.getSensorList().then((data) => {
for (let i = 0; i < data.length; i++) {
console.info("getSensorLists_SensorJsTest001 " + JSON.stringify(data[i]));
done();
}
done();
}, (error)=>{
console.info('getSensorLists_SensorJsTest001 failed');
expect(false).assertTrue();
});
})
}, (error)=>{
console.info('getSensorLists_SensorJsTest001 failed');
expect(false).assertTrue();
});
})
/**
/**
* @tc.number:SUB_SensorsSystem_GetSensorLists_JSTest_0020
* @tc.name: getSensorLists_SensorJsTest002
* @tc.desc: Verification results of the incorrect parameters of the test interface.
*/
it("getSensorLists_SensorJsTest002", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
it("getSensorLists_SensorJsTest002", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info("---------------------------getSensorLists_SensorJsTest002----------------------------------");
sensor.getSensorList((error, data) => {
if (error) {
console.info('getSensorLists_SensorJsTest002 error');
expect(false).assertTrue();
} else {
for (let i = 0; i < data.length; i++) {
for (let i =0; i < data.length; i++) {
console.info("getSensorLists_SensorJsTest002 " + JSON.stringify(data[i]));
}
done()
}
});
})
});
})
/**
* @tc.number:SUB_SensorsSystem_GetSensorLists_JSTest_0030
......@@ -105,10 +105,9 @@ it("getSensorLists_SensorJsTest002", TestType.FUNCTION | Size.MEDIUMTEST | Level
try {
sensor.getSensorList(null)
} catch (error) {
errMessage = error.toString().slice(23, 62);
console.info('getSensorLists_SensorJsTest003 error:' + error);
console.info('getSensorLists_SensorJsTest003 errMessage:' + errMessage);
expect(errMessage).assertEqual(errMessages[0]);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
......@@ -121,12 +120,11 @@ it("getSensorLists_SensorJsTest002", TestType.FUNCTION | Size.MEDIUMTEST | Level
it('getSensorLists_SensorJsTest004', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info("------------------getSensorLists_SensorJsTest004-------------------------");
try {
sensor.getSensorList(invild)
sensor.getSensorList(errMessage)
} catch (error) {
errMessage = error.toString().slice(23,62);
console.info('getSensorLists_SensorJsTest004 error:' + error);
console.info('getSensorLists_SensorJsTest004 errMessage:' + errMessage);
expect(errMessage).assertEqual(errMessages[0]);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
......@@ -141,45 +139,52 @@ it("getSensorLists_SensorJsTest002", TestType.FUNCTION | Size.MEDIUMTEST | Level
try {
sensor.getSensorList('xxx')
} catch (error) {
errMessage = error.toString().slice(23,62);
console.info('getSensorLists_SensorJsTest005 error:' + error);
console.info('getSensorLists_SensorJsTest005 errMessage:' + errMessage);
expect(errMessage).assertEqual(errMessages[0]);
done();
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/**
/**
* @tc.number:SUB_SensorsSystem_GetSensorLists_JSTest_0060
* @tc.name: getSensorLists_SensorJsTest006
* @tc.desc: Verification results of the incorrect parameters of the test interface.
*/
it("getSensorLists_SensorJsTest006", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info("---------------------------getSensorLists_SensorJsTest006----------------------------------");
sensor.getSensorList((error, data) => {
if (error) {
console.info('getSensorLists_SensorJsTest006 error');
expect(true).assertTrue();
done()
} else {
for (let i = 0; i < data.length; i++) {
console.info("getSensorLists_SensorJsTest006 " + JSON.stringify(data[i]));
}
done()
it("getSensorLists_SensorJsTest006", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info("---------------------------getSensorLists_SensorJsTest006----------------------------------");
try {
sensor.getSensorList(invild);
} catch(error) {
console.info("getSensorLists_SensorJsTest006 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
});
sensor.getSensorList((error, data) => {
if (error) {
console.info('getSensorLists_SensorJsTest006 error');
expect(true).assertTrue();
done()
} else {
for (let i = 0; i < data.length; i++) {
console.info("getSensorLists_SensorJsTest006 " + JSON.stringify(data[i]));
}
done()
})
/**
* @tc.number:SUB_SensorsSystem_GetSensorLists_JSTest_0070
* @tc.name: getSensorLists_SensorJsTest007
* @tc.desc: Verification results of the incorrect parameters of the test interface.
*/
it("getSensorLists_SensorJsTest007", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info("---------------------------getSensorLists_SensorJsTest007----------------------------------");
try {
sensor.getSensorList(invild).then(data => {
console.info("getSensorLists_SensorJsTest007 " + JSON.stringify(data));
done();
}), (error => {
console.info(error);
expect(error.code).assertEqual(SERVICE_EXCEPTION_CODE);
expect(error.code).assertEqual(SERVICE_EXCEPTION_MSG);
done();
});
} catch(error) {
console.info(error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
});
})
})
}
})
})}
/*
* 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_42() {
describe("SensorJsTest_sensor_42", 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.timestamp)).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.timestamp)).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')
})
const PARAMETER_ERROR_CODE = 401
const SERVICE_EXCEPTION_CODE = 14500101
const PARAMETER_ERROR_MSG = 'The parameter invalid.'
const SERVICE_EXCEPTION_MSG = 'Service exception.'
let invalid = -1;
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JsTest_0140
* @tc.name: newGravity_SensorJsTest014
* @tc.desc: Functional Use Cases
*/
it("newGravity_SensorJsTest014", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('---------newGravity_SensorJsTest014--------------');
sensor.on(sensor.SensorId.GRAVITY, callback);
setTimeout(()=>{
sensor.off(sensor.SensorId.GRAVITY);
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0150
* @tc.name: newGravity_SensorJsTest015
* @tc.desc: Illegal ID passed in
*/
it("newGravity_SensorJsTest015", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newGravity_SensorJsTest015--------------');
function onSensorCallback(data) {
console.info('newGravity_SensorJsTest015 callback in');
expect(false).assertTrue();
}
try {
sensor.on(invalid, onSensorCallback);
} catch (error) {
console.info("newGravity_SensorJsTest015 error:" + error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0160
* @tc.name: newGravity_SensorJsTest016
* @tc.desc: For normal scenarios
*/
it("newGravity_SensorJsTest016", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newGravity_SensorJsTest016--------------');
sensor.on(sensor.SensorId.GRAVITY, callback, {'interval': 100000000});
setTimeout(()=>{
console.info('---------newGravity_SensorJsTest016 off in--------------');
sensor.off(sensor.SensorId.GRAVITY);
console.info('---------newGravity_SensorJsTest016 off end--------------');
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0170
* @tc.name: newGravity_SensorJsTest017
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGravity_SensorJsTest017", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, function (done) {
console.info('---------newGravity_SensorJsTest017--------------');
function onSensorCallback(data) {
console.info('newGravity_SensorJsTest017 callback in');
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
}
try {
sensor.on(sensor.SensorId.GRAVITY, onSensorCallback, {'interval': 100000000}, 5);
} catch (error) {
console.info("newGravity_SensorJsTest017 error:" +error);
expect(false).assertTrue();
done();
}
setTimeout(()=>{
console.info('---------newGravity_SensorJsTest017 off in--------------');
sensor.off(sensor.SensorId.GRAVITY);
console.info('---------newGravity_SensorJsTest017 off end--------------');
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0180
* @tc.name: newGravity_SensorJsTest018
* @tc.desc: Once Normal Subscription Scenario Use Case
*/
it("newGravity_SensorJsTest018", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
sensor.once(sensor.SensorId.GRAVITY, callback);
setTimeout(()=>{
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0190
* @tc.name: newGravity_SensorJsTest019
* @tc.desc: Use case of illegal parameter passed into once interface
*/
it("newGravity_SensorJsTest019", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(data) {
console.info('newGravity_SensorJsTest019 callback in');
expect(false).assertTrue();
done();
}
try {
sensor.once(invalid, onceSensorCallback);
} catch (error) {
console.info("newGravity_SensorJsTest019 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0200
* @tc.name: newGravity_SensorJsTest020
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGravity_SensorJsTest020", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, function (done) {
function onceSensorCallback(data) {
console.info('newGravity_SensorJsTest020 on error');
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
done();
}
try{
sensor.once(sensor.SensorId.GRAVITY, onceSensorCallback, 5);
} catch (error) {
console.info('newGravity_SensorJsTest020 error:' +error);
expect(false).assertTrue();
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0210
* @tc.name: newGravity_SensorJsTest021
* @tc.desc: Use case of illegal parameter passed into off interface
*/
it("newGravity_SensorJsTest021", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
try {
sensor.off(invalid, callback);
} catch (error) {
console.info('newGravity_SensorJsTest021 error:' +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE)
expect(error.message).assertEqual(PARAMETER_ERROR_MSG)
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0220
* @tc.name: newGravity_SensorJsTest022
* @tc.desc: Unsubscribe directly without waiting after starting subscription
*/
it("newGravity_SensorJsTest022", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onSensorCallback(data) {
console.info('newGravity_SensorJsTest022 callback in');
expect(false).assertTrue();
done();
}
sensor.on(sensor.SensorId.GRAVITY, onSensorCallback);
sensor.off(sensor.SensorId.GRAVITY, onSensorCallback);
setTimeout(()=>{
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0230
* @tc.name: newGravity_SensorJsTest023
* @tc.desc:SensorId1000000 of incoming exception
*/
it("newGravity_SensorJsTest023", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onSensorCallback(data) {
console.info('newGravity_SensorJsTest023 on error');
expect(false).assertTrue();
}
try {
sensor.off(1000000, onSensorCallback);
} catch (error) {
console.info("newGravity_SensorJsTest023 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE)
expect(error.message).assertEqual(PARAMETER_ERROR_MSG)
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0240
* @tc.name: newGravity_SensorJsTest024
* @tc.desc:Call interface multiple times
*/
it("newGravity_SensorJsTest024", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
sensor.on(sensor.SensorId.GRAVITY, (data)=>{
console.info("newGravity_SensorJsTest024 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.timestamp)).assertEqual("number");
});
sensor.on(sensor.SensorId.GRAVITY, (data)=>{
console.info("newGravity_SensorJsTest024 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.timestamp)).assertEqual("number");
});
setTimeout(()=>{
console.info('---------newGravity_SensorJsTest024 off in--------------');
sensor.off(sensor.SensorId.GRAVITY);
console.info('---------newGravity_SensorJsTest024 off end--------------');
done();
}, 1000);
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0250
* @tc.name: newGravity_SensorJsTest025
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGravity_SensorJsTest025", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, function (done) {
try {
sensor.off(sensor.SensorId.GRAVITY, 5);
} catch (error) {
console.info('newGravity_SensorJsTest025 error:'+error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE)
expect(error.message).assertEqual(PARAMETER_ERROR_MSG)
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0260
* @tc.name: newGravity_SensorJsTest026
* @tc.desc:Call on interface and once interface respectively, and use an off interface to close
*/
it("newGravity_SensorJsTest026", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newGravity_SensorJsTest026--------------');
sensor.on(sensor.SensorId.GRAVITY, (data)=>{
console.info("newGravity_SensorJsTest026 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.timestamp)).assertEqual("number");
}, {'interval': 100000000});
sensor.once(sensor.SensorId.GRAVITY, (data)=>{
console.info("newGravity_SensorJsTest026 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.timestamp)).assertEqual("number");
});
setTimeout(()=>{
console.info('---------newGravity_SensorJsTest026 off in--------------');
sensor.off(sensor.SensorId.GRAVITY);
console.info('---------newGravity_SensorJsTest026 off end--------------');
done();
}, 1000);
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0270
* @tc.name: newGravity_SensorJsTest027
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGravity_SensorJsTest027", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newGravity_SensorJsTest027--------------');
sensor.on(sensor.SensorId.GRAVITY, (data)=>{
console.info("newGravity_SensorJsTest027 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.timestamp)).assertEqual("number");
}, {'interval': 100000000});
sensor.on(sensor.SensorId.GRAVITY, (data)=>{
console.info("newGravity_SensorJsTest027 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.timestamp)).assertEqual("number");
}, {'interval': 100000000});
setTimeout(()=>{
console.info('---------newGravity_SensorJsTest027 off in--------------');
sensor.off(sensor.SensorId.GRAVITY);
console.info('---------newGravity_SensorJsTest027 off end--------------');
done();
}, 1000);
})
/*
* @tc.number:SUB_SensorsSystem_GRAVITY_JSTest_0280
* @tc.name: newGravity_SensorJsTest028
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGravity_SensorJsTest028", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newGravity_SensorJsTest028--------------');
try {
sensor.on();
} catch (error) {
console.info("newGravity_SensorJsTest028 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
try {
sensor.once();
} catch (error) {
console.info("newGravity_SensorJsTest028 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
try {
sensor.off();
} catch (error) {
console.info("newGravity_SensorJsTest028 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_GRAVITY_JSTest_0290
* @tc.name: newGravity_SensorJsTest029
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGravity_SensorJsTest029", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('----------------------newGravity_SensorJsTest029--------------');
sensor.on(sensor.SensorId.GRAVITY, callback);
sensor.on(sensor.SensorId.GRAVITY, callback2);
setTimeout(() => {
console.info('----------------------newGravity_SensorJsTest029 off in--------------');
try {
sensor.off(sensor.SensorId.GRAVITY, callback);
} catch (error) {
console.info("newGravity_SensorJsTest029 error:" + error);
}
console.info('----------------------newGravity_SensorJsTest029 off end--------------');
}, 500);
setTimeout(() => {
console.info('----------------------newGravity_SensorJsTest029 off in--------------');
sensor.off(sensor.SensorId.GRAVITY, callback2);
console.info('----------------------newGravity_SensorJsTest029 off end--------------');
done();
}, 1000);
})
/*
* @tc.number: SUB_SensorsSystem_GRAVITY_JSTest_0300
* @tc.name: newGravity_SensorJsTest030
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGravity_SensorJsTest030", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('----------------------newGravity_SensorJsTest030--------------');
sensor.on(sensor.SensorId.GRAVITY, callback, { 'interval': 100000000 });
sensor.on(sensor.SensorId.GRAVITY, callback2, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------newGravity_SensorJsTest030 off in--------------');
try {
sensor.off(sensor.SensorId.GRAVITY, callback);
} catch (error) {
console.info("newGravity_SensorJsTest030 error:" + error);
}
console
console.info('----------------------newGravity_SensorJsTest030 off end--------------');
}, 500);
setTimeout(() => {
console.info('----------------------newGravity_SensorJsTest030_2 off in--------------');
sensor.off(sensor.SensorId.GRAVITY, callback2);
console.info('----------------------newGravity_SensorJsTest030_2 off end--------------');
done();
}, 1000);
})
})}
/*
* 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, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_43() {
describe("SensorJsTest_sensor_43", 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.timestamp)).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.timestamp)).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')
})
const PARAMETER_ERROR_CODE = 401
const SERVICE_EXCEPTION_CODE = 14500101
const PARAMETER_ERROR_MSG = 'The parameter invalid.'
const SERVICE_EXCEPTION_MSG = 'Service exception.'
let invalid = -1;
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0140
* @tc.name: newGyroScope_SensorJsTest014
* @tc.desc: Functional Use Cases
*/
it("newGyroScope_SensorJsTest014", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('---------newGyroScope_SensorJsTest014--------------');
sensor.on(sensor.SensorId.GYROSCOPE, callback);
setTimeout(()=>{
sensor.off(sensor.SensorId.GYROSCOPE);
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0150
* @tc.name: newGyroScope_SensorJsTest015
* @tc.desc: Illegal ID passed in
*/
it("newGyroScope_SensorJsTest015", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newGyroScope_SensorJsTest015--------------');
function onSensorCallback(data) {
console.info('newGyroScope_SensorJsTest015 callback in');
expect(false).assertTrue();
}
try {
sensor.on(invalid, onSensorCallback);
} catch (error) {
console.info("newGyroScope_SensorJsTest015 error:" + error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0160
* @tc.name: newGyroScope_SensorJsTest016
* @tc.desc: For normal scenarios
*/
it("newGyroScope_SensorJsTest016", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newGyroScope_SensorJsTest016--------------');
sensor.on(sensor.SensorId.GYROSCOPE, callback, {'interval': 100000000});
setTimeout(()=>{
console.info('---------newGyroScope_SensorJsTest016 off in--------------');
sensor.off(sensor.SensorId.GYROSCOPE);
console.info('---------newGyroScope_SensorJsTest016 off end--------------');
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0170
* @tc.name: newGyroScope_SensorJsTest017
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGyroScope_SensorJsTest017", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, function (done) {
console.info('---------newGyroScope_SensorJsTest017--------------');
function onSensorCallback(data) {
console.info('newGyroScope_SensorJsTest017 callback in');
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
}
try {
sensor.on(sensor.SensorId.GYROSCOPE, onSensorCallback, {'interval': 100000000}, 5);
} catch (error) {
console.info("newGyroScope_SensorJsTest017 error:" +error);
expect(false).assertTrue();
done();
}
setTimeout(()=>{
console.info('---------newGyroScope_SensorJsTest017 off in--------------');
sensor.off(sensor.SensorId.GYROSCOPE);
console.info('---------newGyroScope_SensorJsTest017 off end--------------');
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0180
* @tc.name: newGyroScope_SensorJsTest018
* @tc.desc: Once Normal Subscription Scenario Use Case
*/
it("newGyroScope_SensorJsTest018", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
sensor.once(sensor.SensorId.GYROSCOPE, callback);
setTimeout(()=>{
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0190
* @tc.name: newGyroScope_SensorJsTest019
* @tc.desc: Use case of illegal parameter passed into once interface
*/
it("newGyroScope_SensorJsTest019", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(data) {
console.info('newGyroScope_SensorJsTest019 callback in');
expect(false).assertTrue();
done();
}
try {
sensor.once(invalid, onceSensorCallback);
} catch (error) {
console.info("newGyroScope_SensorJsTest019 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0200
* @tc.name: newGyroScope_SensorJsTest020
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGyroScope_SensorJsTest020", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, function (done) {
function onceSensorCallback(data) {
console.info('newGyroScope_SensorJsTest020 on error');
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
expect(typeof (data.timestamp)).assertEqual("number");
done();
}
try{
sensor.once(sensor.SensorId.GYROSCOPE, onceSensorCallback, 5);
} catch (error) {
console.info('newGyroScope_SensorJsTest020 error:' +error);
expect(false).assertTrue();
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0210
* @tc.name: newGyroScope_SensorJsTest021
* @tc.desc: Use case of illegal parameter passed into off interface
*/
it("newGyroScope_SensorJsTest021", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
try {
sensor.off(invalid, callback);
} catch (error) {
console.info('newGyroScope_SensorJsTest021 error:' +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE)
expect(error.message).assertEqual(PARAMETER_ERROR_MSG)
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0220
* @tc.name: newGyroScope_SensorJsTest022
* @tc.desc: Unsubscribe directly without waiting after starting subscription
*/
it("newGyroScope_SensorJsTest022", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onSensorCallback(data) {
console.info('newGyroScope_SensorJsTest022 callback in');
expect(false).assertTrue();
done();
}
sensor.on(sensor.SensorId.GYROSCOPE, onSensorCallback);
sensor.off(sensor.SensorId.GYROSCOPE, onSensorCallback);
setTimeout(()=>{
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0230
* @tc.name: newnewGyroScope_SensorJsTest023
* @tc.desc:SensorId1000000 of incoming exception
*/
it("newnewGyroScope_SensorJsTest023", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onSensorCallback(data) {
console.info('newnewGyroScope_SensorJsTest023 on error');
expect(false).assertTrue();
}
try {
sensor.off(1000000, onSensorCallback);
} catch (error) {
console.info("newnewGyroScope_SensorJsTest023 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE)
expect(error.message).assertEqual(PARAMETER_ERROR_MSG)
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0240
* @tc.name: newGyroScope_SensorJsTest024
* @tc.desc:Call interface multiple times
*/
it("newGyroScope_SensorJsTest024", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
sensor.on(sensor.SensorId.GYROSCOPE, (data)=>{
console.info("newGyroScope_SensorJsTest024 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.timestamp)).assertEqual("number");
});
sensor.on(sensor.SensorId.GYROSCOPE, (data)=>{
console.info("newGyroScope_SensorJsTest024 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.timestamp)).assertEqual("number");
});
setTimeout(()=>{
console.info('---------newGyroScope_SensorJsTest024 off in--------------');
sensor.off(sensor.SensorId.GYROSCOPE);
console.info('---------newGyroScope_SensorJsTest024 off end--------------');
done();
}, 1000);
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0250
* @tc.name: newGyroScope_SensorJsTest025
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGyroScope_SensorJsTest025", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, function (done) {
try {
sensor.off(sensor.SensorId.GYROSCOPE, 5);
} catch (error) {
console.info('newGyroScope_SensorJsTest025 error:'+error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE)
expect(error.message).assertEqual(PARAMETER_ERROR_MSG)
done();
}
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0260
* @tc.name: newGyroScope_SensorJsTest026
* @tc.desc:Call on interface and once interface respectively, and use an off interface to close
*/
it("newGyroScope_SensorJsTest026", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newGyroScope_SensorJsTest026--------------');
sensor.on(sensor.SensorId.GYROSCOPE, (data)=>{
console.info("newGyroScope_SensorJsTest026 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.timestamp)).assertEqual("number");
}, {'interval': 100000000});
sensor.once(sensor.SensorId.GYROSCOPE, (data)=>{
console.info("newGyroScope_SensorJsTest026 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.timestamp)).assertEqual("number");
});
setTimeout(()=>{
console.info('---------newGyroScope_SensorJsTest026 off in--------------');
sensor.off(sensor.SensorId.GYROSCOPE);
console.info('---------newGyroScope_SensorJsTest026 off end--------------');
done();
}, 1000);
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0270
* @tc.name: newGyroScope_SensorJsTest027
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGyroScope_SensorJsTest027", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newGyroScope_SensorJsTest027--------------');
sensor.on(sensor.SensorId.GYROSCOPE, (data)=>{
console.info("newGyroScope_SensorJsTest027 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.timestamp)).assertEqual("number");
}, {'interval': 100000000});
sensor.on(sensor.SensorId.GYROSCOPE, (data)=>{
console.info("newGyroScope_SensorJsTest027 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.timestamp)).assertEqual("number");
}, {'interval': 100000000});
setTimeout(()=>{
console.info('---------newGyroScope_SensorJsTest027 off in--------------');
sensor.off(sensor.SensorId.GYROSCOPE);
console.info('---------newGyroScope_SensorJsTest027 off end--------------');
done();
}, 1000);
})
/*
* @tc.number:SUB_SensorsSystem_GYROSCOPE_JSTest_0280
* @tc.name: newGyroScope_SensorJsTest028
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGyroScope_SensorJsTest028", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('---------newGyroScope_SensorJsTest028--------------');
try {
sensor.on();
} catch (error) {
console.info("newGyroScope_SensorJsTest028 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
try {
sensor.once();
} catch (error) {
console.info("newGyroScope_SensorJsTest028 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
try {
sensor.off();
} catch (error) {
console.info("newGyroScope_SensorJsTest028 error:" +error);
expect(error.code).assertEqual(PARAMETER_ERROR_CODE);
expect(error.message).assertEqual(PARAMETER_ERROR_MSG);
done();
}
})
/*
* @tc.number: SUB_SensorsSystem_GYROSCOPE_JSTest_0290
* @tc.name: newGyroScope_SensorJsTest029
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGyroScope_SensorJsTest029", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('----------------------newGyroScope_SensorJsTest029--------------');
sensor.on(sensor.SensorId.GYROSCOPE, callback);
sensor.on(sensor.SensorId.GYROSCOPE, callback2);
setTimeout(() => {
console.info('----------------------newGyroScope_SensorJsTest029 off in--------------');
try {
sensor.off(sensor.SensorId.GYROSCOPE, callback);
} catch (error) {
console.info("newGyroScope_SensorJsTest029 error:" + error);
}
console.info('----------------------newGyroScope_SensorJsTest029 off end--------------');
}, 500);
setTimeout(() => {
console.info('----------------------newGyroScope_SensorJsTest029 off in--------------');
sensor.off(sensor.SensorId.GYROSCOPE, callback2);
console.info('----------------------newGyroScope_SensorJsTest029 off end--------------');
done();
}, 1000);
})
/*
* @tc.number: SUB_SensorsSystem_GYROSCOPE_JSTest_0300
* @tc.name: newGyroScope_SensorJsTest030
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("newGyroScope_SensorJsTest030", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
console.info('----------------------newGyroScope_SensorJsTest030--------------');
sensor.on(sensor.SensorId.GYROSCOPE, callback, { 'interval': 100000000 });
sensor.on(sensor.SensorId.GYROSCOPE, callback2, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------newGyroScope_SensorJsTest030 off in--------------');
try {
sensor.off(sensor.SensorId.GYROSCOPE, callback);
} catch (error) {
console.info("newGyroScope_SensorJsTest030 error:" + error);
}
console
console.info('----------------------newGyroScope_SensorJsTest030 off end--------------');
}, 500);
setTimeout(() => {
console.info('----------------------newGyroScope_SensorJsTest030_2 off in--------------');
sensor.off(sensor.SensorId.GYROSCOPE, callback2);
console.info('----------------------newGyroScope_SensorJsTest030_2 off end--------------');
done();
}, 1000);
})
})}
......@@ -12,12 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import sensor from '@ohos.sensor'
import sensor from '@system.sensor'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, TestType, Size, Level } from '@ohos/hypium'
export default function SensorJsTest_sensor_18() {
describe("SensorJsTest_sensor_18", function () {
export default function SystemServiceExceptionTest() {
describe("SystemServiceExceptionTest", function () {
beforeAll(function () {
/*
......@@ -50,79 +50,25 @@ describe("SensorJsTest_sensor_18", function () {
console.info('afterEach caled')
})
/*
* @tc.number: SUB_SensorsSystem_Pedometer_JSTest_0010
* @tc.name: SensorPedometerJSTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface
*/
it("SUB_SensorsSystem_Pedometer_JSTest_0010", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('----------------------SUB_SensorsSystem_Pedometer_JSTest_0010---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, (error) => {
if (error) {
console.info('SensorPedometerJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorPedometerJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, function (error, data) {
if (error) {
console.info('SensorPedometerJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorPedometerJSTest001 once success steps: ' + data.steps);
expect(typeof (data.steps)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorPedometerJSTest001 reject");
})
done();
})
let invild = -1;
/*
* @tc.number: SUB_SensorsSystem_Pedometer_JSTest_0020
* @tc.name: SensorPedometerJSTest005
* @tc.desc:Verification results of the incorrect parameters of the test interface
* @tc.number:SUB_SensorsSystem_ServiceException_JSTest_0010
* @tc.name:newTestServiceException_SensorJsTest001
* @tc.desc:Verification results of the incorrect parameters of the test interface.
*/
it("SUB_SensorsSystem_Pedometer_JSTest_0050", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL3, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorPedometerJSTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorPedometerJSTest005 once success steps: ' + data.steps);
expect(typeof (data.steps)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
it("newTestServiceException_SensorJsTest001", TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) {
console.info('----------------------newTestServiceException_SensorJsTest001---------------------------');
try {
sensor.on(invild, (data) => {
console.info('newTestServiceException_SensorJsTest001 data: ' + JSON.stringify(data))
});
} catch(err) {
console.info("newTestServiceException_SensorJsTest001 exception: " + JSON.stringify(err))
console.info('newTestServiceException_SensorJsTest001 code: ' + err.code)
console.info('newTestServiceException_SensorJsTest001 message: ' + err.message)
done()
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, onceSensorCallback);
})
})
}
})}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册