提交 0ea09217 编写于 作者: L lidanyang16 提交者: ldy
上级 01975d81
......@@ -48,7 +48,10 @@ describe("VibratorJsTest", function () {
console.info('afterEach caled')
})
var errMessages = ['Param number is invalid', 'Wrong argument type. function expected', 'Wrong argument type', 'Wrong argument number']
let errMessages = ['Param number is invalid', 'Wrong argument type. function expected',
'Wrong argument type', 'Wrong argument number']
let errMessage;
/*
* @tc.name:VibratorJsTest0001
......@@ -62,7 +65,6 @@ describe("VibratorJsTest", function () {
mode: 'long',
success: function () {
console.info("VibratorJsTest0001 success");
expect(true).assertTrue();
done();
},
fail: function (data, code) {
......@@ -87,7 +89,6 @@ describe("VibratorJsTest", function () {
mode: 'short',
success: function () {
console.info("VibratorJsTest0002 success");
expect(true).assertTrue();
done();
},
fail: function (data, code) {
......@@ -112,7 +113,6 @@ describe("VibratorJsTest", function () {
mode: 'short',
success: function () {
console.info("VibratorJsTest0003 success");
expect(true).assertTrue();
done();
},
fail: function (data, code) {
......@@ -134,7 +134,6 @@ describe("VibratorJsTest", function () {
mode: 'short',
success: function () {
console.info("VibratorJsTest0004 success");
expect(true).assertTrue();
done();
},
});
......@@ -151,7 +150,6 @@ describe("VibratorJsTest", function () {
vibrator.vibrate({
success: function () {
console.info("VibratorJsTest0005 success");
expect(true).assertTrue();
done();
},
fail: function (data, code) {
......@@ -174,7 +172,6 @@ describe("VibratorJsTest", function () {
inInvalid: 2,
success: function () {
console.info("VibratorJsTest0006 success");
expect(true).assertTrue();
done();
},
fail: function (data, code) {
......@@ -202,7 +199,7 @@ describe("VibratorJsTest", function () {
},
}, 25);
} catch (error) {
var errMessage = error.toString().slice(39);
errMessage = error.toString().slice(39);
console.info('VibratorJsTest0007 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
......@@ -221,26 +218,22 @@ describe("VibratorJsTest", function () {
mode: 'short',
success: function () {
console.info("VibratorJsTest0008 success");
expect(true).assertTrue();
},
fail: function (data, code) {
console.error('VibratorJsTest0008 failed. Code: ' + code + '; Data: ' + data);
expect(false).assertTrue();
},
});
vibrator.vibrate({
mode: 'short',
success: function () {
console.info("VibratorJsTest0008_1 success");
expect(true).assertTrue();
},
fail: function (data, code) {
console.error('VibratorJsTest0008_1 failed. Code: ' + code + '; Data: ' + data);
expect(false).assertTrue();
},
});
setTimeout(() => {
done();
}, 500);
......@@ -258,7 +251,7 @@ describe("VibratorJsTest", function () {
vibrator.vibrate('xxx', done);
} catch (error) {
console.info('VibratorJsTest0009 error:' + error);
var errMessage = error.toString().slice(68);
errMessage = error.toString().slice(68);
expect(errMessage).assertEqual(errMessages[1]);
done();
}
......@@ -275,7 +268,7 @@ describe("VibratorJsTest", function () {
try {
vibrator.vibrate(done);
} catch (error) {
var errMessage = error.toString().slice(7);
errMessage = error.toString().slice(7);
console.info('VibratorJsTest0010 error:' + error);
expect(errMessage).assertEqual(errMessages[2]);
done();
......@@ -301,7 +294,7 @@ describe("VibratorJsTest", function () {
}, function () {
}, 25);
} catch (error) {
var errMessage = error.toString().slice(39);
errMessage = error.toString().slice(39);
console.info('VibratorJsTest0011 error:' + error);
expect(errMessage).assertEqual(errMessages[3]);
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 } from 'deccjsunit/index'
describe("SensorJsTest", 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_Hall_JSTest_0010
* @tc.name: SensorHallJSTest001
* @tc.desc:verify app info is not null
*/
it("SUB_SensorsSystem_Hall_JSTest_0010", 0, async function (done) {
console.info('----------------------SUB_SensorsSystem_Hall_JSTest_0010---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, (error) => {
if (error) {
console.info('SensorHallJSTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorHallJSTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, function (error, data) {
if (error) {
console.info('SensorHallJSTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorHallJSTest001 on success status: ' + data.status);
expect(typeof (data.status)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorHallJSTest001 reject");
})
done();
})
/*
* @tc.number: SUB_SensorsSystem_Hall_JSTest_0050
* @tc.name: SensorHallJSTest005
* @tc.desc:verify app info is not null
*/
it("SUB_SensorsSystem_Hall_JSTest_0050", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorHallJSTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorHallJSTest005 once success status: ' + data.status);
expect(typeof (data.status)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, onceSensorCallback);
})
})
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import sensor from '@ohos.sensor'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
describe("SensorJsTest", function () {
function callback(data) {
console.info("callback" + JSON.stringify(data));
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
}
function callback2(data) {
console.info("callback2" + JSON.stringify(data));
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
}
beforeAll(function () {
/*
* @tc.setup: setup invoked before all testcases
*/
console.info('beforeAll caled')
})
afterAll(function () {
/*
* @tc.teardown: teardown invoked after all testcases
*/
console.info('afterAll caled')
})
beforeEach(function () {
/*
* @tc.setup: setup invoked before each testcases
*/
console.info('beforeEach caled')
})
afterEach(function () {
/*
* @tc.teardown: teardown invoked after each testcases
*/
console.info('afterEach caled')
})
let errMessages = ['The number of parameters is not valid', 'Should subscribe first',
'string is not defined'];
let errMessage;
/*
* @tc.name:Accelerometer_SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest001", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest001---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
setTimeout(() => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER);
done();
}, 500);
})
/*
* @tc.name:Accelerometer_SensorJsTest002
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest002", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest002---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------Accelerometer_SensorJsTest002 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER);
console.info('----------------------Accelerometer_SensorJsTest002 off end---------------------------');
done();
}, 500);
})
/*
* @tc.name:Accelerometer_SensorJsTest003
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest003", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest003---------------------------');
function onSensorCallback(data) {
console.info('Accelerometer_SensorJsTest003 on error');
expect(false).assertTrue();
done();
}
try {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, onSensorCallback, { 'interval': 100000000 }, 5);
} catch (error) {
console.info("Accelerometer_SensorJsTest003 error:" + error);
errMessage = error.toString().slice(12, 49);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:Accelerometer_SensorJsTest004
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest004", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest004---------------------------');
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
setTimeout(() => {
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.name:Accelerometer_SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest005", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest005---------------------------');
function onceSensorCallback(data) {
console.info('Accelerometer_SensorJsTest005 on error');
expect(false).assertTrue();
done();
}
try {
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, onceSensorCallback, 5);
} catch (error) {
console.info("Accelerometer_SensorJsTest005 error:" + error);
errMessage = error.toString().slice(14, 51);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:Accelerometer_SensorJsTest006
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest006", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest006---------------------------');
try {
sensor.off(string, "");
} catch (error) {
console.info("Accelerometer_SensorJsTest006 error:" + error);
errMessage = error.toString().slice(16, 40);
expect(errMessage).assertEqual(errMessages[2]);
done();
}
})
/*
* @tc.name:Accelerometer_SensorJsTest007
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest007", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest007---------------------------');
function onSensorCallback(data) {
console.info('Accelerometer_SensorJsTest007 on error');
expect(false).assertTrue();
done();
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, onSensorCallback);
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, onSensorCallback);
setTimeout(() => {
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.name:Accelerometer_SensorJsTest008
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest008", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest008---------------------------');
function onSensorCallback(data) {
console.info('Accelerometer_SensorJsTest008 on error');
expect(false).assertTrue();
done();
}
try {
sensor.off(1000000, onSensorCallback);
} catch (error) {
console.info("Accelerometer_SensorJsTest008 error:" + error);
errMessage = error.toString().slice(13, 35);
expect(errMessage).assertEqual(errMessages[1]);
done();
}
})
/*
* @tc.name:Accelerometer_SensorJsTest009
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest009", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest009---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback2);
setTimeout(() => {
console.info('----------------------Accelerometer_SensorJsTest009 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER);
console.info('----------------------Accelerometer_SensorJsTest009 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:Accelerometer_SensorJsTest010
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest010", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest010---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback2);
setTimeout(() => {
console.info('----------------------Accelerometer_SensorJsTest010 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
console.info('----------------------Accelerometer_SensorJsTest010 off end---------------------------');
}, 500);
setTimeout(() => {
console.info('----------------------Accelerometer_SensorJsTest010 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback2);
console.info('----------------------Accelerometer_SensorJsTest010 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:Accelerometer_SensorJsTest011
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest011", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest011---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback, { 'interval': 100000000 });
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback2);
setTimeout(() => {
console.info('----------------------Accelerometer_SensorJsTest011 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER);
console.info('----------------------Accelerometer_SensorJsTest011 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:Accelerometer_SensorJsTest012
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest012", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest012---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback, { 'interval': 100000000 });
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback2, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------Accelerometer_SensorJsTest012 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback);
console.info('----------------------Accelerometer_SensorJsTest012 off end---------------------------');
}, 500);
setTimeout(() => {
console.info('----------------------Accelerometer_SensorJsTest012 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback2);
console.info('----------------------Accelerometer_SensorJsTest012 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:Accelerometer_SensorJsTest013
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Accelerometer_SensorJsTest013", 0, async function (done) {
console.info('----------------------Accelerometer_SensorJsTest013---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback, { 'interval': 100000000 });
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, callback2, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------Accelerometer_SensorJsTest013 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER);
console.info('----------------------Accelerometer_SensorJsTest013 off end---------------------------');
done();
}, 1000);
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import sensor from '@ohos.sensor'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
describe("SensorJsTest", function () {
function callback(data) {
console.info("callback" + JSON.stringify(data));
expect(typeof (data.intensity)).assertEqual("number");
}
function callback2(data) {
console.info("callback2" + JSON.stringify(data));
expect(typeof (data.intensity)).assertEqual("number");
}
beforeAll(function () {
/*
* @tc.setup: setup invoked before all testcases
*/
console.info('beforeAll caled')
})
afterAll(function () {
/*
* @tc.teardown: teardown invoked after all testcases
*/
console.info('afterAll caled')
})
beforeEach(function () {
/*
* @tc.setup: setup invoked before each testcases
*/
console.info('beforeEach caled')
})
afterEach(function () {
/*
* @tc.teardown: teardown invoked after each testcases
*/
console.info('afterEach caled')
})
let errMessages = ['The number of parameters is not valid', 'Should subscribe first',
'string is not defined'];
let errMessage;
/*
* @tc.name:Ambient_Light_SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest001", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest001---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
setTimeout(() => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT);
done();
}, 1500);
})
/*
* @tc.name:Ambient_Light_SensorJsTest002
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest002", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest002---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------Ambient_Light_SensorJsTest002 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT);
console.info('----------------------Ambient_Light_SensorJsTest002 off end---------------------------');
done();
}, 1500);
})
/*
* @tc.name:Ambient_Light_SensorJsTest003
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest003", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest003---------------------------');
function onSensorCallback(data) {
console.info('Ambient_Light_SensorJsTest003 on error');
expect(false).assertTrue();
done();
}
try {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, onSensorCallback, { 'interval': 100000000 }, 5);
} catch (error) {
console.info("Ambient_Light_SensorJsTest003 error:" + error);
errMessage = error.toString().slice(12, 49);
console.info('Ambient_Light_SensorJsTest003 errMessage:' + errMessage);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:Ambient_Light_SensorJsTest004
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest004", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest004---------------------------');
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
setTimeout(() => {
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.name:Ambient_Light_SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest005", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest005---------------------------');
function onceSensorCallback(data) {
console.info('Ambient_Light_SensorJsTest005 on error');
expect(false).assertTrue();
done();
}
try {
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, onceSensorCallback, 5);
} catch (error) {
console.info("Ambient_Light_SensorJsTest005 error:" + error);
errMessage = error.toString().slice(14, 51);
console.info('Ambient_Light_SensorJsTest005 errMessage:' + errMessage);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:Ambient_Light_SensorJsTest006
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest006", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest006---------------------------');
try {
sensor.off(string, "");
} catch (error) {
console.info("Ambient_Light_SensorJsTest006 error:" + error);
errMessage = error.toString().slice(16, 40);
console.info('Ambient_Light_SensorJsTest006 errMessage:' + errMessage);
expect(errMessage).assertEqual(errMessages[2]);
done();
}
})
/*
* @tc.name:Ambient_Light_SensorJsTest007
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest007", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest007---------------------------');
function onSensorCallback(data) {
console.info('Ambient_Light_SensorJsTest007 on error');
expect(false).assertTrue();
done();
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, onSensorCallback);
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, onSensorCallback);
setTimeout(() => {
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.name:Ambient_Light_SensorJsTest008
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest008", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest008---------------------------');
function onSensorCallback(data) {
console.info('Ambient_Light_SensorJsTest008 on error');
expect(false).assertTrue();
done();
}
try {
sensor.off(1000000, onSensorCallback);
} catch (error) {
console.info("Ambient_Light_SensorJsTest008 error:" + error);
errMessage = error.toString().slice(13, 35);
console.info('Ambient_Light_SensorJsTest008 errMessage:' + errMessage);
expect(errMessage).assertEqual(errMessages[1]);
done();
}
})
/*
* @tc.name:Ambient_Light_SensorJsTest009
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest009", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest009---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback2);
setTimeout(() => {
console.info('----------------------Ambient_Light_SensorJsTest009 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT);
console.info('----------------------Ambient_Light_SensorJsTest009 off end---------------------------');
done();
}, 2000);
})
/*
* @tc.name:Ambient_Light_SensorJsTest010
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest010", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest010---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback2);
setTimeout(() => {
console.info('----------------------Ambient_Light_SensorJsTest010 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
console.info('----------------------Ambient_Light_SensorJsTest010 off end---------------------------');
}, 1000);
setTimeout(() => {
console.info('----------------------Ambient_Light_SensorJsTest010 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback2);
console.info('----------------------Ambient_Light_SensorJsTest010 off end---------------------------');
done();
}, 2000);
})
/*
* @tc.name:Ambient_Light_SensorJsTest011
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest011", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest011---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback, { 'interval': 100000000 });
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback2);
setTimeout(() => {
console.info('----------------------Ambient_Light_SensorJsTest011 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT);
console.info('----------------------Ambient_Light_SensorJsTest011 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:Ambient_Light_SensorJsTest012
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest012", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest012---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback, { 'interval': 100000000 });
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback2, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------Ambient_Light_SensorJsTest012 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback);
console.info('----------------------Ambient_Light_SensorJsTest012 off end---------------------------');
}, 500);
setTimeout(() => {
console.info('----------------------Ambient_Light_SensorJsTest012 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback2);
console.info('----------------------Ambient_Light_SensorJsTest012 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:Ambient_Light_SensorJsTest013
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Ambient_Light_SensorJsTest013", 0, async function (done) {
console.info('----------------------Ambient_Light_SensorJsTest013---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback, { 'interval': 100000000 });
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT, callback2, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------Ambient_Light_SensorJsTest013 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_LIGHT);
console.info('----------------------Ambient_Light_SensorJsTest013 off end---------------------------');
done();
}, 1000);
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import sensor from '@ohos.sensor'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
describe("SensorJsTest", function () {
function callback(data) {
console.info("callback" + JSON.stringify(data));
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
}
function callback2(data) {
console.info("callback2" + JSON.stringify(data));
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
}
beforeAll(function () {
/*
* @tc.setup: setup invoked before all testcases
*/
console.info('beforeAll caled')
})
afterAll(function () {
/*
* @tc.teardown: teardown invoked after all testcases
*/
console.info('afterAll caled')
})
beforeEach(function () {
/*
* @tc.setup: setup invoked before each testcases
*/
console.info('beforeEach caled')
})
afterEach(function () {
/*
* @tc.teardown: teardown invoked after each testcases
*/
console.info('afterEach caled')
})
let errMessages = ['The number of parameters is not valid', 'Should subscribe first',
'string is not defined'];
let errMessage;
/*
* @tc.name:GYROSCOPE_SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest001", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest001---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
setTimeout(() => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE);
done();
}, 500);
})
/*
* @tc.name:GYROSCOPE_SensorJsTest002
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest002", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest002---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------GYROSCOPE_SensorJsTest002 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE);
console.info('----------------------GYROSCOPE_SensorJsTest002 off end---------------------------');
done();
}, 500);
})
/*
* @tc.name:GYROSCOPE_SensorJsTest003
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest003", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest003---------------------------');
function onSensorCallback(data) {
console.info('GYROSCOPE_SensorJsTest003 on error');
expect(false).assertTrue();
done();
}
try {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, onSensorCallback, { 'interval': 100000000 }, 5);
} catch (error) {
console.info("GYROSCOPE_SensorJsTest003 error:" + error);
errMessage = error.toString().slice(12, 49);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:GYROSCOPE_SensorJsTest004
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest004", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest004---------------------------');
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
setTimeout(() => {
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.name:GYROSCOPE_SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest005", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest005---------------------------');
function onceSensorCallback(data) {
console.info('GYROSCOPE_SensorJsTest005 on error');
expect(false).assertTrue();
done();
}
try {
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, onceSensorCallback, 5);
} catch (error) {
console.info("GYROSCOPE_SensorJsTest005 error:" + error);
errMessage = error.toString().slice(14, 51);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:GYROSCOPE_SensorJsTest006
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest006", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest006---------------------------');
try {
sensor.off(string, "");
} catch (error) {
console.info("GYROSCOPE_SensorJsTest006 error:" + error);
errMessage = error.toString().slice(16, 40);
expect(errMessage).assertEqual(errMessages[2]);
done();
}
})
/*
* @tc.name:GYROSCOPE_SensorJsTest007
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest007", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest007---------------------------');
function onSensorCallback(data) {
console.info('GYROSCOPE_SensorJsTest007 on error');
expect(false).assertTrue();
done();
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, onSensorCallback);
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, onSensorCallback);
setTimeout(() => {
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.name:GYROSCOPE_SensorJsTest008
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest008", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest008---------------------------');
function onSensorCallback(data) {
console.info('GYROSCOPE_SensorJsTest008 on error');
expect(false).assertTrue();
done();
}
try {
sensor.off(1000000, onSensorCallback);
} catch (error) {
console.info("GYROSCOPE_SensorJsTest008 error:" + error);
errMessage = error.toString().slice(13, 35);
expect(errMessage).assertEqual(errMessages[1]);
done();
}
})
/*
* @tc.name:GYROSCOPE_SensorJsTest009
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest009", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest009---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback2);
setTimeout(() => {
console.info('----------------------GYROSCOPE_SensorJsTest009 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE);
console.info('----------------------GYROSCOPE_SensorJsTest009 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:GYROSCOPE_SensorJsTest010
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest010", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest010---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback2);
setTimeout(() => {
console.info('----------------------GYROSCOPE_SensorJsTest010 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
console.info('----------------------GYROSCOPE_SensorJsTest010 off end---------------------------');
}, 500);
setTimeout(() => {
console.info('----------------------GYROSCOPE_SensorJsTest010 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback2);
console.info('----------------------GYROSCOPE_SensorJsTest010 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:GYROSCOPE_SensorJsTest011
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest011", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest011---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback, { 'interval': 100000000 });
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback2);
setTimeout(() => {
console.info('----------------------GYROSCOPE_SensorJsTest011 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE);
console.info('----------------------GYROSCOPE_SensorJsTest011 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:GYROSCOPE_SensorJsTest012
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest012", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest012---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback, { 'interval': 100000000 });
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback2, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------GYROSCOPE_SensorJsTest012 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback);
console.info('----------------------GYROSCOPE_SensorJsTest012 off end---------------------------');
}, 500);
setTimeout(() => {
console.info('----------------------GYROSCOPE_SensorJsTest012 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback2);
console.info('----------------------GYROSCOPE_SensorJsTest012 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:GYROSCOPE_SensorJsTest013
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("GYROSCOPE_SensorJsTest013", 0, async function (done) {
console.info('----------------------GYROSCOPE_SensorJsTest013---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback, { 'interval': 100000000 });
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE, callback2, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------GYROSCOPE_SensorJsTest013 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE);
console.info('----------------------GYROSCOPE_SensorJsTest013 off end---------------------------');
done();
}, 1000);
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import sensor from '@ohos.sensor'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
describe("SensorJsTest", function () {
function callback(data) {
console.info("callback" + JSON.stringify(data));
expect(typeof (data.status)).assertEqual("number");
}
function callback2(data) {
console.info("callback2" + JSON.stringify(data));
expect(typeof (data.status)).assertEqual("number");
}
beforeAll(function () {
/*
* @tc.setup: setup invoked before all testcases
*/
console.info('beforeAll caled')
})
afterAll(function () {
/*
* @tc.teardown: teardown invoked after all testcases
*/
console.info('afterAll caled')
})
beforeEach(function () {
/*
* @tc.setup: setup invoked before each testcases
*/
console.info('beforeEach caled')
})
afterEach(function () {
/*
* @tc.teardown: teardown invoked after each testcases
*/
console.info('afterEach caled')
})
let errMessages = ['The number of parameters is not valid', 'Should subscribe first',
'string is not defined'];
let errMessage;
/*
* @tc.name:Hall_SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest001", 0, async function (done) {
console.info('----------------------Hall_SensorJsTest001---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
setTimeout(() => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL);
done();
}, 500);
})
/*
* @tc.name:Hall_SensorJsTest002
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest002", 0, async function (done) {
console.info('----------------------Hall_SensorJsTest002---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------Hall_SensorJsTest002 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL);
console.info('----------------------Hall_SensorJsTest002 off end---------------------------');
done();
}, 500);
})
/*
* @tc.name:Hall_SensorJsTest003
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest003", 0, async function (done) {
console.info('----------------------Hall_SensorJsTest003---------------------------');
function onSensorCallback(data) {
console.info('Hall_SensorJsTest003 on error');
expect(false).assertTrue();
done();
}
try {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, onSensorCallback, { 'interval': 100000000 }, 5);
} catch (error) {
console.info("Hall_SensorJsTest003 error:" + error);
errMessage = error.toString().slice(12, 49);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:Hall_SensorJsTest004
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest004", 0, async function (done) {
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
setTimeout(() => {
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.name:Hall_SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest005", 0, async function (done) {
function onceSensorCallback(data) {
console.info('Hall_SensorJsTest005 on error');
expect(false).assertTrue();
done();
}
try {
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, onceSensorCallback, 5);
} catch (error) {
console.info("Hall_SensorJsTest005 error:" + error);
errMessage = error.toString().slice(14, 51);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:Hall_SensorJsTest006
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest006", 0, async function (done) {
try {
sensor.off(string, "");
} catch (error) {
console.info("Hall_SensorJsTest006 error:" + error);
errMessage = error.toString().slice(16, 40);
expect(errMessage).assertEqual(errMessages[2]);
done();
}
})
/*
* @tc.name:Hall_SensorJsTest007
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest007", 0, async function (done) {
function onSensorCallback(data) {
console.info('Hall_SensorJsTest007 on error');
expect(false).assertTrue();
done();
}
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, onSensorCallback);
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, onSensorCallback);
setTimeout(() => {
expect(true).assertTrue();
done();
}, 500);
})
/*
* @tc.name:Hall_SensorJsTest008
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest008", 0, async function (done) {
function onSensorCallback(data) {
console.info('Hall_SensorJsTest008 on error');
expect(false).assertTrue();
done();
}
try {
sensor.off(1000000, onSensorCallback);
} catch (error) {
console.info("Hall_SensorJsTest008 error:" + error);
errMessage = error.toString().slice(13, 35);
expect(errMessage).assertEqual(errMessages[1]);
done();
}
})
/*
* @tc.name:Hall_SensorJsTest009
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest009", 0, async function (done) {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback2);
setTimeout(() => {
console.info('----------------------Hall_SensorJsTest009 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL);
console.info('----------------------Hall_SensorJsTest009 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:Hall_SensorJsTest010
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest010", 0, async function (done) {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback2);
setTimeout(() => {
console.info('----------------------Hall_SensorJsTest010 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
console.info('----------------------Hall_SensorJsTest010 off end---------------------------');
}, 500);
setTimeout(() => {
console.info('----------------------Hall_SensorJsTest010 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback2);
console.info('----------------------Hall_SensorJsTest010 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:Hall_SensorJsTest011
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest011", 0, async function (done) {
console.info('----------------------Hall_SensorJsTest011---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback, { 'interval': 100000000 });
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback2);
setTimeout(() => {
console.info('----------------------Hall_SensorJsTest011 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL);
console.info('----------------------Hall_SensorJsTest011 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:Hall_SensorJsTest012
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest012", 0, async function (done) {
console.info('----------------------Hall_SensorJsTest012---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback, { 'interval': 100000000 });
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback2, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------Hall_SensorJsTest012 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback);
console.info('----------------------Hall_SensorJsTest012 off end---------------------------');
}, 500);
setTimeout(() => {
console.info('----------------------Hall_SensorJsTest012 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback2);
console.info('----------------------Hall_SensorJsTest012 off end---------------------------');
done();
}, 1000);
})
/*
* @tc.name:Hall_SensorJsTest013
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("Hall_SensorJsTest013", 0, async function (done) {
console.info('----------------------Hall_SensorJsTest013---------------------------');
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback, { 'interval': 100000000 });
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_HALL, callback2, { 'interval': 100000000 });
setTimeout(() => {
console.info('----------------------Hall_SensorJsTest013 off in---------------------------');
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL);
console.info('----------------------Hall_SensorJsTest013 off end---------------------------');
done();
}, 1000);
})
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import sensor from '@system.sensor';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
describe("SensorJsTest", 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')
})
let errMessages = ['The number of parameters is not valid', 'Wrong argument type, function expected',
'Wrong argument type, should be object']
let errMessage;
/*
* @tc.name:getOnBodyState_SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest001", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest001---------------------------');
try {
sensor.getOnBodyState();
} catch (error) {
console.info('getOnBodyState_SensorJsTest001 error' + error);
errMessage = error.toString().slice(22, 59);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:getOnBodyState_SensorJsTest002
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest002", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest002---------------------------');
try {
sensor.getOnBodyState({
success: function (data) {
console.info("getOnBodyState_SensorJsTest002 success:" + JSON.stringify(data));
expect(typeof (data.value)).assertEqual("boolean");
done();
}
});
} catch (error) {
console.info('getOnBodyState_SensorJsTest002 error' + error);
expect(false).assertTrue();
done();
}
})
/*
* @tc.name:getOnBodyState_SensorJsTest003
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest003", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest003---------------------------');
sensor.getOnBodyState({
success: function (data) {
console.info("getOnBodyState_SensorJsTest003 success:" + JSON.stringify(data));
expect(typeof (data.value)).assertEqual("boolean");
done();
},
fail: function (data, code) {
console.log("getOnBodyState_SensorJsTest003 is failed, data: " + data + ", code: " + code);
expect(false).assertTrue();
},
complete: function () {
console.log('getOnBodyState_SensorJsTest003 is completed');
}
});
})
/*
* @tc.name:getOnBodyState_SensorJsTest004
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest004", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest004---------------------------');
sensor.getOnBodyState({
success: function (data) {
console.info("getOnBodyState_SensorJsTest004 success:" + JSON.stringify(data));
expect(typeof (data.value)).assertEqual("boolean");
done();
},
});
})
/*
* @tc.name:getOnBodyState_SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest005", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest005---------------------------');
sensor.getOnBodyState({
success: function (data) {
console.info("getOnBodyState_SensorJsTest005 success:" + JSON.stringify(data));
expect(typeof (data.value)).assertEqual("boolean");
done();
},
fail: function (data, code) {
console.error('getOnBodyState_SensorJsTest005 failed. Code: ' + code + '; Data: ' + data);
expect(false).assertTrue();
},
});
})
/*
* @tc.name:getOnBodyState_SensorJsTest006
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest006", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest006---------------------------');
sensor.getOnBodyState({
inInvalid: 2,
success: function (data) {
console.info("getOnBodyState_SensorJsTest006 success:" + JSON.stringify(data));
expect(typeof (data.value)).assertEqual("boolean");
done();
},
fail: function (data, code) {
console.error('getOnBodyState_SensorJsTest006 failed. Code: ' + code + '; Data: ' + data);
expect(false).assertTrue();
},
});
})
/*
* @tc.name:getOnBodyState_SensorJsTest007
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest007", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest007---------------------------');
try {
sensor.getOnBodyState({
success: function (data) {
console.info("getOnBodyState_SensorJsTest007 success:" + JSON.stringify(data));
expect(typeof (data.value)).assertEqual("boolean");
},
}, 25);
} catch (error) {
errMessage = error.toString().slice(22, 59);
console.info('getOnBodyState_SensorJsTest007 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:getOnBodyState_SensorJsTest008
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest008", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest008---------------------------');
sensor.getOnBodyState({
success: function (data) {
console.info("getOnBodyState_SensorJsTest008 success:" + JSON.stringify(data));
expect(typeof (data.value)).assertEqual("boolean");
},
fail: function (data, code) {
console.error('getOnBodyState_SensorJsTest008 failed. Code: ' + code + '; Data: ' + data);
expect(false).assertTrue();
},
});
sensor.getOnBodyState({
success: function (data) {
console.info("getOnBodyState_SensorJsTest008 success:" + JSON.stringify(data));
expect(typeof (data.value)).assertEqual("boolean");
},
fail: function (data, code) {
console.error('getOnBodyState_SensorJsTest008_1 failed. Code: ' + code + '; Data: ' + data);
expect(false).assertTrue();
},
});
setTimeout(() => {
done();
}, 500);
})
/*
* @tc.name:getOnBodyState_SensorJsTest009
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest009", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest009---------------------------');
try {
sensor.getOnBodyState('xxx');
} catch (error) {
console.info('getOnBodyState_SensorJsTest009 error:' + error);
errMessage = error.toString().slice(22, 59);
console.info('getOnBodyState_SensorJsTest009 errMessage:' + errMessage);
expect(errMessage).assertEqual(errMessages[2]);
done();
}
})
/*
* @tc.name:getOnBodyState_SensorJsTest010
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest010", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest010---------------------------');
try {
sensor.getOnBodyState();
} catch (error) {
errMessage = error.toString().slice(22, 59);
console.info('getOnBodyState_SensorJsTest010 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:getOnBodyState_SensorJsTest011
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest011", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest011---------------------------');
try {
sensor.getOnBodyState({
success: function (data) {
console.info("getOnBodyState_SensorJsTest011 success:" + JSON.stringify(data));
expect(typeof (data.value)).assertEqual("boolean");
done();
},
}, function () {
}, 25);
} catch (error) {
errMessage = error.toString().slice(22, 59);
console.info('getOnBodyState_SensorJsTest011 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
}
})
/*
* @tc.name:getOnBodyState_SensorJsTest012
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: SR000H0ALK, AR000H0ALM
*/
it("getOnBodyState_SensorJsTest012", 0, async function (done) {
console.info('----------------------getOnBodyState_SensorJsTest012---------------------------');
sensor.getOnBodyState({
success: function (data) {
console.info("getOnBodyState_SensorJsTest012 success:" + JSON.stringify(data));
expect(typeof (data.value)).assertEqual("boolean");
done();
},
fail: function (data, code) {
console.error('getOnBodyState_SensorJsTest012 failed. Code: ' + code + '; Data: ' + data);
expect(false).assertTrue();
done();
},
});
})
})
\ No newline at end of file
......@@ -16,7 +16,7 @@ import sensor from '@system.sensor'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
describe("SensorJsTest", function () {
beforeAll(function () {
beforeAll(function () {
/*
* @tc.setup: setup invoked before all testcases
......@@ -48,7 +48,10 @@ describe("SensorJsTest", function () {
console.info('afterEach caled')
})
var errMessages = ['The number of parameters is not valid', 'Wrong argument type, should be object', 'UnsubscribeSensor failed'];
let errMessages = ['The number of parameters is not valid', 'Wrong argument type, should be object',
'UnsubscribeSensor failed'];
let errMessage;
/*
* @tc.name:subscribeAccelerometer_SensorJsTest001
......@@ -71,7 +74,6 @@ describe("SensorJsTest", function () {
expect(false).assertTrue();
},
});
setTimeout(() => {
try {
sensor.unsubscribeAccelerometer();
......@@ -107,7 +109,6 @@ describe("SensorJsTest", function () {
expect(false).assertTrue();
},
});
setTimeout(() => {
try {
sensor.unsubscribeAccelerometer();
......@@ -181,7 +182,7 @@ describe("SensorJsTest", function () {
},
}, 25);
} catch (error) {
var errMessage = error.toString().slice(19, 56);
errMessage = error.toString().slice(19, 56);
console.info('subscribeAccelerometer_SensorJsTest004 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
......@@ -212,7 +213,7 @@ describe("SensorJsTest", function () {
}, function () {
}, 25);
} catch (error) {
var errMessage = error.toString().slice(19, 56);
errMessage = error.toString().slice(19, 56);
console.info('subscribeAccelerometer_SensorJsTest005 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
......@@ -280,7 +281,7 @@ describe("SensorJsTest", function () {
try {
sensor.subscribeAccelerometer();
} catch (error) {
var errMessage = error.toString().slice(19, 56);
errMessage = error.toString().slice(19, 56);
console.info('subscribeAccelerometer_SensorJsTest007 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
......@@ -298,7 +299,7 @@ describe("SensorJsTest", function () {
try {
sensor.subscribeAccelerometer('xxx');
} catch (error) {
var errMessage = error.toString().slice(19, 56);
errMessage = error.toString().slice(19, 56);
console.info('subscribeAccelerometer_SensorJsTest008 error:' + error);
expect(errMessage).assertEqual(errMessages[1]);
done();
......@@ -316,7 +317,7 @@ describe("SensorJsTest", function () {
try {
sensor.unsubscribeAccelerometer('xxx');
} catch (error) {
var errMessage = error.toString().slice(21, 58);
errMessage = error.toString().slice(21, 58);
console.info('subscribeAccelerometer_SensorJsTest009 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
......@@ -358,7 +359,7 @@ describe("SensorJsTest", function () {
try {
sensor.unsubscribeAccelerometer();
} catch (error) {
var errMessage = error.toString().slice(21, 45);
errMessage = error.toString().slice(21, 45);
console.info('subscribeAccelerometer_SensorJsTest011 error:' + error);
expect(errMessage).assertEqual(errMessages[2]);
done();
......@@ -430,12 +431,10 @@ describe("SensorJsTest", function () {
expect(false).assertTrue();
},
});
try {
sensor.unsubscribeAccelerometer();
} catch (error) {
console.info('subscribeAccelerometer_SensorJsTest014_unsubscribeAccelerometer error' + error);
expect(true).assertTrue();
}
setTimeout(() => {
expect(true).assertTrue();
......
......@@ -48,7 +48,10 @@ describe("SensorJsTest", function () {
console.info('afterEach caled')
})
var errMessages = ['The number of parameters is not valid', 'Wrong argument type, should be object', 'UnsubscribeSensor failed'];
let errMessages = ['The number of parameters is not valid',
'Wrong argument type, should be object', 'UnsubscribeSensor failed'];
let errMessage;
/*
* @tc.name:subscribeGyroscope_SensorJsTest001
......@@ -71,7 +74,6 @@ describe("SensorJsTest", function () {
expect(false).assertTrue();
},
});
setTimeout(() => {
try {
sensor.unsubscribeGyroscope();
......@@ -107,7 +109,6 @@ describe("SensorJsTest", function () {
expect(false).assertTrue();
},
});
setTimeout(() => {
try {
sensor.unsubscribeGyroscope();
......@@ -229,7 +230,7 @@ describe("SensorJsTest", function () {
},
}, 25);
} catch (error) {
var errMessage = error.toString().slice(19, 56);
errMessage = error.toString().slice(19, 56);
console.info('subscribeGyroscope_SensorJsTest006 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
......@@ -260,7 +261,7 @@ describe("SensorJsTest", function () {
}, function () {
}, 25);
} catch (error) {
var errMessage = error.toString().slice(19, 56);
errMessage = error.toString().slice(19, 56);
console.info('subscribeGyroscope_SensorJsTest007 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
......@@ -288,7 +289,6 @@ describe("SensorJsTest", function () {
expect(false).assertTrue();
},
});
sensor.subscribeGyroscope({
interval: 'normal',
success: function (data) {
......@@ -302,7 +302,6 @@ describe("SensorJsTest", function () {
expect(false).assertTrue();
},
});
setTimeout(() => {
try {
sensor.unsubscribeGyroscope();
......@@ -328,7 +327,7 @@ describe("SensorJsTest", function () {
try {
sensor.subscribeGyroscope();
} catch (error) {
var errMessage = error.toString().slice(19, 56);
errMessage = error.toString().slice(19, 56);
console.info('subscribeGyroscope_SensorJsTest009 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
......@@ -346,7 +345,7 @@ describe("SensorJsTest", function () {
try {
sensor.subscribeGyroscope('xxx');
} catch (error) {
var errMessage = error.toString().slice(19, 56);
errMessage = error.toString().slice(19, 56);
console.info('subscribeGyroscope_SensorJsTest010 error:' + error);
expect(errMessage).assertEqual(errMessages[1]);
done();
......@@ -364,7 +363,7 @@ describe("SensorJsTest", function () {
try {
sensor.unsubscribeGyroscope();
} catch (error) {
var errMessage = error.toString().slice(21, 45);
errMessage = error.toString().slice(21, 45);
console.info('subscribeGyroscope_SensorJsTest011 error:' + error);
expect(errMessage).assertEqual(errMessages[2]);
done();
......@@ -382,7 +381,7 @@ describe("SensorJsTest", function () {
try {
sensor.unsubscribeGyroscope('xxx');
} catch (error) {
var errMessage = error.toString().slice(21, 58);
errMessage = error.toString().slice(21, 58);
console.info('subscribeGyroscope_SensorJsTest012 error:' + error);
expect(errMessage).assertEqual(errMessages[0]);
done();
......@@ -431,12 +430,10 @@ describe("SensorJsTest", function () {
expect(false).assertTrue();
},
});
try {
sensor.unsubscribeGyroscope();
} catch (error) {
console.info('subscribeAccelerometer_SensorJsTest014_unsubscribeAccelerometer error' + error);
expect(false).assertTrue();
}
setTimeout(() => {
expect(true).assertTrue();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册