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

!3103 适配getAbilityIcon的fail用例+补充测试场景

Merge pull request !3103 from ry/master
...@@ -14,30 +14,39 @@ ...@@ -14,30 +14,39 @@
*/ */
import bundle from '@ohos.bundle' import bundle from '@ohos.bundle'
import image from '@ohos.multimedia.image'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
const BUNDLE_NAME = "com.ohos.callui" const BUNDLE_NAME = "com.open.harmony.packagemag";
const ABILITIY_NAME = "com.ohos.callui.MainAbility" const ABILITIY_NAME = "com.open.harmony.packagemag.MainAbility";
const SERVICE_NAME = "com.open.harmony.packagemag.ServiceAbility";
const BUNDLE_NAME_OTHER = "com.ohos.settings";
const ABILITIY_NAME_OTHER = "com.ohos.settings.MainAbility";
const BUNDLE_NAME_ERROR = "com.ohos.packagemag";
const ABILITIY_NAME_ERROR = "com.ohos.packagemag.MainAbility";
export default function getAbilityIcon() { export default function getAbilityIcon() {
describe('ActsBmsGetAbilityIconTest', function () { describe('ActsBmsGetAbilityIconTest', function () {
/* /*
* @tc.number: bms_getAbilityIcon_0100 * @tc.number: bms_getAbilityIcon_0100
* @tc.name: test getAbilityIcon` * @tc.name: test getAbilityIcon
* @tc.desc: get the abilityIcon * @tc.desc: get the abilityIcon
*/ */
it('bms_getAbilityIcon_0100', 0, async function (done) { it('bms_getAbilityIcon_0100', 0, async function (done) {
bundle.getAbilityIcon(BUNDLE_NAME, ABILITIY_NAME).then(pixelmap => { await bundle.getAbilityIcon(BUNDLE_NAME_OTHER, ABILITIY_NAME_OTHER).then(pixelmap => {
console.log('bms_getAbilityIcon_0100 success: ' + pixelmap); image = pixelmap;
expect(pixelmap !== null).assertTrue(); console.log('bms_getAbilityIcon_0100 success: ' + image.getBytesNumberPerRow());
expect(image.getBytesNumberPerRow()).assertLarger(0);
}).catch(err => {
console.info("getAbilityIcon fail:" + JSON.stringify(err));
expect(err).assertFail();
});
bundle.getAbilityIcon(BUNDLE_NAME_OTHER, ABILITIY_NAME_OTHER, (err, pixelmap) => {
expect(err).assertEqual(0);
expect(image.getBytesNumberPerRow()).assertLarger(0);
done(); done();
}) });
.catch(err => {
console.info("getAbilityIcon fail:" + JSON.stringify(err))
expect(err).assertFail();
done();
});
}); });
/* /*
...@@ -46,11 +55,112 @@ export default function getAbilityIcon() { ...@@ -46,11 +55,112 @@ export default function getAbilityIcon() {
* @tc.desc: get the abilityIcon * @tc.desc: get the abilityIcon
*/ */
it('bms_getAbilityIcon_0200', 0, async function (done) { it('bms_getAbilityIcon_0200', 0, async function (done) {
await bundle.getAbilityIcon(BUNDLE_NAME, ABILITIY_NAME).then(pixelmap => {
image = pixelmap;
console.log('bms_getAbilityIcon_0200 success: ' + image.getBytesNumberPerRow());
expect(image.getBytesNumberPerRow()).assertLarger(0);
}).catch(err => {
console.info("getAbilityIcon fail:" + JSON.stringify(err));
expect(err).assertFail();
});
bundle.getAbilityIcon(BUNDLE_NAME, ABILITIY_NAME, (err, pixelmap) => { bundle.getAbilityIcon(BUNDLE_NAME, ABILITIY_NAME, (err, pixelmap) => {
expect(err).assertEqual(0); expect(err).assertEqual(0);
expect(pixelmap !== null).assertTrue(); expect(image.getBytesNumberPerRow()).assertLarger(0);
done(); done();
}); });
}); });
/*
* @tc.number: bms_getAbilityIcon_0300
* @tc.name: test getAbilityIcon
* @tc.desc: get the abilityIcon
*/
it('bms_getAbilityIcon_0300', 0, async function (done) {
await bundle.getAbilityIcon(BUNDLE_NAME, SERVICE_NAME).then(pixelmap => {
expect(err).assertFail();
}).catch(err => {
console.info("getAbilityIcon fail:" + JSON.stringify(err));
expect(err).assertEqual(1);
});
bundle.getAbilityIcon(BUNDLE_NAME, SERVICE_NAME, (err, pixelmap) => {
expect(err).assertEqual(1);
done();
});
});
/*
* @tc.number: bms_getAbilityIcon_0400
* @tc.name: test getAbilityIcon
* @tc.desc: get the abilityIcon
*/
it('bms_getAbilityIcon_0400', 0, async function (done) {
await bundle.getAbilityIcon(BUNDLE_NAME, ABILITIY_NAME_ERROR).then(pixelmap => {
expect(pixelmap !== null).assertFail();
}).catch(err => {
console.info("getAbilityIcon fail:" + JSON.stringify(err))
expect(err).assertEqual(1);
});
await bundle.getAbilityIcon(BUNDLE_NAME_ERROR, ABILITIY_NAME).then(pixelmap => {
expect(err).assertFail();
}).catch(err => {
console.info("getAbilityIcon fail:" + JSON.stringify(err))
expect(err).assertEqual(1);
});
await bundle.getAbilityIcon("", "").then(pixelmap => {
expect(err).assertFail();
}).catch(err => {
console.info("getAbilityIcon fail:" + JSON.stringify(err))
expect(err).assertEqual(1);
});
bundle.getAbilityIcon(BUNDLE_NAME, ABILITIY_NAME_ERROR, (err, pixelmap) => {
console.log('bms_getAbilityIcon_0100 success: ' + pixelmap);
expect(err).assertEqual(1);
bundle.getAbilityIcon(BUNDLE_NAME_ERROR, ABILITIY_NAME, (err, pixelmap) => {
expect(err).assertEqual(1);
bundle.getAbilityIcon("", "", (err, pixelmap) => {
expect(err).assertEqual(1);
done();
});
});
});
});
/*
* @tc.number: bms_getAbilityIcon_0500
* @tc.name: test getAbilityIcon
* @tc.desc: get the abilityIcon
*/
it('bms_getAbilityIcon_0500', 0, async function (done) {
await bundle.getAbilityIcon(BUNDLE_NAME, undefined).then(pixelmap => {
expect(pixelmap).assertFail();
}).catch(err => {
console.info("getAbilityIcon fail:" + JSON.stringify(err));
expect(err).assertEqual(2);
});
await bundle.getAbilityIcon(undefined, ABILITIY_NAME).then(pixelmap => {
expect(pixelmap).assertFail();
}).catch(err => {
console.info("getAbilityIcon fail:" + JSON.stringify(err));
expect(err).assertEqual(2);
});
await bundle.getAbilityIcon(undefined, undefined).then(pixelmap => {
expect(pixelmap).assertFail();
}).catch(err => {
console.info("getAbilityIcon fail:" + JSON.stringify(err));
expect(err).assertEqual(2);
});
bundle.getAbilityIcon(BUNDLE_NAME, undefined, (err, pixelmap) => {
console.log('bms_getAbilityIcon_0100 success: ' + pixelmap);
expect(err).assertEqual(2);
bundle.getAbilityIcon(undefined, ABILITIY_NAME, (err, pixelmap) => {
expect(err).assertEqual(2);
bundle.getAbilityIcon(undefined, undefined, (err, pixelmap) => {
expect(err).assertEqual(2);
done();
});
});
});
});
}); });
} }
\ No newline at end of file
...@@ -19,190 +19,145 @@ import Bundle from '@ohos.bundle'; ...@@ -19,190 +19,145 @@ import Bundle from '@ohos.bundle';
const BUNDLE_NAME = 'com.open.harmony.packagemag'; const BUNDLE_NAME = 'com.open.harmony.packagemag';
const ABILITY_NAME = 'com.open.harmony.packagemag.MainAbility'; const ABILITY_NAME = 'com.open.harmony.packagemag.MainAbility';
const SERVICE_ABILITY_NAME = 'com.open.harmony.packagemag.ServiceAbility'; const SERVICE_ABILITY_NAME = 'com.open.harmony.packagemag.ServiceAbility';
const OTHER_BUNDLE_NAME = 'com.ohos.acepackage'; const OTHER_BUNDLE_NAME = 'com.example.l3jsdemo';
const OTHER_ABILITY_NAME = 'com.ohos.acepackage.MainAbility'; const OTHER_ABILITY_NAME = 'com.example.l3jsdemo.MainAbility';
const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error'; const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error';
const ABILITY_NAME_ERROR = 'com.ohos.acepackage.error.MainAbility'; const ABILITY_NAME_ERROR = 'com.ohos.acepackage.error.MainAbility';
export default function getAbilityLabelJsUnit() { export default function getAbilityLabel() {
describe('getAbilityLabel_test', function () {
describe('context_getAbilityLabel_test', function () {
/* /*
* @tc.number: context_getAbilityLabel_test_0100 * @tc.number: getAbilityLabel_test_0100
* @tc.name: getAbilityLabel : Gets the specified ability label * @tc.name: Test getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by promise) * @tc.desc: Check the return value of the interface
* @tc.level 0
*/ */
it('context_getAbilityLabel_test_0100', 0, async function (done) { it('getAbilityLabel_test_0100', 0, async function (done) {
let mData;
let timeOldStamp = await Utils.getNowTime();
await Bundle.getAbilityLabel(BUNDLE_NAME, ABILITY_NAME).then((data) => { await Bundle.getAbilityLabel(BUNDLE_NAME, ABILITY_NAME).then((data) => {
let timeNewStamp = Utils.getNowTime(); expect(data).assertEqual("entry_MainAbility");
Utils.getDurationTime('[context_getAbilityLabel_test_0100]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_getAbilityLabel_test_0100] promise data is: ' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.info('[context_getAbilityLabel_test_0100] promise error is: ' + error);
expect(error).assertFail(); expect(error).assertFail();
}); });
getAbilityLabelSuccess('[context_getAbilityLabel_test_0100]', mData);
done();
});
/*
* @tc.number: context_getAbilityLabel_test_0200
* @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_getAbilityLabel_test_0200', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime();
let mData;
Bundle.getAbilityLabel(BUNDLE_NAME, ABILITY_NAME, (error, data) => { Bundle.getAbilityLabel(BUNDLE_NAME, ABILITY_NAME, (error, data) => {
if (error) { expect(error).assertEqual(0);
console.error('[context_getAbilityLabel_test_0200]Operation failed. Cause: ' + JSON.stringify(error)); expect(data).assertEqual("entry_MainAbility");
expect(error).assertFail(); done();
}
let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_getAbilityLabel_test_0200]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[context_getAbilityLabel_test_0200] callBack error: ' + error);
console.info('[context_getAbilityLabel_test_0200] callBack data is:' + JSON.stringify(data));
}); });
await Utils.sleep(2000);
getAbilityLabelSuccess('[context_getAbilityLabel_test_0200]', mData);
done();
}); });
/* /*
* @tc.number: context_getAbilityLabel_test_0300 * @tc.number: getAbilityLabel_test_0200
* @tc.name: getAbilityLabel : Gets the specified ability label * @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by promise) * @tc.desc: Check the return value of the interface
* @tc.level 0
*/ */
it('context_getAbilityLabel_test_0300', 0, async function (done) { it('getAbilityLabel_test_0200', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime(); let timeOldStamp = await Utils.getNowTime();
let mError; await Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, OTHER_ABILITY_NAME).then((data) => {
await Bundle.getAbilityLabel(BUNDLE_NAME_ERROR, ABILITY_NAME_ERROR).then((data) => {
let timeNewStamp = Utils.getNowTime(); let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_getAbilityLabel_test_0300]', timeOldStamp, timeNewStamp); Utils.getDurationTime('[getAbilityLabel_test_0200]', timeOldStamp, timeNewStamp);
console.info('[context_getAbilityLabel_test_0300] promise data is: ' + JSON.stringify(data)); expect(data).assertEqual("bmsfirstright");
}).catch((error) => { }).catch((error) => {
expect(error).assertFail();
});
timeOldStamp = await Utils.getNowTime();
Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, OTHER_ABILITY_NAME, (error, data) => {
let timeNewStamp = Utils.getNowTime(); let timeNewStamp = Utils.getNowTime();
mError = error; Utils.getDurationTime('[context_getAbilityLabel_test_0200]', timeOldStamp, timeNewStamp);
Utils.getDurationTime('[context_getAbilityLabel_test_0300]', timeOldStamp, timeNewStamp); expect(data).assertEqual("bmsfirstright");
console.info('[context_getAbilityLabel_test_0300] promise error is: ' + error); expect(error).assertEqual(0);
expect(mError).assertEqual(1); done();
}); });
await Utils.sleep(2000);
getAbilityLabelFailure('[context_getAbilityLabel_test_0300]', mError);
done();
}); });
/* /*
* @tc.number: context_getAbilityLabel_test_0400 * @tc.number: getAbilityLabel_test_0300
* @tc.name: getAbilityLabel : Gets the specified ability label * @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by callback) * @tc.desc: Check the return value of the interface
* @tc.level 0
*/ */
it('context_getAbilityLabel_test_0400', 0, async function (done) { it('getAbilityLabel_test_0300', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime(); await Bundle.getAbilityLabel(BUNDLE_NAME, SERVICE_ABILITY_NAME).then((data) => {
let mError; expect(error).assertFail();
Bundle.getAbilityLabel(BUNDLE_NAME_ERROR, ABILITY_NAME_ERROR, (error, data) => { }).catch((error) => {
if (error !== null) { expect(error).assertEqual(1);
console.info('[context_getAbilityLabel_test_0400] callBack error: ' + error); });
expect(error).assertEqual(1); Bundle.getAbilityLabel(BUNDLE_NAME, SERVICE_ABILITY_NAME, (error, data) => {
} expect(error).assertEqual(1);
let timeNewStamp = Utils.getNowTime(); expect(data).assertEqual(undefined);
Utils.getDurationTime('[context_getAbilityLabel_test_0400]', timeOldStamp, timeNewStamp); done();
mError = error;
console.info('[context_getAbilityLabel_test_0400] callBack data is:' + JSON.stringify(data));
}); });
await Utils.sleep(2000);
getAbilityLabelFailure('[context_getAbilityLabel_test_0400]', mError);
done();
}); });
/* /*
* @tc.number: context_getAbilityLabel_test_0500 * @tc.number: getAbilityLabel_test_0400
* @tc.name: getAbilityLabel : Gets the specified ability label * @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by promise) * @tc.desc: Check the return value of the interface
* @tc.level 0
*/ */
it('context_getAbilityLabel_test_0500', 0, async function (done) { it('getAbilityLabel_test_0400', 0, async function (done) {
let mData;
let mError = null;
let timeOldStamp = await Utils.getNowTime(); let timeOldStamp = await Utils.getNowTime();
await Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, OTHER_ABILITY_NAME).then((data) => { await Bundle.getAbilityLabel(BUNDLE_NAME_ERROR, ABILITY_NAME_ERROR).then((data) => {
expect(error).assertFail();
}).catch((error) => {
let timeNewStamp = Utils.getNowTime(); let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_getAbilityLabel_test_0500]', timeOldStamp, timeNewStamp); Utils.getDurationTime('[getAbilityLabel_test_0400]', timeOldStamp, timeNewStamp);
mData = data; expect(error).assertEqual(1);
expect(mData).assertFail(); });
console.info('[context_getAbilityLabel_test_0500] promise data is: ' + JSON.stringify(data)); await Bundle.getAbilityLabel("", "").then((data) => {
expect(error).assertFail();
}).catch((error) => { }).catch((error) => {
mError = error; expect(error).assertEqual(1);
console.info('[context_getAbilityLabel_test_0500] promise error is: ' + error);
getAbilityLabelFailure('[context_getAbilityLabel_test_0500]', mError);
}); });
done(); timeOldStamp = await Utils.getNowTime();
}); Bundle.getAbilityLabel(BUNDLE_NAME_ERROR, ABILITY_NAME_ERROR, (error, data) => {
/*
* @tc.number: context_getAbilityLabel_test_0600
* @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('context_getAbilityLabel_test_0600', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime();
Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, OTHER_ABILITY_NAME, (error, data) => {
let timeNewStamp = Utils.getNowTime(); let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_getAbilityLabel_test_0600]', timeOldStamp, timeNewStamp); Utils.getDurationTime('[getAbilityLabel_test_0400]', timeOldStamp, timeNewStamp);
console.info('[context_getAbilityLabel_test_0600] callBack error: ' + error); expect(error).assertEqual(1);
getAbilityLabelFailure('[context_getAbilityLabel_test_0600]', error);
expect(data).assertEqual(undefined); expect(data).assertEqual(undefined);
Bundle.getAbilityLabel("", "", (error, data) => {
expect(error).assertEqual(1);
expect(data).assertEqual(undefined);
done();
});
}); });
done();
}); });
/* /*
* @tc.number: context_getAbilityLabel_test_0700 * @tc.number: getAbilityLabel_test_0500
* @tc.name: getAbilityLabel : Gets the specified ability label * @tc.name: getAbilityLabel : Gets the specified ability label
* @tc.desc: Check the return value of the interface (by callback) * @tc.desc: Check the return value of the interface
* @tc.level 0
*/ */
it('context_getAbilityLabel_test_0700', 0, async function (done) { it('getAbilityLabel_test_0500', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime(); await Bundle.getAbilityLabel(undefined, OTHER_ABILITY_NAME).then((data) => {
let mError; expect(error).assertFail();
Bundle.getAbilityLabel(BUNDLE_NAME, SERVICE_ABILITY_NAME, (error, data) => { }).catch((error) => {
let timeNewStamp = Utils.getNowTime(); expect(error).assertEqual(2);
Utils.getDurationTime('[context_getAbilityLabel_test_0700]', timeOldStamp, timeNewStamp); });
mError = error; await Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, undefined).then((data) => {
if (mError !== null) { expect(error).assertFail();
console.info('[context_getAbilityLabel_test_0600] callBack error: ' + error); }).catch((error) => {
} expect(error).assertEqual(2);
console.info('[context_getAbilityLabel_test_0700] callBack data is:' + JSON.stringify(data)); });
await Bundle.getAbilityLabel(undefined, undefined).then((data) => {
expect(error).assertFail();
}).catch((error) => {
expect(error).assertEqual(2);
});
Bundle.getAbilityLabel(undefined, OTHER_ABILITY_NAME, (error, data) => {
expect(error).assertEqual(2);
expect(data).assertEqual(undefined);
Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, undefined, (error, data) => {
expect(error).assertEqual(2);
expect(data).assertEqual(undefined);
Bundle.getAbilityLabel(undefined, undefined, (error, data) => {
expect(error).assertEqual(2);
expect(data).assertEqual(undefined);
done();
});
});
}); });
await Utils.sleep(2000);
getAbilityLabelFailure('[context_getAbilityLabel_test_0700]', mError);
done();
}); });
function getAbilityLabelSuccess(msg, data) {
console.log(msg + ' start ' + JSON.stringify(data));
console.log(msg + ' result ' + data);
expect(typeof (data)).assertEqual('string');
expect(data).assertEqual("entry_MainAbility");
}
function getAbilityLabelFailure(msg, error) {
console.log(msg + ' Failure ');
console.log(msg + ' error ' + JSON.stringify(error));
expect(typeof (error)).assertEqual('number');
expect(error).assertEqual(1)
}
}) })
} }
\ No newline at end of file
...@@ -17,17 +17,47 @@ import Utils from './Utils'; ...@@ -17,17 +17,47 @@ import Utils from './Utils';
import Bundle from '@ohos.bundle'; import Bundle from '@ohos.bundle';
const BUNDLE_NAME = 'com.open.harmony.packagemag'; const BUNDLE_NAME = 'com.open.harmony.packagemag';
const BUNDLE_NAME_OTHER = 'com.example.l3jsdemo';
const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error'; const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error';
const ABILITY_NAME = 'com.open.harmony.packagemag.MainAbility'; const ABILITY_NAME = 'com.open.harmony.packagemag.MainAbility';
const ABILITY_NAME_OTHER = 'com.example.l3jsdemo.MainAbility';
const ABILITY_NAME_ERROR = 'com.ohos.acepackage.error.MainAbility'; const ABILITY_NAME_ERROR = 'com.ohos.acepackage.error.MainAbility';
const ABILITY = { const ABILITY = {
bundleName: BUNDLE_NAME, bundleName: BUNDLE_NAME,
name: ABILITY_NAME name: ABILITY_NAME
} };
const ABILITY_ERROR = { const OTHER_ABILITY = {
bundleName: BUNDLE_NAME_OTHER,
name: ABILITY_NAME_OTHER
};
const ABILITY_ERROR1 = {
bundleName: BUNDLE_NAME_ERROR, bundleName: BUNDLE_NAME_ERROR,
name: ABILITY_NAME_ERROR name: ABILITY_NAME_ERROR
} };
const ABILITY_ERROR2 = {
bundleName: "",
name: ABILITY_NAME
};
const ABILITY_ERROR3 = {
bundleName: BUNDLE_NAME,
name: ""
};
const ABILITY_ERROR4 = {
bundleName: undefined,
name: ABILITY_NAME
};
const ABILITY_ERROR5 = {
bundleName: BUNDLE_NAME,
name: undefined
};
const ABILITY_ERROR6 = {
bundleName: undefined,
name: undefined
};
const ABILITY_ERROR7 = {
bundleName: "",
name: ""
};
export default function isAbilityEnabledETSUnit() { export default function isAbilityEnabledETSUnit() {
...@@ -36,114 +66,126 @@ export default function isAbilityEnabledETSUnit() { ...@@ -36,114 +66,126 @@ export default function isAbilityEnabledETSUnit() {
/* /*
* @tc.number: isAbilityEnabled_test_0100 * @tc.number: isAbilityEnabled_test_0100
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability * @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by promise) * @tc.desc: Check the return value of the interface
* @tc.level 0
*/ */
it('isAbilityEnabled_test_0100', 0, async function (done) { it('isAbilityEnabled_test_0100', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime(); let timeOldStamp = await Utils.getNowTime();
let mData;
await Bundle.isAbilityEnabled(ABILITY).then((data) => { await Bundle.isAbilityEnabled(ABILITY).then((data) => {
let timeNewStamp = Utils.getNowTime(); let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[isAbilityEnabled_test_0100]', timeOldStamp, timeNewStamp); Utils.getDurationTime('[isAbilityEnabled_test_0100]', timeOldStamp, timeNewStamp);
mData = data; expect(data).assertTrue();
console.info('[isAbilityEnabled_test_0100] promise data is: ' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.info('[isAbilityEnabled_test_0100] promise error is: ' + error);
expect(error).assertFail(); expect(error).assertFail();
}); });
getAbilityEnabledTrue('[isAbilityEnabled_test_0100]', mData); timeOldStamp = await Utils.getNowTime();
done(); Bundle.isAbilityEnabled(ABILITY, (error, data) => {
if (error) {
expect(error).assertFail();
}
let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[isAbilityEnabled_test_0100]', timeOldStamp, timeNewStamp);
expect(data).assertTrue();
done();
});
}); });
/* /*
* @tc.number: isAbilityEnabled_test_0200 * @tc.number: isAbilityEnabled_test_0200
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability * @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by callback) * @tc.desc: Check the return value of the interface when bundleName and ability error
* @tc.level 0
*/ */
it('isAbilityEnabled_test_0200', 0, async function (done) { it('isAbilityEnabled_test_0200', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime(); await Bundle.isAbilityEnabled(ABILITY_ERROR1).then((data) => {
let mData; expect(data).assertFalse();
Bundle.isAbilityEnabled(ABILITY, (error, data) => { }).catch((error) => {
if (error) { expect(error).assertFail();
console.error('[isAbilityEnabled_test_0200]Operation failed. Cause: ' + JSON.stringify(error)); });
expect(error).assertFail(); await Bundle.isAbilityEnabled(ABILITY_ERROR2).then((data) => {
} expect(data).assertFalse();
let timeNewStamp = Utils.getNowTime(); }).catch((error) => {
Utils.getDurationTime('[isAbilityEnabled_test_0200]', timeOldStamp, timeNewStamp); expect(error).assertFail();
mData = data; });
console.info('[isAbilityEnabled_test_0200] callBack data is:' + JSON.stringify(data)); await Bundle.isAbilityEnabled(ABILITY_ERROR3).then((data) => {
expect(data).assertFalse();
}).catch((error) => {
expect(error).assertFail();
});
await Bundle.isAbilityEnabled(ABILITY_ERROR7).then((data) => {
expect(data).assertFalse();
}).catch((error) => {
expect(error).assertFail();
});
Bundle.isAbilityEnabled(ABILITY_ERROR1, (error, data) => {
expect(error).assertEqual(0);
expect(data).assertFalse();
Bundle.isAbilityEnabled(ABILITY_ERROR2, (error, data) => {
expect(error).assertEqual(0);
expect(data).assertFalse();
Bundle.isAbilityEnabled(ABILITY_ERROR3, (error, data) => {
expect(error).assertEqual(0);
expect(data).assertFalse();
Bundle.isAbilityEnabled(ABILITY_ERROR7, (error, data) => {
expect(error).assertEqual(0);
expect(data).assertFalse();
done();
});
});
});
}); });
await Utils.sleep(2000);
getAbilityEnabledTrue('[isAbilityEnabled_test_0200]', mData);
done();
}); });
/* /*
* @tc.number: isAbilityEnabled_test_0300 * @tc.number: isAbilityEnabled_test_0300
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability * @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by promise) * @tc.desc: Check the return value of the interface when bundleName and ability error
* @tc.level 0
*/ */
it('isAbilityEnabled_test_0300', 0, async function (done) { it('isAbilityEnabled_test_0300', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime(); await Bundle.isAbilityEnabled(ABILITY_ERROR4).then((data) => {
let mData; expect(data).assertFail();
await Bundle.isAbilityEnabled(ABILITY_ERROR).then((data) => {
let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[isAbilityEnabled_test_0300]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[isAbilityEnabled_test_0300] promise data is: ' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
let timeNewStamp = Utils.getNowTime(); expect(error).assertEqual(2);
Utils.getDurationTime('[isAbilityEnabled_test_0300]', timeOldStamp, timeNewStamp); });
console.info('[isAbilityEnabled_test_0300] promise error is: ' + error); await Bundle.isAbilityEnabled(ABILITY_ERROR5).then((data) => {
expect(error).assertFail(); expect(data).assertFail();
}).catch((error) => {
expect(error).assertEqual(2);
});
await Bundle.isAbilityEnabled(ABILITY_ERROR6).then((data) => {
expect(data).assertFail();
}).catch((error) => {
expect(error).assertEqual(2);
});
Bundle.isAbilityEnabled(ABILITY_ERROR4, (error, data) => {
expect(error).assertEqual(2);
expect(data).assertEqual(undefined);
Bundle.isAbilityEnabled(ABILITY_ERROR5, (error, data) => {
expect(error).assertEqual(2);
expect(data).assertEqual(undefined);
Bundle.isAbilityEnabled(ABILITY_ERROR6, (error, data) => {
expect(error).assertEqual(2);
expect(data).assertEqual(undefined);
done();
});
});
}); });
getAbilityEnabledFalse('[isAbilityEnabled_test_0300]', mData);
done();
}); });
/* /*
* @tc.number: isAbilityEnabled_test_0400 * @tc.number: isAbilityEnabled_test_0400
* @tc.name: isAbilityEnabled : Get whether to enable a specified ability * @tc.name: isAbilityEnabled : Get whether to enable a specified ability
* @tc.desc: Check the return value of the interface (by callback) * @tc.desc: Check the return value of the interface
* @tc.level 0
*/ */
it('isAbilityEnabled_test_0400', 0, async function (done) { it('isAbilityEnabled_test_0400', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime(); await Bundle.isAbilityEnabled(OTHER_ABILITY).then((data) => {
let mData; expect(data).assertTrue();
Bundle.isAbilityEnabled(ABILITY_ERROR, (error, data) => { }).catch((error) => {
if (error) { expect(error).assertFail();
console.error('[isAbilityEnabled_test_0400]Operation failed. Cause: ' + JSON.stringify(error)); });
expect(error).assertFail(); Bundle.isAbilityEnabled(OTHER_ABILITY, (error, data) => {
} expect(error).assertEqual(0);
let timeNewStamp = Utils.getNowTime(); expect(data).assertTrue();
Utils.getDurationTime('[isAbilityEnabled_test_0300]', timeOldStamp, timeNewStamp); done();
mData = data;
console.info('[isAbilityEnabled_test_0400] callBack data is:' + JSON.stringify(data));
}); });
await Utils.sleep(2000);
console.info('[isAbilityEnabled_test_0400] Failure ');
getAbilityEnabledFalse('[isAbilityEnabled_test_0300]', mData);
done();
}); });
function getAbilityEnabledSuccess(msg, data) {
console.log(msg + ' start ' + JSON.stringify(data));
expect(typeof (data)).assertEqual('boolean');
}
function getAbilityEnabledTrue(msg, data) {
getAbilityEnabledSuccess(msg, data);
expect(data).assertEqual(true);
}
function getAbilityEnabledFalse(msg, data) {
getAbilityEnabledSuccess(msg, data);
expect(data).assertEqual(false);
}
}) })
} }
\ No newline at end of file
...@@ -16,122 +16,94 @@ import { describe, it, expect } from 'deccjsunit/index.ets'; ...@@ -16,122 +16,94 @@ import { describe, it, expect } from 'deccjsunit/index.ets';
import Utils from './Utils'; import Utils from './Utils';
import Bundle from '@ohos.bundle'; import Bundle from '@ohos.bundle';
const BUNDLE_NAME = 'com.open.harmony.packagemag' const BUNDLE_NAME = 'com.open.harmony.packagemag';
const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error' const BUNDLE_NAME_OTHER = 'com.example.l3jsdemo';
const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error';
export default function IsApplicationEnabledETSUnit() { export default function IsApplicationEnabledETSUnit() {
describe('isApplicationEnabled_test', function () { describe('isApplicationEnabled_test', function () {
/* /*
* @tc.number: isApplicationEnabled_test_0100 * @tc.number: context_isApplicationEnabled_test_0100
* @tc.name: isApplicationEnabled : Get whether to enable a specified application * @tc.name: isApplicationEnabled : Get whether to enable a specified application
* @tc.desc: Check the return value of the interface (by promise) * @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/ */
it('isApplicationEnabled_test_0100', 0, async function (done) { it('isApplicationEnabled_test_0100', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime(); let timeOldStamp = await Utils.getNowTime();
let mData;
await Bundle.isApplicationEnabled(BUNDLE_NAME).then((data) => { await Bundle.isApplicationEnabled(BUNDLE_NAME).then((data) => {
let timeNewStamp = Utils.getNowTime(); let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[isApplicationEnabled_test_0100]', timeOldStamp, timeNewStamp); Utils.getDurationTime('[isApplicationEnabled_test_0100]', timeOldStamp, timeNewStamp);
mData = data; expect(data).assertTrue();
console.info('[isApplicationEnabled_test_0100] promise data is: ' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
console.info('[isApplicationEnabled_test_0100] promise error is: ' + error);
expect(error).assertFail(); expect(error).assertFail();
}); });
getApplicationEnabledTrue('[isApplicationEnabled_test_0100]', mData); timeOldStamp = await Utils.getNowTime();
done(); Bundle.isApplicationEnabled(BUNDLE_NAME, (error, data) => {
let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[context_isApplicationEnabled_test_0200]', timeOldStamp, timeNewStamp);
expect(error).assertEqual(undefined);
expect(data).assertTrue();
done();
});
}); });
/* /*
* @tc.number: isApplicationEnabled_test_0200 * @tc.number: isApplicationEnabled_test_0200
* @tc.name: isApplicationEnabled : Get whether to enable a specified application * @tc.name: isApplicationEnabled : Get whether to enable a specified application
* @tc.desc: Check the return value of the interface (by callback) * @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/ */
it('isApplicationEnabled_test_0200', 0, async function (done) { it('isApplicationEnabled_test_0200', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime(); await Bundle.isApplicationEnabled(BUNDLE_NAME_ERROR).then((data) => {
let mData; expect(data).assertFalse();
Bundle.isApplicationEnabled(BUNDLE_NAME, (error, data) => { }).catch((error) => {
if (error) { expect(error).assertFail();
console.error('[isApplicationEnabled_test_0200]Operation failed. Cause: ' + JSON.stringify(error)); });
expect(error).assertFail(); await Bundle.isApplicationEnabled("").then((data) => {
} expect(data).assertFalse();
let timeNewStamp = Utils.getNowTime(); }).catch((error) => {
Utils.getDurationTime('[isApplicationEnabled_test_0200]', timeOldStamp, timeNewStamp); expect(error).assertFail();
mData = data; });
console.info('[isApplicationEnabled_test_0200] callBack data is:' + JSON.stringify(data)); await Bundle.isApplicationEnabled(undefined).then((data) => {
expect(data).assertFail();
}).catch((error) => {
expect(error).assertEqual(2);
});
Bundle.isApplicationEnabled(BUNDLE_NAME_ERROR, (error, data) => {
expect(error).assertEqual(undefined);
expect(data).assertFalse();
Bundle.isApplicationEnabled("", (error, data) => {
expect(error).assertEqual(undefined);
expect(data).assertFalse();
Bundle.isApplicationEnabled(undefined, (error, data) => {
expect(error).assertEqual(2);
expect(data).assertEqual(undefined);
done();
});
});
}); });
await Utils.sleep(2000);
getApplicationEnabledTrue('[isApplicationEnabled_test_0200]', mData);
done();
}); });
/* /*
* @tc.number: isApplicationEnabled_test_0300 * @tc.number: isApplicationEnabled_test_0300
* @tc.name: isApplicationEnabled : Get whether to enable a specified application * @tc.name: isApplicationEnabled : Get whether to enable a specified application
* @tc.desc: Check the return value of the interface (by promise) * @tc.desc: Check the return value of the interface (by promise)
* @tc.level 0
*/ */
it('isApplicationEnabled_test_0300', 0, async function (done) { it('isApplicationEnabled_test_0300', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime(); let timeOldStamp = await Utils.getNowTime();
let mData; await Bundle.isApplicationEnabled(BUNDLE_NAME_OTHER).then((data) => {
await Bundle.isApplicationEnabled(BUNDLE_NAME_ERROR).then((data) => { expect(data).assertTrue();
let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[isApplicationEnabled_test_0300]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[isApplicationEnabled_test_0300] promise data is: ' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[isApplicationEnabled_test_0300]', timeOldStamp, timeNewStamp);
console.info('[isApplicationEnabled_test_0300] promise error is: ' + error);
expect(error).assertFail(); expect(error).assertFail();
}); });
getApplicationEnabledFalse('[isApplicationEnabled_test_0300]', mData); timeOldStamp = await Utils.getNowTime();
done(); Bundle.isApplicationEnabled(BUNDLE_NAME_OTHER, (error, data) => {
}); expect(error).assertEqual(undefined);
expect(data).assertTrue();
/* done();
* @tc.number: isApplicationEnabled_test_0400
* @tc.name: isApplicationEnabled : Get whether to enable a specified application
* @tc.desc: Check the return value of the interface (by callback)
* @tc.level 0
*/
it('isApplicationEnabled_test_0400', 0, async function (done) {
let timeOldStamp = await Utils.getNowTime();
let mData;
Bundle.isApplicationEnabled(BUNDLE_NAME_ERROR, (error, data) => {
if (error) {
console.error('[isApplicationEnabled_test_0400]Operation failed. Cause: ' + JSON.stringify(error));
expect(error).assertFail();
}
let timeNewStamp = Utils.getNowTime();
Utils.getDurationTime('[isApplicationEnabled_test_0400]', timeOldStamp, timeNewStamp);
mData = data;
console.info('[isApplicationEnabled_test_0400] callBack data is:' + JSON.stringify(data));
}); });
await Utils.sleep(2000);
getApplicationEnabledFalse('[isApplicationEnabled_test_0300]', mData);
done();
}); });
function getApplicationEnabledSuccess(msg, data) {
console.log(msg + ' start ' + JSON.stringify(data));
expect(typeof (data)).assertEqual('boolean');
}
function getApplicationEnabledTrue(msg, data) {
getApplicationEnabledSuccess(msg, data);
expect(data).assertEqual(true);
}
function getApplicationEnabledFalse(msg, data) {
getApplicationEnabledSuccess(msg, data);
expect(data).assertEqual(false);
}
}) })
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册