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 lib from "session_test"; 17 18loadLibrary("ani_session"); 19 20function test_func_a(my_iface: lib.IfaceD) { 21 const result = my_iface.func_a(); 22 assertEQ(result, "a"); 23} 24 25function test_func_b(my_iface: lib.IfaceD) { 26 const result = my_iface.func_b(); 27 assertEQ(result, "b"); 28} 29 30function test_func_c(my_iface: lib.IfaceD) { 31 const result = my_iface.func_c(); 32 assertEQ(result, "c"); 33} 34 35function test_func_d(my_iface: lib.IfaceD) { 36 const result = my_iface.func_d(); 37 assertEQ(my_iface.name, "IfaceD"); 38 my_iface.name = "new name"; 39 assertEQ(my_iface.name, "new name"); 40 assertEQ(result, "d"); 41 try { 42 my_iface.on("set", () => { 43 console.log("void input void output callback!"); 44 }) 45 } catch (error) { 46 console.error("main finsih test ERROR ", error) 47 } 48 try { 49 my_iface.off("set", () => { 50 console.log("void input void output callback!"); 51 }) 52 } catch (error) { 53 console.error("main finsih test ERROR ", error) 54 } 55} 56 57function test_func_e(my_iface: lib.IfaceE) { 58 let result = my_iface.func_a(); 59 assertEQ(result, "aa"); 60 result = my_iface.func_b(); 61 assertEQ(result, "bb"); 62 result = my_iface.func_c(); 63 assertEQ(result, "cc"); 64 result = my_iface.func_e(); 65 assertEQ(result, "ee"); 66} 67 68function main() { 69 console.log("##############start#############"); 70 let ps = lib.getSession(1); 71 if (ps instanceof lib.PhotoSession) { 72 ps.beginConfig(); 73 ps.canPreconfig(); 74 } 75 76 let vs = lib.getSession(0); 77 if (vs instanceof lib.VideoSession) { 78 vs.beginConfig(); 79 vs.canPreconfig(); 80 } 81 82 const suite = new ArkTestsuite("Interface Tests"); 83 const my_iface = lib.getIfaceD(); 84 const my_iface_e = lib.getIfaceE(); 85 86 suite.addTest("test func_a", () => {test_func_a(my_iface)}); 87 suite.addTest("test func_b", () => {test_func_b(my_iface)}); 88 suite.addTest("test func_c", () => {test_func_c(my_iface)}); 89 suite.addTest("test func_d", () => {test_func_d(my_iface)}); 90 suite.addTest("test func_e", () => {test_func_e(my_iface_e)}); 91 92 exit(suite.run()); 93} 94