1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import {BusinessError} from "@ohos.base"; 16import * as Test from "finalization_test"; 17 18loadLibrary("ani_finalization"); 19 20function doFullGC() { 21 try { 22 GC.waitForFinishGC(GC.startGC(GC.Cause.FULL, GC.IN_PLACE_MODE)); 23 } catch (e) { 24 assertTrue(false, "Unexpected exception during GC"); 25 } 26} 27 28function test_finalization() { 29 let flag: int = 0; 30 31 let foo: Test.Foo|null = Test.makeFoo(); 32 foo.addCallback(() => { 33 flag = 42; 34 }) 35 foo.addCallback(() => { 36 console.log("Bye!"); 37 }) 38 foo = null; 39 40 console.log("...") 41 42 doFullGC() 43 Coroutine.Schedule() 44 45 assertEQ(flag, 42); 46} 47 48function main() { 49 console.log("begin") 50 51 const suite = new ArkTestsuite("FuncTest Test"); 52 53 suite.addTest("test finalization", test_finalization); 54 55 exit(suite.run()); 56} 57