提交 a0a84820 编写于 作者: O openharmony_ci 提交者: liuzixuan10

add sensor js interface testcase

Signed-off-by: Nliuzixuan10 <liuzixuan10@huawei.com>
...@@ -1685,19 +1685,19 @@ describe('ActsBundleManagerTest', function () { ...@@ -1685,19 +1685,19 @@ describe('ActsBundleManagerTest', function () {
*/ */
it('getApplicationInfo_0700', 0, async function (done) { it('getApplicationInfo_0700', 0, async function (done) {
let installData = await demo.getBundleInstaller(); let installData = await demo.getBundleInstaller();
installData.install([PATH + BMSJSTEST2, PATH + BMSJSTEST3], { installData.install([PATH + BMSJSTEST2, PATH + BMSJSTEST3], installParam, async (err, data) => {
userId: 0,
installFlag: 0,
isKeepData: false
}, async (err, data) => {
expect(err.code).assertEqual(0); expect(err.code).assertEqual(0);
expect(data.status).assertEqual(0); expect(data.status).assertEqual(0);
expect(data.statusMessage).assertEqual('SUCCESS'); expect(data.statusMessage).assertEqual('SUCCESS');
getInfo(); getInfo();
}); });
async function getInfo() { async function getInfo() {
await demo.getApplicationInfo(NAME2, demo.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, await demo.getApplicationInfo(NAME2, BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, 0, (error, datainfo) => {
demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES, (error, datainfo) => { if (error) {
console.info("getApplicationInfo error" + JSON.stringify(error))
expect(error).assertFail()
}
console.info("getApplicationInfo success" + JSON.stringify(datainfo))
expect(typeof datainfo).assertEqual(OBJECT) expect(typeof datainfo).assertEqual(OBJECT)
expect(datainfo.name).assertEqual(NAME2) expect(datainfo.name).assertEqual(NAME2)
expect(datainfo.label).assertEqual("$string:app_name") expect(datainfo.label).assertEqual("$string:app_name")
...@@ -1712,11 +1712,7 @@ describe('ActsBundleManagerTest', function () { ...@@ -1712,11 +1712,7 @@ describe('ActsBundleManagerTest', function () {
expect(datainfo.labelId >= 0).assertTrue() expect(datainfo.labelId >= 0).assertTrue()
expect(datainfo.systemApp).assertEqual(true) expect(datainfo.systemApp).assertEqual(true)
expect(datainfo.supportedModes).assertEqual(0) expect(datainfo.supportedModes).assertEqual(0)
installData.uninstall(NAME2, { installData.uninstall(NAME2, installParam, (err, data) => {
userId: 0,
installFlag: 0,
isKeepData: false
}, (err, data) => {
expect(err.code).assertEqual(0); expect(err.code).assertEqual(0);
expect(data.status).assertEqual(0); expect(data.status).assertEqual(0);
expect(data.statusMessage).assertEqual('SUCCESS'); expect(data.statusMessage).assertEqual('SUCCESS');
...@@ -2030,7 +2026,7 @@ describe('ActsBundleManagerTest', function () { ...@@ -2030,7 +2026,7 @@ describe('ActsBundleManagerTest', function () {
it('getApplicationInfo_0900', 0, async function (done) { it('getApplicationInfo_0900', 0, async function (done) {
demo.getApplicationInfo(ERROR, BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, 0, (error, datainfo) => { demo.getApplicationInfo(ERROR, BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, 0, (error, datainfo) => {
if (error) { if (error) {
console.error("getApplicationInfo fail" + JSON.stringify(error)); console.info("getApplicationInfo fail" + JSON.stringify(error));
expect(error).assertEqual(1); expect(error).assertEqual(1);
done() done()
return; return;
...@@ -2740,47 +2736,50 @@ describe('ActsBundleManagerTest', function () { ...@@ -2740,47 +2736,50 @@ describe('ActsBundleManagerTest', function () {
*/ */
it('install_0300', 0, async function (done) { it('install_0300', 0, async function (done) {
let installData = await demo.getBundleInstaller() let installData = await demo.getBundleInstaller()
installData.install([PATH + BMSJSTEST4, PATH + BMSJSTEST5, PATH + BMSJSTEST6], { installData.install([PATH + BMSJSTEST4], installParam, async (err, data) => {
userId: 0, expect(err.code).assertEqual(0);
installFlag: 0, expect(data.statusMessage).assertEqual('SUCCESS');
isKeepData: false installData.install([PATH + BMSJSTEST5], installParam, async (err, data) => {
}, async (err, data) => { expect(err.code).assertEqual(0);
expect(err.code).assertEqual(-1); expect(data.statusMessage).assertEqual('SUCCESS');
expect(data.status).assertEqual(3); installData.install([PATH + BMSJSTEST6], installParam, async (err, data) => {
expect(data.statusMessage).assertEqual('STATUS_INSTALL_FAILURE_INVALID'); expect(err.code).assertEqual(0);
getInfo(); expect(data.statusMessage).assertEqual('SUCCESS');
getInfo();
});
});
}); });
async function getInfo() { async function getInfo() {
var datainfo1 = await demo.getBundleInfo(NAME3, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES); await demo.getBundleInfo(NAME3, BundleFlag.GET_BUNDLE_WITH_ABILITIES).then(dataInfo1 => {
expect(datainfo1.name).assertEqual(''); expect(dataInfo1.name).assertEqual(NAME3);
expect(datainfo1.uid < UIDMINVALUE).assertTrue(); }).catch(errInfo => {
var datainfo2 = await demo.getBundleInfo(NAME4, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES); expect(errInfo).assertFail()
expect(datainfo2.name).assertEqual(''); });
expect(datainfo2.uid < UIDMINVALUE).assertTrue(); await demo.getBundleInfo(NAME4, BundleFlag.GET_BUNDLE_WITH_ABILITIES).then(dataInfo2 => {
var datainfo3 = await demo.getBundleInfo(NAME5, demo.BundleFlag.GET_BUNDLE_WITH_ABILITIES); expect(dataInfo2.name).assertEqual(NAME4);
expect(datainfo3.name).assertEqual(''); }).catch(errInfo => {
expect(datainfo3.uid < UIDMINVALUE).assertTrue(); expect(errInfo).assertFail()
installData.uninstall(NAME3, { });
userId: 0, await demo.getBundleInfo(NAME5, BundleFlag.GET_BUNDLE_WITH_ABILITIES).then(dataInfo3 => {
installFlag: 0, expect(dataInfo3.name).assertEqual(NAME5);
isKeepData: false }).catch(errInfo => {
}, (err, data) => { expect(errInfo).assertFail()
installData.uninstall(NAME4, { });
userId: 0, installData.uninstall(NAME3, installParam, (err, data) => {
installFlag: 0, console.info("uninstall----result1" + JSON.stringify(data))
isKeepData: false expect(err.code).assertEqual(0);
}, (err, data) => { expect(data.statusMessage).assertEqual('SUCCESS');
installData.uninstall(NAME5, { installData.uninstall(NAME4, installParam, (err, data) => {
userId: 0, console.info("uninstall----result2" + JSON.stringify(data))
installFlag: 0, expect(err.code).assertEqual(0);
isKeepData: false expect(data.statusMessage).assertEqual('SUCCESS');
}, (err, data) => { installData.uninstall(NAME5, installParam, (err, data) => {
console.info("uninstall----result3" + JSON.stringify(data))
expect(err.code).assertEqual(0);
expect(data.statusMessage).assertEqual('SUCCESS');
done(); done();
}); });
}); });
expect(err.code).assertEqual(-1);
expect(data.status).assertEqual(7);
expect(data.statusMessage).assertEqual('STATUS_UNINSTALL_FAILURE');
}); });
} }
}) })
......
...@@ -67,9 +67,16 @@ describe('ActsBundleManagerUninstall', function () { ...@@ -67,9 +67,16 @@ describe('ActsBundleManagerUninstall', function () {
installFlag: 1, installFlag: 1,
isKeepData: false isKeepData: false
}, async (err, data) => { }, async (err, data) => {
var datainfo2 = await demo.getBundleInfo(NAME1, 1); expect(err.code).assertEqual(0);
expect(datainfo2.name).assertEqual(''); expect(data.statusMessage).assertEqual('SUCCESS');
done(); await demo.getBundleInfo(NAME1, 1).then(datainfo => {
expect(datainfo).assertFail()
done();
}).catch(err => {
expect(err).assertEqual(1)
done()
});
}) })
}); });
}) })
...@@ -178,8 +185,8 @@ describe('ActsBundleManagerUninstall', function () { ...@@ -178,8 +185,8 @@ describe('ActsBundleManagerUninstall', function () {
function OnReceiveinstallEvent(err, data) { function OnReceiveinstallEvent(err, data) {
expect(typeof data).assertEqual(OBJECT); expect(typeof data).assertEqual(OBJECT);
expect(data.statusMessage).assertEqual("STATUS_UNINSTALL_FAILURE"); expect(data.statusMessage).assertEqual("STATUS_UNINSTALL_FAILURE");
done();
} }
done();
}); });
}) })
...@@ -242,16 +249,24 @@ describe('ActsBundleManagerUninstall', function () { ...@@ -242,16 +249,24 @@ describe('ActsBundleManagerUninstall', function () {
async function OnReceiveinstallEvent(err, data) { async function OnReceiveinstallEvent(err, data) {
expect(typeof data).assertEqual(OBJECT); expect(typeof data).assertEqual(OBJECT);
expect(data.statusMessage).assertEqual(SUCCESS); expect(data.statusMessage).assertEqual(SUCCESS);
var datainfo1 = await demo.getBundleInfo(NAME1, 1); await demo.getBundleInfo(NAME1, 1).then(datainfo1 => {
expect(datainfo1.name).assertEqual(NAME1); expect(datainfo1.name).assertEqual(NAME1);
}).catch(err => {
expect(err).assertFail();
});
result.uninstall(NAME1, { result.uninstall(NAME1, {
userId: 0, userId: 0,
installFlag: 1, installFlag: 1,
isKeepData: false isKeepData: false
}, async(err, data) => { }, async(err, data) => {
var datainfo2 = await demo.getBundleInfo(NAME1, 1); expect(data.statusMessage).assertEqual(SUCCESS);
expect(datainfo2.name).assertEqual(''); await demo.getBundleInfo(NAME1, 1).then(datainfo2 => {
done(); expect(datainfo2).assertFail();
done();
}).catch(err => {
expect(err).assertEqual(1);
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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest001 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_BAROMETER, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 on success pressure: ' + data.pressure);
expect(typeof (data.pressure)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest005 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_WEAR_DETECTION, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 once success value: ' + data.value);
expect(typeof (data.value)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest005 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_MAGNETIC_FIELD_UNCALIBRATED, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest001 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, function (error, data) {
if (error) {
console.info('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest001 on success, x: ' + data.x + "y: " + data.y + "z: " + data.z);
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_GRAVITY, onceSensorCallback);
})
})
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import sensor from '@ohos.sensor'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
describe("SensorJsTest", 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_GYROSCOPE_UNCALIBRATED, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest001 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HALL, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 on success status: ' + data.status);
expect(typeof (data.status)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest005 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 () {
beforeAll(function () {
/*
* @tc.setup: setup invoked before all testcases
*/
console.info('beforeAll caled')
})
afterAll(function () {
/*
* @tc.teardown: teardown invoked after all testcases
*/
console.info('afterAll caled')
})
beforeEach(function () {
/*
* @tc.setup: setup invoked before each testcases
*/
console.info('beforeEach caled')
})
afterEach(function () {
/*
* @tc.teardown: teardown invoked after each testcases
*/
console.info('afterEach caled')
})
/*
* @tc.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HUMIDITY, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 on success humidity: ' + data.humidity);
expect(typeof (data.humidity)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest005 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_LINEAR_ACCELERATION, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest001 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_SIGNIFICANT_MOTION, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 once success scalar: ' + data.scalar);
expect(typeof (data.scalar)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest005 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, function (error, data) {
if (error) {
console.info('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest001 once success, x: ' + data.x + "y: " + data.y + "z: " + data.z);
expect(typeof (data.x)).assertEqual("number");
expect(typeof (data.y)).assertEqual("number");
expect(typeof (data.z)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ORIENTATION, onceSensorCallback);
})
})
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import sensor from '@ohos.sensor'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
describe("SensorJsTest", 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 once success steps: ' + data.steps);
expect(typeof (data.steps)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest005 once success steps: ' + data.steps);
expect(typeof (data.steps)).assertEqual("number");
}
setTimeout(() => {
done();
}, 500);
}
sensor.once(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER, 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 () {
beforeAll(function () {
/*
* @tc.setup: setup invoked before all testcases
*/
console.info('beforeAll caled')
})
afterAll(function () {
/*
* @tc.teardown: teardown invoked after all testcases
*/
console.info('afterAll caled')
})
beforeEach(function () {
/*
* @tc.setup: setup invoked before each testcases
*/
console.info('beforeEach caled')
})
afterEach(function () {
/*
* @tc.teardown: teardown invoked after each testcases
*/
console.info('afterEach caled')
})
/*
* @tc.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PEDOMETER_DETECTION, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 once success scalar: ' + data.scalar);
expect(typeof (data.scalar)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest005 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_PROXIMITY, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 on success distance: ' + data.distance);
expect(typeof (data.distance)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest005 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_HEART_RATE, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 once success heartRate: ' + data.heartRate);
expect(typeof (data.heartRate)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest005 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_AMBIENT_TEMPERATURE, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 once success temperature: ' + data.temperature);
expect(typeof (data.temperature)).assertEqual("number");
setTimeout(() => {
resolve();
}, 500);
}
});
})
await promise.then(() => {
return offPromise();
}, () => {
console.info("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest005 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 } 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.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest001", 0, async function (done) {
console.info('----------------------SensorJsTest001---------------------------');
function offPromise() {
return new Promise((resolve, reject) => {
sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, (error) => {
if (error) {
console.info('SensorJsTest001 off error');
expect(false).assertTrue();
console.info('setTimeout ..start')
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 off success');
expect(true).assertTrue();
setTimeout(() => {
resolve();
}, 500);
}
}, 1000)
})
}
let promise = new Promise((resolve, reject) => {
sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ROTATION_VECTOR, function (error, data) {
if (error) {
console.info('SensorJsTest001 on error');
expect(false).assertTrue();
setTimeout((err) => {
reject(err);
}, 500);
} else {
console.info('SensorJsTest001 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("SensorJsTest001 reject");
})
done();
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it("SensorJsTest005", 0, async function (done) {
function onceSensorCallback(error, data) {
if (error) {
console.info('SensorJsTest005 once error');
expect(false).assertTrue();
} else {
console.info('SensorJsTest001 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_ROTATION_VECTOR, onceSensorCallback);
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册