From 4ccedc7f16a212344ab5c24d30b3ad98b0e9681d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E4=BA=AE?= Date: Sat, 14 Jan 2023 18:17:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E4=BE=8BSUB=5FAA=5F?= =?UTF-8?q?UpdateConfiguration=5F0200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 杨亮 Change-Id: I7f3fdcafcaff1dd7a854ff261f223479b649dcd1 --- .../src/main/ets/MainAbility/MainAbility.ts | 24 ++++++++ .../main/ets/test/NewApiCoverAbility.test.ets | 60 +++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/MainAbility/MainAbility.ts index 881e90c13..7dcadfa15 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -47,4 +47,28 @@ export default class MainAbility extends Ability { // Ability has back to background console.log("[Demo] MainAbility onBackground") } + + onConfigurationUpdate(config) { + console.log('[Demo] MainAbility onConfigurationUpdate: ' + this.context.config.language) + console.log('[Demo] MainAbility onConfigurationUpdate: ' + config.language) + if (globalThis.UpdateConfiguration_0200_prepare_resolve) { + globalThis.UpdateConfiguration_0200_prepare_resolve(); + } + + if (!globalThis.UpdateConfiguration_0200_resolve) { + console.log("[Demo] MainAbility invalid resolve") + return; + } + + if (!globalThis.UpdateConfiguration_0200_reject) { + console.log("[Demo] MainAbility invalid reject") + return; + } + + if (this.context.config.language == "English" && config.language == "zh-Hans") { + globalThis.UpdateConfiguration_0200_resolve(); + } else { + globalThis.UpdateConfiguration_0200_reject(); + } + } }; diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/NewApiCoverAbility.test.ets b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/NewApiCoverAbility.test.ets index 1f7f77d4a..12f62432a 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/NewApiCoverAbility.test.ets +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/NewApiCoverAbility.test.ets @@ -131,5 +131,65 @@ export default function ApiCoverTest() { done(); } }); + + /* + * @tc.number SUB_AA_UpdateConfiguration_0200 + * @tc.name Test updateConfiguration. + * @tc.desc Function test + * @tc.level 3 + */ + it('SUB_AA_UpdateConfiguration_0200', 0, async function (done) { + let enLanguage = { + language: 'English' + } + let zhLanguage = { + language: 'zh-Hans' + } + + // set language to english + await new Promise((resolve, reject) => { + globalThis.UpdateConfiguration_0200_prepare_resolve = resolve; + console.info("SUB_AA_UpdateConfiguration_0200 ----> before set language to english."); + abilityManager.updateConfiguration(enLanguage).then(() => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> set language to english succeed."); + }).catch(err => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> failed to set language to english: " + err); + globalThis.UpdateConfiguration_0200_prepare_resolve(); + }); + }).then(() => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> succees to set language."); + }).catch(err => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> failed to set language: " + err); + }).finally(() => { + globalThis.UpdateConfiguration_0200_prepare_resolve = null; + globalThis.UpdateConfiguration_0200_resolve = null; + globalThis.UpdateConfiguration_0200_reject = null; + console.info("SUB_AA_UpdateConfiguration_0200 ----> set promise to null after all"); + }); + + + // set language to chinese + await new Promise((resolve, reject) => { + globalThis.UpdateConfiguration_0200_resolve = resolve; + globalThis.UpdateConfiguration_0200_reject = reject; + console.info("SUB_AA_UpdateConfiguration_0200 ----> before set language to chinese."); + abilityManager.updateConfiguration(zhLanguage).then(() => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> set language to chinese succeed."); + }).catch(err => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> failed to set language to chinese: " + err); + }); + }).then(() => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> succees to set language."); + expect(true).assertTrue(); + }).catch(err => { + console.info("SUB_AA_UpdateConfiguration_0200 ----> failed to set language: " + err); + expect(false).assertTrue(); + }).finally(() => { + globalThis.UpdateConfiguration_0200_resolve = null; + globalThis.UpdateConfiguration_0200_reject = null; + console.info("SUB_AA_UpdateConfiguration_0200 ----> set promise to null after all"); + done(); + }); + }); }) } -- GitLab