From 2ff62d5fc385682f61674b46af3d75b06534432e Mon Sep 17 00:00:00 2001 From: HuangXW Date: Sat, 15 Oct 2022 17:20:13 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20a5da832=20from=20https://gitee.com/H-xi?= =?UTF-8?q?nwei/xts=5Facts/pulls/5927=20=E9=94=99=E8=AF=AF=E7=A0=81?= =?UTF-8?q?=E6=95=B4=E6=94=B9=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia75b1cbeca2c2a49512f2bcb4e111dd1397d0399 Signed-off-by: HuangXW --- .../entry/src/main/ets/test/Ability.test.ets | 144 ++++++++++-------- .../main/ets/test/ApiCoverAbility.test.ets | 14 +- .../src/main/ets/test/VerificationTest.ets | 29 ++-- 3 files changed, 106 insertions(+), 81 deletions(-) diff --git a/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/test/Ability.test.ets index e96e52c30..50168d40f 100644 --- a/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/actscalltest/systemcallentrytest/entry/src/main/ets/test/Ability.test.ets @@ -47,6 +47,14 @@ var subscriberInfo = { var caseDepBundles = []; var subscriber = null; +const ERROR_CODE_INVALID_PARAM = 401; +const ERROR_CODE_CALLER_RELEASED = 16200001; +const ERROR_CODE_CLAAEE_INVALID = 16200002; +const ERROR_CODE_FUNC_REGISTERED = 16200004; +const ERROR_CODE_FUNC_NOT_EXIST = 16200005; +const ERROR_CODE_INNER_ERROR = 16000050; +const ERROR_CODE_TYPE_ERROR = 16000002; + class MySequenceable { num: number = 0; str: String = "default"; @@ -588,19 +596,21 @@ export default function abilityTest() { */ it('ACTS_CommonComponent_Call_1700', 0, async function (done) { console.log('ACTS_CommonComponent_Call_1700 begin'); - var caller; var exceptionFlag = false; - try { - caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ - bundleName: systemAppCalleeABundleName, - abilityName: systemAppCalleeAThirdAbilityName, - }); - } catch(err) { - console.log('ACTS_CommonComponent_Call_1700 exception' + err); + await globalThis.globalThis.abilityContext.startAbilityByCall({ + bundleName: systemAppCalleeABundleName, + abilityName: systemAppCalleeAThirdAbilityName, + }).then(data => { + expect().assertFail(); + done(); + }).catch(err => { + console.log('ACTS_CommonComponent_Call_1700 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_TYPE_ERROR); exceptionFlag = true; - expect(err.message).assertEqual("function request remote error"); - } + }); + expect(exceptionFlag).assertEqual(true); done(); }) @@ -655,8 +665,9 @@ export default function abilityTest() { try { globalThis.callee.on('', onTest); } catch (err) { - console.log('ACTS_CommonComponent_Call_3100 callee.on err' + err); - expect(err.message).assertEqual("function input parameter error"); + console.log('ACTS_CommonComponent_Call_3100 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INVALID_PARAM); finishFlag = 1; } @@ -680,8 +691,9 @@ export default function abilityTest() { try { globalThis.callee.on(null, onTest); } catch (err) { - console.log('ACTS_CommonComponent_Call_3200 callee.on err' + err); - expect(err.message).assertEqual("function input parameter error"); + console.log('ACTS_CommonComponent_Call_3200 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INVALID_PARAM); finishFlag = 1; } @@ -705,8 +717,9 @@ export default function abilityTest() { try { globalThis.callee.on(undefined, onTest); } catch (err) { - console.log('ACTS_CommonComponent_Call_3300 callee.on err' + err); - expect(err.message).assertEqual("function input parameter error"); + console.log('ACTS_CommonComponent_Call_3300 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INVALID_PARAM); finishFlag = 1; } @@ -726,8 +739,9 @@ export default function abilityTest() { try { globalThis.callee.off(''); } catch (err) { - console.log('ACTS_CommonComponent_Call_3400 callee.off err' + err); - expect(err.message).assertEqual("function input parameter error"); + console.log('ACTS_CommonComponent_Call_3400 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INVALID_PARAM); finishFlag = 1; } @@ -747,8 +761,9 @@ export default function abilityTest() { try { globalThis.callee.off(null); } catch (err) { - console.log('ACTS_CommonComponent_Call_3500 callee.off err' + err); - expect(err.message).assertEqual("function input parameter error"); + console.log('ACTS_CommonComponent_Call_3500 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INVALID_PARAM); finishFlag = 1; } @@ -768,8 +783,9 @@ export default function abilityTest() { try { globalThis.callee.off(undefined); } catch (err) { - console.log('ACTS_CommonComponent_Call_3600 callee.off err' + err); - expect(err.message).assertEqual("function input parameter error"); + console.log('ACTS_CommonComponent_Call_3600 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INVALID_PARAM); finishFlag = 1; } @@ -788,8 +804,9 @@ export default function abilityTest() { try { globalThis.callee.on('testCall', ""); } catch (err) { - console.log('ACTS_CommonComponent_Call_4300 call err' + err); - expect(err.message).assertEqual("function input parameter error"); + console.log('ACTS_CommonComponent_Call_4300 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INVALID_PARAM); finishFlag = 1; } @@ -808,8 +825,9 @@ export default function abilityTest() { try { globalThis.callee.on('testCall', null); } catch (err) { - console.log('ACTS_CommonComponent_Call_4400 call err' + err); - expect(err.message).assertEqual("function input parameter error"); + console.log('ACTS_CommonComponent_Call_4400 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INVALID_PARAM); finishFlag = 1; } @@ -828,8 +846,9 @@ export default function abilityTest() { try { globalThis.callee.on('testCall', undefined); } catch (err) { - console.log('ACTS_CommonComponent_Call_4500 call err' + err); - expect(err.message).assertEqual("function input parameter error"); + console.log('ACTS_CommonComponent_Call_4500 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INVALID_PARAM); finishFlag = 1; } @@ -861,8 +880,9 @@ export default function abilityTest() { try { globalThis.callee.on('ACTS_CommonComponent_Call_5000', testCallback_5100); } catch (err) { - console.log('ACTS_CommonComponent_Call_5000 call err' + err); - expect(err.message).assertEqual("function is registered"); + console.log('ACTS_CommonComponent_Call_5000 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_FUNC_REGISTERED); finishFlag = 1; } @@ -897,8 +917,9 @@ export default function abilityTest() { try { globalThis.callee.off('ACTS_CommonComponent_Call_5100'); } catch (err) { - console.log('ACTS_CommonComponent_Call_5100 call err' + err); - expect(err.message).assertEqual("function not registered"); + console.log('ACTS_CommonComponent_Call_5100 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_FUNC_NOT_EXIST); finishFlag = 1; } @@ -914,17 +935,19 @@ export default function abilityTest() { */ it('ACTS_CommonComponent_Call_5200', 0, async function (done) { console.log('ACTS_CommonComponent_Call_5200 begin'); - let caller; let exceptionFlag = false; - try { - caller = await globalThis.globalThis.abilityContext.startAbilityByCall(null); - console.log('ACTS_CommonComponent_Call_5200 startAbilityByCall' + JSON.stringify(caller)) - } catch(err) { - console.log('ACTS_CommonComponent_Call_5200 exception' + err); - exceptionFlag = true; - expect(err.message).assertEqual("function input parameter error"); - } + + await globalThis.globalThis.abilityContext.startAbilityByCall(null) + .then(data => { + expect().assertFail(); + done(); + }).catch(err => { + console.log('ACTS_CommonComponent_Call_5200 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INVALID_PARAM); + exceptionFlag = true; + }); expect(exceptionFlag).assertEqual(true); done(); @@ -937,20 +960,20 @@ export default function abilityTest() { */ it('ACTS_CommonComponent_Call_5300', 0, async function (done) { console.log('ACTS_CommonComponent_Call_5300 begin'); - let caller; let exceptionFlag = false; - try { - caller = await globalThis.globalThis.abilityContext.startAbilityByCall({ - bundleName: "", - abilityName: "", - }); - console.log('ACTS_CommonComponent_Call_5300 startAbilityByCall' + JSON.stringify(caller)) - } catch(err) { - console.log('ACTS_CommonComponent_Call_5300 exception' + err); + await globalThis.globalThis.abilityContext.startAbilityByCall({ + bundleName: "", + abilityName: "", + }).then(data => { + expect().assertFail(); + done(); + }).catch(err => { + console.log('ACTS_CommonComponent_Call_5300 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INNER_ERROR); exceptionFlag = true; - expect(err.message).assertEqual("function request remote error"); - } + }); expect(exceptionFlag).assertEqual(true); done(); @@ -963,17 +986,18 @@ export default function abilityTest() { */ it('ACTS_CommonComponent_Call_5400', 0, async function (done) { console.log('ACTS_CommonComponent_Call_5400 begin'); - let caller; let exceptionFlag = false; - try { - caller = await globalThis.globalThis.abilityContext.startAbilityByCall(undefined); - console.log('ACTS_CommonComponent_Call_5400 startAbilityByCall' + JSON.stringify(caller)) - } catch(err) { - console.log('ACTS_CommonComponent_Call_5400 exception' + err); + await globalThis.globalThis.abilityContext.startAbilityByCall(undefined) + .then(data => { + expect().assertFail(); + done(); + }).catch(err => { + console.log('ACTS_CommonComponent_Call_5400 call err.code: ' + JSON.stringify(err.code) + + ' err.msg: ' + JSON.stringify(err.message)); + expect(err.code).assertEqual(ERROR_CODE_INVALID_PARAM); exceptionFlag = true; - expect(err.message).assertEqual("function input parameter error"); - } + }); expect(exceptionFlag).assertEqual(true); done(); diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets index df792a639..8f41c6aa1 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/ApiCoverAbility.test.ets @@ -24,9 +24,9 @@ import appManager from '@ohos.application.appManager' import applicationContext from '@ohos.application.context' import commonEvent from '@ohos.commonEvent'; import ability from '@ohos.ability.ability' -FormDimension -var EXTENSION_INFO_ERR = 2097152 -var USERID_ERR = 2097177 + +var EXTENSION_INFO_ERR = 16000001 +var CROSS_USER_DENY = 201 var trueInfo; var array = new Array(); function sleep(time) { @@ -102,7 +102,7 @@ export default function ApiCoverTest() { expect("case execute failed").assertEqual("data"); }).catch((error) => { console.error(`Ability: startServiceExtensionAbilityWithAccount failed: ${JSON.stringify(error)}`); - expect(USERID_ERR).assertEqual(error.code); + expect(CROSS_USER_DENY).assertEqual(error.code); }) done() }) @@ -124,7 +124,7 @@ export default function ApiCoverTest() { expect("case execute failed").assertEqual(data); }).catch((error) => { console.error(`Ability: stopServiceExtensionAbilityWithAccount failed: ${JSON.stringify(error)}`); - expect(USERID_ERR).assertEqual(error.code); + expect(CROSS_USER_DENY).assertEqual(error.code); }) done() }) @@ -193,7 +193,7 @@ export default function ApiCoverTest() { await globalThis.abilityContext.startServiceExtensionAbilityWithAccount(want, 999, (err, data) => { if (err.code) { console.error(`Ability: startServiceExtensionAbilityWithAccount failed: ${JSON.stringify(err)}`); - expect(USERID_ERR).assertEqual(err.code); + expect(CROSS_USER_DENY).assertEqual(err.code); } else { console.log(`Ability: startServiceExtensionAbilityWithAccount success: ${JSON.stringify(data)}`); expect("case execute failed").assertEqual(data); @@ -217,7 +217,7 @@ export default function ApiCoverTest() { globalThis.abilityContext.stopServiceExtensionAbilityWithAccount(want, 999, (err, data) => { if (err.code) { console.error(`Ability: stopServiceExtensionAbilityWithAccount failed: ${JSON.stringify(err)}`); - expect(USERID_ERR).assertEqual(err.code); + expect(CROSS_USER_DENY).assertEqual(err.code); } else { console.log(`Ability: stopServiceExtensionAbilityWithAccount success: ${JSON.stringify(data)}`); expect("case execute failed").assertEqual(data); diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/VerificationTest.ets b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/VerificationTest.ets index 6a1ba6268..d70ed9217 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/VerificationTest.ets +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/VerificationTest.ets @@ -18,6 +18,7 @@ import AbilityConstant from "@ohos.application.AbilityConstant"; import appManager from "@ohos.application.appManager"; import wantConstant from '@ohos.ability.wantConstant'; +var INVALID_PARAM = 401 var TAG export default function verificationTest(){ @@ -280,34 +281,34 @@ export default function verificationTest(){ */ it('SUB_AA_OpenHarmony_SetMissionLabel_0100', 0, async function(done) { TAG = 'SUB_AA_OpenHarmony_SetMissionLabel_0100 ==>'; + let label = undefined; + let code1 = 0; + let code2 = 0; try { - let label = undefined - let code1 = 0 - let code2 = 0 - globalThis.abilityContext.setMissionLabel(label).then((data) => { + await globalThis.abilityContext.setMissionLabel(label).then((data) => { console.info(TAG + "setMissionLabel data = " + JSON.stringify(data)); }).catch((err) => { code1 = err.code console.info(TAG + "setMissionLabel err = " + JSON.stringify(err)); }); + } catch (err) { + console.info(TAG + "setMissionLabel err = " + JSON.stringify(err)); + expect(err.code).assertEqual(INVALID_PARAM); + } - globalThis.abilityContext.setMissionLabel(label, (err, data) => { + try { + await globalThis.abilityContext.setMissionLabel(label, (err, data) => { code2 = err.code console.info(TAG + "setMissionLabel err = " + JSON.stringify(err)); console.info(TAG + "setMissionLabel data = " + JSON.stringify(data)); }) - - setTimeout(()=>{ - expect(code1).assertEqual(-1); - expect(code2).assertEqual(-1); - done() - }, 3000) } catch (err) { - console.info(TAG + "catch err = " + JSON.stringify(err)); - expect().assertFail(); - done(); + console.info(TAG + "setMissionLabel err = " + JSON.stringify(err)); + expect(err.code).assertEqual(INVALID_PARAM); } + + done(); }) /* -- GitLab