From 2133c467ce528c64a55ed2b07918fe0e6148b5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=86=E4=BD=B3=E5=BA=B7?= <851520508@qq.com> Date: Wed, 31 Dec 2025 18:19:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TestCpp.tsx | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/TestCpp.tsx b/TestCpp.tsx index 475fcae..1a352c9 100644 --- a/TestCpp.tsx +++ b/TestCpp.tsx @@ -171,6 +171,7 @@ export const testData: TestResult[] = [ { name: 'NitroModules.isHybridObject(testObject) to be true', state: '⏳ Click to run', message: '' }, { name: 'NitroModules.hasHybridObject(testObject.name) to be true', state: '⏳ Click to run', message: '' }, { name: 'NitroModules.buildType holds a string', state: '⏳ Click to run', message: '' }, + { name: 'createInternalObject() returns SomeExternalObject', state: '⏳ Click to run', message: '' }, ]; const getResult = (state: string) => { @@ -262,6 +263,8 @@ async function getFunc(name: TestResult['name']) { return NitroModulesHasHybridObject(name); case 'NitroModules.buildType holds a string': return NitroModulesBuildType(name); + case 'createInternalObject() returns SomeExternalObject': + return createInternalObjectTest(name); } } @@ -928,6 +931,38 @@ function NitroModulesBuildType(prop: TestResult['name']) { return message } +function createInternalObjectTest(prop: TestResult['name']) { + let message: ResultMessage; + try { + const testObject = NitroModules.createHybridObject("TestObjectCpp"); + + // 调用createInternalObject方法 + const result = testObject.createInternalObject(); + + // 检查返回值是否为对象 + if (typeof result !== 'object' || result === null) { + throw new Error(`Expected SomeExternalObject but got ${typeof result}`); + } + + // 检查是否包含getValue方法(SomeExternalObject的核心方法) + if (!('getValue' in result) || typeof result.getValue !== 'function') { + throw new Error('Expected SomeExternalObject to have getValue method'); + } + + // 调用getValue方法验证功能 + const value = result.getValue(); + if (typeof value !== 'string') { + throw new Error(`Expected getValue() to return string but got ${typeof value}`); + } + + message = resMessage("pass", ""); + + } catch (error) { + message = resMessage("failed", error.message); + } + return message; +} + // 点击调用,更新data export async function upTestData(index: number, testData: TestResult[]) { -- Gitee