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

!8555 【XTS】【communication】【3.2release】优化bt,lbs脚本

Merge pull request !8555 from 权力/myfeature2
......@@ -106,6 +106,16 @@
"when": "inuse"
}
},
{
"name": "ohos.permission.APPROXIMATELY_LOCATION",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.DISCOVER_BLUETOOTH",
"reason": "",
......
......@@ -120,6 +120,16 @@
"when": "inuse"
}
},
{
"name": "ohos.permission.APPROXIMATELY_LOCATION",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.LOCATION",
"reason": "",
......
......@@ -217,18 +217,18 @@ describe('bluetoothBLETest', function() {
await sleep(5000)
try {
await gattClient.getDeviceName().then((data) => {
console.info('[bluetooth_js] device name' + JSON.stringify(data))
console.info('[bluetooth_js] device name:' + JSON.stringify(data))
expect(data).assertNull();
done();
}).catch(err => {
console.error('bluetooth getDeviceName has error: '+ err);
expect(true).assertFalse();
console.error('[bluetooth_js] bluetooth getDeviceName has error: '+ JSON.stringify(err));
expect(err).assertFalse();
done();
});
} catch (error) {
console.error(`[bluetooth_js]GetDeviceName_0100 failed, code is ${error.code},
message is ${error.message}`);
expect(true).assertFalse();
expect(true).assertFalse();
done()
}
})
......
......@@ -16,6 +16,32 @@
import bluetooth from '@ohos.bluetoothManager';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import osaccount from '@ohos.account.osAccount'
import bundle from '@ohos.bundle'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
async function applyPermission() {
let osAccountManager = osaccount.getAccountManager();
console.info("=== getAccountManager finish");
let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
console.info("LocalId is :" + localId);0
let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.bluetooth.bluetoothhost', 0, localId);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName = 'ohos.permission.LOCATION';
await atManager.grantUserGrantedPermission(tokenID, permissionName, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
}).catch((err) => {
console.info('[permis' +
'sion] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
export default function bluetoothBLETest6() {
describe('bluetoothBLETest6', function() {
function sleep(delay) {
......@@ -48,8 +74,10 @@ describe('bluetoothBLETest6', function() {
console.info('[bluetooth_js] enable success');
}
}
beforeAll(function () {
beforeAll(async function (done) {
console.info('beforeAll called')
await applyPermission();
done();
})
beforeEach(async function(done) {
console.info('beforeEach called')
......
......@@ -110,6 +110,16 @@
"when": "inuse"
}
},
{
"name": "ohos.permission.APPROXIMATELY_LOCATION",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.DISCOVER_BLUETOOTH",
"reason": "",
......
......@@ -106,6 +106,16 @@
"when": "inuse"
}
},
{
"name": "ohos.permission.APPROXIMATELY_LOCATION",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
......
......@@ -96,6 +96,16 @@
"when": "inuse"
}
},
{
"name": "ohos.permission.APPROXIMATELY_LOCATION",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS",
"reason": "use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
......
......@@ -14,26 +14,41 @@
*/
import bluetooth from '@ohos.bluetooth';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
const PERMISSION_USER_SET = 1;
const PERMISSION_USER_NAME1 = "ohos.permission.LOCATION";
const PERMISSION_USER_NAME2 = 'ohos.permission.LOCATION_IN_BACKGROUND';
let tokenID = undefined;
async function grantPerm() {
console.info("====grant Permission start====");
let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.bluetooth.bluetoothhost', 0, 100);
tokenID = appInfo.accessTokenId;
console.info("accessTokenId" + appInfo.accessTokenId + " bundleName:" + appInfo.bundleName);
import osaccount from '@ohos.account.osAccount'
import bundle from '@ohos.bundle'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
async function applyPermission() {
let osAccountManager = osaccount.getAccountManager();
console.info("=== getAccountManager finish");
let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
console.info("LocalId is :" + localId);0
let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.bluetooth.bluetoothhost', 0, localId);
let atManager = abilityAccessCtrl.createAtManager();
let result = await atManager.grantUserGrantedPermission(tokenID, PERMISSION_USER_NAME1, PERMISSION_USER_SET);
console.info("tokenId" + tokenID + " result:" + result);
let result1 = await atManager.grantUserGrantedPermission(tokenID, PERMISSION_USER_NAME2, PERMISSION_USER_SET);
console.info("tokenId" + tokenID + " result1:" + result1);
console.info("====grant Permission end====");
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName = 'ohos.permission.LOCATION';
let permissionName1 = 'ohos.permission.APPROXIMATELY_LOCATION';
await atManager.grantUserGrantedPermission(tokenID, permissionName, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
}).catch((err) => {
console.info('[permis' +
'sion] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success1 :' + JSON.stringify(result));
}).catch((err) => {
console.info('[permis' +
'sion] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
export default function bluetoothhostTest3() {
describe('bluetoothhostTest3', function() {
function sleep(delay) {
......@@ -69,7 +84,7 @@ describe('bluetoothhostTest3', function() {
beforeAll(async function (done) {
console.info('beforeAll called')
await grantPerm();
await applyPermission();
done()
})
beforeEach(async function(done) {
......@@ -122,6 +137,8 @@ describe('bluetoothhostTest3', function() {
*/
it('SUB_COMMUNICATION_BLUETOOTH_BR_Discovery_0300', 0, async function (done) {
let result1 = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_CONNECTABLE,10);
console.info('[bluetooth_js] setBluetoothScanMode = '+ JSON.stringify(result1));
await sleep(3000);
expect(result1).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] getScanMode = '+ JSON.stringify(getScanMode));
......
......@@ -332,12 +332,14 @@ describe('bluetoothhostTest2', function() {
let oldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0800 oldScanMode = '+ JSON.stringify(oldScanMode));
let result = bluetooth.setBluetoothScanMode(bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE,0);
expect(result).assertTrue();
console.info('[bluetooth_js] result = '+ JSON.stringify(result));
// expect(result).assertTrue();
let getScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0800 getScanMode = '+ JSON.stringify(getScanMode));
expect(true).assertEqual(getScanMode == bluetooth.ScanMode.SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE);
result=bluetooth.setBluetoothScanMode(oldScanMode,0);
expect(result).assertTrue();
console.info('[bluetooth_js] result1 = '+ JSON.stringify(result));
// expect(result).assertTrue();
let getOldScanMode = bluetooth.getBluetoothScanMode();
console.info('[bluetooth_js] ScanMode_0800 getOldScanMode = '+ JSON.stringify(getOldScanMode));
expect(true).assertEqual(oldScanMode == getOldScanMode);
......
......@@ -15,13 +15,6 @@
import bluetooth from '@ohos.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
let BluetoothState = {
STATE_OFF: 0,STATE_TURNING_ON: 1,
STATE_ON: 2,STATE_TURNING_OFF: 3,
STATE_BLE_TURNING_ON: 4, STATE_BLE_ON: 5,
STATE_BLE_TURNING_OFF: 6
};
export default function bluetoothhostTest() {
describe('bluetoothhostTest', function() {
......@@ -126,6 +119,39 @@ describe('bluetoothhostTest', function() {
}
done()
})
/**
* @tc.number COMMUNICATION_BLUETOOTH_SwitchOff_0444
* @tc.name testEnableBluetooth and getState
* @tc.desc Test EnableBluetooth api by promise.
* @tc.size MEDIUM
* @tc.type Function
* @tc.level Level 0
*/
it('COMMUNICATION_BLUETOOTH_SwitchOff_0444', 0, async function (done) {
let STATE_ON = bluetooth.BluetoothState.STATE_ON;
console.info("[bluetooth_js]STATE_ON : " + JSON.stringify(STATE_ON));
expect(true).assertTrue(STATE_ON == 2);
let STATE_OFF = bluetooth.BluetoothState.STATE_OFF;
console.info("[bluetooth_js]STATE_OFF : " + JSON.stringify(STATE_OFF));
expect(true).assertTrue(STATE_OFF == 0);
let STATE_TURNING_ON = bluetooth.BluetoothState.STATE_TURNING_ON;
console.info("[bluetooth_js]STATE_TURNING_ON : " + JSON.stringify(STATE_TURNING_ON));
expect(true).assertTrue(STATE_TURNING_ON == 1);
let STATE_TURNING_OFF = bluetooth.BluetoothState.STATE_TURNING_OFF;
console.info("[bluetooth_js]STATE_TURNING_OFF : " + JSON.stringify(STATE_TURNING_OFF));
expect(true).assertTrue(STATE_TURNING_OFF == 3);
let STATE_BLE_TURNING_ON = bluetooth.BluetoothState.STATE_BLE_TURNING_ON;
console.info("[bluetooth_js]STATE_BLE_TURNING_ON : " + JSON.stringify(STATE_BLE_TURNING_ON));
expect(true).assertTrue(STATE_BLE_TURNING_ON == 4);
let STATE_BLE_ON = bluetooth.BluetoothState.STATE_BLE_ON;
console.info("[bluetooth_js]STATE_BLE_ON : " + JSON.stringify(STATE_BLE_ON));
expect(true).assertTrue(STATE_BLE_ON == 5);
let STATE_BLE_TURNING_OFF = bluetooth.BluetoothState.STATE_BLE_TURNING_OFF;
console.info("[bluetooth_js]STATE_BLE_TURNING_OFF : " + JSON.stringify(STATE_BLE_TURNING_OFF));
expect(true).assertTrue(STATE_BLE_TURNING_OFF == 6);
done()
})
})
}
......
......@@ -15,14 +15,14 @@
import bluetoothhostTest1 from './BRSetLocalName.test.js'
import bluetoothhostTest2 from './BRScanMode.test.js'
import bluetoothhostTest3 from './BRDiscovery.test.js'
import bluetoothhostTest4 from './BRSpp.test.js'
import bluetoothhostTest from './BRSwitch.test.js'
import bluetoothhostTest3 from './BRDiscovery.test.js'
export default function testsuite() {
bluetoothhostTest()
bluetoothhostTest1()
bluetoothhostTest2()
bluetoothhostTest3()
bluetoothhostTest4()
bluetoothhostTest()
bluetoothhostTest3()
}
......@@ -96,6 +96,16 @@
"when": "inuse"
}
},
{
"name": "ohos.permission.APPROXIMATELY_LOCATION",
"reason": "",
"usedScene": {
"ability": [
"ohos.acts.communication.bluetooth.bluetoothhost.MainAbility"
],
"when": "inuse"
}
},
{
"name": "ohos.permission.MANAGE_BLUETOOTH",
"reason": "",
......
......@@ -17,6 +17,39 @@ import bluetoothManager from '@ohos.bluetoothManager';
import bluetooth from '@ohos.bluetooth';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import osaccount from '@ohos.account.osAccount'
import bundle from '@ohos.bundle'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
async function applyPermission() {
let osAccountManager = osaccount.getAccountManager();
console.info("=== getAccountManager finish");
let localId = await osAccountManager.getOsAccountLocalIdFromProcess();
console.info("LocalId is :" + localId);0
let appInfo = await bundle.getApplicationInfo('ohos.acts.communication.bluetooth.bluetoothhost', 0, localId);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName = 'ohos.permission.LOCATION';
let permissionName1 = 'ohos.permission.APPROXIMATELY_LOCATION';
await atManager.grantUserGrantedPermission(tokenID, permissionName, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + JSON.stringify(result));
}).catch((err) => {
console.info('[permis' +
'sion] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success1 :' + JSON.stringify(result));
}).catch((err) => {
console.info('[permis' +
'sion] case grantUserGrantedPermission failed :' + JSON.stringify(err));
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
export default function bluetoothBLETest3() {
describe('bluetoothBLETest3', function() {
let gattServer = null;
......@@ -47,10 +80,12 @@ describe('bluetoothBLETest3', function() {
console.info('[bluetooth_js] enable success');
}
}
beforeAll(function () {
beforeAll(async function (done) {
console.info('beforeAll called')
gattServer = bluetoothManager.BLE.createGattServer();
gattClient = bluetoothManager.BLE.createGattClientDevice("11:22:33:44:55:66");
await applyPermission();
done();
})
beforeEach(async function(done) {
console.info('beforeEach called')
......
......@@ -164,17 +164,20 @@ export default function geolocationTest_geo5() {
let reverseGeocodeRequest = { "latitude": 31.265496, "longitude": 121.62771, "maxItems": 5};
await geolocationm.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
console.info('[lbs_js] getAddressesFromLocation21 promise: ' + JSON.stringify(data));
console.info('addressUrl: ' + JSON.stringify(data)[0].addressUrl
+ JSON.stringify(data)[0].administrativeArea + JSON.stringify(data)[0].countryCode
+ JSON.stringify(data)[0].countryName + JSON.stringify(data)[0].descriptions
+ JSON.stringify(data)[0].descriptionsSize + data[0].latitude
+ JSON.stringify(data)[0].locale + JSON.stringify(data)[0].locality
+ JSON.stringify(data)[0].longitude + JSON.stringify(data)[0].phoneNumber
+ JSON.stringify(data)[0].placeName
+ JSON.stringify(data)[0].postalCode + JSON.stringify(data)[0].premises
+ JSON.stringify(data)[0].roadName + JSON.stringify(data)[0].subAdministrativeArea
+ JSON.stringify(data)[0].subLocality + JSON.stringify(data)[0].subRoadName
+ JSON.stringify(data)[0].isFromMock);
if(data!="")
{
console.info('addressUrl: ' + JSON.stringify(data)[0].addressUrl
+ JSON.stringify(data)[0].administrativeArea + JSON.stringify(data)[0].countryCode
+ JSON.stringify(data)[0].countryName + JSON.stringify(data)[0].descriptions
+ JSON.stringify(data)[0].descriptionsSize + data[0].latitude
+ JSON.stringify(data)[0].locale + JSON.stringify(data)[0].locality
+ JSON.stringify(data)[0].longitude + JSON.stringify(data)[0].phoneNumber
+ JSON.stringify(data)[0].placeName
+ JSON.stringify(data)[0].postalCode + JSON.stringify(data)[0].premises
+ JSON.stringify(data)[0].roadName + JSON.stringify(data)[0].subAdministrativeArea
+ JSON.stringify(data)[0].subLocality + JSON.stringify(data)[0].subRoadName
+ JSON.stringify(data)[0].isFromMock);
}
}).catch(error => {
console.info("[lbs_js] getAddressesFromLocation21 promise then error." + JSON.stringify(error));
console.info('[lbs_js] not support now');
......
......@@ -612,7 +612,6 @@ export default function geolocationTest_geo7() {
console.info('[lbs_js] sendcommand promise err:' + JSON.stringify(error));
console.info('[lbs_js] not support now');
expect(error.code).assertEqual(801);
//expect(true).assertEqual(JSON.stringify(error) != null);
done();
})
} catch (error) {
......@@ -1180,11 +1179,11 @@ export default function geolocationTest_geo7() {
try {
let last =geolocationm.getLastLocation();
console.info('[lbs_js] getLastLocation latitude: ' + last.latitude +
' longitude: ' + result.longitude +' altitude: ' + result.altitude
+' accuracy: ' + result.accuracy+' speed: ' + result.speed +
'timeStamp: ' + result.timeStamp+'direction:' + result.direction+' timeSinceBoot: '
+ result.timeSinceBoot +'additions: ' + result.additions+' additionSize' + result.additionSize
+ 'isFromMock' +result.isFromMock);
' longitude: ' + last.longitude +' altitude: ' + last.altitude
+' accuracy: ' + last.accuracy+' speed: ' + last.speed +
'timeStamp: ' + last.timeStamp+'direction:' + last.direction+' timeSinceBoot: '
+ last.timeSinceBoot +'additions: ' + last.additions+' additionSize' + last.additionSize
+ 'isFromMock' +last.isFromMock);
expect(true).assertEqual(JSON.stringify(last) != null);
} catch (error) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册