From 4fc944afb843a6efc20c3ab4c7e48be8e5e5666d Mon Sep 17 00:00:00 2001 From: yuwenze Date: Fri, 1 Sep 2023 08:29:42 +0000 Subject: [PATCH] fixed Signed-off-by: yuwenze Change-Id: I08e5f94e9bd21f539d888df23710f5c25774d8d7 --- .../entry/src/main/ets/test/LifecycleTest.ets | 42 +++++++------- .../src/main/ets/TestAbility/TestAbility.ts | 2 - .../entry/src/main/ets/test/LifeCycleTest.ets | 58 ++++++++++--------- 3 files changed, 50 insertions(+), 52 deletions(-) diff --git a/ability/ability_runtime/stage/actslifecyclemultihaptest/entry/src/main/ets/test/LifecycleTest.ets b/ability/ability_runtime/stage/actslifecyclemultihaptest/entry/src/main/ets/test/LifecycleTest.ets index dd0e02bc8..02a3fa123 100644 --- a/ability/ability_runtime/stage/actslifecyclemultihaptest/entry/src/main/ets/test/LifecycleTest.ets +++ b/ability/ability_runtime/stage/actslifecyclemultihaptest/entry/src/main/ets/test/LifecycleTest.ets @@ -331,8 +331,6 @@ export default function abilityTest() { it("Multihap_LifecycleTest_005", 0, async function (done) { console.log("------------Multihap_LifecycleTest_005 start-------------"); TAG = "Multihap_LifecycleTest_005"; - listKeyTemp = []; - listKeyTemp1 = []; globalThis.abilityContext.startAbility({ bundleName: "com.example.lifecycletest", @@ -361,31 +359,31 @@ export default function abilityTest() { setTimeout(() => { console.log(TAG + ": second Hap2MainAbility7 startAbility success, err: " + JSON.stringify(error) + ",data: " + JSON.stringify(data)); - for (var i = 0;i < globalThis.mainAbility4ListKey.length; i++) { + let setTemp = new Set(); + let setTemp1 = new Set(); + for (var i = 0; i < globalThis.mainAbility4ListKey.length; i++) { if (globalThis.mainAbility4ListKey[i].substring(0, 16) == "Hap2MainAbility6") { - listKeyTemp.push(globalThis.mainAbility4ListKey[i]); + setTemp.add(globalThis.mainAbility4ListKey[i]); + console.log(TAG + " setTemp entry is :" + JSON.stringify(globalThis.mainAbility4ListKey[i])); } else if (globalThis.mainAbility4ListKey[i].substring(0, 16) == "Hap2MainAbility7") { - listKeyTemp1.push(globalThis.mainAbility4ListKey[i]); + setTemp1.add(globalThis.mainAbility4ListKey[i]); + console.log(TAG + " setTemp1 entry is :" + JSON.stringify(globalThis.mainAbility4ListKey[i])); } } - console.log(TAG + "listKeyTemp is :" + listKeyTemp); - console.log(TAG + "listKeyTemp1 is :" + listKeyTemp1); console.log(TAG + "globalThis.mainAbility4CallBackId is :" + globalThis.mainAbility4CallBackId); - expect(listKeyTemp[0]).assertEqual("Hap2MainAbility6 onAbilityCreate"); - expect(listKeyTemp[1]).assertEqual("Hap2MainAbility6 onWindowStageCreate"); - expect(listKeyTemp[2]).assertEqual("Hap2MainAbility6 onAbilityForeground"); - expect(listKeyTemp[3]).assertEqual("Hap2MainAbility6 onAbilityBackground"); - var transferStr0 = listKeyTemp[4] + listKeyTemp[5]; - expect(transferStr0.indexOf("Hap2MainAbility6 onWindowStageDestroy")!=-1).assertTrue(); - expect(transferStr0.indexOf("Hap2MainAbility6 onAbilityDestroy")!=-1).assertTrue(); - - expect(listKeyTemp1[0]).assertEqual("Hap2MainAbility7 onAbilityCreate"); - expect(listKeyTemp1[1]).assertEqual("Hap2MainAbility7 onWindowStageCreate"); - expect(listKeyTemp1[2]).assertEqual("Hap2MainAbility7 onAbilityForeground"); - expect(listKeyTemp1[3]).assertEqual("Hap2MainAbility7 onAbilityBackground"); - var transferStr0 = listKeyTemp1[4] + listKeyTemp1[5]; - expect(transferStr0.indexOf("Hap2MainAbility7 onWindowStageDestroy")!=-1).assertTrue(); - expect(transferStr0.indexOf("Hap2MainAbility7 onAbilityDestroy")!=-1).assertTrue(); + expect(setTemp.has("Hap2MainAbility6 onAbilityCreate")).assertTrue(); + expect(setTemp.has("Hap2MainAbility6 onWindowStageCreate")).assertTrue(); + expect(setTemp.has("Hap2MainAbility6 onAbilityForeground")).assertTrue(); + expect(setTemp.has("Hap2MainAbility6 onAbilityBackground")).assertTrue(); + expect(setTemp.has("Hap2MainAbility6 onWindowStageDestroy")).assertTrue(); + expect(setTemp.has("Hap2MainAbility6 onAbilityDestroy")).assertTrue(); + + expect(setTemp1.has("Hap2MainAbility7 onAbilityCreate")).assertTrue(); + expect(setTemp1.has("Hap2MainAbility7 onWindowStageCreate")).assertTrue(); + expect(setTemp1.has("Hap2MainAbility7 onAbilityForeground")).assertTrue(); + expect(setTemp1.has("Hap2MainAbility7 onAbilityBackground")).assertTrue(); + expect(setTemp1.has("Hap2MainAbility7 onWindowStageDestroy")).assertTrue(); + expect(setTemp1.has("Hap2MainAbility7 onAbilityDestroy")).assertTrue(); globalThis.ApplicationContext4 .unregisterAbilityLifecycleCallback(globalThis.mainAbility4CallBackId, (error, data) => { diff --git a/ability/ability_runtime/stage/actslifecyclesinglehaptest/entry/src/main/ets/TestAbility/TestAbility.ts b/ability/ability_runtime/stage/actslifecyclesinglehaptest/entry/src/main/ets/TestAbility/TestAbility.ts index 8028a70f8..66f303ed9 100644 --- a/ability/ability_runtime/stage/actslifecyclesinglehaptest/entry/src/main/ets/TestAbility/TestAbility.ts +++ b/ability/ability_runtime/stage/actslifecyclesinglehaptest/entry/src/main/ets/TestAbility/TestAbility.ts @@ -32,8 +32,6 @@ export default class TestAbility extends Ability { } console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) }); - - globalThis.abilityContext = this.context; } onWindowStageDestroy() { diff --git a/ability/ability_runtime/stage/actslifecyclesinglehaptest/entry/src/main/ets/test/LifeCycleTest.ets b/ability/ability_runtime/stage/actslifecyclesinglehaptest/entry/src/main/ets/test/LifeCycleTest.ets index aa96dda98..26d77763d 100644 --- a/ability/ability_runtime/stage/actslifecyclesinglehaptest/entry/src/main/ets/test/LifeCycleTest.ets +++ b/ability/ability_runtime/stage/actslifecyclesinglehaptest/entry/src/main/ets/test/LifeCycleTest.ets @@ -94,15 +94,14 @@ export default function lifecycleTest() { tempCallbackId = globalThis.callbackid; console.log(TAG + " registerAbilityLifecycleCallback tempCallbackId : " + JSON.stringify(tempCallbackId)); var strtemp = ""; - var listtemp = []; + let settemp = new Set(); for (var i = 0; i < globalThis.list.length; i++) { strtemp = globalThis.list[i].substring(0, 12); if (strtemp === "MainAbility2") { - listtemp.push(globalThis.list[i]); + settemp.add(globalThis.list[i]); + console.log(TAG + " entry is :" + JSON.stringify(globalThis.list[i])); } } - console.log(TAG + " listtemp is :" + JSON.stringify(listtemp)); - let exlist = listtemp; globalThis.applicationContext .unregisterAbilityLifecycleCallback(tempCallbackId, (error, data) => { console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) + @@ -110,12 +109,12 @@ export default function lifecycleTest() { code = error.code; }); setTimeout(function () { - expect(exlist[0]).assertEqual("MainAbility2 onAbilityCreate"); - expect(exlist[1]).assertEqual("MainAbility2 onWindowStageCreate"); - expect(exlist[2]).assertEqual("MainAbility2 onAbilityForeground"); - expect(exlist[3]).assertEqual("MainAbility2 onAbilityBackground"); - expect(exlist[4]).assertEqual("MainAbility2 onWindowStageDestroy"); - expect(exlist[5]).assertEqual("MainAbility2 onAbilityDestroy"); + expect(settemp.has("MainAbility2 onAbilityCreate")).assertTrue(); + expect(settemp.has("MainAbility2 onWindowStageCreate")).assertTrue(); + expect(settemp.has("MainAbility2 onAbilityForeground")).assertTrue(); + expect(settemp.has("MainAbility2 onAbilityBackground")).assertTrue(); + expect(settemp.has("MainAbility2 onWindowStageDestroy")).assertTrue(); + expect(settemp.has("MainAbility2 onAbilityDestroy")).assertTrue(); expect(code).assertEqual(0); console.log("------------Singlehap_LifeCycleTest_0100 END-------------"); done(); @@ -159,20 +158,23 @@ export default function lifecycleTest() { console.log(TAG + " registerAbilityLifecycleCallback listKey : " + JSON.stringify(globalThis.list1)); console.log(TAG + " registerAbilityLifecycleCallback callbackid : " + JSON.stringify(globalThis.callbackid1)); var strtemp = ""; - var listtemp = []; - var listtemp1 = []; + let maptemp = new Map(); + let settemp = new Set(); for (var i = 0; i < globalThis.list1.length; i++) { strtemp = globalThis.list1[i].substring(0, 12); if (strtemp === "MainAbility1") { - listtemp.push(globalThis.list1[i]); + if (maptemp.has(globalThis.list1[i])) { + let value = maptemp.get(globalThis.list1[i]); + maptemp.set(globalThis.list1[i], value + 1); + } else { + maptemp.set(globalThis.list1[i], 1); + } + console.log(TAG + " maptemp entry is :" + JSON.stringify(globalThis.list1[i])); } else if (strtemp === "MainAbility2") { - listtemp1.push(globalThis.list1[i]); + settemp.add(globalThis.list1[i]); + console.log(TAG + " settemp entry is :" + JSON.stringify(globalThis.list1[i])); } } - console.log(TAG + " listtemp is :" + JSON.stringify(listtemp)); - console.log(TAG + " listtemp1 is :" + JSON.stringify(listtemp1)); - let exlist = listtemp; - let exlist1 = listtemp1; globalThis.applicationContext1 .unregisterAbilityLifecycleCallback(globalThis.callbackid1, (error, data) => { console.log(TAG + ": unregisterAbilityLifecycleCallback success, err: " + JSON.stringify(error) + @@ -180,16 +182,16 @@ export default function lifecycleTest() { code = error.code; }) setTimeout(function () { - expect(exlist[0]).assertEqual("MainAbility1 onWindowStageCreate"); - expect(exlist[1]).assertEqual("MainAbility1 onAbilityForeground"); - expect(exlist[2]).assertEqual("MainAbility1 onAbilityBackground"); - expect(exlist[3]).assertEqual("MainAbility1 onAbilityForeground"); - expect(exlist1[0]).assertEqual("MainAbility2 onAbilityCreate"); - expect(exlist1[1]).assertEqual("MainAbility2 onWindowStageCreate"); - expect(exlist1[2]).assertEqual("MainAbility2 onAbilityForeground"); - expect(exlist1[3]).assertEqual("MainAbility2 onAbilityBackground"); - expect(exlist1[4]).assertEqual("MainAbility2 onWindowStageDestroy"); - expect(exlist1[5]).assertEqual("MainAbility2 onAbilityDestroy"); + expect(maptemp.has("MainAbility1 onWindowStageCreate")).assertTrue(); + expect(maptemp.get("MainAbility1 onAbilityForeground")).assertEqual(2); + expect(maptemp.has("MainAbility1 onAbilityBackground")).assertTrue(); + + expect(settemp.has("MainAbility2 onAbilityCreate")).assertTrue(); + expect(settemp.has("MainAbility2 onWindowStageCreate")).assertTrue(); + expect(settemp.has("MainAbility2 onAbilityForeground")).assertTrue(); + expect(settemp.has("MainAbility2 onAbilityBackground")).assertTrue(); + expect(settemp.has("MainAbility2 onWindowStageDestroy")).assertTrue(); + expect(settemp.has("MainAbility2 onAbilityDestroy")).assertTrue(); expect(code).assertEqual(0); console.log("------------Singlehap_LifeCycleTest_0200 END-------------"); done(); -- GitLab